The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 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_H |
| 18 | #define ANDROID_HARDWARE_CAMERA_H |
| 19 | |
| 20 | #include <ui/ICameraClient.h> |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | class ICameraService; |
| 25 | class ICamera; |
| 26 | class Surface; |
| 27 | class Mutex; |
| 28 | class String8; |
| 29 | |
| 30 | typedef void (*shutter_callback)(void *cookie); |
| 31 | typedef void (*frame_callback)(const sp<IMemory>& mem, void *cookie); |
| 32 | typedef void (*autofocus_callback)(bool focused, void *cookie); |
| 33 | typedef void (*error_callback)(status_t err, void *cookie); |
| 34 | |
| 35 | class Camera : public BnCameraClient, public IBinder::DeathRecipient |
| 36 | { |
| 37 | public: |
| 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 | |
| 81 | private: |
| 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 | |