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