]> git.sesse.net Git - ffmpeg/commitdiff
avutil/log: Add av_log_once() for printing a message just once with a high log level
authorMichael Niedermayer <michael@niedermayer.cc>
Thu, 16 Jan 2020 15:34:07 +0000 (16:34 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Wed, 12 Feb 2020 09:25:25 +0000 (10:25 +0100)
Compared to ad-hoc if(printed) ... code this allows the user to disable
it by adjusting the log level

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
doc/APIchanges
libavutil/log.c
libavutil/log.h
libavutil/version.h

index 81969c301ca65a3b07a3d5991fa5c968fdc228f7..30f188d6aa30b319ffcf7ed27b838d98f2de85b7 100644 (file)
@@ -15,6 +15,9 @@ libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2020-02-12 - xxxxxxxxxx - lavu 56.40.100 - log.h
+  Add av_log_once().
+
 2020-02-04 - xxxxxxxxxx - lavu 56.39.100 - hwcontext.h
   Add AV_PIX_FMT_VULKAN
   Add AV_HWDEVICE_TYPE_VULKAN and implementation.
index 78e703b9e9ac25dd41c22f2d5da9f9bc00022552..8d4945249eb863ac9a1c1c5922db39925d285e3e 100644 (file)
@@ -412,6 +412,15 @@ void av_log(void* avcl, int level, const char *fmt, ...)
     va_end(vl);
 }
 
+void av_log_once(void* avcl, int initial_level, int subsequent_level, int *state, const char *fmt, ...)
+{
+    va_list vl;
+    va_start(vl, fmt);
+    av_vlog(avcl, *state ? subsequent_level : initial_level, fmt, vl);
+    va_end(vl);
+    *state = 1;
+}
+
 void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
 {
     AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
index d9554e609d40027760b744e666db44984103072d..9c14188a9c924a5aa9ee054bcfd09dd1d419729a 100644 (file)
@@ -233,6 +233,27 @@ typedef struct AVClass {
  */
 void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
 
+/**
+ * Send the specified message to the log once with the initial_level and then with
+ * the subsequent_level. By default, all logging messages are sent to
+ * stderr. This behavior can be altered by setting a different logging callback
+ * function.
+ * @see av_log
+ *
+ * @param avcl A pointer to an arbitrary struct of which the first field is a
+ *        pointer to an AVClass struct or NULL if general log.
+ * @param initial_level importance level of the message expressed using a @ref
+ *        lavu_log_constants "Logging Constant" for the first occurance.
+ * @param subsequent_level importance level of the message expressed using a @ref
+ *        lavu_log_constants "Logging Constant" after the first occurance.
+ * @param fmt The format string (printf-compatible) that specifies how
+ *        subsequent arguments are converted to output.
+ * @param state a variable to keep trak of if a message has already been printed
+ *        this must be initialized to 0 before the first use. The same state
+ *        must not be accessed by 2 Threads simultaneously.
+ */
+void av_log_once(void* avcl, int initial_level, int subsequent_level, int *state, const char *fmt, ...) av_printf_format(5, 6);
+
 
 /**
  * Send the specified message to the log if the level is less than or equal
index 2bc1b98615891e36300076b51984cda231a740d6..633a21dca36990ea9ff67705ce6cb830be96763d 100644 (file)
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  39
+#define LIBAVUTIL_VERSION_MINOR  40
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \