1 /*
2 * Copyright (c) 2007 Ian Caulfield
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <stdint.h>
22
27
29 16, 20, 24, 0, 0, 0, 0, 0,
30 0, 0, 0, 0, 0, 0, 0, 0,
31 };
32
34 1, 2, 3, 4, 3, 4, 5, 3, 4, 5, 4, 5, 6, 4, 5, 4,
35 5, 6, 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36 };
37
60 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
61 };
62
64 {
65 int has_extension, extensions = 0;
67 if (bufsize < 28)
68 return -1;
69
70 if (
AV_RB32(buf) == 0xf8726fba) {
71 has_extension = buf[25] & 1;
72 if (has_extension) {
73 extensions = buf[26] >> 4;
74 size += 2 + extensions * 2;
75 }
76 }
78 }
79
80 /** Read a major sync info header - contains high level information about
81 * the stream - sample rate, channel arrangement etc. Most of this
82 * information is not actually necessary for decoding, only for playback.
83 * gb must be a freshly initialized GetBitContext with no bits read.
84 */
85
87 {
88 int ratebits, channel_arrangement, header_size;
89 uint16_t checksum;
90
92
94 if (header_size < 0 || gb->size_in_bits < header_size << 3) {
96 return -1;
97 }
98
103 }
104
105 if (
get_bits(gb, 24) != 0xf8726f)
/* Sync words */
107
109 mh->header_size = header_size;
110
111 if (
mh->stream_type == 0xbb) {
114
118
120
121 mh->channel_arrangement=
122 channel_arrangement =
get_bits(gb, 5);
124 mh->channel_layout_mlp =
mlp_layout[channel_arrangement];
125 }
else if (
mh->stream_type == 0xba) {
126 mh->group1_bits = 24;
// TODO: Is this information actually conveyed anywhere?
128
131 mh->group2_samplerate = 0;
132
134
135 mh->channel_modifier_thd_stream0 =
get_bits(gb, 2);
136 mh->channel_modifier_thd_stream1 =
get_bits(gb, 2);
137
138 mh->channel_arrangement=
139 channel_arrangement =
get_bits(gb, 5);
142
143 mh->channel_modifier_thd_stream2 =
get_bits(gb, 2);
144
145 channel_arrangement =
get_bits(gb, 13);
148 } else
150
151 mh->access_unit_size = 40 << (ratebits & 7);
152 mh->access_unit_size_pow2 = 64 << (ratebits & 7);
153
155
157
158 mh->peak_bitrate = (
get_bits(gb, 15) *
mh->group1_samplerate + 8) >> 4;
159
161
163 mh->extended_substream_info =
get_bits(gb, 2);
165
167
168 return 0;
169 }