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
--- 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);
}
}