Restore the bulk submission optimization for Steam Link

This commit is contained in:
Cameron Gutman
2019-05-01 22:31:52 -07:00
parent 21f2b1224a
commit e6a48481a5
3 changed files with 39 additions and 8 deletions

View File

@@ -9,7 +9,9 @@
SLAudioRenderer::SLAudioRenderer()
: m_AudioContext(nullptr),
m_AudioStream(nullptr)
m_AudioStream(nullptr),
m_AudioBuffer(nullptr),
m_AudioBufferBytesFilled(0)
{
SLAudio_SetLogFunction(SLAudioRenderer::slLogCallback, nullptr);
}
@@ -23,7 +25,7 @@ bool SLAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* o
return false;
}
m_AudioBufferSize = SAMPLES_PER_FRAME * sizeof(short) * opusConfig->channelCount;
m_AudioBufferSize = SAMPLES_PER_FRAME * sizeof(short) * opusConfig->channelCount * FRAMES_PER_SUBMISSION;
m_AudioStream = SLAudio_CreateStream(m_AudioContext,
opusConfig->sampleRate,
opusConfig->channelCount,
@@ -43,12 +45,29 @@ bool SLAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* o
void* SLAudioRenderer::getAudioBuffer(int* size)
{
SDL_assert(*size == m_AudioBufferSize);
return SLAudio_BeginFrame(m_AudioStream);
SDL_assert(*size == m_AudioBufferSize / FRAMES_PER_SUBMISSION);
if (m_AudioBuffer == nullptr) {
m_AudioBufferBytesFilled = 0;
m_AudioBuffer = (char*)SLAudio_BeginFrame(m_AudioStream);
if (m_AudioBuffer == nullptr) {
return nullptr;
}
}
return (void*)&m_AudioBuffer[m_AudioBufferBytesFilled];
}
SLAudioRenderer::~SLAudioRenderer()
{
if (m_AudioBuffer != nullptr) {
// We had a buffer in flight when we quit. Just in case
// SLAudio doesn't handle this properly, we'll zero and submit
// it just to be safe.
memset(m_AudioBuffer, 0, m_AudioBufferSize);
SLAudio_SubmitFrame(m_AudioStream);
}
if (m_AudioStream != nullptr) {
SLAudio_FreeStream(m_AudioStream);
}
@@ -58,13 +77,22 @@ SLAudioRenderer::~SLAudioRenderer()
}
}
bool SLAudioRenderer::submitAudio(int)
bool SLAudioRenderer::submitAudio(int bytesWritten)
{
SLAudio_SubmitFrame(m_AudioStream);
m_AudioBufferBytesFilled += bytesWritten;
// Submit the buffer when it's full
SDL_assert(m_AudioBufferBytesFilled <= m_AudioBufferSize);
if (m_AudioBufferBytesFilled == m_AudioBufferSize) {
SLAudio_SubmitFrame(m_AudioStream);
m_AudioBuffer = nullptr;
m_AudioBufferBytesFilled = 0;
}
return true;
}
void SLAudioRenderer::slLogCallback(void *context, ESLAudioLog logLevel, const char *message)
void SLAudioRenderer::slLogCallback(void*, ESLAudioLog logLevel, const char *message)
{
SDL_LogPriority priority;

View File

@@ -21,5 +21,8 @@ private:
CSLAudioContext* m_AudioContext;
CSLAudioStream* m_AudioStream;
char* m_AudioBuffer;
int m_AudioBufferSize;
int m_AudioBufferBytesFilled;
};

View File

@@ -109,7 +109,7 @@ SLVideoDecoder::submitDecodeUnit(PDECODE_UNIT du)
return DR_OK;
}
void SLVideoDecoder::slLogCallback(void *context, ESLVideoLog logLevel, const char *message)
void SLVideoDecoder::slLogCallback(void*, ESLVideoLog logLevel, const char *message)
{
SDL_LogPriority priority;