media_error: Add MediaStatus::from_status_if_negative()
helper
#414
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CC @paxbun
Covers a prevalent
unwrap_err()
pattern for negative status codes, where we want to use any non-negative status code as a useful value and otherwise assert thatfrom_status()
turns the raw value into an appropriate error code (never intoOk(())
, which should be unreachable in the current implementation).Note that we cannot rely on
from_status()
returningOk(())
orErr(_)
and translate theOk(())
back to the original value, as it handles (as of writing) two positive error codes which only relate to a specificAMediaCodec
API, and any unrecognized codes including >0 are treated asUnknownStatus
.The function consumes
Into<isize>
instead ofi32/c_int
orffi::media_status_t
to support passing through numbers from various APIs that return 64-bit numbers (e.g.MediaCodec
). The value only needs to be truncated (with a panic ontry_into()
) when it is lower than zero and needs to be converted toffi::media_status_t
.