Bug 1454630 - P1. Simplify retrieval of current TrackInfo. r=bryce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Sat, 26 May 2018 21:21:45 +0200
changeset 420215 7c444cd068b2e472a18370fec2896ebd54ebd518
parent 420214 d52331db3c626c875de7c4b8fe57d24f36f2cb87
child 420216 16a0b5cfca59ecc2fc5f5c8f8d5decf7d7e37ed6
push id34068
push usernerli@mozilla.com
push dateTue, 29 May 2018 21:40:19 +0000
treeherdermozilla-central@5852258260e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbryce
bugs1454630
milestone62.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 1454630 - P1. Simplify retrieval of current TrackInfo. r=bryce Adding some documentation to clarify on the difference between mInfo and mOriginalInfo MozReview-Commit-ID: DWBsoi16QKf
dom/media/MediaFormatReader.cpp
dom/media/MediaFormatReader.h
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -814,35 +814,32 @@ MediaFormatReader::DecoderFactory::DoCre
   // initialized to a fatal error by default.
   MediaResult result = MediaResult(
     NS_ERROR_DOM_MEDIA_FATAL_ERR,
     nsPrintfCString("error creating %s decoder", TrackTypeToStr(aData.mTrack)));
 
   switch (aData.mTrack) {
     case TrackInfo::kAudioTrack: {
       aData.mDecoder = mOwner->mPlatform->CreateDecoder({
-        ownerData.mInfo
-        ? *ownerData.mInfo->GetAsAudioInfo()
-        : *ownerData.mOriginalInfo->GetAsAudioInfo(),
+        *ownerData.GetCurrentInfo()->GetAsAudioInfo(),
         ownerData.mTaskQueue,
         mOwner->mCrashHelper,
         CreateDecoderParams::UseNullDecoder(ownerData.mIsNullDecode),
         &result,
         TrackInfo::kAudioTrack,
         &mOwner->OnTrackWaitingForKeyProducer()
       });
       break;
     }
 
     case TrackType::kVideoTrack: {
       // Decoders use the layers backend to decide if they can use hardware decoding,
       // so specify LAYERS_NONE if we want to forcibly disable it.
       aData.mDecoder = mOwner->mPlatform->CreateDecoder(
-        { ownerData.mInfo ? *ownerData.mInfo->GetAsVideoInfo()
-                          : *ownerData.mOriginalInfo->GetAsVideoInfo(),
+        { *ownerData.GetCurrentInfo()->GetAsVideoInfo(),
           ownerData.mTaskQueue,
           mOwner->mKnowsCompositor,
           mOwner->GetImageContainer(),
           mOwner->mCrashHelper,
           CreateDecoderParams::UseNullDecoder(ownerData.mIsNullDecode),
           &result,
           TrackType::kVideoTrack,
           &mOwner->OnTrackWaitingForKeyProducer(),
@@ -3512,39 +3509,43 @@ void
 MediaFormatReader::GetMozDebugReaderData(nsACString& aString)
 {
   nsCString result;
   nsAutoCString audioDecoderName("unavailable");
   nsAutoCString videoDecoderName = audioDecoderName;
   nsAutoCString audioType("none");
   nsAutoCString videoType("none");
 
-  if (HasAudio()) {
+  AudioInfo audioInfo = mAudio.GetCurrentInfo()
+                          ? *mAudio.GetCurrentInfo()->GetAsAudioInfo()
+                          : AudioInfo();
+  if (HasAudio())
+  {
     MutexAutoLock lock(mAudio.mMutex);
     audioDecoderName = mAudio.mDecoder
                        ? mAudio.mDecoder->GetDescriptionName()
                        : mAudio.mDescription;
-    audioType = mAudio.mInfo ? mAudio.mInfo->mMimeType : mInfo.mAudio.mMimeType;
+    audioType = audioInfo.mMimeType;
   }
+  VideoInfo videoInfo = mVideo.GetCurrentInfo()
+                          ? *mVideo.GetCurrentInfo()->GetAsVideoInfo()
+                          : VideoInfo();
   if (HasVideo()) {
     MutexAutoLock mon(mVideo.mMutex);
     videoDecoderName = mVideo.mDecoder
                        ? mVideo.mDecoder->GetDescriptionName()
                        : mVideo.mDescription;
-    videoType = mVideo.mInfo ? mVideo.mInfo->mMimeType : mInfo.mVideo.mMimeType;
+    videoType = videoInfo.mMimeType;
   }
 
   result +=
     nsPrintfCString("Audio Decoder(%s, %u channels @ %0.1fkHz): %s\n",
                     audioType.get(),
-                    mAudio.mInfo ? mAudio.mInfo->GetAsAudioInfo()->mChannels
-                                 : mInfo.mAudio.mChannels,
-                    (mAudio.mInfo ? mAudio.mInfo->GetAsAudioInfo()->mRate
-                                  : mInfo.mAudio.mRate) /
-                      1000.0f,
+                    audioInfo.mChannels,
+                    audioInfo.mRate / 1000.0f,
                     audioDecoderName.get());
   result += nsPrintfCString("Audio Frames Decoded: %" PRIu64 "\n",
                             mAudio.mNumSamplesOutputTotal);
   if (HasAudio()) {
     result += nsPrintfCString(
       "Audio State: ni=%d no=%d wp=%d demuxr=%d demuxq=%u decoder=%d tt=%.1f "
       "tths=%d in=%" PRIu64 " out=%" PRIu64
       " qs=%u pending=%u wfd=%d eos=%d ds=%d wfk=%d sid=%u\n",
@@ -3563,22 +3564,16 @@ MediaFormatReader::GetMozDebugReaderData
       unsigned(mAudio.mOutput.Length()),
       mAudio.mWaitingForData,
       mAudio.mDemuxEOS,
       int32_t(mAudio.mDrainState),
       mAudio.mWaitingForKey,
       mAudio.mLastStreamSourceID);
   }
 
-  VideoInfo videoInfo = mVideo.mInfo
-                        ? *mVideo.mInfo->GetAsVideoInfo()
-                        : mVideo.mOriginalInfo
-                          ? *mVideo.mOriginalInfo->GetAsVideoInfo()
-                          : VideoInfo();
-
   result += nsPrintfCString(
     "Video Decoder(%s, %dx%d @ %0.2f): %s\n",
     videoType.get(),
     videoInfo.mDisplay.width < 0 ? 0 : videoInfo.mDisplay.width,
     videoInfo.mDisplay.height < 0 ? 0 : videoInfo.mDisplay.height,
     mVideo.mMeanRate.Mean(),
     videoDecoderName.get());
 
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -571,16 +571,28 @@ private:
       }
     }
 
     bool HasInternalSeekPending() const
     {
       return mTimeThreshold && !mTimeThreshold.ref().mHasSeeked;
     }
 
+    // Return the current TrackInfo in the stream. If the stream content never
+    // changed since AsyncReadMetadata was called then the TrackInfo used is
+    // mOriginalInfo, other it will be mInfo. The later case is only ever true
+    // with MSE or the WebMDemuxer.
+    const TrackInfo* GetCurrentInfo() const
+    {
+      if (mInfo) {
+        return *mInfo;
+      }
+      return mOriginalInfo.get();
+    }
+
     // Used by the MDSM for logging purposes.
     Atomic<size_t> mSizeOfQueue;
     // Used by the MDSM to determine if video decoding is hardware accelerated.
     // This value is updated after a frame is successfully decoded.
     Atomic<bool> mIsHardwareAccelerated;
     // Sample format monitoring.
     uint32_t mLastStreamSourceID;
     Maybe<uint32_t> mNextStreamSourceID;