FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/options.c
Date: 2021-09-24 03:35:22
Exec Total Coverage
Lines: 78 86 90.7%
Branches: 44 52 84.6%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2001 Fabrice Bellard
3 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * Options definition for AVCodecContext.
25 */
26
27 #include "avcodec.h"
28 #include "internal.h"
29 #include "libavutil/avassert.h"
30 #include "libavutil/internal.h"
31 #include "libavutil/mem.h"
32 #include "libavutil/opt.h"
33 #include <string.h>
34
35 FF_DISABLE_DEPRECATION_WARNINGS
36 #include "options_table.h"
37 FF_ENABLE_DEPRECATION_WARNINGS
38
39 4658 static const char* context_to_name(void* ptr) {
40 4658 AVCodecContext *avc= ptr;
41
42
3/4
✓ Branch 0 taken 4658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3909 times.
✓ Branch 3 taken 749 times.
4658 if (avc && avc->codec)
43 3909 return avc->codec->name;
44 else
45 749 return "NULL";
46 }
47
48 41 static void *codec_child_next(void *obj, void *prev)
49 {
50 41 AVCodecContext *s = obj;
51
5/8
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 21 times.
✗ Branch 7 not taken.
41 if (!prev && s->codec && s->codec->priv_class && s->priv_data)
52 21 return s->priv_data;
53 20 return NULL;
54 }
55
56 10319087 static const AVClass *codec_child_class_iterate(void **iter)
57 {
58 const AVCodec *c;
59 /* find next codec with priv options */
60
2/2
✓ Branch 1 taken 51653835 times.
✓ Branch 2 taken 78709 times.
51732544 while (c = av_codec_iterate(iter))
61
2/2
✓ Branch 0 taken 10240378 times.
✓ Branch 1 taken 41413457 times.
51653835 if (c->priv_class)
62 10240378 return c->priv_class;
63 78709 return NULL;
64 }
65
66 4658 static AVClassCategory get_category(void *ptr)
67 {
68 4658 AVCodecContext* avctx = ptr;
69
4/4
✓ Branch 0 taken 3909 times.
✓ Branch 1 taken 749 times.
✓ Branch 2 taken 3793 times.
✓ Branch 3 taken 116 times.
4658 if(avctx->codec && avctx->codec->decode) return AV_CLASS_CATEGORY_DECODER;
70 865 else return AV_CLASS_CATEGORY_ENCODER;
71 }
72
73 static const AVClass av_codec_context_class = {
74 .class_name = "AVCodecContext",
75 .item_name = context_to_name,
76 .option = avcodec_options,
77 .version = LIBAVUTIL_VERSION_INT,
78 .log_level_offset_offset = offsetof(AVCodecContext, log_level_offset),
79 .child_next = codec_child_next,
80 .child_class_iterate = codec_child_class_iterate,
81 .category = AV_CLASS_CATEGORY_ENCODER,
82 .get_category = get_category,
83 };
84
85 38923 static int init_context_defaults(AVCodecContext *s, const AVCodec *codec)
86 {
87 38923 int flags=0;
88 38923 memset(s, 0, sizeof(AVCodecContext));
89
90 38923 s->av_class = &av_codec_context_class;
91
92
2/2
✓ Branch 0 taken 12566 times.
✓ Branch 1 taken 26357 times.
38923 s->codec_type = codec ? codec->type : AVMEDIA_TYPE_UNKNOWN;
93
2/2
✓ Branch 0 taken 12566 times.
✓ Branch 1 taken 26357 times.
38923 if (codec) {
94 12566 s->codec = codec;
95 12566 s->codec_id = codec->id;
96 }
97
98
2/2
✓ Branch 0 taken 2642 times.
✓ Branch 1 taken 36281 times.
38923 if(s->codec_type == AVMEDIA_TYPE_AUDIO)
99 2642 flags= AV_OPT_FLAG_AUDIO_PARAM;
100
2/2
✓ Branch 0 taken 9829 times.
✓ Branch 1 taken 26452 times.
36281 else if(s->codec_type == AVMEDIA_TYPE_VIDEO)
101 9829 flags= AV_OPT_FLAG_VIDEO_PARAM;
102
2/2
✓ Branch 0 taken 95 times.
✓ Branch 1 taken 26357 times.
26452 else if(s->codec_type == AVMEDIA_TYPE_SUBTITLE)
103 95 flags= AV_OPT_FLAG_SUBTITLE_PARAM;
104 38923 av_opt_set_defaults2(s, flags, flags);
105
106 38923 s->time_base = (AVRational){0,1};
107 38923 s->framerate = (AVRational){ 0, 1 };
108 38923 s->pkt_timebase = (AVRational){ 0, 1 };
109 38923 s->get_buffer2 = avcodec_default_get_buffer2;
110 38923 s->get_format = avcodec_default_get_format;
111 38923 s->get_encode_buffer = avcodec_default_get_encode_buffer;
112 38923 s->execute = avcodec_default_execute;
113 38923 s->execute2 = avcodec_default_execute2;
114 38923 s->sample_aspect_ratio = (AVRational){0,1};
115 38923 s->pix_fmt = AV_PIX_FMT_NONE;
116 38923 s->sw_pix_fmt = AV_PIX_FMT_NONE;
117 38923 s->sample_fmt = AV_SAMPLE_FMT_NONE;
118
119 38923 s->reordered_opaque = AV_NOPTS_VALUE;
120
4/4
✓ Branch 0 taken 12566 times.
✓ Branch 1 taken 26357 times.
✓ Branch 2 taken 7217 times.
✓ Branch 3 taken 5349 times.
38923 if(codec && codec->priv_data_size){
121 7217 s->priv_data = av_mallocz(codec->priv_data_size);
122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7217 times.
7217 if (!s->priv_data)
123 return AVERROR(ENOMEM);
124
2/2
✓ Branch 0 taken 2392 times.
✓ Branch 1 taken 4825 times.
7217 if(codec->priv_class){
125 2392 *(const AVClass**)s->priv_data = codec->priv_class;
126 2392 av_opt_set_defaults(s->priv_data);
127 }
128 }
129
4/4
✓ Branch 0 taken 12566 times.
✓ Branch 1 taken 26357 times.
✓ Branch 2 taken 160 times.
✓ Branch 3 taken 12406 times.
38923 if (codec && codec->defaults) {
130 int ret;
131 160 const AVCodecDefault *d = codec->defaults;
132
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 160 times.
320 while (d->key) {
133 160 ret = av_opt_set(s, d->key, d->value, 0);
134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 160 times.
160 av_assert0(ret >= 0);
135 160 d++;
136 }
137 }
138 38923 return 0;
139 }
140
141 38923 AVCodecContext *avcodec_alloc_context3(const AVCodec *codec)
142 {
143 38923 AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
144
145
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38923 times.
38923 if (!avctx)
146 return NULL;
147
148
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 38923 times.
38923 if (init_context_defaults(avctx, codec) < 0) {
149 av_free(avctx);
150 return NULL;
151 }
152
153 38923 return avctx;
154 }
155
156 38800 void avcodec_free_context(AVCodecContext **pavctx)
157 {
158 38800 AVCodecContext *avctx = *pavctx;
159
160
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 38791 times.
38800 if (!avctx)
161 9 return;
162
163 38791 avcodec_close(avctx);
164
165 38791 av_freep(&avctx->extradata);
166 38791 av_freep(&avctx->subtitle_header);
167 38791 av_freep(&avctx->intra_matrix);
168 38791 av_freep(&avctx->inter_matrix);
169 38791 av_freep(&avctx->rc_override);
170
171 38791 av_freep(pavctx);
172 }
173
174 104605 const AVClass *avcodec_get_class(void)
175 {
176 104605 return &av_codec_context_class;
177 }
178
179 #if FF_API_GET_FRAME_CLASS
180 #define FOFFSET(x) offsetof(AVFrame,x)
181
182 static const AVOption frame_options[]={
183 {"best_effort_timestamp", "", FOFFSET(best_effort_timestamp), AV_OPT_TYPE_INT64, {.i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, 0},
184 {"pkt_pos", "", FOFFSET(pkt_pos), AV_OPT_TYPE_INT64, {.i64 = -1 }, INT64_MIN, INT64_MAX, 0},
185 {"pkt_size", "", FOFFSET(pkt_size), AV_OPT_TYPE_INT64, {.i64 = -1 }, INT64_MIN, INT64_MAX, 0},
186 {"sample_aspect_ratio", "", FOFFSET(sample_aspect_ratio), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, 0, INT_MAX, 0},
187 {"width", "", FOFFSET(width), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, 0},
188 {"height", "", FOFFSET(height), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, 0},
189 {"format", "", FOFFSET(format), AV_OPT_TYPE_INT, {.i64 = -1 }, 0, INT_MAX, 0},
190 {"channel_layout", "", FOFFSET(channel_layout), AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX, 0},
191 {"sample_rate", "", FOFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, 0},
192 {NULL},
193 };
194
195 static const AVClass av_frame_class = {
196 .class_name = "AVFrame",
197 .item_name = NULL,
198 .option = frame_options,
199 .version = LIBAVUTIL_VERSION_INT,
200 };
201
202 const AVClass *avcodec_get_frame_class(void)
203 {
204 return &av_frame_class;
205 }
206 #endif
207
208 #define SROFFSET(x) offsetof(AVSubtitleRect,x)
209
210 static const AVOption subtitle_rect_options[]={
211 {"x", "", SROFFSET(x), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, 0},
212 {"y", "", SROFFSET(y), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, 0},
213 {"w", "", SROFFSET(w), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, 0},
214 {"h", "", SROFFSET(h), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, 0},
215 {"type", "", SROFFSET(type), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, 0},
216 {"flags", "", SROFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, 1, 0, "flags"},
217 {"forced", "", SROFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, 1, 0},
218 {NULL},
219 };
220
221 static const AVClass av_subtitle_rect_class = {
222 .class_name = "AVSubtitleRect",
223 .item_name = NULL,
224 .option = subtitle_rect_options,
225 .version = LIBAVUTIL_VERSION_INT,
226 };
227
228 const AVClass *avcodec_get_subtitle_rect_class(void)
229 {
230 return &av_subtitle_rect_class;
231 }
232