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"
12 #include "nsAutoPtr.h"
13 #include "ImageContainer.h"
23 typedef mozilla::layers::Image Image
;
25 VideoFrame(already_AddRefed
<Image
>& aImage
, const gfxIntSize
& aIntrinsicSize
);
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
; }
45 void TakeFrom(VideoFrame
* aFrame
);
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
;
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
;
75 mTimeStamp
= TimeStamp();
77 void SetForceBlack(bool aForceBlack
) { mFrame
.SetForceBlack(aForceBlack
); }
79 size_t SizeOfExcludingThisIfUnshared(MallocSizeOf aMallocSizeOf
) const
88 mozilla::TimeStamp mTimeStamp
;
91 class VideoSegment
: public MediaSegmentBase
<VideoSegment
, VideoChunk
> {
93 typedef mozilla::layers::Image Image
;
94 typedef mozilla::gfx::IntSize IntSize
;
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
);
111 const VideoFrame
* GetLastFrame(TrackTicks
* aStart
= nullptr)
113 VideoChunk
* c
= GetLastChunk();
118 *aStart
= mDuration
- c
->mDuration
;
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_ */