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; } }
public static int GetPitch(int width, DeckLinkPlugin.PixelFormat pixelFormat) { int result = 0; switch (pixelFormat) { case DeckLinkPlugin.PixelFormat.YCbCr_8bpp_422: result = (width * 16) / 8; break; case DeckLinkPlugin.PixelFormat.YCbCr_10bpp_422: result = (((width + 47) / 48) * 128); break; case DeckLinkPlugin.PixelFormat.ARGB_8bpp_444: result = (width * 32) / 8; break; case DeckLinkPlugin.PixelFormat.BGRA_8bpp_444: result = (width * 32) / 8; break; case DeckLinkPlugin.PixelFormat.RGB_10bpp_444: case DeckLinkPlugin.PixelFormat.RGBX_10bpp_444: case DeckLinkPlugin.PixelFormat.RGBX_10bpp_444_LE: result = ((width + 63) / 64) * 256; break; } return(result); }
private static bool HasAlphaChannel(DeckLinkPlugin.PixelFormat format) { bool result = false; switch (format) { case DeckLinkPlugin.PixelFormat.BGRA_8bpp_444: case DeckLinkPlugin.PixelFormat.ARGB_8bpp_444: result = true; break; } return(result); }
public static bool InputFormatSupported(DeckLinkPlugin.PixelFormat format) { switch (format) { case DeckLinkPlugin.PixelFormat.YCbCr_10bpp_422: case DeckLinkPlugin.PixelFormat.ARGB_8bpp_444: case DeckLinkPlugin.PixelFormat.YCbCr_8bpp_422: case DeckLinkPlugin.PixelFormat.BGRA_8bpp_444: return(true); default: return(false); } }
public bool GetPixelConversionShader(DeckLinkPlugin.PixelFormat format, ref Shader shader, ref int pass) { bool result = true; pass = 0; switch (format) { case DeckLinkPlugin.PixelFormat.YCbCr_8bpp_422: shader = _shader_YCbCr_8bpp_422; break; case DeckLinkPlugin.PixelFormat.YCbCr_10bpp_422: shader = _shader_YCbCr_10bpp_422; break; case DeckLinkPlugin.PixelFormat.ARGB_8bpp_444: shader = _shader_ARGB_8bpp_444; break; case DeckLinkPlugin.PixelFormat.BGRA_8bpp_444: shader = _shader_BGRA_8bpp_444; break; case DeckLinkPlugin.PixelFormat.RGB_10bpp_444: shader = _shader_RGB_10bpp_444; pass = 0; break; case DeckLinkPlugin.PixelFormat.RGBX_10bpp_444: shader = _shader_RGB_10bpp_444; pass = 0; break; case DeckLinkPlugin.PixelFormat.RGBX_10bpp_444_LE: shader = _shader_RGB_10bpp_444; pass = 0; break; default: Debug.LogError("[AVProDeckLink] Unsupported pixel format " + format); result = false; break; } return(result); }
public static bool OutputFormatSupported(DeckLinkPlugin.PixelFormat format) { bool result = false; switch (format) { case DeckLinkPlugin.PixelFormat.YCbCr_10bpp_422: case DeckLinkPlugin.PixelFormat.YCbCr_8bpp_422: case DeckLinkPlugin.PixelFormat.BGRA_8bpp_444: case DeckLinkPlugin.PixelFormat.ARGB_8bpp_444: case DeckLinkPlugin.PixelFormat.RGBX_10bpp_444: case DeckLinkPlugin.PixelFormat.RGBX_10bpp_444_LE: case DeckLinkPlugin.PixelFormat.RGB_10bpp_444: result = true; break; } return(result); }
protected override bool ModeValid(DeckLinkPlugin.PixelFormat format) { return(DeckLinkOutput.OutputFormatSupported(format)); }
private string[] GetDeviceModes(int device, out List <Resolution> resolutions, out Resolution[] modeResolutions, out int[] positions) { List <Resolution> outputRes = new List <Resolution>(); int num_modes = DeckLinkPlugin.GetNumVideoInputModes(device); List <string> modes = new List <string>(); List <Resolution> mrs = new List <Resolution>(); List <int> actual_positions = new List <int>(); for (int i = 0; i < num_modes; ++i) { int width, height, fieldMode; float frameRate; long frameDuration; string modeDesc, pixelFormatDesc; if (_isInput) { DeckLinkPlugin.GetVideoInputModeInfo(device, i, out width, out height, out frameRate, out frameDuration, out fieldMode, out modeDesc, out pixelFormatDesc); } else { DeckLinkPlugin.GetVideoOutputModeInfo(device, i, out width, out height, out frameRate, out frameDuration, out fieldMode, out modeDesc, out pixelFormatDesc); } DeckLinkPlugin.PixelFormat format = DeckLinkPlugin.GetPixelFormat(pixelFormatDesc); if (FormatConverter.InputFormatSupported(format)) { modes.Add(modeDesc + " " + pixelFormatDesc); Resolution r = new Resolution(); r.width = width; r.height = height; mrs.Add(r); actual_positions.Add(i); bool resolutionFound = false; for (int j = 0; j < outputRes.Count; ++j) { if (width == outputRes[j].width && height == outputRes[j].height) { resolutionFound = true; break; } } if (!resolutionFound) { Resolution res = new Resolution(); res.width = width; res.height = height; outputRes.Add(res); } } } resolutions = outputRes; modeResolutions = mrs.ToArray(); positions = actual_positions.ToArray(); return(modes.ToArray()); }
protected abstract bool ModeValid(DeckLinkPlugin.PixelFormat format);
protected void DrawModeFilters(bool isInput) { GUILayout.Space(8f); if (GUILayout.Button("Mode Selection", EditorStyles.toolbarButton)) { _expandModeSel.boolValue = !_expandModeSel.boolValue; } if (_expandModeSel.boolValue) { GUILayout.BeginVertical("box"); GUILayout.Space(4f); if (_filterModeByResolution.boolValue) { GUI.color = Color.green; } if (GUILayout.Button("Force resolution")) { _filterModeByResolution.boolValue = !_filterModeByResolution.boolValue; } GUI.color = Color.white; if (_filterModeByResolution.boolValue) { GUILayout.BeginVertical("box"); if (resolutions == null || resolutionNames == null) { GetResolutions(out resolutions, out resolutionNames); } int foundPos = resolutionNames.Length - 1; for (int i = 0; i < resolutions.Length; ++i) { if (resolutions[i].width == _modeWidth.intValue && resolutions[i].height == _modeHeight.intValue) { foundPos = i; break; } } int newPos = EditorGUILayout.Popup("Resolution", foundPos, resolutionNames); if (newPos < resolutions.Length) { _modeWidth.intValue = resolutions[newPos].width; _modeHeight.intValue = resolutions[newPos].height; } else { if (newPos != foundPos) { _modeWidth.intValue = 0; _modeHeight.intValue = 0; } _modeWidth.intValue = EditorGUILayout.IntField("Width ", _modeWidth.intValue); _modeHeight.intValue = EditorGUILayout.IntField("Height ", _modeHeight.intValue); } GUILayout.EndVertical(); } GUILayout.Space(4f); if (_filterModeByFormat.boolValue) { GUI.color = Color.green; } if (GUILayout.Button("Force Format")) { _filterModeByFormat.boolValue = !_filterModeByFormat.boolValue; } GUI.color = Color.white; if (_filterModeByFormat.boolValue) { GUILayout.BeginVertical("box"); if (formatNames == null || formats == null) { if (isInput) { formatNames = GetInputFormats(out formats); } else { formatNames = GetOutputFormats(out formats); } } DeckLinkPlugin.PixelFormat prevFormat = (DeckLinkPlugin.PixelFormat)_modeFormat.intValue; int prevSelected = 0; for (int i = 0; i < formats.Length; ++i) { if (prevFormat == formats[i]) { prevSelected = i; break; } } int selected = EditorGUILayout.Popup("Pixel Format", prevSelected, formatNames); _modeFormat.intValue = (int)formats[selected]; GUILayout.EndVertical(); } GUILayout.Space(4f); if (_filterModeByFPS.boolValue) { GUI.color = Color.green; } if (GUILayout.Button("Force Frame Rate")) { _filterModeByFPS.boolValue = !_filterModeByFPS.boolValue; } GUI.color = Color.white; if (_filterModeByFPS.boolValue) { GUILayout.BeginVertical("box"); if (frameRates == null || fpsNames == null) { GetFrameRates(out frameRates, out fpsNames); } int foundPos = fpsNames.Length - 1; for (int i = 0; i < frameRates.Length; ++i) { if (Mathf.Abs(frameRates[i] - _modeFPS.floatValue) < 0.005f) { foundPos = i; break; } } int newPos = EditorGUILayout.Popup("Frame Rate", foundPos, fpsNames); if (newPos < frameRates.Length) { _modeFPS.floatValue = frameRates[newPos]; } else { if (newPos != foundPos) { _modeFPS.floatValue = 0f; } _modeFPS.floatValue = EditorGUILayout.FloatField("FrameRate", _modeFPS.floatValue); } GUILayout.EndVertical(); } GUILayout.Space(4f); if (_filterModeByInterlacing.boolValue) { GUI.color = Color.green; } if (GUILayout.Button("Force interlacing")) { _filterModeByInterlacing.boolValue = !_filterModeByInterlacing.boolValue; } GUI.color = Color.white; if (_filterModeByInterlacing.boolValue) { GUILayout.BeginVertical("box"); _modeInterlacing.boolValue = EditorGUILayout.Toggle("Interlaced", _modeInterlacing.boolValue); GUILayout.EndVertical(); } GUILayout.Space(4f); GUILayout.EndVertical(); } GUILayout.Space(8f); }
private void InitConversionResources(DeckLinkPlugin.PixelFormat format, int width, int height) { if (_conversionMaterial != null || _format != format) { Material.Destroy(_conversionMaterial); _conversionMaterial = null; _format = format; } int texWidth = -1; if (_conversionMaterial == null) { switch (format) { case DeckLinkPlugin.PixelFormat.YCbCr_8bpp_422: _conversionMaterial = new Material(_rgbaToYuv422Shader); texWidth = width / 2; break; case DeckLinkPlugin.PixelFormat.BGRA_8bpp_444: _conversionMaterial = new Material(_rgbaToBgraShader); texWidth = width; break; case DeckLinkPlugin.PixelFormat.ARGB_8bpp_444: _conversionMaterial = new Material(_rgbaToArgbShader); texWidth = width; break; default: break; } } if (_parameters != null) { _parameters.Release(); _parameters = null; } DeckLinkPlugin.SetOutputBufferPointer(_deviceIndex, null); DeckLinkPlugin.SetOutputTexturePointer(_deviceIndex, IntPtr.Zero); if (_convertedTexture != null) { RenderTexture.ReleaseTemporary(_convertedTexture); _convertedTexture = null; } if (_outputBuffer != null) { _outputBuffer = null; } if (_convertedCompBuffer != null) { _convertedCompBuffer.Release(); _convertedCompBuffer = null; } if (texWidth < 0) { //sets up compute buffers if (_format == DeckLinkPlugin.PixelFormat.RGBX_10bpp_444 || _format == DeckLinkPlugin.PixelFormat.RGBX_10bpp_444_LE || _format == DeckLinkPlugin.PixelFormat.RGB_10bpp_444) { _parameters = new ComputeBuffer(1, ComputeBufferParams.Size()); ComputeBufferParams[] parms = new ComputeBufferParams[1]; parms[0].height = (uint)height; parms[0].width = (uint)width; parms[0].bufferWidth = (uint)(width + 63) / 64 * 64; parms[0].leading = _format == DeckLinkPlugin.PixelFormat.RGB_10bpp_444 ? 1U : 0U; bool formatBigEndian = _format != DeckLinkPlugin.PixelFormat.RGBX_10bpp_444_LE ? true : false; if (BitConverter.IsLittleEndian) { formatBigEndian = !formatBigEndian; } parms[0].bigEndian = formatBigEndian ? 1U : 0U; _outputBuffer = new byte[parms[0].bufferWidth * parms[0].height * 4]; _convertedCompBuffer = new ComputeBuffer((int)(parms[0].bufferWidth * parms[0].height), 4, ComputeBufferType.Raw); _parameters.SetData(parms); DeckLinkPlugin.SetOutputBufferPointer(_deviceIndex, _outputBuffer); } else { _convertedTexture = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1); DeckLinkPlugin.SetOutputTexturePointer(_deviceIndex, _convertedTexture.GetNativeTexturePtr()); } } else { _convertedTexture = RenderTexture.GetTemporary(texWidth, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1); DeckLinkPlugin.SetOutputTexturePointer(_deviceIndex, _convertedTexture.GetNativeTexturePtr()); } }
protected override bool ModeValid(DeckLinkPlugin.PixelFormat format) { return(FormatConverter.InputFormatSupported(format)); }
private void InitConversionResources(DeckLinkPlugin.PixelFormat format, int width, int height) { if (_conversionMaterial != null || _format != format) { Material.Destroy(_conversionMaterial); _conversionMaterial = null; _format = format; } int texWidth = -1; // If we are doing keying and a non-RGBA mode is used for output, then use an RGBA texture, // as this conversion will be handled by the DeckLink hardware. if (_keyerMode != KeyerMode.None && !HasAlphaChannel(format)) { _conversionMaterial = new Material(_rgbaToArgbShader); texWidth = width; } else { // Otherwise convert to the output format switch (format) { case DeckLinkPlugin.PixelFormat.YCbCr_8bpp_422: _conversionMaterial = new Material(_rgbaToYuv422Shader); texWidth = width / 2; break; case DeckLinkPlugin.PixelFormat.YCbCr_10bpp_422: _conversionMaterial = new Material(_rgbaToYuv422Shader2); texWidth = (width / 6) * 4; _conversionMaterial.SetFloat("_TextureWidth", texWidth); break; case DeckLinkPlugin.PixelFormat.BGRA_8bpp_444: _conversionMaterial = new Material(_rgbaToBgraShader); texWidth = width; break; case DeckLinkPlugin.PixelFormat.ARGB_8bpp_444: _conversionMaterial = new Material(_rgbaToArgbShader); texWidth = width; break; default: break; } } if (_parameters != null) { _parameters.Release(); _parameters = null; } DeckLinkPlugin.SetOutputBufferPointer(_deviceIndex, null); DeckLinkPlugin.SetOutputTexturePointer(_deviceIndex, IntPtr.Zero); DeckLinkPlugin.SetRightOutputBufferPointer(_deviceIndex, null); DeckLinkPlugin.SetRightOutputTexturePointer(_deviceIndex, IntPtr.Zero); if (_convertedTexture != null) { RenderTexture.ReleaseTemporary(_convertedTexture); _convertedTexture = null; _convertedPointer = IntPtr.Zero; } if (_rightConvertedTexture != null) { RenderTexture.ReleaseTemporary(_rightConvertedTexture); _rightConvertedTexture = null; _rightConvertedPointer = IntPtr.Zero; } if (_outputBuffer != null) { _outputBuffer = null; } if (_rightOutputBuffer != null) { _rightOutputBuffer = null; } if (_convertedCompBuffer != null) { _convertedCompBuffer.Release(); _convertedCompBuffer = null; } if (texWidth < 0) { //sets up compute buffers if (_format == DeckLinkPlugin.PixelFormat.RGBX_10bpp_444 || _format == DeckLinkPlugin.PixelFormat.RGBX_10bpp_444_LE || _format == DeckLinkPlugin.PixelFormat.RGB_10bpp_444) { _parameters = new ComputeBuffer(1, ComputeBufferParams.Size()); ComputeBufferParams[] parms = new ComputeBufferParams[1]; parms[0].height = (uint)height; parms[0].width = (uint)width; parms[0].bufferWidth = (uint)(width + 63) / 64 * 64; parms[0].leading = _format == DeckLinkPlugin.PixelFormat.RGB_10bpp_444 ? 1U : 0U; bool formatBigEndian = _format != DeckLinkPlugin.PixelFormat.RGBX_10bpp_444_LE ? true : false; if (BitConverter.IsLittleEndian) { formatBigEndian = !formatBigEndian; } parms[0].bigEndian = formatBigEndian ? 1U : 0U; parms[0].isLinear = QualitySettings.activeColorSpace == ColorSpace.Linear ? 1U : 0U; _outputBuffer = new byte[parms[0].bufferWidth * parms[0].height * 4]; if (_current3DEnabled) { _rightOutputBuffer = new byte[parms[0].bufferWidth * parms[0].height * 4]; } _convertedCompBuffer = new ComputeBuffer((int)(parms[0].bufferWidth * parms[0].height), 4, ComputeBufferType.Raw); _parameters.SetData(parms); DeckLinkPlugin.SetOutputBufferPointer(_deviceIndex, _outputBuffer); DeckLinkPlugin.SetRightOutputBufferPointer(_deviceIndex, _rightOutputBuffer); } else { RenderTextureReadWrite readWriteMode = (QualitySettings.activeColorSpace == ColorSpace.Linear ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.Default); _convertedTexture = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, readWriteMode, 1); _convertedPointer = _convertedTexture.GetNativeTexturePtr(); DeckLinkPlugin.SetOutputTexturePointer(_deviceIndex, _convertedPointer); if (_current3DEnabled) { _rightConvertedTexture = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, readWriteMode, 1); _rightConvertedPointer = _rightConvertedTexture.GetNativeTexturePtr(); DeckLinkPlugin.SetRightOutputTexturePointer(_deviceIndex, _rightConvertedPointer); } } } else { RenderTextureReadWrite readWriteMode = (QualitySettings.activeColorSpace == ColorSpace.Linear ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.Default); RenderTextureFormat textureFormat = RenderTextureFormat.ARGB32; if (format == DeckLinkPlugin.PixelFormat.YCbCr_10bpp_422) { textureFormat = RenderTextureFormat.ARGB2101010; } _convertedTexture = RenderTexture.GetTemporary(texWidth, height, 0, textureFormat, readWriteMode, 1); _convertedPointer = _convertedTexture.GetNativeTexturePtr(); DeckLinkPlugin.SetOutputTexturePointer(_deviceIndex, _convertedPointer); if (_current3DEnabled) { _rightConvertedTexture = RenderTexture.GetTemporary(texWidth, height, 0, textureFormat, readWriteMode, 1); _rightConvertedPointer = _rightConvertedTexture.GetNativeTexturePtr(); DeckLinkPlugin.SetRightOutputTexturePointer(_deviceIndex, _rightConvertedPointer); } } }