@@ -1072,14 +1072,13 @@ VideoDecoder::AVFrameStream VideoDecoder::decodeAVFrame(
10721072 veryFirstCall_ = false ;
10731073 goto av_read_frame_call;
10741074 }
1075- begin_loop:
10761075 ffmpegStatus =
10771076 avcodec_receive_frame (streamInfo.codecContext .get (), avFrame.get ());
10781077 printf (" output of avcodec_receive_frame: %d\n " , ffmpegStatus);
10791078
10801079 if (ffmpegStatus != AVSUCCESS && ffmpegStatus != AVERROR (EAGAIN)) {
10811080 // Non-retriable error
1082- // printf("Non-retriable error\n");
1081+ // printf("Non-retriable error\n");
10831082 break ;
10841083 }
10851084
@@ -1089,30 +1088,29 @@ VideoDecoder::AVFrameStream VideoDecoder::decodeAVFrame(
10891088 // Yes, this is the frame we'll return; break out of the decoding loop.
10901089 // printf("%ld %ld\n", avFrame->pts, avFrame->duration);
10911090
1092- // printf("Found frame\n");
1091+ // printf("Found frame\n");
10931092 break ;
10941093 } else if (ffmpegStatus == AVSUCCESS) {
10951094 // No, but we received a valid frame - just not the kind we're looking
10961095 // for. The logic below will read packets and send them to the decoder.
10971096 // But since we did just receive a frame, we should skip reading more
10981097 // packets and sending them to the decoder and just try to receive more
10991098 // frames from the decoder.
1100- // printf("Got AVSUCCESS, continue\n");
1099+ // printf("Got AVSUCCESS, continue\n");
11011100 continue ;
11021101 }
11031102
11041103 if (reachedEOF) {
1105- // We don't have any more packets to send to the decoder. So keep on
1106- // pulling frames from its internal buffers.
1107- // printf("Reached EOF, continue\n");
1104+ // We don't have any more packets to receive. So keep on pulling frames
1105+ // from its internal buffers.
11081106 continue ;
11091107 }
11101108
1109+ // We still haven't found the frame we're looking for. So let's read more
1110+ // packets and send them to the decoder.
11111111 av_read_frame_call:
11121112 ReferenceAVPacket packet (autoAVPacket);
1113- while (true ) {
1114- // We still haven't found the frame we're looking for. So let's read more
1115- // packets and send them to the decoder.
1113+ do {
11161114 ffmpegStatus = av_read_frame (formatContext_.get (), packet.get ());
11171115 decodeStats_.numPacketsRead ++;
11181116
@@ -1128,26 +1126,21 @@ VideoDecoder::AVFrameStream VideoDecoder::decodeAVFrame(
11281126 getFFMPEGErrorStringFromErrorCode (ffmpegStatus));
11291127 }
11301128
1131- // We've reached the end of file so we can't read any more packets from
1132- // it, but the decoder may still have frames to read in its buffer.
1133- // Continue iterating to try reading frames.
11341129 reachedEOF = true ;
1135- goto begin_loop;
1136- // continue;
1130+ break ;
11371131 }
11381132
11391133 if (ffmpegStatus < AVSUCCESS) {
11401134 throw std::runtime_error (
11411135 " Could not read frame from input file: " +
11421136 getFFMPEGErrorStringFromErrorCode (ffmpegStatus));
11431137 }
1138+ } while (packet->stream_index != activeStreamIndex_);
11441139
1145- if (packet->stream_index == activeStreamIndex_) {
1146- // printf("found packet for stream\n");
1147- break ;
1148- } else {
1149- // printf("Not for stream, continue\n");
1150- }
1140+ if (reachedEOF) {
1141+ // We don't have any more packets to send to the decoder. So keep on
1142+ // pulling frames from its internal buffers.
1143+ continue ;
11511144 }
11521145
11531146 // We got a valid packet. Send it to the decoder, and we'll receive it in
0 commit comments