]> git.sesse.net Git - casparcg/blob - modules/ffmpeg/ffmpeg_error.h
59f4e43895ddbfebdfa3b6aff8609f8d2b6fbec5
[casparcg] / modules / ffmpeg / ffmpeg_error.h
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\r
5 *\r
6 * CasparCG is free software: you can redistribute it and/or modify\r
7 * it under the terms of the GNU General Public License as published by\r
8 * the Free Software Foundation, either version 3 of the License, or\r
9 * (at your option) any later version.\r
10 *\r
11 * CasparCG is distributed in the hope that it will be useful,\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 * GNU General Public License for more details.\r
15 *\r
16 * You should have received a copy of the GNU General Public License\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #pragma once\r
23 \r
24 #include <common/except.h>\r
25 \r
26 #include <string>\r
27 \r
28 namespace caspar { namespace ffmpeg {\r
29 \r
30 struct ffmpeg_error : virtual caspar_exception{};\r
31 struct averror_bsf_not_found : virtual ffmpeg_error{};\r
32 struct averror_decoder_not_found : virtual ffmpeg_error{};\r
33 struct averror_demuxer_not_found : virtual ffmpeg_error{};\r
34 struct averror_encoder_not_found : virtual ffmpeg_error{};\r
35 struct averror_eof : virtual ffmpeg_error{};\r
36 struct averror_exit : virtual ffmpeg_error{};\r
37 struct averror_filter_not_found : virtual ffmpeg_error{};\r
38 struct averror_muxer_not_found : virtual ffmpeg_error{};\r
39 struct averror_option_not_found : virtual ffmpeg_error{};\r
40 struct averror_patchwelcome : virtual ffmpeg_error{};\r
41 struct averror_protocol_not_found : virtual ffmpeg_error{};\r
42 struct averror_stream_not_found : virtual ffmpeg_error{};\r
43 \r
44 std::string av_error_str(int errn);\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 void throw_on_ffmpeg_error(int ret, const std::wstring& source, const char* func, const char* local_func, const char* file, int line);\r
48 \r
49 \r
50 //#define THROW_ON_ERROR(ret, source, func) throw_on_ffmpeg_error(ret, source, __FUNC__, __FILE__, __LINE__)\r
51 \r
52 #define THROW_ON_ERROR_STR_(call) #call\r
53 #define THROW_ON_ERROR_STR(call) THROW_ON_ERROR_STR_(call)\r
54 \r
55 #define THROW_ON_ERROR(ret, func, source) \\r
56                 throw_on_ffmpeg_error(ret, source, func, __FUNCTION__, __FILE__, __LINE__);             \r
57 \r
58 #define THROW_ON_ERROR2(call, source)                                                                           \\r
59         [&]() -> int                                                                                                                    \\r
60         {                                                                                                                                               \\r
61                 int ret = call;                                                                                                         \\r
62                 throw_on_ffmpeg_error(ret, source, THROW_ON_ERROR_STR(call), __FUNCTION__, __FILE__, __LINE__); \\r
63                 return ret;                                                                                                                     \\r
64         }()\r
65 \r
66 #define LOG_ON_ERROR2(call, source)                                                                                     \\r
67         [&]() -> int                                                                                                                    \\r
68         {                                       \\r
69                 int ret = -1;\\r
70                 try{                                                                                                                            \\r
71                  ret = call;                                                                                                                    \\r
72                 throw_on_ffmpeg_error(ret, source, THROW_ON_ERROR_STR(call), __FUNCTION__, __FILE__, __LINE__); \\r
73                 return ret;                                                                                                                     \\r
74                 }catch(...){CASPAR_LOG_CURRENT_EXCEPTION();}                                            \\r
75                 return ret;                                                                                                                     \\r
76         }()\r
77 \r
78 }}\r