自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
媒体资源管理器的 OEM 依赖项
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本文档旨在帮助 OEM 正确实现对 Android 媒体资源管理器和相关 API 的支持。
最大并发编解码器实例数量
CodecCapabilities.getMaxSupportedInstances
接口返回支持的并发编解码器实例的最大数量。
CTS 测试 testGetMaxSupportedInstances(android.media.cts.MediaCodecCapabilitiesTest)
用于强制在 /etc/media_codecs.xml
中设置合适的最大值。
示例如下:
...
<MediaCodecs>
...
<Encoders>
<MediaCodec name="OMX.<vendor>.video.encoder.avc" type="video/avc" >
...
<Limit name="concurrent-instances" max="13" />
</MediaCodec>
...
</Encoders>
...
</MediaCodecs>
OEM 可以使用此测试来生成可通过测试的并发限制。具体操作步骤如下:
- 首先使用 cts-tradefed 运行测试。
- 评估生成的失败消息。示例如下:
There was 1 failure:
1) testGetMaxSupportedInstances(android.media.cts.MediaCodecCapabilitiesTest)
junit.framework.AssertionFailedError: In order to pass the test, please publish
following codecs' concurrent instances limit in /etc/media_codecs.xml:
<MediaCodec name="OMX.<vendor>.video.encoder.mpeg4" type="video/mp4v-es" >
<Limit name="concurrent-instances" max="13" />
</MediaCodec>
<MediaCodec name="OMX.<vendor>.video.encoder.h263" type="video/3gpp" >
<Limit name="concurrent-instances" max="13" />
</MediaCodec>
<MediaCodec name="OMX.<vendor>.video.encoder.avc" type="video/avc" >
<Limit name="concurrent-instances" max="13" />
</MediaCodec>
<MediaCodec name="OMX.<vendor>.video.encoder.vp8" type="video/x-vnd.on2.vp8" >
<Limit name="concurrent-instances" max="13" />
</MediaCodec>
<MediaCodec name="OMX.<vendor>.video.decoder.avc" type="video/avc" >
<Limit name="concurrent-instances" max="13" />
</MediaCodec>
<MediaCodec name="OMX.<vendor>.video.decoder.avc.secure" type="video/avc" >
<Limit name="concurrent-instances" max="4" />
</MediaCodec>
<MediaCodec name="OMX.<vendor>.video.decoder.mpeg4" type="video/mp4v-es" >
<Limit name="concurrent-instances" max="12" />
</MediaCodec>
<MediaCodec name="OMX.<vendor>.video.decoder.h263" type="video/3gpp" >
<Limit name="concurrent-instances" max="12" />
</MediaCodec>
<MediaCodec name="OMX.<vendor>.video.decoder.vp8" type="video/x-vnd.on2.vp8" >
<Limit name="concurrent-instances" max="12" />
</MediaCodec>
- 将测试失败消息中建议的
concurrent-instances
行添加到 /etc/media_codecs.xml
文件。
- 重新运行测试以验证测试是否成功。
视频编解码器可实现的帧速率
VideoCapabilities.getAchievableFrameRatesFor
接口针对视频大小返回可实现的视频帧速率的范围。此信息必须由 OEM 通过位于 /etc/media_codecs_performance.xml
的 XML 文件为每个设备提供。这些设置通过 com.android.cts.videoperf.VideoEncoderDecoderTest
和 android.media.cts.VideoDecoderPerfTest
CTS 测试进行测试。
OEM 可以使用 CTS 测试来生成可通过测试的 XML 文件。如果想:
- 首先使用 cts-tradefed 运行测试。鉴于 Android 性能的波动性,建议多次运行测试以获得更准确的最小值和最大值。
- 使用提供的
get_achievable_rates.py 脚本生成 XML 文件。
- 将 XML 文件放置在以下位置:
/etc/media_codecs_performance.xml
为了完成此过程,您通常需要将 XML 文件放置在设备项目(device/<供应商>/<产品>)中,并将 PRODUCT_COPY_FILES
行添加到 device.mk
中,如下所示:
PRODUCT_COPY_FILES += \
...
device/moto/shamu/media_codecs.xml:system/etc/media_codecs.xml \
+ device/moto/shamu/media_codecs_performance.xml:system/etc/media_codecs_performance.xml
- 重新运行性能测试以验证测试是否成功。
安全编解码器和非安全编解码器共存
- supports-secure-with-non-secure-codec - 如果安全编解码器实例和非安全编解码器实例不能同时共存,应在
media_codecs.xml
文件中作为全局设置指明。
<MediaCodecs>
<Settings>
<Setting name="supports-secure-with-non-secure-codec" value="false" />
</Settings>
<Encoders>
…
- supports-multiple-secure-codecs - 如果不支持多个安全编解码器实例共存,应在
media_codecs.xml
文件中作为全局设置指明。
<MediaCodecs>
<Settings>
<Setting name="supports-multiple-secure-codecs" value="false" />
</Settings>
<Encoders>
…
- 请注意,默认情况下,这两项设置都为 true,这意味着如果支持这两项设置,那么无需将设置行添加到
media_codecs.xml
。
- 如果未正确设置这两项设置,
ResourceManagerTest
CTS 测试可能会失败。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# OEM dependencies for media resource manager\n\nThis document is intended to help original equipment manufacturers (OEMs)\nproperly implement support for Android media resource manager and related APIs.\n\nMax concurrent codec instances\n------------------------------\n\nThe `CodecCapabilities.getMaxSupportedInstances` interface\nreturns the maximum number of supported concurrent codec instances.\n\nThe CTS test\n`testGetMaxSupportedInstances(android.media.cts.MediaCodecCapabilitiesTest)`\nis used to enforce the proper maximum is set in\n`/etc/media_codecs.xml`.\n\nHere is an example: \n\n```\n...\n\u003cMediaCodecs\u003e\n ...\n \u003cEncoders\u003e\n \u003cMediaCodec name=\"OMX.\u003cvendor\u003e.video.encoder.avc\" type=\"video/avc\" \u003e\n ...\n \u003cLimit name=\"concurrent-instances\" max=\"13\" /\u003e\n \u003c/MediaCodec\u003e\n ...\n \u003c/Encoders\u003e\n ...\n\u003c/MediaCodecs\u003e\n```\n\nOEMs can use this test to generate the concurrent limits that pass the test.\nTo do this:\n\n1. Run the test first using cts-tradefed.\n2. Evaluate the resulting failure message. Here is an example: \n\n ```\n There was 1 failure:\n 1) testGetMaxSupportedInstances(android.media.cts.MediaCodecCapabilitiesTest)\n junit.framework.AssertionFailedError: In order to pass the test, please publish\n following codecs' concurrent instances limit in /etc/media_codecs.xml:\n \u003cMediaCodec name=\"OMX.\u003cvendor\u003e.video.encoder.mpeg4\" type=\"video/mp4v-es\" \u003e\n \u003cLimit name=\"concurrent-instances\" max=\"13\" /\u003e\n \u003c/MediaCodec\u003e\n \u003cMediaCodec name=\"OMX.\u003cvendor\u003e.video.encoder.h263\" type=\"video/3gpp\" \u003e\n \u003cLimit name=\"concurrent-instances\" max=\"13\" /\u003e\n \u003c/MediaCodec\u003e\n \u003cMediaCodec name=\"OMX.\u003cvendor\u003e.video.encoder.avc\" type=\"video/avc\" \u003e\n \u003cLimit name=\"concurrent-instances\" max=\"13\" /\u003e\n \u003c/MediaCodec\u003e\n \u003cMediaCodec name=\"OMX.\u003cvendor\u003e.video.encoder.vp8\" type=\"video/x-vnd.on2.vp8\" \u003e\n \u003cLimit name=\"concurrent-instances\" max=\"13\" /\u003e\n \u003c/MediaCodec\u003e\n \u003cMediaCodec name=\"OMX.\u003cvendor\u003e.video.decoder.avc\" type=\"video/avc\" \u003e\n \u003cLimit name=\"concurrent-instances\" max=\"13\" /\u003e\n \u003c/MediaCodec\u003e\n \u003cMediaCodec name=\"OMX.\u003cvendor\u003e.video.decoder.avc.secure\" type=\"video/avc\" \u003e\n \u003cLimit name=\"concurrent-instances\" max=\"4\" /\u003e\n \u003c/MediaCodec\u003e\n \u003cMediaCodec name=\"OMX.\u003cvendor\u003e.video.decoder.mpeg4\" type=\"video/mp4v-es\" \u003e\n \u003cLimit name=\"concurrent-instances\" max=\"12\" /\u003e\n \u003c/MediaCodec\u003e\n \u003cMediaCodec name=\"OMX.\u003cvendor\u003e.video.decoder.h263\" type=\"video/3gpp\" \u003e\n \u003cLimit name=\"concurrent-instances\" max=\"12\" /\u003e\n \u003c/MediaCodec\u003e\n \u003cMediaCodec name=\"OMX.\u003cvendor\u003e.video.decoder.vp8\" type=\"video/x-vnd.on2.vp8\" \u003e\n \u003cLimit name=\"concurrent-instances\" max=\"12\" /\u003e\n \u003c/MediaCodec\u003e\n ```\n3. Add the `concurrent-instances` lines suggested in the test failure message to the `/etc/media_codecs.xml` file.\n4. Re-run the test to verify its success.\n\nAchievable frame rates for video codecs\n---------------------------------------\n\nThe `VideoCapabilities.getAchievableFrameRatesFor` interface\nreturns the range of achievable video frame rates for a video size. This\ninformation must be provided by the OEM for each device via an XML file placed at\n`/etc/media_codecs_performance.xml`. These settings are tested by\nthe `com.android.cts.videoperf.VideoEncoderDecoderTest` and\n`android.media.cts.VideoDecoderPerfTest` CTS tests.\n\nOEMs can use the CTS tests to generate the XML files that pass the tests. To do this:\n\n1. Run the tests first using cts-tradefed. Given the variability of Android performance, it is recommended the tests are run multiple times to get more accurate minimum and maximum values.\n2. Use the provided [get_achievable_rates.py](https://android.googlesource.com/platform/cts/+/android16-release/tools/cts-media/get_achievable_rates.py) script to generate the XML file.\n3. Place the XML file at: `/etc/media_codecs_performance.xml` \n This is usually done by placing the XML file in the device project (device/*\\\u003cvendor\\\u003e* /*\\\u003cproduct\\\u003e* ) and adding a `PRODUCT_COPY_FILES` line to `device.mk` like so: \n\n ```\n PRODUCT_COPY_FILES += \\\n ...\n device/moto/shamu/media_codecs.xml:system/etc/media_codecs.xml \\\n + device/moto/shamu/media_codecs_performance.xml:system/etc/media_codecs_performance.xml\n ```\n4. Re-run the performance tests to verify their success.\n\nCoexistence of secure codec and non-secure codec\n------------------------------------------------\n\n- supports-secure-with-non-secure-codec --- If the instance of secure codec and the instance of non-secure codec can't coexist at the same time, that should be indicated as global setting in the `media_codecs.xml` file. \n\n ```\n \u003cMediaCodecs\u003e\n \u003cSettings\u003e\n \u003cSetting name=\"supports-secure-with-non-secure-codec\" value=\"false\" /\u003e\n \u003c/Settings\u003e\n \u003cEncoders\u003e\n …\n ```\n- supports-multiple-secure-codecs --- If the coexistence of multiple secure codec instances is not supported, that should be indicated as a global setting in the `media_codecs.xml` file. \n\n ```\n \u003cMediaCodecs\u003e\n \u003cSettings\u003e\n \u003cSetting name=\"supports-multiple-secure-codecs\" value=\"false\" /\u003e\n \u003c/Settings\u003e\n \u003cEncoders\u003e\n …\n ```\n- Note that the both settings are true by default, meaning if they are supported, there's no need to add the setting line to the `media_codecs.xml`.\n- The `ResourceManagerTest` CTS tests may fail if these two settings were not set properly."]]