[FFmpeg-devel] [PATCH] ffplay: force refresh event when the SDL window is resized

Stefano Sabatini stefano.sabatini-lala at poste.it
Mon Apr 11 19:23:48 CEST 2011


Address roundup issue #604, #1031, #1804.
---
 ffplay.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/ffplay.c b/ffplay.c
index 5032586..a6d2cd2 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -132,6 +132,7 @@ typedef struct VideoState {
     AVInputFormat *iformat;
     int no_background;
     int abort_request;
+    int force_refresh;
     int paused;
     int last_paused;
     int seek_req;
@@ -1119,9 +1120,15 @@ static void video_refresh_timer(void *opaque)
 
     if (is->video_st) {
 retry:
-        if (is->pictq_size == 0) {
-            //nothing to do, no picture to display in the que
-        } else {
+        if (is->pictq_size == 0 && is->force_refresh) {
+            // display last picture in the queue
+            SDL_LockMutex(is->pictq_mutex);
+            is->pictq_size++;
+            is->pictq_rindex = (is->pictq_rindex + VIDEO_PICTURE_QUEUE_SIZE -1) % VIDEO_PICTURE_QUEUE_SIZE;
+            SDL_CondSignal(is->pictq_cond);
+            SDL_UnlockMutex(is->pictq_mutex);
+        }
+        if (is->pictq_size) {
             double time= av_gettime()/1000000.0;
             double next_target;
             /* dequeue the picture */
@@ -1140,7 +1147,7 @@ retry:
             }else{
                 next_target= vp->target_clock + is->video_clock - vp->pts; //FIXME pass durations cleanly
             }
-            if(framedrop && time > next_target){
+            if (framedrop && !is->force_refresh && time > next_target) {
                 is->skip_frames *= 1.0 + FRAME_SKIP_FACTOR;
                 if(is->pictq_size > 1 || time > next_target + 0.5){
                     /* update queue size and signal for next picture */
@@ -1211,6 +1218,7 @@ retry:
             is->pictq_size--;
             SDL_CondSignal(is->pictq_cond);
             SDL_UnlockMutex(is->pictq_mutex);
+            is->force_refresh = 0;
         }
     } else if (is->audio_st) {
         /* draw the next audio frame */
@@ -2759,6 +2767,8 @@ static void event_loop(void)
                 break;
             case SDLK_f:
                 toggle_full_screen();
+                if (cur_stream)
+                    cur_stream->force_refresh = 1;
                 break;
             case SDLK_p:
             case SDLK_SPACE:
@@ -2813,6 +2823,7 @@ static void event_loop(void)
                         pos += incr;
                         stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), (int64_t)(incr * AV_TIME_BASE), 0);
                     }
+                    cur_stream->force_refresh = 1;
                 }
                 break;
             default:
@@ -2864,6 +2875,7 @@ static void event_loop(void)
                                           SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL);
                 screen_width = cur_stream->width = event.resize.w;
                 screen_height= cur_stream->height= event.resize.h;
+                cur_stream->force_refresh = 1;
             }
             break;
         case SDL_QUIT:
@@ -2881,6 +2893,12 @@ static void event_loop(void)
         default:
             break;
         }
+
+        if (cur_stream && cur_stream->force_refresh) {
+            event.type = FF_REFRESH_EVENT;
+            event.user.data1 = cur_stream;
+            SDL_PushEvent(&event);
+        }
     }
 }
 
-- 
1.7.2.3



More information about the ffmpeg-devel mailing list