From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH 2/2] swresample/rematrix: add support for custom order channel layouts Date: Sun, 2 Feb 2025 20:03:54 -0300 Message-ID: <71a8f548-b34b-4c87-a9a1-23d5704feea1@gmail.com> (raw) In-Reply-To: <20250202214642.5316-2-jamrial@gmail.com> [-- Attachment #1.1.1: Type: text/plain, Size: 3798 bytes --] On 2/2/2025 6:46 PM, James Almer wrote: > Limited to the same channels as a native layout, but not constrained by channel ordering. > > Signed-off-by: James Almer <jamrial@gmail.com> > --- > Untested, as i don't have a sample from which we export a custom layout (Like PCM in mp4). Tried with one such sample and it appears to work. > > libswresample/rematrix.c | 28 +++++++++++++++++----------- > 1 file changed, 17 insertions(+), 11 deletions(-) > > diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c > index 8b6e8ae1c5..e3c2cc1211 100644 > --- a/libswresample/rematrix.c > +++ b/libswresample/rematrix.c > @@ -104,6 +104,14 @@ static int clean_layout(AVChannelLayout *out, const AVChannelLayout *in, void *s > } > > static int sane_layout(AVChannelLayout *ch_layout) { > + if(ch_layout->nb_channels >= SWR_CH_MAX) > + return 0; > + if(ch_layout->order == AV_CHANNEL_ORDER_CUSTOM) > + for (int i = 0; i < ch_layout->nb_channels; i++) { > + if (ch_layout->u.map[i].id >= 64) > + return 0; > + } > + else > if (ch_layout->order != AV_CHANNEL_ORDER_NATIVE) > return 0; > if(!av_channel_layout_subset(ch_layout, AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker > @@ -118,8 +126,6 @@ static int sane_layout(AVChannelLayout *ch_layout) { > return 0; > if(!even(av_channel_layout_subset(ch_layout, (AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT)))) > return 0; > - if(ch_layout->nb_channels >= SWR_CH_MAX) > - return 0; > > return 1; > } > @@ -130,9 +136,10 @@ static void build_matrix(const AVChannelLayout *in_ch_layout, const AVChannelLay > ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding) > { > double matrix[NUM_NAMED_CHANNELS][NUM_NAMED_CHANNELS]={{0}}; > - uint64_t unaccounted = in_ch_layout->u.mask & ~out_ch_layout->u.mask; > + uint64_t unaccounted = av_channel_layout_subset(in_ch_layout, UINT64_MAX) & > + ~av_channel_layout_subset(out_ch_layout, UINT64_MAX); > double maxcoef=0; > - int i, j, out_i; > + int i, j; > > for(i=0; i<FF_ARRAY_ELEMS(matrix); i++){ > if( av_channel_layout_index_from_channel(in_ch_layout, i) >= 0 > @@ -305,14 +312,15 @@ static void build_matrix(const AVChannelLayout *in_ch_layout, const AVChannelLay > } > > > - for(out_i=i=0; i<64; i++){ > + for(i=0; i<64; i++){ > double sum=0; > - int in_i=0; > - if (av_channel_layout_index_from_channel(out_ch_layout, i) < 0) > + int out_i = av_channel_layout_index_from_channel(out_ch_layout, i); > + if (out_i < 0) > continue; > for(j=0; j<64; j++){ > - if (av_channel_layout_index_from_channel(in_ch_layout, j) < 0) > - continue; > + int in_i = av_channel_layout_index_from_channel(in_ch_layout, j); > + if (in_i < 0) > + continue; > if (i < FF_ARRAY_ELEMS(matrix) && j < FF_ARRAY_ELEMS(matrix[0])) > matrix_param[stride*out_i + in_i] = matrix[i][j]; > else > @@ -320,10 +328,8 @@ static void build_matrix(const AVChannelLayout *in_ch_layout, const AVChannelLay > ( av_channel_layout_index_from_channel(in_ch_layout, i) >= 0 > && av_channel_layout_index_from_channel(out_ch_layout, i) >= 0); > sum += fabs(matrix_param[stride*out_i + in_i]); > - in_i++; > } > maxcoef= FFMAX(maxcoef, sum); > - out_i++; > } > if(rematrix_volume < 0) > maxcoef = -rematrix_volume; [-- Attachment #1.2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 495 bytes --] [-- Attachment #2: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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".
next prev parent reply other threads:[~2025-02-02 23:04 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-02-02 21:46 [FFmpeg-devel] [PATCH 1/2] swresample/rematrix: split filling the matrix array into its own function James Almer 2025-02-02 21:46 ` [FFmpeg-devel] [PATCH 2/2] swresample/rematrix: add support for custom order channel layouts James Almer 2025-02-02 23:03 ` James Almer [this message] 2025-02-02 23:44 ` Pavel Koshevoy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=71a8f548-b34b-4c87-a9a1-23d5704feea1@gmail.com \ --to=jamrial@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git