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 | 24670 | 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 1386798 times.
✓ Branch 1 taken 24670 times.
|
1411468 | for (i = 0; i < count; i++) { |
77 | 1386798 | size_t offset = i * size; | |
78 |
2/2✓ Branch 0 taken 1362128 times.
✓ Branch 1 taken 24670 times.
|
1386798 | int r = func(c, FF_PTR_ADD((char *)arg, offset)); |
79 |
2/2✓ Branch 0 taken 930 times.
✓ Branch 1 taken 1385868 times.
|
1386798 | if (ret) |
80 | 930 | ret[i] = r; | |
81 | } | ||
82 | 24670 | emms_c(); | |
83 | 24670 | return 0; | |
84 | } | ||
85 | |||
86 | 8760 | 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 244793 times.
✓ Branch 1 taken 8760 times.
|
253553 | for (i = 0; i < count; i++) { |
91 | 244793 | int r = func(c, arg, i, 0); | |
92 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 244743 times.
|
244793 | if (ret) |
93 | 50 | ret[i] = r; | |
94 | } | ||
95 | 8760 | emms_c(); | |
96 | 8760 | return 0; | |
97 | } | ||
98 | |||
99 | static AVMutex codec_mutex = AV_MUTEX_INITIALIZER; | ||
100 | |||
101 | 65171 | static void lock_avcodec(const FFCodec *codec) | |
102 | { | ||
103 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 65171 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
65171 | if (codec->caps_internal & FF_CODEC_CAP_NOT_INIT_THREADSAFE && codec->init) |
104 | ✗ | ff_mutex_lock(&codec_mutex); | |
105 | 65171 | } | |
106 | |||
107 | 65171 | static void unlock_avcodec(const FFCodec *codec) | |
108 | { | ||
109 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 65171 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
65171 | if (codec->caps_internal & FF_CODEC_CAP_NOT_INIT_THREADSAFE && codec->init) |
110 | ✗ | ff_mutex_unlock(&codec_mutex); | |
111 | 65171 | } | |
112 | |||
113 | 27783 | 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 22933 times.
✓ Branch 1 taken 4850 times.
✗ Branch 2 not taken.
|
27783 | switch (ctx->codec_type) { |
119 | 22933 | case AVMEDIA_TYPE_VIDEO: | |
120 | case AVMEDIA_TYPE_DATA: | ||
121 | case AVMEDIA_TYPE_SUBTITLE: | ||
122 | case AVMEDIA_TYPE_ATTACHMENT: | ||
123 | 22933 | bit_rate = ctx->bit_rate; | |
124 | 22933 | break; | |
125 | 4850 | case AVMEDIA_TYPE_AUDIO: | |
126 | 4850 | bits_per_sample = av_get_bits_per_sample(ctx->codec_id); | |
127 |
2/2✓ Branch 0 taken 2432 times.
✓ Branch 1 taken 2418 times.
|
4850 | 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 | 2418 | bit_rate = ctx->bit_rate; | |
135 | 4850 | break; | |
136 | ✗ | default: | |
137 | ✗ | bit_rate = 0; | |
138 | ✗ | break; | |
139 | } | ||
140 | 27783 | return bit_rate; | |
141 | } | ||
142 | |||
143 | 36625 | int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options) | |
144 | { | ||
145 | 36625 | 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 36625 times.
|
36625 | if (avcodec_is_open(avctx)) |
151 | ✗ | return 0; | |
152 | |||
153 |
3/4✓ Branch 0 taken 27 times.
✓ Branch 1 taken 36598 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
|
36625 | 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 36598 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 28309 times.
✓ Branch 3 taken 8289 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 28299 times.
|
36625 | 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 27 times.
✓ Branch 1 taken 36588 times.
|
36615 | if (!codec) |
163 | 27 | codec = avctx->codec; | |
164 | 36615 | codec2 = ffcodec(codec); | |
165 | |||
166 |
3/4✓ Branch 0 taken 36609 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 36609 times.
✗ Branch 3 not taken.
|
36615 | if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) || |
167 |
3/4✓ Branch 0 taken 36609 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36609 times.
|
36615 | (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 | 36615 | avctx->codec_type = codec->type; | |
173 | 36615 | avctx->codec_id = codec->id; | |
174 | 36615 | avctx->codec = codec; | |
175 | |||
176 |
2/4✓ Branch 0 taken 36615 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 36615 times.
|
36615 | 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 8600 times.
✓ Branch 1 taken 28015 times.
|
36615 | e = options ? av_dict_get(*options, "codec_whitelist", NULL, 0) : NULL; |
182 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36615 times.
|
36615 | 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 36615 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
36615 | 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 15445 times.
✓ Branch 2 taken 21170 times.
|
36615 | avci = ff_codec_is_decoder(codec) ? |
194 | 15445 | ff_decode_internal_alloc() : | |
195 | 21170 | ff_encode_internal_alloc(); | |
196 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36615 times.
|
36615 | if (!avci) { |
197 | ✗ | ret = AVERROR(ENOMEM); | |
198 | ✗ | goto end; | |
199 | } | ||
200 | 36615 | avctx->internal = avci; | |
201 | |||
202 | 36615 | avci->buffer_frame = av_frame_alloc(); | |
203 | 36615 | avci->buffer_pkt = av_packet_alloc(); | |
204 |
2/4✓ Branch 0 taken 36615 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 36615 times.
|
36615 | if (!avci->buffer_frame || !avci->buffer_pkt) { |
205 | ✗ | ret = AVERROR(ENOMEM); | |
206 | ✗ | goto free_and_end; | |
207 | } | ||
208 | |||
209 |
2/2✓ Branch 0 taken 16098 times.
✓ Branch 1 taken 20517 times.
|
36615 | if (codec2->priv_data_size > 0) { |
210 |
2/2✓ Branch 0 taken 8136 times.
✓ Branch 1 taken 7962 times.
|
16098 | if (!avctx->priv_data) { |
211 | 8136 | avctx->priv_data = av_mallocz(codec2->priv_data_size); | |
212 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8136 times.
|
8136 | if (!avctx->priv_data) { |
213 | ✗ | ret = AVERROR(ENOMEM); | |
214 | ✗ | goto free_and_end; | |
215 | } | ||
216 |
2/2✓ Branch 0 taken 2374 times.
✓ Branch 1 taken 5762 times.
|
8136 | if (codec->priv_class) { |
217 | 2374 | *(const AVClass **)avctx->priv_data = codec->priv_class; | |
218 | 2374 | av_opt_set_defaults(avctx->priv_data); | |
219 | } | ||
220 | } | ||
221 | } else { | ||
222 | 20517 | avctx->priv_data = NULL; | |
223 | } | ||
224 | |||
225 | 36615 | ret = av_opt_set_dict2(avctx, options, AV_OPT_SEARCH_CHILDREN); | |
226 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36615 times.
|
36615 | 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 32 times.
✓ Branch 1 taken 36583 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.
|
36615 | 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 32 times.
✓ Branch 1 taken 36583 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
|
36615 | if (avctx->coded_width && avctx->coded_height) |
233 | 32 | ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); | |
234 |
3/4✓ Branch 0 taken 27569 times.
✓ Branch 1 taken 9014 times.
✓ Branch 2 taken 27569 times.
✗ Branch 3 not taken.
|
36583 | else if (avctx->width && avctx->height) |
235 | 27569 | ret = ff_set_dimensions(avctx, avctx->width, avctx->height); | |
236 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36615 times.
|
36615 | if (ret < 0) |
237 | ✗ | goto free_and_end; | |
238 | } | ||
239 | |||
240 |
5/8✓ Branch 0 taken 9014 times.
✓ Branch 1 taken 27601 times.
✓ Branch 2 taken 9014 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9014 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9014 times.
|
36615 | if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height) |
241 |
1/2✓ Branch 1 taken 27601 times.
✗ Branch 2 not taken.
|
27601 | && ( 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 27601 times.
|
27601 | || 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 27601 times.
✓ Branch 1 taken 9014 times.
✓ Branch 2 taken 27601 times.
✗ Branch 3 not taken.
|
36615 | if (avctx->width > 0 && avctx->height > 0) { |
248 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 27601 times.
|
27601 | 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 36615 times.
|
36615 | 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 36615 times.
|
36615 | 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 4685 times.
✓ Branch 1 taken 31930 times.
✓ Branch 2 taken 238 times.
✓ Branch 3 taken 4447 times.
|
36615 | if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && !avctx->ch_layout.nb_channels |
271 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 238 times.
|
238 | && !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) { |
272 | ✗ | av_log(avctx, AV_LOG_ERROR, "%s requires channel layout to be set\n", | |
273 | ✗ | ff_codec_is_decoder(codec) ? "Decoder" : "Encoder"); | |
274 | ✗ | ret = AVERROR(EINVAL); | |
275 | ✗ | goto free_and_end; | |
276 | } | ||
277 |
3/4✓ Branch 0 taken 4447 times.
✓ Branch 1 taken 32168 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4447 times.
|
36615 | 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 36615 times.
|
36615 | 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 | 36615 | avctx->frame_num = 0; | |
289 | 36615 | avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id); | |
290 | |||
291 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36608 times.
|
36615 | 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 = ff_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 = ff_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 4685 times.
✓ Branch 1 taken 31930 times.
|
36615 | if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && |
308 |
3/4✓ Branch 0 taken 1330 times.
✓ Branch 1 taken 3355 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1330 times.
|
4685 | (!avctx->time_base.num || !avctx->time_base.den)) { |
309 | 3355 | avctx->time_base.num = 1; | |
310 | 3355 | avctx->time_base.den = avctx->sample_rate; | |
311 | } | ||
312 | |||
313 |
2/2✓ Branch 1 taken 21170 times.
✓ Branch 2 taken 15445 times.
|
36615 | if (ff_codec_is_encoder(avctx->codec)) |
314 | 21170 | ret = ff_encode_preinit(avctx); | |
315 | else | ||
316 | 15445 | ret = ff_decode_preinit(avctx); | |
317 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36615 times.
|
36615 | if (ret < 0) |
318 | ✗ | goto free_and_end; | |
319 | |||
320 |
2/2✓ Branch 0 taken 34972 times.
✓ Branch 1 taken 1643 times.
|
36615 | if (HAVE_THREADS && !avci->frame_thread_encoder) { |
321 | /* Frame-threaded decoders call FFCodec.init for their child contexts. */ | ||
322 | 34972 | lock_avcodec(codec2); | |
323 | 34972 | ret = ff_thread_init(avctx); | |
324 | 34972 | unlock_avcodec(codec2); | |
325 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 34972 times.
|
34972 | 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 1653 times.
✓ Branch 1 taken 34962 times.
|
36615 | if (!(avctx->active_thread_type & FF_THREAD_FRAME) || |
333 |
2/2✓ Branch 0 taken 1643 times.
✓ Branch 1 taken 10 times.
|
1653 | avci->frame_thread_encoder) { |
334 |
2/2✓ Branch 0 taken 30199 times.
✓ Branch 1 taken 6406 times.
|
36605 | if (codec2->init) { |
335 | 30199 | lock_avcodec(codec2); | |
336 | 30199 | ret = codec2->init(avctx); | |
337 | 30199 | unlock_avcodec(codec2); | |
338 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 30191 times.
|
30199 | 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 | 36597 | avci->needs_close = 1; | |
344 | } | ||
345 | |||
346 | 36607 | ret=0; | |
347 | |||
348 |
2/2✓ Branch 1 taken 15437 times.
✓ Branch 2 taken 21170 times.
|
36607 | if (ff_codec_is_decoder(avctx->codec)) { |
349 |
2/2✓ Branch 0 taken 10784 times.
✓ Branch 1 taken 4653 times.
|
15437 | if (!avctx->bit_rate) |
350 | 10784 | avctx->bit_rate = get_bit_rate(avctx); | |
351 | |||
352 | /* validate channel layout from the decoder */ | ||
353 |
3/4✓ Branch 0 taken 3157 times.
✓ Branch 1 taken 12280 times.
✓ Branch 3 taken 3157 times.
✗ Branch 4 not taken.
|
15437 | if ((avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) || |
354 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15437 times.
|
15437 | 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 15437 times.
|
15437 | if (avctx->bits_per_coded_sample < 0) { |
359 | ✗ | ret = AVERROR(EINVAL); | |
360 | ✗ | goto free_and_end; | |
361 | } | ||
362 | } | ||
363 |
2/2✓ Branch 0 taken 5122 times.
✓ Branch 1 taken 31485 times.
|
36607 | if (codec->priv_class) |
364 |
1/2✓ Branch 0 taken 5122 times.
✗ Branch 1 not taken.
|
5122 | av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class); |
365 | |||
366 | 36607 | end: | |
367 | |||
368 | 36615 | return ret; | |
369 | 8 | free_and_end: | |
370 | 8 | ff_codec_close(avctx); | |
371 | 8 | goto end; | |
372 | } | ||
373 | |||
374 | 104 | void avcodec_flush_buffers(AVCodecContext *avctx) | |
375 | { | ||
376 | 104 | AVCodecInternal *avci = avctx->internal; | |
377 | |||
378 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 104 times.
|
104 | 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 | 104 | ff_decode_flush_buffers(avctx); | |
391 | |||
392 | 104 | avci->draining = 0; | |
393 | 104 | avci->draining_done = 0; | |
394 |
1/2✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
|
104 | if (avci->buffer_frame) |
395 | 104 | av_frame_unref(avci->buffer_frame); | |
396 |
1/2✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
|
104 | if (avci->buffer_pkt) |
397 | 104 | av_packet_unref(avci->buffer_pkt); | |
398 | |||
399 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
|
104 | 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 31 times.
✓ Branch 2 taken 73 times.
|
104 | else if (ffcodec(avctx->codec)->flush) |
403 | 31 | 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 | 62691 | av_cold void ff_codec_close(AVCodecContext *avctx) | |
429 | { | ||
430 | int i; | ||
431 | |||
432 |
2/2✓ Branch 1 taken 36615 times.
✓ Branch 2 taken 26076 times.
|
62691 | if (avcodec_is_open(avctx)) { |
433 | 36615 | AVCodecInternal *avci = avctx->internal; | |
434 | |||
435 | 36615 | if (CONFIG_FRAME_THREAD_ENCODER && | |
436 |
4/4✓ Branch 0 taken 14775 times.
✓ Branch 1 taken 21840 times.
✓ Branch 2 taken 1643 times.
✓ Branch 3 taken 13132 times.
|
36615 | avci->frame_thread_encoder && avctx->thread_count > 1) { |
437 | 1643 | ff_frame_thread_encoder_free(avctx); | |
438 | } | ||
439 |
2/2✓ Branch 0 taken 35 times.
✓ Branch 1 taken 36580 times.
|
36615 | if (HAVE_THREADS && avci->thread_ctx) |
440 | 35 | ff_thread_free(avctx); | |
441 |
4/4✓ Branch 0 taken 36597 times.
✓ Branch 1 taken 18 times.
✓ Branch 3 taken 7379 times.
✓ Branch 4 taken 29218 times.
|
36615 | if (avci->needs_close && ffcodec(avctx->codec)->close) |
442 | 7379 | ffcodec(avctx->codec)->close(avctx); | |
443 | 36615 | avci->byte_buffer_size = 0; | |
444 | 36615 | av_freep(&avci->byte_buffer); | |
445 | 36615 | av_frame_free(&avci->buffer_frame); | |
446 | 36615 | av_packet_free(&avci->buffer_pkt); | |
447 | 36615 | av_packet_free(&avci->last_pkt_props); | |
448 | |||
449 | 36615 | av_packet_free(&avci->in_pkt); | |
450 | 36615 | av_frame_free(&avci->in_frame); | |
451 | 36615 | av_frame_free(&avci->recon_frame); | |
452 | |||
453 | 36615 | av_refstruct_unref(&avci->pool); | |
454 | 36615 | av_refstruct_pool_uninit(&avci->progress_frame_pool); | |
455 |
2/2✓ Branch 1 taken 15445 times.
✓ Branch 2 taken 21170 times.
|
36615 | if (av_codec_is_decoder(avctx->codec)) |
456 | 15445 | ff_decode_internal_uninit(avctx); | |
457 | |||
458 | 36615 | ff_hwaccel_uninit(avctx); | |
459 | |||
460 | 36615 | av_bsf_free(&avci->bsf); | |
461 | |||
462 | #if CONFIG_LCMS2 | ||
463 | ff_icc_context_uninit(&avci->icc); | ||
464 | #endif | ||
465 | |||
466 | 36615 | av_freep(&avctx->internal); | |
467 | } | ||
468 | |||
469 |
2/2✓ Branch 0 taken 4227 times.
✓ Branch 1 taken 62691 times.
|
66918 | for (i = 0; i < avctx->nb_coded_side_data; i++) |
470 | 4227 | av_freep(&avctx->coded_side_data[i].data); | |
471 | 62691 | av_freep(&avctx->coded_side_data); | |
472 | 62691 | avctx->nb_coded_side_data = 0; | |
473 | 62691 | av_frame_side_data_free(&avctx->decoded_side_data, | |
474 | &avctx->nb_decoded_side_data); | ||
475 | |||
476 | 62691 | av_buffer_unref(&avctx->hw_frames_ctx); | |
477 | 62691 | av_buffer_unref(&avctx->hw_device_ctx); | |
478 | |||
479 |
5/6✓ Branch 0 taken 24226 times.
✓ Branch 1 taken 38465 times.
✓ Branch 2 taken 24226 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7496 times.
✓ Branch 5 taken 16730 times.
|
62691 | if (avctx->priv_data && avctx->codec && avctx->codec->priv_class) |
480 | 7496 | av_opt_free(avctx->priv_data); | |
481 | 62691 | av_opt_free(avctx); | |
482 | 62691 | av_freep(&avctx->priv_data); | |
483 |
2/2✓ Branch 1 taken 21170 times.
✓ Branch 2 taken 41521 times.
|
62691 | if (av_codec_is_encoder(avctx->codec)) { |
484 | 21170 | av_freep(&avctx->extradata); | |
485 | 21170 | avctx->extradata_size = 0; | |
486 |
2/2✓ Branch 1 taken 31823 times.
✓ Branch 2 taken 9698 times.
|
41521 | } else if (av_codec_is_decoder(avctx->codec)) |
487 | 31823 | av_freep(&avctx->subtitle_header); | |
488 | |||
489 | 62691 | avctx->codec = NULL; | |
490 | 62691 | avctx->active_thread_type = 0; | |
491 | 62691 | } | |
492 | |||
493 | 21677 | static const char *unknown_if_null(const char *str) | |
494 | { | ||
495 |
1/2✓ Branch 0 taken 21677 times.
✗ Branch 1 not taken.
|
21677 | return str ? str : "unknown"; |
496 | } | ||
497 | |||
498 | 17008 | void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) | |
499 | { | ||
500 | const char *codec_type; | ||
501 | const char *codec_name; | ||
502 | 17008 | const char *profile = NULL; | |
503 | AVBPrint bprint; | ||
504 | int64_t bitrate; | ||
505 | 17008 | int new_line = 0; | |
506 | AVRational display_aspect_ratio; | ||
507 |
2/2✓ Branch 0 taken 16972 times.
✓ Branch 1 taken 36 times.
|
17008 | const char *separator = enc->dump_separator ? (const char *)enc->dump_separator : ", "; |
508 | const char *str; | ||
509 | |||
510 |
2/4✓ Branch 0 taken 17008 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17008 times.
|
17008 | if (!buf || buf_size <= 0) |
511 | 9 | return; | |
512 | 17008 | av_bprint_init_for_buffer(&bprint, buf, buf_size); | |
513 | 17008 | codec_type = av_get_media_type_string(enc->codec_type); | |
514 | 17008 | codec_name = avcodec_get_name(enc->codec_id); | |
515 | 17008 | profile = avcodec_profile_name(enc->codec_id, enc->profile); | |
516 | |||
517 |
1/2✓ Branch 0 taken 17008 times.
✗ Branch 1 not taken.
|
17008 | av_bprintf(&bprint, "%s: %s", codec_type ? codec_type : "unknown", |
518 | codec_name); | ||
519 | 17008 | buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */ | |
520 | |||
521 |
4/4✓ Branch 0 taken 8128 times.
✓ Branch 1 taken 8880 times.
✓ Branch 2 taken 309 times.
✓ Branch 3 taken 7819 times.
|
17008 | if (enc->codec && strcmp(enc->codec->name, codec_name)) |
522 | 309 | av_bprintf(&bprint, " (%s)", enc->codec->name); | |
523 | |||
524 |
2/2✓ Branch 0 taken 1986 times.
✓ Branch 1 taken 15022 times.
|
17008 | if (profile) |
525 | 1986 | av_bprintf(&bprint, " (%s)", profile); | |
526 |
2/2✓ Branch 0 taken 13115 times.
✓ Branch 1 taken 3893 times.
|
17008 | if ( enc->codec_type == AVMEDIA_TYPE_VIDEO |
527 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13115 times.
|
13115 | && av_log_get_level() >= AV_LOG_VERBOSE |
528 | ✗ | && enc->refs) | |
529 | ✗ | av_bprintf(&bprint, ", %d reference frame%s", | |
530 | ✗ | enc->refs, enc->refs > 1 ? "s" : ""); | |
531 | |||
532 |
2/2✓ Branch 0 taken 9632 times.
✓ Branch 1 taken 7376 times.
|
17008 | if (enc->codec_tag) |
533 | 9632 | av_bprintf(&bprint, " (%s / 0x%04X)", | |
534 | 9632 | av_fourcc2str(enc->codec_tag), enc->codec_tag); | |
535 | |||
536 |
5/5✓ Branch 0 taken 13115 times.
✓ Branch 1 taken 3638 times.
✓ Branch 2 taken 86 times.
✓ Branch 3 taken 160 times.
✓ Branch 4 taken 9 times.
|
17008 | switch (enc->codec_type) { |
537 | 13115 | case AVMEDIA_TYPE_VIDEO: | |
538 | { | ||
539 | unsigned len; | ||
540 | |||
541 | 13115 | av_bprintf(&bprint, "%s%s", separator, | |
542 |
2/2✓ Branch 0 taken 13067 times.
✓ Branch 1 taken 48 times.
|
13115 | enc->pix_fmt == AV_PIX_FMT_NONE ? "none" : |
543 | 13067 | unknown_if_null(av_get_pix_fmt_name(enc->pix_fmt))); | |
544 | |||
545 | 13115 | av_bprint_chars(&bprint, '(', 1); | |
546 | 13115 | len = bprint.len; | |
547 | |||
548 | /* The following check ensures that '(' has been written | ||
549 | * and therefore allows us to erase it if it turns out | ||
550 | * to be unnecessary. */ | ||
551 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13115 times.
|
13115 | if (!av_bprint_is_complete(&bprint)) |
552 | ✗ | return; | |
553 | |||
554 |
3/4✓ Branch 0 taken 1184 times.
✓ Branch 1 taken 11931 times.
✓ Branch 2 taken 1184 times.
✗ Branch 3 not taken.
|
13115 | if (enc->bits_per_raw_sample && enc->pix_fmt != AV_PIX_FMT_NONE && |
555 |
2/2✓ Branch 1 taken 27 times.
✓ Branch 2 taken 1157 times.
|
1184 | enc->bits_per_raw_sample < av_pix_fmt_desc_get(enc->pix_fmt)->comp[0].depth) |
556 | 27 | av_bprintf(&bprint, "%d bpc, ", enc->bits_per_raw_sample); | |
557 |
3/4✓ Branch 0 taken 10781 times.
✓ Branch 1 taken 2334 times.
✓ Branch 2 taken 10781 times.
✗ Branch 3 not taken.
|
23896 | if (enc->color_range != AVCOL_RANGE_UNSPECIFIED && |
558 | 10781 | (str = av_color_range_name(enc->color_range))) | |
559 | 10781 | av_bprintf(&bprint, "%s, ", str); | |
560 | |||
561 |
2/2✓ Branch 0 taken 10363 times.
✓ Branch 1 taken 2752 times.
|
13115 | if (enc->colorspace != AVCOL_SPC_UNSPECIFIED || |
562 |
2/2✓ Branch 0 taken 10361 times.
✓ Branch 1 taken 2 times.
|
10363 | enc->color_primaries != AVCOL_PRI_UNSPECIFIED || |
563 |
2/2✓ Branch 0 taken 116 times.
✓ Branch 1 taken 10245 times.
|
10361 | enc->color_trc != AVCOL_TRC_UNSPECIFIED) { |
564 | 2870 | const char *col = unknown_if_null(av_color_space_name(enc->colorspace)); | |
565 | 2870 | const char *pri = unknown_if_null(av_color_primaries_name(enc->color_primaries)); | |
566 | 2870 | const char *trc = unknown_if_null(av_color_transfer_name(enc->color_trc)); | |
567 |
4/4✓ Branch 0 taken 285 times.
✓ Branch 1 taken 2585 times.
✓ Branch 2 taken 130 times.
✓ Branch 3 taken 155 times.
|
2870 | if (strcmp(col, pri) || strcmp(col, trc)) { |
568 | 2715 | new_line = 1; | |
569 | 2715 | av_bprintf(&bprint, "%s/%s/%s, ", col, pri, trc); | |
570 | } else | ||
571 | 155 | av_bprintf(&bprint, "%s, ", col); | |
572 | } | ||
573 | |||
574 |
2/2✓ Branch 0 taken 7361 times.
✓ Branch 1 taken 5754 times.
|
13115 | if (enc->field_order != AV_FIELD_UNKNOWN) { |
575 | 7361 | const char *field_order = "progressive"; | |
576 |
2/2✓ Branch 0 taken 142 times.
✓ Branch 1 taken 7219 times.
|
7361 | if (enc->field_order == AV_FIELD_TT) |
577 | 142 | field_order = "top first"; | |
578 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 7171 times.
|
7219 | else if (enc->field_order == AV_FIELD_BB) |
579 | 48 | field_order = "bottom first"; | |
580 |
2/2✓ Branch 0 taken 354 times.
✓ Branch 1 taken 6817 times.
|
7171 | else if (enc->field_order == AV_FIELD_TB) |
581 | 354 | field_order = "top coded first (swapped)"; | |
582 |
2/2✓ Branch 0 taken 126 times.
✓ Branch 1 taken 6691 times.
|
6817 | else if (enc->field_order == AV_FIELD_BT) |
583 | 126 | field_order = "bottom coded first (swapped)"; | |
584 | |||
585 | 7361 | av_bprintf(&bprint, "%s, ", field_order); | |
586 | } | ||
587 | |||
588 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13115 times.
|
13115 | if (av_log_get_level() >= AV_LOG_VERBOSE && |
589 | ✗ | enc->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED && | |
590 | ✗ | (str = av_chroma_location_name(enc->chroma_sample_location))) | |
591 | ✗ | av_bprintf(&bprint, "%s, ", str); | |
592 | |||
593 |
2/2✓ Branch 0 taken 1070 times.
✓ Branch 1 taken 12045 times.
|
13115 | if (len == bprint.len) { |
594 | 1070 | bprint.str[len - 1] = '\0'; | |
595 | 1070 | bprint.len--; | |
596 | } else { | ||
597 |
1/2✓ Branch 0 taken 12045 times.
✗ Branch 1 not taken.
|
12045 | if (bprint.len - 2 < bprint.size) { |
598 | /* Erase the last ", " */ | ||
599 | 12045 | bprint.len -= 2; | |
600 | 12045 | bprint.str[bprint.len] = '\0'; | |
601 | } | ||
602 | 12045 | av_bprint_chars(&bprint, ')', 1); | |
603 | } | ||
604 | } | ||
605 | |||
606 |
2/2✓ Branch 0 taken 13095 times.
✓ Branch 1 taken 20 times.
|
13115 | if (enc->width) { |
607 |
2/2✓ Branch 0 taken 2713 times.
✓ Branch 1 taken 10382 times.
|
13095 | av_bprintf(&bprint, "%s%dx%d", new_line ? separator : ", ", |
608 | enc->width, enc->height); | ||
609 | |||
610 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13095 times.
|
13095 | if (av_log_get_level() >= AV_LOG_VERBOSE && |
611 | ✗ | enc->coded_width && enc->coded_height && | |
612 | ✗ | (enc->width != enc->coded_width || | |
613 | ✗ | enc->height != enc->coded_height)) | |
614 | ✗ | av_bprintf(&bprint, " (%dx%d)", | |
615 | enc->coded_width, enc->coded_height); | ||
616 | |||
617 |
2/2✓ Branch 0 taken 2477 times.
✓ Branch 1 taken 10618 times.
|
13095 | if (enc->sample_aspect_ratio.num) { |
618 | 2477 | av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, | |
619 | 2477 | enc->width * (int64_t)enc->sample_aspect_ratio.num, | |
620 | 2477 | enc->height * (int64_t)enc->sample_aspect_ratio.den, | |
621 | 1024 * 1024); | ||
622 | 2477 | av_bprintf(&bprint, " [SAR %d:%d DAR %d:%d]", | |
623 | enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den, | ||
624 | display_aspect_ratio.num, display_aspect_ratio.den); | ||
625 | } | ||
626 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13095 times.
|
13095 | if (av_log_get_level() >= AV_LOG_DEBUG) { |
627 | ✗ | int g = av_gcd(enc->time_base.num, enc->time_base.den); | |
628 | ✗ | av_bprintf(&bprint, ", %d/%d", | |
629 | ✗ | enc->time_base.num / g, enc->time_base.den / g); | |
630 | } | ||
631 | } | ||
632 |
2/2✓ Branch 0 taken 7010 times.
✓ Branch 1 taken 6105 times.
|
13115 | if (encode) { |
633 | 7010 | av_bprintf(&bprint, ", q=%d-%d", enc->qmin, enc->qmax); | |
634 | } else { | ||
635 | #if FF_API_CODEC_PROPS | ||
636 | FF_DISABLE_DEPRECATION_WARNINGS | ||
637 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6105 times.
|
6105 | if (enc->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS) |
638 | ✗ | av_bprintf(&bprint, ", Closed Captions"); | |
639 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6105 times.
|
6105 | if (enc->properties & FF_CODEC_PROPERTY_FILM_GRAIN) |
640 | ✗ | av_bprintf(&bprint, ", Film Grain"); | |
641 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6105 times.
|
6105 | if (enc->properties & FF_CODEC_PROPERTY_LOSSLESS) |
642 | ✗ | av_bprintf(&bprint, ", lossless"); | |
643 | FF_ENABLE_DEPRECATION_WARNINGS | ||
644 | #endif | ||
645 | } | ||
646 | 13115 | break; | |
647 | 3638 | case AVMEDIA_TYPE_AUDIO: | |
648 | 3638 | av_bprintf(&bprint, "%s", separator); | |
649 | |||
650 |
2/2✓ Branch 0 taken 3622 times.
✓ Branch 1 taken 16 times.
|
3638 | if (enc->sample_rate) { |
651 | 3622 | av_bprintf(&bprint, "%d Hz, ", enc->sample_rate); | |
652 | } | ||
653 | 3638 | av_channel_layout_describe_bprint(&enc->ch_layout, &bprint); | |
654 |
3/4✓ Branch 0 taken 3618 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 3618 times.
✗ Branch 3 not taken.
|
7256 | if (enc->sample_fmt != AV_SAMPLE_FMT_NONE && |
655 | 3618 | (str = av_get_sample_fmt_name(enc->sample_fmt))) { | |
656 | 3618 | av_bprintf(&bprint, ", %s", str); | |
657 | } | ||
658 |
2/2✓ Branch 0 taken 1933 times.
✓ Branch 1 taken 1705 times.
|
3638 | if ( enc->bits_per_raw_sample > 0 |
659 |
2/2✓ Branch 1 taken 218 times.
✓ Branch 2 taken 1715 times.
|
1933 | && enc->bits_per_raw_sample != av_get_bytes_per_sample(enc->sample_fmt) * 8) |
660 | 218 | av_bprintf(&bprint, " (%d bit)", enc->bits_per_raw_sample); | |
661 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3634 times.
|
3638 | if (av_log_get_level() >= AV_LOG_VERBOSE) { |
662 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (enc->initial_padding) |
663 | 2 | av_bprintf(&bprint, ", delay %d", enc->initial_padding); | |
664 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (enc->trailing_padding) |
665 | ✗ | av_bprintf(&bprint, ", padding %d", enc->trailing_padding); | |
666 | } | ||
667 | 3638 | break; | |
668 | 86 | case AVMEDIA_TYPE_DATA: | |
669 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 86 times.
|
86 | if (av_log_get_level() >= AV_LOG_DEBUG) { |
670 | ✗ | int g = av_gcd(enc->time_base.num, enc->time_base.den); | |
671 | ✗ | if (g) | |
672 | ✗ | av_bprintf(&bprint, ", %d/%d", | |
673 | ✗ | enc->time_base.num / g, enc->time_base.den / g); | |
674 | } | ||
675 | 86 | break; | |
676 | 160 | case AVMEDIA_TYPE_SUBTITLE: | |
677 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 127 times.
|
160 | if (enc->width) |
678 | 33 | av_bprintf(&bprint, ", %dx%d", enc->width, enc->height); | |
679 | 160 | break; | |
680 | 9 | default: | |
681 | 9 | return; | |
682 | } | ||
683 |
2/2✓ Branch 0 taken 8769 times.
✓ Branch 1 taken 8230 times.
|
16999 | if (encode) { |
684 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8769 times.
|
8769 | if (enc->flags & AV_CODEC_FLAG_PASS1) |
685 | ✗ | av_bprintf(&bprint, ", pass 1"); | |
686 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8769 times.
|
8769 | if (enc->flags & AV_CODEC_FLAG_PASS2) |
687 | ✗ | av_bprintf(&bprint, ", pass 2"); | |
688 | } | ||
689 | 16999 | bitrate = get_bit_rate(enc); | |
690 |
2/2✓ Branch 0 taken 11032 times.
✓ Branch 1 taken 5967 times.
|
16999 | if (bitrate != 0) { |
691 | 11032 | av_bprintf(&bprint, ", %"PRId64" kb/s", bitrate / 1000); | |
692 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5967 times.
|
5967 | } else if (enc->rc_max_rate > 0) { |
693 | ✗ | av_bprintf(&bprint, ", max. %"PRId64" kb/s", enc->rc_max_rate / 1000); | |
694 | } | ||
695 | } | ||
696 | |||
697 | 2827549 | int avcodec_is_open(AVCodecContext *s) | |
698 | { | ||
699 | 2827549 | return !!s->internal; | |
700 | } | ||
701 | |||
702 | 784222 | int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame) | |
703 | { | ||
704 | 784222 | av_frame_unref(frame); | |
705 | |||
706 |
2/4✓ Branch 1 taken 784222 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 784222 times.
|
784222 | if (!avcodec_is_open(avctx) || !avctx->codec) |
707 | ✗ | return AVERROR(EINVAL); | |
708 | |||
709 |
2/2✓ Branch 1 taken 784162 times.
✓ Branch 2 taken 60 times.
|
784222 | if (ff_codec_is_decoder(avctx->codec)) |
710 | 784162 | return ff_decode_receive_frame(avctx, frame); | |
711 | 60 | return ff_encode_receive_frame(avctx, frame); | |
712 | } | ||
713 | |||
714 | #define WRAP_CONFIG(allowed_type, field, field_type, terminator) \ | ||
715 | do { \ | ||
716 | static const field_type end = terminator; \ | ||
717 | if (codec->type != (allowed_type)) \ | ||
718 | return AVERROR(EINVAL); \ | ||
719 | *out_configs = (field); \ | ||
720 | if (out_num_configs) { \ | ||
721 | for (int i = 0;; i++) { \ | ||
722 | if (!(field) || !memcmp(&(field)[i], &end, sizeof(end))) { \ | ||
723 | *out_num_configs = i; \ | ||
724 | break; \ | ||
725 | } \ | ||
726 | } \ | ||
727 | } \ | ||
728 | return 0; \ | ||
729 | } while (0) | ||
730 | |||
731 | static const enum AVColorRange color_range_jpeg[] = { | ||
732 | AVCOL_RANGE_JPEG, AVCOL_RANGE_UNSPECIFIED | ||
733 | }; | ||
734 | |||
735 | static const enum AVColorRange color_range_mpeg[] = { | ||
736 | AVCOL_RANGE_MPEG, AVCOL_RANGE_UNSPECIFIED | ||
737 | }; | ||
738 | |||
739 | static const enum AVColorRange color_range_all[] = { | ||
740 | AVCOL_RANGE_MPEG, AVCOL_RANGE_JPEG, AVCOL_RANGE_UNSPECIFIED | ||
741 | }; | ||
742 | |||
743 | static const enum AVColorRange *color_range_table[] = { | ||
744 | [AVCOL_RANGE_MPEG] = color_range_mpeg, | ||
745 | [AVCOL_RANGE_JPEG] = color_range_jpeg, | ||
746 | [AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG] = color_range_all, | ||
747 | }; | ||
748 | |||
749 | 59571 | int ff_default_get_supported_config(const AVCodecContext *avctx, | |
750 | const AVCodec *codec, | ||
751 | enum AVCodecConfig config, | ||
752 | unsigned flags, | ||
753 | const void **out_configs, | ||
754 | int *out_num_configs) | ||
755 | { | ||
756 |
7/8✓ Branch 0 taken 31615 times.
✓ Branch 1 taken 6651 times.
✓ Branch 2 taken 2676 times.
✓ Branch 3 taken 2676 times.
✓ Branch 4 taken 2676 times.
✓ Branch 5 taken 6625 times.
✓ Branch 6 taken 6652 times.
✗ Branch 7 not taken.
|
59571 | switch (config) { |
757 | FF_DISABLE_DEPRECATION_WARNINGS | ||
758 | 31615 | case AV_CODEC_CONFIG_PIX_FORMAT: | |
759 |
6/8✗ Branch 0 not taken.
✓ Branch 1 taken 31615 times.
✓ Branch 2 taken 31615 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21581 times.
✓ Branch 5 taken 29826 times.
✓ Branch 6 taken 1789 times.
✓ Branch 7 taken 19792 times.
|
51407 | WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->pix_fmts, enum AVPixelFormat, AV_PIX_FMT_NONE); |
760 | 6651 | case AV_CODEC_CONFIG_FRAME_RATE: | |
761 |
6/8✗ Branch 0 not taken.
✓ Branch 1 taken 6651 times.
✓ Branch 2 taken 6651 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2863 times.
✓ Branch 5 taken 6597 times.
✓ Branch 6 taken 54 times.
✓ Branch 7 taken 2809 times.
|
9460 | WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->supported_framerates, AVRational, {0}); |
762 | 2676 | case AV_CODEC_CONFIG_SAMPLE_RATE: | |
763 |
6/8✗ Branch 0 not taken.
✓ Branch 1 taken 2676 times.
✓ Branch 2 taken 2676 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 832 times.
✓ Branch 5 taken 2556 times.
✓ Branch 6 taken 120 times.
✓ Branch 7 taken 712 times.
|
3388 | WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->supported_samplerates, int, 0); |
764 | 2676 | case AV_CODEC_CONFIG_SAMPLE_FORMAT: | |
765 |
5/8✗ Branch 0 not taken.
✓ Branch 1 taken 2676 times.
✓ Branch 2 taken 2676 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5572 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2676 times.
✓ Branch 7 taken 2896 times.
|
5572 | WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->sample_fmts, enum AVSampleFormat, AV_SAMPLE_FMT_NONE); |
766 | 2676 | case AV_CODEC_CONFIG_CHANNEL_LAYOUT: | |
767 |
6/8✗ Branch 0 not taken.
✓ Branch 1 taken 2676 times.
✓ Branch 2 taken 2676 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 896 times.
✓ Branch 5 taken 2520 times.
✓ Branch 6 taken 156 times.
✓ Branch 7 taken 740 times.
|
3416 | WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->ch_layouts, AVChannelLayout, {0}); |
768 | FF_ENABLE_DEPRECATION_WARNINGS | ||
769 | |||
770 | 6625 | case AV_CODEC_CONFIG_COLOR_RANGE: | |
771 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6625 times.
|
6625 | if (codec->type != AVMEDIA_TYPE_VIDEO) |
772 | ✗ | return AVERROR(EINVAL); | |
773 | 6625 | *out_configs = color_range_table[ffcodec(codec)->color_ranges]; | |
774 |
1/2✓ Branch 0 taken 6625 times.
✗ Branch 1 not taken.
|
6625 | if (out_num_configs) |
775 | 6625 | *out_num_configs = av_popcount(ffcodec(codec)->color_ranges); | |
776 | 6625 | return 0; | |
777 | |||
778 | 6652 | case AV_CODEC_CONFIG_COLOR_SPACE: | |
779 | 6652 | *out_configs = NULL; | |
780 |
1/2✓ Branch 0 taken 6652 times.
✗ Branch 1 not taken.
|
6652 | if (out_num_configs) |
781 | 6652 | *out_num_configs = 0; | |
782 | 6652 | return 0; | |
783 | ✗ | default: | |
784 | ✗ | return AVERROR(EINVAL); | |
785 | } | ||
786 | } | ||
787 | |||
788 | 59598 | int avcodec_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec, | |
789 | enum AVCodecConfig config, unsigned flags, | ||
790 | const void **out, int *out_num) | ||
791 | { | ||
792 | const FFCodec *codec2; | ||
793 | 59598 | int dummy_num = 0; | |
794 |
1/2✓ Branch 0 taken 59598 times.
✗ Branch 1 not taken.
|
59598 | if (!codec) |
795 | 59598 | codec = avctx->codec; | |
796 |
2/2✓ Branch 0 taken 35774 times.
✓ Branch 1 taken 23824 times.
|
59598 | if (!out_num) |
797 | 35774 | out_num = &dummy_num; | |
798 | |||
799 | 59598 | codec2 = ffcodec(codec); | |
800 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 59438 times.
|
59598 | if (codec2->get_supported_config) { |
801 | 160 | return codec2->get_supported_config(avctx, codec, config, flags, out, out_num); | |
802 | } else { | ||
803 | 59438 | return ff_default_get_supported_config(avctx, codec, config, flags, out, out_num); | |
804 | } | ||
805 | } | ||
806 |