Mercurial > mplayer.hg
annotate libmpdemux/asf_streaming.c @ 3463:453d0a52f654
some wishes for mencoder
author | jaf |
---|---|
date | Tue, 11 Dec 2001 19:33:10 +0000 |
parents | 78057c7120f6 |
children | 390388c75209 |
rev | line source |
---|---|
871 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
833 | 3 #include <string.h> |
1430 | 4 #include <unistd.h> |
833 | 5 |
2555
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
6 #include "config.h" |
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
7 |
871 | 8 #include "url.h" |
9 #include "http.h" | |
1001 | 10 #include "asf.h" |
905 | 11 #include "network.h" |
871 | 12 |
1001 | 13 #include "stream.h" |
833 | 14 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
15 typedef struct { |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
16 ASF_StreamType_e streaming_type; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
17 int request; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
18 } asf_http_streaming_ctrl_t; |
871 | 19 |
3042 | 20 // ASF streaming support several network protocol. |
21 // One use UDP, not known, yet! | |
22 // Another is HTTP, this one is known. | |
23 // So for now, we use the HTTP protocol. | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
24 // |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
25 // We can try several protocol for asf streaming |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
26 // * first the UDP protcol, if there is a firewall, UDP |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
27 // packets will not come back, so the mmsu will failed. |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
28 // * Then we can try TCP, but if there is a proxy for |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
29 // internet connection, the TCP connection will not get |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
30 // through |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
31 // * Then we can try HTTP. |
1001 | 32 int |
3042 | 33 asf_streaming_start( stream_t *stream ) { |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
34 char proto_s[10]; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
35 int fd = -1; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
36 |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
37 strncpy( proto_s, stream->streaming_ctrl->url->protocol, 10 ); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
38 |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
39 if( !strncasecmp( proto_s, "mms", 3) && strncasecmp( proto_s, "mmst", 4) ) { |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
40 printf("Trying ASF/UDP...\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
41 //fd = asf_mmsu_streaming_start( stream ); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
42 if( fd!=-1 ) return fd; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
43 printf(" ===> ASF/UDP failed\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
44 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
45 if( !strncasecmp( proto_s, "mms", 3) ) { |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
46 printf("Trying ASF/TCP...\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
47 //fd = asf_mmst_streaming_start( stream ); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
48 if( fd!=-1 ) return fd; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
49 printf(" ===> ASF/TCP failed\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
50 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
51 if( !strncasecmp( proto_s, "http", 4) || !strncasecmp( proto_s, "mms", 3) ) { |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
52 printf("Trying ASF/HTTP...\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
53 fd = asf_http_streaming_start( stream ); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
54 if( fd!=-1 ) return fd; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
55 printf(" ===> ASF/HTTP failed\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
56 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
57 |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
58 printf("Unknown protocol: %s\n", proto_s ); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
59 return -1; |
3042 | 60 } |
61 | |
62 | |
63 int | |
64 asf_http_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *streaming_ctrl ) { | |
1001 | 65 int drop_packet; |
66 int ret; | |
3042 | 67 //printf("asf_http_streaming_read\n"); |
68 | |
69 ret = nop_streaming_read( fd, buffer, size, streaming_ctrl ); | |
70 //printf("Read %d bytes\n", ret); | |
71 | |
72 ret = asf_streaming( buffer, size, &drop_packet ); | |
73 //printf("Streaming packet size=%d\n", ret); | |
1001 | 74 if( ret<0 ) return -1; |
75 if( !drop_packet ) { | |
3042 | 76 memmove( buffer, buffer+sizeof(ASF_stream_chunck_t), ret-sizeof(ASF_stream_chunck_t) ); |
1001 | 77 } |
3042 | 78 return ret-sizeof(ASF_stream_chunck_t); |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
79 } |
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
80 |
1001 | 81 int |
82 asf_streaming(char *data, int length, int *drop_packet ) { | |
833 | 83 ASF_stream_chunck_t *stream_chunck=(ASF_stream_chunck_t*)data; |
3042 | 84 /* |
85 printf("ASF stream chunck size=%d\n", stream_chunck->size); | |
1001 | 86 printf("length: %d\n", length ); |
87 printf("0x%02X\n", stream_chunck->type ); | |
3042 | 88 */ |
89 if( data==NULL || length<=0 ) return -1; | |
1001 | 90 if( drop_packet!=NULL ) *drop_packet = 0; |
871 | 91 |
92 if( stream_chunck->size<8 ) { | |
93 printf("Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size); | |
1001 | 94 return -1; |
871 | 95 } |
96 if( stream_chunck->size!=stream_chunck->size_confirm ) { | |
97 printf("size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm); | |
1001 | 98 return -1; |
871 | 99 } |
3042 | 100 /* |
1001 | 101 printf(" type: 0x%02X\n", stream_chunck->type ); |
102 printf(" size: %d (0x%02X)\n", stream_chunck->size, stream_chunck->size ); | |
103 printf(" sequence_number: 0x%04X\n", stream_chunck->sequence_number ); | |
104 printf(" unknown: 0x%02X\n", stream_chunck->unknown ); | |
105 printf(" size_confirm: 0x%02X\n", stream_chunck->size_confirm ); | |
3042 | 106 */ |
833 | 107 switch(stream_chunck->type) { |
3042 | 108 case 0x4324: // $C Clear ASF configuration |
871 | 109 printf("=====> Clearing ASF stream configuration!\n"); |
1001 | 110 if( drop_packet!=NULL ) *drop_packet = 1; |
111 return stream_chunck->size; | |
833 | 112 break; |
3042 | 113 case 0x4424: // $D Data follows |
114 // printf("=====> Data follows\n"); | |
833 | 115 break; |
3042 | 116 case 0x4524: // $E Transfer complete |
871 | 117 printf("=====> Transfer complete\n"); |
1001 | 118 if( drop_packet!=NULL ) *drop_packet = 1; |
119 return stream_chunck->size; | |
833 | 120 break; |
3042 | 121 case 0x4824: // $H ASF header chunk follows |
871 | 122 printf("=====> ASF header chunk follows\n"); |
833 | 123 break; |
124 default: | |
871 | 125 printf("=====> Unknown stream type 0x%x\n", stream_chunck->type ); |
833 | 126 } |
1001 | 127 return stream_chunck->size+4; |
833 | 128 } |
129 | |
905 | 130 int |
3042 | 131 asf_http_streaming_seek( int fd, off_t pos, streaming_ctrl_t *streaming_ctrl ) { |
132 return -1; | |
133 } | |
134 | |
135 int | |
905 | 136 asf_http_streaming_type(char *content_type, char *features) { |
137 if( content_type==NULL ) return ASF_Unknown_e; | |
833 | 138 if( !strcasecmp(content_type, "application/octet-stream") ) { |
905 | 139 if( features==NULL ) { |
1001 | 140 printf("=====> ASF Prerecorded\n"); |
905 | 141 return ASF_Prerecorded_e; |
142 } else if( strstr(features, "broadcast")) { | |
1001 | 143 printf("=====> ASF Live stream\n"); |
905 | 144 return ASF_Live_e; |
833 | 145 } else { |
1001 | 146 printf("=====> ASF Prerecorded\n"); |
905 | 147 return ASF_Prerecorded_e; |
833 | 148 } |
149 } else { | |
871 | 150 if( (!strcasecmp(content_type, "audio/x-ms-wax")) || |
833 | 151 (!strcasecmp(content_type, "audio/x-ms-wma")) || |
152 (!strcasecmp(content_type, "video/x-ms-asf")) || | |
153 (!strcasecmp(content_type, "video/x-ms-afs")) || | |
154 (!strcasecmp(content_type, "video/x-ms-wvx")) || | |
155 (!strcasecmp(content_type, "video/x-ms-wmv")) || | |
156 (!strcasecmp(content_type, "video/x-ms-wma")) ) { | |
1001 | 157 printf("=====> ASF Redirector\n"); |
905 | 158 return ASF_Redirector_e; |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
159 } else if( !strcasecmp(content_type, "text/plain") ) { |
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
160 printf("=====> ASF Plain text\n"); |
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
161 return ASF_PlainText_e; |
833 | 162 } else { |
1001 | 163 printf("=====> ASF unknown content-type: %s\n", content_type ); |
905 | 164 return ASF_Unknown_e; |
833 | 165 } |
166 } | |
905 | 167 return ASF_Unknown_e; |
833 | 168 } |
871 | 169 |
905 | 170 HTTP_header_t * |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
171 //asf_http_request(URL_t *url) { |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
172 asf_http_request(streaming_ctrl_t *streaming_ctrl) { |
871 | 173 HTTP_header_t *http_hdr; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
174 URL_t *url = streaming_ctrl->url; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
175 asf_http_streaming_ctrl_t *asf_http_ctrl = (asf_http_streaming_ctrl_t*)streaming_ctrl->data; |
871 | 176 char str[250]; |
1001 | 177 char *ptr; |
871 | 178 char *request; |
1001 | 179 int i; |
871 | 180 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
181 int offset_hi=0, offset_lo=0, length=0; |
1001 | 182 int asf_nb_stream; |
871 | 183 |
184 // Common header for all requests. | |
185 http_hdr = http_new_header(); | |
186 http_set_uri( http_hdr, url->file ); | |
187 http_set_field( http_hdr, "Accept: */*" ); | |
188 http_set_field( http_hdr, "User-Agent: NSPlayer/4.1.0.3856" ); | |
189 sprintf( str, "Host: %s:%d", url->hostname, url->port ); | |
190 http_set_field( http_hdr, str ); | |
191 http_set_field( http_hdr, "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" ); | |
192 sprintf(str, | |
193 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=%u", | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
194 offset_hi, offset_lo, asf_http_ctrl->request, length ); |
871 | 195 http_set_field( http_hdr, str ); |
196 | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
197 switch( asf_http_ctrl->streaming_type ) { |
871 | 198 case ASF_Live_e: |
199 case ASF_Prerecorded_e: | |
200 http_set_field( http_hdr, "Pragma: xPlayStrm=1" ); | |
1001 | 201 ptr = str; |
202 ptr += sprintf( ptr, "Pragma: stream-switch-entry="); | |
1340
d4f1e8d0e591
demuxer struct access code temporary disabled - FIXME
arpi
parents:
1001
diff
changeset
|
203 |
d4f1e8d0e591
demuxer struct access code temporary disabled - FIXME
arpi
parents:
1001
diff
changeset
|
204 #if 0 |
1001 | 205 for( i=0, asf_nb_stream=0 ; i<256 ; i++ ) { |
206 // FIXME START | |
207 if( demuxer==NULL ) { | |
208 ptr += sprintf( ptr, " ffff:1:0" ); | |
209 asf_nb_stream = 1; | |
210 break; | |
211 } | |
212 // FIXME END | |
213 if( demuxer->a_streams[i] ) { | |
214 ptr += sprintf( ptr, " ffff:%d:0", i ); | |
215 asf_nb_stream++; | |
216 } | |
217 if( demuxer->v_streams[i] ) { | |
218 ptr += sprintf( ptr, " ffff:%d:0", i ); | |
219 asf_nb_stream++; | |
220 } | |
221 } | |
1340
d4f1e8d0e591
demuxer struct access code temporary disabled - FIXME
arpi
parents:
1001
diff
changeset
|
222 #endif |
1001 | 223 http_set_field( http_hdr, str ); |
871 | 224 sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream ); |
225 http_set_field( http_hdr, str ); | |
226 break; | |
227 case ASF_Redirector_e: | |
228 break; | |
229 case ASF_Unknown_e: | |
230 // First request goes here. | |
231 break; | |
232 default: | |
233 printf("Unknown asf stream type\n"); | |
234 } | |
235 | |
236 http_set_field( http_hdr, "Connection: Close" ); | |
905 | 237 http_build_request( http_hdr ); |
871 | 238 |
905 | 239 return http_hdr; |
871 | 240 } |
241 | |
242 int | |
905 | 243 asf_http_parse_response( HTTP_header_t *http_hdr ) { |
871 | 244 char *content_type, *pragma; |
245 char features[64] = "\0"; | |
246 int len; | |
905 | 247 if( http_response_parse(http_hdr)<0 ) { |
248 printf("Failed to parse HTTP response\n"); | |
249 return -1; | |
250 } | |
871 | 251 if( http_hdr->status_code!=200 ) { |
252 printf("Server return %d:%s\n", http_hdr->status_code, http_hdr->reason_phrase); | |
253 return -1; | |
254 } | |
255 | |
256 content_type = http_get_field( http_hdr, "Content-Type"); | |
3042 | 257 //printf("Content-Type: [%s]\n", content_type); |
871 | 258 |
259 pragma = http_get_field( http_hdr, "Pragma"); | |
905 | 260 while( pragma!=NULL ) { |
871 | 261 char *comma_ptr=NULL; |
262 char *end; | |
3042 | 263 //printf("Pragma: [%s]\n", pragma ); |
871 | 264 // The pragma line can get severals attributes |
265 // separeted with a comma ','. | |
266 do { | |
267 if( !strncasecmp( pragma, "features=", 9) ) { | |
268 pragma += 9; | |
269 end = strstr( pragma, "," ); | |
270 if( end==NULL ) { | |
271 len = strlen(pragma); | |
272 } | |
273 len = MIN(end-pragma,sizeof(features)); | |
274 strncpy( features, pragma, len ); | |
275 features[len]='\0'; | |
276 break; | |
277 } | |
278 comma_ptr = strstr( pragma, "," ); | |
279 if( comma_ptr!=NULL ) { | |
280 pragma = comma_ptr+1; | |
281 if( pragma[0]==' ' ) pragma++; | |
282 } | |
283 } while( comma_ptr!=NULL ); | |
284 pragma = http_get_next_field( http_hdr ); | |
905 | 285 } |
286 | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
287 return asf_http_streaming_type( content_type, features ); |
871 | 288 } |
289 | |
905 | 290 URL_t * |
291 asf_http_ASX_redirect( HTTP_header_t *http_hdr ) { | |
292 URL_t *url_redirect=NULL; | |
293 printf("=========>> ASX parser not yet implemented <<==========\n"); | |
294 | |
295 printf("ASX=[%s]\n", http_hdr->body ); | |
296 | |
297 return url_redirect; | |
871 | 298 } |
905 | 299 |
300 int | |
3042 | 301 asf_http_streaming_start( stream_t *stream ) { |
905 | 302 HTTP_header_t *http_hdr=NULL; |
303 URL_t *url_next=NULL; | |
3042 | 304 URL_t *url = stream->streaming_ctrl->url; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
305 asf_http_streaming_ctrl_t *asf_http_ctrl; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
306 ASF_StreamType_e streaming_type; |
905 | 307 char buffer[BUFFER_SIZE]; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
308 unsigned int port; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
309 int i, ret; |
3042 | 310 int fd = stream->fd; |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
311 int done; |
1001 | 312 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
313 asf_http_ctrl = (asf_http_streaming_ctrl_t*)malloc(sizeof(asf_http_streaming_ctrl_t)); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
314 if( asf_http_ctrl==NULL ) { |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
315 printf("Memory allocation failed\n"); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
316 return -1; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
317 } |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
318 asf_http_ctrl->streaming_type = ASF_Unknown_e; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
319 asf_http_ctrl->request = 1; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
320 stream->streaming_ctrl->data = (void*)asf_http_ctrl; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
321 |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
322 //streaming_type = ASF_Live_e; |
905 | 323 do { |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
324 done = 1; |
905 | 325 if( fd>0 ) close( fd ); |
1001 | 326 |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
327 if( url->port==0 ) url->port = 80; |
905 | 328 fd = connect2Server( url->hostname, url->port ); |
329 if( fd<0 ) return -1; | |
330 | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
331 //http_hdr = asf_http_request( url ); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
332 http_hdr = asf_http_request( stream->streaming_ctrl ); |
3042 | 333 printf("Request [%s]\n", http_hdr->buffer ); |
905 | 334 write( fd, http_hdr->buffer, http_hdr->buffer_size ); |
3042 | 335 http_free( http_hdr ); |
905 | 336 |
337 http_hdr = http_new_header(); | |
338 do { | |
3042 | 339 i = read( fd, buffer, BUFFER_SIZE ); |
905 | 340 printf("read: %d\n", i ); |
1001 | 341 if( i<0 ) { |
342 perror("read"); | |
343 http_free( http_hdr ); | |
344 return -1; | |
345 } | |
905 | 346 http_response_append( http_hdr, buffer, i ); |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
347 } while( !http_is_header_entire( http_hdr ) ); |
3042 | 348 http_hdr->buffer[http_hdr->buffer_size]='\0'; |
349 printf("Response [%s]\n", http_hdr->buffer ); | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
350 streaming_type = asf_http_parse_response(http_hdr); |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
351 if( streaming_type<0 ) { |
905 | 352 printf("Failed to parse header\n"); |
1001 | 353 http_free( http_hdr ); |
905 | 354 return -1; |
355 } | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
356 asf_http_ctrl->streaming_type = streaming_type; |
1001 | 357 switch( streaming_type ) { |
905 | 358 case ASF_Live_e: |
359 case ASF_Prerecorded_e: | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
360 case ASF_PlainText_e: |
1001 | 361 if( http_hdr->body_size>0 ) { |
3042 | 362 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { |
363 http_free( http_hdr ); | |
364 return -1; | |
1001 | 365 } |
905 | 366 } |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
367 if( asf_http_ctrl->request==1 ) { |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
368 // First request, we only got the ASF header. |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
369 // We can redo the request and ask for all the stream. |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
370 // TODO: Here goes the code to read the ASF header and get the proper values. |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
371 asf_http_ctrl->request++; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
372 done = 0; |
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
373 } |
905 | 374 break; |
375 case ASF_Redirector_e: | |
376 url_next = asf_http_ASX_redirect( http_hdr ); | |
377 if( url_next==NULL ) { | |
378 printf("Failed to parse ASX file\n"); | |
379 close(fd); | |
1001 | 380 http_free( http_hdr ); |
905 | 381 return -1; |
382 } | |
3042 | 383 url_free( stream->streaming_ctrl->url ); |
384 stream->streaming_ctrl->url = url_next; | |
905 | 385 url = url_next; |
3042 | 386 done = 0; |
905 | 387 break; |
388 case ASF_Unknown_e: | |
389 default: | |
390 printf("Unknown ASF streaming type\n"); | |
391 close(fd); | |
1001 | 392 http_free( http_hdr ); |
905 | 393 return -1; |
394 } | |
3454
78057c7120f6
Added a switch for the ASF streaming protocol. It will first try ASF/UDP,
bertrand
parents:
3042
diff
changeset
|
395 // Check if we got a redirect. |
905 | 396 } while(!done); |
397 | |
3042 | 398 stream->fd= fd; |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
399 if( streaming_type==ASF_PlainText_e ) { |
3042 | 400 stream->streaming_ctrl->streaming_read = nop_streaming_read; |
401 stream->streaming_ctrl->streaming_seek = nop_streaming_seek; | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
402 } else { |
3042 | 403 stream->streaming_ctrl->streaming_read = asf_http_streaming_read; |
404 stream->streaming_ctrl->streaming_seek = asf_http_streaming_seek; | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
405 } |
3042 | 406 stream->streaming_ctrl->prebuffer_size = 20000; |
407 stream->streaming_ctrl->buffering = 1; | |
408 stream->streaming_ctrl->status = streaming_playing_e; | |
1001 | 409 |
410 http_free( http_hdr ); | |
905 | 411 return fd; |
412 } | |
413 |