~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to libavcodec/tta.c

  • Committer: William Grant
  • Date: 2007-02-03 03:16:07 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: william.grant@ubuntu.org.au-20070203031607-08gc2ompbz6spt9i
Update to 1.0rc1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * TTA (The Lossless True Audio) decoder
3
3
 * Copyright (c) 2006 Alex Beregszaszi
4
4
 *
5
 
 * This library is free software; you can redistribute it and/or
 
5
 * This file is part of FFmpeg.
 
6
 *
 
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.
9
11
 *
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.
14
16
 *
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
18
20
 */
19
21
 
20
22
/**
195
197
    return ret;
196
198
}
197
199
 
198
 
// shamelessly copied from shorten.c
199
 
static int inline get_le16(GetBitContext *gb)
200
 
{
201
 
    return bswap_16(get_bits_long(gb, 16));
202
 
}
203
 
 
204
 
static int inline get_le32(GetBitContext *gb)
205
 
{
206
 
    return bswap_32(get_bits_long(gb, 32));
207
 
}
208
 
 
209
200
static int tta_decode_init(AVCodecContext * avctx)
210
201
{
211
202
    TTAContext *s = avctx->priv_data;
218
209
        return -1;
219
210
 
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"))
222
213
    {
223
214
        /* signature */
224
215
        skip_bits(&s->gb, 32);
227
218
//            return -1;
228
219
//        }
229
220
 
230
 
        s->flags = get_le16(&s->gb);
 
221
        s->flags = get_bits(&s->gb, 16);
231
222
        if (s->flags != 1 && s->flags != 3)
232
223
        {
233
224
            av_log(s->avctx, AV_LOG_ERROR, "Invalid flags\n");
234
225
            return -1;
235
226
        }
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");
243
234
            return -1;
244
235
        }
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
247
238
 
248
239
        if (s->is_float)
361
352
                    rice->k0++;
362
353
            }
363
354
 
364
 
            // extract sign
365
 
#define SIGN(x) (((x)&1) ? (++(x)>>1) : (-(x)>>1))
366
 
            *p = SIGN(value);
 
355
            // extract coded value
 
356
#define UNFOLD(x) (((x)&1) ? (++(x)>>1) : (-(x)>>1))
 
357
            *p = UNFOLD(value);
367
358
 
368
359
            // run hybrid filter
369
360
            ttafilter_process(filter, p, 0);