History

libswresample/rematrix: add support for custom order channel layouts

Limited to the same channels as a native layout, but not constrained by channel ordering.

James Almer committed 1 year ago

Commit b9c99ba1 parent e52701d2 files · +19 −12Browse files

Unified · Split

2 files
  1. Changelog +2 −0
  2. libswresample/rematrix.c +17 −12
Changelog+2−0
@@ -49,6 +49,8 @@ version 7.1: · 48 unmodified lines
4949 error, as such a specifier makes no sense
5050 - Mastering Display and Content Light Level metadata support in hevc_nvenc
5151 and av1_nvenc encoders
52+- libswresample now accepts custom order channel layouts as input, with some
53+ constrains
5254
5355
5456 version 7.0:
libswresample/rematrix.c+17−12
@@ -104,7 +104,14 @@ static int clean_layout(AVChannelLayout *out, const AVChannelLayout *in, void *s · 103 unmodified lines
104104 }
105105
106106 static int sane_layout(AVChannelLayout *ch_layout) {
107− if (ch_layout->order != AV_CHANNEL_ORDER_NATIVE)
107+ if(ch_layout->nb_channels >= SWR_CH_MAX)
108+ return 0;
109+ if(ch_layout->order == AV_CHANNEL_ORDER_CUSTOM)
110+ for (int i = 0; i < ch_layout->nb_channels; i++) {
111+ if (ch_layout->u.map[i].id >= 64)
112+ return 0;
113+ }
114+ else if (ch_layout->order != AV_CHANNEL_ORDER_NATIVE)
108115 return 0;
109116 if(!av_channel_layout_subset(ch_layout, AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker
110117 return 0;
@@ -118,8 +125,6 @@ static int sane_layout(AVChannelLayout *ch_layout) { · 7 unmodified lines
118125 return 0;
119126 if(!even(av_channel_layout_subset(ch_layout, (AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT))))
120127 return 0;
121− if(ch_layout->nb_channels >= SWR_CH_MAX)
122− return 0;
123128
124129 return 1;
125130 }
@@ -130,9 +135,10 @@ static void build_matrix(const AVChannelLayout *in_ch_layout, const AVChannelLay · 4 unmodified lines
130135 ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding)
131136 {
132137 double matrix[NUM_NAMED_CHANNELS][NUM_NAMED_CHANNELS]={{0}};
133− uint64_t unaccounted = in_ch_layout->u.mask & ~out_ch_layout->u.mask;
138+ uint64_t unaccounted = av_channel_layout_subset(in_ch_layout, UINT64_MAX) &
139+ ~av_channel_layout_subset(out_ch_layout, UINT64_MAX);
134140 double maxcoef=0;
135− int i, j, out_i;
141+ int i, j;
136142
137143 for(i=0; i<FF_ARRAY_ELEMS(matrix); i++){
138144 if( av_channel_layout_index_from_channel(in_ch_layout, i) >= 0
@@ -305,14 +311,15 @@ static void build_matrix(const AVChannelLayout *in_ch_layout, const AVChannelLay · 166 unmodified lines
305311 }
306312
307313
308− for(out_i=i=0; i<64; i++){
314+ for (i = 0; i < 64; i++) {
309315 double sum=0;
310− int in_i=0;
311− if (av_channel_layout_index_from_channel(out_ch_layout, i) < 0)
316+ int out_i = av_channel_layout_index_from_channel(out_ch_layout, i);
317+ if (out_i < 0)
312318 continue;
313319 for(j=0; j<64; j++){
314− if (av_channel_layout_index_from_channel(in_ch_layout, j) < 0)
315− continue;
320+ int in_i = av_channel_layout_index_from_channel(in_ch_layout, j);
321+ if (in_i < 0)
322+ continue;
316323 if (i < FF_ARRAY_ELEMS(matrix) && j < FF_ARRAY_ELEMS(matrix[0]))
317324 matrix_param[stride*out_i + in_i] = matrix[i][j];
318325 else
@@ -320,10 +327,8 @@ static void build_matrix(const AVChannelLayout *in_ch_layout, const AVChannelLay · 1 unmodified line
320327 ( av_channel_layout_index_from_channel(in_ch_layout, i) >= 0
321328 && av_channel_layout_index_from_channel(out_ch_layout, i) >= 0);
322329 sum += fabs(matrix_param[stride*out_i + in_i]);
323− in_i++;
324330 }
325331 maxcoef= FFMAX(maxcoef, sum);
326− out_i++;
327332 }
328333 if(rematrix_volume < 0)
329334 maxcoef = -rematrix_volume;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t