Mercurial > mplayer.hg
annotate libmpdemux/asf_mmst_streaming.c @ 15177:9cf799a1a440
noluma suboption for vf_pp
author | diego |
---|---|
date | Sat, 16 Apr 2005 11:31:17 +0000 |
parents | 424386614ad5 |
children | ed74657f25b1 |
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 | |
13600
a0bb374553a1
typo noticed by Shixin Zeng <shixinzeng at sjtu dot edu dot cn>
diego
parents:
12968
diff
changeset
|
25 #ifndef USE_SETLOCALE |
12675
7c5dee73a7dc
disable iconv in case setlocale is disabled - compile fix
alex
parents:
12674
diff
changeset
|
26 #undef USE_ICONV |
7c5dee73a7dc
disable iconv in case setlocale is disabled - compile fix
alex
parents:
12674
diff
changeset
|
27 #endif |
7c5dee73a7dc
disable iconv in case setlocale is disabled - compile fix
alex
parents:
12674
diff
changeset
|
28 |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
29 #ifdef USE_ICONV |
12674
0392f36045f4
user nl_langinfo if langinfo support present for proper chinese support, feature requested by Shixin Zheng <shixinzheng@sjtu.edu.cn>
alex
parents:
12545
diff
changeset
|
30 #include <iconv.h> |
0392f36045f4
user nl_langinfo if langinfo support present for proper chinese support, feature requested by Shixin Zheng <shixinzheng@sjtu.edu.cn>
alex
parents:
12545
diff
changeset
|
31 #ifdef USE_LANGINFO |
0392f36045f4
user nl_langinfo if langinfo support present for proper chinese support, feature requested by Shixin Zheng <shixinzheng@sjtu.edu.cn>
alex
parents:
12545
diff
changeset
|
32 #include <langinfo.h> |
0392f36045f4
user nl_langinfo if langinfo support present for proper chinese support, feature requested by Shixin Zheng <shixinzheng@sjtu.edu.cn>
alex
parents:
12545
diff
changeset
|
33 #endif |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
34 #endif |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
35 |
6092 | 36 #include "url.h" |
37 #include "asf.h" | |
38 | |
39 #include "stream.h" | |
40 | |
41 #include "network.h" | |
42 | |
43 #define BUF_SIZE 102400 | |
14163
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
44 #define HDR_BUF_SIZE 8192 |
6092 | 45 |
46 typedef struct | |
47 { | |
48 uint8_t buf[BUF_SIZE]; | |
49 int num_bytes; | |
50 | |
51 } command_t; | |
52 | |
7880 | 53 static int seq_num; |
54 static int num_stream_ids; | |
55 static int stream_ids[20]; | |
6092 | 56 |
57 static int get_data (int s, char *buf, size_t count); | |
58 | |
59 static void put_32 (command_t *cmd, uint32_t value) | |
60 { | |
61 cmd->buf[cmd->num_bytes ] = value % 256; | |
62 value = value >> 8; | |
63 cmd->buf[cmd->num_bytes+1] = value % 256 ; | |
64 value = value >> 8; | |
65 cmd->buf[cmd->num_bytes+2] = value % 256 ; | |
66 value = value >> 8; | |
67 cmd->buf[cmd->num_bytes+3] = value % 256 ; | |
68 | |
69 cmd->num_bytes += 4; | |
70 } | |
71 | |
72 static uint32_t get_32 (unsigned char *cmd, int offset) | |
73 { | |
74 uint32_t ret; | |
75 | |
76 ret = cmd[offset] ; | |
77 ret |= cmd[offset+1]<<8 ; | |
78 ret |= cmd[offset+2]<<16 ; | |
79 ret |= cmd[offset+3]<<24 ; | |
80 | |
81 return ret; | |
82 } | |
83 | |
84 static void send_command (int s, int command, uint32_t switches, | |
85 uint32_t extra, int length, | |
86 char *data) | |
87 { | |
88 command_t cmd; | |
89 int len8; | |
90 | |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
91 len8 = (length + 7) / 8; |
6092 | 92 |
93 cmd.num_bytes = 0; | |
94 | |
95 put_32 (&cmd, 0x00000001); /* start sequence */ | |
96 put_32 (&cmd, 0xB00BFACE); /* #-)) */ | |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
97 put_32 (&cmd, len8*8 + 32); |
6092 | 98 put_32 (&cmd, 0x20534d4d); /* protocol type "MMS " */ |
99 put_32 (&cmd, len8 + 4); | |
100 put_32 (&cmd, seq_num); | |
101 seq_num++; | |
102 put_32 (&cmd, 0x0); /* unknown */ | |
103 put_32 (&cmd, 0x0); | |
104 put_32 (&cmd, len8+2); | |
105 put_32 (&cmd, 0x00030000 | command); /* dir | command */ | |
106 put_32 (&cmd, switches); | |
107 put_32 (&cmd, extra); | |
108 | |
109 memcpy (&cmd.buf[48], data, length); | |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
110 if (length & 7) |
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
111 memset(&cmd.buf[48 + length], 0, 8 - (length & 7)); |
6092 | 112 |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
113 if (send (s, cmd.buf, len8*8+48, 0) != (len8*8+48)) { |
6092 | 114 printf ("write error\n"); |
115 } | |
116 } | |
117 | |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
118 #ifdef USE_ICONV |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
119 static iconv_t url_conv; |
11403
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
120 #endif |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
121 |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
122 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
|
123 int i; |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
124 #ifdef USE_ICONV |
11350
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 |
11412 | 128 if (url_conv != (iconv_t)(-1)) |
11403
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
129 { |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
130 memset(dest, 0, 1000); |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
131 len1 = len; len2 = 1000; |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
132 ip = src; op = dest; |
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 iconv(url_conv, &ip, &len1, &op, &len2); |
11403
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 else |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
137 { |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
138 #endif |
15150
38ec64821910
Make string_utf16 code behave almost the same with or without iconv
rtognimp
parents:
14542
diff
changeset
|
139 if (len > 499) len = 499; |
11403
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
140 for (i=0; i<len; i++) { |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
141 dest[i*2] = src[i]; |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
142 dest[i*2+1] = 0; |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
143 } |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
144 /* trailing zeroes */ |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
145 dest[i*2] = 0; |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
146 dest[i*2+1] = 0; |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
147 #ifdef USE_ICONV |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
148 } |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
149 #endif |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
150 } |
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
151 |
6092 | 152 static void get_answer (int s) |
153 { | |
154 char data[BUF_SIZE]; | |
155 int command = 0x1b; | |
156 | |
157 while (command == 0x1b) { | |
158 int len; | |
159 | |
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
|
160 len = recv (s, data, BUF_SIZE, 0) ; |
6092 | 161 if (!len) { |
162 printf ("\nalert! eof\n"); | |
163 return; | |
164 } | |
165 | |
166 command = get_32 (data, 36) & 0xFFFF; | |
167 | |
168 if (command == 0x1b) | |
169 send_command (s, 0x1b, 0, 0, 0, data); | |
170 } | |
171 } | |
172 | |
173 static int get_data (int s, char *buf, size_t count) | |
174 { | |
7953 | 175 ssize_t len; |
176 size_t total = 0; | |
6092 | 177 |
178 while (total < count) { | |
179 | |
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
|
180 len = recv (s, &buf[total], count-total, 0); |
6092 | 181 |
12545 | 182 if (len<=0) { |
6092 | 183 perror ("read error:"); |
184 return 0; | |
185 } | |
186 | |
187 total += len; | |
188 | |
189 if (len != 0) { | |
190 // printf ("[%d/%d]", total, count); | |
191 fflush (stdout); | |
192 } | |
193 | |
194 } | |
195 | |
196 return 1; | |
197 | |
198 } | |
199 | |
200 static int get_header (int s, uint8_t *header, streaming_ctrl_t *streaming_ctrl) | |
201 { | |
202 unsigned char pre_header[8]; | |
7953 | 203 int header_len; |
6092 | 204 |
205 header_len = 0; | |
206 | |
207 while (1) { | |
208 if (!get_data (s, pre_header, 8)) { | |
209 printf ("pre-header read failed\n"); | |
210 return 0; | |
211 } | |
212 if (pre_header[4] == 0x02) { | |
213 | |
214 int packet_len; | |
215 | |
216 packet_len = (pre_header[7] << 8 | pre_header[6]) - 8; | |
217 | |
218 // printf ("asf header packet detected, len=%d\n", packet_len); | |
219 | |
14163
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
220 if (packet_len < 0 || packet_len > HDR_BUF_SIZE - header_len) { |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
221 mp_msg(MSGT_NETWORK, MSGL_FATAL, "Invalid header size, giving up\n"); |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
222 return 0; |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
223 } |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
224 |
6092 | 225 if (!get_data (s, &header[header_len], packet_len)) { |
226 printf ("header data read failed\n"); | |
227 return 0; | |
228 } | |
229 | |
230 header_len += packet_len; | |
231 | |
232 if ( (header[header_len-1] == 1) && (header[header_len-2]==1)) { | |
233 | |
234 | |
235 if( streaming_bufferize( streaming_ctrl, header, header_len )<0 ) { | |
236 return -1; | |
237 } | |
238 | |
239 // printf ("get header packet finished\n"); | |
240 | |
241 return (header_len); | |
242 | |
243 } | |
244 | |
245 } else { | |
246 | |
7953 | 247 int32_t packet_len; |
6092 | 248 int command; |
249 char data[BUF_SIZE]; | |
250 | |
7953 | 251 if (!get_data (s, (char*)&packet_len, 4)) { |
6092 | 252 printf ("packet_len read failed\n"); |
253 return 0; | |
254 } | |
255 | |
7953 | 256 packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4; |
6092 | 257 |
258 // printf ("command packet detected, len=%d\n", packet_len); | |
14163
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
259 |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
260 if (packet_len < 0 || packet_len > BUF_SIZE) { |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
261 mp_msg(MSGT_NETWORK, MSGL_FATAL, |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
262 "Invalid rtsp packet size, giving up\n"); |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
263 return 0; |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
264 } |
6092 | 265 |
266 if (!get_data (s, data, packet_len)) { | |
267 printf ("command data read failed\n"); | |
268 return 0; | |
269 } | |
270 | |
271 command = get_32 (data, 24) & 0xFFFF; | |
272 | |
273 // printf ("command: %02x\n", command); | |
274 | |
275 if (command == 0x1b) | |
276 send_command (s, 0x1b, 0, 0, 0, data); | |
277 | |
278 } | |
279 | |
280 // printf ("get header packet succ\n"); | |
281 } | |
282 } | |
283 | |
7880 | 284 static int interp_header (uint8_t *header, int header_len) |
6092 | 285 { |
286 int i; | |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7309
diff
changeset
|
287 int packet_length=-1; |
6092 | 288 |
289 /* | |
290 * parse header | |
291 */ | |
292 | |
293 i = 30; | |
294 while (i<header_len) { | |
295 | |
296 uint64_t guid_1, guid_2, length; | |
297 | |
298 guid_2 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) | |
299 | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) | |
300 | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) | |
301 | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); | |
302 i += 8; | |
303 | |
304 guid_1 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) | |
305 | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) | |
306 | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) | |
307 | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); | |
308 i += 8; | |
309 | |
310 // printf ("guid found: %016llx%016llx\n", guid_1, guid_2); | |
311 | |
312 length = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) | |
313 | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) | |
314 | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) | |
315 | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); | |
316 | |
317 i += 8; | |
318 | |
12121 | 319 if ( (guid_1 == 0x6cce6200aa00d9a6ULL) && (guid_2 == 0x11cf668e75b22630ULL) ) { |
6092 | 320 printf ("header object\n"); |
12121 | 321 } else if ((guid_1 == 0x6cce6200aa00d9a6ULL) && (guid_2 == 0x11cf668e75b22636ULL)) { |
6092 | 322 printf ("data object\n"); |
12121 | 323 } else if ((guid_1 == 0x6553200cc000e48eULL) && (guid_2 == 0x11cfa9478cabdca1ULL)) { |
6092 | 324 |
325 packet_length = get_32(header, i+92-24); | |
326 | |
327 printf ("file object, packet length = %d (%d)\n", | |
328 packet_length, get_32(header, i+96-24)); | |
329 | |
330 | |
12121 | 331 } else if ((guid_1 == 0x6553200cc000e68eULL) && (guid_2 == 0x11cfa9b7b7dc0791ULL)) { |
6092 | 332 |
333 int stream_id = header[i+48] | header[i+49] << 8; | |
334 | |
335 printf ("stream object, stream id: %d\n", stream_id); | |
336 | |
15173
424386614ad5
Fix potential buffer overflow for urls with more than 20 streams
rtognimp
parents:
15150
diff
changeset
|
337 if (num_stream_ids < 20) { |
6092 | 338 stream_ids[num_stream_ids] = stream_id; |
339 num_stream_ids++; | |
15173
424386614ad5
Fix potential buffer overflow for urls with more than 20 streams
rtognimp
parents:
15150
diff
changeset
|
340 } else { |
424386614ad5
Fix potential buffer overflow for urls with more than 20 streams
rtognimp
parents:
15150
diff
changeset
|
341 printf ("too many id, stream skipped"); |
424386614ad5
Fix potential buffer overflow for urls with more than 20 streams
rtognimp
parents:
15150
diff
changeset
|
342 } |
6092 | 343 |
344 } else { | |
345 printf ("unknown object\n"); | |
346 } | |
347 | |
348 // printf ("length : %lld\n", length); | |
349 | |
350 i += length-24; | |
351 | |
352 } | |
353 | |
354 return packet_length; | |
355 | |
356 } | |
357 | |
358 | |
7880 | 359 static int get_media_packet (int s, int padding, streaming_ctrl_t *stream_ctrl) { |
6092 | 360 unsigned char pre_header[8]; |
361 char data[BUF_SIZE]; | |
7880 | 362 |
363 if (!get_data (s, pre_header, 8)) { | |
364 printf ("pre-header read failed\n"); | |
365 return 0; | |
366 } | |
367 | |
368 // for (i=0; i<8; i++) | |
369 // printf ("pre_header[%d] = %02x (%d)\n", | |
370 // i, pre_header[i], pre_header[i]); | |
371 | |
372 if (pre_header[4] == 0x04) { | |
373 | |
374 int packet_len; | |
375 | |
376 packet_len = (pre_header[7] << 8 | pre_header[6]) - 8; | |
377 | |
378 // printf ("asf media packet detected, len=%d\n", packet_len); | |
379 | |
14163
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
380 if (packet_len < 0 || packet_len > BUF_SIZE) { |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
381 mp_msg(MSGT_NETWORK, MSGL_FATAL, |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
382 "Invalid rtsp packet size, giving up\n"); |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
383 return 0; |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
384 } |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
385 |
7880 | 386 if (!get_data (s, data, packet_len)) { |
387 printf ("media data read failed\n"); | |
388 return 0; | |
389 } | |
390 | |
391 streaming_bufferize(stream_ctrl, data, padding); | |
392 | |
393 } else { | |
394 | |
7953 | 395 int32_t packet_len; |
396 int command; | |
7880 | 397 |
7953 | 398 if (!get_data (s, (char*)&packet_len, 4)) { |
7880 | 399 printf ("packet_len read failed\n"); |
400 return 0; | |
401 } | |
402 | |
7953 | 403 packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4; |
7880 | 404 |
14163
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
405 if (packet_len < 0 || packet_len > BUF_SIZE) { |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
406 mp_msg(MSGT_NETWORK, MSGL_FATAL, |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
407 "Invalid rtsp packet size, giving up\n"); |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
408 return 0; |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
409 } |
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
410 |
7880 | 411 if (!get_data (s, data, packet_len)) { |
412 printf ("command data read failed\n"); | |
413 return 0; | |
414 } | |
415 | |
416 if ( (pre_header[7] != 0xb0) || (pre_header[6] != 0x0b) | |
417 || (pre_header[5] != 0xfa) || (pre_header[4] != 0xce) ) { | |
418 | |
419 printf ("missing signature\n"); | |
420 return -1; | |
421 } | |
422 | |
423 command = get_32 (data, 24) & 0xFFFF; | |
424 | |
7977 | 425 // printf ("\ncommand packet detected, len=%d cmd=0x%X\n", packet_len, command); |
7880 | 426 |
427 if (command == 0x1b) | |
428 send_command (s, 0x1b, 0, 0, 0, data); | |
429 else if (command == 0x1e) { | |
430 printf ("everything done. Thank you for downloading a media file containing proprietary and patentend technology.\n"); | |
431 return 0; | |
432 } | |
433 else if (command == 0x21 ) { | |
434 // Looks like it's new in WMS9 | |
435 // Unknown command, but ignoring it seems to work. | |
436 return 0; | |
437 } | |
438 else if (command != 0x05) { | |
439 printf ("unknown command %02x\n", command); | |
440 return -1; | |
441 } | |
442 } | |
443 | |
444 // printf ("get media packet succ\n"); | |
445 | |
446 return 1; | |
447 } | |
6092 | 448 |
449 | |
7880 | 450 static int packet_length1; |
6092 | 451 |
452 int | |
453 asf_mmst_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) | |
454 { | |
7880 | 455 int len; |
456 | |
457 while( stream_ctrl->buffer_size==0 ) { | |
458 // buffer is empty - fill it! | |
459 int ret = get_media_packet( fd, packet_length1, stream_ctrl); | |
460 if( ret<0 ) { | |
461 printf("get_media_packet error : %s\n",strerror(errno)); | |
462 return -1; | |
12077 | 463 } else if (ret==0) //EOF? |
464 return ret; | |
7880 | 465 } |
466 | |
467 len = stream_ctrl->buffer_size-stream_ctrl->buffer_pos; | |
468 if(len>size) len=size; | |
6092 | 469 memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len ); |
470 stream_ctrl->buffer_pos += len; | |
471 if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) { | |
472 free( stream_ctrl->buffer ); | |
473 stream_ctrl->buffer = NULL; | |
474 stream_ctrl->buffer_size = 0; | |
475 stream_ctrl->buffer_pos = 0; | |
476 } | |
7880 | 477 return len; |
6092 | 478 |
479 } | |
480 | |
481 int | |
482 asf_mmst_streaming_seek( int fd, off_t pos, streaming_ctrl_t *streaming_ctrl ) | |
483 { | |
484 return -1; | |
7953 | 485 // Shut up gcc warning |
486 fd++; | |
487 pos++; | |
488 streaming_ctrl=NULL; | |
6092 | 489 } |
490 | |
491 int asf_mmst_streaming_start(stream_t *stream) | |
492 { | |
493 char str[1024]; | |
10183 | 494 char data[BUF_SIZE]; |
14163
dd835e8f3698
fix a problem pointed out by iDEFENSE and several similar ones.
reimar
parents:
13600
diff
changeset
|
495 uint8_t asf_header[HDR_BUF_SIZE]; |
6092 | 496 int asf_header_len; |
497 int len, i, packet_length; | |
12751 | 498 char *path, *unescpath; |
6092 | 499 URL_t *url1 = stream->streaming_ctrl->url; |
7953 | 500 int s = stream->fd; |
6092 | 501 |
7250
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
502 if( s>0 ) { |
10281 | 503 closesocket( stream->fd ); |
7250
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
504 stream->fd = -1; |
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
505 } |
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
506 |
6092 | 507 /* parse url */ |
508 path = strchr(url1->file,'/') + 1; | |
509 | |
12751 | 510 /* mmst filename are not url_escaped by MS MediaPlayer and are expected as |
511 * "plain text" by the server, so need to decode it here | |
512 */ | |
513 unescpath=malloc(strlen(path)+1); | |
514 if (!unescpath) { | |
515 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n"); | |
516 return -1; | |
517 } | |
518 url_unescape_string(unescpath,path); | |
519 path=unescpath; | |
520 | |
521 | |
12968 | 522 if( url1->port==0 ) { |
523 url1->port=1755; | |
524 } | |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10281
diff
changeset
|
525 s = connect2Server( url1->hostname, url1->port, 1); |
7250
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
526 if( s<0 ) { |
12751 | 527 free(path); |
7250
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
528 return s; |
27a1315d6af4
Checked if the connection succeeded before writing in the socket.
bertrand
parents:
6092
diff
changeset
|
529 } |
6092 | 530 printf ("connected\n"); |
7880 | 531 |
532 seq_num=0; | |
6092 | 533 |
534 /* | |
535 * Send the initial connect info including player version no. Client GUID (random) and the host address being connected to. | |
536 * This command is sent at the very start of protocol initiation. It sends local information to the serve | |
537 * cmd 1 0x01 | |
538 * */ | |
539 | |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
540 /* prepare for the url encoding conversion */ |
11403
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
541 #ifdef USE_ICONV |
12674
0392f36045f4
user nl_langinfo if langinfo support present for proper chinese support, feature requested by Shixin Zheng <shixinzheng@sjtu.edu.cn>
alex
parents:
12545
diff
changeset
|
542 #ifdef USE_LANGINFO |
0392f36045f4
user nl_langinfo if langinfo support present for proper chinese support, feature requested by Shixin Zheng <shixinzheng@sjtu.edu.cn>
alex
parents:
12545
diff
changeset
|
543 url_conv = iconv_open("UTF-16LE",nl_langinfo(CODESET)); |
0392f36045f4
user nl_langinfo if langinfo support present for proper chinese support, feature requested by Shixin Zheng <shixinzheng@sjtu.edu.cn>
alex
parents:
12545
diff
changeset
|
544 #else |
14542
4a6b79a1ad52
remove all setlocale calls, they break the behaviour of sscanf and
reimar
parents:
14163
diff
changeset
|
545 url_conv = iconv_open("UTF-16LE", NULL); |
11403
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
546 #endif |
12674
0392f36045f4
user nl_langinfo if langinfo support present for proper chinese support, feature requested by Shixin Zheng <shixinzheng@sjtu.edu.cn>
alex
parents:
12545
diff
changeset
|
547 #endif |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
548 |
10183 | 549 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
|
550 string_utf16 (data, str, strlen(str)); |
6092 | 551 // send_command(s, commandno ....) |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
552 send_command (s, 1, 0, 0x0004000b, strlen(str)*2+2, data); |
6092 | 553 |
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
|
554 len = recv (s, data, BUF_SIZE, 0) ; |
6092 | 555 |
556 /*This sends details of the local machine IP address to a Funnel system at the server. | |
557 * Also, the TCP or UDP transport selection is sent. | |
558 * | |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
559 * here 192.168.0.1 is local ip address TCP/UDP states the tronsport we r using |
6092 | 560 * and 1037 is the local TCP or UDP socket number |
561 * cmd 2 0x02 | |
562 * */ | |
563 | |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
564 string_utf16 (&data[8], "\002\000\\\\192.168.0.1\\TCP\\1037", 24); |
6092 | 565 memset (data, 0, 8); |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
566 send_command (s, 2, 0, 0, 24*2+10, data); |
6092 | 567 |
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
|
568 len = recv (s, data, BUF_SIZE, 0) ; |
6092 | 569 |
570 /* This command sends file path (at server) and file name request to the server. | |
571 * 0x5 */ | |
572 | |
573 string_utf16 (&data[8], path, strlen(path)); | |
574 memset (data, 0, 8); | |
11225
48bb1fd37d2a
Fixing tons of 10ls. Patch by rgselk <rgselknospam@yahoo.com>
alex
parents:
10625
diff
changeset
|
575 send_command (s, 5, 0, 0, strlen(path)*2+10, data); |
12751 | 576 free(path); |
6092 | 577 |
578 get_answer (s); | |
579 | |
580 /* The ASF header chunk request. Includes ?session' variable for pre header value. | |
581 * After this command is sent, | |
582 * the server replies with 0x11 command and then the header chunk with header data follows. | |
583 * 0x15 */ | |
584 | |
585 memset (data, 0, 40); | |
586 data[32] = 2; | |
587 | |
588 send_command (s, 0x15, 1, 0, 40, data); | |
589 | |
590 num_stream_ids = 0; | |
591 /* get_headers(s, asf_header); */ | |
592 | |
593 asf_header_len = get_header (s, asf_header, stream->streaming_ctrl); | |
594 // printf("---------------------------------- asf_header %d\n",asf_header); | |
12545 | 595 if (asf_header_len==0) return -1; //error reading header |
6092 | 596 packet_length = interp_header (asf_header, asf_header_len); |
597 | |
598 | |
599 /* | |
600 * This command is the media stream MBR selector. Switches are always 6 bytes in length. | |
601 * After all switch elements, data ends with bytes [00 00] 00 20 ac 40 [02]. | |
602 * Where: | |
603 * [00 00] shows 0x61 0x00 (on the first 33 sent) or 0xff 0xff for ASF files, and with no ending data for WMV files. | |
604 * It is not yet understood what all this means. | |
605 * And the last [02] byte is probably the header ?session' value. | |
606 * | |
607 * 0x33 */ | |
608 | |
609 memset (data, 0, 40); | |
610 | |
611 for (i=1; i<num_stream_ids; i++) { | |
612 data [ (i-1) * 6 + 2 ] = 0xFF; | |
613 data [ (i-1) * 6 + 3 ] = 0xFF; | |
614 data [ (i-1) * 6 + 4 ] = stream_ids[i]; | |
615 data [ (i-1) * 6 + 5 ] = 0x00; | |
616 } | |
617 | |
618 send_command (s, 0x33, num_stream_ids, 0xFFFF | stream_ids[0] << 16, (num_stream_ids-1)*6+2 , data); | |
619 | |
620 get_answer (s); | |
621 | |
622 /* Start sending file from packet xx. | |
623 * This command is also used for resume downloads or requesting a lost packet. | |
624 * Also used for seeking by sending a play point value which seeks to the media time point. | |
625 * Includes ?session' value in pre header and the maximum media stream time. | |
626 * 0x07 */ | |
627 | |
628 memset (data, 0, 40); | |
629 | |
630 for (i=8; i<16; i++) | |
631 data[i] = 0xFF; | |
632 | |
633 data[20] = 0x04; | |
634 | |
635 send_command (s, 0x07, 1, 0xFFFF | stream_ids[0] << 16, 24, data); | |
636 | |
7880 | 637 stream->fd = s; |
638 stream->streaming_ctrl->streaming_read = asf_mmst_streaming_read; | |
639 stream->streaming_ctrl->streaming_seek = asf_mmst_streaming_seek; | |
640 stream->streaming_ctrl->buffering = 1; | |
641 stream->streaming_ctrl->status = streaming_playing_e; | |
6092 | 642 |
7880 | 643 packet_length1 = packet_length; |
644 printf("mmst packet_length = %d\n",packet_length); | |
6092 | 645 |
11403
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
646 #ifdef USE_ICONV |
11412 | 647 if (url_conv != (iconv_t)(-1)) |
11403
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
648 iconv_close(url_conv); |
86ab7e0b2a65
fallback to non-iconv dummy utf16 conversion if iconv failed
alex
parents:
11402
diff
changeset
|
649 #endif |
11350
007ec48cf146
Current mplayer (mine is mplayer-1.0-pre1cvs20031001) cannot play mms
attila
parents:
11226
diff
changeset
|
650 |
6092 | 651 return 0; |
652 } |