Home | History | Annotate | Download | only in media
      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;"
     28 src="images/ape_fwk_hal_media.png" alt="Android Media HAL icon"/>
     29 
     30 <p>Android includes Stagefright, a media playback engine at the native level
     31 that has built-in software-based codecs for popular media formats.</p>
     32 
     33 <p>Stagefright audio and video playback features include integration with
     34 OpenMAX codecs, session management, time-synchronized rendering, transport
     35 control, and DRM.</p>
     36 
     37 <p>Stagefright also supports integration with custom hardware codecs provided by
     38 you. To set a hardware path to encode and decode media, you must implement a
     39 hardware-based codec as an OpenMax IL (Integration Layer) component.</p>
     40 
     41 <p class="note"><strong>Note:</strong> Stagefright updates can occur through the
     42 Android <a href="{@docRoot}security/bulletin/index.html">monthly security
     43 update</a> process and as part of an Android OS release.</p>
     44 
     45 <h2 id="architecture">Architecture</h2>
     46 <p>Media applications interact with the Android native multimedia framework
     47 according to the following architecture.</p>
     48 <img src="images/ape_fwk_media.png" alt="Android media architecture"
     49 id="figure1" /><p class="img-caption"><strong>Figure 1.</strong> Media
     50 architecture</p>
     51 
     52 <dl>
     53 <dt>Application Framework</dt>
     54 <dd>At the application framework level is application code that utilizes
     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 
     58 <dt>Binder IPC</dt>
     59 <dd>The Binder IPC proxies facilitate communication over process boundaries.
     60 They are located in the <code>frameworks/av/media/libmedia</code> directory and
     61 begin with the letter "I".</dd>
     62 
     63 <dt>Native Multimedia Framework</dt>
     64 <dd>At the native level, Android provides a multimedia framework that utilizes
     65 the Stagefright engine for audio and video recording and playback. Stagefright
     66 comes with a default list of supported software codecs and you can implement
     67 your own hardware codec by using the OpenMax integration layer standard. For
     68 more implementation details, see the MediaPlayer and Stagefright components
     69 located in <code>frameworks/av/media</code>.</dd>
     70 
     71 <dt>OpenMAX Integration Layer (IL)</dt>
     72 <dd>The OpenMAX IL provides a standardized way for Stagefright to recognize and
     73 use custom hardware-based multimedia codecs called components. You must provide
     74 an OpenMAX plugin in the form of a shared library named
     75 <code>libstagefrighthw.so</code>. This plugin links Stagefright with your custom
     76 codec components, which must be implemented according to the OpenMAX IL
     77 component standard.</dd>
     78 </dl>
     79 
     80 <h2 id="codecs">Implementing custom codecs</h2>
     81 <p>Stagefright comes with built-in software codecs for common media formats, but
     82 you can also add your own custom hardware codecs as OpenMAX components. To do
     83 this, you must create the OMX components and an OMX plugin that hooks together
     84 your custom codecs with the Stagefright framework. For example components, see
     85 the <code>hardware/ti/omap4xxx/domx/</code>; for an example plugin for the
     86 Galaxy Nexus, see <code>hardware/ti/omap4xx/libstagefrighthw</code>.</p>
     87 
     88 <p>To add your own codecs:</p>
     89 <ol>
     90 <li>Create your components according to the OpenMAX IL component standard. The
     91 component interface is located in the
     92 <code>frameworks/native/include/media/OpenMAX/OMX_Component.h</code> file. To
     93 learn more about the OpenMAX IL specification, refer to the
     94 <a href="http://www.khronos.org/openmax/">OpenMAX website</a>.</li>
     95 <li>Create a OpenMAX plugin that links your components with the Stagefright
     96 service. For the interfaces to create the plugin, see
     97 <code>frameworks/native/include/media/hardware/OMXPluginBase.h</code> and
     98 <code>HardwareAPI.h</code> header files.</li>
     99 <li>Build your plugin as a shared library with the name
    100 <code>libstagefrighthw.so</code> in your product Makefile. For example:
    101 <br>
    102 <p><pre>LOCAL_MODULE := libstagefrighthw</pre></p>
    103 <p>In your device's Makefile, ensure you declare the module as a product
    104 package:</p>
    105 <pre>
    106 PRODUCT_PACKAGES += \
    107   libstagefrighthw \
    108   ...
    109 </pre></li></ol>
    110 
    111 <h2 id="expose">Exposing codecs to the framework</h2>
    112 <p>The Stagefright service parses the <code>system/etc/media_codecs.xml</code>
    113 and <code>system/etc/media_profiles.xml</code> to expose the supported codecs
    114 and profiles on the device to app developers via the
    115 <code>android.media.MediaCodecList</code> and
    116 <code>android.media.CamcorderProfile</code> classes. You must create both files
    117 in the <code>device/&lt;company&gt;/&lt;device&gt;/</code> directory
    118 and copy this over to the system image's <code>system/etc</code> directory in
    119 your device's Makefile. For example:</p>
    120 <pre>
    121 PRODUCT_COPY_FILES += \
    122   device/samsung/tuna/media_profiles.xml:system/etc/media_profiles.xml \
    123   device/samsung/tuna/media_codecs.xml:system/etc/media_codecs.xml \
    124 </pre>
    125 
    126 <p>For complete examples, seee <code>device/samsung/tuna/media_codecs.xml</code>
    127 and <code>device/samsung/tuna/media_profiles.xml</code> .</p>
    128 
    129 <p class="note"><strong>Note:</strong> As of Android 4.1, the
    130 <code>&lt;Quirk&gt;</code> element for media codecs is no longer supported.</p>
    131