Bug 1694085 - Add a test that verifies that HE-AAC plays back correctly including higher frequency content both with MSE and HTTP playback. r=bryce

Depends on D128895

Differential Revision: https://phabricator.services.mozilla.com/D128907
This commit is contained in:
Paul Adenot 2021-10-21 16:18:19 +00:00
Родитель 4fd578ef5e
Коммит 80684c0e5a
3 изменённых файлов: 91 добавлений и 0 удалений

Просмотреть файл

@ -55,6 +55,7 @@ support-files =
wmf_mismatchedaudiotime.mp4
bug1718709_low_res.mp4
bug1718709_high_res.mp4
whitenoise-he-aac-5s.mp4
[test_AbortAfterPartialMediaSegment.html]
[test_AppendPartialInitSegment.html]
@ -85,6 +86,7 @@ skip-if = os == 'win' # bug 1487973,
(os == 'mac') # mac due to bug 1487973
[test_HaveMetadataUnbufferedSeek.html]
[test_HaveMetadataUnbufferedSeek_mp4.html]
[test_HEAAC_extradata.html]
[test_LiveSeekable.html]
[test_LoadedDataFired_mp4.html]
[test_LoadedMetadataFired.html]

Просмотреть файл

@ -0,0 +1,89 @@
<!DOCTYPE HTML>
<html>
<head>
<title>HE-AAC decoding test</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="mediasource.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
const SOURCE_FILE = "whitenoise-he-aac-5s.mp4";
// This test checks when decoding HE-AAC using MediaSource or HTTP playback, the
// audio is decoded correctly (in particular with the SBR part). This means
// that the extradata describing the encoded AAC stream have been communicated
// correctly to the audio decoder. For this, we check that there is energy
// above 10kHz using the Web Audio API when playing white noise, which has
// maximum energy accross the audible spectrum.
// Return the index corresponding for a particular frequency in an array
// containing frequency data from a FFT.
function binIndexForFrequency(frequency, fftSize, sampleRate) {
return (1 + Math.round((frequency * fftSize) / sampleRate));
}
async function checkHighFrequencyContent(element) {
const ac = new AudioContext();
await ac.resume();
const mediaElementSource = ac.createMediaElementSource(element);
const analyser = new AnalyserNode(ac);
// Undo the volume scaling applied globally during test. This is fine because
// the audio isn't routed to an actual audio output device in this test, it's
// just analyzed with the Web Audio API.
const gain = new GainNode(ac);
const testVolumeScaling =
parseFloat(SpecialPowers.getCharPref("media.volume_scale"));
gain.gain.value = 1 / parseFloat(testVolumeScaling);
mediaElementSource.connect(gain).connect(analyser)
const spectrum = new Float32Array(analyser.frequencyBinCount);
const indexFor15kHz =
binIndexForFrequency(15000, analyser.fftSize, ac.sampleRate);
// Wait a few hundreds of milliseconds
while (!element.ended) {
await once(element, "timeupdate");
analyser.getFloatFrequencyData(spectrum);
if (spectrum[indexFor15kHz] > -50) {
ok(spectrum[indexFor15kHz] > -50,
`Energy present at 15kHz (bin index: ${indexFor15kHz}) when playing white noise encoded in HE-AAC ${spectrum[indexFor15kHz]}`);
return;
}
}
ok(false,
`No energy present at 15kHz (bin index: ${indexFor15kHz}) when playing white noise encoded in HE-AAC (last value ${spectrum[indexFor15kHz]})`);
}
runWithMSE(async (ms, el) => {
// First check with MSE playback
el.controls = true;
await once(ms, "sourceopen");
const audiosb = ms.addSourceBuffer('audio/mp4; codecs="mp4a.40.5"');
await fetchAndLoad(audiosb, SOURCE_FILE, [""], "");
ms.endOfStream();
el.play();
once(el, "playing");
await checkHighFrequencyContent(el);
// Redo the same test, with HTTP playback
el.src = SOURCE_FILE;
el.play();
once(el, "playing");
await checkHighFrequencyContent(el);
SimpleTest.finish();
});
</script>
</pre>
</body>
</html>

Двоичные данные
dom/media/mediasource/test/whitenoise-he-aac-5s.mp4 Normal file

Двоичный файл не отображается.