Example #1
0
        private void EnumerateDevices()
        {
            // Enumerate all cameras
            int numDevices = AVProLiveCameraManager.Instance.NumDevices;

            print("num devices: " + numDevices);
            for (int i = 0; i < numDevices; i++)
            {
                AVProLiveCameraDevice device = AVProLiveCameraManager.Instance.GetDevice(i);

                // Enumerate video inputs (only for devices with multiple analog input sources, eg TV cards)
                print("device " + i + ": " + device.Name + " (" + device.GUID + ") has " + device.NumVideoInputs + " videoInputs");
                for (int j = 0; j < device.NumVideoInputs; j++)
                {
                    print("  videoInput " + j + ": " + device.GetVideoInputName(j));
                }

                // Enumerate camera modes
                print("device " + i + ": " + device.Name + " (" + device.GUID + ") has " + device.NumModes + " modes");
                for (int j = 0; j < device.NumModes; j++)
                {
                    AVProLiveCameraDeviceMode mode = device.GetMode(j);
                    print("  mode " + j + ": " + mode.Width + "x" + mode.Height + " @" + mode.FPS.ToString("F2") + "fps [" + mode.Format + "]");
                }

                // Enumerate camera settings
                print("device " + i + ": " + device.Name + " (" + device.GUID + ") has " + device.NumSettings + " video settings");
                for (int j = 0; j < device.NumSettings; j++)
                {
                    AVProLiveCameraSettingBase settingBase = device.GetVideoSettingByIndex(j);
                    switch (settingBase.DataTypeValue)
                    {
                    case AVProLiveCameraSettingBase.DataType.Boolean:
                    {
                        AVProLiveCameraSettingBoolean settingBool = (AVProLiveCameraSettingBoolean)settingBase;
                        print(string.Format("  setting {0}: {1}({2}) value:{3} default:{4} canAuto:{5} isAuto:{6}", j, settingBase.Name, settingBase.PropertyIndex, settingBool.CurrentValue, settingBool.DefaultValue, settingBase.CanAutomatic, settingBase.IsAutomatic));
                    }
                    break;

                    case AVProLiveCameraSettingBase.DataType.Float:
                    {
                        AVProLiveCameraSettingFloat settingFloat = (AVProLiveCameraSettingFloat)settingBase;
                        print(string.Format("  setting {0}: {1}({2}) value:{3} default:{4} range:{5}-{6} canAuto:{7} isAuto:{8}", j, settingBase.Name, settingBase.PropertyIndex, settingFloat.CurrentValue, settingFloat.DefaultValue, settingFloat.MinValue, settingFloat.MaxValue, settingBase.CanAutomatic, settingBase.IsAutomatic));
                    }
                    break;
                    }
                }

                _instances.Add(new UIData()
                {
                    scrollPos           = Vector2.zero,
                    scrollVideoInputPos = Vector2.zero,
                    showSettings        = false,
                    showModes           = false,
                    material            = null
                });
            }
        }
Example #2
0
    private AVProLiveCameraDeviceMode SelectMode()
    {
        AVProLiveCameraDeviceMode result = null;

        switch (_modeSelection)
        {
        default:
        case SelectModeBy.Default:
            result = null;
            break;

        case SelectModeBy.Resolution:
            if (_desiredResolutions.Count > 0)
            {
                result = GetClosestMode(_device, _desiredResolutions, _maintainAspectRatio);
                if (result == null)
                {
                    Debug.LogWarning("[AVPro Live Camera] Could not find desired mode, using default mode.");
                }
            }
            break;

        case SelectModeBy.Index:
            if (_desiredModeIndex >= 0)
            {
                result = _device.GetMode(_desiredModeIndex);
                if (result == null)
                {
                    Debug.LogWarning("[AVPro Live Camera] Could not find desired mode, using default mode.");
                }
            }
            break;
        }

        return(result);
    }
Example #3
0
        public void OnGUI()
        {
            if (_guiSkin != null)
            {
                if (_buttonStyle == null)
                {
                    _buttonStyle = _guiSkin.FindStyle("LeftButton");
                }
                GUI.skin = _guiSkin;
            }
            if (_buttonStyle == null)
            {
                _buttonStyle = GUI.skin.button;
            }

            _horizScrollPos = GUILayout.BeginScrollView(_horizScrollPos, false, false);
            GUILayout.BeginHorizontal();
            for (int i = 0; i < AVProLiveCameraManager.Instance.NumDevices; i++)
            {
                GUILayout.BeginVertical("box", GUILayout.MaxWidth(300));

                AVProLiveCameraDevice device = AVProLiveCameraManager.Instance.GetDevice(i);

                GUI.enabled = device.IsConnected;

                Rect cameraRect = GUILayoutUtility.GetRect(300, 168);
                if (GUI.Button(cameraRect, ""))
                {
                    if (_zoomed == null)
                    {
                        _zoomed      = device.OutputTexture;
                        _zoomSrcDest = cameraRect;
                        _zoomUp      = true;
                    }
                }

                // Thumbnail image
                if (device.OutputTexture != null && _zoomed != device.OutputTexture)
                {
                    if (_material != null)
                    {
                        DrawTexture(cameraRect, device.OutputTexture, ScaleMode.ScaleToFit, _material);
                    }
                    else
                    {
                        GUI.DrawTexture(cameraRect, device.OutputTexture, ScaleMode.ScaleToFit, false);
                    }
                }

                GUILayout.Box("Camera " + i + ": " + device.Name);
                if (!device.IsRunning)
                {
                    GUILayout.BeginHorizontal();
                    GUI.color = Color.green;
                    if (GUILayout.Button("Start"))
                    {
                        if (_zoomed == null)
                        {
                            device.Start(-1);
                        }
                    }
                    GUI.color = Color.white;
                }
                else
                {
                    GUILayout.Box(string.Format("{0}x{1} {2}", device.CurrentWidth, device.CurrentHeight, device.CurrentFormat));
                    GUILayout.BeginHorizontal();
                    GUILayout.Box(string.Format("Capture {0}hz Display {1}hz", device.CaptureFPS.ToString("F2"), device.DisplayFPS.ToString("F2")));
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    GUI.color = Color.red;
                    if (GUILayout.Button("Stop"))
                    {
                        if (_zoomed == null)
                        {
                            device.Close();
                        }
                    }
                    GUI.color = Color.white;
                }
                GUI.enabled = device.CanShowConfigWindow();
                if (GUILayout.Button("Configure", GUILayout.ExpandWidth(false)))
                {
                    if (_zoomed == null)
                    {
                        device.ShowConfigWindow();
                    }
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                if (device.NumVideoInputs > 0)
                {
                    GUILayout.Label("Select a video input:");
                    _scrollVideoInputPos[i] = GUILayout.BeginScrollView(_scrollVideoInputPos[i], false, false);
                    for (int j = 0; j < device.NumVideoInputs; j++)
                    {
                        if (GUILayout.Button(device.GetVideoInputName(j)))
                        {
                            if (_zoomed == null)
                            {
                                // Start selected device
                                device.Close();
                                device.Start(-1, j);
                            }
                        }
                    }
                    GUILayout.EndScrollView();
                }

                if (device.Deinterlace != GUILayout.Toggle(device.Deinterlace, "Deinterlace", GUILayout.ExpandWidth(true)))
                {
                    device.Deinterlace = !device.Deinterlace;
                    if (device.IsRunning)
                    {
                        device.Close();
                        device.Start(-1, -1);
                    }
                }

                GUILayout.BeginHorizontal();
                device.FlipX = GUILayout.Toggle(device.FlipX, "Flip X", GUILayout.ExpandWidth(true));
                device.FlipY = GUILayout.Toggle(device.FlipY, "Flip Y", GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();

                _scrollPos[i] = GUILayout.BeginScrollView(_scrollPos[i], false, false);

                if (device.NumSettings > 0)
                {
                    GUI.color        = Color.cyan;
                    _showSettings[i] = GUILayout.Toggle(_showSettings[i], "Settings ▶", GUILayout.ExpandWidth(true));
                    GUI.color        = Color.white;
                    if (_showSettings[i])
                    {
                        device.UpdateSettings = GUILayout.Toggle(device.UpdateSettings, "Update Settings", GUILayout.ExpandWidth(true));

                        for (int j = 0; j < device.NumSettings; j++)
                        {
                            AVProLiveCameraSettingBase settingBase = device.GetVideoSettingByIndex(j);
                            GUILayout.BeginHorizontal();
                            GUI.enabled = !settingBase.IsAutomatic;
                            if (GUILayout.Button("D", GUILayout.ExpandWidth(false)))
                            {
                                settingBase.SetDefault();
                            }
                            GUI.enabled = true;
                            GUILayout.Label(settingBase.Name, GUILayout.ExpandWidth(false));
                            GUI.enabled = !settingBase.IsAutomatic;
                            switch (settingBase.DataTypeValue)
                            {
                            case AVProLiveCameraSettingBase.DataType.Boolean:
                                AVProLiveCameraSettingBoolean settingBool = (AVProLiveCameraSettingBoolean)settingBase;
                                settingBool.CurrentValue = GUILayout.Toggle(settingBool.CurrentValue, "", GUILayout.ExpandWidth(true));
                                break;

                            case AVProLiveCameraSettingBase.DataType.Float:
                                AVProLiveCameraSettingFloat settingFloat = (AVProLiveCameraSettingFloat)settingBase;
                                settingFloat.CurrentValue = GUILayout.HorizontalSlider(settingFloat.CurrentValue, settingFloat.MinValue, settingFloat.MaxValue, GUILayout.ExpandWidth(true));

                                GUI.enabled             = settingBase.CanAutomatic;
                                settingBase.IsAutomatic = GUILayout.Toggle(settingBase.IsAutomatic, "", GUILayout.Width(32.0f));
                                GUI.enabled             = true;

                                break;
                            }
                            GUI.enabled = true;
                            GUILayout.EndHorizontal();
                        }

                        if (GUILayout.Button("Defaults"))
                        {
                            for (int j = 0; j < device.NumSettings; j++)
                            {
                                AVProLiveCameraSettingBase settingBase = device.GetVideoSettingByIndex(j);
                                settingBase.SetDefault();
                            }
                        }
                    }
                }

                GUI.color     = Color.cyan;
                _showModes[i] = GUILayout.Toggle(_showModes[i], "Modes ▶", GUILayout.ExpandWidth(true));
                GUI.color     = Color.white;
                if (_showModes[i])
                {
                    for (int j = 0; j < device.NumModes; j++)
                    {
                        AVProLiveCameraDeviceMode mode = device.GetMode(j);
                        if (GUILayout.Button("" + mode.Width + "x" + mode.Height + " " + mode.FPS.ToString("F2") + "hz " + "[" + mode.Format + "]", _buttonStyle))
                        {
                            if (_zoomed == null)
                            {
                                // Start selected device
                                device.Close();
                                Debug.Log("Selecting mode: " + j);
                                device.Start(mode);
                            }
                        }
                    }
                }

                GUILayout.EndScrollView();


                GUILayout.EndVertical();
            }

            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();

            // Show zoomed camera image
            if (_zoomed != null)
            {
                Rect fullScreenRect = new Rect(0f, 0f, Screen.width, Screen.height);

                float t = Mathf.Clamp01(_zoomTimer / ZoomTime);
                t = Mathf.SmoothStep(0f, 1f, t);
                Rect r = new Rect();
                r.x      = Mathf.Lerp(_zoomSrcDest.x, fullScreenRect.x, t);
                r.y      = Mathf.Lerp(_zoomSrcDest.y, fullScreenRect.y, t);
                r.width  = Mathf.Lerp(_zoomSrcDest.width, fullScreenRect.width, t);
                r.height = Mathf.Lerp(_zoomSrcDest.height, fullScreenRect.height, t);

                if (_material != null)
                {
                    DrawTexture(r, _zoomed, ScaleMode.ScaleToFit, _material);
                }
                else
                {
                    GUI.DrawTexture(r, _zoomed, ScaleMode.ScaleToFit, false);
                }
            }
        }