blob: 205c8ba1f123df1ffcf8d23442ce58ce6cf544a4 [file] [log] [blame]
Mathias Agopian3cf61352010-02-09 17:46:37 -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 "ICameraClient"
20#include <utils/Log.h>
21#include <stdint.h>
22#include <sys/types.h>
23#include <camera/ICameraClient.h>
24
25namespace android {
26
27enum {
28 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
29 DATA_CALLBACK,
30 DATA_CALLBACK_TIMESTAMP,
31};
32
33class BpCameraClient: public BpInterface<ICameraClient>
34{
35public:
36 BpCameraClient(const sp<IBinder>& impl)
37 : BpInterface<ICameraClient>(impl)
38 {
39 }
40
41 // generic callback from camera service to app
42 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
43 {
Steve Block3856b092011-10-20 11:56:00 +010044 ALOGV("notifyCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080045 Parcel data, reply;
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);
51 }
52
53 // generic data callback from camera service to app with image data
Wu-cheng Li57c86182011-07-30 05:00:37 +080054 void dataCallback(int32_t msgType, const sp<IMemory>& imageData,
55 camera_frame_metadata_t *metadata)
Mathias Agopian3cf61352010-02-09 17:46:37 -080056 {
Steve Block3856b092011-10-20 11:56:00 +010057 ALOGV("dataCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080058 Parcel data, reply;
59 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
60 data.writeInt32(msgType);
61 data.writeStrongBinder(imageData->asBinder());
Wu-cheng Li57c86182011-07-30 05:00:37 +080062 if (metadata) {
63 data.writeInt32(metadata->number_of_faces);
64 data.write(metadata->faces, sizeof(camera_face_t) * metadata->number_of_faces);
65 }
Mathias Agopian3cf61352010-02-09 17:46:37 -080066 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
67 }
68
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)
71 {
Steve Block3856b092011-10-20 11:56:00 +010072 ALOGV("dataCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080073 Parcel data, reply;
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);
79 }
80};
81
82IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
83
84// ----------------------------------------------------------------------
85
86status_t BnCameraClient::onTransact(
87 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
88{
89 switch(code) {
90 case NOTIFY_CALLBACK: {
Steve Block3856b092011-10-20 11:56:00 +010091 ALOGV("NOTIFY_CALLBACK");
Mathias Agopian3cf61352010-02-09 17:46:37 -080092 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);
97 return NO_ERROR;
98 } break;
99 case DATA_CALLBACK: {
Steve Block3856b092011-10-20 11:56:00 +0100100 ALOGV("DATA_CALLBACK");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800101 CHECK_INTERFACE(ICameraClient, data, reply);
102 int32_t msgType = data.readInt32();
103 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
Wu-cheng Li57c86182011-07-30 05:00:37 +0800104 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);
110 }
111 dataCallback(msgType, imageData, metadata);
112 if (metadata) delete metadata;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800113 return NO_ERROR;
114 } break;
115 case DATA_CALLBACK_TIMESTAMP: {
Steve Block3856b092011-10-20 11:56:00 +0100116 ALOGV("DATA_CALLBACK_TIMESTAMP");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800117 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);
122 return NO_ERROR;
123 } break;
124 default:
125 return BBinder::onTransact(code, data, reply, flags);
126 }
127}
128
129// ----------------------------------------------------------------------------
130
131}; // namespace android
132