subparse, ogmparse: post tags with GST_TAG_SUBTITLE_CODEC
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Thu, 11 Jun 2009 21:32:28 +0000 (22:32 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Thu, 11 Jun 2009 21:32:28 +0000 (22:32 +0100)
Make subtitle parsers post a taglist with codec tags, so the application
knows what kind of subtitle a subtitle stream is. Fixes #576552.

ext/ogg/gstogmparse.c
gst/subparse/gstssaparse.c
gst/subparse/gstssaparse.h
gst/subparse/gstsubparse.c
gst/subparse/gstsubparse.h

index b52b466..630fd3e 100644 (file)
@@ -664,6 +664,15 @@ gst_ogm_parse_stream_header (GstOgmParse * ogm, const guint8 * data, guint size)
       gst_pad_push_event (ogm->srcpad, event);
     }
     g_list_free (cached_events);
+
+    {
+      GstTagList *tags;
+
+      tags = gst_tag_list_new ();
+      gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_SUBTITLE_CODEC,
+          "Ogm", NULL);
+      gst_element_found_tags_for_pad (GST_ELEMENT (ogm), ogm->srcpad, tags);
+    }
   }
 
   gst_caps_unref (caps);
index d720d1a..0d8010a 100644 (file)
@@ -107,6 +107,7 @@ gst_ssa_parse_init (GstSsaParse * parse, GstSsaParseClass * klass)
 
   parse->ini = NULL;
   parse->framed = FALSE;
+  parse->send_tags = FALSE;
 }
 
 static void
@@ -152,6 +153,7 @@ gst_ssa_parse_setcaps (GstPad * sinkpad, GstCaps * caps)
   }
 
   parse->framed = TRUE;
+  parse->send_tags = TRUE;
 
   priv = (GstBuffer *) gst_value_get_mini_object (val);
   g_return_val_if_fail (priv != NULL, FALSE);
@@ -304,6 +306,16 @@ gst_ssa_parse_chain (GstPad * sinkpad, GstBuffer * buf)
   if (G_UNLIKELY (!parse->framed))
     goto not_framed;
 
+  if (G_UNLIKELY (parse->send_tags)) {
+    GstTagList *tags;
+
+    tags = gst_tag_list_new ();
+    gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_SUBTITLE_CODEC,
+        "SubStation Alpha", NULL);
+    gst_element_found_tags_for_pad (GST_ELEMENT (parse), parse->srcpad, tags);
+    parse->send_tags = FALSE;
+  }
+
   /* make double-sure it's 0-terminated and all */
   txt = g_strndup ((gchar *) GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
 
index 60593b1..518c3cd 100644 (file)
@@ -40,6 +40,7 @@ struct _GstSsaParse {
   GstPad         *srcpad;
 
   gboolean        framed;
+  gboolean        send_tags;
 
   gchar          *ini;
 };
index 6aa312c..b75c165 100644 (file)
@@ -318,6 +318,31 @@ gst_sub_parse_get_property (GObject * object, guint prop_id,
 }
 
 static gchar *
+gst_sub_parse_get_format_description (GstSubParseFormat format)
+{
+  switch (format) {
+    case GST_SUB_PARSE_FORMAT_MDVDSUB:
+      return "MicroDVD";
+    case GST_SUB_PARSE_FORMAT_SUBRIP:
+      return "SubRip";
+    case GST_SUB_PARSE_FORMAT_MPSUB:
+      return "MPSub";
+    case GST_SUB_PARSE_FORMAT_SAMI:
+      return "SAMI";
+    case GST_SUB_PARSE_FORMAT_TMPLAYER:
+      return "TMPlayer";
+    case GST_SUB_PARSE_FORMAT_MPL2:
+      return "MPL2";
+    case GST_SUB_PARSE_FORMAT_SUBVIEWER:
+      return "SubViewer";
+    default:
+    case GST_SUB_PARSE_FORMAT_UNKNOWN:
+      break;
+  }
+  return NULL;
+}
+
+static gchar *
 gst_convert_to_utf8 (const gchar * str, gsize len, const gchar * encoding,
     gsize * consumed, GError ** err)
 {
@@ -1144,6 +1169,7 @@ gst_sub_parse_format_autodetect (GstSubParse * self)
   g_free (data);
 
   self->parser_type = format;
+  self->subtitle_codec = gst_sub_parse_get_format_description (format);
   parser_state_init (&self->state);
 
   switch (format) {
@@ -1254,6 +1280,16 @@ handle_buffer (GstSubParse * self, GstBuffer * buf)
       return GST_FLOW_UNEXPECTED;
     }
     gst_caps_unref (caps);
+
+    /* push tags */
+    if (self->subtitle_codec != NULL) {
+      GstTagList *tags;
+
+      tags = gst_tag_list_new ();
+      gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_SUBTITLE_CODEC,
+          self->subtitle_codec, NULL);
+      gst_element_found_tags_for_pad (GST_ELEMENT (self), self->srcpad, tags);
+    }
   }
 
   while (!self->flushing && (line = get_next_line (self))) {
index f40ccee..cd3765d 100644 (file)
@@ -81,6 +81,7 @@ struct _GstSubParse {
 
   GstSubParseFormat parser_type;
   gboolean parser_detected;
+  const gchar *subtitle_codec;
 
   Parser parse_line;
   ParserState state;