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