mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-12-13 21:02:28 +00:00
Add experimental Qt audio renderer
This commit is contained in:
parent
9677569293
commit
6e06174db6
4 changed files with 121 additions and 0 deletions
|
@ -89,6 +89,7 @@ SOURCES += \
|
||||||
streaming/session.cpp \
|
streaming/session.cpp \
|
||||||
streaming/audio/audio.cpp \
|
streaming/audio/audio.cpp \
|
||||||
streaming/audio/renderers/sdlaud.cpp \
|
streaming/audio/renderers/sdlaud.cpp \
|
||||||
|
streaming/audio/renderers/qtaud.cpp \
|
||||||
gui/computermodel.cpp \
|
gui/computermodel.cpp \
|
||||||
gui/appmodel.cpp \
|
gui/appmodel.cpp \
|
||||||
streaming/streamutils.cpp \
|
streaming/streamutils.cpp \
|
||||||
|
@ -107,6 +108,7 @@ HEADERS += \
|
||||||
streaming/session.hpp \
|
streaming/session.hpp \
|
||||||
streaming/audio/renderers/renderer.h \
|
streaming/audio/renderers/renderer.h \
|
||||||
streaming/audio/renderers/sdl.h \
|
streaming/audio/renderers/sdl.h \
|
||||||
|
streaming/audio/renderers/qtaud.h \
|
||||||
gui/computermodel.h \
|
gui/computermodel.h \
|
||||||
gui/appmodel.h \
|
gui/appmodel.h \
|
||||||
streaming/video/decoder.h \
|
streaming/video/decoder.h \
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "../session.hpp"
|
#include "../session.hpp"
|
||||||
#include "renderers/renderer.h"
|
#include "renderers/renderer.h"
|
||||||
#include "renderers/sdl.h"
|
#include "renderers/sdl.h"
|
||||||
|
#include "renderers/qtaud.h"
|
||||||
|
|
||||||
#include <Limelight.h>
|
#include <Limelight.h>
|
||||||
|
|
||||||
|
|
94
app/streaming/audio/renderers/qtaud.cpp
Normal file
94
app/streaming/audio/renderers/qtaud.cpp
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
#include "qtaud.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
QtAudioRenderer::QtAudioRenderer()
|
||||||
|
: m_AudioOutput(nullptr),
|
||||||
|
m_OutputDevice(nullptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QtAudioRenderer::~QtAudioRenderer()
|
||||||
|
{
|
||||||
|
delete m_AudioOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QtAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* opusConfig)
|
||||||
|
{
|
||||||
|
QAudioFormat format;
|
||||||
|
|
||||||
|
// testAudio() assumes this sample rate
|
||||||
|
Q_ASSERT(opusConfig->sampleRate == 48000);
|
||||||
|
|
||||||
|
format.setSampleRate(opusConfig->sampleRate);
|
||||||
|
format.setChannelCount(opusConfig->channelCount);
|
||||||
|
format.setSampleSize(16);
|
||||||
|
format.setSampleType(QAudioFormat::SignedInt);
|
||||||
|
format.setCodec("audio/pcm");
|
||||||
|
|
||||||
|
m_AudioOutput = new QAudioOutput(format);
|
||||||
|
|
||||||
|
m_AudioOutput->setBufferSize(SAMPLES_PER_FRAME * 2);
|
||||||
|
|
||||||
|
qInfo() << "Audio stream buffer:" << m_AudioOutput->bufferSize() << "bytes";
|
||||||
|
|
||||||
|
m_OutputDevice = m_AudioOutput->start();
|
||||||
|
if (m_OutputDevice == nullptr) {
|
||||||
|
qWarning() << "Audio start failed:" << m_AudioOutput->error();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
|
||||||
|
{
|
||||||
|
m_OutputDevice->write((const char *)audioBuffer, audioSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QtAudioRenderer::testAudio(int audioConfiguration)
|
||||||
|
{
|
||||||
|
QAudioFormat format;
|
||||||
|
|
||||||
|
format.setSampleRate(48000);
|
||||||
|
format.setSampleSize(16);
|
||||||
|
format.setSampleType(QAudioFormat::SignedInt);
|
||||||
|
format.setCodec("audio/pcm");
|
||||||
|
|
||||||
|
switch (audioConfiguration) {
|
||||||
|
case AUDIO_CONFIGURATION_STEREO:
|
||||||
|
format.setChannelCount(2);
|
||||||
|
break;
|
||||||
|
case AUDIO_CONFIGURATION_51_SURROUND:
|
||||||
|
format.setChannelCount(6);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QAudioDeviceInfo::defaultOutputDevice().isFormatSupported(format)) {
|
||||||
|
qInfo() << "Audio test successful with" << format.channelCount() << "channels";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qWarning() << "Audio test failed with" << format.channelCount() << "channels";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int QtAudioRenderer::detectAudioConfiguration()
|
||||||
|
{
|
||||||
|
int preferredChannelCount = QAudioDeviceInfo::defaultOutputDevice().preferredFormat().channelCount();
|
||||||
|
|
||||||
|
qInfo() << "Audio output device prefers" << preferredChannelCount << "channel configuration";
|
||||||
|
|
||||||
|
// We can better downmix 5.1 to quad than we can upmix stereo
|
||||||
|
if (preferredChannelCount > 2) {
|
||||||
|
return AUDIO_CONFIGURATION_51_SURROUND;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return AUDIO_CONFIGURATION_STEREO;
|
||||||
|
}
|
||||||
|
}
|
24
app/streaming/audio/renderers/qtaud.h
Normal file
24
app/streaming/audio/renderers/qtaud.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "renderer.h"
|
||||||
|
#include <QAudioOutput>
|
||||||
|
|
||||||
|
class QtAudioRenderer : public IAudioRenderer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtAudioRenderer();
|
||||||
|
|
||||||
|
virtual ~QtAudioRenderer();
|
||||||
|
|
||||||
|
virtual bool prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* opusConfig);
|
||||||
|
|
||||||
|
virtual void submitAudio(short* audioBuffer, int audioSize);
|
||||||
|
|
||||||
|
virtual bool testAudio(int audioConfiguration);
|
||||||
|
|
||||||
|
virtual int detectAudioConfiguration();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QAudioOutput* m_AudioOutput;
|
||||||
|
QIODevice* m_OutputDevice;
|
||||||
|
};
|
Loading…
Reference in a new issue