log.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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 "attributes.h"
  24. #include "version.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. * Category used for visualization (like color)
  97. * This is only set if the category is equal for all objects using this class.
  98. * available since version (51 << 16 | 56 << 8 | 100)
  99. */
  100. AVClassCategory category;
  101. /**
  102. * Callback to return the category.
  103. * available since version (51 << 16 | 59 << 8 | 100)
  104. */
  105. AVClassCategory (*get_category)(void* ctx);
  106. /**
  107. * Callback to return the supported/allowed ranges.
  108. * available since version (52.12)
  109. */
  110. int (*query_ranges)(struct AVOptionRanges **, void *obj, const char *key, int flags);
  111. /**
  112. * Return next AVOptions-enabled child or NULL
  113. */
  114. void* (*child_next)(void *obj, void *prev);
  115. /**
  116. * Iterate over the AVClasses corresponding to potential AVOptions-enabled
  117. * children.
  118. *
  119. * @param iter pointer to opaque iteration state. The caller must initialize
  120. * *iter to NULL before the first call.
  121. * @return AVClass for the next AVOptions-enabled child or NULL if there are
  122. * no more such children.
  123. *
  124. * @note The difference between child_next and this is that child_next
  125. * iterates over _already existing_ objects, while child_class_iterate
  126. * iterates over _all possible_ children.
  127. */
  128. const struct AVClass* (*child_class_iterate)(void **iter);
  129. } AVClass;
  130. /**
  131. * @addtogroup lavu_log
  132. *
  133. * @{
  134. *
  135. * @defgroup lavu_log_constants Logging Constants
  136. *
  137. * @{
  138. */
  139. /**
  140. * Print no output.
  141. */
  142. #define AV_LOG_QUIET -8
  143. /**
  144. * Something went really wrong and we will crash now.
  145. */
  146. #define AV_LOG_PANIC 0
  147. /**
  148. * Something went wrong and recovery is not possible.
  149. * For example, no header was found for a format which depends
  150. * on headers or an illegal combination of parameters is used.
  151. */
  152. #define AV_LOG_FATAL 8
  153. /**
  154. * Something went wrong and cannot losslessly be recovered.
  155. * However, not all future data is affected.
  156. */
  157. #define AV_LOG_ERROR 16
  158. /**
  159. * Something somehow does not look correct. This may or may not
  160. * lead to problems. An example would be the use of '-vstrict -2'.
  161. */
  162. #define AV_LOG_WARNING 24
  163. /**
  164. * Standard information.
  165. */
  166. #define AV_LOG_INFO 32
  167. /**
  168. * Detailed information.
  169. */
  170. #define AV_LOG_VERBOSE 40
  171. /**
  172. * Stuff which is only useful for libav* developers.
  173. */
  174. #define AV_LOG_DEBUG 48
  175. /**
  176. * Extremely verbose debugging, useful for libav* development.
  177. */
  178. #define AV_LOG_TRACE 56
  179. #define AV_LOG_MAX_OFFSET (AV_LOG_TRACE - AV_LOG_QUIET)
  180. /**
  181. * @}
  182. */
  183. /**
  184. * Sets additional colors for extended debugging sessions.
  185. * @code
  186. av_log(ctx, AV_LOG_DEBUG|AV_LOG_C(134), "Message in purple\n");
  187. @endcode
  188. * Requires 256color terminal support. Uses outside debugging is not
  189. * recommended.
  190. */
  191. #define AV_LOG_C(x) ((x) << 8)
  192. /**
  193. * Send the specified message to the log if the level is less than or equal
  194. * to the current av_log_level. By default, all logging messages are sent to
  195. * stderr. This behavior can be altered by setting a different logging callback
  196. * function.
  197. * @see av_log_set_callback
  198. *
  199. * @param avcl A pointer to an arbitrary struct of which the first field is a
  200. * pointer to an AVClass struct or NULL if general log.
  201. * @param level The importance level of the message expressed using a @ref
  202. * lavu_log_constants "Logging Constant".
  203. * @param fmt The format string (printf-compatible) that specifies how
  204. * subsequent arguments are converted to output.
  205. */
  206. void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
  207. /**
  208. * Send the specified message to the log once with the initial_level and then with
  209. * the subsequent_level. By default, all logging messages are sent to
  210. * stderr. This behavior can be altered by setting a different logging callback
  211. * function.
  212. * @see av_log
  213. *
  214. * @param avcl A pointer to an arbitrary struct of which the first field is a
  215. * pointer to an AVClass struct or NULL if general log.
  216. * @param initial_level importance level of the message expressed using a @ref
  217. * lavu_log_constants "Logging Constant" for the first occurance.
  218. * @param subsequent_level importance level of the message expressed using a @ref
  219. * lavu_log_constants "Logging Constant" after the first occurance.
  220. * @param fmt The format string (printf-compatible) that specifies how
  221. * subsequent arguments are converted to output.
  222. * @param state a variable to keep trak of if a message has already been printed
  223. * this must be initialized to 0 before the first use. The same state
  224. * must not be accessed by 2 Threads simultaneously.
  225. */
  226. void av_log_once(void* avcl, int initial_level, int subsequent_level, int *state, const char *fmt, ...) av_printf_format(5, 6);
  227. /**
  228. * Send the specified message to the log if the level is less than or equal
  229. * to the current av_log_level. By default, all logging messages are sent to
  230. * stderr. This behavior can be altered by setting a different logging callback
  231. * function.
  232. * @see av_log_set_callback
  233. *
  234. * @param avcl A pointer to an arbitrary struct of which the first field is a
  235. * pointer to an AVClass struct.
  236. * @param level The importance level of the message expressed using a @ref
  237. * lavu_log_constants "Logging Constant".
  238. * @param fmt The format string (printf-compatible) that specifies how
  239. * subsequent arguments are converted to output.
  240. * @param vl The arguments referenced by the format string.
  241. */
  242. void av_vlog(void *avcl, int level, const char *fmt, va_list vl);
  243. /**
  244. * Get the current log level
  245. *
  246. * @see lavu_log_constants
  247. *
  248. * @return Current log level
  249. */
  250. int av_log_get_level(void);
  251. /**
  252. * Set the log level
  253. *
  254. * @see lavu_log_constants
  255. *
  256. * @param level Logging level
  257. */
  258. void av_log_set_level(int level);
  259. /**
  260. * Set the logging callback
  261. *
  262. * @note The callback must be thread safe, even if the application does not use
  263. * threads itself as some codecs are multithreaded.
  264. *
  265. * @see av_log_default_callback
  266. *
  267. * @param callback A logging function with a compatible signature.
  268. */
  269. void av_log_set_callback(void (*callback)(void*, int, const char*, va_list));
  270. /**
  271. * Default logging callback
  272. *
  273. * It prints the message to stderr, optionally colorizing it.
  274. *
  275. * @param avcl A pointer to an arbitrary struct of which the first field is a
  276. * pointer to an AVClass struct.
  277. * @param level The importance level of the message expressed using a @ref
  278. * lavu_log_constants "Logging Constant".
  279. * @param fmt The format string (printf-compatible) that specifies how
  280. * subsequent arguments are converted to output.
  281. * @param vl The arguments referenced by the format string.
  282. */
  283. void av_log_default_callback(void *avcl, int level, const char *fmt,
  284. va_list vl);
  285. /**
  286. * Return the context name
  287. *
  288. * @param ctx The AVClass context
  289. *
  290. * @return The AVClass class_name
  291. */
  292. const char* av_default_item_name(void* ctx);
  293. AVClassCategory av_default_get_category(void *ptr);
  294. /**
  295. * Format a line of log the same way as the default callback.
  296. * @param line buffer to receive the formatted line
  297. * @param line_size size of the buffer
  298. * @param print_prefix used to store whether the prefix must be printed;
  299. * must point to a persistent integer initially set to 1
  300. */
  301. void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
  302. char *line, int line_size, int *print_prefix);
  303. /**
  304. * Format a line of log the same way as the default callback.
  305. * @param line buffer to receive the formatted line;
  306. * may be NULL if line_size is 0
  307. * @param line_size size of the buffer; at most line_size-1 characters will
  308. * be written to the buffer, plus one null terminator
  309. * @param print_prefix used to store whether the prefix must be printed;
  310. * must point to a persistent integer initially set to 1
  311. * @return Returns a negative value if an error occurred, otherwise returns
  312. * the number of characters that would have been written for a
  313. * sufficiently large buffer, not including the terminating null
  314. * character. If the return value is not less than line_size, it means
  315. * that the log message was truncated to fit the buffer.
  316. */
  317. int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,
  318. char *line, int line_size, int *print_prefix);
  319. /**
  320. * Skip repeated messages, this requires the user app to use av_log() instead of
  321. * (f)printf as the 2 would otherwise interfere and lead to
  322. * "Last message repeated x times" messages below (f)printf messages with some
  323. * bad luck.
  324. * Also to receive the last, "last repeated" line if any, the user app must
  325. * call av_log(NULL, AV_LOG_QUIET, "%s", ""); at the end
  326. */
  327. #define AV_LOG_SKIP_REPEATED 1
  328. /**
  329. * Include the log severity in messages originating from codecs.
  330. *
  331. * Results in messages such as:
  332. * [rawvideo @ 0xDEADBEEF] [error] encode did not produce valid pts
  333. */
  334. #define AV_LOG_PRINT_LEVEL 2
  335. void av_log_set_flags(int arg);
  336. int av_log_get_flags(void);
  337. /**
  338. * @}
  339. */
  340. #endif /* AVUTIL_LOG_H */