OpenSLESAudioStream: Add additional logging

This commit is contained in:
Connor McLaughlin 2020-10-14 14:02:19 +10:00
parent c8011f0b02
commit 3b6b7007b3

View file

@ -31,15 +31,33 @@ bool OpenSLESAudioStream::OpenDevice()
} }
res = (*m_engine)->Realize(m_engine, SL_BOOLEAN_FALSE); res = (*m_engine)->Realize(m_engine, SL_BOOLEAN_FALSE);
if (res == SL_RESULT_SUCCESS) if (res != SL_RESULT_SUCCESS)
{
Log_ErrorPrintf("Realize(Engine) failed: %d", res);
CloseDevice();
return false;
}
res = (*m_engine)->GetInterface(m_engine, SL_IID_ENGINE, &m_engine_engine); res = (*m_engine)->GetInterface(m_engine, SL_IID_ENGINE, &m_engine_engine);
if (res == SL_RESULT_SUCCESS) if (res != SL_RESULT_SUCCESS)
{
Log_ErrorPrintf("GetInterface(SL_IID_ENGINE) failed: %d", res);
CloseDevice();
return false;
}
res = (*m_engine_engine)->CreateOutputMix(m_engine_engine, &m_output_mix, 0, 0, 0); res = (*m_engine_engine)->CreateOutputMix(m_engine_engine, &m_output_mix, 0, 0, 0);
if (res == SL_RESULT_SUCCESS) if (res != SL_RESULT_SUCCESS)
{
Log_ErrorPrintf("CreateOutputMix failed: %d", res);
CloseDevice();
return false;
}
res = (*m_output_mix)->Realize(m_output_mix, SL_BOOLEAN_FALSE); res = (*m_output_mix)->Realize(m_output_mix, SL_BOOLEAN_FALSE);
if (res != SL_RESULT_SUCCESS) if (res != SL_RESULT_SUCCESS)
{ {
Log_ErrorPrintf("Failed to create engine/output mix"); Log_ErrorPrintf("Realize(OutputMix) mix failed: %d", res);
CloseDevice(); CloseDevice();
return false; return false;
} }
@ -63,21 +81,39 @@ bool OpenSLESAudioStream::OpenDevice()
ap_interfaces.data(), ap_interfaces_req.data()); ap_interfaces.data(), ap_interfaces_req.data());
if (res != SL_RESULT_SUCCESS) if (res != SL_RESULT_SUCCESS)
{ {
Log_ErrorPrintf("Failed to create audio player: %d", res); Log_ErrorPrintf("CreateAudioPlayer failed: %d", res);
CloseDevice(); CloseDevice();
return false; return false;
} }
res = (*m_player)->Realize(m_player, SL_BOOLEAN_FALSE); res = (*m_player)->Realize(m_player, SL_BOOLEAN_FALSE);
if (res == SL_RESULT_SUCCESS) if (res != SL_RESULT_SUCCESS)
{
Log_ErrorPrintf("Realize(AudioPlayer) failed: %d", res);
CloseDevice();
return false;
}
res = (*m_player)->GetInterface(m_player, SL_IID_PLAY, &m_play_interface); res = (*m_player)->GetInterface(m_player, SL_IID_PLAY, &m_play_interface);
if (res == SL_RESULT_SUCCESS) if (res != SL_RESULT_SUCCESS)
{
Log_ErrorPrintf("GetInterface(SL_IID_PLAY) failed: %d", res);
CloseDevice();
return false;
}
res = (*m_player)->GetInterface(m_player, SL_IID_BUFFERQUEUE, &m_buffer_queue_interface); res = (*m_player)->GetInterface(m_player, SL_IID_BUFFERQUEUE, &m_buffer_queue_interface);
if (res == SL_RESULT_SUCCESS) if (res != SL_RESULT_SUCCESS)
{
Log_ErrorPrintf("GetInterface(SL_IID_BUFFERQUEUE) failed: %d", res);
CloseDevice();
return false;
}
res = (*m_player)->GetInterface(m_player, SL_IID_VOLUME, &m_volume_interface); res = (*m_player)->GetInterface(m_player, SL_IID_VOLUME, &m_volume_interface);
if (res != SL_RESULT_SUCCESS) if (res != SL_RESULT_SUCCESS)
{ {
Log_ErrorPrintf("Failed to get player interfaces: %d", res); Log_ErrorPrintf("GetInterface(SL_IID_VOLUME) failed: %d", res);
CloseDevice(); CloseDevice();
return false; return false;
} }
@ -93,6 +129,8 @@ bool OpenSLESAudioStream::OpenDevice()
for (u32 i = 0; i < NUM_BUFFERS; i++) for (u32 i = 0; i < NUM_BUFFERS; i++)
m_buffers[i] = std::make_unique<SampleType[]>(m_buffer_size * m_channels); m_buffers[i] = std::make_unique<SampleType[]>(m_buffer_size * m_channels);
Log_InfoPrintf("OpenSL ES device opened: %uhz, %u channels, %u buffer size, %u buffers",
m_output_sample_rate, m_channels, m_buffer_size, NUM_BUFFERS);
return true; return true;
} }
@ -101,7 +139,9 @@ void OpenSLESAudioStream::PauseDevice(bool paused)
if (m_paused == paused) if (m_paused == paused)
return; return;
(*m_play_interface)->SetPlayState(m_play_interface, paused ? SL_PLAYSTATE_PAUSED : SL_PLAYSTATE_PLAYING); SLresult res = (*m_play_interface)->SetPlayState(m_play_interface, paused ? SL_PLAYSTATE_PAUSED : SL_PLAYSTATE_PLAYING);
if (res != SL_RESULT_SUCCESS)
Log_ErrorPrintf("SetPlayState failed: %d", res);
if (!paused && !m_buffer_enqueued) if (!paused && !m_buffer_enqueued)
{ {
@ -142,7 +182,9 @@ void OpenSLESAudioStream::SetOutputVolume(u32 volume)
const SLmillibel attenuation = (volume == 0) ? const SLmillibel attenuation = (volume == 0) ?
SL_MILLIBEL_MIN : SL_MILLIBEL_MIN :
static_cast<SLmillibel>(2000.0f * std::log10(static_cast<float>(volume) / 100.0f)); static_cast<SLmillibel>(2000.0f * std::log10(static_cast<float>(volume) / 100.0f));
(*m_volume_interface)->SetVolumeLevel(m_volume_interface, attenuation); SLresult res = (*m_volume_interface)->SetVolumeLevel(m_volume_interface, attenuation);
if (res != SL_RESULT_SUCCESS)
Log_ErrorPrintf("SetVolumeLevel failed: %d", res);
} }
void OpenSLESAudioStream::EnqueueBuffer() void OpenSLESAudioStream::EnqueueBuffer()