* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#include <stdlib.h>
+#include <string.h>
#include "MltConsumer.h"
+#include "MltEvent.h"
+#include "MltProfile.h"
using namespace Mlt;
-mlt_service Consumer::get_service( )
+Consumer::Consumer( ) :
+ instance( NULL )
{
- return mlt_consumer_service( get_consumer( ) );
+ instance = mlt_factory_consumer( NULL, NULL, NULL );
}
-int Consumer::connect( Service &service )
+Consumer::Consumer( Profile& profile ) :
+ instance( NULL )
{
- return mlt_consumer_connect( get_consumer( ), service.get_service( ) );
+ instance = mlt_factory_consumer( profile.get_profile(), NULL, NULL );
}
-int Consumer::start( )
+Consumer::Consumer( Profile& profile, char *id, char *arg ) :
+ instance( NULL )
{
- return mlt_consumer_start( get_consumer( ) );
+ if ( id == NULL || arg != NULL )
+ {
+ instance = mlt_factory_consumer( profile.get_profile(), id, arg );
+ }
+ else
+ {
+ if ( strchr( id, ':' ) )
+ {
+ char *temp = strdup( id );
+ char *arg = strchr( temp, ':' ) + 1;
+ *( arg - 1 ) = '\0';
+ instance = mlt_factory_consumer( profile.get_profile(), temp, arg );
+ free( temp );
+ }
+ else
+ {
+ instance = mlt_factory_consumer( profile.get_profile(), id, NULL );
+ }
+ }
}
-int Consumer::stop( )
+Consumer::Consumer( Service &consumer ) :
+ instance( NULL )
{
- return mlt_consumer_stop( get_consumer( ) );
+ if ( consumer.type( ) == consumer_type )
+ {
+ instance = ( mlt_consumer )consumer.get_service( );
+ inc_ref( );
+ }
+}
+
+Consumer::Consumer( Consumer &consumer ) :
+ instance( consumer.get_consumer( ) )
+{
+ inc_ref( );
+}
+
+Consumer::Consumer( mlt_consumer consumer ) :
+ instance( consumer )
+{
+ inc_ref( );
}
-int Consumer::is_stopped( )
+Consumer::~Consumer( )
{
- return mlt_consumer_is_stopped( get_consumer( ) );
+ mlt_consumer_close( instance );
}
-mlt_consumer ConsumerInstance::get_consumer( )
+mlt_consumer Consumer::get_consumer( )
{
return instance;
}
-ConsumerInstance::ConsumerInstance( char *id, char *service ) :
- destroy( true ),
- instance( NULL )
+mlt_service Consumer::get_service( )
{
- instance = mlt_factory_consumer( id, service );
+ return mlt_consumer_service( get_consumer( ) );
}
-ConsumerInstance::ConsumerInstance( Consumer &consumer ) :
- destroy( false ),
- instance( consumer.get_consumer( ) )
+int Consumer::connect( Service &service )
{
+ return connect_producer( service );
}
-ConsumerInstance::ConsumerInstance( mlt_consumer consumer ) :
- destroy( false ),
- instance( consumer )
+int Consumer::start( )
+{
+ return mlt_consumer_start( get_consumer( ) );
+}
+
+void Consumer::purge( )
{
+ mlt_consumer_purge( get_consumer( ) );
}
-ConsumerInstance::~ConsumerInstance( )
+int Consumer::stop( )
{
- if ( destroy )
- mlt_consumer_close( instance );
+ return mlt_consumer_stop( get_consumer( ) );
}
+bool Consumer::is_stopped( )
+{
+ return mlt_consumer_is_stopped( get_consumer( ) ) != 0;
+}
+
+int Consumer::run( )
+{
+ int ret = start( );
+ if ( !is_stopped( ) )
+ {
+ Event *e = setup_wait_for( "consumer-stopped" );
+ wait_for( e );
+ delete e;
+ }
+ return ret;
+}