From: lilo_booter Date: Fri, 26 Dec 2003 09:52:28 +0000 (+0000) Subject: SDL updates and resizing fix X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=bbc63e064f2874ea16a4c8cf0e6331fb73f3ffb5;p=melted SDL updates and resizing fix git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@17 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/mlt/src/modules/core/filter_resize.c b/mlt/src/modules/core/filter_resize.c index 1ebb741..dab7fdf 100644 --- a/mlt/src/modules/core/filter_resize.c +++ b/mlt/src/modules/core/filter_resize.c @@ -22,6 +22,7 @@ #include +#include #include #include @@ -33,6 +34,10 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * int owidth = *width; int oheight = *height; mlt_frame_get_image( this, image, format, &owidth, &oheight, 0 ); + if ( *width == 0 ) + *width = 720; + if ( *height == 0 ) + *height = 576; if ( !strcmp( mlt_properties_get( mlt_frame_properties( this ), "resize.scale" ), "affine" ) ) *image = mlt_frame_rescale_yuv422( this, *width, *height ); else diff --git a/mlt/src/modules/sdl/consumer_sdl.c b/mlt/src/modules/sdl/consumer_sdl.c index 764cab3..2d70b90 100644 --- a/mlt/src/modules/sdl/consumer_sdl.c +++ b/mlt/src/modules/sdl/consumer_sdl.c @@ -53,7 +53,7 @@ struct consumer_sdl_s static void consumer_close( mlt_consumer parent ); static void *consumer_thread( void * ); -static void consumer_get_dimensions( int *width, int *height ); +static int consumer_get_dimensions( int *width, int *height ); /** This is what will be called by the factory - anything can be passed in via the argument, but keep it simple. @@ -202,6 +202,7 @@ static void *consumer_thread( void *arg ) int samples; int frequency; int16_t *pcm; + int changed = 0; mlt_frame_get_audio( frame, &pcm, &afmt, &frequency, &channels, &samples ); if ( init_audio == 1 ) @@ -234,33 +235,56 @@ static void *consumer_thread( void *arg ) // Get the image, width and height mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 ); - if ( width != this->window_width || height != this->window_height ) + + if ( sdl_screen != NULL ) { - SDL_Rect rect; - this->window_width = rect.w = width; - this->window_height = rect.h = height; + SDL_Event event; - // open SDL window with video overlay, if possible - if ( sdl_screen == NULL ) - sdl_screen = SDL_SetVideoMode( width, height, 0, sdl_flags ); - if ( sdl_screen != NULL ) + changed = consumer_get_dimensions( &this->window_width, &this->window_height ); + + while ( SDL_PollEvent( &event ) ) + { + switch( event.type ) + { + case SDL_VIDEORESIZE: + this->window_width = event.resize.w; + this->window_height = event.resize.h; + changed = 1; + break; + } + } + } + + if ( sdl_screen == NULL || changed ) + { + double aspect_ratio = mlt_frame_get_aspect_ratio( frame ); + + if ( this->window_width == 0 || this->window_height == 0 ) { - rect.x = rect.y = 0; + this->window_width = width; + this->window_height = height; + } + // open SDL window with video overlay, if possible + sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, sdl_flags ); - // XXX: this is a little hack until we have some sort of aspect - // ratio property on images. - if ( rect.h <= 486 ) + if ( sdl_screen != NULL ) + { + SDL_Rect rect; + if ( this->window_width < this->window_height * aspect_ratio ) { - rect.w = 640; - rect.x = ( 720 - 640 ) / 2; + rect.w = this->window_width; + rect.h = this->window_width / aspect_ratio; } else { - rect.h = 540; - rect.y = ( 576 - 540 ) / 2; + rect.w = this->window_height * aspect_ratio; + rect.h = this->window_height; } + rect.x = ( this->window_width - rect.w ) / 2; + rect.y = ( this->window_height - rect.h ) / 2; + SDL_SetClipRect( sdl_screen, &rect ); // Force an overlay recreation @@ -310,8 +334,10 @@ static void *consumer_thread( void *arg ) return NULL; } -static void consumer_get_dimensions( int *width, int *height ) +static int consumer_get_dimensions( int *width, int *height ) { + int changed = 0; + // SDL windows manager structure SDL_SysWMinfo wm; @@ -334,11 +360,16 @@ static void consumer_get_dimensions( int *width, int *height ) XWindowAttributes attr; XGetWindowAttributes( display, window, &attr ); + // Determine whether window has changed + changed = *width != attr.width || *height != attr.height; + // Return width and height *width = attr.width; *height = attr.height; } } + + return changed; } /** Callback to allow override of the close method. diff --git a/src/modules/core/filter_resize.c b/src/modules/core/filter_resize.c index 1ebb741..dab7fdf 100644 --- a/src/modules/core/filter_resize.c +++ b/src/modules/core/filter_resize.c @@ -22,6 +22,7 @@ #include +#include #include #include @@ -33,6 +34,10 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * int owidth = *width; int oheight = *height; mlt_frame_get_image( this, image, format, &owidth, &oheight, 0 ); + if ( *width == 0 ) + *width = 720; + if ( *height == 0 ) + *height = 576; if ( !strcmp( mlt_properties_get( mlt_frame_properties( this ), "resize.scale" ), "affine" ) ) *image = mlt_frame_rescale_yuv422( this, *width, *height ); else diff --git a/src/modules/sdl/consumer_sdl.c b/src/modules/sdl/consumer_sdl.c index 764cab3..2d70b90 100644 --- a/src/modules/sdl/consumer_sdl.c +++ b/src/modules/sdl/consumer_sdl.c @@ -53,7 +53,7 @@ struct consumer_sdl_s static void consumer_close( mlt_consumer parent ); static void *consumer_thread( void * ); -static void consumer_get_dimensions( int *width, int *height ); +static int consumer_get_dimensions( int *width, int *height ); /** This is what will be called by the factory - anything can be passed in via the argument, but keep it simple. @@ -202,6 +202,7 @@ static void *consumer_thread( void *arg ) int samples; int frequency; int16_t *pcm; + int changed = 0; mlt_frame_get_audio( frame, &pcm, &afmt, &frequency, &channels, &samples ); if ( init_audio == 1 ) @@ -234,33 +235,56 @@ static void *consumer_thread( void *arg ) // Get the image, width and height mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 ); - if ( width != this->window_width || height != this->window_height ) + + if ( sdl_screen != NULL ) { - SDL_Rect rect; - this->window_width = rect.w = width; - this->window_height = rect.h = height; + SDL_Event event; - // open SDL window with video overlay, if possible - if ( sdl_screen == NULL ) - sdl_screen = SDL_SetVideoMode( width, height, 0, sdl_flags ); - if ( sdl_screen != NULL ) + changed = consumer_get_dimensions( &this->window_width, &this->window_height ); + + while ( SDL_PollEvent( &event ) ) + { + switch( event.type ) + { + case SDL_VIDEORESIZE: + this->window_width = event.resize.w; + this->window_height = event.resize.h; + changed = 1; + break; + } + } + } + + if ( sdl_screen == NULL || changed ) + { + double aspect_ratio = mlt_frame_get_aspect_ratio( frame ); + + if ( this->window_width == 0 || this->window_height == 0 ) { - rect.x = rect.y = 0; + this->window_width = width; + this->window_height = height; + } + // open SDL window with video overlay, if possible + sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, sdl_flags ); - // XXX: this is a little hack until we have some sort of aspect - // ratio property on images. - if ( rect.h <= 486 ) + if ( sdl_screen != NULL ) + { + SDL_Rect rect; + if ( this->window_width < this->window_height * aspect_ratio ) { - rect.w = 640; - rect.x = ( 720 - 640 ) / 2; + rect.w = this->window_width; + rect.h = this->window_width / aspect_ratio; } else { - rect.h = 540; - rect.y = ( 576 - 540 ) / 2; + rect.w = this->window_height * aspect_ratio; + rect.h = this->window_height; } + rect.x = ( this->window_width - rect.w ) / 2; + rect.y = ( this->window_height - rect.h ) / 2; + SDL_SetClipRect( sdl_screen, &rect ); // Force an overlay recreation @@ -310,8 +334,10 @@ static void *consumer_thread( void *arg ) return NULL; } -static void consumer_get_dimensions( int *width, int *height ) +static int consumer_get_dimensions( int *width, int *height ) { + int changed = 0; + // SDL windows manager structure SDL_SysWMinfo wm; @@ -334,11 +360,16 @@ static void consumer_get_dimensions( int *width, int *height ) XWindowAttributes attr; XGetWindowAttributes( display, window, &attr ); + // Determine whether window has changed + changed = *width != attr.width || *height != attr.height; + // Return width and height *width = attr.width; *height = attr.height; } } + + return changed; } /** Callback to allow override of the close method.