From patchwork Sun Feb 2 10:49:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 17659 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 61BBD441BFD for ; Sun, 2 Feb 2020 12:51:04 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4AE14689A4B; Sun, 2 Feb 2020 12:51:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-3.mx.upcmail.net (vie01a-dmta-pe05-3.mx.upcmail.net [84.116.36.13]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5082B688117 for ; Sun, 2 Feb 2020 12:50:57 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1iyCq9-0002ZK-0a for ffmpeg-devel@ffmpeg.org; Sun, 02 Feb 2020 11:50:57 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id yCpAiBUGPwlysyCpAixYrA; Sun, 02 Feb 2020 11:49:57 +0100 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=E5OzWpVl c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=dgY1dt6WGnCm1oj3sKcA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 2 Feb 2020 11:49:56 +0100 Message-Id: <20200202104956.11999-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfNigOq56s6OwvXxZmPncZXMjIBj4xOOj1dK/Nan4nJQ5gEGYUO3I6mVcLrIq4rLHIyibKMfszpjBYQA5Care20SOn5csvqf893rsLaoFHAZyGHR8HrPd hwhi6xTuBhxnENytiBTu+KTMmcmbfFQSOKtAWSxraO1VHA/UuI1JxdAY Subject: [FFmpeg-devel] [PATCH] avutil/log: Add av_log_once() for printing a message just once with a high log level X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Compared to ad-hoc if(printed) ... code this allows the user to disable it by adjusting the log level TODO: APIChanges & version bump Signed-off-by: Michael Niedermayer --- libavutil/log.c | 9 +++++++++ libavutil/log.h | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/libavutil/log.c b/libavutil/log.c index 0a7b169bc0..57301d42d6 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -368,6 +368,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; diff --git a/libavutil/log.h b/libavutil/log.h index d9554e609d..9c14188a9c 100644 --- a/libavutil/log.h +++ b/libavutil/log.h @@ -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