log.h 13 KB

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