diff --git a/plugins/mac-capture/mac-audio.c b/plugins/mac-capture/mac-audio.c index 56bf557ccd05701bfc9db9382a60f78aee926415..368480841367842911e85dbf163a8d90559d5ab3 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);