1 /*
2 * Musepack SV8 demuxer
3 * Copyright (c) 2007 Konstantin Shishkov
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
28
29 /// Two-byte MPC tag
30 #define MKMPCTAG(a, b) (a | (b << 8))
31
32 #define TAG_MPCK MKTAG('M','P','C','K')
33
34 /// Reserved MPC tags
38
40
43
46 };
47
48 static const int mpc8_rate[8] = { 44100, 48000, 37800, 32000, -1, -1, -1, -1 };
49
50 typedef struct {
51 int ver;
54
57
59 {
60 int64_t v = 0;
61 int br = 0;
63
64 do {
65 c = **bs; (*bs)++;
66 v <<= 7;
67 v |= c & 0x7F;
68 br++;
69 if (br > 10)
70 return -1;
71 } while (c & 0x80);
72
73 return v - br;
74 }
75
77 {
81
83 return 0;
85 return 0;
86 while (bs < bs_end + 3) {
87 int header_found = (bs[0] == 'S' && bs[1] == 'H');
88 if (bs[0] < 'A' || bs[0] > 'Z' || bs[1] < 'A' || bs[1] > 'Z')
89 return 0;
90 bs += 2;
92 if (size < 2)
93 return 0;
94 if (bs + size - 2 >= bs_end)
96 if (header_found) {
97 if (size < 11 || size > 28)
98 return 0;
99 if (!
AV_RL32(bs))
//zero CRC is invalid
100 return 0;
102 } else {
103 bs += size - 2;
104 }
105 }
106 return 0;
107 }
108
110 {
111 int64_t v = 0;
114 v <<= 7;
116 bits += 7;
117 }
118 v <<= 7;
120
121 return v;
122 }
123
125 {
126 int64_t pos;
131 }
132
134 {
137 int64_t
size, pos, ppos[2];
141
146 return;
147 }
148 if (size > INT_MAX/10 || size<=0) {
150 return;
151 }
153 return;
157 if(size > UINT_MAX/4 || size > c->
samples/1152){
159 return;
160 }
162 for(i = 0; i < 2; i++){
164 ppos[1 - i] = pos;
166 }
167 for(; i <
size; i++){
170 if(t & 1)
171 t = -(t & ~1);
172 pos = (t >> 1) + ppos[0]*2 - ppos[1];
174 ppos[1] = ppos[0];
175 ppos[0] = pos;
176 }
178 }
179
181 {
184
185 switch(tag){
191 break;
192 default:
194 }
195 }
196
198 {
204
209 }
210
215 break;
217 }
221 }
228 }
231
233 if (!st)
238
242
249 if (size > 0)
251
256 }
257
258 return 0;
259 }
260
262 {
266
269
270 /* don't return bogus packets with the ape tag data */
273
275 if (size < 0)
276 return -1;
282 return 0;
283 }
287 }
289 }
290
292 {
295
296 if(index < 0) return -1;
298 return -1;
300 return 0;
301 }
302
303
312 };