/*
* 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;
// 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 );
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->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;
}
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;
// 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
// 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 )
{
}
sdl_unlock_display();
+ mlt_cocoa_autorelease_close( pool );
+ mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
}
else if ( this->running )
{
// Get the wm structure
if ( SDL_GetWMInfo( &wm ) == 1 )
{
+#ifndef WIN32
// Check that we have the X11 wm
if ( wm.subsystem == SDL_SYSWM_X11 )
{
*width = attr.width;
*height = attr.height;
}
+#endif
}
#endif