From 82848d513e8ef8d51dbbc34d51e84bbe1d6331da Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 5 Oct 2018 19:36:51 -0700 Subject: [PATCH] libobs: Add obs_video_active() function (This commit also modifies UI) Adds a universal function for determining whether video output is currently active, rather than having to use video_output_active() on the value returned by obs_get_video(). --- UI/win-update/win-update.cpp | 2 +- UI/window-basic-settings.cpp | 6 +++--- libobs/obs.c | 11 ++++++++++- libobs/obs.h | 3 +++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/UI/win-update/win-update.cpp b/UI/win-update/win-update.cpp index 846364b18..34d2157b0 100644 --- a/UI/win-update/win-update.cpp +++ b/UI/win-update/win-update.cpp @@ -586,7 +586,7 @@ try { auto ActiveOrGameCaptureLocked = [this] () { - if (video_output_active(obs_get_video())) { + if (obs_video_active()) { if (manualUpdate) info(QTStr("Updater.Running.Title"), QTStr("Updater.Running.Text")); diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp index 5fe7b9189..27c9ab737 100644 --- a/UI/window-basic-settings.cpp +++ b/UI/window-basic-settings.cpp @@ -1373,7 +1373,7 @@ void OBSBasicSettings::LoadVideoSettings() { loading = true; - if (video_output_active(obs_get_video())) { + if (obs_video_active()) { ui->videoPage->setEnabled(false); ui->videoMsg->setText( QTStr("Basic.Settings.Video.CurrentlyActive")); @@ -1850,7 +1850,7 @@ void OBSBasicSettings::LoadOutputSettings() LoadAdvOutputFFmpegSettings(); LoadAdvOutputAudioSettings(); - if (video_output_active(obs_get_video())) { + if (obs_video_active()) { ui->outputMode->setEnabled(false); ui->outputModeLabel->setEnabled(false); ui->simpleRecordingGroupBox->setEnabled(false); @@ -2228,7 +2228,7 @@ void OBSBasicSettings::LoadAdvancedSettings() if (!SetComboByValue(ui->bindToIP, bindIP)) SetInvalidValue(ui->bindToIP, bindIP, bindIP); - if (video_output_active(obs_get_video())) { + if (obs_video_active()) { ui->advancedVideoContainer->setEnabled(false); } diff --git a/libobs/obs.c b/libobs/obs.c index 1e71a7da9..10016e7f1 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -1014,7 +1014,7 @@ int obs_reset_video(struct obs_video_info *ovi) if (!obs) return OBS_VIDEO_FAIL; /* don't allow changing of video settings if active. */ - if (obs->video.video && video_output_active(obs->video.video)) + if (obs->video.video && obs_video_active()) return OBS_VIDEO_CURRENTLY_ACTIVE; if (!size_valid(ovi->output_width, ovi->output_height) || @@ -2258,3 +2258,12 @@ obs_data_t *obs_get_private_data(void) obs_data_addref(private_data); return private_data; } + +bool obs_video_active(void) +{ + struct obs_core_video *video = &obs->video; + if (!obs) + return false; + + return os_atomic_load_long(&video->raw_active) > 0; +} diff --git a/libobs/obs.h b/libobs/obs.h index 58e6e5cfe..0bfe28e68 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -535,6 +535,9 @@ EXPORT audio_t *obs_get_audio(void); /** Gets the main video output handler for this OBS context */ EXPORT video_t *obs_get_video(void); +/** Returns true if video is active, false otherwise */ +EXPORT bool obs_video_active(void); + /** Sets the primary output source for a channel. */ EXPORT void obs_set_output_source(uint32_t channel, obs_source_t *source); -- GitLab