Bug 1171314: P1. Add SharedTrackInfo object. r=cpearce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 12 Jun 2015 15:18:05 +1000
changeset 249708 c1b8e5419562452499cb65d1a4a20f5973983058
parent 249707 f25d12a330d60681967b721cb8a1291c5f868ba4
child 249709 40c9845aff7d882bf72a4c258a2a02ff2d8e3eef
push id28936
push userryanvm@gmail.com
push dateFri, 19 Jun 2015 20:34:42 +0000
treeherdermozilla-central@c319f262ce3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1171314
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1171314: P1. Add SharedTrackInfo object. r=cpearce
dom/media/MediaData.cpp
dom/media/MediaData.h
dom/media/MediaInfo.h
--- a/dom/media/MediaData.cpp
+++ b/dom/media/MediaData.cpp
@@ -523,16 +523,17 @@ MediaRawData::Clone() const
   nsRefPtr<MediaRawData> s = new MediaRawData;
   s->mTimecode = mTimecode;
   s->mTime = mTime;
   s->mDuration = mDuration;
   s->mOffset = mOffset;
   s->mKeyframe = mKeyframe;
   s->mExtraData = mExtraData;
   s->mCryptoInternal = mCryptoInternal;
+  s->mTrackInfo = mTrackInfo;
   if (mSize) {
     if (!s->EnsureCapacity(mSize)) {
       return nullptr;
     }
 
     // We ensure sufficient capacity above so this shouldn't fail.
     MOZ_ALWAYS_TRUE(s->mBuffer->AppendElements(mData, mSize, fallible));
     MOZ_ALWAYS_TRUE(s->mBuffer->AppendElements(RAW_DATA_ALIGNMENT, fallible));
@@ -576,19 +577,16 @@ MediaRawData::~MediaRawData()
 {
 }
 
 size_t
 MediaRawData::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
 {
   size_t size = aMallocSizeOf(this);
 
-  if (mExtraData) {
-    size += mExtraData->SizeOfIncludingThis(aMallocSizeOf);
-  }
   size += mBuffer->SizeOfIncludingThis(aMallocSizeOf);
   return size;
 }
 
 MediaRawDataWriter*
 MediaRawData::CreateWriter()
 {
   return new MediaRawDataWriter(this);
--- a/dom/media/MediaData.h
+++ b/dom/media/MediaData.h
@@ -18,16 +18,17 @@
 namespace mozilla {
 
 namespace layers {
 class Image;
 class ImageContainer;
 }
 
 class MediaByteBuffer;
+class SharedTrackInfo;
 
 // Container that holds media samples.
 class MediaData {
 public:
 
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaData)
 
   enum Type {
@@ -390,16 +391,18 @@ public:
   // Pointer to data or null if not-yet allocated
   const uint8_t* mData;
   // Size of buffer.
   size_t mSize;
 
   const CryptoSample& mCrypto;
   nsRefPtr<MediaByteBuffer> mExtraData;
 
+  nsRefPtr<SharedTrackInfo> mTrackInfo;
+
   // Return a deep copy or nullptr if out of memory.
   virtual already_AddRefed<MediaRawData> Clone() const;
   // Create a MediaRawDataWriter for this MediaRawData. The caller must
   // delete the writer once done. The writer is not thread-safe.
   virtual MediaRawDataWriter* CreateWriter();
   virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
 
 protected:
--- a/dom/media/MediaInfo.h
+++ b/dom/media/MediaInfo.h
@@ -355,11 +355,62 @@ public:
   // The Ogg reader tries to kinda-sorta compute the duration by seeking to the
   // end and determining the timestamp of the last frame. This isn't useful as
   // a duration until we know the start time, so we need to track it separately.
   media::NullableTimeUnit mUnadjustedMetadataEndTime;
 
   EncryptionInfo mCrypto;
 };
 
+class SharedTrackInfo {
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SharedTrackInfo)
+public:
+  SharedTrackInfo(const TrackInfo& aOriginal, uint32_t aStreamID)
+    : mInfo(aOriginal.Clone())
+    , mStreamSourceID(aStreamID)
+    , mMimeType(mInfo->mMimeType)
+  {
+  }
+
+  uint32_t GetID() const
+  {
+    return mStreamSourceID;
+  }
+
+  const TrackInfo* operator*() const
+  {
+    return mInfo.get();
+  }
+
+  const TrackInfo* operator->() const
+  {
+    MOZ_ASSERT(mInfo.get(), "dereferencing a UniquePtr containing nullptr");
+    return mInfo.get();
+  }
+
+  const AudioInfo* GetAsAudioInfo() const
+  {
+    return mInfo ? mInfo->GetAsAudioInfo() : nullptr;
+  }
+
+  const VideoInfo* GetAsVideoInfo() const
+  {
+    return mInfo ? mInfo->GetAsVideoInfo() : nullptr;
+  }
+
+  const TextInfo* GetAsTextInfo() const
+  {
+    return mInfo ? mInfo->GetAsTextInfo() : nullptr;
+  }
+
+private:
+  ~SharedTrackInfo() {};
+  UniquePtr<TrackInfo> mInfo;
+  // A unique ID, guaranteed to change when changing streams.
+  uint32_t mStreamSourceID;
+
+public:
+  const nsAutoCString& mMimeType;
+};
+
 } // namespace mozilla
 
 #endif // MediaInfo_h