2

我正在尝试构建 iOS 原生音频/视频聊天并停留在音频上。声音滞后,缺少某些部分并失真。我用 r9919 和由原始构建脚本构建的最新版本 (r10184) 进行了尝试。但是当我尝试使用取自 PerchRTC 演示项目(https://github.com/perchco/perchrtc - fat lib 和公共头文件)的旧版本(r8444、r8926、r9132 和 r9137)时,一切似乎都很好(除了小回声)。我应该执行哪些预操作以至少获得与(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];

使用这个约束(尝试了不同的组合)

强制约束 = @[

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

                                 ];

可选约束 = @[

                                [[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 描述在滞后和非滞后构建中看起来相似(这是提供 - 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

有什么建议么?

4

1 回答 1

1

Demo 默认使用顶部扬声器。您需要使用如下代码设置为主扬声器:

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];
                             }];
于 2016-08-26T07:16:23.863 回答