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 17 #pragma once 18 19 #include <aidl/android/media/BnAidlNode.h> 20 #include <codec2/hidl/client.h> 21 22 namespace android { 23 24 struct C2NodeImpl; 25 26 /** 27 * Thin Codec2 AIdL encoder HAL wrapper for InputSurface 28 */ 29 class C2AidlNode : public ::aidl::android::media::BnAidlNode { 30 public: 31 explicit C2AidlNode(const std::shared_ptr<Codec2Client::Component> &comp); 32 ~C2AidlNode() override = default; 33 34 // IAidlNode 35 ::ndk::ScopedAStatus freeNode() override; 36 37 ::ndk::ScopedAStatus getConsumerUsage(int64_t *_aidl_return) override; 38 39 ::ndk::ScopedAStatus getInputBufferParams( 40 ::aidl::android::media::IAidlNode::InputBufferParams *_aidl_return) override; 41 42 ::ndk::ScopedAStatus setConsumerUsage(int64_t usage) override; 43 44 ::ndk::ScopedAStatus setAdjustTimestampGapUs(int32_t gapUs) override; 45 46 ::ndk::ScopedAStatus setInputSurface( 47 const std::shared_ptr<::aidl::android::media::IAidlBufferSource>& 48 bufferSource) override; 49 50 ::ndk::ScopedAStatus submitBuffer( 51 int32_t buffer, 52 const std::optional<::aidl::android::hardware::HardwareBuffer>& hBuffer, 53 int32_t flags, 54 int64_t timestampUs, 55 const ::ndk::ScopedFileDescriptor& fence) override; 56 57 ::ndk::ScopedAStatus onDataSpaceChanged( 58 int dataSpace, int aspects, int pixelFormat) override; 59 60 /** 61 * Returns underlying IAidlBufferSource object. 62 */ 63 std::shared_ptr<::aidl::android::media::IAidlBufferSource> getSource(); 64 65 /** 66 * Configure the frame size. 67 */ 68 void setFrameSize(uint32_t width, uint32_t height); 69 70 /** 71 * Notify that the input buffer reference is no longer needed by the component. 72 * Clean up if necessary. 73 * 74 * \param index input work index 75 */ 76 void onInputBufferDone(c2_cntr64_t index); 77 78 /** 79 * Notify input buffer is emptied. 80 */ 81 void onInputBufferEmptied(); 82 83 /** 84 * Returns dataspace information from GraphicBufferSource. 85 */ 86 android_dataspace getDataspace(); 87 88 /** 89 * Returns dataspace information from GraphicBufferSource. 90 */ 91 uint32_t getPixelFormat(); 92 93 /** 94 * Sets priority of the queue thread. 95 */ 96 void setPriority(int priority); 97 98 private: 99 std::shared_ptr<C2NodeImpl> mImpl; 100 }; 101 102 } // namespace android 103 104