blob: 41f42d5620a27252d61b6b87092824718bca1c17 [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
Clay Murphy4c746142016-07-11 14:11:37 -070029<p class="note"><strong>Note:</strong> Please see the following pages for the most up-to-date information:<br>
30<a href="{@docRoot}devices/halref/camera_8h_source.html">camera.h</a> source file<br>
31<a href="{@docRoot}devices/halref/camera3_8h_source.html">camera3.h</a> source file<br>
32<a href="{@docRoot}devices/halref/camera__common_8h_source.html">camera_common.h</a> source file<br>
33<a href="https://developer.android.com/reference/android/hardware/camera2/CameraMetadata.html">CameraMetadata</a> developer reference
34</p>
35
Heidi von Markhamb493fb62015-03-25 12:35:11 -070036<p>Android's camera Hardware Abstraction Layer (HAL) connects the higher level
37camera framework APIs in <a href="http://developer.android.com/reference/android/hardware/package-summary.html">android.hardware</a> to your underlying camera driver and hardware. The camera subsystem includes implementations for camera pipeline components while the camera HAL provides interfaces for use in implementing your version of these components.</p>
Heidi von Markham1e7b8b72015-03-09 10:13:48 -070038
39<h2 id="architecture">Architecture</h2>
Heidi von Markhamff5b4b72015-03-31 17:28:50 -070040<p>The following figure and list describe the HAL components:
Robert Ly35f2fda2013-01-29 16:27:05 -080041</p>
42
Heidi von Markham1e7b8b72015-03-09 10:13:48 -070043<img src="images/ape_fwk_camera.png" alt="Android camera architecture" id="figure1" />
Clay Murphy1b77cc22014-12-17 18:20:06 -080044<p class="img-caption">
45 <strong>Figure 1.</strong> Camera architecture
46</p>
Robert Ly35f2fda2013-01-29 16:27:05 -080047
48<dl>
49
50 <dt>Application framework</dt>
51 <dd>At the application framework level is the app's code, which utilizes the <a
52 href="http://developer.android.com/reference/android/hardware/Camera.html">android.hardware.Camera</a>
53 API to interact with the camera hardware. Internally, this code calls a corresponding JNI glue class
54 to access the native code that interacts with the camera.</dd>
55
56 <dt>JNI</dt>
57 <dd>The JNI code associated with <a
58 href="http://developer.android.com/reference/android/hardware/Camera.html">android.hardware.Camera</a> is located in
59 <code>frameworks/base/core/jni/android_hardware_Camera.cpp</code>. This code calls the lower level
60 native code to obtain access to the physical camera and returns data that is used to create the
61 <a href="http://developer.android.com/reference/android/hardware/Camera.html">android.hardware.Camera</a> object at the framework level.</dd>
62
63 <dt>Native framework<dt>
64 <dd>The native framework defined in <code>frameworks/av/camera/Camera.cpp</code> provides a native equivalent
65 to the <a href="http://developer.android.com/reference/android/hardware/Camera.html">android.hardware.Camera</a> class.
66 This class calls the IPC binder proxies to obtain access to the camera service.</dd>
67
68 <dt>Binder IPC proxies</dt>
69 <dd>The IPC binder proxies facilitate communication over process boundaries. There are three camera binder
70 classes that are located in the <code>frameworks/av/camera</code> directory that calls into
71 camera service. ICameraService is the interface to the camera service, ICamera is the interface
72 to a specific opened camera device, and ICameraClient is the device's interface back to the application framework.</dd>
73
74 <dt>Camera service</dt>
75 <dd>The camera service, located in <code>frameworks/av/services/camera/libcameraservice/CameraService.cpp</code>, is the actual code that interacts with the HAL.</p>
76
77 <dt>HAL</dt>
78 <dd>The hardware abstraction layer defines the standard interface that the camera service calls into and that
79 you must implement to have your camera hardware function correctly.
80 </dd>
81
82 <dt>Kernel driver</dt>
83 <dd>The camera's driver interacts with the actual camera hardware and your implementation of the HAL. The
84 camera and driver must support YV12 and NV21 image formats to provide support for
85 previewing the camera image on the display and video recording.</dd>
86 </dl>
87
88
89<h2 id="implementing">Implementing the HAL</h2>
90<p>The HAL sits between the camera driver and the higher level Android framework
91and defines an interface that you must implement so that apps can
92correctly operate the camera hardware. The HAL interface is defined in the
93<code>hardware/libhardware/include/hardware/camera.h</code> and
94<code>hardware/libhardware/include/hardware/camera_common.h</code> header files.
95</p>
96
97<p>
98<code>camera_common.h</code> defines an important struct, <code>camera_module</code>, which defines a standard
99structure to obtain general information about the camera, such as its ID and properties
100that are common to all cameras such as whether or not it is a front or back-facing camera.
101</p>
102
103<p>
104<code>camera.h</code> contains the code that corresponds mainly with
105<a href="http://developer.android.com/reference/android/hardware/Camera.html">android.hardware.Camera</a>. This header file declares a <code>camera_device</code>
106struct that contains a <code>camera_device_ops</code> struct with function pointers
107that point to functions that implement the HAL interface. For documentation on the
108different types of camera parameters that a developer can set,
109see the <code>frameworks/av/include/camera/CameraParameters.h</code> file.
110These parameters are set with the function pointed to by
111<code>int (*set_parameters)(struct camera_device *, const char *parms)</code> in the HAL.
112</p>
113
114<p>For an example of a HAL implementation, see the implementation for the Galaxy Nexus HAL in
115<code>hardware/ti/omap4xxx/camera</code>.</p>
116
117
118<h2 id="configuring">Configuring the Shared Library</h2>
119<p>You need to set up the Android build system to
120 correctly package the HAL implementation into a shared library and copy it to the
121 appropriate location by creating an <code>Android.mk</code> file:
122
123<ol>
124 <li>Create a <code>device/&lt;company_name&gt;/&lt;device_name&gt;/camera</code> directory to contain your
125 library's source files.</li>
126 <li>Create an <code>Android.mk</code> file to build the shared library. Ensure that the Makefile contains the following lines:
127<pre>
128LOCAL_MODULE := camera.&lt;device_name&gt;
Clay Murphyccbdc672014-03-11 20:41:29 +0000129LOCAL_MODULE_RELATIVE_PATH := hw
Robert Ly35f2fda2013-01-29 16:27:05 -0800130</pre>
131<p>Notice that your library must be named <code>camera.&lt;device_name&gt;</code> (<code>.so</code> is appended automatically),
132so that Android can correctly load the library. For an example, see the Makefile
133for the Galaxy Nexus camera located in <code>hardware/ti/omap4xxx/Android.mk</code>.</p>
134
135</li>
136<li>Specify that your device has camera features by copying the necessary feature XML files in the
137<code>frameworks/native/data/etc</code> directory with your
138device's Makefile. For example, to specify that your device has a camera flash and can autofocus,
139add the following lines in your device's
140<code>&lt;device&gt;/&lt;company_name&gt;/&lt;device_name&gt;/device.mk</code> Makefile:
141
142<pre class="no-pretty-print">
143PRODUCT_COPY_FILES := \ ...
144
145PRODUCT_COPY_FILES += \
146frameworks/native/data/etc/android.hardware.camera.flash-autofocus.xml:system/etc/permissions/android.hardware.camera.flash-autofocus.xml \
147</pre>
148
149<p>For an example of a device Makefile, see <code>device/samsung/tuna/device.mk</code>.</p>
150</li>
151
152<li>Declare your camera’s media codec, format, and resolution capabilities in
153<code>device/&lt;company_name&gt;/&lt;device_name&gt;/media_profiles.xml</code> and
154<code>device/&lt;company_name&gt;/&lt;device_name&gt;/media_codecs.xml</code> XML files.
Clay Murphyb6e5f5b2013-10-21 17:01:06 -0700155 For more information, see <a href="{@docRoot}devices/media.html#expose"> Exposing
Robert Ly35f2fda2013-01-29 16:27:05 -0800156 Codecs and Profiles to the Framework</a> for information on how to do this.
157</p></code>
158
159</li>
160
161<li>Add the following lines in your device's
162 <code>device/&lt;company_name&gt;/&lt;device_name&gt;/device.mk</code>
163 Makefile to copy the <code>media_profiles.xml</code>
164and <code>media_codecs.xml</code> files to the appropriate location:
165<pre>
166# media config xml file
167PRODUCT_COPY_FILES += \
168 &lt;device&gt;/&lt;company_name&gt;/&lt;device_name&gt;/media_profiles.xml:system/etc/media_profiles.xml
169
170# media codec config xml file
171PRODUCT_COPY_FILES += \
172 &lt;device&gt;/&lt;company_name&gt;/&lt;device_name&gt;/media_codecs.xml:system/etc/media_codecs.xml
173</pre>
174</li>
175
176<li>
177<p>Declare that you want to include the Camera app in your device's system image by
178specifying it in the <code>PRODUCT_PACKAGES</code> variable in your device's
179 <code>device/&lt;company_name&gt;/&lt;device_name&gt;/device.mk</code>
180 Makefile:</p>
181<pre>
182PRODUCT_PACKAGES := \
183Gallery2 \
184...
185</pre>
186</li>
187
Clay Murphy72bdea02013-06-18 16:44:01 -0700188</ol>