Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Question WebRTC video track

Discussion in 'Unity Render Streaming' started by WayneVenter, May 19, 2021.

  1. WayneVenter

    WayneVenter

    Joined:
    May 8, 2019
    Posts:
    56
    Hi, I have a working signaling server with two PC's, the offer/answer works, the datachannel works, the add tracks works as to that it does the callbacks and I see UDP datagrams flow between the two PC's but I do not get the receive texture to display/update. Any guidance welcome. Not sure if I must send the ice candiate updates via the WS when they happen, what I do see is the updates create new offers/answers when I add tracks.

    First the signaling server, this is just for lab/testing and it works
    upload_2021-5-19_22-43-48.png

    Now the PC1 initiating the call and capturing the video stream
    upload_2021-5-19_22-46-54.png

    Next PC2, where the call is received.
    upload_2021-5-19_22-49-3.png

    I've left out a lot of the code that is generic, but this works, I can make a call, sendMessage via datachannel etc. just the video does not render on the receiveImage.
     
  2. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    288
    pc2Ontrack = e => {receiveStream.addTrack(e.Track); };
    pc2Ontrack = e => { OnTrack(_pc2, e); };

    overwriting the first line?
     
    kazuki_unity729 likes this.
  3. WayneVenter

    WayneVenter

    Joined:
    May 8, 2019
    Posts:
    56
    @gtk2k Thank you, I moved the receiveStream.addTrack(e.Track); into the Ontrack function and impletmented the WebRTC.Update() Coroutine, everything is working now.
     
  4. hyeongwooman

    hyeongwooman

    Joined:
    May 31, 2021
    Posts:
    6
    I am having the same problem. , What is OnTrack(_pc2,e) Method?
     
  5. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    288
    OnTrack () is an event handler.
    The original OnTrack method takes one argument.
    I think OnTrack (_pc2, e) is due to WayneVenter's own implementation
     
    hyeongwooman likes this.
  6. WayneVenter

    WayneVenter

    Joined:
    May 8, 2019
    Posts:
    56
    @gtk2k and @hyeongwooman this is correct, my OnTrack is a self made function to handle the e.Track, here is the example:
    pc2Ontrack = e => { OnTrack(_pc2, e); };

    private void OnTrack(RTCPeerConnection pc, RTCTrackEvent e)
    {
    receiveStream.AddTrack(e.Track);
    //pc2Senders.Add(pc.AddTrack(e.Track, videoStream));
    Debug.Log($"{pc} receives remote track:\r\n");
    Debug.Log($"Track kind: {e.Track.Kind}\r\n");
    Debug.Log($"Track id: {e.Track.Id}\r\n");
    if (!videoUpdateStarted)
    {
    StartCoroutine(WebRTC.Update());
    videoUpdateStarted = true;
    }
    }
     
    hyeongwooman likes this.