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 core.stdc.string; 23 import core.stdc.stdarg; 24 25 extern (C) @nogc nothrow: 26 27 enum AVClassCategory 28 { 29 AV_CLASS_CATEGORY_NA = 0, 30 AV_CLASS_CATEGORY_INPUT = 1, 31 AV_CLASS_CATEGORY_OUTPUT = 2, 32 AV_CLASS_CATEGORY_MUXER = 3, 33 AV_CLASS_CATEGORY_DEMUXER = 4, 34 AV_CLASS_CATEGORY_ENCODER = 5, 35 AV_CLASS_CATEGORY_DECODER = 6, 36 AV_CLASS_CATEGORY_FILTER = 7, 37 AV_CLASS_CATEGORY_BITSTREAM_FILTER = 8, 38 AV_CLASS_CATEGORY_SWSCALER = 9, 39 AV_CLASS_CATEGORY_SWRESAMPLER = 10, 40 AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT = 40, 41 AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT = 41, 42 AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT = 42, 43 AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT = 43, 44 AV_CLASS_CATEGORY_DEVICE_OUTPUT = 44, 45 AV_CLASS_CATEGORY_DEVICE_INPUT = 45, 46 AV_CLASS_CATEGORY_NB = 46 ///< not part of ABI/API 47 } 48 49 extern (D) auto AV_IS_INPUT_DEVICE(T)(auto ref T category) 50 { 51 return (category == AVClassCategory.AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT) || (category == AVClassCategory.AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT) || (category == AVClassCategory.AV_CLASS_CATEGORY_DEVICE_INPUT); 52 } 53 54 extern (D) auto AV_IS_OUTPUT_DEVICE(T)(auto ref T category) 55 { 56 return (category == AVClassCategory.AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT) || (category == AVClassCategory.AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT) || (category == AVClassCategory.AV_CLASS_CATEGORY_DEVICE_OUTPUT); 57 } 58 59 struct AVOptionRanges; 60 61 /** 62 * Describe the class of an AVClass context structure. That is an 63 * arbitrary struct of which the first field is a pointer to an 64 * AVClass struct (e.g. AVCodecContext, AVFormatContext etc.). 65 */ 66 struct AVClass 67 { 68 /** 69 * The name of the class; usually it is the same name as the 70 * context structure type to which the AVClass is associated. 71 */ 72 const(char)* class_name; 73 74 /** 75 * A pointer to a function which returns the name of a context 76 * instance ctx associated with the class. 77 */ 78 const(char)* function (void* ctx) item_name; 79 80 /** 81 * a pointer to the first option specified in the class if any or NULL 82 * 83 * @see av_set_default_options() 84 */ 85 struct AVOption; 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 version_; 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 the 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 * Iterate over the AVClasses corresponding to potential AVOptions-enabled 147 * children. 148 * 149 * @param iter pointer to opaque iteration state. The caller must initialize 150 * *iter to NULL before the first call. 151 * @return AVClass for the next AVOptions-enabled child or NULL if there are 152 * no more such children. 153 * 154 * @note The difference between child_next and this is that child_next 155 * iterates over _already existing_ objects, while child_class_iterate 156 * iterates over _all possible_ children. 157 */ 158 const(AVClass)* function (void** iter) child_class_iterate; 159 } 160 161 /** 162 * @addtogroup lavu_log 163 * 164 * @{ 165 * 166 * @defgroup lavu_log_constants Logging Constants 167 * 168 * @{ 169 */ 170 171 /** 172 * Print no output. 173 */ 174 enum AV_LOG_QUIET = -8; 175 176 /** 177 * Something went really wrong and we will crash now. 178 */ 179 enum AV_LOG_PANIC = 0; 180 181 /** 182 * Something went wrong and recovery is not possible. 183 * For example, no header was found for a format which depends 184 * on headers or an illegal combination of parameters is used. 185 */ 186 enum AV_LOG_FATAL = 8; 187 188 /** 189 * Something went wrong and cannot losslessly be recovered. 190 * However, not all future data is affected. 191 */ 192 enum AV_LOG_ERROR = 16; 193 194 /** 195 * Something somehow does not look correct. This may or may not 196 * lead to problems. An example would be the use of '-vstrict -2'. 197 */ 198 enum AV_LOG_WARNING = 24; 199 200 /** 201 * Standard information. 202 */ 203 enum AV_LOG_INFO = 32; 204 205 /** 206 * Detailed information. 207 */ 208 enum AV_LOG_VERBOSE = 40; 209 210 /** 211 * Stuff which is only useful for libav* developers. 212 */ 213 enum AV_LOG_DEBUG = 48; 214 215 /** 216 * Extremely verbose debugging, useful for libav* development. 217 */ 218 enum AV_LOG_TRACE = 56; 219 220 enum AV_LOG_MAX_OFFSET = AV_LOG_TRACE - AV_LOG_QUIET; 221 222 /** 223 * @} 224 */ 225 226 /** 227 * Sets additional colors for extended debugging sessions. 228 * @code 229 av_log(ctx, AV_LOG_DEBUG|AV_LOG_C(134), "Message in purple\n"); 230 @endcode 231 * Requires 256color terminal support. Uses outside debugging is not 232 * recommended. 233 */ 234 extern (D) auto AV_LOG_C(T)(auto ref T x) 235 { 236 return x << 8; 237 } 238 239 /** 240 * Send the specified message to the log if the level is less than or equal 241 * to the current av_log_level. By default, all logging messages are sent to 242 * stderr. This behavior can be altered by setting a different logging callback 243 * function. 244 * @see av_log_set_callback 245 * 246 * @param avcl A pointer to an arbitrary struct of which the first field is a 247 * pointer to an AVClass struct or NULL if general log. 248 * @param level The importance level of the message expressed using a @ref 249 * lavu_log_constants "Logging Constant". 250 * @param fmt The format string (printf-compatible) that specifies how 251 * subsequent arguments are converted to output. 252 */ 253 void av_log (void* avcl, int level, const(char)* fmt, ...); 254 255 /** 256 * Send the specified message to the log once with the initial_level and then with 257 * the subsequent_level. By default, all logging messages are sent to 258 * stderr. This behavior can be altered by setting a different logging callback 259 * function. 260 * @see av_log 261 * 262 * @param avcl A pointer to an arbitrary struct of which the first field is a 263 * pointer to an AVClass struct or NULL if general log. 264 * @param initial_level importance level of the message expressed using a @ref 265 * lavu_log_constants "Logging Constant" for the first occurance. 266 * @param subsequent_level importance level of the message expressed using a @ref 267 * lavu_log_constants "Logging Constant" after the first occurance. 268 * @param fmt The format string (printf-compatible) that specifies how 269 * subsequent arguments are converted to output. 270 * @param state a variable to keep trak of if a message has already been printed 271 * this must be initialized to 0 before the first use. The same state 272 * must not be accessed by 2 Threads simultaneously. 273 */ 274 void av_log_once (void* avcl, int initial_level, int subsequent_level, int* state, const(char)* fmt, ...); 275 276 /** 277 * Send the specified message to the log if the level is less than or equal 278 * to the current av_log_level. By default, all logging messages are sent to 279 * stderr. This behavior can be altered by setting a different logging callback 280 * function. 281 * @see av_log_set_callback 282 * 283 * @param avcl A pointer to an arbitrary struct of which the first field is a 284 * pointer to an AVClass struct. 285 * @param level The importance level of the message expressed using a @ref 286 * lavu_log_constants "Logging Constant". 287 * @param fmt The format string (printf-compatible) that specifies how 288 * subsequent arguments are converted to output. 289 * @param vl The arguments referenced by the format string. 290 */ 291 void av_vlog (void* avcl, int level, const(char)* fmt, va_list vl); 292 293 /** 294 * Get the current log level 295 * 296 * @see lavu_log_constants 297 * 298 * @return Current log level 299 */ 300 int av_log_get_level (); 301 302 /** 303 * Set the log level 304 * 305 * @see lavu_log_constants 306 * 307 * @param level Logging level 308 */ 309 void av_log_set_level (int level); 310 311 /** 312 * Set the logging callback 313 * 314 * @note The callback must be thread safe, even if the application does not use 315 * threads itself as some codecs are multithreaded. 316 * 317 * @see av_log_default_callback 318 * 319 * @param callback A logging function with a compatible signature. 320 */ 321 void av_log_set_callback (void function (void*, int, const(char)*, va_list) callback); 322 323 /** 324 * Default logging callback 325 * 326 * It prints the message to stderr, optionally colorizing it. 327 * 328 * @param avcl A pointer to an arbitrary struct of which the first field is a 329 * pointer to an AVClass struct. 330 * @param level The importance level of the message expressed using a @ref 331 * lavu_log_constants "Logging Constant". 332 * @param fmt The format string (printf-compatible) that specifies how 333 * subsequent arguments are converted to output. 334 * @param vl The arguments referenced by the format string. 335 */ 336 void av_log_default_callback ( 337 void* avcl, 338 int level, 339 const(char)* fmt, 340 va_list vl); 341 342 /** 343 * Return the context name 344 * 345 * @param ctx The AVClass context 346 * 347 * @return The AVClass class_name 348 */ 349 const(char)* av_default_item_name (void* ctx); 350 AVClassCategory av_default_get_category (void* ptr); 351 352 /** 353 * Format a line of log the same way as the default callback. 354 * @param line buffer to receive the formatted line 355 * @param line_size size of the buffer 356 * @param print_prefix used to store whether the prefix must be printed; 357 * must point to a persistent integer initially set to 1 358 */ 359 void av_log_format_line ( 360 void* ptr, 361 int level, 362 const(char)* fmt, 363 va_list vl, 364 char* line, 365 int line_size, 366 int* print_prefix); 367 368 /** 369 * Format a line of log the same way as the default callback. 370 * @param line buffer to receive the formatted line; 371 * may be NULL if line_size is 0 372 * @param line_size size of the buffer; at most line_size-1 characters will 373 * be written to the buffer, plus one null terminator 374 * @param print_prefix used to store whether the prefix must be printed; 375 * must point to a persistent integer initially set to 1 376 * @return Returns a negative value if an error occurred, otherwise returns 377 * the number of characters that would have been written for a 378 * sufficiently large buffer, not including the terminating null 379 * character. If the return value is not less than line_size, it means 380 * that the log message was truncated to fit the buffer. 381 */ 382 int av_log_format_line2 ( 383 void* ptr, 384 int level, 385 const(char)* fmt, 386 va_list vl, 387 char* line, 388 int line_size, 389 int* print_prefix); 390 391 /** 392 * Skip repeated messages, this requires the user app to use av_log() instead of 393 * (f)printf as the 2 would otherwise interfere and lead to 394 * "Last message repeated x times" messages below (f)printf messages with some 395 * bad luck. 396 * Also to receive the last, "last repeated" line if any, the user app must 397 * call av_log(NULL, AV_LOG_QUIET, "%s", ""); at the end 398 */ 399 enum AV_LOG_SKIP_REPEATED = 1; 400 401 /** 402 * Include the log severity in messages originating from codecs. 403 * 404 * Results in messages such as: 405 * [rawvideo @ 0xDEADBEEF] [error] encode did not produce valid pts 406 */ 407 enum AV_LOG_PRINT_LEVEL = 2; 408 409 void av_log_set_flags (int arg); 410 int av_log_get_flags (); 411 412 /** 413 * @} 414 */ 415 416 /* AVUTIL_LOG_H */