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 | |
Eino-Ville Talvala | 7a3de84 | 2016-06-20 17:00:14 -0700 | [diff] [blame] | 34 | uint8_t ICameraRecordingProxy::baseObject = 0; |
| 35 | |
| 36 | size_t ICameraRecordingProxy::getCommonBaseAddress() { |
| 37 | return (size_t)&baseObject; |
| 38 | } |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 39 | |
| 40 | class BpCameraRecordingProxy: public BpInterface<ICameraRecordingProxy> |
| 41 | { |
| 42 | public: |
| 43 | BpCameraRecordingProxy(const sp<IBinder>& impl) |
| 44 | : BpInterface<ICameraRecordingProxy>(impl) |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | status_t startRecording(const sp<ICameraRecordingProxyListener>& listener) |
| 49 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 50 | ALOGV("startRecording"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 51 | Parcel data, reply; |
| 52 | data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor()); |
| 53 | data.writeStrongBinder(listener->asBinder()); |
| 54 | remote()->transact(START_RECORDING, data, &reply); |
| 55 | return reply.readInt32(); |
| 56 | } |
| 57 | |
| 58 | void stopRecording() |
| 59 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 60 | ALOGV("stopRecording"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 61 | Parcel data, reply; |
| 62 | data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor()); |
| 63 | remote()->transact(STOP_RECORDING, data, &reply); |
| 64 | } |
| 65 | |
| 66 | void releaseRecordingFrame(const sp<IMemory>& mem) |
| 67 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 68 | ALOGV("releaseRecordingFrame"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 69 | Parcel data, reply; |
| 70 | data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor()); |
| 71 | data.writeStrongBinder(mem->asBinder()); |
| 72 | remote()->transact(RELEASE_RECORDING_FRAME, data, &reply); |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | IMPLEMENT_META_INTERFACE(CameraRecordingProxy, "android.hardware.ICameraRecordingProxy"); |
| 77 | |
| 78 | // ---------------------------------------------------------------------- |
| 79 | |
| 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: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 85 | ALOGV("START_RECORDING"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 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: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 93 | ALOGV("STOP_RECORDING"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 94 | CHECK_INTERFACE(ICameraRecordingProxy, data, reply); |
| 95 | stopRecording(); |
| 96 | return NO_ERROR; |
| 97 | } break; |
| 98 | case RELEASE_RECORDING_FRAME: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 99 | ALOGV("RELEASE_RECORDING_FRAME"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 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 |