コード例 #1
0
ファイル: Program.cs プロジェクト: zerratar/libobs-sharp
        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);
            }
        }
コード例 #2
0
        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;
        }