FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/avcodec.c
Date: 2025-08-19 23:55:23
Exec Total Coverage
Lines: 355 454 78.2%
Functions: 15 15 100.0%
Branches: 304 434 70.0%

Line Branch Exec Source
1 /*
2 * AVCodecContext functions for libavcodec
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * AVCodecContext functions for libavcodec
24 */
25
26 #include "config.h"
27 #include "libavutil/avassert.h"
28 #include "libavutil/avstring.h"
29 #include "libavutil/bprint.h"
30 #include "libavutil/channel_layout.h"
31 #include "libavutil/common.h"
32 #include "libavutil/emms.h"
33 #include "libavutil/fifo.h"
34 #include "libavutil/imgutils.h"
35 #include "libavutil/mem.h"
36 #include "libavutil/opt.h"
37 #include "libavutil/thread.h"
38 #include "avcodec.h"
39 #include "avcodec_internal.h"
40 #include "bsf.h"
41 #include "codec_desc.h"
42 #include "codec_internal.h"
43 #include "decode.h"
44 #include "encode.h"
45 #include "frame_thread_encoder.h"
46 #include "hwconfig.h"
47 #include "internal.h"
48 #include "libavutil/refstruct.h"
49 #include "thread.h"
50
51 /**
52 * Maximum size in bytes of extradata.
53 * This value was chosen such that every bit of the buffer is
54 * addressable by a 32-bit signed integer as used by get_bits.
55 */
56 #define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
57
58 const SideDataMap ff_sd_global_map[] = {
59 { AV_PKT_DATA_REPLAYGAIN , AV_FRAME_DATA_REPLAYGAIN },
60 { AV_PKT_DATA_DISPLAYMATRIX, AV_FRAME_DATA_DISPLAYMATRIX },
61 { AV_PKT_DATA_SPHERICAL, AV_FRAME_DATA_SPHERICAL },
62 { AV_PKT_DATA_STEREO3D, AV_FRAME_DATA_STEREO3D },
63 { AV_PKT_DATA_AUDIO_SERVICE_TYPE, AV_FRAME_DATA_AUDIO_SERVICE_TYPE },
64 { AV_PKT_DATA_MASTERING_DISPLAY_METADATA, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
65 { AV_PKT_DATA_CONTENT_LIGHT_LEVEL, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
66 { AV_PKT_DATA_ICC_PROFILE, AV_FRAME_DATA_ICC_PROFILE },
67 { AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT,AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT },
68 { AV_PKT_DATA_3D_REFERENCE_DISPLAYS, AV_FRAME_DATA_3D_REFERENCE_DISPLAYS },
69 { AV_PKT_DATA_NB },
70 };
71
72
73 24693 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
74 {
75 size_t i;
76
77
2/2
✓ Branch 0 taken 1386890 times.
✓ Branch 1 taken 24693 times.
1411583 for (i = 0; i < count; i++) {
78 1386890 size_t offset = i * size;
79
2/2
✓ Branch 0 taken 1362197 times.
✓ Branch 1 taken 24693 times.
1386890 int r = func(c, FF_PTR_ADD((char *)arg, offset));
80
2/2
✓ Branch 0 taken 930 times.
✓ Branch 1 taken 1385960 times.
1386890 if (ret)
81 930 ret[i] = r;
82 }
83 24693 emms_c();
84 24693 return 0;
85 }
86
87 8764 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
88 {
89 int i;
90
91
2/2
✓ Branch 0 taken 244815 times.
✓ Branch 1 taken 8764 times.
253579 for (i = 0; i < count; i++) {
92 244815 int r = func(c, arg, i, 0);
93
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 244765 times.
244815 if (ret)
94 50 ret[i] = r;
95 }
96 8764 emms_c();
97 8764 return 0;
98 }
99
100 static AVMutex codec_mutex = AV_MUTEX_INITIALIZER;
101
102 66039 static void lock_avcodec(const FFCodec *codec)
103 {
104
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 66039 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
66039 if (codec->caps_internal & FF_CODEC_CAP_NOT_INIT_THREADSAFE && codec->init)
105 ff_mutex_lock(&codec_mutex);
106 66039 }
107
108 66039 static void unlock_avcodec(const FFCodec *codec)
109 {
110
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 66039 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
66039 if (codec->caps_internal & FF_CODEC_CAP_NOT_INIT_THREADSAFE && codec->init)
111 ff_mutex_unlock(&codec_mutex);
112 66039 }
113
114 28351 static int64_t get_bit_rate(AVCodecContext *ctx)
115 {
116 int64_t bit_rate;
117 int bits_per_sample;
118
119
2/3
✓ Branch 0 taken 23482 times.
✓ Branch 1 taken 4869 times.
✗ Branch 2 not taken.
28351 switch (ctx->codec_type) {
120 23482 case AVMEDIA_TYPE_VIDEO:
121 case AVMEDIA_TYPE_DATA:
122 case AVMEDIA_TYPE_SUBTITLE:
123 case AVMEDIA_TYPE_ATTACHMENT:
124 23482 bit_rate = ctx->bit_rate;
125 23482 break;
126 4869 case AVMEDIA_TYPE_AUDIO:
127 4869 bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
128
2/2
✓ Branch 0 taken 2448 times.
✓ Branch 1 taken 2421 times.
4869 if (bits_per_sample) {
129 2448 bit_rate = ctx->sample_rate * (int64_t)ctx->ch_layout.nb_channels;
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2448 times.
2448 if (bit_rate > INT64_MAX / bits_per_sample) {
131 bit_rate = 0;
132 } else
133 2448 bit_rate *= bits_per_sample;
134 } else
135 2421 bit_rate = ctx->bit_rate;
136 4869 break;
137 default:
138 bit_rate = 0;
139 break;
140 }
141 28351 return bit_rate;
142 }
143
144 37153 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
145 {
146 37153 int ret = 0;
147 AVCodecInternal *avci;
148 const FFCodec *codec2;
149 const AVDictionaryEntry *e;
150
151
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 37153 times.
37153 if (avcodec_is_open(avctx))
152 return 0;
153
154
3/4
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 37126 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
37153 if (!codec && !avctx->codec) {
155 av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n");
156 return AVERROR(EINVAL);
157 }
158
5/6
✓ Branch 0 taken 37126 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 28683 times.
✓ Branch 3 taken 8443 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 28683 times.
37153 if (codec && avctx->codec && codec != avctx->codec) {
159 av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
160 "but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name);
161 return AVERROR(EINVAL);
162 }
163
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 37126 times.
37153 if (!codec)
164 27 codec = avctx->codec;
165 37153 codec2 = ffcodec(codec);
166
167
3/4
✓ Branch 0 taken 37147 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 37147 times.
✗ Branch 3 not taken.
37153 if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) ||
168
3/4
✓ Branch 0 taken 37147 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 37147 times.
37153 (avctx->codec_id != AV_CODEC_ID_NONE && avctx->codec_id != codec->id)) {
169 av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
170 return AVERROR(EINVAL);
171 }
172
173 37153 avctx->codec_type = codec->type;
174 37153 avctx->codec_id = codec->id;
175 37153 avctx->codec = codec;
176
177
2/4
✓ Branch 0 taken 37153 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37153 times.
37153 if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
178 return AVERROR(EINVAL);
179
180 // set the whitelist from provided options dict,
181 // so we can check it immediately
182
2/2
✓ Branch 0 taken 8776 times.
✓ Branch 1 taken 28377 times.
37153 e = options ? av_dict_get(*options, "codec_whitelist", NULL, 0) : NULL;
183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37153 times.
37153 if (e) {
184 ret = av_opt_set(avctx, e->key, e->value, 0);
185 if (ret < 0)
186 return ret;
187 }
188
189
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 37153 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
37153 if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {
190 av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist);
191 return AVERROR(EINVAL);
192 }
193
194
2/2
✓ Branch 1 taken 15745 times.
✓ Branch 2 taken 21408 times.
37153 avci = ff_codec_is_decoder(codec) ?
195 15745 ff_decode_internal_alloc() :
196 21408 ff_encode_internal_alloc();
197
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37153 times.
37153 if (!avci) {
198 ret = AVERROR(ENOMEM);
199 goto end;
200 }
201 37153 avctx->internal = avci;
202
203 37153 avci->buffer_frame = av_frame_alloc();
204 37153 avci->buffer_pkt = av_packet_alloc();
205
2/4
✓ Branch 0 taken 37153 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37153 times.
37153 if (!avci->buffer_frame || !avci->buffer_pkt) {
206 ret = AVERROR(ENOMEM);
207 goto free_and_end;
208 }
209
210
2/2
✓ Branch 0 taken 16403 times.
✓ Branch 1 taken 20750 times.
37153 if (codec2->priv_data_size > 0) {
211
2/2
✓ Branch 0 taken 8286 times.
✓ Branch 1 taken 8117 times.
16403 if (!avctx->priv_data) {
212 8286 avctx->priv_data = av_mallocz(codec2->priv_data_size);
213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8286 times.
8286 if (!avctx->priv_data) {
214 ret = AVERROR(ENOMEM);
215 goto free_and_end;
216 }
217
2/2
✓ Branch 0 taken 2408 times.
✓ Branch 1 taken 5878 times.
8286 if (codec->priv_class) {
218 2408 *(const AVClass **)avctx->priv_data = codec->priv_class;
219 2408 av_opt_set_defaults(avctx->priv_data);
220 }
221 }
222 } else {
223 20750 avctx->priv_data = NULL;
224 }
225
226 37153 ret = av_opt_set_dict2(avctx, options, AV_OPT_SEARCH_CHILDREN);
227
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37153 times.
37153 if (ret < 0)
228 goto free_and_end;
229
230 // only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions
231
6/8
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 37121 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 26 times.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
37153 if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&
232
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_VP6F || avctx->codec_id == AV_CODEC_ID_DXV))) {
233
3/4
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 37121 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
37153 if (avctx->coded_width && avctx->coded_height)
234 32 ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
235
3/4
✓ Branch 0 taken 27947 times.
✓ Branch 1 taken 9174 times.
✓ Branch 2 taken 27947 times.
✗ Branch 3 not taken.
37121 else if (avctx->width && avctx->height)
236 27947 ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
237
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37153 times.
37153 if (ret < 0)
238 goto free_and_end;
239 }
240
241
5/8
✓ Branch 0 taken 9174 times.
✓ Branch 1 taken 27979 times.
✓ Branch 2 taken 9174 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9174 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9174 times.
37153 if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
242
1/2
✓ Branch 1 taken 27979 times.
✗ Branch 2 not taken.
27979 && ( av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0
243
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27979 times.
27979 || av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0)) {
244 av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n");
245 ff_set_dimensions(avctx, 0, 0);
246 }
247
248
3/4
✓ Branch 0 taken 27979 times.
✓ Branch 1 taken 9174 times.
✓ Branch 2 taken 27979 times.
✗ Branch 3 not taken.
37153 if (avctx->width > 0 && avctx->height > 0) {
249
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27979 times.
27979 if (av_image_check_sar(avctx->width, avctx->height,
250 avctx->sample_aspect_ratio) < 0) {
251 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
252 avctx->sample_aspect_ratio.num,
253 avctx->sample_aspect_ratio.den);
254 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
255 }
256 }
257
258 /* AV_CODEC_CAP_CHANNEL_CONF is a decoder-only flag; so the code below
259 * in particular checks that sample_rate is set for all audio encoders. */
260
1/2
✓ Branch 0 taken 37153 times.
✗ Branch 1 not taken.
37153 if (avctx->sample_rate < 0 ||
261
4/4
✓ Branch 0 taken 32663 times.
✓ Branch 1 taken 4490 times.
✓ Branch 2 taken 242 times.
✓ Branch 3 taken 32421 times.
37153 avctx->sample_rate == 0 && avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
262
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 242 times.
242 !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) {
263 av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", avctx->sample_rate);
264 ret = AVERROR(EINVAL);
265 goto free_and_end;
266 }
267
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37153 times.
37153 if (avctx->block_align < 0) {
268 av_log(avctx, AV_LOG_ERROR, "Invalid block align: %d\n", avctx->block_align);
269 ret = AVERROR(EINVAL);
270 goto free_and_end;
271 }
272
273 /* AV_CODEC_CAP_CHANNEL_CONF is a decoder-only flag; so the code below
274 * in particular checks that nb_channels is set for all audio encoders. */
275
4/4
✓ Branch 0 taken 4732 times.
✓ Branch 1 taken 32421 times.
✓ Branch 2 taken 241 times.
✓ Branch 3 taken 4491 times.
37153 if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && !avctx->ch_layout.nb_channels
276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 241 times.
241 && !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) {
277 av_log(avctx, AV_LOG_ERROR, "%s requires channel layout to be set\n",
278 ff_codec_is_decoder(codec) ? "Decoder" : "Encoder");
279 ret = AVERROR(EINVAL);
280 goto free_and_end;
281 }
282
3/4
✓ Branch 0 taken 4491 times.
✓ Branch 1 taken 32662 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4491 times.
37153 if (avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) {
283 av_log(avctx, AV_LOG_ERROR, "Invalid channel layout\n");
284 ret = AVERROR(EINVAL);
285 goto free_and_end;
286 }
287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37153 times.
37153 if (avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
288 av_log(avctx, AV_LOG_ERROR, "Too many channels: %d\n", avctx->ch_layout.nb_channels);
289 ret = AVERROR(EINVAL);
290 goto free_and_end;
291 }
292
293 37153 avctx->frame_num = 0;
294 37153 avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id);
295
296
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 37146 times.
37153 if ((avctx->codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) &&
297
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
298 const char *codec_string = ff_codec_is_encoder(codec) ? "encoder" : "decoder";
299 const AVCodec *codec2;
300 av_log(avctx, AV_LOG_ERROR,
301 "The %s '%s' is experimental but experimental codecs are not enabled, "
302 "add '-strict %d' if you want to use it.\n",
303 codec_string, codec->name, FF_COMPLIANCE_EXPERIMENTAL);
304 codec2 = ff_codec_is_encoder(codec) ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id);
305 if (!(codec2->capabilities & AV_CODEC_CAP_EXPERIMENTAL))
306 av_log(avctx, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n",
307 codec_string, codec2->name);
308 ret = AVERROR_EXPERIMENTAL;
309 goto free_and_end;
310 }
311
312
2/2
✓ Branch 0 taken 4732 times.
✓ Branch 1 taken 32421 times.
37153 if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
313
3/4
✓ Branch 0 taken 1337 times.
✓ Branch 1 taken 3395 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1337 times.
4732 (!avctx->time_base.num || !avctx->time_base.den)) {
314 3395 avctx->time_base.num = 1;
315 3395 avctx->time_base.den = avctx->sample_rate;
316 }
317
318
2/2
✓ Branch 1 taken 21408 times.
✓ Branch 2 taken 15745 times.
37153 if (ff_codec_is_encoder(avctx->codec))
319 21408 ret = ff_encode_preinit(avctx);
320 else
321 15745 ret = ff_decode_preinit(avctx);
322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37153 times.
37153 if (ret < 0)
323 goto free_and_end;
324
325
2/2
✓ Branch 0 taken 35498 times.
✓ Branch 1 taken 1655 times.
37153 if (HAVE_THREADS && !avci->frame_thread_encoder) {
326 /* Frame-threaded decoders call FFCodec.init for their child contexts. */
327 35498 lock_avcodec(codec2);
328 35498 ret = ff_thread_init(avctx);
329 35498 unlock_avcodec(codec2);
330
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35498 times.
35498 if (ret < 0) {
331 goto free_and_end;
332 }
333 }
334 if (!HAVE_THREADS && !(codec2->caps_internal & FF_CODEC_CAP_AUTO_THREADS))
335 avctx->thread_count = 1;
336
337
2/2
✓ Branch 0 taken 1665 times.
✓ Branch 1 taken 35488 times.
37153 if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||
338
2/2
✓ Branch 0 taken 1655 times.
✓ Branch 1 taken 10 times.
1665 avci->frame_thread_encoder) {
339
2/2
✓ Branch 0 taken 30541 times.
✓ Branch 1 taken 6602 times.
37143 if (codec2->init) {
340 30541 lock_avcodec(codec2);
341 30541 ret = codec2->init(avctx);
342 30541 unlock_avcodec(codec2);
343
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 30533 times.
30541 if (ret < 0) {
344 8 avci->needs_close = codec2->caps_internal & FF_CODEC_CAP_INIT_CLEANUP;
345 8 goto free_and_end;
346 }
347 }
348 37135 avci->needs_close = 1;
349 }
350
351 37145 ret=0;
352
353
2/2
✓ Branch 1 taken 15737 times.
✓ Branch 2 taken 21408 times.
37145 if (ff_codec_is_decoder(avctx->codec)) {
354
2/2
✓ Branch 0 taken 11044 times.
✓ Branch 1 taken 4693 times.
15737 if (!avctx->bit_rate)
355 11044 avctx->bit_rate = get_bit_rate(avctx);
356
357 /* validate channel layout from the decoder */
358
3/4
✓ Branch 0 taken 3197 times.
✓ Branch 1 taken 12540 times.
✓ Branch 3 taken 3197 times.
✗ Branch 4 not taken.
15737 if ((avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) ||
359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15737 times.
15737 avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
360 ret = AVERROR(EINVAL);
361 goto free_and_end;
362 }
363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15737 times.
15737 if (avctx->bits_per_coded_sample < 0) {
364 ret = AVERROR(EINVAL);
365 goto free_and_end;
366 }
367 }
368
2/2
✓ Branch 0 taken 5192 times.
✓ Branch 1 taken 31953 times.
37145 if (codec->priv_class)
369
1/2
✓ Branch 0 taken 5192 times.
✗ Branch 1 not taken.
5192 av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);
370
371 37145 end:
372
373 37153 return ret;
374 8 free_and_end:
375 8 ff_codec_close(avctx);
376 8 goto end;
377 }
378
379 104 void avcodec_flush_buffers(AVCodecContext *avctx)
380 {
381 104 AVCodecInternal *avci = avctx->internal;
382
383
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 104 times.
104 if (av_codec_is_encoder(avctx->codec)) {
384 int caps = avctx->codec->capabilities;
385
386 if (!(caps & AV_CODEC_CAP_ENCODER_FLUSH)) {
387 // Only encoders that explicitly declare support for it can be
388 // flushed. Otherwise, this is a no-op.
389 av_log(avctx, AV_LOG_WARNING, "Ignoring attempt to flush encoder "
390 "that doesn't support it\n");
391 return;
392 }
393 ff_encode_flush_buffers(avctx);
394 } else
395 104 ff_decode_flush_buffers(avctx);
396
397 104 avci->draining = 0;
398 104 avci->draining_done = 0;
399
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 if (avci->buffer_frame)
400 104 av_frame_unref(avci->buffer_frame);
401
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 if (avci->buffer_pkt)
402 104 av_packet_unref(avci->buffer_pkt);
403
404
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME &&
405 !avci->is_frame_mt)
406 ff_thread_flush(avctx);
407
2/2
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 73 times.
104 else if (ffcodec(avctx->codec)->flush)
408 31 ffcodec(avctx->codec)->flush(avctx);
409 }
410
411 1001 void avsubtitle_free(AVSubtitle *sub)
412 {
413 int i;
414
415
2/2
✓ Branch 0 taken 946 times.
✓ Branch 1 taken 1001 times.
1947 for (i = 0; i < sub->num_rects; i++) {
416 946 AVSubtitleRect *const rect = sub->rects[i];
417
418 946 av_freep(&rect->data[0]);
419 946 av_freep(&rect->data[1]);
420 946 av_freep(&rect->data[2]);
421 946 av_freep(&rect->data[3]);
422 946 av_freep(&rect->text);
423 946 av_freep(&rect->ass);
424
425 946 av_freep(&sub->rects[i]);
426 }
427
428 1001 av_freep(&sub->rects);
429
430 1001 memset(sub, 0, sizeof(*sub));
431 1001 }
432
433 63728 av_cold void ff_codec_close(AVCodecContext *avctx)
434 {
435 int i;
436
437
2/2
✓ Branch 1 taken 37153 times.
✓ Branch 2 taken 26575 times.
63728 if (avcodec_is_open(avctx)) {
438 37153 AVCodecInternal *avci = avctx->internal;
439
440 37153 if (CONFIG_FRAME_THREAD_ENCODER &&
441
4/4
✓ Branch 0 taken 14883 times.
✓ Branch 1 taken 22270 times.
✓ Branch 2 taken 1655 times.
✓ Branch 3 taken 13228 times.
37153 avci->frame_thread_encoder && avctx->thread_count > 1) {
442 1655 ff_frame_thread_encoder_free(avctx);
443 }
444
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 37117 times.
37153 if (HAVE_THREADS && avci->thread_ctx)
445 36 ff_thread_free(avctx);
446
4/4
✓ Branch 0 taken 37135 times.
✓ Branch 1 taken 18 times.
✓ Branch 3 taken 7468 times.
✓ Branch 4 taken 29667 times.
37153 if (avci->needs_close && ffcodec(avctx->codec)->close)
447 7468 ffcodec(avctx->codec)->close(avctx);
448 37153 avci->byte_buffer_size = 0;
449 37153 av_freep(&avci->byte_buffer);
450 37153 av_frame_free(&avci->buffer_frame);
451 37153 av_packet_free(&avci->buffer_pkt);
452 37153 av_packet_free(&avci->last_pkt_props);
453
454 37153 av_packet_free(&avci->in_pkt);
455 37153 av_frame_free(&avci->in_frame);
456 37153 av_frame_free(&avci->recon_frame);
457
458 37153 av_refstruct_unref(&avci->pool);
459 37153 av_refstruct_pool_uninit(&avci->progress_frame_pool);
460
2/2
✓ Branch 1 taken 15745 times.
✓ Branch 2 taken 21408 times.
37153 if (av_codec_is_decoder(avctx->codec))
461 15745 ff_decode_internal_uninit(avctx);
462
463 37153 ff_hwaccel_uninit(avctx);
464
465 37153 av_bsf_free(&avci->bsf);
466
467 #if CONFIG_LCMS2
468 ff_icc_context_uninit(&avci->icc);
469 #endif
470
471 37153 av_freep(&avctx->internal);
472 }
473
474
2/2
✓ Branch 0 taken 4299 times.
✓ Branch 1 taken 63728 times.
68027 for (i = 0; i < avctx->nb_coded_side_data; i++)
475 4299 av_freep(&avctx->coded_side_data[i].data);
476 63728 av_freep(&avctx->coded_side_data);
477 63728 avctx->nb_coded_side_data = 0;
478 63728 av_frame_side_data_free(&avctx->decoded_side_data,
479 &avctx->nb_decoded_side_data);
480
481 63728 av_buffer_unref(&avctx->hw_frames_ctx);
482 63728 av_buffer_unref(&avctx->hw_device_ctx);
483
484
5/6
✓ Branch 0 taken 24681 times.
✓ Branch 1 taken 39047 times.
✓ Branch 2 taken 24681 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7600 times.
✓ Branch 5 taken 17081 times.
63728 if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
485 7600 av_opt_free(avctx->priv_data);
486 63728 av_opt_free(avctx);
487 63728 av_freep(&avctx->priv_data);
488
2/2
✓ Branch 1 taken 21408 times.
✓ Branch 2 taken 42320 times.
63728 if (av_codec_is_encoder(avctx->codec)) {
489 21408 av_freep(&avctx->extradata);
490 21408 avctx->extradata_size = 0;
491
2/2
✓ Branch 1 taken 32427 times.
✓ Branch 2 taken 9893 times.
42320 } else if (av_codec_is_decoder(avctx->codec))
492 32427 av_freep(&avctx->subtitle_header);
493
494 63728 avctx->codec = NULL;
495 63728 avctx->active_thread_type = 0;
496 63728 }
497
498 22219 static const char *unknown_if_null(const char *str)
499 {
500
1/2
✓ Branch 0 taken 22219 times.
✗ Branch 1 not taken.
22219 return str ? str : "unknown";
501 }
502
503 17316 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
504 {
505 const char *codec_type;
506 const char *codec_name;
507 17316 const char *profile = NULL;
508 AVBPrint bprint;
509 int64_t bitrate;
510 17316 int new_line = 0;
511 AVRational display_aspect_ratio;
512
2/2
✓ Branch 0 taken 17290 times.
✓ Branch 1 taken 26 times.
17316 const char *separator = enc->dump_separator ? (const char *)enc->dump_separator : ", ";
513 const char *str;
514
515
2/4
✓ Branch 0 taken 17316 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17316 times.
17316 if (!buf || buf_size <= 0)
516 9 return;
517 17316 av_bprint_init_for_buffer(&bprint, buf, buf_size);
518 17316 codec_type = av_get_media_type_string(enc->codec_type);
519 17316 codec_name = avcodec_get_name(enc->codec_id);
520 17316 profile = avcodec_profile_name(enc->codec_id, enc->profile);
521
522
1/2
✓ Branch 0 taken 17316 times.
✗ Branch 1 not taken.
17316 av_bprintf(&bprint, "%s: %s", codec_type ? codec_type : "unknown",
523 codec_name);
524 17316 buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */
525
526
4/4
✓ Branch 0 taken 8268 times.
✓ Branch 1 taken 9048 times.
✓ Branch 2 taken 294 times.
✓ Branch 3 taken 7974 times.
17316 if (enc->codec && strcmp(enc->codec->name, codec_name))
527 294 av_bprintf(&bprint, " (%s)", enc->codec->name);
528
529
2/2
✓ Branch 0 taken 2017 times.
✓ Branch 1 taken 15299 times.
17316 if (profile)
530 2017 av_bprintf(&bprint, " (%s)", profile);
531
2/2
✓ Branch 0 taken 13396 times.
✓ Branch 1 taken 3920 times.
17316 if ( enc->codec_type == AVMEDIA_TYPE_VIDEO
532
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13396 times.
13396 && av_log_get_level() >= AV_LOG_VERBOSE
533 && enc->refs)
534 av_bprintf(&bprint, ", %d reference frame%s",
535 enc->refs, enc->refs > 1 ? "s" : "");
536
537
2/2
✓ Branch 0 taken 9795 times.
✓ Branch 1 taken 7521 times.
17316 if (enc->codec_tag)
538 9795 av_bprintf(&bprint, " (%s / 0x%04X)",
539 9795 av_fourcc2str(enc->codec_tag), enc->codec_tag);
540
541
5/5
✓ Branch 0 taken 13396 times.
✓ Branch 1 taken 3651 times.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 170 times.
✓ Branch 4 taken 9 times.
17316 switch (enc->codec_type) {
542 13396 case AVMEDIA_TYPE_VIDEO:
543 {
544 unsigned len;
545
546 13396 av_bprintf(&bprint, "%s%s", separator,
547
2/2
✓ Branch 0 taken 13348 times.
✓ Branch 1 taken 48 times.
13396 enc->pix_fmt == AV_PIX_FMT_NONE ? "none" :
548 13348 unknown_if_null(av_get_pix_fmt_name(enc->pix_fmt)));
549
550 13396 av_bprint_chars(&bprint, '(', 1);
551 13396 len = bprint.len;
552
553 /* The following check ensures that '(' has been written
554 * and therefore allows us to erase it if it turns out
555 * to be unnecessary. */
556
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13396 times.
13396 if (!av_bprint_is_complete(&bprint))
557 return;
558
559
3/4
✓ Branch 0 taken 1203 times.
✓ Branch 1 taken 12193 times.
✓ Branch 2 taken 1203 times.
✗ Branch 3 not taken.
13396 if (enc->bits_per_raw_sample && enc->pix_fmt != AV_PIX_FMT_NONE &&
560
2/2
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 1176 times.
1203 enc->bits_per_raw_sample < av_pix_fmt_desc_get(enc->pix_fmt)->comp[0].depth)
561 27 av_bprintf(&bprint, "%d bpc, ", enc->bits_per_raw_sample);
562
3/4
✓ Branch 0 taken 11043 times.
✓ Branch 1 taken 2353 times.
✓ Branch 2 taken 11043 times.
✗ Branch 3 not taken.
24439 if (enc->color_range != AVCOL_RANGE_UNSPECIFIED &&
563 11043 (str = av_color_range_name(enc->color_range)))
564 11043 av_bprintf(&bprint, "%s, ", str);
565
566
2/2
✓ Branch 0 taken 10557 times.
✓ Branch 1 taken 2839 times.
13396 if (enc->colorspace != AVCOL_SPC_UNSPECIFIED ||
567
2/2
✓ Branch 0 taken 10555 times.
✓ Branch 1 taken 2 times.
10557 enc->color_primaries != AVCOL_PRI_UNSPECIFIED ||
568
2/2
✓ Branch 0 taken 116 times.
✓ Branch 1 taken 10439 times.
10555 enc->color_trc != AVCOL_TRC_UNSPECIFIED) {
569 2957 const char *col = unknown_if_null(av_color_space_name(enc->colorspace));
570 2957 const char *pri = unknown_if_null(av_color_primaries_name(enc->color_primaries));
571 2957 const char *trc = unknown_if_null(av_color_transfer_name(enc->color_trc));
572
4/4
✓ Branch 0 taken 287 times.
✓ Branch 1 taken 2670 times.
✓ Branch 2 taken 130 times.
✓ Branch 3 taken 157 times.
2957 if (strcmp(col, pri) || strcmp(col, trc)) {
573 2800 new_line = 1;
574 2800 av_bprintf(&bprint, "%s/%s/%s, ", col, pri, trc);
575 } else
576 157 av_bprintf(&bprint, "%s, ", col);
577 }
578
579
2/2
✓ Branch 0 taken 7500 times.
✓ Branch 1 taken 5896 times.
13396 if (enc->field_order != AV_FIELD_UNKNOWN) {
580 7500 const char *field_order = "progressive";
581
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 7358 times.
7500 if (enc->field_order == AV_FIELD_TT)
582 142 field_order = "top first";
583
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 7310 times.
7358 else if (enc->field_order == AV_FIELD_BB)
584 48 field_order = "bottom first";
585
2/2
✓ Branch 0 taken 362 times.
✓ Branch 1 taken 6948 times.
7310 else if (enc->field_order == AV_FIELD_TB)
586 362 field_order = "top coded first (swapped)";
587
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 6822 times.
6948 else if (enc->field_order == AV_FIELD_BT)
588 126 field_order = "bottom coded first (swapped)";
589
590 7500 av_bprintf(&bprint, "%s, ", field_order);
591 }
592
593
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13396 times.
13396 if (av_log_get_level() >= AV_LOG_VERBOSE &&
594 enc->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED &&
595 (str = av_chroma_location_name(enc->chroma_sample_location)))
596 av_bprintf(&bprint, "%s, ", str);
597
598
2/2
✓ Branch 0 taken 1081 times.
✓ Branch 1 taken 12315 times.
13396 if (len == bprint.len) {
599 1081 bprint.str[len - 1] = '\0';
600 1081 bprint.len--;
601 } else {
602
1/2
✓ Branch 0 taken 12315 times.
✗ Branch 1 not taken.
12315 if (bprint.len - 2 < bprint.size) {
603 /* Erase the last ", " */
604 12315 bprint.len -= 2;
605 12315 bprint.str[bprint.len] = '\0';
606 }
607 12315 av_bprint_chars(&bprint, ')', 1);
608 }
609 }
610
611
2/2
✓ Branch 0 taken 13376 times.
✓ Branch 1 taken 20 times.
13396 if (enc->width) {
612
2/2
✓ Branch 0 taken 2798 times.
✓ Branch 1 taken 10578 times.
13376 av_bprintf(&bprint, "%s%dx%d", new_line ? separator : ", ",
613 enc->width, enc->height);
614
615
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13376 times.
13376 if (av_log_get_level() >= AV_LOG_VERBOSE &&
616 enc->coded_width && enc->coded_height &&
617 (enc->width != enc->coded_width ||
618 enc->height != enc->coded_height))
619 av_bprintf(&bprint, " (%dx%d)",
620 enc->coded_width, enc->coded_height);
621
622
2/2
✓ Branch 0 taken 2522 times.
✓ Branch 1 taken 10854 times.
13376 if (enc->sample_aspect_ratio.num) {
623 2522 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
624 2522 enc->width * (int64_t)enc->sample_aspect_ratio.num,
625 2522 enc->height * (int64_t)enc->sample_aspect_ratio.den,
626 1024 * 1024);
627 2522 av_bprintf(&bprint, " [SAR %d:%d DAR %d:%d]",
628 enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
629 display_aspect_ratio.num, display_aspect_ratio.den);
630 }
631
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13376 times.
13376 if (av_log_get_level() >= AV_LOG_DEBUG) {
632 int g = av_gcd(enc->time_base.num, enc->time_base.den);
633 av_bprintf(&bprint, ", %d/%d",
634 enc->time_base.num / g, enc->time_base.den / g);
635 }
636 }
637
2/2
✓ Branch 0 taken 7158 times.
✓ Branch 1 taken 6238 times.
13396 if (encode) {
638 7158 av_bprintf(&bprint, ", q=%d-%d", enc->qmin, enc->qmax);
639 } else {
640 #if FF_API_CODEC_PROPS
641 FF_DISABLE_DEPRECATION_WARNINGS
642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6238 times.
6238 if (enc->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS)
643 av_bprintf(&bprint, ", Closed Captions");
644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6238 times.
6238 if (enc->properties & FF_CODEC_PROPERTY_FILM_GRAIN)
645 av_bprintf(&bprint, ", Film Grain");
646
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6238 times.
6238 if (enc->properties & FF_CODEC_PROPERTY_LOSSLESS)
647 av_bprintf(&bprint, ", lossless");
648 FF_ENABLE_DEPRECATION_WARNINGS
649 #endif
650 }
651 13396 break;
652 3651 case AVMEDIA_TYPE_AUDIO:
653 3651 av_bprintf(&bprint, "%s", separator);
654
655
2/2
✓ Branch 0 taken 3635 times.
✓ Branch 1 taken 16 times.
3651 if (enc->sample_rate) {
656 3635 av_bprintf(&bprint, "%d Hz, ", enc->sample_rate);
657 }
658 3651 av_channel_layout_describe_bprint(&enc->ch_layout, &bprint);
659
2/4
✓ Branch 0 taken 3651 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3651 times.
✗ Branch 3 not taken.
7302 if (enc->sample_fmt != AV_SAMPLE_FMT_NONE &&
660 3651 (str = av_get_sample_fmt_name(enc->sample_fmt))) {
661 3651 av_bprintf(&bprint, ", %s", str);
662 }
663
2/2
✓ Branch 0 taken 1940 times.
✓ Branch 1 taken 1711 times.
3651 if ( enc->bits_per_raw_sample > 0
664
2/2
✓ Branch 1 taken 218 times.
✓ Branch 2 taken 1722 times.
1940 && enc->bits_per_raw_sample != av_get_bytes_per_sample(enc->sample_fmt) * 8)
665 218 av_bprintf(&bprint, " (%d bit)", enc->bits_per_raw_sample);
666
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3647 times.
3651 if (av_log_get_level() >= AV_LOG_VERBOSE) {
667
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (enc->initial_padding)
668 2 av_bprintf(&bprint, ", delay %d", enc->initial_padding);
669
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (enc->trailing_padding)
670 av_bprintf(&bprint, ", padding %d", enc->trailing_padding);
671 }
672 3651 break;
673 90 case AVMEDIA_TYPE_DATA:
674
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
90 if (av_log_get_level() >= AV_LOG_DEBUG) {
675 int g = av_gcd(enc->time_base.num, enc->time_base.den);
676 if (g)
677 av_bprintf(&bprint, ", %d/%d",
678 enc->time_base.num / g, enc->time_base.den / g);
679 }
680 90 break;
681 170 case AVMEDIA_TYPE_SUBTITLE:
682
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 137 times.
170 if (enc->width)
683 33 av_bprintf(&bprint, ", %dx%d", enc->width, enc->height);
684 170 break;
685 9 default:
686 9 return;
687 }
688
2/2
✓ Branch 0 taken 8934 times.
✓ Branch 1 taken 8373 times.
17307 if (encode) {
689
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8934 times.
8934 if (enc->flags & AV_CODEC_FLAG_PASS1)
690 av_bprintf(&bprint, ", pass 1");
691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8934 times.
8934 if (enc->flags & AV_CODEC_FLAG_PASS2)
692 av_bprintf(&bprint, ", pass 2");
693 }
694 17307 bitrate = get_bit_rate(enc);
695
2/2
✓ Branch 0 taken 11188 times.
✓ Branch 1 taken 6119 times.
17307 if (bitrate != 0) {
696 11188 av_bprintf(&bprint, ", %"PRId64" kb/s", bitrate / 1000);
697
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6119 times.
6119 } else if (enc->rc_max_rate > 0) {
698 av_bprintf(&bprint, ", max. %"PRId64" kb/s", enc->rc_max_rate / 1000);
699 }
700 }
701
702 2852006 int avcodec_is_open(AVCodecContext *s)
703 {
704 2852006 return !!s->internal;
705 }
706
707 794752 int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
708 {
709 794752 av_frame_unref(frame);
710
711
2/4
✓ Branch 1 taken 794752 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 794752 times.
794752 if (!avcodec_is_open(avctx) || !avctx->codec)
712 return AVERROR(EINVAL);
713
714
2/2
✓ Branch 1 taken 794690 times.
✓ Branch 2 taken 62 times.
794752 if (ff_codec_is_decoder(avctx->codec))
715 794690 return ff_decode_receive_frame(avctx, frame);
716 62 return ff_encode_receive_frame(avctx, frame);
717 }
718
719 #define WRAP_CONFIG(allowed_type, field, field_type, terminator) \
720 do { \
721 static const field_type end = terminator; \
722 if (codec->type != (allowed_type)) \
723 return AVERROR(EINVAL); \
724 *out_configs = (field); \
725 if (out_num_configs) { \
726 for (int i = 0;; i++) { \
727 if (!(field) || !memcmp(&(field)[i], &end, sizeof(end))) { \
728 *out_num_configs = i; \
729 break; \
730 } \
731 } \
732 } \
733 return 0; \
734 } while (0)
735
736 static const enum AVColorRange color_range_jpeg[] = {
737 AVCOL_RANGE_JPEG, AVCOL_RANGE_UNSPECIFIED
738 };
739
740 static const enum AVColorRange color_range_mpeg[] = {
741 AVCOL_RANGE_MPEG, AVCOL_RANGE_UNSPECIFIED
742 };
743
744 static const enum AVColorRange color_range_all[] = {
745 AVCOL_RANGE_MPEG, AVCOL_RANGE_JPEG, AVCOL_RANGE_UNSPECIFIED
746 };
747
748 static const enum AVColorRange *color_range_table[] = {
749 [AVCOL_RANGE_MPEG] = color_range_mpeg,
750 [AVCOL_RANGE_JPEG] = color_range_jpeg,
751 [AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG] = color_range_all,
752 };
753
754 60499 int ff_default_get_supported_config(const AVCodecContext *avctx,
755 const AVCodec *codec,
756 enum AVCodecConfig config,
757 unsigned flags,
758 const void **out_configs,
759 int *out_num_configs)
760 {
761
7/8
✓ Branch 0 taken 32102 times.
✓ Branch 1 taken 6784 times.
✓ Branch 2 taken 2690 times.
✓ Branch 3 taken 2690 times.
✓ Branch 4 taken 2690 times.
✓ Branch 5 taken 6758 times.
✓ Branch 6 taken 6785 times.
✗ Branch 7 not taken.
60499 switch (config) {
762 FF_DISABLE_DEPRECATION_WARNINGS
763 32102 case AV_CODEC_CONFIG_PIX_FORMAT:
764
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 32102 times.
✓ Branch 2 taken 32102 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21703 times.
✓ Branch 5 taken 30301 times.
✓ Branch 6 taken 1801 times.
✓ Branch 7 taken 19902 times.
52004 WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->pix_fmts, enum AVPixelFormat, AV_PIX_FMT_NONE);
765 6784 case AV_CODEC_CONFIG_FRAME_RATE:
766
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6784 times.
✓ Branch 2 taken 6784 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2863 times.
✓ Branch 5 taken 6730 times.
✓ Branch 6 taken 54 times.
✓ Branch 7 taken 2809 times.
9593 WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->supported_framerates, AVRational, {0});
767 2690 case AV_CODEC_CONFIG_SAMPLE_RATE:
768
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 2690 times.
✓ Branch 2 taken 2690 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 840 times.
✓ Branch 5 taken 2568 times.
✓ Branch 6 taken 122 times.
✓ Branch 7 taken 718 times.
3408 WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->supported_samplerates, int, 0);
769 2690 case AV_CODEC_CONFIG_SAMPLE_FORMAT:
770
5/8
✗ Branch 0 not taken.
✓ Branch 1 taken 2690 times.
✓ Branch 2 taken 2690 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5600 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2690 times.
✓ Branch 7 taken 2910 times.
5600 WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->sample_fmts, enum AVSampleFormat, AV_SAMPLE_FMT_NONE);
771 2690 case AV_CODEC_CONFIG_CHANNEL_LAYOUT:
772
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 2690 times.
✓ Branch 2 taken 2690 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 930 times.
✓ Branch 5 taken 2532 times.
✓ Branch 6 taken 158 times.
✓ Branch 7 taken 772 times.
3462 WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->ch_layouts, AVChannelLayout, {0});
773 FF_ENABLE_DEPRECATION_WARNINGS
774
775 6758 case AV_CODEC_CONFIG_COLOR_RANGE:
776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6758 times.
6758 if (codec->type != AVMEDIA_TYPE_VIDEO)
777 return AVERROR(EINVAL);
778 6758 *out_configs = color_range_table[ffcodec(codec)->color_ranges];
779
1/2
✓ Branch 0 taken 6758 times.
✗ Branch 1 not taken.
6758 if (out_num_configs)
780 6758 *out_num_configs = av_popcount(ffcodec(codec)->color_ranges);
781 6758 return 0;
782
783 6785 case AV_CODEC_CONFIG_COLOR_SPACE:
784 6785 *out_configs = NULL;
785
1/2
✓ Branch 0 taken 6785 times.
✗ Branch 1 not taken.
6785 if (out_num_configs)
786 6785 *out_num_configs = 0;
787 6785 return 0;
788 default:
789 return AVERROR(EINVAL);
790 }
791 }
792
793 60526 int avcodec_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec,
794 enum AVCodecConfig config, unsigned flags,
795 const void **out, int *out_num)
796 {
797 const FFCodec *codec2;
798 60526 int dummy_num = 0;
799
1/2
✓ Branch 0 taken 60526 times.
✗ Branch 1 not taken.
60526 if (!codec)
800 60526 codec = avctx->codec;
801
2/2
✓ Branch 0 taken 36452 times.
✓ Branch 1 taken 24074 times.
60526 if (!out_num)
802 36452 out_num = &dummy_num;
803
804 60526 codec2 = ffcodec(codec);
805
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 60366 times.
60526 if (codec2->get_supported_config) {
806 160 return codec2->get_supported_config(avctx, codec, config, flags, out, out_num);
807 } else {
808 60366 return ff_default_get_supported_config(avctx, codec, config, flags, out, out_num);
809 }
810 }
811