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