2013-11-07 16:45:03 -07:00
|
|
|
/******************************************************************************
|
2023-05-18 17:37:26 -07:00
|
|
|
Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>
|
|
|
|
|
Zachary Lund <admin@computerquip.com>
|
|
|
|
|
Philippe Groarke <philippe.groarke@gmail.com>
|
2013-11-07 16:45:03 -07:00
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2013-12-02 22:24:38 -07:00
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
2013-11-07 16:45:03 -07:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
2013-11-09 00:19:38 -07:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2013-11-07 16:45:03 -07:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
#include "OBSBasic.hpp"
|
2013-12-29 09:17:00 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
#include <components/UIValidation.hpp>
|
|
|
|
|
#include <dialogs/OBSBasicVCamConfig.hpp>
|
2014-03-06 21:08:12 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
#define VIRTUAL_CAM_START "==== Virtual Camera Start =========================================="
|
|
|
|
|
#define VIRTUAL_CAM_STOP "==== Virtual Camera Stop ==========================================="
|
2022-10-22 11:51:30 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::StartVirtualCam()
|
2022-10-22 11:51:30 +02:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler || !outputHandler->virtualCam)
|
|
|
|
|
return;
|
|
|
|
|
if (outputHandler->VirtualCamActive())
|
|
|
|
|
return;
|
|
|
|
|
if (disableOutputsRef)
|
2022-10-22 11:51:30 +02:00
|
|
|
return;
|
2021-11-03 21:11:06 +01:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
SaveProject();
|
2019-04-07 03:34:21 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
outputHandler->StartVirtualCam();
|
2019-04-07 03:34:21 -04:00
|
|
|
}
|
2019-04-23 15:56:30 +08:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::StopVirtualCam()
|
2019-04-23 15:56:30 +08:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler || !outputHandler->virtualCam)
|
|
|
|
|
return;
|
2019-04-23 15:56:30 +08:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
SaveProject();
|
2019-05-05 20:00:06 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (outputHandler->VirtualCamActive())
|
|
|
|
|
outputHandler->StopVirtualCam();
|
2019-05-05 20:00:06 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OnDeactivate();
|
2019-05-05 20:00:06 -07:00
|
|
|
}
|
2019-07-07 15:47:29 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::OnVirtualCamStart()
|
2019-07-07 15:47:29 -07:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler || !outputHandler->virtualCam)
|
2019-07-07 15:47:29 -07:00
|
|
|
return;
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
emit VirtualCamStarted();
|
2019-10-02 19:44:47 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (sysTrayVirtualCam)
|
|
|
|
|
sysTrayVirtualCam->setText(QTStr("Basic.Main.StopVirtualCam"));
|
2020-04-14 20:16:33 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OnEvent(OBS_FRONTEND_EVENT_VIRTUALCAM_STARTED);
|
2019-10-02 19:44:47 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OnActivate();
|
2019-07-07 15:47:29 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
blog(LOG_INFO, VIRTUAL_CAM_START);
|
2019-07-07 15:47:29 -07:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::OnVirtualCamStop(int)
|
2019-07-07 15:47:29 -07:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler || !outputHandler->virtualCam)
|
2019-07-07 15:47:29 -07:00
|
|
|
return;
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
emit VirtualCamStopped();
|
2024-02-29 20:46:07 +00:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (sysTrayVirtualCam)
|
|
|
|
|
sysTrayVirtualCam->setText(QTStr("Basic.Main.StartVirtualCam"));
|
2019-10-02 19:44:47 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OnEvent(OBS_FRONTEND_EVENT_VIRTUALCAM_STOPPED);
|
2020-04-14 20:16:33 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
blog(LOG_INFO, VIRTUAL_CAM_STOP);
|
2019-10-02 19:44:47 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OnDeactivate();
|
2019-07-07 15:47:29 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!restartingVCam)
|
2019-07-07 15:47:29 -07:00
|
|
|
return;
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
/* Restarting needs to be delayed to make sure that the virtual camera
|
|
|
|
|
* implementation is stopped and avoid race condition. */
|
|
|
|
|
QTimer::singleShot(100, this, &OBSBasic::RestartingVirtualCam);
|
2024-04-03 17:08:14 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::VirtualCamActionTriggered()
|
2019-09-27 15:04:07 +02:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (outputHandler->VirtualCamActive()) {
|
|
|
|
|
StopVirtualCam();
|
2019-09-27 15:04:07 +02:00
|
|
|
} else {
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!UIValidation::NoSourcesConfirmation(this))
|
|
|
|
|
return;
|
2019-12-27 17:12:31 +08:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
StartVirtualCam();
|
2020-09-08 20:29:40 -07:00
|
|
|
}
|
2019-06-12 04:56:00 -05:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::OpenVirtualCamConfig()
|
2019-06-12 04:56:00 -05:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
OBSBasicVCamConfig dialog(vcamConfig, outputHandler->VirtualCamActive(), this);
|
2019-10-10 20:12:20 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
connect(&dialog, &OBSBasicVCamConfig::Accepted, this, &OBSBasic::UpdateVirtualCamConfig);
|
|
|
|
|
connect(&dialog, &OBSBasicVCamConfig::AcceptedAndRestart, this, &OBSBasic::RestartVirtualCam);
|
2019-10-15 23:20:35 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
dialog.exec();
|
2019-10-15 23:20:35 -05:00
|
|
|
}
|
2020-02-14 23:30:34 +11:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void log_vcam_changed(const VCamConfig &config, bool starting)
|
2020-02-14 23:30:34 +11:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
const char *action = starting ? "Starting" : "Changing";
|
2022-02-22 00:40:17 +11:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
switch (config.type) {
|
|
|
|
|
case VCamOutputType::Invalid:
|
|
|
|
|
break;
|
|
|
|
|
case VCamOutputType::ProgramView:
|
|
|
|
|
blog(LOG_INFO, "%s Virtual Camera output to Program", action);
|
|
|
|
|
break;
|
|
|
|
|
case VCamOutputType::PreviewOutput:
|
|
|
|
|
blog(LOG_INFO, "%s Virtual Camera output to Preview", action);
|
|
|
|
|
break;
|
|
|
|
|
case VCamOutputType::SceneOutput:
|
|
|
|
|
blog(LOG_INFO, "%s Virtual Camera output to Scene : %s", action, config.scene.c_str());
|
|
|
|
|
break;
|
|
|
|
|
case VCamOutputType::SourceOutput:
|
|
|
|
|
blog(LOG_INFO, "%s Virtual Camera output to Source : %s", action, config.source.c_str());
|
|
|
|
|
break;
|
2022-02-22 00:40:17 +11:00
|
|
|
}
|
2020-02-14 23:30:34 +11:00
|
|
|
}
|
2020-06-13 21:00:55 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::UpdateVirtualCamConfig(const VCamConfig &config)
|
2021-01-11 23:26:02 -06:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
vcamConfig = config;
|
2021-02-04 06:01:35 -06:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
outputHandler->UpdateVirtualCamOutputSource();
|
|
|
|
|
log_vcam_changed(config, false);
|
2021-02-04 06:01:35 -06:00
|
|
|
}
|
2021-08-19 23:56:49 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::RestartVirtualCam(const VCamConfig &config)
|
2021-08-19 23:56:49 -05:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
restartingVCam = true;
|
2020-06-27 02:31:08 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
StopVirtualCam();
|
2023-02-10 13:27:08 +01:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
vcamConfig = config;
|
2023-02-10 13:27:08 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::RestartingVirtualCam()
|
2020-06-27 02:31:08 +02:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!restartingVCam)
|
2020-06-27 02:31:08 +02:00
|
|
|
return;
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
outputHandler->UpdateVirtualCamOutputSource();
|
|
|
|
|
StartVirtualCam();
|
|
|
|
|
restartingVCam = false;
|
2024-07-31 10:53:59 -04:00
|
|
|
}
|
2024-09-03 16:29:30 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
bool OBSBasic::VirtualCamActive()
|
2024-09-03 16:29:30 +02:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler)
|
|
|
|
|
return false;
|
|
|
|
|
return outputHandler->VirtualCamActive();
|
2024-09-03 16:29:30 +02:00
|
|
|
}
|