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 BBA38456A0 for ; Fri, 17 Feb 2023 19:55:24 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BF51268BE6B; Fri, 17 Feb 2023 21:55:16 +0200 (EET) Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A3E6C68BDFD for ; Fri, 17 Feb 2023 21:55:09 +0200 (EET) Received: by mail-oi1-f177.google.com with SMTP id az13so2284446oib.12 for ; Fri, 17 Feb 2023 11:55:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xzIu2K59aBjFz5GfgVU1At97wgCPQ9Awk7+nbyk88i0=; b=ULShrGW9ZQriMS8bUGEchY+Q1vbSV9++4VRcBbTybtkq6FyHg0jyihwr9e2D53Js4l HWnUCtzy2G7xGHlaL39w6YEeVicpiH3P6bOxBKtYkELRWe0aubQS1XMNax1drEF9nsgm /cmHCzX1w1SlkcvGIzyzqSh3U0MApGrKOCAtp+hWrgLK0JN6aa61tRX1P6yOnoAm60bl jiGWSMNFmVTK3ynO66Qu48GxNz3OqP+BAIAYYrDAk0VgaGEJ9KS7s9zm3pZ76EOxAY9g UvuQCxZqFOQn56eqwXyxVmtk+kfojKCJuUa8UGbIojpC4h50eFmTna3wCYIDW9fWu5Uh T9vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xzIu2K59aBjFz5GfgVU1At97wgCPQ9Awk7+nbyk88i0=; b=ZDt4ZUiAg6U0GlZbmwKGJea5Bl8PGKcvEPTBAKUul5oikayxhu1HVK7samS4wZepVk cNsYDVSaM4FkBB4WRQdvjbRWLMww3B/GR3eSb8rgk4huVWROcZ8POz0Pix5KqlxN0FTW cfXXyo7KSk1kTVnXEu2TH2AWcYUkW9wUSwrOIqw5BsPs20UYvDeWLnNwUpxmCKAfpMuI Z/Q9mn/NHm4/pZ/gApEoxrXC8hhdfaYEKZQgwgUBjqfPjLZLtWqouAQ29J4RKZpsaE4+ B6rjJV7HodK88EwT01CJMDyiv78Hbb/RdZz3v4L4b1oZEbat/7OB0SAn4qu+QsGP5pTU /Hvg== X-Gm-Message-State: AO0yUKVyM8Kdx7FnqGvGdL0sUR/k+qfWyoA1UQUxaNd97Q/Dl2HIVwvV mbTtKNt1Urvuql0o6t95hALeDaDp6cw= X-Google-Smtp-Source: AK7set/kHACm/GimaoL87zwt952tJr7E3JjsAxL8c8VA9Y/XRmBSrntg8rwSMeCvJiit9RJjwt2WUg== X-Received: by 2002:a54:480e:0:b0:37d:574a:1290 with SMTP id j14-20020a54480e000000b0037d574a1290mr946598oij.42.1676663707516; Fri, 17 Feb 2023 11:55:07 -0800 (PST) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id q186-20020acac0c3000000b0037d74967ef6sm2158721oif.44.2023.02.17.11.55.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 11:55:06 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 Feb 2023 16:55:03 -0300 Message-Id: <20230217195504.43368-2-jamrial@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230217195504.43368-1-jamrial@gmail.com> References: <20230217195504.43368-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] swresample/swresample: add a used channel layout option using the new API 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-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: Replaces the "used channel count" option, which is now deprecated. Signed-off-by: James Almer --- doc/resampler.texi | 4 +-- libswresample/options.c | 6 ++-- libswresample/rematrix.c | 2 +- libswresample/swresample.c | 56 ++++++++++++++++++----------- libswresample/swresample_internal.h | 5 +-- libswresample/x86/rematrix_init.c | 2 +- 6 files changed, 46 insertions(+), 29 deletions(-) diff --git a/doc/resampler.texi b/doc/resampler.texi index d55654e7bc..a6224eefb3 100644 --- a/doc/resampler.texi +++ b/doc/resampler.texi @@ -11,8 +11,8 @@ programmatic use. @table @option -@item uch, used_channel_count -Set the number of used input channels. Default value is 0. This option is +@item uchl, used_chlayout +Set used input channel layout. Default is unset. This option is only used for special remapping. @item isr, in_sample_rate diff --git a/libswresample/options.c b/libswresample/options.c index ffa27c590d..fb109fdbab 100644 --- a/libswresample/options.c +++ b/libswresample/options.c @@ -46,9 +46,9 @@ static const AVOption options[]={ OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM|DEPREC}, {"out_channel_count" , "set output channel count (Deprecated, use out_chlayout)", OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM|DEPREC}, +{"uch" , "set used channel count" , OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM|DEPREC}, +{"used_channel_count" , "set used channel count" , OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM|DEPREC}, #endif -{"uch" , "set used channel count" , OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM}, -{"used_channel_count" , "set used channel count" , OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0 }, 0 , SWR_CH_MAX, PARAM}, {"isr" , "set input sample rate" , OFFSET( in_sample_rate), AV_OPT_TYPE_INT , {.i64=0 }, 0 , INT_MAX , PARAM}, {"in_sample_rate" , "set input sample rate" , OFFSET( in_sample_rate), AV_OPT_TYPE_INT , {.i64=0 }, 0 , INT_MAX , PARAM}, {"osr" , "set output sample rate" , OFFSET(out_sample_rate), AV_OPT_TYPE_INT , {.i64=0 }, 0 , INT_MAX , PARAM}, @@ -73,6 +73,8 @@ static const AVOption options[]={ {"in_chlayout" , "set input channel layout" , OFFSET(user_in_chlayout ), AV_OPT_TYPE_CHLAYOUT, {.str=NULL }, 0, 0 , PARAM, "chlayout"}, {"ochl" , "set output channel layout" , OFFSET(user_out_chlayout), AV_OPT_TYPE_CHLAYOUT, {.str=NULL }, 0, 0 , PARAM, "chlayout"}, {"out_chlayout" , "set output channel layout" , OFFSET(user_out_chlayout), AV_OPT_TYPE_CHLAYOUT, {.str=NULL }, 0, 0 , PARAM, "chlayout"}, +{"uchl" , "set used channel layout" , OFFSET(user_used_chlayout), AV_OPT_TYPE_CHLAYOUT, {.str=NULL }, 0, 0 , PARAM, "chlayout"}, +{"used_chlayout" , "set used channel layout" , OFFSET(user_used_chlayout), AV_OPT_TYPE_CHLAYOUT, {.str=NULL }, 0, 0 , PARAM, "chlayout"}, {"clev" , "set center mix level" , OFFSET(clev ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB }, -32 , 32 , PARAM}, {"center_mix_level" , "set center mix level" , OFFSET(clev ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB }, -32 , 32 , PARAM}, {"slev" , "set surround mix level" , OFFSET(slev ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB }, -32 , 32 , PARAM}, diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c index 0c3fff6c42..d57c488aca 100644 --- a/libswresample/rematrix.c +++ b/libswresample/rematrix.c @@ -492,7 +492,7 @@ av_cold static int auto_matrix(SwrContext *s) av_cold int swri_rematrix_init(SwrContext *s){ int i, j; - int nb_in = s->used_ch_count; + int nb_in = s->used_chlayout.nb_channels; int nb_out = s->out.ch_count; s->mix_any_f = NULL; diff --git a/libswresample/swresample.c b/libswresample/swresample.c index 5884f8d533..deb1959e89 100644 --- a/libswresample/swresample.c +++ b/libswresample/swresample.c @@ -161,6 +161,7 @@ static void clear_context(SwrContext *s){ free_temp(&s->dither.temp); av_channel_layout_uninit(&s->in_ch_layout); av_channel_layout_uninit(&s->out_ch_layout); + av_channel_layout_uninit(&s->used_chlayout); swri_audio_convert_free(&s-> in_convert); swri_audio_convert_free(&s->out_convert); swri_audio_convert_free(&s->full_convert); @@ -176,6 +177,7 @@ av_cold void swr_free(SwrContext **ss){ clear_context(s); av_channel_layout_uninit(&s->user_in_chlayout); av_channel_layout_uninit(&s->user_out_chlayout); + av_channel_layout_uninit(&s->user_used_chlayout); if (s->resampler) s->resampler->free(&s->resample); @@ -211,12 +213,20 @@ av_cold int swr_init(struct SwrContext *s){ av_log(s, AV_LOG_ERROR, "Requested output sample rate %d is invalid\n", s->out_sample_rate); return AVERROR(EINVAL); } - s->used_ch_count = s->user_used_ch_count; #if FF_API_OLD_CHANNEL_LAYOUT s->out.ch_count = s-> user_out_ch_count; s-> in.ch_count = s-> user_in_ch_count; // if the old/new fields are set inconsistently, prefer the old ones + if (s->user_used_ch_count && s->user_used_ch_count != s->user_used_chlayout.nb_channels) { + av_channel_layout_uninit(&s->used_chlayout); + s->used_chlayout.order = AV_CHANNEL_ORDER_UNSPEC; + s->used_chlayout.nb_channels = s->user_used_ch_count; + } else if (av_channel_layout_check(&s->user_used_chlayout)) { + ret = av_channel_layout_copy(&s->used_chlayout, &s->user_used_chlayout); + if (ret < 0) + return ret; + } if ((s->user_in_ch_count && s->user_in_ch_count != s->user_in_chlayout.nb_channels) || (s->user_in_ch_layout && (s->user_in_chlayout.order != AV_CHANNEL_ORDER_NATIVE || s->user_in_chlayout.u.mask != s->user_in_ch_layout))) { @@ -243,9 +253,9 @@ av_cold int swr_init(struct SwrContext *s){ } else if (av_channel_layout_check(&s->user_out_chlayout)) av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout); - if (!s->out.ch_count && !s->user_out_ch_layout) + if (!s->out.ch_count) s->out.ch_count = s->out_ch_layout.nb_channels; - if (!s-> in.ch_count && !s-> user_in_ch_layout) + if (!s-> in.ch_count) s-> in.ch_count = s->in_ch_layout.nb_channels; if (!(ret = av_channel_layout_check(&s->in_ch_layout)) || s->in_ch_layout.nb_channels > SWR_CH_MAX) { @@ -281,6 +291,7 @@ av_cold int swr_init(struct SwrContext *s){ ret = av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout); ret |= av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout); + ret |= av_channel_layout_copy(&s->used_chlayout, &s->user_used_chlayout); if (ret < 0) return ret; #endif @@ -299,16 +310,19 @@ av_cold int swr_init(struct SwrContext *s){ return AVERROR(EINVAL); } - if(!s->used_ch_count) - s->used_ch_count= s->in.ch_count; + if (!av_channel_layout_check(&s->used_chlayout)) + av_channel_layout_default(&s->used_chlayout, s->in.ch_count); - if (s->used_ch_count && s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->used_ch_count != s->in_ch_layout.nb_channels) { - av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number of used channels, ignoring layout\n"); + if (s->used_chlayout.nb_channels != s->in_ch_layout.nb_channels) av_channel_layout_uninit(&s->in_ch_layout); - } - if (s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) - av_channel_layout_default(&s->in_ch_layout, s->used_ch_count); + if (s->used_chlayout.order == AV_CHANNEL_ORDER_UNSPEC) + av_channel_layout_default(&s->used_chlayout, s->used_chlayout.nb_channels); + if (s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) { + ret = av_channel_layout_copy(&s->in_ch_layout, &s->used_chlayout); + if (ret < 0) + return ret; + } if (s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) av_channel_layout_default(&s->out_ch_layout, s->out.ch_count); @@ -389,8 +403,8 @@ av_cold int swr_init(struct SwrContext *s){ #define RSC 1 //FIXME finetune if(!s-> in.ch_count) s-> in.ch_count = s->in_ch_layout.nb_channels; - if(!s->used_ch_count) - s->used_ch_count= s->in.ch_count; + if (!av_channel_layout_check(&s->used_chlayout)) + av_channel_layout_default(&s->used_chlayout, s->in.ch_count); if(!s->out.ch_count) s->out.ch_count = s->out_ch_layout.nb_channels; @@ -410,23 +424,23 @@ av_cold int swr_init(struct SwrContext *s){ } #endif av_channel_layout_describe(&s->in_ch_layout, l1, sizeof(l1)); - if (s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->used_ch_count != s->in_ch_layout.nb_channels) { - av_log(s, AV_LOG_ERROR, "Input channel layout %s mismatches specified channel count %d\n", l1, s->used_ch_count); + if (s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->used_chlayout.nb_channels != s->in_ch_layout.nb_channels) { + av_log(s, AV_LOG_ERROR, "Input channel layout %s mismatches specified channel count %d\n", l1, s->used_chlayout.nb_channels); ret = AVERROR(EINVAL); goto fail; } if (( s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC - || s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) && s->used_ch_count != s->out.ch_count && !s->rematrix_custom) { + || s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) && s->used_chlayout.nb_channels != s->out.ch_count && !s->rematrix_custom) { av_log(s, AV_LOG_ERROR, "Rematrix is needed between %s and %s " "but there is not enough information to do it\n", l1, l2); ret = AVERROR(EINVAL); goto fail; } -av_assert0(s->used_ch_count); +av_assert0(s->used_chlayout.nb_channels); av_assert0(s->out.ch_count); - s->resample_first= RSC*s->out.ch_count/s->used_ch_count - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0; + s->resample_first= RSC*s->out.ch_count/s->used_chlayout.nb_channels - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0; s->in_buffer= s->in; s->silence = s->in; @@ -442,7 +456,7 @@ av_assert0(s->out.ch_count); } s->in_convert = swri_audio_convert_alloc(s->int_sample_fmt, - s-> in_sample_fmt, s->used_ch_count, s->channel_map, 0); + s-> in_sample_fmt, s->used_chlayout.nb_channels, s->channel_map, 0); s->out_convert= swri_audio_convert_alloc(s->out_sample_fmt, s->int_sample_fmt, s->out.ch_count, NULL, 0); @@ -457,9 +471,9 @@ av_assert0(s->out.ch_count); if(s->channel_map){ s->postin.ch_count= - s->midbuf.ch_count= s->used_ch_count; + s->midbuf.ch_count= s->used_chlayout.nb_channels; if(s->resample) - s->in_buffer.ch_count= s->used_ch_count; + s->in_buffer.ch_count= s->used_chlayout.nb_channels; } if(!s->resample_first){ s->midbuf.ch_count= s->out.ch_count; @@ -697,7 +711,7 @@ static int swr_convert_internal(struct SwrContext *s, AudioData *out, int out_co if((ret=swri_realloc_audio(&s->postin, in_count))<0) return ret; if(s->resample_first){ - av_assert0(s->midbuf.ch_count == s->used_ch_count); + av_assert0(s->midbuf.ch_count == s->used_chlayout.nb_channels); if((ret=swri_realloc_audio(&s->midbuf, out_count))<0) return ret; }else{ diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h index 262a0e2b8c..c426cd782a 100644 --- a/libswresample/swresample_internal.h +++ b/libswresample/swresample_internal.h @@ -99,6 +99,7 @@ struct SwrContext { enum AVSampleFormat in_sample_fmt; ///< input sample format enum AVSampleFormat int_sample_fmt; ///< internal sample format (AV_SAMPLE_FMT_FLTP or AV_SAMPLE_FMT_S16P) enum AVSampleFormat out_sample_fmt; ///< output sample format + AVChannelLayout used_chlayout; ///< number of used input channels (mapped channel count if channel_map, otherwise in.ch_count) AVChannelLayout in_ch_layout; ///< input channel layout AVChannelLayout out_ch_layout; ///< output channel layout int in_sample_rate; ///< input sample rate @@ -111,16 +112,16 @@ struct SwrContext { float rematrix_maxval; ///< maximum value for rematrixing output int matrix_encoding; /**< matrixed stereo encoding */ const int *channel_map; ///< channel index (or -1 if muted channel) map - int used_ch_count; ///< number of used input channels (mapped channel count if channel_map, otherwise in.ch_count) int engine; - int user_used_ch_count; ///< User set used channel count #if FF_API_OLD_CHANNEL_LAYOUT + int user_used_ch_count; ///< User set used channel count int user_in_ch_count; ///< User set input channel count int user_out_ch_count; ///< User set output channel count int64_t user_in_ch_layout; ///< User set input channel layout int64_t user_out_ch_layout; ///< User set output channel layout #endif + AVChannelLayout user_used_chlayout; ///< User set used channel layout AVChannelLayout user_in_chlayout; ///< User set input channel layout AVChannelLayout user_out_chlayout; ///< User set output channel layout enum AVSampleFormat user_int_sample_fmt; ///< User set internal sample format diff --git a/libswresample/x86/rematrix_init.c b/libswresample/x86/rematrix_init.c index b6ed38bf67..6cd8e109c4 100644 --- a/libswresample/x86/rematrix_init.c +++ b/libswresample/x86/rematrix_init.c @@ -33,7 +33,7 @@ D(int16, sse2) av_cold int swri_rematrix_init_x86(struct SwrContext *s){ #if HAVE_X86ASM int mm_flags = av_get_cpu_flags(); - int nb_in = s->used_ch_count; + int nb_in = s->used_chlayout.nb_channels; int nb_out = s->out.ch_count; int num = nb_in * nb_out; int i,j; -- 2.39.1 _______________________________________________ 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".