Producer p( "pango:" );
p.set( "text", "Hello World" );
Consumer c( "sdl" );
+ Event *e = Consumer.setup_wait_for( "consumer-stopped" );
c.connect( p );
c.start( );
- struct timespec tm = { 1, 0 };
- while ( !c.is_stopped( ) )
- nanosleep( &tm, NULL );
+ c.wait_for( e );
+ delete e;
return 0;
}
typically, applications don't wait around for the consumer to be stopped in
the manner shown.
- TODO: Replace wait loop with an event.
-
So far, we've introduced the Producer and Consumer mlt classes. We'll cover
each of these in more detail later in the tutorial, but for now, we'll
briefly cover the remaining classes.
}
Consumer c( "sdl" );
c.connect( list );
+ Event *e = Consumer.setup_wait_for( "consumer-stopped" );
c.start( );
- struct timespec tm = { 1, 0 };
- while ( !c.is_stopped( ) )
- nanosleep( &tm, NULL );
+ c.wait_for( e );
+ delete e;
return 0;
}
list.attach( f );
Consumer c( "sdl" );
c.connect( list );
+ Event *e = Consumer.setup_wait_for( "consumer-stopped" );
c.start( );
- struct timespec tm = { 1, 0 };
- while ( !c.is_stopped( ) )
- nanosleep( &tm, NULL );
+ c.wait_for( e );
+ delete e;
return 0;
}
return producer.is_valid( );
}
-
+
+Events
+------
{
mlt_events_wait_for( get_properties( ), event->get_event( ) );
if ( destroy )
- {
mlt_events_close_wait_for( get_properties( ), event->get_event( ) );
- delete event;
- }
}
int save( char *file );
void listen( char *id, void *object, mlt_listener listener );
Event *setup_wait_for( char *id );
- void wait_for( Event *, bool destroy = false );
+ void wait_for( Event *, bool destroy = true );
};
}
%include <MltTractor.h>
%include <MltFilteredConsumer.h>
+#if defined(SWIGRUBY)
+
+%{
+
+static void ruby_listener( mlt_properties owner, void *object );
+
+class RubyListener
+{
+ public:
+ RubyListener( Mlt::Properties &properties, char *id, VALUE callback ) :
+ callback( callback )
+ {
+ properties.listen( id, this, ( mlt_listener )ruby_listener );
+ }
+
+ void mark( )
+ {
+ ((void (*)(VALUE))(rb_gc_mark))( callback );
+ }
+
+ void doit( )
+ {
+ ID method = rb_intern( "call" );
+ rb_funcall( callback, method, 0 );
+ }
+
+ private:
+ VALUE callback;
+};
+
+static void ruby_listener( mlt_properties owner, void *object )
+{
+ RubyListener *o = static_cast< RubyListener * >( object );
+ o->doit( );
+}
+
+void markRubyListener( void* p )
+{
+ RubyListener *o = static_cast<RubyListener*>( p );
+ o->mark( );
+}
+
+%}
+
+// Ruby wrapper
+%rename( Listener ) RubyListener;
+%markfunc RubyListener "markRubyListener";
+
+class RubyListener
+{
+ public:
+ RubyListener( Mlt::Properties &properties, char *id, VALUE callback );
+};
+
+#endif
+
# Create the consumer
$c = new mltpp::FilteredConsumer( "sdl" );
- $c->attach( new mltpp::Filter( "greyscale" ) );
# Turn of the default rescaling
$c->set( "rescale", "none" );
# Connect the producer to the consumer
$c->connect( $p );
+ $e = $c->setup_wait_for( "consumer-stopped" );
+
# Start the consumer
$c->start;
# Wait until the user stops the consumer
- while ( !$c->is_stopped ) {
- sleep( 1 );
- }
+ $c->wait_for( $e );
- $c->stop( );
+ $e = undef;
$c = undef;
$p = undef;
}