private void UpdateYUVTextureChannel(ref Texture2D channelTexture, MLWebRTC.VideoSink.Frame.ImagePlane imagePlane, Renderer renderer, string samplerName) { if (channelTexture == null || channelTexture.width != imagePlane.Stride || channelTexture.height != (int)(imagePlane.Height)) { channelTexture = new Texture2D((int)imagePlane.Stride, (int)(imagePlane.Height), TextureFormat.Alpha8, false); channelTexture.filterMode = FilterMode.Bilinear; renderer.material.SetTexture(samplerName, channelTexture); } channelTexture.LoadRawTextureData(imagePlane.Data, (int)(imagePlane.Stride * imagePlane.Height)); channelTexture.Apply(); }
private void RenderWebRTCFrameYUV(MLWebRTC.VideoSink.Frame frame) { for (int i = 0; i < rawVideoTexturesYUV.Length; ++i) { MLWebRTC.VideoSink.Frame.ImagePlane imagePlane = frame.ImagePlanes[i]; if (imagePlane.Data == System.IntPtr.Zero) { return; } UpdateYUVTextureChannel(ref rawVideoTexturesYUV[i], imagePlane, remoteDisplayYUV, samplerNamesYUV[i]); } }
private void RenderWebRTCFrameRGB(MLWebRTC.VideoSink.Frame frame) { for (int i = 0; i < rawVideoTexturesRGB.Length; ++i) { MLWebRTC.VideoSink.Frame.ImagePlane imagePlane = frame.ImagePlanes[i]; Texture2D rawVideoTextureRGB = rawVideoTexturesRGB[i]; int width = (int)(imagePlane.Stride / imagePlane.BytesPerPixel); if (rawVideoTextureRGB == null || rawVideoTextureRGB.width != width || rawVideoTextureRGB.height != imagePlane.Height) { rawVideoTextureRGB = new Texture2D(width, (int)imagePlane.Height, TextureFormat.RGBA32, false); rawVideoTextureRGB.filterMode = FilterMode.Bilinear; remoteDisplayRGB.material.mainTexture = rawVideoTextureRGB; remoteDisplayRGB.material.mainTextureScale = new Vector2(1.0f, -1.0f); } rawVideoTexturesRGB[i] = rawVideoTextureRGB; rawVideoTextureRGB.LoadRawTextureData(imagePlane.Data, (int)imagePlane.Size); rawVideoTextureRGB.Apply(); } }