2012-04-30 03:11:19 +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/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_VIDEOSEGMENT_H_
|
|
|
|
#define MOZILLA_VIDEOSEGMENT_H_
|
|
|
|
|
|
|
|
#include "MediaSegment.h"
|
2012-08-21 04:06:46 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "gfxPoint.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2012-08-19 19:33:25 +00:00
|
|
|
#include "ImageContainer.h"
|
2012-04-30 03:11:19 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-08-21 04:06:46 +00:00
|
|
|
namespace layers {
|
|
|
|
class Image;
|
|
|
|
}
|
|
|
|
|
2012-04-30 03:11:19 +00:00
|
|
|
class VideoFrame {
|
|
|
|
public:
|
|
|
|
typedef mozilla::layers::Image Image;
|
|
|
|
|
2012-08-21 04:06:46 +00:00
|
|
|
VideoFrame(already_AddRefed<Image> aImage, const gfxIntSize& aIntrinsicSize);
|
|
|
|
VideoFrame();
|
|
|
|
~VideoFrame();
|
2012-04-30 03:11:19 +00:00
|
|
|
|
|
|
|
bool operator==(const VideoFrame& aFrame) const
|
|
|
|
{
|
2013-05-30 04:44:43 +00:00
|
|
|
return mIntrinsicSize == aFrame.mIntrinsicSize &&
|
|
|
|
mForceBlack == aFrame.mForceBlack &&
|
|
|
|
((mForceBlack && aFrame.mForceBlack) || mImage == aFrame.mImage);
|
2012-04-30 03:11:19 +00:00
|
|
|
}
|
|
|
|
bool operator!=(const VideoFrame& aFrame) const
|
|
|
|
{
|
|
|
|
return !operator==(aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
Image* GetImage() const { return mImage; }
|
2013-05-30 04:44:43 +00:00
|
|
|
void SetForceBlack(bool aForceBlack) { mForceBlack = true; }
|
|
|
|
bool GetForceBlack() const { return mForceBlack; }
|
2012-04-30 03:11:19 +00:00
|
|
|
const gfxIntSize& GetIntrinsicSize() const { return mIntrinsicSize; }
|
2012-08-21 04:06:46 +00:00
|
|
|
void SetNull();
|
|
|
|
void TakeFrom(VideoFrame* aFrame);
|
2012-04-30 03:11:19 +00: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-30 04:44:43 +00:00
|
|
|
bool mForceBlack;
|
2012-04-30 03:11:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VideoChunk {
|
2012-08-21 04:06:46 +00:00
|
|
|
VideoChunk();
|
|
|
|
~VideoChunk();
|
2012-04-30 03:11:19 +00: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-05-30 04:44:43 +00:00
|
|
|
void SetForceBlack(bool aForceBlack) { mFrame.SetForceBlack(aForceBlack); }
|
2012-04-30 03:11:19 +00:00
|
|
|
|
|
|
|
TrackTicks mDuration;
|
|
|
|
VideoFrame mFrame;
|
|
|
|
};
|
|
|
|
|
|
|
|
class VideoSegment : public MediaSegmentBase<VideoSegment, VideoChunk> {
|
|
|
|
public:
|
|
|
|
typedef mozilla::layers::Image Image;
|
|
|
|
|
2012-08-21 04:06:46 +00:00
|
|
|
VideoSegment();
|
|
|
|
~VideoSegment();
|
2012-04-30 03:11:19 +00:00
|
|
|
|
|
|
|
void AppendFrame(already_AddRefed<Image> aImage, TrackTicks aDuration,
|
2012-08-21 04:06:46 +00:00
|
|
|
const gfxIntSize& aIntrinsicSize);
|
2012-07-30 14:20:58 +00:00
|
|
|
const VideoFrame* GetFrameAt(TrackTicks aOffset, TrackTicks* aStart = nullptr)
|
2012-04-30 03:11:19 +00:00
|
|
|
{
|
|
|
|
VideoChunk* c = FindChunkContaining(aOffset, aStart);
|
|
|
|
if (!c) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-04-30 03:11:19 +00:00
|
|
|
}
|
|
|
|
return &c->mFrame;
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
const VideoFrame* GetLastFrame(TrackTicks* aStart = nullptr)
|
2012-04-30 03:11:19 +00:00
|
|
|
{
|
|
|
|
VideoChunk* c = GetLastChunk();
|
|
|
|
if (!c) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-04-30 03:11:19 +00:00
|
|
|
}
|
|
|
|
if (aStart) {
|
|
|
|
*aStart = mDuration - c->mDuration;
|
|
|
|
}
|
|
|
|
return &c->mFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Segment-generic methods not in MediaSegmentBase
|
|
|
|
static Type StaticType() { return VIDEO; }
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MOZILLA_VIDEOSEGMENT_H_ */
|