Skip to content

Commit

Permalink
mediacodec: Refactor mime type constant
Browse files Browse the repository at this point in the history
Couple of small refactoring:
1) Make mime type a constant.
2) Pass DecoderConfig to get_codec_initializers (follow up CLs
   will make use of fields in this struct in this function).

PiperOrigin-RevId: 682023619
  • Loading branch information
vigneshvg authored and copybara-github committed Oct 3, 2024
1 parent a869859 commit 9669802
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/codecs/android_mediacodec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ enum CodecInitializer {
ByMimeType(String),
}

fn get_codec_initializers(mime_type: &str, depth: u8) -> Vec<CodecInitializer> {
fn get_codec_initializers(config: &DecoderConfig) -> Vec<CodecInitializer> {
let dav1d = String::from("c2.android.av1-dav1d.decoder");
let gav1 = String::from("c2.android.av1.decoder");
// As of Sep 2024, c2.android.av1.decoder is the only known decoder to support 12-bit AV1. So
// prefer that for 12 bit images.
let prefer_gav1 = depth == 12;
let prefer_gav1 = config.depth == 12;
let mime_type = MediaCodec::AV1_MIME;
#[cfg(android_soong)]
{
// Use a specific decoder if it is requested.
Expand Down Expand Up @@ -284,6 +285,7 @@ impl MediaCodec {
// YUV P010 format used for 10-bit images:
// https://developer.android.com/reference/android/media/MediaCodecInfo.CodecCapabilities#COLOR_FormatYUVP010
const YUV_P010: i32 = 54;
const AV1_MIME: &str = "video/av01";
}

impl Decoder for MediaCodec {
Expand All @@ -295,7 +297,7 @@ impl Decoder for MediaCodec {
if format.is_null() {
return Err(AvifError::UnknownError("".into()));
}
c_str!(mime_type, mime_type_tmp, "video/av01");
c_str!(mime_type, mime_type_tmp, Self::AV1_MIME);
unsafe {
AMediaFormat_setString(format, AMEDIAFORMAT_KEY_MIME, mime_type);
AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_WIDTH, i32_from_u32(config.width)?);
Expand Down Expand Up @@ -330,7 +332,7 @@ impl Decoder for MediaCodec {
}

let mut codec = ptr::null_mut();
for codec_initializer in get_codec_initializers("video/av01", config.depth) {
for codec_initializer in get_codec_initializers(config) {
codec = match codec_initializer {
CodecInitializer::ByName(name) => {
c_str!(codec_name, codec_name_tmp, name.as_str());
Expand Down

0 comments on commit 9669802

Please sign in to comment.