X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fsdl%2Fconsumer_sdl_still.c;h=ad83aa4567a8dd100cbec7545f9d8e0168140059;hb=65e8ac86ee6e17a12892954ff4a8d46c4766fe0d;hp=c0848dbec4e0b46c77bc699b6615f862df358e74;hpb=efd5f25f6fe70f75f9787e9c7f2b53730ecf6048;p=melted diff --git a/src/modules/sdl/consumer_sdl_still.c b/src/modules/sdl/consumer_sdl_still.c index c0848db..ad83aa4 100644 --- a/src/modules/sdl/consumer_sdl_still.c +++ b/src/modules/sdl/consumer_sdl_still.c @@ -113,7 +113,7 @@ mlt_consumer consumer_sdl_still_init( char *arg ) } // Default window size - this->window_width = ( float )this->height * display_ratio; + this->window_width = ( double )this->height * display_ratio; this->window_height = this->height; // Set the sdl flags @@ -175,6 +175,28 @@ static int consumer_start( mlt_consumer parent ) mlt_properties_set_int( this->properties, "height", this->height ); } + if ( mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent ), "sdl_started" ) == 0 ) + { + if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE ) < 0 ) + { + fprintf( stderr, "Failed to initialize SDL: %s\n", SDL_GetError() ); + return -1; + } + + SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); + SDL_EnableUNICODE( 1 ); + } + else + { + mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( parent ), "changed", 2 ); + if ( SDL_GetVideoSurface( ) != NULL ) + { + this->sdl_screen = SDL_GetVideoSurface( ); + consumer_get_dimensions( &this->window_width, &this->window_height ); + mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( parent ), "changed", 0 ); + } + } + pthread_create( &this->thread, NULL, consumer_thread, this ); } @@ -193,6 +215,11 @@ static int consumer_stop( mlt_consumer parent ) pthread_join( this->thread, NULL ); this->joined = 1; + + if ( mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent ), "sdl_started" ) == 0 ) + SDL_Quit( ); + + this->sdl_screen = NULL; } return 0; @@ -432,7 +459,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) char *rescale = mlt_properties_get( properties, "rescale" ); if ( rescale != NULL && strcmp( rescale, "none" ) ) { - float this_aspect = display_ratio / ( ( float )this->window_width / ( float )this->window_height ); + double this_aspect = display_ratio / ( ( double )this->window_width / ( double )this->window_height ); this->rect.w = this_aspect * this->window_width; this->rect.h = this->window_height; if ( this->rect.w > this->window_width ) @@ -443,7 +470,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) } else { - float frame_aspect = mlt_frame_get_aspect_ratio( frame ) * width / height; + double frame_aspect = mlt_frame_get_aspect_ratio( frame ) * width / height; this->rect.w = frame_aspect * this->window_height; this->rect.h = this->window_height; if ( this->rect.w > this->window_width ) @@ -510,28 +537,6 @@ static void *consumer_thread( void *arg ) // internal intialization mlt_frame frame = NULL; - if ( mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "sdl_started" ) == 0 ) - { - if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE ) < 0 ) - { - fprintf( stderr, "Failed to initialize SDL: %s\n", SDL_GetError() ); - return NULL; - } - - SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); - SDL_EnableUNICODE( 1 ); - } - else - { - mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "changed", 2 ); - if ( SDL_GetVideoSurface( ) != NULL ) - { - this->sdl_screen = SDL_GetVideoSurface( ); - consumer_get_dimensions( &this->window_width, &this->window_height ); - mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "changed", 0 ); - } - } - // Loop until told not to while( this->running ) { @@ -539,22 +544,18 @@ static void *consumer_thread( void *arg ) frame = mlt_consumer_rt_frame( consumer ); // Ensure that we have a frame - if ( frame != NULL ) + if ( this->running && frame != NULL ) { consumer_play_video( this, frame ); mlt_frame_close( frame ); } else { + if ( frame ) mlt_frame_close( frame ); this->running = 0; } } - if ( mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "sdl_started" ) == 0 ) - SDL_Quit( ); - - this->sdl_screen = NULL; - return NULL; }