Mlt Ref Counts and Playlist split/join
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 26 Aug 2004 15:06:37 +0000 (15:06 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 26 Aug 2004 15:06:37 +0000 (15:06 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt++@388 d19143bc-622f-0410-bfdd-b5b2a6649095

19 files changed:
mlt++/src/MltConsumer.cpp
mlt++/src/MltConsumer.h
mlt++/src/MltFilter.cpp
mlt++/src/MltFilter.h
mlt++/src/MltFilteredConsumer.cpp
mlt++/src/MltFilteredConsumer.h
mlt++/src/MltFrame.cpp
mlt++/src/MltFrame.h
mlt++/src/MltPlaylist.cpp
mlt++/src/MltPlaylist.h
mlt++/src/MltProducer.cpp
mlt++/src/MltProducer.h
mlt++/src/MltProperties.cpp
mlt++/src/MltProperties.h
mlt++/src/MltService.cpp
mlt++/src/MltService.h
mlt++/src/MltTransition.cpp
mlt++/src/MltTransition.h
mlt++/swig/perl/play.pl

index 6fdcbc2..c882d4b 100644 (file)
@@ -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( )
index fa43e10..eb12d68 100644 (file)
@@ -32,7 +32,6 @@ namespace Mlt
        class Consumer : public Service
        {
                private:
-                       bool destroy;
                        mlt_consumer instance;
                public:
                        Consumer( char *id, char *service = NULL );
index 9fa0439..7842f55 100644 (file)
@@ -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( )
index 0682210..b659965 100644 (file)
@@ -32,7 +32,6 @@ namespace Mlt
        class Filter : public Service
        {
                private:
-                       bool destroy;
                        mlt_filter instance;
                public:
                        Filter( char *id, char *service = NULL );
index 944281f..2bcf6b4 100644 (file)
@@ -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
index 0b6bca6..250c10d 100644 (file)
@@ -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 );
index 0595a68..59af257 100644 (file)
 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( )
index c5cd502..7cd2854 100644 (file)
@@ -31,7 +31,6 @@ namespace Mlt
        class Frame : public Properties
        {
                private:
-                       bool destroy;
                        mlt_frame instance;
                public:
                        Frame( mlt_frame frame );
index cace71a..15c27b3 100644 (file)
@@ -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 );
+}
index c9adcaa..2bab978 100644 (file)
@@ -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 );
        };
 }
 
index 5a536c7..4aaab48 100644 (file)
 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( )
index d2963d1..a07f091 100644 (file)
@@ -32,7 +32,6 @@ namespace Mlt
        class Producer : public Service
        {
                private:
-                       bool destroy;
                        mlt_producer instance;
                public:
                        Producer( );
index 40d7081..121ca15 100644 (file)
 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;
index 1734200..82eda22 100644 (file)
@@ -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 );
        };
 }
index c058c38..9aa8baf 100644 (file)
 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( )
index 3cff429..10ec563 100644 (file)
@@ -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( );
index 2456a78..4ef08a5 100644 (file)
@@ -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( )
index da430fc..6b3c769 100644 (file)
@@ -31,7 +31,6 @@ namespace Mlt
        class Transition : public Service
        {
                private:
-                       bool destroy;
                        mlt_transition instance;
                public:
                        Transition( char *id, char *arg = NULL );
index 1b2e5ac..b7c2469 100755 (executable)
@@ -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( );