ICameraClient.cpp revision 3cf613507f1e2f7bd932d921a6e222e426fd3be4
1/*
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    {
44        LOGV("notifyCallback");
45        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
54    void dataCallback(int32_t msgType, const sp<IMemory>& imageData)
55    {
56        LOGV("dataCallback");
57        Parcel data, reply;
58        data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
59        data.writeInt32(msgType);
60        data.writeStrongBinder(imageData->asBinder());
61        remote()->transact(DATA_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
62    }
63
64    // generic data callback from camera service to app with image data
65    void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& imageData)
66    {
67        LOGV("dataCallback");
68        Parcel data, reply;
69        data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
70        data.writeInt64(timestamp);
71        data.writeInt32(msgType);
72        data.writeStrongBinder(imageData->asBinder());
73        remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY);
74    }
75};
76
77IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
78
79// ----------------------------------------------------------------------
80
81status_t BnCameraClient::onTransact(
82    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
83{
84    switch(code) {
85        case NOTIFY_CALLBACK: {
86            LOGV("NOTIFY_CALLBACK");
87            CHECK_INTERFACE(ICameraClient, data, reply);
88            int32_t msgType = data.readInt32();
89            int32_t ext1 = data.readInt32();
90            int32_t ext2 = data.readInt32();
91            notifyCallback(msgType, ext1, ext2);
92            return NO_ERROR;
93        } break;
94        case DATA_CALLBACK: {
95            LOGV("DATA_CALLBACK");
96            CHECK_INTERFACE(ICameraClient, data, reply);
97            int32_t msgType = data.readInt32();
98            sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
99            dataCallback(msgType, imageData);
100            return NO_ERROR;
101        } break;
102        case DATA_CALLBACK_TIMESTAMP: {
103            LOGV("DATA_CALLBACK_TIMESTAMP");
104            CHECK_INTERFACE(ICameraClient, data, reply);
105            nsecs_t timestamp = data.readInt64();
106            int32_t msgType = data.readInt32();
107            sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
108            dataCallbackTimestamp(timestamp, msgType, imageData);
109            return NO_ERROR;
110        } break;
111        default:
112            return BBinder::onTransact(code, data, reply, flags);
113    }
114}
115
116// ----------------------------------------------------------------------------
117
118}; // namespace android
119
120