Filtered producers and consumers
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Tue, 17 Aug 2004 15:12:14 +0000 (15:12 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Tue, 17 Aug 2004 15:12:14 +0000 (15:12 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt++@374 d19143bc-622f-0410-bfdd-b5b2a6649095

mlt++/src/Makefile
mlt++/src/Mlt.h
mlt++/src/MltConsumer.cpp
mlt++/src/MltConsumer.h
mlt++/src/MltFilteredConsumer.cpp [new file with mode: 0644]
mlt++/src/MltFilteredConsumer.h [new file with mode: 0644]
mlt++/src/MltFilteredProducer.cpp [new file with mode: 0644]
mlt++/src/MltFilteredProducer.h [new file with mode: 0644]
mlt++/src/MltService.cpp
mlt++/src/MltService.h
mlt++/swig/mltpp.i

index 5a061f5..36e7021 100644 (file)
@@ -8,6 +8,8 @@ TARGET = libmlt++.so
 OBJS = MltConsumer.o \
           MltFactory.o \
           MltFilter.o \
+          MltFilteredConsumer.o \
+          MltFilteredProducer.o \
           MltFrame.o \
           MltPlaylist.o \
           MltProducer.o \
index 22aaf73..60998ca 100644 (file)
@@ -24,6 +24,8 @@
 #include "MltConsumer.h"
 #include "MltFactory.h"
 #include "MltFilter.h"
+#include "MltFilteredConsumer.h"
+#include "MltFilteredProducer.h"
 #include "MltFrame.h"
 #include "MltPlaylist.h"
 #include "MltProducer.h"
index fb80505..a8624cc 100644 (file)
@@ -43,7 +43,10 @@ Consumer::Consumer( mlt_consumer consumer ) :
 Consumer::~Consumer( )
 {
        if ( destroy )
+       {
+               stop( );
                mlt_consumer_close( instance );
+       }
 }
 
 mlt_consumer Consumer::get_consumer( )
@@ -58,7 +61,7 @@ mlt_service Consumer::get_service( )
 
 int Consumer::connect( Service &service )
 {
-       return mlt_consumer_connect( get_consumer( ), service.get_service( ) );
+       return connect_producer( service );
 }
 
 int Consumer::start( )
@@ -71,9 +74,8 @@ int Consumer::stop( )
        return mlt_consumer_stop( get_consumer( ) );
 }
 
-int Consumer::is_stopped( )
+bool Consumer::is_stopped( )
 {
-       return mlt_consumer_is_stopped( get_consumer( ) );
+       return mlt_consumer_is_stopped( get_consumer( ) ) != 0;
 }
 
-
index 0bd2ea1..e1eb187 100644 (file)
@@ -41,10 +41,10 @@ namespace Mlt
                        virtual ~Consumer( );
                        virtual mlt_consumer get_consumer( );
                        mlt_service get_service( );
-                       int connect( Service &service );
+                       virtual int connect( Service &service );
                        int start( );
                        int stop( );
-                       int is_stopped( );
+                       bool is_stopped( );
        };
 }
 
diff --git a/mlt++/src/MltFilteredConsumer.cpp b/mlt++/src/MltFilteredConsumer.cpp
new file mode 100644 (file)
index 0000000..944281f
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * MltFilteredConsumer.cpp - MLT Wrapper
+ * Copyright (C) 2004-2005 Charles Yates
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "MltFilteredConsumer.h"
+using namespace Mlt;
+
+FilteredConsumer::FilteredConsumer( char *id, char *arg ) :
+       Consumer( id, arg )
+{
+       // Create a reference to the first service
+       first = new Service( *this );
+}
+
+FilteredConsumer::~FilteredConsumer( )
+{
+       // Delete the reference to the first service
+       delete first;
+}
+
+int FilteredConsumer::connect( Service &service )
+{
+       // All producers must connect to the first service, hence the use of the virtual here
+       return first->connect_producer( service );
+}
+
+int FilteredConsumer::attach( Filter &filter )
+{
+       int error = 0;
+       if ( filter.is_valid( ) )
+       {
+               Service *producer = first->producer( );
+               error = filter.connect( *producer );
+               if ( error == 0 )
+               {
+                       first->connect_producer( filter );
+                       delete first;
+                       first = new Service( filter );
+               }
+               delete producer;
+       }
+       else
+       {
+               error = 1;
+       }
+       return error;
+}
+
+int FilteredConsumer::detach( Filter &filter )
+{
+       if ( filter.is_valid( ) )
+       {
+               Service *it = new Service( *first );
+               while ( it->is_valid( ) && it->get_service( ) != filter.get_service( ) )
+               {
+                       Service *consumer = it->consumer( );
+                       delete it;
+                       it = consumer;
+               }
+               if ( it->get_service( ) == filter.get_service( ) )
+               {
+                       Service *producer = it->producer( );
+                       Service *consumer = it->consumer( );
+                       consumer->connect_producer( *producer );
+                       Service dummy( NULL );
+                       it->connect_producer( dummy );
+                       if ( first->get_service( ) == it->get_service( ) )
+                       {
+                               delete first;
+                               first = new Service( *consumer );
+                       }
+               }
+               delete it;
+       }
+       return 0;
+}
+
diff --git a/mlt++/src/MltFilteredConsumer.h b/mlt++/src/MltFilteredConsumer.h
new file mode 100644 (file)
index 0000000..0b6bca6
--- /dev/null
@@ -0,0 +1,48 @@
+/**
+ * MltFilteredConsumer.h - MLT Wrapper
+ * Copyright (C) 2004-2005 Charles Yates
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _MLTPP_FILTERED_CONSUMER_H_
+#define _MLTPP_FILTERED_CONSUMER_H_
+
+#include "MltConsumer.h"
+#include "MltFilter.h"
+#include "MltService.h"
+
+namespace Mlt
+{
+       class Consumer;
+       class Service;
+       class Filter;
+
+       class FilteredConsumer : public Consumer
+       {
+               private:
+                       Service *first;
+               public:
+                       FilteredConsumer( char *id, char *arg = NULL );
+                       virtual ~FilteredConsumer( );
+                       int connect( Service &service );
+                       int attach( Filter &filter );
+                       int detach( Filter &filter );
+       };
+}
+
+#endif
+
diff --git a/mlt++/src/MltFilteredProducer.cpp b/mlt++/src/MltFilteredProducer.cpp
new file mode 100644 (file)
index 0000000..559edac
--- /dev/null
@@ -0,0 +1,91 @@
+/**
+ * MltFilteredProducer.cpp - MLT Wrapper
+ * Copyright (C) 2004-2005 Charles Yates
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "MltFilteredProducer.h"
+using namespace Mlt;
+
+FilteredProducer::FilteredProducer( char *id, char *arg ) :
+       Producer( id, arg )
+{
+       // Create a reference to the last service
+       last = new Service( *this );
+}
+
+FilteredProducer::~FilteredProducer( )
+{
+       // Delete the reference to the last service
+       delete last;
+}
+
+mlt_service FilteredProducer::get_connection( )
+{
+       return last->get_service( );
+}
+
+int FilteredProducer::attach( Filter &filter )
+{
+       int error = 0;
+       if ( filter.is_valid( ) )
+       {
+               Service *consumer = last->consumer( );
+               filter.connect_producer( *last );
+               if ( consumer->is_valid( ) )
+                       consumer->connect_producer( filter );
+               delete consumer;
+               delete last;
+               last = new Service( filter );
+       }
+       else
+       {
+               error = 1;
+       }
+       return error;
+}
+
+int FilteredProducer::detach( Filter &filter )
+{
+       if ( filter.is_valid( ) )
+       {
+               Service *it = new Service( *last );
+               while ( it->is_valid( ) && it->get_service( ) != filter.get_service( ) )
+               {
+                       Service *producer = it->producer( );
+                       delete it;
+                       it = producer;
+               }
+               if ( it->get_service( ) == filter.get_service( ) )
+               {
+                       Service *producer = it->producer( );
+                       Service *consumer = it->consumer( );
+                       if ( consumer->is_valid( ) )
+                               consumer->connect_producer( *producer );
+                       Producer dummy( "colour" );
+                       dummy.connect_producer( *it );
+                       if ( last->get_service( ) == it->get_service( ) )
+                       {
+                               delete last;
+                               last = new Service( *producer );
+                       }
+               }
+               delete it;
+       }
+       return 0;
+}
+
diff --git a/mlt++/src/MltFilteredProducer.h b/mlt++/src/MltFilteredProducer.h
new file mode 100644 (file)
index 0000000..f4eafe4
--- /dev/null
@@ -0,0 +1,48 @@
+/**
+ * MltFilteredProducer.h - MLT Wrapper
+ * Copyright (C) 2004-2005 Charles Yates
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _MLTPP_FILTERED_PRODUCER_H_
+#define _MLTPP_FILTERED_PRODUCER_H_
+
+#include "MltProducer.h"
+#include "MltFilter.h"
+#include "MltService.h"
+
+namespace Mlt
+{
+       class Producer;
+       class Service;
+       class Filter;
+
+       class FilteredProducer : public Producer
+       {
+               private:
+                       Service *last;
+               public:
+                       FilteredProducer( char *id, char *arg = NULL );
+                       virtual ~FilteredProducer( );
+                       mlt_service get_connection( );
+                       int attach( Filter &filter );
+                       int detach( Filter &filter );
+       };
+}
+
+#endif
+
index 61034b8..4e70a01 100644 (file)
@@ -41,6 +41,11 @@ mlt_service Service::get_service( )
        return instance;
 }
 
+mlt_service Service::get_connection( )
+{
+       return get_service( );
+}
+
 mlt_properties Service::get_properties( )
 {
        return mlt_service_properties( get_service( ) );
@@ -48,7 +53,7 @@ mlt_properties Service::get_properties( )
 
 int Service::connect_producer( Service &producer, int index )
 {
-       return mlt_service_connect_producer( get_service( ), producer.get_service( ), index );
+       return mlt_service_connect_producer( get_service( ), producer.get_connection( ), index );
 }
 
 Service *Service::producer( )
index ab863c1..3cff429 100644 (file)
@@ -40,6 +40,7 @@ namespace Mlt
                        Service( Service &service );
                        Service( mlt_service service );
                        virtual mlt_service get_service( );
+                       virtual mlt_service get_connection( );
                        mlt_properties get_properties( );
                        int connect_producer( Service &producer, int index = 0 );
                        Service *consumer( );
index de601d5..31f0b39 100644 (file)
@@ -24,8 +24,6 @@
 #include <mlt++/Mlt.h>
 %}
 
-%typedef int mlt_position;
-
 /** These methods return objects which should be gc'd.
  */
 
@@ -44,6 +42,8 @@ namespace Mlt {
 /** Classes to wrap.
  */
 
+%include <framework/mlt_types.h>
+%include <MltFactory.h>
 %include <MltProperties.h>
 %include <MltFrame.h>
 %include <MltService.h>
@@ -51,5 +51,6 @@ namespace Mlt {
 %include <MltPlaylist.h>
 %include <MltConsumer.h>
 %include <MltFilter.h>
-%include <MltFactory.h>
+%include <MltFilteredConsumer.h>
+%include <MltFilteredProducer.h>