]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/ffmpeg_error.h
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[casparcg] / modules / ffmpeg / ffmpeg_error.h
index 017b13c75f5dd10d41ccca413e8d43c6b17f0874..71958c4c7b18dbbddaa3e68a91d239f5e982b250 100644 (file)
@@ -1,6 +1,7 @@
 #pragma once\r
 \r
 #include <common/exception/exceptions.h>\r
+#include <common/utility/string.h>\r
 \r
 #include <string>\r
 \r
@@ -16,6 +17,18 @@ extern "C"
 namespace caspar { namespace ffmpeg {\r
 \r
 struct ffmpeg_error : virtual caspar_exception{};\r
+struct averror_bsf_not_found : virtual ffmpeg_error{};\r
+struct averror_decoder_not_found : virtual ffmpeg_error{};\r
+struct averror_demuxer_not_found : virtual ffmpeg_error{};\r
+struct averror_encoder_not_found : virtual ffmpeg_error{};\r
+struct averror_eof : virtual ffmpeg_error{};\r
+struct averror_exit : virtual ffmpeg_error{};\r
+struct averror_filter_not_found : virtual ffmpeg_error{};\r
+struct averror_muxer_not_found : virtual ffmpeg_error{};\r
+struct averror_option_not_found : virtual ffmpeg_error{};\r
+struct averror_patchwelcome : virtual ffmpeg_error{};\r
+struct averror_protocol_not_found : virtual ffmpeg_error{};\r
+struct averror_stream_not_found : virtual ffmpeg_error{};\r
 \r
 static std::string av_error_str(int errn)\r
 {\r
@@ -26,34 +39,114 @@ static std::string av_error_str(int errn)
        return std::string(buf);\r
 }\r
 \r
-#define THROW_ON_ERROR(ret, source, func)                                                      \\r
-       if(ret < 0)                                                                                                             \\r
-       {                                                                                                                               \\r
-               BOOST_THROW_EXCEPTION(                                                                          \\r
-                       ffmpeg_error() <<                                                                               \\r
-                       msg_info(av_error_str(ret)) <<                                                  \\r
-                       source_info(narrow(source)) <<                                                  \\r
-                       boost::errinfo_api_function(func) <<                                    \\r
-                       boost::errinfo_errno(AVUNERROR(ret)));                                  \\r
+static void throw_on_ffmpeg_error(int ret, const char* source, const char* func, const char* local_func, const char* file, int line)\r
+{\r
+       if(ret >= 0)\r
+               return;\r
+\r
+       switch(ret)\r
+       {\r
+       case AVERROR_BSF_NOT_FOUND:\r
+               ::boost::exception_detail::throw_exception_(averror_bsf_not_found()<<                                                                           \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);  \r
+       case AVERROR_DECODER_NOT_FOUND:\r
+               ::boost::exception_detail::throw_exception_(averror_decoder_not_found()<<                                                                               \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
+       case AVERROR_DEMUXER_NOT_FOUND:\r
+               ::boost::exception_detail::throw_exception_(averror_demuxer_not_found()<<                                                                               \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
+       case AVERROR_ENCODER_NOT_FOUND:\r
+               ::boost::exception_detail::throw_exception_(averror_encoder_not_found()<<                                                                               \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);  \r
+       case AVERROR_EOF:       \r
+               ::boost::exception_detail::throw_exception_(averror_eof()<<                                                                             \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
+       case AVERROR_EXIT:                              \r
+               ::boost::exception_detail::throw_exception_(averror_exit()<<                                                                            \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
+       case AVERROR_FILTER_NOT_FOUND:                          \r
+               ::boost::exception_detail::throw_exception_(averror_filter_not_found()<<                                                                                \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
+       case AVERROR_MUXER_NOT_FOUND:   \r
+               ::boost::exception_detail::throw_exception_(averror_muxer_not_found()<<                                                                         \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
+       case AVERROR_OPTION_NOT_FOUND:  \r
+               ::boost::exception_detail::throw_exception_(averror_option_not_found()<<                                                                                \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
+       case AVERROR_PATCHWELCOME:      \r
+               ::boost::exception_detail::throw_exception_(averror_patchwelcome()<<                                                                            \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
+       case AVERROR_PROTOCOL_NOT_FOUND:        \r
+               ::boost::exception_detail::throw_exception_(averror_protocol_not_found()<<                                                                              \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
+       case AVERROR_STREAM_NOT_FOUND:\r
+               ::boost::exception_detail::throw_exception_(averror_stream_not_found()<<                                                                                \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
+       default:\r
+               ::boost::exception_detail::throw_exception_(ffmpeg_error()<<                                                                            \r
+                       msg_info(av_error_str(ret)) <<                                                  \r
+                       source_info(narrow(source)) <<                                          \r
+                       boost::errinfo_api_function(func) <<                                    \r
+                       boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);\r
        }\r
+}\r
+\r
+static void throw_on_ffmpeg_error(int ret, const std::wstring& source, const char* func, const char* local_func, const char* file, int line)\r
+{\r
+       throw_on_ffmpeg_error(ret, narrow(source).c_str(), func, local_func, file, line);\r
+}\r
+\r
+\r
+//#define THROW_ON_ERROR(ret, source, func) throw_on_ffmpeg_error(ret, source, __FUNC__, __FILE__, __LINE__)\r
 \r
 #define THROW_ON_ERROR_STR_(call) #call\r
 #define THROW_ON_ERROR_STR(call) THROW_ON_ERROR_STR_(call)\r
 \r
+#define THROW_ON_ERROR(ret, func, source) \\r
+               throw_on_ffmpeg_error(ret, source, func, __FUNCTION__, __FILE__, __LINE__);             \r
+\r
 #define THROW_ON_ERROR2(call, source)                                                                          \\r
        [&]() -> int                                                                                                                    \\r
        {                                                                                                                                               \\r
                int ret = call;                                                                                                         \\r
-               if(ret < 0)                                                                                                                     \\r
-               {                                                                                                                                       \\r
-                       BOOST_THROW_EXCEPTION(                                                                                  \\r
-                               ffmpeg_error() <<                                                                                       \\r
-                               msg_info(av_error_str(ret)) <<                                                          \\r
-                               source_info(narrow(source)) <<                                                          \\r
-                               boost::errinfo_api_function(THROW_ON_ERROR_STR(call)) <<        \\r
-                               boost::errinfo_errno(AVUNERROR(ret)));                                          \\r
-               }                                                                                                                                       \\r
+               throw_on_ffmpeg_error(ret, source, THROW_ON_ERROR_STR(call), __FUNCTION__, __FILE__, __LINE__); \\r
                return ret;                                                                                                                     \\r
-       }();\r
+       }()\r
 \r
 }}
\ No newline at end of file