]> git.sesse.net Git - mlt/blobdiff - src/modules/sdl/consumer_sdl_still.c
Fix abruptness when using a luma with softness in composite.
[mlt] / src / modules / sdl / consumer_sdl_still.c
index 3efd8f4eb63c389338bfcac4eb7d7c23c2eeee3e..fdeca81e084a9a5202a0e8ffc03b3285fbba549d 100644 (file)
@@ -23,6 +23,7 @@
 #include <framework/mlt_deque.h>
 #include <framework/mlt_factory.h>
 #include <framework/mlt_filter.h>
+#include <framework/mlt_log.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -31,6 +32,8 @@
 #include <SDL/SDL_syswm.h>
 #include <sys/time.h>
 
+extern pthread_mutex_t mlt_sdl_mutex;
+
 /** This classes definition.
 */
 
@@ -54,7 +57,6 @@ struct consumer_sdl_s
        uint8_t *buffer;
        int last_position;
        mlt_producer last_producer;
-       int filtered;
 };
 
 /** Forward references to static functions.
@@ -96,9 +98,6 @@ mlt_consumer consumer_sdl_still_init( mlt_profile profile, mlt_service_type type
                // We're always going to run this in non-realtime mode
                mlt_properties_set( this->properties, "real_time", "0" );
 
-               // Default progressive true
-               mlt_properties_set_int( this->properties, "progressive", 1 );
-
                // Ensure we don't join on a non-running object
                this->joined = 1;
                
@@ -151,17 +150,6 @@ static int consumer_start( mlt_consumer parent )
                int preview_off = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent ), "preview_off" );
                int sdl_started = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent ), "sdl_started" );
 
-               // Attach a colour space converter
-               if ( !this->filtered )
-               {
-                       mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( parent ) );
-                       mlt_filter filter = mlt_factory_filter( profile, "avcolour_space", NULL );
-                       mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "forced", mlt_image_yuv422 );
-                       mlt_service_attach( MLT_CONSUMER_SERVICE( parent ), filter );
-                       mlt_filter_close( filter );
-                       this->filtered = 1;
-               }
-       
                consumer_stop( parent );
 
                this->last_position = -1;
@@ -197,7 +185,11 @@ static int consumer_start( mlt_consumer parent )
                }
 
                if ( this->sdl_screen == NULL && preview_off == 0 )
+               {
+                       pthread_mutex_lock( &mlt_sdl_mutex );
                        this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );
+                       pthread_mutex_unlock( &mlt_sdl_mutex );
+               }
 
                pthread_create( &this->thread, NULL, consumer_thread, this );
        }
@@ -222,7 +214,11 @@ static int consumer_stop( mlt_consumer parent )
                this->joined = 1;
 
                if ( sdl_started == 0 && preview_off == 0 )
+               {
+                       pthread_mutex_lock( &mlt_sdl_mutex );
                        SDL_Quit( );
+                       pthread_mutex_unlock( &mlt_sdl_mutex );
+               }
 
                this->sdl_screen = NULL;
        }
@@ -238,15 +234,20 @@ static int consumer_is_stopped( mlt_consumer parent )
 
 static int sdl_lock_display( )
 {
+       pthread_mutex_lock( &mlt_sdl_mutex );
        SDL_Surface *screen = SDL_GetVideoSurface( );
-       return screen != NULL && ( !SDL_MUSTLOCK( screen ) || SDL_LockSurface( screen ) >= 0 );
+       int result = screen != NULL && ( !SDL_MUSTLOCK( screen ) || SDL_LockSurface( screen ) >= 0 );
+       pthread_mutex_unlock( &mlt_sdl_mutex );
+       return result;
 }
 
 static void sdl_unlock_display( )
 {
+       pthread_mutex_lock( &mlt_sdl_mutex );
        SDL_Surface *screen = SDL_GetVideoSurface( );
        if ( screen != NULL && SDL_MUSTLOCK( screen ) )
                SDL_UnlockSurface( screen );
+       pthread_mutex_unlock( &mlt_sdl_mutex );
 }
 
 static inline void display_1( SDL_Surface *screen, SDL_Rect rect, uint8_t *image, int width, int height )
@@ -397,7 +398,9 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
        {
                SDL_Event event;
 
+               pthread_mutex_lock( &mlt_sdl_mutex );
                changed = consumer_get_dimensions( &this->window_width, &this->window_height );
+               pthread_mutex_unlock( &mlt_sdl_mutex );
 
                while ( SDL_PollEvent( &event ) )
                {
@@ -431,31 +434,33 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
 
        if ( this->sdl_screen == NULL || changed )
        {
-               // open SDL window 
+               // open SDL window
+               pthread_mutex_lock( &mlt_sdl_mutex );
                this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );
                if ( consumer_get_dimensions( &this->window_width, &this->window_height ) )
                        this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );
+               pthread_mutex_unlock( &mlt_sdl_mutex );
+
                uint32_t color = mlt_properties_get_int( this->properties, "window_background" );
                SDL_FillRect( this->sdl_screen, NULL, color >> 8 );
                changed = 1;
        }
-       else
-       {
-               changed = 1;
-       }
 
        if ( changed == 0 &&
                 this->last_position == mlt_frame_get_position( frame ) &&
-                this->last_producer == mlt_properties_get_data( MLT_FRAME_PROPERTIES( frame ), "_producer", NULL ) )
+                this->last_producer == mlt_frame_get_original_producer( frame ) &&
+                !mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "refresh" ) )
        {
                sdl_unlock_display( );
                if ( unlock != NULL ) unlock( );
+               struct timespec tm = { 0, 100000 };
+               nanosleep( &tm, NULL );
                return 0;
        }
 
        // Update last frame shown info
        this->last_position = mlt_frame_get_position( frame );
-       this->last_producer = mlt_properties_get_data( MLT_FRAME_PROPERTIES( frame ), "_producer", NULL );
+       this->last_producer = mlt_frame_get_original_producer( frame );
 
        // Get the image, width and height
        mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
@@ -539,21 +544,10 @@ static void *consumer_thread( void *arg )
        // Get the consumer
        mlt_consumer consumer = &this->parent;
        mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
-
-       // internal intialization
        mlt_frame frame = NULL;
-       mlt_image_format vfmt = mlt_image_rgb24a;
-       int height = this->height;
-       int width = this->width;
-       uint8_t *image = NULL;
 
        // Allow the hosting app to provide the preview
        int preview_off = mlt_properties_get_int( properties, "preview_off" );
-       mlt_image_format preview_format = mlt_properties_get_int( properties, "preview_format" );
-
-       // Check if a specific colour space has been requested
-       if ( preview_off && preview_format != mlt_image_none )
-               vfmt = preview_format;
 
        // Loop until told not to
        while( this->running )
@@ -570,6 +564,16 @@ static void *consumer_thread( void *arg )
                        }
                        else
                        {
+                               mlt_image_format vfmt = mlt_image_rgb24a;
+                               int height = this->height;
+                               int width = this->width;
+                               uint8_t *image = NULL;
+                               mlt_image_format preview_format = mlt_properties_get_int( properties, "preview_format" );
+
+                               // Check if a specific colour space has been requested
+                               if ( preview_off && preview_format != mlt_image_none )
+                                       vfmt = preview_format;
+                       
                                mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
                                mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "format", vfmt );
                                mlt_events_fire( properties, "consumer-frame-show", frame, NULL );