Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
savoirfairelinux
jami-daemon
Commits
afda24d6
Unverified
Commit
afda24d6
authored
Sep 02, 2020
by
Sébastien Blin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v4l2: use serial id
Change-Id: I7f4d6e5baef04b99a2cf1435aa6848aff7bd84df
parent
8cce5301
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
52 deletions
+30
-52
src/media/video/v4l2/video_device_monitor_impl.cpp
src/media/video/v4l2/video_device_monitor_impl.cpp
+30
-52
No files found.
src/media/video/v4l2/video_device_monitor_impl.cpp
View file @
afda24d6
...
...
@@ -82,33 +82,11 @@ private:
};
std
::
string
getDeviceString
(
udev
*
udev
,
const
std
::
string
&
dev_path
)
getDeviceString
(
struct
udev_device
*
udev_device
)
{
std
::
string
unique_device_string
;
struct
stat
statbuf
;
if
(
stat
(
dev_path
.
c_str
(),
&
statbuf
)
<
0
)
{
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
;
if
(
auto
serial
=
udev_device_get_property_value
(
udev_device
,
"ID_SERIAL"
))
return
serial
;
throw
std
::
invalid_argument
(
"No ID_SERIAL detected"
);
}
static
int
...
...
@@ -167,14 +145,14 @@ VideoDeviceMonitorImpl::VideoDeviceMonitorImpl(VideoDeviceMonitor* monitor)
// udev_device_get_devnode will fail
continue
;
}
auto
unique_name
=
getDeviceString
(
udev_
,
path
);
JAMI_DBG
(
"udev: adding device with id %s"
,
unique_name
.
c_str
());
std
::
map
<
std
::
string
,
std
::
string
>
info
=
{{
"devPath"
,
path
}};
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>
devInfo
=
{
info
};
try
{
auto
unique_name
=
getDeviceString
(
dev
);
JAMI_DBG
(
"udev: adding device with id %s"
,
unique_name
.
c_str
());
std
::
map
<
std
::
string
,
std
::
string
>
info
=
{{
"devPath"
,
path
}};
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>
devInfo
=
{
info
};
monitor_
->
addDevice
(
unique_name
,
&
devInfo
);
currentPathToId_
.
emplace
(
path
,
unique_name
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
JAMI_ERR
(
"%s"
,
e
.
what
());
}
}
...
...
@@ -253,30 +231,30 @@ VideoDeviceMonitorImpl::run()
// udev_device_get_devnode will fail
break
;
}
auto
unique_name
=
getDeviceString
(
udev_
,
path
);
const
char
*
action
=
udev_device_get_action
(
dev
);
if
(
!
strcmp
(
action
,
"add"
))
{
JAMI_DBG
(
"udev: adding device with id %s"
,
unique_name
.
c_str
());
std
::
map
<
std
::
string
,
std
::
string
>
info
=
{{
"devPath"
,
path
}}
;
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>
>
devI
nfo
=
{
info
};
try
{
try
{
auto
unique_name
=
getDeviceString
(
dev
);
const
char
*
action
=
udev_device_get_action
(
dev
);
if
(
!
strcmp
(
action
,
"add"
))
{
JAMI_DBG
(
"udev: adding device with id %s"
,
unique_name
.
c_str
())
;
std
::
map
<
std
::
string
,
std
::
string
>
i
nfo
=
{
{
"devPath"
,
path
}
};
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>
devInfo
=
{
info
};
monitor_
->
addDevice
(
unique_name
,
&
devInfo
);
currentPathToId_
.
emplace
(
path
,
unique_name
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
JAMI_ERR
(
"%s"
,
e
.
what
());
}
}
else
if
(
!
strcmp
(
action
,
"remove"
))
{
auto
it
=
currentPathToId_
.
find
(
path
);
if
(
it
!=
currentPathToId_
.
end
())
{
JAMI_DBG
(
"udev: removing %s"
,
it
->
second
.
c_str
());
monitor_
->
removeDevice
(
it
->
second
);
currentPathToId_
.
erase
(
it
);
}
else
{
// In case of fallback
JAMI_DBG
(
"udev: removing %s"
,
path
);
monitor_
->
removeDevice
(
path
);
}
else
if
(
!
strcmp
(
action
,
"remove"
))
{
auto
it
=
currentPathToId_
.
find
(
path
);
if
(
it
!=
currentPathToId_
.
end
())
{
JAMI_DBG
(
"udev: removing %s"
,
it
->
second
.
c_str
());
monitor_
->
removeDevice
(
it
->
second
);
currentPathToId_
.
erase
(
it
);
}
else
{
// In case of fallback
JAMI_DBG
(
"udev: removing %s"
,
path
);
monitor_
->
removeDevice
(
path
);
}
}
}
catch
(
const
std
::
exception
&
e
)
{
JAMI_ERR
(
"%s"
,
e
.
what
());
}
}
udev_device_unref
(
dev
);
...
...
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