2014-05-18 03:05:46 +00: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 "GMPVideoEncodedFrameImpl.h"
|
|
|
|
#include "GMPVideoHost.h"
|
|
|
|
#include "mozilla/gmp/GMPTypes.h"
|
|
|
|
#include "GMPSharedMemManager.h"
|
2014-08-02 21:29:18 +00:00
|
|
|
#include "GMPEncryptedBufferDataImpl.h"
|
2014-05-18 03:05:46 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gmp {
|
|
|
|
|
|
|
|
GMPVideoEncodedFrameImpl::GMPVideoEncodedFrameImpl(GMPVideoHostImpl* aHost)
|
|
|
|
: mEncodedWidth(0),
|
|
|
|
mEncodedHeight(0),
|
2014-07-11 03:35:56 +00:00
|
|
|
mTimeStamp(0ll),
|
|
|
|
mDuration(0ll),
|
2014-05-18 03:05:46 +00:00
|
|
|
mFrameType(kGMPDeltaFrame),
|
|
|
|
mSize(0),
|
|
|
|
mCompleteFrame(false),
|
2014-07-11 14:39:10 +00:00
|
|
|
mHost(aHost),
|
|
|
|
mBufferType(GMP_BufferSingle)
|
2014-05-18 03:05:46 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aHost);
|
|
|
|
aHost->EncodedFrameCreated(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
GMPVideoEncodedFrameImpl::GMPVideoEncodedFrameImpl(const GMPVideoEncodedFrameData& aFrameData,
|
|
|
|
GMPVideoHostImpl* aHost)
|
|
|
|
: mEncodedWidth(aFrameData.mEncodedWidth()),
|
|
|
|
mEncodedHeight(aFrameData.mEncodedHeight()),
|
2014-07-11 03:35:56 +00:00
|
|
|
mTimeStamp(aFrameData.mTimestamp()),
|
|
|
|
mDuration(aFrameData.mDuration()),
|
2014-05-18 03:05:46 +00:00
|
|
|
mFrameType(static_cast<GMPVideoFrameType>(aFrameData.mFrameType())),
|
|
|
|
mSize(aFrameData.mSize()),
|
|
|
|
mCompleteFrame(aFrameData.mCompleteFrame()),
|
|
|
|
mHost(aHost),
|
2014-07-11 14:39:10 +00:00
|
|
|
mBuffer(aFrameData.mBuffer()),
|
|
|
|
mBufferType(aFrameData.mBufferType())
|
2014-05-18 03:05:46 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aHost);
|
2014-08-02 21:29:18 +00:00
|
|
|
if (aFrameData.mDecryptionData().mKeyId().Length() > 0) {
|
|
|
|
mCrypto = new GMPEncryptedBufferDataImpl(aFrameData.mDecryptionData());
|
|
|
|
}
|
2014-05-18 03:05:46 +00:00
|
|
|
aHost->EncodedFrameCreated(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
GMPVideoEncodedFrameImpl::~GMPVideoEncodedFrameImpl()
|
|
|
|
{
|
|
|
|
DestroyBuffer();
|
|
|
|
if (mHost) {
|
|
|
|
mHost->EncodedFrameDestroyed(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-02 21:29:18 +00:00
|
|
|
void
|
|
|
|
GMPVideoEncodedFrameImpl::InitCrypto(const mp4_demuxer::CryptoSample& aCrypto)
|
|
|
|
{
|
|
|
|
mCrypto = new GMPEncryptedBufferDataImpl(aCrypto);
|
|
|
|
}
|
|
|
|
|
2014-07-23 21:35:02 +00:00
|
|
|
const GMPEncryptedBufferMetadata*
|
2014-07-11 03:35:56 +00:00
|
|
|
GMPVideoEncodedFrameImpl::GetDecryptionData() const
|
|
|
|
{
|
2014-08-02 21:29:18 +00:00
|
|
|
return mCrypto;
|
2014-07-11 03:35:56 +00:00
|
|
|
}
|
|
|
|
|
2014-05-18 03:05:46 +00:00
|
|
|
GMPVideoFrameFormat
|
|
|
|
GMPVideoEncodedFrameImpl::GetFrameFormat()
|
|
|
|
{
|
|
|
|
return kGMPEncodedVideoFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoEncodedFrameImpl::DoneWithAPI()
|
|
|
|
{
|
|
|
|
DestroyBuffer();
|
|
|
|
|
|
|
|
// Do this after destroying the buffer because destruction
|
|
|
|
// involves deallocation, which requires a host.
|
|
|
|
mHost = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoEncodedFrameImpl::ActorDestroyed()
|
|
|
|
{
|
|
|
|
// Simply clear out Shmem reference, do not attempt to
|
|
|
|
// properly free it. It has already been freed.
|
|
|
|
mBuffer = ipc::Shmem();
|
|
|
|
// No more host.
|
|
|
|
mHost = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GMPVideoEncodedFrameImpl::RelinquishFrameData(GMPVideoEncodedFrameData& aFrameData)
|
|
|
|
{
|
|
|
|
aFrameData.mEncodedWidth() = mEncodedWidth;
|
|
|
|
aFrameData.mEncodedHeight() = mEncodedHeight;
|
2014-07-11 03:35:56 +00:00
|
|
|
aFrameData.mTimestamp() = mTimeStamp;
|
|
|
|
aFrameData.mDuration() = mDuration;
|
2014-05-18 03:05:46 +00:00
|
|
|
aFrameData.mFrameType() = mFrameType;
|
|
|
|
aFrameData.mSize() = mSize;
|
|
|
|
aFrameData.mCompleteFrame() = mCompleteFrame;
|
|
|
|
aFrameData.mBuffer() = mBuffer;
|
2014-07-11 14:39:10 +00:00
|
|
|
aFrameData.mBufferType() = mBufferType;
|
2014-08-02 21:29:18 +00:00
|
|
|
if (mCrypto) {
|
|
|
|
mCrypto->RelinquishData(aFrameData.mDecryptionData());
|
|
|
|
}
|
2014-05-18 03:05:46 +00:00
|
|
|
|
|
|
|
// This method is called right before Shmem is sent to another process.
|
|
|
|
// We need to effectively zero out our member copy so that we don't
|
|
|
|
// try to delete Shmem we don't own later.
|
|
|
|
mBuffer = ipc::Shmem();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoEncodedFrameImpl::DestroyBuffer()
|
|
|
|
{
|
|
|
|
if (mHost && mBuffer.IsWritable()) {
|
2014-07-28 15:44:20 +00:00
|
|
|
mHost->SharedMemMgr()->MgrDeallocShmem(GMPSharedMem::kGMPEncodedData, mBuffer);
|
2014-05-18 03:05:46 +00:00
|
|
|
}
|
|
|
|
mBuffer = ipc::Shmem();
|
|
|
|
}
|
|
|
|
|
2014-07-11 03:35:56 +00:00
|
|
|
GMPErr
|
2014-05-18 03:05:46 +00:00
|
|
|
GMPVideoEncodedFrameImpl::CreateEmptyFrame(uint32_t aSize)
|
|
|
|
{
|
2014-07-02 02:26:35 +00:00
|
|
|
if (aSize == 0) {
|
|
|
|
DestroyBuffer();
|
|
|
|
} else if (aSize > AllocatedSize()) {
|
|
|
|
DestroyBuffer();
|
2014-07-28 15:44:20 +00:00
|
|
|
if (!mHost->SharedMemMgr()->MgrAllocShmem(GMPSharedMem::kGMPEncodedData, aSize,
|
2014-07-02 02:26:35 +00:00
|
|
|
ipc::SharedMemory::TYPE_BASIC, &mBuffer) ||
|
2014-05-18 03:05:46 +00:00
|
|
|
!Buffer()) {
|
2014-07-11 03:35:56 +00:00
|
|
|
return GMPAllocErr;
|
2014-05-18 03:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mSize = aSize;
|
|
|
|
|
2014-07-11 03:35:56 +00:00
|
|
|
return GMPNoErr;
|
2014-05-18 03:05:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 03:35:56 +00:00
|
|
|
GMPErr
|
2014-05-18 03:05:46 +00:00
|
|
|
GMPVideoEncodedFrameImpl::CopyFrame(const GMPVideoEncodedFrame& aFrame)
|
|
|
|
{
|
|
|
|
auto& f = static_cast<const GMPVideoEncodedFrameImpl&>(aFrame);
|
|
|
|
|
|
|
|
if (f.mSize != 0) {
|
2014-07-11 03:35:56 +00:00
|
|
|
GMPErr err = CreateEmptyFrame(f.mSize);
|
|
|
|
if (err != GMPNoErr) {
|
2014-05-18 03:05:46 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
memcpy(Buffer(), f.Buffer(), f.mSize);
|
|
|
|
}
|
|
|
|
mEncodedWidth = f.mEncodedWidth;
|
|
|
|
mEncodedHeight = f.mEncodedHeight;
|
|
|
|
mTimeStamp = f.mTimeStamp;
|
2014-07-11 03:35:56 +00:00
|
|
|
mDuration = f.mDuration;
|
2014-05-18 03:05:46 +00:00
|
|
|
mFrameType = f.mFrameType;
|
2014-07-02 02:26:35 +00:00
|
|
|
mSize = f.mSize; // already set...
|
2014-05-18 03:05:46 +00:00
|
|
|
mCompleteFrame = f.mCompleteFrame;
|
2014-07-11 14:39:10 +00:00
|
|
|
mBufferType = f.mBufferType;
|
2014-08-02 21:29:18 +00:00
|
|
|
mCrypto = new GMPEncryptedBufferDataImpl(*(f.mCrypto));
|
2014-05-18 03:05:46 +00:00
|
|
|
// Don't copy host, that should have been set properly on object creation via host.
|
|
|
|
|
2014-07-11 03:35:56 +00:00
|
|
|
return GMPNoErr;
|
2014-05-18 03:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoEncodedFrameImpl::SetEncodedWidth(uint32_t aEncodedWidth)
|
|
|
|
{
|
|
|
|
mEncodedWidth = aEncodedWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
GMPVideoEncodedFrameImpl::EncodedWidth()
|
|
|
|
{
|
|
|
|
return mEncodedWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoEncodedFrameImpl::SetEncodedHeight(uint32_t aEncodedHeight)
|
|
|
|
{
|
|
|
|
mEncodedHeight = aEncodedHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
GMPVideoEncodedFrameImpl::EncodedHeight()
|
|
|
|
{
|
|
|
|
return mEncodedHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 03:35:56 +00:00
|
|
|
GMPVideoEncodedFrameImpl::SetTimeStamp(uint64_t aTimeStamp)
|
2014-05-18 03:05:46 +00:00
|
|
|
{
|
|
|
|
mTimeStamp = aTimeStamp;
|
|
|
|
}
|
|
|
|
|
2014-07-11 03:35:56 +00:00
|
|
|
uint64_t
|
2014-05-18 03:05:46 +00:00
|
|
|
GMPVideoEncodedFrameImpl::TimeStamp()
|
|
|
|
{
|
|
|
|
return mTimeStamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 03:35:56 +00:00
|
|
|
GMPVideoEncodedFrameImpl::SetDuration(uint64_t aDuration)
|
2014-05-18 03:05:46 +00:00
|
|
|
{
|
2014-07-11 03:35:56 +00:00
|
|
|
mDuration = aDuration;
|
2014-05-18 03:05:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 03:35:56 +00:00
|
|
|
uint64_t
|
|
|
|
GMPVideoEncodedFrameImpl::Duration() const
|
2014-05-18 03:05:46 +00:00
|
|
|
{
|
2014-07-11 03:35:56 +00:00
|
|
|
return mDuration;
|
2014-05-18 03:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoEncodedFrameImpl::SetFrameType(GMPVideoFrameType aFrameType)
|
|
|
|
{
|
|
|
|
mFrameType = aFrameType;
|
|
|
|
}
|
|
|
|
|
|
|
|
GMPVideoFrameType
|
|
|
|
GMPVideoEncodedFrameImpl::FrameType()
|
|
|
|
{
|
|
|
|
return mFrameType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoEncodedFrameImpl::SetAllocatedSize(uint32_t aNewSize)
|
|
|
|
{
|
|
|
|
if (aNewSize <= AllocatedSize()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHost) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipc::Shmem new_mem;
|
2014-07-28 15:44:20 +00:00
|
|
|
if (!mHost->SharedMemMgr()->MgrAllocShmem(GMPSharedMem::kGMPEncodedData, aNewSize,
|
2014-07-02 02:26:35 +00:00
|
|
|
ipc::SharedMemory::TYPE_BASIC, &new_mem) ||
|
2014-05-18 03:05:46 +00:00
|
|
|
!new_mem.get<uint8_t>()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mBuffer.IsReadable()) {
|
|
|
|
memcpy(new_mem.get<uint8_t>(), Buffer(), mSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyBuffer();
|
|
|
|
|
|
|
|
mBuffer = new_mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
GMPVideoEncodedFrameImpl::AllocatedSize()
|
|
|
|
{
|
|
|
|
if (mBuffer.IsWritable()) {
|
|
|
|
return mBuffer.Size<uint8_t>();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoEncodedFrameImpl::SetSize(uint32_t aSize)
|
|
|
|
{
|
|
|
|
mSize = aSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
GMPVideoEncodedFrameImpl::Size()
|
|
|
|
{
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoEncodedFrameImpl::SetCompleteFrame(bool aCompleteFrame)
|
|
|
|
{
|
|
|
|
mCompleteFrame = aCompleteFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GMPVideoEncodedFrameImpl::CompleteFrame()
|
|
|
|
{
|
|
|
|
return mCompleteFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t*
|
|
|
|
GMPVideoEncodedFrameImpl::Buffer() const
|
|
|
|
{
|
|
|
|
return mBuffer.get<uint8_t>();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t*
|
|
|
|
GMPVideoEncodedFrameImpl::Buffer()
|
|
|
|
{
|
|
|
|
return mBuffer.get<uint8_t>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoEncodedFrameImpl::Destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2014-07-11 14:39:10 +00:00
|
|
|
GMPBufferType
|
|
|
|
GMPVideoEncodedFrameImpl::BufferType() const
|
|
|
|
{
|
|
|
|
return mBufferType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoEncodedFrameImpl::SetBufferType(GMPBufferType aBufferType)
|
|
|
|
{
|
|
|
|
mBufferType = aBufferType;
|
|
|
|
}
|
|
|
|
|
2014-05-18 03:05:46 +00:00
|
|
|
} // namespace gmp
|
|
|
|
} // namespace mozilla
|