Bug 1336431: P4. Rename SharedTrackInfo. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 13 Feb 2017 19:18:05 +0100
changeset 483575 485ccfe9c084b63c2d496fabbec8de8000967c4c
parent 483574 e4743fa9af00b8073e348c0f7e004401cc213baf
child 483576 f1fbdc6929133049348faa1bc9dcd08d9850019e
push id45346
push userbmo:jyavenard@mozilla.com
push dateTue, 14 Feb 2017 15:11:15 +0000
reviewersgerald
bugs1336431
milestone54.0a1
Bug 1336431: P4. Rename SharedTrackInfo. r?gerald into TrackInfoSharedPtr to better indicate what this class is about. Adding cast operator to allow transparent conversion from TrackInfoSharedPtr to const TrackInfo* MozReview-Commit-ID: 6RwXl5CG0fG
dom/media/MediaData.h
dom/media/MediaFormatReader.cpp
dom/media/MediaFormatReader.h
dom/media/MediaInfo.h
dom/media/mediasource/TrackBuffersManager.cpp
dom/media/mediasource/TrackBuffersManager.h
dom/media/ogg/OggDemuxer.cpp
dom/media/ogg/OggDemuxer.h
dom/media/webm/WebMDemuxer.cpp
dom/media/webm/WebMDemuxer.h
--- a/dom/media/MediaData.h
+++ b/dom/media/MediaData.h
@@ -23,17 +23,17 @@
 namespace mozilla {
 
 namespace layers {
 class Image;
 class ImageContainer;
 } // namespace layers
 
 class MediaByteBuffer;
-class SharedTrackInfo;
+class TrackInfoSharedPtr;
 
 // AlignedBuffer:
 // Memory allocations are fallibles. Methods return a boolean indicating if
 // memory allocations were successful. Return values should always be checked.
 // AlignedBuffer::mData will be nullptr if no memory has been allocated or if
 // an error occurred during construction.
 // Existing data is only ever modified if new memory allocation has succeeded
 // and preserved if not.
@@ -667,17 +667,17 @@ public:
   // Used by the Vorbis decoder and Ogg demuxer.
   // Indicates that this is the last packet of the stream.
   bool mEOS = false;
 
   // Indicate to the audio decoder that mDiscardPadding frames should be
   // trimmed.
   uint32_t mDiscardPadding = 0;
 
-  RefPtr<SharedTrackInfo> mTrackInfo;
+  RefPtr<TrackInfoSharedPtr> 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;
 
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1753,17 +1753,17 @@ MediaFormatReader::HandleDemuxedSamples(
     return;
   }
 
   LOGV("Giving %s input to decoder", TrackTypeToStr(aTrack));
 
   // Decode all our demuxed frames.
   while (decoder.mQueuedSamples.Length()) {
     RefPtr<MediaRawData> sample = decoder.mQueuedSamples[0];
-    RefPtr<SharedTrackInfo> info = sample->mTrackInfo;
+    RefPtr<TrackInfoSharedPtr> info = sample->mTrackInfo;
 
     if (info && decoder.mLastStreamSourceID != info->GetID()) {
       bool supportRecycling = MediaPrefs::MediaDecoderCheckRecycling()
                               && decoder.mDecoder->SupportDecoderRecycling();
       if (decoder.mNextStreamSourceID.isNothing()
           || decoder.mNextStreamSourceID.ref() != info->GetID()) {
         if (!supportRecycling) {
           LOG("%s stream id has changed from:%d to:%d, draining decoder.",
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -418,17 +418,17 @@ private:
     Atomic<bool> mIsHardwareAccelerated;
     // Sample format monitoring.
     uint32_t mLastStreamSourceID;
     Maybe<uint32_t> mNextStreamSourceID;
     media::TimeIntervals mTimeRanges;
     Maybe<media::TimeUnit> mLastTimeRangesEnd;
     // TrackInfo as first discovered during ReadMetadata.
     UniquePtr<TrackInfo> mOriginalInfo;
-    RefPtr<SharedTrackInfo> mInfo;
+    RefPtr<TrackInfoSharedPtr> mInfo;
     Maybe<media::TimeUnit> mFirstDemuxedSampleTime;
     // Use BlankDecoderModule or not.
     bool mIsBlankDecode;
 
   };
 
   class DecoderDataWithPromise : public DecoderData
   {
--- a/dom/media/MediaInfo.h
+++ b/dom/media/MediaInfo.h
@@ -535,32 +535,37 @@ public:
 
   EncryptionInfo mCrypto;
 
   // The minimum of start times of audio and video tracks.
   // Use to map the zero time on the media timeline to the first frame.
   media::TimeUnit mStartTime;
 };
 
-class SharedTrackInfo
+class TrackInfoSharedPtr
 {
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SharedTrackInfo)
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TrackInfoSharedPtr)
 public:
-  SharedTrackInfo(const TrackInfo& aOriginal, uint32_t aStreamID)
+  TrackInfoSharedPtr(const TrackInfo& aOriginal, uint32_t aStreamID)
     : mInfo(aOriginal.Clone())
     , mStreamSourceID(aStreamID)
     , mMimeType(mInfo->mMimeType)
   {
   }
 
   uint32_t GetID() const
   {
     return mStreamSourceID;
   }
 
+  operator const TrackInfo*() const
+  {
+    return mInfo.get();
+  }
+
   const TrackInfo* operator*() const
   {
     return mInfo.get();
   }
 
   const TrackInfo* operator->() const
   {
     MOZ_ASSERT(mInfo.get(), "dereferencing a UniquePtr containing nullptr");
@@ -578,17 +583,17 @@ public:
   }
 
   const TextInfo* GetAsTextInfo() const
   {
     return mInfo ? mInfo->GetAsTextInfo() : nullptr;
   }
 
 private:
-  ~SharedTrackInfo() { }
+  ~TrackInfoSharedPtr() { }
   UniquePtr<TrackInfo> mInfo;
   // A unique ID, guaranteed to change when changing streams.
   uint32_t mStreamSourceID;
 
 public:
   const nsCString& mMimeType;
 };
 
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -1032,17 +1032,17 @@ TrackBuffersManager::OnDemuxerInitDone(n
       //     2. Set active track flag to true.
       activeTrack = true;
       //   8. Add new audio track to the audioTracks attribute on this SourceBuffer object.
       //   9. Queue a task to fire a trusted event named addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent interface, at the AudioTrackList object referenced by the audioTracks attribute on this SourceBuffer object.
       //   10. Add new audio track to the audioTracks attribute on the HTMLMediaElement.
       //   11. Queue a task to fire a trusted event named addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent interface, at the AudioTrackList object referenced by the audioTracks attribute on the HTMLMediaElement.
       mAudioTracks.mBuffers.AppendElement(TrackBuffer());
       // 10. Add the track description for this track to the track buffer.
-      mAudioTracks.mInfo = new SharedTrackInfo(info.mAudio, streamID);
+      mAudioTracks.mInfo = new TrackInfoSharedPtr(info.mAudio, streamID);
       mAudioTracks.mLastInfo = mAudioTracks.mInfo;
     }
 
     mVideoTracks.mNumTracks = numVideos;
     // 3. For each video track in the initialization segment, run following steps:
     // for (uint32_t i = 0; i < numVideos; i++) {
     if (numVideos) {
       // 1. Let video byte stream track ID be the Track ID for the current track being processed.
@@ -1064,31 +1064,31 @@ TrackBuffersManager::OnDemuxerInitDone(n
       //     2. Set active track flag to true.
       activeTrack = true;
       //   8. Add new video track to the videoTracks attribute on this SourceBuffer object.
       //   9. Queue a task to fire a trusted event named addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent interface, at the VideoTrackList object referenced by the videoTracks attribute on this SourceBuffer object.
       //   10. Add new video track to the videoTracks attribute on the HTMLMediaElement.
       //   11. Queue a task to fire a trusted event named addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent interface, at the VideoTrackList object referenced by the videoTracks attribute on the HTMLMediaElement.
       mVideoTracks.mBuffers.AppendElement(TrackBuffer());
       // 10. Add the track description for this track to the track buffer.
-      mVideoTracks.mInfo = new SharedTrackInfo(info.mVideo, streamID);
+      mVideoTracks.mInfo = new TrackInfoSharedPtr(info.mVideo, streamID);
       mVideoTracks.mLastInfo = mVideoTracks.mInfo;
     }
     // 4. For each text track in the initialization segment, run following steps:
     // 5. If active track flag equals true, then run the following steps:
     // This is handled by SourceBuffer once the promise is resolved.
     if (activeTrack) {
       mActiveTrack = true;
     }
 
     // 6. Set first initialization segment received flag to true.
     mFirstInitializationSegmentReceived = true;
   } else {
-    mAudioTracks.mLastInfo = new SharedTrackInfo(info.mAudio, streamID);
-    mVideoTracks.mLastInfo = new SharedTrackInfo(info.mVideo, streamID);
+    mAudioTracks.mLastInfo = new TrackInfoSharedPtr(info.mAudio, streamID);
+    mVideoTracks.mLastInfo = new TrackInfoSharedPtr(info.mVideo, streamID);
   }
 
   UniquePtr<EncryptionInfo> crypto = mInputDemuxer->GetCrypto();
   if (crypto && crypto->IsEncrypted()) {
     // Try and dispatch 'encrypted'. Won't go if ready state still HAVE_NOTHING.
     for (uint32_t i = 0; i < crypto->mInitDatas.Length(); i++) {
       NS_DispatchToMainThread(
         new DispatchKeyNeededEvent(mParentDecoder, crypto->mInitDatas[i].mInitData,
--- a/dom/media/mediasource/TrackBuffersManager.h
+++ b/dom/media/mediasource/TrackBuffersManager.h
@@ -329,19 +329,19 @@ private:
     // occupied by the coded frames currently stored in the track buffer.
     media::TimeIntervals mBufferedRanges;
     // Sanitized mBufferedRanges with a fuzz of half a sample's duration applied
     // This buffered ranges is the basis of what is exposed to the JS.
     media::TimeIntervals mSanitizedBufferedRanges;
     // Byte size of all samples contained in this track buffer.
     uint32_t mSizeBuffer;
     // TrackInfo of the first metadata received.
-    RefPtr<SharedTrackInfo> mInfo;
+    RefPtr<TrackInfoSharedPtr> mInfo;
     // TrackInfo of the last metadata parsed (updated with each init segment.
-    RefPtr<SharedTrackInfo> mLastInfo;
+    RefPtr<TrackInfoSharedPtr> mLastInfo;
 
     // If set, position of the next sample to be retrieved by GetSample().
     // If the position is equal to the TrackBuffer's length, it indicates that
     // we've reached EOS.
     Maybe<uint32_t> mNextGetSampleIndex;
     // Approximation of the next sample's decode timestamp.
     media::TimeUnit mNextSampleTimecode;
     // Approximation of the next sample's presentation timestamp.
--- a/dom/media/ogg/OggDemuxer.cpp
+++ b/dom/media/ogg/OggDemuxer.cpp
@@ -720,17 +720,17 @@ OggDemuxer::ReadOggChain(const media::Ti
     if (mTimedMetadataEvent) {
       mTimedMetadataEvent->Notify(
         TimedMetadata(mDecodedAudioDuration,
                       Move(tags),
                       nsAutoPtr<MediaInfo>(new MediaInfo(mInfo))));
     }
     // Setup a new TrackInfo so that the MediaFormatReader will flush the
     // current decoder.
-    mSharedAudioTrackInfo = new SharedTrackInfo(mInfo.mAudio, ++sStreamSourceID);
+    mSharedAudioTrackInfo = new TrackInfoSharedPtr(mInfo.mAudio, ++sStreamSourceID);
     return true;
   }
 
   return false;
 }
 
 OggDemuxer::OggStateContext&
 OggDemuxer::OggState(TrackInfo::TrackType aType)
--- a/dom/media/ogg/OggDemuxer.h
+++ b/dom/media/ogg/OggDemuxer.h
@@ -321,17 +321,17 @@ private:
   TimedMetadataEventProducer* mTimedMetadataEvent;
   MediaEventProducer<void>* mOnSeekableEvent;
 
   // This will be populated only if a content change occurs, otherwise it
   // will be left as null so the original metadata is used.
   // It is updated once a chained ogg is encountered.
   // As Ogg chaining is only supported for audio, we only need an audio track
   // info.
-  RefPtr<SharedTrackInfo> mSharedAudioTrackInfo;
+  RefPtr<TrackInfoSharedPtr> mSharedAudioTrackInfo;
 
   friend class OggTrackDemuxer;
 };
 
 class OggTrackDemuxer : public MediaTrackDemuxer
 {
 public:
   OggTrackDemuxer(OggDemuxer* aParent,
--- a/dom/media/webm/WebMDemuxer.cpp
+++ b/dom/media/webm/WebMDemuxer.cpp
@@ -683,17 +683,17 @@ WebMDemuxer::GetNextPacket(TrackInfo::Tr
           // We only look for resolution changes on keyframes for both VP8 and
           // VP9. Other resolution changes are invalid.
           if (mLastSeenFrameWidth.isSome()
               && mLastSeenFrameHeight.isSome()
               && (si.w != mLastSeenFrameWidth.value()
                   || si.h != mLastSeenFrameHeight.value())) {
             mInfo.mVideo.mDisplay = nsIntSize(si.w, si.h);
             mSharedVideoTrackInfo =
-              new SharedTrackInfo(mInfo.mVideo, ++sStreamSourceID);
+              new TrackInfoSharedPtr(mInfo.mVideo, ++sStreamSourceID);
           }
           mLastSeenFrameWidth = Some(si.w);
           mLastSeenFrameHeight = Some(si.h);
         }
       }
     }
 
     WEBM_DEBUG("push sample tstamp: %ld next_tstamp: %ld length: %ld kf: %d",
--- a/dom/media/webm/WebMDemuxer.h
+++ b/dom/media/webm/WebMDemuxer.h
@@ -253,17 +253,17 @@ private:
   // as nestegg only performs 1-byte read at a time.
   int64_t mLastWebMBlockOffset;
   const bool mIsMediaSource;
 
   Maybe<uint32_t> mLastSeenFrameWidth;
   Maybe<uint32_t> mLastSeenFrameHeight;
   // This will be populated only if a resolution change occurs, otherwise it
   // will be left as null so the original metadata is used
-  RefPtr<SharedTrackInfo> mSharedVideoTrackInfo;
+  RefPtr<TrackInfoSharedPtr> mSharedVideoTrackInfo;
 
   EncryptionInfo mCrypto;
 };
 
 class WebMTrackDemuxer : public MediaTrackDemuxer
 {
 public:
   WebMTrackDemuxer(WebMDemuxer* aParent,