2
0

log.h 11 KB

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