mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-12-16 06:12:28 +00:00
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
|
#include "slaud.h"
|
||
|
|
||
|
#include <SDL.h>
|
||
|
|
||
|
SLAudioRenderer::SLAudioRenderer()
|
||
|
: m_AudioContext(nullptr),
|
||
|
m_AudioStream(nullptr)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool SLAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* opusConfig)
|
||
|
{
|
||
|
m_AudioContext = SLAudio_CreateContext();
|
||
|
if (m_AudioContext == nullptr) {
|
||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||
|
"SLAudio_CreateContext() failed");
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
m_AudioStream = SLAudio_CreateStream(m_AudioContext,
|
||
|
opusConfig->sampleRate,
|
||
|
opusConfig->channelCount,
|
||
|
SAMPLES_PER_FRAME * sizeof(short) * opusConfig->channelCount,
|
||
|
1);
|
||
|
if (m_AudioStream == nullptr) {
|
||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||
|
"SLAudio_CreateStream() failed");
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||
|
"Using SLAudio renderer");
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
SLAudioRenderer::~SLAudioRenderer()
|
||
|
{
|
||
|
if (m_AudioStream != nullptr) {
|
||
|
SLAudio_FreeStream(m_AudioStream);
|
||
|
}
|
||
|
|
||
|
if (m_AudioContext != nullptr) {
|
||
|
SLAudio_FreeContext(m_AudioContext);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool SLAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
|
||
|
{
|
||
|
void* outputBuffer = SLAudio_BeginFrame(m_AudioStream);
|
||
|
|
||
|
if (outputBuffer != nullptr) {
|
||
|
memcpy(outputBuffer, audioBuffer, audioSize);
|
||
|
SLAudio_SubmitFrame(m_AudioStream);
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|