1 /*
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"
19 #include <camera/ICameraRecordingProxy.h>
20 #include <camera/ICameraRecordingProxyListener.h>
21 #include <binder/IMemory.h>
22 #include <binder/Parcel.h>
23 #include <stdint.h>
24 #include <utils/Log.h>
25
26 namespace android {
27
28 enum {
29 START_RECORDING = IBinder::FIRST_CALL_TRANSACTION,
30 STOP_RECORDING,
31 RELEASE_RECORDING_FRAME,
32 };
33
34 uint8_t ICameraRecordingProxy::baseObject = 0;
35
getCommonBaseAddress()36 size_t ICameraRecordingProxy::getCommonBaseAddress() {
37 return (size_t)&baseObject;
38 }
39
40 class BpCameraRecordingProxy: public BpInterface<ICameraRecordingProxy>
41 {
42 public:
BpCameraRecordingProxy(const sp<IBinder> & impl)43 BpCameraRecordingProxy(const sp<IBinder>& impl)
44 : BpInterface<ICameraRecordingProxy>(impl)
45 {
46 }
47
startRecording(const sp<ICameraRecordingProxyListener> & listener)48 status_t startRecording(const sp<ICameraRecordingProxyListener>& listener)
49 {
50 ALOGV("startRecording");
51 Parcel data, reply;
52 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
53 data.writeStrongBinder(IInterface::asBinder(listener));
54 remote()->transact(START_RECORDING, data, &reply);
55 return reply.readInt32();
56 }
57
stopRecording()58 void stopRecording()
59 {
60 ALOGV("stopRecording");
61 Parcel data, reply;
62 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
63 remote()->transact(STOP_RECORDING, data, &reply);
64 }
65
releaseRecordingFrame(const sp<IMemory> & mem)66 void releaseRecordingFrame(const sp<IMemory>& mem)
67 {
68 ALOGV("releaseRecordingFrame");
69 Parcel data, reply;
70 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
71 data.writeStrongBinder(IInterface::asBinder(mem));
72 remote()->transact(RELEASE_RECORDING_FRAME, data, &reply);
73 }
74 };
75
76 IMPLEMENT_META_INTERFACE(CameraRecordingProxy, "android.hardware.ICameraRecordingProxy");
77
78 // ----------------------------------------------------------------------
79
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)80 status_t BnCameraRecordingProxy::onTransact(
81 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
82 {
83 switch(code) {
84 case START_RECORDING: {
85 ALOGV("START_RECORDING");
86 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
87 sp<ICameraRecordingProxyListener> listener =
88 interface_cast<ICameraRecordingProxyListener>(data.readStrongBinder());
89 reply->writeInt32(startRecording(listener));
90 return NO_ERROR;
91 } break;
92 case STOP_RECORDING: {
93 ALOGV("STOP_RECORDING");
94 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
95 stopRecording();
96 return NO_ERROR;
97 } break;
98 case RELEASE_RECORDING_FRAME: {
99 ALOGV("RELEASE_RECORDING_FRAME");
100 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
101 sp<IMemory> mem = interface_cast<IMemory>(data.readStrongBinder());
102 releaseRecordingFrame(mem);
103 return NO_ERROR;
104 } break;
105
106 default:
107 return BBinder::onTransact(code, data, reply, flags);
108 }
109 }
110
111 // ----------------------------------------------------------------------------
112
113 }; // namespace android
114