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
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 */
242 // MSRLE compatibility with Media Player 3.1 and Windows 95
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. */
250 // MSRLE on Windows 95 requires a zero here
253
254 if (!ignore_extradata) {
257 if (!for_asf && extradata_size & 1)
259 } else if (pal_avi) {
262 /* Initialize 1 bpp palette to black & white */
267 else
269 }
270 }
271 }
272 }
273
275 int *au_ssize, int *au_scale)
276 {
278 int gcd;
279 int audio_frame_size;
280
282 if (!audio_frame_size)
284
287 *au_scale = audio_frame_size;
294 } else {
298 }
299 gcd =
av_gcd(*au_scale, *au_rate);
300 *au_scale /= gcd;
301 *au_rate /= gcd;
302 }
303
305 {
306 size_t len = strlen(str);
307 if (
len > 0 &&
len < UINT32_MAX) {
314 }
315 }
316
318 "IARL", "IART", "IAS1", "IAS2", "IAS3", "IAS4", "IAS5", "IAS6", "IAS7",
319 "IAS8", "IAS9", "ICMS", "ICMT", "ICOP", "ICRD", "ICRP", "IDIM", "IDPI",
320 "IENG", "IGNR", "IKEY", "ILGT", "ILNG", "IMED", "INAM", "IPLT", "IPRD",
321 "IPRT", "ITRK", "ISBJ", "ISFT", "ISHP", "ISMP", "ISRC", "ISRF", "ITCH",
322 { 0 }
323 };
324
326 {
328
331 return 1;
332
333 return 0;
334 }
335
337 {
342
344
345 /* writing empty LIST is not nice and may cause problems */
347 return;
348
356 }
357
359 {
362 }
363
365 {
368 if (
id == av_guid[
i].
id)
369 return &(av_guid[
i].
guid);
370 }
372 }