2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 //#define LOG_NDEBUG 0
18 #define LOG_TAG "ICameraRecordingProxy"
19 #include <camera/CameraUtils.h>
20 #include <camera/ICameraRecordingProxy.h>
21 #include <camera/ICameraRecordingProxyListener.h>
22 #include <binder/IMemory.h>
23 #include <binder/Parcel.h>
24 #include <media/hardware/HardwareAPI.h>
26 #include <utils/Log.h>
31 START_RECORDING = IBinder::FIRST_CALL_TRANSACTION,
33 RELEASE_RECORDING_FRAME,
34 RELEASE_RECORDING_FRAME_HANDLE,
38 class BpCameraRecordingProxy: public BpInterface<ICameraRecordingProxy>
41 BpCameraRecordingProxy(const sp<IBinder>& impl)
42 : BpInterface<ICameraRecordingProxy>(impl)
46 status_t startRecording(const sp<ICameraRecordingProxyListener>& listener)
48 ALOGV("startRecording");
50 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
51 data.writeStrongBinder(IInterface::asBinder(listener));
52 remote()->transact(START_RECORDING, data, &reply);
53 return reply.readInt32();
58 ALOGV("stopRecording");
60 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
61 remote()->transact(STOP_RECORDING, data, &reply);
64 void releaseRecordingFrame(const sp<IMemory>& mem)
66 ALOGV("releaseRecordingFrame");
68 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
69 data.writeStrongBinder(IInterface::asBinder(mem));
70 remote()->transact(RELEASE_RECORDING_FRAME, data, &reply);
73 void releaseRecordingFrameHandle(native_handle_t *handle) {
74 ALOGV("releaseRecordingFrameHandle");
76 data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
77 data.writeNativeHandle(handle);
79 remote()->transact(RELEASE_RECORDING_FRAME_HANDLE, data, &reply);
81 // Close the native handle because camera received a dup copy.
82 native_handle_close(handle);
83 native_handle_delete(handle);
87 IMPLEMENT_META_INTERFACE(CameraRecordingProxy, "android.hardware.ICameraRecordingProxy");
89 // ----------------------------------------------------------------------
91 status_t BnCameraRecordingProxy::onTransact(
92 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
95 case START_RECORDING: {
96 ALOGV("START_RECORDING");
97 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
98 sp<ICameraRecordingProxyListener> listener =
99 interface_cast<ICameraRecordingProxyListener>(data.readStrongBinder());
100 reply->writeInt32(startRecording(listener));
103 case STOP_RECORDING: {
104 ALOGV("STOP_RECORDING");
105 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
109 case RELEASE_RECORDING_FRAME: {
110 ALOGV("RELEASE_RECORDING_FRAME");
111 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
112 sp<IMemory> mem = interface_cast<IMemory>(data.readStrongBinder());
113 releaseRecordingFrame(mem);
116 case RELEASE_RECORDING_FRAME_HANDLE: {
117 ALOGV("RELEASE_RECORDING_FRAME_HANDLE");
118 CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
120 // releaseRecordingFrameHandle will be responsble to close the native handle.
121 releaseRecordingFrameHandle(data.readNativeHandle());
125 return BBinder::onTransact(code, data, reply, flags);
129 // ----------------------------------------------------------------------------
131 }; // namespace android