int mlt_consumer_start( mlt_consumer self )
{
+ if ( !mlt_consumer_is_stopped( self ) )
+ return 0;
+
// Stop listening to the property-changed event
mlt_event_block( self->event_listener );
int64_t time_frame = 0;
int64_t time_process = 0;
int skip_next = 0;
+ mlt_position pos = 0;
+ mlt_position start_pos = 0;
+ mlt_position last_pos = 0;
if ( preview_off && preview_format != 0 )
self->format = preview_format;
// Get the first frame
frame = mlt_consumer_get_frame( self );
- // Get the image of the first frame
- if ( !video_off )
+ if ( frame )
{
- mlt_events_fire( MLT_CONSUMER_PROPERTIES( self ), "consumer-frame-render", frame, NULL );
- mlt_frame_get_image( frame, &image, &self->format, &width, &height, 0 );
- }
+ // Get the image of the first frame
+ if ( !video_off )
+ {
+ mlt_events_fire( MLT_CONSUMER_PROPERTIES( self ), "consumer-frame-render", frame, NULL );
+ mlt_frame_get_image( frame, &image, &self->format, &width, &height, 0 );
+ }
- if ( !audio_off )
- {
- samples = mlt_sample_calculator( fps, frequency, counter++ );
- mlt_frame_get_audio( frame, &audio, &afmt, &frequency, &channels, &samples );
- }
+ if ( !audio_off )
+ {
+ samples = mlt_sample_calculator( fps, frequency, counter++ );
+ mlt_frame_get_audio( frame, &audio, &afmt, &frequency, &channels, &samples );
+ }
- // Mark as rendered
- mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 1 );
+ // Mark as rendered
+ mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 1 );
+ last_pos = start_pos = pos = mlt_frame_get_position( frame );
+ }
// Get the starting time (can ignore the times above)
gettimeofday( &ante, NULL );
// If there's no frame, we're probably stopped...
if ( frame == NULL )
continue;
+ pos = mlt_frame_get_position( frame );
// Increment the count
count ++;
time_wait = 0;
count = 1;
skip_next = 0;
+ start_pos = pos;
}
// Get the image
mlt_frame_get_image( frame, &image, &self->format, &width, &height, 0 );
}
mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 1 );
+ skipped = 0;
}
else
{
time_process += time_difference( &ante );
// Determine if the next frame should be skipped
- if ( mlt_deque_count( self->queue ) <= 5 )
+ if ( pos != last_pos + 1 )
+ start_pos = pos;
+ last_pos = pos;
+ if ( pos - start_pos <= buffer/5 )
+ {
+ // Do not skip the first 20% of buffer at start, resuming, or seeking
+ skipped = 0;
+ time_frame = 0;
+ time_process = 0;
+ time_wait = 0;
+ count = 1;
+ }
+ if ( mlt_deque_count( self->queue ) <= buffer/5 )
{
int frame_duration = mlt_properties_get_int( properties, "frame_duration" );
if ( ( ( time_wait + time_frame + time_process ) / count ) > frame_duration )
static void consumer_work_start( mlt_consumer self )
{
int n = abs( self->real_time );
- pthread_t *thread = calloc( 1, sizeof( pthread_t ) );
+ pthread_t *thread = calloc( 1, sizeof( pthread_t ) * n );
// We're running now
self->ahead = 1;
while ( n-- )
{
- if ( pthread_create( thread, &thread_attributes, consumer_read_ahead_thread, self ) < 0 )
- if ( pthread_create( thread, NULL, consumer_read_ahead_thread, self ) == 0 )
+ if ( pthread_create( thread, &thread_attributes, consumer_worker_thread, self ) < 0 )
+ if ( pthread_create( thread, NULL, consumer_worker_thread, self ) == 0 )
mlt_deque_push_back( self->worker_threads, thread );
+ thread++;
}
pthread_attr_destroy( &thread_attributes );
}
{
if ( pthread_create( thread, NULL, consumer_worker_thread, self ) == 0 )
mlt_deque_push_back( self->worker_threads, thread );
+ thread++;
}
}
self->started = 1;
// Join the threads
pthread_t *thread;
- while ( ( thread = mlt_deque_pop_front( self->worker_threads ) ) )
+ while ( ( thread = mlt_deque_pop_back( self->worker_threads ) ) )
pthread_join( *thread, NULL );
+
+ // Deallocate the array of threads
+ if ( thread )
+ free( thread );
+
+ // Indicate that worker threads no longer running
self->started = 0;
// Destroy the mutexes
// Adapt the worker process head to the runtime conditions.
if ( self->real_time > 0 )
{
- if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "rendered" ) )
+ if ( frame && mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "rendered" ) )
{
self->consecutive_dropped = 0;
if ( self->process_head > size && self->consecutive_rendered >= self->process_head )