diff --git a/src/app/commoncomponents/LocalVideo.qml b/src/app/commoncomponents/LocalVideo.qml index 435ff99308cc8256e5b402972b3f55c843e8685b..178ccf7712edfcd6192da63c5e1502f1419c9c56 100644 --- a/src/app/commoncomponents/LocalVideo.qml +++ b/src/app/commoncomponents/LocalVideo.qml @@ -27,13 +27,13 @@ VideoView { crop: true - function startWithId(id) { + function startWithId(id, force = false) { if (id.length === 0) { VideoDevices.stopDevice(rendererId) rendererId = id } else { - if (rendererId !== id) - rendererId = VideoDevices.startDevice(id) + const forceRestart = rendererId === id + rendererId = VideoDevices.startDevice(id, forceRestart) } } } diff --git a/src/app/settingsview/components/VideoSettings.qml b/src/app/settingsview/components/VideoSettings.qml index fee9be76063261106119985a9d9df237abd6c1df..26aaa618970032a39eab9b45443c997e8c46a5b2 100644 --- a/src/app/settingsview/components/VideoSettings.qml +++ b/src/app/settingsview/components/VideoSettings.qml @@ -40,7 +40,7 @@ ColumnLayout { if (!visible) { return } - previewWidget.startWithId(VideoDevices.getDefaultDevice()) + previewWidget.startWithId(VideoDevices.getDefaultDevice(), force) } onVisibleChanged: { diff --git a/src/app/videodevices.cpp b/src/app/videodevices.cpp index f872cc87a7a2fdb4ae28c9a154fb0485507350d3..42b3d648cae9d60558b7fd79499048abdb33ee63 100644 --- a/src/app/videodevices.cpp +++ b/src/app/videodevices.cpp @@ -236,13 +236,19 @@ VideoDevices::getDefaultDevice() } QString -VideoDevices::startDevice(const QString& id) +VideoDevices::startDevice(const QString& id, bool force) { if (id.isEmpty()) return {}; auto& avModel = lrcInstance_->avModel(); if (avModel.hasRenderer(id)) { - return id; + // If the device is already started AND we're NOT trying to + // force a format change, we can do nothing and return the + // renderer id. + if (!force) { + return id; + } + avModel.stopPreview(id); } deviceOpen_ = true; return avModel.startPreview(id); diff --git a/src/app/videodevices.h b/src/app/videodevices.h index 0ab4d5afe1e6759acc8ccd9fbb67352c9a7c02f5..84cccfefd374788d3f3fc1d2dde13d6de52a6d21 100644 --- a/src/app/videodevices.h +++ b/src/app/videodevices.h @@ -135,7 +135,7 @@ public: Q_INVOKABLE void setDefaultDevice(int index); Q_INVOKABLE const QString getDefaultDevice(); - Q_INVOKABLE QString startDevice(const QString& deviceId); + Q_INVOKABLE QString startDevice(const QString& deviceId, bool force = false); Q_INVOKABLE void stopDevice(const QString& deviceId); Q_INVOKABLE void setDefaultDeviceRes(int index); Q_INVOKABLE void setDefaultDeviceFps(int index);