【问题标题】:WebRTC remote video is shown as blackWebRTC 远程视频显示为黑色
【发布时间】:2013-09-25 14:59:27
【问题描述】:

在开发 WebRTC 视频聊天应用程序时,我遇到了接收远程视频流的情况。接收到视频流 blob,但视频只是黑色。

我已经阅读了这些答案,并尝试了几乎所有我可以让它工作的方法https://stackoverflow.com/a/17424224/923109 Remote VideoStream not working with 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 }));
        }
    });
},
......

完整代码可在https://bitbucket.org/ajaybc/meetchat-clienthttps://bitbucket.org/ajaybc/meetchat-server 获得

【问题讨论】:

  • 您是否尝试过从 chrome 获取更多调试信息?只需在 Chrome 浏览器中转到“chrome://webrtc-internals/”,然后查看所有 webrtc 步骤是否成功完成。你也可以在这里发布信息,我可以看看有没有什么突出的......
  • @Awalias 是的,我搞定了。这实际上是由于我使用的信号机制中的一个错误
  • 你可能想用你为后代所做的事情来回答你自己的问题。
  • @RTB 他可能会使用此链接解决信号机制Signaling: session control, network and media information
  • @RTB 远程黑屏通常表示未设置远程 SDP。也许这对你有帮助。

标签: javascript html webrtc


【解决方案1】:

为什么不使用“decodeURIComponent”而不是“JSON.stringify”?这将确保顺利转换为字符串,然后您可以使用 JSON.parse 获取您发送的对象。根据我使用黑屏 WebRTC 的经验,我感觉到 SDP 负载很脏。

【讨论】:

    【解决方案2】:

    我和你有同样的问题,但只是针对一些客户,我探索了与你相同的途径。最后一件事(可能是我的问题的最终原因)与至少一个客户端后面的 NAT 情况有关。总会有这样一种情况,即其中一个客户端无法在其 NAT 中打洞,因此 STUN 服务器将无法工作。在这些情况下,您需要一个 TURN 服务器将视频中继到该客户端。

    peerConnection 中的 iceServers 有什么配置?它是否包含任何您知道可以工作的 TURN 服务器?

    您可以在此站点http://xirsys.com/simplewebrtc/ 上创建一个免费帐户,然后按照简单说明获取其托管上的 TURN 服务器的凭据,然后您可以使用该凭据来测试是否是问题所在。

    【讨论】:

      【解决方案3】:

      首先创建 Peer 连接,然后将 MediaStream 添加到它。只有在将媒体流添加到对等连接交换offer、answer、candidates后才能完成。

      【讨论】:

        【解决方案4】:

        您可能需要添加

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

        进入你的 AndroidManifest.xml

        我已验证 WebRTC 可在我的 Nexus 5 上与 https://download.01.org/crosswalk/releases/crosswalk/android/beta/7.36.154.12/https://apprtc.appspot.com/ 配合使用。

        希望它对你有用。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-11-22
          • 1970-01-01
          • 2020-06-08
          相关资源
          最近更新 更多