This also helps prevent deadlock while waiting for consumer-sdl-paused
event. Not 100% yet, but 100% requires script (swig) apps to handle the
event asynchronously via an event listener, which is not available yet
for most - only ruby. Furthermore, they would really like to be able to
pass opaque data to the asynchronous handler, which is not yet available
in the framework.
A good example here is pausing playback prior to seeking to a specific
frame. The app should be able to make a consumer-paused event handler to
which it can pass the new position, so it can properly seek after the
pause has officially occurred. Without the ability to pass opaque data,
it must save the new position as an instance variable to use within the
handler - once it has support for event listeners that is.
#include "MltProducer.h"
#include "MltFilter.h"
#include "MltProfile.h"
+#include "MltEvent.h"
using namespace Mlt;
Producer::Producer( ) :
int Producer::set_speed( double speed )
{
- return mlt_producer_set_speed( get_producer( ), speed );
+ double current = get_speed();
+ int result = 0;
+ Service *consumer = this->consumer();
+ Event *event = consumer->setup_wait_for( "consumer-sdl-paused" );
+
+ if ( current != speed )
+ mlt_producer_set_speed( get_producer( ), speed );
+ if ( consumer->is_valid() && current != 0 && speed == 0 )
+ consumer->wait_for( event );
+ delete event;
+
+ return result;
}
double Producer::get_speed( )
{
pthread_mutex_lock( &this->refresh_mutex );
if ( this->running && speed == 0 && this->refresh_count <= 0 )
+ {
+ mlt_events_fire( properties, "consumer-sdl-paused", NULL );
pthread_cond_wait( &this->refresh_cond, &this->refresh_mutex );
+ }
this->refresh_count --;
pthread_mutex_unlock( &this->refresh_mutex );
}