blob: 63c4b1d3e064b46df3882b5c432ee71f6ba8ee2d [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,
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -070034 RELEASE_RECORDING_FRAME_HANDLE,
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080035};
36
37
38class BpCameraRecordingProxy: public BpInterface<ICameraRecordingProxy>
39{
40public:
41 BpCameraRecordingProxy(const sp<IBinder>& impl)
42 : BpInterface<ICameraRecordingProxy>(impl)
43 {
44 }
45
46 status_t startRecording(const sp<ICameraRecordingProxyListener>& listener)
47 {
Steve Block3856b092011-10-20 11:56:00 +010048 ALOGV("startRecording");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080049 Parcel data, reply;
50 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -080051 data.writeStrongBinder(IInterface::asBinder(listener));
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080052 remote()->transact(START_RECORDING, data, &reply);
53 return reply.readInt32();
54 }
55
56 void stopRecording()
57 {
Steve Block3856b092011-10-20 11:56:00 +010058 ALOGV("stopRecording");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080059 Parcel data, reply;
60 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
61 remote()->transact(STOP_RECORDING, data, &reply);
62 }
63
64 void releaseRecordingFrame(const sp<IMemory>& mem)
65 {
Steve Block3856b092011-10-20 11:56:00 +010066 ALOGV("releaseRecordingFrame");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080067 Parcel data, reply;
68 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -080069 data.writeStrongBinder(IInterface::asBinder(mem));
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080070 remote()->transact(RELEASE_RECORDING_FRAME, data, &reply);
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -070071 }
Praveen Chavan6773d472016-01-13 01:24:30 -080072
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -070073 void releaseRecordingFrameHandle(native_handle_t *handle) {
74 ALOGV("releaseRecordingFrameHandle");
75 Parcel data, reply;
76 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
77 data.writeNativeHandle(handle);
78
79 remote()->transact(RELEASE_RECORDING_FRAME_HANDLE, data, &reply);
80
81 // Close the native handle because camera received a dup copy.
82 native_handle_close(handle);
83 native_handle_delete(handle);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080084 }
85};
86
87IMPLEMENT_META_INTERFACE(CameraRecordingProxy, "android.hardware.ICameraRecordingProxy");
88
89// ----------------------------------------------------------------------
90
91status_t BnCameraRecordingProxy::onTransact(
92 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
93{
94 switch(code) {
95 case START_RECORDING: {
Steve Block3856b092011-10-20 11:56:00 +010096 ALOGV("START_RECORDING");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080097 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
98 sp<ICameraRecordingProxyListener> listener =
99 interface_cast<ICameraRecordingProxyListener>(data.readStrongBinder());
100 reply->writeInt32(startRecording(listener));
101 return NO_ERROR;
102 } break;
103 case STOP_RECORDING: {
Steve Block3856b092011-10-20 11:56:00 +0100104 ALOGV("STOP_RECORDING");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800105 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
106 stopRecording();
107 return NO_ERROR;
108 } break;
109 case RELEASE_RECORDING_FRAME: {
Steve Block3856b092011-10-20 11:56:00 +0100110 ALOGV("RELEASE_RECORDING_FRAME");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800111 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
112 sp<IMemory> mem = interface_cast<IMemory>(data.readStrongBinder());
113 releaseRecordingFrame(mem);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800114 return NO_ERROR;
115 } break;
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700116 case RELEASE_RECORDING_FRAME_HANDLE: {
117 ALOGV("RELEASE_RECORDING_FRAME_HANDLE");
118 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800119
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700120 // releaseRecordingFrameHandle will be responsble to close the native handle.
121 releaseRecordingFrameHandle(data.readNativeHandle());
122 return NO_ERROR;
123 } break;
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800124 default:
125 return BBinder::onTransact(code, data, reply, flags);
126 }
127}
128
129// ----------------------------------------------------------------------------
130
131}; // namespace android
132