mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-27 05:00:13 -10:00
Bug 2035059 - Don't latch Infinity in ADTS demuxer mInfo->mDuration r=alwu,media-playback-reviewers
ADTSTrackDemuxer::Init has the same shape as the MP3 case fixed in the preceding commit: when StreamLength() is unknown, Duration() returns TimeUnit::FromInfinity(), and writing that into mInfo->mDuration propagates Some(Infinity) into mInfo.mMetadataDuration in MediaFormatReader. OnMetadataRead in the state machine then clobbers any finite mDuration that BufferedRangeUpdated has already produced. Only assign mInfo->mDuration when Duration() returns a finite value, so mInfo.mMetadataDuration stays unset and the buffered-ranges-driven duration update isn't overwritten. The mochitest is the analog of test_mp3_dataurl_duration.html for ADTS. The byte-size-divided-by-average-frame-length estimate the demuxer uses is ~8% off for variable-rate AAC, so the tolerance is wide; this test's job is to catch the Infinity-latching regression, not the unrelated estimation accuracy. Wave and Flac don't share this shape: WaveDemuxer reads mDataLength from the data chunk header at init and Duration() returns a finite value regardless of stream length; FlacTrackDemuxer::Duration returns max(parsed-frame-duration, info.mDuration), neither of which is ever Infinity. Differential Revision: https://phabricator.services.mozilla.com/D297230
This commit is contained in:
1 parent
68d577da6d
commit
11606654c8
4 files changed
+57
-1
No files matched your search
@@ -110,7 +110,15 @@ bool ADTSTrackDemuxer::Init() {
|
||||
mInfo->mRate = mSamplesPerSecond;
|
||||
mInfo->mChannels = mChannels;
|
||||
mInfo->mBitDepth = 16;
|
||||
mInfo->mDuration = Duration();
|
||||
// If the resource length isn't known yet, Duration() returns Infinity. We
|
||||
// don't want that latched into mInfo, because MediaFormatReader would then
|
||||
// populate mInfo.mMetadataDuration with Infinity and the state machine's
|
||||
// OnMetadataRead would clobber any finite duration BufferedRangeUpdated
|
||||
// produces from buffered ranges. See bug 2035059.
|
||||
if (auto duration = Duration();
|
||||
duration.IsValid() && !duration.IsInfinite()) {
|
||||
mInfo->mDuration = duration;
|
||||
}
|
||||
|
||||
// AAC Specific information
|
||||
mInfo->mMimeType = "audio/mp4a-latm";
|
||||
|
||||
Binary file not shown.
@@ -38,6 +38,7 @@ support-files = [
|
||||
"320x240.webm",
|
||||
"VID_0001.ogg",
|
||||
"VID_0001.ogg^headers^",
|
||||
"adts-cbr.aac",
|
||||
"allowed.sjs",
|
||||
"ambisonics.mp4",
|
||||
"ambisonics.mp4^headers^",
|
||||
@@ -875,6 +876,8 @@ skip-if = [
|
||||
"os == 'mac' && os_version == '10.15' && arch == 'x86_64' && mda_gpu", # Bug 1942396
|
||||
]
|
||||
|
||||
["test_adts_dataurl_duration.html"]
|
||||
|
||||
["test_mp3_broadcast.html"]
|
||||
|
||||
["test_mp3_dataurl_duration.html"]
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bug 2035059 - ADTS duration via data: URL</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<audio id="a"></audio>
|
||||
<script>
|
||||
// ADTS has no per-stream duration in the header, so the demuxer estimates
|
||||
// it from the resource length and falls into the same Infinity-latching
|
||||
// path as plain CBR mp3 when the resource length isn't reported up front.
|
||||
const SRC = "adts-cbr.aac";
|
||||
const EXPECTED = 14.789872;
|
||||
|
||||
add_task(async function test_adts_dataurl_duration() {
|
||||
const blob = await fetch(SRC).then(r => r.blob());
|
||||
const dataUrl = await new Promise(resolve => {
|
||||
const fr = new FileReader();
|
||||
fr.onload = () => resolve(fr.result);
|
||||
fr.readAsDataURL(blob);
|
||||
});
|
||||
|
||||
const audio = document.getElementById("a");
|
||||
audio.src = dataUrl;
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
audio.addEventListener("canplaythrough", resolve, { once: true });
|
||||
audio.addEventListener("error", () => reject(audio.error), { once: true });
|
||||
});
|
||||
|
||||
// The ADTS demuxer extrapolates duration from a small sample of frame
|
||||
// sizes, so the result for variable-rate AAC drifts ~8%. Allow a wide
|
||||
// tolerance: this test's job is to catch the Infinity-latching regression,
|
||||
// not the unrelated estimation accuracy.
|
||||
ok(Number.isFinite(audio.duration),
|
||||
"data: URL ADTS duration should be finite, got " + audio.duration);
|
||||
ok(Math.abs(audio.duration - EXPECTED) / EXPECTED < 0.15,
|
||||
"data: URL ADTS duration should be within 15% of " + EXPECTED + "s, got " +
|
||||
audio.duration);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user