annotate libmpdemux/asf_mmst_streaming.c @ 15453:d7a2ffc6e694

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