Skip to content

controls/codec: V4L2_CID_STATELESS_VP9_FRAME #47

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

Merged
merged 1 commit into from
Feb 12, 2025
Merged

Conversation

fritzk
Copy link
Contributor

@fritzk fritzk commented Feb 10, 2025

I'm looking to add other stateless codecs controls. VP9, AV1, HEVC.

My current setup allows me to test VP9, so I'm looking to add it now. What's included in this PR is only what I need and have tested. I'm willing to add the rest of the controls like VP8 and h.264 have.

Would it be acceptable to also include AV1 and HEVC at this time? Or would you rather wait until I have a setup where they can be tested?

I'm not sure about the Drop impl being necessary. I'm new to Rust and not sure of why this would be necessary for VP8 and not h.264. I have tested VP9 without(not extensively) and have not seen problems.

Signed-off-by: Fritz Koenig <frkoenig@gmail.com>
@Gnurou
Copy link
Owner

Gnurou commented Feb 12, 2025

Hi Fritz,

Thanks, I have merged this patch (after altering the commit message a bit). AV1 and HEVC controls are available in the V4L2 headers, and since their handling will be identical to the others I see no problem with merging them even if they are not exercised yet - actually we should probably use some macros to automatically generate that code, since all pointer controls are handled the same.

Nice catch on the Drop implementation, the code handling H.264 controls was indeed missing, so we were leaking memory! When building a pointer control using its From implementation, we start by putting it on the heap, in a Box. Boxes are typically destroyed when they go out of scope, but here we want to keep the pointer alive in the C control, and use Box::into_raw to that effect. This consumes the Box and makes it yield its payload, without freeing it. But this also means we are now responsible for freeing it ourselves, which we do by re-creating the Box using Box::from_raw on the pointer we borrowed. Not doing that for H.264 controls was thus a bug - this should now be fixed.

@Gnurou Gnurou merged commit 6de41a6 into Gnurou:master Feb 12, 2025
1 check passed
@fritzk
Copy link
Contributor Author

fritzk commented Feb 12, 2025

Thanks for the explanation!

Are you thinking 2 macros?
The first to hold impl<T> From<v4l2_ctrl_vp9_frame> for SafeExtControl<T> and impl<T> SafeExtControl<T>.
The second to be a variadic to do the impl<T: ExtControlTrait> Drop for SafeExtControl<T>?

Or one variadic to handle all of them?

I haven't worked with macros yet so I'm not sure of the limitations.

@Gnurou
Copy link
Owner

Gnurou commented Feb 14, 2025

I suspect that a variadic one that generates everything we need in one go is the right solution here. Feel free to give it a try if you want, my knowledge about macros resets every other day and I have to re-learn the whole thing each time. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants