annotate mpeg4audio.c @ 7098:f49a53051803 libavcodec

Allocate static tables on stack, not heap. Patch by Art Clarke: aclarke vlideshow com
author benoit
date Mon, 23 Jun 2008 07:33:15 +0000
parents 06b1e0371e90
children 13c86fee4873
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6558
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
1 /*
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
2 * MPEG-4 Audio common code
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
3 * Copyright (c) 2008 Baptiste Coudurier <baptiste.coudurier@free.fr>
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
4 *
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
5 * This file is part of FFmpeg.
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
6 *
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
11 *
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
15 * Lesser General Public License for more details.
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
16 *
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
20 */
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
21
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
22 #include "bitstream.h"
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
23 #include "mpeg4audio.h"
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
24
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
25 const int ff_mpeg4audio_sample_rates[16] = {
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
26 96000, 88200, 64000, 48000, 44100, 32000,
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
27 24000, 22050, 16000, 12000, 11025, 8000, 7350
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
28 };
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
29
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
30 const uint8_t ff_mpeg4audio_channels[8] = {
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
31 0, 1, 2, 3, 4, 5, 6, 8
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
32 };
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
33
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
34 static inline int get_object_type(GetBitContext *gb)
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
35 {
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
36 int object_type = get_bits(gb, 5);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
37 if (object_type == 31)
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
38 object_type = 32 + get_bits(gb, 6);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
39 return object_type;
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
40 }
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
41
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
42 static inline int get_sample_rate(GetBitContext *gb, int *index)
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
43 {
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
44 *index = get_bits(gb, 4);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
45 return *index == 0x0f ? get_bits(gb, 24) :
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
46 ff_mpeg4audio_sample_rates[*index];
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
47 }
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
48
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
49 int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size)
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
50 {
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
51 GetBitContext gb;
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
52 int specific_config_bitindex;
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
53
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
54 init_get_bits(&gb, buf, buf_size*8);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
55 c->object_type = get_object_type(&gb);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
56 c->sample_rate = get_sample_rate(&gb, &c->sampling_index);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
57 c->chan_config = get_bits(&gb, 4);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
58 c->sbr = -1;
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
59 if (c->object_type == 5) {
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
60 c->ext_object_type = c->object_type;
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
61 c->sbr = 1;
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
62 c->ext_sample_rate = get_sample_rate(&gb, &c->ext_sampling_index);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
63 c->object_type = get_object_type(&gb);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
64 } else
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
65 c->ext_object_type = 0;
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
66
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
67 specific_config_bitindex = get_bits_count(&gb);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
68
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
69 if (c->ext_object_type != 5) {
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
70 int bits_left = buf_size*8 - specific_config_bitindex;
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
71 for (; bits_left > 15; bits_left--) {
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
72 if (show_bits(&gb, 11) == 0x2b7) { // sync extension
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
73 get_bits(&gb, 11);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
74 c->ext_object_type = get_object_type(&gb);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
75 if (c->ext_object_type == 5 && (c->sbr = get_bits1(&gb)) == 1)
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
76 c->ext_sample_rate = get_sample_rate(&gb, &c->ext_sampling_index);
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
77 break;
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
78 } else
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
79 get_bits1(&gb); // skip 1 bit
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
80 }
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
81 }
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
82 return specific_config_bitindex;
06b1e0371e90 mpeg4audio common code
bcoudurier
parents:
diff changeset
83 }