tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GMPVideoHost.cpp (2816B)


      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 #include "GMPVideoHost.h"
      7 
      8 #include "GMPSharedMemManager.h"
      9 #include "GMPVideoEncodedFrameImpl.h"
     10 #include "GMPVideoPlaneImpl.h"
     11 #include "GMPVideoi420FrameImpl.h"
     12 #include "mozilla/Assertions.h"
     13 
     14 namespace mozilla::gmp {
     15 
     16 GMPVideoHostImpl::GMPVideoHostImpl(GMPSharedMemManager* aSharedMemMgr)
     17    : mSharedMemMgr(aSharedMemMgr) {}
     18 
     19 GMPVideoHostImpl::~GMPVideoHostImpl() = default;
     20 
     21 GMPErr GMPVideoHostImpl::CreateFrame(GMPVideoFrameFormat aFormat,
     22                                     GMPVideoFrame** aFrame) {
     23  if (!mSharedMemMgr) {
     24    return GMPGenericErr;
     25  }
     26 
     27  if (!aFrame) {
     28    return GMPGenericErr;
     29  }
     30  *aFrame = nullptr;
     31 
     32  switch (aFormat) {
     33    case kGMPI420VideoFrame:
     34      *aFrame = new GMPVideoi420FrameImpl(this);
     35      return GMPNoErr;
     36    case kGMPEncodedVideoFrame:
     37      *aFrame = new GMPVideoEncodedFrameImpl(this);
     38      return GMPNoErr;
     39    default:
     40      MOZ_ASSERT_UNREACHABLE("Unknown frame format!");
     41  }
     42 
     43  return GMPGenericErr;
     44 }
     45 
     46 GMPErr GMPVideoHostImpl::CreatePlane(GMPPlane** aPlane) {
     47  if (!mSharedMemMgr) {
     48    return GMPGenericErr;
     49  }
     50 
     51  if (!aPlane) {
     52    return GMPGenericErr;
     53  }
     54  *aPlane = nullptr;
     55 
     56  auto* p = new GMPPlaneImpl();
     57 
     58  *aPlane = p;
     59 
     60  return GMPNoErr;
     61 }
     62 
     63 GMPSharedMemManager* GMPVideoHostImpl::SharedMemMgr() { return mSharedMemMgr; }
     64 
     65 // XXX This should merge with ActorDestroyed
     66 void GMPVideoHostImpl::DoneWithAPI() { ActorDestroyed(); }
     67 
     68 void GMPVideoHostImpl::ActorDestroyed() {
     69  for (uint32_t i = mEncodedFrames.Length(); i > 0; i--) {
     70    mEncodedFrames[i - 1]->DoneWithAPI();
     71    mEncodedFrames.RemoveElementAt(i - 1);
     72  }
     73  for (uint32_t i = mDecodedFrames.Length(); i > 0; i--) {
     74    mDecodedFrames[i - 1]->DoneWithAPI();
     75    mDecodedFrames.RemoveElementAt(i - 1);
     76  }
     77  mSharedMemMgr->MgrPurgeShmems();
     78  mSharedMemMgr = nullptr;
     79 }
     80 
     81 void GMPVideoHostImpl::EncodedFrameCreated(
     82    GMPVideoEncodedFrameImpl* aEncodedFrame) {
     83  mEncodedFrames.AppendElement(aEncodedFrame);
     84 }
     85 
     86 void GMPVideoHostImpl::EncodedFrameDestroyed(GMPVideoEncodedFrameImpl* aFrame) {
     87  MOZ_ALWAYS_TRUE(mEncodedFrames.RemoveElement(aFrame));
     88 }
     89 
     90 void GMPVideoHostImpl::DecodedFrameCreated(
     91    GMPVideoi420FrameImpl* aDecodedFrame) {
     92  mDecodedFrames.AppendElement(aDecodedFrame);
     93 }
     94 
     95 void GMPVideoHostImpl::DecodedFrameDestroyed(GMPVideoi420FrameImpl* aFrame) {
     96  MOZ_ALWAYS_TRUE(mDecodedFrames.RemoveElement(aFrame));
     97  if (mSharedMemMgr && aFrame->mReportPolicy == HostReportPolicy::Destroyed) {
     98    mSharedMemMgr->MgrDecodedFrameDestroyed(aFrame);
     99  }
    100 }
    101 
    102 }  // namespace mozilla::gmp