Skip to content

Commit 79fc3f5

Browse files
committed
Tweak comments
1 parent d93fd4a commit 79fc3f5

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ void VideoDecoder::maybeSeekToBeforeDesiredPts() {
803803
}
804804
}
805805

806-
VideoDecoder::AVFrameStream VideoDecoder::filteredDecode(
807-
std::function<bool(int, AVFrame*)> filter) {
806+
VideoDecoder::AVFrameStream VideoDecoder::decodeAVFrame(
807+
std::function<bool(int, AVFrame*)> filterFunction) {
808808
if (activeStreamIndices_.size() == 0) {
809809
throw std::runtime_error("No active streams configured.");
810810
}
@@ -827,19 +827,19 @@ VideoDecoder::AVFrameStream VideoDecoder::filteredDecode(
827827
frameStreamIndex = -1;
828828
bool gotPermanentErrorOnAnyActiveStream = false;
829829

830-
// Get a frame on an active stream.
830+
// Get a frame on an active stream. Note that we don't know ahead of time
831+
// which streams have frames to receive, so we linearly try the active
832+
// streams.
831833
for (int streamIndex : activeStreamIndices_) {
832834
StreamInfo& streamInfo = streamInfos_[streamIndex];
833835
ffmpegStatus =
834836
avcodec_receive_frame(streamInfo.codecContext.get(), avFrame.get());
835837

836-
// Did we hit any non-retryable errors?
837838
if (ffmpegStatus != AVSUCCESS && ffmpegStatus != AVERROR(EAGAIN)) {
838839
gotPermanentErrorOnAnyActiveStream = true;
839840
break;
840841
}
841842

842-
// Found one!
843843
if (ffmpegStatus == AVSUCCESS) {
844844
frameStreamIndex = streamIndex;
845845
break;
@@ -853,7 +853,8 @@ VideoDecoder::AVFrameStream VideoDecoder::filteredDecode(
853853
decodeStats_.numFramesReceivedByDecoder++;
854854

855855
// Is this the kind of frame we're looking for?
856-
if (ffmpegStatus == AVSUCCESS && filter(frameStreamIndex, avFrame.get())) {
856+
if (ffmpegStatus == AVSUCCESS &&
857+
filterFunction(frameStreamIndex, avFrame.get())) {
857858
// Yes, this is the frame we'll return; break out of the decoding loop.
858859
break;
859860
} else if (ffmpegStatus == AVSUCCESS) {
@@ -1109,7 +1110,7 @@ VideoDecoder::FrameOutput VideoDecoder::getFramePlayedAtNoDemux(
11091110

11101111
setCursorPtsInSeconds(seconds);
11111112
AVFrameStream avFrameStream =
1112-
filteredDecode([seconds, this](int frameStreamIndex, AVFrame* avFrame) {
1113+
decodeAVFrame([seconds, this](int frameStreamIndex, AVFrame* avFrame) {
11131114
StreamInfo& streamInfo = streamInfos_[frameStreamIndex];
11141115
double frameStartTime = ptsToSeconds(avFrame->pts, streamInfo.timeBase);
11151116
double frameEndTime = ptsToSeconds(
@@ -1510,7 +1511,7 @@ VideoDecoder::FrameOutput VideoDecoder::getNextFrameNoDemux() {
15101511
VideoDecoder::FrameOutput VideoDecoder::getNextFrameNoDemuxInternal(
15111512
std::optional<torch::Tensor> preAllocatedOutputTensor) {
15121513
AVFrameStream avFrameStream =
1513-
filteredDecode([this](int frameStreamIndex, AVFrame* avFrame) {
1514+
decodeAVFrame([this](int frameStreamIndex, AVFrame* avFrame) {
15141515
StreamInfo& activeStreamInfo = streamInfos_[frameStreamIndex];
15151516
return avFrame->pts >= activeStreamInfo.discardFramesBeforePts;
15161517
});

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ class VideoDecoder {
404404
const enum AVColorSpace colorspace);
405405

406406
void maybeSeekToBeforeDesiredPts();
407-
AVFrameStream filteredDecode(std::function<bool(int, AVFrame*)>);
407+
AVFrameStream decodeAVFrame(
408+
std::function<bool(int, AVFrame*)> filterFunction);
408409
// Once we create a decoder can update the metadata with the codec context.
409410
// For example, for video streams, we can add the height and width of the
410411
// decoded stream.

0 commit comments

Comments
 (0)