tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

log.h (14088B)


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