blob: d128f5bbb14303cd2ce1eb457473aae085e6a246 [file] [log] [blame]
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18#define LOG_TAG "ICameraRecordingProxy"
Praveen Chavan6773d472016-01-13 01:24:30 -080019#include <camera/CameraUtils.h>
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080020#include <camera/ICameraRecordingProxy.h>
21#include <camera/ICameraRecordingProxyListener.h>
22#include <binder/IMemory.h>
23#include <binder/Parcel.h>
Praveen Chavan6773d472016-01-13 01:24:30 -080024#include <media/hardware/HardwareAPI.h>
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080025#include <stdint.h>
26#include <utils/Log.h>
27
28namespace android {
29
30enum {
31 START_RECORDING = IBinder::FIRST_CALL_TRANSACTION,
32 STOP_RECORDING,
33 RELEASE_RECORDING_FRAME,
34};
35
36
37class BpCameraRecordingProxy: public BpInterface<ICameraRecordingProxy>
38{
39public:
40 BpCameraRecordingProxy(const sp<IBinder>& impl)
41 : BpInterface<ICameraRecordingProxy>(impl)
42 {
43 }
44
45 status_t startRecording(const sp<ICameraRecordingProxyListener>& listener)
46 {
Steve Block3856b092011-10-20 11:56:00 +010047 ALOGV("startRecording");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080048 Parcel data, reply;
49 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -080050 data.writeStrongBinder(IInterface::asBinder(listener));
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080051 remote()->transact(START_RECORDING, data, &reply);
52 return reply.readInt32();
53 }
54
55 void stopRecording()
56 {
Steve Block3856b092011-10-20 11:56:00 +010057 ALOGV("stopRecording");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080058 Parcel data, reply;
59 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
60 remote()->transact(STOP_RECORDING, data, &reply);
61 }
62
63 void releaseRecordingFrame(const sp<IMemory>& mem)
64 {
Steve Block3856b092011-10-20 11:56:00 +010065 ALOGV("releaseRecordingFrame");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080066 Parcel data, reply;
67 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -080068 data.writeStrongBinder(IInterface::asBinder(mem));
Praveen Chavan6773d472016-01-13 01:24:30 -080069
70 native_handle_t *nh = nullptr;
71 if (CameraUtils::isNativeHandleMetadata(mem)) {
72 VideoNativeHandleMetadata *metadata =
73 (VideoNativeHandleMetadata*)(mem->pointer());
74 nh = metadata->pHandle;
75 data.writeNativeHandle(nh);
76 }
77
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080078 remote()->transact(RELEASE_RECORDING_FRAME, data, &reply);
Praveen Chavan6773d472016-01-13 01:24:30 -080079
80 if (nh) {
81 // Close the native handle because camera received a dup copy.
82 native_handle_close(nh);
83 native_handle_delete(nh);
84 }
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080085 }
86};
87
88IMPLEMENT_META_INTERFACE(CameraRecordingProxy, "android.hardware.ICameraRecordingProxy");
89
90// ----------------------------------------------------------------------
91
92status_t BnCameraRecordingProxy::onTransact(
93 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
94{
95 switch(code) {
96 case START_RECORDING: {
Steve Block3856b092011-10-20 11:56:00 +010097 ALOGV("START_RECORDING");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080098 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
99 sp<ICameraRecordingProxyListener> listener =
100 interface_cast<ICameraRecordingProxyListener>(data.readStrongBinder());
101 reply->writeInt32(startRecording(listener));
102 return NO_ERROR;
103 } break;
104 case STOP_RECORDING: {
Steve Block3856b092011-10-20 11:56:00 +0100105 ALOGV("STOP_RECORDING");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800106 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
107 stopRecording();
108 return NO_ERROR;
109 } break;
110 case RELEASE_RECORDING_FRAME: {
Steve Block3856b092011-10-20 11:56:00 +0100111 ALOGV("RELEASE_RECORDING_FRAME");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800112 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
113 sp<IMemory> mem = interface_cast<IMemory>(data.readStrongBinder());
Praveen Chavan6773d472016-01-13 01:24:30 -0800114
115 if (CameraUtils::isNativeHandleMetadata(mem)) {
116 VideoNativeHandleMetadata *metadata =
117 (VideoNativeHandleMetadata*)(mem->pointer());
118 metadata->pHandle = data.readNativeHandle();
119
120 // releaseRecordingFrame will be responsble to close the native handle.
121 }
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800122 releaseRecordingFrame(mem);
Praveen Chavan6773d472016-01-13 01:24:30 -0800123
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800124 return NO_ERROR;
125 } break;
126
127 default:
128 return BBinder::onTransact(code, data, reply, flags);
129 }
130}
131
132// ----------------------------------------------------------------------------
133
134}; // namespace android
135