зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1678373 - Don't count muted time without an audio track, but start counting time as soon as an audio track is added. r=alwu
Differential Revision: https://phabricator.services.mozilla.com/D126912
This commit is contained in:
Родитель
e71999f002
Коммит
53a1455dd0
|
@ -2,6 +2,7 @@
|
|||
subsuite = media
|
||||
support-files =
|
||||
../gizmo.mp4
|
||||
../gizmo-noaudio.mp4
|
||||
../tone2s-silence4s-tone2s.opus
|
||||
|
||||
[test_accumulated_play_time.html]
|
||||
|
|
|
@ -211,6 +211,67 @@ add_task(async function testHiddenPlayTime() {
|
|||
}
|
||||
});
|
||||
|
||||
add_task(async function testAudioProbesWithoutAudio() {
|
||||
const video = document.createElement('video');
|
||||
video.src = "gizmo-noaudio.mp4";
|
||||
video.loop = true;
|
||||
document.body.appendChild(video);
|
||||
|
||||
info(`all accumulated time should be zero`);
|
||||
const videoChrome = SpecialPowers.wrap(video);
|
||||
await new Promise(r => video.onloadeddata = r);
|
||||
assertValueEqualTo(videoChrome, "totalVideoPlayTime", 0);
|
||||
assertValueEqualTo(videoChrome, "totalAudioPlayTime", 0);
|
||||
assertValueEqualTo(videoChrome, "mutedPlayTime", 0);
|
||||
assertValueEqualTo(videoChrome, "audiblePlayTime", 0);
|
||||
|
||||
info(`start accumulating play time after media starts`);
|
||||
await Promise.all([
|
||||
video.play(),
|
||||
once(video, "moztotalplaytimestarted"),
|
||||
]);
|
||||
|
||||
async function checkInvariants() {
|
||||
await assertValueConstantlyIncreases(videoChrome, "totalVideoPlayTime");
|
||||
assertValueKeptUnchanged(videoChrome, "audiblePlayTime");
|
||||
assertValueKeptUnchanged(videoChrome, "mutedPlayTime");
|
||||
assertValueKeptUnchanged(videoChrome, "totalAudioPlayTime");
|
||||
}
|
||||
|
||||
checkInvariants();
|
||||
|
||||
video.muted = true;
|
||||
|
||||
checkInvariants();
|
||||
|
||||
video.currentTime = 0.0;
|
||||
await once(video, "seeked");
|
||||
|
||||
checkInvariants();
|
||||
|
||||
video.muted = false;
|
||||
|
||||
checkInvariants();
|
||||
|
||||
video.volume = 0.0;
|
||||
|
||||
checkInvariants();
|
||||
|
||||
video.volume = 1.0;
|
||||
|
||||
checkInvariants();
|
||||
|
||||
video.muted = true;
|
||||
|
||||
checkInvariants();
|
||||
|
||||
video.currentTime = 0.0;
|
||||
|
||||
checkInvariants();
|
||||
|
||||
await cleanUpMediaAndCheckTelemetry(video, {hasAudio: false});
|
||||
});
|
||||
|
||||
add_task(async function testMutedAudioPlayTime() {
|
||||
const audio = document.createElement('audio');
|
||||
audio.src = "gizmo.mp4";
|
||||
|
@ -397,16 +458,16 @@ add_task(async function testNoReportedTelemetryResult() {
|
|||
/**
|
||||
* Following are helper functions
|
||||
*/
|
||||
async function cleanUpMediaAndCheckTelemetry(media, { reportExpected = true, hasVideo = true} = {}) {
|
||||
async function cleanUpMediaAndCheckTelemetry(media, { reportExpected = true, hasVideo = true, hasAudio = true} = {}) {
|
||||
media.src = "";
|
||||
await checkReportedTelemetry(media, reportExpected, hasVideo);
|
||||
await checkReportedTelemetry(media, reportExpected, hasVideo, hasAudio);
|
||||
}
|
||||
|
||||
async function assertNoReportedTelemetryResult(media) {
|
||||
await checkReportedTelemetry(media, false, true);
|
||||
await checkReportedTelemetry(media, false, true, true);
|
||||
}
|
||||
|
||||
async function checkReportedTelemetry(media, reportExpected, hasVideo) {
|
||||
async function checkReportedTelemetry(media, reportExpected, hasVideo, hasAudio) {
|
||||
const reportResultPromise = once(media, "mozreportedtelemetry");
|
||||
info(`check telemetry result, reportExpected=${reportExpected}`);
|
||||
if (reportExpected) {
|
||||
|
@ -496,7 +557,7 @@ async function checkReportedTelemetry(media, reportExpected, hasVideo) {
|
|||
ok(reportExpected && entriesNums > 0, `Reported ${key} for ${name}`);
|
||||
}
|
||||
} else {
|
||||
ok(!reportExpected, `No audio telemetry expected, none reported`);
|
||||
ok(!reportExpected || !hasAudio, `No audio telemetry expected, none reported`);
|
||||
}
|
||||
// Avoid to pollute next test task.
|
||||
hist.clear();
|
||||
|
|
|
@ -176,11 +176,21 @@ void TelemetryProbesReporter::OnAudibleChanged(AudibleState aAudibleState) {
|
|||
}
|
||||
|
||||
void TelemetryProbesReporter::OnMutedChanged(bool aMuted) {
|
||||
// There are multiple ways to mute an element:
|
||||
// - volume = 0
|
||||
// - muted = true
|
||||
// - set the enabled property of the playing AudioTrack to false
|
||||
// Muted -> Muted "transisition" can therefore happen, and we can't add
|
||||
// asserts here.
|
||||
AssertOnMainThreadAndNotShutdown();
|
||||
if (!(mMediaContent & MediaContent::MEDIA_HAS_AUDIO)) {
|
||||
return;
|
||||
}
|
||||
LOG("Muted changed, was %s now %s", ToMutedStr(mIsMuted), ToMutedStr(aMuted));
|
||||
if (aMuted) {
|
||||
MOZ_ASSERT(!mIsMuted);
|
||||
StartMutedAudioTimeAccumulator();
|
||||
if (!mMutedAudioPlayTime.IsStarted()) {
|
||||
StartMutedAudioTimeAccumulator();
|
||||
}
|
||||
} else {
|
||||
// This happens when starting playback, no need to pause, because it hasn't
|
||||
// been started yet.
|
||||
|
@ -215,6 +225,9 @@ void TelemetryProbesReporter::OnMediaContentChanged(MediaContent aContent) {
|
|||
if (mInaudibleAudioPlayTime.IsStarted()) {
|
||||
mInaudibleAudioPlayTime.Pause();
|
||||
}
|
||||
if (mMutedAudioPlayTime.IsStarted()) {
|
||||
mMutedAudioPlayTime.Pause();
|
||||
}
|
||||
}
|
||||
if (!(mMediaContent & MediaContent::MEDIA_HAS_VIDEO) &&
|
||||
aContent & MediaContent::MEDIA_HAS_VIDEO) {
|
||||
|
@ -231,6 +244,9 @@ void TelemetryProbesReporter::OnMediaContentChanged(MediaContent aContent) {
|
|||
LOG("Audio track added to media.");
|
||||
if (mIsPlaying) {
|
||||
mTotalAudioPlayTime.Start();
|
||||
if (mIsMuted) {
|
||||
StartMutedAudioTimeAccumulator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче