1 /*
2 * MMS protocol common definitions.
3 * Copyright (c) 2006,2007 Ryan Martell
4 * Copyright (c) 2007 Björn Axelsson
5 * Copyright (c) 2010 Zhentan Feng <spyfeng at gmail dot com>
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
26
27 #define MMS_MAX_STREAMS 256 /**< arbitrary sanity check value */
28
30 {
32 int size_to_copy;
34 size_to_copy =
FFMIN(
size, remaining_size);
36 memcpy(buf,
pos, size_to_copy);
39 }
41 return size_to_copy;
42 }
43
45 {
46 int read_size;
51 return read_size;
52 }
53
55 {
57 uint8_t *end;
60
64 "Corrupt stream (invalid ASF header, size=%d)\n",
67 }
68
70
73 uint64_t chunksize;
75 chunksize = 50; // see Reference [2] section 5.1
76 } else {
78 }
79 if (!chunksize || chunksize > end - p) {
81 "Corrupt stream (header chunksize %"PRId64" is invalid)\n",
82 chunksize);
84 }
86 /* read packet size */
91 "Corrupt stream (too large pkt_len %d)\n",
94 }
95 }
99 stream_id =
flags & 0x7F;
100 //The second condition is for checking CS_PKT_STREAM_ID_REQUEST packet size,
101 //we can calculate the packet size by stream_num.
102 //Please see function send_stream_selection_request().
112 } else {
114 "Corrupt stream (too many A/V streams)\n");
116 }
117 }
119 if (end - p >= 88) {
120 int stream_count =
AV_RL16(p + 84), ext_len_count =
AV_RL16(p + 86);
122 while (stream_count--) {
125 "Corrupt stream (next stream name length is not in the buffer)\n");
127 }
129 }
130 while (ext_len_count--) {
133 "Corrupt stream (next extension system info length is not in the buffer)\n");
135 }
137 }
140 "Corrupt stream (the last extension system info length is invalid)\n");
142 }
145 }
147 chunksize = 46; // see references [2] section 3.4. This should be set 46.
148 if (chunksize > end - p) {
150 "Corrupt stream (header chunksize %"PRId64" is invalid)\n",
151 chunksize);
153 }
154 }
155 p += chunksize;
156 }
157
158 return 0;
159 }