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