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 "ICameraClient"
20 #include <utils/Log.h>
22 #include <sys/types.h>
23 #include <camera/ICameraClient.h>
28 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
30 DATA_CALLBACK_TIMESTAMP,
33 class BpCameraClient: public BpInterface<ICameraClient>
36 BpCameraClient(const sp<IBinder>& impl)
37 : BpInterface<ICameraClient>(impl)
41 // generic callback from camera service to app
42 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
44 ALOGV("notifyCallback");
46 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
47 data.writeInt32(msgType);
48 data.writeInt32(ext1);
49 data.writeInt32(ext2);
50 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
53 // generic data callback from camera service to app with image data
54 void dataCallback(int32_t msgType, const sp<IMemory>& imageData,
55 camera_frame_metadata_t *metadata)
57 ALOGV("dataCallback");
59 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
60 data.writeInt32(msgType);
61 data.writeStrongBinder(imageData->asBinder());
63 data.writeInt32(metadata->number_of_faces);
64 data.write(metadata->faces, sizeof(camera_face_t) * metadata->number_of_faces);
66 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
69 // generic data callback from camera service to app with image data
70 void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData)
72 ALOGV("dataCallback");
74 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
75 data.writeInt64(timestamp);
76 data.writeInt32(msgType);
77 data.writeStrongBinder(imageData->asBinder());
78 remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY);
82 IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
84 // ----------------------------------------------------------------------
86 status_t BnCameraClient::onTransact(
87 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
90 case NOTIFY_CALLBACK: {
91 ALOGV("NOTIFY_CALLBACK");
92 CHECK_INTERFACE(ICameraClient, data, reply);
93 int32_t msgType = data.readInt32();
94 int32_t ext1 = data.readInt32();
95 int32_t ext2 = data.readInt32();
96 notifyCallback(msgType, ext1, ext2);
100 ALOGV("DATA_CALLBACK");
101 CHECK_INTERFACE(ICameraClient, data, reply);
102 int32_t msgType = data.readInt32();
103 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
104 camera_frame_metadata_t *metadata = NULL;
105 if (data.dataAvail() > 0) {
106 metadata = new camera_frame_metadata_t;
107 metadata->number_of_faces = data.readInt32();
108 metadata->faces = (camera_face_t *) data.readInplace(
109 sizeof(camera_face_t) * metadata->number_of_faces);
111 dataCallback(msgType, imageData, metadata);
112 if (metadata) delete metadata;
115 case DATA_CALLBACK_TIMESTAMP: {
116 ALOGV("DATA_CALLBACK_TIMESTAMP");
117 CHECK_INTERFACE(ICameraClient, data, reply);
118 nsecs_t timestamp = data.readInt64();
119 int32_t msgType = data.readInt32();
120 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
121 dataCallbackTimestamp(timestamp, msgType, imageData);
125 return BBinder::onTransact(code, data, reply, flags);
129 // ----------------------------------------------------------------------------
131 }; // namespace android