diff mbox series

[FFmpeg-devel,3/6] swresample/rematrix: support mixing top front left/right channels

Message ID 20221031211832.8213-1-jamrial@gmail.com
State Accepted
Commit c79b16306f6c612cb5ef970b2745564082bb8d16
Headers show
Series [FFmpeg-devel,1/6,v3] avcodec/aacdec: fix parsing streams with channel configuration 11 | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

James Almer Oct. 31, 2022, 9:18 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libswresample/rematrix.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
index fe823dc575..0c3fff6c42 100644
--- a/libswresample/rematrix.c
+++ b/libswresample/rematrix.c
@@ -138,6 +138,8 @@  static int sane_layout(AVChannelLayout *ch_layout) {
         return 0;
     if(!even(av_channel_layout_subset(ch_layout, (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER))))
         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;
 
@@ -369,6 +371,28 @@  av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelL
         }else
             av_assert0(0);
     }
+
+    if (unaccounted & AV_CH_TOP_FRONT_LEFT) {
+        if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0) {
+            matrix[TOP_FRONT_CENTER][TOP_FRONT_LEFT ] += M_SQRT1_2;
+            matrix[TOP_FRONT_CENTER][TOP_FRONT_RIGHT] += M_SQRT1_2;
+            if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0)
+                matrix[TOP_FRONT_CENTER][TOP_FRONT_CENTER] = center_mix_level * sqrt(2);
+        } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
+            if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
+                matrix[FRONT_LEFT ][TOP_FRONT_LEFT ] += M_SQRT1_2;
+                matrix[FRONT_RIGHT][TOP_FRONT_RIGHT] += M_SQRT1_2;
+            } else {
+                matrix[FRONT_LEFT ][TOP_FRONT_LEFT ] += 1.0;
+                matrix[FRONT_RIGHT][TOP_FRONT_RIGHT] += 1.0;
+            }
+        } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
+            matrix[FRONT_CENTER][TOP_FRONT_LEFT ] += M_SQRT1_2;
+            matrix[FRONT_CENTER][TOP_FRONT_RIGHT] += M_SQRT1_2;
+        } else
+            av_assert0(0);
+    }
+
     /* mix LFE into front left/right or center */
     if (unaccounted & AV_CH_LOW_FREQUENCY) {
         if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {