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
31
33 {
37 }
38
40 {
42
44
51 }
52
53 /* WAVEFORMATEX header */
54 /* returns the size or -1 on error */
57 {
59 int hdrsize;
61 int waveformatextensible;
63 uint8_t *riff_extradata =
temp;
64 uint8_t *riff_extradata_start =
temp;
65
67 return -1;
68
73 }
74
75 /* We use the known constant frame size for the codec if known, otherwise
76 * fall back on using AVCodecContext.frame_size, which is not as reliable
77 * for indicating packet duration. */
79
86
87 if (waveformatextensible)
89 else
91
100 } else {
104 else
105 bps = 16;
// default to 16
106 }
107 }
110 "requested bits_per_coded_sample (%d) "
111 "and actually stored (%d) differ\n",
113 }
114
118 blkalign = 576 * (par->
sample_rate <= (24000 + 32000)/2 ? 1 : 2);
120 blkalign = 3840; /* maximum bytes per frame */
124 blkalign = 24;
125 }
else if (par->
block_align != 0) {
/* specified by the codec */
127 } else
137 bytespersec = 800;
138 } else {
140 }
141 avio_wl32(pb, bytespersec);
/* bytes per second */
142 avio_wl16(pb, blkalign);
/* block align */
145 bytestream_put_le16(&riff_extradata, 1); /* wID */
146 bytestream_put_le32(&riff_extradata, 2); /* fdwFlags */
147 bytestream_put_le16(&riff_extradata, 1152); /* nBlockSize */
148 bytestream_put_le16(&riff_extradata, 1); /* nFramesPerBlock */
149 bytestream_put_le16(&riff_extradata, 1393); /* nCodecDelay */
151 /* fwHeadLayer */
152 bytestream_put_le16(&riff_extradata, 2);
153 /* dwHeadBitrate */
154 bytestream_put_le32(&riff_extradata, par->
bit_rate);
155 /* fwHeadMode */
157 /* fwHeadModeExt */
158 bytestream_put_le16(&riff_extradata, 0);
159 /* wHeadEmphasis */
160 bytestream_put_le16(&riff_extradata, 1);
161 /* fwHeadFlags */
162 bytestream_put_le16(&riff_extradata, 16);
163 /* dwPTSLow */
164 bytestream_put_le32(&riff_extradata, 0);
165 /* dwPTSHigh */
166 bytestream_put_le32(&riff_extradata, 0);
168 bytestream_put_le32(&riff_extradata, 0x9ace0002); /* extradata needed for msacm g723.1 codec */
169 bytestream_put_le32(&riff_extradata, 0xaea2f732);
170 bytestream_put_le16(&riff_extradata, 0xacde);
173 /* wSamplesPerBlock */
174 bytestream_put_le16(&riff_extradata,
frame_size);
178 }
179 /* write WAVEFORMATEXTENSIBLE extensions */
180 if (waveformatextensible) {
184 /* 22 is WAVEFORMATEXTENSIBLE size */
185 avio_wl16(pb, riff_extradata - riff_extradata_start + 22);
186 /* ValidBitsPerSample || SamplesPerBlock || Reserved */
188 /* dwChannelMask */
190 /* GUID + next 3 */
193 } else {
198 }
201 riff_extradata - riff_extradata_start) {
202 /* WAVEFORMATEX */
203 avio_wl16(pb, riff_extradata - riff_extradata_start);
/* cbSize */
204 } /* else PCMWAVEFORMAT */
205 avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start);
207 if (hdrsize & 1) {
208 hdrsize++;
210 }
211
212 return hdrsize;
213 }
214
215 /* BITMAPINFOHEADER header */
217 int for_asf, int ignore_extradata, int rgb_frame_is_flipped)
218 {
221 int keep_height = flipped_extradata || rgb_frame_is_flipped;
224 int pal_avi;
225
228 pal_avi = !for_asf &&
232
233 /* Size (not including the size of the color table or color masks) */
234 avio_wl32(pb, 40 + (ignore_extradata || pal_avi ? 0 : extradata_size));
236 //We always store RGB TopDown
238 /* planes */
240 /* depth */
242 /* compression type */
247 /* Number of color indices in the color table that are used.
248 * A value of 0 means 2^biBitCount indices, but this doesn't work
249 * with Windows Media Player and files containing xxpc chunks. */
252
253 if (!ignore_extradata) {
256 if (!for_asf && extradata_size & 1)
258 } else if (pal_avi) {
261 /* Initialize 1 bpp palette to black & white */
266 else
268 }
269 }
270 }
271 }
272
274 int *au_ssize, int *au_scale)
275 {
277 int gcd;
278 int audio_frame_size;
279
281 if (!audio_frame_size)
283
286 *au_scale = audio_frame_size;
293 } else {
297 }
298 gcd =
av_gcd(*au_scale, *au_rate);
299 *au_scale /= gcd;
300 *au_rate /= gcd;
301 }
302
304 {
306 if (
len > 0 &&
len < UINT32_MAX) {
313 }
314 }
315
317 "IARL", "IART", "IAS1", "IAS2", "IAS3", "IAS4", "IAS5", "IAS6", "IAS7",
318 "IAS8", "IAS9", "ICMS", "ICMT", "ICOP", "ICRD", "ICRP", "IDIM", "IDPI",
319 "IENG", "IGNR", "IKEY", "ILGT", "ILNG", "IMED", "INAM", "IPLT", "IPRD",
320 "IPRT", "ITRK", "ISBJ", "ISFT", "ISHP", "ISMP", "ISRC", "ISRF", "ITCH",
321 { 0 }
322 };
323
325 {
327
330 return 1;
331
332 return 0;
333 }
334
336 {
339 int64_t list_pos;
341
343
344 /* writing empty LIST is not nice and may cause problems */
346 return;
347
355 }
356
358 {
361 }
362
364 {
367 if (
id == av_guid[
i].
id)
368 return &(av_guid[
i].
guid);
369 }
371 }