Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-1.1
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-1.1
Commits
82954f97
Commit
82954f97
authored
Feb 02, 2010
by
Laurent Aimar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create the synchronization thread only when needed (netsync).
parent
188b465f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
128 additions
and
107 deletions
+128
-107
modules/control/netsync.c
modules/control/netsync.c
+128
-107
No files found.
modules/control/netsync.c
View file @
82954f97
...
...
@@ -28,6 +28,7 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include <vlc_common.h>
#include <vlc_plugin.h>
...
...
@@ -91,9 +92,14 @@ struct intf_sys_t {
int
timeout
;
bool
is_master
;
playlist_t
*
playlist
;
/* */
input_thread_t
*
input
;
vlc_thread_t
thread
;
};
static
void
Run
(
intf_thread_t
*
intf
);
static
int
PlaylistEvent
(
vlc_object_t
*
,
char
const
*
cmd
,
vlc_value_t
oldval
,
vlc_value_t
newval
,
void
*
data
);
/*****************************************************************************
* Activate: initialize and create stuff
...
...
@@ -121,12 +127,12 @@ static int Open(vlc_object_t *object)
return
VLC_EGENERIC
;
}
intf
->
pf_run
=
NULL
;
intf
->
p_sys
=
sys
=
malloc
(
sizeof
(
*
sys
));
if
(
!
sys
)
{
net_Close
(
fd
);
return
VLC_ENOMEM
;
}
intf
->
pf_run
=
Run
;
sys
->
fd
=
fd
;
sys
->
is_master
=
var_InheritBool
(
intf
,
"netsync-master"
);
...
...
@@ -136,6 +142,7 @@ static int Open(vlc_object_t *object)
sys
->
playlist
=
pl_Hold
(
intf
);
sys
->
input
=
NULL
;
var_AddCallback
(
sys
->
playlist
,
"input-current"
,
PlaylistEvent
,
intf
);
return
VLC_SUCCESS
;
}
...
...
@@ -147,20 +154,34 @@ void Close(vlc_object_t *object)
intf_thread_t
*
intf
=
(
intf_thread_t
*
)
object
;
intf_sys_t
*
sys
=
intf
->
p_sys
;
assert
(
sys
->
input
==
NULL
);
var_DelCallback
(
sys
->
playlist
,
"input-current"
,
PlaylistEvent
,
intf
);
pl_Release
(
intf
);
net_Close
(
sys
->
fd
);
free
(
sys
);
}
static
void
Master
(
intf_thread_t
*
intf
)
static
mtime_t
GetPcrSystem
(
input_thread_t
*
input
)
{
int
canc
=
vlc_savecancel
();
mtime_t
system
;
if
(
input_GetPcrSystem
(
input
,
&
system
))
system
=
-
1
;
vlc_restorecancel
(
canc
);
return
system
;
}
static
void
*
Master
(
void
*
handle
)
{
intf_thread_t
*
intf
=
handle
;
intf_sys_t
*
sys
=
intf
->
p_sys
;
for
(;;)
{
struct
pollfd
ufd
=
{
.
fd
=
sys
->
fd
,
.
events
=
POLLIN
,
};
uint64_t
data
[
2
];
/* Don't block */
if
(
poll
(
&
ufd
,
1
,
sys
->
timeout
)
<=
0
)
return
;
if
(
poll
(
&
ufd
,
1
,
-
1
)
<=
0
)
continue
;
/* We received something */
struct
sockaddr_storage
from
;
...
...
@@ -168,9 +189,9 @@ static void Master(intf_thread_t *intf)
recvfrom
(
sys
->
fd
,
data
,
sizeof
(
data
),
0
,
(
struct
sockaddr
*
)
&
from
,
&
struct_size
);
mtime_t
master_system
;
if
(
input_GetPcrSystem
(
sys
->
input
,
&
master_system
)
)
return
;
mtime_t
master_system
=
GetPcrSystem
(
sys
->
input
)
;
if
(
master_system
<
0
)
continue
;
data
[
0
]
=
hton64
(
mdate
());
data
[
1
]
=
hton64
(
master_system
);
...
...
@@ -178,7 +199,6 @@ static void Master(intf_thread_t *intf)
/* Reply to the sender */
sendto
(
sys
->
fd
,
data
,
sizeof
(
data
),
0
,
(
struct
sockaddr
*
)
&
from
,
struct_size
);
#if 0
/* not sure we need the client information to sync,
since we are the master anyway */
...
...
@@ -186,18 +206,22 @@ static void Master(intf_thread_t *intf)
msg_Dbg(intf, "Master clockref: %"PRId64" -> %"PRId64", from %s "
"(date: %"PRId64")", client_system, master_system,
(from.ss_family == AF_INET) ? inet_ntoa(((struct sockaddr_in *)&from)->sin_addr)
: "non-IPv4", date
);
: "non-IPv4", /*date*/ 0
);
#endif
}
}
static
void
Slave
(
intf_thread_t
*
intf
)
static
void
*
Slave
(
void
*
handle
)
{
intf_thread_t
*
intf
=
handle
;
intf_sys_t
*
sys
=
intf
->
p_sys
;
for
(;;)
{
struct
pollfd
ufd
=
{
.
fd
=
sys
->
fd
,
.
events
=
POLLIN
,
};
uint64_t
data
[
2
];
mtime_t
system
;
if
(
input_GetPcrSystem
(
sys
->
input
,
&
system
)
)
mtime_t
system
=
GetPcrSystem
(
sys
->
input
)
;
if
(
system
<
0
)
goto
wait
;
/* Send clock request to the master */
...
...
@@ -210,7 +234,7 @@ static void Slave(intf_thread_t *intf)
/* Don't block */
int
ret
=
poll
(
&
ufd
,
1
,
sys
->
timeout
);
if
(
ret
==
0
)
return
;
continue
;
if
(
ret
<
0
)
goto
wait
;
...
...
@@ -224,10 +248,10 @@ static void Slave(intf_thread_t *intf)
((
receive_date
-
send_date
)
/
2
+
master_date
);
if
(
master_system
>
0
)
{
mtime_t
client_system
;
if
(
input_GetPcrSystem
(
sys
->
input
,
&
client_system
))
goto
wait
;
int
canc
=
vlc_savecancel
();
mtime_t
client_system
;
if
(
!
input_GetPcrSystem
(
sys
->
input
,
&
client_system
))
{
const
mtime_t
diff_system
=
client_system
-
master_system
-
diff_date
;
if
(
diff_system
!=
0
)
{
input_ModifyPcrSystem
(
sys
->
input
,
true
,
master_system
-
diff_date
);
...
...
@@ -239,49 +263,46 @@ static void Slave(intf_thread_t *intf)
#endif
}
}
wait:
vlc_restorecancel
(
canc
);
}
wait:
msleep
(
INTF_IDLE_SLEEP
);
}
}
/*****************************************************************************
* Run: interface thread
*****************************************************************************/
static
void
Run
(
intf_thread_t
*
intf
)
static
int
InputEvent
(
vlc_object_t
*
object
,
char
const
*
cmd
,
vlc_value_t
oldval
,
vlc_value_t
newval
,
void
*
data
)
{
VLC_UNUSED
(
cmd
);
VLC_UNUSED
(
oldval
);
VLC_UNUSED
(
object
);
intf_thread_t
*
intf
=
data
;
intf_sys_t
*
sys
=
intf
->
p_sys
;
int
canc
=
vlc_savecancel
();
/* High priority thread */
vlc_thread_set_priority
(
intf
,
VLC_THREAD_PRIORITY_INPUT
);
while
(
vlc_object_alive
(
intf
))
{
/* Update the input */
if
(
sys
->
input
==
NULL
)
{
sys
->
input
=
playlist_CurrentInput
(
sys
->
playlist
);
}
else
if
(
sys
->
input
->
b_dead
||
!
vlc_object_alive
(
sys
->
input
))
{
if
(
newval
.
i_int
==
INPUT_EVENT_DEAD
&&
sys
->
input
)
{
msg_Err
(
intf
,
"InputEvent DEAD"
);
vlc_cancel
(
sys
->
thread
);
vlc_join
(
sys
->
thread
,
NULL
);
vlc_object_release
(
sys
->
input
);
sys
->
input
=
NULL
;
}
return
VLC_SUCCESS
;
}
if
(
sys
->
input
==
NULL
)
{
/* Wait a bit */
msleep
(
INTF_IDLE_SLEEP
);
continue
;
}
static
int
PlaylistEvent
(
vlc_object_t
*
object
,
char
const
*
cmd
,
vlc_value_t
oldval
,
vlc_value_t
newval
,
void
*
data
)
{
VLC_UNUSED
(
cmd
);
VLC_UNUSED
(
oldval
);
VLC_UNUSED
(
object
);
intf_thread_t
*
intf
=
data
;
intf_sys_t
*
sys
=
intf
->
p_sys
;
/*
* We now have an input
*/
if
(
sys
->
is_master
)
Master
(
intf
);
else
Slave
(
intf
)
;
input_thread_t
*
input
=
newval
.
p_address
;
assert
(
sys
->
input
==
NULL
);
sys
->
input
=
vlc_object_hold
(
input
);
if
(
vlc_clone
(
&
sys
->
thread
,
sys
->
is_master
?
Master
:
Slave
,
intf
,
VLC_THREAD_PRIORITY_INPUT
))
{
vlc_object_release
(
input
);
return
VLC_SUCCESS
;
}
if
(
sys
->
input
)
vlc_object_release
(
sys
->
input
);
vlc_restorecancel
(
canc
);
var_AddCallback
(
input
,
"intf-event"
,
InputEvent
,
intf
);
return
VLC_SUCCESS
;
}
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