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 AVCodecParameters.frame_size, which is not as reliable
76 * for indicating packet duration. */
78
85
86 if (waveformatextensible)
88 else
90
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 */
204 /* HEAACWAVEFORMAT */
207 avio_wl16(pb, 0xFE);
// wAudioProfileLevelIndication, 0xFE = unspecified
208 avio_wl16(pb, 0);
// wStructType, 0 = AudioSpecificConfig()
214 } else
215 avio_wl16(pb, riff_extradata - riff_extradata_start);
/* cbSize */
216 } /* else PCMWAVEFORMAT */
217 avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start);
219 if (hdrsize & 1) {
220 hdrsize++;
222 }
223
224 return hdrsize;
225 }
226
227 /* BITMAPINFOHEADER header */
229 int for_asf, int ignore_extradata, int rgb_frame_is_flipped)
230 {
233 int keep_height = flipped_extradata || rgb_frame_is_flipped;
236 int pal_avi;
237
240 pal_avi = !for_asf &&
244
245 /* Size (not including the size of the color table or color masks) */
246 avio_wl32(pb, 40 + (ignore_extradata || pal_avi ? 0 : extradata_size));
248 //We always store RGB TopDown
250 /* planes */
252 /* depth */
254 /* compression type */
255 // MSRLE compatibility with Media Player 3.1 and Windows 95
260 /* Number of color indices in the color table that are used.
261 * A value of 0 means 2^biBitCount indices, but this doesn't work
262 * with Windows Media Player and files containing xxpc chunks. */
263 // MSRLE on Windows 95 requires a zero here
266
267 if (!ignore_extradata) {
270 if (!for_asf && extradata_size & 1)
272 } else if (pal_avi) {
275 /* Initialize 1 bpp palette to black & white */
280 else
282 }
283 }
284 }
285 }
286
288 int *au_ssize, int *au_scale)
289 {
291 int gcd;
292 int audio_frame_size;
293
295 if (!audio_frame_size)
297
300 *au_scale = audio_frame_size;
307 } else {
311 }
312 gcd =
av_gcd(*au_scale, *au_rate);
313 *au_scale /= gcd;
314 *au_rate /= gcd;
315 }
316
318 {
319 size_t len = strlen(str);
320 if (
len > 0 &&
len < UINT32_MAX) {
327 }
328 }
329
331 "IARL", "IART", "IAS1", "IAS2", "IAS3", "IAS4", "IAS5", "IAS6", "IAS7",
332 "IAS8", "IAS9", "ICMS", "ICMT", "ICOP", "ICRD", "ICRP", "IDIM", "IDPI",
333 "IENG", "IGNR", "IKEY", "ILGT", "ILNG", "IMED", "INAM", "IPLT", "IPRD",
334 "IPRT", "ITRK", "ISBJ", "ISFT", "ISHP", "ISMP", "ISRC", "ISRF", "ITCH",
335 { 0 }
336 };
337
339 {
341
344 return 1;
345
346 return 0;
347 }
348
350 {
355
357
358 /* writing empty LIST is not nice and may cause problems */
360 return;
361
369 }
370
372 {
375 }
376
378 {
381 if (
id == av_guid[
i].
id)
382 return &(av_guid[
i].
guid);
383 }
385 }