Skip to content

Commit f352cfc

Browse files
committed
Use NO_ACTIVE_STREAM
1 parent 780469b commit f352cfc

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,9 @@ int VideoDecoder::getBestStreamIndex(AVMediaType mediaType) {
435435
void VideoDecoder::addVideoStreamDecoder(
436436
int preferredStreamIndex,
437437
const VideoStreamOptions& videoStreamOptions) {
438-
TORCH_CHECK(activeStreamIndex_ == -1, "Can only add one single stream.");
438+
TORCH_CHECK(
439+
activeStreamIndex_ == NO_ACTIVE_STREAM,
440+
"Can only add one single stream.");
439441
TORCH_CHECK(formatContext_.get() != nullptr);
440442

441443
AVCodecOnlyUseForCallingAVFindBestStream avCodec = nullptr;
@@ -722,7 +724,7 @@ bool VideoDecoder::canWeAvoidSeekingForStream(
722724
// AVFormatContext if it is needed. We can skip seeking in certain cases. See
723725
// the comment of canWeAvoidSeeking() for details.
724726
void VideoDecoder::maybeSeekToBeforeDesiredPts() {
725-
if (activeStreamIndex_ == -1) {
727+
if (activeStreamIndex_ == NO_ACTIVE_STREAM) {
726728
return;
727729
}
728730
StreamInfo& streamInfo = streamInfos_[activeStreamIndex_];
@@ -770,7 +772,7 @@ void VideoDecoder::maybeSeekToBeforeDesiredPts() {
770772

771773
VideoDecoder::AVFrameStream VideoDecoder::decodeAVFrame(
772774
std::function<bool(AVFrame*)> filterFunction) {
773-
if (activeStreamIndex_ == -1) {
775+
if (activeStreamIndex_ == NO_ACTIVE_STREAM) {
774776
throw std::runtime_error("No active streams configured.");
775777
}
776778

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ class VideoDecoder {
468468
ContainerMetadata containerMetadata_;
469469
UniqueAVFormatContext formatContext_;
470470
std::map<int, StreamInfo> streamInfos_;
471-
int activeStreamIndex_ = -1;
471+
const int NO_ACTIVE_STREAM = -2;
472+
int activeStreamIndex_ = NO_ACTIVE_STREAM;
472473
// Set when the user wants to seek and stores the desired pts that the user
473474
// wants to seek to.
474475
std::optional<double> desiredPtsSeconds_;

0 commit comments

Comments
 (0)