2014-05-18 07:05:46 +04:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#include "GMPVideoHost.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "GMPVideoi420FrameImpl.h"
|
|
|
|
#include "GMPVideoEncodedFrameImpl.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gmp {
|
|
|
|
|
|
|
|
GMPVideoHostImpl::GMPVideoHostImpl(GMPSharedMemManager* aSharedMemMgr)
|
|
|
|
: mSharedMemMgr(aSharedMemMgr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GMPVideoHostImpl::~GMPVideoHostImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
GMPErr
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPVideoHostImpl::CreateFrame(GMPVideoFrameFormat aFormat, GMPVideoFrame** aFrame)
|
|
|
|
{
|
|
|
|
if (!mSharedMemMgr) {
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPGenericErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!aFrame) {
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPGenericErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
*aFrame = nullptr;
|
|
|
|
|
|
|
|
switch (aFormat) {
|
|
|
|
case kGMPI420VideoFrame:
|
|
|
|
*aFrame = new GMPVideoi420FrameImpl(this);
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPNoErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
case kGMPEncodedVideoFrame:
|
|
|
|
*aFrame = new GMPVideoEncodedFrameImpl(this);
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPNoErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown frame format!");
|
|
|
|
}
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPGenericErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
GMPErr
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPVideoHostImpl::CreatePlane(GMPPlane** aPlane)
|
|
|
|
{
|
|
|
|
if (!mSharedMemMgr) {
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPGenericErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!aPlane) {
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPGenericErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
*aPlane = nullptr;
|
|
|
|
|
|
|
|
auto p = new GMPPlaneImpl(this);
|
|
|
|
|
|
|
|
*aPlane = p;
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPNoErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
GMPSharedMemManager*
|
|
|
|
GMPVideoHostImpl::SharedMemMgr()
|
|
|
|
{
|
|
|
|
return mSharedMemMgr;
|
|
|
|
}
|
|
|
|
|
2015-11-13 09:08:01 +03:00
|
|
|
// XXX This should merge with ActorDestroyed
|
2014-05-18 07:05:46 +04:00
|
|
|
void
|
|
|
|
GMPVideoHostImpl::DoneWithAPI()
|
|
|
|
{
|
2015-11-13 09:08:01 +03:00
|
|
|
ActorDestroyed();
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoHostImpl::ActorDestroyed()
|
|
|
|
{
|
|
|
|
for (uint32_t i = mPlanes.Length(); i > 0; i--) {
|
2015-11-13 09:08:01 +03:00
|
|
|
mPlanes[i - 1]->DoneWithAPI();
|
2014-05-18 07:05:46 +04:00
|
|
|
mPlanes.RemoveElementAt(i - 1);
|
|
|
|
}
|
|
|
|
for (uint32_t i = mEncodedFrames.Length(); i > 0; i--) {
|
2015-11-13 09:08:01 +03:00
|
|
|
mEncodedFrames[i - 1]->DoneWithAPI();
|
2014-05-18 07:05:46 +04:00
|
|
|
mEncodedFrames.RemoveElementAt(i - 1);
|
|
|
|
}
|
2014-06-30 03:02:39 +04:00
|
|
|
mSharedMemMgr = nullptr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoHostImpl::PlaneCreated(GMPPlaneImpl* aPlane)
|
|
|
|
{
|
|
|
|
mPlanes.AppendElement(aPlane);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoHostImpl::PlaneDestroyed(GMPPlaneImpl* aPlane)
|
|
|
|
{
|
|
|
|
MOZ_ALWAYS_TRUE(mPlanes.RemoveElement(aPlane));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoHostImpl::EncodedFrameCreated(GMPVideoEncodedFrameImpl* aEncodedFrame)
|
|
|
|
{
|
|
|
|
mEncodedFrames.AppendElement(aEncodedFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoHostImpl::EncodedFrameDestroyed(GMPVideoEncodedFrameImpl* aFrame)
|
|
|
|
{
|
|
|
|
MOZ_ALWAYS_TRUE(mEncodedFrames.RemoveElement(aFrame));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace gmp
|
|
|
|
} // namespace mozilla
|