ccextractor: Add property to remove caption meta from the outgoing video buffers
authorSebastian Dröge <sebastian@centricular.com>
Wed, 24 Jun 2020 10:33:39 +0000 (13:33 +0300)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 25 Jun 2020 08:18:37 +0000 (08:18 +0000)
This is disabled by default to keep backwards compatibility.

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

docs/plugins/gst_plugins_cache.json
ext/closedcaption/gstccextractor.c
ext/closedcaption/gstccextractor.h

index c444385..976daa7 100644 (file)
                         "presence": "always"
                     }
                 },
+                "properties": {
+                    "remove-caption-meta": {
+                        "blurb": "Remove caption meta from outgoing video buffers",
+                        "conditionally-available": false,
+                        "construct": false,
+                        "construct-only": false,
+                        "controllable": false,
+                        "default": "false",
+                        "mutable": "null",
+                        "readable": true,
+                        "type": "gboolean",
+                        "writable": true
+                    }
+                },
                 "rank": "none",
                 "signals": {}
             },
index c214307..451fbe0 100644 (file)
@@ -44,6 +44,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_cc_extractor_debug);
 enum
 {
   PROP_0,
+  PROP_REMOVE_CAPTION_META,
 };
 
 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
@@ -75,8 +76,12 @@ static GstFlowReturn gst_cc_extractor_chain (GstPad * pad, GstObject * parent,
     GstBuffer * buf);
 static GstStateChangeReturn gst_cc_extractor_change_state (GstElement *
     element, GstStateChange transition);
-static void gst_cc_extractor_finalize (GObject * self);
 
+static void gst_cc_extractor_finalize (GObject * self);
+static void gst_cc_extractor_set_property (GObject * self, guint prop_id,
+    const GValue * value, GParamSpec * pspec);
+static void gst_cc_extractor_get_property (GObject * self, guint prop_id,
+    GValue * value, GParamSpec * pspec);
 
 static void
 gst_cc_extractor_class_init (GstCCExtractorClass * klass)
@@ -88,6 +93,22 @@ gst_cc_extractor_class_init (GstCCExtractorClass * klass)
   gstelement_class = (GstElementClass *) klass;
 
   gobject_class->finalize = gst_cc_extractor_finalize;
+  gobject_class->set_property = gst_cc_extractor_set_property;
+  gobject_class->get_property = gst_cc_extractor_get_property;
+
+  /**
+   * GstCCExtractor:remove-caption-meta
+   *
+   * Selects whether the #GstVideoCaptionMeta should be removed from the
+   * outgoing video buffers or whether it should be kept.
+   *
+   * Since: 1.18
+   */
+  g_object_class_install_property (G_OBJECT_CLASS (klass),
+      PROP_REMOVE_CAPTION_META, g_param_spec_boolean ("remove-caption-meta",
+          "Remove Caption Meta",
+          "Remove caption meta from outgoing video buffers", FALSE,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   gstelement_class->change_state =
       GST_DEBUG_FUNCPTR (gst_cc_extractor_change_state);
@@ -386,6 +407,15 @@ gst_cc_extractor_handle_meta (GstCCExtractor * filter, GstBuffer * buf,
       filter->captionpad, flow);
 }
 
+static gboolean
+remove_caption_meta (GstBuffer * buffer, GstMeta ** meta, gpointer user_data)
+{
+  if ((*meta)->info->api == GST_VIDEO_CAPTION_META_API_TYPE)
+    *meta = NULL;
+
+  return TRUE;
+}
+
 static GstFlowReturn
 gst_cc_extractor_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
 {
@@ -409,6 +439,11 @@ gst_cc_extractor_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
     return flow;
   }
 
+  if (filter->remove_caption_meta) {
+    buf = gst_buffer_make_writable (buf);
+    gst_buffer_foreach_meta (buf, remove_caption_meta, NULL);
+  }
+
   /* Push the buffer downstream and return the combined flow return */
   return gst_flow_combiner_update_pad_flow (filter->combiner, filter->srcpad,
       gst_pad_push (filter->srcpad, buf));
@@ -458,3 +493,35 @@ gst_cc_extractor_finalize (GObject * object)
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
+
+static void
+gst_cc_extractor_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstCCExtractor *filter = GST_CCEXTRACTOR (object);
+
+  switch (prop_id) {
+    case PROP_REMOVE_CAPTION_META:
+      filter->remove_caption_meta = g_value_get_boolean (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+gst_cc_extractor_get_property (GObject * object, guint prop_id, GValue * value,
+    GParamSpec * pspec)
+{
+  GstCCExtractor *filter = GST_CCEXTRACTOR (object);
+
+  switch (prop_id) {
+    case PROP_REMOVE_CAPTION_META:
+      g_value_set_boolean (value, filter->remove_caption_meta);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
index 4ff41db..7dcfb20 100644 (file)
@@ -50,6 +50,8 @@ struct _GstCCExtractor
   GstVideoInfo video_info;
 
   GstFlowCombiner *combiner;
+
+  gboolean remove_caption_meta;
 };
 
 struct _GstCCExtractorClass