Commit cf397b6d authored by bejayoharen's avatar bejayoharen

olivier's device name patch for os x

git-svn-id: https://subversion.assembla.com/svn/portaudio/portaudio/trunk@1930 0f58301d-fd10-0410-b4af-bbb618454e57
parent c9a6fb40
...@@ -125,83 +125,78 @@ static bool ensureChannelNameSize( int size ) ...@@ -125,83 +125,78 @@ static bool ensureChannelNameSize( int size )
*/ */
const char *PaMacCore_GetChannelName( int device, int channelIndex, bool input ) const char *PaMacCore_GetChannelName( int device, int channelIndex, bool input )
{ {
struct PaUtilHostApiRepresentation *hostApi; struct PaUtilHostApiRepresentation *hostApi;
PaError err; PaError err;
OSStatus error; OSStatus error;
err = PaUtil_GetHostApiRepresentation( &hostApi, paCoreAudio ); err = PaUtil_GetHostApiRepresentation( &hostApi, paCoreAudio );
assert(err == paNoError); assert(err == paNoError);
if( err != paNoError ) if( err != paNoError )
return NULL; return NULL;
PaMacAUHAL *macCoreHostApi = (PaMacAUHAL*)hostApi; PaMacAUHAL *macCoreHostApi = (PaMacAUHAL*)hostApi;
AudioDeviceID hostApiDevice = macCoreHostApi->devIds[device]; AudioDeviceID hostApiDevice = macCoreHostApi->devIds[device];
CFStringRef nameRef;
UInt32 size = 0;
/* First try with CFString */
error = AudioDeviceGetPropertyInfo( hostApiDevice, UInt32 size = sizeof(nameRef);
channelIndex + 1, error = AudioDeviceGetProperty( hostApiDevice,
input, channelIndex + 1,
kAudioDevicePropertyChannelName, input,
&size, kAudioDevicePropertyChannelNameCFString,
NULL ); &size,
if( error ) { &nameRef );
//try the CFString if( error )
CFStringRef name; {
bool isDeviceName = false; /* try the C String */
size = sizeof( name ); size = 0;
error = AudioDeviceGetProperty( hostApiDevice, error = AudioDeviceGetPropertyInfo( hostApiDevice,
channelIndex + 1, channelIndex + 1,
input, input,
kAudioDevicePropertyChannelNameCFString, kAudioDevicePropertyChannelName,
&size, &size,
&name ); NULL);
if( error ) { //as a last-ditch effort, get the device name. Later we'll append the channel number. if( !error )
size = sizeof( name ); {
error = AudioDeviceGetProperty( hostApiDevice, if( !ensureChannelNameSize( size ) )
channelIndex + 1, return NULL;
input,
kAudioDevicePropertyDeviceNameCFString, error = AudioDeviceGetProperty( hostApiDevice,
&size, channelIndex + 1,
&name ); input,
if( error ) kAudioDevicePropertyChannelName,
return NULL; &size,
isDeviceName = true; channelName );
}
if( isDeviceName ) {
name = CFStringCreateWithFormat( NULL, NULL, CFSTR( "%@: %d"), name, channelIndex + 1 ); if( !error )
} return channelName;
}
CFIndex length = CFStringGetLength(name);
while( ensureChannelNameSize( length * sizeof(UniChar) + 1 ) ) { /* as a last-ditch effort, we use the device name and append the channel number. */
if( CFStringGetCString( name, channelName, channelNameSize, kCFStringEncodingUTF8 ) ) { nameRef = CFStringCreateWithFormat( NULL, NULL, CFSTR( "%s: %d"), hostApi->deviceInfos[device]->name, channelIndex + 1 );
if( isDeviceName )
CFRelease( name );
return channelName; size = CFStringGetMaximumSizeForEncoding(CFStringGetLength(nameRef), kCFStringEncodingUTF8);;
} if( !ensureChannelNameSize( size ) )
if( length == 0 ) {
++length; CFRelease( nameRef );
length *= 2; return NULL;
} }
if( isDeviceName ) CFStringGetCString( nameRef, channelName, size+1, kCFStringEncodingUTF8 );
CFRelease( name ); CFRelease( nameRef );
return NULL; }
} else
{
//continue with C string: size = CFStringGetMaximumSizeForEncoding(CFStringGetLength(nameRef), kCFStringEncodingUTF8);;
if( !ensureChannelNameSize( size ) ) if( !ensureChannelNameSize( size ) )
return NULL; {
CFRelease( nameRef );
error = AudioDeviceGetProperty( hostApiDevice, return NULL;
channelIndex + 1, }
input, CFStringGetCString( nameRef, channelName, size+1, kCFStringEncodingUTF8 );
kAudioDevicePropertyChannelName, CFRelease( nameRef );
&size, }
channelName );
return channelName;
if( error ) {
ERR( error );
return NULL;
}
return channelName;
} }
...@@ -657,6 +652,7 @@ static PaError InitializeDeviceInfo( PaMacAUHAL *auhalHostApi, ...@@ -657,6 +652,7 @@ static PaError InitializeDeviceInfo( PaMacAUHAL *auhalHostApi,
Float64 sampleRate; Float64 sampleRate;
char *name; char *name;
PaError err = paNoError; PaError err = paNoError;
CFStringRef nameRef;
UInt32 propSize; UInt32 propSize;
VVDBUG(("InitializeDeviceInfo(): macCoreDeviceId=%ld\n", macCoreDeviceId)); VVDBUG(("InitializeDeviceInfo(): macCoreDeviceId=%ld\n", macCoreDeviceId));
...@@ -665,18 +661,37 @@ static PaError InitializeDeviceInfo( PaMacAUHAL *auhalHostApi, ...@@ -665,18 +661,37 @@ static PaError InitializeDeviceInfo( PaMacAUHAL *auhalHostApi,
deviceInfo->structVersion = 2; deviceInfo->structVersion = 2;
deviceInfo->hostApi = hostApiIndex; deviceInfo->hostApi = hostApiIndex;
/* Get the device name. Fail if we can't get it. */ /* Get the device name using CFString */
err = ERR(AudioDeviceGetPropertyInfo(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, NULL)); propSize = sizeof(nameRef);
if (err) err = ERR(AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceNameCFString, &propSize, &nameRef));
return err;
name = PaUtil_GroupAllocateMemory(auhalHostApi->allocations,propSize);
if ( !name )
return paInsufficientMemory;
err = ERR(AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, name));
if (err) if (err)
return err; {
/* Get the device name using c string. Fail if we can't get it. */
err = ERR(AudioDeviceGetPropertyInfo(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, NULL));
if (err)
return err;
name = PaUtil_GroupAllocateMemory(auhalHostApi->allocations,propSize+1);
if ( !name )
return paInsufficientMemory;
err = ERR(AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, name));
if (err)
return err;
}
else
{
/* valid CFString so we just allocate a c string big enough to contain the data */
propSize = CFStringGetMaximumSizeForEncoding(CFStringGetLength(nameRef), kCFStringEncodingUTF8);
name = PaUtil_GroupAllocateMemory(auhalHostApi->allocations, propSize+1);
if ( !name )
{
CFRelease(nameRef);
return paInsufficientMemory;
}
CFStringGetCString(nameRef, name, propSize+1, kCFStringEncodingUTF8);
CFRelease(nameRef);
}
deviceInfo->name = name; deviceInfo->name = name;
/* Try to get the default sample rate. Don't fail if we can't get this. */ /* Try to get the default sample rate. Don't fail if we can't get this. */
......
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