X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fffmpeg%2Fffmpeg_error.h;h=0c70667b1f7cb75ca53bb1ec0f0000dd9d7cd2de;hb=ae40f3d47bad19078bf9f4f47057e623ad8a945f;hp=67e5163ee59071c28d5eba761aea17977455240b;hpb=d39590debe590a1d6846e0b67ccad0690ae8dc2c;p=casparcg diff --git a/modules/ffmpeg/ffmpeg_error.h b/modules/ffmpeg/ffmpeg_error.h index 67e5163ee..0c70667b1 100644 --- a/modules/ffmpeg/ffmpeg_error.h +++ b/modules/ffmpeg/ffmpeg_error.h @@ -1,57 +1,91 @@ -#pragma once - -#include - -#pragma warning(push, 1) - -extern "C" -{ -#include -} - -#pragma warning(pop) - -namespace caspar { - -struct ffmpeg_error : virtual caspar_exception{}; - -static std::string av_error_str(int errn) -{ - char buf[256]; - memset(buf, 0, 256); - if(av_strerror(errn, buf, 256) < 0) - return ""; - 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))); \ - } - -#define THROW_ON_ERROR_STR_(call) #call -#define THROW_ON_ERROR_STR(call) THROW_ON_ERROR_STR_(call) - -#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))); \ - } \ - return ret; \ - }(); - -} \ No newline at end of file +/* +* Copyright (c) 2011 Sveriges Television AB +* +* 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 . +* +* Author: Robert Nagy, ronag89@gmail.com +*/ + +#pragma once + +#include + +#include + +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(ret), L"", THROW_ON_ERROR_STR(call), __FUNCTION__, __FILE__, __LINE__); \ + return ret; \ + }() + +}}