2001-12-23 22:09:02 +00:00
|
|
|
/* Imported from the dvbstream-0.2 project */
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2003-06-11 16:48:09 +00:00
|
|
|
#include "config.h"
|
|
|
|
#ifndef HAVE_WINSOCK2
|
|
|
|
#include <netinet/in.h>
|
2001-12-23 22:09:02 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <arpa/inet.h>
|
2003-06-11 16:48:09 +00:00
|
|
|
#else
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#endif
|
2001-12-23 22:09:02 +00:00
|
|
|
|
|
|
|
/* MPEG-2 TS RTP stack */
|
|
|
|
|
|
|
|
#define DEBUG 1
|
|
|
|
#include "rtp.h"
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
exit(1);
|
|
|
|
if (lengthPacket<0) {
|
|
|
|
fprintf(stderr,"socket read error\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
if (lengthPacket<12) {
|
|
|
|
fprintf(stderr,"packet too small (%d) to be an rtp frame (>12bytes)\n", lengthPacket);
|
|
|
|
exit(3);
|
|
|
|
}
|
|
|
|
rh->b.v = (unsigned int) ((buf[0]>>6)&0x03);
|
|
|
|
rh->b.p = (unsigned int) ((buf[0]>>5)&0x01);
|
|
|
|
rh->b.x = (unsigned int) ((buf[0]>>4)&0x01);
|
|
|
|
rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f);
|
|
|
|
rh->b.m = (unsigned int) ((buf[1]>>7)&0x01);
|
|
|
|
rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f);
|
|
|
|
intP = 0;
|
|
|
|
memcpy(charP+2,&buf[2],2);
|
|
|
|
rh->b.sequence = ntohl(intP);
|
|
|
|
intP = 0;
|
|
|
|
memcpy(charP,&buf[4],4);
|
|
|
|
rh->timestamp = ntohl(intP);
|
|
|
|
|
|
|
|
headerSize = 12 + 4*rh->b.cc; /* in bytes */
|
|
|
|
|
|
|
|
*lengthData = lengthPacket - headerSize;
|
|
|
|
*data = (char*) buf + headerSize;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|