Skip to content

Commit bc36684

Browse files
Update import wizard to create/destroy video capture source.
1 parent bd6a152 commit bc36684

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

src/elgato-cloud-config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ DefaultAVWidget::~DefaultAVWidget()
241241
}
242242
if (_videoCaptureSource) {
243243
obs_source_release(_videoCaptureSource);
244-
obs_source_remove(_videoCaptureSource);
244+
//obs_source_remove(_videoCaptureSource);
245245
}
246246
_levelsWidget = nullptr;
247247
}

src/elgato-widgets.cpp

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ VideoCaptureSourceSelector::VideoCaptureSourceSelector(QWidget *parent,
3939
obs_data_t *videoData)
4040
: QWidget(parent),
4141
_sourceName(sourceName),
42-
_noneSelected(true)
42+
_noneSelected(true),
43+
_deactivated(false)
4344
{
4445
std::string imageBaseDir =
4546
obs_get_module_data_path(obs_current_module());
4647
imageBaseDir += "/images/";
4748

4849
setFixedWidth(258);
50+
_loading = true;
4951

5052
auto layout = new QVBoxLayout(this);
5153
layout->setContentsMargins(0, 0, 0, 16);
@@ -90,22 +92,17 @@ VideoCaptureSourceSelector::VideoCaptureSourceSelector(QWidget *parent,
9092

9193
connect(_videoSources, &QComboBox::currentIndexChanged, this,
9294
[this](int index) {
95+
_loading = true;
9396
if (index > 0) {
9497
auto vSettings = obs_data_create();
9598
std::string id = _videoSourceIds[index];
9699
obs_data_set_string(vSettings,
97-
"video_device_id",
98-
id.c_str());
99-
obs_source_reset_settings(_videoCaptureSource,
100-
vSettings);
100+
"video_device_id",
101+
id.c_str());
102+
_changeSource(vSettings);
101103
obs_data_release(vSettings);
102-
this->_noneSelected = false;
103-
this->_videoPreview->show();
104-
this->_blank->hide();
105104
} else {
106-
this->_noneSelected = true;
107-
this->_videoPreview->hide();
108-
this->_blank->show();
105+
_changeSource(nullptr);
109106
}
110107
});
111108
}
@@ -163,11 +160,44 @@ void VideoCaptureSourceSelector::_setupTempSource(obs_data_t *videoData)
163160
//obs_data_release(videoSettings);
164161
}
165162

163+
void VideoCaptureSourceSelector::_changeSource(obs_data_t *vSettings)
164+
{
165+
if (vSettings != nullptr) {
166+
blog(LOG_INFO, "_changeSource called.");
167+
if (_videoCaptureSource) {
168+
obs_source_t* tmp = _videoCaptureSource;
169+
_videoCaptureSource = nullptr;
170+
obs_source_release(tmp);
171+
}
172+
173+
const char* videoSourceId = "dshow_input";
174+
const char* vId = obs_get_latest_input_type_id(videoSourceId);
175+
_videoCaptureSource = obs_source_create_private(
176+
vId, "elgato-cloud-video-config", vSettings);
177+
178+
this->_noneSelected = false;
179+
this->_videoPreview->show();
180+
this->_blank->hide();
181+
} else {
182+
this->_noneSelected = true;
183+
this->_videoPreview->hide();
184+
this->_blank->show();
185+
if (_videoCaptureSource) {
186+
obs_source_t* tmp = _videoCaptureSource;
187+
_videoCaptureSource = nullptr;
188+
obs_source_release(tmp);
189+
}
190+
}
191+
192+
}
193+
166194
void VideoCaptureSourceSelector::DrawVideoPreview(void *data, uint32_t cx,
167195
uint32_t cy)
168196
{
169197
auto config = static_cast<VideoCaptureSourceSelector *>(data);
170-
198+
if (config->_loading) {
199+
config->_loading = false;
200+
}
171201
if (!config->_videoCaptureSource)
172202
return;
173203

src/elgato-widgets.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ class VideoCaptureSourceSelector : public QWidget {
5252
std::vector<std::string> _videoSourceIds;
5353
std::string _sourceName;
5454
void _setupTempSource(obs_data_t *videoData);
55+
void _changeSource(obs_data_t* vSettings);
5556
bool _noneSelected;
57+
bool _loading;
58+
bool _deactivated;
5659
};
5760

5861
class ProgressSpinner : public QWidget {

src/setup-wizard.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ void StreamPackageSetupWizard::_buildSetupUI(
902902
connect(aSetup, &AudioSetup::proceedPressed, this,
903903
[this](std::string settings) {
904904
_setup.audioSettings = settings;
905+
// Nuke the video preview window
905906
install();
906907
});
907908
connect(aSetup, &AudioSetup::backPressed, this,

0 commit comments

Comments
 (0)