[MPlayer-cvslog] r33242 - in trunk: mplayer.c udp_sync.c

reimar subversion at mplayerhq.hu
Sat Apr 9 16:55:22 CEST 2011


Author: reimar
Date: Sat Apr  9 16:55:22 2011
New Revision: 33242

Log:
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.

Modified:
   trunk/mplayer.c
   trunk/udp_sync.c

Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c	Sat Apr  9 16:47:16 2011	(r33241)
+++ trunk/mplayer.c	Sat Apr  9 16:55:22 2011	(r33242)
@@ -2170,6 +2170,17 @@ static int fill_audio_out_buffers(void)
     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 @@ static int sleep_until_update(float *tim
     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 @@ static void pause_loop(void)
             }
         }
 #endif
+        handle_udp_master(mpctx->sh_video->pts);
         usec_sleep(20000);
     }
     if (cmd && cmd->id == MP_CMD_PAUSE) {

Modified: trunk/udp_sync.c
==============================================================================
--- trunk/udp_sync.c	Sat Apr  9 16:47:16 2011	(r33241)
+++ trunk/udp_sync.c	Sat Apr  9 16:55:22 2011	(r33242)
@@ -53,9 +53,6 @@ const char *udp_ip = "127.0.0.1"; // whe
                                   // (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 @@ static int get_udp(int blocking, double 
     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 @@ void send_udp(const char *send_to_ip, in
 // 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


More information about the MPlayer-cvslog mailing list