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 {
40 int64_t pos;
41
43
45 if (pos & 1)
50 }
51
52 /* WAVEFORMATEX header */
53 /* returns the size or -1 on error */
55 {
57 int hdrsize;
59 int waveformatextensible;
63
65 return -1;
66
67 /* We use the known constant frame size for the codec if known, otherwise
68 * fall back on using AVCodecContext.frame_size, which is not as reliable
69 * for indicating packet duration. */
71
76
77 if (waveformatextensible)
79 else
81
89 bps = 0;
90 } else {
94 else
95 bps = 16; // default to 16
96 }
97 }
100 "requested bits_per_coded_sample (%d) "
101 "and actually stored (%d) differ\n",
103 }
104
108 blkalign = 576 * (enc->
sample_rate <= (24000 + 32000)/2 ? 1 : 2);
110 blkalign = 3840; /* maximum bytes per frame */
112 blkalign = 768 * enc->
channels;
/* maximum bytes per frame */
114 blkalign = 24;
115 }
else if (enc->
block_align != 0) {
/* specified by the codec */
117 } else
127 bytespersec = 800;
128 } else {
130 }
131 avio_wl32(pb, bytespersec);
/* bytes per second */
132 avio_wl16(pb, blkalign);
/* block align */
133 avio_wl16(pb, bps);
/* bits per sample */
135 bytestream_put_le16(&riff_extradata, 1); /* wID */
136 bytestream_put_le32(&riff_extradata, 2); /* fdwFlags */
137 bytestream_put_le16(&riff_extradata, 1152); /* nBlockSize */
138 bytestream_put_le16(&riff_extradata, 1); /* nFramesPerBlock */
139 bytestream_put_le16(&riff_extradata, 1393); /* nCodecDelay */
141 /* fwHeadLayer */
142 bytestream_put_le16(&riff_extradata, 2);
143 /* dwHeadBitrate */
144 bytestream_put_le32(&riff_extradata, enc->
bit_rate);
145 /* fwHeadMode */
146 bytestream_put_le16(&riff_extradata, enc->
channels == 2 ? 1 : 8);
147 /* fwHeadModeExt */
148 bytestream_put_le16(&riff_extradata, 0);
149 /* wHeadEmphasis */
150 bytestream_put_le16(&riff_extradata, 1);
151 /* fwHeadFlags */
152 bytestream_put_le16(&riff_extradata, 16);
153 /* dwPTSLow */
154 bytestream_put_le32(&riff_extradata, 0);
155 /* dwPTSHigh */
156 bytestream_put_le32(&riff_extradata, 0);
158 bytestream_put_le32(&riff_extradata, 0x9ace0002); /* extradata needed for msacm g723.1 codec */
159 bytestream_put_le32(&riff_extradata, 0xaea2f732);
160 bytestream_put_le16(&riff_extradata, 0xacde);
163 /* wSamplesPerBlock */
164 bytestream_put_le16(&riff_extradata, frame_size);
168 }
169 /* write WAVEFORMATEXTENSIBLE extensions */
170 if (waveformatextensible) {
173 /* 22 is WAVEFORMATEXTENSIBLE size */
174 avio_wl16(pb, riff_extradata - riff_extradata_start + 22);
175 /* ValidBitsPerSample || SamplesPerBlock || Reserved */
177 /* dwChannelMask */
179 /* GUID + next 3 */
182 } else {
187 }
190 riff_extradata - riff_extradata_start) {
191 /* WAVEFORMATEX */
192 avio_wl16(pb, riff_extradata - riff_extradata_start);
/* cbSize */
193 } /* else PCMWAVEFORMAT */
194 avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start);
196 if (hdrsize & 1) {
197 hdrsize++;
199 }
200
201 return hdrsize;
202 }
203
204 /* BITMAPINFOHEADER header */
206 const AVCodecTag *tags,
int for_asf,
int ignore_extradata)
207 {
211
212 /* size */
213 avio_wl32(pb, 40 + (ignore_extradata ? 0 :extradata_size));
215 //We always store RGB TopDown
217 /* planes */
219 /* depth */
221 /* compression type */
228
229 if (!ignore_extradata) {
231
232 if (!for_asf && extradata_size & 1)
234 }
235 }
236
238 int *au_ssize, int *au_scale)
239 {
241 int gcd;
242 int audio_frame_size;
243
244 /* We use the known constant frame size for the codec if known, otherwise
245 * fall back on using AVCodecContext.frame_size, which is not as reliable
246 * for indicating packet duration. */
248 if (!audio_frame_size)
250
253 *au_scale = audio_frame_size;
260 } else {
264 }
265 gcd =
av_gcd(*au_scale, *au_rate);
266 *au_scale /= gcd;
267 *au_rate /= gcd;
268 }
269
271 {
272 int len = strlen(str);
273 if (len > 0) {
274 len++;
278 if (len & 1)
280 }
281 }
282
284 "IARL", "IART", "ICMS", "ICMT", "ICOP", "ICRD", "ICRP", "IDIM", "IDPI",
285 "IENG", "IGNR", "IKEY", "ILGT", "ILNG", "IMED", "INAM", "IPLT", "IPRD",
286 "IPRT", "ITRK", "ISBJ", "ISFT", "ISHP", "ISMP", "ISRC", "ISRF", "ITCH",
287 { 0 }
288 };
289
291 {
292 int i;
293
296 return 1;
297
298 return 0;
299 }
300
302 {
304 int i;
305 int64_t list_pos;
307
309
310 /* writing empty LIST is not nice and may cause problems */
312 return;
313
321 }
322
324 {
327 }
328
330 {
331 int i;
333 if (id == av_guid[i].id)
334 return &(av_guid[i].
guid);
335 }
337 }