X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fffmpeg%2Fffmpeg_error.h;h=71958c4c7b18dbbddaa3e68a91d239f5e982b250;hb=01d8a61541548cf535791be39d233799eefc4187;hp=c66f9e4b71994ff84f33e006f340ab2ca8f5a46d;hpb=3db7da0b5ad6045e418cfbe2719ae6d1ffbd2d37;p=casparcg diff --git a/modules/ffmpeg/ffmpeg_error.h b/modules/ffmpeg/ffmpeg_error.h index c66f9e4b7..71958c4c7 100644 --- a/modules/ffmpeg/ffmpeg_error.h +++ b/modules/ffmpeg/ffmpeg_error.h @@ -1,5 +1,8 @@ #pragma once +#include +#include + #include #pragma warning(push, 1) @@ -11,7 +14,21 @@ extern "C" #pragma warning(pop) -namespace caspar { +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) { @@ -22,4 +39,114 @@ static std::string av_error_str(int errn) return std::string(buf); } -} \ No newline at end of file +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; \ + throw_on_ffmpeg_error(ret, source, THROW_ON_ERROR_STR(call), __FUNCTION__, __FILE__, __LINE__); \ + return ret; \ + }() + +}} \ No newline at end of file