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_EXIF, AV_FRAME_DATA_EXIF }, | ||
70 | { AV_PKT_DATA_NB }, | ||
71 | }; | ||
72 | |||
73 | |||
74 | 27045 | int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size) | |
75 | { | ||
76 | size_t i; | ||
77 | |||
78 |
2/2✓ Branch 0 taken 1389242 times.
✓ Branch 1 taken 27045 times.
|
1416287 | for (i = 0; i < count; i++) { |
79 | 1389242 | size_t offset = i * size; | |
80 |
2/2✓ Branch 0 taken 1362197 times.
✓ Branch 1 taken 27045 times.
|
1389242 | int r = func(c, FF_PTR_ADD((char *)arg, offset)); |
81 |
2/2✓ Branch 0 taken 930 times.
✓ Branch 1 taken 1388312 times.
|
1389242 | if (ret) |
82 | 930 | ret[i] = r; | |
83 | } | ||
84 | 27045 | emms_c(); | |
85 | 27045 | return 0; | |
86 | } | ||
87 | |||
88 | 8769 | int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count) | |
89 | { | ||
90 | int i; | ||
91 | |||
92 |
2/2✓ Branch 0 taken 248892 times.
✓ Branch 1 taken 8769 times.
|
257661 | for (i = 0; i < count; i++) { |
93 | 248892 | int r = func(c, arg, i, 0); | |
94 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 248842 times.
|
248892 | if (ret) |
95 | 50 | ret[i] = r; | |
96 | } | ||
97 | 8769 | emms_c(); | |
98 | 8769 | return 0; | |
99 | } | ||
100 | |||
101 | static AVMutex codec_mutex = AV_MUTEX_INITIALIZER; | ||
102 | |||
103 | 66149 | static void lock_avcodec(const FFCodec *codec) | |
104 | { | ||
105 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 66149 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
66149 | if (codec->caps_internal & FF_CODEC_CAP_NOT_INIT_THREADSAFE && codec->init) |
106 | ✗ | ff_mutex_lock(&codec_mutex); | |
107 | 66149 | } | |
108 | |||
109 | 66149 | static void unlock_avcodec(const FFCodec *codec) | |
110 | { | ||
111 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 66149 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
66149 | if (codec->caps_internal & FF_CODEC_CAP_NOT_INIT_THREADSAFE && codec->init) |
112 | ✗ | ff_mutex_unlock(&codec_mutex); | |
113 | 66149 | } | |
114 | |||
115 | 28420 | static int64_t get_bit_rate(AVCodecContext *ctx) | |
116 | { | ||
117 | int64_t bit_rate; | ||
118 | int bits_per_sample; | ||
119 | |||
120 |
2/3✓ Branch 0 taken 23547 times.
✓ Branch 1 taken 4873 times.
✗ Branch 2 not taken.
|
28420 | switch (ctx->codec_type) { |
121 | 23547 | case AVMEDIA_TYPE_VIDEO: | |
122 | case AVMEDIA_TYPE_DATA: | ||
123 | case AVMEDIA_TYPE_SUBTITLE: | ||
124 | case AVMEDIA_TYPE_ATTACHMENT: | ||
125 | 23547 | bit_rate = ctx->bit_rate; | |
126 | 23547 | break; | |
127 | 4873 | case AVMEDIA_TYPE_AUDIO: | |
128 | 4873 | bits_per_sample = av_get_bits_per_sample(ctx->codec_id); | |
129 |
2/2✓ Branch 0 taken 2452 times.
✓ Branch 1 taken 2421 times.
|
4873 | if (bits_per_sample) { |
130 | 2452 | bit_rate = ctx->sample_rate * (int64_t)ctx->ch_layout.nb_channels; | |
131 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2452 times.
|
2452 | if (bit_rate > INT64_MAX / bits_per_sample) { |
132 | ✗ | bit_rate = 0; | |
133 | } else | ||
134 | 2452 | bit_rate *= bits_per_sample; | |
135 | } else | ||
136 | 2421 | bit_rate = ctx->bit_rate; | |
137 | 4873 | break; | |
138 | ✗ | default: | |
139 | ✗ | bit_rate = 0; | |
140 | ✗ | break; | |
141 | } | ||
142 | 28420 | return bit_rate; | |
143 | } | ||
144 | |||
145 | 37210 | int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options) | |
146 | { | ||
147 | 37210 | int ret = 0; | |
148 | AVCodecInternal *avci; | ||
149 | const FFCodec *codec2; | ||
150 | const AVDictionaryEntry *e; | ||
151 | |||
152 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 37210 times.
|
37210 | if (avcodec_is_open(avctx)) |
153 | ✗ | return 0; | |
154 | |||
155 |
3/4✓ Branch 0 taken 35 times.
✓ Branch 1 taken 37175 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 35 times.
|
37210 | if (!codec && !avctx->codec) { |
156 | ✗ | av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n"); | |
157 | ✗ | return AVERROR(EINVAL); | |
158 | } | ||
159 |
5/6✓ Branch 0 taken 37175 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 28710 times.
✓ Branch 3 taken 8465 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 28710 times.
|
37210 | if (codec && avctx->codec && codec != avctx->codec) { |
160 | ✗ | av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, " | |
161 | ✗ | "but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name); | |
162 | ✗ | return AVERROR(EINVAL); | |
163 | } | ||
164 |
2/2✓ Branch 0 taken 35 times.
✓ Branch 1 taken 37175 times.
|
37210 | if (!codec) |
165 | 35 | codec = avctx->codec; | |
166 | 37210 | codec2 = ffcodec(codec); | |
167 | |||
168 |
3/4✓ Branch 0 taken 37204 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 37204 times.
✗ Branch 3 not taken.
|
37210 | if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) || |
169 |
3/4✓ Branch 0 taken 37204 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 37204 times.
|
37210 | (avctx->codec_id != AV_CODEC_ID_NONE && avctx->codec_id != codec->id)) { |
170 | ✗ | av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n"); | |
171 | ✗ | return AVERROR(EINVAL); | |
172 | } | ||
173 | |||
174 | 37210 | avctx->codec_type = codec->type; | |
175 | 37210 | avctx->codec_id = codec->id; | |
176 | 37210 | avctx->codec = codec; | |
177 | |||
178 |
2/4✓ Branch 0 taken 37210 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37210 times.
|
37210 | if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) |
179 | ✗ | return AVERROR(EINVAL); | |
180 | |||
181 | // set the whitelist from provided options dict, | ||
182 | // so we can check it immediately | ||
183 |
2/2✓ Branch 0 taken 8804 times.
✓ Branch 1 taken 28406 times.
|
37210 | e = options ? av_dict_get(*options, "codec_whitelist", NULL, 0) : NULL; |
184 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37210 times.
|
37210 | if (e) { |
185 | ✗ | ret = av_opt_set(avctx, e->key, e->value, 0); | |
186 | ✗ | if (ret < 0) | |
187 | ✗ | return ret; | |
188 | } | ||
189 | |||
190 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 37210 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
37210 | if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) { |
191 | ✗ | av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist); | |
192 | ✗ | return AVERROR(EINVAL); | |
193 | } | ||
194 | |||
195 |
2/2✓ Branch 1 taken 15792 times.
✓ Branch 2 taken 21418 times.
|
37210 | avci = ff_codec_is_decoder(codec) ? |
196 | 15792 | ff_decode_internal_alloc() : | |
197 | 21418 | ff_encode_internal_alloc(); | |
198 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37210 times.
|
37210 | if (!avci) { |
199 | ✗ | ret = AVERROR(ENOMEM); | |
200 | ✗ | goto end; | |
201 | } | ||
202 | 37210 | avctx->internal = avci; | |
203 | |||
204 | 37210 | avci->buffer_frame = av_frame_alloc(); | |
205 | 37210 | avci->buffer_pkt = av_packet_alloc(); | |
206 |
2/4✓ Branch 0 taken 37210 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37210 times.
|
37210 | if (!avci->buffer_frame || !avci->buffer_pkt) { |
207 | ✗ | ret = AVERROR(ENOMEM); | |
208 | ✗ | goto free_and_end; | |
209 | } | ||
210 | |||
211 |
2/2✓ Branch 0 taken 16453 times.
✓ Branch 1 taken 20757 times.
|
37210 | if (codec2->priv_data_size > 0) { |
212 |
2/2✓ Branch 0 taken 8306 times.
✓ Branch 1 taken 8147 times.
|
16453 | if (!avctx->priv_data) { |
213 | 8306 | avctx->priv_data = av_mallocz(codec2->priv_data_size); | |
214 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8306 times.
|
8306 | if (!avctx->priv_data) { |
215 | ✗ | ret = AVERROR(ENOMEM); | |
216 | ✗ | goto free_and_end; | |
217 | } | ||
218 |
2/2✓ Branch 0 taken 2420 times.
✓ Branch 1 taken 5886 times.
|
8306 | if (codec->priv_class) { |
219 | 2420 | *(const AVClass **)avctx->priv_data = codec->priv_class; | |
220 | 2420 | av_opt_set_defaults(avctx->priv_data); | |
221 | } | ||
222 | } | ||
223 | } else { | ||
224 | 20757 | avctx->priv_data = NULL; | |
225 | } | ||
226 | |||
227 | 37210 | ret = av_opt_set_dict2(avctx, options, AV_OPT_SEARCH_CHILDREN); | |
228 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37210 times.
|
37210 | if (ret < 0) |
229 | ✗ | goto free_and_end; | |
230 | |||
231 | // only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions | ||
232 |
6/8✓ Branch 0 taken 32 times.
✓ Branch 1 taken 37178 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.
|
37210 | if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height && |
233 |
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))) { |
234 |
3/4✓ Branch 0 taken 32 times.
✓ Branch 1 taken 37178 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
|
37210 | if (avctx->coded_width && avctx->coded_height) |
235 | 32 | ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); | |
236 |
3/4✓ Branch 0 taken 27978 times.
✓ Branch 1 taken 9200 times.
✓ Branch 2 taken 27978 times.
✗ Branch 3 not taken.
|
37178 | else if (avctx->width && avctx->height) |
237 | 27978 | ret = ff_set_dimensions(avctx, avctx->width, avctx->height); | |
238 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37210 times.
|
37210 | if (ret < 0) |
239 | ✗ | goto free_and_end; | |
240 | } | ||
241 | |||
242 |
5/8✓ Branch 0 taken 9200 times.
✓ Branch 1 taken 28010 times.
✓ Branch 2 taken 9200 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9200 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9200 times.
|
37210 | if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height) |
243 |
1/2✓ Branch 1 taken 28010 times.
✗ Branch 2 not taken.
|
28010 | && ( av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0 |
244 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28010 times.
|
28010 | || av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0)) { |
245 | ✗ | av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n"); | |
246 | ✗ | ff_set_dimensions(avctx, 0, 0); | |
247 | } | ||
248 | |||
249 |
3/4✓ Branch 0 taken 28010 times.
✓ Branch 1 taken 9200 times.
✓ Branch 2 taken 28010 times.
✗ Branch 3 not taken.
|
37210 | if (avctx->width > 0 && avctx->height > 0) { |
250 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28010 times.
|
28010 | if (av_image_check_sar(avctx->width, avctx->height, |
251 | avctx->sample_aspect_ratio) < 0) { | ||
252 | ✗ | av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n", | |
253 | avctx->sample_aspect_ratio.num, | ||
254 | avctx->sample_aspect_ratio.den); | ||
255 | ✗ | avctx->sample_aspect_ratio = (AVRational){ 0, 1 }; | |
256 | } | ||
257 | } | ||
258 | |||
259 | /* AV_CODEC_CAP_CHANNEL_CONF is a decoder-only flag; so the code below | ||
260 | * in particular checks that sample_rate is set for all audio encoders. */ | ||
261 |
1/2✓ Branch 0 taken 37210 times.
✗ Branch 1 not taken.
|
37210 | if (avctx->sample_rate < 0 || |
262 |
4/4✓ Branch 0 taken 32717 times.
✓ Branch 1 taken 4493 times.
✓ Branch 2 taken 242 times.
✓ Branch 3 taken 32475 times.
|
37210 | avctx->sample_rate == 0 && avctx->codec_type == AVMEDIA_TYPE_AUDIO && |
263 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 242 times.
|
242 | !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) { |
264 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", avctx->sample_rate); | |
265 | ✗ | ret = AVERROR(EINVAL); | |
266 | ✗ | goto free_and_end; | |
267 | } | ||
268 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37210 times.
|
37210 | if (avctx->block_align < 0) { |
269 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid block align: %d\n", avctx->block_align); | |
270 | ✗ | ret = AVERROR(EINVAL); | |
271 | ✗ | goto free_and_end; | |
272 | } | ||
273 | |||
274 | /* AV_CODEC_CAP_CHANNEL_CONF is a decoder-only flag; so the code below | ||
275 | * in particular checks that nb_channels is set for all audio encoders. */ | ||
276 |
4/4✓ Branch 0 taken 4735 times.
✓ Branch 1 taken 32475 times.
✓ Branch 2 taken 241 times.
✓ Branch 3 taken 4494 times.
|
37210 | if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && !avctx->ch_layout.nb_channels |
277 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 241 times.
|
241 | && !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) { |
278 | ✗ | av_log(avctx, AV_LOG_ERROR, "%s requires channel layout to be set\n", | |
279 | ✗ | ff_codec_is_decoder(codec) ? "Decoder" : "Encoder"); | |
280 | ✗ | ret = AVERROR(EINVAL); | |
281 | ✗ | goto free_and_end; | |
282 | } | ||
283 |
3/4✓ Branch 0 taken 4494 times.
✓ Branch 1 taken 32716 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4494 times.
|
37210 | if (avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) { |
284 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid channel layout\n"); | |
285 | ✗ | ret = AVERROR(EINVAL); | |
286 | ✗ | goto free_and_end; | |
287 | } | ||
288 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37210 times.
|
37210 | if (avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) { |
289 | ✗ | av_log(avctx, AV_LOG_ERROR, "Too many channels: %d\n", avctx->ch_layout.nb_channels); | |
290 | ✗ | ret = AVERROR(EINVAL); | |
291 | ✗ | goto free_and_end; | |
292 | } | ||
293 | |||
294 | 37210 | avctx->frame_num = 0; | |
295 | 37210 | avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id); | |
296 | |||
297 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 37203 times.
|
37210 | if ((avctx->codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) && |
298 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { |
299 | ✗ | const char *codec_string = ff_codec_is_encoder(codec) ? "encoder" : "decoder"; | |
300 | const AVCodec *codec2; | ||
301 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
302 | "The %s '%s' is experimental but experimental codecs are not enabled, " | ||
303 | "add '-strict %d' if you want to use it.\n", | ||
304 | ✗ | codec_string, codec->name, FF_COMPLIANCE_EXPERIMENTAL); | |
305 | ✗ | codec2 = ff_codec_is_encoder(codec) ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id); | |
306 | ✗ | if (!(codec2->capabilities & AV_CODEC_CAP_EXPERIMENTAL)) | |
307 | ✗ | av_log(avctx, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n", | |
308 | ✗ | codec_string, codec2->name); | |
309 | ✗ | ret = AVERROR_EXPERIMENTAL; | |
310 | ✗ | goto free_and_end; | |
311 | } | ||
312 | |||
313 |
2/2✓ Branch 0 taken 4735 times.
✓ Branch 1 taken 32475 times.
|
37210 | if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && |
314 |
3/4✓ Branch 0 taken 1337 times.
✓ Branch 1 taken 3398 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1337 times.
|
4735 | (!avctx->time_base.num || !avctx->time_base.den)) { |
315 | 3398 | avctx->time_base.num = 1; | |
316 | 3398 | avctx->time_base.den = avctx->sample_rate; | |
317 | } | ||
318 | |||
319 |
2/2✓ Branch 1 taken 21418 times.
✓ Branch 2 taken 15792 times.
|
37210 | if (ff_codec_is_encoder(avctx->codec)) |
320 | 21418 | ret = ff_encode_preinit(avctx); | |
321 | else | ||
322 | 15792 | ret = ff_decode_preinit(avctx); | |
323 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37210 times.
|
37210 | if (ret < 0) |
324 | ✗ | goto free_and_end; | |
325 | |||
326 |
2/2✓ Branch 0 taken 35555 times.
✓ Branch 1 taken 1655 times.
|
37210 | if (HAVE_THREADS && !avci->frame_thread_encoder) { |
327 | /* Frame-threaded decoders call FFCodec.init for their child contexts. */ | ||
328 | 35555 | lock_avcodec(codec2); | |
329 | 35555 | ret = ff_thread_init(avctx); | |
330 | 35555 | unlock_avcodec(codec2); | |
331 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35555 times.
|
35555 | if (ret < 0) { |
332 | ✗ | goto free_and_end; | |
333 | } | ||
334 | } | ||
335 | if (!HAVE_THREADS && !(codec2->caps_internal & FF_CODEC_CAP_AUTO_THREADS)) | ||
336 | avctx->thread_count = 1; | ||
337 | |||
338 |
2/2✓ Branch 0 taken 1665 times.
✓ Branch 1 taken 35545 times.
|
37210 | if (!(avctx->active_thread_type & FF_THREAD_FRAME) || |
339 |
2/2✓ Branch 0 taken 1655 times.
✓ Branch 1 taken 10 times.
|
1665 | avci->frame_thread_encoder) { |
340 |
2/2✓ Branch 0 taken 30594 times.
✓ Branch 1 taken 6606 times.
|
37200 | if (codec2->init) { |
341 | 30594 | lock_avcodec(codec2); | |
342 | 30594 | ret = codec2->init(avctx); | |
343 | 30594 | unlock_avcodec(codec2); | |
344 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 30586 times.
|
30594 | if (ret < 0) { |
345 | 8 | avci->needs_close = codec2->caps_internal & FF_CODEC_CAP_INIT_CLEANUP; | |
346 | 8 | goto free_and_end; | |
347 | } | ||
348 | } | ||
349 | 37192 | avci->needs_close = 1; | |
350 | } | ||
351 | |||
352 | 37202 | ret=0; | |
353 | |||
354 |
2/2✓ Branch 1 taken 15784 times.
✓ Branch 2 taken 21418 times.
|
37202 | if (ff_codec_is_decoder(avctx->codec)) { |
355 |
2/2✓ Branch 0 taken 11072 times.
✓ Branch 1 taken 4712 times.
|
15784 | if (!avctx->bit_rate) |
356 | 11072 | avctx->bit_rate = get_bit_rate(avctx); | |
357 | |||
358 | /* validate channel layout from the decoder */ | ||
359 |
3/4✓ Branch 0 taken 3200 times.
✓ Branch 1 taken 12584 times.
✓ Branch 3 taken 3200 times.
✗ Branch 4 not taken.
|
15784 | if ((avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) || |
360 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15784 times.
|
15784 | avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) { |
361 | ✗ | ret = AVERROR(EINVAL); | |
362 | ✗ | goto free_and_end; | |
363 | } | ||
364 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15784 times.
|
15784 | if (avctx->bits_per_coded_sample < 0) { |
365 | ✗ | ret = AVERROR(EINVAL); | |
366 | ✗ | goto free_and_end; | |
367 | } | ||
368 | } | ||
369 |
2/2✓ Branch 0 taken 5226 times.
✓ Branch 1 taken 31976 times.
|
37202 | if (codec->priv_class) |
370 |
1/2✓ Branch 0 taken 5226 times.
✗ Branch 1 not taken.
|
5226 | av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class); |
371 | |||
372 | 37202 | end: | |
373 | |||
374 | 37210 | return ret; | |
375 | 8 | free_and_end: | |
376 | 8 | ff_codec_close(avctx); | |
377 | 8 | goto end; | |
378 | } | ||
379 | |||
380 | 111 | void avcodec_flush_buffers(AVCodecContext *avctx) | |
381 | { | ||
382 | 111 | AVCodecInternal *avci = avctx->internal; | |
383 | |||
384 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 111 times.
|
111 | if (av_codec_is_encoder(avctx->codec)) { |
385 | ✗ | int caps = avctx->codec->capabilities; | |
386 | |||
387 | ✗ | if (!(caps & AV_CODEC_CAP_ENCODER_FLUSH)) { | |
388 | // Only encoders that explicitly declare support for it can be | ||
389 | // flushed. Otherwise, this is a no-op. | ||
390 | ✗ | av_log(avctx, AV_LOG_WARNING, "Ignoring attempt to flush encoder " | |
391 | "that doesn't support it\n"); | ||
392 | ✗ | return; | |
393 | } | ||
394 | ✗ | ff_encode_flush_buffers(avctx); | |
395 | } else | ||
396 | 111 | ff_decode_flush_buffers(avctx); | |
397 | |||
398 | 111 | avci->draining = 0; | |
399 | 111 | avci->draining_done = 0; | |
400 |
1/2✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
|
111 | if (avci->buffer_frame) |
401 | 111 | av_frame_unref(avci->buffer_frame); | |
402 |
1/2✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
|
111 | if (avci->buffer_pkt) |
403 | 111 | av_packet_unref(avci->buffer_pkt); | |
404 | |||
405 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
|
111 | if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME && |
406 | ✗ | !avci->is_frame_mt) | |
407 | ✗ | ff_thread_flush(avctx); | |
408 |
2/2✓ Branch 1 taken 34 times.
✓ Branch 2 taken 77 times.
|
111 | else if (ffcodec(avctx->codec)->flush) |
409 | 34 | ffcodec(avctx->codec)->flush(avctx); | |
410 | } | ||
411 | |||
412 | 1075 | void avsubtitle_free(AVSubtitle *sub) | |
413 | { | ||
414 | int i; | ||
415 | |||
416 |
2/2✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 1075 times.
|
2095 | for (i = 0; i < sub->num_rects; i++) { |
417 | 1020 | AVSubtitleRect *const rect = sub->rects[i]; | |
418 | |||
419 | 1020 | av_freep(&rect->data[0]); | |
420 | 1020 | av_freep(&rect->data[1]); | |
421 | 1020 | av_freep(&rect->data[2]); | |
422 | 1020 | av_freep(&rect->data[3]); | |
423 | 1020 | av_freep(&rect->text); | |
424 | 1020 | av_freep(&rect->ass); | |
425 | |||
426 | 1020 | av_freep(&sub->rects[i]); | |
427 | } | ||
428 | |||
429 | 1075 | av_freep(&sub->rects); | |
430 | |||
431 | 1075 | memset(sub, 0, sizeof(*sub)); | |
432 | 1075 | } | |
433 | |||
434 | 63857 | av_cold void ff_codec_close(AVCodecContext *avctx) | |
435 | { | ||
436 | int i; | ||
437 | |||
438 |
2/2✓ Branch 1 taken 37210 times.
✓ Branch 2 taken 26647 times.
|
63857 | if (avcodec_is_open(avctx)) { |
439 | 37210 | AVCodecInternal *avci = avctx->internal; | |
440 | |||
441 | 37210 | if (CONFIG_FRAME_THREAD_ENCODER && | |
442 |
4/4✓ Branch 0 taken 14883 times.
✓ Branch 1 taken 22327 times.
✓ Branch 2 taken 1655 times.
✓ Branch 3 taken 13228 times.
|
37210 | avci->frame_thread_encoder && avctx->thread_count > 1) { |
443 | 1655 | ff_frame_thread_encoder_free(avctx); | |
444 | } | ||
445 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 37174 times.
|
37210 | if (HAVE_THREADS && avci->thread_ctx) |
446 | 36 | ff_thread_free(avctx); | |
447 |
4/4✓ Branch 0 taken 37192 times.
✓ Branch 1 taken 18 times.
✓ Branch 3 taken 7511 times.
✓ Branch 4 taken 29681 times.
|
37210 | if (avci->needs_close && ffcodec(avctx->codec)->close) |
448 | 7511 | ffcodec(avctx->codec)->close(avctx); | |
449 | 37210 | avci->byte_buffer_size = 0; | |
450 | 37210 | av_freep(&avci->byte_buffer); | |
451 | 37210 | av_frame_free(&avci->buffer_frame); | |
452 | 37210 | av_packet_free(&avci->buffer_pkt); | |
453 | 37210 | av_packet_free(&avci->last_pkt_props); | |
454 | |||
455 | 37210 | av_packet_free(&avci->in_pkt); | |
456 | 37210 | av_frame_free(&avci->in_frame); | |
457 | 37210 | av_frame_free(&avci->recon_frame); | |
458 | |||
459 | 37210 | av_refstruct_unref(&avci->pool); | |
460 | 37210 | av_refstruct_pool_uninit(&avci->progress_frame_pool); | |
461 |
2/2✓ Branch 1 taken 15792 times.
✓ Branch 2 taken 21418 times.
|
37210 | if (av_codec_is_decoder(avctx->codec)) |
462 | 15792 | ff_decode_internal_uninit(avctx); | |
463 | |||
464 | 37210 | ff_hwaccel_uninit(avctx); | |
465 | |||
466 | 37210 | av_bsf_free(&avci->bsf); | |
467 | |||
468 | #if CONFIG_LCMS2 | ||
469 | ff_icc_context_uninit(&avci->icc); | ||
470 | #endif | ||
471 | |||
472 | 37210 | av_freep(&avctx->internal); | |
473 | } | ||
474 | |||
475 |
2/2✓ Branch 0 taken 4434 times.
✓ Branch 1 taken 63857 times.
|
68291 | for (i = 0; i < avctx->nb_coded_side_data; i++) |
476 | 4434 | av_freep(&avctx->coded_side_data[i].data); | |
477 | 63857 | av_freep(&avctx->coded_side_data); | |
478 | 63857 | avctx->nb_coded_side_data = 0; | |
479 | 63857 | av_frame_side_data_free(&avctx->decoded_side_data, | |
480 | &avctx->nb_decoded_side_data); | ||
481 | |||
482 | 63857 | av_buffer_unref(&avctx->hw_frames_ctx); | |
483 | 63857 | av_buffer_unref(&avctx->hw_device_ctx); | |
484 | |||
485 |
5/6✓ Branch 0 taken 24751 times.
✓ Branch 1 taken 39106 times.
✓ Branch 2 taken 24751 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7646 times.
✓ Branch 5 taken 17105 times.
|
63857 | if (avctx->priv_data && avctx->codec && avctx->codec->priv_class) |
486 | 7646 | av_opt_free(avctx->priv_data); | |
487 | 63857 | av_opt_free(avctx); | |
488 | 63857 | av_freep(&avctx->priv_data); | |
489 |
2/2✓ Branch 1 taken 21418 times.
✓ Branch 2 taken 42439 times.
|
63857 | if (av_codec_is_encoder(avctx->codec)) { |
490 | 21418 | av_freep(&avctx->extradata); | |
491 | 21418 | avctx->extradata_size = 0; | |
492 |
2/2✓ Branch 1 taken 32518 times.
✓ Branch 2 taken 9921 times.
|
42439 | } else if (av_codec_is_decoder(avctx->codec)) |
493 | 32518 | av_freep(&avctx->subtitle_header); | |
494 | |||
495 | 63857 | avctx->codec = NULL; | |
496 | 63857 | avctx->active_thread_type = 0; | |
497 | 63857 | } | |
498 | |||
499 | 22355 | static const char *unknown_if_null(const char *str) | |
500 | { | ||
501 |
1/2✓ Branch 0 taken 22355 times.
✗ Branch 1 not taken.
|
22355 | return str ? str : "unknown"; |
502 | } | ||
503 | |||
504 | 17357 | void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) | |
505 | { | ||
506 | const char *codec_type; | ||
507 | const char *codec_name; | ||
508 | 17357 | const char *profile = NULL; | |
509 | AVBPrint bprint; | ||
510 | int64_t bitrate; | ||
511 | 17357 | int new_line = 0; | |
512 | AVRational display_aspect_ratio; | ||
513 |
2/2✓ Branch 0 taken 17331 times.
✓ Branch 1 taken 26 times.
|
17357 | const char *separator = enc->dump_separator ? (const char *)enc->dump_separator : ", "; |
514 | const char *str; | ||
515 | |||
516 |
2/4✓ Branch 0 taken 17357 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17357 times.
|
17357 | if (!buf || buf_size <= 0) |
517 | 9 | return; | |
518 | 17357 | av_bprint_init_for_buffer(&bprint, buf, buf_size); | |
519 | 17357 | codec_type = av_get_media_type_string(enc->codec_type); | |
520 | 17357 | codec_name = avcodec_get_name(enc->codec_id); | |
521 | 17357 | profile = avcodec_profile_name(enc->codec_id, enc->profile); | |
522 | |||
523 |
1/2✓ Branch 0 taken 17357 times.
✗ Branch 1 not taken.
|
17357 | av_bprintf(&bprint, "%s: %s", codec_type ? codec_type : "unknown", |
524 | codec_name); | ||
525 | 17357 | buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */ | |
526 | |||
527 |
4/4✓ Branch 0 taken 8290 times.
✓ Branch 1 taken 9067 times.
✓ Branch 2 taken 296 times.
✓ Branch 3 taken 7994 times.
|
17357 | if (enc->codec && strcmp(enc->codec->name, codec_name)) |
528 | 296 | av_bprintf(&bprint, " (%s)", enc->codec->name); | |
529 | |||
530 |
2/2✓ Branch 0 taken 2031 times.
✓ Branch 1 taken 15326 times.
|
17357 | if (profile) |
531 | 2031 | av_bprintf(&bprint, " (%s)", profile); | |
532 |
2/2✓ Branch 0 taken 13424 times.
✓ Branch 1 taken 3933 times.
|
17357 | if ( enc->codec_type == AVMEDIA_TYPE_VIDEO |
533 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13424 times.
|
13424 | && av_log_get_level() >= AV_LOG_VERBOSE |
534 | ✗ | && enc->refs) | |
535 | ✗ | av_bprintf(&bprint, ", %d reference frame%s", | |
536 | ✗ | enc->refs, enc->refs > 1 ? "s" : ""); | |
537 | |||
538 |
2/2✓ Branch 0 taken 9816 times.
✓ Branch 1 taken 7541 times.
|
17357 | if (enc->codec_tag) |
539 | 9816 | av_bprintf(&bprint, " (%s / 0x%04X)", | |
540 | 9816 | av_fourcc2str(enc->codec_tag), enc->codec_tag); | |
541 | |||
542 |
5/5✓ Branch 0 taken 13424 times.
✓ Branch 1 taken 3654 times.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 180 times.
✓ Branch 4 taken 9 times.
|
17357 | switch (enc->codec_type) { |
543 | 13424 | case AVMEDIA_TYPE_VIDEO: | |
544 | { | ||
545 | unsigned len; | ||
546 | |||
547 | 13424 | av_bprintf(&bprint, "%s%s", separator, | |
548 |
2/2✓ Branch 0 taken 13376 times.
✓ Branch 1 taken 48 times.
|
13424 | enc->pix_fmt == AV_PIX_FMT_NONE ? "none" : |
549 | 13376 | unknown_if_null(av_get_pix_fmt_name(enc->pix_fmt))); | |
550 | |||
551 | 13424 | av_bprint_chars(&bprint, '(', 1); | |
552 | 13424 | len = bprint.len; | |
553 | |||
554 | /* The following check ensures that '(' has been written | ||
555 | * and therefore allows us to erase it if it turns out | ||
556 | * to be unnecessary. */ | ||
557 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13424 times.
|
13424 | if (!av_bprint_is_complete(&bprint)) |
558 | ✗ | return; | |
559 | |||
560 |
3/4✓ Branch 0 taken 1209 times.
✓ Branch 1 taken 12215 times.
✓ Branch 2 taken 1209 times.
✗ Branch 3 not taken.
|
13424 | if (enc->bits_per_raw_sample && enc->pix_fmt != AV_PIX_FMT_NONE && |
561 |
2/2✓ Branch 1 taken 27 times.
✓ Branch 2 taken 1182 times.
|
1209 | enc->bits_per_raw_sample < av_pix_fmt_desc_get(enc->pix_fmt)->comp[0].depth) |
562 | 27 | av_bprintf(&bprint, "%d bpc, ", enc->bits_per_raw_sample); | |
563 |
3/4✓ Branch 0 taken 11060 times.
✓ Branch 1 taken 2364 times.
✓ Branch 2 taken 11060 times.
✗ Branch 3 not taken.
|
24484 | if (enc->color_range != AVCOL_RANGE_UNSPECIFIED && |
564 | 11060 | (str = av_color_range_name(enc->color_range))) | |
565 | 11060 | av_bprintf(&bprint, "%s, ", str); | |
566 | |||
567 |
2/2✓ Branch 0 taken 10550 times.
✓ Branch 1 taken 2874 times.
|
13424 | if (enc->colorspace != AVCOL_SPC_UNSPECIFIED || |
568 |
2/2✓ Branch 0 taken 10548 times.
✓ Branch 1 taken 2 times.
|
10550 | enc->color_primaries != AVCOL_PRI_UNSPECIFIED || |
569 |
2/2✓ Branch 0 taken 117 times.
✓ Branch 1 taken 10431 times.
|
10548 | enc->color_trc != AVCOL_TRC_UNSPECIFIED) { |
570 | 2993 | const char *col = unknown_if_null(av_color_space_name(enc->colorspace)); | |
571 | 2993 | const char *pri = unknown_if_null(av_color_primaries_name(enc->color_primaries)); | |
572 | 2993 | const char *trc = unknown_if_null(av_color_transfer_name(enc->color_trc)); | |
573 |
4/4✓ Branch 0 taken 289 times.
✓ Branch 1 taken 2704 times.
✓ Branch 2 taken 131 times.
✓ Branch 3 taken 158 times.
|
2993 | if (strcmp(col, pri) || strcmp(col, trc)) { |
574 | 2835 | new_line = 1; | |
575 | 2835 | av_bprintf(&bprint, "%s/%s/%s, ", col, pri, trc); | |
576 | } else | ||
577 | 158 | av_bprintf(&bprint, "%s, ", col); | |
578 | } | ||
579 | |||
580 |
2/2✓ Branch 0 taken 7515 times.
✓ Branch 1 taken 5909 times.
|
13424 | if (enc->field_order != AV_FIELD_UNKNOWN) { |
581 | 7515 | const char *field_order = "progressive"; | |
582 |
2/2✓ Branch 0 taken 142 times.
✓ Branch 1 taken 7373 times.
|
7515 | if (enc->field_order == AV_FIELD_TT) |
583 | 142 | field_order = "top first"; | |
584 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 7325 times.
|
7373 | else if (enc->field_order == AV_FIELD_BB) |
585 | 48 | field_order = "bottom first"; | |
586 |
2/2✓ Branch 0 taken 362 times.
✓ Branch 1 taken 6963 times.
|
7325 | else if (enc->field_order == AV_FIELD_TB) |
587 | 362 | field_order = "top coded first (swapped)"; | |
588 |
2/2✓ Branch 0 taken 129 times.
✓ Branch 1 taken 6834 times.
|
6963 | else if (enc->field_order == AV_FIELD_BT) |
589 | 129 | field_order = "bottom coded first (swapped)"; | |
590 | |||
591 | 7515 | av_bprintf(&bprint, "%s, ", field_order); | |
592 | } | ||
593 | |||
594 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13424 times.
|
13424 | if (av_log_get_level() >= AV_LOG_VERBOSE && |
595 | ✗ | enc->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED && | |
596 | ✗ | (str = av_chroma_location_name(enc->chroma_sample_location))) | |
597 | ✗ | av_bprintf(&bprint, "%s, ", str); | |
598 | |||
599 |
2/2✓ Branch 0 taken 1087 times.
✓ Branch 1 taken 12337 times.
|
13424 | if (len == bprint.len) { |
600 | 1087 | bprint.str[len - 1] = '\0'; | |
601 | 1087 | bprint.len--; | |
602 | } else { | ||
603 |
1/2✓ Branch 0 taken 12337 times.
✗ Branch 1 not taken.
|
12337 | if (bprint.len - 2 < bprint.size) { |
604 | /* Erase the last ", " */ | ||
605 | 12337 | bprint.len -= 2; | |
606 | 12337 | bprint.str[bprint.len] = '\0'; | |
607 | } | ||
608 | 12337 | av_bprint_chars(&bprint, ')', 1); | |
609 | } | ||
610 | } | ||
611 | |||
612 |
2/2✓ Branch 0 taken 13404 times.
✓ Branch 1 taken 20 times.
|
13424 | if (enc->width) { |
613 |
2/2✓ Branch 0 taken 2833 times.
✓ Branch 1 taken 10571 times.
|
13404 | av_bprintf(&bprint, "%s%dx%d", new_line ? separator : ", ", |
614 | enc->width, enc->height); | ||
615 | |||
616 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13404 times.
|
13404 | if (av_log_get_level() >= AV_LOG_VERBOSE && |
617 | ✗ | enc->coded_width && enc->coded_height && | |
618 | ✗ | (enc->width != enc->coded_width || | |
619 | ✗ | enc->height != enc->coded_height)) | |
620 | ✗ | av_bprintf(&bprint, " (%dx%d)", | |
621 | enc->coded_width, enc->coded_height); | ||
622 | |||
623 |
2/2✓ Branch 0 taken 2545 times.
✓ Branch 1 taken 10859 times.
|
13404 | if (enc->sample_aspect_ratio.num) { |
624 | 2545 | av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, | |
625 | 2545 | enc->width * (int64_t)enc->sample_aspect_ratio.num, | |
626 | 2545 | enc->height * (int64_t)enc->sample_aspect_ratio.den, | |
627 | 1024 * 1024); | ||
628 | 2545 | av_bprintf(&bprint, " [SAR %d:%d DAR %d:%d]", | |
629 | enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den, | ||
630 | display_aspect_ratio.num, display_aspect_ratio.den); | ||
631 | } | ||
632 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13404 times.
|
13404 | if (av_log_get_level() >= AV_LOG_DEBUG) { |
633 | ✗ | int g = av_gcd(enc->time_base.num, enc->time_base.den); | |
634 | ✗ | av_bprintf(&bprint, ", %d/%d", | |
635 | ✗ | enc->time_base.num / g, enc->time_base.den / g); | |
636 | } | ||
637 | } | ||
638 |
2/2✓ Branch 0 taken 7168 times.
✓ Branch 1 taken 6256 times.
|
13424 | if (encode) { |
639 | 7168 | av_bprintf(&bprint, ", q=%d-%d", enc->qmin, enc->qmax); | |
640 | } else { | ||
641 | #if FF_API_CODEC_PROPS | ||
642 | FF_DISABLE_DEPRECATION_WARNINGS | ||
643 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6256 times.
|
6256 | if (enc->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS) |
644 | ✗ | av_bprintf(&bprint, ", Closed Captions"); | |
645 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6256 times.
|
6256 | if (enc->properties & FF_CODEC_PROPERTY_FILM_GRAIN) |
646 | ✗ | av_bprintf(&bprint, ", Film Grain"); | |
647 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6256 times.
|
6256 | if (enc->properties & FF_CODEC_PROPERTY_LOSSLESS) |
648 | ✗ | av_bprintf(&bprint, ", lossless"); | |
649 | FF_ENABLE_DEPRECATION_WARNINGS | ||
650 | #endif | ||
651 | } | ||
652 | 13424 | break; | |
653 | 3654 | case AVMEDIA_TYPE_AUDIO: | |
654 | 3654 | av_bprintf(&bprint, "%s", separator); | |
655 | |||
656 |
2/2✓ Branch 0 taken 3638 times.
✓ Branch 1 taken 16 times.
|
3654 | if (enc->sample_rate) { |
657 | 3638 | av_bprintf(&bprint, "%d Hz, ", enc->sample_rate); | |
658 | } | ||
659 | 3654 | av_channel_layout_describe_bprint(&enc->ch_layout, &bprint); | |
660 |
2/4✓ Branch 0 taken 3654 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3654 times.
✗ Branch 3 not taken.
|
7308 | if (enc->sample_fmt != AV_SAMPLE_FMT_NONE && |
661 | 3654 | (str = av_get_sample_fmt_name(enc->sample_fmt))) { | |
662 | 3654 | av_bprintf(&bprint, ", %s", str); | |
663 | } | ||
664 |
2/2✓ Branch 0 taken 1940 times.
✓ Branch 1 taken 1714 times.
|
3654 | if ( enc->bits_per_raw_sample > 0 |
665 |
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) |
666 | 218 | av_bprintf(&bprint, " (%d bit)", enc->bits_per_raw_sample); | |
667 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3650 times.
|
3654 | if (av_log_get_level() >= AV_LOG_VERBOSE) { |
668 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (enc->initial_padding) |
669 | 2 | av_bprintf(&bprint, ", delay %d", enc->initial_padding); | |
670 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (enc->trailing_padding) |
671 | ✗ | av_bprintf(&bprint, ", padding %d", enc->trailing_padding); | |
672 | } | ||
673 | 3654 | break; | |
674 | 90 | case AVMEDIA_TYPE_DATA: | |
675 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
|
90 | if (av_log_get_level() >= AV_LOG_DEBUG) { |
676 | ✗ | int g = av_gcd(enc->time_base.num, enc->time_base.den); | |
677 | ✗ | if (g) | |
678 | ✗ | av_bprintf(&bprint, ", %d/%d", | |
679 | ✗ | enc->time_base.num / g, enc->time_base.den / g); | |
680 | } | ||
681 | 90 | break; | |
682 | 180 | case AVMEDIA_TYPE_SUBTITLE: | |
683 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 147 times.
|
180 | if (enc->width) |
684 | 33 | av_bprintf(&bprint, ", %dx%d", enc->width, enc->height); | |
685 | 180 | break; | |
686 | 9 | default: | |
687 | 9 | return; | |
688 | } | ||
689 |
2/2✓ Branch 0 taken 8949 times.
✓ Branch 1 taken 8399 times.
|
17348 | if (encode) { |
690 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8949 times.
|
8949 | if (enc->flags & AV_CODEC_FLAG_PASS1) |
691 | ✗ | av_bprintf(&bprint, ", pass 1"); | |
692 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8949 times.
|
8949 | if (enc->flags & AV_CODEC_FLAG_PASS2) |
693 | ✗ | av_bprintf(&bprint, ", pass 2"); | |
694 | } | ||
695 | 17348 | bitrate = get_bit_rate(enc); | |
696 |
2/2✓ Branch 0 taken 11212 times.
✓ Branch 1 taken 6136 times.
|
17348 | if (bitrate != 0) { |
697 | 11212 | av_bprintf(&bprint, ", %"PRId64" kb/s", bitrate / 1000); | |
698 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6136 times.
|
6136 | } else if (enc->rc_max_rate > 0) { |
699 | ✗ | av_bprintf(&bprint, ", max. %"PRId64" kb/s", enc->rc_max_rate / 1000); | |
700 | } | ||
701 | } | ||
702 | |||
703 | 2846623 | int avcodec_is_open(AVCodecContext *s) | |
704 | { | ||
705 | 2846623 | return !!s->internal; | |
706 | } | ||
707 | |||
708 | 772078 | int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame) | |
709 | { | ||
710 | 772078 | av_frame_unref(frame); | |
711 | |||
712 |
2/4✓ Branch 1 taken 772078 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 772078 times.
|
772078 | if (!avcodec_is_open(avctx) || !avctx->codec) |
713 | ✗ | return AVERROR(EINVAL); | |
714 | |||
715 |
2/2✓ Branch 1 taken 772016 times.
✓ Branch 2 taken 62 times.
|
772078 | if (ff_codec_is_decoder(avctx->codec)) |
716 | 772016 | return ff_decode_receive_frame(avctx, frame); | |
717 | 62 | return ff_encode_receive_frame(avctx, frame); | |
718 | } | ||
719 | |||
720 | #define WRAP_CONFIG(allowed_type, field, field_type, terminator) \ | ||
721 | do { \ | ||
722 | static const field_type end = terminator; \ | ||
723 | if (codec->type != (allowed_type)) \ | ||
724 | return AVERROR(EINVAL); \ | ||
725 | *out_configs = (field); \ | ||
726 | if (out_num_configs) { \ | ||
727 | for (int i = 0;; i++) { \ | ||
728 | if (!(field) || !memcmp(&(field)[i], &end, sizeof(end))) { \ | ||
729 | *out_num_configs = i; \ | ||
730 | break; \ | ||
731 | } \ | ||
732 | } \ | ||
733 | } \ | ||
734 | return 0; \ | ||
735 | } while (0) | ||
736 | |||
737 | static const enum AVColorRange color_range_jpeg[] = { | ||
738 | AVCOL_RANGE_JPEG, AVCOL_RANGE_UNSPECIFIED | ||
739 | }; | ||
740 | |||
741 | static const enum AVColorRange color_range_mpeg[] = { | ||
742 | AVCOL_RANGE_MPEG, AVCOL_RANGE_UNSPECIFIED | ||
743 | }; | ||
744 | |||
745 | static const enum AVColorRange color_range_all[] = { | ||
746 | AVCOL_RANGE_MPEG, AVCOL_RANGE_JPEG, AVCOL_RANGE_UNSPECIFIED | ||
747 | }; | ||
748 | |||
749 | static const enum AVColorRange *color_range_table[] = { | ||
750 | [AVCOL_RANGE_MPEG] = color_range_mpeg, | ||
751 | [AVCOL_RANGE_JPEG] = color_range_jpeg, | ||
752 | [AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG] = color_range_all, | ||
753 | }; | ||
754 | |||
755 | 69797 | int ff_default_get_supported_config(const AVCodecContext *avctx, | |
756 | const AVCodec *codec, | ||
757 | enum AVCodecConfig config, | ||
758 | unsigned flags, | ||
759 | const void **out_configs, | ||
760 | int *out_num_configs) | ||
761 | { | ||
762 | 69797 | const FFCodec *codec2 = ffcodec(codec); | |
763 | |||
764 |
8/9✓ Branch 0 taken 32118 times.
✓ Branch 1 taken 6792 times.
✓ Branch 2 taken 2690 times.
✓ Branch 3 taken 2690 times.
✓ Branch 4 taken 2690 times.
✓ Branch 5 taken 6766 times.
✓ Branch 6 taken 6793 times.
✓ Branch 7 taken 9258 times.
✗ Branch 8 not taken.
|
69797 | switch (config) { |
765 | FF_DISABLE_DEPRECATION_WARNINGS | ||
766 | 32118 | case AV_CODEC_CONFIG_PIX_FORMAT: | |
767 |
6/8✗ Branch 0 not taken.
✓ Branch 1 taken 32118 times.
✓ Branch 2 taken 32118 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21809 times.
✓ Branch 5 taken 30307 times.
✓ Branch 6 taken 1811 times.
✓ Branch 7 taken 19998 times.
|
52116 | WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->pix_fmts, enum AVPixelFormat, AV_PIX_FMT_NONE); |
768 | 6792 | case AV_CODEC_CONFIG_FRAME_RATE: | |
769 |
6/8✗ Branch 0 not taken.
✓ Branch 1 taken 6792 times.
✓ Branch 2 taken 6792 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2989 times.
✓ Branch 5 taken 6736 times.
✓ Branch 6 taken 56 times.
✓ Branch 7 taken 2933 times.
|
9725 | WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->supported_framerates, AVRational, {0}); |
770 | 2690 | case AV_CODEC_CONFIG_SAMPLE_RATE: | |
771 |
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); |
772 | 2690 | case AV_CODEC_CONFIG_SAMPLE_FORMAT: | |
773 |
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); |
774 | 2690 | case AV_CODEC_CONFIG_CHANNEL_LAYOUT: | |
775 |
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}); |
776 | FF_ENABLE_DEPRECATION_WARNINGS | ||
777 | |||
778 | 6766 | case AV_CODEC_CONFIG_COLOR_RANGE: | |
779 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6766 times.
|
6766 | if (codec->type != AVMEDIA_TYPE_VIDEO) |
780 | ✗ | return AVERROR(EINVAL); | |
781 | 6766 | *out_configs = color_range_table[ffcodec(codec)->color_ranges]; | |
782 |
1/2✓ Branch 0 taken 6766 times.
✗ Branch 1 not taken.
|
6766 | if (out_num_configs) |
783 | 6766 | *out_num_configs = av_popcount(ffcodec(codec)->color_ranges); | |
784 | 6766 | return 0; | |
785 | |||
786 | 6793 | case AV_CODEC_CONFIG_COLOR_SPACE: | |
787 | 6793 | *out_configs = NULL; | |
788 |
1/2✓ Branch 0 taken 6793 times.
✗ Branch 1 not taken.
|
6793 | if (out_num_configs) |
789 | 6793 | *out_num_configs = 0; | |
790 | 6793 | return 0; | |
791 | |||
792 | 9258 | case AV_CODEC_CONFIG_ALPHA_MODE: | |
793 |
6/8✗ Branch 0 not taken.
✓ Branch 1 taken 9258 times.
✓ Branch 2 taken 9258 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 66 times.
✓ Branch 5 taken 9225 times.
✓ Branch 6 taken 33 times.
✓ Branch 7 taken 33 times.
|
9291 | WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec2->alpha_modes, enum AVAlphaMode, AVALPHA_MODE_UNSPECIFIED); |
794 | |||
795 | ✗ | default: | |
796 | ✗ | return AVERROR(EINVAL); | |
797 | } | ||
798 | } | ||
799 | |||
800 | 69824 | 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 | 69824 | int dummy_num = 0; | |
806 |
1/2✓ Branch 0 taken 69824 times.
✗ Branch 1 not taken.
|
69824 | if (!codec) |
807 | 69824 | codec = avctx->codec; | |
808 |
2/2✓ Branch 0 taken 43277 times.
✓ Branch 1 taken 26547 times.
|
69824 | if (!out_num) |
809 | 43277 | out_num = &dummy_num; | |
810 | |||
811 | 69824 | codec2 = ffcodec(codec); | |
812 |
2/2✓ Branch 0 taken 187 times.
✓ Branch 1 taken 69637 times.
|
69824 | if (codec2->get_supported_config) { |
813 | 187 | return codec2->get_supported_config(avctx, codec, config, flags, out, out_num); | |
814 | } else { | ||
815 | 69637 | return ff_default_get_supported_config(avctx, codec, config, flags, out, out_num); | |
816 | } | ||
817 | } | ||
818 |