Sungtak Lee | 64c9d93 | 2024-03-26 03:46:53 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2024, 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 | //#define LOG_NDEBUG 0 |
| 17 | #define LOG_TAG "C2AidlNode" |
| 18 | #include <log/log.h> |
| 19 | #include <private/android/AHardwareBufferHelpers.h> |
| 20 | |
| 21 | #include <media/stagefright/MediaErrors.h> |
| 22 | #include <media/stagefright/aidlpersistentsurface/wrapper/Conversion.h> |
| 23 | |
| 24 | #include "C2NodeImpl.h" |
| 25 | #include "C2AidlNode.h" |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | using ::aidl::android::media::IAidlBufferSource; |
| 30 | using ::aidl::android::media::IAidlNode; |
| 31 | |
| 32 | using ::android::media::CommandStateSet; |
| 33 | using ::android::media::NodeStatusLoaded; |
| 34 | |
| 35 | // Conversion |
| 36 | using ::android::media::aidl_conversion::toAidlStatus; |
| 37 | |
| 38 | C2AidlNode::C2AidlNode(const std::shared_ptr<Codec2Client::Component> &comp) |
| 39 | : mImpl(new C2NodeImpl(comp, true)) {} |
| 40 | |
| 41 | // aidl ndk interfaces |
| 42 | ::ndk::ScopedAStatus C2AidlNode::freeNode() { |
| 43 | return toAidlStatus(mImpl->freeNode()); |
| 44 | } |
| 45 | |
| 46 | ::ndk::ScopedAStatus C2AidlNode::sendCommand(int32_t cmd, int32_t param) { |
| 47 | if (cmd == CommandStateSet && param == NodeStatusLoaded) { |
| 48 | mImpl->onFirstInputFrame(); |
| 49 | } |
| 50 | return toAidlStatus(ERROR_UNSUPPORTED); |
| 51 | } |
| 52 | |
| 53 | ::ndk::ScopedAStatus C2AidlNode::getConsumerUsage(int64_t* _aidl_return) { |
| 54 | uint64_t usage; |
| 55 | mImpl->getConsumerUsageBits(&usage); |
| 56 | *_aidl_return = usage; |
| 57 | return ::ndk::ScopedAStatus::ok(); |
| 58 | } |
| 59 | |
| 60 | ::ndk::ScopedAStatus C2AidlNode::getInputBufferParams(IAidlNode::InputBufferParams* _aidl_return) { |
| 61 | mImpl->getInputBufferParams(_aidl_return); |
| 62 | return ::ndk::ScopedAStatus::ok(); |
| 63 | } |
| 64 | |
| 65 | ::ndk::ScopedAStatus C2AidlNode::setConsumerUsage(int64_t usage) { |
| 66 | mImpl->setConsumerUsageBits(static_cast<uint64_t>(usage)); |
| 67 | return ::ndk::ScopedAStatus::ok(); |
| 68 | } |
| 69 | |
| 70 | ::ndk::ScopedAStatus C2AidlNode::setAdjustTimestampGapUs(int32_t gapUs) { |
| 71 | mImpl->setAdjustTimestampGapUs(gapUs); |
| 72 | return ::ndk::ScopedAStatus::ok(); |
| 73 | } |
| 74 | |
| 75 | ::ndk::ScopedAStatus C2AidlNode::setInputSurface( |
| 76 | const std::shared_ptr<IAidlBufferSource>& bufferSource) { |
| 77 | return toAidlStatus(mImpl->setAidlInputSurface(bufferSource)); |
| 78 | } |
| 79 | |
| 80 | ::ndk::ScopedAStatus C2AidlNode::submitBuffer( |
| 81 | int32_t buffer, const ::aidl::android::hardware::HardwareBuffer& hBuffer, |
| 82 | int32_t flags, int64_t timestamp, const ::ndk::ScopedFileDescriptor& fence) { |
| 83 | sp<GraphicBuffer> gBuf; |
| 84 | AHardwareBuffer *ahwb = hBuffer.get(); |
| 85 | if (ahwb) { |
| 86 | gBuf = AHardwareBuffer_to_GraphicBuffer(ahwb); |
| 87 | } |
| 88 | return toAidlStatus(mImpl->submitBuffer( |
| 89 | buffer, gBuf, flags, timestamp, ::dup(fence.get()))); |
| 90 | } |
| 91 | |
| 92 | ::ndk::ScopedAStatus C2AidlNode::onDataSpaceChanged( |
| 93 | int32_t dataSpace, |
| 94 | int32_t aspects, |
| 95 | int32_t pixelFormat) { |
| 96 | // NOTE: legacy codes passed aspects, but they didn't used. |
| 97 | (void)aspects; |
| 98 | |
| 99 | return toAidlStatus(mImpl->onDataspaceChanged( |
| 100 | static_cast<uint32_t>(dataSpace), |
| 101 | static_cast<uint32_t>(pixelFormat))); |
| 102 | } |
| 103 | |
| 104 | // cpp interface |
| 105 | |
| 106 | std::shared_ptr<IAidlBufferSource> C2AidlNode::getSource() { |
| 107 | return mImpl->getAidlSource(); |
| 108 | } |
| 109 | |
| 110 | void C2AidlNode::setFrameSize(uint32_t width, uint32_t height) { |
| 111 | return mImpl->setFrameSize(width, height); |
| 112 | } |
| 113 | |
| 114 | void C2AidlNode::onInputBufferDone(c2_cntr64_t index) { |
| 115 | return mImpl->onInputBufferDone(index); |
| 116 | } |
| 117 | |
| 118 | android_dataspace C2AidlNode::getDataspace() { |
| 119 | return mImpl->getDataspace(); |
| 120 | } |
| 121 | |
| 122 | uint32_t C2AidlNode::getPixelFormat() { |
| 123 | return mImpl->getPixelFormat(); |
| 124 | } |
| 125 | |
| 126 | void C2AidlNode::setPriority(int priority) { |
| 127 | return mImpl->setPriority(priority); |
| 128 | } |
| 129 | |
| 130 | } // namespace android |