Devices with the same device description cannot be distinguished. Add card number to the description of second and subsequent instances of devices with the same description. This mimics Windows behavior.
Signed-off-by: Doug Kingston dpk@google.com --- dlls/winealsa.drv/mmdevdrv.c | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
diff --git a/dlls/winealsa.drv/mmdevdrv.c b/dlls/winealsa.drv/mmdevdrv.c index 318350471db..a26d09a0bd7 100644 --- a/dlls/winealsa.drv/mmdevdrv.c +++ b/dlls/winealsa.drv/mmdevdrv.c @@ -22,6 +22,8 @@ #include "config.h"
#include <stdarg.h> +#define _GNU_SOURCE +#include <stdio.h> #include <math.h>
#include "windef.h" @@ -521,6 +523,36 @@ static void get_reg_devices(EDataFlow flow, snd_pcm_stream_t stream, WCHAR ***id } }
+struct card_type { + struct list entry; + int first_card_number; + char string[1]; +}; + +static struct list card_types = LIST_INIT(card_types); + +static BOOL need_card_number(int card, const char *string) +{ + struct card_type *cptr; + + LIST_FOR_EACH_ENTRY(cptr, &card_types, struct card_type, entry) + { + if(!strcmp(string, cptr->string)) + return card != cptr->first_card_number; + } + + /* this is the first instance of string */ + cptr = HeapAlloc(GetProcessHeap(), 0, sizeof(struct card_type) + strlen(string)); + if(!cptr) + /* Default to displaying card number if we can't track cards */ + return TRUE; + + cptr->first_card_number = card; + strcpy(cptr->string, string); + list_add_head(&card_types, &cptr->entry); + return FALSE; +} + static HRESULT alsa_enum_devices(EDataFlow flow, WCHAR ***ids, GUID **guids, UINT *num) { @@ -564,6 +596,17 @@ static HRESULT alsa_enum_devices(EDataFlow flow, WCHAR ***ids, GUID **guids, cardpath, err, snd_strerror(err)); alsa_get_card_devices(flow, stream, ids, guids, num, ctl, card, nameW); }else{ + if(need_card_number(card, cardname)){ + char *cardnameN; + /* + * For identical instances, second and subsequent instances get + * instance number prefix to distinguish them (like Windows). + */ + if(asprintf(&cardnameN, "%u-%s", card, cardname) > 0){ + free(cardname); + cardname = cardnameN; + } + } len = MultiByteToWideChar(CP_UNIXCP, 0, cardname, -1, NULL, 0); cardnameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
-- 2.24.3 (Apple Git-128)
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=85529
Your paranoid android.
=== debiant2 (build log) ===
error: corrupt patch at line 24 Task: Patch failed to apply
=== debiant2 (build log) ===
error: corrupt patch at line 24 Task: Patch failed to apply