]> git.sesse.net Git - mlt/commitdiff
Add support for new codec- and muxer-specific AVOptions.
authorDan Dennedy <dan@dennedy.org>
Sun, 1 May 2011 21:07:56 +0000 (14:07 -0700)
committerDan Dennedy <dan@dennedy.org>
Sun, 1 May 2011 21:07:56 +0000 (14:07 -0700)
src/modules/avformat/consumer_avformat.c
src/modules/avformat/factory.c
src/modules/avformat/producer_avformat.c

index 4f5c5d8747cf70f1af07b8ed98d217888cb0a052..a72169d930c438e43d901889e8b94f96811139d6 100644 (file)
@@ -400,11 +400,12 @@ static int consumer_is_stopped( mlt_consumer consumer )
 static void apply_properties( void *obj, mlt_properties properties, int flags, int alloc )
 {
        int i;
-       int count = mlt_properties_count( properties ); 
+       int count = mlt_properties_count( properties );
        for ( i = 0; i < count; i++ )
        {
                const char *opt_name = mlt_properties_get_name( properties, i );
                const AVOption *opt = av_find_opt( obj, opt_name, NULL, flags, flags );
+
                if ( opt != NULL )
 #if LIBAVCODEC_VERSION_INT >= ((52<<16)+(7<<8)+0)
                        av_set_string3( obj, opt_name, mlt_properties_get_value( properties, i), alloc, NULL );
@@ -500,7 +501,7 @@ static AVStream *add_audio_stream( mlt_consumer consumer, AVFormatContext *oc, i
        return st;
 }
 
-static int open_audio( AVFormatContext *oc, AVStream *st, int audio_outbuf_size, const char *codec_name )
+static int open_audio( mlt_properties properties, AVFormatContext *oc, AVStream *st, int audio_outbuf_size, const char *codec_name )
 {
        // We will return the audio input size from here
        int audio_input_frame_size = 0;
@@ -515,6 +516,21 @@ static int open_audio( AVFormatContext *oc, AVStream *st, int audio_outbuf_size,
        else
                codec = avcodec_find_encoder( c->codec_id );
 
+#if LIBAVCODEC_VERSION_MAJOR > 52
+       // Process properties as AVOptions on the AVCodec
+       if ( codec && codec->priv_class && c->priv_data )
+       {
+               char *apre = mlt_properties_get( properties, "apre" );
+               if ( apre )
+               {
+                       mlt_properties p = mlt_properties_load( apre );
+                       apply_properties( c->priv_data, p, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, 1 );
+                       mlt_properties_close( p );
+               }
+               apply_properties( c->priv_data, properties, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, 0 );
+       }
+#endif
+
        avformat_lock();
        
        // Continue if codec found and we can open it
@@ -859,7 +875,7 @@ static AVFrame *alloc_picture( int pix_fmt, int width, int height )
        return picture;
 }
        
-static int open_video(AVFormatContext *oc, AVStream *st, const char *codec_name)
+static int open_video( mlt_properties properties, AVFormatContext *oc, AVStream *st, const char *codec_name )
 {
        // Get the codec
        AVCodecContext *video_enc = st->codec;
@@ -871,6 +887,21 @@ static int open_video(AVFormatContext *oc, AVStream *st, const char *codec_name)
        else
                codec = avcodec_find_encoder( video_enc->codec_id );
 
+#if LIBAVCODEC_VERSION_MAJOR > 52
+       // Process properties as AVOptions on the AVCodec
+       if ( codec && codec->priv_class && video_enc->priv_data )
+       {
+               char *vpre = mlt_properties_get( properties, "vpre" );
+               if ( vpre )
+               {
+                       mlt_properties p = mlt_properties_load( vpre );
+                       apply_properties( video_enc->priv_data, p, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, 1 );
+                       mlt_properties_close( p );
+               }
+               apply_properties( video_enc->priv_data, properties, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, 0 );
+       }
+#endif
+
        if( codec && codec->pix_fmts )
        {
                const enum PixelFormat *p = codec->pix_fmts;
@@ -1178,15 +1209,23 @@ static void *consumer_thread( void *arg )
                {
                        mlt_properties p = mlt_properties_load( fpre );
                        apply_properties( oc, p, AV_OPT_FLAG_ENCODING_PARAM, 1 );
+#if LIBAVFORMAT_VERSION_MAJOR > 52
+                       if ( oc->oformat && oc->oformat->priv_class && oc->priv_data )
+                               apply_properties( oc->priv_data, p, AV_OPT_FLAG_ENCODING_PARAM, 1 );
+#endif
                        mlt_properties_close( p );
                }
                apply_properties( oc, properties, AV_OPT_FLAG_ENCODING_PARAM, 0 );
+#if LIBAVFORMAT_VERSION_MAJOR > 52
+               if ( oc->oformat && oc->oformat->priv_class && oc->priv_data )
+                       apply_properties( oc->priv_data, properties, AV_OPT_FLAG_ENCODING_PARAM, 1 );
+#endif
 
-               if ( video_st && !open_video( oc, video_st, vcodec? vcodec : NULL ) )
+               if ( video_st && !open_video( properties, oc, video_st, vcodec? vcodec : NULL ) )
                        video_st = NULL;
                for ( i = 0; i < MAX_AUDIO_STREAMS && audio_st[i]; i++ )
                {
-                       audio_input_frame_size = open_audio( oc, audio_st[i], audio_outbuf_size,
+                       audio_input_frame_size = open_audio( properties, oc, audio_st[i], audio_outbuf_size,
                                acodec? acodec : NULL );
                        if ( !audio_input_frame_size )
                                audio_st[i] = NULL;
index 030fe3da435566eaf56452bf174160813194c1d0..85921abeeb69a3440ddaa4efad1c6195752bb021 100644 (file)
@@ -135,7 +135,7 @@ static void *create_service( mlt_profile profile, mlt_service_type type, const c
        return NULL;
 }
 
-static void add_parameters( mlt_properties params, void *object, int req_flags, const char *unit )
+static void add_parameters( mlt_properties params, void *object, int req_flags, const char *unit, const char *subclass )
 {
        const AVOption *opt = NULL;
 
@@ -174,7 +174,19 @@ static void add_parameters( mlt_properties params, void *object, int req_flags,
 
                // Add the parameter metadata for this AVOption.
                mlt_properties_set( p, "identifier", opt->name );
-               mlt_properties_set( p, "description", opt->help );
+               if ( subclass )
+               {
+                       char *s = malloc( strlen( opt->help ) + strlen( subclass ) + 4 );
+                       strcpy( s, opt->help );
+                       strcat( s, " (" );
+                       strcat( s, subclass );
+                       strcat( s, ")" );
+                       mlt_properties_set( p, "description", s );
+               }
+               else
+                       mlt_properties_set( p, "description", opt->help );
+
+
         switch ( opt->type )
                {
                case FF_OPT_TYPE_FLAGS:
@@ -189,7 +201,9 @@ static void add_parameters( mlt_properties params, void *object, int req_flags,
                                        mlt_properties_set_int( p, "minimum", (int) opt->min );
                                if ( opt->max != INT_MAX )
                                        mlt_properties_set_int( p, "maximum", (int) opt->max );
-                               mlt_properties_set_int( p, "default", (int) opt->default_val );
+#if LIBAVUTIL_VERSION_MAJOR > 50
+                               mlt_properties_set_int( p, "default", (int) opt->default_val.dbl );
+#endif
                        }
                        else
                        {
@@ -204,6 +218,9 @@ static void add_parameters( mlt_properties params, void *object, int req_flags,
                                mlt_properties_set_int64( p, "minimum", (int64_t) opt->min );
                        if ( opt->max != INT64_MAX )
                        mlt_properties_set_int64( p, "maximum", (int64_t) opt->max );
+#if LIBAVUTIL_VERSION_MAJOR > 50
+                       mlt_properties_set_int64( p, "default", (int64_t) opt->default_val.dbl );
+#endif
                        break;
                case FF_OPT_TYPE_FLOAT:
                        mlt_properties_set( p, "type", "float" );
@@ -211,6 +228,9 @@ static void add_parameters( mlt_properties params, void *object, int req_flags,
                                mlt_properties_set_double( p, "minimum", opt->min );
                        if ( opt->max != FLT_MAX )
                                mlt_properties_set_double( p, "maximum", opt->max );
+#if LIBAVUTIL_VERSION_MAJOR > 50
+                       mlt_properties_set_double( p, "default", opt->default_val.dbl );
+#endif
                        break;
                case FF_OPT_TYPE_DOUBLE:
                        mlt_properties_set( p, "type", "float" );
@@ -219,9 +239,15 @@ static void add_parameters( mlt_properties params, void *object, int req_flags,
                                mlt_properties_set_double( p, "minimum", opt->min );
                        if ( opt->max != DBL_MAX )
                                mlt_properties_set_double( p, "maximum", opt->max );
+#if LIBAVUTIL_VERSION_MAJOR > 50
+                       mlt_properties_set_double( p, "default", opt->default_val.dbl );
+#endif
                        break;
                case FF_OPT_TYPE_STRING:
                        mlt_properties_set( p, "type", "string" );
+#if LIBAVUTIL_VERSION_MAJOR > 50
+                       mlt_properties_set( p, "default", opt->default_val.str );
+#endif
                        break;
                case FF_OPT_TYPE_RATIONAL:
                        mlt_properties_set( p, "type", "string" );
@@ -238,10 +264,13 @@ static void add_parameters( mlt_properties params, void *object, int req_flags,
                {
                        // Create a 'values' sequence.
                        mlt_properties values = mlt_properties_new();
-                       mlt_properties_set_data( p, "values", values, 0, (mlt_destructor) mlt_properties_close, NULL );
 
                        // Recurse to add constants in this group to the 'values' sequence.
-                       add_parameters( values, object, req_flags, opt->unit );
+                       add_parameters( values, object, req_flags, opt->unit, NULL );
+                       if ( mlt_properties_count( values ) )
+                               mlt_properties_set_data( p, "values", values, 0, (mlt_destructor) mlt_properties_close, NULL );
+                       else
+                               mlt_properties_close( values );
                }
        }
 }
@@ -281,8 +310,22 @@ static mlt_properties avformat_metadata( mlt_service_type type, const char *id,
                AVCodecContext *avcodec = avcodec_alloc_context();
                int flags = ( type == consumer_type )? AV_OPT_FLAG_ENCODING_PARAM : AV_OPT_FLAG_DECODING_PARAM;
 
-               add_parameters( params, avformat, flags, NULL );
-               add_parameters( params, avcodec, flags, NULL );
+               add_parameters( params, avformat, flags, NULL, NULL );
+#if LIBAVFORMAT_VERSION_MAJOR > 52
+               avformat_init();
+               AVOutputFormat *f = NULL;
+               while ( ( f = av_oformat_next( f ) ) )
+                       if ( f->priv_class )
+                               add_parameters( params, &f->priv_class, flags, NULL, f->name );
+#endif
+
+               add_parameters( params, avcodec, flags, NULL, NULL );
+#if LIBAVCODEC_VERSION_MAJOR > 52
+               AVCodec *c = NULL;
+               while ( ( c = av_codec_next( c ) ) )
+                       if ( c->priv_class )
+                               add_parameters( params, &c->priv_class, flags, NULL, c->name );
+#endif
 
                av_free( avformat );
                av_free( avcodec );
index d914dab077e965af934baaa7cd7f22d9aad3890c..8b1aca5e2f0a66f98d216ad98400aab75cf067a9 100644 (file)
@@ -815,6 +815,10 @@ void reopen_video( producer_avformat self, mlt_producer producer, mlt_properties
        }
        mlt_events_unblock( properties, producer );
        apply_properties( self->video_format, properties, AV_OPT_FLAG_DECODING_PARAM );
+#if LIBAVFORMAT_VERSION_MAJOR > 52
+       if ( self->video_format->iformat && self->video_format->iformat->priv_class && self->video_format->priv_data )
+               apply_properties( self->video_format->priv_data, properties, AV_OPT_FLAG_DECODING_PARAM );
+#endif
 
        self->audio_index = audio_index;
        if ( self->video_format && video_index > -1 )
@@ -1624,6 +1628,10 @@ static int video_codec_init( producer_avformat self, int index, mlt_properties p
 
                // Process properties as AVOptions
                apply_properties( codec_context, properties, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM );
+#if LIBAVCODEC_VERSION_MAJOR > 52
+               if ( codec->priv_class && codec_context->priv_data )
+                       apply_properties( codec_context->priv_data, properties, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM );
+#endif
 
                // Reset some image properties
                mlt_properties_set_int( properties, "width", self->video_codec->width );
@@ -1755,7 +1763,13 @@ static void producer_set_up_video( producer_avformat self, mlt_frame frame )
 
                // Process properties as AVOptions
                if ( context )
+               {
                        apply_properties( context, properties, AV_OPT_FLAG_DECODING_PARAM );
+#if LIBAVFORMAT_VERSION_MAJOR > 52
+                       if ( context->iformat && context->iformat->priv_class && context->priv_data )
+                               apply_properties( context->priv_data, properties, AV_OPT_FLAG_DECODING_PARAM );
+#endif
+               }
        }
 
        // Exception handling for video_index
@@ -2214,6 +2228,10 @@ static int audio_codec_init( producer_avformat self, int index, mlt_properties p
 
                // Process properties as AVOptions
                apply_properties( codec_context, properties, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM );
+#if LIBAVCODEC_VERSION_MAJOR > 52
+               if ( codec && codec->priv_class && codec_context->priv_data )
+                       apply_properties( codec_context->priv_data, properties, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM );
+#endif
        }
        return self->audio_codec[ index ] && self->audio_index > -1;
 }