From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 02BB54D31F for ; Fri, 16 May 2025 23:11:12 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 7D0B068CEF5; Sat, 17 May 2025 02:11:01 +0300 (EEST) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 67CED68CEED for ; Sat, 17 May 2025 02:10:54 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id EE2D8E1167; Sat, 17 May 2025 01:07:35 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x3SRi0EExiMe; Sat, 17 May 2025 01:07:34 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 651B4E1DC2; Sat, 17 May 2025 01:07:34 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 May 2025 01:08:59 +0200 Message-ID: <20250516231041.4640-2-cus@passwd.hu> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250516231041.4640-1-cus@passwd.hu> References: <20250516231041.4640-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] fftools/cmdutils: factorize loading a file from the datadir 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: Marton Balint 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: This changes the order of preset file loading slighly to be in line with the documentation, because before the patch codec-prefixed presets were probed before trying the next directory. Signed-off-by: Marton Balint --- fftools/cmdutils.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index e516ee6ebd..1de670c2e4 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -920,9 +920,7 @@ int read_yesno(void) return yesno; } -FILE *get_preset_file(AVBPrint *filename, - const char *preset_name, int is_path, - const char *codec_name) +static FILE *get_datadir_file_fmt(AVBPrint *filename, const char *fmt, ...) { FILE *f = NULL; int i; @@ -935,11 +933,6 @@ FILE *get_preset_file(AVBPrint *filename, env_home, /* index=1(HOME) is special: search in a .ffmpeg subfolder */ FFMPEG_DATADIR, }; - if (is_path) { - av_bprintf(filename, "%s", preset_name); - if (av_bprint_is_complete(filename)) - f = fopen_utf8(filename->str, "r"); - } else { #if HAVE_GETMODULEHANDLE && defined(_WIN32) wchar_t *datadir_w = get_module_filename(NULL); base[2] = NULL; @@ -969,21 +962,21 @@ FILE *get_preset_file(AVBPrint *filename, } } #endif + + { + va_list ap; + for (i = 0; i < 3 && !f; i++) { if (!base[i]) continue; av_bprint_clear(filename); - av_bprintf(filename, "%s%s/%s.ffpreset", base[i], - i != 1 ? "" : "/.ffmpeg", preset_name); + av_bprintf(filename, "%s%s/", base[i], i != 1 ? "" : "/.ffmpeg"); + va_start(ap, fmt); + av_vbprintf(filename, fmt, ap); + va_end(ap); + if (!av_bprint_is_complete(filename)) + break; f = fopen_utf8(filename->str, "r"); - if (!f && codec_name) { - av_bprint_clear(filename); - av_bprintf(filename, - "%s%s/%s-%s.ffpreset", - base[i], i != 1 ? "" : "/.ffmpeg", codec_name, - preset_name); - f = fopen_utf8(filename->str, "r"); - } } } @@ -995,6 +988,23 @@ FILE *get_preset_file(AVBPrint *filename, return f; } +FILE *get_preset_file(AVBPrint *filename, + const char *preset_name, int is_path, + const char *codec_name) +{ + FILE *f = NULL; + if (is_path) { + av_bprintf(filename, "%s", preset_name); + if (av_bprint_is_complete(filename)) + f = fopen_utf8(filename->str, "r"); + } else { + f = get_datadir_file_fmt(filename, "%s.ffpreset", preset_name); + if (!f && codec_name) + f = get_datadir_file_fmt(filename, "%s%s/%s-%s.ffpreset", codec_name, preset_name); + } + return f; +} + int cmdutils_isalnum(char c) { return (c >= '0' && c <= '9') || -- 2.43.0 _______________________________________________ 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".