3686
|
1 /* Imported from the dvbstream-0.2 project */
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
3716
|
4 #include <unistd.h>
|
3686
|
5 #include <stdlib.h>
|
|
6 #include <stdio.h>
|
|
7 #include <sys/types.h>
|
10281
|
8 #include "config.h"
|
|
9 #ifndef HAVE_WINSOCK2
|
|
10 #include <netinet/in.h>
|
3686
|
11 #include <sys/socket.h>
|
|
12 #include <arpa/inet.h>
|
10281
|
13 #else
|
|
14 #include <winsock2.h>
|
|
15 #include <ws2tcpip.h>
|
|
16 #endif
|
3686
|
17
|
|
18 /* MPEG-2 TS RTP stack */
|
|
19
|
|
20 #define DEBUG 1
|
|
21 #include "rtp.h"
|
|
22
|
|
23
|
|
24 int getrtp2(int fd, struct rtpheader *rh, char** data, int* lengthData) {
|
|
25 static char buf[1600];
|
|
26 unsigned int intP;
|
|
27 char* charP = (char*) &intP;
|
|
28 int headerSize;
|
|
29 int lengthPacket;
|
|
30 lengthPacket=recv(fd,buf,1590,0);
|
|
31 if (lengthPacket==0)
|
|
32 exit(1);
|
|
33 if (lengthPacket<0) {
|
|
34 fprintf(stderr,"socket read error\n");
|
|
35 exit(2);
|
|
36 }
|
|
37 if (lengthPacket<12) {
|
|
38 fprintf(stderr,"packet too small (%d) to be an rtp frame (>12bytes)\n", lengthPacket);
|
|
39 exit(3);
|
|
40 }
|
|
41 rh->b.v = (unsigned int) ((buf[0]>>6)&0x03);
|
|
42 rh->b.p = (unsigned int) ((buf[0]>>5)&0x01);
|
|
43 rh->b.x = (unsigned int) ((buf[0]>>4)&0x01);
|
|
44 rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f);
|
|
45 rh->b.m = (unsigned int) ((buf[1]>>7)&0x01);
|
|
46 rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f);
|
|
47 intP = 0;
|
|
48 memcpy(charP+2,&buf[2],2);
|
|
49 rh->b.sequence = ntohl(intP);
|
|
50 intP = 0;
|
|
51 memcpy(charP,&buf[4],4);
|
|
52 rh->timestamp = ntohl(intP);
|
|
53
|
|
54 headerSize = 12 + 4*rh->b.cc; /* in bytes */
|
|
55
|
|
56 *lengthData = lengthPacket - headerSize;
|
|
57 *data = (char*) buf + headerSize;
|
|
58
|
|
59 // 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);
|
|
60
|
|
61 return(0);
|
|
62 }
|
|
63
|
|
64
|