Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove multi-stream related code #483

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

NicolasHug
Copy link
Member

@NicolasHug NicolasHug commented Jan 27, 2025

Towards #476

The main point of this PR is to raise an error when the usert tries to add more than one stream. This is a bug fix: previously, we weren't erroring, but we were returning silently wrong results as described in #476.

In addition, we remove multi-stream logic in this PR: we don't support multiple streams or multi-plexing, so there's no point pretending. Effectively, this removes the activeStreamIndices_ set and replaces it with int activeStreamIndex_. We keep the streamInfos_ map and it is unchanged, as its logic is relevant for metadata.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 27, 2025

return AVFrameStream(std::move(avFrame), frameStreamIndex);
return AVFrameStream(std::move(avFrame), activeStreamIndex_);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really need this AVFrameStream struct anymore, since we know the streamIndex is always activeStreamIndex_. We could remove it, but I guess this is better done in another PR.

@@ -907,15 +864,14 @@ VideoDecoder::AVFrameStream VideoDecoder::decodeAVFrame(
getFFMPEGErrorStringFromErrorCode(ffmpegStatus));
}

if (activeStreamIndices_.count(packet->stream_index) == 0) {
// This packet is not for any of the active streams.
if (packet->stream_index != activeStreamIndex_) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, this is the "demux" part now. And I think we should be calling av_read_frame within its own while loop, for as long as the received packet isn't of the target stream.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, what we're currently doing is inefficient, because if the packet is not the right stream, we first have to make a call to avcodec_receive_frame() that we know will fail. We're still doing the correct thing (I think), it's just inefficient.

// Stores the stream indices of the active streams, i.e. the streams we are
// decoding and returning to the user.
std::set<int> activeStreamIndices_;
int activeStreamIndex_ = -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to both make this a named constant, and to use something other than -1. Perhaps:

const int NO_ACTIVE_STREAM = -2;

Obviously 0 and above are potential active stream numbers, so they can't be used as such an indicator. But I'm worried that -1 can get confusing, because that is used to ask FFmpeg to find the best stream in some API calls. So I'd like to also treat -1 as a special stream value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants