Video Stream from MasterClient webcam to others


I am trying to build an application where the MasterClient is streaming video to all other clients, while the scene is being played.

This application has to run on the web browser and since the scene running at this point is not very relevant, I started from the SlotCar Demo scene from PhotonUnityNetworking Package. Then I changed the PhotonServerSettings Protocol to Web Socket Secure.

when I build the WebGL app and host it on my web server this works fine and it is synchronized.

The next step for me it was to create a couple scripts.
The first one creates a rawimage on a canvas and fills the pixels with the buffer read from the webcam on the master client only. This script also mantains a Texture2D with resolution is 640x480 px that is written into or read from depending whether you are masterClient or not.

The second script is in charge of writing or reading into this networked texture. For the master client it will transform the camera feed into an array of bytes "N" and raise an event.
RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.Others };
SendOptions sendOptions = new SendOptions { Reliability = false };
PhotonNetwork.RaiseEvent(evCode, N, raiseEventOptions, sendOptions);

For the rest of clients it will loadImage from the streamed array of bytes and then use this as the texture data in the canvas.

This works somewhat but I believe I am hitting the limitations set to the client buffers. Sometimes clients get disconnected and other times the video both sent and received just freezes, throwing the cars from the Demo out of sync in the process.

I am also trying to lower the Send rate as I don't mind the video being a bit choppy as long as it doesn't hang.
PhotonNetwork.SendRate = 10;
PhotonNetwork.SerializationRate = 10;

I would appreciate some input to make the stream more stable.

Best regards


  • Bump!

    Question still remains the same: How can I optimize or alleviate data transfer for large data buffers.
  • Bumpity bump!

    I dropped the Serialization Rate to 3 and I am using LZMA Compression on the byte array.
    Also tried CLZF and Unity's MemoryStream compression algorithms.

    Because of the nature of the buffer data, the compression algorithms barely do anything (or I am using them wrong)

    Right now every message is around 36Kb.