]> git.sesse.net Git - casparcg/blob - modules/ffmpeg/ffmpeg_error.cpp
x64: Builds in debug without image, oal and ogl projects. Flash doesn't work.
[casparcg] / modules / ffmpeg / ffmpeg_error.cpp
1 #include "StdAfx.h"\r
2 \r
3 /*\r
4 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
5 *\r
6 * This file is part of CasparCG (www.casparcg.com).\r
7 *\r
8 * CasparCG is free software: you can redistribute it and/or modify\r
9 * it under the terms of the GNU General Public License as published by\r
10 * the Free Software Foundation, either version 3 of the License, or\r
11 * (at your option) any later version.\r
12 *\r
13 * CasparCG is distributed in the hope that it will be useful,\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16 * GNU General Public License for more details.\r
17 *\r
18 * You should have received a copy of the GNU General Public License\r
19 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
20 *\r
21 * Author: Robert Nagy, ronag89@gmail.com\r
22 */\r
23 #include "ffmpeg_error.h"\r
24 \r
25 #include <common/exception/exceptions.h>\r
26 #include <common/utility/string.h>\r
27 \r
28 #pragma warning(disable: 4146)\r
29 \r
30 extern "C" \r
31 {\r
32 #include <libavutil/error.h>\r
33 }\r
34 \r
35 namespace caspar { namespace ffmpeg {\r
36         \r
37 std::string av_error_str(int errn)\r
38 {\r
39         char buf[256];\r
40         memset(buf, 0, 256);\r
41         if(av_strerror(errn, buf, 256) < 0)\r
42                 return "";\r
43         return std::string(buf);\r
44 }\r
45 \r
46 void throw_on_ffmpeg_error(int ret, const char* source, const char* func, const char* local_func, const char* file, int line)\r
47 {\r
48         if(ret >= 0)\r
49                 return;\r
50 \r
51         switch(ret)\r
52         {\r
53         case AVERROR_BSF_NOT_FOUND:\r
54                 ::boost::exception_detail::throw_exception_(averror_bsf_not_found()<<                                                                           \r
55                         msg_info(av_error_str(ret)) <<                                                  \r
56                         source_info(source) <<                                          \r
57                         boost::errinfo_api_function(func) <<                                    \r
58                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);  \r
59         case AVERROR_DECODER_NOT_FOUND:\r
60                 ::boost::exception_detail::throw_exception_(averror_decoder_not_found()<<                                                                               \r
61                         msg_info(av_error_str(ret)) <<                                                  \r
62                         source_info(source) <<                                          \r
63                         boost::errinfo_api_function(func) <<                                    \r
64                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
65         case AVERROR_DEMUXER_NOT_FOUND:\r
66                 ::boost::exception_detail::throw_exception_(averror_demuxer_not_found()<<                                                                               \r
67                         msg_info(av_error_str(ret)) <<                                                  \r
68                         source_info(source) <<                                          \r
69                         boost::errinfo_api_function(func) <<                                    \r
70                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
71         case AVERROR_ENCODER_NOT_FOUND:\r
72                 ::boost::exception_detail::throw_exception_(averror_encoder_not_found()<<                                                                               \r
73                         msg_info(av_error_str(ret)) <<                                                  \r
74                         source_info(source) <<                                          \r
75                         boost::errinfo_api_function(func) <<                                    \r
76                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);  \r
77         case AVERROR_EOF:       \r
78                 ::boost::exception_detail::throw_exception_(averror_eof()<<                                                                             \r
79                         msg_info(av_error_str(ret)) <<                                                  \r
80                         source_info(source) <<                                          \r
81                         boost::errinfo_api_function(func) <<                                    \r
82                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
83         case AVERROR_EXIT:                              \r
84                 ::boost::exception_detail::throw_exception_(averror_exit()<<                                                                            \r
85                         msg_info(av_error_str(ret)) <<                                                  \r
86                         source_info(source) <<                                          \r
87                         boost::errinfo_api_function(func) <<                                    \r
88                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
89         case AVERROR_FILTER_NOT_FOUND:                          \r
90                 ::boost::exception_detail::throw_exception_(averror_filter_not_found()<<                                                                                \r
91                         msg_info(av_error_str(ret)) <<                                                  \r
92                         source_info(source) <<                                          \r
93                         boost::errinfo_api_function(func) <<                                    \r
94                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
95         case AVERROR_MUXER_NOT_FOUND:   \r
96                 ::boost::exception_detail::throw_exception_(averror_muxer_not_found()<<                                                                         \r
97                         msg_info(av_error_str(ret)) <<                                                  \r
98                         source_info(source) <<                                          \r
99                         boost::errinfo_api_function(func) <<                                    \r
100                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
101         case AVERROR_OPTION_NOT_FOUND:  \r
102                 ::boost::exception_detail::throw_exception_(averror_option_not_found()<<                                                                                \r
103                         msg_info(av_error_str(ret)) <<                                                  \r
104                         source_info(source) <<                                          \r
105                         boost::errinfo_api_function(func) <<                                    \r
106                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
107         case AVERROR_PATCHWELCOME:      \r
108                 ::boost::exception_detail::throw_exception_(averror_patchwelcome()<<                                                                            \r
109                         msg_info(av_error_str(ret)) <<                                                  \r
110                         source_info(source) <<                                          \r
111                         boost::errinfo_api_function(func) <<                                    \r
112                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
113         case AVERROR_PROTOCOL_NOT_FOUND:        \r
114                 ::boost::exception_detail::throw_exception_(averror_protocol_not_found()<<                                                                              \r
115                         msg_info(av_error_str(ret)) <<                                                  \r
116                         source_info(source) <<                                          \r
117                         boost::errinfo_api_function(func) <<                                    \r
118                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
119         case AVERROR_STREAM_NOT_FOUND:\r
120                 ::boost::exception_detail::throw_exception_(averror_stream_not_found()<<                                                                                \r
121                         msg_info(av_error_str(ret)) <<                                                  \r
122                         source_info(source) <<                                          \r
123                         boost::errinfo_api_function(func) <<                                    \r
124                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
125         default:\r
126                 ::boost::exception_detail::throw_exception_(ffmpeg_error()<<                                                                            \r
127                         msg_info(av_error_str(ret)) <<                                                  \r
128                         source_info(source) <<                                          \r
129                         boost::errinfo_api_function(func) <<                                    \r
130                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
131         }\r
132 }\r
133 \r
134 void throw_on_ffmpeg_error(int ret, const std::wstring& source, const char* func, const char* local_func, const char* file, int line)\r
135 {\r
136         throw_on_ffmpeg_error(ret, u8(source).c_str(), func, local_func, file, line);\r
137 }\r
138 \r
139 }}