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