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