public void renderFrame(int width, int height, int rotation, int textureName, AndroidJavaObject i420Frame) { ThreadUtils.RunOnUpdate(() => { IntPtr textureId = new IntPtr(textureName); if (nativeTexture == null || this.width != width || this.height != height || this.rotation != rotation) { CleanUp(); this.width = width; this.height = height; this.rotation = rotation; nativeTexture = Texture2D.CreateExternalTexture(width, height, TextureFormat.RGB565, false, false, textureId); rTexture = new RenderTexture(Mathf.RoundToInt(width * resolution), Mathf.RoundToInt(height * resolution), 0, RenderTextureFormat.RGB565); rTexture.dimension = UnityEngine.Rendering.TextureDimension.Tex2D; //To optimize, if rotation is zero, we use a different pass, to avoid calculating all the cos and sin. usePass = rotation == 0 ? FlipV_OESExternal_To_RGBA_PassIndex : Rotate_FlipV_OESExternal_To_RGBA_PassIndex; VideoDecodeMaterial.SetFloat("rotation", -(float)rotation * Mathf.Deg2Rad); Action <Texture> OnTextureHandler = OnTexture; if (OnTextureHandler != null) { OnTextureHandler(rTexture); } } else { nativeTexture.UpdateExternalTexture(textureId); } Graphics.Blit(nativeTexture, rTexture, VideoDecodeMaterial, usePass); WebRTCAndroid.KillFrame(i420Frame); }); }
public void renderFrame(int width, int height, int textureName, AndroidJavaObject i420Frame) { ThreadUtils.RunOnUpdate(() => { if (!WebRTCmat.shader.isSupported) { onVideoCapturerError("Unsupported shader"); return; } IntPtr textureId = new IntPtr(textureName); if (nativeTexture != null || this.width != width || this.height != height) { CleanUp(); this.width = width; this.height = height; nativeTexture = Texture2D.CreateExternalTexture(width, height, TextureFormat.YUY2, false, false, textureId); rTexture = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32); Action <Texture> OnTextureHandler = OnTexture; if (OnTextureHandler != null) { OnTextureHandler(rTexture); } } else { nativeTexture.UpdateExternalTexture(textureId); } Graphics.Blit(nativeTexture, rTexture, WebRTCmat); WebRTCAndroid.KillFrame(i420Frame); }); }