Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Kamoso
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Multimedia
Kamoso
Commits
677be503
Commit
677be503
authored
Apr 29, 2020
by
Aleix Pol Gonzalez
🐧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve how we list devices
parent
2e7b5cc4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
20 deletions
+37
-20
src/device.cpp
src/device.cpp
+17
-5
src/device.h
src/device.h
+8
-4
src/devicemanager.cpp
src/devicemanager.cpp
+12
-11
No files found.
src/device.cpp
View file @
677be503
...
...
@@ -31,13 +31,15 @@ QString structureValue(GstStructure* device, const char* key)
// for reference, the properties can be listed with:
// gst-device-monitor-1.0 Video/Source
Device
::
Device
(
Gst
Structur
e
*
device
,
QObject
*
parent
)
Device
::
Device
(
Gst
Devic
e
*
device
,
QObject
*
parent
)
:
QObject
(
parent
)
,
m_description
(
structureValue
(
device
,
"device.product.name"
))
,
m_udi
(
structureValue
(
device
,
"sysfs.path"
))
,
m_path
(
structureValue
(
device
,
"device.path"
))
,
m_description
(
gst_device_get_display_name
(
device
))
,
m_device
(
device
)
{
qDebug
()
<<
"new device"
<<
m_description
<<
m_udi
<<
m_path
;
auto
st
=
gst_device_get_properties
(
device
);
m_udi
=
structureValue
(
st
,
"sysfs.path"
);
m_path
=
structureValue
(
st
,
"device.path"
);
gst_structure_free
(
st
);
}
Device
::~
Device
()
...
...
@@ -50,6 +52,11 @@ void Device::reset()
Q_EMIT
filtersChanged
(
m_filters
);
}
bool
Device
::
isValid
()
const
{
return
!
m_udi
.
isEmpty
()
&&
!
m_path
.
isEmpty
();
}
void
Device
::
setFilters
(
const
QString
&
newFilters
)
{
if
(
newFilters
==
m_filters
)
{
...
...
@@ -59,3 +66,8 @@ void Device::setFilters(const QString &newFilters)
m_filters
=
newFilters
;
Q_EMIT
filtersChanged
(
newFilters
);
}
GstElement
*
Device
::
createElement
()
{
return
gst_device_create_element
(
m_device
,
m_description
.
toUtf8
().
constData
());
}
src/device.h
View file @
677be503
...
...
@@ -21,7 +21,7 @@
#define DEVICE_H
#include <QObject>
#include <gst/gst
structur
e.h>
#include <gst/gst
devic
e.h>
#include <KSharedConfig>
...
...
@@ -33,7 +33,7 @@ class Device : public QObject
Q_PROPERTY
(
QString
filters
READ
filters
WRITE
setFilters
NOTIFY
filtersChanged
)
public:
Device
(
Gst
Structure
*
structur
e
,
QObject
*
parent
);
Device
(
Gst
Device
*
devic
e
,
QObject
*
parent
);
~
Device
();
QString
description
()
const
{
return
m_description
;
}
QString
udi
()
const
{
return
m_udi
;
}
...
...
@@ -41,6 +41,9 @@ class Device : public QObject
void
setFilters
(
const
QString
&
filters
);
QString
filters
()
const
{
return
m_filters
;
}
GstElement
*
createElement
();
bool
isValid
()
const
;
void
reset
();
Q_SIGNALS:
...
...
@@ -48,8 +51,9 @@ class Device : public QObject
private:
const
QString
m_description
;
const
QString
m_udi
;
const
QString
m_path
;
GstDevice
*
const
m_device
;
QString
m_udi
;
QString
m_path
;
QString
m_filters
;
};
...
...
src/devicemanager.cpp
View file @
677be503
...
...
@@ -58,7 +58,7 @@ DeviceManager::DeviceManager() : m_playingDevice(0)
gst_bus_add_watch
(
bus
,
deviceMonitorWatch
,
m_monitor
);
gst_object_unref
(
bus
);
GstCaps
*
caps
=
gst_caps_new_empty_simple
(
"
image/jpeg
"
);
GstCaps
*
caps
=
gst_caps_new_empty_simple
(
"
video/x-raw
"
);
gst_device_monitor_add_filter
(
m_monitor
,
"Video/Source"
,
caps
);
gst_caps_unref
(
caps
);
...
...
@@ -71,15 +71,19 @@ DeviceManager::DeviceManager() : m_playingDevice(0)
}
/* Initialize camera structures */
while
(
devices
)
{
deviceAdded
(
GST_DEVICE
(
devices
->
data
));
devices
=
devices
->
next
;
for
(;
devices
;
devices
=
devices
->
next
)
{
auto
device
=
new
Device
(
GST_DEVICE
(
devices
->
data
),
this
);
if
(
!
device
->
isValid
())
{
delete
device
;
continue
;
}
m_deviceList
.
append
(
device
);
}
g_list_free
(
devices
);
if
(
!
m_deviceList
.
isEmpty
())
{
setPlayingDeviceUdi
(
m_deviceList
.
f
irst
()
->
udi
());
setPlayingDeviceUdi
(
m_deviceList
.
constF
irst
()
->
udi
());
}
}
...
...
@@ -126,7 +130,8 @@ void DeviceManager::setPlayingDeviceUdi(const QString& udi)
}
}
m_playingDevice
=
0
;
qWarning
()
<<
"could not find device"
<<
udi
;
m_playingDevice
=
nullptr
;
}
Device
*
DeviceManager
::
playingDevice
()
...
...
@@ -174,15 +179,11 @@ QVariant DeviceManager::data(const QModelIndex& index, int role) const
void
DeviceManager
::
deviceAdded
(
GstDevice
*
device
)
{
auto
st
=
gst_device_get_properties
(
device
);
const
int
s
=
m_deviceList
.
size
();
beginInsertRows
({},
s
,
s
);
m_deviceList
.
append
(
new
Device
(
st
,
this
));
m_deviceList
.
append
(
new
Device
(
device
,
this
));
endInsertRows
();
gst_structure_free
(
st
);
if
(
!
m_playingDevice
)
{
setPlayingDeviceUdi
(
m_deviceList
.
first
()
->
udi
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment