• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 #include <android/hardware/ICameraService.h>
23 
24 #include <gui/IGraphicBufferProducer.h>
25 #include <system/camera.h>
26 #include <camera/ICameraRecordingProxy.h>
27 #include <camera/ICameraRecordingProxyListener.h>
28 #include <camera/android/hardware/ICamera.h>
29 #include <camera/android/hardware/ICameraClient.h>
30 #include <camera/CameraBase.h>
31 
32 namespace android {
33 
34 class Surface;
35 class String8;
36 class String16;
37 
38 // ref-counted object for callbacks
39 class CameraListener: virtual public RefBase
40 {
41 public:
42     virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
43     virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr,
44                           camera_frame_metadata_t *metadata) = 0;
45     virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
46     virtual void postRecordingFrameHandleTimestamp(nsecs_t timestamp, native_handle_t* handle) = 0;
47     virtual void postRecordingFrameHandleTimestampBatch(
48             const std::vector<nsecs_t>& timestamps,
49             const std::vector<native_handle_t*>& handles) = 0;
50 };
51 
52 class Camera;
53 
54 template <>
55 struct CameraTraits<Camera>
56 {
57     typedef CameraListener                     TCamListener;
58     typedef ::android::hardware::ICamera       TCamUser;
59     typedef ::android::hardware::ICameraClient TCamCallbacks;
60     typedef ::android::binder::Status(::android::hardware::ICameraService::*TCamConnectService)
61         (const sp<::android::hardware::ICameraClient>&,
62         int, const String16&, int, int,
63         /*out*/
64         sp<::android::hardware::ICamera>*);
65     static TCamConnectService     fnConnectService;
66 };
67 
68 
69 class Camera :
70     public CameraBase<Camera>,
71     public ::android::hardware::BnCameraClient
72 {
73 public:
74     enum {
75         USE_CALLING_UID = ::android::hardware::ICameraService::USE_CALLING_UID
76     };
77     enum {
78         USE_CALLING_PID = ::android::hardware::ICameraService::USE_CALLING_PID
79     };
80 
81             // construct a camera client from an existing remote
82     static  sp<Camera>  create(const sp<::android::hardware::ICamera>& camera);
83     static  sp<Camera>  connect(int cameraId,
84                                 const String16& clientPackageName,
85                                 int clientUid, int clientPid);
86 
87     static  status_t  connectLegacy(int cameraId, int halVersion,
88                                      const String16& clientPackageName,
89                                      int clientUid, sp<Camera>& camera);
90 
91             virtual     ~Camera();
92 
93             status_t    reconnect();
94             status_t    lock();
95             status_t    unlock();
96 
97             // pass the buffered IGraphicBufferProducer to the camera service
98             status_t    setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer);
99 
100             // start preview mode, must call setPreviewTarget 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 setPreviewTarget 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             // release a recording frame handle
122             void        releaseRecordingFrameHandle(native_handle_t *handle);
123 
124             // release a batch of recording frame handles
125             void        releaseRecordingFrameHandleBatch(
126                     const std::vector<native_handle_t*> handles);
127 
128             // autoFocus - status returned from callback
129             status_t    autoFocus();
130 
131             // cancel auto focus
132             status_t    cancelAutoFocus();
133 
134             // take a picture - picture returned from callback
135             status_t    takePicture(int msgType);
136 
137             // set preview/capture parameters - key/value pairs
138             status_t    setParameters(const String8& params);
139 
140             // get preview/capture parameters - key/value pairs
141             String8     getParameters() const;
142 
143             // send command to camera driver
144             status_t    sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
145 
146             // Tell camera how to pass video buffers. videoBufferMode is one of VIDEO_BUFFER_MODE_*.
147             // Returns OK if the specified video buffer mode is supported. If videoBufferMode is
148             // VIDEO_BUFFER_MODE_BUFFER_QUEUE, setVideoTarget() must be called before starting
149             // video recording.
150             status_t    setVideoBufferMode(int32_t videoBufferMode);
151 
152             // Set the video buffer producer for camera to use in VIDEO_BUFFER_MODE_BUFFER_QUEUE
153             // mode.
154             status_t    setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer);
155 
156             void        setListener(const sp<CameraListener>& listener);
157             void        setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener);
158 
159             // Configure preview callbacks to app. Only one of the older
160             // callbacks or the callback surface can be active at the same time;
161             // enabling one will disable the other if active. Flags can be
162             // disabled by calling it with CAMERA_FRAME_CALLBACK_FLAG_NOOP, and
163             // Target by calling it with a NULL interface.
164             void        setPreviewCallbackFlags(int preview_callback_flag);
165             status_t    setPreviewCallbackTarget(
166                     const sp<IGraphicBufferProducer>& callbackProducer);
167 
168             sp<ICameraRecordingProxy> getRecordingProxy();
169 
170     // ICameraClient interface
171     virtual void        notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
172     virtual void        dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
173                                      camera_frame_metadata_t *metadata);
174     virtual void        dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
175     virtual void        recordingFrameHandleCallbackTimestamp(nsecs_t timestamp, native_handle_t* handle);
176     virtual void        recordingFrameHandleCallbackTimestampBatch(
177                                 const std::vector<nsecs_t>& timestamps,
178                                 const std::vector<native_handle_t*>& handles);
179 
180 
181     class RecordingProxy : public BnCameraRecordingProxy
182     {
183     public:
184         explicit RecordingProxy(const sp<Camera>& camera);
185 
186         // ICameraRecordingProxy interface
187         virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
188         virtual void stopRecording();
189         virtual void releaseRecordingFrame(const sp<IMemory>& mem);
190         virtual void releaseRecordingFrameHandle(native_handle_t* handle);
191         virtual void releaseRecordingFrameHandleBatch(
192                 const std::vector<native_handle_t*>& handles);
193 
194     private:
195         sp<Camera>         mCamera;
196     };
197 
198 protected:
199     explicit            Camera(int cameraId);
200                         Camera(const Camera&);
201                         Camera& operator=(const Camera);
202 
203     sp<ICameraRecordingProxyListener>  mRecordingProxyListener;
204 
205     friend class        CameraBase;
206 };
207 
208 }; // namespace android
209 
210 #endif
211