Bug 1630569 - Change the limit at which audio is muted with high or low playback rates, and make it and other parameters configurable via prefs. r=alwu

Differential Revision: https://phabricator.services.mozilla.com/D135066
This commit is contained in:
Paul Adenot 2022-01-05 18:11:58 +00:00
Родитель a38481e074
Коммит b980ff2250
4 изменённых файлов: 57 добавлений и 15 удалений

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

@ -181,12 +181,6 @@ static const uint32_t STALL_MS = 3000;
static const double MIN_PLAYBACKRATE = 1.0 / 16; static const double MIN_PLAYBACKRATE = 1.0 / 16;
// Maximum playbackRate for a media // Maximum playbackRate for a media
static const double MAX_PLAYBACKRATE = 16.0; static const double MAX_PLAYBACKRATE = 16.0;
// These are the limits beyonds which SoundTouch does not perform too well and
// when speech is hard to understand anyway. Threshold above which audio is
// muted
static const double THRESHOLD_HIGH_PLAYBACKRATE_AUDIO = 4.0;
// Threshold under which audio is muted
static const double THRESHOLD_LOW_PLAYBACKRATE_AUDIO = 0.25;
static double ClampPlaybackRate(double aPlaybackRate) { static double ClampPlaybackRate(double aPlaybackRate) {
MOZ_ASSERT(aPlaybackRate >= 0.0); MOZ_ASSERT(aPlaybackRate >= 0.0);
@ -6763,10 +6757,10 @@ void HTMLMediaElement::SetPlaybackRate(double aPlaybackRate, ErrorResult& aRv) {
} }
mPlaybackRate = aPlaybackRate; mPlaybackRate = aPlaybackRate;
// Playback rate threshold above which audio is muted.
uint32_t threshold = StaticPrefs::media_audio_playbackrate_muting_threshold();
if (mPlaybackRate != 0.0 && if (mPlaybackRate != 0.0 &&
(mPlaybackRate > THRESHOLD_HIGH_PLAYBACKRATE_AUDIO || (mPlaybackRate > threshold || mPlaybackRate < 1. / threshold)) {
mPlaybackRate < THRESHOLD_LOW_PLAYBACKRATE_AUDIO)) {
SetMutedInternal(mMuted | MUTED_BY_INVALID_PLAYBACK_RATE); SetMutedInternal(mMuted | MUTED_BY_INVALID_PLAYBACK_RATE);
} else { } else {
SetMutedInternal(mMuted & ~MUTED_BY_INVALID_PLAYBACK_RATE); SetMutedInternal(mMuted & ~MUTED_BY_INVALID_PLAYBACK_RATE);

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

@ -28,6 +28,7 @@
#include "Tracing.h" #include "Tracing.h"
#include "webaudio/blink/DenormalDisabler.h" #include "webaudio/blink/DenormalDisabler.h"
#include "AudioThreadRegistry.h" #include "AudioThreadRegistry.h"
#include "mozilla/StaticPrefs_media.h"
// Use abort() instead of exception in SoundTouch. // Use abort() instead of exception in SoundTouch.
#define ST_NO_EXCEPTION_HANDLING 1 #define ST_NO_EXCEPTION_HANDLING 1
@ -178,9 +179,15 @@ nsresult AudioStream::EnsureTimeStretcherInitializedUnlocked() {
// We are going to use a smaller 10ms sequence size to improve speech // We are going to use a smaller 10ms sequence size to improve speech
// clarity, giving more resolution at high tempo and less reverb at low // clarity, giving more resolution at high tempo and less reverb at low
// tempo. Maintain 15ms seekwindow and 8ms overlap for smoothness. // tempo. Maintain 15ms seekwindow and 8ms overlap for smoothness.
mTimeStretcher->setSetting(SETTING_SEQUENCE_MS, 10); mTimeStretcher->setSetting(
mTimeStretcher->setSetting(SETTING_SEEKWINDOW_MS, 15); SETTING_SEQUENCE_MS,
mTimeStretcher->setSetting(SETTING_OVERLAP_MS, 8); StaticPrefs::media_audio_playbackrate_soundtouch_sequence_ms());
mTimeStretcher->setSetting(
SETTING_SEEKWINDOW_MS,
StaticPrefs::media_audio_playbackrate_soundtouch_seekwindow_ms());
mTimeStretcher->setSetting(
SETTING_OVERLAP_MS,
StaticPrefs::media_audio_playbackrate_soundtouch_overlap_ms());
} }
return NS_OK; return NS_OK;
} }

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

@ -6,6 +6,7 @@
#include "MediaData.h" #include "MediaData.h"
#include "mozilla/ScopeExit.h" #include "mozilla/ScopeExit.h"
#include "mozilla/StaticPrefs_media.h"
#include "Tracing.h" #include "Tracing.h"
// Use abort() instead of exception in SoundTouch. // Use abort() instead of exception in SoundTouch.
@ -638,9 +639,15 @@ void AudioDecoderInputTrack::EnsureTimeStretcher() {
// We are going to use a smaller 10ms sequence size to improve speech // We are going to use a smaller 10ms sequence size to improve speech
// clarity, giving more resolution at high tempo and less reverb at low // clarity, giving more resolution at high tempo and less reverb at low
// tempo. Maintain 15ms seekwindow and 8ms overlap for smoothness. // tempo. Maintain 15ms seekwindow and 8ms overlap for smoothness.
mTimeStretcher->setSetting(SETTING_SEQUENCE_MS, 10); mTimeStretcher->setSetting(
mTimeStretcher->setSetting(SETTING_SEEKWINDOW_MS, 15); SETTING_SEQUENCE_MS,
mTimeStretcher->setSetting(SETTING_OVERLAP_MS, 8); StaticPrefs::media_audio_playbackrate_soundtouch_sequence_ms());
mTimeStretcher->setSetting(
SETTING_SEEKWINDOW_MS,
StaticPrefs::media_audio_playbackrate_soundtouch_seekwindow_ms());
mTimeStretcher->setSetting(
SETTING_OVERLAP_MS,
StaticPrefs::media_audio_playbackrate_soundtouch_overlap_ms());
SetTempoAndRateForTimeStretcher(); SetTempoAndRateForTimeStretcher();
LOG("Create TimeStretcher (channel=%d, playbackRate=%f, preservePitch=%d)", LOG("Create TimeStretcher (channel=%d, playbackRate=%f, preservePitch=%d)",
GetChannelCountForTimeStretcher(), mPlaybackRate, mPreservesPitch); GetChannelCountForTimeStretcher(), mPlaybackRate, mPreservesPitch);

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

@ -9236,6 +9236,40 @@
mirror: always mirror: always
#endif #endif
# When the playback rate of an HTMLMediaElement is greater than this value, or
# lower than the inverse of this value, the audio is muted.
- name: media.audio.playbackrate.muting_threshold
type: uint32_t
value: 8
mirror: always
# Time-stretch algorithm single processing sequence length in milliseconds.
# This determines to how long sequences the original sound is chopped in the
# time-stretch algorithm.
- name: media.audio.playbackrate.soundtouch_sequence_ms
type: RelaxedAtomicInt32
value: 10
mirror: always
# Time-stretch algorithm seeking window length in milliseconds for algorithm
# that finds the best possible overlapping location. This determines from how
# wide window the algorithm may look for an optimal joining location when mixing
# the sound sequences back together.
- name: media.audio.playbackrate.soundtouch_seekwindow_ms
type: RelaxedAtomicInt32
value: 15
mirror: always
# Time-stretch algorithm overlap length in milliseconds. When the chopped sound
# sequences are mixed back together, to form a continuous sound stream, this
# parameter defines over how long period the two consecutive sequences are let
# to overlap each other.
- name: media.audio.playbackrate.soundtouch_overlap_ms
type: RelaxedAtomicInt32
value: 8
mirror: always
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# Prefs starting with "midi." # Prefs starting with "midi."
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------