Google在Android Q 引入Codec 2.0 ,与MediaCodec 合作,用于decoding/encoding,之前的版本是MediaCodec 与ACodec/OMX 合作来进行decoding/encoding,两种Flow并存,通过debug.stagefright.ccodec 这个property 以及rank 来决定使用哪个flow。
1.debug.stagefright.ccodec
AndroidS 下,这个property 有5个值,分别定义如下。
Codec2InfoBuilder.cpp
// debug.stagefright.ccodec supports 5 values.
// 0 - No Codec 2.0 components are available.
// 1 - Audio decoders and encoders with prefix "c2.android." are available
// and ranked first.
// All other components with prefix "c2.android." are available with
// their normal ranks.
// Components with prefix "c2.vda." are available with their normal
// ranks.
// All other components with suffix ".avc.decoder" or ".avc.encoder"
// are available but ranked last.
// 2 - Components with prefix "c2.android." are available and ranked
// first.
// Components with prefix "c2.vda." are available with their normal
// ranks.
// All other components with suffix ".avc.decoder" or ".avc.encoder"
// are available but ranked last.
// 3 - Components with prefix "c2.android." are available and ranked
// first.
// All other components are available with their normal ranks.
// 4 - All components are available with their normal ranks.
//
// The default value (boot time) is 1.
// Note: Currently, OMX components have default rank 0x100, while all
// Codec2.0 software components have default rank 0x200.
int option = ::android::base::GetIntProperty("debug.stagefright.ccodec", 4);
Android S默认值是4,也就是C2 和 omx component 并存,需要根据rank 决定采用哪个,rank 越低优先级越高。
2.rank
AndroidS 对于C2 当前采用的是默认rank, Audio 默认是 8,其他0x200(512).
C2Store.cpp
std::shared_ptr<C2Component::Traits> traits(new (std::nothrow) C2Component::Traits);
if (traits) {
if (!C2InterfaceUtils::FillTraitsFromInterface(traits.get(), intf)) {
ALOGD("Failed to fill traits from interface");
return mInit;
}
// TODO: get this properly from the store during emplace
switch (traits->domain) {
case C2Component::DOMAIN_AUDIO:
traits->rank = 8;
break;
default:
traits->rank = 512;
}
}
对于omx 可以通过property 设定rank.
OmxInfoBuilder.cpp
uint32_t defaultRank =
::android::base::GetUintProperty("debug.stagefright.omx_default_rank", 0x100u);
uint32_t defaultSwAudioRank =
::android::base::GetUintProperty("debug.stagefright.omx_default_rank.sw-audio", 0x10u);
uint32_t defaultSwOtherRank =
::android::base::GetUintProperty("debug.stagefright.omx_default_rank.sw-other", 0x210u);
debug.stagefright.omx_default_rank 是用来设定omx hardware decoder/encoder rank;比如audio/video等。
debug.stagefright.omx_default_rank.sw-audio是用来设定omx audio software decoder/encoder rank, 也就是带有“OMX.google” 前缀的audio component.
debug.stagefright.omx_default_rank.sw-other是用来设定omx 非audio component 软解的rank.
综上,AndroidS 默认会优先使用C2 Audio,我们可以修改rank 或者debug.stagefright.ccodec 来选择C2 还是 omx。
3.举个例子:
dumpsys media.player 可以查看当前codec 的rank.
[debug.stagefright.ccodec]: [0]
这种情况下,关闭C2,只会有omx 支援的component.
dumpsys media.player
5 registered handlers:
93: <stale>
97: <stale>
98: <stale>
100: <stale>
101: <stale>
Decoder infos by media types:
=============================
Media type 'audio/3gpp':
Decoder "OMX.NVT.Audio.Decoder.amrnb" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/ac3':
Decoder "OMX.NVT.Audio.Decoder.ac3" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/adpcm':
Decoder "OMX.NVT.Audio.Decoder.adpcm" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/alac':
Decoder "OMX.NVT.Audio.Decoder.alac" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/amr-wb':
Decoder "OMX.NVT.Audio.Decoder.amrwb" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/ape':
Decoder "OMX.NVT.Audio.Decoder.ape" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/cook':
Decoder "OMX.NVT.Audio.Decoder.cook" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/dra':
Decoder "OMX.NVT.Audio.Decoder.dra" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/eac3':
Decoder "OMX.NVT.Audio.Decoder.eac3" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/flac':
Decoder "OMX.NVT.Audio.Decoder.flac" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Decoder "OMX.google.flac.decoder" supports
aliases: []
attributes: 0: [
encoder: 0,
vendor: 0,
software-only: 0,
hw-accelerated: 0 ]
owner: "default"
rank: 259
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string bitrate-range = "8000-320000"
string max-channel-count = "3"
string sample-rate-ranges = "8000,11025,12000,16000,22050,24000,32000,44100,48000,192000"
}
Media type 'audio/g711':
Decoder "OMX.NVT.Audio.Decoder.g711" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/g711-alaw':
Decoder "OMX.NVT.Audio.Decoder.alaw.g711" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/g711-mlaw':
Decoder "OMX.NVT.Audio.Decoder.mlaw.g711" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/mp4a-latm':
Decoder "OMX.NVT.Audio.Decoder.aac" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: [
2/ 0 (LC/??) ]
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Decoder "OMX.NVT.Audio.Decoder.aac.secure" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: [
2/ 0 (LC/??) ]
colors: []
details: AMessage(what = 0x00000000) = {
int32_t feature-secure-playback = 1
string max-concurrent-instances = "2"
}
Media type 'audio/mpeg':
Decoder "OMX.NVT.Audio.Decoder.mp3" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Decoder "OMX.google.mp3.decoder" supports
aliases: []
attributes: 0: [
encoder: 0,
vendor: 0,
software-only: 0,
hw-accelerated: 0 ]
owner: "default"
rank: 259
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string bitrate-range = "8000-320000"
string max-channel-count = "3"
string sample-rate-ranges = "8000,11025,12000,16000,22050,24000,32000,44100,48000"
}
Media type 'audio/mpeg-L1':
Decoder "OMX.NVT.Audio.Decoder.mp1" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/mpeg-L2':
Decoder "OMX.NVT.Audio.Decoder.mp2" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/opus':
Decoder "OMX.NVT.Audio.Decoder.opus" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Decoder "OMX.NVT.Audio.Decoder.opus.secure" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
int32_t feature-secure-playback = 1
string max-concurrent-instances = "2"
}
Media type 'audio/pcm':
Decoder "OMX.NVT.Audio.Decoder.pcm" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/raw':
Decoder "OMX.google.raw.decoder" supports
aliases: []
attributes: 0: [
encoder: 0,
vendor: 0,
software-only: 0,
hw-accelerated: 0 ]
owner: "default"
rank: 259
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string bitrate-range = "1-10000000"
string max-channel-count = "8"
string sample-rate-ranges = "8000-96000"
}
Media type 'audio/vorbis':
Decoder "OMX.NVT.Audio.Decoder.vorbis" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Decoder "OMX.NVT.Audio.Decoder.vorbis.secure" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string bitrate-range = "32000-500000"
int32_t feature-secure-playback = 1
string max-channel-count = "8"
string max-concurrent-instances = "2"
string sample-rate-ranges = "8000-9600"
}
Media type 'audio/wmapro':
Decoder "OMX.NVT.Audio.Decoder.wmapro" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/wmav1':
Decoder "OMX.NVT.Audio.Decoder.wmav1" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'audio/wmav2':
Decoder "OMX.NVT.Audio.Decoder.wmav2" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: []
colors: []
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
}
Media type 'video/3gpp':
Decoder "OMX.NVT.Video.Decoder.h263" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: [
1/ 1 (Baseline/10),
1/ 2 (Baseline/20),
1/ 4 (Baseline/30),
1/ 8 (Baseline/40),
1/ 16 (Baseline/45),
8/ 1 (ISWV2/10),
8/ 2 (ISWV2/20),
8/ 4 (ISWV2/30),
8/ 16 (ISWV2/45) ]
colors: [
0x7f420888 (YUV420Flexible),
0x15 (YUV420SemiPlanar) ]
details: AMessage(what = 0x00000000) = {
string max-concurrent-instances = "2"
string measured-frame-rate-176x144-range = "300-600"
string measured-frame-rate-352x288-range = "350-480"
string performance-point-1920x1080-range = "60-60"
}
Media type 'video/avc':
Decoder "OMX.NVT.Video.Decoder.avc" supports
aliases: []
attributes: 0xa: [
encoder: 0,
vendor: 1,
software-only: 0,
hw-accelerated: 1 ]
owner: "default"
rank: 256
profile/levels: [
1/ 1 (Baseline/1),
65536/ 1 (ConstrainedBaseline/1),
1/ 8 (Baseline/1.2),
65536/ 8 (ConstrainedBaseline/1.2),
1/ 32 (Baseline/2),
65536/ 32 (ConstrainedBaseline/2),
1/ 256 (Baseline/3),
65536/ 256 (ConstrainedBaseline/3),
1/ 512 (Baseline/3.1),
65536/ 512 (ConstrainedBaseline/3.1),
1/ 1024 (Baseline/3.2),
65536/ 1024 (ConstrainedBaseline/3.2),
1/ 2048 (Baseline/4),
65536/ 2048 (ConstrainedBaseline/4),
1/ 4096 (Baseline/4.1),
65536/ 4096 (ConstrainedBaseline/4.1),
1/ 8192 (Baseline/4.2),
65536/ 8192 (ConstrainedBaseline/4.2),
1/16384 (Baseline/5),
65536/16384 (ConstrainedBaseline/5),
1/32768 (Baseline/5.1),
65536/32768 (ConstrainedBaseline/5.1),
2/ 1 (Main/1),
2/ 32 (Main/2),
2/ 256 (Main/3),
2/ 512 (Main/3.1),
2/ 1024 (Main/3.2),
2/ 2048 (Main/4),
2/ 4096 (Main/4.1),
2/ 8192 (Main/4.2),
2/16384 (Main/5),
2/32768 (Main/5.1),
8/ 1 (High/1),
524288/ 1 (ConstrainedHigh/1),
8/ 8 (High/1.2),
524288/ 8 (ConstrainedHigh/1.2),
8/ 32 (High/2),
524288/ 32 (ConstrainedHigh/2),
8/ 256 (High/3),
524288/ 256 (ConstrainedHigh/3),
8/ 512 (High/3.1),
524288/ 512 (ConstrainedHigh/3.1),
8/ 1024 (High/3.2),
524288/ 1024 (ConstrainedHigh/3.2),
8/ 2048 (High/4),
524288/ 2048 (ConstrainedHigh/4),
8/ 4096 (High/4.1),
524288/ 4096 (ConstrainedHigh/4.1),
8/ 8192 (High/4.2),
524288/ 8192 (ConstrainedHigh/4.2),
8/16384 (High/5),
524288/16384 (ConstrainedHigh/5),
8/32768 (High/5.1),
524288/32768 (ConstrainedHigh/5.1) ]
colors: [
0x7f420888 (YUV420Flexible),
0x15 (YUV420SemiPlanar) ]
details: AMessage(what = 0x00000000) = {
string bitrate-range = "1-20000000"
int32_t feature-adaptive-playback = 0
string max-concurrent-instances = "2"
string measured-frame-rate-1280x720-range = "100-350"
string measured-frame-rate-1920x1088-range = "150-180"
string measured-frame-rate-320x240-range = "210-450"