From 8dddcd04d501c3f4ee8d8ef7ae214735f18e427d Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 1 Oct 2018 19:49:08 -0700 Subject: [PATCH] Remove IAudioRenderer::testAudio() and just use IAudioRenderer::prepareForPlayback() instead --- app/streaming/audio/audio.cpp | 20 +++++- .../audio/renderers/portaudiorenderer.cpp | 63 ------------------- .../audio/renderers/portaudiorenderer.h | 2 - app/streaming/audio/renderers/renderer.h | 2 - app/streaming/audio/renderers/sdl.h | 2 - app/streaming/audio/renderers/sdlaud.cpp | 39 ------------ 6 files changed, 19 insertions(+), 109 deletions(-) diff --git a/app/streaming/audio/audio.cpp b/app/streaming/audio/audio.cpp index 976af3f3..48d40b74 100644 --- a/app/streaming/audio/audio.cpp +++ b/app/streaming/audio/audio.cpp @@ -27,7 +27,25 @@ bool Session::testAudio(int audioConfiguration) return false; } - bool ret = audioRenderer->testAudio(audioConfiguration); + // Build a fake OPUS_MULTISTREAM_CONFIGURATION to give + // the renderer the channel count and sample rate. + OPUS_MULTISTREAM_CONFIGURATION opusConfig = {}; + opusConfig.sampleRate = 48000; + + switch (audioConfiguration) + { + case AUDIO_CONFIGURATION_STEREO: + opusConfig.channelCount = 2; + break; + case AUDIO_CONFIGURATION_51_SURROUND: + opusConfig.channelCount = 6; + break; + default: + SDL_assert(false); + return false; + } + + bool ret = audioRenderer->prepareForPlayback(&opusConfig); delete audioRenderer; diff --git a/app/streaming/audio/renderers/portaudiorenderer.cpp b/app/streaming/audio/renderers/portaudiorenderer.cpp index baf2a827..bcb6ce82 100644 --- a/app/streaming/audio/renderers/portaudiorenderer.cpp +++ b/app/streaming/audio/renderers/portaudiorenderer.cpp @@ -109,69 +109,6 @@ void PortAudioRenderer::submitAudio(short* audioBuffer, int audioSize) } } -bool PortAudioRenderer::testAudio(int audioConfiguration) const -{ - PaStreamParameters params = {}; - - PaDeviceIndex outputDeviceIndex = Pa_GetDefaultOutputDevice(); - if (outputDeviceIndex == paNoDevice) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "No output device available"); - return false; - } - - const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(outputDeviceIndex); - if (deviceInfo == nullptr) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "Pa_GetDeviceInfo() failed"); - return false; - } - - switch (audioConfiguration) - { - case AUDIO_CONFIGURATION_STEREO: - params.channelCount = 2; - break; - case AUDIO_CONFIGURATION_51_SURROUND: - params.channelCount = 6; - break; - default: - SDL_assert(false); - return false; - } - - params.sampleFormat = paInt16; - params.device = outputDeviceIndex; - params.suggestedLatency = deviceInfo->defaultLowOutputLatency; - - // We used to just use Pa_IsFormatSupported() but there are cases - // where Pa_IsFormatSupported() will fail but when we actually - // call Pa_OpenStream(), it fails with device unavailable. - PaStream* stream; - PaError error = Pa_OpenStream(&stream, nullptr, ¶ms, - 48000, - SAMPLES_PER_FRAME, - paNoFlag, - nullptr, nullptr); - if (error != paNoError) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "Pa_OpenStream() failed: %s", - Pa_GetErrorText(error)); - return false; - } - - error = Pa_StartStream(stream); - if (error != paNoError) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "Pa_StartStream() failed: %s", - Pa_GetErrorText(error)); - } - - Pa_CloseStream(stream); - - return error == paNoError; -} - int PortAudioRenderer::detectAudioConfiguration() const { const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(Pa_GetDefaultOutputDevice()); diff --git a/app/streaming/audio/renderers/portaudiorenderer.h b/app/streaming/audio/renderers/portaudiorenderer.h index 85ffb475..8ebade6c 100644 --- a/app/streaming/audio/renderers/portaudiorenderer.h +++ b/app/streaming/audio/renderers/portaudiorenderer.h @@ -20,8 +20,6 @@ public: virtual void submitAudio(short* audioBuffer, int audioSize); - virtual bool testAudio(int audioConfiguration) const; - virtual int detectAudioConfiguration() const; virtual void adjustOpusChannelMapping(OPUS_MULTISTREAM_CONFIGURATION* opusConfig) const; diff --git a/app/streaming/audio/renderers/renderer.h b/app/streaming/audio/renderers/renderer.h index eaead051..e490750c 100644 --- a/app/streaming/audio/renderers/renderer.h +++ b/app/streaming/audio/renderers/renderer.h @@ -16,7 +16,5 @@ public: virtual void submitAudio(short* audioBuffer, int audioSize) = 0; - virtual bool testAudio(int audioConfiguration) const = 0; - virtual int detectAudioConfiguration() const = 0; }; diff --git a/app/streaming/audio/renderers/sdl.h b/app/streaming/audio/renderers/sdl.h index accc5508..2e132e3d 100644 --- a/app/streaming/audio/renderers/sdl.h +++ b/app/streaming/audio/renderers/sdl.h @@ -19,8 +19,6 @@ public: virtual void submitAudio(short* audioBuffer, int audioSize); - virtual bool testAudio(int audioConfiguration) const; - virtual int detectAudioConfiguration() const; virtual void adjustOpusChannelMapping(OPUS_MULTISTREAM_CONFIGURATION* opusConfig) const; diff --git a/app/streaming/audio/renderers/sdlaud.cpp b/app/streaming/audio/renderers/sdlaud.cpp index 85d15e87..5ac2f17f 100644 --- a/app/streaming/audio/renderers/sdlaud.cpp +++ b/app/streaming/audio/renderers/sdlaud.cpp @@ -56,45 +56,6 @@ void SdlAudioRenderer::adjustOpusChannelMapping(OPUS_MULTISTREAM_CONFIGURATION*) // The default mapping is fine for SDL } -bool SdlAudioRenderer::testAudio(int audioConfiguration) const -{ - SDL_AudioSpec want, have; - SDL_AudioDeviceID dev; - - SDL_zero(want); - want.freq = 48000; - want.format = AUDIO_S16; - want.samples = SAMPLES_PER_FRAME; - - switch (audioConfiguration) { - case AUDIO_CONFIGURATION_STEREO: - want.channels = 2; - break; - case AUDIO_CONFIGURATION_51_SURROUND: - want.channels = 6; - break; - default: - SDL_assert(false); - return false; - } - - // Test audio device for functionality - dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0); - if (dev == 0) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "Audio test - Failed to open audio device: %s", - SDL_GetError()); - return false; - } - - SDL_CloseAudioDevice(dev); - - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, - "Audio test - Successful with %d channels", - want.channels); - return true; -} - SdlAudioRenderer::SdlAudioRenderer() : m_AudioDevice(0), m_ChannelCount(0),