blob: 4f437964937da234f43183e74e7a322a99854433 [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);
Susmitha Gummallac46f5e162014-04-29 12:18:30 -070049 if ((msgType == CAMERA_MSG_PREVIEW_FRAME) && (ext1 == CAMERA_FRAME_DATA_FD)) {
50 ALOGD("notifyCallback: CAMERA_MSG_PREVIEW_FRAME fd = %d", ext2);
51 data.writeFileDescriptor(ext2);
52 } else {
53 data.writeInt32(ext2);
54 }
Mathias Agopian3cf61352010-02-09 17:46:37 -080055 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
56 }
57
58 // generic data callback from camera service to app with image data
Wu-cheng Li57c86182011-07-30 05:00:37 +080059 void dataCallback(int32_t msgType, const sp<IMemory>& imageData,
60 camera_frame_metadata_t *metadata)
Mathias Agopian3cf61352010-02-09 17:46:37 -080061 {
Steve Block3856b092011-10-20 11:56:00 +010062 ALOGV("dataCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080063 Parcel data, reply;
64 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
65 data.writeInt32(msgType);
Marco Nelissen06b46062014-11-14 07:58:25 -080066 data.writeStrongBinder(IInterface::asBinder(imageData));
Wu-cheng Li57c86182011-07-30 05:00:37 +080067 if (metadata) {
68 data.writeInt32(metadata->number_of_faces);
69 data.write(metadata->faces, sizeof(camera_face_t) * metadata->number_of_faces);
70 }
Mathias Agopian3cf61352010-02-09 17:46:37 -080071 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
72 }
73
74 // generic data callback from camera service to app with image data
75 void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData)
76 {
Steve Block3856b092011-10-20 11:56:00 +010077 ALOGV("dataCallback");
Mathias Agopian3cf61352010-02-09 17:46:37 -080078 Parcel data, reply;
79 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
80 data.writeInt64(timestamp);
81 data.writeInt32(msgType);
Marco Nelissen06b46062014-11-14 07:58:25 -080082 data.writeStrongBinder(IInterface::asBinder(imageData));
Mathias Agopian3cf61352010-02-09 17:46:37 -080083 remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY);
84 }
85};
86
87IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
88
89// ----------------------------------------------------------------------
90
91status_t BnCameraClient::onTransact(
92 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
93{
94 switch(code) {
95 case NOTIFY_CALLBACK: {
Steve Block3856b092011-10-20 11:56:00 +010096 ALOGV("NOTIFY_CALLBACK");
Mathias Agopian3cf61352010-02-09 17:46:37 -080097 CHECK_INTERFACE(ICameraClient, data, reply);
98 int32_t msgType = data.readInt32();
Susmitha Gummallac46f5e162014-04-29 12:18:30 -070099 int32_t ext1 = data.readInt32();
100 int32_t ext2 = 0;
101 if ((msgType == CAMERA_MSG_PREVIEW_FRAME) && (ext1 == CAMERA_FRAME_DATA_FD)) {
102 ext2 = data.readFileDescriptor();
103 ALOGD("onTransact: CAMERA_MSG_PREVIEW_FRAME fd = %d", ext2);
104 } else {
105 ext2 = data.readInt32();
106 }
Mathias Agopian3cf61352010-02-09 17:46:37 -0800107 notifyCallback(msgType, ext1, ext2);
108 return NO_ERROR;
109 } break;
110 case DATA_CALLBACK: {
Steve Block3856b092011-10-20 11:56:00 +0100111 ALOGV("DATA_CALLBACK");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800112 CHECK_INTERFACE(ICameraClient, data, reply);
113 int32_t msgType = data.readInt32();
114 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
Wu-cheng Li57c86182011-07-30 05:00:37 +0800115 camera_frame_metadata_t *metadata = NULL;
116 if (data.dataAvail() > 0) {
117 metadata = new camera_frame_metadata_t;
118 metadata->number_of_faces = data.readInt32();
119 metadata->faces = (camera_face_t *) data.readInplace(
120 sizeof(camera_face_t) * metadata->number_of_faces);
121 }
122 dataCallback(msgType, imageData, metadata);
123 if (metadata) delete metadata;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800124 return NO_ERROR;
125 } break;
126 case DATA_CALLBACK_TIMESTAMP: {
Steve Block3856b092011-10-20 11:56:00 +0100127 ALOGV("DATA_CALLBACK_TIMESTAMP");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800128 CHECK_INTERFACE(ICameraClient, data, reply);
129 nsecs_t timestamp = data.readInt64();
130 int32_t msgType = data.readInt32();
131 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
132 dataCallbackTimestamp(timestamp, msgType, imageData);
133 return NO_ERROR;
134 } break;
135 default:
136 return BBinder::onTransact(code, data, reply, flags);
137 }
138}
139
140// ----------------------------------------------------------------------------
141
142}; // namespace android
143