FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/tests/avcodec.c
Date: 2021-10-25 13:57:44
Exec Total Coverage
Lines: 53 87 60.9%
Branches: 70 110 63.6%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "libavutil/opt.h"
20 #include "libavcodec/codec.h"
21 #include "libavcodec/codec_desc.h"
22 #include "libavcodec/internal.h"
23
24 static const char *get_type_string(enum AVMediaType type)
25 {
26 const char *ret = av_get_media_type_string(type);
27 return ret ? ret : "unknown";
28 }
29
30 #define AV_LOG(...) av_log(NULL, AV_LOG_FATAL, __VA_ARGS__)
31 #define ERR_INTERNAL(msg, ...) \
32 do { \
33 AV_LOG(msg, codec->name __VA_ARGS__); \
34 ret = 1; \
35 } while (0)
36 #define ERR(msg) ERR_INTERNAL(msg, )
37 #define ERR_EXT(msg, ...) ERR_INTERNAL(msg, , __VA_ARGS__)
38
39 658 static int priv_data_size_wrong(const AVCodec *codec)
40 {
41
1/2
✓ Branch 0 taken 658 times.
✗ Branch 1 not taken.
658 if (codec->priv_data_size < 0 ||
42
3/4
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 528 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 130 times.
658 codec->priv_class && codec->priv_data_size < sizeof(AVClass*))
43 return 1;
44
3/4
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 528 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 130 times.
658 if (!codec->priv_class || !codec->priv_class->option)
45 528 return 0;
46
2/2
✓ Branch 0 taken 1613 times.
✓ Branch 1 taken 130 times.
1743 for (const AVOption *opt = codec->priv_class->option; opt->name; opt++) {
47
1/2
✓ Branch 0 taken 1613 times.
✗ Branch 1 not taken.
1613 if (opt->offset >= codec->priv_data_size ||
48
3/4
✓ Branch 0 taken 734 times.
✓ Branch 1 taken 879 times.
✓ Branch 2 taken 734 times.
✗ Branch 3 not taken.
1613 opt->type == AV_OPT_TYPE_CONST && opt->offset != 0 ||
49
4/6
✓ Branch 0 taken 879 times.
✓ Branch 1 taken 734 times.
✓ Branch 2 taken 879 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 879 times.
1613 opt->type != AV_OPT_TYPE_CONST && (opt->offset < sizeof(AVClass*) || opt->offset < 0)) {
50 AV_LOG("Option %s offset %d nonsensical\n",
51 opt->name, opt->offset);
52 return 1;
53 }
54 }
55 130 return 0;
56 }
57
58 1 int main(void){
59 1 void *iter = NULL;
60 1 const AVCodec *codec = NULL;
61 1 int ret = 0;
62
63
2/2
✓ Branch 1 taken 658 times.
✓ Branch 2 taken 1 times.
659 while (codec = av_codec_iterate(&iter)) {
64 const AVCodecDescriptor *desc;
65 int is_decoder, is_encoder;
66
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 658 times.
658 if (!codec->name) {
68 AV_LOG("Codec for format %s has no name\n",
69 avcodec_get_name(codec->id));
70 ret = 1;
71 continue;
72 }
73
2/2
✓ Branch 0 taken 301 times.
✓ Branch 1 taken 357 times.
658 if (codec->type != AVMEDIA_TYPE_VIDEO &&
74
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 268 times.
301 codec->type != AVMEDIA_TYPE_AUDIO &&
75
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 codec->type != AVMEDIA_TYPE_SUBTITLE)
76 ERR_EXT("Codec %s has unsupported type %s\n",
77 get_type_string(codec->type));
78
2/2
✓ Branch 0 taken 390 times.
✓ Branch 1 taken 268 times.
658 if (codec->type != AVMEDIA_TYPE_AUDIO) {
79
2/4
✓ Branch 0 taken 390 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 390 times.
✗ Branch 3 not taken.
390 if (codec->channel_layouts || codec->sample_fmts ||
80
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390 times.
390 codec->supported_samplerates)
81 ERR("Non-audio codec %s has audio-only fields set\n");
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390 times.
390 if (codec->capabilities & (AV_CODEC_CAP_SMALL_LAST_FRAME |
83 AV_CODEC_CAP_CHANNEL_CONF |
84 AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
85 ERR("Non-audio codec %s has audio-only capabilities set\n");
86 }
87
2/2
✓ Branch 0 taken 301 times.
✓ Branch 1 taken 357 times.
658 if (codec->type != AVMEDIA_TYPE_VIDEO) {
88
2/4
✓ Branch 0 taken 301 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 301 times.
301 if (codec->pix_fmts || codec->supported_framerates)
89 ERR("Non-video codec %s has video-only fields set\n");
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 301 times.
301 if (codec->caps_internal & FF_CODEC_CAP_EXPORTS_CROPPING)
91 ERR("Non-video codec %s exports cropping\n");
92 }
93
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 657 times.
658 if (codec->caps_internal & FF_CODEC_CAP_SLICE_THREAD_HAS_MF &&
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 !(codec->capabilities & AV_CODEC_CAP_SLICE_THREADS))
95 ERR("Codec %s wants mainfunction despite not being "
96 "slice-threading capable");
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 658 times.
658 if (codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS &&
98 !(codec->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
99 AV_CODEC_CAP_SLICE_THREADS |
100 AV_CODEC_CAP_OTHER_THREADS)))
101 ERR("Codec %s has private-only threading support\n");
102
103 658 is_decoder = av_codec_is_decoder(codec);
104 658 is_encoder = av_codec_is_encoder(codec);
105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 658 times.
658 if (!!is_decoder + !!is_encoder != 1) {
106 ERR("Codec %s is decoder and encoder or neither.\n");
107 continue;
108 }
109
2/2
✓ Branch 0 taken 178 times.
✓ Branch 1 taken 480 times.
658 if (is_encoder) {
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
178 if (codec->type == AVMEDIA_TYPE_SUBTITLE ^ !!codec->encode_sub)
111 ERR("Encoder %s is both subtitle encoder and not subtitle encoder.");
112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
178 if (!!codec->encode_sub + !!codec->encode2 + !!codec->receive_packet != 1)
113 ERR("Encoder %s does not implement exactly one encode API.\n");
114
3/6
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 178 times.
178 if (codec->update_thread_context || codec->update_thread_context_for_user || codec->bsfs)
115 ERR("Encoder %s has decoder-only thread functions or bsf.\n");
116
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 105 times.
178 if (codec->type == AVMEDIA_TYPE_AUDIO) {
117
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73 times.
73 if (!codec->sample_fmts) {
118 av_log(NULL, AV_LOG_FATAL, "Encoder %s is missing the sample_fmts field\n", codec->name);
119 ret = 1;
120 }
121 }
122
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 if (codec->caps_internal & (FF_CODEC_CAP_ALLOCATE_PROGRESS |
123 FF_CODEC_CAP_SETS_PKT_DTS |
124 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
125 FF_CODEC_CAP_EXPORTS_CROPPING |
126 178 FF_CODEC_CAP_SETS_FRAME_PROPS) ||
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
178 codec->capabilities & (AV_CODEC_CAP_AVOID_PROBING |
128 AV_CODEC_CAP_CHANNEL_CONF |
129 AV_CODEC_CAP_DRAW_HORIZ_BAND |
130 AV_CODEC_CAP_SUBFRAMES))
131 ERR("Encoder %s has decoder-only capabilities set\n");
132
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 161 times.
178 if (codec->capabilities & AV_CODEC_CAP_FRAME_THREADS &&
133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 codec->capabilities & AV_CODEC_CAP_ENCODER_FLUSH)
134 ERR("Frame-threaded encoder %s claims to support flushing\n");
135 } else {
136
3/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 458 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
480 if (codec->type == AVMEDIA_TYPE_SUBTITLE && !codec->decode)
137 ERR("Subtitle decoder %s does not implement decode callback\n");
138
3/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 458 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
480 if (codec->type == AVMEDIA_TYPE_SUBTITLE && codec->bsfs)
139 ERR("Automatic bitstream filtering unsupported for subtitles; "
140 "yet decoder %s has it set\n");
141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 480 times.
480 if (!!codec->decode + !!codec->receive_frame != 1)
142 ERR("Decoder %s does not implement exactly one decode API.\n");
143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 480 times.
480 if (codec->capabilities & (AV_CODEC_CAP_SMALL_LAST_FRAME |
144 AV_CODEC_CAP_VARIABLE_FRAME_SIZE |
145 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
146 AV_CODEC_CAP_ENCODER_FLUSH))
147 ERR("Decoder %s has encoder-only capabilities\n");
148
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 465 times.
480 if (codec->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS &&
149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 !(codec->capabilities & AV_CODEC_CAP_FRAME_THREADS))
150 ERR("Decoder %s wants allocated progress without supporting"
151 "frame threads\n");
152 }
153
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 658 times.
658 if (priv_data_size_wrong(codec))
154 ERR_EXT("Private context of codec %s is impossibly-sized (size %d).",
155 codec->priv_data_size);
156
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 658 times.
658 if (!(desc = avcodec_descriptor_get(codec->id))) {
157 ERR("Codec %s lacks a corresponding descriptor\n");
158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 658 times.
658 } else if (desc->type != codec->type)
159 ERR_EXT("The type of AVCodec %s and its AVCodecDescriptor differ: "
160 "%s vs %s\n",
161 get_type_string(codec->type), get_type_string(desc->type));
162 }
163 1 return ret;
164 }
165