1 /*
2 * Musepack demuxer
3 * Copyright (c) 2006 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
29
30 #define MPC_FRAMESIZE 1152
31 #define DELAY_FRAMES 32
32
33 static const int mpc_rate[4] = { 44100, 48000, 37800, 32000 };
38
39 typedef struct {
47
49 {
51 if (d[0] == 'M' && d[1] == 'P' && d[2] == '+' && (d[3] == 0x17 || d[3] == 0x7))
53 return 0;
54 }
55
57 {
60
64 }
66 if(c->
ver != 0x07 && c->
ver != 0x17){
69 }
74 }
80 }
81 }else{
83 }
88
90 if (!st)
97
102 /* scan for seekpoints */
105
106 /* try to read APE tags */
113 }
114
115 return 0;
116 }
117
119 {
122 unsigned tmp;
123 int64_t pos;
124
127
131 }
137 if(curbits <= 12){
138 size2 = (tmp >> (12 - curbits)) & 0xFFFFF;
139 }else{
140 size2 = (tmp << (curbits - 12) |
avio_rl32(s->
pb) >> (44 - curbits)) & 0xFFFFF;
141 }
142 curbits += 20;
144
145 size = ((size2 + curbits + 31) & ~31) >> 3;
149 c->
frames[cur].skip = curbits - 20;
152 }
153 c->
curbits = (curbits + size2) & 0x1F;
154
156 return ret;
157
158 pkt->
data[0] = curbits;
162
168 if(ret < size){
170 return ret < 0 ? ret :
AVERROR(EIO);
171 }
173
174 return 0;
175 }
176
178 {
180
182 return 0;
183 }
184
185 /**
186 * Seek to the given position
187 * If position is unknown but is within the limits of file
188 * then packets are skipped unless desired position is reached
189 *
190 * Also this function makes use of the fact that timestamp == frameno
191 */
193 {
199 uint32_t lastframe;
200
201 /* if found, seek there */
204 return 0;
205 }
206 /* if timestamp is out of bounds, return error */
207 if(timestamp < 0 || timestamp >= c->
fcount)
208 return -1;
210 /* seek to the furthest known position and read packets until
211 we reach desired position */
216 if (ret < 0){
219 }
221 }
222 return 0;
223 }
224
225
235 .extensions = "mpc",
236 };