From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id DEC064DFF5 for ; Thu, 6 Mar 2025 21:00:06 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3088B68F10C; Thu, 6 Mar 2025 22:59:42 +0200 (EET) Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F305468EECD for ; Thu, 6 Mar 2025 22:59:35 +0200 (EET) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-223378e2b0dso17045825ad.0 for ; Thu, 06 Mar 2025 12:59:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741294774; x=1741899574; darn=ffmpeg.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:from:to:cc:subject:date :message-id:reply-to; bh=R0HTBx64FUEBHpEyJtDmc9IPr9ehT27gmb1oNShG+0w=; b=LU/5IJzWVDmn9otEdXOQ+fDMfAZYPBu2jb38smRb4AHgYEljGK1ShgDFfBlBaY9djP utCXRVbkLuGnaFqUmFtWiHh8spxQ2DXA23LBttz1WGdKGHQzdYeaxjhQB02qY17phwKB j1a2hNtEmMXzkGsRiPBhBgqqyvbUNcxcVpySaAYPZh91QUCfH3M++nQm3iNwUyXykf6a CqWNNz63FL/nZUN6ERs2N+2Q59HCfbt0xJySSyNudpoClUh1/02v9E2EhgbfBwHZ2tnx yamB4GK0w0Mfv+m4HWehp2Sy1Wy7+AqZ9SLYzCV8xYwyu/U0E/PK2O62mgvCk7amVqbP mQTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741294774; x=1741899574; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=R0HTBx64FUEBHpEyJtDmc9IPr9ehT27gmb1oNShG+0w=; b=bUWnquubGI1i0D+IFsetUpLDShturi7QxdLq9V6HhWluv0mZyxUCrJxKNycwlKRNv6 xWgz7APk9vDKXoyfatNaXDzlvAactvSDGWdtbpaL8bgA3qO/IpIhS2OzF83Q1vJvRkJ2 GHHNUZkFUL/GqqQL342ulX9uoNLwuy0GAroNRIy47tiGcsjIj0ONKVaSUH+Q8rb+nAwN yGpztRwrv5vPqatPHlaCdRAE9AE1SYPTjWuKCUtVtd5DU+ipMODIIcx2VX5kr7pCHKus Cy2MUQIZgKWm7rFu11CsiqT0k02FmbPUQUHnbI7i2TaP17FYmq+XvyXTIDxPELBmEMJQ lC8g== X-Gm-Message-State: AOJu0YysWZbKBDOSSC+c181z1eKtdg0QzXWfNUG6Djzo24nn/G0U9o70 +JdhI4sYACwLLnoCxEUlekpMgSICdBvNcK2ZI1ImOrXRWNLruW0TNXtsRiLJ X-Gm-Gg: ASbGncsUWrSGnTymW/KH8yHjihBm3J4SvNWI2GLnXHq3e5u8lO4jBICqh/8rgDW/Dpo W/auzRc6M0/zm0RiY3n+sGu/RoJuPRB6PQVj2quV/MkWHuRbfboaLYa1fuUJAOWqgr2N/5Lqu4q NhRpGrluvRha2PGlyTEO6fAVe0NX59g2CrmapQwCE1jOSypHvqpAZrmciZpEp9lkDz3S/fIIlGc tFqVelq/RDcXi5HpC0V2fgpu33Z3FN95+ujezMirabvpPx5SJXclEFT3wBsQWX8HuuPlqH0s6gI PImzhp4cdKdg4dHcvEl3rTUk/WH07hwibqqCC/K1IsVjEXcKVanxy2caBrpSU6Q= X-Google-Smtp-Source: AGHT+IEcHTsndjHCP+QH7AYgLWst8Ir66yhMRz6yezb2PmlcQpqcp7M+JePhDcyoz8HCxk3W0H9G9Q== X-Received: by 2002:a05:6a00:3a0d:b0:736:5486:7820 with SMTP id d2e1a72fcca58-736aaa2db65mr1142904b3a.13.1741294774117; Thu, 06 Mar 2025 12:59:34 -0800 (PST) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-736982441desm1886791b3a.50.2025.03.06.12.59.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Mar 2025 12:59:33 -0800 (PST) From: softworkz X-Google-Original-From: softworkz Message-Id: <105adac4ba8120c87db97690333845b42bbaa899.1741294751.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Thu, 06 Mar 2025 20:59:10 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v3 3/4] fftools: Provide a log formatting callback for context prefixes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: softworkz Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: softworkz This allows to print logical ids instead of memory addresses. The benefits are: - Smaller log file sizes - The disambiguation is much easier to recognize and to follow - It eventually allows comparing and viewing log file diffs without almost every line being different due to those addresses --- fftools/cmdutils.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++ fftools/cmdutils.h | 5 ++++ fftools/ffmpeg.c | 1 + fftools/ffplay.c | 1 + fftools/ffprobe.c | 1 + 5 files changed, 77 insertions(+) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 8ac20bf049..9f93eb6523 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -59,6 +59,56 @@ AVDictionary *format_opts, *codec_opts; int hide_banner = 0; +static int nb_class_ids; + +#define NB_CLASS_IDS 1000 +static struct class_ids { + void *avcl; + uint64_t class_hash; + unsigned id; +} class_ids[NB_CLASS_IDS]; + +static uint64_t fnv_hash(const char *str) +{ + // FNV-1a 64-bit hash algorithm + uint64_t hash = 0xcbf29ce484222325ULL; + while (*str) { + hash ^= (unsigned char)*str++; + hash *= 0x100000001b3ULL; + } + return hash; +} + +static unsigned get_class_id(void* avcl) +{ + AVClass* avc = avcl ? *(AVClass **) avcl : NULL; + const char* class_name = avc->item_name(avcl); + unsigned i, nb_ids = 0; + uint64_t class_hash; + + for (i = 0; i < NB_CLASS_IDS && class_ids[i].avcl; i++) { + if (class_ids[i].avcl == avcl) + return class_ids[i].id; + } + + class_hash = fnv_hash(avc->class_name); + + for (i = 0; i < NB_CLASS_IDS; i++) { + if (class_ids[i].class_hash == class_hash) + nb_ids++; + + if (!class_ids[i].avcl) { + class_ids[i].avcl = avcl; + class_ids[i].class_hash = class_hash; + class_ids[i].id = nb_ids; + return class_ids[i].id; + } + } + + // exceeded NB_CLASS_IDS entries in class_ids[] + return 0; +} + void uninit_opts(void) { av_dict_free(&swr_opts); @@ -550,6 +600,25 @@ static void check_options(const OptionDef *po) } } +static const char *item_name(void *obj, const AVClass *cls) +{ + return (cls->item_name ? cls->item_name : av_default_item_name)(obj); +} + +static void log_formatprefix_callback(AVBPrint* buffer, AVClass** avcl, int log_flags) +{ + const int print_mem = log_flags & AV_LOG_PRINT_MEMADDRESSES; + if (print_mem) + av_bprintf(buffer+0, "[%s @ %p] ", item_name(avcl, *avcl), avcl); + else + av_bprintf(buffer+0, "[%s #%u] ", item_name(avcl, *avcl), get_class_id(avcl)); +} + +void init_logformatting(void) +{ + av_log_set_formatprefix_callback(&log_formatprefix_callback); +} + void parse_loglevel(int argc, char **argv, const OptionDef *options) { int idx; diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 316b6a8c64..182d894ff9 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -401,6 +401,11 @@ int split_commandline(OptionParseContext *octx, int argc, char *argv[], */ void uninit_parse_context(OptionParseContext *octx); +/** + * Sets up formatting callbacks for logging + */ +void init_logformatting(void); + /** * Find the '-loglevel' option in the command line args and apply it. */ diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index dc321fb4a2..f84a7024be 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -955,6 +955,7 @@ int main(int argc, char **argv) setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */ av_log_set_flags(AV_LOG_SKIP_REPEATED); + init_logformatting(); parse_loglevel(argc, argv, options); #if CONFIG_AVDEVICE diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 2a572fc3aa..2e093c0069 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -3762,6 +3762,7 @@ int main(int argc, char **argv) init_dynload(); av_log_set_flags(AV_LOG_SKIP_REPEATED); + init_logformatting(); parse_loglevel(argc, argv, options); /* register all codecs, demux and protocols */ diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 7341731d2f..3a9f2128fd 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -4652,6 +4652,7 @@ int main(int argc, char **argv) init_dynload(); av_log_set_flags(AV_LOG_SKIP_REPEATED); + init_logformatting(); options = real_options; parse_loglevel(argc, argv, options); -- ffmpeg-codebot _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".