Camera.h revision ceb388d6c03c38b96dc41c0ea4804b749aa077c4
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/IGraphicBufferProducer.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;
56class String16;
57
58// ref-counted object for callbacks
59class CameraListener: virtual public RefBase
60{
61public:
62    virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
63    virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr,
64                          camera_frame_metadata_t *metadata) = 0;
65    virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
66};
67
68class Camera : public BnCameraClient, public IBinder::DeathRecipient
69{
70public:
71    enum {
72        USE_CALLING_UID = -1
73    };
74
75            // construct a camera client from an existing remote
76    static  sp<Camera>  create(const sp<ICamera>& camera);
77    static  int32_t     getNumberOfCameras();
78    static  status_t    getCameraInfo(int cameraId,
79                                      struct CameraInfo* cameraInfo);
80    static  sp<Camera>  connect(int cameraId,
81                                const String16& clientPackageName,
82                                int clientUid);
83
84            virtual     ~Camera();
85            void        init();
86
87            status_t    reconnect();
88            void        disconnect();
89            status_t    lock();
90            status_t    unlock();
91
92            status_t    getStatus() { return mStatus; }
93
94            // pass the buffered Surface to the camera service
95            status_t    setPreviewDisplay(const sp<Surface>& surface);
96
97            // pass the buffered IGraphicBufferProducer to the camera service
98            status_t    setPreviewTexture(const sp<IGraphicBufferProducer>& bufferProducer);
99
100            // start preview mode, must call setPreviewDisplay first
101            status_t    startPreview();
102
103            // stop preview mode
104            void        stopPreview();
105
106            // get preview state
107            bool        previewEnabled();
108
109            // start recording mode, must call setPreviewDisplay first
110            status_t    startRecording();
111
112            // stop recording mode
113            void        stopRecording();
114
115            // get recording state
116            bool        recordingEnabled();
117
118            // release a recording frame
119            void        releaseRecordingFrame(const sp<IMemory>& mem);
120
121            // autoFocus - status returned from callback
122            status_t    autoFocus();
123
124            // cancel auto focus
125            status_t    cancelAutoFocus();
126
127            // take a picture - picture returned from callback
128            status_t    takePicture(int msgType);
129
130            // set preview/capture parameters - key/value pairs
131            status_t    setParameters(const String8& params);
132
133            // get preview/capture parameters - key/value pairs
134            String8     getParameters() const;
135
136            // send command to camera driver
137            status_t    sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
138
139            // tell camera hal to store meta data or real YUV in video buffers.
140            status_t    storeMetaDataInBuffers(bool enabled);
141
142            void        setListener(const sp<CameraListener>& listener);
143            void        setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener);
144            void        setPreviewCallbackFlags(int preview_callback_flag);
145
146            sp<ICameraRecordingProxy> getRecordingProxy();
147
148    // ICameraClient interface
149    virtual void        notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
150    virtual void        dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
151                                     camera_frame_metadata_t *metadata);
152    virtual void        dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
153
154    sp<ICamera>         remote();
155
156    class RecordingProxy : public BnCameraRecordingProxy
157    {
158    public:
159        RecordingProxy(const sp<Camera>& camera);
160
161        // ICameraRecordingProxy interface
162        virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
163        virtual void stopRecording();
164        virtual void releaseRecordingFrame(const sp<IMemory>& mem);
165
166    private:
167        sp<Camera>         mCamera;
168    };
169
170protected:
171                        Camera();
172                        Camera(const Camera&);
173                        Camera& operator=(const Camera);
174                        virtual void binderDied(const wp<IBinder>& who);
175
176            class DeathNotifier: public IBinder::DeathRecipient
177            {
178            public:
179                DeathNotifier() {
180                }
181
182                virtual void binderDied(const wp<IBinder>& who);
183            };
184
185            static sp<DeathNotifier> mDeathNotifier;
186
187            // helper function to obtain camera service handle
188            static const sp<ICameraService>& getCameraService();
189
190            sp<ICamera>         mCamera;
191            status_t            mStatus;
192
193            sp<CameraListener>  mListener;
194            sp<ICameraRecordingProxyListener>  mRecordingProxyListener;
195
196            friend class DeathNotifier;
197
198            static  Mutex               mLock;
199            static  sp<ICameraService>  mCameraService;
200};
201
202}; // namespace android
203
204#endif
205