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