Mercurial > mplayer.hg
changeset 33155:16e5b7f9ddb8
Send udp master updates also when paused and let slave use normal timing
when it gets no messages.
This allows the slave to continue playing normally if the master crashes
or network stops working instead of hanging forever.
Note that the slave might still hang for the 30 second network timeout
in some cases.
author | reimar |
---|---|
date | Sat, 09 Apr 2011 14:55:22 +0000 |
parents | f6a049eff960 |
children | 9ac31195a5e0 |
files | mplayer.c udp_sync.c |
diffstat | 2 files changed, 19 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mplayer.c Sat Apr 09 14:47:16 2011 +0000 +++ b/mplayer.c Sat Apr 09 14:55:22 2011 +0000 @@ -2170,6 +2170,17 @@ return 1; } +static void handle_udp_master(double time) +{ +#ifdef CONFIG_NETWORKING + if (udp_master) { + char current_time[256]; + snprintf(current_time, sizeof(current_time), "%f", time); + send_udp(udp_ip, udp_port, current_time); + } +#endif /* CONFIG_NETWORKING */ +} + static int sleep_until_update(float *time_frame, float *aq_sleep_time) { int frame_time_remaining = 0; @@ -2235,13 +2246,7 @@ if (*time_frame > 0.001 && !(vo_flags&256)) *time_frame = timing_sleep(*time_frame); -#ifdef CONFIG_NETWORKING - if (udp_master) { - char current_time[256]; - snprintf(current_time, sizeof(current_time), "%f", mpctx->sh_video->pts); - send_udp(udp_ip, udp_port, current_time); - } -#endif /* CONFIG_NETWORKING */ + handle_udp_master(mpctx->sh_video->pts); return frame_time_remaining; } @@ -2534,6 +2539,7 @@ } } #endif + handle_udp_master(mpctx->sh_video->pts); usec_sleep(20000); } if (cmd && cmd->id == MP_CMD_PAUSE) {
--- a/udp_sync.c Sat Apr 09 14:47:16 2011 +0000 +++ b/udp_sync.c Sat Apr 09 14:55:22 2011 +0000 @@ -53,9 +53,6 @@ // (can be a broadcast address) float udp_seek_threshold = 1.0; // how far off before we seek -// remember where the master is in the file -static double udp_master_position = -1.0; - // how far off is still considered equal #define UDP_TIMING_TOLERANCE 0.02 @@ -84,6 +81,9 @@ int n; static int sockfd = -1; + + *master_position = MP_NOPTS_VALUE; + if (sockfd == -1) { struct timeval tv = { .tv_sec = 30 }; struct sockaddr_in servaddr = { 0 }; @@ -159,10 +159,12 @@ // position. returns 1 if the master tells us to exit, 0 otherwise. int udp_slave_sync(MPContext *mpctx) { + double udp_master_position; + // grab any waiting datagrams without blocking int master_exited = get_udp(0, &udp_master_position); - while (!master_exited) { + while (udp_master_position != MP_NOPTS_VALUE && !master_exited) { double my_position = mpctx->sh_video->pts; // if we're way off, seek to catch up