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
Automate
Agent sessions
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
73bc5d46
Commit
73bc5d46
authored
Jun 29, 2011
by
Rafaël Carré
Browse files
Options
Downloads
Patches
Plain Diff
* #6179: make sure v4l2 device names are unique
number them sequentially ("X", "X #0", "X
#1
", ...)
parent
0e3b689a
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
sflphone-common/src/video/video_v4l2_list.cpp
+48
-0
48 additions, 0 deletions
sflphone-common/src/video/video_v4l2_list.cpp
with
48 additions
and
0 deletions
sflphone-common/src/video/video_v4l2_list.cpp
+
48
−
0
View file @
73bc5d46
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include
"config.h"
#include
"config.h"
#endif
#endif
#include
<cstdio>
#include
<iostream>
#include
<iostream>
#include
<stdexcept>
// for std::runtime_error
#include
<stdexcept>
// for std::runtime_error
#include
<sstream>
#include
<sstream>
...
@@ -139,6 +140,52 @@ udev_error:
...
@@ -139,6 +140,52 @@ udev_error:
}
}
}
}
namespace
{
int
GetNumber
(
const
std
::
string
&
name
,
size_t
*
sharp
)
{
size_t
len
=
name
.
length
();
if
(
len
<
3
)
{
// name is too short to be numbered
return
-
1
;
}
for
(
size_t
c
=
len
;
c
;
--
c
)
{
if
(
name
[
c
]
==
'#'
)
{
unsigned
i
;
printf
(
"looking `%s'
\n
"
,
name
.
substr
(
c
).
c_str
());
if
(
sscanf
(
name
.
substr
(
c
).
c_str
(),
"#%u"
,
&
i
)
!=
1
)
return
-
1
;
*
sharp
=
c
;
return
i
;
}
}
return
-
1
;
}
void
GiveUniqueName
(
VideoV4l2Device
&
dev
,
const
std
::
vector
<
VideoV4l2Device
>
&
devices
)
{
const
std
::
string
&
name
=
dev
.
name
;
start:
for
(
size_t
i
=
0
;
i
<
devices
.
size
();
i
++
)
{
if
(
name
==
devices
[
i
].
name
)
{
size_t
sharp
;
int
num
=
GetNumber
(
name
,
&
sharp
);
if
(
num
<
0
)
// not numbered
dev
.
name
+=
" #0"
;
else
{
std
::
stringstream
ss
;
ss
<<
num
+
1
;
dev
.
name
.
replace
(
sharp
+
1
,
ss
.
str
().
length
(),
ss
.
str
());
}
goto
start
;
// we changed the name, let's look again if it is unique
}
}
}
}
// end anonymous namespace
bool
VideoV4l2List
::
addDevice
(
const
std
::
string
&
dev
)
bool
VideoV4l2List
::
addDevice
(
const
std
::
string
&
dev
)
{
{
int
fd
=
open
(
dev
.
c_str
(),
O_RDWR
);
int
fd
=
open
(
dev
.
c_str
(),
O_RDWR
);
...
@@ -147,6 +194,7 @@ bool VideoV4l2List::addDevice(const std::string &dev)
...
@@ -147,6 +194,7 @@ bool VideoV4l2List::addDevice(const std::string &dev)
std
::
string
s
(
dev
);
std
::
string
s
(
dev
);
VideoV4l2Device
v
(
fd
,
s
);
VideoV4l2Device
v
(
fd
,
s
);
GiveUniqueName
(
v
,
devices
);
devices
.
push_back
(
v
);
devices
.
push_back
(
v
);
close
(
fd
);
close
(
fd
);
...
...
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
sign in
to comment