Consumer sdl preview correction - attach colour space conversion on start
[melted] / src / modules / sdl / consumer_sdl_still.c
index 82a231d..13f73ee 100644 (file)
@@ -57,6 +57,7 @@ struct consumer_sdl_s
        uint8_t *buffer;
        int last_position;
        mlt_producer last_producer;
+       int filtered;
 };
 
 /** Forward references to static functions.
@@ -85,12 +86,6 @@ mlt_consumer consumer_sdl_still_init( char *arg )
                // Get the parent consumer object
                mlt_consumer parent = &this->parent;
 
-               // Attach a colour space converter
-               mlt_filter filter = mlt_factory_filter( "avcolour_space", NULL );
-               mlt_properties_set_int( mlt_filter_properties( filter ), "forced", mlt_image_yuv422 );
-               mlt_service_attach( mlt_consumer_service( &this->parent ), filter );
-               mlt_filter_close( filter );
-
                // We have stuff to clean up, so override the close method
                parent->close = consumer_close;
 
@@ -162,7 +157,17 @@ static int consumer_start( mlt_consumer parent )
        if ( !this->running )
        {
                pthread_attr_t thread_attributes;
-               
+
+               // Attach a colour space converter
+               if ( !this->filtered )
+               {
+                       mlt_filter filter = mlt_factory_filter( "avcolour_space", NULL );
+                       mlt_properties_set_int( mlt_filter_properties( filter ), "forced", mlt_image_yuv422 );
+                       mlt_service_attach( mlt_consumer_service( &this->parent ), filter );
+                       mlt_filter_close( filter );
+                       this->filtered = 1;
+               }
+       
                consumer_stop( parent );
 
                this->last_position = -1;
@@ -446,7 +451,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
                mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
        }
 
-       if ( 1 )
+       if ( image != NULL )
        {
                char *rescale = mlt_properties_get( properties, "rescale" );
                if ( rescale != NULL && strcmp( rescale, "none" ) )
@@ -512,7 +517,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
 
        if ( unlock != NULL ) unlock( );
 
-       return 0;
+       return 1;
 }
 
 /** Threaded wrapper for pipe.
@@ -528,7 +533,7 @@ static void *consumer_thread( void *arg )
 
        // internal intialization
        mlt_frame frame = NULL;
-       struct timespec tm = { 0, 400000 };
+       struct timespec tm = { 0, 1000000 };
 
        if ( mlt_properties_get_int( mlt_consumer_properties( consumer ), "sdl_started" ) == 0 )
        {
@@ -561,9 +566,9 @@ static void *consumer_thread( void *arg )
                // Ensure that we have a frame
                if ( frame != NULL )
                {
-                       consumer_play_video( this, frame );
+                       if ( consumer_play_video( this, frame ) == 0 )
+                               nanosleep( &tm, NULL );
                        mlt_frame_close( frame );
-                       nanosleep( &tm, NULL );
                }
        }