UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
coreaudio.h File Reference
#include <stddef.h>
Include dependency graph for coreaudio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

AudioDeviceID audio_ca_get_device_by_name (const char *name, int dir)
 
void audio_ca_get_device_name (AudioDeviceID dev_id, size_t namebuf_len, char *namebuf)
 
void audio_ca_probe (struct device_info **available_devices, int *count, int dir)
 

Detailed Description

Function Documentation

◆ audio_ca_get_device_by_name()

AudioDeviceID audio_ca_get_device_by_name ( const char * name,
int dir )

@briew tries to get device id from device name

Parameters
namename of the device to be looked up
dirdirection -
See also
audio_ca_probe for values; dir is needed only for deafult device names

Definition at line 369 of file coreaudio.cpp.

370{
371 struct device_info *devices = NULL;
372 int count = 0;
373 audio_ca_probe(&devices, &count, dir);
374 for (int i = 0; i < count; ++i) {
375 if (strstr(devices[i].name, name) != NULL) {
376 return atoi(devices[i].dev + 1);
377 }
378 }
379 return UINT_MAX;
380}
void audio_ca_probe(struct device_info **available_devices, int *count, int dir)
int count
Definition hd-rum.c:44
const char * name
Definition settings.cpp:193
char dev[1024]
Definition types.h:383

References audio_ca_probe(), count, device_info::dev, and name.

Referenced by audio_cap_ca_init(), and audio_play_ca_init().

Here is the call graph for this function:

◆ audio_ca_get_device_name()

void audio_ca_get_device_name ( AudioDeviceID dev_id,
size_t namebuf_len,
char * namebuf )

Definition at line 281 of file coreaudio.cpp.

282{
283 AudioObjectPropertyAddress propertyAddress{};
284 propertyAddress.mSelector = kAudioHardwarePropertyDevices;
285 propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
286 propertyAddress.mElement = kAudioObjectPropertyElementMain;
287 propertyAddress.mSelector = kAudioDevicePropertyDeviceNameCFString;
288 CFStringRef deviceName = NULL;
289 UInt32 size = sizeof(deviceName);
290 if (OSStatus ret = AudioObjectGetPropertyData(dev_id, &propertyAddress, 0, NULL, &size, &deviceName)) {
291 log_msg(LOG_LEVEL_WARNING, "[CoreAudio] Cannot get device %" PRIu32 " name: %s\n",
292 dev_id, get_osstatus_str(ret));
293 snprintf(namebuf, namebuf_len, "CoreAudio device #%" PRIu32 " (unable to get name)", dev_id);
294 return;
295 }
296 CFStringGetCString(deviceName, namebuf, namebuf_len, kCFStringEncodingMacRoman);
297 CFRelease(deviceName);
298}
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60
#define kAudioObjectPropertyElementMain
Definition macos.h:50
const char * get_osstatus_str(OSStatus err)
Definition macos.m:106

References get_osstatus_str(), kAudioObjectPropertyElementMain, LOG_LEVEL_WARNING, and log_msg().

Referenced by audio_ca_probe(), audio_cap_ca_init(), and audio_play_ca_init().

Here is the call graph for this function:

◆ audio_ca_probe()

void audio_ca_probe ( struct device_info ** available_devices,
int * count,
int dir )

Returns CoreAudio devices

Parameters
dir-1 capture; 1 playback

@briew probe for available capture/playback devices (direction given by parameter dir)

Parameters
dir-1 capture, 1 playback

Definition at line 305 of file coreaudio.cpp.

306{
307 assert(dir == -1 || dir == 1);
308 *available_devices =
309 (struct device_info *) calloc(1, sizeof(struct device_info));
310 snprintf((*available_devices)[0].dev, sizeof(*available_devices)[0].dev,
311 "");
312 snprintf((*available_devices)[0].name,
313 sizeof(*available_devices)[0].name, "Default CoreAudio %s",
314 dir == -1 ? "capture" : "playback");
315 *count = 1;
316
317 int dev_count;
318 AudioDeviceID *dev_ids;
319 OSStatus ret;
320 UInt32 size;
321 AudioObjectPropertyAddress propertyAddress;
322
323 propertyAddress.mSelector = kAudioHardwarePropertyDevices;
324 propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
325 propertyAddress.mElement = kAudioObjectPropertyElementMain;
326 ret = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size);
327 if (ret) {
328 log_msg(LOG_LEVEL_ERROR, MOD_NAME "Cannot get device list size: %s\n", get_osstatus_str(ret));
329 goto error;
330 }
331 dev_ids = (AudioDeviceID *) malloc(size);
332 dev_count = size / sizeof(AudioDeviceID);
333 ret = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size, dev_ids);
334 if (ret) {
335 log_msg(LOG_LEVEL_ERROR, MOD_NAME "Cannot get device list: %s\n", get_osstatus_str(ret));
336 goto error;
337 }
338
339 propertyAddress.mScope = dir == -1 ? kAudioObjectPropertyScopeInput : kAudioObjectPropertyScopeOutput;
340 for (int i = 0; i < dev_count; ++i) {
341 if (dir != 0 && !is_requested_direction(propertyAddress, &dev_ids[i])) {
342 continue;
343 }
344
345 (*count)++;
346 *available_devices = (struct device_info *) realloc(*available_devices, *count * sizeof(struct device_info));
347 memset(&(*available_devices)[*count - 1], 0, sizeof(struct device_info));
348
349 audio_ca_get_device_name(dev_ids[i], sizeof (*available_devices)[*count - 1].name,
350 (char *) (*available_devices)[*count - 1].name);
351 snprintf((*available_devices)[*count - 1].dev, sizeof (*available_devices)[*count - 1].dev,
352 ":%" PRIu32, dev_ids[i]);
353 }
354 free(dev_ids);
355
356 return;
357
358error:
359 LOG(LOG_LEVEL_ERROR) << MOD_NAME "Error obtaining device list.\n";
360}
void audio_ca_get_device_name(AudioDeviceID dev_id, size_t namebuf_len, char *namebuf)
#define MOD_NAME
Definition coreaudio.cpp:77
static bool is_requested_direction(AudioObjectPropertyAddress propertyAddress, AudioDeviceID *audioDevice)
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
#define LOG(level)
Definition debug.h:313

References audio_ca_get_device_name(), count, device_info::dev, get_osstatus_str(), is_requested_direction(), kAudioObjectPropertyElementMain, LOG, LOG_LEVEL_ERROR, log_msg(), MOD_NAME, and name.

Referenced by audio_ca_get_device_by_name(), audio_cap_ca_probe(), and audio_play_ca_probe().

Here is the call graph for this function: