3 ** Copyright 2008, The Android Open Source Project
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
9 ** http://www.apache.org/licenses/LICENSE-2.0
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.
18 //#define LOG_NDEBUG 0
19 #define LOG_TAG "ICamera"
20 #include <utils/Log.h>
22 #include <sys/types.h>
23 #include <binder/Parcel.h>
24 #include <camera/ICamera.h>
25 #include <gui/IGraphicBufferProducer.h>
26 #include <gui/Surface.h>
31 DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
33 SET_PREVIEW_CALLBACK_FLAG,
34 SET_PREVIEW_CALLBACK_TARGET,
50 RELEASE_RECORDING_FRAME,
51 STORE_META_DATA_IN_BUFFERS,
54 class BpCamera: public BpInterface<ICamera>
57 BpCamera(const sp<IBinder>& impl)
58 : BpInterface<ICamera>(impl)
62 // disconnect from camera service
67 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
68 remote()->transact(DISCONNECT, data, &reply);
69 reply.readExceptionCode();
72 // pass the buffered IGraphicBufferProducer to the camera service
73 status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)
75 ALOGV("setPreviewTarget");
77 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
78 sp<IBinder> b(bufferProducer->asBinder());
79 data.writeStrongBinder(b);
80 remote()->transact(SET_PREVIEW_TARGET, data, &reply);
81 return reply.readInt32();
84 // set the preview callback flag to affect how the received frames from
85 // preview are handled. See Camera.h for details.
86 void setPreviewCallbackFlag(int flag)
88 ALOGV("setPreviewCallbackFlag(%d)", flag);
90 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
91 data.writeInt32(flag);
92 remote()->transact(SET_PREVIEW_CALLBACK_FLAG, data, &reply);
95 status_t setPreviewCallbackTarget(
96 const sp<IGraphicBufferProducer>& callbackProducer)
98 ALOGV("setPreviewCallbackTarget");
100 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
101 sp<IBinder> b(callbackProducer->asBinder());
102 data.writeStrongBinder(b);
103 remote()->transact(SET_PREVIEW_CALLBACK_TARGET, data, &reply);
104 return reply.readInt32();
107 // start preview mode, must call setPreviewTarget first
108 status_t startPreview()
110 ALOGV("startPreview");
112 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
113 remote()->transact(START_PREVIEW, data, &reply);
114 return reply.readInt32();
117 // start recording mode, must call setPreviewTarget first
118 status_t startRecording()
120 ALOGV("startRecording");
122 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
123 remote()->transact(START_RECORDING, data, &reply);
124 return reply.readInt32();
130 ALOGV("stopPreview");
132 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
133 remote()->transact(STOP_PREVIEW, data, &reply);
136 // stop recording mode
139 ALOGV("stopRecording");
141 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
142 remote()->transact(STOP_RECORDING, data, &reply);
145 void releaseRecordingFrame(const sp<IMemory>& mem)
147 ALOGV("releaseRecordingFrame");
149 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
150 data.writeStrongBinder(mem->asBinder());
151 remote()->transact(RELEASE_RECORDING_FRAME, data, &reply);
154 status_t storeMetaDataInBuffers(bool enabled)
156 ALOGV("storeMetaDataInBuffers: %s", enabled? "true": "false");
158 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
159 data.writeInt32(enabled);
160 remote()->transact(STORE_META_DATA_IN_BUFFERS, data, &reply);
161 return reply.readInt32();
164 // check preview state
165 bool previewEnabled()
167 ALOGV("previewEnabled");
169 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
170 remote()->transact(PREVIEW_ENABLED, data, &reply);
171 return reply.readInt32();
174 // check recording state
175 bool recordingEnabled()
177 ALOGV("recordingEnabled");
179 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
180 remote()->transact(RECORDING_ENABLED, data, &reply);
181 return reply.readInt32();
189 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
190 remote()->transact(AUTO_FOCUS, data, &reply);
191 status_t ret = reply.readInt32();
196 status_t cancelAutoFocus()
198 ALOGV("cancelAutoFocus");
200 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
201 remote()->transact(CANCEL_AUTO_FOCUS, data, &reply);
202 status_t ret = reply.readInt32();
206 // take a picture - returns an IMemory (ref-counted mmap)
207 status_t takePicture(int msgType)
209 ALOGV("takePicture: 0x%x", msgType);
211 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
212 data.writeInt32(msgType);
213 remote()->transact(TAKE_PICTURE, data, &reply);
214 status_t ret = reply.readInt32();
218 // set preview/capture parameters - key/value pairs
219 status_t setParameters(const String8& params)
221 ALOGV("setParameters");
223 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
224 data.writeString8(params);
225 remote()->transact(SET_PARAMETERS, data, &reply);
226 return reply.readInt32();
229 // get preview/capture parameters - key/value pairs
230 String8 getParameters() const
232 ALOGV("getParameters");
234 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
235 remote()->transact(GET_PARAMETERS, data, &reply);
236 return reply.readString8();
238 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
240 ALOGV("sendCommand");
242 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
243 data.writeInt32(cmd);
244 data.writeInt32(arg1);
245 data.writeInt32(arg2);
246 remote()->transact(SEND_COMMAND, data, &reply);
247 return reply.readInt32();
249 virtual status_t connect(const sp<ICameraClient>& cameraClient)
252 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
253 data.writeStrongBinder(cameraClient->asBinder());
254 remote()->transact(CONNECT, data, &reply);
255 return reply.readInt32();
257 virtual status_t lock()
260 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
261 remote()->transact(LOCK, data, &reply);
262 return reply.readInt32();
264 virtual status_t unlock()
267 data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
268 remote()->transact(UNLOCK, data, &reply);
269 return reply.readInt32();
273 IMPLEMENT_META_INTERFACE(Camera, "android.hardware.ICamera");
275 // ----------------------------------------------------------------------
277 status_t BnCamera::onTransact(
278 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
283 CHECK_INTERFACE(ICamera, data, reply);
285 reply->writeNoException();
288 case SET_PREVIEW_TARGET: {
289 ALOGV("SET_PREVIEW_TARGET");
290 CHECK_INTERFACE(ICamera, data, reply);
291 sp<IGraphicBufferProducer> st =
292 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
293 reply->writeInt32(setPreviewTarget(st));
296 case SET_PREVIEW_CALLBACK_FLAG: {
297 ALOGV("SET_PREVIEW_CALLBACK_TYPE");
298 CHECK_INTERFACE(ICamera, data, reply);
299 int callback_flag = data.readInt32();
300 setPreviewCallbackFlag(callback_flag);
303 case SET_PREVIEW_CALLBACK_TARGET: {
304 ALOGV("SET_PREVIEW_CALLBACK_TARGET");
305 CHECK_INTERFACE(ICamera, data, reply);
306 sp<IGraphicBufferProducer> cp =
307 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
308 reply->writeInt32(setPreviewCallbackTarget(cp));
311 case START_PREVIEW: {
312 ALOGV("START_PREVIEW");
313 CHECK_INTERFACE(ICamera, data, reply);
314 reply->writeInt32(startPreview());
317 case START_RECORDING: {
318 ALOGV("START_RECORDING");
319 CHECK_INTERFACE(ICamera, data, reply);
320 reply->writeInt32(startRecording());
324 ALOGV("STOP_PREVIEW");
325 CHECK_INTERFACE(ICamera, data, reply);
329 case STOP_RECORDING: {
330 ALOGV("STOP_RECORDING");
331 CHECK_INTERFACE(ICamera, data, reply);
335 case RELEASE_RECORDING_FRAME: {
336 ALOGV("RELEASE_RECORDING_FRAME");
337 CHECK_INTERFACE(ICamera, data, reply);
338 sp<IMemory> mem = interface_cast<IMemory>(data.readStrongBinder());
339 releaseRecordingFrame(mem);
342 case STORE_META_DATA_IN_BUFFERS: {
343 ALOGV("STORE_META_DATA_IN_BUFFERS");
344 CHECK_INTERFACE(ICamera, data, reply);
345 bool enabled = data.readInt32();
346 reply->writeInt32(storeMetaDataInBuffers(enabled));
349 case PREVIEW_ENABLED: {
350 ALOGV("PREVIEW_ENABLED");
351 CHECK_INTERFACE(ICamera, data, reply);
352 reply->writeInt32(previewEnabled());
355 case RECORDING_ENABLED: {
356 ALOGV("RECORDING_ENABLED");
357 CHECK_INTERFACE(ICamera, data, reply);
358 reply->writeInt32(recordingEnabled());
363 CHECK_INTERFACE(ICamera, data, reply);
364 reply->writeInt32(autoFocus());
367 case CANCEL_AUTO_FOCUS: {
368 ALOGV("CANCEL_AUTO_FOCUS");
369 CHECK_INTERFACE(ICamera, data, reply);
370 reply->writeInt32(cancelAutoFocus());
374 ALOGV("TAKE_PICTURE");
375 CHECK_INTERFACE(ICamera, data, reply);
376 int msgType = data.readInt32();
377 reply->writeInt32(takePicture(msgType));
380 case SET_PARAMETERS: {
381 ALOGV("SET_PARAMETERS");
382 CHECK_INTERFACE(ICamera, data, reply);
383 String8 params(data.readString8());
384 reply->writeInt32(setParameters(params));
387 case GET_PARAMETERS: {
388 ALOGV("GET_PARAMETERS");
389 CHECK_INTERFACE(ICamera, data, reply);
390 reply->writeString8(getParameters());
394 ALOGV("SEND_COMMAND");
395 CHECK_INTERFACE(ICamera, data, reply);
396 int command = data.readInt32();
397 int arg1 = data.readInt32();
398 int arg2 = data.readInt32();
399 reply->writeInt32(sendCommand(command, arg1, arg2));
403 CHECK_INTERFACE(ICamera, data, reply);
404 sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder());
405 reply->writeInt32(connect(cameraClient));
409 CHECK_INTERFACE(ICamera, data, reply);
410 reply->writeInt32(lock());
414 CHECK_INTERFACE(ICamera, data, reply);
415 reply->writeInt32(unlock());
419 return BBinder::onTransact(code, data, reply, flags);
423 // ----------------------------------------------------------------------------
425 }; // namespace android