mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-03 23:30:46 +00:00
Bug 1584959 - Avoid calling the converter if the conversion is not possible. r=bryce
Differential Revision: https://phabricator.services.mozilla.com/D56736
This commit is contained in:
parent
b0f1299b3f
commit
4c1d0136c9
@ -21,14 +21,8 @@ namespace mozilla {
|
||||
|
||||
AudioConverter::AudioConverter(const AudioConfig& aIn, const AudioConfig& aOut)
|
||||
: mIn(aIn), mOut(aOut), mResampler(nullptr) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(
|
||||
aIn.Format() == aOut.Format() && aIn.Interleaved() == aOut.Interleaved(),
|
||||
"No format or rate conversion is supported at this stage");
|
||||
MOZ_DIAGNOSTIC_ASSERT(
|
||||
aOut.Channels() <= 2 || aIn.Channels() == aOut.Channels(),
|
||||
"Only down/upmixing to mono or stereo is supported at this stage");
|
||||
MOZ_DIAGNOSTIC_ASSERT(aOut.Interleaved(),
|
||||
"planar audio format not supported");
|
||||
MOZ_DIAGNOSTIC_ASSERT(CanConvert(aIn, aOut),
|
||||
"The conversion is not supported");
|
||||
mIn.Layout().MappingTable(mOut.Layout(), &mChannelOrderMap);
|
||||
if (aIn.Rate() != aOut.Rate()) {
|
||||
RecreateResampler();
|
||||
@ -42,6 +36,25 @@ AudioConverter::~AudioConverter() {
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioConverter::CanConvert(const AudioConfig& aIn,
|
||||
const AudioConfig& aOut) {
|
||||
if (aIn.Format() != aOut.Format() ||
|
||||
aIn.Interleaved() != aOut.Interleaved()) {
|
||||
NS_WARNING("No format conversion is supported at this stage");
|
||||
return false;
|
||||
}
|
||||
if (aIn.Channels() != aOut.Channels() && aOut.Channels() > 2) {
|
||||
NS_WARNING(
|
||||
"Only down/upmixing to mono or stereo is supported at this stage");
|
||||
return false;
|
||||
}
|
||||
if (!aOut.Interleaved()) {
|
||||
NS_WARNING("planar audio format not supported");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AudioConverter::CanWorkInPlace() const {
|
||||
bool needDownmix = mIn.Channels() > mOut.Channels();
|
||||
bool needUpmix = mIn.Channels() < mOut.Channels();
|
||||
|
@ -233,6 +233,7 @@ class AudioConverter {
|
||||
bool CanReorderAudio() const {
|
||||
return mIn.Layout().MappingTable(mOut.Layout());
|
||||
}
|
||||
static bool CanConvert(const AudioConfig& aIn, const AudioConfig& aOut);
|
||||
|
||||
const AudioConfig& InputConfig() const { return mIn; }
|
||||
const AudioConfig& OutputConfig() const { return mOut; }
|
||||
|
@ -398,9 +398,15 @@ void AudioSink::NotifyAudioNeeded() {
|
||||
mOutputChannels == data->mChannels
|
||||
? inputLayout
|
||||
: AudioConfig::ChannelLayout(mOutputChannels);
|
||||
mConverter = MakeUnique<AudioConverter>(
|
||||
AudioConfig(inputLayout, data->mChannels, data->mRate),
|
||||
AudioConfig(outputLayout, mOutputChannels, mOutputRate));
|
||||
AudioConfig inConfig =
|
||||
AudioConfig(inputLayout, data->mChannels, data->mRate);
|
||||
AudioConfig outConfig =
|
||||
AudioConfig(outputLayout, mOutputChannels, mOutputRate);
|
||||
if (!AudioConverter::CanConvert(inConfig, outConfig)) {
|
||||
mErrored = true;
|
||||
return;
|
||||
}
|
||||
mConverter = MakeUnique<AudioConverter>(inConfig, outConfig);
|
||||
}
|
||||
|
||||
// See if there's a gap in the audio. If there is, push silence into the
|
||||
|
Loading…
x
Reference in New Issue
Block a user