TuttleOFX  1
LibAV.cpp
Go to the documentation of this file.
00001 #include "LibAV.hpp"
00002 #include <iostream>
00003 #include <cstdio>
00004 
00005 namespace tuttle {
00006 namespace plugin {
00007 namespace av {
00008 
00009 bool LibAV::_hasBeenInit = globalInit( );
00010 
00011 const std::string LibAV::libavLogLevel_toString( int logLevel )
00012 {
00013         switch( logLevel )
00014         {
00015                 case AV_LOG_PANIC :
00016                         return "panic";
00017                 case AV_LOG_FATAL :
00018                         return "fatal";
00019                 case AV_LOG_ERROR :
00020                         return "error";
00021                 case AV_LOG_WARNING :
00022                         return "warning";
00023                 case AV_LOG_INFO :
00024                         return "info";
00025                 case AV_LOG_VERBOSE :
00026                         return "verbose";
00027                 case AV_LOG_DEBUG :
00028                         return "debug";
00029                 default:
00030                         return "unknown log level";
00031         }
00032 }
00033 
00034 void log_callback( void* /*ptr*/, int level, const char* format, va_list arglist )
00035 {
00036 #ifndef TUTTLE_PRODUCTION
00037                 const std::string logID = LibAV::libavLogLevel_toString( level );
00038 
00039                 std::cerr << "AV " << logID << ":\t";
00040                 vfprintf( stderr, format, arglist );
00041                 std::cerr << std::endl;
00042 #endif
00043 }
00044 
00045 bool LibAV::globalInit( )
00046 {
00047         av_register_all();
00048 #ifdef TUTTLE_PRODUCTION
00049         // av_log_set_level( AV_LOG_QUIET );
00050         av_log_set_level( AV_LOG_ERROR );
00051 #else
00052         av_log_set_level( AV_LOG_WARNING );
00053         //      av_log_set_level( AV_LOG_DEBUG );
00054 #endif
00055         av_log_set_callback( log_callback );
00056         return true;
00057 }
00058 
00059 #define CASE_RETURN_STRING( e ) case e: return # e
00060 
00061 const std::string LibAV::libavError_toString( int error )
00062 {
00063         switch( error )
00064         {
00065 #if LIBAVCODEC_VERSION_MAJOR > 52
00066                 case AVERROR_BSF_NOT_FOUND:
00067                         return "Bitstream filter not found";
00068                 case AVERROR_DECODER_NOT_FOUND:
00069                         return "Decoder not found";
00070                 case AVERROR_DEMUXER_NOT_FOUND:
00071                         return "Demuxer not found";
00072                 case AVERROR_ENCODER_NOT_FOUND:
00073                         return "Encoder not found";
00074                 case AVERROR_EXIT:
00075                         return "Immediate exit was requested; the called function should not be restarted";
00076                 case AVERROR_FILTER_NOT_FOUND:
00077                         return "Filter not found";
00078                 case AVERROR_MUXER_NOT_FOUND:
00079                         return "Muxer not found";
00080                 case AVERROR_OPTION_NOT_FOUND:
00081                         return "Option not found";
00082                 case AVERROR_PROTOCOL_NOT_FOUND:
00083                         return "Protocol not found";
00084                 case AVERROR_STREAM_NOT_FOUND:
00085                         return "Stream not found";
00086 #endif
00087                 case AVERROR_EOF:
00088                         return "End of file";
00089                 case AVERROR_INVALIDDATA:
00090                         return "Invalid data found when processing input";
00091                 case AVERROR_PATCHWELCOME:
00092                         return "Not yet implemented in libav, patches welcome";
00093                 default:
00094                         return "unknown error";
00095         }
00096 }
00097 
00098 const std::string LibAV::codecType_toString( const AVMediaType codec_type )
00099 {
00100         switch( codec_type )
00101         {
00102                 case AVMEDIA_TYPE_VIDEO:
00103                         return "AVMEDIA_TYPE_VIDEO";
00104                 case AVMEDIA_TYPE_AUDIO:
00105                         return "AVMEDIA_TYPE_AUDIO";
00106                 case AVMEDIA_TYPE_UNKNOWN:
00107                         return "AVMEDIA_TYPE_UNKNOWN";
00108                 case AVMEDIA_TYPE_DATA:
00109                         return "AVMEDIA_TYPE_DATA";
00110                 case AVMEDIA_TYPE_SUBTITLE:
00111                         return "AVMEDIA_TYPE_SUBTITLE";
00112                 case AVMEDIA_TYPE_ATTACHMENT:
00113                         return "AVMEDIA_TYPE_ATTACHMENT";
00114                 case AVMEDIA_TYPE_NB:
00115                         return "AVMEDIA_TYPE_NB";
00116         }
00117         return "CODEC_TYPE not handle.";
00118 }
00119 
00120 std::vector<AVPrivOption> LibAV::getAVOptions( const AVClass* av_class )
00121 {
00122         std::vector<AVPrivOption> list;
00123         
00124         const AVOption *opt= av_class->option;
00125 
00126         while( opt )
00127         {
00128                 if( opt->help )
00129                         std::cout << opt->name << ": " << opt->help <<  std::endl;
00130                 else
00131                         std::cout << opt->name << std::endl;
00132 
00133                 opt = av_opt_next( (void*)av_class, opt );
00134         }
00135         return list;
00136 }
00137 
00138 void LibAV::getPixelsFormatList( )
00139 {
00140         for( int pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++ )
00141         {
00142                 const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt];
00143                 if(!pix_desc->name)
00144                         continue;
00145                 /*printf("%c%c%c%c%c %-16s       %d            %2d\n",
00146                            sws_isSupportedInput (pix_fmt)      ? 'I' : '.',
00147                            sws_isSupportedOutput(pix_fmt)      ? 'O' : '.',
00148                            pix_desc->flags & PIX_FMT_HWACCEL   ? 'H' : '.',
00149                            pix_desc->flags & PIX_FMT_PAL       ? 'P' : '.',
00150                            pix_desc->flags & PIX_FMT_BITSTREAM ? 'B' : '.',
00151                            pix_desc->name,
00152                            pix_desc->nb_components,
00153                            av_get_bits_per_pixel(pix_desc));*/
00154         }
00155 }
00156 }
00157 }
00158 }
00159