From c7b457de9ef858a7ff66d6b8fbe1fd2afaa78e4b Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 29 Jul 2020 02:23:14 +1000 Subject: [PATCH] CubebAudioStream: Continue even without minimum latency Fixes audio not functioning on Android. --- src/common/cubeb_audio_stream.cpp | 46 ++++++++++++++++++------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/common/cubeb_audio_stream.cpp b/src/common/cubeb_audio_stream.cpp index 0cfdfb44b..4b63685ae 100644 --- a/src/common/cubeb_audio_stream.cpp +++ b/src/common/cubeb_audio_stream.cpp @@ -47,29 +47,37 @@ bool CubebAudioStream::OpenDevice() u32 latency_frames = 0; rv = cubeb_get_min_latency(m_cubeb_context, ¶ms, &latency_frames); - if (rv != CUBEB_OK) + if (rv == CUBEB_ERROR_NOT_SUPPORTED) { - Log_ErrorPrintf("Could not get minimum latency: %d", rv); - DestroyContext(); - return false; - } - - Log_InfoPrintf("Minimum latency in frames: %u", latency_frames); - if (latency_frames > m_buffer_size) - { - Log_WarningPrintf("Minimum latency is above buffer size: %u vs %u, adjusting to compensate.", latency_frames, - m_buffer_size); - - if (!SetBufferSize(latency_frames)) - { - Log_ErrorPrintf("Failed to set new buffer size of %u frames", latency_frames); - DestroyContext(); - return false; - } + Log_WarningPrintf("Cubeb backend does not support latency queries, using buffer size of %u.", m_buffer_size); + latency_frames = m_buffer_size; } else { - latency_frames = m_buffer_size; + if (rv != CUBEB_OK) + { + Log_ErrorPrintf("Could not get minimum latency: %d", rv); + DestroyContext(); + return false; + } + + Log_InfoPrintf("Minimum latency in frames: %u", latency_frames); + if (latency_frames > m_buffer_size) + { + Log_WarningPrintf("Minimum latency is above buffer size: %u vs %u, adjusting to compensate.", latency_frames, + m_buffer_size); + + if (!SetBufferSize(latency_frames)) + { + Log_ErrorPrintf("Failed to set new buffer size of %u frames", latency_frames); + DestroyContext(); + return false; + } + } + else + { + latency_frames = m_buffer_size; + } } char stream_name[32];