]> git.sesse.net Git - mlt/commitdiff
Make the SDL consumer cooperate with VDPAU.
authorDan Dennedy <dan@dennedy.org>
Sun, 29 Nov 2009 01:08:13 +0000 (17:08 -0800)
committerDan Dennedy <dan@dennedy.org>
Fri, 11 Dec 2009 04:37:56 +0000 (20:37 -0800)
This moves the SDL_Quit calls from the consumer_stop to the
consumer_close functions. Also, it exports the X11 Display pointer to
the mlt_environment and the global SDL mutex to the consumer class.

src/framework/mlt_consumer.c
src/modules/sdl/consumer_sdl.c
src/modules/sdl/consumer_sdl_preview.c
src/modules/sdl/consumer_sdl_still.c

index 37e7d3fa0ad0392caf972b103fb28ffceb8c595d..b1a8fa19f5b7eb7d67e1ede288b0831692ceba44 100644 (file)
  */
 #undef DEINTERLACE_ON_NOT_NORMAL_SPEED
 
+/** This is not the ideal place for this, but it is needed by VDPAU as well.
+ */
+pthread_mutex_t mlt_sdl_mutex = PTHREAD_MUTEX_INITIALIZER;
+
 static void mlt_consumer_frame_render( mlt_listener listener, mlt_properties owner, mlt_service this, void **args );
 static void mlt_consumer_frame_show( mlt_listener listener, mlt_properties owner, mlt_service this, void **args );
 static void mlt_consumer_property_changed( mlt_service owner, mlt_consumer this, char *name );
index 42582c6dd8e909ad11f3f56b0067dcd7d78bb85d..b96c384809540db1aac6f9d0503ec2149caee5cb 100644 (file)
@@ -188,12 +188,28 @@ int consumer_start( mlt_consumer parent )
                {
                        if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE ) < 0 )
                        {
-                               fprintf( stderr, "Failed to initialize SDL: %s\n", SDL_GetError() );
+                               mlt_log_error( MLT_CONSUMER_SERVICE(parent), "Failed to initialize SDL: %s\n", SDL_GetError() );
                                return -1;
                        }
 
                        SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
                        SDL_EnableUNICODE( 1 );
+                       
+#ifndef __DARWIN__
+                       // Get the wm structure
+                       SDL_SysWMinfo wm;
+                       SDL_VERSION( &wm.version );
+                       // Only on X11
+                       if ( SDL_GetWMInfo( &wm ) == 1 && wm.subsystem == SDL_SYSWM_X11 )
+                       {
+                               // Set the x11_display property for use by VDPAU
+                               mlt_properties_set_int( this->properties, "x11_display", (int) wm.info.x11.display );
+                               mlt_log_verbose( MLT_CONSUMER_SERVICE(parent), "X11 Display = %p\n", wm.info.x11.display );
+                               char tmp[20];
+                               sprintf( tmp, "%p", wm.info.x11.display );
+                               mlt_environment_set( "x11_display", tmp );
+                       }
+#endif
                }
                else if ( display_off == 0 )
                {
@@ -255,13 +271,6 @@ int consumer_stop( mlt_consumer parent )
                        SDL_QuitSubSystem( SDL_INIT_AUDIO );
                }
 
-               if ( mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent ), "sdl_started" ) == 0 )
-               {
-                       pthread_mutex_lock( &mlt_sdl_mutex );
-                       SDL_Quit( );
-                       pthread_mutex_unlock( &mlt_sdl_mutex );
-               }
-
                this->sdl_screen = NULL;
        }
 
@@ -677,6 +686,10 @@ static void *video_thread( void *arg )
                                start = ( ( int64_t )now.tv_sec * 1000000 + now.tv_usec ) - scheduled + 20000;
                        }
                }
+               else
+               {
+                       mlt_log_debug( MLT_CONSUMER_SERVICE(&this->parent), "dropped video frame\n" );
+               }
 
                // This frame can now be closed
                mlt_frame_close( next );
@@ -837,6 +850,7 @@ static void consumer_close( mlt_consumer parent )
 {
        // Get the actual object
        consumer_sdl this = parent->child;
+       int sdl_started = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent ), "sdl_started" );
 
        // Stop the consumer
        ///mlt_consumer_stop( parent );
@@ -851,6 +865,13 @@ static void consumer_close( mlt_consumer parent )
        pthread_mutex_destroy( &this->audio_mutex );
        pthread_cond_destroy( &this->audio_cond );
                
+       if ( sdl_started == 0 )
+       {
+               pthread_mutex_lock( &mlt_sdl_mutex );
+               SDL_Quit( );
+               pthread_mutex_unlock( &mlt_sdl_mutex );
+       }
+
        // Finally clean up this
        free( this );
 }
index ec2d608fca50f65aa96277077579037139a1a140..ae722a099de16f67bfd8809b41db22c4a3b4eb3f 100644 (file)
@@ -28,7 +28,7 @@
 #include <SDL/SDL.h>
 #include <SDL/SDL_syswm.h>
 
-pthread_mutex_t mlt_sdl_mutex = PTHREAD_MUTEX_INITIALIZER;
+extern pthread_mutex_t mlt_sdl_mutex;
 
 typedef struct consumer_sdl_s *consumer_sdl;
 
@@ -245,10 +245,6 @@ static int consumer_stop( mlt_consumer parent )
                this->joined = 1;
 
                if ( app_locked && lock ) lock( );
-
-               pthread_mutex_lock( &mlt_sdl_mutex );
-               SDL_Quit( );
-               pthread_mutex_unlock( &mlt_sdl_mutex );
        }
 
        return 0;
@@ -422,6 +418,10 @@ static void consumer_close( mlt_consumer parent )
        // Now clean up the rest
        mlt_consumer_close( parent );
 
+       pthread_mutex_lock( &mlt_sdl_mutex );
+       SDL_Quit( );
+       pthread_mutex_unlock( &mlt_sdl_mutex );
+
        // Finally clean up this
        free( this );
 }
index fdeca81e084a9a5202a0e8ffc03b3285fbba549d..02b3d199658c13e0f98e9245a981ced4abc7d117 100644 (file)
@@ -175,6 +175,22 @@ static int consumer_start( mlt_consumer parent )
 
                        SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
                        SDL_EnableUNICODE( 1 );
+                       
+#ifndef __DARWIN__
+                       // Get the wm structure
+                       SDL_SysWMinfo wm;
+                       SDL_VERSION( &wm.version );
+                       // Only on X11
+                       if ( SDL_GetWMInfo( &wm ) == 1 && wm.subsystem == SDL_SYSWM_X11 )
+                       {
+                               // Set the x11_display property for use by VDPAU
+                               mlt_properties_set_int( this->properties, "x11_display", (int) wm.info.x11.display );
+                               mlt_log_verbose( MLT_CONSUMER_SERVICE(parent), "X11 Display = %p\n", wm.info.x11.display );
+                               char tmp[20];
+                               sprintf( tmp, "%p", wm.info.x11.display );
+                               mlt_environment_set( "x11_display", tmp );
+                       }
+#endif
                }
                else if ( preview_off == 0 )
                {
@@ -204,22 +220,12 @@ static int consumer_stop( mlt_consumer parent )
 
        if ( this->joined == 0 )
        {
-               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" );
-
                // Kill the thread and clean up
                this->running = 0;
 
                pthread_join( this->thread, NULL );
                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;
        }
 
@@ -637,6 +643,8 @@ static void consumer_close( mlt_consumer parent )
 {
        // Get the actual object
        consumer_sdl this = parent->child;
+       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" );
 
        // Stop the consumer
        mlt_consumer_stop( parent );
@@ -644,6 +652,13 @@ static void consumer_close( mlt_consumer parent )
        // Now clean up the rest
        mlt_consumer_close( parent );
 
+       if ( sdl_started == 0 && preview_off == 0 )
+       {
+               pthread_mutex_lock( &mlt_sdl_mutex );
+               SDL_Quit( );
+               pthread_mutex_unlock( &mlt_sdl_mutex );
+       }
+
        // Finally clean up this
        free( this );
 }