-/*\r
-* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
-*\r
-* This file is part of CasparCG (www.casparcg.com).\r
-*\r
-* CasparCG is free software: you can redistribute it and/or modify\r
-* it under the terms of the GNU General Public License as published by\r
-* the Free Software Foundation, either version 3 of the License, or\r
-* (at your option) any later version.\r
-*\r
-* CasparCG is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
-*\r
-* Author: Robert Nagy, ronag89@gmail.com\r
-*/\r
-\r
-#pragma once\r
-\r
-#include <common/exception/exceptions.h>\r
-#include <common/utility/string.h>\r
-\r
-#include <string>\r
-\r
-#pragma warning(push, 1)\r
-\r
-extern "C" \r
-{\r
-#include <libavutil/error.h>\r
-}\r
-\r
-#pragma warning(pop)\r
-\r
-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
- char buf[256];\r
- memset(buf, 0, 256);\r
- if(av_strerror(errn, buf, 256) < 0)\r
- return "";\r
- return std::string(buf);\r
-}\r
-\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((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((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((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((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((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((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((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((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((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((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((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((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((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::string& source, const char* func, const char* local_func, const char* file, int line)\r
-{\r
- throw_on_ffmpeg_error(ret, (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
- throw_on_ffmpeg_error(ret, source, THROW_ON_ERROR_STR(call), __FUNCTION__, __FILE__, __LINE__); \\r
- return ret; \\r
- }()\r
-\r
-#define LOG_ON_ERROR2(call, source) \\r
- [&]() -> int \\r
- { \\r
- int ret = -1;\\r
- try{ \\r
- ret = call; \\r
- throw_on_ffmpeg_error(ret, source, THROW_ON_ERROR_STR(call), __FUNCTION__, __FILE__, __LINE__); \\r
- return ret; \\r
- }catch(...){CASPAR_LOG_CURRENT_EXCEPTION();} \\r
- return ret; \\r
- }()\r
-\r
-}}
\ No newline at end of file
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Robert Nagy, ronag89@gmail.com
+*/
+
+#pragma once
+
+#include <common/except.h>
+
+#include <string>
+
+namespace caspar { namespace ffmpeg {
+
+struct ffmpeg_error : virtual caspar_exception{};
+struct ffmpeg_user_error : virtual user_error {};
+struct averror_bsf_not_found : virtual ffmpeg_error{};
+struct averror_decoder_not_found : virtual ffmpeg_user_error {};
+struct averror_demuxer_not_found : virtual ffmpeg_user_error {};
+struct averror_encoder_not_found : virtual ffmpeg_user_error {};
+struct averror_eof : virtual ffmpeg_error{};
+struct averror_exit : virtual ffmpeg_error{};
+struct averror_filter_not_found : virtual ffmpeg_user_error {};
+struct averror_muxer_not_found : virtual ffmpeg_user_error {};
+struct averror_option_not_found : virtual ffmpeg_user_error {};
+struct averror_patchwelcome : virtual ffmpeg_error{};
+struct averror_protocol_not_found : virtual ffmpeg_user_error {};
+struct averror_stream_not_found : virtual ffmpeg_error{};
+struct averror_invalid_argument : virtual ffmpeg_user_error {};
+
+std::string av_error_str(int errn);
+
+void throw_on_ffmpeg_error(int ret, const char* source, const char* func, const char* local_func, const char* file, int line);
+void throw_on_ffmpeg_error(int ret, const std::wstring& source, const char* func, const char* local_func, const char* file, int 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; \
+ }()
+
+#define LOG_ON_ERROR2(call, source) \
+ [&]() -> int \
+ { \
+ int ret = -1;\
+ try{ \
+ ret = call; \
+ throw_on_ffmpeg_error(ret, source, THROW_ON_ERROR_STR(call), __FUNCTION__, __FILE__, __LINE__); \
+ return ret; \
+ }catch(...){CASPAR_LOG_CURRENT_EXCEPTION();} \
+ return ret; \
+ }()
+
+#define FF_RET(ret, func) \
+ caspar::ffmpeg::throw_on_ffmpeg_error(ret, L"", func, __FUNCTION__, __FILE__, __LINE__);
+
+#define FF(call) \
+ [&]() -> int \
+ { \
+ auto ret = call; \
+ caspar::ffmpeg::throw_on_ffmpeg_error(static_cast<int>(ret), L"", THROW_ON_ERROR_STR(call), __FUNCTION__, __FILE__, __LINE__); \
+ return ret; \
+ }()
+
+}}