Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
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
videolan
vlc
Commits
09dcfc63
Commit
09dcfc63
authored
Oct 16, 2009
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
udev: remove item when the device is removed
parent
c9b5c9e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
26 deletions
+61
-26
modules/services_discovery/udev.c
modules/services_discovery/udev.c
+61
-26
No files found.
modules/services_discovery/udev.c
View file @
09dcfc63
...
@@ -52,6 +52,8 @@ struct services_discovery_sys_t
...
@@ -52,6 +52,8 @@ struct services_discovery_sys_t
{
{
struct
udev_monitor
*
monitor
;
struct
udev_monitor
*
monitor
;
vlc_thread_t
thread
;
vlc_thread_t
thread
;
input_item_t
**
itemv
;
size_t
itemc
;
};
};
static
void
*
Run
(
void
*
);
static
void
*
Run
(
void
*
);
...
@@ -69,6 +71,8 @@ static int Open (vlc_object_t *obj)
...
@@ -69,6 +71,8 @@ static int Open (vlc_object_t *obj)
if
(
p_sys
==
NULL
)
if
(
p_sys
==
NULL
)
return
VLC_ENOMEM
;
return
VLC_ENOMEM
;
sd
->
p_sys
=
p_sys
;
sd
->
p_sys
=
p_sys
;
p_sys
->
itemv
=
NULL
;
p_sys
->
itemc
=
0
;
struct
udev_monitor
*
mon
=
NULL
;
struct
udev_monitor
*
mon
=
NULL
;
struct
udev
*
udev
=
udev_new
();
struct
udev
*
udev
=
udev_new
();
...
@@ -108,7 +112,11 @@ static int Open (vlc_object_t *obj)
...
@@ -108,7 +112,11 @@ static int Open (vlc_object_t *obj)
udev_enumerate_unref
(
devenum
);
udev_enumerate_unref
(
devenum
);
if
(
vlc_clone
(
&
p_sys
->
thread
,
Run
,
sd
,
VLC_THREAD_PRIORITY_LOW
))
if
(
vlc_clone
(
&
p_sys
->
thread
,
Run
,
sd
,
VLC_THREAD_PRIORITY_LOW
))
goto
error
;
{
/* Fallback without thread */
udev_monitor_unref
(
mon
);
udev_unref
(
udev
);
p_sys
->
monitor
=
NULL
;
}
return
VLC_SUCCESS
;
return
VLC_SUCCESS
;
error:
error:
...
@@ -128,12 +136,20 @@ static void Close (vlc_object_t *obj)
...
@@ -128,12 +136,20 @@ static void Close (vlc_object_t *obj)
{
{
services_discovery_t
*
sd
=
(
services_discovery_t
*
)
obj
;
services_discovery_t
*
sd
=
(
services_discovery_t
*
)
obj
;
services_discovery_sys_t
*
p_sys
=
sd
->
p_sys
;
services_discovery_sys_t
*
p_sys
=
sd
->
p_sys
;
struct
udev
*
udev
=
udev_monitor_get_udev
(
p_sys
->
monitor
);
vlc_cancel
(
p_sys
->
thread
);
if
(
p_sys
->
monitor
!=
NULL
)
vlc_join
(
p_sys
->
thread
,
NULL
);
{
udev_monitor_unref
(
p_sys
->
monitor
);
struct
udev
*
udev
=
udev_monitor_get_udev
(
p_sys
->
monitor
);
udev_unref
(
udev
);
vlc_cancel
(
p_sys
->
thread
);
vlc_join
(
p_sys
->
thread
,
NULL
);
udev_monitor_unref
(
p_sys
->
monitor
);
udev_unref
(
udev
);
}
for
(
size_t
i
=
0
;
i
<
p_sys
->
itemc
;
i
++
)
vlc_gc_decref
(
p_sys
->
itemv
[
i
]);
free
(
p_sys
->
itemv
);
free
(
p_sys
);
free
(
p_sys
);
}
}
...
@@ -223,37 +239,56 @@ static bool is_v4l_legacy (struct udev_device *dev)
...
@@ -223,37 +239,56 @@ static bool is_v4l_legacy (struct udev_device *dev)
static
void
HandleDevice
(
services_discovery_t
*
sd
,
struct
udev_device
*
dev
,
static
void
HandleDevice
(
services_discovery_t
*
sd
,
struct
udev_device
*
dev
,
bool
add
)
bool
add
)
{
{
//services_discovery_sys_t *p_sys = sd->p_sys;
services_discovery_sys_t
*
p_sys
=
sd
->
p_sys
;
if
(
!
add
)
{
msg_Err
(
sd
,
"FIXME: removing device not implemented!"
);
return
;
}
/* Determine media location */
const
char
*
scheme
=
"v4l2"
;
const
char
*
scheme
=
"v4l2"
;
if
(
is_v4l_legacy
(
dev
))
if
(
is_v4l_legacy
(
dev
))
scheme
=
"v4l"
;
scheme
=
"v4l"
;
const
char
*
node
=
udev_device_get_devnode
(
dev
);
const
char
*
node
=
udev_device_get_devnode
(
dev
);
char
*
vnd
=
decode_property
(
dev
,
"ID_VENDOR_ENC"
);
const
char
*
name
=
udev_device_get_property_value
(
dev
,
"ID_V4L_PRODUCT"
);
char
*
mrl
;
char
*
mrl
;
if
(
asprintf
(
&
mrl
,
"%s://%s"
,
scheme
,
node
)
==
-
1
)
if
(
asprintf
(
&
mrl
,
"%s://%s"
,
scheme
,
node
)
==
-
1
)
return
;
return
;
/* FIXME: check for duplicates (race between monitor starting to receive
/* Find item in list */
* and initial enumeration). */
input_item_t
*
item
=
NULL
;
input_item_t
*
item
;
size_t
i
;
item
=
input_item_NewWithType
(
VLC_OBJECT
(
sd
),
mrl
,
name
?
name
:
"Unnamed"
,
0
,
NULL
,
0
,
-
1
,
ITEM_TYPE_CARD
);
msg_Dbg
(
sd
,
"adding %s"
,
mrl
);
free
(
mrl
);
if
(
item
!=
NULL
)
for
(
i
=
0
;
i
<
p_sys
->
itemc
;
i
++
)
{
{
services_discovery_AddItem
(
sd
,
item
,
vnd
?
vnd
:
"Generic"
);
input_item_t
*
oitem
=
p_sys
->
itemv
[
i
];
char
*
omrl
=
input_item_GetURI
(
oitem
);
if
(
!
strcmp
(
omrl
,
mrl
))
{
item
=
oitem
;
break
;
}
}
/* Add/Remove old item */
if
(
add
&&
(
item
==
NULL
))
{
char
*
vnd
=
decode_property
(
dev
,
"ID_VENDOR_ENC"
);
const
char
*
name
=
udev_device_get_property_value
(
dev
,
"ID_V4L_PRODUCT"
);
item
=
input_item_NewWithType
(
VLC_OBJECT
(
sd
),
mrl
,
name
?
name
:
"Unnamed"
,
0
,
NULL
,
0
,
-
1
,
ITEM_TYPE_CARD
);
msg_Dbg
(
sd
,
"adding %s"
,
mrl
);
if
(
item
!=
NULL
)
{
services_discovery_AddItem
(
sd
,
item
,
vnd
?
vnd
:
"Generic"
);
TAB_APPEND
(
p_sys
->
itemc
,
p_sys
->
itemv
,
item
);
}
free
(
vnd
);
}
else
if
(
!
add
&&
(
item
!=
NULL
))
{
msg_Dbg
(
sd
,
"removing %s"
,
mrl
);
services_discovery_RemoveItem
(
sd
,
item
);
vlc_gc_decref
(
item
);
vlc_gc_decref
(
item
);
TAB_REMOVE
(
p_sys
->
itemc
,
p_sys
->
itemv
,
i
);
}
}
free
(
vnd
);
free
(
mrl
);
}
}
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