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

ndk/media_format: Make all mutating functions take self by &mut #452

Merged
merged 1 commit into from
Jan 27, 2024

Conversation

MarijnS95
Copy link
Member

Fixes #451, CC @zarik5

All setters can inherently change the internals of the format, and should furthermore invalidate - or not be allowed while - borrowed strings or buffers (are) acquired from it.

Unforatunately getString() is documented as:

The returned string is owned by the format, and remains valid until the next call to getString, or until the format is deleted.

Meaning that it is not reentrant, and invalidates any data previously acquired from str(); hence this getter is marked as &mut self too. The same is however not the case for getBuffer().

@MarijnS95 MarijnS95 added the impact: breaking API/ABI-breaking change label Nov 20, 2023
@spencercw
Copy link
Contributor

The doc comments on buffer and str seem a little redundant because the rules are enforced by the type system anyway. The str comment is also not strictly accurate because the string is only invalidated when you re-fetch the same key.1 Not suggesting we should add document this implementation detail, but I don't think the adapted NDK docs are adding much value.

Looks good otherwise.

Footnotes

  1. https://cs.android.com/android/platform/superproject/main/+/main:frameworks/av/media/ndk/NdkMediaFormat.cpp;l=232-258;drc=65d530890d50e7a39f29fc70c0b6e55b402fe10a

@MarijnS95
Copy link
Member Author

Fair enough for buffer, I mostly copied the NDK docs for the few (two) functions that actually have docs upstream.

I'd like to keep "something" for fn str() however, to justify to documentation readers why a getter is borrowing self mutably.

@spencercw
Copy link
Contributor

Yes that makes sense. A mut getter does look a bit odd on the face of it.

All setters can inherently change the internals of the format, and should
furthermore invalidate - or not be allowed while - borrowed strings or
buffers (are) acquired from it.

Unforatunately [`getString()` is documented as]:

    The returned string is owned by the format, and remains valid until
    the next call to getString, or until the format is deleted.

Meaning that it is not reentrant, and invalidates any data previously
acquired from `str()`; hence this getter is marked as `&mut self` too.
The same is however not the case for `getBuffer()`.

[`getString()` is documented as]: #451
@MarijnS95 MarijnS95 merged commit 5c8c0bc into master Jan 27, 2024
38 checks passed
@MarijnS95 MarijnS95 deleted the media-format-mut branch January 27, 2024 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact: breaking API/ABI-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate MediaFormat mutability / lifetimes
2 participants