TuttleOFX  1
AVReaderPluginFactory.cpp
Go to the documentation of this file.
00001 #include "AVReaderPluginFactory.hpp"
00002 #include "AVReaderPlugin.hpp"
00003 #include "AVReaderDefinitions.hpp"
00004 
00005 #include <libav/LibAVOptionsFactory.hpp>
00006 
00007 #include <tuttle/plugin/context/ReaderPluginFactory.hpp>
00008 
00009 #include <boost/algorithm/string/join.hpp>
00010 #include <boost/algorithm/string/split.hpp>
00011 #include <boost/algorithm/string/classification.hpp>
00012 
00013 #include <string>
00014 #include <vector>
00015 
00016 namespace tuttle {
00017 namespace plugin {
00018 namespace av {
00019 namespace reader {
00020 
00021 /**
00022  * @brief Function called to describe the plugin main features.
00023  * @param[in, out]   desc     Effect descriptor
00024  */
00025 void AVReaderPluginFactory::describe( OFX::ImageEffectDescriptor& desc )
00026 {
00027         desc.setLabels(
00028                 "TuttleAVReader",
00029                 "AVReader",
00030                 "Audio Video reader" );
00031         desc.setPluginGrouping( "tuttle/image/io" );
00032 
00033         std::vector<std::string> supportedExtensions;
00034         {
00035                 AVInputFormat* iFormat = av_iformat_next( NULL );
00036                 while( iFormat != NULL )
00037                 {
00038                         if( iFormat->extensions != NULL )
00039                         {
00040                                 using namespace boost::algorithm;
00041                                 const std::string extStr( iFormat->extensions );
00042                                 std::vector<std::string> exts;
00043                                 split( exts, extStr, is_any_of(",") );
00044                                 supportedExtensions.insert( supportedExtensions.end(), exts.begin(), exts.end() );
00045                         }
00046                         iFormat = av_iformat_next( iFormat );
00047                 }
00048         }
00049         
00050         desc.setDescription( "Video reader based on LibAV library\n\n"
00051                         "Supported extensions: \n" +
00052                         boost::algorithm::join( supportedExtensions, ", " )
00053                 );
00054         
00055         // add the supported contexts
00056         desc.addSupportedContext( OFX::eContextReader );
00057         desc.addSupportedContext( OFX::eContextGeneral );
00058 
00059         // add supported pixel depths
00060         desc.addSupportedBitDepth( OFX::eBitDepthUByte );
00061         desc.addSupportedBitDepth( OFX::eBitDepthUShort );
00062         desc.addSupportedBitDepth( OFX::eBitDepthFloat );
00063 
00064         // add supported extensions
00065         desc.addSupportedExtensions( supportedExtensions );
00066         
00067         // plugin flags
00068         desc.setRenderThreadSafety( OFX::eRenderInstanceSafe );
00069         desc.setHostFrameThreading( false );
00070         desc.setSupportsMultiResolution( false );
00071         desc.setSupportsMultipleClipDepths( true );
00072         desc.setSupportsTiles( kSupportTiles );
00073 }
00074 
00075 /**
00076  * @brief Function called to describe the plugin controls and features.
00077  * @param[in, out]   desc       Effect descriptor
00078  * @param[in]        context    Application context
00079  */
00080 void AVReaderPluginFactory::describeInContext( OFX::ImageEffectDescriptor& desc,
00081                                                    OFX::EContext               context )
00082 {
00083         // Create the mandated output clip
00084         OFX::ClipDescriptor* dstClip = desc.defineClip( kOfxImageEffectOutputClipName );
00085         dstClip->addSupportedComponent( OFX::ePixelComponentRGBA );
00086         dstClip->addSupportedComponent( OFX::ePixelComponentRGB );
00087         dstClip->addSupportedComponent( OFX::ePixelComponentAlpha );
00088         dstClip->setSupportsTiles( kSupportTiles );
00089 
00090         describeReaderParamsInContext( desc, context );
00091         
00092         // Groups
00093         OFX::GroupParamDescriptor* formatGroup = desc.defineGroupParam( kParamFormatGroup );
00094         OFX::GroupParamDescriptor* videoGroup  = desc.defineGroupParam( kParamVideoGroup );
00095         OFX::GroupParamDescriptor* audioGroup  = desc.defineGroupParam( kParamAudioGroup );
00096         OFX::GroupParamDescriptor* metaGroup   = desc.defineGroupParam( kParamMetaGroup );
00097         
00098         formatGroup->setLabel( "Format" );
00099         videoGroup->setLabel( "Video" );
00100         audioGroup->setLabel( "Audio" );
00101         metaGroup->setLabel( "Metadata" );
00102         
00103         formatGroup->setAsTab( );
00104         videoGroup->setAsTab( );
00105         audioGroup->setAsTab( );
00106         metaGroup->setAsTab( );
00107         
00108         /// FORMAT PARAMETERS
00109         AVFormatContext* avFormatContext;
00110         avFormatContext = avformat_alloc_context();
00111         addOptionsFromAVOption( desc, formatGroup, (void*)avFormatContext, AV_OPT_FLAG_DECODING_PARAM, 0 );
00112         avformat_free_context( avFormatContext );
00113         
00114         /// VIDEO PARAMETERS
00115         AVCodecContext* avCodecContext;
00116 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 8, 0 )
00117         avCodecContext = avcodec_alloc_context();
00118         // deprecated in the same version
00119         //avCodecContext = avcodec_alloc_context2( AVMEDIA_TYPE_UNKNOWN );
00120 #else
00121         AVCodec* avCodec = NULL;
00122         avCodecContext = avcodec_alloc_context3( avCodec );
00123 #endif
00124         
00125         addOptionsFromAVOption( desc, videoGroup, (void*)avCodecContext, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM, 0 );
00126         
00127         OFX::BooleanParamDescriptor* useCustomSAR = desc.defineBooleanParam( kParamUseCustomSAR );
00128         useCustomSAR->setLabel( "Override SAR" );
00129         useCustomSAR->setDefault( false );
00130         useCustomSAR->setHint( "Override the file SAR (Storage Aspect Ratio) with a custom SAR value." );
00131 
00132         OFX::DoubleParamDescriptor* customSAR = desc.defineDoubleParam( kParamCustomSAR );
00133         customSAR->setLabel( "Custom SAR" );
00134         customSAR->setDefault( 1.0 );
00135         customSAR->setHint( "Choose a custom value to override the file SAR (Storage Aspect Ratio)." );
00136 }
00137 
00138 /**
00139  * @brief Function called to create a plugin effect instance
00140  * @param[in] handle  effect handle
00141  * @param[in] context    Application context
00142  * @return  plugin instance
00143  */
00144 OFX::ImageEffect* AVReaderPluginFactory::createInstance( OfxImageEffectHandle handle,
00145                                                          OFX::EContext        context )
00146 {
00147         return new AVReaderPlugin( handle );
00148 }
00149 
00150 }
00151 }
00152 }
00153 }