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" |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 19 | #include <camera/CameraUtils.h> |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 20 | #include <camera/ICameraRecordingProxy.h> |
| 21 | #include <camera/ICameraRecordingProxyListener.h> |
| 22 | #include <binder/IMemory.h> |
| 23 | #include <binder/Parcel.h> |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 24 | #include <media/hardware/HardwareAPI.h> |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 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, |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 34 | RELEASE_RECORDING_FRAME_HANDLE, |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | |
| 38 | class BpCameraRecordingProxy: public BpInterface<ICameraRecordingProxy> |
| 39 | { |
| 40 | public: |
| 41 | BpCameraRecordingProxy(const sp<IBinder>& impl) |
| 42 | : BpInterface<ICameraRecordingProxy>(impl) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | status_t startRecording(const sp<ICameraRecordingProxyListener>& listener) |
| 47 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 48 | ALOGV("startRecording"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 49 | Parcel data, reply; |
| 50 | data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 51 | data.writeStrongBinder(IInterface::asBinder(listener)); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 52 | remote()->transact(START_RECORDING, data, &reply); |
| 53 | return reply.readInt32(); |
| 54 | } |
| 55 | |
| 56 | void stopRecording() |
| 57 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 58 | ALOGV("stopRecording"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 59 | Parcel data, reply; |
| 60 | data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor()); |
| 61 | remote()->transact(STOP_RECORDING, data, &reply); |
| 62 | } |
| 63 | |
| 64 | void releaseRecordingFrame(const sp<IMemory>& mem) |
| 65 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 66 | ALOGV("releaseRecordingFrame"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 67 | Parcel data, reply; |
| 68 | data.writeInterfaceToken(ICameraRecordingProxy::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 69 | data.writeStrongBinder(IInterface::asBinder(mem)); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 70 | remote()->transact(RELEASE_RECORDING_FRAME, data, &reply); |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 71 | } |
Praveen Chavan | 6773d47 | 2016-01-13 01:24:30 -0800 | [diff] [blame] | 72 | |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 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); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 84 | } |
| 85 | }; |
| 86 | |
| 87 | IMPLEMENT_META_INTERFACE(CameraRecordingProxy, "android.hardware.ICameraRecordingProxy"); |
| 88 | |
| 89 | // ---------------------------------------------------------------------- |
| 90 | |
| 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: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 96 | ALOGV("START_RECORDING"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 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: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 104 | ALOGV("STOP_RECORDING"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 105 | CHECK_INTERFACE(ICameraRecordingProxy, data, reply); |
| 106 | stopRecording(); |
| 107 | return NO_ERROR; |
| 108 | } break; |
| 109 | case RELEASE_RECORDING_FRAME: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 110 | ALOGV("RELEASE_RECORDING_FRAME"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 111 | CHECK_INTERFACE(ICameraRecordingProxy, data, reply); |
| 112 | sp<IMemory> mem = interface_cast<IMemory>(data.readStrongBinder()); |
| 113 | releaseRecordingFrame(mem); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 114 | return NO_ERROR; |
| 115 | } break; |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 116 | case RELEASE_RECORDING_FRAME_HANDLE: { |
| 117 | ALOGV("RELEASE_RECORDING_FRAME_HANDLE"); |
| 118 | CHECK_INTERFACE(ICameraRecordingProxy, data, reply); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 119 | |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 120 | // releaseRecordingFrameHandle will be responsble to close the native handle. |
| 121 | releaseRecordingFrameHandle(data.readNativeHandle()); |
| 122 | return NO_ERROR; |
| 123 | } break; |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 124 | default: |
| 125 | return BBinder::onTransact(code, data, reply, flags); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // ---------------------------------------------------------------------------- |
| 130 | |
| 131 | }; // namespace android |
| 132 | |