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
54
57
59 {
60 uint64_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 (size >= bs_end - bs + 2)
96 if (header_found) {
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 uint64_t v = 0;
112 int bits = 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];
139 int i, t, seekd, ret;
141
144 return;
145 }
146
151 return;
152 }
153 if (size > INT_MAX/10 || size<=0) {
155 return;
156 }
158 return;
160 if (ret != size) {
163 return;
164 }
166
169 if(size > UINT_MAX/4 || size > c->
samples/1152){
171 return;
172 }
174 for(i = 0; i < 2; i++){
176 ppos[1 - i] = pos;
178 }
179 for(; i <
size; i++){
182 if(t & 1)
183 t = -(t & ~1);
184 pos = (t >> 1) + ppos[0]*2 - ppos[1];
186 ppos[1] = ppos[0];
187 ppos[0] = pos;
188 }
190 }
191
193 {
195 int64_t pos, off;
196
197 switch(tag){
203 break;
204 default:
206 }
207 }
208
210 {
216
221 }
222
226 if (size < 0) {
229 }
231 break;
233 }
237 }
244 }
247
249 if (!st)
254
257
264 if (size > 0)
266
271 }
272
273 return 0;
274 }
275
277 {
281
284
285 /* don't return bogus packets with the ape tag data */
288
290 if (size < 0)
291 return -1;
297 return 0;
298 }
302 }
304 }
305
307 {
310
311 if(index < 0) return -1;
313 return -1;
315 return 0;
316 }
317
318
327 };
uint64_t ffio_read_varlen(AVIOContext *bc)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
#define AVERROR_EOF
End of file.
bitstream reader API header.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
unsigned int avio_rl32(AVIOContext *s)
int64_t timestamp
Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
enum AVMediaType codec_type
General type of the encoded data.
int64_t ff_ape_parse_tag(AVFormatContext *s)
Read and parse an APE tag.
int avio_r8(AVIOContext *s)
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
static int read_header(FFV1Context *f)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
AVIOContext * pb
I/O context.
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
This structure contains the data a format has to probe a file.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int64_t duration
Decoding: duration of the stream, in stream time base.
int sample_rate
Audio only.
unsigned int avio_rl16(AVIOContext *s)
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
void * priv_data
Format private data.
int bits_per_coded_sample
The number of bits per sample in the codedwords.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.