History

avutil/log: Add av_log_once() for printing a message just once with a high log level

Compared to ad-hoc if(printed) ... code this allows the user to disable it by adjusting the log level

Michael Niedermayer committed 6 years ago

Commit 31821141 parent f15007a4 files · +34 −1Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavutil/log.c +9 −0
  3. libavutil/log.h +21 −0
  4. libavutil/version.h +1 −1
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2017-10-21 · 14 unmodified lines
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182020-02-12 - xxxxxxxxxx - lavu 56.40.100 - log.h
19 Add av_log_once().
20
182020-02-04 - xxxxxxxxxx - lavu 56.39.100 - hwcontext.h212020-02-04 - xxxxxxxxxx - lavu 56.39.100 - hwcontext.h
19 Add AV_PIX_FMT_VULKAN22 Add AV_PIX_FMT_VULKAN
20 Add AV_HWDEVICE_TYPE_VULKAN and implementation.23 Add AV_HWDEVICE_TYPE_VULKAN and implementation.
libavutil/log.c+9−0
@@ -412,6 +412,15 @@ void av_log(void* avcl, int level, const char *fmt, ...) · 411 unmodified lines
412 va_end(vl);412 va_end(vl);
413}413}
414 414
415void av_log_once(void* avcl, int initial_level, int subsequent_level, int *state, const char *fmt, ...)
416{
417 va_list vl;
418 va_start(vl, fmt);
419 av_vlog(avcl, *state ? subsequent_level : initial_level, fmt, vl);
420 va_end(vl);
421 *state = 1;
422}
423
415void av_vlog(void* avcl, int level, const char *fmt, va_list vl)424void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
416{425{
417 AVClass* avc = avcl ? *(AVClass **) avcl : NULL;426 AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
libavutil/log.h+21−0
@@ -233,6 +233,27 @@ typedef struct AVClass { · 232 unmodified lines
233 */233 */
234void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);234void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
235 235
236/**
237 * Send the specified message to the log once with the initial_level and then with
238 * the subsequent_level. By default, all logging messages are sent to
239 * stderr. This behavior can be altered by setting a different logging callback
240 * function.
241 * @see av_log
242 *
243 * @param avcl A pointer to an arbitrary struct of which the first field is a
244 * pointer to an AVClass struct or NULL if general log.
245 * @param initial_level importance level of the message expressed using a @ref
246 * lavu_log_constants "Logging Constant" for the first occurance.
247 * @param subsequent_level importance level of the message expressed using a @ref
248 * lavu_log_constants "Logging Constant" after the first occurance.
249 * @param fmt The format string (printf-compatible) that specifies how
250 * subsequent arguments are converted to output.
251 * @param state a variable to keep trak of if a message has already been printed
252 * this must be initialized to 0 before the first use. The same state
253 * must not be accessed by 2 Threads simultaneously.
254 */
255void av_log_once(void* avcl, int initial_level, int subsequent_level, int *state, const char *fmt, ...) av_printf_format(5, 6);
256
236 257
237/**258/**
238 * Send the specified message to the log if the level is less than or equal259 * Send the specified message to the log if the level is less than or equal
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
79 */79 */
80 80
81#define LIBAVUTIL_VERSION_MAJOR 5681#define LIBAVUTIL_VERSION_MAJOR 56
82#define LIBAVUTIL_VERSION_MINOR 3982#define LIBAVUTIL_VERSION_MINOR 40
83#define LIBAVUTIL_VERSION_MICRO 10083#define LIBAVUTIL_VERSION_MICRO 100
84 84
85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t