# HG changeset patch # User Ryan C. Gordon # Date 1159900354 0 # Node ID 7006b176ef4f884961419896d6d23bdcdaebdcac # Parent 8d74a4721ca9993d3100b522e950ec3e51083732 More work on the 1.3 CoreAudio code. diff -r 8d74a4721ca9 -r 7006b176ef4f src/audio/SDL_audio.c --- a/src/audio/SDL_audio.c Tue Oct 03 16:26:42 2006 +0000 +++ b/src/audio/SDL_audio.c Tue Oct 03 18:32:34 2006 +0000 @@ -854,7 +854,7 @@ } /* Free the driver data */ - current_audio.Deinitialize(); + current_audio.impl.Deinitialize(); SDL_memset(¤t_audio, '\0', sizeof (current_audio)); SDL_memset(open_devices, '\0', sizeof (open_devices)); } diff -r 8d74a4721ca9 -r 7006b176ef4f src/audio/macosx/SDL_coreaudio.c --- a/src/audio/macosx/SDL_coreaudio.c Tue Oct 03 16:26:42 2006 +0000 +++ b/src/audio/macosx/SDL_coreaudio.c Tue Oct 03 18:32:34 2006 +0000 @@ -29,6 +29,7 @@ #include "../SDL_sysaudio.h" #include "SDL_coreaudio.h" +#define DEBUG_COREAUDIO 1 typedef struct COREAUDIO_DeviceList { @@ -88,10 +89,12 @@ return; for (i = 0; i < max; i++) { + CFStringRef cfstr = NULL; char *ptr = NULL; AudioDeviceID dev = devs[i]; AudioBufferList *buflist = NULL; int usable = 0; + CFIndex len = 0; result = AudioDeviceGetPropertyInfo(dev, 0, iscapture, kAudioDevicePropertyStreamConfiguration, @@ -122,32 +125,43 @@ if (!usable) continue; - /* !!! FIXME: use CFStrings, instead, and convert to UTF-8. */ - result = AudioDeviceGetPropertyInfo(dev, 0, iscapture, - kAudioDevicePropertyDeviceName, - &size, &outWritable); + size = sizeof (CFStringRef); + result = AudioDeviceGetProperty(dev, 0, iscapture, + kAudioObjectPropertyName, + &size, &cfstr); if (result != kAudioHardwareNoError) continue; - ptr = (char *) SDL_malloc(size + 1); - if (ptr == NULL) - continue; + len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr), + kCFStringEncodingUTF8); - result = AudioDeviceGetProperty(dev, 0, iscapture, - kAudioDevicePropertyDeviceName, - &size, ptr); + ptr = (char *) SDL_malloc(len + 1); + usable = ( (ptr != NULL) && + (CFStringGetCString(cfstr,ptr,len+1,kCFStringEncodingUTF8)) ); + + CFRelease(cfstr); - if (result != kAudioHardwareNoError) - continue; + if (usable) { + len = strlen(ptr); + /* Some devices have whitespace at the end...trim it. */ + while ((len > 0) && (ptr[len-1] == ' ')) { + len--; + } + usable = (len > 0); + } - while ((size > 0) && (ptr[size-1] == ' ')) - size--; /* I have a USB device with whitespace at the end... */ - - if (size == 0) { + if (!usable) { SDL_free(ptr); } else { - ptr[size] = '\0'; + ptr[len] = '\0'; + + #if DEBUG_COREAUDIO + printf("COREAUDIO: Found %s device #%d: '%s' (devid %d)\n", + ((iscapture) ? "capture" : "output"), + (int) *devCount, ptr, (int) dev); + #endif + (*devices)[*devCount].id = dev; (*devices)[*devCount].name = ptr; (*devCount)++; @@ -216,8 +230,8 @@ static void COREAUDIO_Deinitialize(void) { - free_device_list(0, &outputDevices, &outputDeviceCount); - free_device_list(1, &inputDevices, &inputDeviceCount); + free_device_list(&outputDevices, &outputDeviceCount); + free_device_list(&inputDevices, &inputDeviceCount); }