Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / content / media / VideoSegment.h
blobc04894f5186bedb4f91fe557e815430ede6f27dc
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef MOZILLA_VIDEOSEGMENT_H_
7 #define MOZILLA_VIDEOSEGMENT_H_
9 #include "MediaSegment.h"
10 #include "nsCOMPtr.h"
11 #include "gfxPoint.h"
12 #include "nsAutoPtr.h"
13 #include "ImageContainer.h"
15 namespace mozilla {
17 namespace layers {
18 class Image;
21 class VideoFrame {
22 public:
23 typedef mozilla::layers::Image Image;
25 VideoFrame(already_AddRefed<Image>& aImage, const gfxIntSize& aIntrinsicSize);
26 VideoFrame();
27 ~VideoFrame();
29 bool operator==(const VideoFrame& aFrame) const
31 return mIntrinsicSize == aFrame.mIntrinsicSize &&
32 mForceBlack == aFrame.mForceBlack &&
33 ((mForceBlack && aFrame.mForceBlack) || mImage == aFrame.mImage);
35 bool operator!=(const VideoFrame& aFrame) const
37 return !operator==(aFrame);
40 Image* GetImage() const { return mImage; }
41 void SetForceBlack(bool aForceBlack) { mForceBlack = aForceBlack; }
42 bool GetForceBlack() const { return mForceBlack; }
43 const gfxIntSize& GetIntrinsicSize() const { return mIntrinsicSize; }
44 void SetNull();
45 void TakeFrom(VideoFrame* aFrame);
47 protected:
48 // mImage can be null to indicate "no video" (aka "empty frame"). It can
49 // still have an intrinsic size in this case.
50 nsRefPtr<Image> mImage;
51 // The desired size to render the video frame at.
52 gfxIntSize mIntrinsicSize;
53 bool mForceBlack;
56 struct VideoChunk {
57 VideoChunk();
58 ~VideoChunk();
59 void SliceTo(TrackTicks aStart, TrackTicks aEnd)
61 NS_ASSERTION(aStart >= 0 && aStart < aEnd && aEnd <= mDuration,
62 "Slice out of bounds");
63 mDuration = aEnd - aStart;
65 TrackTicks GetDuration() const { return mDuration; }
66 bool CanCombineWithFollowing(const VideoChunk& aOther) const
68 return aOther.mFrame == mFrame;
70 bool IsNull() const { return !mFrame.GetImage(); }
71 void SetNull(TrackTicks aDuration)
73 mDuration = aDuration;
74 mFrame.SetNull();
75 mTimeStamp = TimeStamp();
77 void SetForceBlack(bool aForceBlack) { mFrame.SetForceBlack(aForceBlack); }
79 size_t SizeOfExcludingThisIfUnshared(MallocSizeOf aMallocSizeOf) const
81 // Future:
82 // - mFrame
83 return 0;
86 TrackTicks mDuration;
87 VideoFrame mFrame;
88 mozilla::TimeStamp mTimeStamp;
91 class VideoSegment : public MediaSegmentBase<VideoSegment, VideoChunk> {
92 public:
93 typedef mozilla::layers::Image Image;
94 typedef mozilla::gfx::IntSize IntSize;
96 VideoSegment();
97 ~VideoSegment();
99 void AppendFrame(already_AddRefed<Image>&& aImage,
100 TrackTicks aDuration,
101 const IntSize& aIntrinsicSize,
102 bool aForceBlack = false);
103 const VideoFrame* GetFrameAt(TrackTicks aOffset, TrackTicks* aStart = nullptr)
105 VideoChunk* c = FindChunkContaining(aOffset, aStart);
106 if (!c) {
107 return nullptr;
109 return &c->mFrame;
111 const VideoFrame* GetLastFrame(TrackTicks* aStart = nullptr)
113 VideoChunk* c = GetLastChunk();
114 if (!c) {
115 return nullptr;
117 if (aStart) {
118 *aStart = mDuration - c->mDuration;
120 return &c->mFrame;
122 // Override default impl
123 virtual void ReplaceWithDisabled() MOZ_OVERRIDE {
124 for (ChunkIterator i(*this);
125 !i.IsEnded(); i.Next()) {
126 VideoChunk& chunk = *i;
127 chunk.SetForceBlack(true);
131 // Segment-generic methods not in MediaSegmentBase
132 static Type StaticType() { return VIDEO; }
134 virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
136 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
142 #endif /* MOZILLA_VIDEOSEGMENT_H_ */