Mercurial > mplayer.hg
annotate libmpdemux/asf_mmst_streaming.c @ 11402:b0c13371ebdf
remove uncommon langinfo code and replace it by more common setlocal. patch by Steven M. Schultz <sms@2BSD.COM>
author | alex |
---|---|
date | Thu, 06 Nov 2003 22:28:55 +0000 |
parents | 007ec48cf146 |
children | 86ab7e0b2a65 |
rev | line source |
---|---|
6092 | 1 // mmst implementation taken from the xine-mms plugin made by majormms (http://geocities.com/majormms/) |
2 // | |
3 // ported to mplayer by Abhijeet Phatak <abhijeetphatak@yahoo.com> | |
4 // date : 16 April 2002 | |
5 // | |
6 // information about the mms protocol can be find at http://get.to/sdp | |
7 // | |
8 | |
9 | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <string.h> | |
13 #include <unistd.h> | |
14 #include <errno.h> | |
7880 | 15 #include <inttypes.h> |
6092 | 16 |
17 #include "config.h" | |
18 | |
10281 | 19 #ifndef HAVE_WINSOCK2 |
20 #define closesocket close | |
21 #else | |
22 #include <winsock2.h> | |
23 #endif | |
24 | |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
25 #ifdef USE_ICONV |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
26 #include <locale.h> |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
27 #include <iconv.h> |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
28 #endif |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
29 |
6092 | 30 #include "url.h" |
31 #include "asf.h" | |
32 | |
33 #include "stream.h" | |
34 | |
35 #include "network.h" | |
36 | |
37 #define BUF_SIZE 102400 | |
38 | |
39 typedef struct | |
40 { | |
41 uint8_t buf[BUF_SIZE]; | |
42 int num_bytes; | |
43 | |
44 } command_t; | |
45 | |
7880 | 46 static int seq_num; |
47 static int num_stream_ids; | |
48 static int stream_ids[20]; | |
6092 | 49 |
50 static int get_data (int s, char *buf, size_t count); | |
51 | |
52 static void put_32 (command_t *cmd, uint32_t value) | |
53 { | |
54 cmd->buf[cmd->num_bytes ] = value % 256; | |
55 value = value >> 8; | |
56 cmd->buf[cmd->num_bytes+1] = value % 256 ; | |
57 value = value >> 8; | |
58 cmd->buf[cmd->num_bytes+2] = value % 256 ; | |
59 value = value >> 8; | |
60 cmd->buf[cmd->num_bytes+3] = value % 256 ; | |
61 | |
62 cmd->num_bytes += 4; | |
63 } | |
64 | |
65 static uint32_t get_32 (unsigned char *cmd, int offset) | |
66 { | |
67 uint32_t ret; | |
68 | |
69 ret = cmd[offset] ; | |
70 ret |= cmd[offset+1]<<8 ; | |
71 ret |= cmd[offset+2]<<16 ; | |
72 ret |= cmd[offset+3]<<24 ; | |
73 | |
74 return ret; | |
75 } | |
76 | |
77 static void send_command (int s, int command, uint32_t switches, | |
78 uint32_t extra, int length, | |
79 char *data) | |
80 { | |
81 command_t cmd; | |
82 int len8; | |
83 | |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
84 len8 = (length + 7) / 8; |
6092 | 85 |
86 cmd.num_bytes = 0; | |
87 | |
88 put_32 (&cmd, 0x00000001); /* start sequence */ | |
89 put_32 (&cmd, 0xB00BFACE); /* #-)) */ | |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
90 put_32 (&cmd, len8*8 + 32); |
6092 | 91 put_32 (&cmd, 0x20534d4d); /* protocol type "MMS " */ |
92 put_32 (&cmd, len8 + 4); | |
93 put_32 (&cmd, seq_num); | |
94 seq_num++; | |
95 put_32 (&cmd, 0x0); /* unknown */ | |
96 put_32 (&cmd, 0x0); | |
97 put_32 (&cmd, len8+2); | |
98 put_32 (&cmd, 0x00030000 | command); /* dir | command */ | |
99 put_32 (&cmd, switches); | |
100 put_32 (&cmd, extra); | |
101 | |
102 memcpy (&cmd.buf[48], data, length); | |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
103 if (length & 7) |
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
104 memset(&cmd.buf[48 + length], 0, 8 - (length & 7)); |
6092 | 105 |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
106 if (send (s, cmd.buf, len8*8+48, 0) != (len8*8+48)) { |
6092 | 107 printf ("write error\n"); |
108 } | |
109 } | |
110 | |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
111 #ifdef USE_ICONV |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
112 static iconv_t url_conv; |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
113 |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
114 static void string_utf16_open() { |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
115 setlocale(LC_CTYPE, ""); |
11402
b0c13371ebdf
remove uncommon langinfo code and replace it by more common setlocal. patch by Steven M. Schultz <sms@2BSD.COM>
alex
parents:
11350
diff
changeset
|
116 url_conv = iconv_open("UTF-16LE",setlocale(LC_CTYPE, NULL)); |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
117 } |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
118 |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
119 static void string_utf16_close() { |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
120 |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
121 iconv_close(url_conv); |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
122 } |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
123 |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
124 static void string_utf16(char *dest, char *src, int len) { |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
125 size_t len1, len2; |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
126 char *ip, *op; |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
127 |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
128 memset(dest, 0, 1000); |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
129 len1 = len; len2 = 1000; |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
130 ip = src; op = dest; |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
131 |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
132 iconv(url_conv, &ip, &len1, &op, &len2); |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
133 } |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
134 |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
135 #else |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
136 |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
137 static void string_utf16_open() { |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
138 } |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
139 |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
140 static void string_utf16_close() { |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
141 } |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
142 |
6092 | 143 static void string_utf16(char *dest, char *src, int len) |
144 { | |
145 int i; | |
146 | |
147 for (i=0; i<len; i++) { | |
148 dest[i*2] = src[i]; | |
149 dest[i*2+1] = 0; | |
150 } | |
151 | |
11226 | 152 /* trailing zeroes */ |
6092 | 153 dest[i*2] = 0; |
154 dest[i*2+1] = 0; | |
155 } | |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
156 #endif |
6092 | 157 |
158 static void get_answer (int s) | |
159 { | |
160 char data[BUF_SIZE]; | |
161 int command = 0x1b; | |
162 | |
163 while (command == 0x1b) { | |
164 int len; | |
165 | |
10206
35e306346e59
Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents:
10183
diff
changeset
|
166 len = recv (s, data, BUF_SIZE, 0) ; |
6092 | 167 if (!len) { |
168 printf ("\nalert! eof\n"); | |
169 return; | |
170 } | |
171 | |
172 command = get_32 (data, 36) & 0xFFFF; | |
173 | |
174 if (command == 0x1b) | |
175 send_command (s, 0x1b, 0, 0, 0, data); | |
176 } | |
177 } | |
178 | |
179 static int get_data (int s, char *buf, size_t count) | |
180 { | |
7953 | 181 ssize_t len; |
182 size_t total = 0; | |
6092 | 183 |
184 while (total < count) { | |
185 | |
10206
35e306346e59
Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents:
10183
diff
changeset
|
186 len = recv (s, &buf[total], count-total, 0); |
6092 | 187 |
188 if (len<0) { | |
189 perror ("read error:"); | |
190 return 0; | |
191 } | |
192 | |
193 total += len; | |
194 | |
195 if (len != 0) { | |
196 // printf ("[%d/%d]", total, count); | |
197 fflush (stdout); | |
198 } | |
199 | |
200 } | |
201 | |
202 return 1; | |
203 | |
204 } | |
205 | |
206 static int get_header (int s, uint8_t *header, streaming_ctrl_t *streaming_ctrl) | |
207 { | |
208 unsigned char pre_header[8]; | |
7953 | 209 int header_len; |
6092 | 210 |
211 header_len = 0; | |
212 | |
213 while (1) { | |
214 if (!get_data (s, pre_header, 8)) { | |
215 printf ("pre-header read failed\n"); | |
216 return 0; | |
217 } | |
218 if (pre_header[4] == 0x02) { | |
219 | |
220 int packet_len; | |
221 | |
222 packet_len = (pre_header[7] << 8 | pre_header[6]) - 8; | |
223 | |
224 // printf ("asf header packet detected, len=%d\n", packet_len); | |
225 | |
226 if (!get_data (s, &header[header_len], packet_len)) { | |
227 printf ("header data read failed\n"); | |
228 return 0; | |
229 } | |
230 | |
231 header_len += packet_len; | |
232 | |
233 if ( (header[header_len-1] == 1) && (header[header_len-2]==1)) { | |
234 | |
235 | |
236 if( streaming_bufferize( streaming_ctrl, header, header_len )<0 ) { | |
237 return -1; | |
238 } | |
239 | |
240 // printf ("get header packet finished\n"); | |
241 | |
242 return (header_len); | |
243 | |
244 } | |
245 | |
246 } else { | |
247 | |
7953 | 248 int32_t packet_len; |
6092 | 249 int command; |
250 char data[BUF_SIZE]; | |
251 | |
7953 | 252 if (!get_data (s, (char*)&packet_len, 4)) { |
6092 | 253 printf ("packet_len read failed\n"); |
254 return 0; | |
255 } | |
256 | |
7953 | 257 packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4; |
6092 | 258 |
259 // printf ("command packet detected, len=%d\n", packet_len); | |
260 | |
261 if (!get_data (s, data, packet_len)) { | |
262 printf ("command data read failed\n"); | |
263 return 0; | |
264 } | |
265 | |
266 command = get_32 (data, 24) & 0xFFFF; | |
267 | |
268 // printf ("command: %02x\n", command); | |
269 | |
270 if (command == 0x1b) | |
271 send_command (s, 0x1b, 0, 0, 0, data); | |
272 | |
273 } | |
274 | |
275 // printf ("get header packet succ\n"); | |
276 } | |
277 } | |
278 | |
7880 | 279 static int interp_header (uint8_t *header, int header_len) |
6092 | 280 { |
281 int i; | |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7309
diff
changeset
|
282 int packet_length=-1; |
6092 | 283 |
284 /* | |
285 * parse header | |
286 */ | |
287 | |
288 i = 30; | |
289 while (i<header_len) { | |
290 | |
291 uint64_t guid_1, guid_2, length; | |
292 | |
293 guid_2 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) | |
294 | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) | |
295 | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) | |
296 | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); | |
297 i += 8; | |
298 | |
299 guid_1 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) | |
300 | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) | |
301 | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) | |
302 | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); | |
303 i += 8; | |
304 | |
305 // printf ("guid found: %016llx%016llx\n", guid_1, guid_2); | |
306 | |
307 length = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) | |
308 | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) | |
309 | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) | |
310 | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); | |
311 | |
312 i += 8; | |
313 | |
314 if ( (guid_1 == 0x6cce6200aa00d9a6) && (guid_2 == 0x11cf668e75b22630) ) { | |
315 printf ("header object\n"); | |
316 } else if ((guid_1 == 0x6cce6200aa00d9a6) && (guid_2 == 0x11cf668e75b22636)) { | |
317 printf ("data object\n"); | |
318 } else if ((guid_1 == 0x6553200cc000e48e) && (guid_2 == 0x11cfa9478cabdca1)) { | |
319 | |
320 packet_length = get_32(header, i+92-24); | |
321 | |
322 printf ("file object, packet length = %d (%d)\n", | |
323 packet_length, get_32(header, i+96-24)); | |
324 | |
325 | |
326 } else if ((guid_1 == 0x6553200cc000e68e) && (guid_2 == 0x11cfa9b7b7dc0791)) { | |
327 | |
328 int stream_id = header[i+48] | header[i+49] << 8; | |
329 | |
330 printf ("stream object, stream id: %d\n", stream_id); | |
331 | |
332 stream_ids[num_stream_ids] = stream_id; | |
333 num_stream_ids++; | |
334 | |
335 } else { | |
336 printf ("unknown object\n"); | |
337 } | |
338 | |
339 // printf ("length : %lld\n", length); | |
340 | |
341 i += length-24; | |
342 | |
343 } | |
344 | |
345 return packet_length; | |
346 | |
347 } | |
348 | |
349 | |
7880 | 350 static int get_media_packet (int s, int padding, streaming_ctrl_t *stream_ctrl) { |
6092 | 351 unsigned char pre_header[8]; |
352 char data[BUF_SIZE]; | |
7880 | 353 |
354 if (!get_data (s, pre_header, 8)) { | |
355 printf ("pre-header read failed\n"); | |
356 return 0; | |
357 } | |
358 | |
359 // for (i=0; i<8; i++) | |
360 // printf ("pre_header[%d] = %02x (%d)\n", | |
361 // i, pre_header[i], pre_header[i]); | |
362 | |
363 if (pre_header[4] == 0x04) { | |
364 | |
365 int packet_len; | |
366 | |
367 packet_len = (pre_header[7] << 8 | pre_header[6]) - 8; | |
368 | |
369 // printf ("asf media packet detected, len=%d\n", packet_len); | |
370 | |
371 if (!get_data (s, data, packet_len)) { | |
372 printf ("media data read failed\n"); | |
373 return 0; | |
374 } | |
375 | |
376 streaming_bufferize(stream_ctrl, data, padding); | |
377 | |
378 } else { | |
379 | |
7953 | 380 int32_t packet_len; |
381 int command; | |
7880 | 382 |
7953 | 383 if (!get_data (s, (char*)&packet_len, 4)) { |
7880 | 384 printf ("packet_len read failed\n"); |
385 return 0; | |
386 } | |
387 | |
7953 | 388 packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4; |
7880 | 389 |
390 if (!get_data (s, data, packet_len)) { | |
391 printf ("command data read failed\n"); | |
392 return 0; | |
393 } | |
394 | |
395 if ( (pre_header[7] != 0xb0) || (pre_header[6] != 0x0b) | |
396 || (pre_header[5] != 0xfa) || (pre_header[4] != 0xce) ) { | |
397 | |
398 printf ("missing signature\n"); | |
399 return -1; | |
400 } | |
401 | |
402 command = get_32 (data, 24) & 0xFFFF; | |
403 | |
7977 | 404 // printf ("\ncommand packet detected, len=%d cmd=0x%X\n", packet_len, command); |
7880 | 405 |
406 if (command == 0x1b) | |
407 send_command (s, 0x1b, 0, 0, 0, data); | |
408 else if (command == 0x1e) { | |
409 printf ("everything done. Thank you for downloading a media file containing proprietary and patentend technology.\n"); | |
410 return 0; | |
411 } | |
412 else if (command == 0x21 ) { | |
413 // Looks like it's new in WMS9 | |
414 // Unknown command, but ignoring it seems to work. | |
415 return 0; | |
416 } | |
417 else if (command != 0x05) { | |
418 printf ("unknown command %02x\n", command); | |
419 return -1; | |
420 } | |
421 } | |
422 | |
423 // printf ("get media packet succ\n"); | |
424 | |
425 return 1; | |
426 } | |
6092 | 427 |
428 | |
7880 | 429 static int packet_length1; |
6092 | 430 |
431 int | |
432 asf_mmst_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) | |
433 { | |
7880 | 434 int len; |
435 | |
436 while( stream_ctrl->buffer_size==0 ) { | |
437 // buffer is empty - fill it! | |
438 int ret = get_media_packet( fd, packet_length1, stream_ctrl); | |
439 if( ret<0 ) { | |
440 printf("get_media_packet error : %s\n",strerror(errno)); | |
441 return -1; | |
442 } | |
443 } | |
444 | |
445 len = stream_ctrl->buffer_size-stream_ctrl->buffer_pos; | |
446 if(len>size) len=size; | |
6092 | 447 memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len ); |
448 stream_ctrl->buffer_pos += len; | |
449 if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) { | |
450 free( stream_ctrl->buffer ); | |
451 stream_ctrl->buffer = NULL; | |
452 stream_ctrl->buffer_size = 0; | |
453 stream_ctrl->buffer_pos = 0; | |
454 } | |
7880 | 455 return len; |
6092 | 456 |
457 } | |
458 | |
459 int | |
460 asf_mmst_streaming_seek( int fd, off_t pos, streaming_ctrl_t *streaming_ctrl ) | |
461 { | |
462 return -1; | |
7953 | 463 // Shut up gcc warning |
464 fd++; | |
465 pos++; | |
466 streaming_ctrl=NULL; | |
6092 | 467 } |
468 | |
469 int asf_mmst_streaming_start(stream_t *stream) | |
470 { | |
471 char str[1024]; | |
10183 | 472 char data[BUF_SIZE]; |
6092 | 473 uint8_t asf_header[8192]; |
474 int asf_header_len; | |
475 int len, i, packet_length; | |
476 char *path; | |
477 URL_t *url1 = stream->streaming_ctrl->url; | |
7953 | 478 int s = stream->fd; |
6092 | 479 |
7250
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
480 if( s>0 ) { |
10281 | 481 closesocket( stream->fd ); |
7250
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
482 stream->fd = -1; |
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
483 } |
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
484 |
6092 | 485 /* parse url */ |
486 path = strchr(url1->file,'/') + 1; | |
487 | |
488 url1->port=1755; | |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10281
diff
changeset
|
489 s = connect2Server( url1->hostname, url1->port, 1); |
7250
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
490 if( s<0 ) { |
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
491 return s; |
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
492 } |
6092 | 493 printf ("connected\n"); |
7880 | 494 |
495 seq_num=0; | |
6092 | 496 |
497 /* | |
498 * Send the initial connect info including player version no. Client GUID (random) and the host address being connected to. | |
499 * This command is sent at the very start of protocol initiation. It sends local information to the serve | |
500 * cmd 1 0x01 | |
501 * */ | |
502 | |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
503 /* prepare for the url encoding conversion */ |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
504 string_utf16_open(); |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
505 |
10183 | 506 snprintf (str, 1023, "\034\003NSPlayer/7.0.0.1956; {33715801-BAB3-9D85-24E9-03B90328270A}; Host: %s", url1->hostname); |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
507 string_utf16 (data, str, strlen(str)); |
6092 | 508 // send_command(s, commandno ....) |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
509 send_command (s, 1, 0, 0x0004000b, strlen(str)*2+2, data); |
6092 | 510 |
10206
35e306346e59
Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents:
10183
diff
changeset
|
511 len = recv (s, data, BUF_SIZE, 0) ; |
6092 | 512 |
513 /*This sends details of the local machine IP address to a Funnel system at the server. | |
514 * Also, the TCP or UDP transport selection is sent. | |
515 * | |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
516 * here 192.168.0.1 is local ip address TCP/UDP states the tronsport we r using |
6092 | 517 * and 1037 is the local TCP or UDP socket number |
518 * cmd 2 0x02 | |
519 * */ | |
520 | |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
521 string_utf16 (&data[8], "\002\000\\\\192.168.0.1\\TCP\\1037", 24); |
6092 | 522 memset (data, 0, 8); |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
523 send_command (s, 2, 0, 0, 24*2+10, data); |
6092 | 524 |
10206
35e306346e59
Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents:
10183
diff
changeset
|
525 len = recv (s, data, BUF_SIZE, 0) ; |
6092 | 526 |
527 /* This command sends file path (at server) and file name request to the server. | |
528 * 0x5 */ | |
529 | |
530 string_utf16 (&data[8], path, strlen(path)); | |
531 memset (data, 0, 8); | |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
532 send_command (s, 5, 0, 0, strlen(path)*2+10, data); |
6092 | 533 |
534 get_answer (s); | |
535 | |
536 /* The ASF header chunk request. Includes ?session' variable for pre header value. | |
537 * After this command is sent, | |
538 * the server replies with 0x11 command and then the header chunk with header data follows. | |
539 * 0x15 */ | |
540 | |
541 memset (data, 0, 40); | |
542 data[32] = 2; | |
543 | |
544 send_command (s, 0x15, 1, 0, 40, data); | |
545 | |
546 num_stream_ids = 0; | |
547 /* get_headers(s, asf_header); */ | |
548 | |
549 asf_header_len = get_header (s, asf_header, stream->streaming_ctrl); | |
550 // printf("---------------------------------- asf_header %d\n",asf_header); | |
551 packet_length = interp_header (asf_header, asf_header_len); | |
552 | |
553 | |
554 /* | |
555 * This command is the media stream MBR selector. Switches are always 6 bytes in length. | |
556 * After all switch elements, data ends with bytes [00 00] 00 20 ac 40 [02]. | |
557 * Where: | |
558 * [00 00] shows 0x61 0x00 (on the first 33 sent) or 0xff 0xff for ASF files, and with no ending data for WMV files. | |
559 * It is not yet understood what all this means. | |
560 * And the last [02] byte is probably the header ?session' value. | |
561 * | |
562 * 0x33 */ | |
563 | |
564 memset (data, 0, 40); | |
565 | |
566 for (i=1; i<num_stream_ids; i++) { | |
567 data [ (i-1) * 6 + 2 ] = 0xFF; | |
568 data [ (i-1) * 6 + 3 ] = 0xFF; | |
569 data [ (i-1) * 6 + 4 ] = stream_ids[i]; | |
570 data [ (i-1) * 6 + 5 ] = 0x00; | |
571 } | |
572 | |
573 send_command (s, 0x33, num_stream_ids, 0xFFFF | stream_ids[0] << 16, (num_stream_ids-1)*6+2 , data); | |
574 | |
575 get_answer (s); | |
576 | |
577 /* Start sending file from packet xx. | |
578 * This command is also used for resume downloads or requesting a lost packet. | |
579 * Also used for seeking by sending a play point value which seeks to the media time point. | |
580 * Includes ?session' value in pre header and the maximum media stream time. | |
581 * 0x07 */ | |
582 | |
583 memset (data, 0, 40); | |
584 | |
585 for (i=8; i<16; i++) | |
586 data[i] = 0xFF; | |
587 | |
588 data[20] = 0x04; | |
589 | |
590 send_command (s, 0x07, 1, 0xFFFF | stream_ids[0] << 16, 24, data); | |
591 | |
7880 | 592 stream->fd = s; |
593 stream->streaming_ctrl->streaming_read = asf_mmst_streaming_read; | |
594 stream->streaming_ctrl->streaming_seek = asf_mmst_streaming_seek; | |
595 stream->streaming_ctrl->buffering = 1; | |
596 stream->streaming_ctrl->status = streaming_playing_e; | |
6092 | 597 |
7880 | 598 packet_length1 = packet_length; |
599 printf("mmst packet_length = %d\n",packet_length); | |
6092 | 600 |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
601 string_utf16_close(); |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
602 |
6092 | 603 return 0; |
604 } |