blob: c2ad74f088fc7c85873a121b146f5ac4473088f6 [file] [log] [blame]
Igor Murashkinbfb5d5e2013-02-20 17:15:11 -08001/*
2**
3** Copyright 2013, 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 "IProCameraCallbacks"
20#include <utils/Log.h>
21#include <stdint.h>
22#include <sys/types.h>
23
24#include <binder/Parcel.h>
25#include <gui/IGraphicBufferProducer.h>
26#include <gui/Surface.h>
27#include <utils/Mutex.h>
28
29#include <camera/IProCameraCallbacks.h>
30
31namespace android {
32
33enum {
34 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
35 DATA_CALLBACK,
36 DATA_CALLBACK_TIMESTAMP,
37};
38
39class BpProCameraCallbacks: public BpInterface<IProCameraCallbacks>
40{
41public:
42 BpProCameraCallbacks(const sp<IBinder>& impl)
43 : BpInterface<IProCameraCallbacks>(impl)
44 {
45 }
46
47 // generic callback from camera service to app
48 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
49 {
50 ALOGV("notifyCallback");
51 Parcel data, reply;
52 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
53 data.writeInt32(msgType);
54 data.writeInt32(ext1);
55 data.writeInt32(ext2);
56 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
57 }
58
59 // generic data callback from camera service to app with image data
60 void dataCallback(int32_t msgType, const sp<IMemory>& imageData,
61 camera_frame_metadata_t *metadata)
62 {
63 ALOGV("dataCallback");
64 Parcel data, reply;
65 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
66 data.writeInt32(msgType);
67 data.writeStrongBinder(imageData->asBinder());
68 if (metadata) {
69 data.writeInt32(metadata->number_of_faces);
70 data.write(metadata->faces,
71 sizeof(camera_face_t) * metadata->number_of_faces);
72 }
73 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
74 }
75
76 // generic data callback from camera service to app with image data
77 void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType,
78 const sp<IMemory>& imageData)
79 {
80 ALOGV("dataCallback");
81 Parcel data, reply;
82 data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
83 data.writeInt64(timestamp);
84 data.writeInt32(msgType);
85 data.writeStrongBinder(imageData->asBinder());
86 remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply,
87 IBinder::FLAG_ONEWAY);
88 }
89};
90
91IMPLEMENT_META_INTERFACE(ProCameraCallbacks,
92 "android.hardware.IProCameraCallbacks");
93
94// ----------------------------------------------------------------------
95
96status_t BnProCameraCallbacks::onTransact(
97 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
98{
99 switch(code) {
100 case NOTIFY_CALLBACK: {
101 ALOGV("NOTIFY_CALLBACK");
102 CHECK_INTERFACE(IProCameraCallbacks, 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: {
110 ALOGV("DATA_CALLBACK");
111 CHECK_INTERFACE(IProCameraCallbacks, data, reply);
112 int32_t msgType = data.readInt32();
113 sp<IMemory> imageData = interface_cast<IMemory>(
114 data.readStrongBinder());
115 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;
124 return NO_ERROR;
125 } break;
126 case DATA_CALLBACK_TIMESTAMP: {
127 ALOGV("DATA_CALLBACK_TIMESTAMP");
128 CHECK_INTERFACE(IProCameraCallbacks, data, reply);
129 nsecs_t timestamp = data.readInt64();
130 int32_t msgType = data.readInt32();
131 sp<IMemory> imageData = interface_cast<IMemory>(
132 data.readStrongBinder());
133 dataCallbackTimestamp(timestamp, msgType, imageData);
134 return NO_ERROR;
135 } break;
136 default:
137 return BBinder::onTransact(code, data, reply, flags);
138 }
139}
140
141// ----------------------------------------------------------------------------
142
143}; // namespace android
144