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

Add StreamReadBits() and StreamWriteBits() #1506

Merged
merged 2 commits into from
Aug 18, 2023

Conversation

y-guyon
Copy link
Collaborator

@y-guyon y-guyon commented Aug 18, 2023

Simplify calling sites that were doing manual bit manipulation.
Also add VarInt versions.

#1432 will be simplified when this PR is merged.

Simplify calling sites that were doing manual bit manipulation.
Also add VarInt versions.
Copy link
Collaborator

@maryla-uc maryla-uc left a comment

Choose a reason for hiding this comment

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

Nice! I'm wondering if the other, whole byte writing/reading functions should check that numUsedBitsInPartialByte is 0? to make sure that padding bits were properly added? otherwise if I understand correctly, the next bit read/write will keep acting on a previous byte which seems like a weird api? but maybe that's intentional or maybe I didn't read carefully enough

@y-guyon
Copy link
Collaborator Author

y-guyon commented Aug 18, 2023

Nice! I'm wondering if the other, whole byte writing/reading functions should check that numUsedBitsInPartialByte is 0?

avifROStreamSetOffset() already had assert(stream->numUsedBitsInPartialByte == 0);. I added the assertion to other functions. offsetOfPartialByte made no sense anymore (as described in #1432 (comment)) so I removed it. I fixed avifstreamtest too because it tested that pattern.

otherwise if I understand correctly, the next bit read/write will keep acting on a previous byte which seems like a weird api

This is the behavior of libwebp2 for what it is worth.

but maybe that's intentional or maybe I didn't read carefully enough

Yes it was intentional. I will add it back one day if needed.

@y-guyon y-guyon requested a review from maryla-uc August 18, 2023 15:44
Copy link
Collaborator

@maryla-uc maryla-uc left a comment

Choose a reason for hiding this comment

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

Thanks for the details. I didn't realize webp2 did this. I think it can work but it's not really in the spirit of isobmff boxes. You could have bits leaking into other boxes which seems weird. Although in practice we're following what the specs say anyway, and they use padding bits. I think it's less error prone to check that padding was indeed properly added (like you did).

@y-guyon y-guyon merged commit 8490d98 into AOMediaCodec:main Aug 18, 2023
@y-guyon y-guyon deleted the stream_bits branch August 18, 2023 15:56
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