Commit 57ac8cc5 authored by Elia Devito's avatar Elia Devito
Browse files

code improvement

parent cd88623d
......@@ -29,6 +29,18 @@ QString structureValue(GstStructure* device, const char* key)
return QString::fromUtf8(g_value_get_string(x));
}
QString udiFromProperties(GstStructure* deviceProperties)
{
QString udi;
gboolean udev_probed;
if (gst_structure_get_boolean(deviceProperties, "udev-probed", &udev_probed) && !udev_probed)
udi = structureValue(deviceProperties, "device.path");
else
udi = structureValue(deviceProperties, "sysfs.path");
return udi;
}
// for reference, the properties can be listed with:
// gst-device-monitor-1.0 Video/Source
Device::Device(GstDevice *device, QObject* parent)
......@@ -37,13 +49,7 @@ Device::Device(GstDevice *device, QObject* parent)
, m_device(device)
{
auto st = gst_device_get_properties(device);
gboolean udev_probed;
if (gst_structure_get_boolean(st, "udev-probed", &udev_probed) && !udev_probed)
m_udi = structureValue(st, "device.path");
else
m_udi = structureValue(st, "sysfs.path");
m_udi = udiFromProperties(st);
m_path = structureValue(st, "device.path");
gst_structure_free(st);
}
......
......@@ -26,6 +26,7 @@
#include <KSharedConfig>
QString structureValue(GstStructure* device, const char* key);
QString udiFromProperties(GstStructure* deviceProperties);
class Device : public QObject
{
......
......@@ -191,9 +191,8 @@ void DeviceManager::deviceAdded(GstDevice* device)
void DeviceManager::deviceRemoved(GstDevice* device)
{
auto removedDevice = new Device(device, this);
auto udi = removedDevice->udi();
delete removedDevice;
auto st = gst_device_get_properties(device);
auto udi = udiFromProperties(st);
for(int i = 0, c = m_deviceList.size(); i<c; ++i) {
auto dev = m_deviceList.at(i);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment