SIPSorcery - 去电语音噪音大,质量差

问题描述 投票:0回答:0

我使用 SIPSorcery 来构建 Softphone,包括注册、接听来电和拨出电话。

来电工作正常(语音传入和传出都很好)但传出电话有一些问题。

打其他分机时(例如:118打117),语音进出正常,但当CALL TO PHONE NUMBER时,进出声音很吵,但出声很好。

拨打电话功能如下:

    var sipTransport = new SIPTransport();

    var audioSession = new WindowsAudioEndPoint(new AudioEncoder(true));
    // audioSession.RestrictFormats(x => x.Codec == AudioCodecsEnum.PCMA || x.Codec == AudioCodecsEnum.PCMU);
    var rtpSession = new VoIPMediaSession(audioSession.ToMediaEndPoints());
    rtpSession.AcceptRtpFromAny = true;
    var preferIPv6 = false;
    var offerSDP = rtpSession.CreateOffer(preferIPv6 ? IPAddress.IPv6Any : IPAddress.Any);

    var userAgent = new SIPUserAgent(sipTransport, null);

    Extensions.EnableTraceLogs(sipTransport);

    userAgent.ClientCallAnswered += async (ua, res) =>
    {
        _logger.LogInformation($"Call is accepted by client machine");

        _soundHelper.PlaySound(@"Sounds/phone-pick-up-2.wav");

        await _hubContext?.Clients?.Client(connectionId)?.SendAsync(Strings.Events.OnAccept, ua.SIPDialogue?.CallId);

        var result = rtpSession.SetRemoteDescription(SdpType.answer, SDP.ParseSDPDescription(res.Body));
        if (result == SetDescriptionResultEnum.OK)
        {
            await rtpSession.Start();
        }
        else
        {
            _logger.LogWarning($"Failed to set remote description {result}.");
            userAgent.Hangup();
        }
    };

    var sipDescriptor = new SIPCallDescriptor(
        username: sipInfo.Username,
        password: sipInfo.Password,
        uri: $"{destination}",
        //uri: $"{destination};transport={(SIPProtocolsEnum)sipInfo.Protocol}",
        from: sipInfo.URI,
        to: destination,
        routeSet: null,
        customHeaders: new List<string> {
            "Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH,MESSAGE",
            $"User-Agent: {USER_AGENT}"
        },
        authUsername: sipInfo.AuthUsername,
        SIPCallDirection.Out,
        contentType: SDP.SDP_MIME_CONTENTTYPE,
        content: null, // offerSDP.ToString(),
        mangleIPAddress: null
    );

    sipDescriptor.SetGeneralFromHeaderFields(sipInfo.DisplayName, null, null);

    sipInfo.UAO = userAgent;

    userAgent.Call(sipDescriptor, rtpSession, RINGING_TIMEOUT);

在这里登录:

SIP/2.0 183 Session Progress
Via: SIP/2.0/TCP 172.16.118.248:56217;rport=56217;received=172.16.118.248;branch=z9hG4bK331951b79dc24a81806c35617f5e8c24
To: <sip:[email protected]>;tag=8b6eb528-2bfa-4abf-82d4-99718dda1c3f
From: "Phuong Dông" <sip:[email protected]>;tag=IJDAHPFLCC
Call-ID: 550a382c9e2548698fac012355d46d79
CSeq: 2 INVITE
Contact: <sip:[email protected]:5060;transport=TCP>
Allow: OPTIONS, INFO, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REFER, MESSAGE, REGISTER
Server: Grandstream UCM6208V1.4A 1.0.20.48
Content-Length: 286
Content-Type: application/sdp



v=0
o=- 1828996934 3 IN IP4 172.16.10.30
s=Asterisk
c=IN IP4 172.16.10.30
t=0 0
m=audio 13780 RTP/AVP 8 0 9 18 101
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:9 G722/8000
a=rtpmap:18 G729/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20
a=sendrecv

我错过了什么吗?

c# asterisk sip
© www.soinside.com 2019 - 2024. All rights reserved.