+ // Do not interrupt the play consumer near the end
+ if ( duration - self->last_position > eos_threshold )
+ {
+ // Get a new frame at the sought position
+ mlt_frame_close( frame );
+ if ( producer )
+ mlt_producer_seek( producer, self->last_position );
+ frame = mlt_consumer_get_frame( consumer );
+ pause = 1;
+ }
+ else
+ {
+ // Send frame with speed 0 to stop it
+ if ( frame && !mlt_consumer_is_stopped( self->play ) )
+ {
+ mlt_consumer_put_frame( self->play, frame );
+ frame = NULL;
+ eos = 1;
+ }
+
+ // Check for end of stream
+ if ( mlt_consumer_is_stopped( self->play ) )
+ {
+ // Stream has ended
+ 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 );
+ }
+ }
+ }
+#else
+ pause = self->active == self->play;
+#endif
+ if ( pause )
+ {
+ // Start the still consumer
+ if ( !mlt_consumer_is_stopped( self->play ) )
+ mlt_consumer_stop( self->play );
+ self->last_speed = speed;
+ self->active = self->still;
+ self->ignore_change = 0;
+ mlt_consumer_start( self->still );
+ }
+ // Send the frame to the active child
+ if ( frame && !eos )
+ {
+ mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "refresh", 1 );
+ mlt_consumer_put_frame( self->active, frame );
+ }
+ if ( pause && speed == 0.0 )
+ {
+ mlt_events_fire( properties, "consumer-sdl-paused", NULL );