diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/media/gmp/GMPSharedMemManager.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/gmp/GMPSharedMemManager.h')
-rw-r--r-- | dom/media/gmp/GMPSharedMemManager.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/dom/media/gmp/GMPSharedMemManager.h b/dom/media/gmp/GMPSharedMemManager.h new file mode 100644 index 0000000000..1a04bdde14 --- /dev/null +++ b/dom/media/gmp/GMPSharedMemManager.h @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef GMPSharedMemManager_h_ +#define GMPSharedMemManager_h_ + +#include "mozilla/ipc/Shmem.h" +#include "nsTArray.h" + +namespace mozilla::gmp { + +class GMPSharedMemManager; + +class GMPSharedMem { + public: + typedef enum { + kGMPFrameData = 0, + kGMPEncodedData, + kGMPNumTypes + } GMPMemoryClasses; + + // This is a heuristic - max of 10 free in the Child pool, plus those + // in-use for the encoder and decoder at the given moment and not yet + // returned to the parent pool (which is not included). If more than + // this are needed, we presume the client has either crashed or hung + // (perhaps temporarily). + static const uint32_t kGMPBufLimit = 40; + + GMPSharedMem() { + for (size_t i = 0; i < sizeof(mGmpAllocated) / sizeof(mGmpAllocated[0]); + i++) { + mGmpAllocated[i] = 0; + } + } + virtual ~GMPSharedMem() = default; + + // Parent and child impls will differ here + virtual void CheckThread() = 0; + + protected: + friend class GMPSharedMemManager; + + nsTArray<ipc::Shmem> mGmpFreelist[GMPSharedMem::kGMPNumTypes]; + uint32_t mGmpAllocated[GMPSharedMem::kGMPNumTypes]; +}; + +class GMPSharedMemManager { + public: + explicit GMPSharedMemManager(GMPSharedMem* aData) : mData(aData) {} + virtual ~GMPSharedMemManager() = default; + + virtual bool MgrAllocShmem(GMPSharedMem::GMPMemoryClasses aClass, + size_t aSize, ipc::Shmem* aMem); + virtual bool MgrDeallocShmem(GMPSharedMem::GMPMemoryClasses aClass, + ipc::Shmem& aMem); + + // So we can know if data is "piling up" for the plugin - I.e. it's hung or + // crashed + virtual uint32_t NumInUse(GMPSharedMem::GMPMemoryClasses aClass); + + // These have to be implemented using the AllocShmem/etc provided by the + // IPDL-generated interfaces, so have the Parent/Child implement them. + virtual bool Alloc(size_t aSize, ipc::Shmem* aMem) = 0; + virtual void Dealloc(ipc::Shmem&& aMem) = 0; + + private: + nsTArray<ipc::Shmem>& GetGmpFreelist(GMPSharedMem::GMPMemoryClasses aTypes) { + return mData->mGmpFreelist[aTypes]; + } + + GMPSharedMem* mData; +}; + +} // namespace mozilla::gmp + +#endif // GMPSharedMemManager_h_ |