X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_playlist.c;h=8cf433892d44816d290c1ee2fe95f9e671e6b3d3;hb=6c95a9df3eee556eb8375fdee25c1d5469642745;hp=7dbbd7b07c073792d7e6cccfb6f0c41014d7b101;hpb=f7e7842cf52946218db15c6a45958644a96248d6;p=melted diff --git a/src/framework/mlt_playlist.c b/src/framework/mlt_playlist.c index 7dbbd7b..8cf4338 100644 --- a/src/framework/mlt_playlist.c +++ b/src/framework/mlt_playlist.c @@ -1,7 +1,9 @@ -/* - * mlt_playlist.c -- playlist service class - * Copyright (C) 2003-2004 Ushodaya Enterprises Limited - * Author: Charles Yates +/** + * \file mlt_playlist.c + * \brief playlist service class + * + * Copyright (C) 2003-2008 Ushodaya Enterprises Limited + * \author Charles Yates * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,8 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "config.h" - #include "mlt_playlist.h" #include "mlt_tractor.h" #include "mlt_multitrack.h" @@ -31,7 +31,7 @@ #include #include -/** Virtual playlist entry. +/** \brief virtual playlist entry */ struct playlist_entry_s @@ -92,7 +92,7 @@ mlt_playlist mlt_playlist_init( ) this->size = 10; this->list = malloc( this->size * sizeof( playlist_entry * ) ); } - + return this; } @@ -134,28 +134,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 @@ -335,6 +338,27 @@ static mlt_service mlt_playlist_virtual_seek( mlt_playlist this, int *progressiv // Get the properties mlt_properties properties = MLT_PLAYLIST_PROPERTIES( this ); + // Automatically close previous producers if requested + if ( i > 1 // keep immediate previous in case app wants to get info about what just finished + && position < 2 // tolerate off-by-one error on going to next clip + && mlt_properties_get_int( properties, "autoclose" ) ) + { + int j; + // They might have jumped ahead! + for ( j = 0; j < i - 1; j++ ) + { + mlt_service_lock( MLT_PRODUCER_SERVICE( this->list[ j ]->producer ) ); + mlt_producer p = this->list[ j ]->producer; + if ( 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" + } + } + // Get the eof handling char *eof = mlt_properties_get( properties, "eof" ); @@ -499,7 +523,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 ) { @@ -571,7 +595,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. @@ -610,11 +637,11 @@ int mlt_playlist_remove( mlt_playlist this, int where ) // Loop variable int i = 0; - // Get the clip info + // Get the clip info mlt_playlist_get_clip_info( this, &where_info, where ); // Make sure the clip to be removed is valid and correct if necessary - if ( where < 0 ) + if ( where < 0 ) where = 0; if ( where >= this->count ) where = this->count - 1; @@ -637,7 +664,7 @@ int mlt_playlist_remove( mlt_playlist this, int where ) mlt_properties mix = mlt_properties_get_data( properties, "mix_out", NULL ); mlt_properties_set_data( mix, "mix_in", NULL, 0, NULL, NULL ); } - + if ( mlt_properties_ref_count( MLT_PRODUCER_PROPERTIES( entry->producer ) ) == 1 ) mlt_producer_clear( entry->producer ); } @@ -672,16 +699,16 @@ 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 ) + if ( src < 0 ) src = 0; if ( src >= this->count ) src = this->count - 1; - if ( dest < 0 ) + 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 ); @@ -1047,7 +1074,7 @@ int mlt_playlist_clip_is_mix( mlt_playlist this, int clip ) static int mlt_playlist_unmix( mlt_playlist this, int clip ) { - int error = ( clip < 0 || clip >= this->count ); + int error = ( clip < 0 || clip >= this->count ); // Ensure that the clip request is actually a mix if ( error == 0 ) @@ -1099,7 +1126,7 @@ static int mlt_playlist_unmix( mlt_playlist this, int clip ) static int mlt_playlist_resize_mix( mlt_playlist this, int clip, int in, int out ) { - int error = ( clip < 0 || clip >= this->count ); + int error = ( clip < 0 || clip >= this->count ); // Ensure that the clip request is actually a mix if ( error == 0 ) @@ -1299,10 +1326,10 @@ int mlt_playlist_insert_at( mlt_playlist this, mlt_position position, mlt_produc mlt_playlist_insert( this, producer, clip, -1, -1 ); ret = clip; } - else + else { if ( mode == 1 ) { - if ( position == info.start ) + if ( position == info.start ) mlt_playlist_remove( this, clip ); else mlt_playlist_blank( this, position - mlt_properties_get_int( properties, "length" ) - 1 ); @@ -1386,7 +1413,7 @@ int mlt_playlist_remove_region( mlt_playlist this, mlt_position position, int le length -= mlt_playlist_clip_length( this, index ); mlt_playlist_remove( this, index ); } - + mlt_playlist_consolidate_blanks( this, 0 ); mlt_events_unblock( properties, this ); mlt_playlist_virtual_refresh( this ); @@ -1413,8 +1440,8 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i // Check that we have a producer if ( producer == NULL ) { - *frame = mlt_frame_init( ); - return 0; + *frame = NULL; + return -1; } // Get this mlt_playlist @@ -1429,7 +1456,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i // Check that we have a producer if ( real == NULL ) { - *frame = mlt_frame_init( ); + *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) ); return 0; } @@ -1441,7 +1468,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i else { mlt_producer parent = mlt_producer_cut_parent( ( mlt_producer )real ); - *frame = mlt_frame_init( ); + *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( parent ) ); mlt_properties_set_int( MLT_FRAME_PROPERTIES( *frame ), "fx_cut", 1 ); mlt_frame_push_service( *frame, NULL ); mlt_frame_push_audio( *frame, NULL );