From patchwork Thu Jan 16 16:51:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 17386 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 3805244A0AC for ; Thu, 16 Jan 2020 19:03:01 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 18F8368B002; Thu, 16 Jan 2020 19:03:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe01-2.mx.upcmail.net (vie01a-dmta-pe01-2.mx.upcmail.net [62.179.121.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2335868AFFC for ; Thu, 16 Jan 2020 19:02:54 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe01.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1is8QO-0005iW-0u for ffmpeg-devel@ffmpeg.org; Thu, 16 Jan 2020 17:55:16 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id s8PPiJ6F4wlyss8PPigFbv; Thu, 16 Jan 2020 17:54:16 +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=tCK7bAYBlE2wtvdxCSQA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 16 Jan 2020 17:51:28 +0100 Message-Id: <20200116165129.1058-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 X-CMAE-Envelope: MS4wfFBOcwMr5LlDBJQSN/i23N+hGs2H7G7tzbqbbByMqbL+tHECIJsQVFFagZsEM77qMA5HMxiLMOb4++HlHacxy5VjcBxyfVl7Xcaqg8lqyZ4xPo2CVcnJ RJ0ZMg1ucMb4vpWJz8nlVpszwyC1j12jULRSpR7+9TeSj+SvzicAmUWV Subject: [FFmpeg-devel] [PATCH 1/2] avutil/log: Add av_log_once() for printing a message just once per instance 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Compared to ad-hoc if(printed) ... code this allows the user to disable it with a flag and see all repeated messages, it is also simpler TODO: APIChanges & version bump Signed-off-by: Michael Niedermayer --- libavutil/log.c | 15 +++++++++++++++ libavutil/log.h | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/libavutil/log.c b/libavutil/log.c index e8a0db7716..7646e18cfa 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -372,6 +372,21 @@ void av_log(void* avcl, int level, const char *fmt, ...) va_end(vl); } +void av_log_once(void* avcl, int level, int *state, const char *fmt, ...) +{ + if (!((flags & AV_LOG_SKIP_REPEATED) && *state)) { + AVClass* avc = avcl ? *(AVClass **) avcl : NULL; + va_list vl; + va_start(vl, fmt); + if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) && + avc->log_level_offset_offset && level >= AV_LOG_FATAL) + level += *(int *) (((uint8_t *) avcl) + avc->log_level_offset_offset); + av_vlog(avcl, level, fmt, vl); + va_end(vl); + *state = 1; + } +} + void av_vlog(void* avcl, int level, const char *fmt, va_list vl) { void (*log_callback)(void*, int, const char*, va_list) = av_log_callback; diff --git a/libavutil/log.h b/libavutil/log.h index d9554e609d..618d0d1817 100644 --- a/libavutil/log.h +++ b/libavutil/log.h @@ -233,6 +233,25 @@ 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 if the level is less than or equal + * to the current av_log_level. By default, all logging messages are sent to + * stderr. This behavior can be altered by setting a different logging callback + * function. + * If AV_LOG_SKIP_REPEATED is set each message (each unique state) will only be + * printed once. If its not set then this behaves live av_log() + * @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 level The importance level of the message expressed using a @ref + * lavu_log_constants "Logging Constant". + * @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. + */ +void av_log_once(void *avcl, int level, int *state, const char *fmt, ...) av_printf_format(4, 5); /** * Send the specified message to the log if the level is less than or equal From patchwork Thu Jan 16 16:51:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 17387 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 3AE5144ACB3 for ; Thu, 16 Jan 2020 19:04:10 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 26A9768B03C; Thu, 16 Jan 2020 19:04:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-1.mx.upcmail.net (vie01a-dmta-pe06-1.mx.upcmail.net [84.116.36.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7CB06689F3F for ; Thu, 16 Jan 2020 19:04:03 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1is8QO-00086Z-0u for ffmpeg-devel@ffmpeg.org; Thu, 16 Jan 2020 17:55:16 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id s8PQiJ6HHwlyss8PQigFcG; Thu, 16 Jan 2020 17:54:16 +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=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=PrqT0C4z4u8SA-gbcYMA:9 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 16 Jan 2020 17:51:29 +0100 Message-Id: <20200116165129.1058-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200116165129.1058-1-michael@niedermayer.cc> References: <20200116165129.1058-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfFBOcwMr5LlDBJQSN/i23N+hGs2H7G7tzbqbbByMqbL+tHECIJsQVFFagZsEM77qMA5HMxiLMOb4++HlHacxy5VjcBxyfVl7Xcaqg8lqyZ4xPo2CVcnJ RJ0ZMg1ucMb4vpWJz8nlVpszwyC1j12jULRSpR7+9TeSj+SvzicAmUWV Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/h264_ps: Show VUI and SPS overread messages just once per frame thread 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Michael Niedermayer --- libavcodec/h264_ps.c | 3 ++- libavcodec/h264_ps.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c index edbaa96b64..7b523833c1 100644 --- a/libavcodec/h264_ps.c +++ b/libavcodec/h264_ps.c @@ -579,7 +579,8 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, } if (get_bits_left(gb) < 0) { - av_log(avctx, ignore_truncation ? AV_LOG_WARNING : AV_LOG_ERROR, + av_log_once(avctx, ignore_truncation ? AV_LOG_WARNING : AV_LOG_ERROR, + &ps->overread_warning_printed[sps->vui_parameters_present_flag], "Overread %s by %d bits\n", sps->vui_parameters_present_flag ? "VUI" : "SPS", -get_bits_left(gb)); if (!ignore_truncation) goto fail; diff --git a/libavcodec/h264_ps.h b/libavcodec/h264_ps.h index 9014326dfb..2cc1cd6254 100644 --- a/libavcodec/h264_ps.h +++ b/libavcodec/h264_ps.h @@ -144,6 +144,8 @@ typedef struct H264ParamSets { /* currently active parameters sets */ const PPS *pps; const SPS *sps; + + int overread_warning_printed[2]; } H264ParamSets; /**