Skip to content

Commit f20d6f2

Browse files
committed
Address comments
1 parent d87189f commit f20d6f2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,6 @@ VideoDecoder::AVFrameStream VideoDecoder::decodeAVFrame(
948948
int ffmpegStatus = AVSUCCESS;
949949
bool reachedEOF = false;
950950
while (true) {
951-
outerLoopStart:
952951
ffmpegStatus =
953952
avcodec_receive_frame(streamInfo.codecContext.get(), avFrame.get());
954953

@@ -972,16 +971,15 @@ VideoDecoder::AVFrameStream VideoDecoder::decodeAVFrame(
972971
}
973972

974973
if (reachedEOF) {
975-
// We don't have any more packets to send to the decoder. So keep on
976-
// pulling frames from its internal buffers.
974+
// We don't have any more packets to receive. So keep on pulling frames
975+
// from its internal buffers.
977976
continue;
978977
}
979978

980979
// We still haven't found the frame we're looking for. So let's read more
981980
// packets and send them to the decoder.
982981
ReferenceAVPacket packet(autoAVPacket);
983-
bool foundPacketForStream = false;
984-
while (!foundPacketForStream) {
982+
do {
985983
ffmpegStatus = av_read_frame(formatContext_.get(), packet.get());
986984
decodeStats_.numPacketsRead++;
987985

@@ -997,19 +995,21 @@ VideoDecoder::AVFrameStream VideoDecoder::decodeAVFrame(
997995
getFFMPEGErrorStringFromErrorCode(ffmpegStatus));
998996
}
999997

1000-
// We've reached the end of file so we can't read any more packets from
1001-
// it, but the decoder may still have frames to read in its buffer.
1002-
// Continue iterating to try reading frames.
1003998
reachedEOF = true;
1004-
goto outerLoopStart;
999+
break;
10051000
}
10061001

10071002
if (ffmpegStatus < AVSUCCESS) {
10081003
throw std::runtime_error(
10091004
"Could not read frame from input file: " +
10101005
getFFMPEGErrorStringFromErrorCode(ffmpegStatus));
10111006
}
1012-
foundPacketForStream = packet->stream_index == activeStreamIndex_;
1007+
} while (packet->stream_index != activeStreamIndex_);
1008+
1009+
if (reachedEOF) {
1010+
// We don't have any more packets to send to the decoder. So keep on
1011+
// pulling frames from its internal buffers.
1012+
continue;
10131013
}
10141014

10151015
// We got a valid packet. Send it to the decoder, and we'll receive it in

0 commit comments

Comments
 (0)