FFmpeg
rematrix.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2012 Michael Niedermayer (michaelni@gmx.at)
3  *
4  * This file is part of libswresample
5  *
6  * libswresample is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * libswresample is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with libswresample; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "swresample_internal.h"
22 #include "libavutil/avassert.h"
24 #include "libavutil/mem.h"
25 
26 #define TEMPLATE_REMATRIX_FLT
27 #include "rematrix_template.c"
28 #undef TEMPLATE_REMATRIX_FLT
29 
30 #define TEMPLATE_REMATRIX_DBL
31 #include "rematrix_template.c"
32 #undef TEMPLATE_REMATRIX_DBL
33 
34 #define TEMPLATE_REMATRIX_S16
35 #include "rematrix_template.c"
36 #define TEMPLATE_CLIP
37 #include "rematrix_template.c"
38 #undef TEMPLATE_CLIP
39 #undef TEMPLATE_REMATRIX_S16
40 
41 #define TEMPLATE_REMATRIX_S32
42 #include "rematrix_template.c"
43 #undef TEMPLATE_REMATRIX_S32
44 
45 #define FRONT_LEFT 0
46 #define FRONT_RIGHT 1
47 #define FRONT_CENTER 2
48 #define LOW_FREQUENCY 3
49 #define BACK_LEFT 4
50 #define BACK_RIGHT 5
51 #define FRONT_LEFT_OF_CENTER 6
52 #define FRONT_RIGHT_OF_CENTER 7
53 #define BACK_CENTER 8
54 #define SIDE_LEFT 9
55 #define SIDE_RIGHT 10
56 #define TOP_CENTER 11
57 #define TOP_FRONT_LEFT 12
58 #define TOP_FRONT_CENTER 13
59 #define TOP_FRONT_RIGHT 14
60 #define TOP_BACK_LEFT 15
61 #define TOP_BACK_CENTER 16
62 #define TOP_BACK_RIGHT 17
63 #define LOW_FREQUENCY_2 35
64 #define TOP_SIDE_LEFT 36
65 #define TOP_SIDE_RIGHT 37
66 #define BOTTOM_FRONT_CENTER 38
67 #define BOTTOM_FRONT_LEFT 39
68 #define BOTTOM_FRONT_RIGHT 40
69 #define NUM_NAMED_CHANNELS 41
70 
71 int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
72 {
73  int nb_in, nb_out, in, out;
74 
75  if (!s || s->in_convert || // s needs to be allocated but not initialized
76  swri_check_chlayout(s, &s->user_in_chlayout , "input") ||
77  swri_check_chlayout(s, &s->user_out_chlayout, "output")
78  )
79  return AVERROR(EINVAL);
80  memset(s->matrix, 0, sizeof(s->matrix));
81 
82  nb_in = s->user_in_chlayout.nb_channels;
83  nb_out = s->user_out_chlayout.nb_channels;
84  for (out = 0; out < nb_out; out++) {
85  for (in = 0; in < nb_in; in++)
86  s->matrix[out][in] = matrix[in];
87  matrix += stride;
88  }
89  s->rematrix_custom = 1;
90  return 0;
91 }
92 
93 static int even(int64_t layout){
94  if(!layout) return 1;
95  if(layout&(layout-1)) return 1;
96  return 0;
97 }
98 
99 static int clean_layout(AVChannelLayout *out, const AVChannelLayout *in, void *s)
100 {
101  int ret = 0;
102 
104  char buf[128];
105  av_channel_layout_describe(in, buf, sizeof(buf));
106  av_log(s, AV_LOG_VERBOSE, "Treating %s as mono\n", buf);
108  } else
110 
111  return ret;
112 }
113 
114 static int sane_layout(AVChannelLayout *ch_layout) {
115  if(ch_layout->nb_channels >= SWR_CH_MAX)
116  return 0;
117  if(ch_layout->order == AV_CHANNEL_ORDER_CUSTOM)
118  for (int i = 0; i < ch_layout->nb_channels; i++) {
119  if (ch_layout->u.map[i].id >= 64)
120  return 0;
121  }
122  else if (ch_layout->order != AV_CHANNEL_ORDER_NATIVE)
123  return 0;
124  uint64_t mask = av_channel_layout_subset(ch_layout, ~(uint64_t)0);
125  if(!(mask & AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker
126  return 0;
127  if (!even(mask & (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT))) // no asymmetric front
128  return 0;
129  if (!even(mask & (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT))) // no asymmetric side
130  return 0;
132  return 0;
134  return 0;
136  return 0;
138  return 0;
140  return 0;
142  return 0;
143 
144  return 1;
145 }
146 
147 static void build_matrix(const AVChannelLayout *in_ch_layout, const AVChannelLayout *out_ch_layout,
148  double center_mix_level, double surround_mix_level,
149  double lfe_mix_level, double maxval, double rematrix_volume, double *matrix_param,
150  ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding)
151 {
153  uint64_t in_mask = av_channel_layout_subset(in_ch_layout, ~(uint64_t)0);
154  uint64_t out_mask = av_channel_layout_subset(out_ch_layout, ~(uint64_t)0);
155  uint64_t unaccounted = in_mask & ~out_mask;
156  double maxcoef=0;
157  int i, j;
158 
159  for(i=0; i<FF_ARRAY_ELEMS(matrix); i++){
160  if (in_mask & out_mask & (1ULL << i))
161  matrix[i][i]= 1.0;
162  }
163 
164 //FIXME implement dolby surround
165 //FIXME implement full ac3
166 
167  if(unaccounted & AV_CH_FRONT_CENTER){
168  if ((out_mask & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO) {
169  if (in_mask & AV_CH_LAYOUT_STEREO) {
170  matrix[ FRONT_LEFT][FRONT_CENTER]+= center_mix_level;
171  matrix[FRONT_RIGHT][FRONT_CENTER]+= center_mix_level;
172  } else {
175  }
176  }else
177  av_assert0(0);
178  }
179  if(unaccounted & AV_CH_LAYOUT_STEREO){
180  if (out_mask & AV_CH_FRONT_CENTER) {
183  if (in_mask & AV_CH_FRONT_CENTER)
184  matrix[FRONT_CENTER][ FRONT_CENTER] = center_mix_level*sqrt(2);
185  }else
186  av_assert0(0);
187  }
188 
189  if(unaccounted & AV_CH_BACK_CENTER){
190  if (out_mask & AV_CH_BACK_LEFT) {
193  } else if (out_mask & AV_CH_SIDE_LEFT) {
196  } else if (out_mask & AV_CH_FRONT_LEFT) {
197  if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
198  matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
199  if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
200  matrix[FRONT_LEFT ][BACK_CENTER] -= surround_mix_level * M_SQRT1_2;
201  matrix[FRONT_RIGHT][BACK_CENTER] += surround_mix_level * M_SQRT1_2;
202  } else {
203  matrix[FRONT_LEFT ][BACK_CENTER] -= surround_mix_level;
204  matrix[FRONT_RIGHT][BACK_CENTER] += surround_mix_level;
205  }
206  } else {
207  matrix[ FRONT_LEFT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
208  matrix[FRONT_RIGHT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
209  }
210  } else if (out_mask & AV_CH_FRONT_CENTER) {
211  matrix[ FRONT_CENTER][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
212  }else
213  av_assert0(0);
214  }
215  if(unaccounted & AV_CH_BACK_LEFT){
216  if (out_mask & AV_CH_BACK_CENTER) {
219  } else if (out_mask & AV_CH_SIDE_LEFT) {
220  if (in_mask & AV_CH_SIDE_LEFT) {
223  }else{
224  matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
225  matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
226  }
227  } else if (out_mask & AV_CH_FRONT_LEFT) {
228  if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
229  matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * M_SQRT1_2;
230  matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2;
231  matrix[FRONT_RIGHT][BACK_LEFT ] += surround_mix_level * M_SQRT1_2;
232  matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level * M_SQRT1_2;
233  } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
234  matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * SQRT3_2;
235  matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2;
236  matrix[FRONT_RIGHT][BACK_LEFT ] += surround_mix_level * M_SQRT1_2;
237  matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level * SQRT3_2;
238  } else {
239  matrix[ FRONT_LEFT][ BACK_LEFT] += surround_mix_level;
240  matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level;
241  }
242  } else if (out_mask & AV_CH_FRONT_CENTER) {
243  matrix[ FRONT_CENTER][BACK_LEFT ]+= surround_mix_level*M_SQRT1_2;
244  matrix[ FRONT_CENTER][BACK_RIGHT]+= surround_mix_level*M_SQRT1_2;
245  }else
246  av_assert0(0);
247  }
248 
249  if(unaccounted & AV_CH_SIDE_LEFT){
250  if (out_mask & AV_CH_BACK_LEFT) {
251  /* if back channels do not exist in the input, just copy side
252  channels to back channels, otherwise mix side into back */
253  if (in_mask & AV_CH_BACK_LEFT) {
256  } else {
257  matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;
258  matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;
259  }
260  } else if (out_mask & AV_CH_BACK_CENTER) {
263  } else if (out_mask & AV_CH_FRONT_LEFT) {
264  if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
265  matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * M_SQRT1_2;
266  matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2;
267  matrix[FRONT_RIGHT][SIDE_LEFT ] += surround_mix_level * M_SQRT1_2;
268  matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level * M_SQRT1_2;
269  } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
270  matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * SQRT3_2;
271  matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2;
272  matrix[FRONT_RIGHT][SIDE_LEFT ] += surround_mix_level * M_SQRT1_2;
273  matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level * SQRT3_2;
274  } else {
275  matrix[ FRONT_LEFT][ SIDE_LEFT] += surround_mix_level;
276  matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level;
277  }
278  } else if (out_mask & AV_CH_FRONT_CENTER) {
279  matrix[ FRONT_CENTER][SIDE_LEFT ]+= surround_mix_level * M_SQRT1_2;
280  matrix[ FRONT_CENTER][SIDE_RIGHT]+= surround_mix_level * M_SQRT1_2;
281  }else
282  av_assert0(0);
283  }
284 
285  if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
286  if (out_mask & AV_CH_FRONT_LEFT) {
289  } else if (out_mask & AV_CH_FRONT_CENTER) {
292  }else
293  av_assert0(0);
294  }
295 
296  if (unaccounted & AV_CH_TOP_FRONT_LEFT) {
297  if (out_mask & AV_CH_TOP_FRONT_CENTER) {
300  if (in_mask & AV_CH_TOP_FRONT_CENTER)
301  matrix[TOP_FRONT_CENTER][TOP_FRONT_CENTER] = center_mix_level * sqrt(2);
302  } else if (out_mask & AV_CH_FRONT_LEFT) {
303  /* U+030 -> M+030 in ITU-R BS.2127-1, Table 16. */
304  matrix[FRONT_LEFT ][TOP_FRONT_LEFT ] += 1.0;
306  } else if (out_mask & AV_CH_FRONT_CENTER) {
309  } else
310  av_assert0(0);
311  }
312 
313  if (unaccounted & AV_CH_TOP_FRONT_CENTER) {
314  if (out_mask & AV_CH_TOP_FRONT_LEFT) {
315  /* U+030 = U-030 = sqrt(1/2) */
318  } else if (out_mask & AV_CH_FRONT_CENTER) {
319  /* M+000 = 1 */
321  } else if (out_mask & AV_CH_FRONT_LEFT) {
322  /* M+030 = M-030 = sqrt(1/2) */
323  matrix[FRONT_LEFT ][TOP_FRONT_CENTER] += center_mix_level;
324  matrix[FRONT_RIGHT][TOP_FRONT_CENTER] += center_mix_level;
325  } else
326  av_assert0(0);
327  }
328 
329  if (unaccounted & AV_CH_TOP_BACK_LEFT) {
330  if (out_mask & AV_CH_TOP_BACK_CENTER) {
333  } else if (out_mask & AV_CH_TOP_FRONT_LEFT) {
334  /* IAMF v1.1.0, Section 7.3.2.1.1. */
337  } else if (out_mask & AV_CH_BACK_LEFT) {
338  matrix[BACK_LEFT ][TOP_BACK_LEFT ] += 1.0;
340  } else if (out_mask & AV_CH_SIDE_LEFT) {
341  matrix[SIDE_LEFT ][TOP_BACK_LEFT ] += 1.0;
343  } else if (out_mask & AV_CH_FRONT_LEFT) {
344  matrix[FRONT_LEFT ][TOP_BACK_LEFT ] += surround_mix_level;
345  matrix[FRONT_RIGHT][TOP_BACK_RIGHT] += surround_mix_level;
346  } else if (out_mask & AV_CH_FRONT_CENTER) {
347  matrix[FRONT_CENTER][TOP_BACK_LEFT ] += surround_mix_level*M_SQRT1_2;
348  matrix[FRONT_CENTER][TOP_BACK_RIGHT] += surround_mix_level*M_SQRT1_2;
349  } else
350  av_assert0(0);
351  }
352 
353  /* BS.2127-1 maps U+180 to rear outputs before front outputs. */
354  if (unaccounted & AV_CH_TOP_BACK_CENTER) {
355  if (out_mask & AV_CH_TOP_BACK_LEFT) {
358  } else if (out_mask & AV_CH_BACK_LEFT) {
361  } else if (out_mask & AV_CH_SIDE_LEFT) {
364  } else if (out_mask & AV_CH_FRONT_LEFT) {
367  } else if (out_mask & AV_CH_FRONT_CENTER)
369  else
370  av_assert0(0);
371  }
372 
373 
374  if (unaccounted & AV_CH_TOP_SIDE_LEFT) {
375  if ((out_mask & (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_BACK_CENTER)) ==
377  /* UH+180 = sqrt(1/3); U±045 = sqrt(2/3)*/
382  } else if ((out_mask & (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_BACK_LEFT)) ==
384  /* U±030 = U±110 = sqrt(1/2) */
389  } else if (out_mask & AV_CH_TOP_FRONT_LEFT &&
390  (out_mask & (AV_CH_BACK_LEFT|AV_CH_SIDE_LEFT))) {
391  /* U±030 = M±110 = sqrt(1/2) */
394  if (out_mask & AV_CH_BACK_LEFT) {
397  } else if (out_mask & AV_CH_SIDE_LEFT) {
400  }
401  } else if (out_mask & AV_CH_SIDE_LEFT) {
402  /* M±090 = 1 */
403  matrix[SIDE_LEFT ][TOP_SIDE_LEFT ] += 1.0;
405  } else if (out_mask & AV_CH_FRONT_LEFT) {
406  /* M±030 = M±110 = sqrt(1/2) */
407  matrix[FRONT_LEFT ][TOP_SIDE_LEFT ] += surround_mix_level;
408  matrix[FRONT_RIGHT][TOP_SIDE_RIGHT] += surround_mix_level;
409  if (out_mask & AV_CH_BACK_LEFT) {
412  }
413  } else if (out_mask & AV_CH_FRONT_CENTER) {
414  matrix[FRONT_CENTER][TOP_SIDE_LEFT ] += surround_mix_level*M_SQRT1_2;
415  matrix[FRONT_CENTER][TOP_SIDE_RIGHT] += surround_mix_level*M_SQRT1_2;
416  } else
417  av_assert0(0);
418  }
419 
420  if (unaccounted & AV_CH_TOP_CENTER) {
421  if ((out_mask & (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_BACK_LEFT)) ==
423  /* U+045 = U-045 = U+135 = U-135 = sqrt(1/4) */
424  matrix[TOP_FRONT_LEFT ][TOP_CENTER] += 0.5;
426  matrix[TOP_BACK_LEFT ][TOP_CENTER] += 0.5;
428  } else if ((out_mask & (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_BACK_CENTER)) ==
430  /* U+045 = U-045 = UH+180 = sqrt(1/3) */
434  } else if (out_mask & AV_CH_TOP_FRONT_LEFT &&
435  out_mask & (AV_CH_BACK_LEFT|AV_CH_SIDE_LEFT)) {
436  /* U+045 = U-045 = M+135 = M-135 = sqrt(1/4) *
437  * U+030 = U-030 = M+110 = M-110 = sqrt(1/4) */
438  matrix[TOP_FRONT_LEFT ][TOP_CENTER] += 0.5;
440  if (out_mask & AV_CH_BACK_LEFT) {
441  matrix[BACK_LEFT ][TOP_CENTER] += 0.5;
442  matrix[BACK_RIGHT][TOP_CENTER] += 0.5;
443  } else if (out_mask & AV_CH_SIDE_LEFT) {
444  matrix[SIDE_LEFT ][TOP_CENTER] += 0.5;
445  matrix[SIDE_RIGHT][TOP_CENTER] += 0.5;
446  }
447  } else if (out_mask & AV_CH_FRONT_LEFT) {
448  /* M+030 = M-030 = M+135 = M-135 = sqrt(1/4) */
449  /* M+030 = M-030 = sqrt(1/4) */
450  matrix[FRONT_LEFT ][TOP_CENTER] += 0.5;
451  matrix[FRONT_RIGHT][TOP_CENTER] += 0.5;
452  if (out_mask & AV_CH_BACK_LEFT) {
453  matrix[BACK_LEFT ][TOP_CENTER] += 0.5;
454  matrix[BACK_RIGHT][TOP_CENTER] += 0.5;
455  } else if (out_mask & AV_CH_SIDE_LEFT) {
456  matrix[SIDE_LEFT ][TOP_CENTER] += 0.5;
457  matrix[SIDE_RIGHT][TOP_CENTER] += 0.5;
458  }
459  } else if (out_mask & AV_CH_FRONT_CENTER) {
460  matrix[FRONT_CENTER][TOP_CENTER] += 0.5;
461  } else
462  av_assert0(0);
463  }
464 
465  if (unaccounted & AV_CH_BOTTOM_FRONT_CENTER) {
466  if (out_mask & AV_CH_FRONT_CENTER) {
468  } else if (out_mask & AV_CH_FRONT_LEFT) {
469  matrix[FRONT_LEFT ][BOTTOM_FRONT_CENTER] += center_mix_level;
470  matrix[FRONT_RIGHT][BOTTOM_FRONT_CENTER] += center_mix_level;
471  } else
472  av_assert0(0);
473  }
474 
475  if (unaccounted & AV_CH_BOTTOM_FRONT_LEFT) {
476  if (out_mask & AV_CH_BOTTOM_FRONT_CENTER) {
479  if (in_mask & AV_CH_BOTTOM_FRONT_CENTER)
480  matrix[BOTTOM_FRONT_CENTER][BOTTOM_FRONT_CENTER] = center_mix_level * sqrt(2);
481  } else if (out_mask & AV_CH_FRONT_LEFT) {
482  /* M±030 = 1 */
485  } else if (out_mask & AV_CH_FRONT_CENTER) {
488  } else
489  av_assert0(0);
490  }
491 
492  /* mix LFE into front left/right or center */
493  if (unaccounted & AV_CH_LOW_FREQUENCY) {
494  if (out_mask & AV_CH_FRONT_CENTER) {
495  matrix[FRONT_CENTER][LOW_FREQUENCY] += lfe_mix_level;
496  } else if (out_mask & AV_CH_FRONT_LEFT) {
497  matrix[FRONT_LEFT ][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
498  matrix[FRONT_RIGHT][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
499  } else
500  av_assert0(0);
501  }
502 
503  /* mix LFE2 into LFE, front left/right or center */
504  if (unaccounted & AV_CH_LOW_FREQUENCY_2) {
505  if (out_mask & AV_CH_LOW_FREQUENCY) {
507  } else if (out_mask & AV_CH_FRONT_CENTER) {
508  matrix[FRONT_CENTER][LOW_FREQUENCY_2] += lfe_mix_level;
509  } else if (out_mask & AV_CH_FRONT_LEFT) {
510  matrix[FRONT_LEFT ][LOW_FREQUENCY_2] += lfe_mix_level * M_SQRT1_2;
511  matrix[FRONT_RIGHT][LOW_FREQUENCY_2] += lfe_mix_level * M_SQRT1_2;
512  } else
513  av_assert0(0);
514  }
515 
516 
517  for (i = 0; i < 64; i++) {
518  double sum=0;
519  int out_i = av_channel_layout_index_from_channel(out_ch_layout, i);
520  if (out_i < 0)
521  continue;
522  for(j=0; j<64; j++){
523  int in_i = av_channel_layout_index_from_channel(in_ch_layout, j);
524  if (in_i < 0)
525  continue;
526  if (i < FF_ARRAY_ELEMS(matrix) && j < FF_ARRAY_ELEMS(matrix[0]))
527  matrix_param[stride*out_i + in_i] = matrix[i][j];
528  else
529  matrix_param[stride*out_i + in_i] = i == j && (in_mask & out_mask & (1ULL << i));
530  sum += fabs(matrix_param[stride*out_i + in_i]);
531  }
532  maxcoef= FFMAX(maxcoef, sum);
533  }
534  if(rematrix_volume < 0)
535  maxcoef = -rematrix_volume;
536 
537  if(maxcoef > maxval || rematrix_volume < 0){
538  maxcoef /= maxval;
539  for(i=0; i<SWR_CH_MAX; i++)
540  for(j=0; j<SWR_CH_MAX; j++){
541  matrix_param[stride*i + j] /= maxcoef;
542  }
543  }
544 }
545 
546 av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,
547  double center_mix_level, double surround_mix_level,
548  double lfe_mix_level, double maxval,
549  double rematrix_volume, double *matrix_param,
550  ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
551 {
552  int i, j, ret;
553  AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
554  char buf[128];
555 
556  ret = clean_layout(&in_ch_layout, in_layout, log_context);
557  ret |= clean_layout(&out_ch_layout, out_layout, log_context);
558  if (ret < 0)
559  goto fail;
560 
563  ) {
564  av_channel_layout_uninit(&out_ch_layout);
565  out_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
566  }
569  ) {
570  av_channel_layout_uninit(&in_ch_layout);
572  }
573 
574  if(!av_channel_layout_check(&in_ch_layout)) {
575  av_log(log_context, AV_LOG_ERROR, "Input channel layout is invalid\n");
576  ret = AVERROR(EINVAL);
577  goto fail;
578  }
579  if(!sane_layout(&in_ch_layout)) {
580  av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
581  av_log(log_context, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
582  ret = AVERROR(EINVAL);
583  goto fail;
584  }
585 
586  if(!av_channel_layout_check(&out_ch_layout)) {
587  av_log(log_context, AV_LOG_ERROR, "Output channel layout is invalid\n");
588  ret = AVERROR(EINVAL);
589  goto fail;
590  }
591  if(!sane_layout(&out_ch_layout)) {
592  av_channel_layout_describe(&out_ch_layout, buf, sizeof(buf));
593  av_log(log_context, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
594  ret = AVERROR(EINVAL);
595  goto fail;
596  }
597 
598  build_matrix(&in_ch_layout, &out_ch_layout, center_mix_level,
599  surround_mix_level, lfe_mix_level, maxval, rematrix_volume,
600  matrix_param, stride, matrix_encoding);
601 
602  if(rematrix_volume > 0){
603  for(i=0; i<SWR_CH_MAX; i++)
604  for(j=0; j<SWR_CH_MAX; j++){
605  matrix_param[stride*i + j] *= rematrix_volume;
606  }
607  }
608 
609  av_log(log_context, AV_LOG_DEBUG, "Matrix coefficients:\n");
610  for (i = 0; i < out_ch_layout.nb_channels; i++){
611  av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&out_ch_layout, i));
612  av_log(log_context, AV_LOG_DEBUG, "%s: ", buf);
613  for (j = 0; j < in_ch_layout.nb_channels; j++){
614  av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&in_ch_layout, j));
615  av_log(log_context, AV_LOG_DEBUG, "%s:%f ", buf, matrix_param[stride*i + j]);
616  }
617  av_log(log_context, AV_LOG_DEBUG, "\n");
618  }
619 
620  ret = 0;
621 fail:
622  av_channel_layout_uninit(&in_ch_layout);
623  av_channel_layout_uninit(&out_ch_layout);
624 
625  return ret;
626 }
627 
629 {
630  double maxval;
631 
632  if (s->rematrix_maxval > 0) {
633  maxval = s->rematrix_maxval;
634  } else if ( av_get_packed_sample_fmt(s->out_sample_fmt) < AV_SAMPLE_FMT_FLT
635  || av_get_packed_sample_fmt(s->int_sample_fmt) < AV_SAMPLE_FMT_FLT) {
636  maxval = 1.0;
637  } else
638  maxval = INT_MAX;
639 
640  memset(s->matrix, 0, sizeof(s->matrix));
641  return swr_build_matrix2(&s->in_ch_layout, &s->out_ch_layout,
642  s->clev, s->slev, s->lfe_mix_level,
643  maxval, s->rematrix_volume, (double*)s->matrix,
644  s->matrix[1] - s->matrix[0], s->matrix_encoding, s);
645 }
646 
648  int i, j;
649  int nb_in = s->used_ch_layout.nb_channels;
650  int nb_out = s->out.ch_count;
651 
652  s->mix_any_f = NULL;
653 
654  if (!s->rematrix_custom) {
655  int r = auto_matrix(s);
656  if (r)
657  return r;
658  } else {
659  char buf[128];
660  av_log(s, AV_LOG_DEBUG, "Custom matrix coefficients:\n");
661  double *matrix_param = (double*)s->matrix;
662  ptrdiff_t stride = s->matrix[1] - s->matrix[0];
663  for (i = 0; i < s->out_ch_layout.nb_channels; i++) {
664  av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&s->out_ch_layout, i));
665  av_log(s, AV_LOG_DEBUG, "%s: ", buf);
666  for (j = 0; j < s->in_ch_layout.nb_channels; j++){
667  av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&s->in_ch_layout, j));
668  av_log(s, AV_LOG_DEBUG, "%s:%f ", buf, matrix_param[stride*i + j]);
669  }
670  av_log(s, AV_LOG_DEBUG, "\n");
671  }
672  }
673  if (s->midbuf.fmt == AV_SAMPLE_FMT_S16P){
674  int maxsum = 0;
675  s->native_matrix = av_calloc(nb_in * nb_out, sizeof(int));
676  if (!s->native_matrix)
677  return AVERROR(ENOMEM);
678  for (i = 0; i < nb_out; i++) {
679  double rem = 0;
680  int sum = 0;
681 
682  for (j = 0; j < nb_in; j++) {
683  double target = s->matrix[i][j] * 32768 + rem;
684  ((int*)s->native_matrix)[i * nb_in + j] = lrintf(target);
685  rem += target - ((int*)s->native_matrix)[i * nb_in + j];
686  sum += FFABS(((int*)s->native_matrix)[i * nb_in + j]);
687  }
688  maxsum = FFMAX(maxsum, sum);
689  }
690  s->native_one.i = 32768;
691  if (maxsum <= 32768) {
692  s->mix_1_1_f = copy_s16;
693  s->mix_2_1_f = sum2_s16;
694  s->mix_any_f = get_mix_any_func_s16(s);
695  } else {
696  s->mix_1_1_f = copy_clip_s16;
697  s->mix_2_1_f = sum2_clip_s16;
698  s->mix_any_f = get_mix_any_func_clip_s16(s);
699  }
700  }else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){
701  s->native_matrix = av_calloc(nb_in * nb_out, sizeof(float));
702  if (!s->native_matrix)
703  return AVERROR(ENOMEM);
704  for (i = 0; i < nb_out; i++)
705  for (j = 0; j < nb_in; j++)
706  ((float*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
707  s->native_one.f = 1.0;
708  s->mix_1_1_f = copy_float;
709  s->mix_2_1_f = sum2_float;
710  s->mix_any_f = get_mix_any_func_float(s);
711  }else if(s->midbuf.fmt == AV_SAMPLE_FMT_DBLP){
712  s->native_matrix = av_calloc(nb_in * nb_out, sizeof(double));
713  if (!s->native_matrix)
714  return AVERROR(ENOMEM);
715  for (i = 0; i < nb_out; i++)
716  for (j = 0; j < nb_in; j++)
717  ((double*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
718  s->native_one.d = 1.0;
719  s->mix_1_1_f = copy_double;
720  s->mix_2_1_f = sum2_double;
721  s->mix_any_f = get_mix_any_func_double(s);
722  }else if(s->midbuf.fmt == AV_SAMPLE_FMT_S32P){
723  s->native_matrix = av_calloc(nb_in * nb_out, sizeof(int));
724  if (!s->native_matrix)
725  return AVERROR(ENOMEM);
726  for (i = 0; i < nb_out; i++) {
727  double rem = 0;
728 
729  for (j = 0; j < nb_in; j++) {
730  double target = s->matrix[i][j] * 32768 + rem;
731  ((int*)s->native_matrix)[i * nb_in + j] = lrintf(target);
732  rem += target - ((int*)s->native_matrix)[i * nb_in + j];
733  }
734  }
735  s->native_one.i = 32768;
736  s->mix_1_1_f = copy_s32;
737  s->mix_2_1_f = sum2_s32;
738  s->mix_any_f = get_mix_any_func_s32(s);
739  }else
740  av_assert0(0);
741  //FIXME quantize for integeres
742  for (i = 0; i < SWR_CH_MAX; i++) {
743  int ch_in=0;
744  for (j = 0; j < SWR_CH_MAX; j++) {
745  const double coeff = s->matrix[i][j];
746  if (coeff)
747  s->matrix_ch[i][++ch_in]= j;
748  switch (s->int_sample_fmt) {
749  case AV_SAMPLE_FMT_FLTP:
750  s->matrix_flt[i][j] = coeff;
751  break;
752  case AV_SAMPLE_FMT_DBLP:
753  break;
754  default:
755  s->matrix32[i][j] = lrintf(coeff * 32768);
756  break;
757  }
758  }
759  s->matrix_ch[i][0]= ch_in;
760  }
761 
762 #if ARCH_X86 && HAVE_X86ASM
763  return swri_rematrix_init_x86(s);
764 #endif
765 
766  return 0;
767 }
768 
770  av_freep(&s->native_matrix);
771  av_freep(&s->native_simd_matrix);
772 }
773 
774 int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy){
775  int out_i, in_i, i, j;
776  int len1 = 0;
777  int off = 0;
778 
779  if(s->mix_any_f) {
780  s->mix_any_f(out->ch, (const uint8_t *const *)in->ch, s->native_matrix, len);
781  return 0;
782  }
783 
784  if(s->mix_2_1_simd || s->mix_1_1_simd){
785  len1= len&~15;
786  off = len1 * out->bps;
787  }
788 
789  av_assert0(s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || out->ch_count == s->out_ch_layout.nb_channels);
790  av_assert0(s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || in ->ch_count == s->in_ch_layout.nb_channels);
791 
792  for(out_i=0; out_i<out->ch_count; out_i++){
793  switch(s->matrix_ch[out_i][0]){
794  case 0:
795  if(mustcopy)
796  memset(out->ch[out_i], 0, len * av_get_bytes_per_sample(s->int_sample_fmt));
797  break;
798  case 1:
799  in_i= s->matrix_ch[out_i][1];
800  if(s->matrix[out_i][in_i]!=1.0){
801  if(s->mix_1_1_simd && len1)
802  s->mix_1_1_simd(out->ch[out_i] , in->ch[in_i] , s->native_simd_matrix, in->ch_count*out_i + in_i, len1);
803  if(len != len1)
804  s->mix_1_1_f (out->ch[out_i]+off, in->ch[in_i]+off, s->native_matrix, in->ch_count*out_i + in_i, len-len1);
805  }else if(mustcopy){
806  memcpy(out->ch[out_i], in->ch[in_i], len*out->bps);
807  }else{
808  out->ch[out_i]= in->ch[in_i];
809  }
810  break;
811  case 2: {
812  int in_i1 = s->matrix_ch[out_i][1];
813  int in_i2 = s->matrix_ch[out_i][2];
814  if(s->mix_2_1_simd && len1)
815  s->mix_2_1_simd(out->ch[out_i] , in->ch[in_i1] , in->ch[in_i2] , s->native_simd_matrix, in->ch_count*out_i + in_i1, in->ch_count*out_i + in_i2, len1);
816  else
817  s->mix_2_1_f (out->ch[out_i] , in->ch[in_i1] , in->ch[in_i2] , s->native_matrix, in->ch_count*out_i + in_i1, in->ch_count*out_i + in_i2, len1);
818  if(len != len1)
819  s->mix_2_1_f (out->ch[out_i]+off, in->ch[in_i1]+off, in->ch[in_i2]+off, s->native_matrix, in->ch_count*out_i + in_i1, in->ch_count*out_i + in_i2, len-len1);
820  break;}
821  default:
822  if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){
823  for(i=0; i<len; i++){
824  float v=0;
825  for(j=0; j<s->matrix_ch[out_i][0]; j++){
826  in_i= s->matrix_ch[out_i][1+j];
827  v+= ((float*)in->ch[in_i])[i] * s->matrix_flt[out_i][in_i];
828  }
829  ((float*)out->ch[out_i])[i]= v;
830  }
831  }else if(s->int_sample_fmt == AV_SAMPLE_FMT_DBLP){
832  for(i=0; i<len; i++){
833  double v=0;
834  for(j=0; j<s->matrix_ch[out_i][0]; j++){
835  in_i= s->matrix_ch[out_i][1+j];
836  v+= ((double*)in->ch[in_i])[i] * s->matrix[out_i][in_i];
837  }
838  ((double*)out->ch[out_i])[i]= v;
839  }
840  }else{
841  for(i=0; i<len; i++){
842  int v=0;
843  for(j=0; j<s->matrix_ch[out_i][0]; j++){
844  in_i= s->matrix_ch[out_i][1+j];
845  v+= ((int16_t*)in->ch[in_i])[i] * s->matrix32[out_i][in_i];
846  }
847  ((int16_t*)out->ch[out_i])[i]= (v + 16384)>>15;
848  }
849  }
850  }
851  }
852  return 0;
853 }
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
AV_CHANNEL_LAYOUT_STEREO_DOWNMIX
#define AV_CHANNEL_LAYOUT_STEREO_DOWNMIX
Definition: channel_layout.h:432
r
const char * r
Definition: vf_curves.c:127
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AV_CH_TOP_SIDE_LEFT
#define AV_CH_TOP_SIDE_LEFT
Definition: channel_layout.h:200
TOP_SIDE_RIGHT
#define TOP_SIDE_RIGHT
Definition: rematrix.c:65
AV_CH_TOP_FRONT_CENTER
#define AV_CH_TOP_FRONT_CENTER
Definition: channel_layout.h:188
out
static FILE * out
Definition: movenc.c:55
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:395
AV_CH_LOW_FREQUENCY_2
#define AV_CH_LOW_FREQUENCY_2
Definition: channel_layout.h:199
NUM_NAMED_CHANNELS
#define NUM_NAMED_CHANNELS
Definition: rematrix.c:69
matrix
Definition: vc1dsp.c:43
av_cold
#define av_cold
Definition: attributes.h:119
int64_t
long long int64_t
Definition: coverity.c:34
rematrix_template.c
AVChannelLayout::map
AVChannelCustom * map
This member must be used when the channel order is AV_CHANNEL_ORDER_CUSTOM.
Definition: channel_layout.h:370
mask
int mask
Definition: mediacodecdec_common.c:154
AV_CH_TOP_FRONT_RIGHT
#define AV_CH_TOP_FRONT_RIGHT
Definition: channel_layout.h:189
av_channel_layout_channel_from_index
enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx)
Get the channel with the given index in a channel layout.
Definition: channel_layout.c:674
TOP_FRONT_RIGHT
#define TOP_FRONT_RIGHT
Definition: rematrix.c:59
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:65
swri_rematrix_init_x86
int swri_rematrix_init_x86(struct SwrContext *s)
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
sane_layout
static int sane_layout(AVChannelLayout *ch_layout)
Definition: rematrix.c:114
AV_CH_TOP_FRONT_LEFT
#define AV_CH_TOP_FRONT_LEFT
Definition: channel_layout.h:187
SQRT3_2
#define SQRT3_2
Definition: swresample_internal.h:32
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:324
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
swr_set_matrix
int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
Set a customized remix matrix.
Definition: rematrix.c:71
AV_CH_BOTTOM_FRONT_LEFT
#define AV_CH_BOTTOM_FRONT_LEFT
Definition: channel_layout.h:203
AV_CH_TOP_BACK_LEFT
#define AV_CH_TOP_BACK_LEFT
Definition: channel_layout.h:190
BOTTOM_FRONT_LEFT
#define BOTTOM_FRONT_LEFT
Definition: rematrix.c:67
AudioData
Definition: swresample_internal.h:47
AV_CH_TOP_BACK_CENTER
#define AV_CH_TOP_BACK_CENTER
Definition: channel_layout.h:191
BOTTOM_FRONT_RIGHT
#define BOTTOM_FRONT_RIGHT
Definition: rematrix.c:68
FRONT_LEFT_OF_CENTER
#define FRONT_LEFT_OF_CENTER
Definition: rematrix.c:51
AV_CH_BACK_LEFT
#define AV_CH_BACK_LEFT
Definition: channel_layout.h:179
LOW_FREQUENCY_2
#define LOW_FREQUENCY_2
Definition: rematrix.c:63
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:218
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
even
static int even(int64_t layout)
Definition: rematrix.c:93
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AV_MATRIX_ENCODING_DOLBY
@ AV_MATRIX_ENCODING_DOLBY
Definition: channel_layout.h:262
TOP_FRONT_LEFT
#define TOP_FRONT_LEFT
Definition: rematrix.c:57
AV_CH_LOW_FREQUENCY
#define AV_CH_LOW_FREQUENCY
Definition: channel_layout.h:178
av_channel_layout_describe
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
Definition: channel_layout.c:654
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:119
AV_CH_LAYOUT_STEREO_DOWNMIX
#define AV_CH_LAYOUT_STEREO_DOWNMIX
Definition: channel_layout.h:255
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
swri_rematrix
int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy)
Definition: rematrix.c:774
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
AV_CH_TOP_SIDE_RIGHT
#define AV_CH_TOP_SIDE_RIGHT
Definition: channel_layout.h:201
auto_matrix
static av_cold int auto_matrix(SwrContext *s)
Definition: rematrix.c:628
SwrContext
The libswresample context.
Definition: swresample_internal.h:97
AudioData::ch
uint8_t * ch[SWR_CH_MAX]
samples buffer per channel
Definition: swresample_internal.h:48
FRONT_RIGHT
#define FRONT_RIGHT
Definition: rematrix.c:46
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
swr_build_matrix2
av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout, double center_mix_level, double surround_mix_level, double lfe_mix_level, double maxval, double rematrix_volume, double *matrix_param, ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
Generate a channel mixing matrix.
Definition: rematrix.c:546
AVMatrixEncoding
AVMatrixEncoding
Definition: channel_layout.h:260
fail
#define fail
Definition: test.h:479
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
AV_CH_TOP_CENTER
#define AV_CH_TOP_CENTER
Definition: channel_layout.h:186
NULL
#define NULL
Definition: coverity.c:32
build_matrix
static void build_matrix(const AVChannelLayout *in_ch_layout, const AVChannelLayout *out_ch_layout, double center_mix_level, double surround_mix_level, double lfe_mix_level, double maxval, double rematrix_volume, double *matrix_param, ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding)
Definition: rematrix.c:147
AV_CH_FRONT_CENTER
#define AV_CH_FRONT_CENTER
Definition: channel_layout.h:177
AV_CH_FRONT_LEFT_OF_CENTER
#define AV_CH_FRONT_LEFT_OF_CENTER
Definition: channel_layout.h:181
TOP_BACK_RIGHT
#define TOP_BACK_RIGHT
Definition: rematrix.c:62
AV_CH_BOTTOM_FRONT_CENTER
#define AV_CH_BOTTOM_FRONT_CENTER
Definition: channel_layout.h:202
AV_CHAN_FRONT_CENTER
@ AV_CHAN_FRONT_CENTER
Definition: channel_layout.h:52
AudioData::ch_count
int ch_count
number of channels
Definition: swresample_internal.h:50
TOP_BACK_CENTER
#define TOP_BACK_CENTER
Definition: rematrix.c:61
BACK_LEFT
#define BACK_LEFT
Definition: rematrix.c:49
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:319
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
BACK_RIGHT
#define BACK_RIGHT
Definition: rematrix.c:50
BOTTOM_FRONT_CENTER
#define BOTTOM_FRONT_CENTER
Definition: rematrix.c:66
SIDE_LEFT
#define SIDE_LEFT
Definition: rematrix.c:54
swri_rematrix_free
av_cold void swri_rematrix_free(SwrContext *s)
Definition: rematrix.c:769
swresample_internal.h
AV_CH_TOP_BACK_RIGHT
#define AV_CH_TOP_BACK_RIGHT
Definition: channel_layout.h:192
AV_CHANNEL_ORDER_NATIVE
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
Definition: channel_layout.h:125
AV_CH_FRONT_RIGHT_OF_CENTER
#define AV_CH_FRONT_RIGHT_OF_CENTER
Definition: channel_layout.h:182
FRONT_CENTER
#define FRONT_CENTER
Definition: rematrix.c:47
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:811
layout
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
Definition: filter_design.txt:18
FRONT_RIGHT_OF_CENTER
#define FRONT_RIGHT_OF_CENTER
Definition: rematrix.c:52
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:108
TOP_BACK_LEFT
#define TOP_BACK_LEFT
Definition: rematrix.c:60
av_channel_name
int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel_id)
Get a human readable string in an abbreviated form describing a given channel.
Definition: channel_layout.c:105
s
uint8_t s
Definition: llvidencdsp.c:39
AV_CH_BACK_CENTER
#define AV_CH_BACK_CENTER
Definition: channel_layout.h:183
AV_CH_FRONT_LEFT
#define AV_CH_FRONT_LEFT
Definition: channel_layout.h:175
AV_CH_SIDE_RIGHT
#define AV_CH_SIDE_RIGHT
Definition: channel_layout.h:185
len
int len
Definition: vorbis_enc_data.h:426
FRONT_LEFT
#define FRONT_LEFT
Definition: rematrix.c:45
swri_check_chlayout
int swri_check_chlayout(struct SwrContext *s, const AVChannelLayout *chl, const char *name)
Definition: swresample.c:33
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
ret
ret
Definition: filter_design.txt:187
AV_CH_LAYOUT_SURROUND
#define AV_CH_LAYOUT_SURROUND
Definition: channel_layout.h:221
av_channel_layout_check
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
Definition: channel_layout.c:785
TOP_CENTER
#define TOP_CENTER
Definition: rematrix.c:56
TOP_FRONT_CENTER
#define TOP_FRONT_CENTER
Definition: rematrix.c:58
M_SQRT1_2
#define M_SQRT1_2
Definition: mathematics.h:103
SWR_CH_MAX
#define SWR_CH_MAX
Definition: af_amerge.c:37
AV_CHANNEL_ORDER_CUSTOM
@ AV_CHANNEL_ORDER_CUSTOM
The channel order does not correspond to any other predefined order and is stored as an explicit map.
Definition: channel_layout.h:132
channel_layout.h
av_channel_layout_subset
uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout, uint64_t mask)
Find out what channels from a given set are present in a channel layout, without regard for their pos...
Definition: channel_layout.c:867
av_channel_layout_index_from_channel
int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, enum AVChannel channel)
Get the index of a given channel in a channel layout.
Definition: channel_layout.c:715
AV_CH_BOTTOM_FRONT_RIGHT
#define AV_CH_BOTTOM_FRONT_RIGHT
Definition: channel_layout.h:204
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:443
av_get_packed_sample_fmt
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
Definition: samplefmt.c:77
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:67
swri_rematrix_init
av_cold int swri_rematrix_init(SwrContext *s)
Definition: rematrix.c:647
AV_CH_FRONT_RIGHT
#define AV_CH_FRONT_RIGHT
Definition: channel_layout.h:176
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:450
mem.h
TOP_SIDE_LEFT
#define TOP_SIDE_LEFT
Definition: rematrix.c:64
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:394
LOW_FREQUENCY
#define LOW_FREQUENCY
Definition: rematrix.c:48
BACK_CENTER
#define BACK_CENTER
Definition: rematrix.c:53
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
SQRT2_3
#define SQRT2_3
Definition: swresample_internal.h:31
SQRT1_3
#define SQRT1_3
Definition: swresample_internal.h:30
SIDE_RIGHT
#define SIDE_RIGHT
Definition: rematrix.c:55
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:80
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AV_CH_BACK_RIGHT
#define AV_CH_BACK_RIGHT
Definition: channel_layout.h:180
stride
#define stride
Definition: h264pred_template.c:536
AVChannelLayout::u
union AVChannelLayout::@530 u
Details about which channels are present in this layout.
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60
AVChannelCustom::id
enum AVChannel id
Definition: channel_layout.h:284
AV_CH_SIDE_LEFT
#define AV_CH_SIDE_LEFT
Definition: channel_layout.h:184
AV_MATRIX_ENCODING_DPLII
@ AV_MATRIX_ENCODING_DPLII
Definition: channel_layout.h:263
clean_layout
static int clean_layout(AVChannelLayout *out, const AVChannelLayout *in, void *s)
Definition: rematrix.c:99