GMPSharedMemManager.h (1421B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef GMPSharedMemManager_h_ 7 #define GMPSharedMemManager_h_ 8 9 #include "mozilla/ipc/Shmem.h" 10 #include "nsTArray.h" 11 12 namespace mozilla::gmp { 13 14 class GMPVideoi420FrameImpl; 15 16 enum class GMPSharedMemClass { Decoded, Encoded }; 17 18 class GMPSharedMemManager { 19 public: 20 GMPSharedMemManager() = default; 21 22 virtual ~GMPSharedMemManager(); 23 24 bool MgrTakeShmem(GMPSharedMemClass aClass, ipc::Shmem* aMem); 25 bool MgrTakeShmem(GMPSharedMemClass aClass, size_t aSize, ipc::Shmem* aMem); 26 void MgrGiveShmem(GMPSharedMemClass aClass, ipc::Shmem&& aMem); 27 void MgrPurgeShmems(); 28 29 virtual bool MgrAllocShmem(size_t aSize, ipc::Shmem* aMem) { return false; } 30 virtual void MgrDeallocShmem(ipc::Shmem& aMem) = 0; 31 32 virtual void MgrDecodedFrameDestroyed(GMPVideoi420FrameImpl* aFrame) {} 33 34 protected: 35 virtual bool MgrIsOnOwningThread() const = 0; 36 37 static constexpr size_t kMaxPools = 2; 38 39 private: 40 void PurgeSmallerShmem(nsTArray<ipc::Shmem>& aPool, size_t aSize); 41 42 static constexpr size_t kMaxPoolLength = 16; 43 AutoTArray<ipc::Shmem, kMaxPoolLength> mPool[kMaxPools]; 44 }; 45 46 } // namespace mozilla::gmp 47 48 #endif // GMPSharedMemManager_h_