annotate asf_streaming.c @ 1224:cf2ef08fca25

Reviewed for release.
author atmos4
date Sun, 24 Jun 2001 21:12:17 +0000
parents 876c3edc2fa9
children d4f1e8d0e591
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 "url.h"
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
6 #include "http.h"
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
7 #include "asf.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
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
10 #include "stream.h"
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
11 #include "demuxer.h"
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
12
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
13 extern demuxer_t *demuxer;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
14
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
15 static ASF_StreamType_e streaming_type = ASF_Unknown_e;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
16
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
17 int
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
18 asf_http_streaming_read( streaming_ctrl_t *streaming_ctrl ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
19 char *buffer;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
20 int drop_packet;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
21 int ret;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
22 printf("asf_streaming_read\n");
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
23 ret = asf_streaming( streaming_ctrl->buffer->buffer, streaming_ctrl->buffer->length, &drop_packet );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
24 printf("ret: %d\n", ret);
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
25 if( ret<0 ) return -1;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
26 if( ret>streaming_ctrl->buffer->length ) return 0;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
27 buffer = (char*)malloc(ret);
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
28 if( buffer==NULL ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
29 printf("Memory allocation failed\n");
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
30 return -1;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
31 }
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
32 printf("buffer length: %d\n", streaming_ctrl->buffer->length );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
33 net_fifo_pop( streaming_ctrl->buffer, buffer, ret );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
34 printf(" pop: 0x%02X\n", *((unsigned int*)buffer) );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
35 printf("buffer length: %d\n", streaming_ctrl->buffer->length );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
36 printf("0x%02X\n", *((unsigned int*)(buffer+sizeof(ASF_stream_chunck_t))) );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
37 if( !drop_packet ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
38 write( streaming_ctrl->fd_pipe_in, buffer+sizeof(ASF_stream_chunck_t), ret-sizeof(ASF_stream_chunck_t) );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
39 }
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
40 free( buffer );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
41 return ret;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
42 }
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
43
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
44 int
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
45 asf_streaming(char *data, int length, int *drop_packet ) {
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
46 ASF_stream_chunck_t *stream_chunck=(ASF_stream_chunck_t*)data;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
47 printf("ASF stream chunck size=%d\n", stream_chunck->size);
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
48 printf("length: %d\n", length );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
49 printf("0x%02X\n", stream_chunck->type );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
50
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
51 if( drop_packet!=NULL ) *drop_packet = 0;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
52 if( data==NULL || length<=0 ) return -1;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
53
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
54 if( stream_chunck->size<8 ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
55 printf("Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size);
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
56 return -1;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
57 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
58 if( stream_chunck->size!=stream_chunck->size_confirm ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
59 printf("size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm);
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
60 return -1;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
61 }
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
62
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
63 printf(" type: 0x%02X\n", stream_chunck->type );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
64 printf(" size: %d (0x%02X)\n", stream_chunck->size, stream_chunck->size );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
65 printf(" sequence_number: 0x%04X\n", stream_chunck->sequence_number );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
66 printf(" unknown: 0x%02X\n", stream_chunck->unknown );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
67 printf(" size_confirm: 0x%02X\n", stream_chunck->size_confirm );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
68
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
69
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
70 switch(stream_chunck->type) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
71 case 0x4324: // Clear ASF configuration
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
72 printf("=====> Clearing ASF stream configuration!\n");
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
73 if( drop_packet!=NULL ) *drop_packet = 1;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
74 return stream_chunck->size;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
75 break;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
76 case 0x4424: // Data follows
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
77 printf("=====> Data follows\n");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
78 break;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
79 case 0x4524: // Transfer complete
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
80 printf("=====> Transfer complete\n");
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
81 if( drop_packet!=NULL ) *drop_packet = 1;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
82 return stream_chunck->size;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
83 break;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
84 case 0x4824: // ASF header chunk follows
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
85 printf("=====> ASF header chunk follows\n");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
86 break;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
87 default:
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
88 printf("=====> Unknown stream type 0x%x\n", stream_chunck->type );
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
89 }
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
90 return stream_chunck->size+4;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
91 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
92
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
93 int
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
94 asf_http_streaming_type(char *content_type, char *features) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
95 if( content_type==NULL ) return ASF_Unknown_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
96 if( !strcasecmp(content_type, "application/octet-stream") ) {
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
97 if( features==NULL ) {
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
98 printf("=====> ASF Prerecorded\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
99 return ASF_Prerecorded_e;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
100 } else if( strstr(features, "broadcast")) {
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
101 printf("=====> ASF Live stream\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
102 return ASF_Live_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
103 } else {
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
104 printf("=====> ASF Prerecorded\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
105 return ASF_Prerecorded_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
106 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
107 } else {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
108 if( (!strcasecmp(content_type, "audio/x-ms-wax")) ||
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
109 (!strcasecmp(content_type, "audio/x-ms-wma")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
110 (!strcasecmp(content_type, "video/x-ms-asf")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
111 (!strcasecmp(content_type, "video/x-ms-afs")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
112 (!strcasecmp(content_type, "video/x-ms-wvx")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
113 (!strcasecmp(content_type, "video/x-ms-wmv")) ||
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
114 (!strcasecmp(content_type, "video/x-ms-wma")) ) {
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
115 printf("=====> ASF Redirector\n");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
116 return ASF_Redirector_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
117 } else {
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
118 printf("=====> ASF unknown content-type: %s\n", content_type );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
119 return ASF_Unknown_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
120 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
121 }
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
122 return ASF_Unknown_e;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
123 }
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
124
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
125 HTTP_header_t *
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
126 asf_http_request(URL_t *url) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
127 HTTP_header_t *http_hdr;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
128 char str[250];
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
129 char *ptr;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
130 char *request;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
131 int i;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
132
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
133 int offset_hi=0, offset_lo=0, req_nb=1, length=0;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
134 int asf_nb_stream;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
135
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
136 // Common header for all requests.
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
137 http_hdr = http_new_header();
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
138 http_set_uri( http_hdr, url->file );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
139 http_set_field( http_hdr, "Accept: */*" );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
140 http_set_field( http_hdr, "User-Agent: NSPlayer/4.1.0.3856" );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
141 sprintf( str, "Host: %s:%d", url->hostname, url->port );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
142 http_set_field( http_hdr, str );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
143 http_set_field( http_hdr, "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}" );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
144 sprintf(str,
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
145 "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
146 offset_hi, offset_lo, req_nb, length );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
147 http_set_field( http_hdr, str );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
148
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
149 switch( streaming_type ) {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
150 case ASF_Live_e:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
151 case ASF_Prerecorded_e:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
152 http_set_field( http_hdr, "Pragma: xPlayStrm=1" );
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
153 ptr = str;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
154 ptr += sprintf( ptr, "Pragma: stream-switch-entry=");
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
155 for( i=0, asf_nb_stream=0 ; i<256 ; i++ ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
156 // FIXME START
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
157 if( demuxer==NULL ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
158 ptr += sprintf( ptr, " ffff:1:0" );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
159 asf_nb_stream = 1;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
160 break;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
161 }
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
162 // FIXME END
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
163 if( demuxer->a_streams[i] ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
164 ptr += sprintf( ptr, " ffff:%d:0", i );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
165 asf_nb_stream++;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
166 }
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
167 if( demuxer->v_streams[i] ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
168 ptr += sprintf( ptr, " ffff:%d:0", i );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
169 asf_nb_stream++;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
170 }
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
171 }
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
172 http_set_field( http_hdr, str );
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
173 sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
174 http_set_field( http_hdr, str );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
175 break;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
176 case ASF_Redirector_e:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
177 break;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
178 case ASF_Unknown_e:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
179 // First request goes here.
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
180 break;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
181 default:
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
182 printf("Unknown asf stream type\n");
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
183 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
184
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
185 http_set_field( http_hdr, "Connection: Close" );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
186 http_build_request( http_hdr );
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
187
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
188 return http_hdr;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
189 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
190
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
191 int
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
192 asf_http_parse_response( HTTP_header_t *http_hdr ) {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
193 char *content_type, *pragma;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
194 char features[64] = "\0";
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
195 int len;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
196 if( http_response_parse(http_hdr)<0 ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
197 printf("Failed to parse HTTP response\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
198 return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
199 }
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
200 if( http_hdr->status_code!=200 ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
201 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
202 return -1;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
203 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
204
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
205 content_type = http_get_field( http_hdr, "Content-Type");
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
206
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
207 pragma = http_get_field( http_hdr, "Pragma");
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
208 while( pragma!=NULL ) {
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
209 char *comma_ptr=NULL;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
210 char *end;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
211 // The pragma line can get severals attributes
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
212 // separeted with a comma ','.
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
213 do {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
214 if( !strncasecmp( pragma, "features=", 9) ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
215 pragma += 9;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
216 end = strstr( pragma, "," );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
217 if( end==NULL ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
218 len = strlen(pragma);
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
219 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
220 len = MIN(end-pragma,sizeof(features));
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
221 strncpy( features, pragma, len );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
222 features[len]='\0';
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
223 break;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
224 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
225 comma_ptr = strstr( pragma, "," );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
226 if( comma_ptr!=NULL ) {
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
227 pragma = comma_ptr+1;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
228 if( pragma[0]==' ' ) pragma++;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
229 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
230 } while( comma_ptr!=NULL );
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
231 pragma = http_get_next_field( http_hdr );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
232 }
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
233
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
234 streaming_type = asf_http_streaming_type( content_type, features );
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
235
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
236 if( http_hdr->body_size>0 ) {
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
237 asf_streaming( http_hdr->body, http_hdr->body_size, NULL);
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
238 }
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
239
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
240 return 0;
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
241 }
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
242
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
243 URL_t *
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
244 asf_http_ASX_redirect( HTTP_header_t *http_hdr ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
245 URL_t *url_redirect=NULL;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
246 printf("=========>> ASX parser not yet implemented <<==========\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
247
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
248 printf("ASX=[%s]\n", http_hdr->body );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
249
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
250 return url_redirect;
871
ab94c4cf96d8 Continue implementation of ASF streaming.
bertrand
parents: 833
diff changeset
251 }
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
252
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
253 int
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
254 asf_http_streaming_start( streaming_ctrl_t *streaming_ctrl ) {
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
255 HTTP_header_t *http_hdr=NULL;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
256 URL_t *url_next=NULL;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
257 URL_t *url = *(streaming_ctrl->url);
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
258 char buffer[BUFFER_SIZE];
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
259 int i;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
260 int fd = streaming_ctrl->fd_net;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
261 int done=1;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
262
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
263 streaming_type = ASF_Live_e;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
264 do {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
265 if( fd>0 ) close( fd );
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
266
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
267 fd = connect2Server( url->hostname, url->port );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
268 if( fd<0 ) return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
269
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
270 http_hdr = asf_http_request( url );
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
271 printf("[%s]\n", http_hdr->buffer );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
272 write( fd, http_hdr->buffer, http_hdr->buffer_size );
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
273 // http_free( http_hdr );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
274
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
275 http_hdr = http_new_header();
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
276 do {
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
277 i = readFromServer( fd, buffer, BUFFER_SIZE );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
278 printf("read: %d\n", i );
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
279 if( i<0 ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
280 perror("read");
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
281 http_free( http_hdr );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
282 return -1;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
283 }
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
284 http_response_append( http_hdr, buffer, i );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
285 } while( !http_is_header_entired( http_hdr ) );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
286 //http_hdr->buffer[http_hdr->buffer_len]='\0';
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
287 //printf("[%s]\n", http_hdr->buffer );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
288 if( asf_http_parse_response(http_hdr)<0 ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
289 printf("Failed to parse header\n");
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
290 http_free( http_hdr );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
291 return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
292 }
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
293 switch( streaming_type ) {
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
294 case ASF_Live_e:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
295 case ASF_Prerecorded_e:
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
296 if( http_hdr->body_size>0 ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
297 printf("--- 0x%02X\n", streaming_ctrl->buffer );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
298 net_fifo_push( streaming_ctrl->buffer, http_hdr->body, http_hdr->body_size );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
299 } else {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
300 ASF_stream_chunck_t *ptr;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
301 int ret;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
302 i = readFromServer( fd, buffer, sizeof(ASF_stream_chunck_t) );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
303 printf("read: %d\n", i );
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
304 ret = asf_streaming( buffer, i, NULL );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
305 net_fifo_push( streaming_ctrl->buffer, buffer, i );
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
306 ptr = (ASF_stream_chunck_t*)buffer;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
307 if( ret==ptr->size ) {
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
308 }
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
309 }
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
310 // done = 0;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
311 break;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
312 case ASF_Redirector_e:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
313 url_next = asf_http_ASX_redirect( http_hdr );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
314 if( url_next==NULL ) {
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
315 printf("Failed to parse ASX file\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
316 close(fd);
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
317 http_free( http_hdr );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
318 return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
319 }
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
320 if( url_next->port==0 ) url_next->port=80;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
321 url_free( url );
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
322 url = url_next;
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
323 *(streaming_ctrl->url) = url_next;
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
324 url_next = NULL;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
325 break;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
326 case ASF_Unknown_e:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
327 default:
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
328 printf("Unknown ASF streaming type\n");
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
329 close(fd);
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
330 http_free( http_hdr );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
331 return -1;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
332 }
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
333
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
334 // Check if we got a redirect.
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
335 } while(!done);
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
336
1001
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
337 streaming_ctrl->fd_net = fd;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
338 streaming_ctrl->streaming_read = asf_http_streaming_read;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
339 streaming_ctrl->prebuffer_size = 10000;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
340 streaming_ctrl->buffering = 1;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
341 streaming_ctrl->status = streaming_playing_e;
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
342
876c3edc2fa9 Continue implementation of ASF streaming.
bertrand
parents: 905
diff changeset
343 http_free( http_hdr );
905
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
344 return fd;
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
345 }
4b6f81dbb2da Continue implementation.
bertrand
parents: 871
diff changeset
346