Camera.h revision 4ca2c7c913f8bd4ada13aca56d36045d42d1e00f
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 <utils/Timers.h>
21#include <gui/ISurfaceTexture.h>
22#include <system/camera.h>
23#include <camera/ICameraClient.h>
24#include <camera/ICameraRecordingProxy.h>
25#include <camera/ICameraRecordingProxyListener.h>
26
27namespace android {
28
29struct CameraInfo {
30    /**
31     * The direction that the camera faces to. It should be CAMERA_FACING_BACK
32     * or CAMERA_FACING_FRONT.
33     */
34    int facing;
35
36    /**
37     * The orientation of the camera image. The value is the angle that the
38     * camera image needs to be rotated clockwise so it shows correctly on the
39     * display in its natural orientation. It should be 0, 90, 180, or 270.
40     *
41     * For example, suppose a device has a naturally tall screen. The
42     * back-facing camera sensor is mounted in landscape. You are looking at
43     * the screen. If the top side of the camera sensor is aligned with the
44     * right edge of the screen in natural orientation, the value should be
45     * 90. If the top side of a front-facing camera sensor is aligned with the
46     * right of the screen, the value should be 270.
47     */
48    int orientation;
49};
50
51class ICameraService;
52class ICamera;
53class Surface;
54class Mutex;
55class String8;
56
57// ref-counted object for callbacks
58class CameraListener: virtual public RefBase
59{
60public:
61    virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
62    virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr) = 0;
63    virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
64};
65
66class Camera : public BnCameraClient, public IBinder::DeathRecipient
67{
68public:
69            // construct a camera client from an existing remote
70    static  sp<Camera>  create(const sp<ICamera>& camera);
71    static  int32_t     getNumberOfCameras();
72    static  status_t    getCameraInfo(int cameraId,
73                                      struct CameraInfo* cameraInfo);
74    static  sp<Camera>  connect(int cameraId);
75            virtual     ~Camera();
76            void        init();
77
78            status_t    reconnect();
79            void        disconnect();
80            status_t    lock();
81            status_t    unlock();
82
83            status_t    getStatus() { return mStatus; }
84
85            // pass the buffered Surface to the camera service
86            status_t    setPreviewDisplay(const sp<Surface>& surface);
87
88            // pass the buffered ISurfaceTexture to the camera service
89            status_t    setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture);
90
91            // start preview mode, must call setPreviewDisplay first
92            status_t    startPreview();
93
94            // stop preview mode
95            void        stopPreview();
96
97            // get preview state
98            bool        previewEnabled();
99
100            // start recording mode, must call setPreviewDisplay first
101            status_t    startRecording();
102
103            // stop recording mode
104            void        stopRecording();
105
106            // get recording state
107            bool        recordingEnabled();
108
109            // release a recording frame
110            void        releaseRecordingFrame(const sp<IMemory>& mem);
111
112            // autoFocus - status returned from callback
113            status_t    autoFocus();
114
115            // cancel auto focus
116            status_t    cancelAutoFocus();
117
118            // take a picture - picture returned from callback
119            status_t    takePicture(int msgType);
120
121            // set preview/capture parameters - key/value pairs
122            status_t    setParameters(const String8& params);
123
124            // get preview/capture parameters - key/value pairs
125            String8     getParameters() const;
126
127            // send command to camera driver
128            status_t    sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
129
130            // tell camera hal to store meta data or real YUV in video buffers.
131            status_t    storeMetaDataInBuffers(bool enabled);
132
133            void        setListener(const sp<CameraListener>& listener);
134            void        setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener);
135            void        setPreviewCallbackFlags(int preview_callback_flag);
136
137            sp<ICameraRecordingProxy> getRecordingProxy();
138
139    // ICameraClient interface
140    virtual void        notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
141    virtual void        dataCallback(int32_t msgType, const sp<IMemory>& dataPtr);
142    virtual void        dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
143
144    sp<ICamera>         remote();
145
146    class RecordingProxy : public BnCameraRecordingProxy
147    {
148    public:
149        RecordingProxy(const sp<Camera>& camera);
150
151        // ICameraRecordingProxy interface
152        virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
153        virtual void stopRecording();
154        virtual void releaseRecordingFrame(const sp<IMemory>& mem);
155
156    private:
157        sp<Camera>         mCamera;
158    };
159
160private:
161                        Camera();
162                        Camera(const Camera&);
163                        Camera& operator=(const Camera);
164                        virtual void binderDied(const wp<IBinder>& who);
165
166            class DeathNotifier: public IBinder::DeathRecipient
167            {
168            public:
169                DeathNotifier() {
170                }
171
172                virtual void binderDied(const wp<IBinder>& who);
173            };
174
175            static sp<DeathNotifier> mDeathNotifier;
176
177            // helper function to obtain camera service handle
178            static const sp<ICameraService>& getCameraService();
179
180            sp<ICamera>         mCamera;
181            status_t            mStatus;
182
183            sp<CameraListener>  mListener;
184            sp<ICameraRecordingProxyListener>  mRecordingProxyListener;
185
186            friend class DeathNotifier;
187
188            static  Mutex               mLock;
189            static  sp<ICameraService>  mCameraService;
190};
191
192}; // namespace android
193
194#endif
195