# HG changeset patch # User reimar # Date 1302360922 0 # Node ID 16e5b7f9ddb8eee1785daebf2fa0a38d78396844 # Parent f6a049eff960a78099d9031f87d1adfcd9439db5 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. diff -r f6a049eff960 -r 16e5b7f9ddb8 mplayer.c --- 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) { diff -r f6a049eff960 -r 16e5b7f9ddb8 udp_sync.c --- 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