From 14ec0259df095710d48a67f71e40caad36372a18 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 22 Sep 2018 16:20:00 -0700 Subject: [PATCH] Switch back from Qt Multimedia to SDL for audio configuration detection. Qt is also broken, but just broken in a way that always reports stereo --- app/app.pro | 4 +-- app/streaming/audio/audio.cpp | 1 - app/streaming/audio/renderers/sdlaud.cpp | 39 ++++++++++++++++++------ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/app.pro b/app/app.pro index c63a377e..a9596ca8 100644 --- a/app/app.pro +++ b/app/app.pro @@ -1,4 +1,4 @@ -QT += core quick network quickcontrols2 svg multimedia +QT += core quick network quickcontrols2 svg CONFIG += c++11 unix:!macx { @@ -96,7 +96,6 @@ SOURCES += \ streaming/session.cpp \ streaming/audio/audio.cpp \ streaming/audio/renderers/sdlaud.cpp \ - streaming/audio/renderers/qtaud.cpp \ gui/computermodel.cpp \ gui/appmodel.cpp \ streaming/streamutils.cpp \ @@ -115,7 +114,6 @@ HEADERS += \ streaming/session.hpp \ streaming/audio/renderers/renderer.h \ streaming/audio/renderers/sdl.h \ - streaming/audio/renderers/qtaud.h \ gui/computermodel.h \ gui/appmodel.h \ streaming/video/decoder.h \ diff --git a/app/streaming/audio/audio.cpp b/app/streaming/audio/audio.cpp index 8f5566cf..ba6c2f59 100644 --- a/app/streaming/audio/audio.cpp +++ b/app/streaming/audio/audio.cpp @@ -1,7 +1,6 @@ #include "../session.hpp" #include "renderers/renderer.h" #include "renderers/sdl.h" -#include "renderers/qtaud.h" #include diff --git a/app/streaming/audio/renderers/sdlaud.cpp b/app/streaming/audio/renderers/sdlaud.cpp index 72e4b9b1..e7f505f0 100644 --- a/app/streaming/audio/renderers/sdlaud.cpp +++ b/app/streaming/audio/renderers/sdlaud.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #define MIN_QUEUED_FRAMES 2 @@ -11,20 +10,40 @@ #define STOP_THE_WORLD_LIMIT 20 #define DROP_RATIO_DENOM 32 -// Detecting this with SDL is quite problematic, so we'll use Qt's -// multimedia framework to do so. It appears to be actually -// accurate on Linux and macOS, unlike using SDL and relying -// on a channel change in the format received. +// 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() { - int preferredChannelCount = QAudioDeviceInfo::defaultOutputDevice().preferredFormat().channelCount(); + 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 output device prefers %d channel configuration", - preferredChannelCount); + "Audio device has %d channels", have.channels); - // We can better downmix 5.1 to quad than we can upmix stereo - if (preferredChannelCount > 2) { + 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 {