annotate libmpdemux/rtp.c @ 15585:281d155fb37f

ported all network streams to the new API
author nicodvb
date Sun, 29 May 2005 12:54:00 +0000
parents 8dd7a656eaf8
children 5dcc5524cb68
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>
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
14 #include <ctype.h>
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
15 #include "config.h"
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
16 #ifndef HAVE_WINSOCK2
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
17 #include <netinet/in.h>
3686
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
18 #include <sys/socket.h>
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
19 #include <arpa/inet.h>
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
20 #define closesocket close
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
21 #else
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
22 #include <winsock2.h>
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
23 #include <ws2tcpip.h>
54bcbf28698a Networking support under MinGW.
diego
parents: 7472
diff changeset
24 #endif
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
25 #include <errno.h>
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
26 #include "stream.h"
3686
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
27
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
28 /* MPEG-2 TS RTP stack */
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 #define DEBUG 1
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
31 #include "rtp.h"
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
32
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
33 extern int network_bandwidth;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
34
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
35 int read_rtp_from_server(int fd, char *buffer, int length) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
36 struct rtpheader rh;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
37 char *data;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
38 int len;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
39 static int got_first = 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
40 static unsigned short sequence;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
41
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
42 if( buffer==NULL || length<0 ) return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
43
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
44 getrtp2(fd, &rh, &data, &len);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
45 if( got_first && rh.b.sequence != (unsigned short)(sequence+1) )
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
46 mp_msg(MSGT_NETWORK,MSGL_ERR,"RTP packet sequence error! Expected: %d, received: %d\n",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
47 sequence+1, rh.b.sequence);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
48 got_first = 1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
49 sequence = rh.b.sequence;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
50 memcpy(buffer, data, len);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
51 return(len);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
52 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
53
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
54
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
55 // Start listening on a UDP port. If multicast, join the group.
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
56 static int rtp_open_socket( URL_t *url ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
57 int socket_server_fd, rxsockbufsz;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
58 int err, err_len;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
59 fd_set set;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
60 struct sockaddr_in server_address;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
61 struct ip_mreq mcast;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
62 struct timeval tv;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
63 struct hostent *hp;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
64
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
65 mp_msg(MSGT_NETWORK,MSGL_V,"Listening for traffic on %s:%d ...\n", url->hostname, url->port );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
66
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
67 socket_server_fd = socket(AF_INET, SOCK_DGRAM, 0);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
68 // fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
69 if( socket_server_fd==-1 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
70 mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to create socket\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
71 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
72 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
73
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
74 if( isalpha(url->hostname[0]) ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
75 #ifndef HAVE_WINSOCK2
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
76 hp =(struct hostent*)gethostbyname( url->hostname );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
77 if( hp==NULL ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
78 mp_msg(MSGT_NETWORK,MSGL_ERR,"Counldn't resolve name: %s\n", url->hostname);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
79 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
80 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
81 memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
82 #else
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
83 server_address.sin_addr.s_addr = htonl(INADDR_ANY);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
84 #endif
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
85 } else {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
86 #ifndef HAVE_WINSOCK2
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
87 #ifdef USE_ATON
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
88 inet_aton(url->hostname, &server_address.sin_addr);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
89 #else
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
90 inet_pton(AF_INET, url->hostname, &server_address.sin_addr);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
91 #endif
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
92 #else
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
93 server_address.sin_addr.s_addr = htonl(INADDR_ANY);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
94 #endif
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
95 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
96 server_address.sin_family=AF_INET;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
97 server_address.sin_port=htons(url->port);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
98
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
99 if( bind( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
100 #ifndef HAVE_WINSOCK2
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
101 if( errno!=EINPROGRESS ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
102 #else
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
103 if( WSAGetLastError() != WSAEINPROGRESS ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
104 #endif
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
105 mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to connect to server\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
106 closesocket(socket_server_fd);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
107 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
108 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
109 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
110
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
111 #ifdef HAVE_WINSOCK2
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
112 if (isalpha(url->hostname[0])) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
113 hp =(struct hostent*)gethostbyname( url->hostname );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
114 if( hp==NULL ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
115 mp_msg(MSGT_NETWORK,MSGL_ERR,"Counldn't resolve name: %s\n", url->hostname);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
116 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
117 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
118 memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
119 } else {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
120 unsigned int addr = inet_addr(url->hostname);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
121 memcpy( (void*)&server_address.sin_addr, (void*)&addr, sizeof(addr) );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
122 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
123 #endif
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
124
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
125 // Increase the socket rx buffer size to maximum -- this is UDP
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
126 rxsockbufsz = 240 * 1024;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
127 if( setsockopt( socket_server_fd, SOL_SOCKET, SO_RCVBUF, &rxsockbufsz, sizeof(rxsockbufsz))) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
128 mp_msg(MSGT_NETWORK,MSGL_ERR,"Couldn't set receive socket buffer size\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
129 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
130
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
131 if((ntohl(server_address.sin_addr.s_addr) >> 28) == 0xe) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
132 mcast.imr_multiaddr.s_addr = server_address.sin_addr.s_addr;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
133 //mcast.imr_interface.s_addr = inet_addr("10.1.1.2");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
134 mcast.imr_interface.s_addr = 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
135 if( setsockopt( socket_server_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mcast, sizeof(mcast))) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
136 mp_msg(MSGT_NETWORK,MSGL_ERR,"IP_ADD_MEMBERSHIP failed (do you have multicasting enabled in your kernel?)\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
137 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
138 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
139 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
140
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
141 tv.tv_sec = 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
142 tv.tv_usec = (1 * 1000000); // 1 second timeout
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
143 FD_ZERO( &set );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
144 FD_SET( socket_server_fd, &set );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
145 if( select(socket_server_fd+1, &set, NULL, NULL, &tv)>0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
146 //if( select(socket_server_fd+1, &set, NULL, NULL, NULL)>0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
147 err_len = sizeof( err );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
148 getsockopt( socket_server_fd, SOL_SOCKET, SO_ERROR, &err, &err_len );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
149 if( err ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
150 mp_msg(MSGT_NETWORK,MSGL_ERR,"Timeout! No data from host %s\n", url->hostname );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
151 mp_msg(MSGT_NETWORK,MSGL_DBG2,"Socket error: %d\n", err );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
152 closesocket(socket_server_fd);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
153 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
154 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
155 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
156 return socket_server_fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
157 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
158
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
159 static int rtp_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *streaming_ctrl ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
160 return read_rtp_from_server( fd, buffer, size );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
161 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
162
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
163 static int rtp_streaming_start( stream_t *stream, int raw_udp ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
164 streaming_ctrl_t *streaming_ctrl;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
165 int fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
166
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
167 if( stream==NULL ) return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
168 streaming_ctrl = stream->streaming_ctrl;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
169 fd = stream->fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
170
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
171 if( fd<0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
172 fd = rtp_open_socket( (streaming_ctrl->url) );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
173 if( fd<0 ) return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
174 stream->fd = fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
175 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
176
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
177 if(raw_udp)
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
178 streaming_ctrl->streaming_read = nop_streaming_read;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
179 else
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
180 streaming_ctrl->streaming_read = rtp_streaming_read;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
181 streaming_ctrl->streaming_seek = nop_streaming_seek;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
182 streaming_ctrl->prebuffer_size = 64*1024; // 64 KBytes
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
183 streaming_ctrl->buffering = 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
184 streaming_ctrl->status = streaming_playing_e;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
185 return 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
186 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
187
3686
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
188
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
189 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
190 static char buf[1600];
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
191 unsigned int intP;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
192 char* charP = (char*) &intP;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
193 int headerSize;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
194 int lengthPacket;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
195 lengthPacket=recv(fd,buf,1590,0);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
196 if (lengthPacket==0)
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
197 exit(1);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
198 if (lengthPacket<0) {
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
199 fprintf(stderr,"socket read error\n");
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
200 exit(2);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
201 }
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
202 if (lengthPacket<12) {
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
203 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
204 exit(3);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
205 }
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
206 rh->b.v = (unsigned int) ((buf[0]>>6)&0x03);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
207 rh->b.p = (unsigned int) ((buf[0]>>5)&0x01);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
208 rh->b.x = (unsigned int) ((buf[0]>>4)&0x01);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
209 rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
210 rh->b.m = (unsigned int) ((buf[1]>>7)&0x01);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
211 rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
212 intP = 0;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
213 memcpy(charP+2,&buf[2],2);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
214 rh->b.sequence = ntohl(intP);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
215 intP = 0;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
216 memcpy(charP,&buf[4],4);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
217 rh->timestamp = ntohl(intP);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
218
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
219 headerSize = 12 + 4*rh->b.cc; /* in bytes */
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
220
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
221 *lengthData = lengthPacket - headerSize;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
222 *data = (char*) buf + headerSize;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
223
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
224 // 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
225
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
226 return(0);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
227 }
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
228
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
229
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
230 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
231 URL_t *url;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
232 int udp = 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
233
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
234 mp_msg(MSGT_OPEN, MSGL_INFO, "STREAM_RTP, URL: %s\n", stream->url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
235 stream->streaming_ctrl = streaming_ctrl_new();
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
236 if( stream->streaming_ctrl==NULL ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
237 return STREAM_ERROR;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
238 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
239 stream->streaming_ctrl->bandwidth = network_bandwidth;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
240 url = url_new(stream->url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
241 stream->streaming_ctrl->url = check4proxies(url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
242
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
243 if( url->port==0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
244 mp_msg(MSGT_NETWORK,MSGL_ERR,"You must enter a port number for RTP and UDP streams!\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
245 goto fail;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
246 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
247 if(!strncmp(stream->url, "udp", 3))
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
248 udp = 1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
249
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
250 if(rtp_streaming_start(stream, udp) < 0) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
251 mp_msg(MSGT_NETWORK,MSGL_ERR,"rtp_streaming_start(rtp) failed\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
252 goto fail;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
253 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
254
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
255 stream->type = STREAMTYPE_STREAM;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
256 fixup_network_stream_cache(stream);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
257 return STREAM_OK;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
258
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
259 fail:
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
260 streaming_ctrl_free( stream->streaming_ctrl );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
261 stream->streaming_ctrl = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
262 return STREAM_UNSUPORTED;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
263 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
264
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
265
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
266 stream_info_t stream_info_rtp_udp = {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
267 "mpeg rtp and upd streaming",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
268 "rtp and udp",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
269 "Dave Chapman",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
270 "native rtp support",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
271 open_s,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
272 {"rtp", "udp", NULL},
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
273 NULL,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
274 0 // Urls are an option string
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
275 };
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
276
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
277