1 /*
2 * LATM/LOAS muxer
3 * Copyright (c) 2011 Kieran Kunhya <kieran@kunhya.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
34
35 #define MAX_EXTRADATA_SIZE 1024
36
46
48 {"smc-interval", "StreamMuxConfig interval.",
51 };
52
58 };
59
61 {
64
68 }
72
74 // as long as avpriv_mpeg4audio_get_config works correctly this is impossible
77 }
78 /* FIXME: are any formats not allowed in LATM? */
79
83 }
86
87 return 0;
88 }
89
91 {
93
95 return 0;
99 }
100
104
105 return 0;
106 }
107
109 {
110 int words = length >> 4;
111 int bits = length & 15;
113 for (
i = 0;
i < words;
i++)
117 }
118
120 {
123 int header_size;
124
125 /* AudioMuxElement */
127
129 /* StreamMuxConfig */
130 put_bits(bs, 1, 0);
/* audioMuxVersion */
131 put_bits(bs, 1, 1);
/* allStreamsSameTimeFraming */
132 put_bits(bs, 6, 0);
/* numSubFrames */
133 put_bits(bs, 4, 0);
/* numProgram */
135
136 /* AudioSpecificConfig */
140 } else {
141 // + 3 assumes not scalable and dependsOnCoreCoder == 0,
142 // see decode_ga_specific_config in libavcodec/aacdec.c
144
145 if (!
ctx->channel_conf) {
148 av_assert0(
ret >= 0);
// extradata size has been checked already, so this should not fail
151 }
152 }
153
154 put_bits(bs, 3, 0);
/* frameLengthType */
155 put_bits(bs, 8, 0xff);
/* latmBufferFullness */
156
157 put_bits(bs, 1, 0);
/* otherDataPresent */
158 put_bits(bs, 1, 0);
/* crcCheckPresent */
159 }
160
163 }
164
166 {
172 uint8_t loas_header[] = "\x56\xe0\x00";
173
176
181 else {
182 uint8_t *side_data;
183 size_t side_data_size;
185
187 &side_data_size);
188 if (side_data_size) {
194 memcpy(par->
extradata, side_data, side_data_size);
195 } else
197 }
198 }
199
201 goto too_large;
202
204
206
207 /* PayloadLengthInfo() */
210
212
213 /* The LATM payload is written unaligned */
214
215 /* PayloadMux() */
217 // Convert byte-aligned DSE to non-aligned.
218 // Due to the input format encoding we know that
219 // it is naturally byte-aligned in the input stream,
220 // so there are no padding bits to account for.
221 // To avoid having to add padding bits and rearrange
222 // the whole stream we just remove the byte-align flag.
223 // This allows us to remux our FATE AAC samples into latm
224 // files that are still playable with minimal effort.
227 } else
229
231
233
235 goto too_large;
236
237 loas_header[1] |= (
len >> 8) & 0x1f;
238 loas_header[2] |=
len & 0xff;
239
242
243 return 0;
244
245 too_large:
248 }
249
252 {
254
258 }
259
261 }
262
266 .p.mime_type = "audio/MP4A-LATM",
267 .p.extensions = "latm,loas",
278 };