LCOV - code coverage report
Current view: top level - dom/media/gmp - GMPSharedMemManager.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 10 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 {
      13             : namespace gmp {
      14             : 
      15             : class GMPSharedMemManager;
      16             : 
      17             : class GMPSharedMem
      18             : {
      19             : public:
      20             :   typedef enum {
      21             :     kGMPFrameData = 0,
      22             :     kGMPEncodedData,
      23             :     kGMPNumTypes
      24             :   } GMPMemoryClasses;
      25             : 
      26             :   // This is a heuristic - max of 10 free in the Child pool, plus those
      27             :   // in-use for the encoder and decoder at the given moment and not yet
      28             :   // returned to the parent pool (which is not included).  If more than
      29             :   // this are needed, we presume the client has either crashed or hung
      30             :   // (perhaps temporarily).
      31             :   static const uint32_t kGMPBufLimit = 20;
      32             : 
      33           0 :   GMPSharedMem()
      34           0 :   {
      35           0 :     for (size_t i = 0; i < sizeof(mGmpAllocated)/sizeof(mGmpAllocated[0]); i++) {
      36           0 :       mGmpAllocated[i] = 0;
      37             :     }
      38           0 :   }
      39           0 :   virtual ~GMPSharedMem() {}
      40             : 
      41             :   // Parent and child impls will differ here
      42             :   virtual void CheckThread() = 0;
      43             : 
      44             : protected:
      45             :   friend class GMPSharedMemManager;
      46             : 
      47             :   nsTArray<ipc::Shmem> mGmpFreelist[GMPSharedMem::kGMPNumTypes];
      48             :   uint32_t mGmpAllocated[GMPSharedMem::kGMPNumTypes];
      49             : };
      50             : 
      51             : class GMPSharedMemManager
      52             : {
      53             : public:
      54           0 :   explicit GMPSharedMemManager(GMPSharedMem *aData) : mData(aData) {}
      55           0 :   virtual ~GMPSharedMemManager() {}
      56             : 
      57             :   virtual bool MgrAllocShmem(GMPSharedMem::GMPMemoryClasses aClass, size_t aSize,
      58             :                              ipc::Shmem::SharedMemory::SharedMemoryType aType,
      59             :                              ipc::Shmem* aMem);
      60             :   virtual bool MgrDeallocShmem(GMPSharedMem::GMPMemoryClasses aClass, ipc::Shmem& aMem);
      61             : 
      62             :   // So we can know if data is "piling up" for the plugin - I.e. it's hung or crashed
      63             :   virtual uint32_t NumInUse(GMPSharedMem::GMPMemoryClasses aClass);
      64             : 
      65             :   // These have to be implemented using the AllocShmem/etc provided by the IPDL-generated interfaces,
      66             :   // so have the Parent/Child implement them.
      67             :   virtual bool Alloc(size_t aSize, ipc::Shmem::SharedMemory::SharedMemoryType aType, ipc::Shmem* aMem) = 0;
      68             :   virtual void Dealloc(ipc::Shmem& aMem) = 0;
      69             : 
      70             : private:
      71           0 :   nsTArray<ipc::Shmem>& GetGmpFreelist(GMPSharedMem::GMPMemoryClasses aTypes)
      72             :   {
      73           0 :     return mData->mGmpFreelist[aTypes];
      74             :   }
      75             : 
      76             :   GMPSharedMem *mData;
      77             : };
      78             : 
      79             : } // namespace gmp
      80             : } // namespace mozilla
      81             : 
      82             : #endif // GMPSharedMemManager_h_

Generated by: LCOV version 1.13