From ee2e6412d37d012fbf8d25bd37271a5ee92b3ad4 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis 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