Commit 9f4a9e42 authored by David Reid's avatar David Reid

ALSA: Bug fixes for the new device iteration system.

parent 8f932b3c
...@@ -1365,10 +1365,6 @@ void mal_pcm_convert(void* pOut, mal_format formatOut, const void* pIn, mal_form ...@@ -1365,10 +1365,6 @@ void mal_pcm_convert(void* pOut, mal_format formatOut, const void* pIn, mal_form
#include <dlfcn.h> #include <dlfcn.h>
#endif #endif
#ifdef MAL_ENABLE_ALSA
#include <stdio.h> // Needed for sprintf() which is used for "hw:%d,%d" formatting. TODO: Remove this later.
#endif
#if !defined(MAL_64BIT) && !defined(MAL_32BIT) #if !defined(MAL_64BIT) && !defined(MAL_32BIT)
#ifdef _WIN32 #ifdef _WIN32
#ifdef _WIN64 #ifdef _WIN64
...@@ -5470,10 +5466,10 @@ static int mal_convert_device_name_to_hw_format__alsa(mal_context* pContext, cha ...@@ -5470,10 +5466,10 @@ static int mal_convert_device_name_to_hw_format__alsa(mal_context* pContext, cha
const char* dev = mal_find_char(src, ',', &commaPos); const char* dev = mal_find_char(src, ',', &commaPos);
if (dev == NULL) { if (dev == NULL) {
dev = "0"; dev = "0";
mal_strncpy_s(card, sizeof(card), src+5, (size_t)-1); mal_strncpy_s(card, sizeof(card), src+6, (size_t)-1); // +6 = ":CARD="
} else { } else {
dev = dev + 4; dev = dev + 5; // +5 = ",DEV="
mal_strncpy_s(card, sizeof(card), src+5, commaPos-5); mal_strncpy_s(card, sizeof(card), src+6, commaPos-6); // +6 = ":CARD="
} }
int cardIndex = ((mal_snd_card_get_index_proc)pContext->alsa.snd_card_get_index)(card); int cardIndex = ((mal_snd_card_get_index_proc)pContext->alsa.snd_card_get_index)(card);
...@@ -5481,7 +5477,7 @@ static int mal_convert_device_name_to_hw_format__alsa(mal_context* pContext, cha ...@@ -5481,7 +5477,7 @@ static int mal_convert_device_name_to_hw_format__alsa(mal_context* pContext, cha
return -2; // Failed to retrieve the card index. return -2; // Failed to retrieve the card index.
} }
printf("TESTING: CARD=%s,DEV=%s\n", card, dev); //printf("TESTING: CARD=%s,DEV=%s\n", card, dev);
// Construction. // Construction.
...@@ -5511,6 +5507,7 @@ static mal_result mal_enumerate_devices__alsa(mal_context* pContext, mal_device_ ...@@ -5511,6 +5507,7 @@ static mal_result mal_enumerate_devices__alsa(mal_context* pContext, mal_device_
return MAL_NO_BACKEND; return MAL_NO_BACKEND;
} }
char** ppNextDeviceHint = ppDeviceHints; char** ppNextDeviceHint = ppDeviceHints;
while (*ppNextDeviceHint != NULL) { while (*ppNextDeviceHint != NULL) {
char* NAME = ((mal_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "NAME"); char* NAME = ((mal_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "NAME");
...@@ -5533,7 +5530,10 @@ static mal_result mal_enumerate_devices__alsa(mal_context* pContext, mal_device_ ...@@ -5533,7 +5530,10 @@ static mal_result mal_enumerate_devices__alsa(mal_context* pContext, mal_device_
printf("NAME: %s\n", NAME); printf("NAME: %s\n", NAME);
printf("DESC: %s\n", DESC); printf("DESC: %s\n", DESC);
printf("IOID: %s\n", IOID); printf("IOID: %s\n", IOID);
printf("\n");
char hwid[256];
mal_convert_device_name_to_hw_format__alsa(pContext, hwid, sizeof(hwid), NAME);
printf("DEVICE ID: %s\n\n", hwid);
#endif #endif
if (pInfo != NULL) { if (pInfo != NULL) {
...@@ -5605,7 +5605,7 @@ static mal_result mal_device_init__alsa(mal_context* pContext, mal_device_type t ...@@ -5605,7 +5605,7 @@ static mal_result mal_device_init__alsa(mal_context* pContext, mal_device_type t
// When opening the device, we first try opening it based on the name provided in deviceName. If this fails, fall back to the "hw:%d,%d". // When opening the device, we first try opening it based on the name provided in deviceName. If this fails, fall back to the "hw:%d,%d".
snd_pcm_stream_t stream = (type == mal_device_type_playback) ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE; snd_pcm_stream_t stream = (type == mal_device_type_playback) ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE;
if (((mal_snd_pcm_open_proc)pContext->alsa.snd_pcm_open)((snd_pcm_t**)&pDevice->alsa.pPCM, deviceName, stream, 0) < 0) { if (((mal_snd_pcm_open_proc)pContext->alsa.snd_pcm_open)((snd_pcm_t**)&pDevice->alsa.pPCM, deviceName, stream, 0) < 0) {
printf("Failed 1\n"); //printf("Failed first attempt at opening device.\n");
if (mal_strcmp(deviceName, "default") == 0 || mal_strcmp(deviceName, "pulse") == 0) { if (mal_strcmp(deviceName, "default") == 0 || mal_strcmp(deviceName, "pulse") == 0) {
// We may have failed to open the default device. Try falling back to the "hw" or "plughw" device, depending on preferences. // We may have failed to open the default device. Try falling back to the "hw" or "plughw" device, depending on preferences.
if (pConfig->alsa.preferPlugHW) { if (pConfig->alsa.preferPlugHW) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment