From d5140e9206c6d8727841bad771e36dd865f8c683 Mon Sep 17 00:00:00 2001 From: pkviet Date: Sat, 9 Dec 2017 15:34:25 +0100 Subject: [PATCH] mac-capture: Update fix for Soundflower Some audio devices do not have a fixed number of channels. For example, Soundflower. This was previously fixed by defaulting the speaker layout to stereo. With surround sound support, the default has been changed to the output speaker layout as set in Settings > Audio. Closes jp9000/obs-studio#1110 --- plugins/mac-capture/mac-audio.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/plugins/mac-capture/mac-audio.c b/plugins/mac-capture/mac-audio.c index 56bf557cc..368480841 100644 --- a/plugins/mac-capture/mac-audio.c +++ b/plugins/mac-capture/mac-audio.c @@ -205,6 +205,14 @@ static bool coreaudio_init_format(struct coreaudio_data *ca) AudioStreamBasicDescription desc; OSStatus stat; UInt32 size = sizeof(desc); + struct obs_audio_info aoi; + int channels; + + if (!obs_get_audio_info(&aoi)) { + blog(LOG_WARNING, "No active audio"); + return false; + } + channels = get_audio_channels(aoi.speakers); stat = get_property(ca->unit, kAudioUnitProperty_StreamFormat, SCOPE_INPUT, BUS_INPUT, &desc, &size); @@ -213,13 +221,13 @@ static bool coreaudio_init_format(struct coreaudio_data *ca) /* Certain types of devices have no limit on channel count, and * there's no way to know the actual number of channels it's using, - * so if we encounter this situation just force to stereo */ - if (desc.mChannelsPerFrame > 8) { - desc.mChannelsPerFrame = 2; - desc.mBytesPerFrame = 2 * desc.mBitsPerChannel / 8; - desc.mBytesPerPacket = - desc.mFramesPerPacket * desc.mBytesPerFrame; - } + * so if we encounter this situation just force to what is defined in output */ + if (desc.mChannelsPerFrame > 8) { + desc.mChannelsPerFrame = channels; + desc.mBytesPerFrame = channels * desc.mBitsPerChannel / 8; + desc.mBytesPerPacket = + desc.mFramesPerPacket * desc.mBytesPerFrame; + } stat = set_property(ca->unit, kAudioUnitProperty_StreamFormat, SCOPE_OUTPUT, BUS_INPUT, &desc, size); -- GitLab