自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
媒体
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 包含 Stagefright。Stagefright 是位于原生层的媒体播放引擎,内置了基于软件的编解码器,可用于处理热门媒体格式。
Stagefright 音频和视频播放功能包括集成 OpenMAX 编解码器、会话管理、基于时间的同步渲染、传输控制和 DRM。
Stagefright 还支持集成由您提供的自定义硬件编解码器。要设置编码和解码媒体的硬件路径,您必须将基于硬件的编解码器作为 OpenMax IL(集成层)组件加以实现。
注意:Stagefright 可通过 Android 每月安全更新流程,作为 Android 操作系统版本的一部分进行更新。
架构
媒体应用根据以下架构与 Android 原生多媒体框架进行交互。

图 1. 媒体架构
- 应用框架
- 应用代码位于应用框架层,利用 android.media API 与多媒体硬件进行交互。
- Binder IPC
- Binder IPC 代理用于促进跨越进程边界的通信。
这些代理位于
frameworks/av/media/libmedia
目录中,并以字母“I”开头。
- 原生多媒体框架
- 在原生层,Android 提供了一个利用 Stagefright 引擎进行音频和视频录制及播放的多媒体框架。Stagefright 随附支持的软件编解码器的默认列表,并且您可以使用 OpenMax 集成层标准来实现自己的硬件编解码器。如需了解关于实现的更多详情,请参阅位于
frameworks/av/media
中的 MediaPlayer 和 Stagefright 组件。
- OpenMAX 集成层 (IL)
- OpenMAX IL 为 Stagefright 提供了一种标准化的方式来识别和使用基于硬件的自定义多媒体编解码器(称为组件)。您必须以名为
libstagefrighthw.so
的共享库的形式提供 OpenMAX 插件。此插件将 Stagefright 与您的自定义编解码器组件相连接,并且这些组件必须根据 OpenMAX IL 组件标准来实现。
实现自定义编解码器
Stagefright 随附适用于通用媒体格式的内置软件编解码器,但您也可以添加自己的自定义硬件编解码器作为 OpenMAX 组件。为此,您必须创建 OMX 组件和一个 OMX 插件,将您的自定义编解码器与 Stagefright 框架连接起来。如需查看示例组件,请参阅 hardware/ti/omap4xxx/domx/
;如需查看 Galaxy Nexus 的示例插件,请参阅 hardware/ti/omap4xx/libstagefrighthw
。
添加您自己的编解码器:
- 根据 OpenMAX IL 组件标准创建您的组件。组件接口位于
frameworks/native/include/media/OpenMAX/OMX_Component.h
文件中。如需详细了解 OpenMAX IL 规范,请参阅 OpenMAX 网站。
- 创建一个将您的组件与 Stagefright 服务相连接的 OpenMAX 插件。如需查看用于创建插件的接口,请参阅
frameworks/native/include/media/hardware/OMXPluginBase.h
和 HardwareAPI.h
头文件。
- 将您的插件构建为产品 Makefile 中名为
libstagefrighthw.so
的共享库。例如:
LOCAL_MODULE := libstagefrighthw
在设备的 Makefile 中,确保将模块声明为产品包:
PRODUCT_PACKAGES += \
libstagefrighthw \
...
向框架提供编解码器
Stagefright 服务会解析 system/etc/media_codecs.xml
和 system/etc/media_profiles.xml
,从而通过 android.media.MediaCodecList
和 android.media.CamcorderProfile
类向应用开发者提供设备上受支持的编解码器和配置文件。您必须在 device/<company>/<device>/
目录中创建这两个文件,并将其复制到设备的 Makefile 中系统映像的 system/etc
目录中。例如:
PRODUCT_COPY_FILES += \
device/samsung/tuna/media_profiles.xml:system/etc/media_profiles.xml \
device/samsung/tuna/media_codecs.xml:system/etc/media_codecs.xml \
如需查看完整示例,请参阅 device/samsung/tuna/media_codecs.xml
和 device/samsung/tuna/media_profiles.xml
。
注意:从 Android 4.1 开始,不再支持媒体编解码器的 <Quirk>
元素。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Media\n\nAndroid includes Stagefright, a media playback engine at the native level\nthat has built-in software-based codecs for popular media formats.\n\nStagefright audio and video playback features include integration with\nOpenMAX codecs, session management, time-synchronized rendering, transport\ncontrol, and DRM.\n\nStagefright also supports integration with custom hardware codecs provided by\nyou. To set a hardware path to encode and decode media, you must implement a\nhardware-based codec as an OpenMax IL (Integration Layer) component.\n\n**Note:** Stagefright updates can occur through the\nAndroid [monthly security\nupdate](/docs/security/bulletin) process and as part of an Android OS release.\n\nArchitecture\n------------\n\nMedia applications interact with the Android native multimedia framework\naccording to the following architecture.\n\n**Figure 1.** Media\narchitecture\n\nApplication Framework\n: At the application framework level is application code that utilizes\n [android.media](http://developer.android.com/reference/android/media/package-summary.html)\n APIs to interact with the multimedia hardware.\n\nBinder IPC\n: The Binder IPC proxies facilitate communication over process boundaries.\n They are located in the `frameworks/av/media/libmedia` directory and\n begin with the letter \"I\".\n\nNative Multimedia Framework\n: At the native level, Android provides a multimedia framework that utilizes\n the Stagefright engine for audio and video recording and playback. Stagefright\n comes with a default list of supported software codecs and you can implement\n your own hardware codec by using the OpenMax integration layer standard. For\n more implementation details, see the MediaPlayer and Stagefright components\n located in `frameworks/av/media`.\n\nOpenMAX Integration Layer (IL)\n: The OpenMAX IL provides a standardized way for Stagefright to recognize and\n use custom hardware-based multimedia codecs called components. You must provide\n an OpenMAX plugin in the form of a shared library named\n `libstagefrighthw.so`. This plugin links Stagefright with your custom\n codec components, which must be implemented according to the OpenMAX IL\n component standard.\n\nImplement custom codecs\n-----------------------\n\nStagefright comes with built-in software codecs for common media formats, but\nyou can also add your own custom hardware codecs as OpenMAX components. To do\nthis, you must create the OMX components and an OMX plugin that hooks together\nyour custom codecs with the Stagefright framework. For example components, see\nthe `hardware/ti/omap4xxx/domx/`; for an example plugin for the\nGalaxy Nexus, see `hardware/ti/omap4xx/libstagefrighthw`.\n\nTo add your own codecs:\n\n1. Create your components according to the OpenMAX IL component standard. The component interface is located in the `frameworks/native/include/media/OpenMAX/OMX_Component.h` file. To learn more about the OpenMAX IL specification, refer to the [OpenMAX website](http://www.khronos.org/openmax/).\n2. Create a OpenMAX plugin that links your components with the Stagefright service. For the interfaces to create the plugin, see `frameworks/native/include/media/hardware/OMXPluginBase.h` and `HardwareAPI.h` header files.\n3. Build your plugin as a shared library with the name `libstagefrighthw.so` in your product Makefile. For example: \n\n ```\n LOCAL_MODULE := libstagefrighthw\n ```\n\n In your device's Makefile, ensure you declare the module as a product\n package: \n\n ```\n PRODUCT_PACKAGES += \\\n libstagefrighthw \\\n ...\n ```\n\nExpose codecs to the framework\n------------------------------\n\nThe Stagefright service parses the `system/etc/media_codecs.xml`\nand `system/etc/media_profiles.xml` to expose the supported codecs\nand profiles on the device to app developers via the\n`android.media.MediaCodecList` and\n`android.media.CamcorderProfile` classes. You must create both files\nin the `device/\u003ccompany\u003e/\u003cdevice\u003e/` directory\nand copy this over to the system image's `system/etc` directory in\nyour device's Makefile. For example: \n\n```\nPRODUCT_COPY_FILES += \\\n device/samsung/tuna/media_profiles.xml:system/etc/media_profiles.xml \\\n device/samsung/tuna/media_codecs.xml:system/etc/media_codecs.xml \\\n```\n\nFor complete examples, see `device/samsung/tuna/media_codecs.xml`\nand `device/samsung/tuna/media_profiles.xml` .\n\n**Note:** As of Android 4.1, the\n`\u003cQuirk\u003e` element for media codecs is no longer supported."]]