• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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>
25 #include <stdint.h>
26 #include <utils/Log.h>
27 
28 namespace android {
29 
30 enum {
31     START_RECORDING = IBinder::FIRST_CALL_TRANSACTION,
32     STOP_RECORDING,
33     RELEASE_RECORDING_FRAME,
34     RELEASE_RECORDING_FRAME_HANDLE,
35 };
36 
37 
38 class BpCameraRecordingProxy: public BpInterface<ICameraRecordingProxy>
39 {
40 public:
BpCameraRecordingProxy(const sp<IBinder> & impl)41     BpCameraRecordingProxy(const sp<IBinder>& impl)
42         : BpInterface<ICameraRecordingProxy>(impl)
43     {
44     }
45 
startRecording(const sp<ICameraRecordingProxyListener> & listener)46     status_t startRecording(const sp<ICameraRecordingProxyListener>& listener)
47     {
48         ALOGV("startRecording");
49         Parcel data, reply;
50         data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
51         data.writeStrongBinder(IInterface::asBinder(listener));
52         remote()->transact(START_RECORDING, data, &reply);
53         return reply.readInt32();
54     }
55 
stopRecording()56     void stopRecording()
57     {
58         ALOGV("stopRecording");
59         Parcel data, reply;
60         data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
61         remote()->transact(STOP_RECORDING, data, &reply);
62     }
63 
releaseRecordingFrame(const sp<IMemory> & mem)64     void releaseRecordingFrame(const sp<IMemory>& mem)
65     {
66         ALOGV("releaseRecordingFrame");
67         Parcel data, reply;
68         data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor());
69         data.writeStrongBinder(IInterface::asBinder(mem));
70         remote()->transact(RELEASE_RECORDING_FRAME, data, &reply);
71     }
72 
releaseRecordingFrameHandle(native_handle_t * handle)73     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);
84     }
85 };
86 
87 IMPLEMENT_META_INTERFACE(CameraRecordingProxy, "android.hardware.ICameraRecordingProxy");
88 
89 // ----------------------------------------------------------------------
90 
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)91 status_t BnCameraRecordingProxy::onTransact(
92     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
93 {
94     switch(code) {
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));
101             return NO_ERROR;
102         } break;
103         case STOP_RECORDING: {
104             ALOGV("STOP_RECORDING");
105             CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
106             stopRecording();
107             return NO_ERROR;
108         } break;
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);
114             return NO_ERROR;
115         } break;
116         case RELEASE_RECORDING_FRAME_HANDLE: {
117             ALOGV("RELEASE_RECORDING_FRAME_HANDLE");
118             CHECK_INTERFACE(ICameraRecordingProxy, data, reply);
119 
120             // releaseRecordingFrameHandle will be responsble to close the native handle.
121             releaseRecordingFrameHandle(data.readNativeHandle());
122             return NO_ERROR;
123         } break;
124         default:
125             return BBinder::onTransact(code, data, reply, flags);
126     }
127 }
128 
129 // ----------------------------------------------------------------------------
130 
131 }; // namespace android
132 
133