+ mlt_properties properties = MLT_CONSUMER_PROPERTIES( parent );
+ int video_off = mlt_properties_get_int( properties, "video_off" );
+ int preview_off = mlt_properties_get_int( properties, "preview_off" );
+ int display_off = video_off | preview_off;
+ int audio_off = mlt_properties_get_int( properties, "audio_off" );
+ int sdl_started = mlt_properties_get_int( properties, "sdl_started" );
+ char *output_display = mlt_properties_get( properties, "output_display" );
+ char *window_id = mlt_properties_get( properties, "window_id" );
+ char *audio_driver = mlt_properties_get( properties, "audio_driver" );
+ char *video_driver = mlt_properties_get( properties, "video_driver" );
+ char *audio_device = mlt_properties_get( properties, "audio_device" );
+
+ consumer_stop( parent );
+
+ self->running = 1;
+ self->joined = 0;
+
+ if ( output_display != NULL )
+ setenv( "DISPLAY", output_display, 1 );
+
+ if ( window_id != NULL )
+ setenv( "SDL_WINDOWID", window_id, 1 );
+
+ if ( video_driver != NULL )
+ setenv( "SDL_VIDEODRIVER", video_driver, 1 );
+
+ if ( audio_driver != NULL )
+ setenv( "SDL_AUDIODRIVER", audio_driver, 1 );
+
+ if ( audio_device != NULL )
+ setenv( "AUDIODEV", audio_device, 1 );
+
+ if ( ! mlt_properties_get_int( self->properties, "_arg_size" ) )
+ {
+ if ( mlt_properties_get_int( self->properties, "width" ) > 0 )
+ self->width = mlt_properties_get_int( self->properties, "width" );
+ if ( mlt_properties_get_int( self->properties, "height" ) > 0 )
+ self->height = mlt_properties_get_int( self->properties, "height" );
+ }
+
+ self->bpp = mlt_properties_get_int( self->properties, "bpp" );
+
+ if ( sdl_started == 0 && display_off == 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;
+ }
+
+ SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
+ SDL_EnableUNICODE( 1 );
+ }
+
+ if ( audio_off == 0 )
+ SDL_InitSubSystem( SDL_INIT_AUDIO );
+
+ // Default window size
+ if ( mlt_properties_get_int( self->properties, "_arg_size" ) )
+ {
+ self->window_width = self->width;
+ self->window_height = self->height;
+ }
+ else
+ {
+ double display_ratio = mlt_properties_get_double( self->properties, "display_ratio" );
+ self->window_width = ( double )self->height * display_ratio + 0.5;
+ self->window_height = self->height;
+ }
+
+ pthread_mutex_lock( &mlt_sdl_mutex );
+ if ( !SDL_GetVideoSurface() && display_off == 0 )
+ {
+ if ( mlt_properties_get_int( self->properties, "fullscreen" ) )
+ {
+ const SDL_VideoInfo *vi;
+ vi = SDL_GetVideoInfo();
+ self->window_width = vi->current_w;
+ self->window_height = vi->current_h;
+ self->sdl_flags |= SDL_FULLSCREEN;
+ SDL_ShowCursor( SDL_DISABLE );
+ }
+ SDL_SetVideoMode( self->window_width, self->window_height, 0, self->sdl_flags );
+ }
+ pthread_mutex_unlock( &mlt_sdl_mutex );
+
+ pthread_create( &self->thread, NULL, consumer_thread, self );