kate: fix up for additional subtitle/x-kate media type
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Sun, 19 Jul 2009 21:29:19 +0000 (22:29 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Sun, 19 Jul 2009 21:29:19 +0000 (22:29 +0100)
ext/kate/gstkate.h
ext/kate/gstkatedec.c
ext/kate/gstkateenc.c
ext/kate/gstkateparse.c
ext/kate/gstkatetiger.c
ext/kate/gstkateutil.c
tests/check/elements/kate.c

index fbccfea..f196881 100644 (file)
@@ -48,7 +48,7 @@
 
 G_BEGIN_DECLS
 
-#define GST_KATE_MEDIA_TYPE "subtitle/x-kate"
+/* nothing here any more */
 
 G_END_DECLS
 
index 8becb27..30ab8c1 100644 (file)
@@ -103,7 +103,7 @@ enum
 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
     GST_PAD_SINK,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (GST_KATE_MEDIA_TYPE)
+    GST_STATIC_CAPS ("subtitle/x-kate")
     );
 
 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
index 8e1b2ec..ccf0139 100644 (file)
@@ -133,7 +133,7 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_SRC,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (GST_KATE_MEDIA_TYPE)
+    GST_STATIC_CAPS ("subtitle/x-kate; application/x-kate")
     );
 
 static void gst_kate_enc_set_property (GObject * object, guint prop_id,
@@ -554,9 +554,13 @@ gst_kate_enc_send_headers (GstKateEnc * ke)
   }
 
   if (rflow == GST_FLOW_OK) {
-    caps =
-        gst_kate_util_set_header_on_caps (&ke->element,
-        gst_pad_get_caps (ke->srcpad), headers);
+    if (ke->category != NULL && strstr (ke->category, "subtitle")) {
+      caps = gst_kate_util_set_header_on_caps (&ke->element,
+          gst_caps_from_string ("subtitle/x-kate"), headers);
+    } else {
+      caps = gst_kate_util_set_header_on_caps (&ke->element,
+          gst_caps_from_string ("application/x-kate"), headers);
+    }
     if (caps) {
       GST_DEBUG_OBJECT (ke, "here are the caps: %" GST_PTR_FORMAT, caps);
       gst_pad_set_caps (ke->srcpad, caps);
index b44eea9..5cf8ec4 100644 (file)
@@ -76,17 +76,17 @@ GST_ELEMENT_DETAILS ("Kate stream parser",
     "Vincent Penquerc'h <ogg.k.ogg.k at googlemail dot com>");
 
 static GstStaticPadTemplate gst_kate_parse_sink_factory =
-GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_STATIC_PAD_TEMPLATE ("sink",
     GST_PAD_SINK,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (GST_KATE_MEDIA_TYPE)
+    GST_STATIC_CAPS ("subtitle/x-kate; application/x-kate")
     );
 
 static GstStaticPadTemplate gst_kate_parse_src_factory =
-GST_STATIC_PAD_TEMPLATE ("src",
+    GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_SRC,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (GST_KATE_MEDIA_TYPE)
+    GST_STATIC_CAPS ("subtitle/x-kate; application/x-kate")
     );
 
 GST_BOILERPLATE (GstKateParse, gst_kate_parse, GstElement, GST_TYPE_ELEMENT);
@@ -169,7 +169,8 @@ gst_kate_parse_push_headers (GstKateParse * parse)
   /* get the headers into the caps, passing them to kate as we go */
   caps =
       gst_kate_util_set_header_on_caps (&parse->element,
-      gst_pad_get_caps (parse->srcpad), parse->streamheader);
+      gst_pad_get_negotiated_caps (parse->sinkpad), parse->streamheader);
+
   if (G_UNLIKELY (!caps)) {
     GST_ERROR_OBJECT (parse, "Failed to set headers on caps");
     return GST_FLOW_ERROR;
@@ -389,6 +390,9 @@ gst_kate_parse_chain (GstPad * pad, GstBuffer * buffer)
 
   g_assert (klass->parse_packet != NULL);
 
+  if (G_UNLIKELY (GST_PAD_CAPS (pad) == NULL))
+    return GST_FLOW_NOT_NEGOTIATED;
+
   return klass->parse_packet (parse, buffer);
 }
 
index 20df048..433a310 100644 (file)
@@ -108,14 +108,14 @@ enum
   ARG_DEFAULT_BACKGROUND_RED,
   ARG_DEFAULT_BACKGROUND_GREEN,
   ARG_DEFAULT_BACKGROUND_BLUE,
-  ARG_DEFAULT_BACKGROUND_ALPHA,
+  ARG_DEFAULT_BACKGROUND_ALPHA
 };
 
 static GstStaticPadTemplate kate_sink_factory =
-GST_STATIC_PAD_TEMPLATE ("kate_sink",
+    GST_STATIC_PAD_TEMPLATE ("kate_sink",
     GST_PAD_SINK,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (GST_KATE_MEDIA_TYPE)
+    GST_STATIC_CAPS ("subtitle/x-kate; application/x-kate")
     );
 
 static GstStaticPadTemplate video_sink_factory =
@@ -294,10 +294,8 @@ gst_kate_tiger_init (GstKateTiger * tiger, GstKateTigerClass * gclass)
       GST_DEBUG_FUNCPTR (gst_kate_tiger_kate_chain));
   gst_pad_set_query_function (tiger->katesinkpad,
       GST_DEBUG_FUNCPTR (gst_kate_tiger_kate_sink_query));
-  gst_pad_use_fixed_caps (tiger->katesinkpad);
-  gst_pad_set_caps (tiger->katesinkpad,
-      gst_static_pad_template_get_caps (&kate_sink_factory));
-  gst_pad_set_event_function (tiger->katesinkpad, gst_kate_tiger_kate_event);
+  gst_pad_set_event_function (tiger->katesinkpad,
+      GST_DEBUG_FUNCPTR (gst_kate_tiger_kate_event));
   gst_element_add_pad (GST_ELEMENT (tiger), tiger->katesinkpad);
 
   tiger->videosinkpad =
index 2928771..f47ba57 100644 (file)
@@ -33,6 +33,8 @@ gst_kate_util_set_header_on_caps (GstElement * element, GstCaps * caps,
   GstStructure *structure;
   GValue array = { 0 };
 
+  GST_LOG_OBJECT (element, "caps: %" GST_PTR_FORMAT, caps);
+
   if (G_UNLIKELY (!caps))
     return NULL;
   if (G_UNLIKELY (!headers))
index f7ac3ed..80ea688 100644 (file)
@@ -40,20 +40,25 @@ static const guint8 kate_header_0x81[53] = {
   0x72, 0x29, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x54, 0x49, 0x54, 0x4c, 0x45, 0x3d,       /* r)........TITLE= */
   0x54, 0x69, 0x67, 0x65, 0x72, /* Tiger            */
 };
+
 static const guint8 kate_header_0x8x[10] = {
   0x80, 0x6b, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00
 };
+
 static const guint8 kate_header_0x88[11] = {
   0x88, 0x6b, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00
 };
+
 static const guint8 kate_header_0x00[45] = {
   0x00, 0xe8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,       /* ................ */
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x70, 0x6c, 0x61,       /* .............pla */
   0x69, 0x6e, 0x20, 0x6f, 0x6c, 0x64, 0x20, 0x74, 0x65, 0x78, 0x74, 0x08, 0x00  /* in old text..    */
 };
+
 static const guint8 kate_header_0x01[1] = {
   0x01
 };
+
 static const guint8 kate_header_0x7f[1] = {
   0x7f
 };
@@ -600,16 +605,21 @@ static void
 test_kate_send_headers (GstPad * pad)
 {
   GstBuffer *inbuffer;
+  GstCaps *caps;
   int i;
 
+  caps = gst_caps_new_simple ("subtitle/x-kate", NULL);
+
   /* push headers */
   inbuffer = gst_buffer_new ();
+  gst_buffer_set_caps (inbuffer, caps);
   GST_BUFFER_DATA (inbuffer) = (guint8 *) kate_header_0x80;
   GST_BUFFER_SIZE (inbuffer) = sizeof (kate_header_0x80);
   GST_BUFFER_OFFSET (inbuffer) = GST_BUFFER_OFFSET_END (inbuffer) = 0;
   fail_unless_equals_int (gst_pad_push (pad, inbuffer), GST_FLOW_OK);
 
   inbuffer = gst_buffer_new ();
+  gst_buffer_set_caps (inbuffer, caps);
   GST_BUFFER_DATA (inbuffer) = (guint8 *) kate_header_0x81;
   GST_BUFFER_SIZE (inbuffer) = sizeof (kate_header_0x81);
   GST_BUFFER_OFFSET (inbuffer) = GST_BUFFER_OFFSET_END (inbuffer) = 0;
@@ -617,6 +627,7 @@ test_kate_send_headers (GstPad * pad)
 
   for (i = 2; i < 8; ++i) {
     inbuffer = gst_buffer_new_and_alloc (sizeof (kate_header_0x8x));
+    gst_buffer_set_caps (inbuffer, caps);
     memcpy (GST_BUFFER_DATA (inbuffer), (guint8 *) kate_header_0x8x,
         sizeof (kate_header_0x8x));
     GST_BUFFER_DATA (inbuffer)[0] = 0x80 | i;
@@ -625,10 +636,13 @@ test_kate_send_headers (GstPad * pad)
   }
 
   inbuffer = gst_buffer_new ();
+  gst_buffer_set_caps (inbuffer, caps);
   GST_BUFFER_DATA (inbuffer) = (guint8 *) kate_header_0x88;
   GST_BUFFER_SIZE (inbuffer) = sizeof (kate_header_0x88);
   GST_BUFFER_OFFSET (inbuffer) = GST_BUFFER_OFFSET_END (inbuffer) = 0;
   fail_unless_equals_int (gst_pad_push (pad, inbuffer), GST_FLOW_OK);
+
+  gst_caps_unref (caps);
 }
 
 GST_START_TEST (test_kate_parse)