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 0C9064CC29 for ; Fri, 31 Oct 2025 04:55:37 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'ur89WH5xCrlckDQGZypKn86h5eE0jRfBvdEBvKEM3+4=', expected b'Dn8wbKZL5EJpU7hP02kEiJmgzpxUa1BTOBHKOXCnk8c=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1761886490; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=ur89WH5xCrlckDQGZypKn86h5eE0jRfBvdEBvKEM3+4=; b=q34rxfgzK4o8y4aYp87scQ/ak63K3Z2YPhuzybv4Ej7Oz/m27Dpg1djNL07fO8QgoR4jc q4phlpMs0R/2lFSrE1wdj9Ti3m/QhbsuxTvvJQbwh0BciBISCUNV3mq/8wH3i3A6OI6jW9U 3LpP2aq7OshcTN75AVYJf2i2Krax/RGzKpHFZXM/wmIvPIxB/4GS7EpDMgQ4lGmTsad4kjk iMhql6wDT4qCjt2UjTtioi4If5Ih4wZuxgdwNlBve3ukTNT+VoO7OfPk3MHL0Cciijf/Jj8 1fO/fq5jmE8yQQh+FuiGipIRqi7bsui/mrVUP0tHziOt3Lp29HLuzcskBkmw== Received: from [172.19.0.2] (unknown [172.19.0.2]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id E55D468F855; Fri, 31 Oct 2025 06:54:50 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1761886468; b=IcUszFDpDR/4/lBR99Wx1ex98GYcekuax54RcTqtu1p/xILpqwnjANGhsMnW4UDyYmX15 ToX2uquVWAGBf4x9Qlgj5QoTgppzzDwE0S9zhnke2jitZIalgBAAVvNSJl/6sXHh5NDaKxa 3w6rd+Q1+1GIFNPxoXj7xN2KHG80zZQW8bqEWDT2SpS/48NiFnIic7biNkHIMl5eEBeexFn S3GWjczwD3WbuaO7VW2ODr9zHoWxQIYgy7oO7nFnTcWyZ71oEU1sy80QG44VlndyyZwKfVs 5CKqZ7DC8xIKH2LpdedXi+JwrxX/kJsvMc5uJ3jRdU1WEcH4CVxjr78j7w7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1761886468; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=RTs0U7N/cBUSwAllzXL1fcYuowr/2Bvtxv/SzOPKH34=; b=mbFoLFPiNfONpEMH0TNaDp4Q4EOBeYfjaY30+uklEClIsdteyN+xPls07pPGvT3TiAfOz 3h7ilmPedGDgpOIyre0c1ZS9y63TTr9Hrv6Lqh0mdEG+Hp0z5zXFpH2zej30QI4WeGeJ3iH C0F7CLNjCJMUv7vfaWh+LeJ6++x1QthtKhhHiMBXcWQXRSMYZSlR8q71bbdNyaIBrBE5LXV nQwbqyBmXEYqAfaATTlRKw9uRZRtBJACUxNUjCulZKS5H788X0o0vYpLPZVCvX+jK36em0d HkJbqlBij/mp0WjMp0oAF09SG1NtylM0oGwBtxlPLFHVyMZ6vpwKxQ7W0aqQ== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1761886454; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=Dn8wbKZL5EJpU7hP02kEiJmgzpxUa1BTOBHKOXCnk8c=; b=E7fVqF7XL6Qlpm6itv6XPj9tyhscA439/Vw3OmV/2dMDdwv0fYHL9gyWVTXw1TfrS6G3+ vUS1+agicMoXZYi8SaCqDEneKgsJd0HYBXWqug8kZhcsIXQU/TuFmQ3fyMznoBDTteqSIlK 8Da77bnJvyoyVRS+vb3xGj7Pl6u4rZHRAmQfuX0p4czdfgFNbts7ubNISBcgOwRiojReRvk dwfLVtAvagRMQzw4CFOzrHRf1+GbwKC6oev5qSS+OiQSa4cVQQtYmGaPEzgDdR3guvNpfra xJ/P2a/icEmYWX4iOYcjG9TnfcUF3uVFlCtUiDtIx81GmPx75DDWo4aXU9tw== Received: from 02c22a36bd31 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id B262B68F7D4 for ; Fri, 31 Oct 2025 06:54:14 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Fri, 31 Oct 2025 04:54:14 -0000 Message-ID: <176188645499.81.1055473105333256582@7d278768979e> Message-ID-Hash: HUVZWV5U7ZBHP4LVIWPMLM3PYUA4LIMW X-Message-ID-Hash: HUVZWV5U7ZBHP4LVIWPMLM3PYUA4LIMW X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] avformat/libopenmpt: implement file reading callbacks (PR #20801) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: paper via ffmpeg-devel Cc: paper Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #20801 opened by paper URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20801 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20801.patch Before, this code would unnecessarily waste quite a bit of memory reading the entire file in, and in many cases just freeing the result and throwing it out anyway. This commit changes the behavior to use libopenmpt's callback structure. This is much more memory efficient, especially for particularly large files. Both pre-0.3.0 and post-0.3.0 preprocessor branches have been tested working with a plain amiga-style 'M.K.' module in ffplay. Signed-off-by: Paper >>From 81787bbaa31733ad7c5dd2ea727bc7bd06104719 Mon Sep 17 00:00:00 2001 From: Paper Date: Tue, 2 Sep 2025 10:34:14 -0400 Subject: [PATCH] avformat/libopenmpt: implement file reading callbacks Before, this code would unnecessarily waste quite a bit of memory reading the entire file in, and in many cases just freeing the result and throwing it out anyway. This commit changes the behavior to use libopenmpt's callback structure. This is much more memory efficient, especially for particularly large files. Both pre-0.3.0 and post-0.3.0 preprocessor branches have been tested working with a plain amiga-style 'M.K.' module in ffplay. Signed-off-by: Paper --- libavformat/libopenmpt.c | 66 ++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/libavformat/libopenmpt.c b/libavformat/libopenmpt.c index 46af4bff22..52f4ab2b7d 100644 --- a/libavformat/libopenmpt.c +++ b/libavformat/libopenmpt.c @@ -69,6 +69,51 @@ static void openmpt_logfunc(const char *message, void *userdata) av_log(userdata, level, "%s\n", message); } +static size_t av_openmpt_read(void *stream, void *dst, size_t bytes) +{ + AVIOContext *ioctx = stream; + int r; + + /* avio_read takes an int, cap the size accordingly */ + if (bytes > (size_t)INT_MAX) + bytes = (size_t)INT_MAX; + + r = avio_read(ioctx, dst, bytes); + + return (r >= 0) ? r : 0; +} + +static int av_openmpt_seek(void *stream, int64_t offset, int whence) +{ + AVIOContext *ioctx = stream; + int whence_av; + + switch (whence) { + case OPENMPT_STREAM_SEEK_SET: whence_av = SEEK_SET; break; + case OPENMPT_STREAM_SEEK_CUR: whence_av = SEEK_CUR; break; + case OPENMPT_STREAM_SEEK_END: whence_av = SEEK_END; break; + /* invalid value, punt */ + default: return -1; + } + + /* openmpt expects stdio-style seek; don't return new position */ + return (avio_seek(ioctx, offset, whence_av) < 0) ? -1 : 0; +} + +static int64_t av_openmpt_tell(void *stream) +{ + AVIOContext *ioctx = stream; + int64_t r = avio_tell(ioctx); + + return (r < 0) ? -1 : r; +} + +static const openmpt_stream_callbacks openmpt_cbs = { + av_openmpt_read, + av_openmpt_seek, + av_openmpt_tell +}; + #define add_meta(s, name, meta) \ do { \ const char *value = meta; \ @@ -81,30 +126,14 @@ static int read_header_openmpt(AVFormatContext *s) { AVStream *st; OpenMPTContext *openmpt = s->priv_data; - int64_t size; - char *buf; #if OPENMPT_API_VERSION_AT_LEAST(0,3,0) int error; #endif int ret; - size = avio_size(s->pb); - if (size <= 0) - return AVERROR_INVALIDDATA; - buf = av_malloc(size); - if (!buf) - return AVERROR(ENOMEM); - size = avio_read(s->pb, buf, size); - if (size < 0) { - av_log(s, AV_LOG_ERROR, "Reading input buffer failed.\n"); - av_freep(&buf); - return size; - } - #if OPENMPT_API_VERSION_AT_LEAST(0,3,0) error = OPENMPT_ERROR_OK; - openmpt->module = openmpt_module_create_from_memory2(buf, size, openmpt_logfunc, s, NULL, NULL, &error, NULL, NULL); - av_freep(&buf); + openmpt->module = openmpt_module_create2(openmpt_cbs, s->pb, openmpt_logfunc, s, NULL, NULL, &error, NULL, NULL); if (!openmpt->module) { if (error == OPENMPT_ERROR_OUT_OF_MEMORY) return AVERROR(ENOMEM); @@ -114,8 +143,7 @@ static int read_header_openmpt(AVFormatContext *s) return AVERROR_UNKNOWN; } #else - openmpt->module = openmpt_module_create_from_memory(buf, size, openmpt_logfunc, s, NULL); - av_freep(&buf); + openmpt->module = openmpt_module_create(openmpt_cbs, s->pb, openmpt_logfunc, s, NULL); if (!openmpt->module) return AVERROR_INVALIDDATA; #endif -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org