/// <summary> /// Constructs a new SDPSender object /// </summary> /// <param name="stream_task"> /// The streaming task that can be used to add clients to the RTP server /// </param> public SdpSender(RTPStreamAsyncHandler stream_task) { Debug.Log("Start listener"); server_ = new TcpListener(IPAddress.Any, SERVER_PORT); server_.Start(); stream_task_ = stream_task; }
/// <summary> /// Creates all the underlying components /// </summary> void Start() { cam_ = GetComponent <Camera>(); cubemap_left_ = new RenderTexture(DIM, DIM, 24, RenderTextureFormat.ARGB32); cubemap_left_.dimension = TextureDimension.Cube; equirect_ = new RenderTexture(DIM, DIM, 24, RenderTextureFormat.ARGB32); // The encode task handles sending frames to the rtp stream in a semi-async fashion // codec_type 0 => H264 // codec_type 1 => H265 stream_task_ = new Server.RTPStreamAsyncHandler(FRAMERATE, DIM, DIM, "ultrafast", /* codec type */ 0); if (stream_task_ == null) { Debug.LogError("ERROR failed to create streaming task"); } // Async GPU callbacks prevent the CPU from being stalled when GPU tasks // are running. The performance is significantly better on machines // that support this functionality supports_async_gpu_ = UnityEngine.SystemInfo.supportsAsyncGPUReadback; if (!supports_async_gpu_) { texture_ = new Texture2D(DIM, DIM, TextureFormat.ARGB32, false); UnityEngine.Debug.LogWarning( "Device does not support asynchronous GPU Callbacks in Unity. " + "Performance will suffer as a result."); } // Start a TCP server that serves SDP files to clients that want to // connect to the RTP stream sdp_server_ = new Server.SdpSender(stream_task_); Task.Run(() => AcceptRequests()); }