我正在尝试构建iOS原生音频/视频聊天,并卡在音频上。声音是滞后的,缺少一些部分和扭曲。我用r9919和由原始构建脚本构建的最新版本(r10184)尝试了这一点。但是当我试图使用旧版本(r8444, r8926, r9132和r9137)从PerchRTC演示项目(https://github.com/perchco/perchrtc -脂肪库和公共头)一切似乎都很好(除了小回声)。我应该采取哪些预防措施来实现至少与(r8444, r8926, r9132和r9137)提供的相同的流媒体质量?我也尝试使用不同的音频编解码器和不同的媒体限制,仍然没有运气。我用这种方式创建音频连接
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];
使用此约束(尝试不同的组合)
mandatoryConstraints = @
[[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"]
];
optionalConstraints = @
[[RTCPair alloc] initWithKey:@"internalSctpDataChannels" value:@"true"],
[[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"]
];
在获得audioTrack之前,我还尝试了AVAudioSession的不同操作:
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描述在滞后和非滞后构建中看起来很相似(这个是offer - a=setup:actpass,answer有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
有什么建议吗?
Demo默认使用top speaker。您需要使用如下代码设置为主扬声器:
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];
}];