[MPlayer-dev-eng] [PATCH] Network synchronized playback using UDP

Diego Biurrun diego at biurrun.de
Thu May 21 19:31:10 CEST 2009


On Wed, May 20, 2009 at 11:37:49PM -0700, Jason Holt wrote:
> Fixed a bug and updated patch to work with current svn.

> --- DOCS/xml/en/usage.xml	(revision 29317)
> +++ DOCS/xml/en/usage.xml	(working copy)
> @@ -494,6 +494,65 @@
> +
> +<para>
> +On each slave, run:
> +</para>
> +
> +<screen>
> +mplayer -udp-slave videoN.mpg
> +</screen>

It is not clear what you are referring to with 'N'.

> --- DOCS/man/en/mplayer.1	(revision 29317)
> +++ DOCS/man/en/mplayer.1	(working copy)
> @@ -1149,8 +1149,36 @@
>  The normal framerate of the movie is kept, so playback is accelerated.
>  Since MPlayer can only seek to the next keyframe this may be inexact.
>  .
> +.TP
> +.B \-udp\-master
> +Send a datagram to \-udp\-ip on \-udp\-port just before playing each frame.
> +The datagram indicates the master's position in the file.  
>  .
> +.TP
> +.B \-udp\-slave
> +Listen on \-udp\-port and match the master's position.
>  .
> +.TP
> +.B \-udp\-ip <ip>
> +Sets the destination address for datagrams sent by the \-udp\-master.
> +Setting it to a broadcast address allows multiple slaves having the same
> +broadcast address to sync to the master (default: 127.0.0.1).
> +.
> +.TP
> +.B \-udp\-port <port>
> +Sets the destination port for datagrams sent by the \-udp\-master, and the
> +port a \-udp\-slave listens on (default: 23867).
> +.
> +.TP
> +.B \-udp\-seek\-threshold <sec>
> +When the master seeks, the slave has to decide whether to seek as
> +well, or to catch up by decoding frames without pausing between frames. 
> +If the master is more than <sec> seconds away from the
> +slave, the slave seeks.
> +Otherwise, it "runs" to catch up or waits for the master.  
> +This should almost always be left at its default setting of 1 second. 

Please keep options in alphabetical order.

> --- mplayer.c	(revision 29317)
> +++ mplayer.c	(working copy)
> @@ -681,6 +688,10 @@
>  
> +   if(udp_master) {
> +
> @@ -2083,6 +2094,11 @@
>  
> +    if (udp_slave) {
> +
>      if (mpctx->sh_audio && !mpctx->d_audio->eof) {
> @@ -2131,6 +2147,13 @@
>      if (*time_frame > 0.001 && !(vo_flags&256))
>  	*time_frame = timing_sleep(*time_frame);
> +
> +    if(udp_master) {
> +      char current_time[256];

Please consistently use K&R style, i.e. 'if ('.

> --- mplayer.h	(revision 29317)
> +++ mplayer.h	(working copy)
> @@ -47,7 +47,7 @@
>  
> -void exit_player(const char* how);
> +void exit_player(exit_reason_t);

Unrelated?

> --- udp_sync.c	(revision 0)
> +++ udp_sync.c	(revision 0)
> @@ -0,0 +1,188 @@
> +

missing license header

> +#include "mplayer.h"
> +#include "udp_sync.h"
> +#include "mp_msg.h"
> +#include "help_mp.h"
> +
> +#include <errno.h>
> +#include <sys/types.h>
> +#include <sys/socket.h>
> +#include <netinet/in.h>
> +#include <stdlib.h>
> +#include <sys/ioctl.h>
> +#include <fcntl.h>
> +#include <string.h>
> +#include <strings.h>
> +#include <netdb.h>

Please place system #includes before local #includes.

> +void get_udp(int blocking)
> +{
> +  static int done_init_yet = 0;
> +  static int sockfd;
> +  static struct sockaddr_in servaddr, cliaddr;

Use 4 spaces as indentation for new files.

> +  if(!done_init_yet) {

'if (', same below

> +    servaddr.sin_family = AF_INET;
> +    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
> +    servaddr.sin_port = htons(udp_port);

align

> +  if (blocking) {
> +    fcntl(sockfd, F_SETFL, sock_flags & (~O_NONBLOCK));
> +  } else {
> +    fcntl(sockfd, F_SETFL, sock_flags | O_NONBLOCK);
> +  }

pointless {}

> +    if ((my_position > udp_master_position - udp_seek_threshold) &&
> +        (my_position < udp_master_position + udp_timing_tolerance)) {
> +      closebehind = 1;
> +    } else {
> +      closebehind = 0;
> +    }

pointless {}

> +    if (absolute_timing_error > udp_seek_threshold) {
> +      // seek
> +      abs_seek_pos = SEEK_ABSOLUTE;
> +      rel_seek_secs = udp_master_position;
> +      break;
> +    }
> +
> +    if (my_position < udp_master_position + udp_timing_tolerance) {
> +      break;
> +    }

pointless {}

> --- udp_sync.h	(revision 0)
> +++ udp_sync.h	(revision 0)
> @@ -0,0 +1,22 @@
> +#ifndef MPLAYER_UDP_SYNC_H
> +#define MPLAYER_UDP_SYNC_H

missing license header

Diego



More information about the MPlayer-dev-eng mailing list