blob: 805c2ca2be2c906321eed616c9c392685a8d2dd3 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2**
3** Copyright 2008, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18//#define LOG_NDEBUG 0
19#define LOG_TAG "ICamera"
20#include <utils/Log.h>
21#include <stdint.h>
22#include <sys/types.h>
Mathias Agopian07952722009-05-19 19:08:10 -070023#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024#include <ui/ICamera.h>
25
26namespace android {
27
28enum {
29 DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
30 SET_PREVIEW_DISPLAY,
31 SET_PREVIEW_CALLBACK_FLAG,
32 START_PREVIEW,
33 STOP_PREVIEW,
34 AUTO_FOCUS,
35 TAKE_PICTURE,
36 SET_PARAMETERS,
37 GET_PARAMETERS,
38 CONNECT,
39 LOCK,
40 UNLOCK,
41 PREVIEW_ENABLED,
42 START_RECORDING,
43 STOP_RECORDING,
44 RECORDING_ENABLED,
45 RELEASE_RECORDING_FRAME,
46};
47
48class BpCamera: public BpInterface<ICamera>
49{
50public:
51 BpCamera(const sp<IBinder>& impl)
52 : BpInterface<ICamera>(impl)
53 {
54 }
55
56 // disconnect from camera service
57 void disconnect()
58 {
59 LOGV("disconnect");
60 Parcel data, reply;
61 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
62 remote()->transact(DISCONNECT, data, &reply);
63 }
64
65 // pass the buffered ISurface to the camera service
66 status_t setPreviewDisplay(const sp<ISurface>& surface)
67 {
68 LOGV("setPreviewDisplay");
69 Parcel data, reply;
70 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
71 data.writeStrongBinder(surface->asBinder());
72 remote()->transact(SET_PREVIEW_DISPLAY, data, &reply);
73 return reply.readInt32();
74 }
75
76 // set the preview callback flag to affect how the received frames from
77 // preview are handled. See Camera.h for details.
78 void setPreviewCallbackFlag(int flag)
79 {
80 LOGV("setPreviewCallbackFlag(%d)", flag);
81 Parcel data, reply;
82 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
83 data.writeInt32(flag);
84 remote()->transact(SET_PREVIEW_CALLBACK_FLAG, data, &reply);
85 }
86
87 // start preview mode, must call setPreviewDisplay first
88 status_t startPreview()
89 {
90 LOGV("startPreview");
91 Parcel data, reply;
92 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
93 remote()->transact(START_PREVIEW, data, &reply);
94 return reply.readInt32();
95 }
96
97 // start recording mode, must call setPreviewDisplay first
98 status_t startRecording()
99 {
100 LOGV("startRecording");
101 Parcel data, reply;
102 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
103 remote()->transact(START_RECORDING, data, &reply);
104 return reply.readInt32();
105 }
106
107 // stop preview mode
108 void stopPreview()
109 {
110 LOGV("stopPreview");
111 Parcel data, reply;
112 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
113 remote()->transact(STOP_PREVIEW, data, &reply);
114 }
115
116 // stop recording mode
117 void stopRecording()
118 {
119 LOGV("stopRecording");
120 Parcel data, reply;
121 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
122 remote()->transact(STOP_RECORDING, data, &reply);
123 }
124
125 void releaseRecordingFrame(const sp<IMemory>& mem)
126 {
127 LOGV("releaseRecordingFrame");
128 Parcel data, reply;
129 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
130 data.writeStrongBinder(mem->asBinder());
131 remote()->transact(RELEASE_RECORDING_FRAME, data, &reply);
132 }
133
134 // check preview state
135 bool previewEnabled()
136 {
137 LOGV("previewEnabled");
138 Parcel data, reply;
139 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
140 remote()->transact(PREVIEW_ENABLED, data, &reply);
141 return reply.readInt32();
142 }
143
144 // check recording state
145 bool recordingEnabled()
146 {
147 LOGV("recordingEnabled");
148 Parcel data, reply;
149 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
150 remote()->transact(RECORDING_ENABLED, data, &reply);
151 return reply.readInt32();
152 }
153
154 // auto focus
155 status_t autoFocus()
156 {
157 LOGV("autoFocus");
158 Parcel data, reply;
159 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
160 remote()->transact(AUTO_FOCUS, data, &reply);
161 status_t ret = reply.readInt32();
162 return ret;
163 }
164
165 // take a picture - returns an IMemory (ref-counted mmap)
166 status_t takePicture()
167 {
168 LOGV("takePicture");
169 Parcel data, reply;
170 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
171 remote()->transact(TAKE_PICTURE, data, &reply);
172 status_t ret = reply.readInt32();
173 return ret;
174 }
175
176 // set preview/capture parameters - key/value pairs
177 status_t setParameters(const String8& params)
178 {
179 LOGV("setParameters");
180 Parcel data, reply;
181 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
182 data.writeString8(params);
183 remote()->transact(SET_PARAMETERS, data, &reply);
184 return reply.readInt32();
185 }
186
187 // get preview/capture parameters - key/value pairs
188 String8 getParameters() const
189 {
190 LOGV("getParameters");
191 Parcel data, reply;
192 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
193 remote()->transact(GET_PARAMETERS, data, &reply);
194 return reply.readString8();
195 }
196 virtual status_t connect(const sp<ICameraClient>& cameraClient)
197 {
198 Parcel data, reply;
199 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
200 data.writeStrongBinder(cameraClient->asBinder());
201 remote()->transact(CONNECT, data, &reply);
202 return reply.readInt32();
203 }
204 virtual status_t lock()
205 {
206 Parcel data, reply;
207 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
208 remote()->transact(LOCK, data, &reply);
209 return reply.readInt32();
210 }
211 virtual status_t unlock()
212 {
213 Parcel data, reply;
214 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
215 remote()->transact(UNLOCK, data, &reply);
216 return reply.readInt32();
217 }
218};
219
220IMPLEMENT_META_INTERFACE(Camera, "android.hardware.ICamera");
221
222// ----------------------------------------------------------------------
223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224status_t BnCamera::onTransact(
225 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
226{
227 switch(code) {
228 case DISCONNECT: {
229 LOGV("DISCONNECT");
230 CHECK_INTERFACE(ICamera, data, reply);
231 disconnect();
232 return NO_ERROR;
233 } break;
234 case SET_PREVIEW_DISPLAY: {
235 LOGV("SET_PREVIEW_DISPLAY");
236 CHECK_INTERFACE(ICamera, data, reply);
237 sp<ISurface> surface = interface_cast<ISurface>(data.readStrongBinder());
238 reply->writeInt32(setPreviewDisplay(surface));
239 return NO_ERROR;
240 } break;
241 case SET_PREVIEW_CALLBACK_FLAG: {
242 LOGV("SET_PREVIEW_CALLBACK_TYPE");
243 CHECK_INTERFACE(ICamera, data, reply);
244 int callback_flag = data.readInt32();
245 setPreviewCallbackFlag(callback_flag);
246 return NO_ERROR;
247 } break;
248 case START_PREVIEW: {
249 LOGV("START_PREVIEW");
250 CHECK_INTERFACE(ICamera, data, reply);
251 reply->writeInt32(startPreview());
252 return NO_ERROR;
253 } break;
254 case START_RECORDING: {
255 LOGV("START_RECORDING");
256 CHECK_INTERFACE(ICamera, data, reply);
257 reply->writeInt32(startRecording());
258 return NO_ERROR;
259 } break;
260 case STOP_PREVIEW: {
261 LOGV("STOP_PREVIEW");
262 CHECK_INTERFACE(ICamera, data, reply);
263 stopPreview();
264 return NO_ERROR;
265 } break;
266 case STOP_RECORDING: {
267 LOGV("STOP_RECORDING");
268 CHECK_INTERFACE(ICamera, data, reply);
269 stopRecording();
270 return NO_ERROR;
271 } break;
272 case RELEASE_RECORDING_FRAME: {
273 LOGV("RELEASE_RECORDING_FRAME");
274 CHECK_INTERFACE(ICamera, data, reply);
275 sp<IMemory> mem = interface_cast<IMemory>(data.readStrongBinder());
276 releaseRecordingFrame(mem);
277 return NO_ERROR;
278 } break;
279 case PREVIEW_ENABLED: {
280 LOGV("PREVIEW_ENABLED");
281 CHECK_INTERFACE(ICamera, data, reply);
282 reply->writeInt32(previewEnabled());
283 return NO_ERROR;
284 } break;
285 case RECORDING_ENABLED: {
286 LOGV("RECORDING_ENABLED");
287 CHECK_INTERFACE(ICamera, data, reply);
288 reply->writeInt32(recordingEnabled());
289 return NO_ERROR;
290 } break;
291 case AUTO_FOCUS: {
292 LOGV("AUTO_FOCUS");
293 CHECK_INTERFACE(ICamera, data, reply);
294 reply->writeInt32(autoFocus());
295 return NO_ERROR;
296 } break;
297 case TAKE_PICTURE: {
298 LOGV("TAKE_PICTURE");
299 CHECK_INTERFACE(ICamera, data, reply);
300 reply->writeInt32(takePicture());
301 return NO_ERROR;
302 } break;
303 case SET_PARAMETERS: {
304 LOGV("SET_PARAMETERS");
305 CHECK_INTERFACE(ICamera, data, reply);
306 String8 params(data.readString8());
307 reply->writeInt32(setParameters(params));
308 return NO_ERROR;
309 } break;
310 case GET_PARAMETERS: {
311 LOGV("GET_PARAMETERS");
312 CHECK_INTERFACE(ICamera, data, reply);
313 reply->writeString8(getParameters());
314 return NO_ERROR;
315 } break;
316 case CONNECT: {
317 CHECK_INTERFACE(ICamera, data, reply);
318 sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder());
319 reply->writeInt32(connect(cameraClient));
320 return NO_ERROR;
321 } break;
322 case LOCK: {
323 CHECK_INTERFACE(ICamera, data, reply);
324 reply->writeInt32(lock());
325 return NO_ERROR;
326 } break;
327 case UNLOCK: {
328 CHECK_INTERFACE(ICamera, data, reply);
329 reply->writeInt32(unlock());
330 return NO_ERROR;
331 } break;
332 default:
333 return BBinder::onTransact(code, data, reply, flags);
334 }
335}
336
337// ----------------------------------------------------------------------------
338
339}; // namespace android
340