Server shutdown state
[melted] / mlt++ / src / MltConsumer.cpp
index 6fdcbc2..0a0a402 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include "MltConsumer.h"
+#include "MltEvent.h"
 using namespace Mlt;
 
+Consumer::Consumer( ) :
+       instance( NULL )
+{
+       instance = mlt_factory_consumer( NULL, NULL );
+}
+
 Consumer::Consumer( char *id, char *arg ) :
-       destroy( true ),
        instance( NULL )
 {
-       if ( arg != NULL )
+       if ( id == NULL || arg != NULL )
        {
                instance = mlt_factory_consumer( id, arg );
        }
@@ -48,25 +54,31 @@ Consumer::Consumer( char *id, char *arg ) :
        }
 }
 
+Consumer::Consumer( Service &consumer ) :
+       instance( NULL )
+{
+       if ( consumer.type( ) == consumer_type )
+       {
+               instance = ( mlt_consumer )consumer.get_service( );
+               inc_ref( );
+       }
+}
+
 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( )
@@ -104,3 +116,14 @@ 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;
+}