annotate libmpdemux/rtp.c @ 15178:8dd7a656eaf8

Mark modified imported files as such to comply more closely with GPL ¡ø2a.
author diego
date Sat, 16 Apr 2005 12:51:09 +0000
parents befb79b0232e
children 281d155fb37f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15178
8dd7a656eaf8 Mark modified imported files as such to comply more closely with GPL ¡ø2a.
diego
parents: 12799
diff changeset
1 /* Imported from the dvbstream-0.2 project
8dd7a656eaf8 Mark modified imported files as such to comply more closely with GPL ¡ø2a.
diego
parents: 12799
diff changeset
2 *
8dd7a656eaf8 Mark modified imported files as such to comply more closely with GPL ¡ø2a.
diego
parents: 12799
diff changeset
3 * Modified for use with MPlayer, for details see the CVS changelog at
8dd7a656eaf8 Mark modified imported files as such to comply more closely with GPL ¡ø2a.
diego
parents: 12799
diff changeset
4 * http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
8dd7a656eaf8 Mark modified imported files as such to comply more closely with GPL ¡ø2a.
diego
parents: 12799
diff changeset
5 * $Id$
8dd7a656eaf8 Mark modified imported files as such to comply more closely with GPL ¡ø2a.
diego
parents: 12799
diff changeset
6 */
8dd7a656eaf8 Mark modified imported files as such to comply more closely with GPL ¡ø2a.
diego
parents: 12799
diff changeset
7
3686
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
8 #include <stdlib.h>
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
9 #include <string.h>
3716
f3f2566fa4aa FreeBSD fix
nexus
parents: 3686
diff changeset
10 #include <unistd.h>
3686
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
11 #include <stdlib.h>
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
12 #include <stdio.h>
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
13 #include <sys/types.h>
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
14 #include "config.h"
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
15 #ifndef HAVE_WINSOCK2
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
16 #include <netinet/in.h>
3686
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
17 #include <sys/socket.h>
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
18 #include <arpa/inet.h>
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
19 #else
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
20 #include <winsock2.h>
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
21 #include <ws2tcpip.h>
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
22 #endif
3686
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
23
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
24 /* MPEG-2 TS RTP stack */
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
25
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
26 #define DEBUG 1
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
27 #include "rtp.h"
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
28
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
29
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
30 int getrtp2(int fd, struct rtpheader *rh, char** data, int* lengthData) {
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
31 static char buf[1600];
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
32 unsigned int intP;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
33 char* charP = (char*) &intP;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
34 int headerSize;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
35 int lengthPacket;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
36 lengthPacket=recv(fd,buf,1590,0);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
37 if (lengthPacket==0)
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
38 exit(1);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
39 if (lengthPacket<0) {
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
40 fprintf(stderr,"socket read error\n");
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
41 exit(2);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
42 }
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
43 if (lengthPacket<12) {
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
44 fprintf(stderr,"packet too small (%d) to be an rtp frame (>12bytes)\n", lengthPacket);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
45 exit(3);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
46 }
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
47 rh->b.v = (unsigned int) ((buf[0]>>6)&0x03);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
48 rh->b.p = (unsigned int) ((buf[0]>>5)&0x01);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
49 rh->b.x = (unsigned int) ((buf[0]>>4)&0x01);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
50 rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
51 rh->b.m = (unsigned int) ((buf[1]>>7)&0x01);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
52 rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
53 intP = 0;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
54 memcpy(charP+2,&buf[2],2);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
55 rh->b.sequence = ntohl(intP);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
56 intP = 0;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
57 memcpy(charP,&buf[4],4);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
58 rh->timestamp = ntohl(intP);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
59
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
60 headerSize = 12 + 4*rh->b.cc; /* in bytes */
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
61
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
62 *lengthData = lengthPacket - headerSize;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
63 *data = (char*) buf + headerSize;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
64
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
65 // fprintf(stderr,"Reading rtp: v=%x p=%x x=%x cc=%x m=%x pt=%x seq=%x ts=%x lgth=%d\n",rh->b.v,rh->b.p,rh->b.x,rh->b.cc,rh->b.m,rh->b.pt,rh->b.sequence,rh->timestamp,lengthPacket);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
66
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
67 return(0);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
68 }
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
69
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
70