/// <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; }
private static void InitObs() { try { Debug.WriteLine("libobs version: " + Obs.GetVersion()); // forward OBS logging messages to debugger Obs.SetLogHandler((lvl, msg, p) => { Debug.WriteLine(msg); }); if (!Obs.Startup("en-US")) { throw new ApplicationException("Startup failed."); } // initialize video libobs.obs_video_info ovi = new libobs.obs_video_info { adapter = 0, base_width = (uint)MainWidth, base_height = (uint)MainHeight, fps_num = 30000, fps_den = 1001, graphics_module = "libobs-d3d11", output_format = libobs.video_format.VIDEO_FORMAT_RGBA, output_width = (uint)MainWidth, output_height = (uint)MainHeight, }; if (!Obs.ResetVideo(ovi)) { throw new ApplicationException("ResetVideo failed."); } // initialize audio libobs.obs_audio_info avi = new libobs.obs_audio_info { samples_per_sec = 44100, speakers = libobs.speaker_layout.SPEAKERS_STEREO, //buffer_ms = 1000 }; if (!Obs.ResetAudio(avi)) { throw new ApplicationException("ResetAudio failed."); } // load all plugins and modules Obs.LoadAllModules(); } catch (BadImageFormatException exp) { MessageBox.Show("Platform target mismatch: " + (FX35Helper.Is64BitProcess() ? "Loading 32-bit OBS with 64-bit executable is not supported." : "Loading 64-bit OBS with 32-bit executable is not supported.") + "\n\n" + exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } }
private void TestForm_Load(object sender, EventArgs e) { if (FX35Helper.Is64BitProcess()) { Text += " (64-bit)"; } else { Text += " (32-bit)"; } presentation = new Presentation(); // Bindings // Scene SceneListBox.DisplayMember = "Name"; SceneListBox.ValueMember = "Items"; SceneListBox.DataSource = presentation.Scenes; // Item ItemListBox.DisplayMember = "Name"; // Source SourceListBox.DisplayMember = "Name"; SourceListBox.DataSource = presentation.Sources; presentation.AddScene(); ItemListBox.DataSource = SceneListBox.SelectedValue; var source = presentation.CreateSource("monitor_capture", "Monitor Capture Source"); presentation.AddSource(source); var item = presentation.CreateItem(source); item.Name = "Monitor Capture SceneItem"; presentation.AddItem(item); presentation.SetScene(SceneListBox.SelectedIndex); presentation.SetItem(ItemListBox.SelectedIndex); presentation.SetSource(SourceListBox.SelectedIndex); HideItemCheckBox.DataBindings.Add( new Binding("Checked", presentation.SelectedItem, "Visible", false, DataSourceUpdateMode.OnPropertyChanged)); EnableSourceCheckBox.DataBindings.Add( new Binding("Checked", presentation.SelectedSource, "Enabled", false, DataSourceUpdateMode.OnPropertyChanged)); MuteSourceCheckBox.DataBindings.Add( new Binding("Checked", presentation.SelectedSource, "Muted", false, DataSourceUpdateMode.OnPropertyChanged)); // setup scene preview panel previewPanel = new PreviewPanel(); previewPanel.Dock = DockStyle.Fill; topPanel.Controls.Add(previewPanel); previewPanel.Show(); previewPanel.SetScene(presentation.SelectedScene); }