X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_playlist.c;h=acf0fd26d0961324bd28cebeb521894f690551db;hb=51de85d7a61e44bde5395629af348d9ca96ee13b;hp=ff9e27386ba3ec2960a54e715934073b6061d919;hpb=1d46befd8150131541aa98e93573d5d6e54e9c3a;p=melted diff --git a/src/framework/mlt_playlist.c b/src/framework/mlt_playlist.c index ff9e273..acf0fd2 100644 --- a/src/framework/mlt_playlist.c +++ b/src/framework/mlt_playlist.c @@ -75,12 +75,19 @@ mlt_playlist mlt_playlist_init( ) // Initialise blank mlt_producer_init( &this->blank, NULL ); + mlt_properties_set( mlt_producer_properties( &this->blank ), "mlt_service", "blank" ); + mlt_properties_set( mlt_producer_properties( &this->blank ), "resource", "blank" ); // Indicate that this producer is a playlist mlt_properties_set_data( mlt_playlist_properties( this ), "playlist", this, 0, NULL, NULL ); // Specify the eof condition mlt_properties_set( mlt_playlist_properties( this ), "eof", "pause" ); + mlt_properties_set( mlt_playlist_properties( this ), "resource", "" ); + mlt_properties_set( mlt_playlist_properties( this ), "mlt_type", "mlt_producer" ); + + this->size = 10; + this->list = malloc( this->size * sizeof( playlist_entry * ) ); } return this; @@ -164,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; } @@ -175,6 +181,8 @@ static int mlt_playlist_virtual_append( mlt_playlist this, mlt_producer producer this->list[ this->count ]->frame_out = out; this->list[ this->count ]->frame_count = out - in + 1; + mlt_properties_set( mlt_producer_properties( producer ), "eof", "pause" ); + mlt_producer_set_speed( producer, 0 ); this->count ++; @@ -193,6 +201,8 @@ static mlt_producer mlt_playlist_virtual_seek( mlt_playlist this ) // Map playlist position to real producer in virtual playlist mlt_position position = mlt_producer_frame( &this->parent ); + mlt_position original = position; + // Total number of frames int64_t total = 0; @@ -235,10 +245,11 @@ static mlt_producer mlt_playlist_virtual_seek( mlt_playlist this ) { playlist_entry *entry = this->list[ this->count - 1 ]; mlt_producer this_producer = mlt_playlist_producer( this ); - mlt_producer_seek( this_producer, total - 1 - mlt_producer_get_in( this_producer ) ); + mlt_producer_seek( this_producer, original - 1 ); producer = entry->producer; mlt_producer_seek( producer, entry->frame_out ); mlt_producer_set_speed( this_producer, 0 ); + mlt_producer_set_speed( producer, 0 ); } else if ( !strcmp( eof, "loop" ) && total > 0 ) { @@ -344,7 +355,7 @@ mlt_producer mlt_playlist_current( mlt_playlist this ) mlt_position mlt_playlist_clip( mlt_playlist this, mlt_whence whence, int index ) { - int64_t position = 0; + mlt_position position = 0; int absolute_clip = index; int i = 0; @@ -377,6 +388,9 @@ mlt_position mlt_playlist_clip( mlt_playlist this, mlt_whence whence, int index return position; } +/** Get all the info about the clip specified. +*/ + int mlt_playlist_get_clip_info( mlt_playlist this, mlt_playlist_clip_info *info, int index ) { int error = index < 0 || index >= this->count; @@ -385,6 +399,7 @@ int mlt_playlist_get_clip_info( mlt_playlist this, mlt_playlist_clip_info *info, { mlt_producer producer = this->list[ index ]->producer; mlt_properties properties = mlt_producer_properties( producer ); + info->clip = index; info->producer = producer; info->start = mlt_playlist_clip( this, mlt_whence_relative_start, index ); info->resource = mlt_properties_get( properties, "resource" ); @@ -450,16 +465,110 @@ int mlt_playlist_blank( mlt_playlist this, mlt_position length ) int mlt_playlist_insert( mlt_playlist this, mlt_producer producer, int where, mlt_position in, mlt_position out ) { - return 0; + // Append to end + mlt_playlist_append_io( this, producer, in, out ); + + // Move to the position specified + return mlt_playlist_move( this, this->count - 1, where ); } +/** Remove an entry in the playlist. +*/ + int mlt_playlist_remove( mlt_playlist this, int where ) { + if ( this->count > 0 ) + { + // We need to know the current clip and the position within the playlist + int current = mlt_playlist_current_clip( this ); + mlt_position position = mlt_producer_position( mlt_playlist_producer( this ) ); + + // We need all the details about the clip we're removing + mlt_playlist_clip_info where_info; + + // Loop variable + int i = 0; + + // Make sure the clip to be removed is valid and correct if necessary + if ( where < 0 ) + where = 0; + if ( where >= this->count ) + where = this->count - 1; + + // Get the clip info of the clip to be removed + mlt_playlist_get_clip_info( this, &where_info, where ); + + // Reorganise the list + for ( i = where + 1; i < this->count; i ++ ) + this->list[ i - 1 ] = this->list[ i ]; + this->count --; + + // Correct position + if ( where == current ) + mlt_producer_seek( mlt_playlist_producer( this ), where_info.start ); + else if ( where < current && this->count > 0 ) + mlt_producer_seek( mlt_playlist_producer( this ), position - where_info.frame_count ); + else if ( this->count == 0 ) + mlt_producer_seek( mlt_playlist_producer( this ), 0 ); + } + return 0; } -int mlt_playlist_move( mlt_playlist this, int from, int to ) +/** Move an entry in the playlist. +*/ + +int mlt_playlist_move( mlt_playlist this, int src, int dest ) { + int i; + + /* We need to ensure that the requested indexes are valid and correct it as necessary */ + if ( src < 0 ) + src = 0; + if ( src >= this->count ) + src = this->count - 1; + + if ( dest < 0 ) + dest = 0; + if ( dest >= this->count ) + dest = this->count - 1; + + if ( src != dest && this->count > 1 ) + { + int current = mlt_playlist_current_clip( this ); + mlt_position position = mlt_producer_position( mlt_playlist_producer( this ) ); + playlist_entry *src_entry = NULL; + + // We need all the details about the current clip + mlt_playlist_clip_info current_info; + + mlt_playlist_get_clip_info( this, ¤t_info, current ); + position -= current_info.start; + + if ( current == src ) + current = dest; + else if ( current > src && current < dest ) + current ++; + else if ( current == dest ) + current = src; + + src_entry = this->list[ src ]; + if ( src > dest ) + { + for ( i = src; i > dest; i -- ) + this->list[ i ] = this->list[ i - 1 ]; + } + else + { + for ( i = src; i < dest; i ++ ) + this->list[ i ] = this->list[ i + 1 ]; + } + this->list[ dest ] = src_entry; + + mlt_playlist_get_clip_info( this, ¤t_info, current ); + mlt_producer_seek( mlt_playlist_producer( this ), current_info.start + position ); + } + return 0; } @@ -536,7 +645,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 ); }