summaryrefslogtreecommitdiffstats
path: root/meta-pipewire/recipes-multimedia/pipewire/pipewire/0005-pipewiresink-set-a-default-channel-map-if-the-number.patch
blob: 3b1b2a490aac74db05c54ac5c1e4b6603769673f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
From ee2e6412d37d012fbf8d25bd37271a5ee92b3ad4 Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Thu, 3 Feb 2022 15:08:57 +0200
Subject: [PATCH] pipewiresink: set a default channel map if the number of
 channels is fixed

This allows remaping streams using pipewiresink to match the channel layout
of the target device
Upstream-Status: Backport [from master/0.3.46]
---
 src/gst/gstpipewireformat.c | 42 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/gst/gstpipewireformat.c b/src/gst/gstpipewireformat.c
index dca90267c..c8ce7ba62 100644
--- a/src/gst/gstpipewireformat.c
+++ b/src/gst/gstpipewireformat.c
@@ -445,6 +445,44 @@ handle_video_fields (ConvertData *d)
   return TRUE;
 }
 
+static void
+set_default_channels (struct spa_pod_builder *b, uint32_t channels)
+{
+  uint32_t position[SPA_AUDIO_MAX_CHANNELS] = {0};
+  gboolean ok = TRUE;
+
+  switch (channels) {
+  case 8:
+    position[6] = SPA_AUDIO_CHANNEL_SL;
+    position[7] = SPA_AUDIO_CHANNEL_SR;
+    SPA_FALLTHROUGH
+  case 6:
+    position[5] = SPA_AUDIO_CHANNEL_LFE;
+    SPA_FALLTHROUGH
+  case 5:
+    position[4] = SPA_AUDIO_CHANNEL_FC;
+    SPA_FALLTHROUGH
+  case 4:
+    position[2] = SPA_AUDIO_CHANNEL_RL;
+    position[3] = SPA_AUDIO_CHANNEL_RR;
+    SPA_FALLTHROUGH
+  case 2:
+    position[0] = SPA_AUDIO_CHANNEL_FL;
+    position[1] = SPA_AUDIO_CHANNEL_FR;
+    break;
+  case 1:
+    position[0] = SPA_AUDIO_CHANNEL_MONO;
+    break;
+  default:
+    ok = FALSE;
+    break;
+  }
+
+  if (ok)
+    spa_pod_builder_add (b, SPA_FORMAT_AUDIO_position,
+        SPA_POD_Array(sizeof(uint32_t), SPA_TYPE_Id, channels, position), 0);
+}
+
 static gboolean
 handle_audio_fields (ConvertData *d)
 {
@@ -538,8 +576,10 @@ handle_audio_fields (ConvertData *d)
     }
     if (i > 0) {
       choice = spa_pod_builder_pop(&d->b, &f);
-      if (i == 1)
+      if (i == 1) {
         choice->body.type = SPA_CHOICE_None;
+        set_default_channels (&d->b, v);
+      }
     }
   }
   return TRUE;
-- 
2.34.1