producer_avformat.c: rework the aspect ratio detection to try to fetch it from the...
[melted] / src / framework / mlt_playlist.c
index 4183506..27c4443 100644 (file)
@@ -132,28 +132,31 @@ static int mlt_playlist_virtual_refresh( mlt_playlist this )
        {
                // Get the producer
                mlt_producer producer = this->list[ i ]->producer;
-               int current_length = mlt_producer_get_out( producer ) - mlt_producer_get_in( producer ) + 1;
-
-               // Check if the length of the producer has changed
-               if ( this->list[ i ]->frame_in != mlt_producer_get_in( producer ) ||
-                        this->list[ i ]->frame_out != mlt_producer_get_out( producer ) )
+               if ( producer )
                {
-                       // This clip should be removed...
-                       if ( current_length < 1 )
-                       {
-                               this->list[ i ]->frame_in = 0;
-                               this->list[ i ]->frame_out = -1;
-                               this->list[ i ]->frame_count = 0;
-                       }
-                       else 
+                       int current_length = mlt_producer_get_out( producer ) - mlt_producer_get_in( producer ) + 1;
+       
+                       // Check if the length of the producer has changed
+                       if ( this->list[ i ]->frame_in != mlt_producer_get_in( producer ) ||
+                               this->list[ i ]->frame_out != mlt_producer_get_out( producer ) )
                        {
-                               this->list[ i ]->frame_in = mlt_producer_get_in( producer );
-                               this->list[ i ]->frame_out = mlt_producer_get_out( producer );
-                               this->list[ i ]->frame_count = current_length;
+                               // This clip should be removed...
+                               if ( current_length < 1 )
+                               {
+                                       this->list[ i ]->frame_in = 0;
+                                       this->list[ i ]->frame_out = -1;
+                                       this->list[ i ]->frame_count = 0;
+                               }
+                               else 
+                               {
+                                       this->list[ i ]->frame_in = mlt_producer_get_in( producer );
+                                       this->list[ i ]->frame_out = mlt_producer_get_out( producer );
+                                       this->list[ i ]->frame_count = current_length;
+                               }
+       
+                               // Update the producer_length
+                               this->list[ i ]->producer_length = current_length;
                        }
-
-                       // Update the producer_length
-                       this->list[ i ]->producer_length = current_length;
                }
 
                // Calculate the frame_count
@@ -346,20 +349,11 @@ static mlt_service mlt_playlist_virtual_seek( mlt_playlist this, int *progressiv
                        mlt_producer p = this->list[ j ]->producer;
                        if ( p )
                        {
-                               mlt_properties p_properties = MLT_PRODUCER_PROPERTIES( p );
-                               // Prevent closing previously autoclosed to maintain integrity of references
-                               if ( ! mlt_properties_get_int( p_properties, "_autoclosed" ) )
-                               {
-                                       mlt_properties_set_int( p_properties, "_autoclosed", 1 );
-                                       mlt_service_unlock( MLT_PRODUCER_SERVICE( p ) );
-                                       mlt_producer_close( p );
-                                       this->list[ j ]->producer = NULL;
-                               }
-                               else
-                               {
-                                       mlt_service_unlock( MLT_PRODUCER_SERVICE( p ) );
-                               }
+                               this->list[ j ]->producer = NULL;
+                               mlt_service_unlock( MLT_PRODUCER_SERVICE( p ) );
+                               mlt_producer_close( p );
                        }
+                       // If p is null, the lock will not have been "taken"
                }
        }
 
@@ -527,7 +521,7 @@ mlt_position mlt_playlist_clip( mlt_playlist this, mlt_whence whence, int index
 
 int mlt_playlist_get_clip_info( mlt_playlist this, mlt_playlist_clip_info *info, int index )
 {
-       int error = index < 0 || index >= this->count;
+       int error = index < 0 || index >= this->count || this->list[ index ]->producer == NULL;
        memset( info, 0, sizeof( mlt_playlist_clip_info ) );
        if ( !error )
        {
@@ -599,7 +593,10 @@ int mlt_playlist_append_io( mlt_playlist this, mlt_producer producer, mlt_positi
 int mlt_playlist_blank( mlt_playlist this, mlt_position length )
 {
        // Append to the virtual list
-       return mlt_playlist_virtual_append( this, &this->blank, 0, length );
+       if (length >= 0) 
+               return mlt_playlist_virtual_append( this, &this->blank, 0, length );
+       else 
+               return 1;
 }
 
 /** Insert a producer into the playlist.