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"
|
2012-08-19 12:33:25 -07:00
|
|
|
#include "ImageContainer.h"
|
2012-04-29 20:11:19 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-08-20 21:06:46 -07:00
|
|
|
namespace layers {
|
|
|
|
class Image;
|
|
|
|
}
|
|
|
|
|
2012-04-29 20:11:19 -07:00
|
|
|
class VideoFrame {
|
|
|
|
public:
|
|
|
|
typedef mozilla::layers::Image Image;
|
|
|
|
|
2014-03-15 12:00:17 -07:00
|
|
|
VideoFrame(already_AddRefed<Image>& aImage, const gfxIntSize& 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; }
|
2012-04-29 20:11:19 -07:00
|
|
|
const gfxIntSize& 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
|
|
|
|
2014-09-03 17:08:00 -07:00
|
|
|
// Create a planar YCbCr black image.
|
|
|
|
static already_AddRefed<Image> CreateBlackImage(const gfxIntSize& aSize);
|
|
|
|
|
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.
|
|
|
|
nsRefPtr<Image> mImage;
|
|
|
|
// The desired size to render the video frame at.
|
|
|
|
gfxIntSize 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();
|
2012-04-29 20:11:19 -07:00
|
|
|
void SliceTo(TrackTicks aStart, TrackTicks aEnd)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aStart >= 0 && aStart < aEnd && aEnd <= mDuration,
|
|
|
|
"Slice out of bounds");
|
|
|
|
mDuration = aEnd - aStart;
|
|
|
|
}
|
|
|
|
TrackTicks GetDuration() const { return mDuration; }
|
|
|
|
bool CanCombineWithFollowing(const VideoChunk& aOther) const
|
|
|
|
{
|
|
|
|
return aOther.mFrame == mFrame;
|
|
|
|
}
|
|
|
|
bool IsNull() const { return !mFrame.GetImage(); }
|
|
|
|
void SetNull(TrackTicks aDuration)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-04-29 20:11:19 -07:00
|
|
|
TrackTicks mDuration;
|
|
|
|
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:
|
|
|
|
typedef mozilla::layers::Image Image;
|
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,
|
|
|
|
TrackTicks aDuration,
|
|
|
|
const IntSize& aIntrinsicSize,
|
|
|
|
bool aForceBlack = false);
|
2012-07-30 07:20:58 -07:00
|
|
|
const VideoFrame* GetFrameAt(TrackTicks aOffset, TrackTicks* aStart = nullptr)
|
2012-04-29 20:11:19 -07:00
|
|
|
{
|
|
|
|
VideoChunk* c = FindChunkContaining(aOffset, aStart);
|
|
|
|
if (!c) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-04-29 20:11:19 -07:00
|
|
|
}
|
|
|
|
return &c->mFrame;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
const VideoFrame* GetLastFrame(TrackTicks* 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
|
|
|
|
virtual void ReplaceWithDisabled() MOZ_OVERRIDE {
|
|
|
|
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
|
|
|
|
|
|
|
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
2012-04-29 20:11:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MOZILLA_VIDEOSEGMENT_H_ */
|