blob: 240c1348a35efc7f7068aa3595b5795307b133df [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Mathias Agopian07952722009-05-19 19:08:10 -070020#include <binder/IMemory.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021#include <utils/RefBase.h>
Benny Wongda83f462009-08-12 12:01:27 -050022#include <ui/ISurface.h>
23#include <ui/Camera.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024#include <ui/CameraParameters.h>
25#include <ui/Overlay.h>
26
27namespace android {
Wu-cheng Li4cb04c42009-10-23 17:39:46 +080028/**
29 * The size of image for display.
30 */
31typedef struct image_rect_struct
32{
33 uint32_t width; /* Image width */
34 uint32_t height; /* Image height */
35} image_rect_type;
36
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
Benny Wongda83f462009-08-12 12:01:27 -050038typedef void (*notify_callback)(int32_t msgType,
39 int32_t ext1,
40 int32_t ext2,
41 void* user);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
Benny Wongda83f462009-08-12 12:01:27 -050043typedef void (*data_callback)(int32_t msgType,
44 const sp<IMemory>& dataPtr,
45 void* user);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046
Benny Wongda83f462009-08-12 12:01:27 -050047typedef void (*data_callback_timestamp)(nsecs_t timestamp,
48 int32_t msgType,
49 const sp<IMemory>& dataPtr,
50 void* user);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52/**
53 * CameraHardwareInterface.h defines the interface to the
54 * camera hardware abstraction layer, used for setting and getting
55 * parameters, live previewing, and taking pictures.
56 *
57 * It is a referenced counted interface with RefBase as its base class.
58 * CameraService calls openCameraHardware() to retrieve a strong pointer to the
59 * instance of this interface and may be called multiple times. The
60 * following steps describe a typical sequence:
61 *
62 * -# After CameraService calls openCameraHardware(), getParameters() and
63 * setParameters() are used to initialize the camera instance.
64 * CameraService calls getPreviewHeap() to establish access to the
65 * preview heap so it can be registered with SurfaceFlinger for
66 * efficient display updating while in preview mode.
Benny Wongda83f462009-08-12 12:01:27 -050067 * -# startPreview() is called. The camera instance then periodically
68 * sends the message CAMERA_MSG_PREVIEW_FRAME (if enabled) each time
69 * a new preview frame is available. If data callback code needs to use
70 * this memory after returning, it must copy the data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 *
Benny Wongda83f462009-08-12 12:01:27 -050072 * Prior to taking a picture, CameraService calls autofocus(). When auto
73 * focusing has completed, the camera instance sends a CAMERA_MSG_FOCUS notification,
74 * which informs the application whether focusing was successful. The camera instance
75 * only sends this message once and it is up to the application to call autoFocus()
76 * again if refocusing is desired.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 *
78 * CameraService calls takePicture() to request the camera instance take a
Benny Wongda83f462009-08-12 12:01:27 -050079 * picture. At this point, if a shutter, postview, raw, and/or compressed callback
80 * is desired, the corresponding message must be enabled. As with CAMERA_MSG_PREVIEW_FRAME,
81 * any memory provided in a data callback must be copied if it's needed after returning.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 */
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 /** Return the IMemoryHeap for the raw image heap */
91 virtual sp<IMemoryHeap> getRawHeap() const = 0;
92
Benny Wongda83f462009-08-12 12:01:27 -050093 /** Set the notification and data callbacks */
94 virtual void setCallbacks(notify_callback notify_cb,
95 data_callback data_cb,
96 data_callback_timestamp data_cb_timestamp,
97 void* user) = 0;
98
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 /**
Benny Wongda83f462009-08-12 12:01:27 -0500100 * The following three functions all take a msgtype,
101 * which is a bitmask of the messages defined in
102 * include/ui/Camera.h
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 */
Benny Wongda83f462009-08-12 12:01:27 -0500104
105 /**
106 * Enable a message, or set of messages.
107 */
108 virtual void enableMsgType(int32_t msgType) = 0;
109
110 /**
111 * Disable a message, or a set of messages.
112 */
113 virtual void disableMsgType(int32_t msgType) = 0;
114
115 /**
116 * Query whether a message, or a set of messages, is enabled.
117 * Note that this is operates as an AND, if any of the messages
118 * queried are off, this will return false.
119 */
120 virtual bool msgTypeEnabled(int32_t msgType) = 0;
121
122 /**
123 * Start preview mode.
124 */
125 virtual status_t startPreview() = 0;
126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 /**
128 * Only used if overlays are used for camera preview.
129 */
Benny Wongda83f462009-08-12 12:01:27 -0500130 virtual bool useOverlay() {return false;}
131 virtual status_t setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132
133 /**
134 * Stop a previously started preview.
135 */
136 virtual void stopPreview() = 0;
137
138 /**
139 * Returns true if preview is enabled.
140 */
141 virtual bool previewEnabled() = 0;
142
143 /**
Benny Wongda83f462009-08-12 12:01:27 -0500144 * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME
145 * message is sent with the corresponding frame. Every record frame must be released
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 * by calling releaseRecordingFrame().
147 */
Benny Wongda83f462009-08-12 12:01:27 -0500148 virtual status_t startRecording() = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149
150 /**
151 * Stop a previously started recording.
152 */
153 virtual void stopRecording() = 0;
154
155 /**
156 * Returns true if recording is enabled.
157 */
158 virtual bool recordingEnabled() = 0;
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 /**
Benny Wongda83f462009-08-12 12:01:27 -0500161 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 */
163 virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;
164
165 /**
Benny Wongda83f462009-08-12 12:01:27 -0500166 * Start auto focus, the notification callback routine is called
167 * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus()
168 * will be called again if another auto focus is needed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 */
Benny Wongda83f462009-08-12 12:01:27 -0500170 virtual status_t autoFocus() = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171
172 /**
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800173 * Cancels auto-focus function. If the auto-focus is still in progress,
174 * this function will cancel it. Whether the auto-focus is in progress
175 * or not, this function will return the focus position to the default.
176 * If the camera does not support auto-focus, this is a no-op.
177 */
178 virtual status_t cancelAutoFocus() = 0;
179
180 /**
Benny Wongda83f462009-08-12 12:01:27 -0500181 * Take a picture.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 */
Benny Wongda83f462009-08-12 12:01:27 -0500183 virtual status_t takePicture() = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184
185 /**
Benny Wongda83f462009-08-12 12:01:27 -0500186 * Cancel a picture that was started with takePicture. Calling this
187 * method when no picture is being taken is a no-op.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 */
Benny Wongda83f462009-08-12 12:01:27 -0500189 virtual status_t cancelPicture() = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190
191 /** Set the camera parameters. */
192 virtual status_t setParameters(const CameraParameters& params) = 0;
193
194 /** Return the camera parameters. */
195 virtual CameraParameters getParameters() const = 0;
196
197 /**
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700198 * Send command to camera driver.
199 */
200 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
201
202 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 * Release the hardware resources owned by this object. Note that this is
204 * *not* done in the destructor.
205 */
206 virtual void release() = 0;
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 /**
209 * Dump state of the camera hardware
210 */
211 virtual status_t dump(int fd, const Vector<String16>& args) const = 0;
212};
213
214/** factory function to instantiate a camera hardware object */
215extern "C" sp<CameraHardwareInterface> openCameraHardware();
216
217}; // namespace android
218
219#endif