git » pipewire.git » main » tree

[main] / 0004-gst-Re-enable-handling-of-single-long-modifiers.patch

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Robert Mader <robert.mader@collabora.com>
Date: Thu, 28 Mar 2024 14:01:20 +0100
Subject: [PATCH] gst: Re-enable handling of single long modifiers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

A peer may announce support for a single modifier, in which case it may
not use a choice-pod. And while the documentation in `dma-buf.dox`
requires modifiers to always be announced as `SPA_CHOICE_Enum`, this has
been supported in the past - as well as matching Pipewire conventions.

Thus, in order to not break existing clients not crash, reintroduce
handling of modifiers as a single long.

Fixes: f1b75fc6f (gst: Add support for DMA_DRM / explicit modifiers)

Solution suggested by Barnabás Pőcze <pobrn@protonmail.com>
---
 src/gst/gstpipewireformat.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/gst/gstpipewireformat.c b/src/gst/gstpipewireformat.c
index a0f64747697c..e4159835da76 100644
--- a/src/gst/gstpipewireformat.c
+++ b/src/gst/gstpipewireformat.c
@@ -877,25 +877,35 @@ handle_dmabuf_prop (const struct spa_pod_prop *prop,
   const struct spa_pod *pod_modifier;
   struct spa_pod *val;
   uint32_t *id, n_fmts, n_mods, choice, i, j;
-  uint64_t *mods;
-
+  uint64_t *mods, single_modifier;
 
   val = spa_pod_get_values (&prop->value, &n_fmts, &choice);
   if (val->type != SPA_TYPE_Id)
     return;
 
   id = SPA_POD_BODY (val);
   if (n_fmts > 1) {
     n_fmts--;
     id++;
   }
 
   pod_modifier = &prop_modifier->value;
-  mods = SPA_POD_CHOICE_VALUES (pod_modifier);
-  n_mods = SPA_POD_CHOICE_N_VALUES (pod_modifier);
-  if (n_mods > 1) {
-    n_mods--;
-    mods++;
+  if (spa_pod_is_long (pod_modifier) &&
+      spa_pod_get_long (pod_modifier, (int64_t *) &single_modifier)) {
+    mods = &single_modifier;
+    n_mods = 1;
+  } else if (spa_pod_is_choice (pod_modifier) &&
+             SPA_POD_CHOICE_TYPE (pod_modifier) == SPA_CHOICE_Enum &&
+             SPA_POD_CHOICE_VALUE_TYPE (pod_modifier) == SPA_TYPE_Long) {
+    mods = SPA_POD_CHOICE_VALUES (pod_modifier);
+    n_mods = SPA_POD_CHOICE_N_VALUES (pod_modifier);
+
+    if (n_mods > 1) {
+      n_mods--;
+      mods++;
+    }
+  } else {
+    return;
   }
 
   fmt_array = g_ptr_array_new_with_free_func (g_free);