ICameraClient.cpp revision 3cf613507f1e2f7bd932d921a6e222e426fd3be4
13cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian/* 23cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** 33cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** Copyright 2008, The Android Open Source Project 43cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** 53cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** Licensed under the Apache License, Version 2.0 (the "License"); 63cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** you may not use this file except in compliance with the License. 73cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** You may obtain a copy of the License at 83cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** 93cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** http://www.apache.org/licenses/LICENSE-2.0 103cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** 113cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** Unless required by applicable law or agreed to in writing, software 123cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** distributed under the License is distributed on an "AS IS" BASIS, 133cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 143cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** See the License for the specific language governing permissions and 153cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** limitations under the License. 163cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian*/ 173cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 183cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian//#define LOG_NDEBUG 0 193cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#define LOG_TAG "ICameraClient" 203cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <utils/Log.h> 213cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <stdint.h> 223cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <sys/types.h> 233cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <camera/ICameraClient.h> 243cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 253cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopiannamespace android { 263cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 273cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianenum { 283cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION, 293cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian DATA_CALLBACK, 303cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian DATA_CALLBACK_TIMESTAMP, 313cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian}; 323cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 333cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianclass BpCameraClient: public BpInterface<ICameraClient> 343cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian{ 353cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianpublic: 363cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian BpCameraClient(const sp<IBinder>& impl) 373cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian : BpInterface<ICameraClient>(impl) 383cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian { 393cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } 403cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 413cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian // generic callback from camera service to app 423cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) 433cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian { 443cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian LOGV("notifyCallback"); 453cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian Parcel data, reply; 463cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); 473cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeInt32(msgType); 483cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeInt32(ext1); 493cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeInt32(ext2); 503cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); 513cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } 523cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 533cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian // generic data callback from camera service to app with image data 543cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian void dataCallback(int32_t msgType, const sp<IMemory>& imageData) 553cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian { 563cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian LOGV("dataCallback"); 573cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian Parcel data, reply; 583cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); 593cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeInt32(msgType); 603cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeStrongBinder(imageData->asBinder()); 613cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); 623cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } 633cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 643cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian // generic data callback from camera service to app with image data 653cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData) 663cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian { 673cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian LOGV("dataCallback"); 683cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian Parcel data, reply; 693cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); 703cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeInt64(timestamp); 713cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeInt32(msgType); 723cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeStrongBinder(imageData->asBinder()); 733cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY); 743cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } 753cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian}; 763cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 773cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias AgopianIMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient"); 783cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 793cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian// ---------------------------------------------------------------------- 803cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 813cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianstatus_t BnCameraClient::onTransact( 823cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 833cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian{ 843cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian switch(code) { 853cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian case NOTIFY_CALLBACK: { 863cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian LOGV("NOTIFY_CALLBACK"); 873cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian CHECK_INTERFACE(ICameraClient, data, reply); 883cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian int32_t msgType = data.readInt32(); 893cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian int32_t ext1 = data.readInt32(); 903cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian int32_t ext2 = data.readInt32(); 913cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian notifyCallback(msgType, ext1, ext2); 923cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian return NO_ERROR; 933cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } break; 943cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian case DATA_CALLBACK: { 953cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian LOGV("DATA_CALLBACK"); 963cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian CHECK_INTERFACE(ICameraClient, data, reply); 973cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian int32_t msgType = data.readInt32(); 983cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder()); 993cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian dataCallback(msgType, imageData); 1003cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian return NO_ERROR; 1013cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } break; 1023cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian case DATA_CALLBACK_TIMESTAMP: { 1033cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian LOGV("DATA_CALLBACK_TIMESTAMP"); 1043cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian CHECK_INTERFACE(ICameraClient, data, reply); 1053cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian nsecs_t timestamp = data.readInt64(); 1063cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian int32_t msgType = data.readInt32(); 1073cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder()); 1083cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian dataCallbackTimestamp(timestamp, msgType, imageData); 1093cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian return NO_ERROR; 1103cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } break; 1113cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian default: 1123cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian return BBinder::onTransact(code, data, reply, flags); 1133cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } 1143cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian} 1153cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 1163cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian// ---------------------------------------------------------------------------- 1173cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 1183cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian}; // namespace android 1193cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 120