diff options
author | Liong Sauw Ming <ming@teluu.com> | 2011-01-13 16:42:21 +0000 |
---|---|---|
committer | Liong Sauw Ming <ming@teluu.com> | 2011-01-13 16:42:21 +0000 |
commit | a22edb7e705e27853307a483f60e16cf2a07ff9d (patch) | |
tree | 10799711be2748f52cb91bb32522c6e1f698bda0 /pjmedia/src/pjmedia-audiodev/coreaudio_dev.c | |
parent | cd50e094430a4105fb181d0c524445a97bb21d35 (diff) |
Fix #1195: assertion during thread registration in coreaudio and portaudio's input/output callbacks on Mac OS X and #1196: using system's default audio input/output device instead of first available device.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3404 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjmedia/src/pjmedia-audiodev/coreaudio_dev.c')
-rw-r--r-- | pjmedia/src/pjmedia-audiodev/coreaudio_dev.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/pjmedia/src/pjmedia-audiodev/coreaudio_dev.c b/pjmedia/src/pjmedia-audiodev/coreaudio_dev.c index b235b7e5..e8c77e60 100644 --- a/pjmedia/src/pjmedia-audiodev/coreaudio_dev.c +++ b/pjmedia/src/pjmedia-audiodev/coreaudio_dev.c @@ -417,6 +417,49 @@ static pj_status_t ca_factory_refresh(pjmedia_aud_dev_factory *f) */ return PJMEDIA_EAUD_INIT; } + + if (dev_size > 1) { + AudioDeviceID dev_id = kAudioObjectUnknown; + unsigned idx = 0; + + /* Find default audio input device */ + addr.mSelector = kAudioHardwarePropertyDefaultInputDevice; + addr.mScope = kAudioObjectPropertyScopeGlobal; + addr.mElement = kAudioObjectPropertyElementMaster; + size = sizeof(dev_id); + + ostatus = AudioObjectGetPropertyData(kAudioObjectSystemObject, + &addr, 0, NULL, + &size, (void *)&dev_id); + if (ostatus != noErr && dev_id != dev_ids[idx]) { + AudioDeviceID temp_id = dev_ids[idx]; + + for (i = idx + 1; i < dev_size; i++) { + if (dev_ids[i] == dev_id) { + dev_ids[idx++] = dev_id; + dev_ids[i] = temp_id; + break; + } + } + } + + /* Find default audio output device */ + addr.mSelector = kAudioHardwarePropertyDefaultOutputDevice; + ostatus = AudioObjectGetPropertyData(kAudioObjectSystemObject, + &addr, 0, NULL, + &size, (void *)&dev_id); + if (ostatus != noErr && dev_id != dev_ids[idx]) { + AudioDeviceID temp_id = dev_ids[idx]; + + for (i = idx + 1; i < dev_size; i++) { + if (dev_ids[i] == dev_id) { + dev_ids[idx] = dev_id; + dev_ids[i] = temp_id; + break; + } + } + } + } /* Build the devices' info */ cf->dev_info = (struct coreaudio_dev_info*) @@ -649,6 +692,7 @@ static OSStatus resample_callback(void *inRefCon, */ if (strm->rec_thread_initialized == 0 || !pj_thread_is_registered()) { + pj_bzero(strm->rec_thread_desc, sizeof(pj_thread_desc)); status = pj_thread_register("ca_rec", strm->rec_thread_desc, &strm->rec_thread); strm->rec_thread_initialized = 1; @@ -789,6 +833,7 @@ static OSStatus input_callback(void *inRefCon, */ if (strm->rec_thread_initialized == 0 || !pj_thread_is_registered()) { + pj_bzero(strm->rec_thread_desc, sizeof(pj_thread_desc)); status = pj_thread_register("ca_rec", strm->rec_thread_desc, &strm->rec_thread); strm->rec_thread_initialized = 1; @@ -904,6 +949,7 @@ static OSStatus output_renderer(void *inRefCon, */ if (stream->play_thread_initialized == 0 || !pj_thread_is_registered()) { + pj_bzero(stream->play_thread_desc, sizeof(pj_thread_desc)); status = pj_thread_register("coreaudio", stream->play_thread_desc, &stream->play_thread); stream->play_thread_initialized = 1; |