1 /*
2 * RIFF muxing functions
3 * Copyright (c) 2000 Fabrice Bellard
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
30
32 {
36 }
37
39 {
41
43
50 }
51
52 /* WAVEFORMATEX header */
53 /* returns the size or -1 on error */
56 {
58 int hdrsize;
60 int waveformatextensible;
62 uint8_t *riff_extradata =
temp;
63 uint8_t *riff_extradata_start =
temp;
64
66 return -1;
67
72 }
73
74 /* We use the known constant frame size for the codec if known, otherwise
75 * fall back on using AVCodecContext.frame_size, which is not as reliable
76 * for indicating packet duration. */
78
85
86 if (waveformatextensible)
88 else
90
99 } else {
103 else
104 bps = 16;
// default to 16
105 }
106 }
109 "requested bits_per_coded_sample (%d) "
110 "and actually stored (%d) differ\n",
112 }
113
117 blkalign = 576 * (par->
sample_rate <= (24000 + 32000)/2 ? 1 : 2);
119 blkalign = 3840; /* maximum bytes per frame */
123 blkalign = 24;
124 }
else if (par->
block_align != 0) {
/* specified by the codec */
126 } else
136 bytespersec = 800;
137 } else {
139 }
140 avio_wl32(pb, bytespersec);
/* bytes per second */
141 avio_wl16(pb, blkalign);
/* block align */
144 bytestream_put_le16(&riff_extradata, 1); /* wID */
145 bytestream_put_le32(&riff_extradata, 2); /* fdwFlags */
146 bytestream_put_le16(&riff_extradata, 1152); /* nBlockSize */
147 bytestream_put_le16(&riff_extradata, 1); /* nFramesPerBlock */
148 bytestream_put_le16(&riff_extradata, 1393); /* nCodecDelay */
150 /* fwHeadLayer */
151 bytestream_put_le16(&riff_extradata, 2);
152 /* dwHeadBitrate */
153 bytestream_put_le32(&riff_extradata, par->
bit_rate);
154 /* fwHeadMode */
156 /* fwHeadModeExt */
157 bytestream_put_le16(&riff_extradata, 0);
158 /* wHeadEmphasis */
159 bytestream_put_le16(&riff_extradata, 1);
160 /* fwHeadFlags */
161 bytestream_put_le16(&riff_extradata, 16);
162 /* dwPTSLow */
163 bytestream_put_le32(&riff_extradata, 0);
164 /* dwPTSHigh */
165 bytestream_put_le32(&riff_extradata, 0);
167 bytestream_put_le32(&riff_extradata, 0x9ace0002); /* extradata needed for msacm g723.1 codec */
168 bytestream_put_le32(&riff_extradata, 0xaea2f732);
169 bytestream_put_le16(&riff_extradata, 0xacde);
172 /* wSamplesPerBlock */
173 bytestream_put_le16(&riff_extradata,
frame_size);
177 }
178 /* write WAVEFORMATEXTENSIBLE extensions */
179 if (waveformatextensible) {
183 /* 22 is WAVEFORMATEXTENSIBLE size */
184 avio_wl16(pb, riff_extradata - riff_extradata_start + 22);
185 /* ValidBitsPerSample || SamplesPerBlock || Reserved */
187 /* dwChannelMask */
189 /* GUID + next 3 */
192 } else {
197 }
200 riff_extradata - riff_extradata_start) {
201 /* WAVEFORMATEX */
202 avio_wl16(pb, riff_extradata - riff_extradata_start);
/* cbSize */
203 } /* else PCMWAVEFORMAT */
204 avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start);
206 if (hdrsize & 1) {
207 hdrsize++;
209 }
210
211 return hdrsize;
212 }
213
214 /* BITMAPINFOHEADER header */
216 int for_asf, int ignore_extradata, int rgb_frame_is_flipped)
217 {
220 int keep_height = flipped_extradata || rgb_frame_is_flipped;
223 int pal_avi;
224
227 pal_avi = !for_asf &&
231
232 /* Size (not including the size of the color table or color masks) */
233 avio_wl32(pb, 40 + (ignore_extradata || pal_avi ? 0 : extradata_size));
235 //We always store RGB TopDown
237 /* planes */
239 /* depth */
241 /* compression type */
246 /* Number of color indices in the color table that are used.
247 * A value of 0 means 2^biBitCount indices, but this doesn't work
248 * with Windows Media Player and files containing xxpc chunks. */
251
252 if (!ignore_extradata) {
255 if (!for_asf && extradata_size & 1)
257 } else if (pal_avi) {
260 /* Initialize 1 bpp palette to black & white */
265 else
267 }
268 }
269 }
270 }
271
273 int *au_ssize, int *au_scale)
274 {
276 int gcd;
277 int audio_frame_size;
278
280 if (!audio_frame_size)
282
285 *au_scale = audio_frame_size;
292 } else {
296 }
297 gcd =
av_gcd(*au_scale, *au_rate);
298 *au_scale /= gcd;
299 *au_rate /= gcd;
300 }
301
303 {
305 if (
len > 0 &&
len < UINT32_MAX) {
312 }
313 }
314
316 "IARL", "IART", "IAS1", "IAS2", "IAS3", "IAS4", "IAS5", "IAS6", "IAS7",
317 "IAS8", "IAS9", "ICMS", "ICMT", "ICOP", "ICRD", "ICRP", "IDIM", "IDPI",
318 "IENG", "IGNR", "IKEY", "ILGT", "ILNG", "IMED", "INAM", "IPLT", "IPRD",
319 "IPRT", "ITRK", "ISBJ", "ISFT", "ISHP", "ISMP", "ISRC", "ISRF", "ITCH",
320 { 0 }
321 };
322
324 {
326
329 return 1;
330
331 return 0;
332 }
333
335 {
338 int64_t list_pos;
340
342
343 /* writing empty LIST is not nice and may cause problems */
345 return;
346
354 }
355
357 {
360 }
361
363 {
366 if (
id == av_guid[
i].
id)
367 return &(av_guid[
i].
guid);
368 }
370 }