private void EnableFullScreen_Executed(object sender, ExecutedRoutedEventArgs e) { if (!UserSettings.All.FullScreenMode) { Left = _latestPoint.X; Top = _latestPoint.Y; UserSettings.All.RecorderThinMode = _wasThin; return; } _latestPoint = new System.Windows.Point(Left, Top); _wasThin = UserSettings.All.RecorderThinMode; //Check memory usage. //Check the stop. //To hide a few elements. UserSettings.All.RecorderThinMode = true; //Reposition the window to the lower right corner. var screen = ScreenHelper.GetScreen(this); //Lower Right corner. Left = screen.WorkingArea.Width / _scale - Width; Top = screen.WorkingArea.Height / _scale - Height; }
/// <summary> /// Shows the Encoder window. /// </summary> /// <param name="scale">Screen scale.</param> public static void Start(double scale) { #region If already started if (_encoder != null) { if (_encoder.WindowState == WindowState.Minimized) { Restore(); } return; } #endregion _encoder = new Encoder(); var screen = ScreenHelper.GetScreen(_encoder); //Lower Right corner. _encoder.Left = screen.WorkingArea.Width / scale - _encoder.Width; _encoder.Top = screen.WorkingArea.Height / scale - _encoder.Height; _encoder.Show(); }
/// <summary> /// Calculates where the OBS webcam item should be positioned. /// </summary> public static void CalculateItemPosition() { if (Store.Data.Webcam.Item == null || Store.Data.Webcam.Window == null) { return; } // todo: verify that this is the correct screen Rect activeScreenBounds = DpiUtil.GetScreenWpfBounds(ScreenHelper.GetScreen(Store.Data.SelectionWindow.Left, Store.Data.SelectionWindow.Top)); double baseOffsetX = activeScreenBounds.X; double baseOffsetY = activeScreenBounds.Y; if (!Store.Data.Record.IsFullScreen) { baseOffsetX = Store.Data.SelectionWindow.Left + Store.Data.SelectionWindow.BorderWidth; baseOffsetY = Store.Data.SelectionWindow.Top + Store.Data.SelectionWindow.BorderWidth; } WindowSizeProperties webcamWindowSize = Util.GetWindowSizeProperties(Store.Data.Webcam.Window); double webcamItemWidth = webcamWindowSize.Width - (webcamWindowSize.BorderWidth.Value * 2); double webcamItemHeight = webcamWindowSize.Height - (webcamWindowSize.BorderWidth.Value * 2); int webcamObsX = DpiUtil.ConvertSizeWpfToPhysicalPixel(webcamWindowSize.Left + webcamWindowSize.BorderWidth.Value - baseOffsetX); int webcamObsY = DpiUtil.ConvertSizeWpfToPhysicalPixel(webcamWindowSize.Top + webcamWindowSize.BorderWidth.Value - baseOffsetY); int webcamObsWidth = DpiUtil.ConvertSizeWpfToPhysicalPixel(webcamItemWidth); int webcamObsHeight = DpiUtil.ConvertSizeWpfToPhysicalPixel(webcamItemHeight); Store.Data.Webcam.Item.Position = new Vector2((float)webcamObsX, (float)webcamObsY); Store.Data.Webcam.Item.SetBounds(new Vector2(webcamObsWidth, webcamObsHeight), ObsBoundsType.ScaleOuter, ObsAlignment.Center); double webcamAspectRatio = Convert.ToDouble(Store.Data.Webcam.Source.Width) / Convert.ToDouble(Store.Data.Webcam.Source.Height); double webcamItemAspectRatio = Convert.ToDouble(webcamItemWidth) / Convert.ToDouble(webcamItemHeight); double webcamWidthD = Convert.ToDouble(Store.Data.Webcam.Source.Width); double webcamHeightD = Convert.ToDouble(Store.Data.Webcam.Source.Height); int cropWidth = webcamItemAspectRatio < webcamAspectRatio?Convert.ToInt32((webcamWidthD - (webcamHeightD * webcamItemAspectRatio)) / 2) : 0; int cropHeight = webcamItemAspectRatio < webcamAspectRatio ? 0 : Convert.ToInt32((webcamHeightD - (webcamWidthD / webcamItemAspectRatio)) / 2); libobs.obs_sceneitem_crop webcamCrop = new libobs.obs_sceneitem_crop { left = webcamItemAspectRatio < webcamAspectRatio ? cropWidth : 0, top = webcamItemAspectRatio < webcamAspectRatio ? 0 : cropHeight, right = webcamItemAspectRatio < webcamAspectRatio ? cropWidth : 0, bottom = webcamItemAspectRatio < webcamAspectRatio ? 0 : cropHeight }; Store.Data.Webcam.Item.SetCrop(webcamCrop); }
public override void Execute() { if (!Store.Data.Obs.IsObsStarted) { if (!Obs.Startup("en-US")) { // todo: if any exceptions are thrown in this app, we need to bubble it all up to a single terminate code so consuming apps know that it shut down throw new ApplicationException("Startup failed."); } Loggers.OBSLogger.Trace("libobs version: " + Obs.GetVersion()); // forward OBS logging messages to debugger Obs.SetLogHandler((lvl, msg, p) => { Debug.WriteLine(msg); Loggers.OBSLogger.Trace(msg); }); AudioService.ResetAudioInfo(); } VideoService.ResetVideoInfo(new ResetVideoInfoParameters { CropTop = CropTop, CropRight = CropRight, CropLeft = CropLeft, CropBottom = CropBottom, FrameRate = FrameRate, OutputWidth = OutputWidth, OutputHeight = OutputHeight, CanvasWidth = CanvasWidth, CanvasHeight = CanvasHeight, ScreenX = ScreenX, ScreenY = ScreenY }); if (!Store.Data.Obs.IsObsStarted) { Obs.LoadAllModules(); Store.Data.Obs.Presentation = new Presentation(); Store.Data.Obs.Presentation.AddScene("Main"); Store.Data.Obs.Presentation.AddScene("Webcam"); Store.Data.Obs.Presentation.SetScene(Store.Data.Obs.MainScene); Store.Data.Display.DisplaySource = Store.Data.Obs.Presentation.CreateSource("monitor_capture", "Monitor Capture Source"); Store.Data.Obs.Presentation.AddSource(Store.Data.Display.DisplaySource); Store.Data.Display.DisplayItem = Store.Data.Obs.Presentation.CreateItem(Store.Data.Display.DisplaySource); Store.Data.Display.DisplayItem.Name = "Monitor Capture SceneItem"; Rectangle activeScreenBounds = ScreenHelper.GetScreen(ScreenX, ScreenY).Bounds; Store.Data.Display.DisplayItem.SetBounds(new Vector2(activeScreenBounds.Width, activeScreenBounds.Height), ObsBoundsType.None, ObsAlignment.Top); // this should always be the screen's resolution Store.Data.Obs.MainScene.Items.Add(Store.Data.Display.DisplayItem); Thread webcamWindowThread = new Thread(() => { Store.Data.Webcam.Window = new WebcamWindow(); Store.Data.App.ApplicationInstance = new Application(); Store.Data.App.ApplicationInstance.Run(Store.Data.Webcam.Window); }); webcamWindowThread.Name = Constants.Webcam.Settings.WebcamWindowThreadName; webcamWindowThread.SetApartmentState(ApartmentState.STA); webcamWindowThread.Start(); var usedAudioInputId = AudioService.SetAudioInput(this.SavedAudioInputId); var usedAudioOutputId = AudioService.SetAudioOutput(this.SavedAudioOutputId); Store.Data.Obs.Presentation.SetItem(0); Store.Data.Obs.Presentation.SetSource(0); // wait until the window is initialized before emitting a response while (Store.Data.Webcam.Window == null) { Thread.Sleep(100); } EmitService.EmitInitializeResponse(new InitializeResponse { IsSuccessful = true, SetAudioInputDevice = usedAudioInputId, SetAudioOutputDevice = usedAudioOutputId }); } MagnitudeService.Setup(); Store.Data.Obs.IsObsStarted = true; }
/// <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); }