FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/avcodec.c
Date: 2025-01-20 09:27:23
Exec Total Coverage
Lines: 356 455 78.2%
Functions: 15 16 93.8%
Branches: 300 426 70.4%

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_NB },
69 };
70
71
72 24915 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
73 {
74 size_t i;
75
76
2/2
✓ Branch 0 taken 1386988 times.
✓ Branch 1 taken 24915 times.
1411903 for (i = 0; i < count; i++) {
77 1386988 size_t offset = i * size;
78
2/2
✓ Branch 0 taken 1362073 times.
✓ Branch 1 taken 24915 times.
1386988 int r = func(c, FF_PTR_ADD((char *)arg, offset));
79
2/2
✓ Branch 0 taken 930 times.
✓ Branch 1 taken 1386058 times.
1386988 if (ret)
80 930 ret[i] = r;
81 }
82 24915 emms_c();
83 24915 return 0;
84 }
85
86 8253 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
87 {
88 int i;
89
90
2/2
✓ Branch 0 taken 243678 times.
✓ Branch 1 taken 8253 times.
251931 for (i = 0; i < count; i++) {
91 243678 int r = func(c, arg, i, 0);
92
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 243628 times.
243678 if (ret)
93 50 ret[i] = r;
94 }
95 8253 emms_c();
96 8253 return 0;
97 }
98
99 static AVMutex codec_mutex = AV_MUTEX_INITIALIZER;
100
101 64337 static void lock_avcodec(const FFCodec *codec)
102 {
103
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64337 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64337 if (codec->caps_internal & FF_CODEC_CAP_NOT_INIT_THREADSAFE && codec->init)
104 ff_mutex_lock(&codec_mutex);
105 64337 }
106
107 64337 static void unlock_avcodec(const FFCodec *codec)
108 {
109
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64337 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64337 if (codec->caps_internal & FF_CODEC_CAP_NOT_INIT_THREADSAFE && codec->init)
110 ff_mutex_unlock(&codec_mutex);
111 64337 }
112
113 27385 static int64_t get_bit_rate(AVCodecContext *ctx)
114 {
115 int64_t bit_rate;
116 int bits_per_sample;
117
118
2/3
✓ Branch 0 taken 22532 times.
✓ Branch 1 taken 4853 times.
✗ Branch 2 not taken.
27385 switch (ctx->codec_type) {
119 22532 case AVMEDIA_TYPE_VIDEO:
120 case AVMEDIA_TYPE_DATA:
121 case AVMEDIA_TYPE_SUBTITLE:
122 case AVMEDIA_TYPE_ATTACHMENT:
123 22532 bit_rate = ctx->bit_rate;
124 22532 break;
125 4853 case AVMEDIA_TYPE_AUDIO:
126 4853 bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
127
2/2
✓ Branch 0 taken 2432 times.
✓ Branch 1 taken 2421 times.
4853 if (bits_per_sample) {
128 2432 bit_rate = ctx->sample_rate * (int64_t)ctx->ch_layout.nb_channels;
129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2432 times.
2432 if (bit_rate > INT64_MAX / bits_per_sample) {
130 bit_rate = 0;
131 } else
132 2432 bit_rate *= bits_per_sample;
133 } else
134 2421 bit_rate = ctx->bit_rate;
135 4853 break;
136 default:
137 bit_rate = 0;
138 break;
139 }
140 27385 return bit_rate;
141 }
142
143 36181 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
144 {
145 36181 int ret = 0;
146 AVCodecInternal *avci;
147 const FFCodec *codec2;
148 const AVDictionaryEntry *e;
149
150
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 36181 times.
36181 if (avcodec_is_open(avctx))
151 return 0;
152
153
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 36177 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
36181 if (!codec && !avctx->codec) {
154 av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n");
155 return AVERROR(EINVAL);
156 }
157
6/6
✓ Branch 0 taken 36177 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 27924 times.
✓ Branch 3 taken 8253 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 27914 times.
36181 if (codec && avctx->codec && codec != avctx->codec) {
158 10 av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
159 10 "but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name);
160 10 return AVERROR(EINVAL);
161 }
162
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 36167 times.
36171 if (!codec)
163 4 codec = avctx->codec;
164 36171 codec2 = ffcodec(codec);
165
166
3/4
✓ Branch 0 taken 36165 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 36165 times.
✗ Branch 3 not taken.
36171 if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) ||
167
3/4
✓ Branch 0 taken 36165 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36165 times.
36171 (avctx->codec_id != AV_CODEC_ID_NONE && avctx->codec_id != codec->id)) {
168 av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
169 return AVERROR(EINVAL);
170 }
171
172 36171 avctx->codec_type = codec->type;
173 36171 avctx->codec_id = codec->id;
174 36171 avctx->codec = codec;
175
176
2/4
✓ Branch 0 taken 36171 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 36171 times.
36171 if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
177 return AVERROR(EINVAL);
178
179 // set the whitelist from provided options dict,
180 // so we can check it immediately
181
2/2
✓ Branch 0 taken 8563 times.
✓ Branch 1 taken 27608 times.
36171 e = options ? av_dict_get(*options, "codec_whitelist", NULL, 0) : NULL;
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36171 times.
36171 if (e) {
183 ret = av_opt_set(avctx, e->key, e->value, 0);
184 if (ret < 0)
185 return ret;
186 }
187
188
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 36171 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
36171 if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {
189 av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist);
190 return AVERROR(EINVAL);
191 }
192
193
2/2
✓ Branch 1 taken 15376 times.
✓ Branch 2 taken 20795 times.
36171 avci = av_codec_is_decoder(codec) ?
194 15376 ff_decode_internal_alloc() :
195 20795 ff_encode_internal_alloc();
196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36171 times.
36171 if (!avci) {
197 ret = AVERROR(ENOMEM);
198 goto end;
199 }
200 36171 avctx->internal = avci;
201
202 36171 avci->buffer_frame = av_frame_alloc();
203 36171 avci->buffer_pkt = av_packet_alloc();
204
2/4
✓ Branch 0 taken 36171 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 36171 times.
36171 if (!avci->buffer_frame || !avci->buffer_pkt) {
205 ret = AVERROR(ENOMEM);
206 goto free_and_end;
207 }
208
209
2/2
✓ Branch 0 taken 16026 times.
✓ Branch 1 taken 20145 times.
36171 if (codec2->priv_data_size > 0) {
210
2/2
✓ Branch 0 taken 8100 times.
✓ Branch 1 taken 7926 times.
16026 if (!avctx->priv_data) {
211 8100 avctx->priv_data = av_mallocz(codec2->priv_data_size);
212
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8100 times.
8100 if (!avctx->priv_data) {
213 ret = AVERROR(ENOMEM);
214 goto free_and_end;
215 }
216
2/2
✓ Branch 0 taken 2367 times.
✓ Branch 1 taken 5733 times.
8100 if (codec->priv_class) {
217 2367 *(const AVClass **)avctx->priv_data = codec->priv_class;
218 2367 av_opt_set_defaults(avctx->priv_data);
219 }
220 }
221 } else {
222 20145 avctx->priv_data = NULL;
223 }
224
225 36171 ret = av_opt_set_dict2(avctx, options, AV_OPT_SEARCH_CHILDREN);
226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36171 times.
36171 if (ret < 0)
227 goto free_and_end;
228
229 // only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions
230
6/8
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 36141 times.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 24 times.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
36171 if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&
231
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))) {
232
3/4
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 36141 times.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
36171 if (avctx->coded_width && avctx->coded_height)
233 30 ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
234
3/4
✓ Branch 0 taken 27149 times.
✓ Branch 1 taken 8992 times.
✓ Branch 2 taken 27149 times.
✗ Branch 3 not taken.
36141 else if (avctx->width && avctx->height)
235 27149 ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36171 times.
36171 if (ret < 0)
237 goto free_and_end;
238 }
239
240
5/8
✓ Branch 0 taken 8992 times.
✓ Branch 1 taken 27179 times.
✓ Branch 2 taken 8992 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8992 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 8992 times.
36171 if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
241
1/2
✓ Branch 1 taken 27179 times.
✗ Branch 2 not taken.
27179 && ( av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0
242
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27179 times.
27179 || av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0)) {
243 av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n");
244 ff_set_dimensions(avctx, 0, 0);
245 }
246
247
3/4
✓ Branch 0 taken 27179 times.
✓ Branch 1 taken 8992 times.
✓ Branch 2 taken 27179 times.
✗ Branch 3 not taken.
36171 if (avctx->width > 0 && avctx->height > 0) {
248
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27179 times.
27179 if (av_image_check_sar(avctx->width, avctx->height,
249 avctx->sample_aspect_ratio) < 0) {
250 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
251 avctx->sample_aspect_ratio.num,
252 avctx->sample_aspect_ratio.den);
253 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
254 }
255 }
256
257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36171 times.
36171 if (avctx->sample_rate < 0) {
258 av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", avctx->sample_rate);
259 ret = AVERROR(EINVAL);
260 goto free_and_end;
261 }
262
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36171 times.
36171 if (avctx->block_align < 0) {
263 av_log(avctx, AV_LOG_ERROR, "Invalid block align: %d\n", avctx->block_align);
264 ret = AVERROR(EINVAL);
265 goto free_and_end;
266 }
267
268 /* AV_CODEC_CAP_CHANNEL_CONF is a decoder-only flag; so the code below
269 * in particular checks that nb_channels is set for all audio encoders. */
270
4/4
✓ Branch 0 taken 4688 times.
✓ Branch 1 taken 31483 times.
✓ Branch 2 taken 239 times.
✓ Branch 3 taken 4449 times.
36171 if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && !avctx->ch_layout.nb_channels
271
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 239 times.
239 && !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) {
272 av_log(avctx, AV_LOG_ERROR, "%s requires channel layout to be set\n",
273 av_codec_is_decoder(codec) ? "Decoder" : "Encoder");
274 ret = AVERROR(EINVAL);
275 goto free_and_end;
276 }
277
3/4
✓ Branch 0 taken 4449 times.
✓ Branch 1 taken 31722 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4449 times.
36171 if (avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) {
278 av_log(avctx, AV_LOG_ERROR, "Invalid channel layout\n");
279 ret = AVERROR(EINVAL);
280 goto free_and_end;
281 }
282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36171 times.
36171 if (avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
283 av_log(avctx, AV_LOG_ERROR, "Too many channels: %d\n", avctx->ch_layout.nb_channels);
284 ret = AVERROR(EINVAL);
285 goto free_and_end;
286 }
287
288 36171 avctx->frame_num = 0;
289 36171 avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id);
290
291
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36164 times.
36171 if ((avctx->codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) &&
292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
293 const char *codec_string = av_codec_is_encoder(codec) ? "encoder" : "decoder";
294 const AVCodec *codec2;
295 av_log(avctx, AV_LOG_ERROR,
296 "The %s '%s' is experimental but experimental codecs are not enabled, "
297 "add '-strict %d' if you want to use it.\n",
298 codec_string, codec->name, FF_COMPLIANCE_EXPERIMENTAL);
299 codec2 = av_codec_is_encoder(codec) ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id);
300 if (!(codec2->capabilities & AV_CODEC_CAP_EXPERIMENTAL))
301 av_log(avctx, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n",
302 codec_string, codec2->name);
303 ret = AVERROR_EXPERIMENTAL;
304 goto free_and_end;
305 }
306
307
2/2
✓ Branch 0 taken 4688 times.
✓ Branch 1 taken 31483 times.
36171 if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
308
3/4
✓ Branch 0 taken 1331 times.
✓ Branch 1 taken 3357 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1331 times.
4688 (!avctx->time_base.num || !avctx->time_base.den)) {
309 3357 avctx->time_base.num = 1;
310 3357 avctx->time_base.den = avctx->sample_rate;
311 }
312
313
2/2
✓ Branch 1 taken 20795 times.
✓ Branch 2 taken 15376 times.
36171 if (av_codec_is_encoder(avctx->codec))
314 20795 ret = ff_encode_preinit(avctx);
315 else
316 15376 ret = ff_decode_preinit(avctx);
317
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36171 times.
36171 if (ret < 0)
318 goto free_and_end;
319
320
2/2
✓ Branch 0 taken 34536 times.
✓ Branch 1 taken 1635 times.
36171 if (HAVE_THREADS && !avci->frame_thread_encoder) {
321 /* Frame-threaded decoders call FFCodec.init for their child contexts. */
322 34536 lock_avcodec(codec2);
323 34536 ret = ff_thread_init(avctx);
324 34536 unlock_avcodec(codec2);
325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34536 times.
34536 if (ret < 0) {
326 goto free_and_end;
327 }
328 }
329 if (!HAVE_THREADS && !(codec2->caps_internal & FF_CODEC_CAP_AUTO_THREADS))
330 avctx->thread_count = 1;
331
332
2/2
✓ Branch 0 taken 1645 times.
✓ Branch 1 taken 34526 times.
36171 if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||
333
2/2
✓ Branch 0 taken 1635 times.
✓ Branch 1 taken 10 times.
1645 avci->frame_thread_encoder) {
334
2/2
✓ Branch 0 taken 29801 times.
✓ Branch 1 taken 6360 times.
36161 if (codec2->init) {
335 29801 lock_avcodec(codec2);
336 29801 ret = codec2->init(avctx);
337 29801 unlock_avcodec(codec2);
338
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 29793 times.
29801 if (ret < 0) {
339 8 avci->needs_close = codec2->caps_internal & FF_CODEC_CAP_INIT_CLEANUP;
340 8 goto free_and_end;
341 }
342 }
343 36153 avci->needs_close = 1;
344 }
345
346 36163 ret=0;
347
348
2/2
✓ Branch 1 taken 15368 times.
✓ Branch 2 taken 20795 times.
36163 if (av_codec_is_decoder(avctx->codec)) {
349
2/2
✓ Branch 0 taken 10736 times.
✓ Branch 1 taken 4632 times.
15368 if (!avctx->bit_rate)
350 10736 avctx->bit_rate = get_bit_rate(avctx);
351
352 /* validate channel layout from the decoder */
353
3/4
✓ Branch 0 taken 3158 times.
✓ Branch 1 taken 12210 times.
✓ Branch 3 taken 3158 times.
✗ Branch 4 not taken.
15368 if ((avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) ||
354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15368 times.
15368 avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
355 ret = AVERROR(EINVAL);
356 goto free_and_end;
357 }
358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15368 times.
15368 if (avctx->bits_per_coded_sample < 0) {
359 ret = AVERROR(EINVAL);
360 goto free_and_end;
361 }
362 }
363
2/2
✓ Branch 0 taken 5107 times.
✓ Branch 1 taken 31056 times.
36163 if (codec->priv_class)
364
1/2
✓ Branch 0 taken 5107 times.
✗ Branch 1 not taken.
5107 av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);
365
366 36163 end:
367
368 36171 return ret;
369 8 free_and_end:
370 8 ff_codec_close(avctx);
371 8 goto end;
372 }
373
374 103 void avcodec_flush_buffers(AVCodecContext *avctx)
375 {
376 103 AVCodecInternal *avci = avctx->internal;
377
378
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 103 times.
103 if (av_codec_is_encoder(avctx->codec)) {
379 int caps = avctx->codec->capabilities;
380
381 if (!(caps & AV_CODEC_CAP_ENCODER_FLUSH)) {
382 // Only encoders that explicitly declare support for it can be
383 // flushed. Otherwise, this is a no-op.
384 av_log(avctx, AV_LOG_WARNING, "Ignoring attempt to flush encoder "
385 "that doesn't support it\n");
386 return;
387 }
388 ff_encode_flush_buffers(avctx);
389 } else
390 103 ff_decode_flush_buffers(avctx);
391
392 103 avci->draining = 0;
393 103 avci->draining_done = 0;
394
1/2
✓ Branch 0 taken 103 times.
✗ Branch 1 not taken.
103 if (avci->buffer_frame)
395 103 av_frame_unref(avci->buffer_frame);
396
1/2
✓ Branch 0 taken 103 times.
✗ Branch 1 not taken.
103 if (avci->buffer_pkt)
397 103 av_packet_unref(avci->buffer_pkt);
398
399
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 103 times.
103 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME &&
400 !avci->is_frame_mt)
401 ff_thread_flush(avctx);
402
2/2
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 74 times.
103 else if (ffcodec(avctx->codec)->flush)
403 29 ffcodec(avctx->codec)->flush(avctx);
404 }
405
406 915 void avsubtitle_free(AVSubtitle *sub)
407 {
408 int i;
409
410
2/2
✓ Branch 0 taken 860 times.
✓ Branch 1 taken 915 times.
1775 for (i = 0; i < sub->num_rects; i++) {
411 860 AVSubtitleRect *const rect = sub->rects[i];
412
413 860 av_freep(&rect->data[0]);
414 860 av_freep(&rect->data[1]);
415 860 av_freep(&rect->data[2]);
416 860 av_freep(&rect->data[3]);
417 860 av_freep(&rect->text);
418 860 av_freep(&rect->ass);
419
420 860 av_freep(&sub->rects[i]);
421 }
422
423 915 av_freep(&sub->rects);
424
425 915 memset(sub, 0, sizeof(*sub));
426 915 }
427
428 61858 av_cold void ff_codec_close(AVCodecContext *avctx)
429 {
430 int i;
431
432
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 61858 times.
61858 if (!avctx)
433 return;
434
435
2/2
✓ Branch 1 taken 36171 times.
✓ Branch 2 taken 25687 times.
61858 if (avcodec_is_open(avctx)) {
436 36171 AVCodecInternal *avci = avctx->internal;
437
438 36171 if (CONFIG_FRAME_THREAD_ENCODER &&
439
4/4
✓ Branch 0 taken 14703 times.
✓ Branch 1 taken 21468 times.
✓ Branch 2 taken 1635 times.
✓ Branch 3 taken 13068 times.
36171 avci->frame_thread_encoder && avctx->thread_count > 1) {
440 1635 ff_frame_thread_encoder_free(avctx);
441 }
442
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 36141 times.
36171 if (HAVE_THREADS && avci->thread_ctx)
443 30 ff_thread_free(avctx);
444
4/4
✓ Branch 0 taken 36153 times.
✓ Branch 1 taken 18 times.
✓ Branch 3 taken 7353 times.
✓ Branch 4 taken 28800 times.
36171 if (avci->needs_close && ffcodec(avctx->codec)->close)
445 7353 ffcodec(avctx->codec)->close(avctx);
446 36171 avci->byte_buffer_size = 0;
447 36171 av_freep(&avci->byte_buffer);
448 36171 av_frame_free(&avci->buffer_frame);
449 36171 av_packet_free(&avci->buffer_pkt);
450 36171 av_packet_free(&avci->last_pkt_props);
451
452 36171 av_packet_free(&avci->in_pkt);
453 36171 av_frame_free(&avci->in_frame);
454 36171 av_frame_free(&avci->recon_frame);
455
456 36171 av_refstruct_unref(&avci->pool);
457 36171 av_refstruct_pool_uninit(&avci->progress_frame_pool);
458
2/2
✓ Branch 1 taken 15376 times.
✓ Branch 2 taken 20795 times.
36171 if (av_codec_is_decoder(avctx->codec))
459 15376 ff_decode_internal_uninit(avctx);
460
461 36171 ff_hwaccel_uninit(avctx);
462
463 36171 av_bsf_free(&avci->bsf);
464
465 #if FF_API_DROPCHANGED
466 36171 av_channel_layout_uninit(&avci->initial_ch_layout);
467 #endif
468
469 #if CONFIG_LCMS2
470 ff_icc_context_uninit(&avci->icc);
471 #endif
472
473 36171 av_freep(&avctx->internal);
474 }
475
476
2/2
✓ Branch 0 taken 4227 times.
✓ Branch 1 taken 61858 times.
66085 for (i = 0; i < avctx->nb_coded_side_data; i++)
477 4227 av_freep(&avctx->coded_side_data[i].data);
478 61858 av_freep(&avctx->coded_side_data);
479 61858 avctx->nb_coded_side_data = 0;
480 61858 av_frame_side_data_free(&avctx->decoded_side_data,
481 &avctx->nb_decoded_side_data);
482
483 61858 av_buffer_unref(&avctx->hw_frames_ctx);
484 61858 av_buffer_unref(&avctx->hw_device_ctx);
485
486
5/6
✓ Branch 0 taken 24118 times.
✓ Branch 1 taken 37740 times.
✓ Branch 2 taken 24118 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7474 times.
✓ Branch 5 taken 16644 times.
61858 if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
487 7474 av_opt_free(avctx->priv_data);
488 61858 av_opt_free(avctx);
489 61858 av_freep(&avctx->priv_data);
490
2/2
✓ Branch 1 taken 20795 times.
✓ Branch 2 taken 41063 times.
61858 if (av_codec_is_encoder(avctx->codec)) {
491 20795 av_freep(&avctx->extradata);
492 20795 avctx->extradata_size = 0;
493
2/2
✓ Branch 1 taken 31682 times.
✓ Branch 2 taken 9381 times.
41063 } else if (av_codec_is_decoder(avctx->codec))
494 31682 av_freep(&avctx->subtitle_header);
495
496 61858 avctx->codec = NULL;
497 61858 avctx->active_thread_type = 0;
498 }
499
500 #if FF_API_AVCODEC_CLOSE
501 int avcodec_close(AVCodecContext *avctx)
502 {
503 ff_codec_close(avctx);
504 return 0;
505 }
506 #endif
507
508 21301 static const char *unknown_if_null(const char *str)
509 {
510
1/2
✓ Branch 0 taken 21301 times.
✗ Branch 1 not taken.
21301 return str ? str : "unknown";
511 }
512
513 16658 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
514 {
515 const char *codec_type;
516 const char *codec_name;
517 16658 const char *profile = NULL;
518 AVBPrint bprint;
519 int64_t bitrate;
520 16658 int new_line = 0;
521 AVRational display_aspect_ratio;
522
2/2
✓ Branch 0 taken 16622 times.
✓ Branch 1 taken 36 times.
16658 const char *separator = enc->dump_separator ? (const char *)enc->dump_separator : ", ";
523 const char *str;
524
525
2/4
✓ Branch 0 taken 16658 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16658 times.
16658 if (!buf || buf_size <= 0)
526 9 return;
527 16658 av_bprint_init_for_buffer(&bprint, buf, buf_size);
528 16658 codec_type = av_get_media_type_string(enc->codec_type);
529 16658 codec_name = avcodec_get_name(enc->codec_id);
530 16658 profile = avcodec_profile_name(enc->codec_id, enc->profile);
531
532
1/2
✓ Branch 0 taken 16658 times.
✗ Branch 1 not taken.
16658 av_bprintf(&bprint, "%s: %s", codec_type ? codec_type : "unknown",
533 codec_name);
534 16658 buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */
535
536
4/4
✓ Branch 0 taken 8092 times.
✓ Branch 1 taken 8566 times.
✓ Branch 2 taken 309 times.
✓ Branch 3 taken 7783 times.
16658 if (enc->codec && strcmp(enc->codec->name, codec_name))
537 309 av_bprintf(&bprint, " (%s)", enc->codec->name);
538
539
2/2
✓ Branch 0 taken 1981 times.
✓ Branch 1 taken 14677 times.
16658 if (profile)
540 1981 av_bprintf(&bprint, " (%s)", profile);
541
2/2
✓ Branch 0 taken 12763 times.
✓ Branch 1 taken 3895 times.
16658 if ( enc->codec_type == AVMEDIA_TYPE_VIDEO
542
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12763 times.
12763 && av_log_get_level() >= AV_LOG_VERBOSE
543 && enc->refs)
544 av_bprintf(&bprint, ", %d reference frame%s",
545 enc->refs, enc->refs > 1 ? "s" : "");
546
547
2/2
✓ Branch 0 taken 9529 times.
✓ Branch 1 taken 7129 times.
16658 if (enc->codec_tag)
548 9529 av_bprintf(&bprint, " (%s / 0x%04X)",
549 9529 av_fourcc2str(enc->codec_tag), enc->codec_tag);
550
551
5/5
✓ Branch 0 taken 12763 times.
✓ Branch 1 taken 3640 times.
✓ Branch 2 taken 86 times.
✓ Branch 3 taken 160 times.
✓ Branch 4 taken 9 times.
16658 switch (enc->codec_type) {
552 12763 case AVMEDIA_TYPE_VIDEO:
553 {
554 unsigned len;
555
556 12763 av_bprintf(&bprint, "%s%s", separator,
557
2/2
✓ Branch 0 taken 12715 times.
✓ Branch 1 taken 48 times.
12763 enc->pix_fmt == AV_PIX_FMT_NONE ? "none" :
558 12715 unknown_if_null(av_get_pix_fmt_name(enc->pix_fmt)));
559
560 12763 av_bprint_chars(&bprint, '(', 1);
561 12763 len = bprint.len;
562
563 /* The following check ensures that '(' has been written
564 * and therefore allows us to erase it if it turns out
565 * to be unnecessary. */
566
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12763 times.
12763 if (!av_bprint_is_complete(&bprint))
567 return;
568
569
3/4
✓ Branch 0 taken 1182 times.
✓ Branch 1 taken 11581 times.
✓ Branch 2 taken 1182 times.
✗ Branch 3 not taken.
12763 if (enc->bits_per_raw_sample && enc->pix_fmt != AV_PIX_FMT_NONE &&
570
2/2
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 1155 times.
1182 enc->bits_per_raw_sample < av_pix_fmt_desc_get(enc->pix_fmt)->comp[0].depth)
571 27 av_bprintf(&bprint, "%d bpc, ", enc->bits_per_raw_sample);
572
3/4
✓ Branch 0 taken 10439 times.
✓ Branch 1 taken 2324 times.
✓ Branch 2 taken 10439 times.
✗ Branch 3 not taken.
23202 if (enc->color_range != AVCOL_RANGE_UNSPECIFIED &&
573 10439 (str = av_color_range_name(enc->color_range)))
574 10439 av_bprintf(&bprint, "%s, ", str);
575
576
2/2
✓ Branch 0 taken 10019 times.
✓ Branch 1 taken 2744 times.
12763 if (enc->colorspace != AVCOL_SPC_UNSPECIFIED ||
577
2/2
✓ Branch 0 taken 10017 times.
✓ Branch 1 taken 2 times.
10019 enc->color_primaries != AVCOL_PRI_UNSPECIFIED ||
578
2/2
✓ Branch 0 taken 116 times.
✓ Branch 1 taken 9901 times.
10017 enc->color_trc != AVCOL_TRC_UNSPECIFIED) {
579 2862 const char *col = unknown_if_null(av_color_space_name(enc->colorspace));
580 2862 const char *pri = unknown_if_null(av_color_primaries_name(enc->color_primaries));
581 2862 const char *trc = unknown_if_null(av_color_transfer_name(enc->color_trc));
582
4/4
✓ Branch 0 taken 285 times.
✓ Branch 1 taken 2577 times.
✓ Branch 2 taken 130 times.
✓ Branch 3 taken 155 times.
2862 if (strcmp(col, pri) || strcmp(col, trc)) {
583 2707 new_line = 1;
584 2707 av_bprintf(&bprint, "%s/%s/%s, ", col, pri, trc);
585 } else
586 155 av_bprintf(&bprint, "%s, ", col);
587 }
588
589
2/2
✓ Branch 0 taken 7048 times.
✓ Branch 1 taken 5715 times.
12763 if (enc->field_order != AV_FIELD_UNKNOWN) {
590 7048 const char *field_order = "progressive";
591
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 6906 times.
7048 if (enc->field_order == AV_FIELD_TT)
592 142 field_order = "top first";
593
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 6862 times.
6906 else if (enc->field_order == AV_FIELD_BB)
594 44 field_order = "bottom first";
595
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 6510 times.
6862 else if (enc->field_order == AV_FIELD_TB)
596 352 field_order = "top coded first (swapped)";
597
2/2
✓ Branch 0 taken 122 times.
✓ Branch 1 taken 6388 times.
6510 else if (enc->field_order == AV_FIELD_BT)
598 122 field_order = "bottom coded first (swapped)";
599
600 7048 av_bprintf(&bprint, "%s, ", field_order);
601 }
602
603
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12763 times.
12763 if (av_log_get_level() >= AV_LOG_VERBOSE &&
604 enc->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED &&
605 (str = av_chroma_location_name(enc->chroma_sample_location)))
606 av_bprintf(&bprint, "%s, ", str);
607
608
2/2
✓ Branch 0 taken 1064 times.
✓ Branch 1 taken 11699 times.
12763 if (len == bprint.len) {
609 1064 bprint.str[len - 1] = '\0';
610 1064 bprint.len--;
611 } else {
612
1/2
✓ Branch 0 taken 11699 times.
✗ Branch 1 not taken.
11699 if (bprint.len - 2 < bprint.size) {
613 /* Erase the last ", " */
614 11699 bprint.len -= 2;
615 11699 bprint.str[bprint.len] = '\0';
616 }
617 11699 av_bprint_chars(&bprint, ')', 1);
618 }
619 }
620
621
2/2
✓ Branch 0 taken 12743 times.
✓ Branch 1 taken 20 times.
12763 if (enc->width) {
622
2/2
✓ Branch 0 taken 2705 times.
✓ Branch 1 taken 10038 times.
12743 av_bprintf(&bprint, "%s%dx%d", new_line ? separator : ", ",
623 enc->width, enc->height);
624
625
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12743 times.
12743 if (av_log_get_level() >= AV_LOG_VERBOSE &&
626 enc->coded_width && enc->coded_height &&
627 (enc->width != enc->coded_width ||
628 enc->height != enc->coded_height))
629 av_bprintf(&bprint, " (%dx%d)",
630 enc->coded_width, enc->coded_height);
631
632
2/2
✓ Branch 0 taken 2194 times.
✓ Branch 1 taken 10549 times.
12743 if (enc->sample_aspect_ratio.num) {
633 2194 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
634 2194 enc->width * (int64_t)enc->sample_aspect_ratio.num,
635 2194 enc->height * (int64_t)enc->sample_aspect_ratio.den,
636 1024 * 1024);
637 2194 av_bprintf(&bprint, " [SAR %d:%d DAR %d:%d]",
638 enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
639 display_aspect_ratio.num, display_aspect_ratio.den);
640 }
641
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12743 times.
12743 if (av_log_get_level() >= AV_LOG_DEBUG) {
642 int g = av_gcd(enc->time_base.num, enc->time_base.den);
643 av_bprintf(&bprint, ", %d/%d",
644 enc->time_base.num / g, enc->time_base.den / g);
645 }
646 }
647
2/2
✓ Branch 0 taken 6695 times.
✓ Branch 1 taken 6068 times.
12763 if (encode) {
648 6695 av_bprintf(&bprint, ", q=%d-%d", enc->qmin, enc->qmax);
649 } else {
650 #if FF_API_CODEC_PROPS
651 FF_DISABLE_DEPRECATION_WARNINGS
652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6068 times.
6068 if (enc->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS)
653 av_bprintf(&bprint, ", Closed Captions");
654
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6068 times.
6068 if (enc->properties & FF_CODEC_PROPERTY_FILM_GRAIN)
655 av_bprintf(&bprint, ", Film Grain");
656
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6068 times.
6068 if (enc->properties & FF_CODEC_PROPERTY_LOSSLESS)
657 av_bprintf(&bprint, ", lossless");
658 FF_ENABLE_DEPRECATION_WARNINGS
659 #endif
660 }
661 12763 break;
662 3640 case AVMEDIA_TYPE_AUDIO:
663 3640 av_bprintf(&bprint, "%s", separator);
664
665
2/2
✓ Branch 0 taken 3624 times.
✓ Branch 1 taken 16 times.
3640 if (enc->sample_rate) {
666 3624 av_bprintf(&bprint, "%d Hz, ", enc->sample_rate);
667 }
668 3640 av_channel_layout_describe_bprint(&enc->ch_layout, &bprint);
669
3/4
✓ Branch 0 taken 3620 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 3620 times.
✗ Branch 3 not taken.
7260 if (enc->sample_fmt != AV_SAMPLE_FMT_NONE &&
670 3620 (str = av_get_sample_fmt_name(enc->sample_fmt))) {
671 3620 av_bprintf(&bprint, ", %s", str);
672 }
673
2/2
✓ Branch 0 taken 1934 times.
✓ Branch 1 taken 1706 times.
3640 if ( enc->bits_per_raw_sample > 0
674
2/2
✓ Branch 1 taken 218 times.
✓ Branch 2 taken 1716 times.
1934 && enc->bits_per_raw_sample != av_get_bytes_per_sample(enc->sample_fmt) * 8)
675 218 av_bprintf(&bprint, " (%d bit)", enc->bits_per_raw_sample);
676
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3636 times.
3640 if (av_log_get_level() >= AV_LOG_VERBOSE) {
677
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (enc->initial_padding)
678 2 av_bprintf(&bprint, ", delay %d", enc->initial_padding);
679
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (enc->trailing_padding)
680 av_bprintf(&bprint, ", padding %d", enc->trailing_padding);
681 }
682 3640 break;
683 86 case AVMEDIA_TYPE_DATA:
684
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 86 times.
86 if (av_log_get_level() >= AV_LOG_DEBUG) {
685 int g = av_gcd(enc->time_base.num, enc->time_base.den);
686 if (g)
687 av_bprintf(&bprint, ", %d/%d",
688 enc->time_base.num / g, enc->time_base.den / g);
689 }
690 86 break;
691 160 case AVMEDIA_TYPE_SUBTITLE:
692
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 127 times.
160 if (enc->width)
693 33 av_bprintf(&bprint, ", %dx%d", enc->width, enc->height);
694 160 break;
695 9 default:
696 9 return;
697 }
698
2/2
✓ Branch 0 taken 8455 times.
✓ Branch 1 taken 8194 times.
16649 if (encode) {
699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8455 times.
8455 if (enc->flags & AV_CODEC_FLAG_PASS1)
700 av_bprintf(&bprint, ", pass 1");
701
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8455 times.
8455 if (enc->flags & AV_CODEC_FLAG_PASS2)
702 av_bprintf(&bprint, ", pass 2");
703 }
704 16649 bitrate = get_bit_rate(enc);
705
2/2
✓ Branch 0 taken 10711 times.
✓ Branch 1 taken 5938 times.
16649 if (bitrate != 0) {
706 10711 av_bprintf(&bprint, ", %"PRId64" kb/s", bitrate / 1000);
707
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5938 times.
5938 } else if (enc->rc_max_rate > 0) {
708 av_bprintf(&bprint, ", max. %"PRId64" kb/s", enc->rc_max_rate / 1000);
709 }
710 }
711
712 2804104 int avcodec_is_open(AVCodecContext *s)
713 {
714 2804104 return !!s->internal;
715 }
716
717 783613 int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
718 {
719 783613 av_frame_unref(frame);
720
721
2/2
✓ Branch 1 taken 783553 times.
✓ Branch 2 taken 60 times.
783613 if (av_codec_is_decoder(avctx->codec))
722 783553 return ff_decode_receive_frame(avctx, frame);
723 60 return ff_encode_receive_frame(avctx, frame);
724 }
725
726 #define WRAP_CONFIG(allowed_type, field, field_type, terminator) \
727 do { \
728 static const field_type end = terminator; \
729 if (codec->type != (allowed_type)) \
730 return AVERROR(EINVAL); \
731 *out_configs = (field); \
732 if (out_num_configs) { \
733 for (int i = 0;; i++) { \
734 if (!(field) || !memcmp(&(field)[i], &end, sizeof(end))) { \
735 *out_num_configs = i; \
736 break; \
737 } \
738 } \
739 } \
740 return 0; \
741 } while (0)
742
743 static const enum AVColorRange color_range_jpeg[] = {
744 AVCOL_RANGE_JPEG, AVCOL_RANGE_UNSPECIFIED
745 };
746
747 static const enum AVColorRange color_range_mpeg[] = {
748 AVCOL_RANGE_MPEG, AVCOL_RANGE_UNSPECIFIED
749 };
750
751 static const enum AVColorRange color_range_all[] = {
752 AVCOL_RANGE_MPEG, AVCOL_RANGE_JPEG, AVCOL_RANGE_UNSPECIFIED
753 };
754
755 static const enum AVColorRange *color_range_table[] = {
756 [AVCOL_RANGE_MPEG] = color_range_mpeg,
757 [AVCOL_RANGE_JPEG] = color_range_jpeg,
758 [AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG] = color_range_all,
759 };
760
761 74067 int ff_default_get_supported_config(const AVCodecContext *avctx,
762 const AVCodec *codec,
763 enum AVCodecConfig config,
764 unsigned flags,
765 const void **out_configs,
766 int *out_num_configs)
767 {
768
7/8
✓ Branch 0 taken 38829 times.
✓ Branch 1 taken 14551 times.
✓ Branch 2 taken 2678 times.
✓ Branch 3 taken 2678 times.
✓ Branch 4 taken 2678 times.
✓ Branch 5 taken 6313 times.
✓ Branch 6 taken 6340 times.
✗ Branch 7 not taken.
74067 switch (config) {
769 FF_DISABLE_DEPRECATION_WARNINGS
770 38829 case AV_CODEC_CONFIG_PIX_FORMAT:
771
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 38829 times.
✓ Branch 2 taken 38829 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 78453 times.
✓ Branch 5 taken 28839 times.
✓ Branch 6 taken 9990 times.
✓ Branch 7 taken 68463 times.
107292 WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->pix_fmts, enum AVPixelFormat, AV_PIX_FMT_NONE);
772 14551 case AV_CODEC_CONFIG_FRAME_RATE:
773
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 14551 times.
✓ Branch 2 taken 14551 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2863 times.
✓ Branch 5 taken 14497 times.
✓ Branch 6 taken 54 times.
✓ Branch 7 taken 2809 times.
17360 WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->supported_framerates, AVRational, {0});
774 2678 case AV_CODEC_CONFIG_SAMPLE_RATE:
775
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 2678 times.
✓ Branch 2 taken 2678 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 860 times.
✓ Branch 5 taken 2556 times.
✓ Branch 6 taken 122 times.
✓ Branch 7 taken 738 times.
3416 WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->supported_samplerates, int, 0);
776 2678 case AV_CODEC_CONFIG_SAMPLE_FORMAT:
777
5/8
✗ Branch 0 not taken.
✓ Branch 1 taken 2678 times.
✓ Branch 2 taken 2678 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5576 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2678 times.
✓ Branch 7 taken 2898 times.
5576 WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->sample_fmts, enum AVSampleFormat, AV_SAMPLE_FMT_NONE);
778 2678 case AV_CODEC_CONFIG_CHANNEL_LAYOUT:
779
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 2678 times.
✓ Branch 2 taken 2678 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 896 times.
✓ Branch 5 taken 2522 times.
✓ Branch 6 taken 156 times.
✓ Branch 7 taken 740 times.
3418 WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->ch_layouts, AVChannelLayout, {0});
780 FF_ENABLE_DEPRECATION_WARNINGS
781
782 6313 case AV_CODEC_CONFIG_COLOR_RANGE:
783
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6313 times.
6313 if (codec->type != AVMEDIA_TYPE_VIDEO)
784 return AVERROR(EINVAL);
785 6313 *out_configs = color_range_table[ffcodec(codec)->color_ranges];
786
1/2
✓ Branch 0 taken 6313 times.
✗ Branch 1 not taken.
6313 if (out_num_configs)
787 6313 *out_num_configs = av_popcount(ffcodec(codec)->color_ranges);
788 6313 return 0;
789
790 6340 case AV_CODEC_CONFIG_COLOR_SPACE:
791 6340 *out_configs = NULL;
792
1/2
✓ Branch 0 taken 6340 times.
✗ Branch 1 not taken.
6340 if (out_num_configs)
793 6340 *out_num_configs = 0;
794 6340 return 0;
795 default:
796 return AVERROR(EINVAL);
797 }
798 }
799
800 57670 int avcodec_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec,
801 enum AVCodecConfig config, unsigned flags,
802 const void **out, int *out_num)
803 {
804 const FFCodec *codec2;
805 57670 int dummy_num = 0;
806
1/2
✓ Branch 0 taken 57670 times.
✗ Branch 1 not taken.
57670 if (!codec)
807 57670 codec = avctx->codec;
808
2/2
✓ Branch 0 taken 34219 times.
✓ Branch 1 taken 23451 times.
57670 if (!out_num)
809 34219 out_num = &dummy_num;
810
811 57670 codec2 = ffcodec(codec);
812
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 57510 times.
57670 if (codec2->get_supported_config) {
813 160 return codec2->get_supported_config(avctx, codec, config, flags, out, out_num);
814 } else {
815 57510 return ff_default_get_supported_config(avctx, codec, config, flags, out, out_num);
816 }
817 }
818