Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 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 | |
| 35 | class BpCameraRecordingProxy: public BpInterface<ICameraRecordingProxy> |
| 36 | { |
| 37 | public: |
| 38 | BpCameraRecordingProxy(const sp<IBinder>& impl) |
| 39 | : BpInterface<ICameraRecordingProxy>(impl) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | status_t startRecording(const sp<ICameraRecordingProxyListener>& listener) |
| 44 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 45 | ALOGV("startRecording"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 46 | Parcel data, reply; |
| 47 | data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 48 | data.writeStrongBinder(IInterface::asBinder(listener)); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 49 | remote()->transact(START_RECORDING, data, &reply); |
| 50 | return reply.readInt32(); |
| 51 | } |
| 52 | |
| 53 | void stopRecording() |
| 54 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 55 | ALOGV("stopRecording"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 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 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 63 | ALOGV("releaseRecordingFrame"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 64 | Parcel data, reply; |
| 65 | data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 66 | data.writeStrongBinder(IInterface::asBinder(mem)); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 67 | remote()->transact(RELEASE_RECORDING_FRAME, data, &reply); |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | IMPLEMENT_META_INTERFACE(CameraRecordingProxy, "android.hardware.ICameraRecordingProxy"); |
| 72 | |
| 73 | // ---------------------------------------------------------------------- |
| 74 | |
| 75 | status_t BnCameraRecordingProxy::onTransact( |
| 76 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 77 | { |
| 78 | switch(code) { |
| 79 | case START_RECORDING: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 80 | ALOGV("START_RECORDING"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 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: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 88 | ALOGV("STOP_RECORDING"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 89 | CHECK_INTERFACE(ICameraRecordingProxy, data, reply); |
| 90 | stopRecording(); |
| 91 | return NO_ERROR; |
| 92 | } break; |
| 93 | case RELEASE_RECORDING_FRAME: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 94 | ALOGV("RELEASE_RECORDING_FRAME"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 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 | |