2
2
* TTA (The Lossless True Audio) decoder
3
3
* Copyright (c) 2006 Alex Beregszaszi
5
* This library is free software; you can redistribute it and/or
5
* This file is part of FFmpeg.
7
* FFmpeg is free software; you can redistribute it and/or
6
8
* modify it under the terms of the GNU Lesser General Public
7
9
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
12
* FFmpeg is distributed in the hope that it will be useful,
11
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
15
* Lesser General Public License for more details.
15
17
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
* License along with FFmpeg; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
198
// shamelessly copied from shorten.c
199
static int inline get_le16(GetBitContext *gb)
201
return bswap_16(get_bits_long(gb, 16));
204
static int inline get_le32(GetBitContext *gb)
206
return bswap_32(get_bits_long(gb, 32));
209
200
static int tta_decode_init(AVCodecContext * avctx)
211
202
TTAContext *s = avctx->priv_data;
220
211
init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size);
221
if (show_bits_long(&s->gb, 32) == bswap_32(ff_get_fourcc("TTA1")))
212
if (show_bits_long(&s->gb, 32) == ff_get_fourcc("TTA1"))
224
215
skip_bits(&s->gb, 32);
230
s->flags = get_le16(&s->gb);
221
s->flags = get_bits(&s->gb, 16);
231
222
if (s->flags != 1 && s->flags != 3)
233
224
av_log(s->avctx, AV_LOG_ERROR, "Invalid flags\n");
236
227
s->is_float = (s->flags == FORMAT_FLOAT);
237
avctx->channels = s->channels = get_le16(&s->gb);
238
avctx->bits_per_sample = get_le16(&s->gb);
228
avctx->channels = s->channels = get_bits(&s->gb, 16);
229
avctx->bits_per_sample = get_bits(&s->gb, 16);
239
230
s->bps = (avctx->bits_per_sample + 7) / 8;
240
avctx->sample_rate = get_le32(&s->gb);
231
avctx->sample_rate = get_bits_long(&s->gb, 32);
241
232
if(avctx->sample_rate > 1000000){ //prevent FRAME_TIME * avctx->sample_rate from overflowing and sanity check
242
233
av_log(avctx, AV_LOG_ERROR, "sample_rate too large\n");
245
s->data_length = get_le32(&s->gb);
236
s->data_length = get_bits_long(&s->gb, 32);
246
237
skip_bits(&s->gb, 32); // CRC32 of header