blob: 562a0a226e2b3784eafb46935d9ce4001c65add3 [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_H
18#define ANDROID_HARDWARE_CAMERA_H
19
20#include <ui/ICameraClient.h>
21
22namespace android {
23
24class ICameraService;
25class ICamera;
26class Surface;
27class Mutex;
28class String8;
29
30typedef void (*shutter_callback)(void *cookie);
31typedef void (*frame_callback)(const sp<IMemory>& mem, void *cookie);
32typedef void (*autofocus_callback)(bool focused, void *cookie);
33typedef void (*error_callback)(status_t err, void *cookie);
34
35class Camera : public BnCameraClient, public IBinder::DeathRecipient
36{
37public:
38 static sp<Camera> connect();
39 ~Camera();
40
41 void disconnect();
42
43 status_t getStatus() { return mStatus; }
44
45 // pass the buffered ISurface to the camera service
46 status_t setPreviewDisplay(const sp<Surface>& surface);
47
48 // start preview mode, must call setPreviewDisplay first
49 status_t startPreview();
50
51 // stop preview mode
52 void stopPreview();
53
54 // autoFocus - status returned from callback
55 status_t autoFocus();
56
57 // take a picture - picture returned from callback
58 status_t takePicture();
59
60 // set preview/capture parameters - key/value pairs
61 status_t setParameters(const String8& params);
62
63 // get preview/capture parameters - key/value pairs
64 String8 getParameters() const;
65
66 void setShutterCallback(shutter_callback cb, void *cookie);
67 void setRawCallback(frame_callback cb, void *cookie);
68 void setJpegCallback(frame_callback cb, void *cookie);
69 void setFrameCallback(frame_callback cb, void *cookie);
70 void setErrorCallback(error_callback cb, void *cookie);
71 void setAutoFocusCallback(autofocus_callback cb, void *cookie);
72 // ICameraClient interface
73 virtual void shutterCallback();
74 virtual void rawCallback(const sp<IMemory>& picture);
75 virtual void jpegCallback(const sp<IMemory>& picture);
76 virtual void frameCallback(const sp<IMemory>& frame);
77 virtual void errorCallback(status_t error);
78 virtual void autoFocusCallback(bool focused);
79
80
81private:
82 Camera();
83 virtual void binderDied(const wp<IBinder>& who);
84
85 class DeathNotifier: public IBinder::DeathRecipient
86 {
87 public:
88 DeathNotifier() {
89 }
90
91 virtual void binderDied(const wp<IBinder>& who);
92 };
93
94 static sp<DeathNotifier> mDeathNotifier;
95
96 // helper function to obtain camera service handle
97 static const sp<ICameraService>& getCameraService();
98
99 sp<ICamera> mCamera;
100 status_t mStatus;
101
102 shutter_callback mShutterCallback;
103 void *mShutterCallbackCookie;
104 frame_callback mRawCallback;
105 void *mRawCallbackCookie;
106 frame_callback mJpegCallback;
107 void *mJpegCallbackCookie;
108 frame_callback mFrameCallback;
109 void *mFrameCallbackCookie;
110 error_callback mErrorCallback;
111 void *mErrorCallbackCookie;
112 autofocus_callback mAutoFocusCallback;
113 void *mAutoFocusCallbackCookie;
114
115 friend class DeathNotifier;
116
117 static Mutex mLock;
118 static sp<ICameraService> mCameraService;
119
120};
121
122}; // namespace android
123
124#endif
125