简体   繁体   English

WebRTC 远程视频显示为黑色

[英]WebRTC remote video is shown as black

While developing a WebRTC video chat application I have encountered receiving remote the video stream.在开发 WebRTC 视频聊天应用程序时,我遇到了接收远程视频流的情况。 The video stream blob is received, but the video is just black.接收到视频流 blob,但视频只是黑色。

I have gone through these answers and tried almost everything I could to get it to work https://stackoverflow.com/a/17424224/923109 Remote VideoStream not working with WebRTC我已经完成了这些答案并尝试了几乎所有我可以让它工作的方法https://stackoverflow.com/a/17424224/923109 远程视频流不能与 WebRTC 一起工作

......
Globalvars.socket.on('call', function (signal) {
    if(!Globalvars.pc){
        Methods.startCall(false, signal);
    }

    if(signal.sdp){
        temp = new RTCSessionDescription({"sdp" : decodeURIComponent(signal.sdp), "type" : signal.type});
        Globalvars.pc.setRemoteDescription(temp);
        for(i = 0; i < Globalvars.iceCandidateArray.length; i++){
            Globalvars.pc.addIceCandidate(new RTCIceCandidate({
                sdpMLineIndex: decodeURIComponent(signal.sdpMLineIndex),
                candidate: decodeURIComponent(signal.candidate)
            }));
        }

        Globalvars.iceCandidateArray = [];
    }
    else{
        if(Globalvars.pc.remoteDescription){
            Globalvars.pc.addIceCandidate(new RTCIceCandidate({
                sdpMLineIndex: decodeURIComponent(signal.sdpMLineIndex),
                candidate: decodeURIComponent(signal.candidate)
            }));
            console.log("remot");
        }
        else{
            Globalvars.iceCandidateArray.push(new RTCIceCandidate({
                sdpMLineIndex: decodeURIComponent(signal.sdpMLineIndex),
                candidate: decodeURIComponent(signal.candidate)
            }));
            console.log("ice candidate to temp array");
        }
    }
});


$("#roster-wrap").on("click", ".roster-list-item", function(e){
    //Globalvars.socket.emit('call', {"receiver_id" : $(this).attr("data-id"), "caller_id" : Globalvars.me.id});
    params = {"receiver_id" : $(this).attr("data-id"), "caller_id" : Globalvars.me.id};
    Methods.startCall(true, params);
    e.preventDefault();
});
.....


.....
// run start(true) to initiate a call
"startCall" : function (isCaller, params) {
    var configuration = {"iceServers": [{"url": "stun:stun.l.google.com:19302"}]};
    Globalvars.pc = new RTCPeerConnection(configuration);

    // send any ice candidates to the other peer
    Globalvars.pc.onicecandidate = function (evt) {
        //alert("ice candidate");
        if (!Globalvars.pc || !evt || !evt.candidate) return;
        var candidate = evt.candidate;
        Globalvars.socket.emit("call",{ "candidate": encodeURIComponent(candidate.candidate), "sdpMLineIndex" : encodeURIComponent(candidate.sdpMLineIndex), "receiver_id" :  params.receiver_id, "caller_id" : params.caller_id});
    };

    // once remote stream arrives, show it in the remote video element
    Globalvars.pc.onaddstream = function (evt) {
        console.log("add stream");
        if (!event) return;
        $("#remote-video").attr("src",URL.createObjectURL(evt.stream));
        Methods.waitUntilRemoteStreamStartsFlowing();
    };

    // get the local stream, show it in the local video element and send it
    navigator.getUserMedia({ "audio": false, "video": true }, function (stream) {
        $("#my-video").attr("src", URL.createObjectURL(stream));
        Globalvars.pc.addStream(stream);

        if (isCaller){
            Globalvars.pc.createOffer(getDescription, null, { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } });
        }
        else{
            console.log("Got Remote Description");
            console.log(Globalvars.pc.remoteDescription);               
            //Globalvars.pc.createAnswer(Globalvars.pc.remoteDescription, getDescription);
            Globalvars.pc.createAnswer(getDescription, null, { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } });
        }

        function getDescription(desc) {
            Globalvars.pc.setLocalDescription(desc);
            console.log("my desc");
            console.log(desc);
            Globalvars.socket.emit("call", {"sdp": encodeURIComponent(desc.sdp), "type": desc.type, "receiver_id" :  params.receiver_id, "caller_id" : params.caller_id});
            //signalingChannel.send(JSON.stringify({ "sdp": desc }));
        }
    });
},
......

The complete code is available at https://bitbucket.org/ajaybc/meetchat-client and https://bitbucket.org/ajaybc/meetchat-server完整代码可在https://bitbucket.org/ajaybc/meetchat-c​​lienthttps://bitbucket.org/ajaybc/meetchat-server 获得

You may need to add您可能需要添加

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />

into your AndroidManifest.xml进入你的 AndroidManifest.xml

I verified WebRTC works with https://download.01.org/crosswalk/releases/crosswalk/android/beta/7.36.154.12/ and https://apprtc.appspot.com/ on my Nexus 5.我在我的 Nexus 5 上验证了 WebRTC 与https://download.01.org/crosswalk/releases/crosswalk/android/beta/7.36.154.12/https://apprtc.appspot.com/一起工作。

Hope it works for you.希望对你有效。

I had the same issues as you, but only for some clients, and I explored the same avenues that you did.我和你有同样的问题,但只针对一些客户,我探索了和你一样的途径。 The last thing (and probably the ultimate cause of my issues) was related to the NAT situation behind at least one of the clients.最后一件事(可能也是我问题的最终原因)与至少一个客户端背后的 NAT 情况有关。 There will always be the possibility of a situation where one of the clients cannot get a hole punched in their NAT, and therefore a STUN server will not work.总会有一种情况出现,其中一个客户端无法在其 NAT 中打孔,因此 STUN 服务器将无法工作。 In these cases, you need a TURN server to relay the video to that client.在这些情况下,您需要一个 TURN 服务器将视频中继到该客户端。

What configuration do you have for your iceServers in your peerConnection ?您的 peerConnection 中的peerConnection有什么配置? Does it contain any TURN servers that you know to work?它是否包含您知道可以工作的任何 TURN 服务器?

You can create a free account on this site http://xirsys.com/simplewebrtc/ , and follow the simple instructions on getting credentials for a TURN server on their hosting, which you can then use to test if this is the issue.您可以在此站点http://xirsys.com/simplewebrtc/上创建一个免费帐户,并按照有关在其主机上获取 TURN 服务器的凭据的简单说明进行操作,然后您可以使用它来测试是否是问题所在。

Instead of using "decodeURIComponent" why don't you try "JSON.stringify"?为什么不使用“decodeURIComponent”,而是尝试“JSON.stringify”? That will ensure a smooth transformation to a string and you can then use JSON.parse to get out the object you sent.这将确保顺利转换为字符串,然后您可以使用 JSON.parse 来获取您发送的对象。 From my experience with black screen WebRTC, I sense a dirty SDP payload.根据我使用黑屏 WebRTC 的经验,我感觉到 SDP 负载很脏。

First create Peer connection and then add MediaStream to it.首先创建 Peer 连接,然后向其中添加 MediaStream。 Only after adding mediastream to peerconnection exchange of offer,answer,candidates should be done.只有在将媒体流添加到 peerconnection 的 offer、answer、candidate 交换之后,才应该完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM