private void EnumerateDevices() { foreach (var input in _inputDecklinks) { Destroy(input.gameObject); } _inputDecklinks.Clear(); // Enumerate all devices int numDevices = DeckLink.GetNumDevices(); print("num devices: " + numDevices); for (int i = 0; i < numDevices; i++) { GameObject decklinkObject = new GameObject(); DeckLinkInput input = decklinkObject.AddComponent <DeckLinkInput>(); input.DeviceIndex = i; input.ModeIndex = 0; input._playOnStart = true; input._autoDeinterlace = true; input._autoDetectMode = _autoDetect; input.Begin(); _inputDecklinks.Add(input); // Enumerate input modes print("device " + i + ": " + input.Device.Name + " has " + input.Device.NumInputModes + " input modes"); for (int j = 0; j < input.Device.NumInputModes; j++) { DeviceMode mode = input.Device.GetInputMode(j); print(" mode " + j + ": " + mode.Width + "x" + mode.Height + " @" + mode.FrameRate.ToString("F2") + "fps [" + mode.PixelFormatDescription + "] idx:" + mode.Index); } _scrollPos.Add(new Vector2(0, 0)); } }
public void EnumerateDevices() { foreach (var instance in _instances) { Destroy(instance.decklink.gameObject); } _instances.Clear(); // Enumerate all devices int numDevices = DeckLink.GetNumDevices(); if (_logDeviceModes) { print("num devices: " + numDevices); } for (int i = 0; i < numDevices; i++) { Device device = DeckLink.GetDevice(i); if (device.NumInputModes == 0) { continue; } GameObject decklinkObject = new GameObject(); DeckLinkInput input = decklinkObject.AddComponent <DeckLinkInput>(); input.DeviceIndex = i; input.ModeIndex = 0; input._playOnStart = true; input._autoDeinterlace = true; input._autoDetectMode = _autoDetect; input.Begin(); Instance instance = new Instance() { decklink = input }; _instances.Add(instance); if (_logDeviceModes) { // Enumerate input modes print("device " + i + ": " + input.Device.Name + " has " + input.Device.NumInputModes + " input modes"); for (int j = 0; j < input.Device.NumInputModes; j++) { DeviceMode mode = input.Device.GetInputMode(j); print(" mode " + j + ": " + mode.Width + "x" + mode.Height + " @" + mode.FrameRate.ToString("F2") + "fps [" + mode.PixelFormatDescription + "] idx:" + mode.Index); } } } }
private void EnumerateDevices() { // Enumerate all devices int numDevices = DeckLink.GetNumDevices(); print("num devices: " + numDevices); for (int i = 0; i < numDevices; i++) { Device device = DeckLink.GetDevice(i); // Enumerate output modes print("device " + i + ": " + device.Name + " has " + device.NumOutputModes + " output modes"); for (int j = 0; j < device.NumOutputModes; j++) { DeviceMode mode = device.GetOutputMode(j); print(" mode " + j + ": " + mode.Width + "x" + mode.Height + " @" + mode.FrameRate.ToString("F2") + "fps [" + mode.PixelFormatDescription + "] idx:" + mode.Index + " " + mode.InterlacedFieldMode); } } }
protected void DrawPreviewTexture(DeckLink decklink) { GUILayout.Space(8f); if (GUILayout.Button("Preview", EditorStyles.toolbarButton)) { _expandPreview.boolValue = !_expandPreview.boolValue; } if (_expandPreview.boolValue) { bool active = decklink != null && decklink.Device != null; GUI.enabled = active; Texture previewTex = null; if (active) { previewTex = _isInput ? ((DeckLinkInput)decklink).OutputTexture : ((DeckLinkOutput)decklink).InputTexture; if (previewTex == null) { previewTex = EditorGUIUtility.whiteTexture; } } else { previewTex = EditorGUIUtility.whiteTexture; } GUILayout.Space(8f); if (previewTex != EditorGUIUtility.whiteTexture) { Rect textureRect = GUILayoutUtility.GetRect(128.0f, 128.0f, GUILayout.MinWidth(128.0f), GUILayout.MinHeight(128.0f)); GUI.DrawTexture(textureRect, previewTex, ScaleMode.ScaleToFit); } else { Rect textureRect = GUILayoutUtility.GetRect(1920f / 40, 1080f / 40); GUI.DrawTexture(textureRect, EditorGUIUtility.whiteTexture, ScaleMode.ScaleToFit); } GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Select Texture", GUILayout.ExpandWidth(false))) { Selection.activeObject = previewTex; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); Device device = active ? decklink.Device : null; string deviceName = active ? device.Name : "N/A"; GUILayout.Label("Device: " + deviceName); DeviceMode mode = null; if (device != null) { mode = _isInput ? device.CurrentMode : device.CurrentOutputMode; } if (active && mode != null) { GUILayout.Label(string.Format("Mode: {0}x{1}/{2}hz {3}", mode.Width, mode.Height, mode.FrameRate.ToString("F2"), mode.PixelFormatDescription)); } if (_isInput) { if (active && device.FramesTotal > 30) { GUILayout.Label("Running at " + device.FPS.ToString("F1") + " fps"); } else { GUILayout.Label("Running at ... fps"); } if (active && device.IsStreaming) { GUILayout.BeginHorizontal(); if (device.IsPaused) { if (GUILayout.Button("Unpause Stream")) { device.Unpause(); } } else { if (GUILayout.Button("Pause Stream")) { device.Pause(); } } GUILayout.EndHorizontal(); } } else { if (active) { GUILayout.Label("Genlock status: " + (device.IsGenLocked ? " Locked" : "Not Locked")); if (device.IsGenLocked) { GUILayout.Label("Pixel offset: " + device.GenlockOffset); GUILayout.Label("Full Frame Pixel Offset is " + (device.SupportsFullFrameGenlockOffset ? " supported" : "not supported")); } } } GUI.enabled = true; } GUILayout.Space(8f); }
public void OnGUI() { GUI.skin = _guiSkin; if (_modeListStyle == null) { _modeListStyle = GUI.skin.GetStyle("ModeList"); } GUILayout.BeginHorizontal(); // List the devices _deviceScrollPos = GUILayout.BeginScrollView(_deviceScrollPos, false, false); GUILayout.BeginVertical("box", GUILayout.MaxWidth(300)); if (GUILayout.Button("Select Device:")) { _selectedDevice = null; } GUILayout.EndVertical(); GUILayout.BeginVertical("box", GUILayout.MaxWidth(300)); for (int i = 0; i < DeckLink.GetNumDevices(); i++) { Device device = DeckLink.GetDevice(i); if (device == _selectedDevice) { GUI.color = Color.blue; } if (_activeMode != null && device == _selectedDevice && device.IsStreamingOutput) { GUI.color = Color.green; } if (GUILayout.Button(device.Name + " " + device.ModelName, _modeListStyle)) { _selectedDevice = device; } GUI.color = Color.white; } GUILayout.EndVertical(); GUILayout.EndScrollView(); // For the selected device, list the modes available if (_selectedDevice != null) { GUILayout.BeginVertical(); GUILayout.BeginVertical("box", GUILayout.MaxWidth(300)); if (GUILayout.Button("Select Mode:")) { _selectedDevice = null; } GUILayout.EndVertical(); if (_selectedDevice != null) { GUILayout.BeginVertical("box", GUILayout.MaxWidth(600)); _modeScrollPos = GUILayout.BeginScrollView(_modeScrollPos, false, false); for (int j = 0; j < _selectedDevice.NumOutputModes; j++) { DeviceMode mode = _selectedDevice.GetOutputMode(j); if (mode == _activeMode) { if (_selectedDevice.IsStreamingOutput) { GUI.color = Color.green; } else { GUI.color = Color.blue; } } //GUILayout.BeginVertical("box", GUILayout.MaxWidth(300)); if (GUILayout.Button("" + j.ToString("D2") + ") " + mode.ModeDescription + " - " + mode.PixelFormatDescription + " - " + mode.Width + "x" + mode.Height, _modeListStyle)) { _decklink.StopOutput(); _decklink.DeviceIndex = _selectedDevice.DeviceIndex; _decklink.ModeIndex = mode.Index; _decklink.Begin(); _activeMode = mode; } GUI.color = Color.white; } GUILayout.EndScrollView(); GUILayout.EndVertical(); } GUILayout.EndVertical(); } if (_decklink.Device != null && _decklink.Device.IsStreamingOutput) { GUILayout.BeginVertical("box"); int numDecklinkBufferedFrames = DeckLinkPlugin.GetOutputBufferedFramesCount(_decklink.Device.DeviceIndex); int numWaitingOutputFrames = DeckLinkPlugin.GetWaitingOutputBufferCount(_decklink.Device.DeviceIndex); int numFreeOutputFrames = DeckLinkPlugin.GetFreeOutputBufferCount(_decklink.Device.DeviceIndex); GUILayout.Space(20f); GUILayout.Label(string.Format("VSync {0}", QualitySettings.vSyncCount)); GUILayout.Label(string.Format("{0:F3} {1}", _decklink.TargetFramerate, _decklink.OutputFramerate)); GUILayout.Label(string.Format("Buffers: DeckLink {0:D2} << Full {1:D2} << Empty {2:D2}", numDecklinkBufferedFrames, numWaitingOutputFrames, numFreeOutputFrames)); GUILayout.Label("Screen: " + Screen.currentResolution.width + "x" + Screen.currentResolution.height + " " + Screen.currentResolution.refreshRate); GUILayout.EndVertical(); } GUILayout.EndHorizontal(); }
public void OnGUI() { GUI.skin = _guiSkin; if (_modeListStyle == null) { _modeListStyle = GUI.skin.GetStyle("ModeList"); } // List the devices GUILayout.BeginVertical("box", GUILayout.MaxWidth(400)); if (GUILayout.Button("Select Input and Output Device:")) { _selectedInputDevice = null; _selectedOutputDevice = null; _needsInputAutoScroll = _needsOutputAutoScroll = false; } GUILayout.EndVertical(); GUILayout.BeginVertical("box", GUILayout.MaxWidth(400)); for (int i = 0; i < DeckLink.GetNumDevices(); i++) { Device device = DeckLink.GetDevice(i); GUILayout.BeginHorizontal(); GUILayout.Label(device.Name + " " + device.ModelName, _modeListStyle, GUILayout.Width(192f)); GUI.color = Color.white; if (device == _selectedInputDevice) { GUI.color = Color.blue; } if (device.IsStreamingInput) { GUI.color = Color.green; } GUI.enabled = true; if (device.IsStreamingOutput && !device.FullDuplexSupported) { GUI.enabled = false; } if (GUILayout.Button("Input", _modeListStyle)) { _selectedInputDevice = device; _needsInputAutoScroll = true; } GUI.color = Color.white; if (device == _selectedOutputDevice) { GUI.color = Color.blue; } if (device.IsStreamingOutput) { GUI.color = Color.green; } GUI.enabled = true; if (device.IsStreamingInput && !device.FullDuplexSupported) { GUI.enabled = false; } if (GUILayout.Button("Output", _modeListStyle)) { _selectedOutputDevice = device; _needsOutputAutoScroll = true; } GUI.enabled = device.IsStreaming; GUI.color = Color.white; if (GUILayout.Button("Stop", _modeListStyle)) { if (device.IsStreamingInput) { StopInput(); } if (device.IsStreamingOutput) { StopOutput(); } } GUILayout.EndHorizontal(); GUI.enabled = true; GUI.color = Color.white; } GUILayout.EndVertical(); _outputModeMatchInputMode = GUILayout.Toggle(_outputModeMatchInputMode, "Auto Match Output Mode To Input"); GUILayout.BeginHorizontal(); // For the selected device, list the INPUTmodes available if (_selectedInputDevice != null) { GUILayout.BeginVertical(); GUILayout.BeginVertical("box", GUILayout.MaxWidth(500)); if (GUILayout.Button("Select " + _selectedInputDevice.Name + " Input Mode:")) { _selectedInputDevice = null; } GUILayout.EndVertical(); if (_selectedInputDevice != null) { GUILayout.BeginVertical("box", GUILayout.MaxWidth(500), GUILayout.MaxHeight(400)); _inputModeScrollPos = GUILayout.BeginScrollView(_inputModeScrollPos, false, false); for (int j = 0; j < _selectedInputDevice.NumInputModes; j++) { DeviceMode mode = _selectedInputDevice.GetInputMode(j); if (_inputDecklink.Device != null && _inputDecklink.Device.IsStreaming && _inputDecklink.Device.CurrentMode == mode) { GUI.color = Color.green; } if (GUILayout.Button("" + j.ToString("D2") + ") " + mode.ModeDescription + " - " + mode.PixelFormatDescription + " - " + mode.Width + "x" + mode.Height, _modeListStyle)) { StartInput(mode); } GUI.color = Color.white; } if (Event.current.type == EventType.Repaint) { if (_needsInputAutoScroll) { if (_inputDecklink.Device != null && _inputDecklink.Device.IsStreaming && _inputDecklink.Device.CurrentMode != null) { float height = _modeListStyle.CalcHeight(new GUIContent("A"), 64); float y = _inputDecklink.Device.CurrentMode.Index * height; GUI.ScrollTo(new Rect(0, y, 10, height * 8)); } _needsInputAutoScroll = false; } } GUILayout.EndScrollView(); GUILayout.EndVertical(); } GUILayout.EndVertical(); } // For the selected device, list the OUTPUT modes available if (_selectedOutputDevice != null) { GUILayout.BeginVertical(); GUILayout.BeginVertical("box", GUILayout.MaxWidth(500)); if (GUILayout.Button("Select " + _selectedOutputDevice.Name + " Output Mode:")) { _selectedOutputDevice = null; } GUILayout.EndVertical(); if (_selectedOutputDevice != null) { GUILayout.BeginVertical("box", GUILayout.MaxWidth(500), GUILayout.MaxHeight(400)); _outputModeScrollPos = GUILayout.BeginScrollView(_outputModeScrollPos, false, false); for (int j = 0; j < _selectedOutputDevice.NumOutputModes; j++) { DeviceMode mode = _selectedOutputDevice.GetOutputMode(j); if (_outputDecklink.Device != null && _outputDecklink.Device.IsStreaming && _outputDecklink.Device.CurrentOutputMode == mode) { GUI.color = Color.green; } if (GUILayout.Button("" + j.ToString("D2") + ") " + mode.ModeDescription + " - " + mode.PixelFormatDescription + " - " + mode.Width + "x" + mode.Height, _modeListStyle)) { StartOutput(mode); } GUI.color = Color.white; } if (Event.current.type == EventType.Repaint) { if (_needsOutputAutoScroll) { if (_outputDecklink.Device != null && _outputDecklink.Device.IsStreaming && _outputDecklink.Device.CurrentOutputMode != null) { float height = _modeListStyle.CalcHeight(new GUIContent("A"), 64); float y = _outputDecklink.Device.CurrentOutputMode.Index * height; GUI.ScrollTo(new Rect(0, y, 10, height * 8)); } _needsOutputAutoScroll = false; } } GUILayout.EndScrollView(); GUILayout.EndVertical(); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); // Active input output device summary GUILayout.BeginArea(new Rect(0, Screen.height - 64, Screen.width, 64)); GUILayout.BeginVertical("box"); string inputStr = "None"; string outputStr = "None"; if (_inputDecklink.Device != null && _inputDecklink.Device.IsStreamingInput) { inputStr = "" + _inputDecklink.Device.Name + " - " + _inputDecklink.Device.CurrentMode.ModeDescription; } if (_outputDecklink.Device != null && _outputDecklink.Device.IsStreamingOutput) { outputStr = "" + _outputDecklink.Device.Name + " - " + _outputDecklink.Device.CurrentOutputMode.ModeDescription; } GUILayout.Label("Input: " + inputStr, _modeListStyle); GUILayout.Label("Output: " + outputStr, _modeListStyle); GUILayout.EndVertical(); GUILayout.EndArea(); // Output stats GUILayout.BeginArea(new Rect(Screen.width - 256, Screen.height - 192, 256, 192)); GUILayout.BeginVertical("box", GUILayout.ExpandHeight(true)); if (_outputDecklink.Device != null && _outputDecklink.Device.IsStreaming) { int numDecklinkBufferedFrames = DeckLinkPlugin.GetOutputBufferedFramesCount(_outputDecklink.Device.DeviceIndex); int numWaitingOutputFrames = DeckLinkPlugin.GetWaitingOutputBufferCount(_outputDecklink.Device.DeviceIndex); int numFreeOutputFrames = DeckLinkPlugin.GetFreeOutputBufferCount(_outputDecklink.Device.DeviceIndex); //GUILayout.Space(20f); GUILayout.Label(string.Format("VSync {0}", QualitySettings.vSyncCount)); GUILayout.Label(string.Format("{0:F3} {1}", _outputDecklink.TargetFramerate, _outputDecklink.OutputFramerate)); GUILayout.Label(string.Format("Buffers: DeckLink {0:D2} << Full {1:D2} << Empty {2:D2}", numDecklinkBufferedFrames, numWaitingOutputFrames, numFreeOutputFrames)); //GUILayout.Label("Buffered Frames: " + AVProDeckLinkPlugin.GetOutputBufferedFramesCount(_outputDecklink.Device.DeviceIndex)); //GUILayout.Label("Free Frames: " + AVProDeckLinkPlugin.GetFreeOutputBufferCount(_outputDecklink.Device.DeviceIndex)); GUILayout.Label("Screen: " + Screen.currentResolution.width + "x" + Screen.currentResolution.height + " " + Screen.currentResolution.refreshRate); } else { GUILayout.Label("No Output Stats"); } GUILayout.EndVertical(); GUILayout.EndArea(); }
protected void DrawPreviewTexture(DeckLink decklink) { GUILayout.Space(8f); if (GUILayout.Button("Preview", EditorStyles.toolbarButton)) { _expandPreview = !_expandPreview; } if (_expandPreview) { bool active = decklink != null && decklink.Device != null; GUI.enabled = active; Texture previewTex = null; Texture rightEyeTex = null; if (active) { previewTex = _isInput ? ((DeckLinkInput)decklink).OutputTexture : ((DeckLinkOutput)decklink).InputTexture; if (previewTex == null) { previewTex = EditorGUIUtility.whiteTexture; } rightEyeTex = _isInput ? ((DeckLinkInput)decklink).RightOutputTexture : ((DeckLinkOutput)decklink).RightInputTexture; if (rightEyeTex == null) { rightEyeTex = EditorGUIUtility.whiteTexture; } } else { previewTex = EditorGUIUtility.whiteTexture; } GUILayout.Space(8f); if (previewTex != EditorGUIUtility.whiteTexture) { Rect textureRect = GUILayoutUtility.GetRect(128.0f, 128.0f, GUILayout.MinWidth(128.0f), GUILayout.MinHeight(128.0f)); GUI.DrawTexture(textureRect, previewTex, ScaleMode.ScaleToFit); } else { Rect textureRect = GUILayoutUtility.GetRect(1920f / 40, 1080f / 40); GUI.DrawTexture(textureRect, EditorGUIUtility.whiteTexture, ScaleMode.ScaleToFit); } if (active) { bool drawRightEye = _isInput ? ((DeckLinkInput)decklink)._enable3D : ((DeckLinkOutput)decklink)._enable3D; if (drawRightEye) { if (previewTex != EditorGUIUtility.whiteTexture) { Rect textureRect = GUILayoutUtility.GetRect(128.0f, 128.0f, GUILayout.MinWidth(128.0f), GUILayout.MinHeight(128.0f)); GUI.DrawTexture(textureRect, rightEyeTex, ScaleMode.ScaleToFit); } else { Rect textureRect = GUILayoutUtility.GetRect(1920f / 40, 1080f / 40); GUI.DrawTexture(textureRect, EditorGUIUtility.whiteTexture, ScaleMode.ScaleToFit); } } } // Texture tools GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Select Texture", GUILayout.ExpandWidth(false))) { Selection.activeObject = previewTex; } if (GUILayout.Button("Save PNG", GUILayout.ExpandWidth(false))) { decklink.SavePNG(); } #if UNITY_5_6_OR_NEWER if (GUILayout.Button("Save EXR", GUILayout.ExpandWidth(false))) { decklink.SaveEXR(); } #endif GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); Device device = active ? decklink.Device : null; string deviceName = active ? device.Name : "N/A"; GUILayout.Label("Device: " + deviceName); DeviceMode mode = null; if (device != null) { mode = _isInput ? device.CurrentMode : device.CurrentOutputMode; if (active && mode != null) { GUILayout.Label(string.Format("Mode: {0}x{1}/{2}hz {3}", mode.Width, mode.Height, mode.FrameRate.ToString("F2"), mode.PixelFormatDescription)); } if (_isInput) { if (device.EnableTimeCodeInput) { FrameTimeCode tc = device.GetInputFrameTimeCode(); GUILayout.Label(string.Format("TimeCode: {0}:{1}:{2}:{3}", tc.hours, tc.minutes, tc.seconds, tc.frames)); } GUILayout.BeginHorizontal(); if (active && device.FramesTotal > 30) { GUILayout.Label("Running at " + device.FPS.ToString("F1") + " fps"); GUILayout.Label("Frame: " + device.FramesTotal); GUILayout.Label("Signal Drops: " + device.DroppedInputSignalCount); } else { GUILayout.Label("Running at ... fps"); } GUILayout.EndHorizontal(); if (active && device.IsStreaming) { GUILayout.BeginHorizontal(); if (device.IsPaused) { if (GUILayout.Button("Unpause Stream")) { device.Unpause(); } } else { if (GUILayout.Button("Pause Stream")) { device.Pause(); } } GUILayout.EndHorizontal(); } } else { if (active) { GUILayout.Label("Frame: " + device.FramesTotal); GUILayout.Label("Genlock status: " + (device.IsGenLocked ? " Locked" : "Not Locked")); if (device.IsGenLocked) { GUILayout.Label("Pixel offset: " + device.GenlockOffset); GUILayout.Label("Full Frame Pixel Offset is " + (device.SupportsFullFrameGenlockOffset ? " supported" : "not supported")); } } } } GUI.enabled = true; } GUILayout.Space(8f); }