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