2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
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.
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.
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
25 #include "attributes.h"
29 AV_CLASS_CATEGORY_NA
= 0,
30 AV_CLASS_CATEGORY_INPUT
,
31 AV_CLASS_CATEGORY_OUTPUT
,
32 AV_CLASS_CATEGORY_MUXER
,
33 AV_CLASS_CATEGORY_DEMUXER
,
34 AV_CLASS_CATEGORY_ENCODER
,
35 AV_CLASS_CATEGORY_DECODER
,
36 AV_CLASS_CATEGORY_FILTER
,
37 AV_CLASS_CATEGORY_BITSTREAM_FILTER
,
38 AV_CLASS_CATEGORY_SWSCALER
,
39 AV_CLASS_CATEGORY_SWRESAMPLER
,
40 AV_CLASS_CATEGORY_HWDEVICE
,
41 AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT
= 40,
42 AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
,
43 AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT
,
44 AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT
,
45 AV_CLASS_CATEGORY_DEVICE_OUTPUT
,
46 AV_CLASS_CATEGORY_DEVICE_INPUT
,
47 AV_CLASS_CATEGORY_NB
///< not part of ABI/API
50 enum AVClassStateFlags
{
52 * Object initialization has finished and it is now in the 'runtime' stage.
53 * This affects e.g. what options can be set on the object (only
54 * AV_OPT_FLAG_RUNTIME_PARAM options can be set on initialized objects).
56 AV_CLASS_STATE_INITIALIZED
= (1 << 0),
59 #define AV_IS_INPUT_DEVICE(category) \
60 (((category) == AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT) || \
61 ((category) == AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT) || \
62 ((category) == AV_CLASS_CATEGORY_DEVICE_INPUT))
64 #define AV_IS_OUTPUT_DEVICE(category) \
65 (((category) == AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT) || \
66 ((category) == AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT) || \
67 ((category) == AV_CLASS_CATEGORY_DEVICE_OUTPUT))
69 struct AVOptionRanges
;
72 * Describe the class of an AVClass context structure. That is an
73 * arbitrary struct of which the first field is a pointer to an
74 * AVClass struct (e.g. AVCodecContext, AVFormatContext etc.).
76 typedef struct AVClass
{
78 * The name of the class; usually it is the same name as the
79 * context structure type to which the AVClass is associated.
81 const char* class_name
;
84 * A pointer to a function which returns the name of a context
85 * instance ctx associated with the class.
87 const char* (*item_name
)(void* ctx
);
90 * An array of options for the structure or NULL.
91 * When non-NULL, the array must be terminated by an option with a NULL
94 * @see av_set_default_options()
96 const struct AVOption
*option
;
99 * LIBAVUTIL_VERSION with which this structure was created.
100 * This is used to allow fields to be added to AVClass without requiring
101 * major version bumps everywhere.
107 * Offset in the structure where the log level offset is stored. The log
108 * level offset is an int added to the log level for logging with this
109 * object as the context.
111 * 0 means there is no such variable.
113 int log_level_offset_offset
;
116 * Offset in the structure where a pointer to the parent context for
117 * logging is stored. For example a decoder could pass its AVCodecContext
118 * to eval as such a parent context, which an ::av_log() implementation
119 * could then leverage to display the parent context.
121 * When the pointer is NULL, or this offset is zero, the object is assumed
124 int parent_log_context_offset
;
127 * Category used for visualization (like color).
129 * Only used when ::get_category() is NULL. Use this field when all
130 * instances of this class have the same category, use ::get_category()
133 AVClassCategory category
;
136 * Callback to return the instance category. Use this callback when
137 * different instances of this class may have different categories,
138 * ::category otherwise.
140 AVClassCategory (*get_category
)(void* ctx
);
143 * Callback to return the supported/allowed ranges.
145 int (*query_ranges
)(struct AVOptionRanges
**, void *obj
, const char *key
, int flags
);
148 * Return next AVOptions-enabled child or NULL
150 void* (*child_next
)(void *obj
, void *prev
);
153 * Iterate over the AVClasses corresponding to potential AVOptions-enabled
156 * @param iter pointer to opaque iteration state. The caller must initialize
157 * *iter to NULL before the first call.
158 * @return AVClass for the next AVOptions-enabled child or NULL if there are
159 * no more such children.
161 * @note The difference between ::child_next() and ::child_class_iterate()
162 * is that ::child_next() iterates over _actual_ children of an
163 * _existing_ object instance, while ::child_class_iterate() iterates
164 * over the classes of all _potential_ children of any possible
165 * instance of this class.
167 const struct AVClass
* (*child_class_iterate
)(void **iter
);
170 * When non-zero, offset in the object to an unsigned int holding object
171 * state flags, a combination of AVClassStateFlags values. The flags are
172 * updated by the object to signal its state to the generic code.
174 * Added in version 59.41.100.
176 int state_flags_offset
;
180 * @addtogroup lavu_log
184 * @defgroup lavu_log_constants Logging Constants
192 #define AV_LOG_QUIET -8
195 * Something went really wrong and we will crash now.
197 #define AV_LOG_PANIC 0
200 * Something went wrong and recovery is not possible.
201 * For example, no header was found for a format which depends
202 * on headers or an illegal combination of parameters is used.
204 #define AV_LOG_FATAL 8
207 * Something went wrong and cannot losslessly be recovered.
208 * However, not all future data is affected.
210 #define AV_LOG_ERROR 16
213 * Something somehow does not look correct. This may or may not
214 * lead to problems. An example would be the use of '-vstrict -2'.
216 #define AV_LOG_WARNING 24
219 * Standard information.
221 #define AV_LOG_INFO 32
224 * Detailed information.
226 #define AV_LOG_VERBOSE 40
229 * Stuff which is only useful for libav* developers.
231 #define AV_LOG_DEBUG 48
234 * Extremely verbose debugging, useful for libav* development.
236 #define AV_LOG_TRACE 56
238 #define AV_LOG_MAX_OFFSET (AV_LOG_TRACE - AV_LOG_QUIET)
245 * Sets additional colors for extended debugging sessions.
247 av_log(ctx, AV_LOG_DEBUG|AV_LOG_C(134), "Message in purple\n");
249 * Requires 256color terminal support. Uses outside debugging is not
252 #define AV_LOG_C(x) ((x) << 8)
255 * Send the specified message to the log if the level is less than or equal
256 * to the current av_log_level. By default, all logging messages are sent to
257 * stderr. This behavior can be altered by setting a different logging callback
259 * @see av_log_set_callback
261 * @param avcl A pointer to an arbitrary struct of which the first field is a
262 * pointer to an AVClass struct or NULL if general log.
263 * @param level The importance level of the message expressed using a @ref
264 * lavu_log_constants "Logging Constant".
265 * @param fmt The format string (printf-compatible) that specifies how
266 * subsequent arguments are converted to output.
268 void av_log(void *avcl
, int level
, const char *fmt
, ...) av_printf_format(3, 4);
271 * Send the specified message to the log once with the initial_level and then with
272 * the subsequent_level. By default, all logging messages are sent to
273 * stderr. This behavior can be altered by setting a different logging callback
277 * @param avcl A pointer to an arbitrary struct of which the first field is a
278 * pointer to an AVClass struct or NULL if general log.
279 * @param initial_level importance level of the message expressed using a @ref
280 * lavu_log_constants "Logging Constant" for the first occurrence.
281 * @param subsequent_level importance level of the message expressed using a @ref
282 * lavu_log_constants "Logging Constant" after the first occurrence.
283 * @param fmt The format string (printf-compatible) that specifies how
284 * subsequent arguments are converted to output.
285 * @param state a variable to keep trak of if a message has already been printed
286 * this must be initialized to 0 before the first use. The same state
287 * must not be accessed by 2 Threads simultaneously.
289 void av_log_once(void* avcl
, int initial_level
, int subsequent_level
, int *state
, const char *fmt
, ...) av_printf_format(5, 6);
293 * Send the specified message to the log if the level is less than or equal
294 * to the current av_log_level. By default, all logging messages are sent to
295 * stderr. This behavior can be altered by setting a different logging callback
297 * @see av_log_set_callback
299 * @param avcl A pointer to an arbitrary struct of which the first field is a
300 * pointer to an AVClass struct.
301 * @param level The importance level of the message expressed using a @ref
302 * lavu_log_constants "Logging Constant".
303 * @param fmt The format string (printf-compatible) that specifies how
304 * subsequent arguments are converted to output.
305 * @param vl The arguments referenced by the format string.
307 void av_vlog(void *avcl
, int level
, const char *fmt
, va_list vl
);
310 * Get the current log level
312 * @see lavu_log_constants
314 * @return Current log level
316 int av_log_get_level(void);
321 * @see lavu_log_constants
323 * @param level Logging level
325 void av_log_set_level(int level
);
328 * Set the logging callback
330 * @note The callback must be thread safe, even if the application does not use
331 * threads itself as some codecs are multithreaded.
333 * @see av_log_default_callback
335 * @param callback A logging function with a compatible signature.
337 void av_log_set_callback(void (*callback
)(void*, int, const char*, va_list));
340 * Default logging callback
342 * It prints the message to stderr, optionally colorizing it.
344 * @param avcl A pointer to an arbitrary struct of which the first field is a
345 * pointer to an AVClass struct.
346 * @param level The importance level of the message expressed using a @ref
347 * lavu_log_constants "Logging Constant".
348 * @param fmt The format string (printf-compatible) that specifies how
349 * subsequent arguments are converted to output.
350 * @param vl The arguments referenced by the format string.
352 void av_log_default_callback(void *avcl
, int level
, const char *fmt
,
356 * Return the context name
358 * @param ctx The AVClass context
360 * @return The AVClass class_name
362 const char* av_default_item_name(void* ctx
);
363 AVClassCategory
av_default_get_category(void *ptr
);
366 * Format a line of log the same way as the default callback.
367 * @param line buffer to receive the formatted line
368 * @param line_size size of the buffer
369 * @param print_prefix used to store whether the prefix must be printed;
370 * must point to a persistent integer initially set to 1
372 void av_log_format_line(void *ptr
, int level
, const char *fmt
, va_list vl
,
373 char *line
, int line_size
, int *print_prefix
);
376 * Format a line of log the same way as the default callback.
377 * @param line buffer to receive the formatted line;
378 * may be NULL if line_size is 0
379 * @param line_size size of the buffer; at most line_size-1 characters will
380 * be written to the buffer, plus one null terminator
381 * @param print_prefix used to store whether the prefix must be printed;
382 * must point to a persistent integer initially set to 1
383 * @return Returns a negative value if an error occurred, otherwise returns
384 * the number of characters that would have been written for a
385 * sufficiently large buffer, not including the terminating null
386 * character. If the return value is not less than line_size, it means
387 * that the log message was truncated to fit the buffer.
389 int av_log_format_line2(void *ptr
, int level
, const char *fmt
, va_list vl
,
390 char *line
, int line_size
, int *print_prefix
);
393 * Skip repeated messages, this requires the user app to use av_log() instead of
394 * (f)printf as the 2 would otherwise interfere and lead to
395 * "Last message repeated x times" messages below (f)printf messages with some
397 * Also to receive the last, "last repeated" line if any, the user app must
398 * call av_log(NULL, AV_LOG_QUIET, "%s", ""); at the end
400 #define AV_LOG_SKIP_REPEATED 1
403 * Include the log severity in messages originating from codecs.
405 * Results in messages such as:
406 * [rawvideo @ 0xDEADBEEF] [error] encode did not produce valid pts
408 #define AV_LOG_PRINT_LEVEL 2
411 * Include system time in log output.
413 #define AV_LOG_PRINT_TIME 4
416 * Include system date and time in log output.
418 #define AV_LOG_PRINT_DATETIME 8
420 void av_log_set_flags(int arg
);
421 int av_log_get_flags(void);
427 #endif /* AVUTIL_LOG_H */