From c9cf6baf4b99d749e770f353ec4c2b33de13db4f Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Sun, 26 Mar 2023 17:36:18 +0200 Subject: [PATCH] Improved Device support for V4L2 streams Allow to reload list of devices, avoid timestamp warning in Loopback, clear UI menu. --- src/DeviceSource.cpp | 12 +++++++++++- src/DeviceSource.h | 15 +-------------- src/Loopback.cpp | 2 +- src/UserInterfaceManager.cpp | 7 +++++++ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/DeviceSource.cpp b/src/DeviceSource.cpp index 8261aca..f2a1715 100644 --- a/src/DeviceSource.cpp +++ b/src/DeviceSource.cpp @@ -203,7 +203,7 @@ void Device::remove(GstDevice *device) g_free (device_name); } -Device::Device(): monitor_initialized_(false), monitor_unplug_event_(false) +Device::Device(): monitor_(nullptr), monitor_initialized_(false), monitor_unplug_event_(false) { std::thread(launchMonitoring, this).detach(); } @@ -212,6 +212,7 @@ void Device::launchMonitoring(Device *d) { // gstreamer monitoring of devices d->monitor_ = gst_device_monitor_new (); + gst_device_monitor_set_show_all_devices(d->monitor_, true); // watching all video stream sources GstCaps *caps = gst_caps_new_empty_simple ("video/x-raw"); @@ -280,6 +281,15 @@ bool Device::initialized() return Device::manager().monitor_initialized_; } +void Device::reload() +{ + if (monitor_ != nullptr) { + gst_device_monitor_stop(monitor_); + if ( !gst_device_monitor_start (monitor_) ) + Log::Info("Device discovery start failed."); + } +} + int Device::numDevices() { access_.lock(); diff --git a/src/DeviceSource.h b/src/DeviceSource.h index ff70148..b21a495 100644 --- a/src/DeviceSource.h +++ b/src/DeviceSource.h @@ -5,7 +5,6 @@ #include #include -#include "GstToolkit.h" #include "StreamSource.h" class DeviceSource : public StreamSource @@ -53,19 +52,6 @@ struct DeviceConfig { format = ""; } - inline DeviceConfig& operator = (const DeviceConfig& b) - { - if (this != &b) { - this->width = b.width; - this->height = b.height; - this->fps_numerator = b.fps_numerator; - this->fps_denominator = b.fps_denominator; - this->stream = b.stream; - this->format = b.format; - } - return *this; - } - inline bool operator < (const DeviceConfig b) const { int formatscore = this->format.find("R") != std::string::npos ? 2 : 1; // best score for RGBx @@ -124,6 +110,7 @@ public: int index (const std::string &device); bool exists (const std::string &device) ; + void reload (); static gboolean callback_device_monitor (GstBus *, GstMessage *, gpointer); static DeviceConfigSet getDeviceConfigs(const std::string &src_description); diff --git a/src/Loopback.cpp b/src/Loopback.cpp index 2744420..72b5e6d 100644 --- a/src/Loopback.cpp +++ b/src/Loopback.cpp @@ -86,7 +86,7 @@ std::string Loopback::init(GstCaps *caps) return std::string("Loopback : Invalid caps"); // create a gstreamer pipeline - std::string description = "appsrc name=src ! videoconvert ! "; + std::string description = "appsrc name=src ! videoconvert ! queue ! "; // complement pipeline with sink description += Loopback::loopback_sink_ + " name=sink"; diff --git a/src/UserInterfaceManager.cpp b/src/UserInterfaceManager.cpp index 8526b41..2da4421 100644 --- a/src/UserInterfaceManager.cpp +++ b/src/UserInterfaceManager.cpp @@ -4377,6 +4377,10 @@ void OutputPreview::Render() ImGui::SetCursorPos(draw_pos); } } + else { + ImGui::Separator(); + ImGui::MenuItem("No active streams", nullptr, false, false); + } ImGui::EndMenu(); } @@ -7484,6 +7488,9 @@ void Navigator::RenderNewPannel() // Indication ImGui::SameLine(); ImVec2 pos = ImGui::GetCursorPos(); + if (ImGuiToolkit::IconButton(5,15,"Reload list")) + Device::manager().reload(); + ImGui::SameLine(); ImGuiToolkit::HelpToolTip("Create a source capturing video streams from connected devices or machines;\n" ICON_FA_CARET_RIGHT " webcams or frame grabbers\n" ICON_FA_CARET_RIGHT " screen capture\n"