Exemplo n.º 1
0
        private void EnumModes()
        {
            int numModes = DeckLinkPlugin.GetNumVideoInputModes(_deviceIndex);

            for (int modeIndex = 0; modeIndex < numModes; modeIndex++)
            {
                int    width, height;
                float  frameRate;
                string modeDesc;
                string pixelFormatDesc;
                long   frameDuration;
                int    fieldMode;
                if (DeckLinkPlugin.GetVideoInputModeInfo(_deviceIndex, modeIndex, out width, out height, out frameRate, out frameDuration, out fieldMode, out modeDesc, out pixelFormatDesc))
                {
                    DeviceMode mode = new DeviceMode(this, modeIndex, width, height, frameRate, frameDuration, (DeviceMode.FieldMode)fieldMode, modeDesc, pixelFormatDesc);
                    _inputModes.Add(mode);
                }
            }

            numModes = DeckLinkPlugin.GetNumVideoOutputModes(_deviceIndex);
            for (int modeIndex = 0; modeIndex < numModes; modeIndex++)
            {
                int    width, height;
                float  frameRate;
                string modeDesc;
                string pixelFormatDesc;
                long   frameDuration;
                int    fieldMode;
                if (DeckLinkPlugin.GetVideoOutputModeInfo(_deviceIndex, modeIndex, out width, out height, out frameRate, out frameDuration, out fieldMode, out modeDesc, out pixelFormatDesc))
                {
                    DeviceMode mode = new DeviceMode(this, modeIndex, width, height, frameRate, frameDuration, (DeviceMode.FieldMode)fieldMode, modeDesc, pixelFormatDesc);
                    _outputModes.Add(mode);
                }
            }
        }
Exemplo n.º 2
0
        protected override void BeginDevice()
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            DeckLinkPlugin.SetAutoDetectEnabled(_deviceIndex, _autoDetectMode);

            UnsetInputReceivedFlag = false;

            _device.AutoDeinterlace = _autoDeinterlace;
            int actualAudioChannels = Mathf.Clamp(_audioChannels, 2, _device.MaxAudioChannels);

            _device.Enable3DInput            = _enable3D;
            _device.EnableAncillaryDataInput = _enableAncillaryData;
            _device.EnableTimeCodeInput      = _enableTimeCodeCapture;
            _device.SetInputBufferSizes(_inputBufferCount, _inputBufferReadCount);

            if (!_device.StartInput(_modeIndex, actualAudioChannels, false, _useHdr))
            {
                _device.StopInput();
                _device = null;
            }

            if (_device != null)
            {
                _enable3D          = _device.Enable3DInput;
                _device.FlipInputX = _flipX;
                _device.FlipInputY = _flipY;

                DeviceMode mode = _device.GetInputMode(_modeIndex);
                _audioSource.clip = AudioClip.Create("DeckLink Input Audio", 48000 / (int)(mode.FrameRate + 0.5f), actualAudioChannels, 48000, false);
                _audioSource.Play();
            }
#endif
        }
Exemplo n.º 3
0
        public DeviceMode(Device device, int modeIndex, int width, int height, float frameRate, long frameDuration, FieldMode fieldMode, string modeDesc, string pixelFormatDesc)
        {
            _device          = device;
            _modeIndex       = modeIndex;
            _width           = width;
            _height          = height;
            _frameRate       = frameRate;
            _fieldMode       = fieldMode;
            _frameDuration   = frameDuration;
            _modeDesc        = modeDesc;
            _pixelFormatDesc = pixelFormatDesc;
            _pixelFormat     = DeckLinkPlugin.GetPixelFormat(_pixelFormatDesc);
            _pitch           = GetPitch(_width, _pixelFormat);

            _fieldModeString = "p";
            switch (_fieldMode)
            {
            case FieldMode.Interlaced_UpperFirst:
            case FieldMode.Interlaced_LowerFirst:
                _fieldModeString = "i";
                break;

            case FieldMode.Progressive_Segmented:
                _fieldModeString = "PsF";
                break;
            }
        }
Exemplo n.º 4
0
        public bool StartInput(int modeIndex, int numAudioChannels, bool delayResourceCreationUntilFramesStart = false)
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            bool result = false;

            if (modeIndex == -1)
            {
                return(false);
            }

            if (!CanInput())
            {
                Debug.LogWarning("[AVProDeckLink] Warning: Unable to start input for device " + _name + " as it is currently busy");
                return(false);
            }

            if (DeckLinkPlugin.StartInputStream(_deviceIndex, modeIndex, numAudioChannels))
            {
                _audioChannels = numAudioChannels;
                _currentMode   = _inputModes[modeIndex];
                result         = true;

                if (_currentMode.Width > 0 && _currentMode.Width <= 4096 && _currentMode.Height > 0 && _currentMode.Height <= 4096)
                {
                    _formatConverter.AutoDeinterlace = _autoDeinterlace;
                    if (_formatConverter.Build(_deviceIndex, _currentMode, delayResourceCreationUntilFramesStart))
                    {
                        ResetFPS();
                        IsActive          = true;
                        IsStreaming       = true;
                        IsPicture         = false;
                        IsPaused          = false;
                        result            = true;
                        _isStreamingInput = true;
                    }
                    else
                    {
                        Debug.LogWarning("[AVProDeckLink] unable to convert camera format");
                    }
                }
                else
                {
                    Debug.LogWarning("[AVProDeckLink] invalid width or height");
                }
            }
            else
            {
                Debug.LogWarning("[AVProDeckLink] Unable to start input stream on device " + _name);
            }

            if (!result)
            {
                StopInput();
            }

            return(result);
#else
            return(false);
#endif
        }
        public void OnAudioFilterRead(float[] data, int channels)
        {
            DeckLinkManager manager = DeckLinkManager.Instance;

            if (manager == null)
            {
                return;
            }

            _mutex.WaitOne();
            foreach (var deviceIndex in _registeredDevices)
            {
                var device = manager.GetDevice(deviceIndex);

                if (device == null)
                {
                    _mutex.ReleaseMutex();

                    return;
                }

                short[] buffer = new short[data.Length];

                for (int i = 0; i < data.Length; ++i)
                {
                    buffer[i] = (short)(data[i] * 32767f);
                }

                DeckLinkPlugin.OutputAudio(deviceIndex, buffer, buffer.Length * 2);
            }
            _mutex.ReleaseMutex();
        }
Exemplo n.º 6
0
 void OnAudioFilterRead(float[] data, int channels)
 {
     if (!_muteAudio)
     {
         DeckLinkPlugin.GetAudioBuffer(_deviceIndex, data, data.Length, channels, _audioVolume);
     }
 }
Exemplo n.º 7
0
        public Device(string modelName, string name, int index)
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            IsStreamingAudio = false;
            IsStreaming      = false;
            IsPaused         = true;
            IsPicture        = false;
            _name            = name;
            _modelName       = modelName;
            _deviceIndex     = index;
            _genlockOffset   = 0;
            _supportsInputModeAutoDetection = DeckLinkPlugin.SupportsInputModeAutoDetection(_deviceIndex);
            _supportsInternalKeying         = DeckLinkPlugin.SupportsInternalKeying(_deviceIndex);
            _supportsExternalKeying         = DeckLinkPlugin.SupportsExternalKeying(_deviceIndex);
            _maxSupportedAudioChannels      = DeckLinkPlugin.GetMaxSupportedAudioChannels(_deviceIndex);
            _supportsFullFrameGenlockOffset = DeckLinkPlugin.SupportsFullFrameGenlockOffset(_deviceIndex);
            _supportsConfigurableDuplex     = DeckLinkPlugin.ConfigurableDuplexMode(_deviceIndex);
            _inputModes      = new List <DeviceMode>(256);
            _outputModes     = new List <DeviceMode>(256);
            _formatConverter = new FormatConverter();

            _ancPacketsBufferHandle = GCHandle.Alloc(_ancPackets, GCHandleType.Pinned);
            _ancPacketsBufferPtr    = _ancPacketsBufferHandle.AddrOfPinnedObject();
            _ancDataBufferHandle    = GCHandle.Alloc(_ancData, GCHandleType.Pinned);
            _ancDataBufferPtr       = _ancDataBufferHandle.AddrOfPinnedObject();

            _fullDuplexSupported = DeckLinkPlugin.FullDuplexSupported(_deviceIndex);
            EnumModes();
#if AVPRODECKLINK_UNITYFEATURE_NONPOW2TEXTURES
            DeckLinkPlugin.SetPotTextures(_deviceIndex, SystemInfo.npotSupport == NPOTSupport.None);
            DeckLinkPlugin.SetGammaSpace(_deviceIndex, QualitySettings.activeColorSpace == ColorSpace.Gamma);
#endif
#endif
        }
Exemplo n.º 8
0
        private void AdjustPlaybackFramerate()
        {
            int numWaitingOutputFrames = DeckLinkPlugin.GetOutputBufferedFramesCount(_device.DeviceIndex);

            // Dynamically adjust frame rate so we get a smooth output
            int target = _targetFrameRate;

            if (numWaitingOutputFrames < _bufferBalance)
            {
                target = Mathf.CeilToInt(_targetFrameRate + 1);
            }
            else if (numWaitingOutputFrames > _bufferBalance)
            {
                target = Mathf.CeilToInt(_targetFrameRate - 1);
            }

            if (!DeckLinkSettings.Instance._multiOutput)
            {
                Time.captureFramerate = Application.targetFrameRate = target;
            }
            else
            {
                _outputFrameRate = target;
            }
        }
Exemplo n.º 9
0
 public void Reset()
 {
     Deinit();
     DeckLinkPlugin.Deinit();
     DeckLinkPlugin.Init();
     Init();
 }
Exemplo n.º 10
0
 private void SetKeying(DeckLinkOutput.KeyerMode mode)
 {
     if (_supportsInternalKeying || _supportsExternalKeying)
     {
         DeckLinkPlugin.SwitchKeying(_deviceIndex, mode != DeckLinkOutput.KeyerMode.None, mode == DeckLinkOutput.KeyerMode.External);
         _keyingMode = mode;
     }
 }
Exemplo n.º 11
0
        public void Unpause()
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            if (_isStreamingInput)
            {
                DeckLinkPlugin.Unpause(_deviceIndex);
                IsPaused = false;
            }
#endif
        }
Exemplo n.º 12
0
        public void StopOutput()
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            _currentOutputMode = null;
            _isStreamingOutput = false;
            IsStreaming        = _isStreamingOutput || _isStreamingInput;
            ResetFPS();
            DeckLinkPlugin.StopOutputStream(_deviceIndex);
            _keyingMode = DeckLinkOutput.KeyerMode.None;
#endif
        }
Exemplo n.º 13
0
        private void UpdateTimeCode()
        {
            uint timeCode = 0;

            if (DeckLinkPlugin.GetLastFrameTimeCode(_deviceIndex, ref _timeCodeTimeStamp, ref timeCode))
            {
                _timeCode.hours   = (byte)((timeCode >> 24) & 0xff);
                _timeCode.minutes = (byte)((timeCode >> 16) & 0xff);
                _timeCode.seconds = (byte)((timeCode >> 8) & 0xff);
                _timeCode.frames  = (byte)(timeCode & 0xff);
            }
        }
Exemplo n.º 14
0
        private void EnumDevices()
        {
            _devices = new List <Device>(8);
            int numDevices = DeckLinkPlugin.GetNumDevices();

            if (numDevices == 0)
            {
                uint   apiVersionCode   = DeckLinkPlugin.GetDeckLinkAPIVersion();
                string apiVersionString = "" + ((apiVersionCode >> 24) & 255) + "." + ((apiVersionCode >> 16) & 255) + "." + ((apiVersionCode >> 8) & 255) + "." + ((apiVersionCode >> 0) & 255);
                Debug.LogWarning("[AVProDeckLink] Unable to find any DeckLink Devices, It is possible that your Desktop Video is out of date. Please update to version " + apiVersionString);
            }

            for (int deviceIndex = 0; deviceIndex < numDevices; deviceIndex++)
            {
                int numInputModes  = DeckLinkPlugin.GetNumVideoInputModes(deviceIndex);
                int numOutputModes = DeckLinkPlugin.GetNumVideoOutputModes(deviceIndex);
                if (numInputModes > 0 || numOutputModes > 0)
                {
                    string modelName   = DeckLinkPlugin.GetDeviceName(deviceIndex);
                    string displayName = DeckLinkPlugin.GetDeviceDisplayName(deviceIndex);
                    Device device      = new Device(modelName, displayName, deviceIndex);
                    _devices.Add(device);

                    if (_logDeviceEnumeration)
                    {
                        Debug.Log("[AVProDeckLink] Device" + deviceIndex + ": " + displayName + "(" + modelName + ") has " + device.NumInputModes + " video input modes, " + device.NumOutputModes + " video output modes");
                        if (device.SupportsInputModeAutoDetection)
                        {
                            Debug.Log("[AVProDeckLink]\tSupports input video mode auto-detection");
                        }
                        if (device.SupportsInternalKeying)
                        {
                            Debug.Log("[AVProDeckLink]\tSupports internal keyer");
                        }
                        if (device.SupportsExternalKeying)
                        {
                            Debug.Log("[AVProDeckLink]\tSupports external keyer");
                        }

                        for (int modeIndex = 0; modeIndex < device.NumInputModes; modeIndex++)
                        {
                            DeviceMode mode = device.GetInputMode(modeIndex);
                            Debug.Log("[AVProDeckLink]\t\tInput Mode" + modeIndex + ":  " + mode.ModeDescription + " " + mode.Width + "x" + mode.Height + " @" + mode.FrameRate + " (" + mode.PixelFormatDescription + ") ");
                        }
                        for (int modeIndex = 0; modeIndex < device.NumOutputModes; modeIndex++)
                        {
                            DeviceMode mode = device.GetOutputMode(modeIndex);
                            Debug.Log("[AVProDeckLink]\t\tOutput Mode" + modeIndex + ": " + mode.ModeDescription + " " + mode.Width + "x" + mode.Height + " @" + mode.FrameRate + " (" + mode.PixelFormatDescription + ") ");
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
        public void StopInput()
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            _currentMode      = null;
            _isStreamingInput = false;
            IsStreaming       = _isStreamingOutput || _isStreamingInput;
            IsPaused          = false;
            ResetFPS();
            DeckLinkPlugin.StopInputStream(_deviceIndex);
            DeckLinkPlugin.SetTexturePointer(_deviceIndex, System.IntPtr.Zero);
#endif
        }
Exemplo n.º 16
0
        public void Update()
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            if (_isStreamingInput)
            {
                // Check if the input mode has changed
                if (DeckLinkPlugin.IsNoInputSignal(_deviceIndex))
                {
                    _receivedSignal = false;
                    DroppedInputSignalCount++;
                    return;
                }
                else
                {
                    _receivedSignal = true;
                }

                int modeIndex = DeckLinkPlugin.GetVideoInputModeIndex(_deviceIndex);
                if (modeIndex != _currentMode.Index)
                {
                    var newMode = _inputModes[modeIndex];

                    if (!FormatConverter.InputFormatSupported(newMode.PixelFormat))
                    {
                        Debug.LogWarning("Auto detected format for input device not currently supported");
                    }

                    if (modeIndex >= 0 && modeIndex < _inputModes.Count)
                    {
                        // If the device has changed mode we may need to rebuild buffers
                        ChangeInput(modeIndex, true);
                        return;
                    }
                }

                if (EnableAncillaryDataInput)
                {
                    UpdateAncillaryData();
                }
                if (EnableTimeCodeInput)
                {
                    UpdateTimeCode();
                }

                // Update textures
                if (_formatConverter != null)
                {
                    UpdateFPS(_formatConverter.Update());
                }
            }
#endif
        }
Exemplo n.º 17
0
        /*public bool StartAudioOutput(int numChannels)
         * {
         #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
         *  if (IsStreamingAudio)
         *  {
         *      StopAudio();
         *  }
         *
         *  if (numChannels > 0 && numChannels <= MaxAudioChannels)
         *  {
         *      IsStreamingAudio = DeckLinkPlugin.StartAudioOutput(_deviceIndex, numChannels);
         *  }
         *  else
         *  {
         *      Debug.LogError("Unsupported number of audio channels " + numChannels + " vs " + MaxAudioChannels);
         *  }
         *
         *  return IsStreamingAudio;
         #else
         *  return false;
         #endif
         * }*/

        public bool StartOutput(int modeIndex)
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            bool result = false;

            if (_isStreamingOutput)
            {
                Debug.Log("Warning: Please stop device before starting new stream");
                return(false);
            }

            DeckLinkPlugin.SetGenlockOffset(_deviceIndex, _genlockOffset);

            if (DeckLinkPlugin.StartOutputStream(_deviceIndex, modeIndex))
            {
                //_currentOutputMode = _outputModes[modeIndex];
                _currentOutputMode = _outputModes[modeIndex];

                //if (_currentOutputMode.Width > 0 && _currentOutputMode.Width <= 4096 && _currentOutputMode.Height > 0 && _currentOutputMode.Height <= 4096)
                if (_currentOutputMode.Width > 0 && _currentOutputMode.Width <= 4096 && _currentOutputMode.Height > 0 && _currentOutputMode.Height <= 4096)
                {
                    ResetFPS();
                    IsActive           = true;
                    IsStreaming        = true;
                    _isStreamingOutput = true;
                    IsPicture          = false;
                    IsPaused           = false;
                    result             = true;
                }
                else
                {
                    Debug.LogWarning("[AVProDeckLink] invalid width or height");
                }
            }

            /*if(!DeckLinkPlugin.StartAudioOutput(_deviceIndex, 2))
             * {
             *  Debug.LogWarning("[AVProDeckLink] Unable to start audio output stream");
             * }*/

            if (!result)
            {
                Debug.LogWarning("[AVProDeckLink] unable to start output device");
                StopOutput();
            }

            return(result);
#else
            return(false);
#endif
        }
Exemplo n.º 18
0
        protected override void Cleanup()
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            DeckLinkPlugin.SetAutoDetectEnabled(_deviceIndex, false);

            _audioSource.Stop();

            if (_audioSource.clip != null)
            {
                AudioClip.Destroy(_audioSource.clip);
                _audioSource.clip = null;
            }
#endif
        }
Exemplo n.º 19
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
        }
Exemplo n.º 20
0
        private void UpdateAncillaryData()
        {
            int ancPacketCount   = _ancPackets.Length;
            int ancDataByteCount = _ancData.Length;

            if (DeckLinkPlugin.GetLastFrameAncillaryData(_deviceIndex, ref _ancFrameTimeStamp, _ancPacketsBufferPtr, ref ancPacketCount, _ancDataBufferPtr, ref ancDataByteCount))
            {
                _ancPacketCount   = ancPacketCount;
                _ancDataByteCount = ancDataByteCount;

                //DebugAncillaryData();
                //ParseAncillaryData();
            }
        }
Exemplo n.º 21
0
        public void Dispose()
        {
            _mode        = null;
            ValidPicture = false;

            if (_conversionMaterial != null)
            {
                _conversionMaterial.mainTexture = null;
                Material.Destroy(_conversionMaterial);
                _conversionMaterial = null;
            }

            if (_deinterlaceMaterial != null)
            {
                _deinterlaceMaterial.mainTexture = null;
                Material.Destroy(_deinterlaceMaterial);
                _deinterlaceMaterial = null;
            }

            if (_finalTexture != null)
            {
                RenderTexture.ReleaseTemporary(_finalTexture);
                _finalTexture = null;
            }

            if (_rightEyeFinalTexture != null)
            {
                RenderTexture.ReleaseTemporary(_rightEyeFinalTexture);
                _rightEyeFinalTexture = null;
            }

#if AVPRODECKLINK_UNITYFEATURE_EXTERNALTEXTURES
            _rawTexture         = null;
            _rightEyeRawTexture = null;
#else
            if (_rawTexture != null)
            {
                Texture2D.Destroy(_rawTexture);
                DeckLinkPlugin.SetTexturePointer(_deviceHandle, System.IntPtr.Zero);
                _rawTexture = null;
            }

            if (_rightEyeRawTexture != null)
            {
                Texture2D.Destroy(_rightEyeRawTexture);
                DeckLinkPlugin.SetTexturePointer(_deviceHandle, System.IntPtr.Zero);
                _rightEyeRawTexture = null;
            }
#endif
        }
Exemplo n.º 22
0
        private void EnumDevices()
        {
            _devices = new List <Device>(8);
            int numDevices = DeckLinkPlugin.GetNumDevices();

            for (int deviceIndex = 0; deviceIndex < numDevices; deviceIndex++)
            {
                int numInputModes  = DeckLinkPlugin.GetNumVideoInputModes(deviceIndex);
                int numOutputModes = DeckLinkPlugin.GetNumVideoOutputModes(deviceIndex);
                if (numInputModes > 0 || numOutputModes > 0)
                {
                    string modelName   = DeckLinkPlugin.GetDeviceName(deviceIndex);
                    string displayName = DeckLinkPlugin.GetDeviceDisplayName(deviceIndex);
                    Device device      = new Device(modelName, displayName, deviceIndex);
                    _devices.Add(device);

                    if (_logDeviceEnumeration)
                    {
                        Debug.Log("[AVProDeckLink] Device" + deviceIndex + ": " + displayName + "(" + modelName + ") has " + device.NumInputModes + " video input modes, " + device.NumOutputModes + " video output modes");
                        if (device.SupportsInputModeAutoDetection)
                        {
                            Debug.Log("[AVProDeckLink]\tSupports input video mode auto-detection");
                        }
                        if (device.SupportsInternalKeying)
                        {
                            Debug.Log("[AVProDeckLink]\tSupports internal keyer");
                        }
                        if (device.SupportsExternalKeying)
                        {
                            Debug.Log("[AVProDeckLink]\tSupports external keyer");
                        }

                        for (int modeIndex = 0; modeIndex < device.NumInputModes; modeIndex++)
                        {
                            DeviceMode mode = device.GetInputMode(modeIndex);
                            Debug.Log("[AVProDeckLink]\t\tInput Mode" + modeIndex + ":  " + mode.ModeDescription + " " + mode.Width + "x" + mode.Height + " @" + mode.FrameRate + " (" + mode.PixelFormatDescription + ") ");
                        }
                        for (int modeIndex = 0; modeIndex < device.NumOutputModes; modeIndex++)
                        {
                            DeviceMode mode = device.GetOutputMode(modeIndex);
                            Debug.Log("[AVProDeckLink]\t\tOutput Mode" + modeIndex + ": " + mode.ModeDescription + " " + mode.Width + "x" + mode.Height + " @" + mode.FrameRate + " (" + mode.PixelFormatDescription + ") ");
                        }
                    }
                }
            }
        }
Exemplo n.º 23
0
        new void Awake()
        {
            base.Awake();
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            if (Init())
            {
                Debug.Log("[AVProDeckLink] Initialised (plugin v" + DeckLinkPlugin.GetNativePluginVersion() + " script v" + Helper.Version + ")");

                uint   apiVersionCode   = DeckLinkPlugin.GetDeckLinkAPIVersion();
                string apiVersionString = "" + ((apiVersionCode >> 24) & 255) + "." + ((apiVersionCode >> 16) & 255) + "." + ((apiVersionCode >> 8) & 255) + "." + ((apiVersionCode >> 0) & 255);
                Debug.Log("[AVProDeckLink] Using DeckLink API version " + apiVersionString);
            }
            else
            {
                Debug.LogError("[AVProDeckLink] failed to initialise.");
                this.enabled   = false;
                _isInitialised = false;
            }
#endif
        }
Exemplo n.º 24
0
        private RenderTexture Interlace(RenderTexture inputTexture)
        {
            if (_interlaced)
            {
                if (_interlacedTexture == null || _interlaceMaterial == null)
                {
                    Debug.LogError("[AVPro DeckLink] Something went really wrong, I should not be here :(");
                }

                Graphics.Blit(inputTexture, _interlacedTexture, _interlaceMaterial, _interlacePass);
                // Notify the plugin that the interlaced frame is complete now
                DeckLinkPlugin.SetInterlacedOutputFrameReady(_device.DeviceIndex, _interlacePass == 1);

                _interlacePass = (_interlacePass + 1) % 2;

                return(_interlacedTexture);
            }

            return(inputTexture);
        }
Exemplo n.º 25
0
        private bool Build()
        {
            if (CreateMaterial())
            {
#if AVPRODECKLINK_UNITYFEATURE_EXTERNALTEXTURES
                System.IntPtr texPtr = AVProDeckLinkPlugin.GetTexturePointer(_deviceHandle);
                if (texPtr != System.IntPtr.Zero)
                {
                    _usedTextureWidth  = _mode.Pitch / 4;
                    _usedTextureHeight = _mode.Height;
                    _rawTexture        = Texture2D.CreateExternalTexture(_mode.Width / 2, _mode.Height, TextureFormat.ARGB32, false, false, AVProDeckLinkPlugin.GetTexturePointer(_deviceHandle));
                }
#else
                CreateRawTexture();
#endif
                if (_rawTexture != null)
                {
                    CreateFinalTexture();

                    _requiresTextureCrop = (_usedTextureWidth != _rawTexture.width || _usedTextureHeight != _rawTexture.height);

                    if (_requiresTextureCrop)
                    {
                        CreateUVs(_flipX || false, !_flipY && true);
                    }
                    else
                    {
                        Flip(_flipX || false, !_flipY && true);
                    }

                    _conversionMaterial.SetFloat("_TextureWidth", _mode.Width);
                    _conversionMaterial.mainTexture = _rawTexture;
#if !AVPRODECKLINK_UNITYFEATURE_EXTERNALTEXTURES
                    DeckLinkPlugin.SetTexturePointer(_deviceHandle, _rawTexture.GetNativeTexturePtr());
#endif
                }
            }

            _isBuilt = (_conversionMaterial != null && _rawTexture != null && _finalTexture != null);
            return(_isBuilt);
        }
Exemplo n.º 26
0
        protected override void BeginDevice()
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            DeckLinkPlugin.SetAutoDetectEnabled(_deviceIndex, _autoDetectMode);

            _device.AutoDeinterlace = _autoDeinterlace;
            int actualAudioChannels;

            if (_audioChannels <= 2)
            {
                actualAudioChannels = 2;
            }
            else
            {
                actualAudioChannels = 8;
            }

            int maxSupportedChannels = DeckLinkPlugin.GetMaxSupportedAudioChannels(_deviceIndex);
            if (actualAudioChannels > maxSupportedChannels)
            {
                actualAudioChannels = maxSupportedChannels;
            }

            if (!_device.StartInput(_modeIndex, actualAudioChannels))
            {
                _device.StopInput();
                _device = null;
            }
            if (_device != null)
            {
                _device.FlipInputX = _flipX;
                _device.FlipInputY = _flipY;

                DeviceMode mode = _device.GetInputMode(_modeIndex);
                _audioSource.clip = AudioClip.Create("DeckLink Input Audio", 48000 / (int)(mode.FrameRate + 0.5f), actualAudioChannels, 48000, false);
                _audioSource.Play();
            }
#endif
        }
Exemplo n.º 27
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
        }
Exemplo n.º 28
0
        public Device(string modelName, string name, int index)
        {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            IsStreamingAudio = false;
            IsStreaming      = false;
            IsPaused         = true;
            IsPicture        = false;
            _name            = name;
            _modelName       = ModelName;
            _deviceIndex     = index;
            _genlockOffset   = 0;
            _supportsInputModeAutoDetection = DeckLinkPlugin.SupportsInputModeAutoDetection(_deviceIndex);
            _supportsInternalKeying         = DeckLinkPlugin.SupportsInternalKeying(_deviceIndex);
            _supportsExternalKeying         = DeckLinkPlugin.SupportsExternalKeying(_deviceIndex);
            _maxSupportedAudioChannels      = DeckLinkPlugin.GetMaxSupportedAudioChannels(_deviceIndex);
            _supportsFullFrameGenlockOffset = DeckLinkPlugin.SupportsFullFrameGenlockOffset(_deviceIndex);
            _supportsConfigurableDuplex     = DeckLinkPlugin.ConfigurableDuplexMode(_deviceIndex);
            _inputModes          = new List <DeviceMode>(32);
            _outputModes         = new List <DeviceMode>(32);
            _formatConverter     = new FormatConverter();
            _fullDuplexSupported = DeckLinkPlugin.FullDuplexSupported(_deviceIndex);
            EnumModes();
#endif
        }
Exemplo n.º 29
0
 public void SetInputFrameReceived(bool received)
 {
     DeckLinkPlugin.SetInputFrameReceived(_deviceIndex, received);
 }
Exemplo n.º 30
0
 public bool InputFrameReceived()
 {
     return(DeckLinkPlugin.InputFrameReceived(_deviceIndex));
 }