Skip to content

Commit e52701d

Browse files
committed
swresample/rematrix: split filling the matrix array into its own function
Signed-off-by: James Almer <[email protected]>
1 parent 33679f5 commit e52701d

File tree

1 file changed

+106
-96
lines changed

1 file changed

+106
-96
lines changed

libswresample/rematrix.c

Lines changed: 106 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -124,85 +124,28 @@ static int sane_layout(AVChannelLayout *ch_layout) {
124124
return 1;
125125
}
126126

127-
av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,
128-
double center_mix_level, double surround_mix_level,
129-
double lfe_mix_level, double maxval,
130-
double rematrix_volume, double *matrix_param,
131-
ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
127+
static void build_matrix(const AVChannelLayout *in_ch_layout, const AVChannelLayout *out_ch_layout,
128+
double center_mix_level, double surround_mix_level,
129+
double lfe_mix_level, double maxval, double rematrix_volume, double *matrix_param,
130+
ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding)
132131
{
133-
int i, j, out_i, ret;
134-
AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
135132
double matrix[NUM_NAMED_CHANNELS][NUM_NAMED_CHANNELS]={{0}};
136-
int64_t unaccounted;
133+
uint64_t unaccounted = in_ch_layout->u.mask & ~out_ch_layout->u.mask;
137134
double maxcoef=0;
138-
char buf[128];
139-
140-
ret = clean_layout(&in_ch_layout, in_layout, log_context);
141-
ret |= clean_layout(&out_ch_layout, out_layout, log_context);
142-
if (ret < 0)
143-
goto fail;
144-
145-
if( !av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
146-
&& !av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
147-
) {
148-
av_channel_layout_uninit(&out_ch_layout);
149-
out_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
150-
}
151-
if( !av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
152-
&& !av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
153-
) {
154-
av_channel_layout_uninit(&in_ch_layout);
155-
in_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
156-
}
157-
if (!av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2) &&
158-
av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2)) {
159-
av_channel_layout_from_mask(&in_ch_layout, (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER));
160-
av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
161-
av_log(log_context, AV_LOG_WARNING,
162-
"Full-on remixing from 22.2 has not yet been implemented! "
163-
"Processing the input as '%s'\n",
164-
buf);
165-
}
166-
167-
if(!av_channel_layout_check(&in_ch_layout)) {
168-
av_log(log_context, AV_LOG_ERROR, "Input channel layout is invalid\n");
169-
ret = AVERROR(EINVAL);
170-
goto fail;
171-
}
172-
if(!sane_layout(&in_ch_layout)) {
173-
av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
174-
av_log(log_context, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
175-
ret = AVERROR(EINVAL);
176-
goto fail;
177-
}
178-
179-
if(!av_channel_layout_check(&out_ch_layout)) {
180-
av_log(log_context, AV_LOG_ERROR, "Output channel layout is invalid\n");
181-
ret = AVERROR(EINVAL);
182-
goto fail;
183-
}
184-
if(!sane_layout(&out_ch_layout)) {
185-
av_channel_layout_describe(&out_ch_layout, buf, sizeof(buf));
186-
av_log(log_context, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
187-
ret = AVERROR(EINVAL);
188-
goto fail;
189-
}
135+
int i, j, out_i;
190136

191137
for(i=0; i<FF_ARRAY_ELEMS(matrix); i++){
192-
if( av_channel_layout_index_from_channel(&in_ch_layout, i) >= 0
193-
&& av_channel_layout_index_from_channel(&out_ch_layout, i) >= 0)
138+
if( av_channel_layout_index_from_channel(in_ch_layout, i) >= 0
139+
&& av_channel_layout_index_from_channel(out_ch_layout, i) >= 0)
194140
matrix[i][i]= 1.0;
195141
}
196142

197-
unaccounted = in_ch_layout.u.mask & ~out_ch_layout.u.mask;
198-
199143
//FIXME implement dolby surround
200144
//FIXME implement full ac3
201145

202-
203146
if(unaccounted & AV_CH_FRONT_CENTER){
204-
if (av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO) {
205-
if (av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO)) {
147+
if (av_channel_layout_subset(out_ch_layout, AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO) {
148+
if (av_channel_layout_subset(in_ch_layout, AV_CH_LAYOUT_STEREO)) {
206149
matrix[ FRONT_LEFT][FRONT_CENTER]+= center_mix_level;
207150
matrix[FRONT_RIGHT][FRONT_CENTER]+= center_mix_level;
208151
} else {
@@ -213,23 +156,23 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL
213156
av_assert0(0);
214157
}
215158
if(unaccounted & AV_CH_LAYOUT_STEREO){
216-
if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
159+
if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
217160
matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;
218161
matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;
219-
if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_FRONT_CENTER) >= 0)
162+
if (av_channel_layout_index_from_channel(in_ch_layout, AV_CHAN_FRONT_CENTER) >= 0)
220163
matrix[FRONT_CENTER][ FRONT_CENTER] = center_mix_level*sqrt(2);
221164
}else
222165
av_assert0(0);
223166
}
224167

225168
if(unaccounted & AV_CH_BACK_CENTER){
226-
if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
169+
if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
227170
matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;
228171
matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;
229-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {
172+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {
230173
matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2;
231174
matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2;
232-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
175+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
233176
if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
234177
matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
235178
if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
@@ -243,24 +186,24 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL
243186
matrix[ FRONT_LEFT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
244187
matrix[FRONT_RIGHT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
245188
}
246-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
189+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
247190
matrix[ FRONT_CENTER][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
248191
}else
249192
av_assert0(0);
250193
}
251194
if(unaccounted & AV_CH_BACK_LEFT){
252-
if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0) {
195+
if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_BACK_CENTER) >= 0) {
253196
matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;
254197
matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;
255-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {
256-
if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {
198+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {
199+
if (av_channel_layout_index_from_channel(in_ch_layout, AV_CHAN_SIDE_LEFT) >= 0) {
257200
matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;
258201
matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;
259202
}else{
260203
matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
261204
matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
262205
}
263-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
206+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
264207
if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
265208
matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * M_SQRT1_2;
266209
matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2;
@@ -275,28 +218,28 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL
275218
matrix[ FRONT_LEFT][ BACK_LEFT] += surround_mix_level;
276219
matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level;
277220
}
278-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
221+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
279222
matrix[ FRONT_CENTER][BACK_LEFT ]+= surround_mix_level*M_SQRT1_2;
280223
matrix[ FRONT_CENTER][BACK_RIGHT]+= surround_mix_level*M_SQRT1_2;
281224
}else
282225
av_assert0(0);
283226
}
284227

285228
if(unaccounted & AV_CH_SIDE_LEFT){
286-
if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
229+
if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
287230
/* if back channels do not exist in the input, just copy side
288231
channels to back channels, otherwise mix side into back */
289-
if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
232+
if (av_channel_layout_index_from_channel(in_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
290233
matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2;
291234
matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2;
292235
} else {
293236
matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;
294237
matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;
295238
}
296-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0) {
239+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_BACK_CENTER) >= 0) {
297240
matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2;
298241
matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2;
299-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
242+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
300243
if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
301244
matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * M_SQRT1_2;
302245
matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2;
@@ -311,39 +254,39 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL
311254
matrix[ FRONT_LEFT][ SIDE_LEFT] += surround_mix_level;
312255
matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level;
313256
}
314-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
257+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
315258
matrix[ FRONT_CENTER][SIDE_LEFT ]+= surround_mix_level * M_SQRT1_2;
316259
matrix[ FRONT_CENTER][SIDE_RIGHT]+= surround_mix_level * M_SQRT1_2;
317260
}else
318261
av_assert0(0);
319262
}
320263

321264
if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
322-
if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
265+
if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
323266
matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;
324267
matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;
325-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
268+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
326269
matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;
327270
matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;
328271
}else
329272
av_assert0(0);
330273
}
331274

332275
if (unaccounted & AV_CH_TOP_FRONT_LEFT) {
333-
if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0) {
276+
if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0) {
334277
matrix[TOP_FRONT_CENTER][TOP_FRONT_LEFT ] += M_SQRT1_2;
335278
matrix[TOP_FRONT_CENTER][TOP_FRONT_RIGHT] += M_SQRT1_2;
336-
if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0)
279+
if (av_channel_layout_index_from_channel(in_ch_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0)
337280
matrix[TOP_FRONT_CENTER][TOP_FRONT_CENTER] = center_mix_level * sqrt(2);
338-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
339-
if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
281+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
282+
if (av_channel_layout_index_from_channel(in_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
340283
matrix[FRONT_LEFT ][TOP_FRONT_LEFT ] += M_SQRT1_2;
341284
matrix[FRONT_RIGHT][TOP_FRONT_RIGHT] += M_SQRT1_2;
342285
} else {
343286
matrix[FRONT_LEFT ][TOP_FRONT_LEFT ] += 1.0;
344287
matrix[FRONT_RIGHT][TOP_FRONT_RIGHT] += 1.0;
345288
}
346-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
289+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
347290
matrix[FRONT_CENTER][TOP_FRONT_LEFT ] += M_SQRT1_2;
348291
matrix[FRONT_CENTER][TOP_FRONT_RIGHT] += M_SQRT1_2;
349292
} else
@@ -352,29 +295,30 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL
352295

353296
/* mix LFE into front left/right or center */
354297
if (unaccounted & AV_CH_LOW_FREQUENCY) {
355-
if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
298+
if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
356299
matrix[FRONT_CENTER][LOW_FREQUENCY] += lfe_mix_level;
357-
} else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
300+
} else if (av_channel_layout_index_from_channel(out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
358301
matrix[FRONT_LEFT ][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
359302
matrix[FRONT_RIGHT][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
360303
} else
361304
av_assert0(0);
362305
}
363306

307+
364308
for(out_i=i=0; i<64; i++){
365309
double sum=0;
366310
int in_i=0;
367-
if (av_channel_layout_index_from_channel(&out_ch_layout, i) < 0)
311+
if (av_channel_layout_index_from_channel(out_ch_layout, i) < 0)
368312
continue;
369313
for(j=0; j<64; j++){
370-
if (av_channel_layout_index_from_channel(&in_ch_layout, j) < 0)
314+
if (av_channel_layout_index_from_channel(in_ch_layout, j) < 0)
371315
continue;
372316
if (i < FF_ARRAY_ELEMS(matrix) && j < FF_ARRAY_ELEMS(matrix[0]))
373317
matrix_param[stride*out_i + in_i] = matrix[i][j];
374318
else
375319
matrix_param[stride*out_i + in_i] = i == j &&
376-
( av_channel_layout_index_from_channel(&in_ch_layout, i) >= 0
377-
&& av_channel_layout_index_from_channel(&out_ch_layout, i) >= 0);
320+
( av_channel_layout_index_from_channel(in_ch_layout, i) >= 0
321+
&& av_channel_layout_index_from_channel(out_ch_layout, i) >= 0);
378322
sum += fabs(matrix_param[stride*out_i + in_i]);
379323
in_i++;
380324
}
@@ -391,6 +335,72 @@ av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL
391335
matrix_param[stride*i + j] /= maxcoef;
392336
}
393337
}
338+
}
339+
340+
av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,
341+
double center_mix_level, double surround_mix_level,
342+
double lfe_mix_level, double maxval,
343+
double rematrix_volume, double *matrix_param,
344+
ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
345+
{
346+
int i, j, ret;
347+
AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
348+
char buf[128];
349+
350+
ret = clean_layout(&in_ch_layout, in_layout, log_context);
351+
ret |= clean_layout(&out_ch_layout, out_layout, log_context);
352+
if (ret < 0)
353+
goto fail;
354+
355+
if( !av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
356+
&& !av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
357+
) {
358+
av_channel_layout_uninit(&out_ch_layout);
359+
out_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
360+
}
361+
if( !av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
362+
&& !av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
363+
) {
364+
av_channel_layout_uninit(&in_ch_layout);
365+
in_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
366+
}
367+
if (!av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2) &&
368+
av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2)) {
369+
av_channel_layout_from_mask(&in_ch_layout, (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER));
370+
av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
371+
av_log(log_context, AV_LOG_WARNING,
372+
"Full-on remixing from 22.2 has not yet been implemented! "
373+
"Processing the input as '%s'\n",
374+
buf);
375+
}
376+
377+
if(!av_channel_layout_check(&in_ch_layout)) {
378+
av_log(log_context, AV_LOG_ERROR, "Input channel layout is invalid\n");
379+
ret = AVERROR(EINVAL);
380+
goto fail;
381+
}
382+
if(!sane_layout(&in_ch_layout)) {
383+
av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
384+
av_log(log_context, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
385+
ret = AVERROR(EINVAL);
386+
goto fail;
387+
}
388+
389+
if(!av_channel_layout_check(&out_ch_layout)) {
390+
av_log(log_context, AV_LOG_ERROR, "Output channel layout is invalid\n");
391+
ret = AVERROR(EINVAL);
392+
goto fail;
393+
}
394+
if(!sane_layout(&out_ch_layout)) {
395+
av_channel_layout_describe(&out_ch_layout, buf, sizeof(buf));
396+
av_log(log_context, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
397+
ret = AVERROR(EINVAL);
398+
goto fail;
399+
}
400+
401+
build_matrix(&in_ch_layout, &out_ch_layout, center_mix_level,
402+
surround_mix_level, lfe_mix_level, maxval, rematrix_volume,
403+
matrix_param, stride, matrix_encoding);
394404

395405
if(rematrix_volume > 0){
396406
for(i=0; i<SWR_CH_MAX; i++)

0 commit comments

Comments
 (0)