decklink: Implement GstBaseSrc::get_caps() to return more constrained caps
authorSebastian Dröge <sebastian@centricular.com>
Thu, 10 Dec 2020 10:35:07 +0000 (12:35 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 16 Dec 2020 12:13:40 +0000 (14:13 +0200)
Instead of the template caps we can return a subset of them based on the
selected properties.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1868>

sys/decklink/gstdecklinkaudiosrc.cpp
sys/decklink/gstdecklinkvideosrc.cpp

index 4ec47a8..5824f90 100644 (file)
@@ -125,6 +125,8 @@ gst_decklink_audio_src_change_state (GstElement * element,
 
 static gboolean gst_decklink_audio_src_unlock (GstBaseSrc * bsrc);
 static gboolean gst_decklink_audio_src_unlock_stop (GstBaseSrc * bsrc);
+static GstCaps *gst_decklink_audio_src_get_caps (GstBaseSrc * bsrc,
+    GstCaps * filter);
 static gboolean gst_decklink_audio_src_query (GstBaseSrc * bsrc,
     GstQuery * query);
 
@@ -156,6 +158,7 @@ gst_decklink_audio_src_class_init (GstDecklinkAudioSrcClass * klass)
 
   basesrc_class->query = GST_DEBUG_FUNCPTR (gst_decklink_audio_src_query);
   basesrc_class->negotiate = NULL;
+  basesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_decklink_audio_src_get_caps);
   basesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_decklink_audio_src_unlock);
   basesrc_class->unlock_stop =
       GST_DEBUG_FUNCPTR (gst_decklink_audio_src_unlock_stop);
@@ -797,6 +800,42 @@ retry:
   return flow_ret;
 }
 
+static GstCaps *
+gst_decklink_audio_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
+{
+  GstDecklinkAudioSrc *self = GST_DECKLINK_AUDIO_SRC_CAST (bsrc);
+  GstCaps *caps, *template_caps;
+  const GstStructure *s;
+  gint channels;
+
+  channels = self->channels;
+  if (channels == 0)
+    channels = self->channels_found;
+
+  template_caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (bsrc));
+  if (channels == 0) {
+    caps = template_caps;
+  } else {
+    if (channels > 2)
+      s = gst_caps_get_structure (template_caps, 1);
+    else
+      s = gst_caps_get_structure (template_caps, 0);
+
+    caps = gst_caps_new_full (gst_structure_copy (s), NULL);
+    gst_caps_set_simple (caps, "channels", G_TYPE_INT, channels, NULL);
+    gst_caps_unref (template_caps);
+  }
+
+  if (filter) {
+    GstCaps *tmp =
+        gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
+    gst_caps_unref (caps);
+    caps = tmp;
+  }
+
+  return caps;
+}
+
 static gboolean
 gst_decklink_audio_src_query (GstBaseSrc * bsrc, GstQuery * query)
 {
index 4edeffd..40dc31d 100644 (file)
@@ -223,6 +223,8 @@ static GstStateChangeReturn
 gst_decklink_video_src_change_state (GstElement * element,
     GstStateChange transition);
 
+static GstCaps *gst_decklink_video_src_get_caps (GstBaseSrc * bsrc,
+    GstCaps * filter);
 static gboolean gst_decklink_video_src_query (GstBaseSrc * bsrc,
     GstQuery * query);
 static gboolean gst_decklink_video_src_unlock (GstBaseSrc * bsrc);
@@ -259,6 +261,7 @@ gst_decklink_video_src_class_init (GstDecklinkVideoSrcClass * klass)
 
   basesrc_class->query = GST_DEBUG_FUNCPTR (gst_decklink_video_src_query);
   basesrc_class->negotiate = NULL;
+  basesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_decklink_video_src_get_caps);
   basesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_decklink_video_src_unlock);
   basesrc_class->unlock_stop =
       GST_DEBUG_FUNCPTR (gst_decklink_video_src_unlock_stop);
@@ -1374,6 +1377,31 @@ retry:
   return flow_ret;
 }
 
+static GstCaps *
+gst_decklink_video_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
+{
+  GstDecklinkVideoSrc *self = GST_DECKLINK_VIDEO_SRC_CAST (bsrc);
+  GstCaps *caps;
+
+  if (self->mode != GST_DECKLINK_MODE_AUTO) {
+    caps = gst_decklink_mode_get_caps (self->mode, self->caps_format, TRUE);
+  } else if (self->caps_mode != GST_DECKLINK_MODE_AUTO) {
+    caps =
+        gst_decklink_mode_get_caps (self->caps_mode, self->caps_format, TRUE);
+  } else {
+    caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (bsrc));
+  }
+
+  if (filter) {
+    GstCaps *tmp =
+        gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
+    gst_caps_unref (caps);
+    caps = tmp;
+  }
+
+  return caps;
+}
+
 static gboolean
 gst_decklink_video_src_query (GstBaseSrc * bsrc, GstQuery * query)
 {