From patchwork Tue Dec 13 18:36:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Faiz X-Patchwork-Id: 1774 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.65.86 with SMTP id o83csp2371031vsa; Tue, 13 Dec 2016 10:38:33 -0800 (PST) X-Received: by 10.28.11.208 with SMTP id 199mr4001734wml.97.1481654313304; Tue, 13 Dec 2016 10:38:33 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f7si50445342wjg.224.2016.12.13.10.38.31; Tue, 13 Dec 2016 10:38:33 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 256D4689FA4; Tue, 13 Dec 2016 20:38:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f66.google.com (mail-pg0-f66.google.com [74.125.83.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 83E84689BC9 for ; Tue, 13 Dec 2016 20:38:17 +0200 (EET) Received: by mail-pg0-f66.google.com with SMTP id x23so5258385pgx.3 for ; Tue, 13 Dec 2016 10:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=2o5E+7iJOYJ+p1eX02kxajXYeI5Mb07mgeNpPnAt9Kc=; b=htX8MdZyTxr0Im7N1fLLE1JMmms+pRFLsCVtnDJcwxWRAgunW3FpuGGztLJOcHBcQu /0WE944wlFyQl0SGTXfyBBefmbv50Abq26kXwNiVF3wP5X1gIghQFCLYIWZIKzrG0oKe h1ASG2BItdEZ5h7BL+723NYH7CsnNJHLpEcwRT+z9e5+96LJv8fdFWlzDpmOrzKjzR/i su05FD0frBKqixiR2S3DzWeVYJUBq215CmIHYXnilUXGDkEw1g1Ps/2G/U1y2yM1sIBE cnnXYyJWhKAHzNcw9EGHsnAaKnsVsTrwNyqOQywsgbvC3APvQKnwim1tSs1iVnM2+UrZ Cpzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=2o5E+7iJOYJ+p1eX02kxajXYeI5Mb07mgeNpPnAt9Kc=; b=l5i2wogcSMG9zslf256bDylWV1PDnDkmHt7iGKwclBrWDSXGGMyhU0X7aO4gZ5uQD3 3FBUFc5YkaRZx4/EBSvqXQsGFLIkL5niXmCBlFb/GPrJkurewVi7r3bxplxeDq9lAnjS WuIQ7TLr8yYEhiWnz6Qo1si6xdpupBBqcXVTdO4k6criosXELNzMVLzbius0YxPCQseX W/LX3wssPTZXtYxgW5cG/Sz/jQNAk27IDa8pKQrlbQz/Ony8bu1M3Poicsks4AsEkb8R KjF8tiqnXXKh8aid+EnUpLxbVy3Cf3lRL/B57RX9GCNd6ovWMyuv/Pmp43UlTGjEt4iS JyfQ== X-Gm-Message-State: AKaTC01YyKmloKyJm+mWYh8K3CP8tR+5ybcqMqcMzaLrcYQ5WoSrgQrkmpg2iWwzzZQudg== X-Received: by 10.84.210.46 with SMTP id z43mr200267612plh.175.1481654301053; Tue, 13 Dec 2016 10:38:21 -0800 (PST) Received: from localhost.localdomain.localdomain ([114.121.239.147]) by smtp.gmail.com with ESMTPSA id s8sm81669504pfj.45.2016.12.13.10.38.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Dec 2016 10:38:20 -0800 (PST) From: Muhammad Faiz To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 Dec 2016 01:36:51 +0700 Message-Id: <1481654211-26771-1-git-send-email-mfcc64@gmail.com> X-Mailer: git-send-email 2.5.0 Subject: [FFmpeg-devel] [PATCH] swresample/resample: remove swri_resample function 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 Cc: Muhammad Faiz MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" integrate it inside multiple_resample allow some calculations to be performed outside loop Suggested-By: Michael Niedermayer Signed-off-by: Muhammad Faiz --- libswresample/resample.c | 79 +++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/libswresample/resample.c b/libswresample/resample.c index ce6a82f..8e2f769 100644 --- a/libswresample/resample.c +++ b/libswresample/resample.c @@ -467,70 +467,61 @@ static int set_compensation(ResampleContext *c, int sample_delta, int compensati return 0; } -static int swri_resample(ResampleContext *c, - uint8_t *dst, const uint8_t *src, int *consumed, - int src_size, int dst_size, int update_ctx) -{ +static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed){ + int i; + int av_unused mm_flags = av_get_cpu_flags(); + int need_emms = c->format == AV_SAMPLE_FMT_S16P && ARCH_X86_32 && + (mm_flags & (AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE2)) == AV_CPU_FLAG_MMX2; + int64_t max_src_size = (INT64_MAX/2 / c->phase_count) / c->src_incr; + + if (c->compensation_distance) + dst_size = FFMIN(dst_size, c->compensation_distance); + src_size = FFMIN(src_size, max_src_size); + + *consumed = 0; + if (c->filter_length == 1 && c->phase_count == 1) { - int index= c->index; - int frac= c->frac; - int64_t index2= (1LL<<32)*c->frac/c->src_incr + (1LL<<32)*index; + int64_t index2= (1LL<<32)*c->frac/c->src_incr + (1LL<<32)*c->index; int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr; - int new_size = (src_size * (int64_t)c->src_incr - frac + c->dst_incr - 1) / c->dst_incr; + 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) - c->dsp.resample_one(dst, src, dst_size, index2, incr); - - index += dst_size * c->dst_incr_div; - index += (frac + dst_size * (int64_t)c->dst_incr_mod) / c->src_incr; - av_assert2(index >= 0); - *consumed= index; - if (update_ctx) { - c->frac = (frac + dst_size * (int64_t)c->dst_incr_mod) % c->src_incr; - c->index = 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; + int (*resample_func)(struct ResampleContext *c, void *dst, + const void *src, int n, int update_ctx); dst_size = FFMAX(FFMIN(dst_size, delta_n), 0); if (dst_size > 0) { /* resample_linear and resample_common should have same behavior * when frac and dst_incr_mod are zero */ - if (c->linear && (c->frac || c->dst_incr_mod)) - *consumed = c->dsp.resample_linear(c, dst, src, dst_size, update_ctx); - else - *consumed = c->dsp.resample_common(c, dst, src, dst_size, update_ctx); - } else { - *consumed = 0; + resample_func = (c->linear && (c->frac || c->dst_incr_mod)) ? + c->dsp.resample_linear : 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); } } - return dst_size; -} - -static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed){ - int i, ret= -1; - int av_unused mm_flags = av_get_cpu_flags(); - int need_emms = c->format == AV_SAMPLE_FMT_S16P && ARCH_X86_32 && - (mm_flags & (AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE2)) == AV_CPU_FLAG_MMX2; - int64_t max_src_size = (INT64_MAX/2 / c->phase_count) / c->src_incr; - - if (c->compensation_distance) - dst_size = FFMIN(dst_size, c->compensation_distance); - src_size = FFMIN(src_size, max_src_size); - - for(i=0; ich_count; i++){ - ret= swri_resample(c, dst->ch[i], src->ch[i], - consumed, src_size, dst_size, i+1==dst->ch_count); - } if(need_emms) emms_c(); if (c->compensation_distance) { - c->compensation_distance -= ret; + c->compensation_distance -= dst_size; if (!c->compensation_distance) { c->dst_incr = c->ideal_dst_incr; c->dst_incr_div = c->dst_incr / c->src_incr; @@ -538,7 +529,7 @@ static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, A } } - return ret; + return dst_size; } static int64_t get_delay(struct SwrContext *s, int64_t base){