blob: d05813821675bc73e9385c92e5250a3a2fc8fa7b [file] [log] [blame]
Mathias Agopian3cf61352010-02-09 17:46:37 -08001/*
2**
3** Copyright 2008, The Android Open Source Project
4**
Praveen Chavan6773d472016-01-13 01:24:30 -08005** 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
Mathias Agopian3cf61352010-02-09 17:46:37 -08008**
Praveen Chavan6773d472016-01-13 01:24:30 -08009** http://www.apache.org/licenses/LICENSE-2.0
Mathias Agopian3cf61352010-02-09 17:46:37 -080010**
Praveen Chavan6773d472016-01-13 01:24:30 -080011** 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
Mathias Agopian3cf61352010-02-09 17:46:37 -080015** 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>
Praveen Chavan6773d472016-01-13 01:24:30 -080023#include <camera/CameraUtils.h>
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080024#include <android/hardware/ICameraClient.h>
Praveen Chavan6773d472016-01-13 01:24:30 -080025#include <media/hardware/HardwareAPI.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080026
27namespace android {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080028namespace hardware {
Mathias Agopian3cf61352010-02-09 17:46:37 -080029
30enum {
31 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
32 DATA_CALLBACK,
33 DATA_CALLBACK_TIMESTAMP,
34};
35
36class BpCameraClient: public BpInterface<ICameraClient>
37{
38public:
39 BpCameraClient(const sp<IBinder>& impl)
40 : BpInterface<ICameraClient>(impl)
41 {
42 }
43
44 // generic callback from camera service to app
45 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
46 {
Steve Block3856b092011-10-20 11:56:00 +010047 ALOGV("notifyCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080048 Parcel data, reply;
49 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
50 data.writeInt32(msgType);
51 data.writeInt32(ext1);
52 data.writeInt32(ext2);
53 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
54 }
55
56 // generic data callback from camera service to app with image data
Wu-cheng Li57c86182011-07-30 05:00:37 +080057 void dataCallback(int32_t msgType, const sp<IMemory>& imageData,
58 camera_frame_metadata_t *metadata)
Mathias Agopian3cf61352010-02-09 17:46:37 -080059 {
Steve Block3856b092011-10-20 11:56:00 +010060 ALOGV("dataCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080061 Parcel data, reply;
62 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
63 data.writeInt32(msgType);
Marco Nelissen06b46062014-11-14 07:58:25 -080064 data.writeStrongBinder(IInterface::asBinder(imageData));
Wu-cheng Li57c86182011-07-30 05:00:37 +080065 if (metadata) {
66 data.writeInt32(metadata->number_of_faces);
67 data.write(metadata->faces, sizeof(camera_face_t) * metadata->number_of_faces);
68 }
Mathias Agopian3cf61352010-02-09 17:46:37 -080069 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
70 }
71
72 // generic data callback from camera service to app with image data
73 void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData)
74 {
Steve Block3856b092011-10-20 11:56:00 +010075 ALOGV("dataCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080076 Parcel data, reply;
77 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
78 data.writeInt64(timestamp);
79 data.writeInt32(msgType);
Marco Nelissen06b46062014-11-14 07:58:25 -080080 data.writeStrongBinder(IInterface::asBinder(imageData));
Praveen Chavan6773d472016-01-13 01:24:30 -080081 // If imageData is metadata and it contains a native handle, write the native handle to
82 // parcel.
83 if (CameraUtils::isNativeHandleMetadata(imageData)) {
84 VideoNativeHandleMetadata *metadata =
85 (VideoNativeHandleMetadata*)(imageData->pointer());
86 data.writeNativeHandle(metadata->pHandle);
87 }
Mathias Agopian3cf61352010-02-09 17:46:37 -080088 remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY);
89 }
90};
91
92IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
93
94// ----------------------------------------------------------------------
95
96status_t BnCameraClient::onTransact(
97 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
98{
99 switch(code) {
100 case NOTIFY_CALLBACK: {
Steve Block3856b092011-10-20 11:56:00 +0100101 ALOGV("NOTIFY_CALLBACK");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800102 CHECK_INTERFACE(ICameraClient, data, reply);
103 int32_t msgType = data.readInt32();
104 int32_t ext1 = data.readInt32();
105 int32_t ext2 = data.readInt32();
106 notifyCallback(msgType, ext1, ext2);
107 return NO_ERROR;
108 } break;
109 case DATA_CALLBACK: {
Steve Block3856b092011-10-20 11:56:00 +0100110 ALOGV("DATA_CALLBACK");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800111 CHECK_INTERFACE(ICameraClient, data, reply);
112 int32_t msgType = data.readInt32();
113 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
Wu-cheng Li57c86182011-07-30 05:00:37 +0800114 camera_frame_metadata_t *metadata = NULL;
115 if (data.dataAvail() > 0) {
116 metadata = new camera_frame_metadata_t;
117 metadata->number_of_faces = data.readInt32();
118 metadata->faces = (camera_face_t *) data.readInplace(
119 sizeof(camera_face_t) * metadata->number_of_faces);
120 }
121 dataCallback(msgType, imageData, metadata);
122 if (metadata) delete metadata;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800123 return NO_ERROR;
124 } break;
125 case DATA_CALLBACK_TIMESTAMP: {
Steve Block3856b092011-10-20 11:56:00 +0100126 ALOGV("DATA_CALLBACK_TIMESTAMP");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800127 CHECK_INTERFACE(ICameraClient, data, reply);
128 nsecs_t timestamp = data.readInt64();
129 int32_t msgType = data.readInt32();
130 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
Praveen Chavan6773d472016-01-13 01:24:30 -0800131
132 // If the image data contains a native handle, read the native handle from the parcel
133 // and replace the native handle in the image data. (The native handle in image data is
134 // not serielized/deserialized so it's not valid in the process.)
135 if (CameraUtils::isNativeHandleMetadata(imageData)) {
136 VideoNativeHandleMetadata *metadata =
137 (VideoNativeHandleMetadata*)(imageData->pointer());
138 metadata->pHandle = data.readNativeHandle();
139
140 // The native handle will be freed in
141 // BpCameraRecordingProxyListener::releaseRecordingFrame.
142 }
143
Mathias Agopian3cf61352010-02-09 17:46:37 -0800144 dataCallbackTimestamp(timestamp, msgType, imageData);
145 return NO_ERROR;
146 } break;
147 default:
148 return BBinder::onTransact(code, data, reply, flags);
149 }
150}
151
152// ----------------------------------------------------------------------------
153
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800154} // namespace hardware
155} // namespace android