Small modifications to allow seeking
[melted] / src / framework / mlt_playlist.c
index 928c76d..2b14358 100644 (file)
@@ -84,6 +84,10 @@ mlt_playlist mlt_playlist_init( )
                // Specify the eof condition
                mlt_properties_set( mlt_playlist_properties( this ), "eof", "pause" );
                mlt_properties_set( mlt_playlist_properties( this ), "resource", "<playlist>" );
+               mlt_properties_set( mlt_playlist_properties( this ), "mlt_type", "mlt_producer" );
+
+               this->size = 10;
+               this->list = malloc( this->size * sizeof( playlist_entry * ) );
        }
        
        return this;
@@ -167,8 +171,7 @@ static int mlt_playlist_virtual_append( mlt_playlist this, mlt_producer producer
        {
                int i;
                this->list = realloc( this->list, ( this->size + 10 ) * sizeof( playlist_entry * ) );
-               for ( i = this->size; i < this->size + 10; i ++ )
-                       this->list[ i ] = NULL;
+               for ( i = this->size; i < this->size + 10; i ++ ) this->list[ i ] = NULL;
                this->size += 10;
        }
 
@@ -190,10 +193,11 @@ static int mlt_playlist_virtual_append( mlt_playlist this, mlt_producer producer
 /** Seek in the virtual playlist.
 */
 
-static mlt_producer mlt_playlist_virtual_seek( mlt_playlist this )
+static mlt_service mlt_playlist_virtual_seek( mlt_playlist this )
 {
        // Default producer to blank
        mlt_producer producer = NULL;
+       mlt_service service = NULL;
 
        // Map playlist position to real producer in virtual playlist
        mlt_position position = mlt_producer_frame( &this->parent );
@@ -261,7 +265,14 @@ static mlt_producer mlt_playlist_virtual_seek( mlt_playlist this )
                producer = &this->blank;
        }
 
-       return producer;
+       if ( producer != NULL )
+       {
+               service = mlt_producer_service( producer );
+               while ( mlt_service_consumer( service ) != NULL )
+                       service = mlt_service_consumer( service );
+       }
+
+       return service;
 }
 
 /** Invoked when a producer indicates that it has prematurely reached its end.
@@ -406,6 +417,15 @@ int mlt_playlist_get_clip_info( mlt_playlist this, mlt_playlist_clip_info *info,
                info->length = mlt_producer_get_length( producer );
                info->fps = mlt_producer_get_fps( producer );
        }
+
+       // Determine the consuming filter service
+       if ( info->producer != NULL )
+       {
+               info->service = mlt_producer_service( info->producer );
+               while ( mlt_service_consumer( info->service ) != NULL )
+                       info->service = mlt_service_consumer( info->service );
+       }
+
        return error;
 }
 
@@ -609,10 +629,10 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
        mlt_playlist this = producer->child;
 
        // Get the real producer
-       mlt_producer real = mlt_playlist_virtual_seek( this );
+       mlt_service real = mlt_playlist_virtual_seek( this );
 
        // Get the frame
-       mlt_service_get_frame( mlt_producer_service( real ), frame, index );
+       mlt_service_get_frame( real, frame, index );
 
        // Check if we're at the end of the clip
        mlt_properties properties = mlt_frame_properties( *frame );
@@ -642,7 +662,11 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
 
 void mlt_playlist_close( mlt_playlist this )
 {
+       int i = 0;
        mlt_producer_close( &this->parent );
        mlt_producer_close( &this->blank );
+       for ( i = 0; i < this->count; i ++ )
+               free( this->list[ i ] );
+       free( this->list );
        free( this );
 }