]> git.sesse.net Git - mlt/blobdiff - src/modules/sdl/consumer_sdl.c
Fix SDL and keyboard input on Win32.
[mlt] / src / modules / sdl / consumer_sdl.c
index 8d53c19e8779e765e34d3e1c0ba944cf9650536d..53310b7df4f54e90e8a9f6e566f27e7869539409 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * consumer_sdl.c -- A Simple DirectMedia Layer consumer
- * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Copyright (C) 2003-2004, 2010 Ushodaya Enterprises Limited
  * Author: Dan Dennedy <dan@dennedy.org>
  *
  * This library is free software; you can redistribute it and/or
@@ -28,8 +28,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <pthread.h>
-#include <SDL/SDL.h>
-#include <SDL/SDL_syswm.h>
+#include <SDL.h>
+#include <SDL_syswm.h>
 #include <sys/time.h>
 #include "consumer_sdl_osx.h"
 
@@ -128,15 +128,21 @@ mlt_consumer consumer_sdl_init( mlt_profile profile, mlt_service_type type, cons
                this->joined = 1;
                
                // process actual param
-               if ( arg == NULL || sscanf( arg, "%dx%d", &this->width, &this->height ) != 2 )
+               if ( arg && sscanf( arg, "%dx%d", &this->width, &this->height ) )
+               {
+                       mlt_properties_set_int( this->properties, "_arg_size", 1 );
+               }
+               else
                {
                        this->width = mlt_properties_get_int( this->properties, "width" );
                        this->height = mlt_properties_get_int( this->properties, "height" );
                }
-
+       
                // Set the sdl flags
-               this->sdl_flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL | SDL_RESIZABLE | SDL_DOUBLEBUF;
-
+               this->sdl_flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL | SDL_DOUBLEBUF;
+#if !defined(__DARWIN__) && !defined(WIN32)
+               this->sdl_flags |= SDL_RESIZABLE;
+#endif         
                // Allow thread to be started/stopped
                parent->start = consumer_start;
                parent->stop = consumer_stop;
@@ -179,16 +185,22 @@ int consumer_start( mlt_consumer parent )
                this->running = 1;
                this->joined = 0;
 
-               if ( mlt_properties_get_int( this->properties, "width" ) > 0 )
-                       this->width = mlt_properties_get_int( this->properties, "width" );
-               if ( mlt_properties_get_int( this->properties, "height" ) > 0 )
-                       this->height = mlt_properties_get_int( this->properties, "height" );
+               if ( ! mlt_properties_get_int( this->properties, "_arg_size" ) )
+               {
+                       if ( mlt_properties_get_int( this->properties, "width" ) > 0 )
+                               this->width = mlt_properties_get_int( this->properties, "width" );
+                       if ( mlt_properties_get_int( this->properties, "height" ) > 0 )
+                               this->height = mlt_properties_get_int( this->properties, "height" );
+               }
 
                this->bpp = mlt_properties_get_int( this->properties, "bpp" );
 
                if ( sdl_started == 0 && display_off == 0 )
                {
-                       if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE ) < 0 )
+                       pthread_mutex_lock( &mlt_sdl_mutex );
+                       int ret = SDL_Init( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE );
+                       pthread_mutex_unlock( &mlt_sdl_mutex );
+                       if ( ret < 0 )
                        {
                                mlt_log_error( MLT_CONSUMER_SERVICE(parent), "Failed to initialize SDL: %s\n", SDL_GetError() );
                                return -1;
@@ -199,22 +211,35 @@ int consumer_start( mlt_consumer parent )
                }
                else if ( display_off == 0 )
                {
+                       pthread_mutex_lock( &mlt_sdl_mutex );
                        this->sdl_screen = SDL_GetVideoSurface( );
+                       pthread_mutex_unlock( &mlt_sdl_mutex );
                }
 
                if ( audio_off == 0 )
                        SDL_InitSubSystem( SDL_INIT_AUDIO );
 
                // Default window size
-               double display_ratio = mlt_properties_get_double( this->properties, "display_ratio" );
-               this->window_width = ( double )this->height * display_ratio;
-               this->window_height = this->height;
+               if ( mlt_properties_get_int( this->properties, "_arg_size" ) )
+               {
+                       this->window_width = this->width;
+                       this->window_height = this->height;
+               }
+               else
+               {
+                       double display_ratio = mlt_properties_get_double( this->properties, "display_ratio" );
+                       this->window_width = ( double )this->height * display_ratio + 0.5;
+                       this->window_height = this->height;
+               }
 
                if ( this->sdl_screen == NULL && display_off == 0 )
                {
                        if ( mlt_properties_get_int( this->properties, "fullscreen" ) )
                        {
-                               const SDL_VideoInfo *vi = SDL_GetVideoInfo();
+                               const SDL_VideoInfo *vi;
+                               pthread_mutex_lock( &mlt_sdl_mutex );
+                               vi = SDL_GetVideoInfo();
+                               pthread_mutex_unlock( &mlt_sdl_mutex );
                                this->window_width = vi->current_w;
                                this->window_height = vi->current_h;
                                this->sdl_flags |= SDL_FULLSCREEN;
@@ -241,7 +266,9 @@ int consumer_stop( mlt_consumer parent )
                // Kill the thread and clean up
                this->joined = 1;
                this->running = 0;
+#ifndef WIN32
                if ( this->thread )
+#endif
                        pthread_join( this->thread, NULL );
 
                // internal cleanup
@@ -832,6 +859,7 @@ static int consumer_get_dimensions( int *width, int *height )
        // Get the wm structure
        if ( SDL_GetWMInfo( &wm ) == 1 )
        {
+#ifndef WIN32
                // Check that we have the X11 wm
                if ( wm.subsystem == SDL_SYSWM_X11 ) 
                {
@@ -852,6 +880,7 @@ static int consumer_get_dimensions( int *width, int *height )
                        *width = attr.width;
                        *height = attr.height;
                }
+#endif
        }
 #endif