mirror of
https://github.com/mpv-player/mpv
synced 2024-12-18 21:06:00 +00:00
Make rtp:// cohexist with LIVE.COM
Patch by Nico Sabbi git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@12800 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
1772486e47
commit
18557ad90b
@ -8,7 +8,7 @@ ifeq ($(XMMS_PLUGINS),yes)
|
||||
SRCS += demux_xmms.c
|
||||
endif
|
||||
ifeq ($(MPLAYER_NETWORK),yes)
|
||||
SRCS += asf_streaming.c http.c network.c cookies.c asf_mmst_streaming.c pnm.c
|
||||
SRCS += asf_streaming.c http.c network.c cookies.c asf_mmst_streaming.c pnm.c rtp.c
|
||||
SRCS += realrtsp/asmrp.c realrtsp/real.c realrtsp/rmff.c realrtsp/rtsp.c realrtsp/rtsp_session.c realrtsp/sdpplin.c realrtsp/xbuffer.c
|
||||
ifeq ($(STREAMING_LIVE_DOT_COM),yes)
|
||||
CPLUSPLUSSRCS = demux_rtp.cpp demux_rtp_codec.cpp
|
||||
@ -16,8 +16,6 @@ CPLUSPLUSINCLUDE = -I$(LIVE_LIB_DIR)/liveMedia/include
|
||||
CPLUSPLUSINCLUDE += -I$(LIVE_LIB_DIR)/UsageEnvironment/include
|
||||
CPLUSPLUSINCLUDE += -I$(LIVE_LIB_DIR)/BasicUsageEnvironment/include
|
||||
CPLUSPLUSINCLUDE += -I$(LIVE_LIB_DIR)/groupsock/include
|
||||
else
|
||||
SRCS += rtp.c
|
||||
endif
|
||||
endif
|
||||
|
||||
|
@ -32,9 +32,7 @@
|
||||
#include "cookies.h"
|
||||
#include "url.h"
|
||||
#include "asf.h"
|
||||
#ifndef STREAMING_LIVE_DOT_COM
|
||||
#include "rtp.h"
|
||||
#endif
|
||||
#include "pnm.h"
|
||||
#include "realrtsp/rtsp_session.h"
|
||||
|
||||
@ -149,7 +147,6 @@ streaming_ctrl_free( streaming_ctrl_t *streaming_ctrl ) {
|
||||
free( streaming_ctrl );
|
||||
}
|
||||
|
||||
#ifndef STREAMING_LIVE_DOT_COM
|
||||
int
|
||||
read_rtp_from_server(int fd, char *buffer, int length) {
|
||||
struct rtpheader rh;
|
||||
@ -169,7 +166,6 @@ read_rtp_from_server(int fd, char *buffer, int length) {
|
||||
memcpy(buffer, data, len);
|
||||
return(len);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Converts an address family constant to a string
|
||||
@ -704,8 +700,7 @@ extension=NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef STREAMING_LIVE_DOT_COM
|
||||
// Old, hacked RTP support, which works for MPEG Program Streams
|
||||
// Old, hacked RTP support, which works for MPEG Streams
|
||||
// RTP streams only:
|
||||
// Checking for RTP
|
||||
if( !strcasecmp(url->protocol, "rtp") ) {
|
||||
@ -715,7 +710,6 @@ extension=NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Checking for ASF
|
||||
if( !strncasecmp(url->protocol, "mms", 3) ) {
|
||||
@ -1075,9 +1069,8 @@ realrtsp_streaming_start( stream_t *stream ) {
|
||||
}
|
||||
|
||||
|
||||
#ifndef STREAMING_LIVE_DOT_COM
|
||||
// Start listening on a UDP port. If multicast, join the group.
|
||||
int
|
||||
static int
|
||||
rtp_open_socket( URL_t *url ) {
|
||||
int socket_server_fd, rxsockbufsz;
|
||||
int err, err_len;
|
||||
@ -1181,12 +1174,12 @@ rtp_open_socket( URL_t *url ) {
|
||||
return socket_server_fd;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
rtp_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *streaming_ctrl ) {
|
||||
return read_rtp_from_server( fd, buffer, size );
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
rtp_streaming_start( stream_t *stream ) {
|
||||
streaming_ctrl_t *streaming_ctrl;
|
||||
int fd;
|
||||
@ -1208,7 +1201,6 @@ rtp_streaming_start( stream_t *stream ) {
|
||||
streaming_ctrl->status = streaming_playing_e;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
streaming_start(stream_t *stream, int *demuxer_type, URL_t *url) {
|
||||
@ -1240,7 +1232,6 @@ streaming_start(stream_t *stream, int *demuxer_type, URL_t *url) {
|
||||
// Get the bandwidth available
|
||||
stream->streaming_ctrl->bandwidth = network_bandwidth;
|
||||
|
||||
#ifndef STREAMING_LIVE_DOT_COM
|
||||
// For RTP streams, we usually don't know the stream type until we open it.
|
||||
if( !strcasecmp( stream->streaming_ctrl->url->protocol, "rtp")) {
|
||||
if(stream->fd >= 0) {
|
||||
@ -1250,7 +1241,6 @@ streaming_start(stream_t *stream, int *demuxer_type, URL_t *url) {
|
||||
stream->fd = -1;
|
||||
ret = rtp_streaming_start( stream );
|
||||
} else
|
||||
#endif
|
||||
|
||||
if( !strcasecmp( stream->streaming_ctrl->url->protocol, "pnm")) {
|
||||
stream->fd = -1;
|
||||
|
136
libmpdemux/rtp.c
136
libmpdemux/rtp.c
@ -20,30 +20,6 @@
|
||||
#define DEBUG 1
|
||||
#include "rtp.h"
|
||||
|
||||
void initrtp(struct rtpheader *foo) { /* fill in the MPEG-2 TS deefaults */
|
||||
/* Note: MPEG-2 TS defines a timestamping base frequency of 90000 Hz. */
|
||||
foo->b.v=2;
|
||||
foo->b.p=0;
|
||||
foo->b.x=0;
|
||||
foo->b.cc=0;
|
||||
foo->b.m=0;
|
||||
foo->b.pt=33; /* MPEG-2 TS */
|
||||
foo->b.sequence=rand() & 65535;
|
||||
foo->timestamp=rand();
|
||||
foo->ssrc=rand();
|
||||
}
|
||||
|
||||
/* Send a single RTP packet, converting the RTP header to network byte order. */
|
||||
int sendrtp(int fd, struct sockaddr_in *sSockAddr, struct rtpheader *foo, char *data, int len) {
|
||||
char *buf=(char*)alloca(len+sizeof(struct rtpheader));
|
||||
int *cast=(int *)foo;
|
||||
int *outcast=(int *)buf;
|
||||
outcast[0]=htonl(cast[0]);
|
||||
outcast[1]=htonl(cast[1]);
|
||||
memmove(outcast+2,data,len);
|
||||
fprintf(stderr,"v=%x %x\n",foo->b.v,buf[0]);
|
||||
return sendto(fd,buf,len+3,0,(struct sockaddr *)sSockAddr,sizeof(*sSockAddr));
|
||||
}
|
||||
|
||||
int getrtp2(int fd, struct rtpheader *rh, char** data, int* lengthData) {
|
||||
static char buf[1600];
|
||||
@ -85,116 +61,4 @@ int getrtp2(int fd, struct rtpheader *rh, char** data, int* lengthData) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Send a single RTP packet, converting the RTP header to network byte order. */
|
||||
int sendrtp2(int fd, struct sockaddr_in *sSockAddr, struct rtpheader *foo, char *data, int len) {
|
||||
char *buf=(char*)alloca(len+72);
|
||||
unsigned int intP;
|
||||
char* charP = (char*) &intP;
|
||||
int headerSize;
|
||||
buf[0] = 0x00;
|
||||
buf[0] |= ((((char) foo->b.v)<<6)&0xc0);
|
||||
buf[0] |= ((((char) foo->b.p)<<5)&0x20);
|
||||
buf[0] |= ((((char) foo->b.x)<<4)&0x10);
|
||||
buf[0] |= ((((char) foo->b.cc)<<0)&0x0f);
|
||||
buf[1] = 0x00;
|
||||
buf[1] |= ((((char) foo->b.m)<<7)&0x80);
|
||||
buf[1] |= ((((char) foo->b.pt)<<0)&0x7f);
|
||||
intP = htonl(foo->b.sequence);
|
||||
memcpy(&buf[2],charP+2,2);
|
||||
intP = htonl(foo->timestamp);
|
||||
memcpy(&buf[4],&intP,4);
|
||||
/* SSRC: not implemented */
|
||||
buf[8] = 0x0f;
|
||||
buf[9] = 0x0f;
|
||||
buf[10] = 0x0f;
|
||||
buf[11] = 0x0f;
|
||||
headerSize = 12 + 4*foo->b.cc; /* in bytes */
|
||||
memcpy(buf+headerSize,data,len);
|
||||
|
||||
// fprintf(stderr,"Sending rtp: v=%x p=%x x=%x cc=%x m=%x pt=%x seq=%x ts=%x lgth=%d\n",foo->b.v,foo->b.p,foo->b.x,foo->b.cc,foo->b.m,foo->b.pt,foo->b.sequence,foo->timestamp,len+headerSize);
|
||||
|
||||
foo->b.sequence++;
|
||||
return sendto(fd,buf,len+headerSize,0,(struct sockaddr *)sSockAddr,sizeof(*sSockAddr));
|
||||
}
|
||||
|
||||
|
||||
int getrtp(int fd, struct rtpheader *rh, char** data, int* lengthData) {
|
||||
static char buf[1600];
|
||||
int headerSize;
|
||||
int lengthPacket;
|
||||
|
||||
lengthPacket=recv(fd,buf,1590,0);
|
||||
// FIXME: error handling to write here
|
||||
headerSize = 3;
|
||||
*lengthData = lengthPacket - headerSize;
|
||||
*data = (char*) buf + headerSize;
|
||||
fprintf(stderr,"[%d] %02x %x\n",lengthPacket,buf[8],buf[0]);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* create a sender socket. */
|
||||
int makesocket(char *szAddr,unsigned short port,int TTL,struct sockaddr_in *sSockAddr) {
|
||||
int iRet, iLoop = 1;
|
||||
struct sockaddr_in sin;
|
||||
char cTtl = (char)TTL;
|
||||
char cLoop=0;
|
||||
|
||||
int iSocket = socket( AF_INET, SOCK_DGRAM, 0 );
|
||||
|
||||
if (iSocket < 0) {
|
||||
fprintf(stderr,"socket() failed.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sSockAddr->sin_family = sin.sin_family = AF_INET;
|
||||
sSockAddr->sin_port = sin.sin_port = htons(port);
|
||||
sSockAddr->sin_addr.s_addr = inet_addr(szAddr);
|
||||
|
||||
iRet = setsockopt(iSocket, SOL_SOCKET, SO_REUSEADDR, &iLoop, sizeof(int));
|
||||
if (iRet < 0) {
|
||||
fprintf(stderr,"setsockopt SO_REUSEADDR failed\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
iRet = setsockopt(iSocket, IPPROTO_IP, IP_MULTICAST_TTL, &cTtl, sizeof(char));
|
||||
if (iRet < 0) {
|
||||
fprintf(stderr,"setsockopt IP_MULTICAST_TTL failed. multicast in kernel?\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cLoop = 1; /* !? */
|
||||
iRet = setsockopt(iSocket, IPPROTO_IP, IP_MULTICAST_LOOP,
|
||||
&cLoop, sizeof(char));
|
||||
if (iRet < 0) {
|
||||
fprintf(stderr,"setsockopt IP_MULTICAST_LOOP failed. multicast in kernel?\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return iSocket;
|
||||
}
|
||||
|
||||
/* create a receiver socket, i.e. join the multicast group. */
|
||||
int makeclientsocket(char *szAddr,unsigned short port,int TTL,struct sockaddr_in *sSockAddr) {
|
||||
int socket=makesocket(szAddr,port,TTL,sSockAddr);
|
||||
struct ip_mreq blub;
|
||||
struct sockaddr_in sin;
|
||||
unsigned int tempaddr;
|
||||
sin.sin_family=AF_INET;
|
||||
sin.sin_port=htons(port);
|
||||
sin.sin_addr.s_addr=inet_addr(szAddr);
|
||||
if (bind(socket,(struct sockaddr *) &sin,sizeof(sin))) {
|
||||
perror("bind failed");
|
||||
exit(1);
|
||||
}
|
||||
tempaddr=inet_addr(szAddr);
|
||||
if ((ntohl(tempaddr) >> 28) == 0xe) {
|
||||
blub.imr_multiaddr.s_addr = inet_addr(szAddr);
|
||||
blub.imr_interface.s_addr = 0;
|
||||
if (setsockopt(socket,IPPROTO_IP,IP_ADD_MEMBERSHIP,&blub,sizeof(blub))) {
|
||||
perror("setsockopt IP_ADD_MEMBERSHIP failed (multicast kernel?)");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
return socket;
|
||||
}
|
||||
|
||||
|
@ -25,12 +25,6 @@ struct rtpheader { /* in network byte order */
|
||||
};
|
||||
|
||||
|
||||
void initrtp(struct rtpheader *foo); /* fill in the MPEG-2 TS deefaults */
|
||||
int sendrtp(int fd, struct sockaddr_in *sSockAddr, struct rtpheader *foo, char *data, int len);
|
||||
int getrtp2(int fd, struct rtpheader *rh, char** data, int* lengthData);
|
||||
int sendrtp2(int fd, struct sockaddr_in *sSockAddr, struct rtpheader *foo, char *data, int len);
|
||||
int getrtp(int fd, struct rtpheader *rh, char** data, int* lengthData);
|
||||
int makesocket(char *szAddr,unsigned short port,int TTL,struct sockaddr_in *sSockAddr);
|
||||
int makeclientsocket(char *szAddr,unsigned short port,int TTL,struct sockaddr_in *sSockAddr);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user