DisconnectByServerReasonUnknown (Webcam Sending)
Options
Currently, I try to do a personal project for streaming purposes.
So I send my Webcam over the Network with this code snippet:
And receive it here:
Since I want to push 30fps I finally would like to change
yield return new WaitForSeconds(1f / 0.5f); => yield return new WaitForSeconds(1f / 30f);
My guessing is that I am already overloading the capabilities. Is there any way to optimize or fix the issue?
So I send my Webcam over the Network with this code snippet:
private PhotonView m_PhotonView; private RawImage m_WebcamImage; private WebCamTexture m_WebcamTexture; public void SetDependencies(PhotonView _this, RawImage _webcamImage) { m_PhotonView = _this; m_WebcamImage = _webcamImage; m_WebcamTexture = MainMenuManager.WebCamTexture; m_WebcamImage.texture = m_WebcamTexture; m_WebcamImage.material.mainTexture = m_WebcamTexture; m_WebcamTexture.Play(); StartCoroutine(SendWebcamRoutine()); } private IEnumerator SendWebcamRoutine() { while (true) { yield return new WaitForSeconds(1f / 0.5f); m_PhotonView.RPC("WebcamUpdate", RpcTarget.Others, Color32ArrayToByteArray(m_WebcamTexture.GetPixels32())); } } private byte[] Color32ArrayToByteArray(Color32[] colors) { int length = 4 * colors.Length; byte[] bytes = new byte[length]; IntPtr ptr = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(colors, ptr, true); Marshal.Copy(ptr, bytes, 0, length); Marshal.FreeHGlobal(ptr); return bytes; }
And receive it here:
[SerializeField] private Canvas m_Canvas; [SerializeField] private RawImage m_WebcamImage; private PhotonView m_PhotonView; private void OnEnable() { m_PhotonView = GetComponent<PhotonView>(); if (m_PhotonView.IsMine) { gameObject.AddComponent<LocalWebcam>().SetDependencies(m_PhotonView, m_WebcamImage); } } [PunRPC] private void WebcamUpdate(byte[] _newWebcamImage) { Texture2D newTexture = new Texture2D(1, 1); newTexture.LoadImage(_newWebcamImage); m_WebcamImage.texture = newTexture; m_WebcamImage.material.mainTexture = newTexture; } private Color32[] ByteArrayToColor32Array(byte[] _byteArray) { Color32[] colorArray = new Color32[_byteArray.Length / 4]; for (var i = 0; i < _byteArray.Length; i += 4) { var color = new Color32(_byteArray[i + 0], _byteArray[i + 1], _byteArray[i + 2], _byteArray[i + 3]); colorArray[i / 4] = color; } return colorArray; }
Since I want to push 30fps I finally would like to change
yield return new WaitForSeconds(1f / 0.5f); => yield return new WaitForSeconds(1f / 30f);
My guessing is that I am already overloading the capabilities. Is there any way to optimize or fix the issue?
0