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 "GMPVideoi420FrameImpl.h"
|
|
|
|
#include "mozilla/gmp/GMPTypes.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gmp {
|
|
|
|
|
|
|
|
GMPVideoi420FrameImpl::GMPVideoi420FrameImpl(GMPVideoHostImpl* aHost)
|
|
|
|
: mYPlane(aHost),
|
|
|
|
mUPlane(aHost),
|
|
|
|
mVPlane(aHost),
|
|
|
|
mWidth(0),
|
|
|
|
mHeight(0),
|
2014-07-11 07:35:56 +04:00
|
|
|
mTimestamp(0ll),
|
|
|
|
mDuration(0ll)
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aHost);
|
|
|
|
}
|
|
|
|
|
|
|
|
GMPVideoi420FrameImpl::GMPVideoi420FrameImpl(const GMPVideoi420FrameData& aFrameData,
|
|
|
|
GMPVideoHostImpl* aHost)
|
|
|
|
: mYPlane(aFrameData.mYPlane(), aHost),
|
|
|
|
mUPlane(aFrameData.mUPlane(), aHost),
|
|
|
|
mVPlane(aFrameData.mVPlane(), aHost),
|
|
|
|
mWidth(aFrameData.mWidth()),
|
|
|
|
mHeight(aFrameData.mHeight()),
|
|
|
|
mTimestamp(aFrameData.mTimestamp()),
|
2014-07-11 07:35:56 +04:00
|
|
|
mDuration(aFrameData.mDuration())
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aHost);
|
|
|
|
}
|
|
|
|
|
|
|
|
GMPVideoi420FrameImpl::~GMPVideoi420FrameImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GMPVideoi420FrameImpl::InitFrameData(GMPVideoi420FrameData& aFrameData)
|
|
|
|
{
|
|
|
|
mYPlane.InitPlaneData(aFrameData.mYPlane());
|
|
|
|
mUPlane.InitPlaneData(aFrameData.mUPlane());
|
|
|
|
mVPlane.InitPlaneData(aFrameData.mVPlane());
|
|
|
|
aFrameData.mWidth() = mWidth;
|
|
|
|
aFrameData.mHeight() = mHeight;
|
|
|
|
aFrameData.mTimestamp() = mTimestamp;
|
2014-07-11 07:35:56 +04:00
|
|
|
aFrameData.mDuration() = mDuration;
|
2014-05-18 07:05:46 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
GMPVideoFrameFormat
|
|
|
|
GMPVideoi420FrameImpl::GetFrameFormat()
|
|
|
|
{
|
|
|
|
return kGMPI420VideoFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoi420FrameImpl::Destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GMPVideoi420FrameImpl::CheckDimensions(int32_t aWidth, int32_t aHeight,
|
|
|
|
int32_t aStride_y, int32_t aStride_u, int32_t aStride_v)
|
|
|
|
{
|
|
|
|
int32_t half_width = (aWidth + 1) / 2;
|
|
|
|
if (aWidth < 1 || aHeight < 1 || aStride_y < aWidth ||
|
|
|
|
aStride_u < half_width ||
|
|
|
|
aStride_v < half_width) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const GMPPlaneImpl*
|
|
|
|
GMPVideoi420FrameImpl::GetPlane(GMPPlaneType aType) const {
|
|
|
|
switch (aType) {
|
|
|
|
case kGMPYPlane:
|
|
|
|
return &mYPlane;
|
|
|
|
case kGMPUPlane:
|
|
|
|
return &mUPlane;
|
|
|
|
case kGMPVPlane:
|
|
|
|
return &mVPlane;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown plane type!");
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
GMPPlaneImpl*
|
|
|
|
GMPVideoi420FrameImpl::GetPlane(GMPPlaneType aType) {
|
|
|
|
switch (aType) {
|
|
|
|
case kGMPYPlane :
|
|
|
|
return &mYPlane;
|
|
|
|
case kGMPUPlane :
|
|
|
|
return &mUPlane;
|
|
|
|
case kGMPVPlane :
|
|
|
|
return &mVPlane;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown plane type!");
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
GMPErr
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPVideoi420FrameImpl::CreateEmptyFrame(int32_t aWidth, int32_t aHeight,
|
|
|
|
int32_t aStride_y, int32_t aStride_u, int32_t aStride_v)
|
|
|
|
{
|
|
|
|
if (!CheckDimensions(aWidth, aHeight, aStride_y, aStride_u, aStride_v)) {
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPGenericErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t size_y = aStride_y * aHeight;
|
|
|
|
int32_t half_height = (aHeight + 1) / 2;
|
|
|
|
int32_t size_u = aStride_u * half_height;
|
|
|
|
int32_t size_v = aStride_v * half_height;
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
GMPErr err = mYPlane.CreateEmptyPlane(size_y, aStride_y, size_y);
|
|
|
|
if (err != GMPNoErr) {
|
2014-05-18 07:05:46 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
err = mUPlane.CreateEmptyPlane(size_u, aStride_u, size_u);
|
2014-07-11 07:35:56 +04:00
|
|
|
if (err != GMPNoErr) {
|
2014-05-18 07:05:46 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
err = mVPlane.CreateEmptyPlane(size_v, aStride_v, size_v);
|
2014-07-11 07:35:56 +04:00
|
|
|
if (err != GMPNoErr) {
|
2014-05-18 07:05:46 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
mWidth = aWidth;
|
|
|
|
mHeight = aHeight;
|
2014-07-11 07:35:56 +04:00
|
|
|
mTimestamp = 0ll;
|
|
|
|
mDuration = 0ll;
|
2014-05-18 07:05:46 +04:00
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPNoErr;
|
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
|
|
|
GMPVideoi420FrameImpl::CreateFrame(int32_t aSize_y, const uint8_t* aBuffer_y,
|
|
|
|
int32_t aSize_u, const uint8_t* aBuffer_u,
|
|
|
|
int32_t aSize_v, const uint8_t* aBuffer_v,
|
|
|
|
int32_t aWidth, int32_t aHeight,
|
|
|
|
int32_t aStride_y, int32_t aStride_u, int32_t aStride_v)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aBuffer_y);
|
|
|
|
MOZ_ASSERT(aBuffer_u);
|
|
|
|
MOZ_ASSERT(aBuffer_v);
|
|
|
|
|
|
|
|
if (aSize_y < 1 || aSize_u < 1 || aSize_v < 1) {
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPGenericErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!CheckDimensions(aWidth, aHeight, aStride_y, aStride_u, aStride_v)) {
|
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 err = mYPlane.Copy(aSize_y, aStride_y, aBuffer_y);
|
|
|
|
if (err != GMPNoErr) {
|
2014-05-18 07:05:46 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
err = mUPlane.Copy(aSize_u, aStride_u, aBuffer_u);
|
2014-07-11 07:35:56 +04:00
|
|
|
if (err != GMPNoErr) {
|
2014-05-18 07:05:46 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
err = mVPlane.Copy(aSize_v, aStride_v, aBuffer_v);
|
2014-07-11 07:35:56 +04:00
|
|
|
if (err != GMPNoErr) {
|
2014-05-18 07:05:46 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
mWidth = aWidth;
|
|
|
|
mHeight = aHeight;
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPNoErr;
|
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
|
|
|
GMPVideoi420FrameImpl::CopyFrame(const GMPVideoi420Frame& aFrame)
|
|
|
|
{
|
|
|
|
auto& f = static_cast<const GMPVideoi420FrameImpl&>(aFrame);
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
GMPErr err = mYPlane.Copy(f.mYPlane);
|
|
|
|
if (err != GMPNoErr) {
|
2014-05-18 07:05:46 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = mUPlane.Copy(f.mUPlane);
|
2014-07-11 07:35:56 +04:00
|
|
|
if (err != GMPNoErr) {
|
2014-05-18 07:05:46 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = mVPlane.Copy(f.mVPlane);
|
2014-07-11 07:35:56 +04:00
|
|
|
if (err != GMPNoErr) {
|
2014-05-18 07:05:46 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
mWidth = f.mWidth;
|
|
|
|
mHeight = f.mHeight;
|
|
|
|
mTimestamp = f.mTimestamp;
|
2014-07-11 07:35:56 +04:00
|
|
|
mDuration = f.mDuration;
|
2014-05-18 07:05:46 +04:00
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPNoErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoi420FrameImpl::SwapFrame(GMPVideoi420Frame* aFrame)
|
|
|
|
{
|
|
|
|
auto f = static_cast<GMPVideoi420FrameImpl*>(aFrame);
|
|
|
|
mYPlane.Swap(f->mYPlane);
|
|
|
|
mUPlane.Swap(f->mUPlane);
|
|
|
|
mVPlane.Swap(f->mVPlane);
|
|
|
|
std::swap(mWidth, f->mWidth);
|
|
|
|
std::swap(mHeight, f->mHeight);
|
|
|
|
std::swap(mTimestamp, f->mTimestamp);
|
2014-07-11 07:35:56 +04:00
|
|
|
std::swap(mDuration, f->mDuration);
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t*
|
|
|
|
GMPVideoi420FrameImpl::Buffer(GMPPlaneType aType)
|
|
|
|
{
|
|
|
|
GMPPlane* p = GetPlane(aType);
|
|
|
|
if (p) {
|
|
|
|
return p->Buffer();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t*
|
|
|
|
GMPVideoi420FrameImpl::Buffer(GMPPlaneType aType) const
|
|
|
|
{
|
|
|
|
const GMPPlane* p = GetPlane(aType);
|
|
|
|
if (p) {
|
|
|
|
return p->Buffer();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
GMPVideoi420FrameImpl::AllocatedSize(GMPPlaneType aType) const
|
|
|
|
{
|
|
|
|
const GMPPlane* p = GetPlane(aType);
|
|
|
|
if (p) {
|
|
|
|
return p->AllocatedSize();
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
GMPVideoi420FrameImpl::Stride(GMPPlaneType aType) const
|
|
|
|
{
|
|
|
|
const GMPPlane* p = GetPlane(aType);
|
|
|
|
if (p) {
|
|
|
|
return p->Stride();
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
GMPErr
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPVideoi420FrameImpl::SetWidth(int32_t aWidth)
|
|
|
|
{
|
|
|
|
if (!CheckDimensions(aWidth, mHeight,
|
|
|
|
mYPlane.Stride(), mUPlane.Stride(),
|
|
|
|
mVPlane.Stride())) {
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPGenericErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
mWidth = aWidth;
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPNoErr;
|
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
|
|
|
GMPVideoi420FrameImpl::SetHeight(int32_t aHeight)
|
|
|
|
{
|
|
|
|
if (!CheckDimensions(mWidth, aHeight,
|
|
|
|
mYPlane.Stride(), mUPlane.Stride(),
|
|
|
|
mVPlane.Stride())) {
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPGenericErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
mHeight = aHeight;
|
2014-07-11 07:35:56 +04:00
|
|
|
return GMPNoErr;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
GMPVideoi420FrameImpl::Width() const
|
|
|
|
{
|
|
|
|
return mWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
GMPVideoi420FrameImpl::Height() const
|
|
|
|
{
|
|
|
|
return mHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 07:35:56 +04:00
|
|
|
GMPVideoi420FrameImpl::SetTimestamp(uint64_t aTimestamp)
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
|
|
|
mTimestamp = aTimestamp;
|
|
|
|
}
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
uint64_t
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPVideoi420FrameImpl::Timestamp() const
|
|
|
|
{
|
|
|
|
return mTimestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-11 07:35:56 +04:00
|
|
|
GMPVideoi420FrameImpl::SetDuration(uint64_t aDuration)
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
2014-07-11 07:35:56 +04:00
|
|
|
mDuration = aDuration;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
uint64_t
|
|
|
|
GMPVideoi420FrameImpl::Duration() const
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
2014-07-11 07:35:56 +04:00
|
|
|
return mDuration;
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GMPVideoi420FrameImpl::IsZeroSize() const
|
|
|
|
{
|
|
|
|
return (mYPlane.IsZeroSize() && mUPlane.IsZeroSize() && mVPlane.IsZeroSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GMPVideoi420FrameImpl::ResetSize()
|
|
|
|
{
|
|
|
|
mYPlane.ResetSize();
|
|
|
|
mUPlane.ResetSize();
|
|
|
|
mVPlane.ResetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace gmp
|
|
|
|
} // namespace mozilla
|