예제 #1
0
        protected override void Process()
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            if (_device == null)
            {
                return;
            }

            if (_conversionMaterial != null)
            {
                //in this case, since we are dealing with non-srgb texture, need to do conversion from gamma to linear
                if (QualitySettings.activeColorSpace == ColorSpace.Linear && !_bypassGamma)
                {
                    _conversionMaterial.EnableKeyword("APPLY_GAMMA");
                }
                else
                {
                    _conversionMaterial.DisableKeyword("APPLY_GAMMA");
                }
            }

            if (_convertedTexture != null && _convertedPointer == IntPtr.Zero)
            {
                _convertedPointer = _convertedTexture.GetNativeTexturePtr();
                DeckLinkPlugin.SetOutputTexturePointer(_deviceIndex, _convertedPointer);
            }

            if (_device.IsStreamingOutput)
            {
                CaptureFrame();

                if (CanOutputFrame())
                {
                    if (DeckLinkSettings.Instance._multiOutput)
                    {
                        BlendCapturedFrames();
                    }

                    RenderTexture input = _blended;

                    input = Interlace(input);
                    Convert(input);
                    AdjustPlaybackFramerate();

                    DeckLinkPlugin.SetDeviceOutputReady(_deviceIndex);
                }
            }
            ProcessAudio();
#endif
        }
예제 #2
0
        protected override void Process()
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            if (_device == null)
            {
                return;
            }

            if (_convertedTexture != null && _convertedTexture.GetNativeTexturePtr() != _convertedPointer)
            {
                _convertedPointer = _convertedTexture.GetNativeTexturePtr();
                DeckLinkPlugin.SetOutputTexturePointer(_deviceIndex, _convertedTexture.GetNativeTexturePtr());
            }

            if (_device.IsStreamingOutput)
            {
                CaptureFrame();

                if (CanOutputFrame())
                {
                    if (DeckLinkSettings.Instance._multiOutput)
                    {
                        BlendCapturedFrames();
                    }

                    RenderTexture input = _blended;

                    input = ConvertColourSpace(input);
                    input = Interlace(input);
                    Convert(input);
                    AdjustPlaybackFramerate();

                    DeckLinkPlugin.SetDeviceOutputReady(_deviceIndex);
                }
            }
            ProcessAudio();
#endif
        }
        protected override void Process()
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            if (_device == null)
            {
                return;
            }

            bool restartDevice = false;

            if (_current3DEnabled != _enable3D)
            {
                _current3DEnabled = _enable3D;
                restartDevice     = true;
            }

            _device.LowLatencyMode = _lowLatencyMode;

            // If we're syncing to an input, then make sure we output using the same frame rate
            if (_syncedToInput != null && _syncedToInput.Device != null && _syncedToInput.Device.IsStreamingInput && _syncedToInput.ModeIndex >= 0)
            {
                // If we're using auto detect mode then we need to wait for frames to start coming in, otherwise
                // it may be still on the default mode awaiting auto detection
                if (!_syncedToInput._autoDetectMode || _syncedToInput.Device.FramesTotal > 1)
                {
                    var inputMode  = _syncedToInput.Device.CurrentMode;
                    var outputMode = (Device == null) ? null : Device.CurrentOutputMode;

                    // TODO: add better support for interlaced modes
                    float inputFrameRate = inputMode.FrameRate;                    // * (inputMode.InterlacedFieldMode ? 2 : 1);

                    if (outputMode == null || outputMode.FrameRate != inputFrameRate)
                    {
                        _filterModeByFPS         = true;
                        _filterModeByInterlacing = true;

                        _modeFPS         = inputFrameRate;
                        _modeInterlacing = false;

                        restartDevice = true;
                    }
                }
                else
                {
                    return;
                }
            }

            if (restartDevice)
            {
                StopOutput();
                Begin(true);

                if (_device == null)
                {
                    return;
                }
            }

            _enable3D = _current3DEnabled;

            if (_conversionMaterial != null)
            {
                //in this case, since we are dealing with non-srgb texture, need to do conversion from gamma to linear
                if (QualitySettings.activeColorSpace == ColorSpace.Linear && !_bypassGamma)
                {
                    _conversionMaterial.EnableKeyword("APPLY_GAMMA");
                }
                else
                {
                    _conversionMaterial.DisableKeyword("APPLY_GAMMA");
                }
                if (_ignoreAlphaChannel)
                {
                    _conversionMaterial.EnableKeyword(ShaderKeyIgnoreAlpha);
                }
                else
                {
                    _conversionMaterial.DisableKeyword(ShaderKeyIgnoreAlpha);
                }

                switch (_colorspaceMode)
                {
                case DeckLink.ColorspaceMode.Rec709:
                    _conversionMaterial.DisableKeyword(ShaderKeyRec2020);
                    _conversionMaterial.DisableKeyword(ShaderKeyRec2100);
                    _conversionMaterial.EnableKeyword(ShaderKeyRec709);
                    break;

                case DeckLink.ColorspaceMode.Rec2020:
                    _conversionMaterial.DisableKeyword(ShaderKeyRec709);
                    _conversionMaterial.DisableKeyword(ShaderKeyRec2100);
                    _conversionMaterial.EnableKeyword(ShaderKeyRec2020);
                    break;

                case DeckLink.ColorspaceMode.Rec2100:
                    _conversionMaterial.DisableKeyword(ShaderKeyRec709);
                    _conversionMaterial.DisableKeyword(ShaderKeyRec2020);
                    _conversionMaterial.EnableKeyword(ShaderKeyRec2100);
                    break;
                }
            }

            if (_convertedTexture != null && _convertedPointer == IntPtr.Zero)
            {
                _convertedPointer = _convertedTexture.GetNativeTexturePtr();
                DeckLinkPlugin.SetOutputTexturePointer(_deviceIndex, _convertedPointer);
            }

            if (_rightConvertedTexture != null && _rightConvertedPointer == IntPtr.Zero)
            {
                _rightConvertedPointer = _rightConvertedTexture.GetNativeTexturePtr();
                DeckLinkPlugin.SetRightOutputTexturePointer(_deviceIndex, _rightConvertedPointer);
            }

            if (_device.IsStreamingOutput)
            {
                CaptureFrame();

                if (CanOutputFrame())
                {
                    if (_syncedToInput)
                    {
                        _syncedToInput.UnsetInputReceivedFlag = true;
                    }

                    if (DeckLinkSettings.Instance._multiOutput)
                    {
                        BlendCapturedFrames();
                    }

                    RenderTexture input = _blended;

                    input = Interlace(input, !_current3DEnabled);
                    Convert(input, _convertedTexture, _outputBuffer);

                    if (_current3DEnabled)
                    {
                        input = _rightBlended;
                        input = Interlace(input, true);
                        Convert(input, _rightConvertedTexture, _rightOutputBuffer);
                    }

                    if (_syncedToInput == null)
                    {
                        AdjustPlaybackFramerate();
                    }

                    DeckLinkPlugin.SetDeviceOutputReady(_deviceIndex);
                }
            }
            ProcessAudio();
#endif
        }