ALSA: Use more descriptive error messages.

This commit is contained in:
David Reid
2026-01-10 13:07:10 +10:00
parent 9a4318997b
commit 96c4b105b0
+30 -30
View File
@@ -29182,14 +29182,14 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
resultALSA = pContextStateALSA->snd_pcm_open(&pPCM, pDeviceName, (deviceType == ma_device_type_playback) ? MA_SND_PCM_STREAM_PLAYBACK : MA_SND_PCM_STREAM_CAPTURE, openMode);
if (resultALSA < 0) {
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_open() failed for device \"%s\".", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_open() failed for device \"%s\". %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
resultALSA = pContextStateALSA->snd_pcm_hw_params_any(pPCM, pHWParams);
if (resultALSA < 0) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to initialize hardware parameters for device \"%s\". snd_pcm_hw_params_any() failed.", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to initialize hardware parameters for device \"%s\". snd_pcm_hw_params_any() failed. %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
@@ -29209,7 +29209,7 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
resultALSA = pContextStateALSA->snd_pcm_hw_params_set_access(pPCM, pHWParams, MA_SND_PCM_ACCESS_RW_INTERLEAVED);
if (resultALSA < 0) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set access mode to neither SND_PCM_ACCESS_MMAP_INTERLEAVED nor SND_PCM_ACCESS_RW_INTERLEAVED for device \"%s\". snd_pcm_hw_params_set_access() failed.", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set access mode to neither SND_PCM_ACCESS_MMAP_INTERLEAVED nor SND_PCM_ACCESS_RW_INTERLEAVED for device \"%s\". snd_pcm_hw_params_set_access() failed. %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
}
@@ -29236,7 +29236,7 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
if (formatALSA == MA_SND_PCM_FORMAT_UNKNOWN) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Format not supported. The device \"%s\" does not support any miniaudio formats.", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Format not supported. The device \"%s\" does not support any miniaudio formats. %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
}
@@ -29244,14 +29244,14 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
resultALSA = pContextStateALSA->snd_pcm_hw_params_set_format(pPCM, pHWParams, formatALSA);
if (resultALSA < 0) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_hw_params_set_format() failed for device \"%s\".", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_hw_params_set_format() failed for device \"%s\". %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
internalFormat = ma_format_from_alsa(formatALSA);
if (internalFormat == ma_format_unknown) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] The chosen format used by device \"%s\" is not supported by miniaudio.", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] The chosen format used by device \"%s\" is not supported by miniaudio. %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
}
@@ -29265,7 +29265,7 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
if (channels != 0 && pContextStateALSA->snd_pcm_hw_params_test_channels(pPCM, pHWParams, channels) == 0) {
resultALSA = pContextStateALSA->snd_pcm_hw_params_set_channels(pPCM, pHWParams, channels);
if (resultALSA < 0) {
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_WARNING, "[ALSA] Failed to set channel count for device \"%s\" to %u. Falling back to snd_pcm_hw_params_set_channels_near().", pDeviceName, channels);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_WARNING, "[ALSA] Failed to set channel count for device \"%s\" to %u. Falling back to snd_pcm_hw_params_set_channels_near(). %s.", pDeviceName, channels, pContextStateALSA->snd_strerror(resultALSA));
}
}
@@ -29287,7 +29287,7 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
resultALSA = pContextStateALSA->snd_pcm_hw_params_get_channels_max(pHWParams, &channels);
if (resultALSA < 0) {
channels = MA_DEFAULT_CHANNELS;
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_WARNING, "[ALSA] Trying to open hardware device \"%s\", but requesting the maximum channel count failed. Defaulting to stereo.", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_WARNING, "[ALSA] Trying to open hardware device \"%s\", but requesting the maximum channel count failed. Defaulting to stereo. %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
} else {
if (channels > MA_ALSA_MAX_NATIVE_CHANNELS) {
channels = MA_ALSA_MAX_NATIVE_CHANNELS;
@@ -29302,7 +29302,7 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
resultALSA = pContextStateALSA->snd_pcm_hw_params_set_channels_near(pPCM, pHWParams, &channels);
if (resultALSA < 0) {
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set channel count for device \"%s\" with snd_pcm_hw_params_set_channels_near().", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set channel count for device \"%s\" with snd_pcm_hw_params_set_channels_near(). %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
}
}
@@ -29346,7 +29346,7 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
resultALSA = pContextStateALSA->snd_pcm_hw_params_set_rate_near(pPCM, pHWParams, &sampleRate, 0);
if (resultALSA < 0) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_hw_params_set_rate_near() failed for device \"%s\".", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_hw_params_set_rate_near() failed for device \"%s\". %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
@@ -29360,7 +29360,7 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
resultALSA = pContextStateALSA->snd_pcm_hw_params_set_periods_near(pPCM, pHWParams, &periods, NULL);
if (resultALSA < 0) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set period count for device \"%s\". snd_pcm_hw_params_set_periods_near() failed.", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set period count for device \"%s\". snd_pcm_hw_params_set_periods_near() failed. %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
@@ -29389,7 +29389,7 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
resultALSA = pContextStateALSA->snd_pcm_hw_params_set_buffer_size_near(pPCM, pHWParams, &actualBufferSizeInFrames);
if (resultALSA < 0) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set buffer size for device \"%s\". snd_pcm_hw_params_set_buffer_size() failed.", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set buffer size for device \"%s\". snd_pcm_hw_params_set_buffer_size() failed. %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
@@ -29400,7 +29400,7 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
resultALSA = pContextStateALSA->snd_pcm_hw_params(pPCM, pHWParams);
if (resultALSA < 0) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set hardware parameters for device \"%s\". snd_pcm_hw_params() failed.", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set hardware parameters for device \"%s\". snd_pcm_hw_params() failed. %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
@@ -29409,14 +29409,14 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
resultALSA = pContextStateALSA->snd_pcm_sw_params_current(pPCM, pSWParams);
if (resultALSA < 0) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to initialize software parameters for device \"%s\". snd_pcm_sw_params_current() failed.", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to initialize software parameters for device \"%s\". snd_pcm_sw_params_current() failed. %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
resultALSA = pContextStateALSA->snd_pcm_sw_params_set_avail_min(pPCM, pSWParams, internalPeriodSizeInFrames);
if (resultALSA < 0) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_sw_params_set_avail_min() failed for device \"%s\".", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_sw_params_set_avail_min() failed for device \"%s\". %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
@@ -29438,7 +29438,7 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
resultALSA = pContextStateALSA->snd_pcm_sw_params_set_start_threshold(pPCM, pSWParams, 0xFFFFFFFF);
if (resultALSA < 0) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set start threshold for playback device \"%s\". snd_pcm_sw_params_set_start_threshold() failed.", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set start threshold for playback device \"%s\". snd_pcm_sw_params_set_start_threshold() failed. %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
}
@@ -29446,7 +29446,7 @@ static ma_result ma_device_init_by_type__alsa(ma_context* pContext, ma_context_s
resultALSA = pContextStateALSA->snd_pcm_sw_params(pPCM, pSWParams);
if (resultALSA < 0) {
pContextStateALSA->snd_pcm_close(pPCM);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set software parameters for device \"%s\". snd_pcm_sw_params() failed.", pDeviceName);
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set software parameters for device \"%s\". snd_pcm_sw_params() failed. %s.", pDeviceName, pContextStateALSA->snd_strerror(resultALSA));
continue;
}
@@ -29646,7 +29646,7 @@ static ma_result ma_device_init__alsa(ma_device* pDevice, const void* pDeviceBac
if (pollDescriptorCountCapture > 0) {
resultALSA = pContextStateALSA->snd_pcm_poll_descriptors(pDeviceStateALSA->pPCMCapture, pDeviceStateALSA->pPollDescriptors + 1, pollDescriptorCountCapture);
if (resultALSA < 0) {
ma_log_postf(ma_context_get_log(ma_device_get_context(pDevice)), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to retrieve poll descriptors.");
ma_log_postf(ma_context_get_log(ma_device_get_context(pDevice)), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to retrieve poll descriptors. %s.", pContextStateALSA->snd_strerror(resultALSA));
ma_device_uninit_internal__alsa(pDevice, pDeviceStateALSA);
return MA_ERROR;
}
@@ -29657,7 +29657,7 @@ static ma_result ma_device_init__alsa(ma_device* pDevice, const void* pDeviceBac
if (pollDescriptorCountPlayback > 0) {
resultALSA = pContextStateALSA->snd_pcm_poll_descriptors(pDeviceStateALSA->pPCMPlayback, pDeviceStateALSA->pPollDescriptors + 1 + pollDescriptorCountCapture, pollDescriptorCountPlayback);
if (resultALSA < 0) {
ma_log_postf(ma_context_get_log(ma_device_get_context(pDevice)), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to retrieve poll descriptors.");
ma_log_postf(ma_context_get_log(ma_device_get_context(pDevice)), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to retrieve poll descriptors. %s.", pContextStateALSA->snd_strerror(resultALSA));
ma_device_uninit_internal__alsa(pDevice, pDeviceStateALSA);
return MA_ERROR;
}
@@ -29743,7 +29743,7 @@ static ma_result ma_device_start__alsa(ma_device* pDevice)
if (pDeviceStateALSA->pPCMCapture != NULL) {
resultALSA = pContextStateALSA->snd_pcm_start(pDeviceStateALSA->pPCMCapture);
if (resultALSA < 0) {
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start capture device.");
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start capture device. %s.", pContextStateALSA->snd_strerror(resultALSA));
return ma_result_from_errno(-resultALSA);
}
}
@@ -29752,7 +29752,7 @@ static ma_result ma_device_start__alsa(ma_device* pDevice)
if (pDeviceStateALSA->pPCMPlayback != NULL) {
resultALSA = pContextStateALSA->snd_pcm_start(pDeviceStateALSA->pPCMPlayback);
if (resultALSA < 0) {
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start playback device.");
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start playback device. %s.", pContextStateALSA->snd_strerror(resultALSA));
return ma_result_from_errno(-resultALSA);
}
}
@@ -29879,7 +29879,7 @@ static ma_result ma_device_step__alsa(ma_device* pDevice, ma_blocking_mode block
return ma_result_from_errno(errno);
}
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] POLLIN set for wakeupfd");
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] POLLIN set for wakeupfd.");
return MA_SUCCESS;
}
@@ -29887,7 +29887,7 @@ static ma_result ma_device_step__alsa(ma_device* pDevice, ma_blocking_mode block
if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) {
resultALSA = pContextStateALSA->snd_pcm_poll_descriptors_revents(pDeviceStateALSA->pPCMCapture, pDeviceStateALSA->pPollDescriptors + 1, pDeviceStateALSA->pollDescriptorCountCapture, &revents);
if (resultALSA < 0) {
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] snd_pcm_poll_descriptors_revents() failed for capture.");
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] snd_pcm_poll_descriptors_revents() failed for capture. %s.", pContextStateALSA->snd_strerror(resultALSA));
return MA_ERROR;
}
@@ -29918,17 +29918,17 @@ static ma_result ma_device_step__alsa(ma_device* pDevice, ma_blocking_mode block
/* Overrun. Recover. If this fails we need to return an error. */
resultALSA = pContextStateALSA->snd_pcm_recover(pDeviceStateALSA->pPCMCapture, resultALSA, MA_TRUE);
if (resultALSA < 0) {
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to recover capture device after overrun.");
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to recover capture device after overrun. %s.", pContextStateALSA->snd_strerror(resultALSA));
return ma_result_from_errno((int)-resultALSA);
}
resultALSA = pContextStateALSA->snd_pcm_start(pDeviceStateALSA->pPCMCapture);
if (resultALSA < 0) {
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start capture device after overrun.");
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start capture device after overrun. %s.", pContextStateALSA->snd_strerror(resultALSA));
return ma_result_from_errno((int)-resultALSA);
}
} else {
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Unexpected error when reading from capture device. errno = %d.", (int)-resultALSA);
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Unexpected error when reading from capture device. %s.", pContextStateALSA->snd_strerror(resultALSA));
return ma_result_from_errno((int)-resultALSA);
}
}
@@ -29939,7 +29939,7 @@ static ma_result ma_device_step__alsa(ma_device* pDevice, ma_blocking_mode block
if (deviceType == ma_device_type_playback || deviceType == ma_device_type_duplex) {
resultALSA = pContextStateALSA->snd_pcm_poll_descriptors_revents(pDeviceStateALSA->pPCMPlayback, pDeviceStateALSA->pPollDescriptors + 1 + pDeviceStateALSA->pollDescriptorCountCapture, pDeviceStateALSA->pollDescriptorCountPlayback, &revents);
if (resultALSA < 0) {
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] snd_pcm_poll_descriptors_revents() failed for playback.");
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] snd_pcm_poll_descriptors_revents() failed for playback. %s.", pContextStateALSA->snd_strerror(resultALSA));
return MA_ERROR;
}
@@ -29970,17 +29970,17 @@ static ma_result ma_device_step__alsa(ma_device* pDevice, ma_blocking_mode block
/* Underrun. Recover. If this fails we need to return an error. */
resultALSA = pContextStateALSA->snd_pcm_recover(pDeviceStateALSA->pPCMPlayback, resultALSA, MA_TRUE);
if (resultALSA < 0) {
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to recover playback device after underrun.");
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to recover playback device after underrun. %s.", pContextStateALSA->snd_strerror(resultALSA));
return ma_result_from_errno((int)-resultALSA);
}
resultALSA = pContextStateALSA->snd_pcm_start(pDeviceStateALSA->pPCMPlayback);
if (resultALSA < 0) {
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start playback device after underrun.");
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start playback device after underrun. %s.", pContextStateALSA->snd_strerror(resultALSA));
return ma_result_from_errno((int)-resultALSA);
}
} else {
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Unexpected error when writing to playback device. errno = %d.", (int)-resultALSA);
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Unexpected error when writing to playback device. %s.", pContextStateALSA->snd_strerror(resultALSA));
return ma_result_from_errno((int)-resultALSA);
}
}