-
Notifications
You must be signed in to change notification settings - Fork 110
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
media_codec: Fix dequeue_output_buffer
treating some events as error
#316
Conversation
Can you call |
@MarijnS95 The problem is that |
86e7fc7
to
33f0f75
Compare
I've replaced |
The MediaCodec API in ndk v0.7 is flat out broken without this PR. |
@MarijnS95 ping, I'm using my branch in production and it works, I think this PR can be merged. |
@zarik5 This patch simply fails to explain why the caller can't match on the |
@MarijnS95 I see this is a matter of convention. I think |
Any documentation we can quote that states that these functions return both Regardless, I'd rather see anything that doesn't return an |
Nevertheless, don't forget to document this problem and API change in the changelog. |
2fc96ce
to
1e4c992
Compare
@MarijnS95 I looked in the source code and it's not completely clear what to do either https://android.googlesource.com/platform/frameworks/av/+/master/media/ndk/NdkMediaCodec.cpp#693 . I tried another opinionated solution. |
ndk/src/media/media_codec.rs
Outdated
Ok(None) | ||
} else if result >= 0 { | ||
Ok(Some(OutputBuffer { | ||
// result usage: https://android.googlesource.com/platform/frameworks/av/+/master/media/ndk/NdkMediaCodec.cpp#693 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this a permalink: if the file changes the line number wont match up anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
ndk/src/media/media_codec.rs
Outdated
@@ -269,8 +284,7 @@ impl MediaCodec { | |||
} | |||
} | |||
|
|||
/// Returns [`None`] if timeout is reached. | |||
pub fn dequeue_input_buffer(&self, timeout: Duration) -> Result<Option<InputBuffer>> { | |||
pub fn dequeue_input_buffer(&self, timeout: Duration) -> Result<InputBuffer> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this then return MediaCodecResult
if AMediaCodec_dequeueInputBuffer
has the ability to return MediaCodecInfo::TryAgainLater
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is, the source code is not clear in this regard, and every sample I've seen online does not handle TryAgainLater for the dequeueInputBuffer call.
That's absolutely horrible, is there any documentation stating the highest buffer index being used? Or is it just these two loose positive values? If you can't find anything I'll ping some NDK contacts to see what's up here. |
@MarijnS95 I didn't find any information about a "minimum error code integer" or "maximum buffer index". The "1000" cut point was completely arbitrary on my side. |
933808c
to
f1d38a0
Compare
|
ndk/src/media/media_codec.rs
Outdated
@@ -269,8 +285,8 @@ impl MediaCodec { | |||
} | |||
} | |||
|
|||
/// Returns [`None`] if timeout is reached. | |||
pub fn dequeue_input_buffer(&self, timeout: Duration) -> Result<Option<InputBuffer>> { | |||
/// Can return only `MediaCodecInfo::TryAgainLater` with `MediaCodecResult::Info(...)`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make these intradoc-links please :) (and grammar):
/// Can return only `MediaCodecInfo::TryAgainLater` with `MediaCodecResult::Info(...)`. | |
/// Can only return [`MediaCodecResult::Info(...)`] with [`MediaCodecInfo::TryAgainLater`]. |
Anything we can do about this? Otherwise I'd recommend purely parsing the two positive error codes and considering any other positive number as a valid buffer index. |
Otherwise can you inquire about this over at https://github.com/android/ndk? |
Not a good idea to me, it might break in a new API level.
Sure. |
It is already broken by design unless there's a maximum buffer index. |
Here you go: android/ndk#1768 |
Looks like you bumped the issue today @zarik5, unfortunate to see that upstream hasn't provided any clarification thus far :( |
Given no feedback upstream, should we merge this PR with my assumption of 1000 as an absolute value cutting point? I think It's reasonable, because how C APIs normally evolve. Usually error codes get added with increasing magnitude, maybe sometimes skipping tens or hundreds to reserve slots to more neatly group errors by scope, but almost never going under the lowest initial error value (in absolute terms). |
In its current form this PR proposes a breaking change, merging it would mean forcing the release of Rather we accept that this API was fundamentally broken and Deal With It™ until the next sensible opportunity to correct it. Users can currently work around this by manually matching these "error-like" values out of One thing you could do is return these codes in |
Correct me if I'm wrong, but if a certain API is completely broken, it's ok to fix it with a patch release (-.-.X) even if the API surface changes in a breaking way (it's a bug fix). I imagine noone in the wild is doing what you propose right now, instead if they are interested in the Mediacodec API they are probably using my PR. |
If it goes paired with a yank of the broken release, within a day of releasing, maybe? At this point you can't assume no-one is using |
I'm not gonna debate further. I'll will continue using my fork for production, I hope this PR will land sometimes. Maybe add it to a 0.8 tag as a reminder? |
Nothing to debate, circumventing semver is simply not done. Proposing another alternative: new unbroken functions with a different name, and |
No reason messing with it IMO. Let's merge this PR once you are ready to release v0.8. |
…isinterpreting some errors as buffer indices
If a new release of ndk is imminent, please consider merging this PR. |
@zarik5 as said before, only if it were a semver-breaking release. |
I saw that the MSRV got bumped, this is a breaking change. |
Hardly anyone seems to consider this breaking (see how we got broken by |
That's fair. |
@zarik5 Now that a new breaking release is impending I've given this PR another look, and there are a few observations:
I've stuffed all that thought in a new approach, which is quite a bit simpler than this PR. If you agree with this, I'll PR and merge the following (after rebasing on #399): https://github.com/rust-mobile/ndk/compare/ndk-media-codec-rewrap-dequeue-results Then, some followup items:
Thoughts? |
They are: https://developer.android.com/ndk/reference/group/media#summary
Yeah, my gripe is that I have nothing contrary to your other changes you described, especially the removal of |
@zarik5 I'm sorry, I meant to say "These error codes are properly negative", otherwise the bullet-point before and after don't make sense 🤭
Have you looked at the branch that I linked? I've handled that properly there, by defining two different
Will see what I can do. |
Sorry, I was on mobile. The branch looks fine, except that I would change slightly the names of the result structs. instead of |
I agree to append |
Another option is the suffix -Value. But having "Buffer" in the name is misleading as the value might also mot be a buffer. What about |
@zarik5 sure, I think the As explained in the linked commit message flattening the |
In hindsight keeping |
The MediaCodec wrapper had some issues with handling some non-error results for
dequeue_output_buffer
. This PR fixes it.The PR has been tested for the decoder path in soon-to-be-in-production code. I did not experience any unhandleable error originating inside the ndk calls.
Here I used
unreachable!()
to avoid adding an unused variant inMediaCodecOutputResult
and I would like some feedback for a better solution.