Skip to content

Commit 982102b

Browse files
authored
Simplify seek skipping logic (#1039)
1 parent 289ff5d commit 982102b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/torchcodec/_core/SingleStreamDecoder.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,11 @@ bool SingleStreamDecoder::canWeAvoidSeeking() const {
11051105
// within getFramesPlayedInRangeAudio(), when setCursorPtsInSeconds() was
11061106
// called. For more context, see [Audio Decoding Design]
11071107
return !cursorWasJustSet_;
1108+
} else if (!cursorWasJustSet_) {
1109+
// For videos, when decoding consecutive frames, we don't need to seek.
1110+
return true;
11081111
}
1112+
11091113
if (cursor_ < lastDecodedAvFramePts_) {
11101114
// We can never skip a seek if we are seeking backwards.
11111115
return false;
@@ -1181,10 +1185,8 @@ UniqueAVFrame SingleStreamDecoder::decodeAVFrame(
11811185

11821186
resetDecodeStats();
11831187

1184-
if (cursorWasJustSet_) {
1185-
maybeSeekToBeforeDesiredPts();
1186-
cursorWasJustSet_ = false;
1187-
}
1188+
maybeSeekToBeforeDesiredPts();
1189+
cursorWasJustSet_ = false;
11881190

11891191
UniqueAVFrame avFrame(av_frame_alloc());
11901192
AutoAVPacket autoAVPacket;

0 commit comments

Comments
 (0)