mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +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;
|
GstDevice *device;
|
||||||
gchar *name;
|
gchar *name;
|
||||||
gchar *stru;
|
|
||||||
|
|
||||||
switch (GST_MESSAGE_TYPE (message)) {
|
switch (GST_MESSAGE_TYPE (message)) {
|
||||||
case GST_MESSAGE_DEVICE_ADDED: {
|
case GST_MESSAGE_DEVICE_ADDED: {
|
||||||
@@ -41,6 +40,9 @@ Device::callback_device_monitor (GstBus * bus, GstMessage * message, gpointer us
|
|||||||
DeviceConfigSet confs = getDeviceConfigs(pipe.str());
|
DeviceConfigSet confs = getDeviceConfigs(pipe.str());
|
||||||
manager().src_config_.push_back(confs);
|
manager().src_config_.push_back(confs);
|
||||||
|
|
||||||
|
manager().list_uptodate_ = false;
|
||||||
|
|
||||||
|
// gchar *stru;
|
||||||
// stru = gst_structure_to_string( gst_device_get_properties(device) );
|
// stru = gst_structure_to_string( gst_device_get_properties(device) );
|
||||||
// g_print("New device %s \n", stru);
|
// 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_print("Device removed: %s\n", name);
|
||||||
g_free (name);
|
g_free (name);
|
||||||
|
|
||||||
|
manager().list_uptodate_ = false;
|
||||||
|
|
||||||
gst_object_unref (device);
|
gst_object_unref (device);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -126,7 +130,7 @@ Device::Device()
|
|||||||
src_config_.push_back(confs);
|
src_config_.push_back(confs);
|
||||||
}
|
}
|
||||||
g_list_free(devices);
|
g_list_free(devices);
|
||||||
|
list_uptodate_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -141,6 +145,13 @@ bool Device::exists(const std::string &device) const
|
|||||||
return d != src_name_.end();
|
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
|
std::string Device::name(int index) const
|
||||||
{
|
{
|
||||||
if (index > -1 && index < src_name_.size())
|
if (index > -1 && index < src_name_.size())
|
||||||
@@ -240,7 +251,7 @@ void DeviceSource::accept(Visitor& v)
|
|||||||
|
|
||||||
bool DeviceSource::failed() const
|
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;
|
DeviceConfigSet config (int index) const;
|
||||||
|
|
||||||
bool exists (const std::string &device) const;
|
bool exists (const std::string &device) const;
|
||||||
|
bool unplugged (const std::string &device) const;
|
||||||
int index (const std::string &device) const;
|
int index (const std::string &device) const;
|
||||||
|
|
||||||
static gboolean callback_device_monitor (GstBus *, GstMessage *, gpointer);
|
static gboolean callback_device_monitor (GstBus *, GstMessage *, gpointer);
|
||||||
@@ -85,6 +86,7 @@ private:
|
|||||||
std::vector< DeviceConfigSet > src_config_;
|
std::vector< DeviceConfigSet > src_config_;
|
||||||
static DeviceConfigSet getDeviceConfigs(const std::string &src_description);
|
static DeviceConfigSet getDeviceConfigs(const std::string &src_description);
|
||||||
|
|
||||||
|
bool list_uptodate_;
|
||||||
GstDeviceMonitor *monitor_;
|
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* 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);
|
glm::ivec2 resolutionFromDescription(int aspectratio, int height);
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ Stream::Stream()
|
|||||||
description_ = "undefined";
|
description_ = "undefined";
|
||||||
pipeline_ = nullptr;
|
pipeline_ = nullptr;
|
||||||
|
|
||||||
width_ = 800;
|
width_ = -1;
|
||||||
height_ = 600;
|
height_ = -1;
|
||||||
single_frame_ = false;
|
single_frame_ = false;
|
||||||
live_ = false;
|
live_ = false;
|
||||||
ready_ = false;
|
ready_ = false;
|
||||||
@@ -76,9 +76,8 @@ void Stream::open(const std::string &gstreamer_description, int w, int h)
|
|||||||
{
|
{
|
||||||
// set gstreamer pipeline source
|
// set gstreamer pipeline source
|
||||||
description_ = gstreamer_description;
|
description_ = gstreamer_description;
|
||||||
|
width_ = w;
|
||||||
if (w>0) width_ = w;
|
height_ = h;
|
||||||
if (h>0) height_ = h;
|
|
||||||
|
|
||||||
// close before re-openning
|
// close before re-openning
|
||||||
if (isOpen())
|
if (isOpen())
|
||||||
|
|||||||
2
Stream.h
2
Stream.h
@@ -29,7 +29,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Open a media using gstreamer pipeline keyword
|
* Open a media using gstreamer pipeline keyword
|
||||||
* */
|
* */
|
||||||
void open(const std::string &gstreamer_description, int w = -1, int h = -1);
|
void open(const std::string &gstreamer_description, int w = 1024, int h = 576);
|
||||||
/**
|
/**
|
||||||
* Get description string
|
* Get description string
|
||||||
* */
|
* */
|
||||||
|
|||||||
Reference in New Issue
Block a user