]> git.sesse.net Git - mlt/blobdiff - src/modules/avformat/producer_avformat.c
Drop usage of av_demuxer_open() in avformat v53.
[mlt] / src / modules / avformat / producer_avformat.c
index 856634bbff771b79844cdbec646f5a0ca976f220..bdcc4656aaa4b4e072b5ac3dac1deb2e7d0f8660 100644 (file)
@@ -141,6 +141,7 @@ static void producer_set_up_video( producer_avformat self, mlt_frame frame );
 static void producer_set_up_audio( producer_avformat self, mlt_frame frame );
 static void apply_properties( void *obj, mlt_properties properties, int flags );
 static int video_codec_init( producer_avformat self, int index, mlt_properties properties );
+static void get_audio_streams_info( producer_avformat self );
 
 #ifdef VDPAU
 #include "vdpau.c"
@@ -193,9 +194,6 @@ mlt_producer producer_avformat_init( mlt_profile profile, const char *service, c
                                {
                                        // Close the file to release resources for large playlists - reopen later as needed
                                        avformat_lock();
-                                       if ( self->dummy_context )
-                                               av_close_input_file( self->dummy_context );
-                                       self->dummy_context = NULL;
                                        if ( self->audio_format )
                                                av_close_input_file( self->audio_format );
                                        self->audio_format = NULL;
@@ -203,14 +201,13 @@ mlt_producer producer_avformat_init( mlt_profile profile, const char *service, c
                                                av_close_input_file( self->video_format );
                                        self->video_format = NULL;
                                        avformat_unlock();
-
-                                       // Default the user-selectable indices from the auto-detected indices
-                                       mlt_properties_set_int( properties, "audio_index",  self->audio_index );
-                                       mlt_properties_set_int( properties, "video_index",  self->video_index );
                                }
                        }
                        if ( producer )
                        {
+                               // Default the user-selectable indices from the auto-detected indices
+                               mlt_properties_set_int( properties, "audio_index",  self->audio_index );
+                               mlt_properties_set_int( properties, "video_index",  self->video_index );
 #ifdef VDPAU
                                mlt_service_cache_set_size( MLT_PRODUCER_SERVICE(producer), "producer_avformat", 5 );
 #endif
@@ -544,7 +541,7 @@ static double get_aspect_ratio( mlt_properties properties, AVStream *stream, AVC
        return aspect_ratio;
 }
 
-static char* parse_url( mlt_profile profile, const char* URL, AVInputFormat **format, AVFormatParameters **parameters )
+static char* parse_url( mlt_profile profile, const char* URL, AVInputFormat **format, AVFormatParameters *params )
 {
        if ( !URL ) return NULL;
 
@@ -571,9 +568,6 @@ static char* parse_url( mlt_profile profile, const char* URL, AVInputFormat **fo
 
                if ( *format )
                {
-                       // Allocate params
-                       AVFormatParameters *params = *parameters = calloc( 1, sizeof( AVFormatParameters ) );
-
                        // These are required by video4linux2 (defaults)
                        params->width = profile->width;
                        params->height = profile->height;
@@ -671,7 +665,7 @@ static int get_basic_info( producer_avformat self, mlt_profile profile, const ch
        {
                // protocols can indicate if they support seeking
 #if LIBAVFORMAT_VERSION_MAJOR > 52
-               self->seekable = context->pb->seekable;
+               self->seekable = format->pb->seekable;
 #else
                URLContext *uc = url_fileno( format->pb );
                if ( uc )
@@ -737,33 +731,42 @@ static int producer_open( producer_avformat self, mlt_profile profile, const cha
 {
        // Return an error code (0 == no error)
        int error = 0;
+       mlt_properties properties = MLT_PRODUCER_PROPERTIES( self->parent );
 
        // Lock the service
        pthread_mutex_init( &self->audio_mutex, NULL );
        pthread_mutex_init( &self->video_mutex, NULL );
        pthread_mutex_init( &self->packets_mutex, NULL );
+       mlt_events_block( properties, self->parent );
        pthread_mutex_lock( &self->audio_mutex );
        pthread_mutex_lock( &self->video_mutex );
 
        // Parse URL
        AVInputFormat *format = NULL;
-       AVFormatParameters *params = NULL;
+       AVFormatParameters params;
+       memset( &params, 0, sizeof(params) );
        char *filename = parse_url( profile, URL, &format, &params );
 
        // Now attempt to open the file or device with filename
-       error = av_open_input_file( &self->video_format, filename, format, 0, params ) < 0;
+       error = av_open_input_file( &self->video_format, filename, format, 0, &params ) < 0;
        if ( error )
                // If the URL is a network stream URL, then we probably need to open with full URL
-               error = av_open_input_file( &self->video_format, URL, format, 0, params ) < 0;
+               error = av_open_input_file( &self->video_format, URL, format, 0, &params ) < 0;
 
-       // Cleanup AVFormatParameters
-       if ( params )
+       // Set MLT properties onto video AVFormatContext
+       if ( !error && self->video_format )
        {
-               if ( params->standard )
-                       free( (void*) params->standard );
-               free( params );
+               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
        }
 
+       // Cleanup AVFormatParameters
+       if ( params.standard )
+               free( (void*) params.standard );
+
        // If successful, then try to get additional info
        if ( !error )
        {
@@ -790,6 +793,11 @@ static int producer_open( producer_avformat self, mlt_profile profile, const cha
                                {
                                        // And open again for our audio context
                                        av_open_input_file( &self->audio_format, filename, NULL, 0, NULL );
+                                       apply_properties( self->audio_format, properties, AV_OPT_FLAG_DECODING_PARAM );
+#if LIBAVFORMAT_VERSION_MAJOR > 52
+                                       if ( self->audio_format->iformat && self->audio_format->iformat->priv_class && self->audio_format->priv_data )
+                                               apply_properties( self->audio_format->priv_data, properties, AV_OPT_FLAG_DECODING_PARAM );
+#endif
                                        av_find_stream_info( self->audio_format );
                                }
                                else
@@ -808,6 +816,8 @@ static int producer_open( producer_avformat self, mlt_profile profile, const cha
                                // Something has gone wrong
                                error = -1;
                        }
+                       if ( self->audio_format && !self->audio_streams )
+                               get_audio_streams_info( self );
                }
        }
        if ( filename )
@@ -818,9 +828,16 @@ static int producer_open( producer_avformat self, mlt_profile profile, const cha
                self->vpackets = mlt_deque_init();
        }
 
+       if ( self->dummy_context )
+       {
+               av_close_input_file( self->dummy_context );
+               self->dummy_context = NULL;
+       }
+
        // Unlock the service
        pthread_mutex_unlock( &self->audio_mutex );
        pthread_mutex_unlock( &self->video_mutex );
+       mlt_events_unblock( properties, self->parent );
 
        return error;
 }
@@ -848,24 +865,12 @@ static void reopen_video( producer_avformat self, mlt_producer producer )
        int audio_index = self->audio_index;
        int video_index = self->video_index;
 
-       mlt_events_block( properties, producer );
        pthread_mutex_unlock( &self->audio_mutex );
        pthread_mutex_unlock( &self->video_mutex );
        producer_open( self, mlt_service_profile( MLT_PRODUCER_SERVICE(producer) ),
                mlt_properties_get( properties, "resource" ) );
        pthread_mutex_lock( &self->video_mutex );
        pthread_mutex_lock( &self->audio_mutex );
-       if ( self->dummy_context )
-       {
-               av_close_input_file( self->dummy_context );
-               self->dummy_context = NULL;
-       }
-       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 )
@@ -1845,28 +1850,9 @@ static void producer_set_up_video( producer_avformat self, mlt_frame frame )
        // Reopen the file if necessary
        if ( !context && index > -1 )
        {
-               mlt_events_block( properties, producer );
                producer_open( self, mlt_service_profile( MLT_PRODUCER_SERVICE(producer) ),
                        mlt_properties_get( properties, "resource" ) );
                context = self->video_format;
-               if ( self->dummy_context )
-               {
-                       av_close_input_file( self->dummy_context );
-                       self->dummy_context = NULL;
-               }
-               mlt_events_unblock( properties, producer );
-               if ( self->audio_format && !self->audio_streams )
-                       get_audio_streams_info( self );
-
-               // 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
@@ -2417,18 +2403,9 @@ static void producer_set_up_audio( producer_avformat self, mlt_frame frame )
        // Reopen the file if necessary
        if ( !context && self->audio_index > -1 && index > -1 )
        {
-               mlt_events_block( properties, producer );
                producer_open( self, mlt_service_profile( MLT_PRODUCER_SERVICE(producer) ),
                        mlt_properties_get( properties, "resource" ) );
                context = self->audio_format;
-               if ( self->dummy_context )
-               {
-                       av_close_input_file( self->dummy_context );
-                       self->dummy_context = NULL;
-               }
-               mlt_events_unblock( properties, producer );
-               if ( self->audio_format )
-                       get_audio_streams_info( self );
        }
 
        // Exception handling for audio_index