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 ESMTP id 1A0E148F2F for ; Thu, 29 Feb 2024 17:55:13 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 38B5E68CD8D; Thu, 29 Feb 2024 19:55:10 +0200 (EET) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C3E3A68C8AE for ; Thu, 29 Feb 2024 19:55:03 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 6A0A5E9FED for ; Thu, 29 Feb 2024 18:55:03 +0100 (CET) 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 EsZHasRk8tR1 for ; Thu, 29 Feb 2024 18:55:01 +0100 (CET) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id 90C09E9F49 for ; Thu, 29 Feb 2024 18:55:01 +0100 (CET) Date: Thu, 29 Feb 2024 18:55:01 +0100 (CET) From: Marton Balint To: FFmpeg development discussions and patches In-Reply-To: <20240229122205.GD6420@pb2> Message-ID: References: <20240226221940.GV6420@pb2> <20240227094810.1182-1-cus@passwd.hu> <20240227094810.1182-2-cus@passwd.hu> <20240229122205.GD6420@pb2> MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH 2/2] swresample/resample: rework resample_one function to work the same way as the others 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Thu, 29 Feb 2024, Michael Niedermayer wrote: > On Tue, Feb 27, 2024 at 10:48:10AM +0100, Marton Balint wrote: >> Signed-off-by: Marton Balint >> --- >> libswresample/resample.c | 29 +++++++---------------------- >> libswresample/resample.h | 4 ++-- >> libswresample/resample_template.c | 14 ++++++++++++-- >> 3 files changed, 21 insertions(+), 26 deletions(-) >> >> diff --git a/libswresample/resample.c b/libswresample/resample.c >> index 17cebad01b..89859dec79 100644 >> --- a/libswresample/resample.c >> +++ b/libswresample/resample.c >> @@ -356,26 +356,7 @@ static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, A >> >> *consumed = 0; >> >> - if (c->filter_length == 1 && c->phase_count == 1) { >> - int64_t index2= (1LL<<32)*c->frac/c->src_incr + (1LL<<32)*c->index + 1; >> - int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr + 1; >> - int new_size = (src_size * (int64_t)c->src_incr - c->frac + c->dst_incr - 1) / c->dst_incr; >> - >> - dst_size = FFMAX(FFMIN(dst_size, new_size), 0); >> - if (dst_size > 0) { >> - for (i = 0; i < dst->ch_count; i++) { >> - c->dsp.resample_one(dst->ch[i], src->ch[i], dst_size, index2, incr); >> - if (i+1 == dst->ch_count) { >> - c->index += dst_size * c->dst_incr_div; >> - c->index += (c->frac + dst_size * (int64_t)c->dst_incr_mod) / c->src_incr; >> - av_assert2(c->index >= 0); >> - *consumed = c->index; >> - c->frac = (c->frac + dst_size * (int64_t)c->dst_incr_mod) % c->src_incr; >> - c->index = 0; >> - } >> - } >> - } >> - } else { >> + { >> int64_t end_index = (1LL + src_size - c->filter_length) * c->phase_count; >> int64_t delta_frac = (end_index - c->index) * c->src_incr - c->frac; >> int delta_n = (delta_frac + c->dst_incr - 1) / c->dst_incr; >> @@ -386,8 +367,12 @@ static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, A >> if (dst_size > 0) { >> /* resample_linear and resample_common should have same behavior >> * when frac and dst_incr_mod are zero */ >> - resample_func = (c->linear && (c->frac || c->dst_incr_mod)) ? >> - c->dsp.resample_linear : c->dsp.resample_common; >> + if (c->filter_length == 1 && c->phase_count == 1) >> + resample_func = c->dsp.resample_one; >> + else if (c->linear && (c->frac || c->dst_incr_mod)) >> + resample_func = c->dsp.resample_linear; >> + else >> + resample_func = c->dsp.resample_common; >> for (i = 0; i < dst->ch_count; i++) >> *consumed = resample_func(c, dst->ch[i], src->ch[i], dst_size, i+1 == dst->ch_count); >> } >> diff --git a/libswresample/resample.h b/libswresample/resample.h >> index 1731dad3cf..8cc29effe8 100644 >> --- a/libswresample/resample.h >> +++ b/libswresample/resample.h >> @@ -51,8 +51,8 @@ typedef struct ResampleContext { >> int phase_count_compensation; /* desired phase_count when compensation is enabled */ >> >> struct { >> - void (*resample_one)(void *dst, const void *src, >> - int n, int64_t index, int64_t incr); >> + int (*resample_one)(struct ResampleContext *c, void *dst, >> + const void *src, int n, int update_ctx); >> int (*resample_common)(struct ResampleContext *c, void *dst, >> const void *src, int n, int update_ctx); >> int (*resample_linear)(struct ResampleContext *c, void *dst, >> diff --git a/libswresample/resample_template.c b/libswresample/resample_template.c >> index 4c227b9940..a8114ea918 100644 >> --- a/libswresample/resample_template.c >> +++ b/libswresample/resample_template.c >> @@ -72,17 +72,27 @@ >> >> #endif >> >> -static void RENAME(resample_one)(void *dest, const void *source, >> - int dst_size, int64_t index2, int64_t incr) >> +static int RENAME(resample_one)(ResampleContext *c, >> + void *dest, const void *source, >> + int dst_size, int update_ctx) >> { >> DELEM *dst = dest; >> const DELEM *src = source; >> int dst_index; > >> + int64_t index2 = (1LL << 32) * c->frac / c->src_incr + 1 + (1LL << 32) * c->index; >> + int64_t incr = (1LL << 32) * c->dst_incr / c->src_incr + 1; > > This computation is done repeatedly for each channel, thats not needed > its enough if its done once I consider that negligable for real cases, and it makes the code cleaner doing the computations here. If you insist on this, then it is better to rework all the resample funcs to work on all channels in a separate patch. Regards, Marton _______________________________________________ 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".