2012-04-30 07:11:19 +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/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_VIDEOSEGMENT_H_
|
|
|
|
#define MOZILLA_VIDEOSEGMENT_H_
|
|
|
|
|
|
|
|
#include "MediaSegment.h"
|
2012-08-21 08:06:46 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "gfxPoint.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2015-04-09 16:15:00 +03:00
|
|
|
#if defined(MOZILLA_XPCOMRT_API)
|
|
|
|
#include "SimpleImageBuffer.h"
|
|
|
|
#else
|
2012-08-19 23:33:25 +04:00
|
|
|
#include "ImageContainer.h"
|
2015-04-09 16:15:00 +03:00
|
|
|
#endif
|
2012-04-30 07:11:19 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-08-21 08:06:46 +04:00
|
|
|
namespace layers {
|
|
|
|
class Image;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
2012-08-21 08:06:46 +04:00
|
|
|
|
2012-04-30 07:11:19 +04:00
|
|
|
class VideoFrame {
|
|
|
|
public:
|
2015-04-09 16:15:00 +03:00
|
|
|
#if defined(MOZILLA_XPCOMRT_API)
|
|
|
|
typedef mozilla::SimpleImageBuffer Image;
|
|
|
|
#else
|
2012-04-30 07:11:19 +04:00
|
|
|
typedef mozilla::layers::Image Image;
|
2015-04-09 16:15:00 +03:00
|
|
|
#endif
|
2012-04-30 07:11:19 +04:00
|
|
|
|
2015-09-23 21:49:05 +03:00
|
|
|
VideoFrame(already_AddRefed<Image>& aImage, const gfx::IntSize& aIntrinsicSize);
|
2012-08-21 08:06:46 +04:00
|
|
|
VideoFrame();
|
|
|
|
~VideoFrame();
|
2012-04-30 07:11:19 +04:00
|
|
|
|
|
|
|
bool operator==(const VideoFrame& aFrame) const
|
|
|
|
{
|
2013-05-30 08:44:43 +04:00
|
|
|
return mIntrinsicSize == aFrame.mIntrinsicSize &&
|
|
|
|
mForceBlack == aFrame.mForceBlack &&
|
|
|
|
((mForceBlack && aFrame.mForceBlack) || mImage == aFrame.mImage);
|
2012-04-30 07:11:19 +04:00
|
|
|
}
|
|
|
|
bool operator!=(const VideoFrame& aFrame) const
|
|
|
|
{
|
|
|
|
return !operator==(aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
Image* GetImage() const { return mImage; }
|
2013-12-02 11:52:54 +04:00
|
|
|
void SetForceBlack(bool aForceBlack) { mForceBlack = aForceBlack; }
|
2013-05-30 08:44:43 +04:00
|
|
|
bool GetForceBlack() const { return mForceBlack; }
|
2015-09-23 21:49:05 +03:00
|
|
|
const gfx::IntSize& GetIntrinsicSize() const { return mIntrinsicSize; }
|
2012-08-21 08:06:46 +04:00
|
|
|
void SetNull();
|
|
|
|
void TakeFrom(VideoFrame* aFrame);
|
2012-04-30 07:11:19 +04:00
|
|
|
|
2015-04-09 16:15:00 +03:00
|
|
|
#if !defined(MOZILLA_XPCOMRT_API)
|
2014-09-04 04:08:00 +04:00
|
|
|
// Create a planar YCbCr black image.
|
2015-09-23 21:49:05 +03:00
|
|
|
static already_AddRefed<Image> CreateBlackImage(const gfx::IntSize& aSize);
|
2015-04-09 16:15:00 +03:00
|
|
|
#endif // !defined(MOZILLA_XPCOMRT_API)
|
2014-09-04 04:08:00 +04:00
|
|
|
|
2012-04-30 07:11:19 +04:00
|
|
|
protected:
|
|
|
|
// mImage can be null to indicate "no video" (aka "empty frame"). It can
|
|
|
|
// still have an intrinsic size in this case.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> mImage;
|
2012-04-30 07:11:19 +04:00
|
|
|
// The desired size to render the video frame at.
|
2015-09-23 21:49:05 +03:00
|
|
|
gfx::IntSize mIntrinsicSize;
|
2013-05-30 08:44:43 +04:00
|
|
|
bool mForceBlack;
|
2012-04-30 07:11:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VideoChunk {
|
2012-08-21 08:06:46 +04:00
|
|
|
VideoChunk();
|
|
|
|
~VideoChunk();
|
2014-09-18 09:20:43 +04:00
|
|
|
void SliceTo(StreamTime aStart, StreamTime aEnd)
|
2012-04-30 07:11:19 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aStart >= 0 && aStart < aEnd && aEnd <= mDuration,
|
|
|
|
"Slice out of bounds");
|
|
|
|
mDuration = aEnd - aStart;
|
|
|
|
}
|
2014-09-18 09:20:43 +04:00
|
|
|
StreamTime GetDuration() const { return mDuration; }
|
2012-04-30 07:11:19 +04:00
|
|
|
bool CanCombineWithFollowing(const VideoChunk& aOther) const
|
|
|
|
{
|
|
|
|
return aOther.mFrame == mFrame;
|
|
|
|
}
|
|
|
|
bool IsNull() const { return !mFrame.GetImage(); }
|
2014-09-18 09:20:43 +04:00
|
|
|
void SetNull(StreamTime aDuration)
|
2012-04-30 07:11:19 +04:00
|
|
|
{
|
|
|
|
mDuration = aDuration;
|
|
|
|
mFrame.SetNull();
|
2013-01-28 22:22:37 +04:00
|
|
|
mTimeStamp = TimeStamp();
|
2012-04-30 07:11:19 +04:00
|
|
|
}
|
2013-05-30 08:44:43 +04:00
|
|
|
void SetForceBlack(bool aForceBlack) { mFrame.SetForceBlack(aForceBlack); }
|
2012-04-30 07:11:19 +04:00
|
|
|
|
2014-04-13 22:08:10 +04:00
|
|
|
size_t SizeOfExcludingThisIfUnshared(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
// Future:
|
|
|
|
// - mFrame
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-18 09:20:43 +04:00
|
|
|
StreamTime mDuration;
|
2012-04-30 07:11:19 +04:00
|
|
|
VideoFrame mFrame;
|
2013-01-28 22:22:37 +04:00
|
|
|
mozilla::TimeStamp mTimeStamp;
|
2012-04-30 07:11:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class VideoSegment : public MediaSegmentBase<VideoSegment, VideoChunk> {
|
|
|
|
public:
|
2015-04-09 16:15:00 +03:00
|
|
|
#if defined(MOZILLA_XPCOMRT_API)
|
|
|
|
typedef mozilla::SimpleImageBuffer Image;
|
|
|
|
#else
|
2012-04-30 07:11:19 +04:00
|
|
|
typedef mozilla::layers::Image Image;
|
2015-04-09 16:15:00 +03:00
|
|
|
#endif
|
2014-02-09 12:04:38 +04:00
|
|
|
typedef mozilla::gfx::IntSize IntSize;
|
2012-04-30 07:11:19 +04:00
|
|
|
|
2012-08-21 08:06:46 +04:00
|
|
|
VideoSegment();
|
|
|
|
~VideoSegment();
|
2012-04-30 07:11:19 +04:00
|
|
|
|
2014-07-04 10:37:36 +04:00
|
|
|
void AppendFrame(already_AddRefed<Image>&& aImage,
|
2014-09-18 09:20:43 +04:00
|
|
|
StreamTime aDuration,
|
2014-07-04 10:37:36 +04:00
|
|
|
const IntSize& aIntrinsicSize,
|
|
|
|
bool aForceBlack = false);
|
2014-09-18 09:20:43 +04:00
|
|
|
const VideoFrame* GetLastFrame(StreamTime* aStart = nullptr)
|
2012-04-30 07:11:19 +04:00
|
|
|
{
|
|
|
|
VideoChunk* c = GetLastChunk();
|
|
|
|
if (!c) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-04-30 07:11:19 +04:00
|
|
|
}
|
|
|
|
if (aStart) {
|
|
|
|
*aStart = mDuration - c->mDuration;
|
|
|
|
}
|
|
|
|
return &c->mFrame;
|
|
|
|
}
|
2013-08-26 10:07:17 +04:00
|
|
|
// Override default impl
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ReplaceWithDisabled() override {
|
2013-08-26 10:07:17 +04:00
|
|
|
for (ChunkIterator i(*this);
|
|
|
|
!i.IsEnded(); i.Next()) {
|
|
|
|
VideoChunk& chunk = *i;
|
|
|
|
chunk.SetForceBlack(true);
|
|
|
|
}
|
|
|
|
}
|
2012-04-30 07:11:19 +04:00
|
|
|
|
|
|
|
// Segment-generic methods not in MediaSegmentBase
|
|
|
|
static Type StaticType() { return VIDEO; }
|
2014-04-13 22:08:10 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
|
2014-04-13 22:08:10 +04:00
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
2012-04-30 07:11:19 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2012-04-30 07:11:19 +04:00
|
|
|
|
|
|
|
#endif /* MOZILLA_VIDEOSEGMENT_H_ */
|