filter_sox.c: bugfix (2040035) segfault with libsox 14.1.0
[melted] / src / modules / avformat / producer_avformat.c
index 5d4a55f..909d424 100644 (file)
@@ -74,11 +74,13 @@ mlt_producer producer_avformat_init( mlt_profile profile, char *file )
                                mlt_producer_close( this );
                                this = NULL;
                        }
-
-                       // Close the file to release resources for large playlists - reopen later as needed
-                       mlt_properties_set_data( properties, "dummy_context", NULL, 0, NULL, NULL );
-                       mlt_properties_set_data( properties, "audio_context", NULL, 0, NULL, NULL );
-                       mlt_properties_set_data( properties, "video_context", NULL, 0, NULL, NULL );
+                       else
+                       {
+                               // Close the file to release resources for large playlists - reopen later as needed
+                               mlt_properties_set_data( properties, "dummy_context", NULL, 0, NULL, NULL );
+                               mlt_properties_set_data( properties, "audio_context", NULL, 0, NULL, NULL );
+                               mlt_properties_set_data( properties, "video_context", NULL, 0, NULL, NULL );
+                       }
                }
        }
 
@@ -290,7 +292,7 @@ static int producer_open( mlt_producer this, mlt_profile profile, char *file )
                                mlt_properties_set_double( properties, "_start_time", context->start_time );
                        
                        // Check if we're seekable (something funny about mpeg here :-/)
-                       if ( strcmp( file, "pipe:" ) && strncmp( file, "http://", 6 ) )
+                       if ( strcmp( file, "pipe:" ) && strncmp( file, "http://", 6 )  && strncmp( file, "udp:", 4 )  && strncmp( file, "tcp:", 4 ) && strncmp( file, "rtsp:", 5 )  && strncmp( file, "rtp:", 4 ) )
                        {
                                mlt_properties_set_int( properties, "seekable", av_seek_frame( context, -1, mlt_properties_get_double( properties, "_start_time" ), AVSEEK_FLAG_BACKWARD ) >= 0 );
                                mlt_properties_set_data( properties, "dummy_context", context, 0, producer_file_close, NULL );
@@ -331,7 +333,7 @@ static int producer_open( mlt_producer this, mlt_profile profile, char *file )
                                mlt_properties_set_int(properties, "meta.attr.track.markup", context->track );
                        
                        // We're going to cheat here - for a/v files, we will have two contexts (reasoning will be clear later)
-                       if ( av == 0 && !av_bypass && audio_index != -1 && video_index != -1 )
+                       if ( av == 0 && audio_index != -1 && video_index != -1 )
                        {
                                // We'll use the open one as our video_context
                                mlt_properties_set_data( properties, "video_context", context, 0, producer_file_close, NULL );
@@ -680,20 +682,22 @@ static void producer_set_up_video( mlt_producer this, mlt_frame frame )
 
        // Fetch the video_context
        AVFormatContext *context = mlt_properties_get_data( properties, "video_context", NULL );
-       if ( !context )
+
+       // Get the video_index
+       int index = mlt_properties_get_int( properties, "video_index" );
+
+       // Reopen the file if necessary
+       if ( !context && index != -1 )
        {
-               // Reopen the file
                mlt_events_block( properties, this );
                producer_open( this, mlt_service_profile( MLT_PRODUCER_SERVICE(this) ),
                        mlt_properties_get( properties, "resource" ) );
                context = mlt_properties_get_data( properties, "video_context", NULL );
+               index = mlt_properties_get_int( properties, "video_index" );
                mlt_properties_set_data( properties, "dummy_context", NULL, 0, NULL, NULL );
                mlt_events_unblock( properties, this );
        }
 
-       // Get the video_index
-       int index = mlt_properties_get_int( properties, "video_index" );
-
        // Get the frame properties
        mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame );
 
@@ -985,9 +989,12 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
                                }
 
                                // If we're behind, ignore this packet
-                               float current_pts = av_q2d( stream->time_base ) * pkt.pts;
-                               if ( seekable && ( !ignore && current_pts <= ( real_timecode - 0.02 ) ) )
-                                       ignore = 1;
+                               if ( pkt.pts >= 0 )
+                               {
+                                       float current_pts = av_q2d( stream->time_base ) * pkt.pts;
+                                       if ( seekable && ( !ignore && current_pts <= ( real_timecode - 0.02 ) ) )
+                                               ignore = 1;
+                               }
                        }
 
                        // We're finished with this packet regardless
@@ -1042,6 +1049,18 @@ static void producer_set_up_audio( mlt_producer this, mlt_frame frame )
        // Get the audio_index
        int index = mlt_properties_get_int( properties, "audio_index" );
 
+       // Reopen the file if necessary
+       if ( !context && index != -1 )
+       {
+               mlt_events_block( properties, this );
+               producer_open( this, mlt_service_profile( MLT_PRODUCER_SERVICE(this) ),
+                       mlt_properties_get( properties, "resource" ) );
+               context = mlt_properties_get_data( properties, "audio_context", NULL );
+               index = mlt_properties_get_int( properties, "audio_index" );
+               mlt_properties_set_data( properties, "dummy_context", NULL, 0, NULL, NULL );
+               mlt_events_unblock( properties, this );
+       }
+
        // Deal with audio context
        if ( context != NULL && index != -1 )
        {