pipewiresink: set a default channel map if the number of channels is fixed
[AGL/meta-agl.git] / meta-pipewire / recipes-multimedia / pipewire / pipewire / 0005-pipewiresink-set-a-default-channel-map-if-the-number.patch
1 From ee2e6412d37d012fbf8d25bd37271a5ee92b3ad4 Mon Sep 17 00:00:00 2001
2 From: George Kiagiadakis <george.kiagiadakis@collabora.com>
3 Date: Thu, 3 Feb 2022 15:08:57 +0200
4 Subject: [PATCH] pipewiresink: set a default channel map if the number of
5  channels is fixed
6
7 This allows remaping streams using pipewiresink to match the channel layout
8 of the target device
9 Upstream-Status: Backport [from master/0.3.46]
10 ---
11  src/gst/gstpipewireformat.c | 42 ++++++++++++++++++++++++++++++++++++-
12  1 file changed, 41 insertions(+), 1 deletion(-)
13
14 diff --git a/src/gst/gstpipewireformat.c b/src/gst/gstpipewireformat.c
15 index dca90267c..c8ce7ba62 100644
16 --- a/src/gst/gstpipewireformat.c
17 +++ b/src/gst/gstpipewireformat.c
18 @@ -445,6 +445,44 @@ handle_video_fields (ConvertData *d)
19    return TRUE;
20  }
21  
22 +static void
23 +set_default_channels (struct spa_pod_builder *b, uint32_t channels)
24 +{
25 +  uint32_t position[SPA_AUDIO_MAX_CHANNELS] = {0};
26 +  gboolean ok = TRUE;
27 +
28 +  switch (channels) {
29 +  case 8:
30 +    position[6] = SPA_AUDIO_CHANNEL_SL;
31 +    position[7] = SPA_AUDIO_CHANNEL_SR;
32 +    SPA_FALLTHROUGH
33 +  case 6:
34 +    position[5] = SPA_AUDIO_CHANNEL_LFE;
35 +    SPA_FALLTHROUGH
36 +  case 5:
37 +    position[4] = SPA_AUDIO_CHANNEL_FC;
38 +    SPA_FALLTHROUGH
39 +  case 4:
40 +    position[2] = SPA_AUDIO_CHANNEL_RL;
41 +    position[3] = SPA_AUDIO_CHANNEL_RR;
42 +    SPA_FALLTHROUGH
43 +  case 2:
44 +    position[0] = SPA_AUDIO_CHANNEL_FL;
45 +    position[1] = SPA_AUDIO_CHANNEL_FR;
46 +    break;
47 +  case 1:
48 +    position[0] = SPA_AUDIO_CHANNEL_MONO;
49 +    break;
50 +  default:
51 +    ok = FALSE;
52 +    break;
53 +  }
54 +
55 +  if (ok)
56 +    spa_pod_builder_add (b, SPA_FORMAT_AUDIO_position,
57 +        SPA_POD_Array(sizeof(uint32_t), SPA_TYPE_Id, channels, position), 0);
58 +}
59 +
60  static gboolean
61  handle_audio_fields (ConvertData *d)
62  {
63 @@ -538,8 +576,10 @@ handle_audio_fields (ConvertData *d)
64      }
65      if (i > 0) {
66        choice = spa_pod_builder_pop(&d->b, &f);
67 -      if (i == 1)
68 +      if (i == 1) {
69          choice->body.type = SPA_CHOICE_None;
70 +        set_default_channels (&d->b, v);
71 +      }
72      }
73    }
74    return TRUE;
75 -- 
76 2.34.1
77