Remove automatic audio configuration permanently due to brokenness and allow renderers to request reinitialization on demand

This commit is contained in:
Cameron Gutman
2018-10-02 01:21:42 -07:00
parent a614a693e5
commit 3dc049ee5f
10 changed files with 52 additions and 121 deletions
@@ -74,14 +74,14 @@ bool PortAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION*
return true;
}
void PortAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
bool PortAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
{
SDL_assert(audioSize == SAMPLES_PER_FRAME * m_ChannelCount * 2);
// Check if there is space for this sample in the buffer. Again, this can race
// but in the worst case, we'll not see the sample callback having consumed a sample.
if (((m_WriteIndex + 1) % CIRCULAR_BUFFER_SIZE) == m_ReadIndex) {
return;
return true;
}
SDL_memcpy(&m_AudioBuffer[m_WriteIndex * CIRCULAR_BUFFER_STRIDE], audioBuffer, audioSize);
@@ -102,33 +102,13 @@ void PortAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Pa_StartStream() failed: %s",
Pa_GetErrorText(error));
return;
return false;
}
m_Started = true;
}
}
int PortAudioRenderer::detectAudioConfiguration() const
{
const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(Pa_GetDefaultOutputDevice());
if (deviceInfo == nullptr) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Pa_GetDeviceInfo() failed");
return false;
}
// PulseAudio reports max output channels that don't
// correspond to any output devices (32 channels), so
// only use 5.1 surround sound if the output channel count
// is reasonable. Additionally, PortAudio doesn't do remixing
// for quadraphonic, so only use 5.1 if we have 6 or more channels.
if (deviceInfo->maxOutputChannels == 6 || deviceInfo->maxOutputChannels == 8) {
return AUDIO_CONFIGURATION_51_SURROUND;
}
else {
return AUDIO_CONFIGURATION_STEREO;
}
return true;
}
int PortAudioRenderer::paStreamCallback(const void*, void* output, unsigned long frameCount, const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags, void* userData)
@@ -18,9 +18,7 @@ public:
virtual bool prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* opusConfig);
virtual void submitAudio(short* audioBuffer, int audioSize);
virtual int detectAudioConfiguration() const;
virtual bool submitAudio(short* audioBuffer, int audioSize);
static int paStreamCallback(const void *input,
void *output,
+2 -3
View File
@@ -12,7 +12,6 @@ public:
virtual bool prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* opusConfig) = 0;
virtual void submitAudio(short* audioBuffer, int audioSize) = 0;
virtual int detectAudioConfiguration() const = 0;
// Return false if an unrecoverable error has occurred and the renderer must be reinitialized
virtual bool submitAudio(short* audioBuffer, int audioSize) = 0;
};
+1 -3
View File
@@ -17,9 +17,7 @@ public:
virtual bool prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* opusConfig);
virtual void submitAudio(short* audioBuffer, int audioSize);
virtual int detectAudioConfiguration() const;
virtual bool submitAudio(short* audioBuffer, int audioSize);
private:
SDL_AudioDeviceID m_AudioDevice;
+5 -44
View File
@@ -10,47 +10,6 @@
#define STOP_THE_WORLD_LIMIT 20
#define DROP_RATIO_DENOM 32
// This isn't accurate on macOS and Linux (PulseAudio),
// since they both report supporting a large number of
// channels, regardless of the actual output device.
int SdlAudioRenderer::detectAudioConfiguration() const
{
SDL_AudioSpec want, have;
SDL_AudioDeviceID dev;
SDL_zero(want);
want.freq = 48000;
want.format = AUDIO_S16;
want.channels = 6;
want.samples = 1024;
// Try to open for 5.1 surround sound, but allow SDL to tell us that's
// not available.
dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, SDL_AUDIO_ALLOW_CHANNELS_CHANGE);
if (dev == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Failed to open audio device");
// We'll probably have issues during audio stream init, but we'll
// try anyway
return AUDIO_CONFIGURATION_STEREO;
}
SDL_CloseAudioDevice(dev);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Audio device has %d channels", have.channels);
if (have.channels > 2) {
// We don't support quadraphonic or 7.1 surround, but SDL
// should be able to downmix or upmix better from 5.1 than
// from stereo, so use 5.1 in non-stereo cases.
return AUDIO_CONFIGURATION_51_SURROUND;
}
else {
return AUDIO_CONFIGURATION_STEREO;
}
}
SdlAudioRenderer::SdlAudioRenderer()
: m_AudioDevice(0),
m_ChannelCount(0),
@@ -141,7 +100,7 @@ SdlAudioRenderer::~SdlAudioRenderer()
SDL_assert(!SDL_WasInit(SDL_INIT_AUDIO));
}
void SdlAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
bool SdlAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
{
m_SampleIndex++;
@@ -181,13 +140,13 @@ void SdlAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
// Hard drops happen all at once to forcefully
// resync with the source.
m_PendingHardDrops--;
return;
return true;
}
else if (m_PendingDrops != 0 && m_SampleIndex % DROP_RATIO_DENOM == 0) {
// Normal drops are interspersed with the audio data
// to hide the glitches.
m_PendingDrops--;
return;
return true;
}
if (SDL_QueueAudio(m_AudioDevice, audioBuffer, audioSize) < 0) {
@@ -195,4 +154,6 @@ void SdlAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
"Failed to queue audio sample: %s",
SDL_GetError());
}
return true;
}