annotate libmpdemux/rtp.c @ 17131:80d3fdcf58a8

option to show the lines containing anomalies, patch by Ivo van Poorten
author wanderer
date Wed, 07 Dec 2005 18:11:58 +0000
parents 5dcc5524cb68
children 028e4c7a749e
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);
15760
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
79 goto err_out;
15585
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");
15760
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
106 goto err_out;
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
107 }
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 #ifdef HAVE_WINSOCK2
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
111 if (isalpha(url->hostname[0])) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
112 hp =(struct hostent*)gethostbyname( url->hostname );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
113 if( hp==NULL ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
114 mp_msg(MSGT_NETWORK,MSGL_ERR,"Counldn't resolve name: %s\n", url->hostname);
15760
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
115 goto err_out;
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
116 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
117 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
118 } else {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
119 unsigned int addr = inet_addr(url->hostname);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
120 memcpy( (void*)&server_address.sin_addr, (void*)&addr, sizeof(addr) );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
121 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
122 #endif
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
123
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
124 // 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
125 rxsockbufsz = 240 * 1024;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
126 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
127 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
128 }
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 if((ntohl(server_address.sin_addr.s_addr) >> 28) == 0xe) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
131 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
132 //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
133 mcast.imr_interface.s_addr = 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
134 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
135 mp_msg(MSGT_NETWORK,MSGL_ERR,"IP_ADD_MEMBERSHIP failed (do you have multicasting enabled in your kernel?)\n");
15760
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
136 goto err_out;
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
137 }
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 tv.tv_sec = 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
141 tv.tv_usec = (1 * 1000000); // 1 second timeout
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
142 FD_ZERO( &set );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
143 FD_SET( socket_server_fd, &set );
15760
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
144 err = select(socket_server_fd+1, &set, NULL, NULL, &tv);
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
145 if (err < 0) {
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
146 mp_msg(MSGT_NETWORK, MSGL_FATAL, "Select failed: %s\n", strerror(errno));
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
147 goto err_out;
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
148 }
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
149 if (err == 0) {
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
150 mp_msg(MSGT_NETWORK,MSGL_ERR,"Timeout! No data from host %s\n", url->hostname );
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
151 goto err_out;
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
152 }
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
153 err_len = sizeof( err );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
154 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
155 if( err ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
156 mp_msg(MSGT_NETWORK,MSGL_DBG2,"Socket error: %d\n", err );
15760
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
157 goto err_out;
15585
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 return socket_server_fd;
15760
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
160
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
161 err_out:
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
162 closesocket(socket_server_fd);
5dcc5524cb68 fix wrong usage of select() (based on patch by Selwyn Tang selwyn hectrix com),
reimar
parents: 15585
diff changeset
163 return -1;
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
164 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
165
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
166 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
167 return read_rtp_from_server( fd, buffer, size );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
168 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
169
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
170 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
171 streaming_ctrl_t *streaming_ctrl;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
172 int fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
173
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
174 if( stream==NULL ) return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
175 streaming_ctrl = stream->streaming_ctrl;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
176 fd = stream->fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
177
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
178 if( fd<0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
179 fd = rtp_open_socket( (streaming_ctrl->url) );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
180 if( fd<0 ) return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
181 stream->fd = fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
182 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
183
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
184 if(raw_udp)
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
185 streaming_ctrl->streaming_read = nop_streaming_read;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
186 else
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
187 streaming_ctrl->streaming_read = rtp_streaming_read;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
188 streaming_ctrl->streaming_seek = nop_streaming_seek;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
189 streaming_ctrl->prebuffer_size = 64*1024; // 64 KBytes
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
190 streaming_ctrl->buffering = 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
191 streaming_ctrl->status = streaming_playing_e;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
192 return 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
193 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
194
3686
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
195
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
196 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
197 static char buf[1600];
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
198 unsigned int intP;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
199 char* charP = (char*) &intP;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
200 int headerSize;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
201 int lengthPacket;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
202 lengthPacket=recv(fd,buf,1590,0);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
203 if (lengthPacket==0)
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
204 exit(1);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
205 if (lengthPacket<0) {
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
206 fprintf(stderr,"socket read error\n");
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
207 exit(2);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
208 }
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
209 if (lengthPacket<12) {
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
210 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
211 exit(3);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
212 }
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
213 rh->b.v = (unsigned int) ((buf[0]>>6)&0x03);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
214 rh->b.p = (unsigned int) ((buf[0]>>5)&0x01);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
215 rh->b.x = (unsigned int) ((buf[0]>>4)&0x01);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
216 rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
217 rh->b.m = (unsigned int) ((buf[1]>>7)&0x01);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
218 rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
219 intP = 0;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
220 memcpy(charP+2,&buf[2],2);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
221 rh->b.sequence = ntohl(intP);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
222 intP = 0;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
223 memcpy(charP,&buf[4],4);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
224 rh->timestamp = ntohl(intP);
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 headerSize = 12 + 4*rh->b.cc; /* in bytes */
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 *lengthData = lengthPacket - headerSize;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
229 *data = (char*) buf + headerSize;
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
230
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
231 // 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
232
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
233 return(0);
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
234 }
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
235
bed6226ffb46 RTP support patch by Brian Kuschak <bkuschak@yahoo.com>
arpi
parents:
diff changeset
236
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
237 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
238 URL_t *url;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
239 int udp = 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
240
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
241 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
242 stream->streaming_ctrl = streaming_ctrl_new();
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
243 if( stream->streaming_ctrl==NULL ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
244 return STREAM_ERROR;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
245 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
246 stream->streaming_ctrl->bandwidth = network_bandwidth;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
247 url = url_new(stream->url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
248 stream->streaming_ctrl->url = check4proxies(url);
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( url->port==0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
251 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
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 if(!strncmp(stream->url, "udp", 3))
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
255 udp = 1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
256
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
257 if(rtp_streaming_start(stream, udp) < 0) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
258 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
259 goto fail;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
260 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
261
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
262 stream->type = STREAMTYPE_STREAM;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
263 fixup_network_stream_cache(stream);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
264 return STREAM_OK;
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 fail:
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
267 streaming_ctrl_free( stream->streaming_ctrl );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
268 stream->streaming_ctrl = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
269 return STREAM_UNSUPORTED;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
270 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
271
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
272
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
273 stream_info_t stream_info_rtp_udp = {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
274 "mpeg rtp and upd streaming",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
275 "rtp and udp",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
276 "Dave Chapman",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
277 "native rtp support",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
278 open_s,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
279 {"rtp", "udp", NULL},
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
280 NULL,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
281 0 // Urls are an option string
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
282 };
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
283
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15178
diff changeset
284