blob: 1b6fac4b14a866e7da73e561424e627e3104927e [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,
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -070034 RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP,
Mathias Agopian3cf61352010-02-09 17:46:37 -080035};
36
37class BpCameraClient: public BpInterface<ICameraClient>
38{
39public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070040 explicit BpCameraClient(const sp<IBinder>& impl)
Mathias Agopian3cf61352010-02-09 17:46:37 -080041 : BpInterface<ICameraClient>(impl)
42 {
43 }
44
45 // generic callback from camera service to app
46 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
47 {
Steve Block3856b092011-10-20 11:56:00 +010048 ALOGV("notifyCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080049 Parcel data, reply;
50 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
51 data.writeInt32(msgType);
52 data.writeInt32(ext1);
53 data.writeInt32(ext2);
54 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
55 }
56
57 // generic data callback from camera service to app with image data
Wu-cheng Li57c86182011-07-30 05:00:37 +080058 void dataCallback(int32_t msgType, const sp<IMemory>& imageData,
59 camera_frame_metadata_t *metadata)
Mathias Agopian3cf61352010-02-09 17:46:37 -080060 {
Steve Block3856b092011-10-20 11:56:00 +010061 ALOGV("dataCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080062 Parcel data, reply;
63 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
64 data.writeInt32(msgType);
Marco Nelissen06b46062014-11-14 07:58:25 -080065 data.writeStrongBinder(IInterface::asBinder(imageData));
Wu-cheng Li57c86182011-07-30 05:00:37 +080066 if (metadata) {
67 data.writeInt32(metadata->number_of_faces);
68 data.write(metadata->faces, sizeof(camera_face_t) * metadata->number_of_faces);
69 }
Mathias Agopian3cf61352010-02-09 17:46:37 -080070 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
71 }
72
73 // generic data callback from camera service to app with image data
74 void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData)
75 {
Steve Block3856b092011-10-20 11:56:00 +010076 ALOGV("dataCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080077 Parcel data, reply;
78 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
79 data.writeInt64(timestamp);
80 data.writeInt32(msgType);
Marco Nelissen06b46062014-11-14 07:58:25 -080081 data.writeStrongBinder(IInterface::asBinder(imageData));
Mathias Agopian3cf61352010-02-09 17:46:37 -080082 remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY);
83 }
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -070084
85 void recordingFrameHandleCallbackTimestamp(nsecs_t timestamp, native_handle_t* handle) {
86 ALOGV("recordingFrameHandleCallbackTimestamp");
87 Parcel data, reply;
88 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
89 data.writeInt64(timestamp);
90 data.writeNativeHandle(handle);
91 remote()->transact(RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP, data, &reply,
92 IBinder::FLAG_ONEWAY);
93 }
Mathias Agopian3cf61352010-02-09 17:46:37 -080094};
95
96IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
97
98// ----------------------------------------------------------------------
99
100status_t BnCameraClient::onTransact(
101 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
102{
103 switch(code) {
104 case NOTIFY_CALLBACK: {
Steve Block3856b092011-10-20 11:56:00 +0100105 ALOGV("NOTIFY_CALLBACK");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800106 CHECK_INTERFACE(ICameraClient, data, reply);
107 int32_t msgType = data.readInt32();
108 int32_t ext1 = data.readInt32();
109 int32_t ext2 = data.readInt32();
110 notifyCallback(msgType, ext1, ext2);
111 return NO_ERROR;
112 } break;
113 case DATA_CALLBACK: {
Steve Block3856b092011-10-20 11:56:00 +0100114 ALOGV("DATA_CALLBACK");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800115 CHECK_INTERFACE(ICameraClient, data, reply);
116 int32_t msgType = data.readInt32();
117 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
Wu-cheng Li57c86182011-07-30 05:00:37 +0800118 camera_frame_metadata_t *metadata = NULL;
119 if (data.dataAvail() > 0) {
120 metadata = new camera_frame_metadata_t;
121 metadata->number_of_faces = data.readInt32();
122 metadata->faces = (camera_face_t *) data.readInplace(
123 sizeof(camera_face_t) * metadata->number_of_faces);
124 }
125 dataCallback(msgType, imageData, metadata);
126 if (metadata) delete metadata;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800127 return NO_ERROR;
128 } break;
129 case DATA_CALLBACK_TIMESTAMP: {
Steve Block3856b092011-10-20 11:56:00 +0100130 ALOGV("DATA_CALLBACK_TIMESTAMP");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800131 CHECK_INTERFACE(ICameraClient, data, reply);
132 nsecs_t timestamp = data.readInt64();
133 int32_t msgType = data.readInt32();
134 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700135 dataCallbackTimestamp(timestamp, msgType, imageData);
136 return NO_ERROR;
137 } break;
138 case RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP: {
139 ALOGV("RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP");
140 CHECK_INTERFACE(ICameraClient, data, reply);
141 nsecs_t timestamp;
142 status_t res = data.readInt64(&timestamp);
143 if (res != OK) {
144 ALOGE("%s: Failed to read timestamp: %s (%d)", __FUNCTION__, strerror(-res), res);
145 return BAD_VALUE;
146 }
147 native_handle_t* handle = data.readNativeHandle();
148 if (handle == nullptr) {
149 ALOGE("%s: Received a null native handle", __FUNCTION__);
150 return BAD_VALUE;
Praveen Chavan6773d472016-01-13 01:24:30 -0800151 }
152
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700153 // The native handle will be freed in BpCamera::releaseRecordingFrameHandle.
154 recordingFrameHandleCallbackTimestamp(timestamp, handle);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800155 return NO_ERROR;
156 } break;
157 default:
158 return BBinder::onTransact(code, data, reply, flags);
159 }
160}
161
162// ----------------------------------------------------------------------------
163
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800164} // namespace hardware
165} // namespace android