blob: 4282f9a86663d2b9d0bfaf2d38daf3d4169233b1 [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>
Mathias Agopian3cf61352010-02-09 17:46:37 -080024#include <camera/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 {
28
29enum {
30 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
31 DATA_CALLBACK,
32 DATA_CALLBACK_TIMESTAMP,
33};
34
35class BpCameraClient: public BpInterface<ICameraClient>
36{
37public:
38 BpCameraClient(const sp<IBinder>& impl)
39 : BpInterface<ICameraClient>(impl)
40 {
41 }
42
43 // generic callback from camera service to app
44 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
45 {
Steve Block3856b092011-10-20 11:56:00 +010046 ALOGV("notifyCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080047 Parcel data, reply;
48 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
49 data.writeInt32(msgType);
50 data.writeInt32(ext1);
51 data.writeInt32(ext2);
52 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
53 }
54
55 // generic data callback from camera service to app with image data
Wu-cheng Li57c86182011-07-30 05:00:37 +080056 void dataCallback(int32_t msgType, const sp<IMemory>& imageData,
57 camera_frame_metadata_t *metadata)
Mathias Agopian3cf61352010-02-09 17:46:37 -080058 {
Steve Block3856b092011-10-20 11:56:00 +010059 ALOGV("dataCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080060 Parcel data, reply;
61 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
62 data.writeInt32(msgType);
Marco Nelissen06b46062014-11-14 07:58:25 -080063 data.writeStrongBinder(IInterface::asBinder(imageData));
Wu-cheng Li57c86182011-07-30 05:00:37 +080064 if (metadata) {
65 data.writeInt32(metadata->number_of_faces);
66 data.write(metadata->faces, sizeof(camera_face_t) * metadata->number_of_faces);
67 }
Mathias Agopian3cf61352010-02-09 17:46:37 -080068 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
69 }
70
71 // generic data callback from camera service to app with image data
72 void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData)
73 {
Steve Block3856b092011-10-20 11:56:00 +010074 ALOGV("dataCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080075 Parcel data, reply;
76 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
77 data.writeInt64(timestamp);
78 data.writeInt32(msgType);
Marco Nelissen06b46062014-11-14 07:58:25 -080079 data.writeStrongBinder(IInterface::asBinder(imageData));
Praveen Chavan6773d472016-01-13 01:24:30 -080080 // If imageData is metadata and it contains a native handle, write the native handle to
81 // parcel.
82 if (CameraUtils::isNativeHandleMetadata(imageData)) {
83 VideoNativeHandleMetadata *metadata =
84 (VideoNativeHandleMetadata*)(imageData->pointer());
85 data.writeNativeHandle(metadata->pHandle);
86 }
Mathias Agopian3cf61352010-02-09 17:46:37 -080087 remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY);
88 }
89};
90
91IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
92
93// ----------------------------------------------------------------------
94
95status_t BnCameraClient::onTransact(
96 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
97{
98 switch(code) {
99 case NOTIFY_CALLBACK: {
Steve Block3856b092011-10-20 11:56:00 +0100100 ALOGV("NOTIFY_CALLBACK");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800101 CHECK_INTERFACE(ICameraClient, data, reply);
102 int32_t msgType = data.readInt32();
103 int32_t ext1 = data.readInt32();
104 int32_t ext2 = data.readInt32();
105 notifyCallback(msgType, ext1, ext2);
106 return NO_ERROR;
107 } break;
108 case DATA_CALLBACK: {
Steve Block3856b092011-10-20 11:56:00 +0100109 ALOGV("DATA_CALLBACK");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800110 CHECK_INTERFACE(ICameraClient, data, reply);
111 int32_t msgType = data.readInt32();
112 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
Wu-cheng Li57c86182011-07-30 05:00:37 +0800113 camera_frame_metadata_t *metadata = NULL;
114 if (data.dataAvail() > 0) {
115 metadata = new camera_frame_metadata_t;
116 metadata->number_of_faces = data.readInt32();
117 metadata->faces = (camera_face_t *) data.readInplace(
118 sizeof(camera_face_t) * metadata->number_of_faces);
119 }
120 dataCallback(msgType, imageData, metadata);
121 if (metadata) delete metadata;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800122 return NO_ERROR;
123 } break;
124 case DATA_CALLBACK_TIMESTAMP: {
Steve Block3856b092011-10-20 11:56:00 +0100125 ALOGV("DATA_CALLBACK_TIMESTAMP");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800126 CHECK_INTERFACE(ICameraClient, data, reply);
127 nsecs_t timestamp = data.readInt64();
128 int32_t msgType = data.readInt32();
129 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
Praveen Chavan6773d472016-01-13 01:24:30 -0800130
131 // If the image data contains a native handle, read the native handle from the parcel
132 // and replace the native handle in the image data. (The native handle in image data is
133 // not serielized/deserialized so it's not valid in the process.)
134 if (CameraUtils::isNativeHandleMetadata(imageData)) {
135 VideoNativeHandleMetadata *metadata =
136 (VideoNativeHandleMetadata*)(imageData->pointer());
137 metadata->pHandle = data.readNativeHandle();
138
139 // The native handle will be freed in
140 // BpCameraRecordingProxyListener::releaseRecordingFrame.
141 }
142
Mathias Agopian3cf61352010-02-09 17:46:37 -0800143 dataCallbackTimestamp(timestamp, msgType, imageData);
144 return NO_ERROR;
145 } break;
146 default:
147 return BBinder::onTransact(code, data, reply, flags);
148 }
149}
150
151// ----------------------------------------------------------------------------
152
153}; // namespace android
154