]> git.sesse.net Git - mlt/commitdiff
Synchronize Producer.set_speed(0) with sdl_preview.
authorDan Dennedy <dan@dennedy.org>
Thu, 16 Dec 2010 07:49:54 +0000 (23:49 -0800)
committerDan Dennedy <dan@dennedy.org>
Thu, 16 Dec 2010 07:49:54 +0000 (23:49 -0800)
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.

src/mlt++/MltProducer.cpp
src/modules/sdl/consumer_sdl_preview.c

index e12dd42ce0223ac4a2c53433b74e049fdafb4925..95a66568e4bee84b3c57ebb6aad7403b112652bd 100644 (file)
@@ -21,6 +21,7 @@
 #include "MltProducer.h"
 #include "MltFilter.h"
 #include "MltProfile.h"
+#include "MltEvent.h"
 using namespace Mlt;
 
 Producer::Producer( ) :
@@ -121,7 +122,18 @@ int Producer::frame( )
 
 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( )
index 5745d90ed41688e6f5e5b0a7933c979c407cf83d..f6f08b929075fb1d99c36f44625a143035d35022 100644 (file)
@@ -430,7 +430,10 @@ static void *consumer_thread( void *arg )
                        {
                                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 );
                        }