blob: 535f70e0cdc6e68f0db8e717cc51f3c2c08e7656 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-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 Agopianc5b2c0b2009-05-19 19:08:10 -070020#include <binder/IMemory.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021#include <utils/RefBase.h>
Benny Wong4c8fb0a2009-08-12 12:01:27 -050022#include <ui/ISurface.h>
23#include <ui/Camera.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080024#include <ui/CameraParameters.h>
25#include <ui/Overlay.h>
26
27namespace android {
28
Benny Wong4c8fb0a2009-08-12 12:01:27 -050029typedef void (*notify_callback)(int32_t msgType,
30 int32_t ext1,
31 int32_t ext2,
32 void* user);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
Benny Wong4c8fb0a2009-08-12 12:01:27 -050034typedef void (*data_callback)(int32_t msgType,
35 const sp<IMemory>& dataPtr,
36 void* user);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037
Benny Wong4c8fb0a2009-08-12 12:01:27 -050038typedef void (*data_callback_timestamp)(nsecs_t timestamp,
39 int32_t msgType,
40 const sp<IMemory>& dataPtr,
41 void* user);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
43/**
44 * CameraHardwareInterface.h defines the interface to the
45 * camera hardware abstraction layer, used for setting and getting
46 * parameters, live previewing, and taking pictures.
47 *
48 * It is a referenced counted interface with RefBase as its base class.
49 * CameraService calls openCameraHardware() to retrieve a strong pointer to the
50 * instance of this interface and may be called multiple times. The
51 * following steps describe a typical sequence:
52 *
53 * -# After CameraService calls openCameraHardware(), getParameters() and
54 * setParameters() are used to initialize the camera instance.
55 * CameraService calls getPreviewHeap() to establish access to the
56 * preview heap so it can be registered with SurfaceFlinger for
57 * efficient display updating while in preview mode.
Benny Wong4c8fb0a2009-08-12 12:01:27 -050058 * -# startPreview() is called. The camera instance then periodically
59 * sends the message CAMERA_MSG_PREVIEW_FRAME (if enabled) each time
60 * a new preview frame is available. If data callback code needs to use
61 * this memory after returning, it must copy the data.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062 *
Benny Wong4c8fb0a2009-08-12 12:01:27 -050063 * Prior to taking a picture, CameraService calls autofocus(). When auto
64 * focusing has completed, the camera instance sends a CAMERA_MSG_FOCUS notification,
65 * which informs the application whether focusing was successful. The camera instance
66 * only sends this message once and it is up to the application to call autoFocus()
67 * again if refocusing is desired.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068 *
69 * CameraService calls takePicture() to request the camera instance take a
Benny Wong4c8fb0a2009-08-12 12:01:27 -050070 * picture. At this point, if a shutter, postview, raw, and/or compressed callback
71 * is desired, the corresponding message must be enabled. As with CAMERA_MSG_PREVIEW_FRAME,
72 * any memory provided in a data callback must be copied if it's needed after returning.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080073 */
74class CameraHardwareInterface : public virtual RefBase {
75public:
76 virtual ~CameraHardwareInterface() { }
77
78 /** Return the IMemoryHeap for the preview image heap */
79 virtual sp<IMemoryHeap> getPreviewHeap() const = 0;
80
81 /** Return the IMemoryHeap for the raw image heap */
82 virtual sp<IMemoryHeap> getRawHeap() const = 0;
83
Benny Wong4c8fb0a2009-08-12 12:01:27 -050084 /** Set the notification and data callbacks */
85 virtual void setCallbacks(notify_callback notify_cb,
86 data_callback data_cb,
87 data_callback_timestamp data_cb_timestamp,
88 void* user) = 0;
89
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090 /**
Benny Wong4c8fb0a2009-08-12 12:01:27 -050091 * The following three functions all take a msgtype,
92 * which is a bitmask of the messages defined in
93 * include/ui/Camera.h
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094 */
Benny Wong4c8fb0a2009-08-12 12:01:27 -050095
96 /**
97 * Enable a message, or set of messages.
98 */
99 virtual void enableMsgType(int32_t msgType) = 0;
100
101 /**
102 * Disable a message, or a set of messages.
103 */
104 virtual void disableMsgType(int32_t msgType) = 0;
105
106 /**
107 * Query whether a message, or a set of messages, is enabled.
108 * Note that this is operates as an AND, if any of the messages
109 * queried are off, this will return false.
110 */
111 virtual bool msgTypeEnabled(int32_t msgType) = 0;
112
113 /**
114 * Start preview mode.
115 */
116 virtual status_t startPreview() = 0;
117
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118 /**
119 * Only used if overlays are used for camera preview.
120 */
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500121 virtual bool useOverlay() {return false;}
122 virtual status_t setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800123
124 /**
125 * Stop a previously started preview.
126 */
127 virtual void stopPreview() = 0;
128
129 /**
130 * Returns true if preview is enabled.
131 */
132 virtual bool previewEnabled() = 0;
133
134 /**
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500135 * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME
136 * message is sent with the corresponding frame. Every record frame must be released
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800137 * by calling releaseRecordingFrame().
138 */
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500139 virtual status_t startRecording() = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800140
141 /**
142 * Stop a previously started recording.
143 */
144 virtual void stopRecording() = 0;
145
146 /**
147 * Returns true if recording is enabled.
148 */
149 virtual bool recordingEnabled() = 0;
150
151 /**
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500152 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153 */
154 virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;
155
156 /**
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500157 * Start auto focus, the notification callback routine is called
158 * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus()
159 * will be called again if another auto focus is needed.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800160 */
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500161 virtual status_t autoFocus() = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800162
163 /**
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500164 * Take a picture.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165 */
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500166 virtual status_t takePicture() = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800167
168 /**
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500169 * Cancel a picture that was started with takePicture. Calling this
170 * method when no picture is being taken is a no-op.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800171 */
Benny Wong4c8fb0a2009-08-12 12:01:27 -0500172 virtual status_t cancelPicture() = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800173
174 /** Set the camera parameters. */
175 virtual status_t setParameters(const CameraParameters& params) = 0;
176
177 /** Return the camera parameters. */
178 virtual CameraParameters getParameters() const = 0;
179
180 /**
181 * Release the hardware resources owned by this object. Note that this is
182 * *not* done in the destructor.
183 */
184 virtual void release() = 0;
185
186 /**
187 * Dump state of the camera hardware
188 */
189 virtual status_t dump(int fd, const Vector<String16>& args) const = 0;
190};
191
192/** factory function to instantiate a camera hardware object */
193extern "C" sp<CameraHardwareInterface> openCameraHardware();
194
195}; // namespace android
196
197#endif