Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
afda24d6
Unverified
Commit
afda24d6
authored
4 years ago
by
Sébastien Blin
Browse files
Options
Downloads
Patches
Plain Diff
v4l2: use serial id
Change-Id: I7f4d6e5baef04b99a2cf1435aa6848aff7bd84df
parent
8cce5301
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/media/video/v4l2/video_device_monitor_impl.cpp
+30
-52
30 additions, 52 deletions
src/media/video/v4l2/video_device_monitor_impl.cpp
with
30 additions
and
52 deletions
src/media/video/v4l2/video_device_monitor_impl.cpp
+
30
−
52
View file @
afda24d6
...
@@ -82,33 +82,11 @@ private:
...
@@ -82,33 +82,11 @@ private:
};
};
std
::
string
std
::
string
getDeviceString
(
udev
*
udev
,
const
std
::
string
&
dev_path
)
getDeviceString
(
struct
udev_device
*
udev_device
)
{
{
std
::
string
unique_device_string
;
if
(
auto
serial
=
udev_device_get_property_value
(
udev_device
,
"ID_SERIAL"
))
struct
stat
statbuf
;
return
serial
;
if
(
stat
(
dev_path
.
c_str
(),
&
statbuf
)
<
0
)
{
throw
std
::
invalid_argument
(
"No ID_SERIAL detected"
);
return
{};
}
auto
type
=
S_ISBLK
(
statbuf
.
st_mode
)
?
'b'
:
S_ISCHR
(
statbuf
.
st_mode
)
?
'c'
:
0
;
auto
opened_dev
=
udev_device_new_from_devnum
(
udev
,
type
,
statbuf
.
st_rdev
);
auto
dev
=
opened_dev
;
while
(
dev
!=
nullptr
)
{
auto
serial
=
udev_device_get_sysattr_value
(
dev
,
"serial"
);
if
(
nullptr
==
serial
)
{
dev
=
udev_device_get_parent
(
dev
);
}
else
{
unique_device_string
+=
udev_device_get_sysattr_value
(
dev
,
"idVendor"
);
unique_device_string
+=
udev_device_get_sysattr_value
(
dev
,
"idProduct"
);
unique_device_string
+=
serial
;
break
;
}
}
if
(
opened_dev
)
{
udev_device_unref
(
opened_dev
);
}
return
unique_device_string
;
}
}
static
int
static
int
...
@@ -167,14 +145,14 @@ VideoDeviceMonitorImpl::VideoDeviceMonitorImpl(VideoDeviceMonitor* monitor)
...
@@ -167,14 +145,14 @@ VideoDeviceMonitorImpl::VideoDeviceMonitorImpl(VideoDeviceMonitor* monitor)
// udev_device_get_devnode will fail
// udev_device_get_devnode will fail
continue
;
continue
;
}
}
auto
unique_name
=
getDeviceString
(
udev_
,
path
);
try
{
auto
unique_name
=
getDeviceString
(
dev
);
JAMI_DBG
(
"udev: adding device with id %s"
,
unique_name
.
c_str
());
JAMI_DBG
(
"udev: adding device with id %s"
,
unique_name
.
c_str
());
std
::
map
<
std
::
string
,
std
::
string
>
info
=
{{
"devPath"
,
path
}};
std
::
map
<
std
::
string
,
std
::
string
>
info
=
{{
"devPath"
,
path
}};
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>
devInfo
=
{
info
};
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>
devInfo
=
{
info
};
try
{
monitor_
->
addDevice
(
unique_name
,
&
devInfo
);
monitor_
->
addDevice
(
unique_name
,
&
devInfo
);
currentPathToId_
.
emplace
(
path
,
unique_name
);
currentPathToId_
.
emplace
(
path
,
unique_name
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
JAMI_ERR
(
"%s"
,
e
.
what
());
JAMI_ERR
(
"%s"
,
e
.
what
());
}
}
}
}
...
@@ -253,19 +231,16 @@ VideoDeviceMonitorImpl::run()
...
@@ -253,19 +231,16 @@ VideoDeviceMonitorImpl::run()
// udev_device_get_devnode will fail
// udev_device_get_devnode will fail
break
;
break
;
}
}
auto
unique_name
=
getDeviceString
(
udev_
,
path
);
try
{
auto
unique_name
=
getDeviceString
(
dev
);
const
char
*
action
=
udev_device_get_action
(
dev
);
const
char
*
action
=
udev_device_get_action
(
dev
);
if
(
!
strcmp
(
action
,
"add"
))
{
if
(
!
strcmp
(
action
,
"add"
))
{
JAMI_DBG
(
"udev: adding device with id %s"
,
unique_name
.
c_str
());
JAMI_DBG
(
"udev: adding device with id %s"
,
unique_name
.
c_str
());
std
::
map
<
std
::
string
,
std
::
string
>
info
=
{{
"devPath"
,
path
}};
std
::
map
<
std
::
string
,
std
::
string
>
info
=
{{
"devPath"
,
path
}};
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>
devInfo
=
{
info
};
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>
devInfo
=
{
info
};
try
{
monitor_
->
addDevice
(
unique_name
,
&
devInfo
);
monitor_
->
addDevice
(
unique_name
,
&
devInfo
);
currentPathToId_
.
emplace
(
path
,
unique_name
);
currentPathToId_
.
emplace
(
path
,
unique_name
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
JAMI_ERR
(
"%s"
,
e
.
what
());
}
}
else
if
(
!
strcmp
(
action
,
"remove"
))
{
}
else
if
(
!
strcmp
(
action
,
"remove"
))
{
auto
it
=
currentPathToId_
.
find
(
path
);
auto
it
=
currentPathToId_
.
find
(
path
);
if
(
it
!=
currentPathToId_
.
end
())
{
if
(
it
!=
currentPathToId_
.
end
())
{
...
@@ -278,6 +253,9 @@ VideoDeviceMonitorImpl::run()
...
@@ -278,6 +253,9 @@ VideoDeviceMonitorImpl::run()
monitor_
->
removeDevice
(
path
);
monitor_
->
removeDevice
(
path
);
}
}
}
}
}
catch
(
const
std
::
exception
&
e
)
{
JAMI_ERR
(
"%s"
,
e
.
what
());
}
}
}
udev_device_unref
(
dev
);
udev_device_unref
(
dev
);
break
;
break
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment