blob: 14ac96e3baf05ad99bc832fce4bc6aa2a1e69d80 [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>
23
24namespace android {
25
26/** Callback for startPreview() */
27typedef void (*preview_callback)(const sp<IMemory>& mem, void* user);
28
29/** Callback for takePicture() */
30typedef void (*shutter_callback)(void* user);
31
32/** Callback for takePicture() */
33typedef void (*raw_callback)(const sp<IMemory>& mem, void* user);
34
35/** Callback for takePicture() */
36typedef void (*jpeg_callback)(const sp<IMemory>& mem, void* user);
37
38/** Callback for autoFocus() */
39typedef void (*autofocus_callback)(bool focused, void* user);
40
41/**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080042 * CameraHardwareInterface.h defines the interface to the
43 * camera hardware abstraction layer, used for setting and getting
44 * parameters, live previewing, and taking pictures.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070045 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080046 * It is a referenced counted interface with RefBase as its base class.
47 * CameraService calls openCameraHardware() to retrieve a strong pointer to the
48 * instance of this interface and may be called multiple times. The
49 * following steps describe a typical sequence:
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070050 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080051 * -# After CameraService calls openCameraHardware(), getParameters() and
52 * setParameters() are used to initialize the camera instance.
53 * CameraService calls getPreviewHeap() to establish access to the
54 * preview heap so it can be registered with SurfaceFlinger for
55 * efficient display updating while in preview mode.
56 * -# startPreview() is called, which is passed a preview_callback()
57 * function and a user parameter. The camera instance then periodically
58 * calls preview_callback() each time a new preview frame is available.
59 * The callback routine has two parameters: the first is a pointer to
60 * the IMemory containing the frame and the second a user parameter. If
61 * the preview_callback code needs to use this memory after returning,
62 * it must copy the data.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070063 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080064 * Prior to taking a picture, CameraService calls autofocus() with
65 * autofocus_callback() and a user parameter. When auto focusing has
66 * completed, the camera instance calls autofocus_callback(), which informs
67 * the application whether focusing was successful. The camera instance
68 * only calls autofocus_callback() once and it is up to the application to
69 * call autoFocus() again if refocusing is desired.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070070 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080071 * CameraService calls takePicture() to request the camera instance take a
72 * picture. This method has two callbacks: raw_callback() and jpeg_callback().
73 * When the raw image is available, raw_callback() is called with a pointer
74 * to the IMemory containing the raw image. When the jpeg image is available,
75 * jpeg_callback() is called with a pointer to the IMemory containing the
76 * jpeg image. As with preview_callback(), the memory must be copied if it's
77 * needed after returning.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070078 */
79class CameraHardwareInterface : public virtual RefBase {
80public:
81 virtual ~CameraHardwareInterface() { }
82
83 /** Return the IMemoryHeap for the preview image heap */
84 virtual sp<IMemoryHeap> getPreviewHeap() const = 0;
85
86 /**
87 * Start preview mode. When a preview image is available
88 * preview_callback is called with the user parameter. The
89 * call back parameter may be null.
90 */
91 virtual status_t startPreview(preview_callback cb, void* user) = 0;
92
93 /**
94 * Stop a previously started preview.
95 */
96 virtual void stopPreview() = 0;
97
98 /**
99 * Start auto focus, the callback routine is called
100 * once when focusing is complete. autoFocus() will
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800101 * be called again if another auto focus is needed.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700102 */
103 virtual status_t autoFocus(autofocus_callback,
104 void* user) = 0;
105
106 /**
107 * Take a picture. The raw_callback is called when
108 * the uncompressed image is available. The jpeg_callback
109 * is called when the compressed image is available. These
110 * call backs may be null. The user parameter is passed
111 * to each of the call back routines.
112 */
113 virtual status_t takePicture(shutter_callback,
114 raw_callback,
115 jpeg_callback,
116 void* user) = 0;
117
118 /**
119 * Cancel a picture that was started with takePicture. You may cancel any
120 * of the shutter, raw, or jpeg callbacks. Calling this method when no
121 * picture is being taken is a no-op.
122 */
123 virtual status_t cancelPicture(bool cancel_shutter,
124 bool cancel_raw,
125 bool cancel_jpeg) = 0;
126
127 /** Set the camera parameters. */
128 virtual status_t setParameters(const CameraParameters& params) = 0;
129
130 /** Return the camera parameters. */
131 virtual CameraParameters getParameters() const = 0;
132
133 /**
134 * Release the hardware resources owned by this object. Note that this is
135 * *not* done in the destructor.
136 */
137 virtual void release() = 0;
138
139 /**
140 * Dump state of the camera hardware
141 */
142 virtual status_t dump(int fd, const Vector<String16>& args) const = 0;
143};
144
145/** factory function to instantiate a camera hardware object */
146extern "C" sp<CameraHardwareInterface> openCameraHardware();
147
148}; // namespace android
149
150#endif