Ticket #2783: 0001-ffplay-ensure-we-got-the-last-frame-from-the-decoder.patch

File 0001-ffplay-ensure-we-got-the-last-frame-from-the-decoder.patch, 2.7 KB (added by Marton Balint, 13 years ago)
  • ffplay.c

    From 640b02ed04a36467cf8fc28eee139678c04fbea2 Mon Sep 17 00:00:00 2001
    From: Marton Balint <cus@passwd.hu>
    Date: Tue, 16 Jul 2013 03:04:22 +0200
    Subject: [PATCH] ffplay: ensure we got the last frame from the decoder before
     exiting or looping
    
    Signed-off-by: Marton Balint <cus@passwd.hu>
    ---
     ffplay.c | 24 ++++++++++++++++--------
     1 file changed, 16 insertions(+), 8 deletions(-)
    
    diff --git a/ffplay.c b/ffplay.c
    index d462eee..ea0ebdc 100644
    a b typedef struct VideoState {  
    177177    int read_pause_return;
    178178    AVFormatContext *ic;
    179179    int realtime;
     180    int audio_finished;
     181    int video_finished;
    180182
    181183    Clock audclk;
    182184    Clock vidclk;
    static int get_video_frame(VideoState *is, AVFrame *frame, AVPacket *pkt, int *s  
    16711673    if(avcodec_decode_video2(is->video_st->codec, frame, &got_picture, pkt) < 0)
    16721674        return 0;
    16731675
     1676    if (!got_picture && !pkt->data)
     1677        is->video_finished = *serial;
     1678
    16741679    if (got_picture) {
    16751680        int ret = 1;
    16761681        double dpts = NAN;
    static int audio_decode_frame(VideoState *is)  
    21662171                pkt_temp->size -= len1;
    21672172                if (pkt_temp->data && pkt_temp->size <= 0 || !pkt_temp->data && !got_frame)
    21682173                    pkt_temp->stream_index = -1;
     2174                if (!pkt_temp->data && !got_frame)
     2175                    is->audio_finished = is->audio_pkt_temp_serial;
    21692176
    21702177                if (!got_frame)
    21712178                    continue;
    static int read_thread(void *arg)  
    28952902            SDL_UnlockMutex(wait_mutex);
    28962903            continue;
    28972904        }
     2905        if ((!is->audio_st || is->audio_finished == is->audioq.serial) &&
     2906            (!is->video_st || is->video_finished == is->videoq.serial)) {
     2907            if (loop != 1 && (!loop || --loop)) {
     2908                stream_seek(is, start_time != AV_NOPTS_VALUE ? start_time : 0, 0, 0);
     2909            } else if (autoexit) {
     2910                ret = AVERROR_EOF;
     2911                goto fail;
     2912            }
     2913        }
    28982914        if (eof) {
    28992915            if (is->video_stream >= 0) {
    29002916                av_init_packet(pkt);
    static int read_thread(void *arg)  
    29112927                packet_queue_put(&is->audioq, pkt);
    29122928            }
    29132929            SDL_Delay(10);
    2914             if (is->audioq.size + is->videoq.size + is->subtitleq.size == 0) {
    2915                 if (loop != 1 && (!loop || --loop)) {
    2916                     stream_seek(is, start_time != AV_NOPTS_VALUE ? start_time : 0, 0, 0);
    2917                 } else if (autoexit) {
    2918                     ret = AVERROR_EOF;
    2919                     goto fail;
    2920                 }
    2921             }
    29222930            eof=0;
    29232931            continue;
    29242932        }