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