Android setRemoteDesctiption WebRtc返回错误SessionDescription为NULL

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

我正在关注this guide以在Android应用中实现WebRtc。出于测试目的,我在一台设备上使用createOffer()生成了一个sdp,然后将该sdp粘贴到另一台设备上的setRemoteDescription()方法中。但它说onSetFailure() called with: s = [SessionDescription is NULL.]

但是它不是空的!我正在使用官方的lib版本:实现“ org.webrtc:google-webrtc:1.0.22672”。

我的sdp看起来像这样:

v=0
o=- 3635975532777709566 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio video
a=msid-semantic: WMS 102
m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 102 0 8 106 105 13 110 112 113 126
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:7GHL
a=ice-pwd:2t88ckFp9GNCvHSuz1Zh9bfm
a=ice-options:trickle renomination
a=fingerprint:sha-256 63:A9:6A:A9:99:91:42:32:33:E7:01:B6:C9:69:F0:72:63:D4:C3:EC:F7:DA:56:71:C8:DD:65:B9:95:C6:5E:A4
a=setup:actpass
a=mid:audio
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=sendrecv
a=rtcp-mux
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
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:110 telephone-event/48000
a=rtpmap:112 telephone-event/32000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000
a=ssrc:4038374106 cname:+k3jOS/KAhQMKOq3
a=ssrc:4038374106 msid:102 101
a=ssrc:4038374106 mslabel:102
a=ssrc:4038374106 label:101
m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 127
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:7GHL
a=ice-pwd:2t88ckFp9GNCvHSuz1Zh9bfm
a=ice-options:trickle renomination
a=fingerprint:sha-256 63:A9:6A:A9:99:91:42:32:33:E7:01:B6:C9:69:F0:72:63:D4:C3:EC:F7:DA:56:71:C8:DD:65:B9:95:C6:5E:A4
a=setup:actpass
a=mid:video
a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:3gpp:video-orientation
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
a=sendrecv
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:96 VP8/90000
a=rtcp-fb:96 goog-remb
a=rtcp-fb:96 transport-cc
a=rtcp-fb:96 ccm fir
a=rtcp-fb:96 nack
a=rtcp-fb:96 nack pli
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtpmap:98 VP9/90000
a=rtcp-fb:98 goog-remb
a=rtcp-fb:98 transport-cc
a=rtcp-fb:98 ccm fir
a=rtcp-fb:98 nack
a=rtcp-fb:98 nack pli
a=rtpmap:99 rtx/90000
a=fmtp:99 apt=98
a=rtpmap:100 red/90000
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=rtpmap:127 ulpfec/90000
a=ssrc-group:FID 2007914204 2080922876
a=ssrc:2007914204 cname:+k3jOS/KAhQMKOq3
a=ssrc:2007914204 msid:102 100
a=ssrc:2007914204 mslabel:102
a=ssrc:2007914204 label:100
a=ssrc:2080922876 cname:+k3jOS/KAhQMKOq3
a=ssrc:2080922876 msid:102 100
a=ssrc:2080922876 mslabel:102
a=ssrc:2080922876 label:100

我的同事iOS开发人员有同样的问题。我手动粘贴了sdp,没有任何信令服务器,只是为了检查它是否正常工作,因此sdp不会被损坏或更改。

下面是创建peerConnection并提供的代码:

  /**
 * Creating the local peerconnection instance
 */
private void createPeerConnection() {
    Log.d(TAG, "createPeerConnection()");

    PeerConnection.RTCConfiguration rtcConfig =
            new PeerConnection.RTCConfiguration(peerIceServers);
    // TCP candidates are only useful when connecting to a server that supports
    // ICE-TCP.
    rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.DISABLED;
    rtcConfig.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE;
    rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;
    rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
    // Use ECDSA encryption.
    rtcConfig.keyType = PeerConnection.KeyType.ECDSA;
    localPeer = peerConnectionFactory.createPeerConnection(rtcConfig, new CustomPeerConnectionObserver("localPeerCreation") {
        @Override
        public void onIceCandidate(IceCandidate iceCandidate) {
            super.onIceCandidate(iceCandidate);
            Log.d(TAG, "onIceCandidate()");
            //onIceCandidateReceived(iceCandidate);
        }

        @Override
        public void onAddStream(MediaStream mediaStream) {
            showToast("Received Remote stream");
            super.onAddStream(mediaStream);
            gotRemoteStream(mediaStream);
        }
    });

    addStreamToLocalPeer();
}
 /**
 * This method is called when the app is initiator - We generate the offer and send it over through socket
 * to remote peer
 */
private void doCall() {
    sdpConstraints = new MediaConstraints();
    sdpConstraints.mandatory.add(
            new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
    sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair(
            "OfferToReceiveVideo", "true"));
    localPeer.createOffer(new CustomSdpObserver("localCreateOffer") {
        @Override
        public void onCreateSuccess(SessionDescription sessionDescription) {
            super.onCreateSuccess(sessionDescription);
            Log.d(TAG, "onCreateOfferSuccess, sdp = "+sessionDescription.description);

            localPeer.setLocalDescription(new CustomSdpObserver("localSetLocalDesc"), sessionDescription);

           //here i take the sdp and pass it to the method onOfferReceived() on another device;

        }
    }, sdpConstraints);
}

此代码用于另一台设备:

   onOfferReceived(createTestSdpJsonObject());//here i just pass the same sdp

  /**
 * SignallingCallback - Called when remote peer sends offer
 */
@Override
public void onOfferReceived(final JSONObject data) {
    runOnUiThread(() -> {
        try {
            localPeer.setRemoteDescription(new CustomSdpObserver("localSetRemote"), new SessionDescription(SessionDescription.Type.OFFER, data.getString("sdp")));
   ////here the exception occures in onSetFailure() callback of CustomSdpObserver
            doAnswer();
            updateVideoViews(true);
        } catch (JSONException e) {
            Log.d(TAG, "e in onOfferReceived, ="+e.getMessage());
            e.printStackTrace();
        }
    });
}

CustomSdpObserver:

class CustomSdpObserver implements SdpObserver {


private String tag;

CustomSdpObserver(String logTag) {
    tag = this.getClass().getCanonicalName();
    this.tag = this.tag + " " + logTag;
}


@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
    Log.d(tag, "onCreateSuccess() called with: sessionDescription = [" + sessionDescription + "]");
}

@Override
public void onSetSuccess() {
    Log.d(tag, "onSetSuccess() called");
}

@Override
public void onCreateFailure(String s) {
    Log.d(tag, "onCreateFailure() called with: s = [" + s + "]");
}

@Override
public void onSetFailure(String s) {
    Log.d(tag, "onSetFailure() called with: s = [" + s + "]");
}

}

请帮助谁知道为什么会发生这种情况。

android webrtc
1个回答
0
投票
上的setRemoteDescription()方法中。

我不知道这是什么,但是我找到了一个易于启动的本地Web服务器进行测试的可行解决方案:https://www.amryousef.me/android-webrtc

https://github.com/amrfarid140/webrtc-android-codelab

© www.soinside.com 2019 - 2024. All rights reserved.