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 "GMPVideoDecoderChild.h"
|
|
|
|
#include "GMPVideoi420FrameImpl.h"
|
2015-02-10 13:48:42 +03:00
|
|
|
#include "GMPContentChild.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
#include <stdio.h>
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
#include "GMPVideoEncodedFrameImpl.h"
|
2015-05-08 04:36:34 +03:00
|
|
|
#include "runnable_utils.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gmp {
|
|
|
|
|
2015-02-10 13:48:42 +03:00
|
|
|
GMPVideoDecoderChild::GMPVideoDecoderChild(GMPContentChild* aPlugin)
|
2015-05-08 04:36:34 +03:00
|
|
|
: GMPSharedMemManager(aPlugin)
|
|
|
|
, mPlugin(aPlugin)
|
|
|
|
, mVideoDecoder(nullptr)
|
|
|
|
, mVideoHost(this)
|
|
|
|
, mNeedShmemIntrCount(0)
|
|
|
|
, mPendingDecodeComplete(false)
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPlugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
GMPVideoDecoderChild::~GMPVideoDecoderChild()
|
|
|
|
{
|
2015-05-08 04:36:34 +03:00
|
|
|
MOZ_ASSERT(!mNeedShmemIntrCount);
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoDecoderChild::Init(GMPVideoDecoder* aDecoder)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDecoder, "Cannot initialize video decoder child without a video decoder!");
|
|
|
|
mVideoDecoder = aDecoder;
|
|
|
|
}
|
|
|
|
|
|
|
|
GMPVideoHostImpl&
|
|
|
|
GMPVideoDecoderChild::Host()
|
|
|
|
{
|
|
|
|
return mVideoHost;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoDecoderChild::Decoded(GMPVideoi420Frame* aDecodedFrame)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
|
|
|
|
|
|
|
|
if (!aDecodedFrame) {
|
|
|
|
MOZ_CRASH("Not given a decoded frame!");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto df = static_cast<GMPVideoi420FrameImpl*>(aDecodedFrame);
|
|
|
|
|
|
|
|
GMPVideoi420FrameData frameData;
|
|
|
|
df->InitFrameData(frameData);
|
|
|
|
SendDecoded(frameData);
|
|
|
|
|
|
|
|
aDecodedFrame->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoDecoderChild::ReceivedDecodedReferenceFrame(const uint64_t aPictureId)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
|
|
|
|
|
|
|
|
SendReceivedDecodedReferenceFrame(aPictureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoDecoderChild::ReceivedDecodedFrame(const uint64_t aPictureId)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
|
|
|
|
|
|
|
|
SendReceivedDecodedFrame(aPictureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoDecoderChild::InputDataExhausted()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
|
|
|
|
|
|
|
|
SendInputDataExhausted();
|
|
|
|
}
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
void
|
|
|
|
GMPVideoDecoderChild::DrainComplete()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
|
|
|
|
|
|
|
|
SendDrainComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoDecoderChild::ResetComplete()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
|
|
|
|
|
|
|
|
SendResetComplete();
|
|
|
|
}
|
|
|
|
|
2014-07-24 01:35:01 +04:00
|
|
|
void
|
|
|
|
GMPVideoDecoderChild::Error(GMPErr aError)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
|
|
|
|
|
|
|
|
SendError(aError);
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPVideoDecoderChild::RecvInitDecode(const GMPVideoCodec& aCodecSettings,
|
2015-01-16 22:58:52 +03:00
|
|
|
InfallibleTArray<uint8_t>&& aCodecSpecific,
|
2014-05-18 07:05:46 +04:00
|
|
|
const int32_t& aCoreCount)
|
|
|
|
{
|
|
|
|
if (!mVideoDecoder) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore any return code. It is OK for this to fail without killing the process.
|
2014-07-11 07:35:56 +04:00
|
|
|
mVideoDecoder->InitDecode(aCodecSettings,
|
|
|
|
aCodecSpecific.Elements(),
|
|
|
|
aCodecSpecific.Length(),
|
|
|
|
this,
|
|
|
|
aCoreCount);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPVideoDecoderChild::RecvDecode(const GMPVideoEncodedFrameData& aInputFrame,
|
|
|
|
const bool& aMissingFrames,
|
2015-01-16 22:58:52 +03:00
|
|
|
InfallibleTArray<uint8_t>&& aCodecSpecificInfo,
|
2014-05-18 07:05:46 +04:00
|
|
|
const int64_t& aRenderTimeMs)
|
|
|
|
{
|
|
|
|
if (!mVideoDecoder) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
auto f = new GMPVideoEncodedFrameImpl(aInputFrame, &mVideoHost);
|
|
|
|
|
|
|
|
// Ignore any return code. It is OK for this to fail without killing the process.
|
2014-07-11 07:36:21 +04:00
|
|
|
mVideoDecoder->Decode(f,
|
|
|
|
aMissingFrames,
|
|
|
|
aCodecSpecificInfo.Elements(),
|
|
|
|
aCodecSpecificInfo.Length(),
|
|
|
|
aRenderTimeMs);
|
2014-07-02 06:26:35 +04:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-07-02 06:26:35 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2015-01-16 22:58:52 +03:00
|
|
|
GMPVideoDecoderChild::RecvChildShmemForPool(Shmem&& aFrameBuffer)
|
2014-07-02 06:26:35 +04:00
|
|
|
{
|
|
|
|
if (aFrameBuffer.IsWritable()) {
|
2014-07-28 19:44:20 +04:00
|
|
|
mVideoHost.SharedMemMgr()->MgrDeallocShmem(GMPSharedMem::kGMPFrameData,
|
2014-07-02 06:26:35 +04:00
|
|
|
aFrameBuffer);
|
|
|
|
}
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPVideoDecoderChild::RecvReset()
|
|
|
|
{
|
|
|
|
if (!mVideoDecoder) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore any return code. It is OK for this to fail without killing the process.
|
|
|
|
mVideoDecoder->Reset();
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPVideoDecoderChild::RecvDrain()
|
|
|
|
{
|
|
|
|
if (!mVideoDecoder) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore any return code. It is OK for this to fail without killing the process.
|
|
|
|
mVideoDecoder->Drain();
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPVideoDecoderChild::RecvDecodingComplete()
|
|
|
|
{
|
2015-05-08 04:36:34 +03:00
|
|
|
MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
|
|
|
|
|
|
|
|
if (mNeedShmemIntrCount) {
|
|
|
|
// There's a GMP blocked in Alloc() waiting for the CallNeedShem() to
|
|
|
|
// return a frame they can use. Don't call the GMP's DecodingComplete()
|
|
|
|
// now and don't delete the GMPVideoDecoderChild, defer processing the
|
|
|
|
// DecodingComplete() until once the Alloc() finishes.
|
|
|
|
mPendingDecodeComplete = true;
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-05-08 04:36:34 +03:00
|
|
|
}
|
2014-05-18 07:05:46 +04:00
|
|
|
if (mVideoDecoder) {
|
|
|
|
// Ignore any return code. It is OK for this to fail without killing the process.
|
|
|
|
mVideoDecoder->DecodingComplete();
|
|
|
|
mVideoDecoder = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mVideoHost.DoneWithAPI();
|
|
|
|
|
|
|
|
mPlugin = nullptr;
|
|
|
|
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << Send__delete__(this);
|
2014-05-18 07:05:46 +04:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
2015-05-08 04:36:34 +03:00
|
|
|
bool
|
|
|
|
GMPVideoDecoderChild::Alloc(size_t aSize,
|
|
|
|
Shmem::SharedMemory::SharedMemoryType aType,
|
|
|
|
Shmem* aMem)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
|
|
|
|
|
|
|
|
bool rv;
|
|
|
|
#ifndef SHMEM_ALLOC_IN_CHILD
|
|
|
|
++mNeedShmemIntrCount;
|
|
|
|
rv = CallNeedShmem(aSize, aMem);
|
|
|
|
--mNeedShmemIntrCount;
|
2016-07-11 12:52:31 +03:00
|
|
|
if (mPendingDecodeComplete && mNeedShmemIntrCount == 0) {
|
|
|
|
mPendingDecodeComplete = false;
|
2016-05-05 11:45:00 +03:00
|
|
|
mPlugin->GMPMessageLoop()->PostTask(
|
2017-06-12 22:34:10 +03:00
|
|
|
NewRunnableMethod("gmp::GMPVideoDecoderChild::RecvDecodingComplete",
|
|
|
|
this,
|
|
|
|
&GMPVideoDecoderChild::RecvDecodingComplete));
|
2015-05-08 04:36:34 +03:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
#ifdef GMP_SAFE_SHMEM
|
|
|
|
rv = AllocShmem(aSize, aType, aMem);
|
|
|
|
#else
|
|
|
|
rv = AllocUnsafeShmem(aSize, aType, aMem);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoDecoderChild::Dealloc(Shmem& aMem)
|
|
|
|
{
|
|
|
|
#ifndef SHMEM_ALLOC_IN_CHILD
|
|
|
|
SendParentShmemForPool(aMem);
|
|
|
|
#else
|
|
|
|
DeallocShmem(aMem);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
} // namespace gmp
|
|
|
|
} // namespace mozilla
|