X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fsdl%2Fconsumer_sdl_preview.c;h=cb2e33c59eba7a1cfe050168fe2f1fd8e35ba7a9;hb=df1a6457d0270cc8156b38c59b7479d415847551;hp=5415ed3c8280b5c5322ba56dc7d8e587f224cebd;hpb=c12c6c380fa37b6a0d28ce98fdcda487a8aca76d;p=melted diff --git a/src/modules/sdl/consumer_sdl_preview.c b/src/modules/sdl/consumer_sdl_preview.c index 5415ed3..cb2e33c 100644 --- a/src/modules/sdl/consumer_sdl_preview.c +++ b/src/modules/sdl/consumer_sdl_preview.c @@ -63,7 +63,7 @@ mlt_consumer consumer_sdl_preview_init( char *arg ) mlt_consumer parent = &this->parent; // Get the properties - mlt_properties properties = mlt_consumer_properties( parent ); + mlt_properties properties = MLT_CONSUMER_PROPERTIES( parent ); // Get the width and height int width = mlt_properties_get_int( properties, "width" ); @@ -79,17 +79,17 @@ mlt_consumer consumer_sdl_preview_init( char *arg ) // Create child consumers this->play = mlt_factory_consumer( "sdl", arg ); this->still = mlt_factory_consumer( "sdl_still", arg ); - mlt_properties_set( mlt_consumer_properties( parent ), "real_time", "0" ); - mlt_properties_set( mlt_consumer_properties( parent ), "rescale", "nearest" ); + mlt_properties_set( MLT_CONSUMER_PROPERTIES( parent ), "real_time", "0" ); + mlt_properties_set( MLT_CONSUMER_PROPERTIES( parent ), "rescale", "nearest" ); parent->close = consumer_close; parent->start = consumer_start; parent->stop = consumer_stop; parent->is_stopped = consumer_is_stopped; this->joined = 1; - mlt_events_listen( mlt_consumer_properties( this->play ), this, "consumer-frame-show", ( mlt_listener )consumer_frame_show_cb ); - mlt_events_listen( mlt_consumer_properties( this->still ), this, "consumer-frame-show", ( mlt_listener )consumer_frame_show_cb ); - mlt_events_listen( mlt_consumer_properties( this->play ), this, "consumer-sdl-event", ( mlt_listener )consumer_sdl_event_cb ); - mlt_events_listen( mlt_consumer_properties( this->still ), this, "consumer-sdl-event", ( mlt_listener )consumer_sdl_event_cb ); + mlt_events_listen( MLT_CONSUMER_PROPERTIES( this->play ), this, "consumer-frame-show", ( mlt_listener )consumer_frame_show_cb ); + mlt_events_listen( MLT_CONSUMER_PROPERTIES( this->still ), this, "consumer-frame-show", ( mlt_listener )consumer_frame_show_cb ); + mlt_events_listen( MLT_CONSUMER_PROPERTIES( this->play ), this, "consumer-sdl-event", ( mlt_listener )consumer_sdl_event_cb ); + mlt_events_listen( MLT_CONSUMER_PROPERTIES( this->still ), this, "consumer-sdl-event", ( mlt_listener )consumer_sdl_event_cb ); return parent; } free( this ); @@ -99,13 +99,13 @@ mlt_consumer consumer_sdl_preview_init( char *arg ) void consumer_frame_show_cb( mlt_consumer sdl, mlt_consumer parent, mlt_frame frame ) { consumer_sdl this = parent->child; - this->last_speed = mlt_properties_get_double( mlt_frame_properties( frame ), "_speed" ); - mlt_events_fire( mlt_consumer_properties( parent ), "consumer-frame-show", frame, NULL ); + this->last_speed = mlt_properties_get_double( MLT_FRAME_PROPERTIES( frame ), "_speed" ); + mlt_events_fire( MLT_CONSUMER_PROPERTIES( parent ), "consumer-frame-show", frame, NULL ); } static void consumer_sdl_event_cb( mlt_consumer sdl, mlt_consumer parent, SDL_Event *event ) { - mlt_events_fire( mlt_consumer_properties( parent ), "consumer-sdl-event", event, NULL ); + mlt_events_fire( MLT_CONSUMER_PROPERTIES( parent ), "consumer-sdl-event", event, NULL ); } static int consumer_start( mlt_consumer parent ) @@ -139,11 +139,23 @@ static int consumer_stop( mlt_consumer parent ) if ( this->joined == 0 ) { + mlt_properties properties = MLT_CONSUMER_PROPERTIES( parent ); + int app_locked = mlt_properties_get_int( properties, "app_locked" ); + void ( *lock )( void ) = mlt_properties_get_data( properties, "app_lock", NULL ); + void ( *unlock )( void ) = mlt_properties_get_data( properties, "app_unlock", NULL ); + + if ( app_locked && unlock ) unlock( ); + // Kill the thread and clean up this->running = 0; + if ( this->play ) mlt_consumer_stop( this->play ); + if ( this->still ) mlt_consumer_stop( this->still ); + pthread_join( this->thread, NULL ); this->joined = 1; + + if ( app_locked && lock ) lock( ); } return 0; @@ -166,11 +178,12 @@ static void *consumer_thread( void *arg ) // internal intialization int first = 1; mlt_frame frame = NULL; + int last_position = -1; // properties - mlt_properties properties = mlt_consumer_properties( consumer ); - mlt_properties play = mlt_consumer_properties( this->play ); - mlt_properties still = mlt_consumer_properties( this->still ); + mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer ); + mlt_properties play = MLT_CONSUMER_PROPERTIES( this->play ); + mlt_properties still = MLT_CONSUMER_PROPERTIES( this->still ); if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE ) < 0 ) { @@ -190,18 +203,20 @@ static void *consumer_thread( void *arg ) mlt_properties_set_data( still, "transport_producer", mlt_properties_get_data( properties, "transport_producer", NULL ), 0, NULL, NULL ); mlt_properties_set_data( play, "transport_callback", mlt_properties_get_data( properties, "transport_callback", NULL ), 0, NULL, NULL ); mlt_properties_set_data( still, "transport_callback", mlt_properties_get_data( properties, "transport_callback", NULL ), 0, NULL, NULL ); + mlt_properties_set_int( play, "resize", mlt_properties_get_int( properties, "resize" ) ); + mlt_properties_set_int( still, "resize", mlt_properties_get_int( properties, "resize" ) ); mlt_properties_set( play, "rescale", mlt_properties_get( properties, "rescale" ) ); mlt_properties_set( still, "rescale", mlt_properties_get( properties, "rescale" ) ); - mlt_properties_set( play, "width", mlt_properties_get( properties, "width" ) ); - mlt_properties_set( still, "width", mlt_properties_get( properties, "width" ) ); - mlt_properties_set( play, "height", mlt_properties_get( properties, "height" ) ); - mlt_properties_set( still, "height", mlt_properties_get( properties, "height" ) ); + mlt_properties_set_int( play, "width", mlt_properties_get_int( properties, "width" ) ); + mlt_properties_set_int( still, "width", mlt_properties_get_int( properties, "width" ) ); + mlt_properties_set_int( play, "height", mlt_properties_get_int( properties, "height" ) ); + mlt_properties_set_int( still, "height", mlt_properties_get_int( properties, "height" ) ); mlt_properties_set_int( play, "progressive", 1 ); mlt_properties_set_int( still, "progressive", 1 ); - mlt_properties_pass( play, mlt_consumer_properties( consumer ), "play." ); - mlt_properties_pass( still, mlt_consumer_properties( consumer ), "still." ); + mlt_properties_pass( play, MLT_CONSUMER_PROPERTIES( consumer ), "play." ); + mlt_properties_pass( still, MLT_CONSUMER_PROPERTIES( consumer ), "still." ); mlt_properties_set_data( play, "app_lock", mlt_properties_get_data( properties, "app_lock", NULL ), 0, NULL, NULL ); mlt_properties_set_data( still, "app_lock", mlt_properties_get_data( properties, "app_lock", NULL ), 0, NULL, NULL ); @@ -221,7 +236,7 @@ static void *consumer_thread( void *arg ) if ( frame != NULL ) { // Get the speed of the frame - double speed = mlt_properties_get_double( mlt_frame_properties( frame ), "_speed" ); + double speed = mlt_properties_get_double( MLT_FRAME_PROPERTIES( frame ), "_speed" ); // Determine which speed to use double use_speed = first ? speed : this->last_speed; @@ -237,10 +252,22 @@ static void *consumer_thread( void *arg ) mlt_properties_set_int( properties, "changed", 0 ); // Set the changed property on this frame for the benefit of still - mlt_properties_set_int( mlt_frame_properties( frame ), "refresh", refresh ); + mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "refresh", refresh ); // Make sure the recipient knows that this frame isn't really rendered - mlt_properties_set_int( mlt_frame_properties( frame ), "rendered", 0 ); + mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 0 ); + + // Optimisation to reduce latency + if ( speed == 1.0 ) + { + if ( last_position != -1 && last_position + 1 != mlt_frame_get_position( frame ) ) + mlt_consumer_purge( this->play ); + last_position = mlt_frame_get_position( frame ); + } + else + { + last_position = -1; + } // If we're not the first frame and both consumers are stopped, then stop ourselves if ( !first && mlt_consumer_is_stopped( this->play ) && mlt_consumer_is_stopped( this->still ) ) @@ -287,7 +314,7 @@ static void *consumer_thread( void *arg ) // Copy the rectangle info from the active consumer if ( this->running ) { - mlt_properties active = mlt_consumer_properties( this->active ); + mlt_properties active = MLT_CONSUMER_PROPERTIES( this->active ); mlt_properties_set_int( properties, "rect_x", mlt_properties_get_int( active, "rect_x" ) ); mlt_properties_set_int( properties, "rect_y", mlt_properties_get_int( active, "rect_y" ) ); mlt_properties_set_int( properties, "rect_w", mlt_properties_get_int( active, "rect_w" ) );