]> git.sesse.net Git - mlt/blobdiff - src/modules/sdl/consumer_sdl.c
Initial port to Windows using MinGW.
[mlt] / src / modules / sdl / consumer_sdl.c
index 1e285dc8b8501b970e1dc08bbe8241fa26d814fe..92957cdf2375d1ce1d99433f4ae90b79fb04a253 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
 #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"
 
 extern pthread_mutex_t mlt_sdl_mutex;
 
@@ -115,6 +116,7 @@ mlt_consumer consumer_sdl_init( mlt_profile profile, mlt_service_type type, cons
                
                // Default scaler (for now we'll use nearest)
                mlt_properties_set( this->properties, "rescale", "nearest" );
+               mlt_properties_set( this->properties, "deinterlace_method", "onefield" );
 
                // Default buffer for low latency
                mlt_properties_set_int( this->properties, "buffer", 1 );
@@ -126,12 +128,16 @@ 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;
 
@@ -177,16 +183,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;
@@ -197,22 +209,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;
+                       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;
@@ -239,7 +264,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
@@ -460,8 +487,9 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
                // Get the image, width and height
                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 );
                
+               void *pool = mlt_cocoa_autorelease_init();
+
                // Handle events
                if ( this->sdl_screen != NULL )
                {
@@ -609,6 +637,8 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
                }
 
                sdl_unlock_display();
+               mlt_cocoa_autorelease_close( pool );
+               mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
        }
        else if ( this->running )
        {
@@ -827,6 +857,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 ) 
                {
@@ -847,6 +878,7 @@ static int consumer_get_dimensions( int *width, int *height )
                        *width = attr.width;
                        *height = attr.height;
                }
+#endif
        }
 #endif