From 5c5addb89f636e3f65255ab45ec1a5addb2fb243 Mon Sep 17 00:00:00 2001 From: Dan Dennedy Date: Sat, 23 Jun 2012 18:46:18 -0700 Subject: [PATCH] add support for time string to playlist blanks --- src/framework/mlt_playlist.c | 48 ++++++++++++++++++++++++++++---- src/framework/mlt_playlist.h | 4 ++- src/mlt++/MltPlaylist.cpp | 16 +++++++++-- src/mlt++/MltPlaylist.h | 5 +++- src/modules/core/producer_melt.c | 10 +++++-- src/modules/xml/producer_xml.c | 9 ++---- 6 files changed, 74 insertions(+), 18 deletions(-) diff --git a/src/framework/mlt_playlist.c b/src/framework/mlt_playlist.c index 356b0d79..324f6aad 100644 --- a/src/framework/mlt_playlist.c +++ b/src/framework/mlt_playlist.c @@ -102,6 +102,23 @@ mlt_playlist mlt_playlist_init( ) return self; } +/** Construct a playlist with a profile. + * + * Sets the resource property to "". + * Set the mlt_type to property to "mlt_producer". + * \public \memberof mlt_playlist_s + * \param profile the profile to use with the profile + * \return a new playlist + */ + +mlt_playlist mlt_playlist_new( mlt_profile profile ) +{ + mlt_playlist self = mlt_playlist_init(); + if ( self ) + mlt_properties_set_data( MLT_PLAYLIST_PROPERTIES( self ), "_profile", profile, 0, NULL, NULL ); + return self; +} + /** Get the producer associated to this playlist. * * \public \memberof mlt_playlist_s @@ -702,15 +719,36 @@ int mlt_playlist_append_io( mlt_playlist self, mlt_producer producer, mlt_positi * * \public \memberof mlt_playlist_s * \param self a playlist - * \param length the ending time of the blank entry, not its duration + * \param out the ending time of the blank entry, not its duration * \return true if there was an error */ -int mlt_playlist_blank( mlt_playlist self, mlt_position length ) +int mlt_playlist_blank( mlt_playlist self, mlt_position out ) { // Append to the virtual list - if (length >= 0) - return mlt_playlist_virtual_append( self, &self->blank, 0, length ); + if ( out >= 0 ) + return mlt_playlist_virtual_append( self, &self->blank, 0, out ); + else + return 1; +} + +/** Append a blank item to the playlist with duration as a time string. + * + * \public \memberof mlt_playlist_s + * \param self a playlist + * \param length the duration of the blank entry as a time string + * \return true if there was an error + */ + +int mlt_playlist_blank_time( mlt_playlist self, const char* length ) +{ + if ( self && length ) + { + mlt_properties properties = MLT_PLAYLIST_PROPERTIES( self ); + mlt_properties_set( properties , "_blank_time", length ); + mlt_position duration = mlt_properties_get_position( properties, "_blank_time" ); + return mlt_playlist_blank( self, duration - 1 ); + } else return 1; } @@ -1067,7 +1105,7 @@ int mlt_playlist_join( mlt_playlist self, int clip, int count, int merge ) if ( error == 0 ) { int i = clip; - mlt_playlist new_clip = mlt_playlist_init( ); + mlt_playlist new_clip = mlt_playlist_new( mlt_service_profile( MLT_PLAYLIST_SERVICE(self) ) ); mlt_events_block( MLT_PLAYLIST_PROPERTIES( self ), self ); if ( clip + count >= self->count ) count = self->count - clip - 1; diff --git a/src/framework/mlt_playlist.h b/src/framework/mlt_playlist.h index a6364316..ee5411b5 100644 --- a/src/framework/mlt_playlist.h +++ b/src/framework/mlt_playlist.h @@ -80,6 +80,7 @@ struct mlt_playlist_s #define MLT_PLAYLIST_PROPERTIES( playlist ) MLT_SERVICE_PROPERTIES( MLT_PLAYLIST_SERVICE( playlist ) ) extern mlt_playlist mlt_playlist_init( ); +extern mlt_playlist mlt_playlist_new( mlt_profile profile ); extern mlt_producer mlt_playlist_producer( mlt_playlist self ); extern mlt_service mlt_playlist_service( mlt_playlist self ); extern mlt_properties mlt_playlist_properties( mlt_playlist self ); @@ -87,7 +88,8 @@ extern int mlt_playlist_count( mlt_playlist self ); extern int mlt_playlist_clear( mlt_playlist self ); extern int mlt_playlist_append( mlt_playlist self, mlt_producer producer ); extern int mlt_playlist_append_io( mlt_playlist self, mlt_producer producer, mlt_position in, mlt_position out ); -extern int mlt_playlist_blank( mlt_playlist self, mlt_position length ); +extern int mlt_playlist_blank( mlt_playlist self, mlt_position out ); +extern int mlt_playlist_blank_time( mlt_playlist self, const char *length ); extern mlt_position mlt_playlist_clip( mlt_playlist self, mlt_whence whence, int index ); extern int mlt_playlist_current_clip( mlt_playlist self ); extern mlt_producer mlt_playlist_current( mlt_playlist self ); diff --git a/src/mlt++/MltPlaylist.cpp b/src/mlt++/MltPlaylist.cpp index a13faf35..557cd7d6 100644 --- a/src/mlt++/MltPlaylist.cpp +++ b/src/mlt++/MltPlaylist.cpp @@ -22,6 +22,7 @@ #include #include "MltPlaylist.h" #include "MltTransition.h" +#include "MltProfile.h" using namespace Mlt; ClipInfo::ClipInfo( ) : @@ -85,6 +86,12 @@ Playlist::Playlist( ) : instance = mlt_playlist_init( ); } +Playlist::Playlist( Profile& profile ) : + instance( NULL ) +{ + instance = mlt_playlist_new( profile.get_profile() ); +} + Playlist::Playlist( Service &producer ) : instance( NULL ) { @@ -138,9 +145,14 @@ int Playlist::append( Producer &producer, int in, int out ) return mlt_playlist_append_io( get_playlist( ), producer.get_producer( ), in, out ); } -int Playlist::blank( int length ) +int Playlist::blank( int out ) +{ + return mlt_playlist_blank( get_playlist( ), out ); +} + +int Playlist::blank( const char *length ) { - return mlt_playlist_blank( get_playlist( ), length ); + return mlt_playlist_blank_time( get_playlist( ), length ); } int Playlist::clip( mlt_whence whence, int index ) diff --git a/src/mlt++/MltPlaylist.h b/src/mlt++/MltPlaylist.h index 1a485032..7d032556 100644 --- a/src/mlt++/MltPlaylist.h +++ b/src/mlt++/MltPlaylist.h @@ -33,6 +33,7 @@ namespace Mlt class Service; class Playlist; class Transition; + class Profile; class MLTPP_DECLSPEC ClipInfo { @@ -60,6 +61,7 @@ namespace Mlt mlt_playlist instance; public: Playlist( ); + Playlist( Profile& profile ); Playlist( Service &playlist ); Playlist( Playlist &playlist ); Playlist( mlt_playlist playlist ); @@ -69,7 +71,8 @@ namespace Mlt int count( ); int clear( ); int append( Producer &producer, int in = -1, int out = -1 ); - int blank( int length ); + int blank( int out ); + int blank( const char *length ); int clip( mlt_whence whence, int index ); int current_clip( ); Producer *current( ); diff --git a/src/modules/core/producer_melt.c b/src/modules/core/producer_melt.c index 3c8368cb..47307f64 100644 --- a/src/modules/core/producer_melt.c +++ b/src/modules/core/producer_melt.c @@ -126,7 +126,7 @@ mlt_producer producer_melt_init( mlt_profile profile, mlt_service_type type, con int track = 0; mlt_producer producer = NULL; mlt_tractor mix = NULL; - mlt_playlist playlist = mlt_playlist_init( ); + mlt_playlist playlist = mlt_playlist_new( profile ); mlt_properties group = mlt_properties_new( ); mlt_tractor tractor = mlt_tractor_new( ); mlt_properties properties = MLT_TRACTOR_PROPERTIES( tractor ); @@ -373,7 +373,11 @@ mlt_producer producer_melt_init( mlt_profile profile, mlt_service_type type, con if ( producer != NULL && !mlt_producer_is_cut( producer ) ) mlt_playlist_append( playlist, producer ); producer = NULL; - mlt_playlist_blank( playlist, atof( argv[ ++ i ] ) ); + if ( strchr( argv[ i + 1 ], ':' ) ) + mlt_playlist_blank_time( playlist, argv[ ++ i ] ); + else + // support for legacy where plain int is an out point instead of length + mlt_playlist_blank( playlist, atof( argv[ ++ i ] ) ); } else if ( !strcmp( argv[ i ], "-track" ) || !strcmp( argv[ i ], "-null-track" ) || @@ -391,7 +395,7 @@ mlt_producer producer_melt_init( mlt_profile profile, mlt_service_type type, con { mlt_multitrack_connect( multitrack, MLT_PLAYLIST_PRODUCER( playlist ), track ++ ); track_service( field, playlist, ( mlt_destructor )mlt_playlist_close ); - playlist = mlt_playlist_init( ); + playlist = mlt_playlist_new( profile ); } if ( playlist != NULL ) { diff --git a/src/modules/xml/producer_xml.c b/src/modules/xml/producer_xml.c index 2b41e7a1..88d7eebc 100644 --- a/src/modules/xml/producer_xml.c +++ b/src/modules/xml/producer_xml.c @@ -466,7 +466,7 @@ static void on_end_multitrack( deserialise_context context, const xmlChar *name static void on_start_playlist( deserialise_context context, const xmlChar *name, const xmlChar **atts) { - mlt_playlist playlist = mlt_playlist_init( ); + mlt_playlist playlist = mlt_playlist_new( context->profile ); mlt_service service = MLT_PLAYLIST_SERVICE( playlist ); mlt_properties properties = MLT_SERVICE_PROPERTIES( service ); @@ -675,7 +675,6 @@ static void on_start_blank( deserialise_context context, const xmlChar *name, co // Get the playlist from the stack enum service_type type; mlt_service service = context_pop_service( context, &type ); - mlt_position length = 0; if ( type == mlt_playlist_type && service != NULL ) { @@ -684,14 +683,12 @@ static void on_start_blank( deserialise_context context, const xmlChar *name, co { if ( xmlStrcmp( atts[0], _x("length") ) == 0 ) { - length = atoll( _s(atts[1]) ); + // Append a blank to the playlist + mlt_playlist_blank_time( MLT_PLAYLIST( service ), _s(atts[1]) ); break; } } - // Append a blank to the playlist - mlt_playlist_blank( MLT_PLAYLIST( service ), length - 1 ); - // Push the playlist back onto the stack context_push_service( context, service, type ); } -- 2.39.2