| 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 <assert.h> | ||
| 27 | |||
| 28 | #include "config.h" | ||
| 29 | #include "libavutil/avassert.h" | ||
| 30 | #include "libavutil/avstring.h" | ||
| 31 | #include "libavutil/bprint.h" | ||
| 32 | #include "libavutil/channel_layout.h" | ||
| 33 | #include "libavutil/common.h" | ||
| 34 | #include "libavutil/emms.h" | ||
| 35 | #include "libavutil/imgutils.h" | ||
| 36 | #include "libavutil/mem.h" | ||
| 37 | #include "libavutil/opt.h" | ||
| 38 | #include "libavutil/thread.h" | ||
| 39 | #include "avcodec.h" | ||
| 40 | #include "avcodec_internal.h" | ||
| 41 | #include "bsf.h" | ||
| 42 | #include "codec_desc.h" | ||
| 43 | #include "codec_internal.h" | ||
| 44 | #include "decode.h" | ||
| 45 | #include "frame_thread_encoder.h" | ||
| 46 | #include "hwconfig.h" | ||
| 47 | #include "internal.h" | ||
| 48 | #include "libavutil/refstruct.h" | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Maximum size in bytes of extradata. | ||
| 52 | * This value was chosen such that every bit of the buffer is | ||
| 53 | * addressable by a 32-bit signed integer as used by get_bits. | ||
| 54 | */ | ||
| 55 | #define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE) | ||
| 56 | |||
| 57 | const SideDataMap ff_sd_global_map[] = { | ||
| 58 | { AV_PKT_DATA_REPLAYGAIN , AV_FRAME_DATA_REPLAYGAIN }, | ||
| 59 | { AV_PKT_DATA_DISPLAYMATRIX, AV_FRAME_DATA_DISPLAYMATRIX }, | ||
| 60 | { AV_PKT_DATA_SPHERICAL, AV_FRAME_DATA_SPHERICAL }, | ||
| 61 | { AV_PKT_DATA_STEREO3D, AV_FRAME_DATA_STEREO3D }, | ||
| 62 | { AV_PKT_DATA_AUDIO_SERVICE_TYPE, AV_FRAME_DATA_AUDIO_SERVICE_TYPE }, | ||
| 63 | { AV_PKT_DATA_MASTERING_DISPLAY_METADATA, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA }, | ||
| 64 | { AV_PKT_DATA_CONTENT_LIGHT_LEVEL, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL }, | ||
| 65 | { AV_PKT_DATA_ICC_PROFILE, AV_FRAME_DATA_ICC_PROFILE }, | ||
| 66 | { AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT,AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT }, | ||
| 67 | { AV_PKT_DATA_3D_REFERENCE_DISPLAYS, AV_FRAME_DATA_3D_REFERENCE_DISPLAYS }, | ||
| 68 | { AV_PKT_DATA_EXIF, AV_FRAME_DATA_EXIF }, | ||
| 69 | { AV_PKT_DATA_NB }, | ||
| 70 | }; | ||
| 71 | |||
| 72 | |||
| 73 | 27829 | 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 1390026 times.
✓ Branch 1 taken 27829 times.
|
1417855 | for (i = 0; i < count; i++) { |
| 78 | 1390026 | size_t offset = i * size; | |
| 79 |
2/2✓ Branch 0 taken 1362197 times.
✓ Branch 1 taken 27829 times.
|
1390026 | int r = func(c, FF_PTR_ADD((char *)arg, offset)); |
| 80 |
2/2✓ Branch 0 taken 930 times.
✓ Branch 1 taken 1389096 times.
|
1390026 | if (ret) |
| 81 | 930 | ret[i] = r; | |
| 82 | } | ||
| 83 | 27829 | emms_c(); | |
| 84 | 27829 | return 0; | |
| 85 | } | ||
| 86 | |||
| 87 | 8709 | 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 231716 times.
✓ Branch 1 taken 8709 times.
|
240425 | for (i = 0; i < count; i++) { |
| 92 | 231716 | int r = func(c, arg, i, 0); | |
| 93 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 231666 times.
|
231716 | if (ret) |
| 94 | 50 | ret[i] = r; | |
| 95 | } | ||
| 96 | 8709 | emms_c(); | |
| 97 | 8709 | return 0; | |
| 98 | } | ||
| 99 | |||
| 100 | static AVMutex codec_mutex = AV_MUTEX_INITIALIZER; | ||
| 101 | |||
| 102 | 66753 | static void lock_avcodec(const FFCodec *codec) | |
| 103 | { | ||
| 104 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 66753 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
66753 | if (codec->caps_internal & FF_CODEC_CAP_NOT_INIT_THREADSAFE && codec->init) |
| 105 | ✗ | ff_mutex_lock(&codec_mutex); | |
| 106 | 66753 | } | |
| 107 | |||
| 108 | 66753 | static void unlock_avcodec(const FFCodec *codec) | |
| 109 | { | ||
| 110 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 66753 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
66753 | if (codec->caps_internal & FF_CODEC_CAP_NOT_INIT_THREADSAFE && codec->init) |
| 111 | ✗ | ff_mutex_unlock(&codec_mutex); | |
| 112 | 66753 | } | |
| 113 | |||
| 114 | 28733 | 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 23674 times.
✓ Branch 1 taken 5059 times.
✗ Branch 2 not taken.
|
28733 | switch (ctx->codec_type) { |
| 120 | 23674 | case AVMEDIA_TYPE_VIDEO: | |
| 121 | case AVMEDIA_TYPE_DATA: | ||
| 122 | case AVMEDIA_TYPE_SUBTITLE: | ||
| 123 | case AVMEDIA_TYPE_ATTACHMENT: | ||
| 124 | 23674 | bit_rate = ctx->bit_rate; | |
| 125 | 23674 | break; | |
| 126 | 5059 | case AVMEDIA_TYPE_AUDIO: | |
| 127 | 5059 | bits_per_sample = av_get_bits_per_sample(ctx->codec_id); | |
| 128 |
2/2✓ Branch 0 taken 2462 times.
✓ Branch 1 taken 2597 times.
|
5059 | if (bits_per_sample) { |
| 129 | 2462 | bit_rate = ctx->sample_rate * (int64_t)ctx->ch_layout.nb_channels; | |
| 130 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2462 times.
|
2462 | if (bit_rate > INT64_MAX / bits_per_sample) { |
| 131 | ✗ | bit_rate = 0; | |
| 132 | } else | ||
| 133 | 2462 | bit_rate *= bits_per_sample; | |
| 134 | } else | ||
| 135 | 2597 | bit_rate = ctx->bit_rate; | |
| 136 | 5059 | break; | |
| 137 | ✗ | default: | |
| 138 | ✗ | bit_rate = 0; | |
| 139 | ✗ | break; | |
| 140 | } | ||
| 141 | 28733 | return bit_rate; | |
| 142 | } | ||
| 143 | |||
| 144 | 37510 | int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options) | |
| 145 | { | ||
| 146 | 37510 | 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 37510 times.
|
37510 | if (avcodec_is_open(avctx)) |
| 152 | ✗ | return 0; | |
| 153 | |||
| 154 |
3/4✓ Branch 0 taken 35 times.
✓ Branch 1 taken 37475 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 35 times.
|
37510 | 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 37475 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 28920 times.
✓ Branch 3 taken 8555 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 28920 times.
|
37510 | 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 35 times.
✓ Branch 1 taken 37475 times.
|
37510 | if (!codec) |
| 164 | 35 | codec = avctx->codec; | |
| 165 | 37510 | codec2 = ffcodec(codec); | |
| 166 | |||
| 167 |
2/4✓ Branch 0 taken 37510 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37510 times.
✗ Branch 3 not taken.
|
37510 | if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) || |
| 168 |
2/4✓ Branch 0 taken 37510 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37510 times.
|
37510 | (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 | 37510 | avctx->codec_type = codec->type; | |
| 174 | 37510 | avctx->codec_id = codec->id; | |
| 175 | 37510 | avctx->codec = codec; | |
| 176 | |||
| 177 |
2/4✓ Branch 0 taken 37510 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37510 times.
|
37510 | 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 8936 times.
✓ Branch 1 taken 28574 times.
|
37510 | e = options ? av_dict_get(*options, "codec_whitelist", NULL, 0) : NULL; |
| 183 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37510 times.
|
37510 | 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 37510 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
37510 | 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 15951 times.
✓ Branch 2 taken 21559 times.
|
37510 | avci = ff_codec_is_decoder(codec) ? |
| 195 | 15951 | ff_decode_internal_alloc() : | |
| 196 | 21559 | ff_encode_internal_alloc(); | |
| 197 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37510 times.
|
37510 | if (!avci) { |
| 198 | ✗ | ret = AVERROR(ENOMEM); | |
| 199 | ✗ | goto end; | |
| 200 | } | ||
| 201 | 37510 | avctx->internal = avci; | |
| 202 | |||
| 203 | 37510 | avci->buffer_frame = av_frame_alloc(); | |
| 204 | 37510 | avci->buffer_pkt = av_packet_alloc(); | |
| 205 |
2/4✓ Branch 0 taken 37510 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37510 times.
|
37510 | if (!avci->buffer_frame || !avci->buffer_pkt) { |
| 206 | ✗ | ret = AVERROR(ENOMEM); | |
| 207 | ✗ | goto free_and_end; | |
| 208 | } | ||
| 209 | |||
| 210 |
2/2✓ Branch 0 taken 16633 times.
✓ Branch 1 taken 20877 times.
|
37510 | if (codec2->priv_data_size > 0) { |
| 211 |
2/2✓ Branch 0 taken 8404 times.
✓ Branch 1 taken 8229 times.
|
16633 | if (!avctx->priv_data) { |
| 212 | 8404 | avctx->priv_data = av_mallocz(codec2->priv_data_size); | |
| 213 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8404 times.
|
8404 | if (!avctx->priv_data) { |
| 214 | ✗ | ret = AVERROR(ENOMEM); | |
| 215 | ✗ | goto free_and_end; | |
| 216 | } | ||
| 217 |
2/2✓ Branch 0 taken 2500 times.
✓ Branch 1 taken 5904 times.
|
8404 | if (codec->priv_class) { |
| 218 | 2500 | *(const AVClass **)avctx->priv_data = codec->priv_class; | |
| 219 | 2500 | av_opt_set_defaults(avctx->priv_data); | |
| 220 | } | ||
| 221 | } | ||
| 222 | } else { | ||
| 223 | 20877 | avctx->priv_data = NULL; | |
| 224 | } | ||
| 225 | |||
| 226 | 37510 | ret = av_opt_set_dict2(avctx, options, AV_OPT_SEARCH_CHILDREN); | |
| 227 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37510 times.
|
37510 | 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 34 times.
✓ Branch 1 taken 37476 times.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 28 times.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
|
37510 | 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 34 times.
✓ Branch 1 taken 37476 times.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
|
37510 | if (avctx->coded_width && avctx->coded_height) |
| 234 | 34 | ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); | |
| 235 |
3/4✓ Branch 0 taken 28154 times.
✓ Branch 1 taken 9322 times.
✓ Branch 2 taken 28154 times.
✗ Branch 3 not taken.
|
37476 | else if (avctx->width && avctx->height) |
| 236 | 28154 | ret = ff_set_dimensions(avctx, avctx->width, avctx->height); | |
| 237 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37510 times.
|
37510 | if (ret < 0) |
| 238 | ✗ | goto free_and_end; | |
| 239 | } | ||
| 240 | |||
| 241 |
5/8✓ Branch 0 taken 9322 times.
✓ Branch 1 taken 28188 times.
✓ Branch 2 taken 9322 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9322 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9322 times.
|
37510 | if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height) |
| 242 |
1/2✓ Branch 1 taken 28188 times.
✗ Branch 2 not taken.
|
28188 | && ( 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 28188 times.
|
28188 | || 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 28188 times.
✓ Branch 1 taken 9322 times.
✓ Branch 2 taken 28188 times.
✗ Branch 3 not taken.
|
37510 | if (avctx->width > 0 && avctx->height > 0) { |
| 249 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28188 times.
|
28188 | 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 37510 times.
✗ Branch 1 not taken.
|
37510 | if (avctx->sample_rate < 0 || |
| 261 |
4/4✓ Branch 0 taken 32899 times.
✓ Branch 1 taken 4611 times.
✓ Branch 2 taken 242 times.
✓ Branch 3 taken 32657 times.
|
37510 | 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 37510 times.
|
37510 | 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 4853 times.
✓ Branch 1 taken 32657 times.
✓ Branch 2 taken 241 times.
✓ Branch 3 taken 4612 times.
|
37510 | if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && !avctx->ch_layout.nb_channels |
| 276 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 241 times.
|
241 | && !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) { |
| 277 | ✗ | av_log(avctx, AV_LOG_ERROR, "%s requires channel layout to be set\n", | |
| 278 | ✗ | ff_codec_is_decoder(codec) ? "Decoder" : "Encoder"); | |
| 279 | ✗ | ret = AVERROR(EINVAL); | |
| 280 | ✗ | goto free_and_end; | |
| 281 | } | ||
| 282 |
3/4✓ Branch 0 taken 4612 times.
✓ Branch 1 taken 32898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4612 times.
|
37510 | 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 37510 times.
|
37510 | 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 | 37510 | avctx->frame_num = 0; | |
| 294 | 37510 | avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id); | |
| 295 | |||
| 296 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 37503 times.
|
37510 | 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 4853 times.
✓ Branch 1 taken 32657 times.
|
37510 | if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && |
| 313 |
3/4✓ Branch 0 taken 1343 times.
✓ Branch 1 taken 3510 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1343 times.
|
4853 | (!avctx->time_base.num || !avctx->time_base.den)) { |
| 314 | 3510 | avctx->time_base.num = 1; | |
| 315 | 3510 | avctx->time_base.den = avctx->sample_rate; | |
| 316 | } | ||
| 317 | |||
| 318 |
2/2✓ Branch 1 taken 21559 times.
✓ Branch 2 taken 15951 times.
|
37510 | if (ff_codec_is_encoder(avctx->codec)) |
| 319 | 21559 | ret = ff_encode_preinit(avctx); | |
| 320 | else | ||
| 321 | 15951 | ret = ff_decode_preinit(avctx); | |
| 322 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37510 times.
|
37510 | if (ret < 0) |
| 323 | ✗ | goto free_and_end; | |
| 324 | |||
| 325 |
2/2✓ Branch 0 taken 35845 times.
✓ Branch 1 taken 1665 times.
|
37510 | if (HAVE_THREADS && !avci->frame_thread_encoder) { |
| 326 | /* Frame-threaded decoders call FFCodec.init for their child contexts. */ | ||
| 327 | 35845 | lock_avcodec(codec2); | |
| 328 | 35845 | ret = ff_thread_init(avctx); | |
| 329 | 35845 | unlock_avcodec(codec2); | |
| 330 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35845 times.
|
35845 | 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 1675 times.
✓ Branch 1 taken 35835 times.
|
37510 | if (!(avctx->active_thread_type & FF_THREAD_FRAME) || |
| 338 |
2/2✓ Branch 0 taken 1665 times.
✓ Branch 1 taken 10 times.
|
1675 | avci->frame_thread_encoder) { |
| 339 |
2/2✓ Branch 0 taken 30908 times.
✓ Branch 1 taken 6592 times.
|
37500 | if (codec2->init) { |
| 340 | 30908 | lock_avcodec(codec2); | |
| 341 | 30908 | ret = codec2->init(avctx); | |
| 342 | 30908 | unlock_avcodec(codec2); | |
| 343 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 30900 times.
|
30908 | 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 | 37492 | avci->needs_close = 1; | |
| 349 | } | ||
| 350 | |||
| 351 | 37502 | ret=0; | |
| 352 | |||
| 353 |
2/2✓ Branch 1 taken 15943 times.
✓ Branch 2 taken 21559 times.
|
37502 | if (ff_codec_is_decoder(avctx->codec)) { |
| 354 |
2/2✓ Branch 0 taken 11207 times.
✓ Branch 1 taken 4736 times.
|
15943 | if (!avctx->bit_rate) |
| 355 | 11207 | avctx->bit_rate = get_bit_rate(avctx); | |
| 356 | |||
| 357 | 15943 | avci->skip_samples = avctx->delay; | |
| 358 | |||
| 359 | /* validate channel layout from the decoder */ | ||
| 360 |
3/4✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 12631 times.
✓ Branch 3 taken 3312 times.
✗ Branch 4 not taken.
|
15943 | if ((avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) || |
| 361 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15943 times.
|
15943 | avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) { |
| 362 | ✗ | ret = AVERROR(EINVAL); | |
| 363 | ✗ | goto free_and_end; | |
| 364 | } | ||
| 365 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15943 times.
|
15943 | if (avctx->bits_per_coded_sample < 0) { |
| 366 | ✗ | ret = AVERROR(EINVAL); | |
| 367 | ✗ | goto free_and_end; | |
| 368 | } | ||
| 369 | } | ||
| 370 |
2/2✓ Branch 0 taken 5364 times.
✓ Branch 1 taken 32138 times.
|
37502 | if (codec->priv_class) |
| 371 |
1/2✓ Branch 0 taken 5364 times.
✗ Branch 1 not taken.
|
5364 | av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class); |
| 372 | |||
| 373 | 37502 | end: | |
| 374 | |||
| 375 | 37510 | return ret; | |
| 376 | 8 | free_and_end: | |
| 377 | 8 | ff_codec_close(avctx); | |
| 378 | 8 | goto end; | |
| 379 | } | ||
| 380 | |||
| 381 | 111 | void avcodec_flush_buffers(AVCodecContext *avctx) | |
| 382 | { | ||
| 383 | 111 | AVCodecInternal *avci = avctx->internal; | |
| 384 | |||
| 385 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 111 times.
|
111 | if (av_codec_is_encoder(avctx->codec)) { |
| 386 | ✗ | int caps = avctx->codec->capabilities; | |
| 387 | |||
| 388 | ✗ | if (!(caps & AV_CODEC_CAP_ENCODER_FLUSH)) { | |
| 389 | // Only encoders that explicitly declare support for it can be | ||
| 390 | // flushed. Otherwise, this is a no-op. | ||
| 391 | ✗ | av_log(avctx, AV_LOG_WARNING, "Ignoring attempt to flush encoder " | |
| 392 | "that doesn't support it\n"); | ||
| 393 | ✗ | return; | |
| 394 | } | ||
| 395 | ✗ | ff_encode_flush_buffers(avctx); | |
| 396 | } else | ||
| 397 | 111 | ff_decode_flush_buffers(avctx); | |
| 398 | |||
| 399 | 111 | avci->draining = 0; | |
| 400 | 111 | avci->draining_done = 0; | |
| 401 |
1/2✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
|
111 | if (avci->buffer_frame) |
| 402 | 111 | av_frame_unref(avci->buffer_frame); | |
| 403 |
1/2✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
|
111 | if (avci->buffer_pkt) |
| 404 | 111 | av_packet_unref(avci->buffer_pkt); | |
| 405 | |||
| 406 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
|
111 | if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME && |
| 407 | ✗ | !avci->is_frame_mt) | |
| 408 | ✗ | ff_thread_flush(avctx); | |
| 409 |
2/2✓ Branch 1 taken 34 times.
✓ Branch 2 taken 77 times.
|
111 | else if (ffcodec(avctx->codec)->flush) |
| 410 | 34 | ffcodec(avctx->codec)->flush(avctx); | |
| 411 | } | ||
| 412 | |||
| 413 | 1075 | void avsubtitle_free(AVSubtitle *sub) | |
| 414 | { | ||
| 415 | int i; | ||
| 416 | |||
| 417 |
2/2✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 1075 times.
|
2095 | for (i = 0; i < sub->num_rects; i++) { |
| 418 | 1020 | AVSubtitleRect *const rect = sub->rects[i]; | |
| 419 | |||
| 420 | 1020 | av_freep(&rect->data[0]); | |
| 421 | 1020 | av_freep(&rect->data[1]); | |
| 422 | 1020 | av_freep(&rect->data[2]); | |
| 423 | 1020 | av_freep(&rect->data[3]); | |
| 424 | 1020 | av_freep(&rect->text); | |
| 425 | 1020 | av_freep(&rect->ass); | |
| 426 | |||
| 427 | 1020 | av_freep(&sub->rects[i]); | |
| 428 | } | ||
| 429 | |||
| 430 | 1075 | av_freep(&sub->rects); | |
| 431 | |||
| 432 | 1075 | memset(sub, 0, sizeof(*sub)); | |
| 433 | 1075 | } | |
| 434 | |||
| 435 | 64450 | av_cold void ff_codec_close(AVCodecContext *avctx) | |
| 436 | { | ||
| 437 | int i; | ||
| 438 | |||
| 439 |
2/2✓ Branch 1 taken 37510 times.
✓ Branch 2 taken 26940 times.
|
64450 | if (avcodec_is_open(avctx)) { |
| 440 | 37510 | AVCodecInternal *avci = avctx->internal; | |
| 441 | |||
| 442 | #if CONFIG_FRAME_THREAD_ENCODER | ||
| 443 |
4/4✓ Branch 0 taken 14973 times.
✓ Branch 1 taken 22537 times.
✓ Branch 2 taken 1665 times.
✓ Branch 3 taken 13308 times.
|
37510 | if (avci->frame_thread_encoder && avctx->thread_count > 1) { |
| 444 | 1665 | ff_frame_thread_encoder_free(avctx); | |
| 445 | } | ||
| 446 | #endif | ||
| 447 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 37474 times.
|
37510 | if (HAVE_THREADS && avci->thread_ctx) |
| 448 | 36 | ff_thread_free(avctx); | |
| 449 |
4/4✓ Branch 0 taken 37492 times.
✓ Branch 1 taken 18 times.
✓ Branch 3 taken 7673 times.
✓ Branch 4 taken 29819 times.
|
37510 | if (avci->needs_close && ffcodec(avctx->codec)->close) |
| 450 | 7673 | ffcodec(avctx->codec)->close(avctx); | |
| 451 | 37510 | avci->byte_buffer_size = 0; | |
| 452 | 37510 | av_freep(&avci->byte_buffer); | |
| 453 | 37510 | av_frame_free(&avci->buffer_frame); | |
| 454 | 37510 | av_packet_free(&avci->buffer_pkt); | |
| 455 | 37510 | av_packet_free(&avci->last_pkt_props); | |
| 456 | |||
| 457 | 37510 | av_packet_free(&avci->in_pkt); | |
| 458 | 37510 | av_frame_free(&avci->in_frame); | |
| 459 | 37510 | av_frame_free(&avci->recon_frame); | |
| 460 | |||
| 461 | 37510 | av_refstruct_unref(&avci->pool); | |
| 462 | 37510 | av_refstruct_pool_uninit(&avci->progress_frame_pool); | |
| 463 |
2/2✓ Branch 1 taken 15951 times.
✓ Branch 2 taken 21559 times.
|
37510 | if (av_codec_is_decoder(avctx->codec)) |
| 464 | 15951 | ff_decode_internal_uninit(avctx); | |
| 465 | |||
| 466 | 37510 | ff_hwaccel_uninit(avctx); | |
| 467 | |||
| 468 | 37510 | av_bsf_free(&avci->bsf); | |
| 469 | |||
| 470 | #if CONFIG_LCMS2 | ||
| 471 | ff_icc_context_uninit(&avci->icc); | ||
| 472 | #endif | ||
| 473 | |||
| 474 | 37510 | av_freep(&avctx->internal); | |
| 475 | } | ||
| 476 | |||
| 477 |
2/2✓ Branch 0 taken 4382 times.
✓ Branch 1 taken 64450 times.
|
68832 | for (i = 0; i < avctx->nb_coded_side_data; i++) |
| 478 | 4382 | av_freep(&avctx->coded_side_data[i].data); | |
| 479 | 64450 | av_freep(&avctx->coded_side_data); | |
| 480 | 64450 | avctx->nb_coded_side_data = 0; | |
| 481 | 64450 | av_frame_side_data_free(&avctx->decoded_side_data, | |
| 482 | &avctx->nb_decoded_side_data); | ||
| 483 | |||
| 484 | 64450 | av_buffer_unref(&avctx->hw_frames_ctx); | |
| 485 | 64450 | av_buffer_unref(&avctx->hw_device_ctx); | |
| 486 | |||
| 487 |
5/6✓ Branch 0 taken 25029 times.
✓ Branch 1 taken 39421 times.
✓ Branch 2 taken 25029 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7864 times.
✓ Branch 5 taken 17165 times.
|
64450 | if (avctx->priv_data && avctx->codec && avctx->codec->priv_class) |
| 488 | 7864 | av_opt_free(avctx->priv_data); | |
| 489 | 64450 | av_opt_free(avctx); | |
| 490 | 64450 | av_freep(&avctx->priv_data); | |
| 491 |
2/2✓ Branch 1 taken 21559 times.
✓ Branch 2 taken 42891 times.
|
64450 | if (av_codec_is_encoder(avctx->codec)) { |
| 492 | 21559 | av_freep(&avctx->extradata); | |
| 493 | 21559 | avctx->extradata_size = 0; | |
| 494 |
2/2✓ Branch 1 taken 32857 times.
✓ Branch 2 taken 10034 times.
|
42891 | } else if (av_codec_is_decoder(avctx->codec)) |
| 495 | 32857 | av_freep(&avctx->subtitle_header); | |
| 496 | |||
| 497 | 64450 | avctx->codec = NULL; | |
| 498 | 64450 | avctx->active_thread_type = 0; | |
| 499 | 64450 | } | |
| 500 | |||
| 501 | 22556 | static const char *unknown_if_null(const char *str) | |
| 502 | { | ||
| 503 |
1/2✓ Branch 0 taken 22556 times.
✗ Branch 1 not taken.
|
22556 | return str ? str : "unknown"; |
| 504 | } | ||
| 505 | |||
| 506 | 17535 | void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) | |
| 507 | { | ||
| 508 | const char *codec_type; | ||
| 509 | const char *codec_name; | ||
| 510 | 17535 | const char *profile = NULL; | |
| 511 | AVBPrint bprint; | ||
| 512 | int64_t bitrate; | ||
| 513 | 17535 | int new_line = 0; | |
| 514 | AVRational display_aspect_ratio; | ||
| 515 |
2/2✓ Branch 0 taken 17509 times.
✓ Branch 1 taken 26 times.
|
17535 | const char *separator = enc->dump_separator ? (const char *)enc->dump_separator : ", "; |
| 516 | const char *str; | ||
| 517 | |||
| 518 |
2/4✓ Branch 0 taken 17535 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17535 times.
|
17535 | if (!buf || buf_size <= 0) |
| 519 | 9 | return; | |
| 520 | 17535 | av_bprint_init_for_buffer(&bprint, buf, buf_size); | |
| 521 | 17535 | codec_type = av_get_media_type_string(enc->codec_type); | |
| 522 | 17535 | codec_name = avcodec_get_name(enc->codec_id); | |
| 523 | 17535 | profile = avcodec_profile_name(enc->codec_id, enc->profile); | |
| 524 | |||
| 525 |
1/2✓ Branch 0 taken 17535 times.
✗ Branch 1 not taken.
|
17535 | av_bprintf(&bprint, "%s: %s", codec_type ? codec_type : "unknown", |
| 526 | codec_name); | ||
| 527 | 17535 | buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */ | |
| 528 | |||
| 529 |
4/4✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 9155 times.
✓ Branch 2 taken 323 times.
✓ Branch 3 taken 8057 times.
|
17535 | if (enc->codec && strcmp(enc->codec->name, codec_name)) |
| 530 | 323 | av_bprintf(&bprint, " (%s)", enc->codec->name); | |
| 531 | |||
| 532 |
2/2✓ Branch 0 taken 2091 times.
✓ Branch 1 taken 15444 times.
|
17535 | if (profile) |
| 533 | 2091 | av_bprintf(&bprint, " (%s)", profile); | |
| 534 |
2/2✓ Branch 0 taken 13516 times.
✓ Branch 1 taken 4019 times.
|
17535 | if ( enc->codec_type == AVMEDIA_TYPE_VIDEO |
| 535 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13516 times.
|
13516 | && av_log_get_level() >= AV_LOG_VERBOSE |
| 536 | ✗ | && enc->refs) | |
| 537 | ✗ | av_bprintf(&bprint, ", %d reference frame%s", | |
| 538 | ✗ | enc->refs, enc->refs > 1 ? "s" : ""); | |
| 539 | |||
| 540 |
2/2✓ Branch 0 taken 9904 times.
✓ Branch 1 taken 7631 times.
|
17535 | if (enc->codec_tag) |
| 541 | 9904 | av_bprintf(&bprint, " (%s / 0x%04X)", | |
| 542 | 9904 | av_fourcc2str(enc->codec_tag), enc->codec_tag); | |
| 543 | |||
| 544 |
5/5✓ Branch 0 taken 13516 times.
✓ Branch 1 taken 3740 times.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 180 times.
✓ Branch 4 taken 9 times.
|
17535 | switch (enc->codec_type) { |
| 545 | 13516 | case AVMEDIA_TYPE_VIDEO: | |
| 546 | { | ||
| 547 | unsigned len; | ||
| 548 | |||
| 549 | 13516 | av_bprintf(&bprint, "%s%s", separator, | |
| 550 |
2/2✓ Branch 0 taken 13466 times.
✓ Branch 1 taken 50 times.
|
13516 | enc->pix_fmt == AV_PIX_FMT_NONE ? "none" : |
| 551 | 13466 | unknown_if_null(av_get_pix_fmt_name(enc->pix_fmt))); | |
| 552 | |||
| 553 | 13516 | av_bprint_chars(&bprint, '(', 1); | |
| 554 | 13516 | len = bprint.len; | |
| 555 | |||
| 556 | /* The following check ensures that '(' has been written | ||
| 557 | * and therefore allows us to erase it if it turns out | ||
| 558 | * to be unnecessary. */ | ||
| 559 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13516 times.
|
13516 | if (!av_bprint_is_complete(&bprint)) |
| 560 | ✗ | return; | |
| 561 | |||
| 562 |
3/4✓ Branch 0 taken 1211 times.
✓ Branch 1 taken 12305 times.
✓ Branch 2 taken 1211 times.
✗ Branch 3 not taken.
|
13516 | if (enc->bits_per_raw_sample && enc->pix_fmt != AV_PIX_FMT_NONE && |
| 563 |
2/2✓ Branch 1 taken 27 times.
✓ Branch 2 taken 1184 times.
|
1211 | enc->bits_per_raw_sample < av_pix_fmt_desc_get(enc->pix_fmt)->comp[0].depth) |
| 564 | 27 | av_bprintf(&bprint, "%d bpc, ", enc->bits_per_raw_sample); | |
| 565 |
3/4✓ Branch 0 taken 11176 times.
✓ Branch 1 taken 2340 times.
✓ Branch 2 taken 11176 times.
✗ Branch 3 not taken.
|
24692 | if (enc->color_range != AVCOL_RANGE_UNSPECIFIED && |
| 566 | 11176 | (str = av_color_range_name(enc->color_range))) | |
| 567 | 11176 | av_bprintf(&bprint, "%s, ", str); | |
| 568 | |||
| 569 |
2/2✓ Branch 0 taken 10605 times.
✓ Branch 1 taken 2911 times.
|
13516 | if (enc->colorspace != AVCOL_SPC_UNSPECIFIED || |
| 570 |
2/2✓ Branch 0 taken 10603 times.
✓ Branch 1 taken 2 times.
|
10605 | enc->color_primaries != AVCOL_PRI_UNSPECIFIED || |
| 571 |
2/2✓ Branch 0 taken 117 times.
✓ Branch 1 taken 10486 times.
|
10603 | enc->color_trc != AVCOL_TRC_UNSPECIFIED) { |
| 572 | 3030 | const char *col = unknown_if_null(av_color_space_name(enc->colorspace)); | |
| 573 | 3030 | const char *pri = unknown_if_null(av_color_primaries_name(enc->color_primaries)); | |
| 574 | 3030 | const char *trc = unknown_if_null(av_color_transfer_name(enc->color_trc)); | |
| 575 |
4/4✓ Branch 0 taken 290 times.
✓ Branch 1 taken 2740 times.
✓ Branch 2 taken 132 times.
✓ Branch 3 taken 158 times.
|
3030 | if (strcmp(col, pri) || strcmp(col, trc)) { |
| 576 | 2872 | new_line = 1; | |
| 577 | 2872 | av_bprintf(&bprint, "%s/%s/%s, ", col, pri, trc); | |
| 578 | } else | ||
| 579 | 158 | av_bprintf(&bprint, "%s, ", col); | |
| 580 | } | ||
| 581 | |||
| 582 |
2/2✓ Branch 0 taken 7579 times.
✓ Branch 1 taken 5937 times.
|
13516 | if (enc->field_order != AV_FIELD_UNKNOWN) { |
| 583 | 7579 | const char *field_order = "progressive"; | |
| 584 |
2/2✓ Branch 0 taken 142 times.
✓ Branch 1 taken 7437 times.
|
7579 | if (enc->field_order == AV_FIELD_TT) |
| 585 | 142 | field_order = "top first"; | |
| 586 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 7386 times.
|
7437 | else if (enc->field_order == AV_FIELD_BB) |
| 587 | 51 | field_order = "bottom first"; | |
| 588 |
2/2✓ Branch 0 taken 362 times.
✓ Branch 1 taken 7024 times.
|
7386 | else if (enc->field_order == AV_FIELD_TB) |
| 589 | 362 | field_order = "top coded first (swapped)"; | |
| 590 |
2/2✓ Branch 0 taken 131 times.
✓ Branch 1 taken 6893 times.
|
7024 | else if (enc->field_order == AV_FIELD_BT) |
| 591 | 131 | field_order = "bottom coded first (swapped)"; | |
| 592 | |||
| 593 | 7579 | av_bprintf(&bprint, "%s, ", field_order); | |
| 594 | } | ||
| 595 | |||
| 596 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13516 times.
|
13516 | if (av_log_get_level() >= AV_LOG_VERBOSE && |
| 597 | ✗ | enc->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED && | |
| 598 | ✗ | (str = av_chroma_location_name(enc->chroma_sample_location))) | |
| 599 | ✗ | av_bprintf(&bprint, "%s, ", str); | |
| 600 | |||
| 601 |
2/2✓ Branch 0 taken 1093 times.
✓ Branch 1 taken 12423 times.
|
13516 | if (len == bprint.len) { |
| 602 | 1093 | bprint.str[len - 1] = '\0'; | |
| 603 | 1093 | bprint.len--; | |
| 604 | } else { | ||
| 605 |
1/2✓ Branch 0 taken 12423 times.
✗ Branch 1 not taken.
|
12423 | if (bprint.len - 2 < bprint.size) { |
| 606 | /* Erase the last ", " */ | ||
| 607 | 12423 | bprint.len -= 2; | |
| 608 | 12423 | bprint.str[bprint.len] = '\0'; | |
| 609 | } | ||
| 610 | 12423 | av_bprint_chars(&bprint, ')', 1); | |
| 611 | } | ||
| 612 | } | ||
| 613 | |||
| 614 |
2/2✓ Branch 0 taken 13496 times.
✓ Branch 1 taken 20 times.
|
13516 | if (enc->width) { |
| 615 |
2/2✓ Branch 0 taken 2870 times.
✓ Branch 1 taken 10626 times.
|
13496 | av_bprintf(&bprint, "%s%dx%d", new_line ? separator : ", ", |
| 616 | enc->width, enc->height); | ||
| 617 | |||
| 618 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13496 times.
|
13496 | if (av_log_get_level() >= AV_LOG_VERBOSE && |
| 619 | ✗ | enc->coded_width && enc->coded_height && | |
| 620 | ✗ | (enc->width != enc->coded_width || | |
| 621 | ✗ | enc->height != enc->coded_height)) | |
| 622 | ✗ | av_bprintf(&bprint, " (%dx%d)", | |
| 623 | enc->coded_width, enc->coded_height); | ||
| 624 | |||
| 625 |
2/2✓ Branch 0 taken 2645 times.
✓ Branch 1 taken 10851 times.
|
13496 | if (enc->sample_aspect_ratio.num) { |
| 626 | 2645 | av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, | |
| 627 | 2645 | enc->width * (int64_t)enc->sample_aspect_ratio.num, | |
| 628 | 2645 | enc->height * (int64_t)enc->sample_aspect_ratio.den, | |
| 629 | 1024 * 1024); | ||
| 630 | 2645 | av_bprintf(&bprint, " [SAR %d:%d DAR %d:%d]", | |
| 631 | enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den, | ||
| 632 | display_aspect_ratio.num, display_aspect_ratio.den); | ||
| 633 | } | ||
| 634 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13496 times.
|
13496 | if (av_log_get_level() >= AV_LOG_DEBUG) { |
| 635 | ✗ | int g = av_gcd(enc->time_base.num, enc->time_base.den); | |
| 636 | ✗ | av_bprintf(&bprint, ", %d/%d", | |
| 637 | ✗ | enc->time_base.num / g, enc->time_base.den / g); | |
| 638 | } | ||
| 639 | } | ||
| 640 |
2/2✓ Branch 0 taken 7230 times.
✓ Branch 1 taken 6286 times.
|
13516 | if (encode) { |
| 641 | 7230 | av_bprintf(&bprint, ", q=%d-%d", enc->qmin, enc->qmax); | |
| 642 | } else { | ||
| 643 | #if FF_API_CODEC_PROPS | ||
| 644 | FF_DISABLE_DEPRECATION_WARNINGS | ||
| 645 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6286 times.
|
6286 | if (enc->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS) |
| 646 | ✗ | av_bprintf(&bprint, ", Closed Captions"); | |
| 647 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6286 times.
|
6286 | if (enc->properties & FF_CODEC_PROPERTY_FILM_GRAIN) |
| 648 | ✗ | av_bprintf(&bprint, ", Film Grain"); | |
| 649 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6286 times.
|
6286 | if (enc->properties & FF_CODEC_PROPERTY_LOSSLESS) |
| 650 | ✗ | av_bprintf(&bprint, ", lossless"); | |
| 651 | FF_ENABLE_DEPRECATION_WARNINGS | ||
| 652 | #endif | ||
| 653 | } | ||
| 654 | 13516 | break; | |
| 655 | 3740 | case AVMEDIA_TYPE_AUDIO: | |
| 656 | 3740 | av_bprintf(&bprint, "%s", separator); | |
| 657 | |||
| 658 |
2/2✓ Branch 0 taken 3724 times.
✓ Branch 1 taken 16 times.
|
3740 | if (enc->sample_rate) { |
| 659 | 3724 | av_bprintf(&bprint, "%d Hz, ", enc->sample_rate); | |
| 660 | } | ||
| 661 | 3740 | av_channel_layout_describe_bprint(&enc->ch_layout, &bprint); | |
| 662 |
2/4✓ Branch 0 taken 3740 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3740 times.
✗ Branch 3 not taken.
|
7480 | if (enc->sample_fmt != AV_SAMPLE_FMT_NONE && |
| 663 | 3740 | (str = av_get_sample_fmt_name(enc->sample_fmt))) { | |
| 664 | 3740 | av_bprintf(&bprint, ", %s", str); | |
| 665 | } | ||
| 666 |
2/2✓ Branch 0 taken 1985 times.
✓ Branch 1 taken 1755 times.
|
3740 | if ( enc->bits_per_raw_sample > 0 |
| 667 |
2/2✓ Branch 1 taken 239 times.
✓ Branch 2 taken 1746 times.
|
1985 | && enc->bits_per_raw_sample != av_get_bytes_per_sample(enc->sample_fmt) * 8) |
| 668 | 239 | av_bprintf(&bprint, " (%d bit)", enc->bits_per_raw_sample); | |
| 669 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3736 times.
|
3740 | if (av_log_get_level() >= AV_LOG_VERBOSE) { |
| 670 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (enc->initial_padding) |
| 671 | 2 | av_bprintf(&bprint, ", delay %d", enc->initial_padding); | |
| 672 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (enc->trailing_padding) |
| 673 | ✗ | av_bprintf(&bprint, ", padding %d", enc->trailing_padding); | |
| 674 | } | ||
| 675 | 3740 | break; | |
| 676 | 90 | case AVMEDIA_TYPE_DATA: | |
| 677 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
|
90 | if (av_log_get_level() >= AV_LOG_DEBUG) { |
| 678 | ✗ | int g = av_gcd(enc->time_base.num, enc->time_base.den); | |
| 679 | ✗ | if (g) | |
| 680 | ✗ | av_bprintf(&bprint, ", %d/%d", | |
| 681 | ✗ | enc->time_base.num / g, enc->time_base.den / g); | |
| 682 | } | ||
| 683 | 90 | break; | |
| 684 | 180 | case AVMEDIA_TYPE_SUBTITLE: | |
| 685 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 147 times.
|
180 | if (enc->width) |
| 686 | 33 | av_bprintf(&bprint, ", %dx%d", enc->width, enc->height); | |
| 687 | 180 | break; | |
| 688 | 9 | default: | |
| 689 | 9 | return; | |
| 690 | } | ||
| 691 |
2/2✓ Branch 0 taken 9033 times.
✓ Branch 1 taken 8493 times.
|
17526 | if (encode) { |
| 692 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9033 times.
|
9033 | if (enc->flags & AV_CODEC_FLAG_PASS1) |
| 693 | ✗ | av_bprintf(&bprint, ", pass 1"); | |
| 694 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9033 times.
|
9033 | if (enc->flags & AV_CODEC_FLAG_PASS2) |
| 695 | ✗ | av_bprintf(&bprint, ", pass 2"); | |
| 696 | } | ||
| 697 | 17526 | bitrate = get_bit_rate(enc); | |
| 698 |
2/2✓ Branch 0 taken 11293 times.
✓ Branch 1 taken 6233 times.
|
17526 | if (bitrate != 0) { |
| 699 | 11293 | av_bprintf(&bprint, ", %"PRId64" kb/s", bitrate / 1000); | |
| 700 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6233 times.
|
6233 | } else if (enc->rc_max_rate > 0) { |
| 701 | ✗ | av_bprintf(&bprint, ", max. %"PRId64" kb/s", enc->rc_max_rate / 1000); | |
| 702 | } | ||
| 703 | } | ||
| 704 | |||
| 705 | 2873104 | int avcodec_is_open(AVCodecContext *s) | |
| 706 | { | ||
| 707 | 2873104 | return !!s->internal; | |
| 708 | } | ||
| 709 | |||
| 710 | 778163 | int attribute_align_arg avcodec_receive_frame_flags(AVCodecContext *avctx, | |
| 711 | AVFrame *frame, unsigned flags) | ||
| 712 | { | ||
| 713 | 778163 | av_frame_unref(frame); | |
| 714 | |||
| 715 |
2/4✓ Branch 1 taken 778163 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 778163 times.
|
778163 | if (!avcodec_is_open(avctx) || !avctx->codec) |
| 716 | ✗ | return AVERROR(EINVAL); | |
| 717 | |||
| 718 |
2/2✓ Branch 1 taken 778101 times.
✓ Branch 2 taken 62 times.
|
778163 | if (ff_codec_is_decoder(avctx->codec)) |
| 719 | 778101 | return ff_decode_receive_frame(avctx, frame, flags); | |
| 720 | 62 | return ff_encode_receive_frame(avctx, frame); | |
| 721 | } | ||
| 722 | |||
| 723 | 27692 | int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame) | |
| 724 | { | ||
| 725 | 27692 | return avcodec_receive_frame_flags(avctx, frame, 0); | |
| 726 | } | ||
| 727 | |||
| 728 | #define WRAP_CONFIG(allowed_type, field, var, field_type, sentinel_check) \ | ||
| 729 | do { \ | ||
| 730 | if (codec->type != (allowed_type)) \ | ||
| 731 | return AVERROR(EINVAL); \ | ||
| 732 | const field_type *ptr = codec->field; \ | ||
| 733 | *out_configs = ptr; \ | ||
| 734 | if (ptr) { \ | ||
| 735 | for (int i = 0;; i++) { \ | ||
| 736 | const field_type var = ptr[i]; \ | ||
| 737 | if (sentinel_check) { \ | ||
| 738 | *out_num_configs = i; \ | ||
| 739 | break; \ | ||
| 740 | } \ | ||
| 741 | } \ | ||
| 742 | } else \ | ||
| 743 | *out_num_configs = 0; \ | ||
| 744 | return 0; \ | ||
| 745 | } while (0) | ||
| 746 | |||
| 747 | static const enum AVColorRange color_range_tab[] = { | ||
| 748 | AVCOL_RANGE_MPEG, AVCOL_RANGE_JPEG, AVCOL_RANGE_UNSPECIFIED, | ||
| 749 | AVCOL_RANGE_MPEG, AVCOL_RANGE_UNSPECIFIED, | ||
| 750 | }; | ||
| 751 | |||
| 752 | static const enum AVAlphaMode alpha_mode_tab[] = { | ||
| 753 | AVALPHA_MODE_PREMULTIPLIED, AVALPHA_MODE_STRAIGHT, AVALPHA_MODE_UNSPECIFIED, | ||
| 754 | AVALPHA_MODE_PREMULTIPLIED, AVALPHA_MODE_UNSPECIFIED | ||
| 755 | }; | ||
| 756 | |||
| 757 | static_assert((int)AVCOL_RANGE_MPEG == (int)AVALPHA_MODE_PREMULTIPLIED, "unexpected enum values"); | ||
| 758 | static_assert((int)AVCOL_RANGE_JPEG == (int)AVALPHA_MODE_STRAIGHT, "unexpected enum values"); | ||
| 759 | static_assert(AVCOL_RANGE_UNSPECIFIED == 0 && AVALPHA_MODE_UNSPECIFIED == 0, "unexpected enum values"); | ||
| 760 | static_assert(AVCOL_RANGE_NB == 3 && AVALPHA_MODE_NB == 3, "unexpected enum values"); | ||
| 761 | |||
| 762 | static const uint8_t offset_tab[] = { | ||
| 763 | [AVCOL_RANGE_MPEG] = 3, | ||
| 764 | [AVCOL_RANGE_JPEG] = 1, | ||
| 765 | [AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG] = 0, | ||
| 766 | }; | ||
| 767 | |||
| 768 | 70297 | int ff_default_get_supported_config(const AVCodecContext *avctx, | |
| 769 | const AVCodec *codec, | ||
| 770 | enum AVCodecConfig config, | ||
| 771 | unsigned flags, | ||
| 772 | const void **out_configs, | ||
| 773 | int *out_num_configs) | ||
| 774 | { | ||
| 775 | 70297 | const FFCodec *codec2 = ffcodec(codec); | |
| 776 | |||
| 777 |
8/9✓ Branch 0 taken 32353 times.
✓ Branch 1 taken 6847 times.
✓ Branch 2 taken 2702 times.
✓ Branch 3 taken 2702 times.
✓ Branch 4 taken 2702 times.
✓ Branch 5 taken 6821 times.
✓ Branch 6 taken 6848 times.
✓ Branch 7 taken 9322 times.
✗ Branch 8 not taken.
|
70297 | switch (config) { |
| 778 | FF_DISABLE_DEPRECATION_WARNINGS | ||
| 779 | 32353 | case AV_CODEC_CONFIG_PIX_FORMAT: | |
| 780 |
5/6✗ Branch 0 not taken.
✓ Branch 1 taken 32353 times.
✓ Branch 2 taken 1813 times.
✓ Branch 3 taken 30540 times.
✓ Branch 4 taken 1813 times.
✓ Branch 5 taken 20002 times.
|
54168 | WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, pix_fmts, pix_fmt, enum AVPixelFormat, pix_fmt == AV_PIX_FMT_NONE); |
| 781 | 6847 | case AV_CODEC_CONFIG_FRAME_RATE: | |
| 782 |
5/6✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
✓ Branch 2 taken 57 times.
✓ Branch 3 taken 6790 times.
✓ Branch 4 taken 57 times.
✓ Branch 5 taken 2995 times.
|
9842 | WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, supported_framerates, framerate, AVRational, framerate.num == 0); |
| 783 | 2702 | case AV_CODEC_CONFIG_SAMPLE_RATE: | |
| 784 |
5/6✗ Branch 0 not taken.
✓ Branch 1 taken 2702 times.
✓ Branch 2 taken 128 times.
✓ Branch 3 taken 2574 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 736 times.
|
3566 | WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, supported_samplerates, samplerate, int, samplerate == 0); |
| 785 | 2702 | case AV_CODEC_CONFIG_SAMPLE_FORMAT: | |
| 786 |
4/6✗ Branch 0 not taken.
✓ Branch 1 taken 2702 times.
✓ Branch 2 taken 2702 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2702 times.
✓ Branch 5 taken 2930 times.
|
8334 | WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, sample_fmts, sample_fmt, enum AVSampleFormat, sample_fmt == AV_SAMPLE_FMT_NONE); |
| 787 | 2702 | case AV_CODEC_CONFIG_CHANNEL_LAYOUT: | |
| 788 |
5/6✗ Branch 0 not taken.
✓ Branch 1 taken 2702 times.
✓ Branch 2 taken 158 times.
✓ Branch 3 taken 2544 times.
✓ Branch 4 taken 158 times.
✓ Branch 5 taken 772 times.
|
3474 | WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, ch_layouts, ch_layout, AVChannelLayout, ch_layout.nb_channels == 0); |
| 789 | FF_ENABLE_DEPRECATION_WARNINGS | ||
| 790 | |||
| 791 | 6821 | case AV_CODEC_CONFIG_COLOR_RANGE: | |
| 792 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6821 times.
|
6821 | if (codec->type != AVMEDIA_TYPE_VIDEO) |
| 793 | ✗ | return AVERROR(EINVAL); | |
| 794 | 6821 | unsigned color_ranges = codec2->color_ranges; | |
| 795 |
2/2✓ Branch 0 taken 475 times.
✓ Branch 1 taken 6346 times.
|
6821 | if (color_ranges) |
| 796 | 475 | *out_configs = color_range_tab + offset_tab[color_ranges]; | |
| 797 | else | ||
| 798 | 6346 | *out_configs = NULL; | |
| 799 | 6821 | *out_num_configs = av_popcount(color_ranges); | |
| 800 | 6821 | return 0; | |
| 801 | |||
| 802 | 6848 | case AV_CODEC_CONFIG_COLOR_SPACE: | |
| 803 | 6848 | *out_configs = NULL; | |
| 804 | 6848 | *out_num_configs = 0; | |
| 805 | 6848 | return 0; | |
| 806 | |||
| 807 | 9322 | case AV_CODEC_CONFIG_ALPHA_MODE: | |
| 808 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9322 times.
|
9322 | if (codec->type != AVMEDIA_TYPE_VIDEO) |
| 809 | ✗ | return AVERROR(EINVAL); | |
| 810 | 9322 | unsigned alpha_modes = codec2->alpha_modes; | |
| 811 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 9289 times.
|
9322 | if (alpha_modes) |
| 812 | 33 | *out_configs = alpha_mode_tab + offset_tab[alpha_modes]; | |
| 813 | else | ||
| 814 | 9289 | *out_configs = NULL; | |
| 815 | 9322 | *out_num_configs = av_popcount(alpha_modes); | |
| 816 | 9322 | return 0; | |
| 817 | |||
| 818 | ✗ | default: | |
| 819 | ✗ | return AVERROR(EINVAL); | |
| 820 | } | ||
| 821 | } | ||
| 822 | |||
| 823 | 70324 | int avcodec_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec, | |
| 824 | enum AVCodecConfig config, unsigned flags, | ||
| 825 | const void **out, int *out_num) | ||
| 826 | { | ||
| 827 | const FFCodec *codec2; | ||
| 828 | 70324 | int dummy_num = 0; | |
| 829 |
1/2✓ Branch 0 taken 70324 times.
✗ Branch 1 not taken.
|
70324 | if (!codec) |
| 830 | 70324 | codec = avctx->codec; | |
| 831 |
2/2✓ Branch 0 taken 43615 times.
✓ Branch 1 taken 26709 times.
|
70324 | if (!out_num) |
| 832 | 43615 | out_num = &dummy_num; | |
| 833 | |||
| 834 | 70324 | codec2 = ffcodec(codec); | |
| 835 |
2/2✓ Branch 0 taken 187 times.
✓ Branch 1 taken 70137 times.
|
70324 | if (codec2->get_supported_config) { |
| 836 | 187 | return codec2->get_supported_config(avctx, codec, config, flags, out, out_num); | |
| 837 | } else { | ||
| 838 | 70137 | return ff_default_get_supported_config(avctx, codec, config, flags, out, out_num); | |
| 839 | } | ||
| 840 | } | ||
| 841 | |||
| 842 | ✗ | int av_packet_side_data_from_frame(AVPacketSideData **psd, int *pnb_sd, | |
| 843 | const AVFrameSideData *src, unsigned int flags) | ||
| 844 | { | ||
| 845 | ✗ | AVPacketSideData *sd = NULL; | |
| 846 | |||
| 847 | ✗ | for (unsigned j = 0; ff_sd_global_map[j].packet < AV_PKT_DATA_NB; j++) { | |
| 848 | ✗ | if (ff_sd_global_map[j].frame != src->type) | |
| 849 | ✗ | continue; | |
| 850 | |||
| 851 | ✗ | sd = av_packet_side_data_new(psd, pnb_sd, ff_sd_global_map[j].packet, | |
| 852 | ✗ | src->size, 0); | |
| 853 | |||
| 854 | ✗ | if (!sd) | |
| 855 | ✗ | return AVERROR(ENOMEM); | |
| 856 | |||
| 857 | ✗ | memcpy(sd->data, src->data, src->size); | |
| 858 | ✗ | break; | |
| 859 | } | ||
| 860 | |||
| 861 | ✗ | if (!sd) | |
| 862 | ✗ | return AVERROR(EINVAL); | |
| 863 | |||
| 864 | ✗ | return 0; | |
| 865 | } | ||
| 866 | |||
| 867 | ✗ | int av_packet_side_data_to_frame(AVFrameSideData ***psd, int *pnb_sd, | |
| 868 | const AVPacketSideData *src, unsigned int flags) | ||
| 869 | { | ||
| 870 | ✗ | AVFrameSideData *sd = NULL; | |
| 871 | |||
| 872 | ✗ | for (unsigned j = 0; ff_sd_global_map[j].packet < AV_PKT_DATA_NB; j++) { | |
| 873 | ✗ | if (ff_sd_global_map[j].packet != src->type) | |
| 874 | ✗ | continue; | |
| 875 | |||
| 876 | ✗ | sd = av_frame_side_data_new(psd, pnb_sd, ff_sd_global_map[j].frame, | |
| 877 | ✗ | src->size, flags); | |
| 878 | |||
| 879 | ✗ | if (!sd) | |
| 880 | ✗ | return AVERROR(ENOMEM); | |
| 881 | |||
| 882 | ✗ | memcpy(sd->data, src->data, src->size); | |
| 883 | ✗ | break; | |
| 884 | } | ||
| 885 | |||
| 886 | ✗ | if (!sd) | |
| 887 | ✗ | return AVERROR(EINVAL); | |
| 888 | |||
| 889 | ✗ | return 0; | |
| 890 | } | ||
| 891 |