annotate asf_streaming.c @ 944:0f8fe938f56b

New things
author nickols_k
date Sat, 02 Jun 2001 14:46:35 +0000
parents 4b6f81dbb2da
children 876c3edc2fa9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
1 #include <stdio.h>
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
2 #include <stdlib.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
3 #include <string.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
4
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
5 #include "asf.h"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
6 #include "url.h"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
7 #include "http.h"
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
8 #include "network.h"
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
9
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
10 #define BUFFER_SIZE 2048
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
11
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
12 const char *temp_response =
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
13 "HTTP/1.0 200 OK\r\n"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
14 "Date: Tue, 20 Mar 2001 11:40:35 GMT\r\n"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
15 "Content-Type: application/octet-stream\r\n"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
16 "Server: Cougar 4.1.0.3920\r\n"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
17 "Cache-Control: no-cache\r\n"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
18 "Pragma: no-cache, client-id=290092, features=\"broadcast\"\r\n"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
19 /* "Pragma: no-cache\r\n"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
20 "Pragma: client-id=290092\r\n"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
21 "Pragma: features=\"broadcast\"\r\n"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
22 */ "\r\n";
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
23
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
24 static ASF_StreamType_e streaming_type = ASF_Unknown_e;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
25
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
26 void
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
27 asf_streaming(char *data, int length) {
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
28 ASF_stream_chunck_t *stream_chunck=(ASF_stream_chunck_t*)data;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
29 printf("ASF stream chunck size=%d\n", stream_chunck->size);
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
30
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
31 if( stream_chunck->size<8 ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
32 printf("Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size);
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
33 return;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
34 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
35 if( stream_chunck->size!=stream_chunck->size_confirm ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
36 printf("size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm);
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
37 return;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
38 }
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
39
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
40 switch(stream_chunck->type) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
41 case 0x4324: // Clear ASF configuration
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
42 printf("=====> Clearing ASF stream configuration!\n");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
43 break;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
44 case 0x4424: // Data follows
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
45 printf("=====> Data follows\n");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
46 break;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
47 case 0x4524: // Transfer complete
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
48 printf("=====> Transfer complete\n");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
49 break;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
50 case 0x4824: // ASF header chunk follows
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
51 printf("=====> ASF header chunk follows\n");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
52 break;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
53 default:
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
54 printf("=====> Unknown stream type 0x%x\n", stream_chunck->type );
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
55 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
56 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
57
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
58 int
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
59 asf_http_streaming_type(char *content_type, char *features) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
60 if( content_type==NULL ) return ASF_Unknown_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
61 if( !strcasecmp(content_type, "application/octet-stream") ) {
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
62 if( features==NULL ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
63 printf("=====> Prerecorded\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
64 return ASF_Prerecorded_e;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
65 } else if( strstr(features, "broadcast")) {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
66 printf("=====> Live stream\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
67 return ASF_Live_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
68 } else {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
69 printf("=====> Prerecorded\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
70 return ASF_Prerecorded_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
71 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
72 } else {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
73 if( (!strcasecmp(content_type, "audio/x-ms-wax")) ||
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
74 (!strcasecmp(content_type, "audio/x-ms-wma")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
75 (!strcasecmp(content_type, "video/x-ms-asf")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
76 (!strcasecmp(content_type, "video/x-ms-afs")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
77 (!strcasecmp(content_type, "video/x-ms-wvx")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
78 (!strcasecmp(content_type, "video/x-ms-wmv")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
79 (!strcasecmp(content_type, "video/x-ms-wma")) ) {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
80 printf("=====> Redirector\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
81 return ASF_Redirector_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
82 } else {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
83 printf("=====> unknown content-type: %s\n", content_type );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
84 return ASF_Unknown_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
85 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
86 }
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
87 return ASF_Unknown_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
88 }
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
89
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
90 //void asf_http_request(stream_t *stream, URL_t *url) {
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
91 HTTP_header_t *
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
92 asf_http_request(URL_t *url) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
93 HTTP_header_t *http_hdr;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
94 char str[250];
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
95 char *request;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
96
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
97 int offset_hi=0, offset_lo=0, req_nb=1, length=0;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
98 int asf_nb_stream=1; // FIXME
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
99
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
100 // Common header for all requests.
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
101 http_hdr = http_new_header();
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
102 http_set_uri( http_hdr, url->file );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
103 http_set_field( http_hdr, "Accept: */*" );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
104 http_set_field( http_hdr, "User-Agent: NSPlayer/4.1.0.3856" );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
105 sprintf( str, "Host: %s:%d", url->hostname, url->port );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
106 http_set_field( http_hdr, str );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
107 http_set_field( http_hdr, "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
108 sprintf(str,
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
109 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=%u",
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
110 offset_hi, offset_lo, req_nb, length );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
111 http_set_field( http_hdr, str );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
112
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
113 switch( streaming_type ) {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
114 case ASF_Live_e:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
115 case ASF_Prerecorded_e:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
116 http_set_field( http_hdr, "Pragma: xPlayStrm=1" );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
117 sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
118 http_set_field( http_hdr, str );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
119 http_set_field( http_hdr, "Pragma: stream-switch-entry=ffff:1:0" ); // FIXME
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
120 break;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
121 case ASF_Redirector_e:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
122 break;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
123 case ASF_Unknown_e:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
124 // First request goes here.
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
125 break;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
126 default:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
127 printf("Unknown asf stream type\n");
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
128 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
129
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
130 http_set_field( http_hdr, "Connection: Close" );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
131 http_build_request( http_hdr );
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
132
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
133 return http_hdr;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
134 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
135
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
136 int
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
137 asf_http_parse_response( HTTP_header_t *http_hdr ) {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
138 char *content_type, *pragma;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
139 char features[64] = "\0";
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
140 int len;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
141 if( http_response_parse(http_hdr)<0 ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
142 printf("Failed to parse HTTP response\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
143 return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
144 }
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
145 if( http_hdr->status_code!=200 ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
146 printf("Server return %d:%s\n", http_hdr->status_code, http_hdr->reason_phrase);
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
147 return -1;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
148 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
149
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
150 content_type = http_get_field( http_hdr, "Content-Type");
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
151
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
152 pragma = http_get_field( http_hdr, "Pragma");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
153 while( pragma!=NULL ) {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
154 char *comma_ptr=NULL;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
155 char *end;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
156 // The pragma line can get severals attributes
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
157 // separeted with a comma ','.
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
158 do {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
159 if( !strncasecmp( pragma, "features=", 9) ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
160 pragma += 9;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
161 end = strstr( pragma, "," );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
162 if( end==NULL ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
163 len = strlen(pragma);
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
164 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
165 len = MIN(end-pragma,sizeof(features));
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
166 strncpy( features, pragma, len );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
167 features[len]='\0';
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
168 break;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
169 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
170 comma_ptr = strstr( pragma, "," );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
171 if( comma_ptr!=NULL ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
172 pragma = comma_ptr+1;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
173 if( pragma[0]==' ' ) pragma++;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
174 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
175 } while( comma_ptr!=NULL );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
176 pragma = http_get_next_field( http_hdr );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
177 }
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
178
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
179 streaming_type = asf_http_streaming_type( content_type, features );
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
180
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
181 if( http_hdr->body_size>0 ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
182 asf_streaming( http_hdr->body, http_hdr->body_size );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
183 }
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
184
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
185 return 0;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
186 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
187
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
188 URL_t *
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
189 asf_http_ASX_redirect( HTTP_header_t *http_hdr ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
190 URL_t *url_redirect=NULL;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
191 printf("=========>> ASX parser not yet implemented <<==========\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
192
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
193 printf("ASX=[%s]\n", http_hdr->body );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
194
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
195 return url_redirect;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
196 }
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
197
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
198 int
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
199 asf_http_streaming_start( URL_t **url_ref ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
200 HTTP_header_t *http_hdr=NULL;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
201 URL_t *url_next=NULL;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
202 URL_t *url=*url_ref;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
203 char buffer[BUFFER_SIZE];
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
204 int i;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
205 int fd=-1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
206 int done=1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
207 do {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
208 if( fd>0 ) close( fd );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
209 fd = connect2Server( url->hostname, url->port );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
210 if( fd<0 ) return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
211
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
212 http_hdr = asf_http_request( url );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
213 //printf("[%s]\n", http_hdr->buffer );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
214 write( fd, http_hdr->buffer, http_hdr->buffer_size );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
215 http_free( http_hdr );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
216
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
217 http_hdr = http_new_header();
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
218 do {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
219 i = read( fd, buffer, BUFFER_SIZE );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
220 printf("read: %d\n", i );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
221 http_response_append( http_hdr, buffer, i );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
222 } while( !http_is_header_entired( http_hdr ) );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
223 //http_hdr->buffer[http_hdr->buffer_len]='\0';
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
224 //printf("[%s]\n", http_hdr->buffer );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
225 if( asf_http_parse_response(http_hdr)<0 ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
226 printf("Failed to parse header\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
227 return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
228 }
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
229
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
230 switch(streaming_type) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
231 case ASF_Live_e:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
232 case ASF_Prerecorded_e:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
233 if( http_hdr->body_size==0 ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
234 i = read( fd, buffer, BUFFER_SIZE );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
235 printf("read: %d\n", i );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
236 asf_streaming( buffer, i );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
237 }
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
238 break;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
239 case ASF_Redirector_e:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
240 url_next = asf_http_ASX_redirect( http_hdr );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
241 if( url_next==NULL ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
242 printf("Failed to parse ASX file\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
243 close(fd);
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
244 return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
245 }
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
246 if( url_next->port==0 ) url_next->port=80;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
247 url_free( url );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
248 url = url_next;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
249 *url_ref = url_next;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
250 url_next = NULL;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
251 break;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
252 case ASF_Unknown_e:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
253 default:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
254 printf("Unknown ASF streaming type\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
255 close(fd);
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
256 return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
257 }
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
258
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
259 // Check if we got a redirect.
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
260 } while(!done);
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
261
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
262 return fd;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
263 }
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
264