FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
log.h
Go to the documentation of this file.
1 /*
2  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
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 #ifndef AVUTIL_LOG_H
22 #define AVUTIL_LOG_H
23 
24 #include <stdarg.h>
25 #include "attributes.h"
26 #include "version.h"
27 
28 typedef enum {
47  AV_CLASS_CATEGORY_NB ///< not part of ABI/API
49 
51  /**
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).
55  */
57 };
58 
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))
63 
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))
68 
69 struct AVOptionRanges;
70 
71 /**
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.).
75  */
76 typedef struct AVClass {
77  /**
78  * The name of the class; usually it is the same name as the
79  * context structure type to which the AVClass is associated.
80  */
81  const char* class_name;
82 
83  /**
84  * A pointer to a function which returns the name of a context
85  * instance ctx associated with the class.
86  */
87  const char* (*item_name)(void* ctx);
88 
89  /**
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
92  * name.
93  *
94  * @see av_set_default_options()
95  */
96  const struct AVOption *option;
97 
98  /**
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.
102  */
103 
104  int version;
105 
106  /**
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.
110  *
111  * 0 means there is no such variable.
112  */
114 
115  /**
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.
120  *
121  * When the pointer is NULL, or this offset is zero, the object is assumed
122  * to have no parent.
123  */
125 
126  /**
127  * Category used for visualization (like color).
128  *
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()
131  * otherwise.
132  */
134 
135  /**
136  * Callback to return the instance category. Use this callback when
137  * different instances of this class may have different categories,
138  * ::category otherwise.
139  */
141 
142  /**
143  * Callback to return the supported/allowed ranges.
144  */
145  int (*query_ranges)(struct AVOptionRanges **, void *obj, const char *key, int flags);
146 
147  /**
148  * Return next AVOptions-enabled child or NULL
149  */
150  void* (*child_next)(void *obj, void *prev);
151 
152  /**
153  * Iterate over the AVClasses corresponding to potential AVOptions-enabled
154  * children.
155  *
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.
160  *
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.
166  */
167  const struct AVClass* (*child_class_iterate)(void **iter);
168 
169  /**
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.
173  *
174  * Added in version 59.41.100.
175  */
177 } AVClass;
178 
179 /**
180  * @addtogroup lavu_log
181  *
182  * @{
183  *
184  * @defgroup lavu_log_constants Logging Constants
185  *
186  * @{
187  */
188 
189 /**
190  * Print no output.
191  */
192 #define AV_LOG_QUIET -8
193 
194 /**
195  * Something went really wrong and we will crash now.
196  */
197 #define AV_LOG_PANIC 0
198 
199 /**
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.
203  */
204 #define AV_LOG_FATAL 8
205 
206 /**
207  * Something went wrong and cannot losslessly be recovered.
208  * However, not all future data is affected.
209  */
210 #define AV_LOG_ERROR 16
211 
212 /**
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'.
215  */
216 #define AV_LOG_WARNING 24
217 
218 /**
219  * Standard information.
220  */
221 #define AV_LOG_INFO 32
222 
223 /**
224  * Detailed information.
225  */
226 #define AV_LOG_VERBOSE 40
227 
228 /**
229  * Stuff which is only useful for libav* developers.
230  */
231 #define AV_LOG_DEBUG 48
232 
233 /**
234  * Extremely verbose debugging, useful for libav* development.
235  */
236 #define AV_LOG_TRACE 56
237 
238 #define AV_LOG_MAX_OFFSET (AV_LOG_TRACE - AV_LOG_QUIET)
239 
240 /**
241  * @}
242  */
243 
244 /**
245  * Sets additional colors for extended debugging sessions.
246  * @code
247  av_log(ctx, AV_LOG_DEBUG|AV_LOG_C(134), "Message in purple\n");
248  @endcode
249  * Requires 256color terminal support. Uses outside debugging is not
250  * recommended.
251  */
252 #define AV_LOG_C(x) ((x) << 8)
253 
254 /**
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
258  * function.
259  * @see av_log_set_callback
260  *
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.
267  */
268 void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
269 
270 /**
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
274  * function.
275  * @see av_log
276  *
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 occurance.
281  * @param subsequent_level importance level of the message expressed using a @ref
282  * lavu_log_constants "Logging Constant" after the first occurance.
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.
288  */
289 void av_log_once(void* avcl, int initial_level, int subsequent_level, int *state, const char *fmt, ...) av_printf_format(5, 6);
290 
291 
292 /**
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
296  * function.
297  * @see av_log_set_callback
298  *
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.
306  */
307 void av_vlog(void *avcl, int level, const char *fmt, va_list vl);
308 
309 /**
310  * Get the current log level
311  *
312  * @see lavu_log_constants
313  *
314  * @return Current log level
315  */
316 int av_log_get_level(void);
317 
318 /**
319  * Set the log level
320  *
321  * @see lavu_log_constants
322  *
323  * @param level Logging level
324  */
325 void av_log_set_level(int level);
326 
327 /**
328  * Set the logging callback
329  *
330  * @note The callback must be thread safe, even if the application does not use
331  * threads itself as some codecs are multithreaded.
332  *
333  * @see av_log_default_callback
334  *
335  * @param callback A logging function with a compatible signature.
336  */
337 void av_log_set_callback(void (*callback)(void*, int, const char*, va_list));
338 
339 /**
340  * Default logging callback
341  *
342  * It prints the message to stderr, optionally colorizing it.
343  *
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.
351  */
352 void av_log_default_callback(void *avcl, int level, const char *fmt,
353  va_list vl);
354 
355 /**
356  * Return the context name
357  *
358  * @param ctx The AVClass context
359  *
360  * @return The AVClass class_name
361  */
362 const char* av_default_item_name(void* ctx);
364 
365 /**
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
371  */
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);
374 
375 /**
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.
388  */
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);
391 
392 /**
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
396  * bad luck.
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
399  */
400 #define AV_LOG_SKIP_REPEATED 1
401 
402 /**
403  * Include the log severity in messages originating from codecs.
404  *
405  * Results in messages such as:
406  * [rawvideo @ 0xDEADBEEF] [error] encode did not produce valid pts
407  */
408 #define AV_LOG_PRINT_LEVEL 2
409 
410 /**
411  * Include system time in log output.
412  */
413 #define AV_LOG_PRINT_TIME 4
414 
415 /**
416  * Include system date and time in log output.
417  */
418 #define AV_LOG_PRINT_DATETIME 8
419 
420 void av_log_set_flags(int arg);
421 int av_log_get_flags(void);
422 
423 /**
424  * @}
425  */
426 
427 #endif /* AVUTIL_LOG_H */
flags
const SwsFlags flags[]
Definition: swscale.c:61
av_vlog
void void void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
Send the specified message to the log if the level is less than or equal to the current av_log_level.
Definition: log.c:458
level
uint8_t level
Definition: svq3.c:205
AV_CLASS_CATEGORY_DECODER
@ AV_CLASS_CATEGORY_DECODER
Definition: log.h:35
AVClass::version
int version
LIBAVUTIL_VERSION with which this structure was created.
Definition: log.h:104
av_log_format_line2
int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl, char *line, int line_size, int *print_prefix)
Format a line of log the same way as the default callback.
Definition: log.c:365
AV_CLASS_CATEGORY_INPUT
@ AV_CLASS_CATEGORY_INPUT
Definition: log.h:30
AV_CLASS_CATEGORY_NA
@ AV_CLASS_CATEGORY_NA
Definition: log.h:29
AVClassStateFlags
AVClassStateFlags
Definition: log.h:50
AVOption
AVOption.
Definition: opt.h:429
AV_CLASS_CATEGORY_OUTPUT
@ AV_CLASS_CATEGORY_OUTPUT
Definition: log.h:31
AV_CLASS_CATEGORY_DEVICE_INPUT
@ AV_CLASS_CATEGORY_DEVICE_INPUT
Definition: log.h:46
AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT
@ AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT
Definition: log.h:44
av_log_format_line
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, char *line, int line_size, int *print_prefix)
Format a line of log the same way as the default callback.
Definition: log.c:359
state
static struct @492 state
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AVClass::query_ranges
int(* query_ranges)(struct AVOptionRanges **, void *obj, const char *key, int flags)
Callback to return the supported/allowed ranges.
Definition: log.h:145
AV_CLASS_CATEGORY_HWDEVICE
@ AV_CLASS_CATEGORY_HWDEVICE
Definition: log.h:40
AVClass::state_flags_offset
int state_flags_offset
When non-zero, offset in the object to an unsigned int holding object state flags,...
Definition: log.h:176
AV_CLASS_CATEGORY_NB
@ AV_CLASS_CATEGORY_NB
not part of ABI/API
Definition: log.h:47
key
const char * key
Definition: hwcontext_opencl.c:189
arg
const char * arg
Definition: jacosubdec.c:67
callback
static void callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, enum dshowDeviceType devtype)
Definition: dshow.c:342
AV_CLASS_CATEGORY_DEMUXER
@ AV_CLASS_CATEGORY_DEMUXER
Definition: log.h:33
av_log_get_level
int av_log_get_level(void)
Get the current log level.
Definition: log.c:469
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
av_default_item_name
const char * av_default_item_name(void *ctx)
Return the context name.
Definition: log.c:240
av_printf_format
#define av_printf_format(fmtpos, attrpos)
Definition: attributes.h:161
av_log_set_flags
void av_log_set_flags(int arg)
Definition: log.c:479
AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT
@ AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT
Definition: log.h:41
av_log
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level.
AV_CLASS_STATE_INITIALIZED
@ AV_CLASS_STATE_INITIALIZED
Object initialization has finished and it is now in the 'runtime' stage.
Definition: log.h:56
AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
@ AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
Definition: log.h:42
AV_CLASS_CATEGORY_FILTER
@ AV_CLASS_CATEGORY_FILTER
Definition: log.h:36
av_log_set_callback
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
Definition: log.c:489
AVClass::category
AVClassCategory category
Category used for visualization (like color).
Definition: log.h:133
AVClass::get_category
AVClassCategory(* get_category)(void *ctx)
Callback to return the instance category.
Definition: log.h:140
av_log_get_flags
int av_log_get_flags(void)
Definition: log.c:484
line
Definition: graph2dot.c:48
attributes.h
AV_CLASS_CATEGORY_SWRESAMPLER
@ AV_CLASS_CATEGORY_SWRESAMPLER
Definition: log.h:39
av_log_set_level
void av_log_set_level(int level)
Set the log level.
Definition: log.c:474
AVClassCategory
AVClassCategory
Definition: log.h:28
AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT
@ AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT
Definition: log.h:43
AVOptionRanges
List of AVOptionRange structs.
Definition: opt.h:508
version.h
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
AV_CLASS_CATEGORY_MUXER
@ AV_CLASS_CATEGORY_MUXER
Definition: log.h:32
AVClass::option
const struct AVOption * option
An array of options for the structure or NULL.
Definition: log.h:96
av_default_get_category
AVClassCategory av_default_get_category(void *ptr)
Definition: log.c:245
AV_CLASS_CATEGORY_SWSCALER
@ AV_CLASS_CATEGORY_SWSCALER
Definition: log.h:38
AV_CLASS_CATEGORY_DEVICE_OUTPUT
@ AV_CLASS_CATEGORY_DEVICE_OUTPUT
Definition: log.h:45
av_log_default_callback
void av_log_default_callback(void *avcl, int level, const char *fmt, va_list vl)
Default logging callback.
Definition: log.c:377
AV_CLASS_CATEGORY_BITSTREAM_FILTER
@ AV_CLASS_CATEGORY_BITSTREAM_FILTER
Definition: log.h:37
AVClass::log_level_offset_offset
int log_level_offset_offset
Offset in the structure where the log level offset is stored.
Definition: log.h:113
AV_CLASS_CATEGORY_ENCODER
@ AV_CLASS_CATEGORY_ENCODER
Definition: log.h:34
AVClass::parent_log_context_offset
int parent_log_context_offset
Offset in the structure where a pointer to the parent context for logging is stored.
Definition: log.h:124
av_log_once
void void av_log_once(void *avcl, int initial_level, int subsequent_level, int *state, const char *fmt,...) av_printf_format(5
Send the specified message to the log once with the initial_level and then with the subsequent_level.