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 {
|
| 177 | 177 | int read_pause_return; |
| 178 | 178 | AVFormatContext *ic; |
| 179 | 179 | int realtime; |
| | 180 | int audio_finished; |
| | 181 | int video_finished; |
| 180 | 182 | |
| 181 | 183 | Clock audclk; |
| 182 | 184 | Clock vidclk; |
| … |
… |
static int get_video_frame(VideoState *is, AVFrame *frame, AVPacket *pkt, int *s
|
| 1671 | 1673 | if(avcodec_decode_video2(is->video_st->codec, frame, &got_picture, pkt) < 0) |
| 1672 | 1674 | return 0; |
| 1673 | 1675 | |
| | 1676 | if (!got_picture && !pkt->data) |
| | 1677 | is->video_finished = *serial; |
| | 1678 | |
| 1674 | 1679 | if (got_picture) { |
| 1675 | 1680 | int ret = 1; |
| 1676 | 1681 | double dpts = NAN; |
| … |
… |
static int audio_decode_frame(VideoState *is)
|
| 2166 | 2171 | pkt_temp->size -= len1; |
| 2167 | 2172 | if (pkt_temp->data && pkt_temp->size <= 0 || !pkt_temp->data && !got_frame) |
| 2168 | 2173 | pkt_temp->stream_index = -1; |
| | 2174 | if (!pkt_temp->data && !got_frame) |
| | 2175 | is->audio_finished = is->audio_pkt_temp_serial; |
| 2169 | 2176 | |
| 2170 | 2177 | if (!got_frame) |
| 2171 | 2178 | continue; |
| … |
… |
static int read_thread(void *arg)
|
| 2895 | 2902 | SDL_UnlockMutex(wait_mutex); |
| 2896 | 2903 | continue; |
| 2897 | 2904 | } |
| | 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 | } |
| 2898 | 2914 | if (eof) { |
| 2899 | 2915 | if (is->video_stream >= 0) { |
| 2900 | 2916 | av_init_packet(pkt); |
| … |
… |
static int read_thread(void *arg)
|
| 2911 | 2927 | packet_queue_put(&is->audioq, pkt); |
| 2912 | 2928 | } |
| 2913 | 2929 | 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 | | } |
| 2922 | 2930 | eof=0; |
| 2923 | 2931 | continue; |
| 2924 | 2932 | } |