From: lilo_booter Date: Thu, 26 Aug 2004 15:06:37 +0000 (+0000) Subject: Mlt Ref Counts and Playlist split/join X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=8283ca2eb4e3b523e04a46578a19a985d3b2af3c;p=melted Mlt Ref Counts and Playlist split/join git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt++@388 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/mlt++/src/MltConsumer.cpp b/mlt++/src/MltConsumer.cpp index 6fdcbc2..c882d4b 100644 --- a/mlt++/src/MltConsumer.cpp +++ b/mlt++/src/MltConsumer.cpp @@ -24,7 +24,6 @@ using namespace Mlt; Consumer::Consumer( char *id, char *arg ) : - destroy( true ), instance( NULL ) { if ( arg != NULL ) @@ -49,24 +48,20 @@ Consumer::Consumer( char *id, char *arg ) : } Consumer::Consumer( Consumer &consumer ) : - destroy( false ), instance( consumer.get_consumer( ) ) { + inc_ref( ); } Consumer::Consumer( mlt_consumer consumer ) : - destroy( false ), instance( consumer ) { + inc_ref( ); } Consumer::~Consumer( ) { - if ( destroy ) - { - stop( ); - mlt_consumer_close( instance ); - } + mlt_consumer_close( instance ); } mlt_consumer Consumer::get_consumer( ) diff --git a/mlt++/src/MltConsumer.h b/mlt++/src/MltConsumer.h index fa43e10..eb12d68 100644 --- a/mlt++/src/MltConsumer.h +++ b/mlt++/src/MltConsumer.h @@ -32,7 +32,6 @@ namespace Mlt class Consumer : public Service { private: - bool destroy; mlt_consumer instance; public: Consumer( char *id, char *service = NULL ); diff --git a/mlt++/src/MltFilter.cpp b/mlt++/src/MltFilter.cpp index 9fa0439..7842f55 100644 --- a/mlt++/src/MltFilter.cpp +++ b/mlt++/src/MltFilter.cpp @@ -24,7 +24,6 @@ using namespace Mlt; Filter::Filter( char *id, char *arg ) : - destroy( true ), instance( NULL ) { if ( arg != NULL ) @@ -49,21 +48,20 @@ Filter::Filter( char *id, char *arg ) : } Filter::Filter( Filter &filter ) : - destroy( false ), instance( filter.get_filter( ) ) { + inc_ref( ); } Filter::Filter( mlt_filter filter ) : - destroy( false ), instance( filter ) { + inc_ref( ); } Filter::~Filter( ) { - if ( destroy ) - mlt_filter_close( instance ); + mlt_filter_close( instance ); } mlt_filter Filter::get_filter( ) diff --git a/mlt++/src/MltFilter.h b/mlt++/src/MltFilter.h index 0682210..b659965 100644 --- a/mlt++/src/MltFilter.h +++ b/mlt++/src/MltFilter.h @@ -32,7 +32,6 @@ namespace Mlt class Filter : public Service { private: - bool destroy; mlt_filter instance; public: Filter( char *id, char *service = NULL ); diff --git a/mlt++/src/MltFilteredConsumer.cpp b/mlt++/src/MltFilteredConsumer.cpp index 944281f..2bcf6b4 100644 --- a/mlt++/src/MltFilteredConsumer.cpp +++ b/mlt++/src/MltFilteredConsumer.cpp @@ -28,6 +28,13 @@ FilteredConsumer::FilteredConsumer( char *id, char *arg ) : first = new Service( *this ); } +FilteredConsumer::FilteredConsumer( Consumer &consumer ) : + Consumer( consumer ) +{ + // Create a reference to the first service + first = new Service( *this ); +} + FilteredConsumer::~FilteredConsumer( ) { // Delete the reference to the first service diff --git a/mlt++/src/MltFilteredConsumer.h b/mlt++/src/MltFilteredConsumer.h index 0b6bca6..250c10d 100644 --- a/mlt++/src/MltFilteredConsumer.h +++ b/mlt++/src/MltFilteredConsumer.h @@ -37,6 +37,7 @@ namespace Mlt Service *first; public: FilteredConsumer( char *id, char *arg = NULL ); + FilteredConsumer( Consumer &consumer ); virtual ~FilteredConsumer( ); int connect( Service &service ); int attach( Filter &filter ); diff --git a/mlt++/src/MltFrame.cpp b/mlt++/src/MltFrame.cpp index 0595a68..59af257 100644 --- a/mlt++/src/MltFrame.cpp +++ b/mlt++/src/MltFrame.cpp @@ -22,21 +22,19 @@ using namespace Mlt; Frame::Frame( mlt_frame frame ) : - destroy( true ), instance( frame ) { } Frame::Frame( Frame &frame ) : - destroy( false ), instance( frame.get_frame( ) ) { + inc_ref( ); } Frame::~Frame( ) { - if ( destroy ) - mlt_frame_close( instance ); + mlt_frame_close( instance ); } mlt_frame Frame::get_frame( ) diff --git a/mlt++/src/MltFrame.h b/mlt++/src/MltFrame.h index c5cd502..7cd2854 100644 --- a/mlt++/src/MltFrame.h +++ b/mlt++/src/MltFrame.h @@ -31,7 +31,6 @@ namespace Mlt class Frame : public Properties { private: - bool destroy; mlt_frame instance; public: Frame( mlt_frame frame ); diff --git a/mlt++/src/MltPlaylist.cpp b/mlt++/src/MltPlaylist.cpp index cace71a..15c27b3 100644 --- a/mlt++/src/MltPlaylist.cpp +++ b/mlt++/src/MltPlaylist.cpp @@ -45,28 +45,26 @@ ClipInfo::~ClipInfo( ) } Playlist::Playlist( ) : - destroy( true ), instance( NULL ) { instance = mlt_playlist_init( ); } Playlist::Playlist( Playlist &playlist ) : - destroy( false ), instance( playlist.get_playlist( ) ) { + inc_ref( ); } Playlist::Playlist( mlt_playlist playlist ) : - destroy( false ), instance( playlist ) { + inc_ref( ); } Playlist::~Playlist( ) { - if ( destroy ) - mlt_playlist_close( instance ); + mlt_playlist_close( instance ); } mlt_playlist Playlist::get_playlist( ) @@ -141,3 +139,12 @@ int Playlist::resize_clip( int clip, int in, int out ) return mlt_playlist_resize_clip( get_playlist( ), clip, in, out ); } +int Playlist::split( int clip, int position ) +{ + return mlt_playlist_split( get_playlist( ), clip, position ); +} + +int Playlist::join( int clip, int count, int merge ) +{ + return mlt_playlist_join( get_playlist( ), clip, count, merge ); +} diff --git a/mlt++/src/MltPlaylist.h b/mlt++/src/MltPlaylist.h index c9adcaa..2bab978 100644 --- a/mlt++/src/MltPlaylist.h +++ b/mlt++/src/MltPlaylist.h @@ -51,7 +51,6 @@ namespace Mlt class Playlist : public Producer { private: - bool destroy; mlt_playlist instance; public: Playlist( ); @@ -72,6 +71,8 @@ namespace Mlt int remove( int where ); int move( int from, int to ); int resize_clip( int clip, int in, int out ); + int split( int clip, int position ); + int join( int clip, int count = 1, int merge = 1 ); }; } diff --git a/mlt++/src/MltProducer.cpp b/mlt++/src/MltProducer.cpp index 5a536c7..4aaab48 100644 --- a/mlt++/src/MltProducer.cpp +++ b/mlt++/src/MltProducer.cpp @@ -22,13 +22,11 @@ using namespace Mlt; Producer::Producer( ) : - destroy( false ), instance( NULL ) { } Producer::Producer( char *id, char *service ) : - destroy( true ), instance( NULL ) { if ( id != NULL && service != NULL ) @@ -38,21 +36,20 @@ Producer::Producer( char *id, char *service ) : } Producer::Producer( mlt_producer producer ) : - destroy( false ), instance( producer ) { + inc_ref( ); } Producer::Producer( Producer &producer ) : - destroy( false ), instance( producer.get_producer( ) ) { + inc_ref( ); } Producer::~Producer( ) { - if ( destroy ) - mlt_producer_close( instance ); + mlt_producer_close( instance ); } mlt_producer Producer::get_producer( ) diff --git a/mlt++/src/MltProducer.h b/mlt++/src/MltProducer.h index d2963d1..a07f091 100644 --- a/mlt++/src/MltProducer.h +++ b/mlt++/src/MltProducer.h @@ -32,7 +32,6 @@ namespace Mlt class Producer : public Service { private: - bool destroy; mlt_producer instance; public: Producer( ); diff --git a/mlt++/src/MltProperties.cpp b/mlt++/src/MltProperties.cpp index 40d7081..121ca15 100644 --- a/mlt++/src/MltProperties.cpp +++ b/mlt++/src/MltProperties.cpp @@ -22,26 +22,31 @@ using namespace Mlt; Properties::Properties( ) : - destroy( true ), instance( NULL ) { instance = mlt_properties_new( ); } +Properties::Properties( bool dummy ) : + instance( NULL ) +{ +} + Properties::Properties( Properties &properties ) : - destroy( false ), instance( properties.get_properties( ) ) { + fprintf( stderr, "Incrementing ref count on properties #1\n" ); + inc_ref( ); } Properties::Properties( mlt_properties properties ) : - destroy( false ), instance( properties ) { + fprintf( stderr, "Incrementing ref count on properties #2\n" ); + inc_ref( ); } Properties::Properties( char *file ) : - destroy( true ), instance( NULL ) { instance = mlt_properties_load( file ); @@ -49,8 +54,7 @@ Properties::Properties( char *file ) : Properties::~Properties( ) { - if ( destroy ) - mlt_properties_close( instance ); + mlt_properties_close( instance ); } mlt_properties Properties::get_properties( ) @@ -58,6 +62,16 @@ mlt_properties Properties::get_properties( ) return instance; } +int Properties::inc_ref( ) +{ + return mlt_properties_inc_ref( get_properties( ) ); +} + +int Properties::dec_ref( ) +{ + return mlt_properties_dec_ref( get_properties( ) ); +} + bool Properties::is_valid( ) { return get_properties( ) != NULL; @@ -153,6 +167,11 @@ void Properties::dump( FILE *output ) mlt_properties_dump( get_properties( ), output ); } +void Properties::debug( char *title, FILE *output ) +{ + mlt_properties_debug( get_properties( ), title, output ); +} + int Properties::save( char *file ) { int error = 0; diff --git a/mlt++/src/MltProperties.h b/mlt++/src/MltProperties.h index 1734200..82eda22 100644 --- a/mlt++/src/MltProperties.h +++ b/mlt++/src/MltProperties.h @@ -32,16 +32,18 @@ namespace Mlt class Properties { private: - bool destroy; mlt_properties instance; protected: virtual mlt_properties get_properties( ); public: Properties( ); + Properties( bool dummy ); Properties( Properties &properties ); Properties( mlt_properties properties ); Properties( char *file ); virtual ~Properties( ); + int inc_ref( ); + int dec_ref( ); bool is_valid( ); int count( ); char *get( char *name ); @@ -61,6 +63,7 @@ namespace Mlt int inherit( Properties &that ); int rename( char *source, char *dest ); void dump( FILE *output = stderr ); + void debug( char *title = "Object", FILE *output = stderr ); int save( char *file ); }; } diff --git a/mlt++/src/MltService.cpp b/mlt++/src/MltService.cpp index c058c38..9aa8baf 100644 --- a/mlt++/src/MltService.cpp +++ b/mlt++/src/MltService.cpp @@ -22,18 +22,28 @@ using namespace Mlt; Service::Service( ) : + Properties( false ), instance( NULL ) { } Service::Service( Service &service ) : + Properties( false ), instance( service.get_service( ) ) { + inc_ref( ); } Service::Service( mlt_service service ) : + Properties( false ), instance( service ) { + inc_ref( ); +} + +Service::~Service( ) +{ + mlt_service_close( instance ); } mlt_service Service::get_service( ) diff --git a/mlt++/src/MltService.h b/mlt++/src/MltService.h index 3cff429..10ec563 100644 --- a/mlt++/src/MltService.h +++ b/mlt++/src/MltService.h @@ -39,6 +39,7 @@ namespace Mlt Service( ); Service( Service &service ); Service( mlt_service service ); + virtual ~Service( ); virtual mlt_service get_service( ); virtual mlt_service get_connection( ); mlt_properties get_properties( ); diff --git a/mlt++/src/MltTransition.cpp b/mlt++/src/MltTransition.cpp index 2456a78..4ef08a5 100644 --- a/mlt++/src/MltTransition.cpp +++ b/mlt++/src/MltTransition.cpp @@ -24,7 +24,6 @@ using namespace Mlt; Transition::Transition( char *id, char *arg ) : - destroy( true ), instance( NULL ) { if ( arg != NULL ) @@ -49,21 +48,20 @@ Transition::Transition( char *id, char *arg ) : } Transition::Transition( Transition &transition ) : - destroy( false ), instance( transition.get_transition( ) ) { + inc_ref( ); } Transition::Transition( mlt_transition transition ) : - destroy( false ), instance( transition ) { + inc_ref( ); } Transition::~Transition( ) { - if ( destroy ) - mlt_transition_close( instance ); + mlt_transition_close( instance ); } mlt_transition Transition::get_transition( ) diff --git a/mlt++/src/MltTransition.h b/mlt++/src/MltTransition.h index da430fc..6b3c769 100644 --- a/mlt++/src/MltTransition.h +++ b/mlt++/src/MltTransition.h @@ -31,7 +31,6 @@ namespace Mlt class Transition : public Service { private: - bool destroy; mlt_transition instance; public: Transition( char *id, char *arg = NULL ); diff --git a/mlt++/swig/perl/play.pl b/mlt++/swig/perl/play.pl index 1b2e5ac..b7c2469 100755 --- a/mlt++/swig/perl/play.pl +++ b/mlt++/swig/perl/play.pl @@ -15,7 +15,8 @@ if ( $p->is_valid( ) ) $p->set( "eof", "loop" ); # Create the consumer - $c = new mltpp::Consumer( "sdl" ); + $c = new mltpp::FilteredConsumer( "sdl" ); + $c->attach( new mltpp::Filter( "greyscale" ) ); # Turn of the default rescaling $c->set( "rescale", "none" ); @@ -30,9 +31,14 @@ if ( $p->is_valid( ) ) while ( !$c->is_stopped ) { sleep( 1 ); } + + $c->stop( ); + $c = undef; + $p = undef; } else { print "Unable to open $ARGV[0]\n"; } +mltpp::mlt_factory_close( );