log.h 10 KB

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