1 /* 2 * Copyright 2018 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 #ifndef CODEC2_AIDL_UTILS_COMPONENT_H 18 #define CODEC2_AIDL_UTILS_COMPONENT_H 19 20 #include <codec2/aidl/ComponentInterface.h> 21 #include <codec2/aidl/Configurable.h> 22 #include <codec2/aidl/BufferTypes.h> 23 #include <codec2/aidl/ParamTypes.h> 24 25 #include <aidl/android/hardware/media/bufferpool2/IClientManager.h> 26 #include <aidl/android/hardware/media/c2/BnComponent.h> 27 #include <aidl/android/hardware/media/c2/IComponentInterface.h> 28 #include <aidl/android/hardware/media/c2/IComponentListener.h> 29 #include <aidl/android/hardware/media/c2/IComponentStore.h> 30 #include <aidl/android/hardware/media/c2/IInputSink.h> 31 #include <aidl/android/hardware/media/c2/IInputSurface.h> 32 #include <aidl/android/hardware/media/c2/IInputSurfaceConnection.h> 33 34 #include <codec2/common/MultiAccessUnitHelper.h> 35 36 #include <C2Component.h> 37 #include <C2Buffer.h> 38 #include <C2.h> 39 40 #include <map> 41 #include <memory> 42 #include <mutex> 43 44 namespace aidl { 45 namespace android { 46 namespace hardware { 47 namespace media { 48 namespace c2 { 49 namespace utils { 50 51 using ::android::MultiAccessUnitInterface; 52 using ::android::MultiAccessUnitHelper; 53 54 struct ComponentStore; 55 56 struct Component : public BnComponent { 57 Component( 58 const std::shared_ptr<C2Component>&, 59 const std::shared_ptr<IComponentListener>& listener, 60 const std::shared_ptr<ComponentStore>& store, 61 const std::shared_ptr<bufferpool2::IClientManager>& clientPoolManager); 62 c2_status_t status() const; 63 64 // Methods from IComponent follow. 65 ::ndk::ScopedAStatus queue(const WorkBundle& workBundle) override; 66 ::ndk::ScopedAStatus flush(WorkBundle *workBundle) override; 67 ::ndk::ScopedAStatus drain(bool withEos) override; 68 ::ndk::ScopedAStatus createBlockPool( 69 const IComponent::BlockPoolAllocator &allocator, 70 IComponent::BlockPool *blockPool) override; 71 ::ndk::ScopedAStatus destroyBlockPool(int64_t blockPoolId) override; 72 ::ndk::ScopedAStatus start() override; 73 ::ndk::ScopedAStatus stop() override; 74 ::ndk::ScopedAStatus reset() override; 75 ::ndk::ScopedAStatus release() override; 76 ::ndk::ScopedAStatus getInterface( 77 std::shared_ptr<IComponentInterface> *intf) override; 78 ::ndk::ScopedAStatus configureVideoTunnel( 79 int32_t avSyncHwId, 80 common::NativeHandle* handle) override; 81 ::ndk::ScopedAStatus connectToInputSurface( 82 const std::shared_ptr<IInputSurface>& inputSurface, 83 std::shared_ptr<IInputSurfaceConnection> *connection) override; 84 ::ndk::ScopedAStatus asInputSink( 85 std::shared_ptr<IInputSink> *sink) override; 86 87 protected: 88 c2_status_t mInit; 89 std::shared_ptr<C2Component> mComponent; 90 std::shared_ptr<ComponentInterface> mInterface; 91 std::shared_ptr<IComponentListener> mListener; 92 std::shared_ptr<MultiAccessUnitInterface> mMultiAccessUnitIntf; 93 std::shared_ptr<MultiAccessUnitHelper> mMultiAccessUnitHelper; 94 std::shared_ptr<ComponentStore> mStore; 95 DefaultBufferPoolSender mBufferPoolSender; 96 97 std::mutex mBlockPoolsMutex; 98 // This map keeps C2BlockPool objects that are created by createBlockPool() 99 // alive. These C2BlockPool objects can be deleted by calling 100 // destroyBlockPool(), reset() or release(), or by destroying the component. 101 std::map<uint64_t, std::shared_ptr<C2BlockPool>> mBlockPools; 102 103 void initListener(const std::shared_ptr<Component>& self); 104 105 virtual ~Component() override; 106 107 friend struct ComponentStore; 108 109 struct Listener; 110 111 friend struct MultiAccessUnitListener; 112 113 ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient; 114 static void OnBinderDied(void *cookie); 115 static void OnBinderUnlinked(void *cookie); 116 struct DeathContext; 117 DeathContext *mDeathContext; 118 }; 119 120 } // namespace utils 121 } // namespace c2 122 } // namespace media 123 } // namespace hardware 124 } // namespace android 125 } // namespace aidl 126 127 #endif // CODEC2_AIDL_UTILS_COMPONENT_H 128