Browse code

ffplay: simplify audio decoding

Also use negative stream_index for signaling obsolete audio packets. Using the
size alone is not enough, because size is 0 for null packets as well.

Signed-off-by: Marton Balint <cus@passwd.hu>

Marton Balint authored on 2013/07/03 08:58:15
Showing 1 changed files
... ...
@@ -2128,8 +2128,6 @@ static int audio_decode_frame(VideoState *is)
2128 2128
     int64_t dec_channel_layout;
2129 2129
     int got_frame;
2130 2130
     av_unused double audio_clock0;
2131
-    int new_packet = 0;
2132
-    int flush_complete = 0;
2133 2131
     int wanted_nb_samples;
2134 2132
     AVRational tb;
2135 2133
     int ret;
... ...
@@ -2137,7 +2135,7 @@ static int audio_decode_frame(VideoState *is)
2137 2137
 
2138 2138
     for (;;) {
2139 2139
         /* NOTE: the audio packet can contain several frames */
2140
-        while (pkt_temp->size > 0 || (!pkt_temp->data && new_packet) || is->audio_buf_frames_pending) {
2140
+        while (pkt_temp->stream_index != -1 || is->audio_buf_frames_pending) {
2141 2141
             if (!is->frame) {
2142 2142
                 if (!(is->frame = avcodec_alloc_frame()))
2143 2143
                     return AVERROR(ENOMEM);
... ...
@@ -2153,9 +2151,6 @@ static int audio_decode_frame(VideoState *is)
2153 2153
                 return -1;
2154 2154
 
2155 2155
             if (!is->audio_buf_frames_pending) {
2156
-                if (flush_complete)
2157
-                    break;
2158
-                new_packet = 0;
2159 2156
                 len1 = avcodec_decode_audio4(dec, is->frame, &got_frame, pkt_temp);
2160 2157
                 if (len1 < 0) {
2161 2158
                     /* if error, we skip the frame */
... ...
@@ -2165,13 +2160,11 @@ static int audio_decode_frame(VideoState *is)
2165 2165
 
2166 2166
                 pkt_temp->data += len1;
2167 2167
                 pkt_temp->size -= len1;
2168
+                if (pkt_temp->data && pkt_temp->size <= 0 || !pkt_temp->data && !got_frame)
2169
+                    pkt_temp->stream_index = -1;
2168 2170
 
2169
-                if (!got_frame) {
2170
-                    /* stop sending empty packets if the decoder is finished */
2171
-                    if (!pkt_temp->data && dec->codec->capabilities & CODEC_CAP_DELAY)
2172
-                        flush_complete = 1;
2171
+                if (!got_frame)
2173 2172
                     continue;
2174
-                }
2175 2173
 
2176 2174
                 tb = (AVRational){1, is->frame->sample_rate};
2177 2175
                 if (is->frame->pts != AV_NOPTS_VALUE)
... ...
@@ -2317,6 +2310,7 @@ static int audio_decode_frame(VideoState *is)
2317 2317
         if (pkt->data)
2318 2318
             av_free_packet(pkt);
2319 2319
         memset(pkt_temp, 0, sizeof(*pkt_temp));
2320
+        pkt_temp->stream_index = -1;
2320 2321
 
2321 2322
         if (is->audioq.abort_request) {
2322 2323
             return -1;
... ...
@@ -2326,12 +2320,11 @@ static int audio_decode_frame(VideoState *is)
2326 2326
             SDL_CondSignal(is->continue_read_thread);
2327 2327
 
2328 2328
         /* read next packet */
2329
-        if ((new_packet = packet_queue_get(&is->audioq, pkt, 1, &is->audio_pkt_temp_serial)) < 0)
2329
+        if ((packet_queue_get(&is->audioq, pkt, 1, &is->audio_pkt_temp_serial)) < 0)
2330 2330
             return -1;
2331 2331
 
2332 2332
         if (pkt->data == flush_pkt.data) {
2333 2333
             avcodec_flush_buffers(dec);
2334
-            flush_complete = 0;
2335 2334
             is->audio_buf_frames_pending = 0;
2336 2335
         }
2337 2336
 
... ...
@@ -2541,6 +2534,7 @@ static int stream_component_open(VideoState *is, int stream_index)
2541 2541
 
2542 2542
         memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
2543 2543
         memset(&is->audio_pkt_temp, 0, sizeof(is->audio_pkt_temp));
2544
+        is->audio_pkt_temp.stream_index = -1;
2544 2545
 
2545 2546
         is->audio_stream = stream_index;
2546 2547
         is->audio_st = ic->streams[stream_index];