content/media/VideoSegment.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial