4 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
6 * This file is part of CasparCG (www.casparcg.com).
8 * CasparCG is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * CasparCG is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
21 * Author: Robert Nagy, ronag89@gmail.com
23 #include "ffmpeg_error.h"
25 #include <common/utf.h>
26 #include <common/log.h>
28 #pragma warning(disable: 4146)
32 #include <libavutil/error.h>
35 namespace caspar { namespace ffmpeg {
37 std::string av_error_str(int errn)
41 if(av_strerror(errn, buf, 256) < 0)
43 return std::string(buf);
46 void throw_on_ffmpeg_error(int ret, const char* source, const char* func, const char* local_func, const char* file, int line)
53 case AVERROR_BSF_NOT_FOUND:
54 ::boost::exception_detail::throw_exception_(
55 averror_bsf_not_found()
56 << msg_info(av_error_str(ret))
57 << source_info(source)
58 << boost::errinfo_api_function(func)
59 << boost::errinfo_errno(AVUNERROR(ret))
60 << call_stack_info(caspar::get_call_stack())
61 << context_info(get_context()),
62 local_func, log::remove_source_prefix(file), line);
63 case AVERROR_DECODER_NOT_FOUND:
64 ::boost::exception_detail::throw_exception_(
65 averror_decoder_not_found()
66 << msg_info(av_error_str(ret))
67 << source_info(source)
68 << boost::errinfo_api_function(func)
69 << boost::errinfo_errno(AVUNERROR(ret))
70 << call_stack_info(caspar::get_call_stack())
71 << context_info(get_context()),
72 local_func, log::remove_source_prefix(file), line);
73 case AVERROR_DEMUXER_NOT_FOUND:
74 ::boost::exception_detail::throw_exception_(
75 averror_demuxer_not_found()
76 << msg_info(av_error_str(ret))
77 << source_info(source)
78 << boost::errinfo_api_function(func)
79 << boost::errinfo_errno(AVUNERROR(ret))
80 << call_stack_info(caspar::get_call_stack())
81 << context_info(get_context()),
82 local_func, log::remove_source_prefix(file), line);
83 case AVERROR_ENCODER_NOT_FOUND:
84 ::boost::exception_detail::throw_exception_(
85 averror_encoder_not_found()
86 << msg_info(av_error_str(ret))
87 << source_info(source)
88 << boost::errinfo_api_function(func)
89 << boost::errinfo_errno(AVUNERROR(ret))
90 << call_stack_info(caspar::get_call_stack())
91 << context_info(get_context()),
92 local_func, log::remove_source_prefix(file), line);
94 ::boost::exception_detail::throw_exception_(
96 << msg_info(av_error_str(ret))
97 << source_info(source)
98 << boost::errinfo_api_function(func)
99 << boost::errinfo_errno(AVUNERROR(ret))
100 << call_stack_info(caspar::get_call_stack())
101 << context_info(get_context()),
102 local_func, log::remove_source_prefix(file), line);
104 ::boost::exception_detail::throw_exception_(
106 << msg_info(av_error_str(ret))
107 << source_info(source)
108 << boost::errinfo_api_function(func)
109 << boost::errinfo_errno(AVUNERROR(ret))
110 << call_stack_info(caspar::get_call_stack())
111 << context_info(get_context()),
112 local_func, log::remove_source_prefix(file), line);
113 case AVERROR_FILTER_NOT_FOUND:
114 ::boost::exception_detail::throw_exception_(
115 averror_filter_not_found()
116 << msg_info(av_error_str(ret))
117 << source_info(source)
118 << boost::errinfo_api_function(func)
119 << boost::errinfo_errno(AVUNERROR(ret))
120 << call_stack_info(caspar::get_call_stack())
121 << context_info(get_context()),
122 local_func, log::remove_source_prefix(file), line);
123 case AVERROR_MUXER_NOT_FOUND:
124 ::boost::exception_detail::throw_exception_(
125 averror_muxer_not_found()
126 << msg_info(av_error_str(ret))
127 << source_info(source)
128 << boost::errinfo_api_function(func)
129 << boost::errinfo_errno(AVUNERROR(ret))
130 << call_stack_info(caspar::get_call_stack())
131 << context_info(get_context()),
132 local_func, log::remove_source_prefix(file), line);
133 case AVERROR_OPTION_NOT_FOUND:
134 ::boost::exception_detail::throw_exception_(
135 averror_option_not_found()
136 << msg_info(av_error_str(ret))
137 << source_info(source)
138 << boost::errinfo_api_function(func)
139 << boost::errinfo_errno(AVUNERROR(ret))
140 << call_stack_info(caspar::get_call_stack())
141 << context_info(get_context()),
142 local_func, log::remove_source_prefix(file), line);
143 case AVERROR_PATCHWELCOME:
144 ::boost::exception_detail::throw_exception_(
145 averror_patchwelcome()
146 << msg_info(av_error_str(ret))
147 << source_info(source)
148 << boost::errinfo_api_function(func)
149 << boost::errinfo_errno(AVUNERROR(ret))
150 << call_stack_info(caspar::get_call_stack())
151 << context_info(get_context()),
152 local_func, log::remove_source_prefix(file), line);
153 case AVERROR_PROTOCOL_NOT_FOUND:
154 ::boost::exception_detail::throw_exception_(
155 averror_protocol_not_found()
156 << msg_info(av_error_str(ret))
157 << source_info(source)
158 << boost::errinfo_api_function(func)
159 << boost::errinfo_errno(AVUNERROR(ret))
160 << call_stack_info(caspar::get_call_stack())
161 << context_info(get_context()),
162 local_func, log::remove_source_prefix(file), line);
163 case AVERROR_STREAM_NOT_FOUND:
164 ::boost::exception_detail::throw_exception_(
165 averror_stream_not_found()
166 << msg_info(av_error_str(ret))
167 << source_info(source)
168 << boost::errinfo_api_function(func)
169 << boost::errinfo_errno(AVUNERROR(ret))
170 << call_stack_info(caspar::get_call_stack())
171 << context_info(get_context()),
172 local_func, log::remove_source_prefix(file), line);
173 case AVUNERROR(EINVAL):
174 ::boost::exception_detail::throw_exception_(
175 averror_invalid_argument()
176 << msg_info("Invalid FFmpeg argument given")
177 << source_info(source)
178 << boost::errinfo_api_function(func)
179 << boost::errinfo_errno(AVUNERROR(ret))
180 << call_stack_info(caspar::get_call_stack())
181 << context_info(get_context()),
182 local_func, log::remove_source_prefix(file), line);
184 ::boost::exception_detail::throw_exception_(
186 << msg_info(av_error_str(ret))
187 << source_info(source)
188 << boost::errinfo_api_function(func)
189 << boost::errinfo_errno(AVUNERROR(ret))
190 << call_stack_info(caspar::get_call_stack())
191 << context_info(get_context()),
192 local_func, log::remove_source_prefix(file), line);
196 void throw_on_ffmpeg_error(int ret, const std::wstring& source, const char* func, const char* local_func, const char* file, int line)
198 throw_on_ffmpeg_error(ret, u8(source).c_str(), func, local_func, file, line);