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