Bug 1343437 - MP4Demuxer rejects InitPromise is there is no valid track - r?jya draft
authorGerald Squelart <gsquelart@mozilla.com>
Mon, 27 Feb 2017 10:11:07 +1100
changeset 491780 23a33eaff992505a4fc311f322655359f738d357
parent 491779 eba9c52494943a2f39476d4ddcd087646ff6e326
child 491781 18a8bb9e36042de7e9b94b9d48bb4b588a00cb9d
push id47417
push usergsquelart@mozilla.com
push dateThu, 02 Mar 2017 07:58:48 +0000
reviewersjya
bugs1343437
milestone54.0a1
Bug 1343437 - MP4Demuxer rejects InitPromise is there is no valid track - r?jya An easy check that the MP4Demuxer::Init can do, is to ensure that there is at least one valid track. Note that the caller may itself do similar checks, but they are currently only looking at the first track of each type, so this check here adds a bit more information ("*no* valid tracks" vs "no valid *first* tracks"). MozReview-Commit-ID: 7JCcGjRUQAM
dom/media/fmp4/MP4Demuxer.cpp
--- a/dom/media/fmp4/MP4Demuxer.cpp
+++ b/dom/media/fmp4/MP4Demuxer.cpp
@@ -144,16 +144,18 @@ MP4Demuxer::Init()
   auto videoTrackCount = metadata.GetNumberTracks(TrackInfo::kVideoTrack);
   if (audioTrackCount == 0 && videoTrackCount == 0) {
     return InitPromise::CreateAndReject(
       MediaResult(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
                   RESULT_DETAIL("No MP4 audio or video tracks")),
       __func__);
   }
 
+  int totalValidTracks = 0;
+
   if (audioTrackCount != 0) {
     mAudioDemuxers.SetLength(audioTrackCount);
     for (size_t i = 0; i < audioTrackCount; i++) {
       UniquePtr<TrackInfo> info =
         metadata.GetTrackInfo(TrackInfo::kAudioTrack, i);
       if (!info) {
         if (result == NS_OK) {
           result = MediaResult(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
@@ -166,16 +168,17 @@ MP4Demuxer::Init()
         if (result == NS_OK) {
           result =
             MediaResult(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
                         RESULT_DETAIL("Invalid MP4 audio track index list"));
         }
         continue;
       }
       mAudioDemuxers[i] = new MP4TrackDemuxer(this, Move(info), indices);
+      totalValidTracks++;
     }
   }
 
   if (videoTrackCount != 0) {
     mVideoDemuxers.SetLength(videoTrackCount);
     for (size_t i = 0; i < videoTrackCount; i++) {
       UniquePtr<TrackInfo> info =
         metadata.GetTrackInfo(TrackInfo::kVideoTrack, i);
@@ -191,19 +194,27 @@ MP4Demuxer::Init()
         if (result == NS_OK) {
           result =
             MediaResult(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
                         RESULT_DETAIL("Invalid MP4 video track index list"));
         }
         continue;
       }
       mVideoDemuxers[i] = new MP4TrackDemuxer(this, Move(info), indices);
+      totalValidTracks++;
     }
   }
 
+  if (totalValidTracks == 0) {
+    return InitPromise::CreateAndReject(
+      MediaResult(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
+                  RESULT_DETAIL("No valid MP4 audio or video tracks")),
+      __func__);
+  }
+
   const mp4_demuxer::CryptoFile& cryptoFile = metadata.Crypto();
   if (cryptoFile.valid) {
     const nsTArray<mp4_demuxer::PsshInfo>& psshs = cryptoFile.pssh;
     for (uint32_t i = 0; i < psshs.Length(); i++) {
       mCryptoInitData.AppendElements(psshs[i].data);
     }
   }