mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-17 06:01:12 +00:00
Fix audio device error with PA renderer (and constify some methods)
This commit is contained in:
@@ -109,7 +109,7 @@ void PortAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PortAudioRenderer::testAudio(int audioConfiguration)
|
bool PortAudioRenderer::testAudio(int audioConfiguration) const
|
||||||
{
|
{
|
||||||
PaStreamParameters params = {};
|
PaStreamParameters params = {};
|
||||||
|
|
||||||
@@ -120,6 +120,13 @@ bool PortAudioRenderer::testAudio(int audioConfiguration)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(outputDeviceIndex);
|
||||||
|
if (deviceInfo == nullptr) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"Pa_GetDeviceInfo() failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (audioConfiguration)
|
switch (audioConfiguration)
|
||||||
{
|
{
|
||||||
case AUDIO_CONFIGURATION_STEREO:
|
case AUDIO_CONFIGURATION_STEREO:
|
||||||
@@ -135,20 +142,37 @@ bool PortAudioRenderer::testAudio(int audioConfiguration)
|
|||||||
|
|
||||||
params.sampleFormat = paInt16;
|
params.sampleFormat = paInt16;
|
||||||
params.device = outputDeviceIndex;
|
params.device = outputDeviceIndex;
|
||||||
|
params.suggestedLatency = deviceInfo->defaultLowOutputLatency;
|
||||||
|
|
||||||
PaError error = Pa_IsFormatSupported(nullptr, ¶ms, 48000);
|
// We used to just use Pa_IsFormatSupported() but there are cases
|
||||||
if (error == paFormatIsSupported) {
|
// where Pa_IsFormatSupported() will fail but when we actually
|
||||||
return true;
|
// call Pa_OpenStream(), it fails with device unavailable.
|
||||||
}
|
PaStream* stream;
|
||||||
else {
|
PaError error = Pa_OpenStream(&stream, nullptr, ¶ms,
|
||||||
|
48000,
|
||||||
|
SAMPLES_PER_FRAME,
|
||||||
|
paNoFlag,
|
||||||
|
nullptr, nullptr);
|
||||||
|
if (error != paNoError) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Pa_IsFormatSupported() failed: %s",
|
"Pa_OpenStream() failed: %s",
|
||||||
Pa_GetErrorText(error));
|
Pa_GetErrorText(error));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error = Pa_StartStream(m_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()
|
int PortAudioRenderer::detectAudioConfiguration() const
|
||||||
{
|
{
|
||||||
const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(Pa_GetDefaultOutputDevice());
|
const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(Pa_GetDefaultOutputDevice());
|
||||||
if (deviceInfo == nullptr) {
|
if (deviceInfo == nullptr) {
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ public:
|
|||||||
|
|
||||||
virtual void submitAudio(short* audioBuffer, int audioSize);
|
virtual void submitAudio(short* audioBuffer, int audioSize);
|
||||||
|
|
||||||
virtual bool testAudio(int audioConfiguration);
|
virtual bool testAudio(int audioConfiguration) const;
|
||||||
|
|
||||||
virtual int detectAudioConfiguration();
|
virtual int detectAudioConfiguration() const;
|
||||||
|
|
||||||
static int paStreamCallback(const void *input,
|
static int paStreamCallback(const void *input,
|
||||||
void *output,
|
void *output,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public:
|
|||||||
|
|
||||||
virtual void submitAudio(short* audioBuffer, int audioSize) = 0;
|
virtual void submitAudio(short* audioBuffer, int audioSize) = 0;
|
||||||
|
|
||||||
virtual bool testAudio(int audioConfiguration) = 0;
|
virtual bool testAudio(int audioConfiguration) const = 0;
|
||||||
|
|
||||||
virtual int detectAudioConfiguration() = 0;
|
virtual int detectAudioConfiguration() const = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ public:
|
|||||||
|
|
||||||
virtual void submitAudio(short* audioBuffer, int audioSize);
|
virtual void submitAudio(short* audioBuffer, int audioSize);
|
||||||
|
|
||||||
virtual bool testAudio(int audioConfiguration);
|
virtual bool testAudio(int audioConfiguration) const;
|
||||||
|
|
||||||
virtual int detectAudioConfiguration();
|
virtual int detectAudioConfiguration() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDL_AudioDeviceID m_AudioDevice;
|
SDL_AudioDeviceID m_AudioDevice;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
// This isn't accurate on macOS and Linux (PulseAudio),
|
// This isn't accurate on macOS and Linux (PulseAudio),
|
||||||
// since they both report supporting a large number of
|
// since they both report supporting a large number of
|
||||||
// channels, regardless of the actual output device.
|
// channels, regardless of the actual output device.
|
||||||
int SdlAudioRenderer::detectAudioConfiguration()
|
int SdlAudioRenderer::detectAudioConfiguration() const
|
||||||
{
|
{
|
||||||
SDL_AudioSpec want, have;
|
SDL_AudioSpec want, have;
|
||||||
SDL_AudioDeviceID dev;
|
SDL_AudioDeviceID dev;
|
||||||
@@ -51,7 +51,7 @@ int SdlAudioRenderer::detectAudioConfiguration()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SdlAudioRenderer::testAudio(int audioConfiguration)
|
bool SdlAudioRenderer::testAudio(int audioConfiguration) const
|
||||||
{
|
{
|
||||||
SDL_AudioSpec want, have;
|
SDL_AudioSpec want, have;
|
||||||
SDL_AudioDeviceID dev;
|
SDL_AudioDeviceID dev;
|
||||||
|
|||||||
Reference in New Issue
Block a user