Unity-Technologies / Unity-Technologies/com.unity.webrtc

[BUG]: When running the video streaming track on Android, the video source cannot be transmitted

Open
#1,046 9 comments 0 reactions 1 assignee View on GitHub

@karasusan is already working on this.

Since Aug 14, 2024.

bug
Dominant language
Assembly
Stars
852
Forks
238
PR merge metrics
No merged PRs in 30d

Description

Package version

3.0.0-pre.7

Environment
* OS:Android
* Unity version:2022.3
Steps To Reproduce
  1. import package WebRTC 3.0.0-pre.7
  2. in unity Create Scene
  3. Create video-related objects, such as Camera, RawImage...
Current Behavior

When the video track is running on Android, the video source cannot be sent
I don't know what the problem is. It can run when editing, but after packaging into an App, the video cannot be sent to the service. The program code is as follows:

 peerConnection = new()
        {
            OnIceConnectionChange = state => { Debug.Log("IceConnectionState: " + state); },
            OnConnectionStateChange = state => { Debug.Log("ConnectionState: " + state); },
            OnIceGatheringStateChange = state => { Debug.Log("IceGatheringState: " + state); },
            // OnIceGatheringChange = state => { Debug.Log("IceGatheringState: " + state); },
            OnIceCandidate = state => { Debug.Log("OnIceCandidate: " + state); },
            OnDataChannel = state => { Debug.Log("OnDataChannel: " + state); },
            OnNegotiationNeeded = () => { Debug.Log("OnNegotiationNeeded: "); },
            OnTrack = state => { Debug.Log("OnTrack: " + state); },
            // OnRemoveTrack = state => { Debug.Log("OnRemoveTrack: " + state); },
        };
        videoTrack = _camera.CaptureStreamTrack(localView.texture.width, localView.texture.height);
        peerConnection.AddTrack(videoTrack);

        StartCoroutine(WebRTC.Update());

        var offer = peerConnection.CreateOffer();
        yield return offer;

        var offerDesc = offer.Desc;

        var opLocal = peerConnection.SetLocalDescription(ref offerDesc);
        yield return opLocal;

        var filteredSdp = "";

        foreach (string sdpLine in offer.Desc.sdp.Split("\r\n"))
        {
            if (!sdpLine.StartsWith("a=extmap"))
            {
                filteredSdp += sdpLine + "\r\n";
            }
        }

        Debug.LogWarning(filteredSdp);

        using (UnityWebRequest www = new(
                $"https://webrtcpush.tlivewebrtcpush.com/webrtc/v2/whip",
                UnityWebRequest.kHttpVerbPOST
            ))
        {
            www.uploadHandler = new UploadHandlerRaw(Encoding.ASCII.GetBytes(filteredSdp));
            www.downloadHandler = new DownloadHandlerBuffer();
            www.SetRequestHeader("Content-Type", "application/sdp");
            www.SetRequestHeader("Authorization", $"Bearer {webrtcUrl}");

            yield return www.SendWebRequest();

            if (www.result != UnityWebRequest.Result.Success)
            {
                Debug.LogWarning(www.error);
            }
            else
            {
                Debug.LogWarning(www.downloadHandler.text);

                var answer = new RTCSessionDescription { type = RTCSdpType.Answer, sdp = www.downloadHandler.text };
                var opRemote = peerConnection.SetRemoteDescription(ref answer);
                yield return opRemote;
                if (opRemote.IsError)
                {
                    Debug.LogWarning(opRemote.Error);
                }
                else
                {
                    // Debug.LogWarning(opRemote.Current);
                }
            }
        };
Expected Behavior

When starting stream video call,you can pull video

Anything else?

return version to package WebRTC 3.0.0-pre.6 can Publish Streaming

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.