mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 10:19:59 +01:00
Improved detection of unplugged device
This commit is contained in:
@@ -23,7 +23,6 @@ Device::callback_device_monitor (GstBus * bus, GstMessage * message, gpointer us
|
||||
{
|
||||
GstDevice *device;
|
||||
gchar *name;
|
||||
gchar *stru;
|
||||
|
||||
switch (GST_MESSAGE_TYPE (message)) {
|
||||
case GST_MESSAGE_DEVICE_ADDED: {
|
||||
@@ -41,6 +40,9 @@ Device::callback_device_monitor (GstBus * bus, GstMessage * message, gpointer us
|
||||
DeviceConfigSet confs = getDeviceConfigs(pipe.str());
|
||||
manager().src_config_.push_back(confs);
|
||||
|
||||
manager().list_uptodate_ = false;
|
||||
|
||||
// gchar *stru;
|
||||
// stru = gst_structure_to_string( gst_device_get_properties(device) );
|
||||
// g_print("New device %s \n", stru);
|
||||
|
||||
@@ -54,6 +56,8 @@ Device::callback_device_monitor (GstBus * bus, GstMessage * message, gpointer us
|
||||
// g_print("Device removed: %s\n", name);
|
||||
g_free (name);
|
||||
|
||||
manager().list_uptodate_ = false;
|
||||
|
||||
gst_object_unref (device);
|
||||
}
|
||||
break;
|
||||
@@ -126,7 +130,7 @@ Device::Device()
|
||||
src_config_.push_back(confs);
|
||||
}
|
||||
g_list_free(devices);
|
||||
|
||||
list_uptodate_ = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -141,6 +145,13 @@ bool Device::exists(const std::string &device) const
|
||||
return d != src_name_.end();
|
||||
}
|
||||
|
||||
bool Device::unplugged(const std::string &device) const
|
||||
{
|
||||
if (list_uptodate_)
|
||||
return false;
|
||||
return !exists(device);
|
||||
}
|
||||
|
||||
std::string Device::name(int index) const
|
||||
{
|
||||
if (index > -1 && index < src_name_.size())
|
||||
@@ -240,7 +251,7 @@ void DeviceSource::accept(Visitor& v)
|
||||
|
||||
bool DeviceSource::failed() const
|
||||
{
|
||||
return stream_->failed() || !Device::manager().exists(device_);
|
||||
return stream_->failed() || Device::manager().unplugged(device_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ public:
|
||||
DeviceConfigSet config (int index) const;
|
||||
|
||||
bool exists (const std::string &device) const;
|
||||
bool unplugged (const std::string &device) const;
|
||||
int index (const std::string &device) const;
|
||||
|
||||
static gboolean callback_device_monitor (GstBus *, GstMessage *, gpointer);
|
||||
@@ -85,6 +86,7 @@ private:
|
||||
std::vector< DeviceConfigSet > src_config_;
|
||||
static DeviceConfigSet getDeviceConfigs(const std::string &src_description);
|
||||
|
||||
bool list_uptodate_;
|
||||
GstDeviceMonitor *monitor_;
|
||||
};
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
|
||||
static const char* aspect_ratio_names[6] = { "1:1", "4:3", "3:2", "16:10", "16:9", "21:9" };
|
||||
static const char* height_names[9] = { "16", "64", "200", "320", "480", "720p", "1080p", "1440", "4K" };
|
||||
static const char* height_names[10] = { "16", "64", "200", "320", "480", "576", "720p", "1080p", "1440", "4K" };
|
||||
|
||||
glm::ivec2 resolutionFromDescription(int aspectratio, int height);
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ Stream::Stream()
|
||||
description_ = "undefined";
|
||||
pipeline_ = nullptr;
|
||||
|
||||
width_ = 800;
|
||||
height_ = 600;
|
||||
width_ = -1;
|
||||
height_ = -1;
|
||||
single_frame_ = false;
|
||||
live_ = false;
|
||||
ready_ = false;
|
||||
@@ -76,9 +76,8 @@ void Stream::open(const std::string &gstreamer_description, int w, int h)
|
||||
{
|
||||
// set gstreamer pipeline source
|
||||
description_ = gstreamer_description;
|
||||
|
||||
if (w>0) width_ = w;
|
||||
if (h>0) height_ = h;
|
||||
width_ = w;
|
||||
height_ = h;
|
||||
|
||||
// close before re-openning
|
||||
if (isOpen())
|
||||
|
||||
Reference in New Issue
Block a user