AgoraIO / AgoraRtcEngine_iOS

iOS Package for Agora Video RTE SDK. Perfect for video calls and live streaming.
https://agoraio.github.io/AgoraRtcEngine_iOS/
MIT License
58 stars 17 forks source link

After starting Agora call Video audio volume changes to really low. #52

Closed pkuzia closed 10 months ago

pkuzia commented 11 months ago

Hello!

I work on an application where users can watch streams and simultaneously be in video call with other users. I use Agora library for this and all call-related stuff works really well. The issue that I have is that after starting or joining to call and changing AVAudioSession mode and category, stream audio volume changes to really low.

Technical context:

Agora settings:

agoraEngine = AgoraRtcEngineKit.sharedEngine(with: configuration, delegate: self)
agoraEngine.setAudioSessionOperationRestriction(.all)
agoraEngine.setChannelProfile(.liveBroadcasting)
agoraEngine.setClientRole(.broadcaster)

...

agoraEngine.enableVideo()
agoraEngine.enableAudio()
agoraEngine.setDefaultAudioRouteToSpeakerphone(true)
agoraEngine.setChannelProfile(.liveBroadcasting)
agoraEngine.setClientRole(.broadcaster)

let option = AgoraRtcChannelMediaOptions()
option.clientRoleType = .broadcaster
option.channelProfile = .liveBroadcasting
option.autoSubscribeAudio = true
option.autoSubscribeVideo = true

...

agoraEngine.enableLocalVideo(true)
agoraEngine.enableLocalAudio(true)

agoraEngine.muteLocalAudioStream(false)
agoraEngine.muteLocalVideoStream(false)

AVAudioSession settings:

Basically to provide the best audio experience app sets AVAudioSession while watching stream to:

try? AVAudioSession.sharedInstance().setMode(.default)
try? AVAudioSession.sharedInstance().setCategory(
    .playback, options: [.mixWithOthers, .defaultToSpeaker, .allowBluetooth]
)

When Agora call is active app sets AVAudioSession to:

try? AVAudioSession.sharedInstance().setMode(.videoChat)
try? AVAudioSession.sharedInstance().setCategory(
    .playAndRecord, options: [.mixWithOthers, .defaultToSpeaker, .allowBluetooth]
)

After switching AVAudioSession to videoChat and playAndRecord stream audio changes to really low, but Agora call audio is normal. Both - Agora audio signal volume (adjustPlaybackSignalVolume) and steam player volume are set to 100%. Device audio volume is also set to 100%.

Am I missing something? Should I set the AVAudioSession settings differently? Does Agora lib have ability to set the audio mix ratio between a call volume and another audio source that uses AVAudioSession?

maxxfrazer commented 11 months ago

@pkuzia this sounds like an audio ducking issue. try out setting the audio profile to .speechStandard, that's fixed in for me in the past:

pkuzia commented 11 months ago

Hey @maxxfrazer ! Thank you so much for your answer.

Setting .speechStandard as AudioProfile didn't work in my case but I found another function: setAudioScenario. I set .meeting as a parameter, and the volume remains stable.

Surprisingly, I have to set .meeting as scenario only when the user is a guest. When user is a host I have to set scenario as .default to provide stable sound.

maxxfrazer commented 10 months ago

I'm glad .meeting worked for you at least!

For bugs/support in the future, we do have a dedicated support dashboard: https://agora-ticket.agora.io/