• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H
18 #define ANDROID_HARDWARE_CAMERA_HARDWARE_INTERFACE_H
19 
20 #include <binder/IMemory.h>
21 #include <utils/RefBase.h>
22 #include <ui/ISurface.h>
23 #include <ui/Camera.h>
24 #include <ui/CameraParameters.h>
25 #include <ui/Overlay.h>
26 
27 namespace android {
28 /**
29  *  The size of image for display.
30  */
31 typedef struct image_rect_struct
32 {
33   uint32_t width;      /* Image width */
34   uint32_t height;     /* Image height */
35 } image_rect_type;
36 
37 
38 typedef void (*notify_callback)(int32_t msgType,
39                                 int32_t ext1,
40                                 int32_t ext2,
41                                 void* user);
42 
43 typedef void (*data_callback)(int32_t msgType,
44                               const sp<IMemory>& dataPtr,
45                               void* user);
46 
47 typedef void (*data_callback_timestamp)(nsecs_t timestamp,
48                                         int32_t msgType,
49                                         const sp<IMemory>& dataPtr,
50                                         void* user);
51 
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.
67  *   -# 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.
71  *
72  * 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.
77  *
78  * CameraService calls takePicture() to request the camera instance take a
79  * 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.
82  */
83 class CameraHardwareInterface : public virtual RefBase {
84 public:
~CameraHardwareInterface()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 
93     /** 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 
99     /**
100      * The following three functions all take a msgtype,
101      * which is a bitmask of the messages defined in
102      * include/ui/Camera.h
103      */
104 
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 
127     /**
128      * Only used if overlays are used for camera preview.
129      */
useOverlay()130     virtual bool         useOverlay() {return false;}
setOverlay(const sp<Overlay> & overlay)131     virtual status_t     setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;}
132 
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     /**
144      * 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
146      * by calling releaseRecordingFrame().
147      */
148     virtual status_t    startRecording() = 0;
149 
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;
159 
160     /**
161      * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
162      */
163     virtual void        releaseRecordingFrame(const sp<IMemory>& mem) = 0;
164 
165     /**
166      * 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.
169      */
170     virtual status_t    autoFocus() = 0;
171 
172     /**
173      * 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     /**
181      * Take a picture.
182      */
183     virtual status_t    takePicture() = 0;
184 
185     /**
186      * Cancel a picture that was started with takePicture.  Calling this
187      * method when no picture is being taken is a no-op.
188      */
189     virtual status_t    cancelPicture() = 0;
190 
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     /**
198      * Send command to camera driver.
199      */
200     virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
201 
202     /**
203      * Release the hardware resources owned by this object.  Note that this is
204      * *not* done in the destructor.
205      */
206     virtual void release() = 0;
207 
208     /**
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 */
215 extern "C" sp<CameraHardwareInterface> openCameraHardware();
216 
217 };  // namespace android
218 
219 #endif
220