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
20 #include <stdio.h>
21
30
59
60 #define OFFSET(x) offsetof(TestContext, x)
61
62 #define TEST_FLAG_COOL 01
63 #define TEST_FLAG_LAME 02
64 #define TEST_FLAG_MU 04
65
93 };
94
96 {
97 return "test";
98 }
99
104 };
105
107 {
108 vfprintf(stdout, fmt, vl);
109 }
110
112 {
113 int i;
114
117
118 printf("Testing default values\n");
119 {
123
124 printf(
"num=%d\n", test_ctx.
num);
125 printf(
"toggle=%d\n", test_ctx.
toggle);
126 printf(
"string=%s\n", test_ctx.
string);
127 printf(
"escape=%s\n", test_ctx.
escape);
128 printf(
"flags=%d\n", test_ctx.
flags);
131 printf(
"width=%d height=%d\n", test_ctx.
w, test_ctx.
h);
134 printf(
"duration=%"PRId64
"\n", test_ctx.
duration);
135 printf(
"color=%d %d %d %d\n", test_ctx.
color[0], test_ctx.
color[1], test_ctx.
color[2], test_ctx.
color[3]);
140 printf(
"num64=%"PRId64
"\n", test_ctx.
num64);
141 printf(
"flt=%.6f\n", test_ctx.
flt);
142 printf(
"dbl=%.6f\n", test_ctx.
dbl);
143
145
147 }
148
149 printf("\nTesting av_opt_is_set_to_default()\n");
150 {
151 int ret;
155
157
160 printf(
"name:%10s default:%d error:%s\n", o->
name, !!ret, ret < 0 ?
av_err2str(ret) :
"");
161 }
165 printf(
"name:%10s default:%d error:%s\n", o->
name, !!ret, ret < 0 ?
av_err2str(ret) :
"");
166 }
168 }
169
170 printf("\nTest av_opt_serialize()\n");
171 {
175
177
180 printf("%s\n", buf);
182 memset(&test_ctx, 0, sizeof(test_ctx));
187 printf("%s\n", buf);
189 }
190 }
192 }
193
194 printf("\nTesting av_set_options_string()\n");
195 {
197 static const char *
const options[] = {
198 "",
199 ":",
200 "=",
201 "foo=:",
202 ":=foo",
203 "=foo",
204 "foo=",
205 "foo",
206 "foo=val",
207 "foo==val",
208 "toggle=:",
209 "string=:",
210 "toggle=1 : foo",
211 "toggle=100",
212 "toggle==1",
213 "flags=+mu-lame : num=42: toggle=0",
214 "num=42 : string=blahblah",
215 "rational=0 : rational=1/2 : rational=1/-1",
216 "rational=-1/0",
217 "size=1024x768",
218 "size=pal",
219 "size=bogus",
220 "pix_fmt=yuv420p",
221 "pix_fmt=2",
222 "pix_fmt=bogus",
223 "sample_fmt=s16",
224 "sample_fmt=2",
225 "sample_fmt=bogus",
226 "video_rate=pal",
227 "video_rate=25",
228 "video_rate=30000/1001",
229 "video_rate=30/1.001",
230 "video_rate=bogus",
231 "duration=bogus",
232 "duration=123.45",
233 "duration=1\\:23\\:45.67",
234 "color=blue",
235 "color=0x223300",
236 "color=0x42FF07AA",
237 "cl=stereo+downmix",
238 "cl=foo",
239 "bin=boguss",
240 "bin=111",
241 "bin=ffff",
242 "num64=bogus",
243 "num64=44",
244 "num64=44.4",
245 "num64=-1",
246 "num64=101",
247 "flt=bogus",
248 "flt=2",
249 "flt=2.2",
250 "flt=-1",
251 "flt=101",
252 "dbl=bogus",
253 "dbl=2",
254 "dbl=2.2",
255 "dbl=-1",
256 "dbl=101",
257 "bool1=true",
258 "bool2=auto",
259 };
260
263
265
267 int silence_log = !strcmp(options[i], "rational=-1/0"); // inf formating differs between platforms
269 if (silence_log)
272 printf("Error '%s'\n", options[i]);
273 else
274 printf("OK '%s'\n", options[i]);
276 }
278 }
279
280 printf("\nTesting av_opt_set_from_string()\n");
281 {
283 static const char *
const options[] = {
284 "",
285 "5",
286 "5:hello",
287 "5:hello:size=pal",
288 "5:size=pal:hello",
289 ":",
290 "=",
291 " 5 : hello : size = pal ",
292 "a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42"
293 };
294 static const char *
const shorthand[] = {
"num",
"string",
NULL };
295
298
300
304 printf("Error '%s'\n", options[i]);
305 else
306 printf("OK '%s'\n", options[i]);
307 }
309 }
310
311 return 0;
312 }
static enum AVPixelFormat pix_fmt
Memory handling functions.
void av_log_set_level(int level)
Set the log level.
enum AVPixelFormat pix_fmt
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
int av_set_options_string(void *ctx, const char *opts, const char *key_val_sep, const char *pairs_sep)
Parse the key/value pairs list in opts.
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, const char key_val_sep, const char pairs_sep)
Serialize object's options.
int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags)
Check if given option is set to its default value.
#define AV_LOG_QUIET
Print no output.
int av_opt_set_from_string(void *ctx, const char *opts, const char *const *shorthand, const char *key_val_sep, const char *pairs_sep)
Parse the key-value pairs list in opts.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
enum AVSampleFormat sample_fmt
#define AV_CH_LAYOUT_HEXAGONAL
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
const AVOption * av_opt_next(const void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
static void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
audio channel layout utility functions
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define FF_ARRAY_ELEMS(a)
offset must point to a pointer immediately followed by an int for the length
static const AVClass test_class
AVSampleFormat
Audio sample formats.
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
Show the obj options.
static const AVOption test_options[]
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
offset must point to AVRational
offset must point to two consecutive integers
static const char * test_get_name(void *ctx)
void av_opt_free(void *obj)
Free all allocated objects in obj.
const OptionDef options[]
common internal and external API header
Utilties for rational number calculation.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
AVPixelFormat
Pixel format.