mal_result result = mal_device__cork_stream__pulse(pDevice, 1);
/*
Corking the device without flushing or draining should satisfy the requirements of mal_device_stop() which is that it must not
drop unprocessed samples.
*/
result = mal_device__cork_stream__pulse(pDevice, 1);
if (result != MAL_SUCCESS) {
if (result != MAL_SUCCESS) {
return result;
return result;
}
}
// For playback, buffers need to be flushed. For capture they need to be drained.
mal_bool32 wasSuccessful;
mal_pa_operation* pOP = NULL;
if (pDevice->type == mal_device_type_playback) {
pOP = ((mal_pa_stream_flush_proc)pContext->pulse.pa_stream_flush)((mal_pa_stream*)pDevice->pulse.pStream, mal_pulse_operation_complete_callback, &wasSuccessful);
} else {
pOP = ((mal_pa_stream_drain_proc)pContext->pulse.pa_stream_drain)((mal_pa_stream*)pDevice->pulse.pStream, mal_pulse_operation_complete_callback, &wasSuccessful);
}
if (pOP == NULL) {
return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[PulseAudio] Failed to flush buffers after stopping PulseAudio stream.", MAL_ERROR);
}
result = mal_device__wait_for_operation__pulse(pDevice, pOP);