/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ namespace NRKernal.Experimental.StreammingCast { using NRKernal.Record; using UnityEngine; /// An observer view blender. public class ObserverViewBlender : IFrameConsumer { /// Target camera. protected Camera m_TargetCamera; /// The encoder. protected IEncoder m_Encoder; /// Gets or sets the width. /// The width. public int Width { get; private set; } /// Gets or sets the height. /// The height. public int Height { get; private set; } /// Gets the blend texture. /// The blend texture. public Texture BlendTexture { get { return m_TargetCamera?.targetTexture; } } /// Configs. /// The camera. /// The encoder. /// The parameter. public virtual void Config(Camera camera, IEncoder encoder, CameraParameters param) { Width = param.cameraResolutionWidth; Height = param.cameraResolutionHeight; m_TargetCamera = camera; m_Encoder = encoder; m_TargetCamera.enabled = true; // As the texture will be used to blend with physical camera image, the alpha channel need to be 0. m_TargetCamera.backgroundColor = new Color(0, 0, 0, 0); m_TargetCamera.targetTexture = UnityExtendedUtility.CreateRenderTexture(Width, Height, 24, RenderTextureFormat.ARGB32); m_TargetCamera.depthTextureMode = DepthTextureMode.Depth; } /// Executes the 'frame' action. /// The frame. public virtual void OnFrame(UniversalTextureFrame frame) { // Commit frame m_Encoder.Commit((RenderTexture)frame.textures[0], frame.timeStamp); } /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged /// resources. public void Dispose() { } } }