Mercurial > libavformat.hg
annotate mmsh.c @ 6410:31aef55204bd libavformat
rtsp: Return EOF if the TCP control channel is closed
author | mstorsjo |
---|---|
date | Wed, 25 Aug 2010 13:42:17 +0000 |
parents | c2e5016e2b4e |
children | 2f0124b97014 |
rev | line source |
---|---|
6396
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
1 /* |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
2 * MMS protocol over HTTP |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
3 * Copyright (c) 2010 Zhentan Feng <spyfeng at gmail dot com> |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
4 * |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
5 * This file is part of FFmpeg. |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
6 * |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
11 * |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
16 * |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
20 */ |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
21 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
22 /* |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
23 * Reference |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
24 * Windows Media HTTP Streaming Protocol. |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
25 * http://msdn.microsoft.com/en-us/library/cc251059(PROT.10).aspx |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
26 */ |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
27 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
28 #include <string.h> |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
29 #include "libavutil/intreadwrite.h" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
30 #include "libavutil/avstring.h" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
31 #include "libavformat/internal.h" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
32 #include "mms.h" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
33 #include "asf.h" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
34 #include "http.h" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
35 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
36 #define CHUNK_HEADER_LENGTH 4 // 2bytes chunk type and 2bytes chunk length. |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
37 #define EXT_HEADER_LENGTH 8 // 4bytes sequence, 2bytes useless and 2bytes chunk length. |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
38 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
39 // see Ref 2.2.1.8 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
40 #define USERAGENT "User-Agent: NSPlayer/4.1.0.3856\r\n" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
41 // see Ref 2.2.1.4.33 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
42 // the guid value can be changed to any valid value. |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
43 #define CLIENTGUID "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}\r\n" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
44 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
45 // see Ref 2.2.3 for packet type define: |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
46 // chunk type contains 2 fields: Frame and PacketID. |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
47 // Frame is 0x24 or 0xA4(rarely), different PacketID indicates different packet type. |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
48 typedef enum { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
49 CHUNK_TYPE_DATA = 0x4424, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
50 CHUNK_TYPE_ASF_HEADER = 0x4824, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
51 CHUNK_TYPE_END = 0x4524, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
52 CHUNK_TYPE_STREAM_CHANGE = 0x4324, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
53 } ChunkType; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
54 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
55 typedef struct { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
56 MMSContext mms; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
57 int request_seq; ///< request packet sequence |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
58 int chunk_seq; ///< data packet sequence |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
59 } MMSHContext; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
60 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
61 static int mmsh_close(URLContext *h) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
62 { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
63 MMSHContext *mmsh = (MMSHContext *)h->priv_data; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
64 MMSContext *mms = &mmsh->mms; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
65 if (mms->mms_hd) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
66 url_close(mms->mms_hd); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
67 av_free(mms->streams); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
68 av_free(mms->asf_header); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
69 av_freep(&h->priv_data); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
70 return 0; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
71 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
72 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
73 static ChunkType get_chunk_header(MMSHContext *mmsh, int *len) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
74 { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
75 MMSContext *mms = &mmsh->mms; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
76 uint8_t chunk_header[CHUNK_HEADER_LENGTH]; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
77 uint8_t ext_header[EXT_HEADER_LENGTH]; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
78 ChunkType chunk_type; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
79 int chunk_len, res, ext_header_len; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
80 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
81 res = url_read_complete(mms->mms_hd, chunk_header, CHUNK_HEADER_LENGTH); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
82 if (res != CHUNK_HEADER_LENGTH) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
83 av_log(NULL, AV_LOG_ERROR, "Read data packet header failed!\n"); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
84 return AVERROR(EIO); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
85 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
86 chunk_type = AV_RL16(chunk_header); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
87 chunk_len = AV_RL16(chunk_header + 2); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
88 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
89 switch (chunk_type) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
90 case CHUNK_TYPE_END: |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
91 case CHUNK_TYPE_STREAM_CHANGE: |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
92 ext_header_len = 4; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
93 break; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
94 case CHUNK_TYPE_ASF_HEADER: |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
95 case CHUNK_TYPE_DATA: |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
96 ext_header_len = 8; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
97 break; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
98 default: |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
99 av_log(NULL, AV_LOG_ERROR, "Strange chunk type %d\n", chunk_type); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
100 return AVERROR_INVALIDDATA; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
101 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
102 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
103 res = url_read_complete(mms->mms_hd, ext_header, ext_header_len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
104 if (res != ext_header_len) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
105 av_log(NULL, AV_LOG_ERROR, "Read ext header failed!\n"); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
106 return AVERROR(EIO); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
107 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
108 *len = chunk_len - ext_header_len; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
109 if (chunk_type == CHUNK_TYPE_END || chunk_type == CHUNK_TYPE_DATA) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
110 mmsh->chunk_seq = AV_RL32(ext_header); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
111 return chunk_type; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
112 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
113 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
114 static int read_data_packet(MMSHContext *mmsh, const int len) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
115 { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
116 MMSContext *mms = &mmsh->mms; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
117 int res; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
118 if (len > sizeof(mms->in_buffer)) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
119 av_log(NULL, AV_LOG_ERROR, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
120 "Data packet length %d exceeds the in_buffer size %d\n", |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
121 len, sizeof(mms->in_buffer)); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
122 return AVERROR(EIO); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
123 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
124 res = url_read_complete(mms->mms_hd, mms->in_buffer, len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
125 dprintf(NULL, "Data packet len = %d\n", len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
126 if (res != len) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
127 av_log(NULL, AV_LOG_ERROR, "Read data packet failed!\n"); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
128 return AVERROR(EIO); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
129 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
130 if (len > mms->asf_packet_len) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
131 av_log(NULL, AV_LOG_ERROR, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
132 "Chunk length %d exceed packet length %d\n",len, mms->asf_packet_len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
133 return AVERROR_INVALIDDATA; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
134 } else { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
135 memset(mms->in_buffer + len, 0, mms->asf_packet_len - len); // padding |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
136 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
137 mms->read_in_ptr = mms->in_buffer; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
138 mms->remaining_in_len = mms->asf_packet_len; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
139 return 0; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
140 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
141 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
142 static int get_http_header_data(MMSHContext *mmsh) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
143 { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
144 MMSContext *mms = &mmsh->mms; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
145 int res, len; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
146 ChunkType chunk_type; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
147 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
148 for (;;) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
149 len = 0; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
150 chunk_type = get_chunk_header(mmsh, &len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
151 if (chunk_type < 0) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
152 return chunk_type; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
153 } else if (chunk_type == CHUNK_TYPE_ASF_HEADER){ |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
154 // get asf header and stored it |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
155 if (!mms->header_parsed) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
156 if (mms->asf_header) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
157 if (len != mms->asf_header_size) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
158 mms->asf_header_size = len; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
159 dprintf(NULL, "Header len changed from %d to %d\n", |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
160 mms->asf_header_size, len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
161 av_freep(&mms->asf_header); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
162 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
163 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
164 mms->asf_header = av_mallocz(len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
165 if (!mms->asf_header) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
166 return AVERROR(ENOMEM); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
167 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
168 mms->asf_header_size = len; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
169 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
170 if (len > mms->asf_header_size) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
171 av_log(NULL, AV_LOG_ERROR, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
172 "Asf header packet len = %d exceed the asf header buf size %d\n", |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
173 len, mms->asf_header_size); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
174 return AVERROR(EIO); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
175 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
176 res = url_read_complete(mms->mms_hd, mms->asf_header, len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
177 if (res != len) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
178 av_log(NULL, AV_LOG_ERROR, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
179 "Recv asf header data len %d != expected len %d\n", res, len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
180 return AVERROR(EIO); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
181 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
182 mms->asf_header_size = len; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
183 if (!mms->header_parsed) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
184 res = ff_mms_asf_header_parser(mms); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
185 mms->header_parsed = 1; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
186 return res; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
187 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
188 } else if (chunk_type == CHUNK_TYPE_DATA) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
189 // read data packet and do padding |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
190 return read_data_packet(mmsh, len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
191 } else { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
192 if (len) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
193 if (len > sizeof(mms->in_buffer)) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
194 av_log(NULL, AV_LOG_ERROR, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
195 "Other packet len = %d exceed the in_buffer size %d\n", |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
196 len, sizeof(mms->in_buffer)); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
197 return AVERROR(EIO); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
198 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
199 res = url_read_complete(mms->mms_hd, mms->in_buffer, len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
200 if (res != len) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
201 av_log(NULL, AV_LOG_ERROR, "Read other chunk type data failed!\n"); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
202 return AVERROR(EIO); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
203 } else { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
204 dprintf(NULL, "Skip chunk type %d \n", chunk_type); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
205 continue; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
206 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
207 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
208 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
209 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
210 return 0; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
211 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
212 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
213 static int mmsh_open(URLContext *h, const char *uri, int flags) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
214 { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
215 int i, port, err; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
216 char httpname[256], path[256], host[128], location[1024]; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
217 char *stream_selection; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
218 char headers[1024]; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
219 MMSHContext *mmsh; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
220 MMSContext *mms; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
221 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
222 mmsh = h->priv_data = av_mallocz(sizeof(MMSHContext)); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
223 if (!h->priv_data) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
224 return AVERROR(ENOMEM); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
225 mmsh->request_seq = h->is_streamed = 1; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
226 mms = &mmsh->mms; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
227 av_strlcpy(location, uri, sizeof(location)); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
228 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
229 av_url_split(NULL, 0, NULL, 0, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
230 host, sizeof(host), &port, path, sizeof(path), location); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
231 if (port<0) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
232 port = 80; // default mmsh protocol port |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
233 ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, path); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
234 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
235 if (url_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
236 return AVERROR(EIO); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
237 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
238 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
239 snprintf(headers, sizeof(headers), |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
240 "Accept: */*\r\n" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
241 USERAGENT |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
242 "Host: %s:%d\r\n" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
243 "Pragma: no-cache,rate=1.000000,stream-time=0," |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
244 "stream-offset=0:0,request-context=%u,max-duration=0\r\n" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
245 CLIENTGUID |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
246 "Connection: Close\r\n\r\n", |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
247 host, port, mmsh->request_seq++); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
248 ff_http_set_headers(mms->mms_hd, headers); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
249 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
250 err = url_connect(mms->mms_hd); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
251 if (err) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
252 goto fail; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
253 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
254 err = get_http_header_data(mmsh); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
255 if (err) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
256 av_log(NULL, AV_LOG_ERROR, "Get http header data failed!\n"); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
257 goto fail; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
258 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
259 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
260 // close the socket and then reopen it for sending the second play request. |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
261 url_close(mms->mms_hd); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
262 memset(headers, 0, sizeof(headers)); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
263 if (url_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
264 return AVERROR(EIO); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
265 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
266 stream_selection = av_mallocz(mms->stream_num * 19 + 1); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
267 if (!stream_selection) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
268 return AVERROR(ENOMEM); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
269 for (i = 0; i < mms->stream_num; i++) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
270 char tmp[20]; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
271 err = snprintf(tmp, sizeof(tmp), "ffff:%d:0 ", mms->streams[i].id); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
272 if (err < 0) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
273 goto fail; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
274 av_strlcat(stream_selection, tmp, mms->stream_num * 19 + 1); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
275 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
276 // send play request |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
277 err = snprintf(headers, sizeof(headers), |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
278 "Accept: */*\r\n" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
279 USERAGENT |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
280 "Host: %s:%d\r\n" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
281 "Pragma: no-cache,rate=1.000000,request-context=%u\r\n" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
282 "Pragma: xPlayStrm=1\r\n" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
283 CLIENTGUID |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
284 "Pragma: stream-switch-count=%d\r\n" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
285 "Pragma: stream-switch-entry=%s\r\n" |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
286 "Connection: Close\r\n\r\n", |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
287 host, port, mmsh->request_seq++, mms->stream_num, stream_selection); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
288 av_freep(&stream_selection); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
289 if (err < 0) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
290 av_log(NULL, AV_LOG_ERROR, "Build play request failed!\n"); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
291 goto fail; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
292 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
293 dprintf(NULL, "out_buffer is %s", headers); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
294 ff_http_set_headers(mms->mms_hd, headers); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
295 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
296 err = url_connect(mms->mms_hd); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
297 if (err) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
298 goto fail; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
299 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
300 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
301 err = get_http_header_data(mmsh); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
302 if (err) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
303 av_log(NULL, AV_LOG_ERROR, "Get http header data failed!\n"); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
304 goto fail; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
305 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
306 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
307 dprintf(NULL, "Connection successfully open\n"); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
308 return 0; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
309 fail: |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
310 av_freep(&stream_selection); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
311 mmsh_close(h); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
312 dprintf(NULL, "Connection failed with error %d\n", err); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
313 return err; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
314 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
315 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
316 static int handle_chunk_type(MMSHContext *mmsh) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
317 { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
318 MMSContext *mms = &mmsh->mms; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
319 int res, len = 0; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
320 ChunkType chunk_type; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
321 chunk_type = get_chunk_header(mmsh, &len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
322 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
323 switch (chunk_type) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
324 case CHUNK_TYPE_END: |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
325 mmsh->chunk_seq = 0; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
326 av_log(NULL, AV_LOG_ERROR, "Stream ended!\n"); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
327 return AVERROR(EIO); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
328 case CHUNK_TYPE_STREAM_CHANGE: |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
329 mms->header_parsed = 0; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
330 if (res = get_http_header_data(mmsh)) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
331 av_log(NULL, AV_LOG_ERROR,"Stream changed! Failed to get new header!\n"); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
332 return res; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
333 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
334 break; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
335 case CHUNK_TYPE_DATA: |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
336 return read_data_packet(mmsh, len); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
337 default: |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
338 av_log(NULL, AV_LOG_ERROR, "Recv other type packet %d\n", chunk_type); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
339 return AVERROR_INVALIDDATA; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
340 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
341 return 0; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
342 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
343 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
344 static int mmsh_read(URLContext *h, uint8_t *buf, int size) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
345 { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
346 int res = 0; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
347 MMSHContext *mmsh = h->priv_data; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
348 MMSContext *mms = &mmsh->mms; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
349 do { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
350 if (mms->asf_header_read_size < mms->asf_header_size) { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
351 // copy asf header into buffer |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
352 res = ff_mms_read_header(mms, buf, size); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
353 } else { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
354 if (!mms->remaining_in_len && (res = handle_chunk_type(mmsh))) |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
355 return res; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
356 res = ff_mms_read_data(mms, buf, size); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
357 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
358 } while (!res); |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
359 return res; |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
360 } |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
361 |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
362 URLProtocol mmsh_protocol = { |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
363 .name = "mmsh", |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
364 .url_open = mmsh_open, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
365 .url_read = mmsh_read, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
366 .url_write = NULL, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
367 .url_seek = NULL, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
368 .url_close = mmsh_close, |
c2e5016e2b4e
MMSH support, the most popular and widely used of all MMS variants. Written by
rbultje
parents:
diff
changeset
|
369 }; |