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