blob: 613358a996fb22c701e098b82156aa922ed0711d [file] [log] [blame]
Igor Murashkine7ee7632013-06-11 18:10:18 -07001/*
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 "ICameraDeviceCallbacks"
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
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070029#include <camera/camera2/ICameraDeviceCallbacks.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070030#include "camera/CameraMetadata.h"
31
32namespace android {
33
34enum {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070035 CAMERA_ERROR = IBinder::FIRST_CALL_TRANSACTION,
36 CAMERA_IDLE,
37 CAPTURE_STARTED,
Igor Murashkine7ee7632013-06-11 18:10:18 -070038 RESULT_RECEIVED,
39};
40
41class BpCameraDeviceCallbacks: public BpInterface<ICameraDeviceCallbacks>
42{
43public:
44 BpCameraDeviceCallbacks(const sp<IBinder>& impl)
45 : BpInterface<ICameraDeviceCallbacks>(impl)
46 {
47 }
48
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070049 void onDeviceError(CameraErrorCode errorCode)
Igor Murashkine7ee7632013-06-11 18:10:18 -070050 {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070051 ALOGV("onDeviceError");
Igor Murashkine7ee7632013-06-11 18:10:18 -070052 Parcel data, reply;
53 data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070054 data.writeInt32(static_cast<int32_t>(errorCode));
55 remote()->transact(CAMERA_ERROR, data, &reply, IBinder::FLAG_ONEWAY);
Igor Murashkine7ee7632013-06-11 18:10:18 -070056 data.writeNoException();
57 }
58
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070059 void onDeviceIdle()
60 {
61 ALOGV("onDeviceIdle");
62 Parcel data, reply;
63 data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
64 remote()->transact(CAMERA_IDLE, data, &reply, IBinder::FLAG_ONEWAY);
65 data.writeNoException();
66 }
67
68 void onCaptureStarted(int32_t requestId, int64_t timestamp)
69 {
70 ALOGV("onCaptureStarted");
71 Parcel data, reply;
72 data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
73 data.writeInt32(requestId);
74 data.writeInt64(timestamp);
75 remote()->transact(CAPTURE_STARTED, data, &reply, IBinder::FLAG_ONEWAY);
76 data.writeNoException();
77 }
78
79
Zhijun He11d0d442013-07-31 09:50:58 -070080 void onResultReceived(int32_t requestId, const CameraMetadata& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070081 ALOGV("onResultReceived");
82 Parcel data, reply;
83 data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
Zhijun He11d0d442013-07-31 09:50:58 -070084 data.writeInt32(requestId);
85 data.writeInt32(1); // to mark presence of metadata object
Igor Murashkine7ee7632013-06-11 18:10:18 -070086 result.writeToParcel(&data);
87 remote()->transact(RESULT_RECEIVED, data, &reply, IBinder::FLAG_ONEWAY);
88 data.writeNoException();
89 }
90};
91
92IMPLEMENT_META_INTERFACE(CameraDeviceCallbacks,
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070093 "android.hardware.camera2.ICameraDeviceCallbacks");
Igor Murashkine7ee7632013-06-11 18:10:18 -070094
95// ----------------------------------------------------------------------
96
97status_t BnCameraDeviceCallbacks::onTransact(
98 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
99{
100 ALOGV("onTransact - code = %d", code);
101 switch(code) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700102 case CAMERA_ERROR: {
103 ALOGV("onDeviceError");
Igor Murashkine7ee7632013-06-11 18:10:18 -0700104 CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700105 CameraErrorCode errorCode =
106 static_cast<CameraErrorCode>(data.readInt32());
107 onDeviceError(errorCode);
108 data.readExceptionCode();
109 return NO_ERROR;
110 } break;
111 case CAMERA_IDLE: {
112 ALOGV("onDeviceIdle");
113 CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
114 onDeviceIdle();
115 data.readExceptionCode();
116 return NO_ERROR;
117 } break;
118 case CAPTURE_STARTED: {
119 ALOGV("onCaptureStarted");
120 CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
121 int32_t requestId = data.readInt32();
122 int64_t timestamp = data.readInt64();
123 onCaptureStarted(requestId, timestamp);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700124 data.readExceptionCode();
125 return NO_ERROR;
126 } break;
127 case RESULT_RECEIVED: {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700128 ALOGV("onResultReceived");
Igor Murashkine7ee7632013-06-11 18:10:18 -0700129 CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
Zhijun He11d0d442013-07-31 09:50:58 -0700130 int32_t requestId = data.readInt32();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700131 CameraMetadata result;
Zhijun He11d0d442013-07-31 09:50:58 -0700132 if (data.readInt32() != 0) {
133 result.readFromParcel(const_cast<Parcel*>(&data));
134 } else {
135 ALOGW("No metadata object is present in result");
136 }
137 onResultReceived(requestId, result);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700138 data.readExceptionCode();
139 return NO_ERROR;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700140 } break;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700141 default:
142 return BBinder::onTransact(code, data, reply, flags);
143 }
144}
145
146// ----------------------------------------------------------------------------
147
148}; // namespace android