---
 avplay.c |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/avplay.c b/avplay.c
index 198dce1..c94aaf7 100644
--- a/avplay.c
+++ b/avplay.c
@@ -2008,10 +2008,13 @@ static int audio_decode_frame(VideoState *is, double 
*pts_ptr)
     AVCodecContext *dec= is->audio_st->codec;
     int n, len1, data_size;
     double pts;
+    int new_packet = 0;
+    int flush_complete = 0;
 
     for(;;) {
         /* NOTE: the audio packet can contain several frames */
-        while (pkt_temp->size > 0) {
+        while (pkt_temp->size > 0 || (!pkt_temp->data && new_packet)) {
+            new_packet = 0;
             data_size = sizeof(is->audio_buf1);
             len1 = avcodec_decode_audio3(dec,
                                         (int16_t *)is->audio_buf1, &data_size,
@@ -2024,8 +2027,11 @@ static int audio_decode_frame(VideoState *is, double 
*pts_ptr)
 
             pkt_temp->data += len1;
             pkt_temp->size -= len1;
-            if (data_size <= 0)
+            if (data_size <= 0) {
+                if (pkt_temp->size <= 0)
+                    flush_complete = 1;
                 continue;
+            }
 
             if (dec->sample_fmt != is->audio_src_fmt) {
                 if (is->reformat_ctx)
@@ -2085,11 +2091,19 @@ static int audio_decode_frame(VideoState *is, double 
*pts_ptr)
             return -1;
         }
 
+        /* if decoder flush is complete, empty packet queue */
+        if (flush_complete) {
+            packet_queue_flush(&is->audioq);
+            continue;
+        }
+
         /* read next packet */
-        if (packet_queue_get(&is->audioq, pkt, 1) < 0)
+        if ((new_packet = packet_queue_get(&is->audioq, pkt, 1)) < 0)
             return -1;
+
         if(pkt->data == flush_pkt.data){
             avcodec_flush_buffers(dec);
+            new_packet = 0;
             continue;
         }
 
@@ -2508,6 +2522,13 @@ static int decode_thread(void *arg)
                 pkt->stream_index= is->video_stream;
                 packet_queue_put(&is->videoq, pkt);
             }
+            if (is->audio_stream >= 0) {
+                av_init_packet(pkt);
+                pkt->data = NULL;
+                pkt->size = 0;
+                pkt->stream_index = is->audio_stream;
+                packet_queue_put(&is->audioq, pkt);
+            }
             SDL_Delay(10);
             if(is->audioq.size + is->videoq.size + is->subtitleq.size ==0){
                 if(loop!=1 && (!loop || --loop)){
-- 
1.7.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to