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 AVFrameStream struct and remove raw AVFrame* pointers #572

Merged
merged 6 commits into from
Mar 18, 2025

Conversation

NicolasHug
Copy link
Member

@NicolasHug NicolasHug commented Mar 17, 2025

Continuing the work towards making the decoder properly single-stream. This PR addresses #483 (comment).

The AVFrameStream struct is obsolete, we don't need to keep track of the stream - we know it's activeStreamIndex_.

Additionally, since this is fairly related, this PR removes all (but one) uses of AVFrame* and replaces those with [const] UniqueAVFrame&.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 17, 2025
@NicolasHug NicolasHug changed the title Remove AVFrameStream struct Remove AVFrameStream struct and remove raw AVFrame* pointers Mar 17, 2025
@@ -1302,7 +1301,7 @@ void VideoDecoder::convertAVFrameToFrameOutputOnCPU(
}

int VideoDecoder::convertAVFrameToTensorUsingSwsScale(
const AVFrame* avFrame,
UniqueAVFrame& avFrame,
Copy link
Member Author

Choose a reason for hiding this comment

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

Unless I'm misunderstanding, pretending the AVFrame* was const was a big lie, because of the call to sws_scale(..., avFrame->data, ...) below. So I made the ref non-const.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it still makes sense for it to be const. We have a const reference to a unique pointer, which means that we can't change the contents of the unique pointer. That is, we can't call release() or reset() on the unique pointer. But we can make changes to the object the unique pointer points to.

This is similar to the difference between a "const pointer" and "pointer to const." A const pointer is a pointer that cannot change what it is pointing to. A pointer to const is a pointer to an object that cannot change - but you can change what the pointer points to.

Basically, anytime we don't want ownership of the unique pointer to change, we should use const.


int convertAVFrameToTensorUsingSwsScale(
const AVFrame* avFrame,
UniqueAVFrame& avFrame,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's worth reasoning through if all of these should be const references - see my above.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll open an issue to keep track of this

@NicolasHug NicolasHug merged commit b830480 into pytorch:main Mar 18, 2025
46 checks passed
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