X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffplay.c;h=946e9b3a308edaa652de9dd232b2cea983e387bc;hb=7ebf3ab959a02b67c9d73c8e3f74325913564140;hp=26a813b0714b2a4d6556e7eede983cc87a312a9e;hpb=73d5cf8f43786b3a643d9955e4c6499f5b391b81;p=ffmpeg diff --git a/ffplay.c b/ffplay.c index 26a813b0714..946e9b3a308 100644 --- a/ffplay.c +++ b/ffplay.c @@ -134,6 +134,7 @@ typedef struct VideoPicture { typedef struct SubPicture { double pts; /* presentation time stamp for this picture */ AVSubtitle sub; + int serial; } SubPicture; typedef struct AudioParams { @@ -212,8 +213,6 @@ typedef struct VideoState { #endif struct AudioParams audio_tgt; struct SwrContext *swr_ctx; - double audio_current_pts; - double audio_current_pts_drift; int frame_drops_early; int frame_drops_late; AVFrame *frame; @@ -232,7 +231,6 @@ typedef struct VideoState { SDL_Thread *subtitle_tid; int subtitle_stream; - int subtitle_stream_changed; AVStream *subtitle_st; PacketQueue subtitleq; SubPicture subpq[SUBPICTURE_QUEUE_SIZE]; @@ -251,8 +249,6 @@ typedef struct VideoState { int video_stream; AVStream *video_st; PacketQueue videoq; - double video_current_pts; // current displayed pts - double video_current_pts_drift; // video_current_pts - time (av_gettime) at which we updated video_current_pts - used to have running video pts int64_t video_current_pos; // current displayed file pos double max_frame_duration; // maximum duration of a frame - above this, we consider the jump a timestamp discontinuity VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE]; @@ -1404,24 +1400,7 @@ retry: } if (is->subtitle_st) { - if (is->subtitle_stream_changed) { - SDL_LockMutex(is->subpq_mutex); - - while (is->subpq_size) { - free_subpicture(&is->subpq[is->subpq_rindex]); - - /* update queue size and signal for next picture */ - if (++is->subpq_rindex == SUBPICTURE_QUEUE_SIZE) - is->subpq_rindex = 0; - - is->subpq_size--; - } - is->subtitle_stream_changed = 0; - - SDL_CondSignal(is->subpq_cond); - SDL_UnlockMutex(is->subpq_mutex); - } else { - if (is->subpq_size > 0) { + while (is->subpq_size > 0) { sp = &is->subpq[is->subpq_rindex]; if (is->subpq_size > 1) @@ -1429,8 +1408,9 @@ retry: else sp2 = NULL; - if ((is->video_current_pts > (sp->pts + ((float) sp->sub.end_display_time / 1000))) - || (sp2 && is->video_current_pts > (sp2->pts + ((float) sp2->sub.start_display_time / 1000)))) + if (sp->serial != is->subtitleq.serial + || (is->vidclk.pts > (sp->pts + ((float) sp->sub.end_display_time / 1000))) + || (sp2 && is->vidclk.pts > (sp2->pts + ((float) sp2->sub.start_display_time / 1000)))) { free_subpicture(sp); @@ -1442,9 +1422,10 @@ retry: is->subpq_size--; SDL_CondSignal(is->subpq_cond); SDL_UnlockMutex(is->subpq_mutex); + } else { + break; } } - } } display: @@ -1518,7 +1499,7 @@ static void alloc_picture(VideoState *is) SDL_YV12_OVERLAY, screen); bufferdiff = vp->bmp ? FFMAX(vp->bmp->pixels[0], vp->bmp->pixels[1]) - FFMIN(vp->bmp->pixels[0], vp->bmp->pixels[1]) : 0; - if (!vp->bmp || vp->bmp->pitches[0] < vp->width || bufferdiff < vp->height * vp->bmp->pitches[0]) { + if (!vp->bmp || vp->bmp->pitches[0] < vp->width || bufferdiff < (int64_t)vp->height * vp->bmp->pitches[0]) { /* SDL allocates a buffer smaller than requested if the video * overlay hardware is unable to support the requested size. */ av_log(NULL, AV_LOG_FATAL, @@ -2004,6 +1985,7 @@ static int subtitle_thread(void *arg) SubPicture *sp; AVPacket pkt1, *pkt = &pkt1; int got_subtitle; + int serial; double pts; int i, j; int r, g, b, y, u, v, a; @@ -2012,7 +1994,7 @@ static int subtitle_thread(void *arg) while (is->paused && !is->subtitleq.abort_request) { SDL_Delay(10); } - if (packet_queue_get(&is->subtitleq, pkt, 1, NULL) < 0) + if (packet_queue_get(&is->subtitleq, pkt, 1, &serial) < 0) break; if (pkt->data == flush_pkt.data) { @@ -2043,6 +2025,7 @@ static int subtitle_thread(void *arg) if (sp->sub.pts != AV_NOPTS_VALUE) pts = sp->sub.pts / (double)AV_TIME_BASE; sp->pts = pts; + sp->serial = serial; for (i = 0; i < sp->sub.num_rects; i++) { @@ -2637,8 +2620,6 @@ static void stream_component_close(VideoState *is, int stream_index) /* note: we also signal this mutex to make sure we deblock the video thread in all cases */ SDL_LockMutex(is->subpq_mutex); - is->subtitle_stream_changed = 1; - SDL_CondSignal(is->subpq_cond); SDL_UnlockMutex(is->subpq_mutex);