1 /*
2 * MMS protocol over HTTP
3 * Copyright (c) 2010 Zhentan Feng <spyfeng at gmail dot com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /*
23 * Reference
24 * Windows Media HTTP Streaming Protocol.
25 * http://msdn.microsoft.com/en-us/library/cc251059(PROT.10).aspx
26 */
27
28 #include <string.h>
37
38 #define CHUNK_HEADER_LENGTH 4 // 2bytes chunk type and 2bytes chunk length.
39 #define EXT_HEADER_LENGTH 8 // 4bytes sequence, 2bytes useless and 2bytes chunk length.
40
41 // see Ref 2.2.1.8
42 #define USERAGENT "User-Agent: NSPlayer/4.1.0.3856\r\n"
43 // see Ref 2.2.1.4.33
44 // the GUID value can be changed to any valid value.
45 #define CLIENTGUID "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}\r\n"
46
47 // see Ref 2.2.3 for packet type define:
48 // chunk type contains 2 fields: Frame and PacketID.
49 // Frame is 0x24 or 0xA4(rarely), different PacketID indicates different packet type.
56
63
65 {
71 return 0;
72 }
73
75 {
80 int chunk_len, res, ext_header_len;
81
86 }
87 chunk_type =
AV_RL16(chunk_header);
88 chunk_len =
AV_RL16(chunk_header + 2);
89
90 switch (chunk_type) {
93 ext_header_len = 4;
94 break;
97 ext_header_len = 8;
98 break;
99 default:
102 }
103
105 if (res != ext_header_len) {
108 }
109 *
len = chunk_len - ext_header_len;
112 return chunk_type;
113 }
114
116 {
118 int res;
121 "Data packet length %d exceeds the in_buffer size %"SIZE_SPECIFIER "\n",
124 }
130 }
135 } else {
137 }
140 return 0;
141 }
142
144 {
148
149 for (;;) {
152 if (res < 0) {
153 return res;
155 // get asf header and stored it
163 }
164 }
168 }
170 }
173 "Asf header packet len = %d exceed the asf header buf size %d\n",
176 }
180 "Recv asf header data len %d != expected len %d\n", res,
len);
182 }
187 return res;
188 }
190 // read data packet and do padding
192 } else {
196 "Other packet len = %d exceed the in_buffer size %"SIZE_SPECIFIER "\n",
199 }
204 } else {
206 continue;
207 }
208 }
209 }
210 }
211 }
212
214 {
216 char httpname[256], path[256], host[128];
217 char *stream_selection =
NULL;
221
225
227 host,
sizeof(host), &port, path,
sizeof(path), mmsh->
location);
228 if (port<0)
229 port = 80; // default mmsh protocol port
230 ff_url_join(httpname,
sizeof(httpname),
"http",
NULL, host, port,
"%s", path);
231
233 &
h->interrupt_callback) < 0) {
235 }
236
238 "Accept: */*\r\n"
240 "Host: %s:%d\r\n"
241 "Pragma: no-cache,rate=1.000000,stream-time=0,"
242 "stream-offset=0:0,request-context=%u,max-duration=0\r\n"
244 "Connection: Close\r\n",
247
253 }
254 }
255
257 if (err) {
259 }
261 if (err) {
264 }
265
266 // close the socket and then reopen it for sending the second play request.
270 &
h->interrupt_callback)) < 0) {
272 }
274 if (!stream_selection)
279 if (err < 0)
282 }
283 // send play request
285 "Accept: */*\r\n"
287 "Host: %s:%d\r\n"
288 "Pragma: no-cache,rate=1.000000,request-context=%u\r\n"
289 "Pragma: xPlayStrm=1\r\n"
291 "Pragma: stream-switch-count=%d\r\n"
292 "Pragma: stream-switch-entry=%s\r\n"
293 "Pragma: no-cache,rate=1.000000,stream-time=%u"
294 "Connection: Close\r\n",
297 if (err < 0) {
300 }
303
305 if (err) {
307 }
308
310 if (err) {
313 }
314
316 return 0;
321 return err;
322 }
323
325 {
327 }
328
330 {
335
336 switch (chunk_type) {
345 return res;
346 }
347 break;
350 default:
353 }
354 return 0;
355 }
356
358 {
359 int res = 0;
362 do {
364 // copy asf header into buffer
366 } else {
368 return res;
370 }
371 } while (!res);
372 return res;
373 }
374
377 {
382
383 if (!mmsh)
385
389 h->priv_data = mmsh_old;
394 }else {
395 h->priv_data = mmsh_old;
397 }
398
400 }
401
403 {
406
407 if(
pos == 0 && whence == SEEK_CUR)
410 }
411
421 .default_whitelist = "http,tcp",
422 };