]> git.sesse.net Git - casparcg/blob - modules/ffmpeg/ffmpeg_error.cpp
de51f14f65a718c3bfe932e1cd24019016459e6f
[casparcg] / modules / ffmpeg / ffmpeg_error.cpp
1 #include "StdAfx.h"
2
3 /*
4 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
5 *
6 * This file is part of CasparCG (www.casparcg.com).
7 *
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.
12 *
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.
17 *
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/>.
20 *
21 * Author: Robert Nagy, ronag89@gmail.com
22 */
23 #include "ffmpeg_error.h"
24
25 #include <common/utf.h>
26
27 #pragma warning(disable: 4146)
28
29 extern "C" 
30 {
31 #include <libavutil/error.h>
32 }
33
34 namespace caspar { namespace ffmpeg {
35         
36 std::string av_error_str(int errn)
37 {
38         char buf[256];
39         memset(buf, 0, 256);
40         if(av_strerror(errn, buf, 256) < 0)
41                 return "";
42         return std::string(buf);
43 }
44
45 void throw_on_ffmpeg_error(int ret, const char* source, const char* func, const char* local_func, const char* file, int line)
46 {
47         if(ret >= 0)
48                 return;
49
50         switch(ret)
51         {
52         case AVERROR_BSF_NOT_FOUND:
53                 ::boost::exception_detail::throw_exception_(averror_bsf_not_found()<<                                                                           
54                         msg_info(av_error_str(ret)) <<                                                  
55                         source_info(source) <<                                          
56                         boost::errinfo_api_function(func) <<                                    
57                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);  
58         case AVERROR_DECODER_NOT_FOUND:
59                 ::boost::exception_detail::throw_exception_(averror_decoder_not_found()<<                                                                               
60                         msg_info(av_error_str(ret)) <<                                                  
61                         source_info(source) <<                                          
62                         boost::errinfo_api_function(func) <<                                    
63                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);
64         case AVERROR_DEMUXER_NOT_FOUND:
65                 ::boost::exception_detail::throw_exception_(averror_demuxer_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)), local_func, file, line);
70         case AVERROR_ENCODER_NOT_FOUND:
71                 ::boost::exception_detail::throw_exception_(averror_encoder_not_found()<<                                                                               
72                         msg_info(av_error_str(ret)) <<                                                  
73                         source_info(source) <<                                          
74                         boost::errinfo_api_function(func) <<                                    
75                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);  
76         case AVERROR_EOF:       
77                 ::boost::exception_detail::throw_exception_(averror_eof()<<                                                                             
78                         msg_info(av_error_str(ret)) <<                                                  
79                         source_info(source) <<                                          
80                         boost::errinfo_api_function(func) <<                                    
81                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);
82         case AVERROR_EXIT:                              
83                 ::boost::exception_detail::throw_exception_(averror_exit()<<                                                                            
84                         msg_info(av_error_str(ret)) <<                                                  
85                         source_info(source) <<                                          
86                         boost::errinfo_api_function(func) <<                                    
87                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);
88         case AVERROR_FILTER_NOT_FOUND:                          
89                 ::boost::exception_detail::throw_exception_(averror_filter_not_found()<<                                                                                
90                         msg_info(av_error_str(ret)) <<                                                  
91                         source_info(source) <<                                          
92                         boost::errinfo_api_function(func) <<                                    
93                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);
94         case AVERROR_MUXER_NOT_FOUND:   
95                 ::boost::exception_detail::throw_exception_(averror_muxer_not_found()<<                                                                         
96                         msg_info(av_error_str(ret)) <<                                                  
97                         source_info(source) <<                                          
98                         boost::errinfo_api_function(func) <<                                    
99                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);
100         case AVERROR_OPTION_NOT_FOUND:  
101                 ::boost::exception_detail::throw_exception_(averror_option_not_found()<<                                                                                
102                         msg_info(av_error_str(ret)) <<                                                  
103                         source_info(source) <<                                          
104                         boost::errinfo_api_function(func) <<                                    
105                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);
106         case AVERROR_PATCHWELCOME:      
107                 ::boost::exception_detail::throw_exception_(averror_patchwelcome()<<                                                                            
108                         msg_info(av_error_str(ret)) <<                                                  
109                         source_info(source) <<                                          
110                         boost::errinfo_api_function(func) <<                                    
111                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);
112         case AVERROR_PROTOCOL_NOT_FOUND:        
113                 ::boost::exception_detail::throw_exception_(averror_protocol_not_found()<<                                                                              
114                         msg_info(av_error_str(ret)) <<                                                  
115                         source_info(source) <<                                          
116                         boost::errinfo_api_function(func) <<                                    
117                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);
118         case AVERROR_STREAM_NOT_FOUND:
119                 ::boost::exception_detail::throw_exception_(averror_stream_not_found()<<                                                                                
120                         msg_info(av_error_str(ret)) <<                                                  
121                         source_info(source) <<                                          
122                         boost::errinfo_api_function(func) <<                                    
123                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);
124         default:
125                 ::boost::exception_detail::throw_exception_(ffmpeg_error()<<                                                                            
126                         msg_info(av_error_str(ret)) <<                                                  
127                         source_info(source) <<                                          
128                         boost::errinfo_api_function(func) <<                                    
129                         boost::errinfo_errno(AVUNERROR(ret)), local_func, file, line);
130         }
131 }
132
133 void throw_on_ffmpeg_error(int ret, const std::wstring& source, const char* func, const char* local_func, const char* file, int line)
134 {
135         throw_on_ffmpeg_error(ret, u8(source).c_str(), func, local_func, file, line);
136 }
137
138 }}