blob: 205c8ba1f123df1ffcf8d23442ce58ce6cf544a4 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -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>
Mathias Agopian000479f2010-02-09 17:46:37 -080023#include <camera/ICameraClient.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25namespace android {
26
27enum {
Dave Sparksd6289b12009-05-07 19:27:32 -070028 NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
Dave Sparks2a04aef2009-05-07 12:25:25 -070029 DATA_CALLBACK,
Dave Sparks59c1a932009-07-08 15:56:53 -070030 DATA_CALLBACK_TIMESTAMP,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031};
32
33class BpCameraClient: public BpInterface<ICameraClient>
34{
35public:
36 BpCameraClient(const sp<IBinder>& impl)
37 : BpInterface<ICameraClient>(impl)
38 {
39 }
40
Dave Sparks2a04aef2009-05-07 12:25:25 -070041 // generic callback from camera service to app
42 void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
43 {
Steve Block71f2cf12011-10-20 11:56:00 +010044 ALOGV("notifyCallback");
Dave Sparks2a04aef2009-05-07 12:25:25 -070045 Parcel data, reply;
46 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
47 data.writeInt32(msgType);
48 data.writeInt32(ext1);
49 data.writeInt32(ext2);
50 remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
51 }
52
53 // generic data callback from camera service to app with image data
Wu-cheng Libb1e2752011-07-30 05:00:37 +080054 void dataCallback(int32_t msgType, const sp<IMemory>& imageData,
55 camera_frame_metadata_t *metadata)
Dave Sparks2a04aef2009-05-07 12:25:25 -070056 {
Steve Block71f2cf12011-10-20 11:56:00 +010057 ALOGV("dataCallback");
Dave Sparks2a04aef2009-05-07 12:25:25 -070058 Parcel data, reply;
59 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
60 data.writeInt32(msgType);
61 data.writeStrongBinder(imageData->asBinder());
Wu-cheng Libb1e2752011-07-30 05:00:37 +080062 if (metadata) {
63 data.writeInt32(metadata->number_of_faces);
64 data.write(metadata->faces, sizeof(camera_face_t) * metadata->number_of_faces);
65 }
Dave Sparks2a04aef2009-05-07 12:25:25 -070066 remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
67 }
68
Dave Sparks59c1a932009-07-08 15:56:53 -070069 // generic data callback from camera service to app with image data
70 void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData)
71 {
Steve Block71f2cf12011-10-20 11:56:00 +010072 ALOGV("dataCallback");
Dave Sparks59c1a932009-07-08 15:56:53 -070073 Parcel data, reply;
74 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
75 data.writeInt64(timestamp);
76 data.writeInt32(msgType);
77 data.writeStrongBinder(imageData->asBinder());
78 remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY);
79 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080};
81
82IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
83
84// ----------------------------------------------------------------------
85
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086status_t BnCameraClient::onTransact(
87 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
88{
89 switch(code) {
Dave Sparks2a04aef2009-05-07 12:25:25 -070090 case NOTIFY_CALLBACK: {
Steve Block71f2cf12011-10-20 11:56:00 +010091 ALOGV("NOTIFY_CALLBACK");
Dave Sparks2a04aef2009-05-07 12:25:25 -070092 CHECK_INTERFACE(ICameraClient, data, reply);
93 int32_t msgType = data.readInt32();
94 int32_t ext1 = data.readInt32();
95 int32_t ext2 = data.readInt32();
96 notifyCallback(msgType, ext1, ext2);
97 return NO_ERROR;
98 } break;
99 case DATA_CALLBACK: {
Steve Block71f2cf12011-10-20 11:56:00 +0100100 ALOGV("DATA_CALLBACK");
Dave Sparks2a04aef2009-05-07 12:25:25 -0700101 CHECK_INTERFACE(ICameraClient, data, reply);
102 int32_t msgType = data.readInt32();
103 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800104 camera_frame_metadata_t *metadata = NULL;
105 if (data.dataAvail() > 0) {
106 metadata = new camera_frame_metadata_t;
107 metadata->number_of_faces = data.readInt32();
108 metadata->faces = (camera_face_t *) data.readInplace(
109 sizeof(camera_face_t) * metadata->number_of_faces);
110 }
111 dataCallback(msgType, imageData, metadata);
112 if (metadata) delete metadata;
Dave Sparks2a04aef2009-05-07 12:25:25 -0700113 return NO_ERROR;
114 } break;
Dave Sparks59c1a932009-07-08 15:56:53 -0700115 case DATA_CALLBACK_TIMESTAMP: {
Steve Block71f2cf12011-10-20 11:56:00 +0100116 ALOGV("DATA_CALLBACK_TIMESTAMP");
Dave Sparks59c1a932009-07-08 15:56:53 -0700117 CHECK_INTERFACE(ICameraClient, data, reply);
118 nsecs_t timestamp = data.readInt64();
119 int32_t msgType = data.readInt32();
120 sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
121 dataCallbackTimestamp(timestamp, msgType, imageData);
122 return NO_ERROR;
123 } break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 default:
125 return BBinder::onTransact(code, data, reply, flags);
126 }
127}
128
129// ----------------------------------------------------------------------------
130
131}; // namespace android
132