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