annotate libac3/bitstream.c @ 251:75091bfc577b libavcodec

fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
author michaelni
date Fri, 22 Feb 2002 19:19:01 +0000
parents 5aa6292a1660
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
2 * bitstream.c
986e461dc072 Initial revision
glantau
parents:
diff changeset
3 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 * Copyright (C) Aaron Holtzman - Dec 1999
986e461dc072 Initial revision
glantau
parents:
diff changeset
5 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
6 * This file is part of ac3dec, a free AC-3 audio decoder
986e461dc072 Initial revision
glantau
parents:
diff changeset
7 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
8 * ac3dec is free software; you can redistribute it and/or modify
986e461dc072 Initial revision
glantau
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
986e461dc072 Initial revision
glantau
parents:
diff changeset
10 * the Free Software Foundation; either version 2, or (at your option)
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 * any later version.
986e461dc072 Initial revision
glantau
parents:
diff changeset
12 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
13 * ac3dec is distributed in the hope that it will be useful,
986e461dc072 Initial revision
glantau
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
986e461dc072 Initial revision
glantau
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
986e461dc072 Initial revision
glantau
parents:
diff changeset
16 * GNU General Public License for more details.
986e461dc072 Initial revision
glantau
parents:
diff changeset
17 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
986e461dc072 Initial revision
glantau
parents:
diff changeset
19 * along with GNU Make; see the file COPYING. If not, write to
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
986e461dc072 Initial revision
glantau
parents:
diff changeset
21 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
22 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
23
64
5aa6292a1660 win32 fixes
glantau
parents: 0
diff changeset
24 #include "../common.h"
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
25 #include "ac3.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
26 #include "ac3_internal.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
27 #include "bitstream.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
28
986e461dc072 Initial revision
glantau
parents:
diff changeset
29 #define BUFFER_SIZE 4096
986e461dc072 Initial revision
glantau
parents:
diff changeset
30
986e461dc072 Initial revision
glantau
parents:
diff changeset
31 static uint8_t *buffer_start;
986e461dc072 Initial revision
glantau
parents:
diff changeset
32
986e461dc072 Initial revision
glantau
parents:
diff changeset
33 uint32_t bits_left;
986e461dc072 Initial revision
glantau
parents:
diff changeset
34 uint32_t current_word;
986e461dc072 Initial revision
glantau
parents:
diff changeset
35
986e461dc072 Initial revision
glantau
parents:
diff changeset
36 void bitstream_set_ptr (uint8_t * buf)
986e461dc072 Initial revision
glantau
parents:
diff changeset
37 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
38 buffer_start = buf;
986e461dc072 Initial revision
glantau
parents:
diff changeset
39 bits_left = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
41
986e461dc072 Initial revision
glantau
parents:
diff changeset
42 static inline void
986e461dc072 Initial revision
glantau
parents:
diff changeset
43 bitstream_fill_current()
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
45 current_word = *((uint32_t*)buffer_start)++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
46 current_word = swab32(current_word);
986e461dc072 Initial revision
glantau
parents:
diff changeset
47 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
48
986e461dc072 Initial revision
glantau
parents:
diff changeset
49 //
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 // The fast paths for _get is in the
986e461dc072 Initial revision
glantau
parents:
diff changeset
51 // bitstream.h header file so it can be inlined.
986e461dc072 Initial revision
glantau
parents:
diff changeset
52 //
986e461dc072 Initial revision
glantau
parents:
diff changeset
53 // The "bottom half" of this routine is suffixed _bh
986e461dc072 Initial revision
glantau
parents:
diff changeset
54 //
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 // -ah
986e461dc072 Initial revision
glantau
parents:
diff changeset
56 //
986e461dc072 Initial revision
glantau
parents:
diff changeset
57
986e461dc072 Initial revision
glantau
parents:
diff changeset
58 uint32_t
986e461dc072 Initial revision
glantau
parents:
diff changeset
59 bitstream_get_bh(uint32_t num_bits)
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
61 uint32_t result;
986e461dc072 Initial revision
glantau
parents:
diff changeset
62
986e461dc072 Initial revision
glantau
parents:
diff changeset
63 num_bits -= bits_left;
986e461dc072 Initial revision
glantau
parents:
diff changeset
64 result = (current_word << (32 - bits_left)) >> (32 - bits_left);
986e461dc072 Initial revision
glantau
parents:
diff changeset
65
986e461dc072 Initial revision
glantau
parents:
diff changeset
66 bitstream_fill_current();
986e461dc072 Initial revision
glantau
parents:
diff changeset
67
986e461dc072 Initial revision
glantau
parents:
diff changeset
68 if(num_bits != 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
69 result = (result << num_bits) | (current_word >> (32 - num_bits));
986e461dc072 Initial revision
glantau
parents:
diff changeset
70
986e461dc072 Initial revision
glantau
parents:
diff changeset
71 bits_left = 32 - num_bits;
986e461dc072 Initial revision
glantau
parents:
diff changeset
72
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 return result;
986e461dc072 Initial revision
glantau
parents:
diff changeset
74 }