content/media/MediaData.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: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6 #if !defined(MediaData_h)
michael@0 7 #define MediaData_h
michael@0 8
michael@0 9 #include "nsSize.h"
michael@0 10 #include "mozilla/gfx/Rect.h"
michael@0 11 #include "nsRect.h"
michael@0 12 #include "AudioSampleFormat.h"
michael@0 13 #include "nsIMemoryReporter.h"
michael@0 14 #include "SharedBuffer.h"
michael@0 15
michael@0 16 namespace mozilla {
michael@0 17
michael@0 18 namespace layers {
michael@0 19 class Image;
michael@0 20 class ImageContainer;
michael@0 21 }
michael@0 22
michael@0 23 // Container that holds media samples.
michael@0 24 class MediaData {
michael@0 25 public:
michael@0 26
michael@0 27 enum Type {
michael@0 28 AUDIO_SAMPLES = 0,
michael@0 29 VIDEO_FRAME = 1
michael@0 30 };
michael@0 31
michael@0 32 MediaData(Type aType,
michael@0 33 int64_t aOffset,
michael@0 34 int64_t aTimestamp,
michael@0 35 int64_t aDuration)
michael@0 36 : mType(aType)
michael@0 37 , mOffset(aOffset)
michael@0 38 , mTime(aTimestamp)
michael@0 39 , mDuration(aDuration)
michael@0 40 {}
michael@0 41
michael@0 42 virtual ~MediaData() {}
michael@0 43
michael@0 44 // Type of contained data.
michael@0 45 const Type mType;
michael@0 46
michael@0 47 // Approximate byte offset where this data was demuxed from its media.
michael@0 48 const int64_t mOffset;
michael@0 49
michael@0 50 // Start time of sample, in microseconds.
michael@0 51 const int64_t mTime;
michael@0 52
michael@0 53 // Duration of sample, in microseconds.
michael@0 54 const int64_t mDuration;
michael@0 55
michael@0 56 int64_t GetEndTime() const { return mTime + mDuration; }
michael@0 57
michael@0 58 };
michael@0 59
michael@0 60 // Holds chunk a decoded audio frames.
michael@0 61 class AudioData : public MediaData {
michael@0 62 public:
michael@0 63
michael@0 64 AudioData(int64_t aOffset,
michael@0 65 int64_t aTime,
michael@0 66 int64_t aDuration,
michael@0 67 uint32_t aFrames,
michael@0 68 AudioDataValue* aData,
michael@0 69 uint32_t aChannels)
michael@0 70 : MediaData(AUDIO_SAMPLES, aOffset, aTime, aDuration)
michael@0 71 , mFrames(aFrames)
michael@0 72 , mChannels(aChannels)
michael@0 73 , mAudioData(aData)
michael@0 74 {
michael@0 75 MOZ_COUNT_CTOR(AudioData);
michael@0 76 }
michael@0 77
michael@0 78 ~AudioData()
michael@0 79 {
michael@0 80 MOZ_COUNT_DTOR(AudioData);
michael@0 81 }
michael@0 82
michael@0 83 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
michael@0 84 size_t size = aMallocSizeOf(this) + aMallocSizeOf(mAudioData);
michael@0 85 if (mAudioBuffer) {
michael@0 86 size += mAudioBuffer->SizeOfIncludingThis(aMallocSizeOf);
michael@0 87 }
michael@0 88 return size;
michael@0 89 }
michael@0 90
michael@0 91 // If mAudioBuffer is null, creates it from mAudioData.
michael@0 92 void EnsureAudioBuffer();
michael@0 93
michael@0 94 const uint32_t mFrames;
michael@0 95 const uint32_t mChannels;
michael@0 96 // At least one of mAudioBuffer/mAudioData must be non-null.
michael@0 97 // mChannels channels, each with mFrames frames
michael@0 98 nsRefPtr<SharedBuffer> mAudioBuffer;
michael@0 99 // mFrames frames, each with mChannels values
michael@0 100 nsAutoArrayPtr<AudioDataValue> mAudioData;
michael@0 101 };
michael@0 102
michael@0 103 namespace layers {
michael@0 104 class TextureClient;
michael@0 105 class PlanarYCbCrImage;
michael@0 106 }
michael@0 107
michael@0 108 class VideoInfo;
michael@0 109
michael@0 110 // Holds a decoded video frame, in YCbCr format. These are queued in the reader.
michael@0 111 class VideoData : public MediaData {
michael@0 112 public:
michael@0 113 typedef gfx::IntRect IntRect;
michael@0 114 typedef gfx::IntSize IntSize;
michael@0 115 typedef layers::ImageContainer ImageContainer;
michael@0 116 typedef layers::Image Image;
michael@0 117 typedef layers::PlanarYCbCrImage PlanarYCbCrImage;
michael@0 118
michael@0 119 // YCbCr data obtained from decoding the video. The index's are:
michael@0 120 // 0 = Y
michael@0 121 // 1 = Cb
michael@0 122 // 2 = Cr
michael@0 123 struct YCbCrBuffer {
michael@0 124 struct Plane {
michael@0 125 uint8_t* mData;
michael@0 126 uint32_t mWidth;
michael@0 127 uint32_t mHeight;
michael@0 128 uint32_t mStride;
michael@0 129 uint32_t mOffset;
michael@0 130 uint32_t mSkip;
michael@0 131 };
michael@0 132
michael@0 133 Plane mPlanes[3];
michael@0 134 };
michael@0 135
michael@0 136 // Constructs a VideoData object. If aImage is nullptr, creates a new Image
michael@0 137 // holding a copy of the YCbCr data passed in aBuffer. If aImage is not
michael@0 138 // nullptr, it's stored as the underlying video image and aBuffer is assumed
michael@0 139 // to point to memory within aImage so no copy is made. aTimecode is a codec
michael@0 140 // specific number representing the timestamp of the frame of video data.
michael@0 141 // Returns nsnull if an error occurs. This may indicate that memory couldn't
michael@0 142 // be allocated to create the VideoData object, or it may indicate some
michael@0 143 // problem with the input data (e.g. negative stride).
michael@0 144 static VideoData* Create(VideoInfo& aInfo,
michael@0 145 ImageContainer* aContainer,
michael@0 146 Image* aImage,
michael@0 147 int64_t aOffset,
michael@0 148 int64_t aTime,
michael@0 149 int64_t aDuration,
michael@0 150 const YCbCrBuffer &aBuffer,
michael@0 151 bool aKeyframe,
michael@0 152 int64_t aTimecode,
michael@0 153 const IntRect& aPicture);
michael@0 154
michael@0 155 // Variant that always makes a copy of aBuffer
michael@0 156 static VideoData* Create(VideoInfo& aInfo,
michael@0 157 ImageContainer* aContainer,
michael@0 158 int64_t aOffset,
michael@0 159 int64_t aTime,
michael@0 160 int64_t aDuration,
michael@0 161 const YCbCrBuffer &aBuffer,
michael@0 162 bool aKeyframe,
michael@0 163 int64_t aTimecode,
michael@0 164 const IntRect& aPicture);
michael@0 165
michael@0 166 // Variant to create a VideoData instance given an existing aImage
michael@0 167 static VideoData* Create(VideoInfo& aInfo,
michael@0 168 Image* aImage,
michael@0 169 int64_t aOffset,
michael@0 170 int64_t aTime,
michael@0 171 int64_t aDuration,
michael@0 172 const YCbCrBuffer &aBuffer,
michael@0 173 bool aKeyframe,
michael@0 174 int64_t aTimecode,
michael@0 175 const IntRect& aPicture);
michael@0 176
michael@0 177 static VideoData* Create(VideoInfo& aInfo,
michael@0 178 ImageContainer* aContainer,
michael@0 179 int64_t aOffset,
michael@0 180 int64_t aTime,
michael@0 181 int64_t aDuration,
michael@0 182 layers::TextureClient* aBuffer,
michael@0 183 bool aKeyframe,
michael@0 184 int64_t aTimecode,
michael@0 185 const IntRect& aPicture);
michael@0 186
michael@0 187 static VideoData* CreateFromImage(VideoInfo& aInfo,
michael@0 188 ImageContainer* aContainer,
michael@0 189 int64_t aOffset,
michael@0 190 int64_t aTime,
michael@0 191 int64_t aDuration,
michael@0 192 const nsRefPtr<Image>& aImage,
michael@0 193 bool aKeyframe,
michael@0 194 int64_t aTimecode,
michael@0 195 const IntRect& aPicture);
michael@0 196
michael@0 197 // Creates a new VideoData identical to aOther, but with a different
michael@0 198 // specified duration. All data from aOther is copied into the new
michael@0 199 // VideoData. The new VideoData's mImage field holds a reference to
michael@0 200 // aOther's mImage, i.e. the Image is not copied. This function is useful
michael@0 201 // in reader backends that can't determine the duration of a VideoData
michael@0 202 // until the next frame is decoded, i.e. it's a way to change the const
michael@0 203 // duration field on a VideoData.
michael@0 204 static VideoData* ShallowCopyUpdateDuration(VideoData* aOther,
michael@0 205 int64_t aDuration);
michael@0 206
michael@0 207 // Creates a new VideoData identical to aOther, but with a different
michael@0 208 // specified timestamp. All data from aOther is copied into the new
michael@0 209 // VideoData, as ShallowCopyUpdateDuration() does.
michael@0 210 static VideoData* ShallowCopyUpdateTimestamp(VideoData* aOther,
michael@0 211 int64_t aTimestamp);
michael@0 212
michael@0 213 // Initialize PlanarYCbCrImage. Only When aCopyData is true,
michael@0 214 // video data is copied to PlanarYCbCrImage.
michael@0 215 static void SetVideoDataToImage(PlanarYCbCrImage* aVideoImage,
michael@0 216 VideoInfo& aInfo,
michael@0 217 const YCbCrBuffer &aBuffer,
michael@0 218 const IntRect& aPicture,
michael@0 219 bool aCopyData);
michael@0 220
michael@0 221 // Constructs a duplicate VideoData object. This intrinsically tells the
michael@0 222 // player that it does not need to update the displayed frame when this
michael@0 223 // frame is played; this frame is identical to the previous.
michael@0 224 static VideoData* CreateDuplicate(int64_t aOffset,
michael@0 225 int64_t aTime,
michael@0 226 int64_t aDuration,
michael@0 227 int64_t aTimecode)
michael@0 228 {
michael@0 229 return new VideoData(aOffset, aTime, aDuration, aTimecode);
michael@0 230 }
michael@0 231
michael@0 232 ~VideoData();
michael@0 233
michael@0 234 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
michael@0 235
michael@0 236 // Dimensions at which to display the video frame. The picture region
michael@0 237 // will be scaled to this size. This is should be the picture region's
michael@0 238 // dimensions scaled with respect to its aspect ratio.
michael@0 239 const IntSize mDisplay;
michael@0 240
michael@0 241 // Codec specific internal time code. For Ogg based codecs this is the
michael@0 242 // granulepos.
michael@0 243 const int64_t mTimecode;
michael@0 244
michael@0 245 // This frame's image.
michael@0 246 nsRefPtr<Image> mImage;
michael@0 247
michael@0 248 // When true, denotes that this frame is identical to the frame that
michael@0 249 // came before; it's a duplicate. mBuffer will be empty.
michael@0 250 const bool mDuplicate;
michael@0 251 const bool mKeyframe;
michael@0 252
michael@0 253 public:
michael@0 254 VideoData(int64_t aOffset,
michael@0 255 int64_t aTime,
michael@0 256 int64_t aDuration,
michael@0 257 int64_t aTimecode);
michael@0 258
michael@0 259 VideoData(int64_t aOffset,
michael@0 260 int64_t aTime,
michael@0 261 int64_t aDuration,
michael@0 262 bool aKeyframe,
michael@0 263 int64_t aTimecode,
michael@0 264 IntSize aDisplay);
michael@0 265
michael@0 266 };
michael@0 267
michael@0 268 } // namespace mozilla
michael@0 269
michael@0 270 #endif // MediaData_h

mercurial