line21enc: add remove-caption-meta property
authorMathieu Duponchelle <mathieu@centricular.com>
Fri, 4 Sep 2020 14:53:03 +0000 (16:53 +0200)
committerMathieu Duponchelle <mathieu@centricular.com>
Wed, 9 Sep 2020 20:11:28 +0000 (22:11 +0200)
Similar to #GstCCExtractor:remove-caption-meta

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

docs/plugins/gst_plugins_cache.json
ext/closedcaption/gstline21enc.c
ext/closedcaption/gstline21enc.h
tests/check/elements/line21.c

index e69a334..f2ca4f6 100644 (file)
                         "presence": "always"
                     }
                 },
-                "properties": {},
+                "properties": {
+                    "remove-caption-meta": {
+                        "blurb": "Remove encoded 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"
             }
         },
index 6c9d13c..6902bc0 100644 (file)
 GST_DEBUG_CATEGORY_STATIC (gst_line_21_encoder_debug);
 #define GST_CAT_DEFAULT gst_line_21_encoder_debug
 
+enum
+{
+  PROP_0,
+  PROP_REMOVE_CAPTION_META,
+};
+
 /* FIXME: add and test support for PAL resolutions */
 #define CAPS "video/x-raw, format={ I420, YUY2, YVYU, UYVY, VYUY }, width=(int)720, height=(int){ 525, 486 }, interlace-mode=interleaved"
 
@@ -60,16 +66,41 @@ static gboolean gst_line_21_encoder_set_info (GstVideoFilter * filter,
     GstCaps * outcaps, GstVideoInfo * out_info);
 static GstFlowReturn gst_line_21_encoder_transform_ip (GstVideoFilter * filter,
     GstVideoFrame * frame);
+static void gst_line_21_encoder_set_property (GObject * self, guint prop_id,
+    const GValue * value, GParamSpec * pspec);
+static void gst_line_21_encoder_get_property (GObject * self, guint prop_id,
+    GValue * value, GParamSpec * pspec);
+
 
 static void
 gst_line_21_encoder_class_init (GstLine21EncoderClass * klass)
 {
+  GObjectClass *gobject_class;
   GstElementClass *gstelement_class;
   GstVideoFilterClass *filter_class;
 
+  gobject_class = (GObjectClass *) klass;
   gstelement_class = (GstElementClass *) klass;
   filter_class = (GstVideoFilterClass *) klass;
 
+  gobject_class->set_property = gst_line_21_encoder_set_property;
+  gobject_class->get_property = gst_line_21_encoder_get_property;
+
+  /**
+   * line21encoder:remove-caption-meta
+   *
+   * Selects whether the encoded #GstVideoCaptionMeta should be removed from
+   * the outgoing video buffers or whether it should be kept.
+   *
+   * Since: 1.20
+   */
+  g_object_class_install_property (G_OBJECT_CLASS (klass),
+      PROP_REMOVE_CAPTION_META, g_param_spec_boolean ("remove-caption-meta",
+          "Remove Caption Meta",
+          "Remove encoded caption meta from outgoing video buffers", FALSE,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+
   gst_element_class_set_static_metadata (gstelement_class,
       "Line 21 CC Encoder",
       "Filter/Video/ClosedCaption",
@@ -92,6 +123,38 @@ gst_line_21_encoder_init (GstLine21Encoder * filter)
 {
 }
 
+static void
+gst_line_21_encoder_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstLine21Encoder *enc = GST_LINE21ENCODER (object);
+
+  switch (prop_id) {
+    case PROP_REMOVE_CAPTION_META:
+      enc->remove_caption_meta = g_value_get_boolean (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+gst_line_21_encoder_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstLine21Encoder *enc = GST_LINE21ENCODER (object);
+
+  switch (prop_id) {
+    case PROP_REMOVE_CAPTION_META:
+      g_value_set_boolean (value, enc->remove_caption_meta);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
 static vbi_pixfmt
 vbi_pixfmt_from_gst_video_format (GstVideoFormat format)
 {
@@ -445,8 +508,8 @@ gst_line_21_encoder_transform_ip (GstVideoFilter * filter,
     }
   }
 
-  /* We've encoded this meta, it can now be removed */
-  if (cc_meta)
+  /* We've encoded this meta, it can now be removed if required */
+  if (cc_meta && self->remove_caption_meta)
     gst_buffer_remove_meta (frame->buffer, (GstMeta *) cc_meta);
 
   /* When dealing with standard NTSC resolution, field 1 goes at line 21,
index ac89f2c..325a61f 100644 (file)
@@ -48,6 +48,8 @@ struct _GstLine21Encoder
   vbi_sampling_par sp;
 
   GstVideoInfo info;
+
+  gboolean remove_caption_meta;
 };
 
 struct _GstLine21EncoderClass
index 2a507fa..fa9427b 100644 (file)
@@ -42,7 +42,8 @@ GST_START_TEST (basic)
       "interlace-mode", G_TYPE_STRING, "interleaved",
       NULL);
 
-  h = gst_harness_new_parse ("line21encoder ! line21decoder");
+  h = gst_harness_new_parse
+      ("line21encoder remove-caption-meta=true ! line21decoder");
   gst_harness_set_caps (h, gst_caps_ref (caps), gst_caps_ref (caps));
 
   gst_video_info_from_caps (&info, caps);