Skip to content

Commit 3182114

Browse files
committed
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 Signed-off-by: Michael Niedermayer <[email protected]>
1 parent f15007a commit 3182114

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

doc/APIchanges

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
1515

1616
API changes, most recent first:
1717

18+
2020-02-12 - xxxxxxxxxx - lavu 56.40.100 - log.h
19+
Add av_log_once().
20+
1821
2020-02-04 - xxxxxxxxxx - lavu 56.39.100 - hwcontext.h
1922
Add AV_PIX_FMT_VULKAN
2023
Add AV_HWDEVICE_TYPE_VULKAN and implementation.

libavutil/log.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,15 @@ void av_log(void* avcl, int level, const char *fmt, ...)
412412
va_end(vl);
413413
}
414414

415+
void 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+
415424
void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
416425
{
417426
AVClass* avc = avcl ? *(AVClass **) avcl : NULL;

libavutil/log.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,27 @@ typedef struct AVClass {
233233
*/
234234
void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
235235

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+
*/
255+
void av_log_once(void* avcl, int initial_level, int subsequent_level, int *state, const char *fmt, ...) av_printf_format(5, 6);
256+
236257

237258
/**
238259
* Send the specified message to the log if the level is less than or equal

libavutil/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
*/
8080

8181
#define LIBAVUTIL_VERSION_MAJOR 56
82-
#define LIBAVUTIL_VERSION_MINOR 39
82+
#define LIBAVUTIL_VERSION_MINOR 40
8383
#define LIBAVUTIL_VERSION_MICRO 100
8484

8585
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

0 commit comments

Comments
 (0)