iosaudiowebrtcavaudiosessionaudio-capture

WebRTC iOS Native app audio problems with latest revisions


i'm trying to build iOS native audio/video chat and stucked on audio. The sound is lagging, missing some parts and distorting. I tried this with r9919 and the latest one (r10184) builded by pristine build scripts. But when I tried to use older versions (r8444, r8926, r9132 and r9137) taken from PerchRTC Demo project (https://github.com/perchco/perchrtc - fat lib and public headers) everything seems ok (except little echo). What preactions should I perform to achieve at least the same streaming quality as (r8444, r8926, r9132 and r9137) provide? I also tried to use different audio codecs and different media constraints, still have no luck. I create audio connection this way

RTCMediaStream *localStream = [_pcFactory mediaStreamWithLabel:@"ARDAMS"];

RTCAudioTrack *localAudioTrack = [_pcFactory audioTrackWithID:@"ARDAMSa0"];

localAudioTrack.delegate = self;

[localStream addAudioTrack:localAudioTrack];

[self.peerConnection addStream:localStream];

[self.peerConnection createOfferWithDelegate:self constraints:_constraints];

using this constraints (tried different combinations)

mandatoryConstraints = @[

                                 [[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"]

                                 ];

optionalConstraints = @[

                                [[RTCPair alloc] initWithKey:@"internalSctpDataChannels" value:@"true"],

                                [[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"]

                                ];

Also I tried to different manipulations with AVAudioSession before obtaining audioTrack with no luck:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];

[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&categoryError];

[audioSession setMode:AVAudioSessionModeVoiceChat error:&modeError];

[audioSession overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&overrideError];

[audioSession setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&activeError];

SDP descriptions look similar in lagging and not lagging builds (this one is offer - a=setup:actpass,answer has a=setup:active):

sdp = "v=0

o=- 7772121714021031999 2 IN IP4 127.0.0.1

s=-

t=0 0

a=group:BUNDLE audio

a=msid-semantic: WMS ARDAMS

m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 102 0 8 106 105 13 127 126

c=IN IP4 0.0.0.0

a=rtcp:9 IN IP4 0.0.0.0

a=ice-ufrag:XLpFvB+JEaSN7tww

a=ice-pwd:9hoMfb7AJ9jC6Weej7qqTWkT

a=fingerprint:sha-256 AE:73:33:DD:31:CA:84:5A:96:4D:68:27:A0:23:82:3C:08:3B:7F:7B:A2:FE:91:1D:A7:3A:1F:2A:58:4B:FF:A2

a=setup:actpass

a=mid:audio

a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level

a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time

a=sendrecv

a=rtcp-mux

a=rtpmap:111 opus/48000/2

a=fmtp:111 minptime=10; useinbandfec=1

a=rtpmap:103 ISAC/16000

a=rtpmap:104 ISAC/32000

a=rtpmap:9 G722/8000

a=rtpmap:102 ILBC/8000

a=rtpmap:0 PCMU/8000

a=rtpmap:8 PCMA/8000

a=rtpmap:106 CN/32000

a=rtpmap:105 CN/16000

a=rtpmap:13 CN/8000

a=rtpmap:127 red/8000

a=rtpmap:126 telephone-event/8000

a=maxptime:60

a=ssrc:2797474154 cname:43zbAmj6VvYHT31F

a=ssrc:2797474154 msid:ARDAMS ARDAMSa0

a=ssrc:2797474154 mslabel:ARDAMS

a=ssrc:2797474154 label:ARDAMSa0

Any suggestions?


Solution

  • The Demo is using the top speaker by default. You need set to main speaker using code like this:

    AVAudioSessionPortOverride override = AVAudioSessionPortOverrideSpeaker;
    [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeAudioSession
                                 block:^{
                                     RTCAudioSession *session =     [RTCAudioSession sharedInstance];
                                     [session lockForConfiguration];
                                     NSError *error = nil;
                                     if ([session overrideOutputAudioPort:override error:&error]) {
                                         _portOverride = override;
                                     } else {
                                         RTCLogError(@"Error overriding output port: %@",
                                                     error.localizedDescription);
                                     }
                                     [session unlockForConfiguration];
                                 }];