FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/riffenc.c
Date: 2022-12-05 03:11:11
Exec Total Coverage
Lines: 186 210 88.6%
Functions: 10 10 100.0%
Branches: 151 200 75.5%

Line Branch Exec Source
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
22 #include "libavutil/channel_layout.h"
23 #include "libavutil/dict.h"
24 #include "libavutil/log.h"
25 #include "libavutil/mathematics.h"
26 #include "libavcodec/bytestream.h"
27 #include "avformat.h"
28 #include "avio_internal.h"
29 #include "riff.h"
30
31 4105 int64_t ff_start_tag(AVIOContext *pb, const char *tag)
32 {
33 4105 ffio_wfourcc(pb, tag);
34 4105 avio_wl32(pb, -1);
35 4105 return avio_tell(pb);
36 }
37
38 3747 void ff_end_tag(AVIOContext *pb, int64_t start)
39 {
40 int64_t pos;
41
42
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3747 times.
3747 av_assert0((start&1) == 0);
43
44 3747 pos = avio_tell(pb);
45
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3746 times.
3747 if (pos & 1)
46 1 avio_w8(pb, 0);
47 3747 avio_seek(pb, start - 4, SEEK_SET);
48 3747 avio_wl32(pb, (uint32_t)(pos - start));
49 3747 avio_seek(pb, FFALIGN(pos, 2), SEEK_SET);
50 3747 }
51
52 /* WAVEFORMATEX header */
53 /* returns the size or -1 on error */
54 495 int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb,
55 AVCodecParameters *par, int flags)
56 {
57 int bps, blkalign, bytespersec, frame_size;
58 int hdrsize;
59 495 int64_t hdrstart = avio_tell(pb);
60 int waveformatextensible;
61 uint8_t temp[256];
62 495 uint8_t *riff_extradata = temp;
63 495 uint8_t *riff_extradata_start = temp;
64
65
2/4
✓ Branch 0 taken 495 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 495 times.
495 if (!par->codec_tag || par->codec_tag > 0xffff)
66 return -1;
67
68
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 494 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
495 if (par->codec_id == AV_CODEC_ID_ADPCM_SWF && par->block_align == 0) {
69 av_log(s, AV_LOG_ERROR, "%s can only be written to WAVE with a constant frame size\n",
70 avcodec_get_name(par->codec_id));
71 return AVERROR(EINVAL);
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. */
77 495 frame_size = av_get_audio_frame_duration2(par, par->block_align);
78
79
2/2
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 355 times.
494 waveformatextensible = (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
80
2/2
✓ Branch 1 taken 137 times.
✓ Branch 2 taken 2 times.
633 av_channel_layout_compare(&par->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO) &&
81 139 av_channel_layout_compare(&par->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) ||
82
2/2
✓ Branch 0 taken 440 times.
✓ Branch 1 taken 53 times.
493 par->sample_rate > 48000 ||
83
6/8
✓ Branch 0 taken 494 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 440 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 440 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 436 times.
1430 par->codec_id == AV_CODEC_ID_EAC3 || par->codec_id == AV_CODEC_ID_DFPWM ||
84 440 av_get_bits_per_sample(par->codec_id) > 16;
85
86
2/2
✓ Branch 0 taken 59 times.
✓ Branch 1 taken 436 times.
495 if (waveformatextensible)
87 59 avio_wl16(pb, 0xfffe);
88 else
89 436 avio_wl16(pb, par->codec_tag);
90
91 495 avio_wl16(pb, par->ch_layout.nb_channels);
92 495 avio_wl32(pb, par->sample_rate);
93
1/2
✓ Branch 0 taken 495 times.
✗ Branch 1 not taken.
495 if (par->codec_id == AV_CODEC_ID_ATRAC3 ||
94
1/2
✓ Branch 0 taken 495 times.
✗ Branch 1 not taken.
495 par->codec_id == AV_CODEC_ID_G723_1 ||
95
2/2
✓ Branch 0 taken 489 times.
✓ Branch 1 taken 6 times.
495 par->codec_id == AV_CODEC_ID_MP2 ||
96
1/2
✓ Branch 0 taken 489 times.
✗ Branch 1 not taken.
489 par->codec_id == AV_CODEC_ID_MP3 ||
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 489 times.
489 par->codec_id == AV_CODEC_ID_GSM_MS) {
98 6 bps = 0;
99 } else {
100
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 480 times.
489 if (!(bps = av_get_bits_per_sample(par->codec_id))) {
101
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
9 if (par->bits_per_coded_sample)
102 5 bps = par->bits_per_coded_sample;
103 else
104 4 bps = 16; // default to 16
105 }
106 }
107
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 490 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
495 if (bps != par->bits_per_coded_sample && par->bits_per_coded_sample) {
108 av_log(s, AV_LOG_WARNING,
109 "requested bits_per_coded_sample (%d) "
110 "and actually stored (%d) differ\n",
111 par->bits_per_coded_sample, bps);
112 }
113
114
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 489 times.
495 if (par->codec_id == AV_CODEC_ID_MP2) {
115 6 blkalign = (144 * par->bit_rate - 1)/par->sample_rate + 1;
116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 489 times.
489 } else if (par->codec_id == AV_CODEC_ID_MP3) {
117 blkalign = 576 * (par->sample_rate <= (24000 + 32000)/2 ? 1 : 2);
118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 489 times.
489 } else if (par->codec_id == AV_CODEC_ID_AC3) {
119 blkalign = 3840; /* maximum bytes per frame */
120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 489 times.
489 } else if (par->codec_id == AV_CODEC_ID_AAC) {
121 blkalign = 768 * par->ch_layout.nb_channels; /* maximum bytes per frame */
122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 489 times.
489 } else if (par->codec_id == AV_CODEC_ID_G723_1) {
123 blkalign = 24;
124
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 5 times.
489 } else if (par->block_align != 0) { /* specified by the codec */
125 484 blkalign = par->block_align;
126 } else
127 5 blkalign = bps * par->ch_layout.nb_channels / av_gcd(8, bps);
128
2/2
✓ Branch 0 taken 493 times.
✓ Branch 1 taken 2 times.
495 if (par->codec_id == AV_CODEC_ID_PCM_U8 ||
129
2/2
✓ Branch 0 taken 487 times.
✓ Branch 1 taken 6 times.
493 par->codec_id == AV_CODEC_ID_PCM_S24LE ||
130
2/2
✓ Branch 0 taken 486 times.
✓ Branch 1 taken 1 times.
487 par->codec_id == AV_CODEC_ID_PCM_S32LE ||
131
2/2
✓ Branch 0 taken 485 times.
✓ Branch 1 taken 1 times.
486 par->codec_id == AV_CODEC_ID_PCM_F32LE ||
132
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 1 times.
485 par->codec_id == AV_CODEC_ID_PCM_F64LE ||
133
2/2
✓ Branch 0 taken 459 times.
✓ Branch 1 taken 25 times.
484 par->codec_id == AV_CODEC_ID_PCM_S16LE) {
134 470 bytespersec = par->sample_rate * blkalign;
135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 } else if (par->codec_id == AV_CODEC_ID_G723_1) {
136 bytespersec = 800;
137 } else {
138 25 bytespersec = par->bit_rate / 8;
139 }
140 495 avio_wl32(pb, bytespersec); /* bytes per second */
141 495 avio_wl16(pb, blkalign); /* block align */
142 495 avio_wl16(pb, bps); /* bits per sample */
143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 495 times.
495 if (par->codec_id == AV_CODEC_ID_MP3) {
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 */
149
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 489 times.
495 } else if (par->codec_id == AV_CODEC_ID_MP2) {
150 /* fwHeadLayer */
151 6 bytestream_put_le16(&riff_extradata, 2);
152 /* dwHeadBitrate */
153 6 bytestream_put_le32(&riff_extradata, par->bit_rate);
154 /* fwHeadMode */
155
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 bytestream_put_le16(&riff_extradata, par->ch_layout.nb_channels == 2 ? 1 : 8);
156 /* fwHeadModeExt */
157 6 bytestream_put_le16(&riff_extradata, 0);
158 /* wHeadEmphasis */
159 6 bytestream_put_le16(&riff_extradata, 1);
160 /* fwHeadFlags */
161 6 bytestream_put_le16(&riff_extradata, 16);
162 /* dwPTSLow */
163 6 bytestream_put_le32(&riff_extradata, 0);
164 /* dwPTSHigh */
165 6 bytestream_put_le32(&riff_extradata, 0);
166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 489 times.
489 } else if (par->codec_id == AV_CODEC_ID_G723_1) {
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);
170
1/2
✓ Branch 0 taken 489 times.
✗ Branch 1 not taken.
489 } else if (par->codec_id == AV_CODEC_ID_GSM_MS ||
171
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 487 times.
489 par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) {
172 /* wSamplesPerBlock */
173 2 bytestream_put_le16(&riff_extradata, frame_size);
174
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 480 times.
487 } else if (par->extradata_size) {
175 7 riff_extradata_start = par->extradata;
176 7 riff_extradata = par->extradata + par->extradata_size;
177 }
178 /* write WAVEFORMATEXTENSIBLE extensions */
179
2/2
✓ Branch 0 taken 59 times.
✓ Branch 1 taken 436 times.
495 if (waveformatextensible) {
180
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
118 int write_channel_mask = !(flags & FF_PUT_WAV_HEADER_SKIP_CHANNELMASK) &&
181
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
59 (s->strict_std_compliance < FF_COMPLIANCE_NORMAL ||
182
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
59 par->ch_layout.u.mask < 0x40000);
183 /* 22 is WAVEFORMATEXTENSIBLE size */
184 59 avio_wl16(pb, riff_extradata - riff_extradata_start + 22);
185 /* ValidBitsPerSample || SamplesPerBlock || Reserved */
186 59 avio_wl16(pb, bps);
187 /* dwChannelMask */
188
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
59 avio_wl32(pb, write_channel_mask ? par->ch_layout.u.mask : 0);
189 /* GUID + next 3 */
190
2/4
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59 times.
59 if (par->codec_id == AV_CODEC_ID_EAC3 || par->codec_id == AV_CODEC_ID_DFPWM) {
191 ff_put_guid(pb, ff_get_codec_guid(par->codec_id, ff_codec_wav_guids));
192 } else {
193 59 avio_wl32(pb, par->codec_tag);
194 59 avio_wl32(pb, 0x00100000);
195 59 avio_wl32(pb, 0xAA000080);
196 59 avio_wl32(pb, 0x719B3800);
197 }
198
2/2
✓ Branch 0 taken 429 times.
✓ Branch 1 taken 7 times.
436 } else if ((flags & FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX) ||
199
3/4
✓ Branch 0 taken 411 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 411 times.
429 par->codec_tag != 0x0001 /* PCM */ ||
200 riff_extradata - riff_extradata_start) {
201 /* WAVEFORMATEX */
202 25 avio_wl16(pb, riff_extradata - riff_extradata_start); /* cbSize */
203 } /* else PCMWAVEFORMAT */
204 495 avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start);
205 495 hdrsize = avio_tell(pb) - hdrstart;
206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 495 times.
495 if (hdrsize & 1) {
207 hdrsize++;
208 avio_w8(pb, 0);
209 }
210
211 495 return hdrsize;
212 }
213
214 /* BITMAPINFOHEADER header */
215 285 void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par,
216 int for_asf, int ignore_extradata, int rgb_frame_is_flipped)
217 {
218
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 215 times.
355 int flipped_extradata = (par->extradata_size >= 9 &&
219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 !memcmp(par->extradata + par->extradata_size - 9, "BottomUp", 9));
220
2/4
✓ Branch 0 taken 285 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 285 times.
285 int keep_height = flipped_extradata || rgb_frame_is_flipped;
221 285 int extradata_size = par->extradata_size - 9*flipped_extradata;
222 285 enum AVPixelFormat pix_fmt = par->format;
223 int pal_avi;
224
225
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 285 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
285 if (pix_fmt == AV_PIX_FMT_NONE && par->bits_per_coded_sample == 1)
226 pix_fmt = AV_PIX_FMT_MONOWHITE;
227
4/4
✓ Branch 0 taken 283 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 282 times.
✓ Branch 3 taken 1 times.
567 pal_avi = !for_asf &&
228
2/2
✓ Branch 0 taken 278 times.
✓ Branch 1 taken 4 times.
282 (pix_fmt == AV_PIX_FMT_PAL8 ||
229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 278 times.
278 pix_fmt == AV_PIX_FMT_MONOWHITE ||
230 pix_fmt == AV_PIX_FMT_MONOBLACK);
231
232 /* Size (not including the size of the color table or color masks) */
233
4/4
✓ Branch 0 taken 283 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 278 times.
✓ Branch 3 taken 5 times.
285 avio_wl32(pb, 40 + (ignore_extradata || pal_avi ? 0 : extradata_size));
234 285 avio_wl32(pb, par->width);
235 //We always store RGB TopDown
236
3/4
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 271 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
285 avio_wl32(pb, par->codec_tag || keep_height ? par->height : -par->height);
237 /* planes */
238 285 avio_wl16(pb, 1);
239 /* depth */
240
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 212 times.
285 avio_wl16(pb, par->bits_per_coded_sample ? par->bits_per_coded_sample : 24);
241 /* compression type */
242 285 avio_wl32(pb, par->codec_tag);
243
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 212 times.
285 avio_wl32(pb, (par->width * par->height * (par->bits_per_coded_sample ? par->bits_per_coded_sample : 24)+7) / 8);
244 285 avio_wl32(pb, 0);
245 285 avio_wl32(pb, 0);
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. */
249
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 280 times.
285 avio_wl32(pb, pal_avi ? 1 << par->bits_per_coded_sample : 0);
250 285 avio_wl32(pb, 0);
251
252
2/2
✓ Branch 0 taken 283 times.
✓ Branch 1 taken 2 times.
285 if (!ignore_extradata) {
253
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 197 times.
283 if (par->extradata_size) {
254 86 avio_write(pb, par->extradata, extradata_size);
255
3/4
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 74 times.
86 if (!for_asf && extradata_size & 1)
256 12 avio_w8(pb, 0);
257
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 193 times.
197 } else if (pal_avi) {
258 int i;
259
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 for (i = 0; i < 1 << par->bits_per_coded_sample; i++) {
260 /* Initialize 1 bpp palette to black & white */
261
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 if (i == 0 && pix_fmt == AV_PIX_FMT_MONOWHITE)
262 4 avio_wl32(pb, 0xffffff);
263
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 else if (i == 1 && pix_fmt == AV_PIX_FMT_MONOBLACK)
264 avio_wl32(pb, 0xffffff);
265 else
266 4 avio_wl32(pb, 0);
267 }
268 }
269 }
270 285 }
271
272 2864 void ff_parse_specific_params(AVStream *st, int *au_rate,
273 int *au_ssize, int *au_scale)
274 {
275 2864 AVCodecParameters *par = st->codecpar;
276 int gcd;
277 int audio_frame_size;
278
279 2864 audio_frame_size = av_get_audio_frame_duration2(par, 0);
280
2/2
✓ Branch 0 taken 2859 times.
✓ Branch 1 taken 5 times.
2864 if (!audio_frame_size)
281 2859 audio_frame_size = par->frame_size;
282
283 2864 *au_ssize = par->block_align;
284
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2859 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
2864 if (audio_frame_size && par->sample_rate) {
285 5 *au_scale = audio_frame_size;
286 5 *au_rate = par->sample_rate;
287
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 2844 times.
2859 } else if (par->codec_type == AVMEDIA_TYPE_VIDEO ||
288
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 par->codec_type == AVMEDIA_TYPE_DATA ||
289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
290 2844 *au_scale = st->time_base.num;
291 2844 *au_rate = st->time_base.den;
292 } else {
293
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 *au_scale = par->block_align ? par->block_align * 8 : 8;
294
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 *au_rate = par->bit_rate ? par->bit_rate :
295 8 * par->sample_rate;
296 }
297 2864 gcd = av_gcd(*au_scale, *au_rate);
298 2864 *au_scale /= gcd;
299 2864 *au_rate /= gcd;
300 2864 }
301
302 329 void ff_riff_write_info_tag(AVIOContext *pb, const char *tag, const char *str)
303 {
304 329 size_t len = strlen(str);
305
2/4
✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329 times.
✗ Branch 3 not taken.
329 if (len > 0 && len < UINT32_MAX) {
306 329 len++;
307 329 ffio_wfourcc(pb, tag);
308 329 avio_wl32(pb, len);
309 329 avio_put_str(pb, str);
310
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 322 times.
329 if (len & 1)
311 7 avio_w8(pb, 0);
312 }
313 329 }
314
315 static const char riff_tags[][5] = {
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
323 759 static int riff_has_valid_tags(AVFormatContext *s)
324 {
325 int i;
326
327
2/2
✓ Branch 0 taken 25631 times.
✓ Branch 1 taken 430 times.
26061 for (i = 0; *riff_tags[i]; i++)
328
2/2
✓ Branch 1 taken 329 times.
✓ Branch 2 taken 25302 times.
25631 if (av_dict_get(s->metadata, riff_tags[i], NULL, AV_DICT_MATCH_CASE))
329 329 return 1;
330
331 430 return 0;
332 }
333
334 759 void ff_riff_write_info(AVFormatContext *s)
335 {
336 759 AVIOContext *pb = s->pb;
337 int i;
338 int64_t list_pos;
339 759 AVDictionaryEntry *t = NULL;
340
341 759 ff_metadata_conv(&s->metadata, ff_riff_info_conv, NULL);
342
343 /* writing empty LIST is not nice and may cause problems */
344
2/2
✓ Branch 1 taken 430 times.
✓ Branch 2 taken 329 times.
759 if (!riff_has_valid_tags(s))
345 430 return;
346
347 329 list_pos = ff_start_tag(pb, "LIST");
348 329 ffio_wfourcc(pb, "INFO");
349
2/2
✓ Branch 0 taken 11844 times.
✓ Branch 1 taken 329 times.
12173 for (i = 0; *riff_tags[i]; i++)
350
2/2
✓ Branch 1 taken 329 times.
✓ Branch 2 taken 11515 times.
11844 if ((t = av_dict_get(s->metadata, riff_tags[i],
351 NULL, AV_DICT_MATCH_CASE)))
352 329 ff_riff_write_info_tag(s->pb, t->key, t->value);
353 329 ff_end_tag(pb, list_pos);
354 }
355
356 258 void ff_put_guid(AVIOContext *s, const ff_asf_guid *g)
357 {
358 av_assert0(sizeof(*g) == 16);
359 258 avio_write(s, *g, sizeof(*g));
360 258 }
361
362 4 const ff_asf_guid *ff_get_codec_guid(enum AVCodecID id, const AVCodecGuid *av_guid)
363 {
364 int i;
365
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 for (i = 0; av_guid[i].id != AV_CODEC_ID_NONE; i++) {
366
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
12 if (id == av_guid[i].id)
367 4 return &(av_guid[i].guid);
368 }
369 return NULL;
370 }
371