blob: c5d6d52f4df9a79dd25048467b64e7829340f48d [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
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
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080018//#define LOG_NDEBUG 0
19#define LOG_TAG "ICameraClient"
20#include <utils/Log.h>
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070021#include <stdint.h>
22#include <sys/types.h>
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070023#include <ui/ICameraClient.h>
24
25namespace android {
26
27enum {
28 SHUTTER_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
29 RAW_CALLBACK,
30 JPEG_CALLBACK,
31 FRAME_CALLBACK,
32 ERROR_CALLBACK,
33 AUTOFOCUS_CALLBACK
34};
35
36class BpCameraClient: public BpInterface<ICameraClient>
37{
38public:
39 BpCameraClient(const sp<IBinder>& impl)
40 : BpInterface<ICameraClient>(impl)
41 {
42 }
43
44 // callback to let the app know the shutter has closed, ideal for playing the shutter sound
45 void shutterCallback()
46 {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080047 LOGV("shutterCallback");
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070048 Parcel data, reply;
49 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
50 remote()->transact(SHUTTER_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
51 }
52
53 // callback from camera service to app with picture data
54 void rawCallback(const sp<IMemory>& picture)
55 {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080056 LOGV("rawCallback");
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070057 Parcel data, reply;
58 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
59 data.writeStrongBinder(picture->asBinder());
60 remote()->transact(RAW_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
61 }
62
63 // callback from camera service to app with picture data
64 void jpegCallback(const sp<IMemory>& picture)
65 {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080066 LOGV("jpegCallback");
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070067 Parcel data, reply;
68 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
69 data.writeStrongBinder(picture->asBinder());
70 remote()->transact(JPEG_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
71 }
72
73 // callback from camera service to app with video frame data
74 void frameCallback(const sp<IMemory>& frame)
75 {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080076 LOGV("frameCallback");
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070077 Parcel data, reply;
78 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
79 data.writeStrongBinder(frame->asBinder());
80 remote()->transact(FRAME_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
81 }
82
83 // callback from camera service to app to report error
84 void errorCallback(status_t error)
85 {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080086 LOGV("errorCallback");
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070087 Parcel data, reply;
88 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
89 data.writeInt32(error);
90 remote()->transact(ERROR_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
91 }
92
93 // callback from camera service to app to report autofocus completion
94 void autoFocusCallback(bool focused)
95 {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080096 LOGV("autoFocusCallback");
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070097 Parcel data, reply;
98 data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
99 data.writeInt32(focused);
100 remote()->transact(AUTOFOCUS_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
101 }
102};
103
104IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
105
106// ----------------------------------------------------------------------
107
108#define CHECK_INTERFACE(interface, data, reply) \
109 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
110 LOGW("Call incorrectly routed to " #interface); \
111 return PERMISSION_DENIED; \
112 } } while (0)
113
114status_t BnCameraClient::onTransact(
115 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
116{
117 switch(code) {
118 case SHUTTER_CALLBACK: {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800119 LOGV("SHUTTER_CALLBACK");
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700120 CHECK_INTERFACE(ICameraClient, data, reply);
121 shutterCallback();
122 return NO_ERROR;
123 } break;
124 case RAW_CALLBACK: {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800125 LOGV("RAW_CALLBACK");
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700126 CHECK_INTERFACE(ICameraClient, data, reply);
127 sp<IMemory> picture = interface_cast<IMemory>(data.readStrongBinder());
128 rawCallback(picture);
129 return NO_ERROR;
130 } break;
131 case JPEG_CALLBACK: {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800132 LOGV("JPEG_CALLBACK");
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700133 CHECK_INTERFACE(ICameraClient, data, reply);
134 sp<IMemory> picture = interface_cast<IMemory>(data.readStrongBinder());
135 jpegCallback(picture);
136 return NO_ERROR;
137 } break;
138 case FRAME_CALLBACK: {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800139 LOGV("FRAME_CALLBACK");
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700140 CHECK_INTERFACE(ICameraClient, data, reply);
141 sp<IMemory> frame = interface_cast<IMemory>(data.readStrongBinder());
142 frameCallback(frame);
143 return NO_ERROR;
144 } break;
145 case ERROR_CALLBACK: {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800146 LOGV("ERROR_CALLBACK");
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700147 CHECK_INTERFACE(ICameraClient, data, reply);
148 status_t error = data.readInt32();
149 errorCallback(error);
150 return NO_ERROR;
151 } break;
152 case AUTOFOCUS_CALLBACK: {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800153 LOGV("AUTOFOCUS_CALLBACK");
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700154 CHECK_INTERFACE(ICameraClient, data, reply);
155 bool focused = (bool)data.readInt32();
156 autoFocusCallback(focused);
157 return NO_ERROR;
158 } break;
159 default:
160 return BBinder::onTransact(code, data, reply, flags);
161 }
162}
163
164// ----------------------------------------------------------------------------
165
166}; // namespace android
167