#include <framework/mlt_frame.h>
#include <framework/mlt_factory.h>
#include <framework/mlt_producer.h>
+#include <framework/mlt_log.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <SDL.h>
#include <SDL_syswm.h>
-#include <assert.h>
+#include <sys/time.h>
extern pthread_mutex_t mlt_sdl_mutex;
// Create child consumers
this->play = mlt_factory_consumer( profile, "sdl", arg );
this->still = mlt_factory_consumer( profile, "sdl_still", arg );
- mlt_properties_set( properties, "real_time", "0" );
mlt_properties_set( properties, "rescale", "nearest" );
mlt_properties_set( properties, "deinterlace_method", "onefield" );
+ mlt_properties_set_int( properties, "prefill", 1 );
parent->close = consumer_close;
parent->start = consumer_start;
parent->stop = consumer_stop;
pthread_cond_init( &this->refresh_cond, NULL );
pthread_mutex_init( &this->refresh_mutex, NULL );
mlt_events_listen( MLT_CONSUMER_PROPERTIES( parent ), this, "property-changed", ( mlt_listener )consumer_refresh_cb );
+ mlt_events_register( properties, "consumer-sdl-paused", NULL );
return parent;
}
free( this );
{
consumer_sdl this = parent->child;
pthread_mutex_lock( &this->refresh_mutex );
- this->refresh_count = this->refresh_count <= 0 ? 1 : this->refresh_count ++;
+ this->refresh_count = this->refresh_count <= 0 ? 1 : this->refresh_count + 1;
pthread_cond_broadcast( &this->refresh_cond );
pthread_mutex_unlock( &this->refresh_mutex );
}
mlt_properties_set_int( play, "progressive", progressive );
mlt_properties_set_int( still, "progressive", progressive );
- mlt_properties_pass_list( play, properties, "resize,rescale,width,height,aspect_ratio,display_ratio,volume" );
- mlt_properties_pass_list( still, properties, "resize,rescale,width,height,aspect_ratio,display_ratio" );
- mlt_properties_pass_list( play, properties, "deinterlace_method" );
- mlt_properties_pass_list( still, properties, "deinterlace_method" );
- mlt_properties_pass_list( play, properties, "preview_off,preview_format,window_background" );
- mlt_properties_pass_list( still, properties, "preview_off,preview_format,window_background" );
+ mlt_properties_pass_list( play, properties,
+ "deinterlace_method,resize,rescale,width,height,aspect_ratio,display_ratio,preview_off,preview_format,window_background"
+ ",volume,real_time,buffer,prefill,audio_off,frequency,drop_max" );
+ mlt_properties_pass_list( still, properties,
+ "deinterlace_method,resize,rescale,width,height,aspect_ratio,display_ratio,preview_off,preview_format,window_background" );
mlt_properties_pass( play, properties, "play." );
mlt_properties_pass( still, properties, "still." );
pthread_mutex_lock( &this->refresh_mutex );
pthread_cond_broadcast( &this->refresh_cond );
pthread_mutex_unlock( &this->refresh_mutex );
+#ifndef WIN32
if ( this->thread )
+#endif
pthread_join( this->thread, NULL );
this->joined = 1;
// Identify the arg
consumer_sdl this = arg;
- // Get the consumer and producer
+ // Get the consumer
mlt_consumer consumer = &this->parent;
- mlt_producer producer = MLT_PRODUCER( mlt_service_get_producer( MLT_CONSUMER_SERVICE( consumer ) ) );
// Get the properties
mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
// If we aren't playing normally, then use the still
if ( speed != 1 )
{
- mlt_position duration = mlt_producer_get_playtime( producer );
- int paused = 0;
+ mlt_producer producer = MLT_PRODUCER( mlt_service_get_producer( MLT_CONSUMER_SERVICE( consumer ) ) );
+ mlt_position duration = producer? mlt_producer_get_playtime( producer ) : -1;
+ int pause = 0;
+#ifndef SKIP_WAIT_EOS
if ( this->active == this->play )
{
// Do not interrupt the play consumer near the end
if ( duration - this->last_position > eos_threshold )
{
- // Stop the play consumer and reposition
- mlt_consumer_stop( this->play );
- paused = 1;
-
// Get a new frame at the sought position
mlt_frame_close( frame );
if ( producer )
mlt_producer_seek( producer, this->last_position );
frame = mlt_consumer_get_frame( consumer );
+ pause = 1;
}
else
{
- // Send frame with speed 0 once to stop it
- if ( frame && !eos && speed == 0.0 )
+ // Send frame with speed 0 to stop it
+ if ( frame && !mlt_consumer_is_stopped( this->play ) )
{
mlt_consumer_put_frame( this->play, frame );
+ frame = NULL;
eos = 1;
}
if ( mlt_consumer_is_stopped( this->play ) )
{
// Stream has ended
- mlt_consumer_stop( this->play );
- paused = 1;
- eos = 0; // reset eof indicator
+ mlt_log_verbose( MLT_CONSUMER_SERVICE( consumer ), "END OF STREAM\n" );
+ pause = 1;
+ eos = 0; // reset eos indicator
+ }
+ else
+ {
+ // Prevent a tight busy loop
+ struct timespec tm = { 0, 100000L }; // 100 usec
+ nanosleep( &tm, NULL );
}
}
}
- if ( paused )
+#else
+ pause = this->active == this->play;
+#endif
+ if ( pause )
{
// Start the still consumer
+ mlt_consumer_stop( this->play );
this->last_speed = speed;
this->active = this->still;
this->ignore_change = 0;
}
// Send the frame to the active child
if ( frame && !eos )
+ {
+ mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "refresh", 1 );
mlt_consumer_put_frame( this->active, frame );
+ }
+ if ( pause && speed == 0.0 )
+ {
+ mlt_events_fire( properties, "consumer-sdl-paused", NULL );
+ }
}
// Allow a little grace time before switching consumers on speed changes
else if ( this->ignore_change -- > 0 && this->active != NULL && !mlt_consumer_is_stopped( this->active ) )
{
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 );
}