X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fsdl%2Fconsumer_sdl.c;h=07f483fd7e903f5f68b8566077f8df512053d20d;hb=a59ccd047ab1fafc417e4f577e6c858442c348b8;hp=23f1bd9e11ebb069ccc1ac4a98586704e5a387d9;hpb=66241484cc41f0af876e493bca95b48d39a271bd;p=melted diff --git a/src/modules/sdl/consumer_sdl.c b/src/modules/sdl/consumer_sdl.c index 23f1bd9..07f483f 100644 --- a/src/modules/sdl/consumer_sdl.c +++ b/src/modules/sdl/consumer_sdl.c @@ -41,7 +41,7 @@ struct consumer_sdl_s mlt_deque queue; pthread_t thread; int running; - uint8_t audio_buffer[ 4096 * 19 ]; + uint8_t audio_buffer[ 4096 * 10 ]; int audio_avail; pthread_mutex_t audio_mutex; pthread_cond_t audio_cond; @@ -51,6 +51,7 @@ struct consumer_sdl_s int window_height; float aspect_ratio; float display_aspect; + double last_frame_aspect; int width; int height; int playing; @@ -407,10 +408,11 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) } } - if ( width != this->width || height != this->height ) + if ( width != this->width || height != this->height || this->last_frame_aspect != mlt_frame_get_aspect_ratio( frame ) ) { this->width = width; this->height = height; + this->last_frame_aspect = mlt_frame_get_aspect_ratio( frame ); changed = 1; } @@ -437,7 +439,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) else { // Use hardware scaler to normalise display aspect ratio - this->rect.w = frame_aspect / this_aspect * this->window_width + 0.5; + this->rect.w = frame_aspect / this_aspect * this->window_width; this->rect.h = this->window_height; if ( this->rect.w > this->window_width ) { @@ -454,14 +456,14 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) this->rect.h = this->window_height; } // Use hardware scaler to normalise sample aspect ratio - else if ( this->window_height * frame_aspect > this->window_width ) + else if ( this->window_height * this->display_aspect > this->window_width ) { this->rect.w = this->window_width; - this->rect.h = this->window_width / frame_aspect + 0.5; + this->rect.h = this->window_width / this->display_aspect + 0.5; } else { - this->rect.w = this->window_height * frame_aspect + 0.5; + this->rect.w = this->window_height * this->display_aspect + 0.5; this->rect.h = this->window_height; } @@ -473,7 +475,9 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) SDL_FreeYUVOverlay( this->sdl_overlay ); // open SDL window with video overlay, if possible + sdl_lock_display(); this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags ); + sdl_unlock_display(); if ( this->sdl_screen != NULL ) { @@ -497,6 +501,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) if ( this->sdl_screen != NULL && this->sdl_overlay != NULL ) { this->buffer = this->sdl_overlay->pixels[ 0 ]; + sdl_lock_display(); if ( SDL_LockYUVOverlay( this->sdl_overlay ) >= 0 ) { if ( image != NULL ) @@ -504,6 +509,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) SDL_UnlockYUVOverlay( this->sdl_overlay ); SDL_DisplayYUVOverlay( this->sdl_overlay, &this->sdl_screen->clip_rect ); } + sdl_unlock_display(); } } @@ -523,7 +529,6 @@ static void *video_thread( void *arg ) mlt_frame next = NULL; mlt_properties properties = NULL; double speed = 0; - int skipped = 0; // Get the current time gettimeofday( &now, NULL ); @@ -571,11 +576,9 @@ static void *video_thread( void *arg ) // Show current frame if not too old if ( difference > -10000 || speed != 1.0 || mlt_deque_count( this->queue ) < 2 ) consumer_play_video( this, next ); - else - skipped ++; // If the queue is empty, recalculate start to allow build up again - if ( mlt_deque_count( this->queue ) == 0 ) + if ( mlt_deque_count( this->queue ) == 0 && speed == 1.0 ) { gettimeofday( &now, NULL ); start = ( ( int64_t )now.tv_sec * 1000000 + now.tv_usec ) - scheduled + 20000; @@ -693,6 +696,9 @@ static int consumer_get_dimensions( int *width, int *height ) // Specify the SDL Version SDL_VERSION( &wm.version ); + // Lock the display + sdl_lock_display(); + // Get the wm structure if ( SDL_GetWMInfo( &wm ) == 1 ) { @@ -718,6 +724,9 @@ static int consumer_get_dimensions( int *width, int *height ) } } + // Unlock the display + sdl_lock_display(); + return changed; }