blob: f56227d1ff1bf3169880dcf2279b53f45dd477a1 [file] [log] [blame]
Clay Murphyf9d451e2014-10-21 18:11:12 -07001page.title=Camera
Robert Ly35f2fda2013-01-29 16:27:05 -08002@jd:body
3
4<!--
Heidi von Markham1e7b8b72015-03-09 10:13:48 -07005 Copyright 2015 The Android Open Source Project
Robert Ly35f2fda2013-01-29 16:27:05 -08006
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
Heidi von Markhamb493fb62015-03-25 12:35:11 -070027<img style="float: right; margin: 0px 15px 15px 15px;" src="images/ape_fwk_hal_camera.png" alt="Android Camera HAL icon"/>
Heidi von Markham1e7b8b72015-03-09 10:13:48 -070028
Heidi von Markhamb493fb62015-03-25 12:35:11 -070029<p>Android's camera Hardware Abstraction Layer (HAL) connects the higher level
Heidi von Markhama9b85d12016-07-21 13:20:23 -070030camera framework APIs in
31<a href="http://developer.android.com/reference/android/hardware/package-summary.html">android.hardware</a>
32to your underlying camera driver and hardware. The camera subsystem includes
33implementations for camera pipeline components while the camera HAL provides
34interfaces for use in implementing your version of these components.</p>
35
36<p>For the most up-to-date information, refer to the following resources:</p>
37<ul>
38<li><a href="{@docRoot}devices/halref/camera_8h_source.html">camera.h</a> source
39file</li>
40<li><a href="{@docRoot}devices/halref/camera3_8h_source.html">camera3.h</a>
41source file</li>
42<li><a href="{@docRoot}devices/halref/camera__common_8h_source.html">camera_common.h</a>
43source file</li>
44<li><a href="https://developer.android.com/reference/android/hardware/camera2/CameraMetadata.html">CameraMetadata</a>
45developer reference</li>
46</ul>
47
Heidi von Markham1e7b8b72015-03-09 10:13:48 -070048
49<h2 id="architecture">Architecture</h2>
Heidi von Markhama9b85d12016-07-21 13:20:23 -070050<p>The following figure and list describe the HAL components:</p>
Robert Ly35f2fda2013-01-29 16:27:05 -080051
Heidi von Markham1e7b8b72015-03-09 10:13:48 -070052<img src="images/ape_fwk_camera.png" alt="Android camera architecture" id="figure1" />
Heidi von Markhama9b85d12016-07-21 13:20:23 -070053<p class="img-caption"><strong>Figure 1.</strong> Camera architecture</p>
Robert Ly35f2fda2013-01-29 16:27:05 -080054
55<dl>
Robert Ly35f2fda2013-01-29 16:27:05 -080056 <dt>Application framework</dt>
Heidi von Markhama9b85d12016-07-21 13:20:23 -070057 <dd>At the application framework level is the app's code, which utilizes the
58 <a href="http://developer.android.com/reference/android/hardware/Camera.html">android.hardware.Camera</a>
59 API to interact with the camera hardware. Internally, this code calls a
60 corresponding JNI glue class to access the native code that interacts with the
61 camera.</dd>
Robert Ly35f2fda2013-01-29 16:27:05 -080062 <dt>JNI</dt>
Heidi von Markhama9b85d12016-07-21 13:20:23 -070063 <dd>The JNI code associated with <a href="http://developer.android.com/reference/android/hardware/Camera.html">android.hardware.Camera</a>
64 is located in
65 <code>frameworks/base/core/jni/android_hardware_Camera.cpp</code>. This code
66 calls the lower level native code to obtain access to the physical camera
67 and returns data that is used to create the
68 <a href="http://developer.android.com/reference/android/hardware/Camera.html">android.hardware.Camera</a>
69 object at the framework level.</dd>
Robert Ly35f2fda2013-01-29 16:27:05 -080070 <dt>Native framework<dt>
Heidi von Markhama9b85d12016-07-21 13:20:23 -070071 <dd>The native framework defined in <code>frameworks/av/camera/Camera.cpp</code>
72 provides a native equivalent to the
73 <a href="http://developer.android.com/reference/android/hardware/Camera.html">android.hardware.Camera</a>
74 class. This class calls the IPC binder proxies to obtain access to the camera
75 service.</dd>
Robert Ly35f2fda2013-01-29 16:27:05 -080076 <dt>Binder IPC proxies</dt>
Heidi von Markhama9b85d12016-07-21 13:20:23 -070077 <dd>The IPC binder proxies facilitate communication over process boundaries.
78 There are three camera binder classes that are located in
79 <code>frameworks/av/camera</code> directory that calls into camera service.
80 ICameraService is the interface to the camera service, ICamera is the
81 interface to a specific opened camera device, and ICameraClient is the
82 device's interface back to the application framework.</dd>
Robert Ly35f2fda2013-01-29 16:27:05 -080083 <dt>Camera service</dt>
Heidi von Markhama9b85d12016-07-21 13:20:23 -070084 <dd>The camera service, located in
85 <code>frameworks/av/services/camera/libcameraservice/CameraService.cpp</code>,
86 is the actual code that interacts with the HAL.</dd>
Robert Ly35f2fda2013-01-29 16:27:05 -080087 <dt>HAL</dt>
Heidi von Markhama9b85d12016-07-21 13:20:23 -070088 <dd>The hardware abstraction layer defines the standard interface that the
89 camera service calls into and that you must implement to have your camera
90 hardware function correctly.</dd>
Robert Ly35f2fda2013-01-29 16:27:05 -080091 <dt>Kernel driver</dt>
Heidi von Markhama9b85d12016-07-21 13:20:23 -070092 <dd>The camera's driver interacts with the actual camera hardware and your
93 implementation of the HAL. The camera and driver must support YV12 and NV21
94 image formats to provide support for previewing the camera image on the
95 display and video recording.</dd>
96</dl>
Robert Ly35f2fda2013-01-29 16:27:05 -080097
98<h2 id="implementing">Implementing the HAL</h2>
99<p>The HAL sits between the camera driver and the higher level Android framework
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700100and defines an interface you must implement so apps can correctly operate the
101camera hardware. The HAL interface is defined in the
Robert Ly35f2fda2013-01-29 16:27:05 -0800102<code>hardware/libhardware/include/hardware/camera.h</code> and
103<code>hardware/libhardware/include/hardware/camera_common.h</code> header files.
104</p>
105
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700106<p><code>camera_common.h</code> defines <code>camera_module</code>, a standard
107structure to obtain general information about the camera, such as the camera ID
108and properties common to all cameras (i.e., whether it is a front- or
109back-facing camera).</p>
Robert Ly35f2fda2013-01-29 16:27:05 -0800110
111<p>
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700112<code>camera.h</code> contains code that corresponds to
113<a href="http://developer.android.com/reference/android/hardware/Camera.html">android.hardware.Camera</a>. This header file declares a
114<code>camera_device</code> struct that in turn contains a
115<code>camera_device_ops</code> struct with pointers to functions that implement
116the HAL interface. For documentation on the camera parameters developers can
117set, refer to <code>frameworks/av/include/camera/CameraParameters.h</code>.
118These parameters are set with the function pointed to by <code>int
119(*set_parameters)(struct camera_device *, const char *parms)</code> in the HAL.
Robert Ly35f2fda2013-01-29 16:27:05 -0800120</p>
121
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700122<p>For an example of a HAL implementation, refer to the implementation for the
123Galaxy Nexus HAL in <code>hardware/ti/omap4xxx/camera</code>.</p>
Robert Ly35f2fda2013-01-29 16:27:05 -0800124
125
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700126<h2 id="configuring">Configuring the shared library</h2>
127<p>Set up the Android build system to correctly package the HAL implementation
128into a shared library and copy it to the appropriate location by creating an
129<code>Android.mk</code> file:</p>
Robert Ly35f2fda2013-01-29 16:27:05 -0800130
131<ol>
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700132<li>Create a <code>device/&lt;company_name&gt;/&lt;device_name&gt;/camera</code>
133directory to contain your library's source files.</li>
134
135<li>Create an <code>Android.mk</code> file to build the shared library. Ensure
136the Makefile contains the following lines:
Robert Ly35f2fda2013-01-29 16:27:05 -0800137<pre>
138LOCAL_MODULE := camera.&lt;device_name&gt;
Clay Murphyccbdc672014-03-11 20:41:29 +0000139LOCAL_MODULE_RELATIVE_PATH := hw
Robert Ly35f2fda2013-01-29 16:27:05 -0800140</pre>
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700141<p>Your library must be named <code>camera.&lt;device_name&gt;</code>
142(<code>.so</code> is appended automatically), so Android can correctly load the
143library. For an example, see the Makefile for the Galaxy Nexus camera located in
144<code>hardware/ti/omap4xxx/Android.mk</code>.</p></li>
Robert Ly35f2fda2013-01-29 16:27:05 -0800145
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700146<li>Specify your device has camera features by copying the necessary feature XML
147files in the <code>frameworks/native/data/etc</code> directory with your
148device's Makefile. For example, to specify your device has a camera flash and
149can autofocus, add the following lines in your device's
150<code>&lt;device&gt;/&lt;company_name&gt;/&lt;device_name&gt;/device.mk</code>
151Makefile:
Robert Ly35f2fda2013-01-29 16:27:05 -0800152<pre class="no-pretty-print">
153PRODUCT_COPY_FILES := \ ...
154
155PRODUCT_COPY_FILES += \
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700156frameworks/native/data/etc/android.hardware.camera.flash-autofocus.xml:system/etc/permissions/android.hardware.camera.flash-autofocus.xml \
Robert Ly35f2fda2013-01-29 16:27:05 -0800157</pre>
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700158<p>For an example of a device Makefile, see
159<code>device/samsung/tuna/device.mk</code>.</p></li>
Robert Ly35f2fda2013-01-29 16:27:05 -0800160
161<li>Declare your camera’s media codec, format, and resolution capabilities in
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700162<code>device/&lt;company_name&gt;/&lt;device_name&gt;/media_profiles.xml</code>
163and <code>device/&lt;company_name&gt;/&lt;device_name&gt;/media_codecs.xml</code>
164XML files. For details, see
165<a href="{@docRoot}devices/media/index.html#expose">Exposing codecs to the
166framework</a>.</li>
Robert Ly35f2fda2013-01-29 16:27:05 -0800167
168<li>Add the following lines in your device's
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700169<code>device/&lt;company_name&gt;/&lt;device_name&gt;/device.mk</code> Makefile
170to copy the <code>media_profiles.xml</code> and <code>media_codecs.xml</code>
171files to the appropriate location:
Robert Ly35f2fda2013-01-29 16:27:05 -0800172<pre>
173# media config xml file
174PRODUCT_COPY_FILES += \
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700175 &lt;device&gt;/&lt;company&gt;/&lt;device&gt;/media_profiles.xml:system/etc/media_profiles.xml
Robert Ly35f2fda2013-01-29 16:27:05 -0800176
177# media codec config xml file
178PRODUCT_COPY_FILES += \
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700179 &lt;device&gt;/&lt;company&gt;/&lt;device&gt;/media_codecs.xml:system/etc/media_codecs.xml
180</pre></li>
Robert Ly35f2fda2013-01-29 16:27:05 -0800181
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700182<li>To include the Camera app in your device's system image, specify it in the
183<code>PRODUCT_PACKAGES</code> variable in your device's
184<code>device/&lt;company&gt;/&lt;device&gt;/device.mk</code>
185Makefile:
Robert Ly35f2fda2013-01-29 16:27:05 -0800186<pre>
187PRODUCT_PACKAGES := \
188Gallery2 \
189...
Heidi von Markhama9b85d12016-07-21 13:20:23 -0700190</pre></li>
Clay Murphy72bdea02013-06-18 16:44:01 -0700191</ol>