CameraHardwareInterface.h
Go to the documentation of this file.
1 /*
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 #ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H
17 #define ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H
18 #include <binder/IMemory.h>
19 #include <utils/RefBase.h>
20 #include <surfaceflinger/ISurface.h>
21 #include <camera/Camera.h>
22 #include <camera/CameraParameters.h>
23 namespace android {
24 class Overlay;
25 /**
26  * The size of image for display.
27  */
28 typedef struct image_rect_struct
29 {
30  uint32_t width; /* Image width */
31  uint32_t height; /* Image height */
33 typedef void (*notify_callback)(int32_t msgType,
34  int32_t ext1,
35  int32_t ext2,
36  void* user);
37 typedef void (*data_callback)(int32_t msgType,
38  const sp<IMemory>& dataPtr,
39  void* user);
40 typedef void (*data_callback_timestamp)(nsecs_t timestamp,
41  int32_t msgType,
42  const sp<IMemory>& dataPtr,
43  void* user);
44 /**
45  * CameraHardwareInterface.h defines the interface to the
46  * camera hardware abstraction layer, used for setting and getting
47  * parameters, live previewing, and taking pictures.
48  *
49  * It is a referenced counted interface with RefBase as its base class.
50  * CameraService calls openCameraHardware() to retrieve a strong pointer to the
51  * instance of this interface and may be called multiple times. The
52  * following steps describe a typical sequence:
53  *
54  * -# After CameraService calls openCameraHardware(), getParameters() and
55  * setParameters() are used to initialize the camera instance.
56  * CameraService calls getPreviewHeap() to establish access to the
57  * preview heap so it can be registered with SurfaceFlinger for
58  * efficient display updating while in preview mode.
59  * -# startPreview() is called. The camera instance then periodically
60  * sends the message CAMERA_MSG_PREVIEW_FRAME (if enabled) each time
61  * a new preview frame is available. If data callback code needs to use
62  * this memory after returning, it must copy the data.
63  *
64  * Prior to taking a picture, CameraService calls autofocus(). When auto
65  * focusing has completed, the camera instance sends a CAMERA_MSG_FOCUS notification,
66  * which informs the application whether focusing was successful. The camera instance
67  * only sends this message once and it is up to the application to call autoFocus()
68  * again if refocusing is desired.
69  *
70  * CameraService calls takePicture() to request the camera instance take a
71  * picture. At this point, if a shutter, postview, raw, and/or compressed callback
72  * is desired, the corresponding message must be enabled. As with CAMERA_MSG_PREVIEW_FRAME,
73  * any memory provided in a data callback must be copied if it's needed after returning.
74  */
75 class CameraHardwareInterface : public virtual RefBase {
76 public:
78  /** Return the IMemoryHeap for the preview image heap */
79  virtual sp<IMemoryHeap> getPreviewHeap() const = 0;
80  /** Return the IMemoryHeap for the raw image heap */
81  virtual sp<IMemoryHeap> getRawHeap() const = 0;
82  /** Set the notification and data callbacks */
83  virtual void setCallbacks(notify_callback notify_cb,
84  data_callback data_cb,
85  data_callback_timestamp data_cb_timestamp,
86  void* user) = 0;
87  /**
88  * The following three functions all take a msgtype,
89  * which is a bitmask of the messages defined in
90  * include/ui/Camera.h
91  */
92  /**
93  * Enable a message, or set of messages.
94  */
95  virtual void enableMsgType(int32_t msgType) = 0;
96  /**
97  * Disable a message, or a set of messages.
98  */
99  virtual void disableMsgType(int32_t msgType) = 0;
100  /**
101  * Query whether a message, or a set of messages, is enabled.
102  * Note that this is operates as an AND, if any of the messages
103  * queried are off, this will return false.
104  */
105  virtual bool msgTypeEnabled(int32_t msgType) = 0;
106  /**
107  * Start preview mode.
108  */
109  virtual status_t startPreview() = 0;
110  /**
111  * Only used if overlays are used for camera preview.
112  */
113  virtual bool useOverlay() {return false;}
114  virtual status_t setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;}
115  /**
116  * Stop a previously started preview.
117  */
118  virtual void stopPreview() = 0;
119  /**
120  * Returns true if preview is enabled.
121  */
122  virtual bool previewEnabled() = 0;
123  /**
124  * Start record mode. When a record image is available a CAMERA_MSG_VIDEO_FRAME
125  * message is sent with the corresponding frame. Every record frame must be released
126  * by calling releaseRecordingFrame().
127  */
128  virtual status_t startRecording() = 0;
129  /**
130  * Stop a previously started recording.
131  */
132  virtual void stopRecording() = 0;
133  /**
134  * Returns true if recording is enabled.
135  */
136  virtual bool recordingEnabled() = 0;
137  /**
138  * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
139  */
140  virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;
141  /**
142  * Start auto focus, the notification callback routine is called
143  * with CAMERA_MSG_FOCUS once when focusing is complete. autoFocus()
144  * will be called again if another auto focus is needed.
145  */
146  virtual status_t autoFocus() = 0;
147  /**
148  * Cancels auto-focus function. If the auto-focus is still in progress,
149  * this function will cancel it. Whether the auto-focus is in progress
150  * or not, this function will return the focus position to the default.
151  * If the camera does not support auto-focus, this is a no-op.
152  */
153  virtual status_t cancelAutoFocus() = 0;
154  /**
155  * Take a picture.
156  */
157  virtual status_t takePicture() = 0;
158  /**
159  * Cancel a picture that was started with takePicture. Calling this
160  * method when no picture is being taken is a no-op.
161  */
162  virtual status_t cancelPicture() = 0;
163  /**
164  * Set the camera parameters. This returns BAD_VALUE if any parameter is
165  * invalid or not supported. */
166  virtual status_t setParameters(const CameraParameters& params) = 0;
167  /** Return the camera parameters. */
168  virtual CameraParameters getParameters() const = 0;
169  /**
170  * Send command to camera driver.
171  */
172  virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
173  /**
174  * Release the hardware resources owned by this object. Note that this is
175  * *not* done in the destructor.
176  */
177  virtual void release() = 0;
178  /**
179  * Dump state of the camera hardware
180  */
181  virtual status_t dump(int fd, const Vector<String16>& args) const = 0;
182 };
183 /**
184  * The functions need to be provided by the camera HAL.
185  *
186  * If getNumberOfCameras() returns N, the valid cameraId for getCameraInfo()
187  * and openCameraHardware() is 0 to N-1.
188  */
189 extern "C" int HAL_getNumberOfCameras();
190 extern "C" void HAL_getCameraInfo(int cameraId, struct CameraInfo* cameraInfo);
191 /* HAL should return NULL if it fails to open camera hardware. */
192 extern "C" sp<CameraHardwareInterface> HAL_openCameraHardware(int cameraId);
193 }; // namespace android
194 #endif
virtual void stopPreview()=0
Stop a previously started preview.
virtual status_t takePicture()=0
Take a picture.
struct android::image_rect_struct image_rect_type
The size of image for display.
virtual status_t setOverlay(const sp< Overlay > &overlay)
virtual status_t cancelPicture()=0
Cancel a picture that was started with takePicture.
int HAL_getNumberOfCameras()
The functions need to be provided by the camera HAL.
virtual status_t cancelAutoFocus()=0
Cancels auto-focus function.
virtual bool recordingEnabled()=0
Returns true if recording is enabled.
sp< CameraHardwareInterface > HAL_openCameraHardware(int cameraId)
virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)=0
Send command to camera driver.
virtual void release()=0
Release the hardware resources owned by this object.
CameraHardwareInterface.h defines the interface to the camera hardware abstraction layer...
virtual bool previewEnabled()=0
Returns true if preview is enabled.
virtual void enableMsgType(int32_t msgType)=0
The following three functions all take a msgtype, which is a bitmask of the messages defined in inclu...
virtual bool msgTypeEnabled(int32_t msgType)=0
Query whether a message, or a set of messages, is enabled.
virtual status_t startPreview()=0
Start preview mode.
virtual status_t setParameters(const CameraParameters &params)=0
Set the camera parameters.
virtual sp< IMemoryHeap > getPreviewHeap() const =0
Return the IMemoryHeap for the preview image heap.
virtual sp< IMemoryHeap > getRawHeap() const =0
Return the IMemoryHeap for the raw image heap.
virtual status_t dump(int fd, const Vector< String16 > &args) const =0
Dump state of the camera hardware.
virtual void releaseRecordingFrame(const sp< IMemory > &mem)=0
Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
void(* data_callback)(int32_t msgType, const sp< IMemory > &dataPtr, void *user)
void(* notify_callback)(int32_t msgType, int32_t ext1, int32_t ext2, void *user)
virtual status_t startRecording()=0
Start record mode.
void(* data_callback_timestamp)(nsecs_t timestamp, int32_t msgType, const sp< IMemory > &dataPtr, void *user)
virtual void disableMsgType(int32_t msgType)=0
Disable a message, or a set of messages.
virtual bool useOverlay()
Only used if overlays are used for camera preview.
virtual CameraParameters getParameters() const =0
Return the camera parameters.
virtual status_t autoFocus()=0
Start auto focus, the notification callback routine is called with CAMERA_MSG_FOCUS once when focusin...
virtual void stopRecording()=0
Stop a previously started recording.
void HAL_getCameraInfo(int cameraId, struct CameraInfo *cameraInfo)
virtual void setCallbacks(notify_callback notify_cb, data_callback data_cb, data_callback_timestamp data_cb_timestamp, void *user)=0
Set the notification and data callbacks.
The size of image for display.