From patchwork Sun Nov 20 19:21:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Faiz X-Patchwork-Id: 1499 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp1213193vsb; Sun, 20 Nov 2016 11:26:39 -0800 (PST) X-Received: by 10.28.127.9 with SMTP id a9mr10251464wmd.95.1479669999200; Sun, 20 Nov 2016 11:26:39 -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 jt9si16407106wjb.163.2016.11.20.11.26.38; Sun, 20 Nov 2016 11:26:39 -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 EC9CA689F80; Sun, 20 Nov 2016 21:26:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f176.google.com (mail-qk0-f176.google.com [209.85.220.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EA38D68987D for ; Sun, 20 Nov 2016 21:26:26 +0200 (EET) Received: by mail-qk0-f176.google.com with SMTP id n21so326415617qka.3 for ; Sun, 20 Nov 2016 11:26:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=bm90PLOMECxwMVEOcBT1q5PzKHqsRPoRnHOYcLlxMw8=; b=HKy87spx/l7Ll2s7t0Lzo4RPz7oqZ63V8i62ttwIFNrJL9PlRCz5Ke62ByecpOW+wV mDgc+wurcW2HsssmhJfcvVqe7KYXQZ6wbmrHtqDb/n6Q2/y33Qlmp5oNLVj39RnLvXtf r+8FvuM9SFE5xks1F0u8JHJNtm4VEQosBrW7ZGKvNCYtZnXa/cw2C2IgHP3TGLHpAGAv YnS40Te39dE6gn7zyHnwCKaxqXVyu0OHVDTIDnJDvijplKdmP/kEOfax11mbA4Jknrvu iT9U2s6bY+1cWwK1oDaCNSKMvPoKqfk7b93KD7BJ1Xhq/D4rkE587xTb1AehKPPJgZoL catw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=bm90PLOMECxwMVEOcBT1q5PzKHqsRPoRnHOYcLlxMw8=; b=QYGx7BpcaLzeaDMg7UkQBzBuhc36oBcDWPwlfHW6YpE8kIsCEsQzauxrEYUmOBgS67 waJksfO611rlJ9pjn6QhCX8K8FDDzTCmU0yoaplG3zSx8+acoaC/ShuRSoUKTaY3Rvl4 ETNGb8SGw2oY/M2Hr4V3ulhY2++0moGnu6ouPT85FEaPjTQoy0M1THzY7zkluLEIXhqw tjyxSh+eUlT3HjeDlVNvZrs1kzAYpG4DM90I+2/hLvjSHJpwyutGNKwOHZfvWoRSRiZg Gl3HOV1A2tyMOE+JMnXHDuQELoKWpilse0GZWOTqsobqttBFCuskQIy/4lBhQBqZrpUG Kgrw== X-Gm-Message-State: AKaTC03oCddUgS0Tqp5z7BHPAvz2AGKlEQYRBWVBbo1gk7pI18kQDgT81wnfgNZ6mUqKWQImsr2RwDcY01QVOg== X-Received: by 10.55.86.196 with SMTP id k187mr12803608qkb.203.1479669668032; Sun, 20 Nov 2016 11:21:08 -0800 (PST) MIME-Version: 1.0 Received: by 10.237.36.249 with HTTP; Sun, 20 Nov 2016 11:21:07 -0800 (PST) In-Reply-To: <20161120171619.GA4824@nb4> References: <1479632188-21626-1-git-send-email-mfcc64@gmail.com> <20161120171619.GA4824@nb4> From: Muhammad Faiz Date: Mon, 21 Nov 2016 02:21:07 +0700 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH] swresample/resample: add force_comp argument 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On 11/21/16, Michael Niedermayer wrote: > On Sun, Nov 20, 2016 at 03:56:28PM +0700, Muhammad Faiz wrote: >> this allow to use phase_count_compensation on init (rather than >> rebuild on swr_set_compensation) when options suggest that >> soft compensation is enabled >> >> Signed-off-by: Muhammad Faiz >> --- >> libswresample/resample.c | 4 +++- >> libswresample/soxr_resample.c | 2 +- >> libswresample/swresample.c | 5 ++++- >> libswresample/swresample_internal.h | 3 ++- >> 4 files changed, 10 insertions(+), 4 deletions(-) > > please document this in the code with a comment or 2 > its not immedeatly obvious from reading the code ok, new patch attached thanks From 5846ba0a6df69e41783ab4caa88d392abd339ed1 Mon Sep 17 00:00:00 2001 From: Muhammad Faiz Date: Mon, 21 Nov 2016 02:08:40 +0700 Subject: [PATCH] swresample/resample: add soft_compensation argument this allow to use larger phase_count on init (rather than rebuild on swr_set_compensation) when options suggest that soft compensation is enabled this affects only when exact_rational is enabled Signed-off-by: Muhammad Faiz --- libswresample/resample.c | 7 ++++++- libswresample/soxr_resample.c | 3 ++- libswresample/swresample.c | 7 ++++++- libswresample/swresample_internal.h | 3 ++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libswresample/resample.c b/libswresample/resample.c index 8635bf1..d1822e2 100644 --- a/libswresample/resample.c +++ b/libswresample/resample.c @@ -302,7 +302,7 @@ fail: static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff0, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, - double precision, int cheby, int exact_rational) + double precision, int cheby, int exact_rational, int soft_compensation) { double cutoff = cutoff0? cutoff0 : 0.97; double factor= FFMIN(out_rate * cutoff / in_rate, 1.0); @@ -316,6 +316,10 @@ static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_r if (phase_count_exact <= phase_count) { phase_count_compensation = phase_count_exact * (phase_count / phase_count_exact); phase_count = phase_count_exact; + /* use larger phase_count when soft_compensation is true */ + /* so rebuilding filter bank at runtime is not required */ + if (soft_compensation) + phase_count = phase_count_compensation; } } @@ -449,6 +453,7 @@ static int rebuild_filter_bank_with_compensation(ResampleContext *c) static int set_compensation(ResampleContext *c, int sample_delta, int compensation_distance){ int ret; + /* handle users who call swr_set_compensation() manually without setting soft compensation options */ if (compensation_distance) { ret = rebuild_filter_bank_with_compensation(c); if (ret < 0) diff --git a/libswresample/soxr_resample.c b/libswresample/soxr_resample.c index b9c6735..595cb64 100644 --- a/libswresample/soxr_resample.c +++ b/libswresample/soxr_resample.c @@ -30,7 +30,8 @@ #include static struct ResampleContext *create(struct ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear, - double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, double precision, int cheby, int exact_rational){ + double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, double precision, int cheby, + int exact_rational, int soft_compensation){ soxr_error_t error; soxr_datatype_t type = diff --git a/libswresample/swresample.c b/libswresample/swresample.c index 0ef4dea..8f85993 100644 --- a/libswresample/swresample.c +++ b/libswresample/swresample.c @@ -265,7 +265,12 @@ av_cold int swr_init(struct SwrContext *s){ } if (s->out_sample_rate!=s->in_sample_rate || (s->flags & SWR_FLAG_RESAMPLE)){ - s->resample = s->resampler->init(s->resample, s->out_sample_rate, s->in_sample_rate, s->filter_size, s->phase_shift, s->linear_interp, s->cutoff, s->int_sample_fmt, s->filter_type, s->kaiser_beta, s->precision, s->cheby, s->exact_rational); + /* suggested from swr_next_pts() */ + /* if soft_compensation is false, swr_next_pts() will not call swr_set_compensation() */ + int soft_compensation = s->min_compensation < FLT_MAX && s->soft_compensation_duration && s->max_soft_compensation; + s->resample = s->resampler->init(s->resample, s->out_sample_rate, s->in_sample_rate, s->filter_size, + s->phase_shift, s->linear_interp, s->cutoff, s->int_sample_fmt, s->filter_type, + s->kaiser_beta, s->precision, s->cheby, s->exact_rational, soft_compensation); if (!s->resample) { av_log(s, AV_LOG_ERROR, "Failed to initialize resampler\n"); return AVERROR(ENOMEM); diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h index f2ea5a2..8de8f1e 100644 --- a/libswresample/swresample_internal.h +++ b/libswresample/swresample_internal.h @@ -69,7 +69,8 @@ struct DitherContext { }; typedef struct ResampleContext * (* resample_init_func)(struct ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear, - double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, double precision, int cheby, int exact_rational); + double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, double precision, int cheby, + int exact_rational, int soft_compensation); typedef void (* resample_free_func)(struct ResampleContext **c); typedef int (* multiple_resample_func)(struct ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed); typedef int (* resample_flush_func)(struct SwrContext *c); -- 2.5.0