Пример #1
0
        /// <summary>
        /// Creates the click highlight settings.
        /// </summary>
        /// <returns></returns>
        private ObsData CreateClickHighlightSettings()
        {
            ObsData settings = new ObsData();

            settings.SetBool(MediaSource.IS_LOCAL_FILE, true);
            settings.SetBool(MediaSource.LOOPING, true);
            settings.SetBool(MediaSource.RESTART_ON_ACTIVATE, true);
            settings.SetBool(MediaSource.HW_DECODE, true);
            settings.SetString(MediaSource.LOCAL_FILE_PATH, _highlightImagePath);
            settings.SetBool(Common.ACTIVATE, true);
            return(settings);
        }
        /// <summary>
        /// Sets the audio output to the device with the given audio output id.
        /// </summary>
        /// <param name="savedAudioOutputId"></param>
        /// <returns></returns>
        public static string SetAudioOutput(string savedAudioOutputId)
        {
            ObsData aoSettings = new ObsData();

            aoSettings.SetBool(Constants.Audio.SettingKeys.UseDeviceTiming, false);
            Store.Data.Audio.OutputSource = Store.Data.Obs.Presentation.CreateSource(Constants.Audio.SettingKeys.WasapiOutputCapture, Constants.Audio.Settings.WasapiOutputCaptureName, aoSettings);
            aoSettings.Dispose();
            Store.Data.Audio.OutputSource.AudioOffset = Constants.Audio.DELAY_OUTPUT; // For some reason, this offset needs to be here before presentation.CreateSource is called again to take affect
            Store.Data.Obs.Presentation.AddSource(Store.Data.Audio.OutputSource);
            Store.Data.Audio.OutputItem      = Store.Data.Obs.Presentation.CreateItem(Store.Data.Audio.OutputSource);
            Store.Data.Audio.OutputItem.Name = Constants.Audio.Settings.WasapiOutputCaptureName;

            Store.Data.Audio.OutputMeter       = new VolMeter();
            Store.Data.Audio.OutputMeter.Level = float.NegativeInfinity;
            Store.Data.Audio.OutputMeter.AttachSource(Store.Data.Audio.OutputSource);
            Store.Data.Audio.OutputMeter.AddCallBack(MagnitudeService.OutputVolumeCallback);

            List <AudioDevice> allAudioOutputs = GetAudioOutputDevices();
            bool savedIsInAvailableOutputs     = allAudioOutputs.Any(x => x.id == savedAudioOutputId);

            var usedAudioOutputId = string.Empty;

            if (savedAudioOutputId != null && savedIsInAvailableOutputs)
            {
                UpdateAudioOutput(savedAudioOutputId);
                usedAudioOutputId = savedAudioOutputId;
            }
            else
            {
                UpdateAudioOutput(Constants.Audio.NO_DEVICE_ID);
                usedAudioOutputId = Constants.Audio.NO_DEVICE_ID;
            }

            return(usedAudioOutputId);
        }
Пример #3
0
        private ObsData CreateWebcamSettings()
        {
            ObsData webcamSettings = new ObsData();

            webcamSettings.SetString(VideoCapture.VIDEO_DEVICE_ID, selectedWebcam.value);

            int buffering = 2;

            webcamSettings.SetInt(VideoCapture.BUFFERING, buffering); // 0 = Auto, 1 = Enable, 2 = Disable

            // need to check webcam whitelist
            if (Store.Data.Webcam.WebcamSettings.ShouldUseCustomSettings)
            {
                webcamSettings.SetString(VideoCapture.RESOLUTION, Store.Data.Webcam.WebcamSettings.Resolution);
                webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 1);
                webcamSettings.SetInt(VideoCapture.VIDEO_FORMAT, (int)Store.Data.Webcam.WebcamSettings.VideoFormat);
                webcamSettings.SetInt(VideoCapture.FRAME_INTERVAL, Store.Data.Webcam.WebcamSettings.Fps);
            }
            else
            {
                if (selectedWebcamResolution != null)
                {
                    webcamSettings.SetString(VideoCapture.RESOLUTION, selectedWebcamResolution.value);
                    webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 1);
                }
                else
                {
                    var preferredResolution = WebcamService.GetOptimalWebcamResolution(selectedWebcam.dsDeviceValue);

                    if (!string.IsNullOrEmpty(preferredResolution))
                    {
                        webcamSettings.SetString(VideoCapture.RESOLUTION, preferredResolution);
                        webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 1);
                    }
                    else
                    {
                        webcamSettings.Erase(VideoCapture.RESOLUTION);
                        webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 0);
                    }
                }
            }

            webcamSettings.SetBool(VideoCapture.ACTIVATE, true);

            return(webcamSettings);
        }
        /// <summary>
        /// Sets the audio input to the device with the given audio input id.
        /// </summary>
        /// <param name="savedAudioInputId"></param>
        /// <returns></returns>
        public static string SetAudioInput(string savedAudioInputId)
        {
            ObsData aiSettings = new ObsData();

            aiSettings.SetBool(Constants.Audio.SettingKeys.UseDeviceTiming, false);
            Store.Data.Audio.InputSource = Store.Data.Obs.Presentation.CreateSource(Constants.Audio.SettingKeys.WasapiInputCapture, Constants.Audio.Settings.WasapiInputCaptureName, aiSettings);
            aiSettings.Dispose();

            Store.Data.Audio.InputSource.AudioOffset = Constants.Audio.DELAY_INPUT;
            Store.Data.Obs.Presentation.AddSource(Store.Data.Audio.InputSource);
            Store.Data.Audio.InputItem      = Store.Data.Obs.Presentation.CreateItem(Store.Data.Audio.InputSource);
            Store.Data.Audio.InputItem.Name = Constants.Audio.Settings.WasapiInputCaptureName;

            Store.Data.Audio.InputMeter       = new VolMeter();
            Store.Data.Audio.InputMeter.Level = float.NegativeInfinity;
            Store.Data.Audio.InputMeter.AttachSource(Store.Data.Audio.InputSource);
            Store.Data.Audio.InputMeter.AddCallBack(MagnitudeService.InputVolumeCallback);

            List <AudioDevice> allAudioInputs = GetAudioInputDevices();
            bool savedIsInAvailableInputs     = allAudioInputs.Any(x => x.id == savedAudioInputId);

            var usedAudioInputId = string.Empty;

            if (savedAudioInputId != null && savedIsInAvailableInputs)
            {
                UpdateAudioInput(savedAudioInputId);
                usedAudioInputId = savedAudioInputId;
            }
            else
            {
                string defaultDeviceId = Constants.Audio.NO_DEVICE_ID;

                IEnumerable <AudioDevice> availableInputs = allAudioInputs.Where(x => x.id != Constants.Audio.NO_DEVICE_ID);
                if (availableInputs.Any())
                {
                    defaultDeviceId = availableInputs.First().id;
                }

                UpdateAudioInput(defaultDeviceId);
                usedAudioInputId = defaultDeviceId;
            }

            return(usedAudioInputId);
        }
Пример #5
0
        private void AddBool(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;

            CheckBox checkbox = new CheckBox
            {
                Width     = 300,
                Height    = 18,
                Checked   = setting.GetBool(name),
                Text      = property.Description,
                TextAlign = ContentAlignment.MiddleLeft
            };

            checkbox.CheckedChanged += (sender, args) =>
            {
                setting.SetBool(name, checkbox.Checked);
                view.PropertyChanged(property);
            };

            controls.Add(checkbox);
        }
Пример #6
0
        /// <summary>
        /// Finds DirectShow audio device from current wsapi audio device to attach to the webcam.
        /// </summary>
        public static void UpdateAudioDevice()
        {
            // DISABLING CUSTOM AUDIO DEVICE - if re-enabling, search for this comment
            if (Store.Data.Audio.InputSource != null)
            {
                Store.Data.Audio.InputSource.AudioOffset = Constants.Audio.DELAY_INPUT_NOT_ATTACHED_TO_WEBCAM;
            }

            return;

            if (Store.Data.Webcam.Source == null)
            {
                return;
            }

            // Disable the main microphone, we need to attach it to the webcamsource_webcam
            Store.Data.Audio.InputSource.Enabled = false;

            var foundWebcamAudio = false;

            if (Store.Data.Audio.CurrentInputId == Constants.Audio.NO_DEVICE_ID)
            {
                ObsData wcSettings = new ObsData();
                wcSettings.SetBool("use_custom_audio_device", false);
                Store.Data.Webcam.Source.Update(wcSettings);
                foundWebcamAudio = true;
                return;
            }

            Store.Data.Webcam.Source.GetProperties();

            string      devenumDir            = FX35Helper.Is64BitProcess() ? "devenum 64-bit" : "devenum";
            RegistryKey inputDevicesDirectory = Registry.CurrentUser.OpenSubKey("SOFTWARE")?.OpenSubKey("Microsoft")?.OpenSubKey("ActiveMovie")?.OpenSubKey(devenumDir)?.OpenSubKey("{33D9A762-90C8-11D0-BD43-00A0C911CE86}");

            if (inputDevicesDirectory == null)
            {
                foundWebcamAudio = false;
                return;
            }

            string[] subKeyNames        = inputDevicesDirectory.GetSubKeyNames();
            string   directShowDeviceId = null;

            foreach (string name in subKeyNames)
            {
                RegistryKey subkey     = inputDevicesDirectory.OpenSubKey(name);
                string      endpointId = subkey.GetValue("EndpointId")?.ToString();
                object      waveInId   = subkey.GetValue("WaveInId");

                if (Store.Data.Audio.CurrentInputId == Constants.Audio.DEFAULT_DEVICE_ID)
                {
                    if (waveInId == null || (int)waveInId != 0)
                    {
                        continue;
                    }
                }
                else if (endpointId == null || endpointId != Store.Data.Audio.CurrentInputId)
                {
                    continue;
                }

                string friendlyName = subkey.GetValue("FriendlyName")?.ToString();
                if (friendlyName != null)
                {
                    // Direct show adds a colon to the friendly name for the id
                    directShowDeviceId = $"{friendlyName}:";
                    break;
                }
            }

            if (directShowDeviceId == null)
            {
                foundWebcamAudio = false;
                return;
            }

            ObsData wSettings = new ObsData();

            wSettings.SetBool("use_custom_audio_device", true);
            wSettings.SetString("audio_device_id", directShowDeviceId);
            Store.Data.Webcam.Source.Update(wSettings);
            foundWebcamAudio = true;
        }
Пример #7
0
        /// <summary>
        /// Resets and updates the video settings for video output.
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static bool ResetVideoInfo(ResetVideoInfoParameters parameters)
        {
            if (Store.Data.Obs.Presentation != null)
            {
                if (Store.Data.Obs.Presentation.SelectedScene.GetName().ToLowerInvariant() != "main")
                {
                    Store.Data.Obs.Presentation.SetScene(0);
                }
            }

            Store.Data.Record.AppliedCrop = new obs_sceneitem_crop
            {
                left   = parameters.CropLeft,
                top    = parameters.CropTop,
                right  = parameters.CropRight,
                bottom = parameters.CropBottom
            };

            Store.Data.Record.ActiveScreen = ScreenHelper.GetScreen(parameters.ScreenX, parameters.ScreenY);

            //Set the proper display source
            if (Store.Data.Display.DisplaySource != null)
            {
                ObsData displaySettings = new ObsData();
                displaySettings.SetBool("capture_cursor", true);

                displaySettings.SetInt("monitor", ObsHelper.GetObsDisplayValueFromScreen(Store.Data.Display.DisplaySource, Store.Data.Record.ActiveScreen));

                Store.Data.Display.DisplaySource.Update(displaySettings);
                displaySettings.Dispose();
            }

            //Set the proper display bounds and crop
            if (Store.Data.Display.DisplayItem != null)
            {
                Store.Data.Display.DisplayItem.SetBounds(new Vector2(0, 0), ObsBoundsType.None, ObsAlignment.Top);
                Store.Data.Display.DisplayItem.SetCrop(Store.Data.Record.AppliedCrop);
            }

            WebcamService.CalculateItemPosition();

            var obsVideoInfo = new GenerateObsVideoInfoParameters
            {
                BaseWidth    = (uint)parameters.CanvasWidth,
                OutputWidth  = (uint)parameters.OutputWidth,
                BaseHeight   = (uint)parameters.CanvasHeight,
                OutputHeight = (uint)parameters.OutputHeight,
                FrameRate    = GetFrameRate(parameters.FrameRate)
            };

            obs_video_info ovi = ObsHelper.GenerateObsVideoInfoObject(obsVideoInfo);

            if (!Obs.ResetVideo(ovi))
            {
                return(false);
            }

            Store.Data.Record.CanvasHeight = parameters.CanvasHeight;
            Store.Data.Record.CanvasWidth  = parameters.CanvasWidth;

            return(true);
        }