/// <summary> /// Updates the remote video. If the frame is null it will hide the video image. /// </summary> /// <param name="frame"></param> public virtual void UpdateRemoteTexture(IFrame frame, FramePixelFormat format) { if (uRemoteVideoImage != null) { if (frame != null) { UnityMediaHelper.UpdateTexture(frame, ref mRemoteVideoTexture); uRemoteVideoImage.texture = mRemoteVideoTexture; //watch out: due to conversion from WebRTC to Unity format the image is flipped (top to bottom) //this also inverts the rotation uRemoteVideoImage.transform.rotation = Quaternion.Euler(0, 0, frame.Rotation * -1); mHasRemoteVideo = true; mRemoteVideoWidth = frame.Width; mRemoteVideoHeight = frame.Height; mRemoteVideoFormat = format; mRemoteFrameCounter++; } else { mHasRemoteVideo = false; uRemoteVideoImage.texture = uNoCameraTexture; uRemoteVideoImage.transform.rotation = Quaternion.Euler(0, 0, 0); } } }
public static bool UpdateTexture(ref Texture2D tex, RawFrame frame, FramePixelFormat format) { bool newTextureCreated = false; //texture exists but has the wrong height /width? -> destroy it and set the value to null if (tex != null && (tex.width != frame.Width || tex.height != frame.Height)) { Texture2D.Destroy(tex); tex = null; } //no texture? create a new one first if (tex == null) { newTextureCreated = true; //current default format for compatibility reasons if (format == FramePixelFormat.ABGR) { tex = new Texture2D(frame.Width, frame.Height, TextureFormat.RGBA32, false); } tex.wrapMode = TextureWrapMode.Clamp; } //copy image data into the texture and apply tex.LoadRawTextureData(frame.Buffer); tex.Apply(); return(newTextureCreated); }
/// <summary> /// Updates the remote video. If the frame is null it will hide the video image. /// </summary> /// <param name="frame"></param> public virtual void UpdateRemoteTexture(IFrame frame, FramePixelFormat format) { if (uRemoteVideoImage != null) { if (frame != null) { UnityMediaHelper.UpdateTexture(frame, ref mRemoteVideoTexture); //Implement Video texture in UI mode uRemoteVideoImage.texture = mRemoteVideoTexture; uRemoteVideoImage.transform.rotation = Quaternion.Euler(new Vector3(0, 0, frame.Rotation * -1)); //Implement Video texture in Holokit mode FloatingPlaneLeft.GetComponent <Renderer>().material.mainTexture = mRemoteVideoTexture; FloatingPlaneRight.GetComponent <Renderer>().material.mainTexture = mRemoteVideoTexture; //Shift texture for Lefteye_plane & Righteye_plane FloatingPlaneLeft.GetComponent <Renderer>().material.mainTextureScale = new Vector2(0.5f, 1); FloatingPlaneRight.GetComponent <Renderer>().material.mainTextureScale = new Vector2(0.5f, 1); FloatingPlaneRight.GetComponent <Renderer>().material.mainTextureOffset = new Vector2(0.5f, 0); mHasRemoteVideo = true; mRemoteVideoWidth = frame.Width; mRemoteVideoHeight = frame.Height; mRemoteVideoFormat = format; mRemoteFrameCounter++; } else { mHasRemoteVideo = false; uRemoteVideoImage.texture = uNoCameraTexture; FloatingPlaneLeft.GetComponent <Renderer>().material.mainTexture = uNoCameraTexture; FloatingPlaneRight.GetComponent <Renderer>().material.mainTexture = uNoCameraTexture; } } }
/// <summary> /// Updates the local video. If the frame is null it will hide the video image /// </summary> /// <param name="frame"></param> public virtual void UpdateLocalTexture(IFrame frame, FramePixelFormat format) { if (uLocalVideoImage != null) { if (frame != null) { UnityMediaHelper.UpdateTexture(frame, ref mLocalVideoTexture); uLocalVideoImage.texture = mLocalVideoTexture; if (uLocalVideoImage.gameObject.activeSelf == false) { uLocalVideoImage.gameObject.SetActive(true); } //apply rotation //watch out uLocalVideoImage should be scaled -1 X to make the local camera appear mirrored //it should also be scaled -1 Y because Unity reads the image from bottom to top uLocalVideoImage.transform.rotation = Quaternion.Euler(0, 0, frame.Rotation); mHasLocalVideo = true; mLocalFrameCounter++; mLocalVideoWidth = frame.Width; mLocalVideoHeight = frame.Height; mLocalVideoFormat = format; } else { //app shutdown. reset values mHasLocalVideo = false; uLocalVideoImage.texture = null; uLocalVideoImage.transform.rotation = Quaternion.Euler(0, 0, 0); uLocalVideoImage.gameObject.SetActive(false); } } }
public void SetFrame(IFrame frame, FramePixelFormat format) { if (frame != null) { Debug.Log("frameee"); UnityMediaHelper.UpdateTexture(frame, ref VideoTexture); mr.material.mainTexture = VideoTexture; } }
/// <summary> /// Updates the texture based on the given frame update. /// /// Returns true if a complete new texture was created /// </summary> /// <param name="tex"></param> /// <param name="frame"></param> protected bool UpdateTexture(ref Texture2D tex, RawFrame frame, FramePixelFormat format) { bool newTextureCreated = false; //texture exists but has the wrong height /width? -> destroy it and set the value to null if (tex != null && (tex.width != frame.Width || tex.height != frame.Height)) { Texture2D.Destroy(tex); tex = null; } //no texture? create a new one first if (tex == null) { newTextureCreated = true; Debug.Log("Creating new texture with resolution " + frame.Width + "x" + frame.Height + " Format:" + format); //so far only ABGR is really supported. this will change later if (format == FramePixelFormat.ABGR) { tex = new Texture2D(frame.Width, frame.Height, TextureFormat.RGBA32, false); } else { Debug.LogWarning("YUY2 texture is set. This is only for testing"); tex = new Texture2D(frame.Width, frame.Height, TextureFormat.YUY2, false); } tex.wrapMode = TextureWrapMode.Clamp; } //copy image data into the texture and apply //Watch out the RawImage has the top pixels in the top row but //unity has the top pixels in the bottom row. Result is an image that is //flipped. Fixing this here would waste a lot of CPU power thus //the UI will simply set scale.Y of the UI element to -1 to reverse this. tex.LoadRawTextureData(frame.Buffer); tex.Apply(); return(newTextureCreated); }
//666 Roger added another argument private void UpdateTexture(GameObject videoObject, bool flipped, ref Texture2D videoTexture, IFrame frame, FramePixelFormat format) { if (frame != null) { if (videoTexture == null) { DebugLog.AddEntry("Video texture: " + frame.Width + "x" + frame.Height + " Format:" + format); } UnityMediaHelper.UpdateTexture(frame, ref videoTexture); videoObject.GetComponent <UITexture>().mainTexture = videoTexture; if (flipped) { videoObject.transform.rotation = Quaternion.Euler(0, 180f, 180f); } else { videoObject.transform.rotation = Quaternion.Euler(0, 0, 180f); } } else { // app shutdown. reset values videoObject.GetComponent <UITexture>().mainTexture = null; videoObject.transform.rotation = Quaternion.Euler(0, 0, 0); } }
public void SetFrameAR(Texture frame, FramePixelFormat format) { }
/// <summary> /// Updates the local video. If the frame is null it will hide the video image /// </summary> /// <param name="frame"></param> protected virtual void UpdateImage(RawImage image, ref Texture2D tex, RawFrame frame, FramePixelFormat format) { if (image != null) { if (frame != null) { UpdateTexture(ref tex, frame, format); image.texture = tex; if (image.gameObject.activeSelf == false) { image.gameObject.SetActive(true); } //apply rotation //watch out uLocalVideoImage should be scaled -1 X to make the local camera appear mirrored //it should also be scaled -1 Y because Unity reads the image from bottom to top image.transform.rotation = Quaternion.Euler(0, 0, frame.Rotation); // mHasLocalVideo = true; // mLocalFrameCounter++; // mLocalVideoWidth = frame.Width; // mLocalVideoHeight = frame.Height; // mLocalVideoFormat = format; } else { //app shutdown. reset values // mHasLocalVideo = false; image.texture = null; image.transform.rotation = Quaternion.Euler(0, 0, 0); image.gameObject.SetActive(false); } } }