blob: b068c52f542c908cef217e4e7c97a6b54ed4dcf2 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H
18#define ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H
19
20#include <utils/IMemory.h>
21#include <utils/RefBase.h>
22#include <ui/CameraParameters.h>
The Android Open Source Projecta6938ba2009-02-10 15:44:00 -080023#include <ui/Overlay.h>
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070024
25namespace android {
26
27/** Callback for startPreview() */
28typedef void (*preview_callback)(const sp<IMemory>& mem, void* user);
29
The Android Open Source Projecta6938ba2009-02-10 15:44:00 -080030/** Callback for startRecord() */
31typedef void (*recording_callback)(const sp<IMemory>& mem, void* user);
32
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070033/** Callback for takePicture() */
34typedef void (*shutter_callback)(void* user);
35
36/** Callback for takePicture() */
37typedef void (*raw_callback)(const sp<IMemory>& mem, void* user);
38
39/** Callback for takePicture() */
40typedef void (*jpeg_callback)(const sp<IMemory>& mem, void* user);
41
42/** Callback for autoFocus() */
43typedef void (*autofocus_callback)(bool focused, void* user);
44
45/**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080046 * CameraHardwareInterface.h defines the interface to the
47 * camera hardware abstraction layer, used for setting and getting
48 * parameters, live previewing, and taking pictures.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070049 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080050 * It is a referenced counted interface with RefBase as its base class.
51 * CameraService calls openCameraHardware() to retrieve a strong pointer to the
52 * instance of this interface and may be called multiple times. The
53 * following steps describe a typical sequence:
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070054 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080055 * -# After CameraService calls openCameraHardware(), getParameters() and
56 * setParameters() are used to initialize the camera instance.
57 * CameraService calls getPreviewHeap() to establish access to the
58 * preview heap so it can be registered with SurfaceFlinger for
59 * efficient display updating while in preview mode.
60 * -# startPreview() is called, which is passed a preview_callback()
61 * function and a user parameter. The camera instance then periodically
62 * calls preview_callback() each time a new preview frame is available.
63 * The callback routine has two parameters: the first is a pointer to
64 * the IMemory containing the frame and the second a user parameter. If
65 * the preview_callback code needs to use this memory after returning,
66 * it must copy the data.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070067 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080068 * Prior to taking a picture, CameraService calls autofocus() with
69 * autofocus_callback() and a user parameter. When auto focusing has
70 * completed, the camera instance calls autofocus_callback(), which informs
71 * the application whether focusing was successful. The camera instance
72 * only calls autofocus_callback() once and it is up to the application to
73 * call autoFocus() again if refocusing is desired.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070074 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080075 * CameraService calls takePicture() to request the camera instance take a
76 * picture. This method has two callbacks: raw_callback() and jpeg_callback().
77 * When the raw image is available, raw_callback() is called with a pointer
78 * to the IMemory containing the raw image. When the jpeg image is available,
79 * jpeg_callback() is called with a pointer to the IMemory containing the
80 * jpeg image. As with preview_callback(), the memory must be copied if it's
81 * needed after returning.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070082 */
83class CameraHardwareInterface : public virtual RefBase {
84public:
85 virtual ~CameraHardwareInterface() { }
86
87 /** Return the IMemoryHeap for the preview image heap */
88 virtual sp<IMemoryHeap> getPreviewHeap() const = 0;
89
90 /**
91 * Start preview mode. When a preview image is available
92 * preview_callback is called with the user parameter. The
93 * call back parameter may be null.
94 */
95 virtual status_t startPreview(preview_callback cb, void* user) = 0;
The Android Open Source Projecta6938ba2009-02-10 15:44:00 -080096 /**
97 * Only used if overlays are used for camera preview.
98 */
99 virtual bool useOverlay() {return false;}
100 virtual status_t setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;}
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700101
102 /**
103 * Stop a previously started preview.
104 */
105 virtual void stopPreview() = 0;
106
107 /**
The Android Open Source Project27629322009-01-09 17:51:23 -0800108 * Returns true if preview is enabled.
109 */
110 virtual bool previewEnabled() = 0;
111
112 /**
The Android Open Source Projecta6938ba2009-02-10 15:44:00 -0800113 * Start record mode. When a record image is available recording_callback()
114 * is called with the user parameter. Every record frame must be released
115 * by calling releaseRecordingFrame().
116 */
117 virtual status_t startRecording(recording_callback cb, void* user) = 0;
118
119 /**
120 * Stop a previously started recording.
121 */
122 virtual void stopRecording() = 0;
123
124 /**
125 * Returns true if recording is enabled.
126 */
127 virtual bool recordingEnabled() = 0;
128
129 /**
130 * Release a record frame previously returned by the recording_callback()
131 * passed to startRecord().
132 */
133 virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;
134
135 /**
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700136 * Start auto focus, the callback routine is called
137 * once when focusing is complete. autoFocus() will
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800138 * be called again if another auto focus is needed.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700139 */
140 virtual status_t autoFocus(autofocus_callback,
141 void* user) = 0;
142
143 /**
144 * Take a picture. The raw_callback is called when
145 * the uncompressed image is available. The jpeg_callback
146 * is called when the compressed image is available. These
147 * call backs may be null. The user parameter is passed
148 * to each of the call back routines.
149 */
150 virtual status_t takePicture(shutter_callback,
151 raw_callback,
152 jpeg_callback,
153 void* user) = 0;
154
155 /**
156 * Cancel a picture that was started with takePicture. You may cancel any
157 * of the shutter, raw, or jpeg callbacks. Calling this method when no
158 * picture is being taken is a no-op.
159 */
160 virtual status_t cancelPicture(bool cancel_shutter,
161 bool cancel_raw,
162 bool cancel_jpeg) = 0;
163
164 /** Set the camera parameters. */
165 virtual status_t setParameters(const CameraParameters& params) = 0;
166
167 /** Return the camera parameters. */
168 virtual CameraParameters getParameters() const = 0;
169
170 /**
171 * Release the hardware resources owned by this object. Note that this is
172 * *not* done in the destructor.
173 */
174 virtual void release() = 0;
175
176 /**
177 * Dump state of the camera hardware
178 */
179 virtual status_t dump(int fd, const Vector<String16>& args) const = 0;
180};
181
182/** factory function to instantiate a camera hardware object */
183extern "C" sp<CameraHardwareInterface> openCameraHardware();
184
185}; // namespace android
186
187#endif