log.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. #ifndef AVUTIL_LOG_H
  21. #define AVUTIL_LOG_H
  22. #include <stdarg.h>
  23. #include "avutil.h"
  24. #include "attributes.h"
  25. typedef enum {
  26. AV_CLASS_CATEGORY_NA = 0,
  27. AV_CLASS_CATEGORY_INPUT,
  28. AV_CLASS_CATEGORY_OUTPUT,
  29. AV_CLASS_CATEGORY_MUXER,
  30. AV_CLASS_CATEGORY_DEMUXER,
  31. AV_CLASS_CATEGORY_ENCODER,
  32. AV_CLASS_CATEGORY_DECODER,
  33. AV_CLASS_CATEGORY_FILTER,
  34. AV_CLASS_CATEGORY_BITSTREAM_FILTER,
  35. AV_CLASS_CATEGORY_SWSCALER,
  36. AV_CLASS_CATEGORY_SWRESAMPLER,
  37. AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT = 40,
  38. AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT,
  39. AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT,
  40. AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT,
  41. AV_CLASS_CATEGORY_DEVICE_OUTPUT,
  42. AV_CLASS_CATEGORY_DEVICE_INPUT,
  43. AV_CLASS_CATEGORY_NB, ///< not part of ABI/API
  44. }AVClassCategory;
  45. struct AVOptionRanges;
  46. /**
  47. * Describe the class of an AVClass context structure. That is an
  48. * arbitrary struct of which the first field is a pointer to an
  49. * AVClass struct (e.g. AVCodecContext, AVFormatContext etc.).
  50. */
  51. typedef struct AVClass {
  52. /**
  53. * The name of the class; usually it is the same name as the
  54. * context structure type to which the AVClass is associated.
  55. */
  56. const char* class_name;
  57. /**
  58. * A pointer to a function which returns the name of a context
  59. * instance ctx associated with the class.
  60. */
  61. const char* (*item_name)(void* ctx);
  62. /**
  63. * a pointer to the first option specified in the class if any or NULL
  64. *
  65. * @see av_set_default_options()
  66. */
  67. const struct AVOption *option;
  68. /**
  69. * LIBAVUTIL_VERSION with which this structure was created.
  70. * This is used to allow fields to be added without requiring major
  71. * version bumps everywhere.
  72. */
  73. int version;
  74. /**
  75. * Offset in the structure where log_level_offset is stored.
  76. * 0 means there is no such variable
  77. */
  78. int log_level_offset_offset;
  79. /**
  80. * Offset in the structure where a pointer to the parent context for
  81. * logging is stored. For example a decoder could pass its AVCodecContext
  82. * to eval as such a parent context, which an av_log() implementation
  83. * could then leverage to display the parent context.
  84. * The offset can be NULL.
  85. */
  86. int parent_log_context_offset;
  87. /**
  88. * Return next AVOptions-enabled child or NULL
  89. */
  90. void* (*child_next)(void *obj, void *prev);
  91. /**
  92. * Return an AVClass corresponding to the next potential
  93. * AVOptions-enabled child.
  94. *
  95. * The difference between child_next and this is that
  96. * child_next iterates over _already existing_ objects, while
  97. * child_class_next iterates over _all possible_ children.
  98. */
  99. const struct AVClass* (*child_class_next)(const struct AVClass *prev);
  100. /**
  101. * Category used for visualization (like color)
  102. * This is only set if the category is equal for all objects using this class.
  103. * available since version (51 << 16 | 56 << 8 | 100)
  104. */
  105. AVClassCategory category;
  106. /**
  107. * Callback to return the category.
  108. * available since version (51 << 16 | 59 << 8 | 100)
  109. */
  110. AVClassCategory (*get_category)(void* ctx);
  111. /**
  112. * Callback to return the supported/allowed ranges.
  113. * available since version (52.12)
  114. */
  115. int (*query_ranges)(struct AVOptionRanges **, void *obj, const char *key, int flags);
  116. } AVClass;
  117. /**
  118. * @addtogroup lavu_log
  119. *
  120. * @{
  121. *
  122. * @defgroup lavu_log_constants Logging Constants
  123. *
  124. * @{
  125. */
  126. /**
  127. * Print no output.
  128. */
  129. #define AV_LOG_QUIET -8
  130. /**
  131. * Something went really wrong and we will crash now.
  132. */
  133. #define AV_LOG_PANIC 0
  134. /**
  135. * Something went wrong and recovery is not possible.
  136. * For example, no header was found for a format which depends
  137. * on headers or an illegal combination of parameters is used.
  138. */
  139. #define AV_LOG_FATAL 8
  140. /**
  141. * Something went wrong and cannot losslessly be recovered.
  142. * However, not all future data is affected.
  143. */
  144. #define AV_LOG_ERROR 16
  145. /**
  146. * Something somehow does not look correct. This may or may not
  147. * lead to problems. An example would be the use of '-vstrict -2'.
  148. */
  149. #define AV_LOG_WARNING 24
  150. /**
  151. * Standard information.
  152. */
  153. #define AV_LOG_INFO 32
  154. /**
  155. * Detailed information.
  156. */
  157. #define AV_LOG_VERBOSE 40
  158. /**
  159. * Stuff which is only useful for libav* developers.
  160. */
  161. #define AV_LOG_DEBUG 48
  162. #define AV_LOG_MAX_OFFSET (AV_LOG_DEBUG - AV_LOG_QUIET)
  163. /**
  164. * @}
  165. */
  166. /**
  167. * Sets additional colors for extended debugging sessions.
  168. * @code
  169. av_log(ctx, AV_LOG_DEBUG|AV_LOG_C(134), "Message in purple\n");
  170. @endcode
  171. * Requires 256color terminal support. Uses outside debugging is not
  172. * recommended.
  173. */
  174. #define AV_LOG_C(x) (x << 8)
  175. /**
  176. * Send the specified message to the log if the level is less than or equal
  177. * to the current av_log_level. By default, all logging messages are sent to
  178. * stderr. This behavior can be altered by setting a different logging callback
  179. * function.
  180. * @see av_log_set_callback
  181. *
  182. * @param avcl A pointer to an arbitrary struct of which the first field is a
  183. * pointer to an AVClass struct.
  184. * @param level The importance level of the message expressed using a @ref
  185. * lavu_log_constants "Logging Constant".
  186. * @param fmt The format string (printf-compatible) that specifies how
  187. * subsequent arguments are converted to output.
  188. */
  189. void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
  190. /**
  191. * Send the specified message to the log if the level is less than or equal
  192. * to the current av_log_level. By default, all logging messages are sent to
  193. * stderr. This behavior can be altered by setting a different logging callback
  194. * function.
  195. * @see av_log_set_callback
  196. *
  197. * @param avcl A pointer to an arbitrary struct of which the first field is a
  198. * pointer to an AVClass struct.
  199. * @param level The importance level of the message expressed using a @ref
  200. * lavu_log_constants "Logging Constant".
  201. * @param fmt The format string (printf-compatible) that specifies how
  202. * subsequent arguments are converted to output.
  203. * @param vl The arguments referenced by the format string.
  204. */
  205. void av_vlog(void *avcl, int level, const char *fmt, va_list vl);
  206. /**
  207. * Get the current log level
  208. *
  209. * @see lavu_log_constants
  210. *
  211. * @return Current log level
  212. */
  213. int av_log_get_level(void);
  214. /**
  215. * Set the log level
  216. *
  217. * @see lavu_log_constants
  218. *
  219. * @param level Logging level
  220. */
  221. void av_log_set_level(int level);
  222. /**
  223. * Set the logging callback
  224. *
  225. * @note The callback must be thread safe, even if the application does not use
  226. * threads itself as some codecs are multithreaded.
  227. *
  228. * @see av_log_default_callback
  229. *
  230. * @param callback A logging function with a compatible signature.
  231. */
  232. void av_log_set_callback(void (*callback)(void*, int, const char*, va_list));
  233. /**
  234. * Default logging callback
  235. *
  236. * It prints the message to stderr, optionally colorizing it.
  237. *
  238. * @param avcl A pointer to an arbitrary struct of which the first field is a
  239. * pointer to an AVClass struct.
  240. * @param level The importance level of the message expressed using a @ref
  241. * lavu_log_constants "Logging Constant".
  242. * @param fmt The format string (printf-compatible) that specifies how
  243. * subsequent arguments are converted to output.
  244. * @param vl The arguments referenced by the format string.
  245. */
  246. void av_log_default_callback(void *avcl, int level, const char *fmt,
  247. va_list vl);
  248. /**
  249. * Return the context name
  250. *
  251. * @param ctx The AVClass context
  252. *
  253. * @return The AVClass class_name
  254. */
  255. const char* av_default_item_name(void* ctx);
  256. AVClassCategory av_default_get_category(void *ptr);
  257. /**
  258. * Format a line of log the same way as the default callback.
  259. * @param line buffer to receive the formated line
  260. * @param line_size size of the buffer
  261. * @param print_prefix used to store whether the prefix must be printed;
  262. * must point to a persistent integer initially set to 1
  263. */
  264. void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
  265. char *line, int line_size, int *print_prefix);
  266. /**
  267. * av_dlog macros
  268. * Useful to print debug messages that shouldn't get compiled in normally.
  269. */
  270. #ifdef DEBUG
  271. # define av_dlog(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
  272. #else
  273. # define av_dlog(pctx, ...) do { if (0) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
  274. #endif
  275. /**
  276. * Skip repeated messages, this requires the user app to use av_log() instead of
  277. * (f)printf as the 2 would otherwise interfere and lead to
  278. * "Last message repeated x times" messages below (f)printf messages with some
  279. * bad luck.
  280. * Also to receive the last, "last repeated" line if any, the user app must
  281. * call av_log(NULL, AV_LOG_QUIET, "%s", ""); at the end
  282. */
  283. #define AV_LOG_SKIP_REPEATED 1
  284. /**
  285. * Include the log severity in messages originating from codecs.
  286. *
  287. * Results in messages such as:
  288. * [rawvideo @ 0xDEADBEEF] [error] encode did not produce valid pts
  289. */
  290. #define AV_LOG_PRINT_LEVEL 2
  291. void av_log_set_flags(int arg);
  292. int av_log_get_flags(void);
  293. /**
  294. * @}
  295. */
  296. #endif /* AVUTIL_LOG_H */