annotate network.c @ 913:18c43d261c35

corrected strcmp() bug, now it works again with every subs (it was broken)
author laaz
date Thu, 31 May 2001 02:07:34 +0000
parents 7f6641b1b0df
children 92833c9472e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
1 /*
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
2 * Network layer for MPlayer
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
3 * by Bertrand BAUDET <bertrand_baudet@yahoo.com>
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
4 * (C) 2001, MPlayer team.
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
5 */
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
6
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
7 #include <unistd.h>
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
8 #include <netinet/in.h>
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
9 #include <netdb.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
10 #include <sys/types.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
11 #include <sys/socket.h>
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
12 #include <arpa/inet.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
13
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
14 #include <ctype.h>
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
15 #include <string.h>
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
16 #include <stdlib.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
17 #include <stdio.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
18
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
19 #include "network.h"
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
20 #include "http.h"
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
21 #include "url.h"
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
22 #include "asf.h"
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
23
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
24 // Connect to a server using a TCP connection
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
25 int
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
26 connect2Server(char *host, int port) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
27 int socket_server_fd;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
28 struct sockaddr_in server_address;
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
29 printf("Connecting to server %s:%d ...\n", host, port );
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
30 socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
31 if( socket_server_fd==-1 ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
32 perror("Failed to create socket");
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
33 return -1;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
34 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
35
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
36 if( isalpha(host[0]) ) {
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
37 struct hostent *hp =(struct hostent*)gethostbyname( host );
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
38 if( hp==NULL ) {
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
39 printf("Unknown host: %s\n", host);
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
40 return -1;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
41 }
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
42 memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
43 } else {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
44 inet_pton(AF_INET, host, &server_address.sin_addr);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
45 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
46 server_address.sin_family=AF_INET;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
47 server_address.sin_port=htons(port);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
48
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
49 if( connect( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
50 perror("Failed to connect to server");
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
51 close(socket_server_fd);
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
52 return -1;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
53 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
54 return socket_server_fd;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
55 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
56
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
57 // By using the protocol, the extension of the file or the content-type
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
58 // we might be able to guess the streaming type.
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
59 int
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
60 autodetectProtocol(URL_t *url, int *fd_out) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
61 HTTP_header_t *http_hdr;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
62 int fd=-1;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
63 int i;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
64 char *extension;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
65 char *content_type;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
66 char *next_url;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
67 char response[1024];
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
68
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
69 redo_request:
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
70 *fd_out=-1;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
71 next_url = NULL;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
72 extension = NULL;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
73 content_type = NULL;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
74
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
75 if( url==NULL ) return STREAMING_TYPE_UNKNOWN;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
76
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
77 // Get the extension of the file if present
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
78 if( url->file!=NULL ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
79 for( i=strlen(url->file) ; i>0 ; i-- ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
80 if( url->file[i]=='.' ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
81 extension=(url->file)+i+1;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
82 break;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
83 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
84 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
85 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
86
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
87 if( extension!=NULL ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
88 printf("Extension: %s\n", extension );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
89 if( !strcasecmp(extension, "asf") ||
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
90 !strcasecmp(extension, "wmv") ||
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
91 !strcasecmp(extension, "asx") ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
92 if( url->port==0 ) url->port = 80;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
93 return STREAMING_TYPE_ASF;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
94 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
95 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
96
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
97 // Checking for RTSP
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
98 if( !strcasecmp(url->protocol, "rtsp") ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
99 printf("RTSP protocol not yet implemented!\n");
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
100 return STREAMING_TYPE_UNKNOWN;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
101 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
102
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
103 // Checking for ASF
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
104 if( !strcasecmp(url->protocol, "mms") ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
105 if( url->port==0 ) url->port = 80;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
106 return STREAMING_TYPE_ASF;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
107 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
108
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
109 // HTTP based protocol
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
110 if( !strcasecmp(url->protocol, "http") ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
111 if( url->port==0 ) url->port = 80;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
112
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
113 http_hdr = http_new_header();
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
114 http_set_uri( http_hdr, url->file );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
115 http_set_field( http_hdr, "User-Agent: MPlayer");
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
116 http_set_field( http_hdr, "Connection: closed");
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
117 if( http_build_request( http_hdr )==NULL ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
118 return STREAMING_TYPE_UNKNOWN;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
119 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
120
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
121 fd = connect2Server( url->hostname, url->port );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
122 if( fd<0 ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
123 *fd_out=-1;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
124 return STREAMING_TYPE_UNKNOWN;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
125 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
126 write( fd, http_hdr->buffer, http_hdr->buffer_size );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
127 // http_free( http_hdr );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
128
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
129 http_hdr = http_new_header();
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
130 if( http_hdr==NULL ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
131 close( fd );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
132 *fd_out=-1;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
133 return STREAMING_TYPE_UNKNOWN;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
134 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
135
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
136 do {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
137 i = read( fd, response, 1024 );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
138 http_response_append( http_hdr, response, i );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
139 } while( !http_is_header_entired( http_hdr ) );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
140 http_response_parse( http_hdr );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
141
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
142 *fd_out=fd;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
143 //http_debug_hdr( http_hdr );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
144
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
145 // Check if the response is an ICY status_code reason_phrase
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
146 if( !strcasecmp(http_hdr->protocol, "ICY") ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
147 // Ok, we have detected an mp3 streaming
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
148 return STREAMING_TYPE_MP3;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
149 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
150
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
151 switch( http_hdr->status_code ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
152 case 200: // OK
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
153 // Look if we can use the Content-Type
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
154 content_type = http_get_field( http_hdr, "Content-Type" );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
155 if( content_type!=NULL ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
156 printf("Content-Type: %s\n", content_type );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
157 // Check for ASF
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
158 if( asf_http_streaming_type(content_type, NULL)!=ASF_Unknown_e ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
159 return STREAMING_TYPE_ASF;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
160 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
161 // Check for MP3 streaming
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
162 // Some MP3 streaming server answer with audio/mpeg
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
163 if( !strcasecmp(content_type, "audio/mpeg") ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
164 return STREAMING_TYPE_MP3;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
165 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
166 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
167 break;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
168 // Redirect
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
169 case 301: // Permanently
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
170 case 302: // Temporarily
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
171 // RFC 2616, recommand to detect infinite redirection loops
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
172 next_url = http_get_field( http_hdr, "Location" );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
173 if( next_url!=NULL ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
174 close( fd );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
175 url_free( url );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
176 url_new( next_url );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
177 goto redo_request;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
178 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
179 //break;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
180 default:
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
181 printf("Server returned %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
182 close( fd );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
183 *fd_out=-1;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
184 return STREAMING_TYPE_UNKNOWN;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
185 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
186 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
187 return STREAMING_TYPE_UNKNOWN;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
188 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
189
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
190
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
191 void
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
192 network_streaming() {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
193 int ret;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
194 /*
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
195 do {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
196 ret = select( );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
197
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
198 } while( );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
199 */
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
200 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
201
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
202 int
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
203 streaming_start(URL_t **url, int fd, int streaming_type) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
204 switch( streaming_type ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
205 case STREAMING_TYPE_ASF:
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
206 // Send a the appropriate HTTP request
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
207 if( fd>0 ) close( fd );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
208 fd = asf_http_streaming_start( url );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
209 break;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
210 case STREAMING_TYPE_MP3:
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
211 // Nothing else to do the server is already feeding the pipe.
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
212 break;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
213 case STREAMING_TYPE_UNKNOWN:
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
214 default:
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
215 printf("Unable to detect the streaming type\n");
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
216 close( fd );
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
217 return -1;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
218 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
219
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
220 return fd;
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
221 }
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
222
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
223 int
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
224 streaming_stop( ) {
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
225
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
226 }