@@ -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() {
15101511VideoDecoder::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 });
0 commit comments