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
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+9−0
@@ -412,6 +412,15 @@ void av_log(void* avcl, int level, const char *fmt, ...) · 411 unmodified lines
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+21−0
@@ -233,6 +233,27 @@ typedef struct AVClass { · 232 unmodified lines
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+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
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, \

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