]> git.sesse.net Git - mlt/blobdiff - src/modules/sdl/consumer_sdl.c
Make the SDL consumer cooperate with VDPAU.
[mlt] / src / modules / sdl / consumer_sdl.c
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 );
 }