From: lilo_booter Date: Sun, 7 Nov 2004 14:12:52 +0000 (+0000) Subject: Simplified playlist access X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=02a17f9f66f0829ce95782096bcc528d6f250a4a;p=melted Simplified playlist access git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@510 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/src/framework/mlt_playlist.c b/src/framework/mlt_playlist.c index 6ebf37a..ddcc28f 100644 --- a/src/framework/mlt_playlist.c +++ b/src/framework/mlt_playlist.c @@ -286,52 +286,59 @@ static int mlt_playlist_virtual_append( mlt_playlist this, mlt_producer source, return mlt_playlist_virtual_refresh( this ); } -/** Seek in the virtual playlist. -*/ - -static mlt_service mlt_playlist_virtual_seek( mlt_playlist this, int *progressive ) +static mlt_producer mlt_playlist_locate( mlt_playlist this, mlt_position *position, int *clip, int *total ) { - // Default producer to blank + // Default producer to NULL mlt_producer producer = NULL; - // 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; - - // Get the properties - mlt_properties properties = mlt_playlist_properties( this ); - - // Get the eof handling - char *eof = mlt_properties_get( properties, "eof" ); - - // Index for the main loop - int i = 0; - // Loop for each producer until found - for ( i = 0; i < this->count; i ++ ) + for ( *clip = 0; *clip < this->count; *clip += 1 ) { // Increment the total - total += this->list[ i ]->frame_count; + *total += this->list[ *clip ]->frame_count; // Check if the position indicates that we have found the clip // Note that 0 length clips get skipped automatically - if ( position < this->list[ i ]->frame_count ) + if ( *position < this->list[ *clip ]->frame_count ) { // Found it, now break - producer = this->list[ i ]->producer; + producer = this->list[ *clip ]->producer; break; } else { // Decrement position by length of this entry - position -= this->list[ i ]->frame_count; + *position -= this->list[ *clip ]->frame_count; } } + return producer; +} + +/** Seek in the virtual playlist. +*/ + +static mlt_service mlt_playlist_virtual_seek( mlt_playlist this, int *progressive ) +{ + // Map playlist position to real producer in virtual playlist + mlt_position position = mlt_producer_frame( &this->parent ); + + // Keep the original position since we change it while iterating through the list + mlt_position original = position; + + // Clip index and total + int i = 0; + int total = 0; + + // Locate the producer for the position + mlt_producer producer = mlt_playlist_locate( this, &position, &i, &total ); + + // Get the properties + mlt_properties properties = mlt_playlist_properties( this ); + + // Get the eof handling + char *eof = mlt_properties_get( properties, "eof" ); + // Seek in real producer to relative position if ( producer != NULL ) { @@ -932,7 +939,7 @@ int mlt_playlist_mix_add( mlt_playlist this, int clip, mlt_transition transition return error; } -/** Return the clip at the position. +/** Return the clip at the clip index. */ mlt_producer mlt_playlist_get_clip( mlt_playlist this, int clip ) @@ -942,6 +949,25 @@ mlt_producer mlt_playlist_get_clip( mlt_playlist this, int clip ) return NULL; } +/** Return the clip at the specified position. +*/ + +mlt_producer mlt_playlist_get_clip_at( mlt_playlist this, int position ) +{ + int index = 0, total = 0; + return mlt_playlist_locate( this, &position, &index, &total ); +} + +/** Return the clip index of the specified position. +*/ + +int mlt_playlist_get_clip_index_at( mlt_playlist this, int position ) +{ + int index = 0, total = 0; + mlt_playlist_locate( this, &position, &index, &total ); + return index; +} + /** Determine if the clip is a mix. */ diff --git a/src/framework/mlt_playlist.h b/src/framework/mlt_playlist.h index a7dd3f2..50b236d 100644 --- a/src/framework/mlt_playlist.h +++ b/src/framework/mlt_playlist.h @@ -68,6 +68,8 @@ extern int mlt_playlist_join( mlt_playlist self, int clip, int count, int merge extern int mlt_playlist_mix( mlt_playlist self, int clip, int length, mlt_transition transition ); extern int mlt_playlist_mix_add( mlt_playlist self, int clip, mlt_transition transition ); extern mlt_producer mlt_playlist_get_clip( mlt_playlist self, int clip ); +extern mlt_producer mlt_playlist_get_clip_at( mlt_playlist self, int position ); +extern int mlt_playlist_get_clip_index_at( mlt_playlist self, int position ); extern int mlt_playlist_clip_is_mix( mlt_playlist self, int clip ); extern void mlt_playlist_close( mlt_playlist self );