Beispiel #1
0
    private IEnumerator SdiIOCoroutine()
    {
        yield return(new WaitForEndOfFrame());

        UtyGLNvSdi.SdiInputSetBufferSize(options.inputRingBufferSize);
        UtyGLNvSdi.SdiInputSetCaptureFields(options.inputCaptureFields);

        //
        // Input/Ouput Initialization
        //
        GL.IssuePluginEvent(UtyGLNvSdi.GetSdiInputRenderEventFunc(), (int)SdiRenderEvent.Initialize);
        GL.IssuePluginEvent(UtyGLNvSdi.GetSdiOutputRenderEventFunc(), (int)SdiRenderEvent.Initialize);
        yield return(new WaitForEndOfFrame());


        if (UtyGLNvSdi.SdiError() == 0)
        {
            //
            // Input Setup
            //
            if (options.inputCaptureFields)
            {
                CreateSdiInputTextures(8, UtyGLNvSdi.SdiInputWidth(), UtyGLNvSdi.SdiInputHeight() / 2);
            }
            else
            {
                CreateSdiInputTextures(4, UtyGLNvSdi.SdiInputWidth(), UtyGLNvSdi.SdiInputHeight());
            }

            GL.IssuePluginEvent(UtyGLNvSdi.GetSdiInputRenderEventFunc(), (int)SdiRenderEvent.Setup);
            GL.IssuePluginEvent(UtyGLNvSdi.GetSdiInputRenderEventFunc(), (int)SdiRenderEvent.StartCapture);
            yield return(new WaitForEndOfFrame());

            //
            // Output Setup
            //
            UtyGLNvSdi.SdiOutputSetGlobalOptions();
            UtyGLNvSdi.SdiOutputSetVideoFormat(
                options.videoFormat,
                options.syncSource,
                options.outputDelay,
                options.outputHorizontalDelay,
                options.outputVerticalDelay,
                options.outputDual,
                options.outputRingBufferSize);

            UtyGLNvSdi.SdiOutputComputePresentTimeFromCapture(true);

            yield return(new WaitForEndOfFrame());


            GL.IssuePluginEvent(UtyGLNvSdi.GetSdiOutputRenderEventFunc(), (int)SdiRenderEvent.Setup);


            int   texWidth   = 1920;
            int   texHeight  = 1080;
            bool  interlaced = true;
            float aspect     = 1.0f;

            UtyGLNvSdi.GetSizeFromVideoFormat(options.videoFormat, ref texWidth, ref texHeight, ref aspect, ref interlaced);
            if (!SetupOutputTextures(texWidth, texHeight, aspect, interlaced, options.outputDual))
            {
                UnityEngine.Debug.LogError("GLNvSdi_Plugin could not setup sdi textures for input/output");
            }

            sdiEnabled = true;

            //while (true)
            //{
            //    // Wait until all frame rendering is done
            //    yield return new WaitForEndOfFrame();

            //    // Capture frame from device
            //    GL.IssuePluginEvent(UtyGLNvSdi.GetSdiInputRenderEventFunc(), (int)SdiRenderEvent.CaptureFrame);
            //    // Present frame
            //    GL.IssuePluginEvent(UtyGLNvSdi.GetSdiOutputRenderEventFunc(), (int)SdiRenderEvent.PresentFrame);

            //}
        }
    }
Beispiel #2
0
    bool SetupOutputTextures()
    {
        int   texWidth      = 1920; // HD=1920, SD=720
        int   texHeight     = 1080; // HD=1080, SD=486
        float lAspect       = 0;
        bool  lIsInterlaced = false;

        UtyGLNvSdi.GetSizeFromVideoFormat(options.videoFormat, ref texWidth, ref texHeight, ref lAspect, ref lIsInterlaced);

        // Check the count of cameras. The plugin support until two cameras
        if (outputTexture.Length > 4)
        {
            UnityEngine.Debug.LogWarning("GLNvSdi plugin does not support more than four cameras.");
        }

        // Verify the amount of render textures needed
        int lTexCount = 0;

        if (options.outputDual)
        {
            lTexCount = 2;
        }
        else
        {
            lTexCount = 1;
        }

        if (lIsInterlaced)
        {
            lTexCount *= 2;
        }


        // If dual progressive output, change the order of cameras. So, the first two are active
        if (options.outputDual && !lIsInterlaced)     // dual output progressive
        {
            RenderTexture tmp = outputTexture[1];
            outputTexture[1] = outputTexture[2];
            outputTexture[2] = tmp;
        }


        // Setting the cameras and directing the render to texture
        for (int i = 0; i < lTexCount; ++i)
        {
            if (outputTexture[i] != null)
            {
                //
                // Checking texture sizes
                //
                if (texWidth != outputTexture[i].width || texHeight != outputTexture[i].height)
                {
                    UnityEngine.Debug.LogError("The size of RenderTexture does not match with sdi video options");
                    return(false);
                }

                //
                // Check if the texture has been created
                //
                if (!outputTexture[i].IsCreated())
                {
                    if (!outputTexture[i].Create())
                    {
                        UnityEngine.Debug.LogError("Could not create Output Sdi RenderTexture");
                    }
                }

                //
                // Sending texture id to plugin
                //
                UtyGLNvSdi.SdiOutputSetTexturePtr(i, outputTexture[i].GetNativeTexturePtr(), outputTexture[i].width, outputTexture[i].height);
            }
            else
            {
                UnityEngine.Debug.LogError("Sdi Output RenderTexture is null");
                return(false);
            }
        }

        // If the options to invert fields is marked, we have to invert
        // the textures id already sent to plugin
        if (options.outputInvertFields)
        {
            UtyGLNvSdi.SdiOutputInvertFields(options.outputInvertFields);
        }

        return(true);
    }
Beispiel #3
0
    bool SetupOutputTextures()
    {
        float lAspect       = 0;
        bool  lIsInterlaced = false;

        UtyGLNvSdi.GetSizeFromVideoFormat(options.videoFormat, ref m_TexWidth, ref m_TexHeight, ref lAspect, ref lIsInterlaced);

        // Check the count of cameras. The plugin support until two cameras
        if (m_Camera.Length > 4)
        {
            UnityEngine.Debug.LogWarning("GLNvSdi plugin does not support more than four cameras.");
        }

        // Disable all cameras
        for (int i = 0; i < m_Camera.Length; ++i)
        {
            m_Camera[i].enabled = false;
        }

        // Verify the amount of render textures needed
        int lTexCount = 0;

        if (options.outputDual)
        {
            lTexCount = 2;
        }
        else
        {
            lTexCount = 1;
        }

        if (lIsInterlaced)
        {
            lTexCount *= 2;
        }

        // If dual progressive output, change the order of cameras. So, the first two are active
        if (options.outputDual && !lIsInterlaced)     // dual output progressive
        {
            Camera tmp = m_Camera[1];
            m_Camera[1] = m_Camera[2];
            m_Camera[2] = tmp;

            GLNvSdiRenderTexture rt1 = m_Camera[1].GetComponent <GLNvSdiRenderTexture>();
            GLNvSdiRenderTexture rt2 = m_Camera[2].GetComponent <GLNvSdiRenderTexture>();

            if (rt1 != null && rt2 != null)
            {
                int tmp_index = rt1.sdiTextureIndex;
                rt1.sdiTextureIndex = rt2.sdiTextureIndex;
                rt2.sdiTextureIndex = tmp_index;
            }
            else
            {
                UnityEngine.Debug.LogError("Error: Could not find GLNvSdiRenderTexture when switching camera parameters");
                return(false);
            }
        }


        // Setting the cameras and directing the render to texture
        for (int i = 0; i < lTexCount; ++i)
        {
            if (m_Camera[i] != null)
            {
                m_Camera[i].aspect  = lAspect;
                m_Camera[i].enabled = true;


                GLNvSdiRenderTexture sdiTex = m_Camera[i].GetComponent <GLNvSdiRenderTexture>();
                if (sdiTex != null)
                {
                    sdiTex.CreateSdiTexture(m_TexWidth, m_TexHeight, 32, false, "RenderTex_" + m_Camera[i].name);

                    if (sdiTex.sdiRenderTarget == null)
                    {
                        UnityEngine.Debug.LogError("Could not create SdiRenderTarget for GLNvSdiRenderTexture in " + m_Camera[i].name);
                        return(false);
                    }

                    UtyGLNvSdi.SdiOutputSetTexturePtr(i, sdiTex.sdiRenderTarget.GetNativeTexturePtr(), sdiTex.sdiRenderTarget.width, sdiTex.sdiRenderTarget.height);
                    //UtyGLNvSdi.SdiOutputSetTexturePtr(i, outputTexture[i].GetNativeTexturePtr(), outputTexture[i].width, outputTexture[i].height);
                }
                else
                {
                    UnityEngine.Debug.LogError("Could not find GLNvSdiRenderTexture in " + m_Camera[i].name);
                    return(false);
                }
            }
            else
            {
                UnityEngine.Debug.LogError(m_Camera[i].name + " is null");
                return(false);
            }
        }

        // If the options to invert fields is marked, we have to invert
        // the textures id already sent to plugin
        if (options.outputInvertFields)
        {
            UtyGLNvSdi.SdiOutputInvertFields(options.outputInvertFields);
        }

        return(true);
    }