1 page.title=Media 2 @jd:body 3 4 <!-- 5 Copyright 2015 The Android Open Source Project 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 --> 19 <div id="qv-wrapper"> 20 <div id="qv"> 21 <h2>In this document</h2> 22 <ol id="auto-toc"> 23 </ol> 24 </div> 25 </div> 26 27 <img style="float: right; margin: 0px 15px 15px 15px;" src="images/ape_fwk_hal_media.png" alt="Android Media HAL icon"/> 28 29 <p> 30 Android provides a media playback engine at the native level called 31 Stagefright that comes built-in with software-based codecs for several popular 32 media formats. Stagefright features for audio and video playback include 33 integration with OpenMAX codecs, session management, time-synchronized 34 rendering, transport control, and DRM.</p> 35 36 <p class="note"><strong>Note:</strong> The Stagefright media playback engine 37 had been updated through our <a 38 href="{@docRoot}security/bulletin/index.html">monthly security update</a> 39 process.</p> 40 41 <p>In addition, Stagefright supports integration with custom hardware codecs 42 that you provide. There actually isn't a HAL to implement for custom codecs, 43 but to provide a hardware path to encode and decode media, you must implement 44 your hardware-based codec as an OpenMax IL (Integration Layer) component.</p> 45 46 <h2 id="architecture">Architecture</h2> 47 <p>The following diagram shows how media applications interact with the Android native multimedia framework.</p> 48 <img src="images/ape_fwk_media.png" alt="Android media architecture" id="figure1" /> 49 <p class="img-caption"> 50 <strong>Figure 1.</strong> Media architecture 51 </p> 52 <dl> 53 <dt>Application Framework</dt> 54 <dd>At the application framework level is the app's code, which utilizes the 55 <a href="http://developer.android.com/reference/android/media/package-summary.html">android.media</a> 56 APIs to interact with the multimedia hardware.</dd> 57 <dt>Binder IPC</dt> 58 <dd>The Binder IPC proxies facilitate communication over process boundaries. They are located in 59 the <code>frameworks/av/media/libmedia</code> directory and begin with the letter "I".</dd> 60 <dt>Native Multimedia Framework</dt> 61 <dd>At the native level, Android provides a multimedia framework that utilizes the Stagefright engine for 62 audio and video recording and playback. Stagefright comes with a default list of supported software codecs 63 and you can implement your own hardware codec by using the OpenMax integration layer standard. For more 64 implementation details, see the various MediaPlayer and Stagefright components located in 65 <code>frameworks/av/media</code>. 66 </dd> 67 <dt>OpenMAX Integration Layer (IL)</dt> 68 <dd>The OpenMAX IL provides a standardized way for Stagefright to recognize and use custom hardware-based 69 multimedia codecs called components. You must provide an OpenMAX plugin in the form of a shared library 70 named <code>libstagefrighthw.so</code>. This plugin links your custom codec components to Stagefright. 71 Your custom codecs must be implemented according to the OpenMAX IL component standard. 72 </dd> 73 </dl> 74 75 76 <h2 id="codecs"> 77 Implementing Custom Codecs 78 </h2> 79 <p>Stagefright comes with built-in software codecs for common media formats, but you can also add your 80 own custom hardware codecs as OpenMAX components. To do this, you need to create OMX components and also an 81 OMX plugin that hooks together your custom codecs with the Stagefright framework. For an example, see 82 the <code>hardware/ti/omap4xxx/domx/</code> for example components and <code>hardware/ti/omap4xx/libstagefrighthw</code> 83 for an example plugin for the Galaxy Nexus. 84 </p> 85 <p>To add your own codecs:</p> 86 <ol> 87 <li>Create your components according to the OpenMAX IL component standard. The component interface is located in the 88 <code>frameworks/native/include/media/OpenMAX/OMX_Component.h</code> file. To learn more about the 89 OpenMAX IL specification, see the <a href="http://www.khronos.org/openmax/">OpenMAX website</a>.</li> 90 <li>Create a OpenMAX plugin that links your components with the Stagefright service. 91 See the <code>frameworks/native/include/media/hardware/OMXPluginBase.h</code> and <code>HardwareAPI.h</code> header 92 files for the interfaces to create the plugin. 93 </li> 94 <li>Build your plugin as a shared library with the name <code>libstagefrighthw.so</code> in your product Makefile. For example: 95 <pre>LOCAL_MODULE := libstagefrighthw</pre> 96 97 <p>In your device's Makefile, ensure that you declare the module as a product package:</p> 98 <pre> 99 PRODUCT_PACKAGES += \ 100 libstagefrighthw \ 101 ... 102 </pre> 103 </li> 104 </ol> 105 106 <h2 id="expose">Exposing Codecs to the Framework</h2> 107 <p>The Stagefright service parses the <code>system/etc/media_codecs.xml</code> and <code>system/etc/media_profiles.xml</code> 108 to expose the supported codecs and profiles on the device to app developers via the <code>android.media.MediaCodecList</code> and 109 <code>android.media.CamcorderProfile</code> classes. You need to create both files in the 110 <code>device/<company_name>/<device_name>/</code> directory 111 and copy this over to the system image's <code>system/etc</code> directory in your device's Makefile. 112 For example:</p> 113 114 <pre> 115 PRODUCT_COPY_FILES += \ 116 device/samsung/tuna/media_profiles.xml:system/etc/media_profiles.xml \ 117 device/samsung/tuna/media_codecs.xml:system/etc/media_codecs.xml \ 118 </pre> 119 120 <p>See the <code>device/samsung/tuna/media_codecs.xml</code> and 121 <code>device/samsung/tuna/media_profiles.xml</code> file for complete examples.</p> 122 123 <p class="note"><strong>Note:</strong> The <code><Quirk></code> element for media codecs is no longer supported 124 by Android starting in Jelly Bean.</p> 125