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
29
30 #define MAX_EXTRADATA_SIZE 1024
31
41
43 {"smc-interval", "StreamMuxConfig interval.",
46 };
47
53 };
54
56 {
58
62 }
66
68 // as long as avpriv_mpeg4audio_get_config works correctly this is impossible
71 }
72 /* FIXME: are any formats not allowed in LATM? */
73
77 }
80
81 return 0;
82 }
83
85 {
88
90 return 0;
91
95
96 return 0;
97 }
98
100 {
103 int header_size;
104
105 /* AudioMuxElement */
107
109 /* StreamMuxConfig */
110 put_bits(bs, 1, 0);
/* audioMuxVersion */
111 put_bits(bs, 1, 1);
/* allStreamsSameTimeFraming */
112 put_bits(bs, 6, 0);
/* numSubFrames */
113 put_bits(bs, 4, 0);
/* numProgram */
115
116 /* AudioSpecificConfig */
120 } else {
121 // + 3 assumes not scalable and dependsOnCoreCoder == 0,
122 // see decode_ga_specific_config in libavcodec/aacdec.c
124
130 }
131 }
132
133 put_bits(bs, 3, 0);
/* frameLengthType */
134 put_bits(bs, 8, 0xff);
/* latmBufferFullness */
135
136 put_bits(bs, 1, 0);
/* otherDataPresent */
137 put_bits(bs, 1, 0);
/* crcCheckPresent */
138 }
139
142 }
143
145 {
150 uint8_t loas_header[] =
"\x56\xe0\x00";
151
154
155 if (pkt->
size > 2 && pkt->
data[0] == 0xff && (pkt->
data[1] >> 4) == 0xf) {
156 av_log(s,
AV_LOG_ERROR,
"ADTS header detected - ADTS will not be incorrectly muxed into LATM\n");
158 }
159
161 if(pkt->
size > 2 && pkt->
data[0] == 0x56 && (pkt->
data[1] >> 4) == 0xe &&
164 else
166 }
167
168 if (pkt->
size > 0x1fff)
169 goto too_large;
170
172
174
175 /* PayloadLengthInfo() */
176 for (i = 0; i <= pkt->
size-255; i+=255)
178
180
181 /* The LATM payload is written unaligned */
182
183 /* PayloadMux() */
184 if (pkt->
size && (pkt->
data[0] & 0xe1) == 0x81) {
185 // Convert byte-aligned DSE to non-aligned.
186 // Due to the input format encoding we know that
187 // it is naturally byte-aligned in the input stream,
188 // so there are no padding bits to account for.
189 // To avoid having to add padding bits and rearrange
190 // the whole stream we just remove the byte-align flag.
191 // This allows us to remux our FATE AAC samples into latm
192 // files that are still playable with minimal effort.
195 } else
197
200
202
203 if (len > 0x1fff)
204 goto too_large;
205
206 loas_header[1] |= (len >> 8) & 0x1f;
207 loas_header[2] |= len & 0xff;
208
211
212 return 0;
213
214 too_large:
217 }
218
222 .mime_type = "audio/MP4A-LATM",
223 .extensions = "latm,loas",
229 .priv_class = &latm_muxer_class,
231 };