[MPlayer-dev-eng] rtp support in mplayer

Chas Williams (CONTRACTOR) chas at cmf.nrl.navy.mil
Mon Jun 9 19:27:12 CEST 2008


In message <20080516134500.8485095e.tempn at twmi.rr.com>,compn writes:
>ah good, is it all working properly now ?

the following patch adds a skip for the mpeg1 video specific header
in an rtp stream.  it also adds support for hinting the file format
of the stream to the upper layer by capturing a single packet during
the open and giving it a quick parse.

diff -u mplayer-1.0rc2.orig/stream/rtp.c mplayer-1.0rc2/stream/rtp.c
--- mplayer-1.0rc2.orig/stream/rtp.c	2007-10-07 15:49:26.000000000 -0400
+++ mplayer-1.0rc2/stream/rtp.c	2008-05-14 22:54:18.000000000 -0400
@@ -39,22 +39,6 @@
 
 #define MAXRTPPACKETSIN 32   // The number of max packets being reordered
 
-struct rtpbits {
-  unsigned int v:2;           /* version: 2 */
-  unsigned int p:1;           /* is there padding appended: 0 */
-  unsigned int x:1;           /* number of extension headers: 0 */
-  unsigned int cc:4;          /* number of CSRC identifiers: 0 */
-  unsigned int m:1;           /* marker: 0 */
-  unsigned int pt:7;          /* payload type: 33 for MPEG2 TS - RFC 1890 */
-  unsigned int sequence:16;   /* sequence number: random */
-};
-
-struct rtpheader {	/* in network byte order */
-  struct rtpbits b;
-  int timestamp;	/* start: random */
-  int ssrc;		/* random */
-};
-
 struct rtpbuffer
 {
 	unsigned char  data[MAXRTPPACKETSIN][STREAM_BUFFER_SIZE];
@@ -64,7 +48,7 @@
 };
 static struct rtpbuffer rtpbuf;
 
-static int getrtp2(int fd, struct rtpheader *rh, char** data, int* lengthData);
+int getrtp2(int fd, struct rtpheader *rh, char** data, int* lengthData);
 
 // RTP Reordering functions
 // Algorithm works as follows:
@@ -216,12 +200,13 @@
 	return(length);
 }
 
-static int getrtp2(int fd, struct rtpheader *rh, char** data, int* lengthData) {
+int getrtp2(int fd, struct rtpheader *rh, char** data, int* lengthData) {
   static char buf[1600];
   unsigned int intP;
   char* charP = (char*) &intP;
   int headerSize;
   int lengthPacket;
+
   lengthPacket=recv(fd,buf,1590,0);
   if (lengthPacket<0)
     mp_msg(MSGT_NETWORK,MSGL_ERR,"rtp: socket read error\n");
@@ -246,6 +231,9 @@
 
   headerSize = 12 + 4*rh->b.cc; /* in bytes */
 
+  if (rh->b.pt == 32)		/* 32 = MPV from RFC 1890 */
+	headerSize += 4;	/* skip MPEG video-specific header RFC 2250 */
+
   *lengthData = lengthPacket - headerSize;
   *data = (char*) buf + headerSize;
 
diff -u mplayer-1.0rc2.orig/stream/rtp.h mplayer-1.0rc2/stream/rtp.h
--- mplayer-1.0rc2.orig/stream/rtp.h	2007-10-07 15:49:26.000000000 -0400
+++ mplayer-1.0rc2/stream/rtp.h	2008-06-09 13:20:10.000000000 -0400
@@ -9,5 +9,22 @@
 #define RTP_H
 
 int read_rtp_from_server(int fd, char *buffer, int length);
+int getrtp2(int fd, struct rtpheader *rh, char** data, int* lengthData);
+
+struct rtpbits {
+  unsigned int v:2;           /* version: 2 */
+  unsigned int p:1;           /* is there padding appended: 0 */
+  unsigned int x:1;           /* number of extension headers: 0 */
+  unsigned int cc:4;          /* number of CSRC identifiers: 0 */
+  unsigned int m:1;           /* marker: 0 */
+  unsigned int pt:7;          /* payload type: 33 for MPEG2 TS - RFC 1890 */
+  unsigned int sequence:16;   /* sequence number: random */
+};
+
+struct rtpheader {	/* in network byte order */
+  struct rtpbits b;
+  int timestamp;	/* start: random */
+  int ssrc;		/* random */
+};
 
 #endif
diff -u mplayer-1.0rc2.orig/stream/stream_rtp.c mplayer-1.0rc2/stream/stream_rtp.c
--- mplayer-1.0rc2.orig/stream/stream_rtp.c	2007-10-07 15:49:26.000000000 -0400
+++ mplayer-1.0rc2/stream/stream_rtp.c	2008-06-09 13:21:08.000000000 -0400
@@ -26,6 +26,7 @@
 #include "url.h"
 #include "udp.h"
 #include "rtp.h"
+#include "libmpdemux/demuxer.h"
 
 static int
 rtp_streaming_read (int fd, char *buffer,
@@ -67,6 +68,9 @@
 rtp_stream_open (stream_t *stream, int mode, void *opts, int *file_format)
 {
   URL_t *url;
+  struct rtpheader rh;
+  char *data;
+  int len;
   extern int network_bandwidth;
   
   mp_msg (MSGT_OPEN, MSGL_INFO, "STREAM_RTP, URL: %s\n", stream->url);
@@ -99,6 +103,15 @@
 
   stream->type = STREAMTYPE_STREAM;
   fixup_network_stream_cache (stream);
+
+  /* grab a packet and determine if we can hint the type */
+  getrtp2(stream->fd, &rh, &data, &len);
+
+  if (rh.b.pt == 32)
+	*file_format = DEMUXER_TYPE_MPEG_ES;
+
+  if (rh.b.pt == 9)
+	*file_format = DEMUXER_TYPE_RAWAUDIO;
   
   return STREAM_OK;
 }



More information about the MPlayer-dev-eng mailing list