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 Multi-receivers watching one broadcaster's shared screen problem

Discussion in 'Unity Render Streaming' started by SamTerrae, Sep 11, 2021.

  1. SamTerrae

    SamTerrae

    Joined:
    Sep 10, 2019
    Posts:
    11
    Hello,

    I'm currently having some questions about the sample scenes, Broadcast, and Receiver in particular.

    This is my environment's information:
    Unity Editor Version: 2019.4.21f1 (LTS)
    RenderStreaming version: 3.0.1-preview
    Environment: Windows 10 64bit, NVIDIA GeForce GTX 1650 Ti

    So, let's jump into the basic scenario first. (I'm using Photon for networking)

    I'm having a scene that contains 5 people, 1 of them is the Host (Master Client) who has the right to share his/her screen with others. I found that the Receiver and Broadcast samples are the two that can be applied to my project. However, it's having a little problem when the 3rd person joins into the room, there always be an error that says InvalidOperationException: Sequence contains no matching element whenever I try creating connection through SingleConnection on the 3rd person client.

    In terms of the webapp, I merely served it as shown from the Github page without any changes and run in the socket mode. Basically, there is no problem on the web server.

    So here's my setup in Unity, I did not change anything from the package and leave it as is:

    upload_2021-9-11_20-34-0.png

    As you see above, there are 3 primary GameObjects:
    Streaming Camera: Holding the Render Texture to send through the network
    <Component> Camera Streamer​

    upload_2021-9-11_20-37-31.png

    Streaming Renderer (Sender): Similar to RenderStreaming GameObject in the scene Broadcast but without the Audio and Input from Browser
    <Component> Render Streaming
    <Component> Broadcast
    upload_2021-9-11_20-41-29.png

    Streaming Renderer (Receiver): Similar to RenderStreaming GameObject in the scene Receiver but without the Audio and Input from Browser
    <Component> Render Streaming
    <Component> Single Connection
    <Component> Receive Video Viewer
    <Component> Streaming Receiver(*)

    upload_2021-9-11_20-44-10.png

    *<Component> Streaming Receiver: Based on the idea of ReceiverSample script

    Code (CSharp):
    1.  
    2. public class StreamingReceiver : MonoBehaviour
    3. {
    4.         #region Constants
    5.  
    6.         private const string _ID_CONNECTION = "<mywebserver>";
    7.  
    8.         #endregion
    9.  
    10. #pragma warning disable 0649
    11.  
    12.         #region Private Serialized Fields
    13.  
    14.         [Header("Render Streaming")]
    15.         [SerializeField]
    16.         private SingleConnection connection;
    17.         [SerializeField]
    18.         private ReceiveVideoViewer videoViewer;
    19.  
    20.         [Header("UI")]
    21.         [SerializeField]
    22.         private RawImage remoteVideo;
    23.  
    24.         #endregion
    25.  
    26. #pragma warning restore 0649
    27.  
    28.         #region Private Fields
    29.  
    30.         private string connectionId;
    31.  
    32.         #endregion
    33.  
    34.  
    35.         #region MonoBehaviour Callbacks
    36.  
    37.         private void Awake()
    38.         {
    39.             videoViewer.OnUpdateReceiveTexture +=
    40.                 texture => remoteVideo.texture = texture;
    41.         }
    42.  
    43.         private void Start()
    44.         {
    45.             if (string.IsNullOrEmpty(connectionId))
    46.             {
    47.                 connectionId = System.Guid.NewGuid().ToString("N");
    48.             }
    49.  
    50.             connectionId = _ID_CONNECTION;
    51.             StartCoroutine(Connect());
    52.         }
    53.  
    54.         #endregion
    55.  
    56.         IEnumerator Connect()
    57.         {
    58.             yield return new WaitForSeconds(4f);
    59.  
    60.             connection.CreateConnection(connectionId, true);
    61.         }
    62.     }
    63.  
    As you can see, I'm using Coroutine because there is no callback from the RennderStreaming which lets me know when the WebSocket actually connected to the web server.

    Q1. Should I have to tweak something inside RenderStreaming script to achieve the point when it complete the connection?

    Q2. Could the Broadcast connect to multi-receivers at a time? If yes, could you give me briefly the instructions about getting thing right, or at least, you can merely show me the document having the possibility to solve the problem, please?

    Q3. Am I going the right way to achieve the expected result?

    Finally, I really appreciate any of your help and sorry if I made any mistake in this post.
     
  2. SamTerrae

    SamTerrae

    Joined:
    Sep 10, 2019
    Posts:
    11
    Well, I figured it out anyway.

    My mistake for not noticing the connectionIds that should be actually different from each other in the code... I hardcoded it by the string of my webserver... at line 6 you can see...

    Now my app runs smoothly anyway, it works like a charm. Even though there is not any help but if anyone needs help with the same use case, it would be my honor to help you guys.

    So, the Q2 and Q3 are solved, I am really confused about the Q1, if there is any other method rather than tweaking inside the base code, it would be nice.
     
  3. SamTerrae

    SamTerrae

    Joined:
    Sep 10, 2019
    Posts:
    11
    Bump

    Q1.
    Should I have to tweak something inside RenderStreaming script to achieve the point when RenderStreaming completes its connection? How to know when the correct time to CreateConnection from the SingleConnection of the Receiver 'cause when I create a connection without waiting for the WebSocket to complete its connection, it will popup an error said that:

    Signaling: WS is not connected. Unable to send message

    I want to ask if there is any way to handle this.

    Thank you.
     
    Last edited: Sep 13, 2021
  4. kazuki_unity729

    kazuki_unity729

    Unity Technologies

    Joined:
    Aug 2, 2018
    Posts:
    803
  5. SamTerrae

    SamTerrae

    Joined:
    Sep 10, 2019
    Posts:
    11
    Thanks for your reply. I could handle that problem by using PUN 2 package combining with Cinemachine Virtual Camera. I actually could stack up to 20 CCUs at a time without any problem, or maybe my use case does not generate the same issue. However, I want to know whether any method we could get the complete time of the connection between the RenderStreaming and the WebServer. It runs on the other threads, maybe, so it's a little bit challenge for me to get the exact time when the RenderStreaming finishes its connection.

    Anyway, thank you!
     
  6. salvolannister

    salvolannister

    Joined:
    Jan 3, 2019
    Posts:
    50

    Can I ask you why do you need photon if everybody is gonna see the same screen? Do you need it in order to enable a chat through photon voice?
     
    Last edited: Oct 27, 2021
  7. SamTerrae

    SamTerrae

    Joined:
    Sep 10, 2019
    Posts:
    11
    I will answer your question in the conversation section. I'm sorry for being late. I hope that my information will be useful for you.
     
    salvolannister likes this.