 +  const gchar *test_string="";
 +  int i, num_buffers;
 +  unsigned char packet_type;
++  GstCaps *caps;
 +
 +  kateenc = setup_kateenc ();
 +  fail_unless (gst_element_set_state (kateenc,

+  GstClockTime start = GST_BUFFER_TIMESTAMP(buf);
+  GstClockTime duration = GST_BUFFER_DURATION(buf);
+  GstClockTime stop = GST_BUFFER_TIMESTAMP(buf)+duration;
+  int ret;
+
+  GST_LOG_OBJECT (ke, "got packet, %u bytes", GST_BUFFER_SIZE(buf));
+
+  /* first push headers if we haven't done that yet */
+  rflow = gst_kate_flush_headers (ke);
+
+  if (rflow == GST_FLOW_OK) {
+    kate_float t0 = start/(double)GST_SECOND;
+    kate_float t1 = stop/(double)GST_SECOND;
+    const char *text = (const char*) GST_BUFFER_DATA(buf);
+    size_t text_len = GST_BUFFER_SIZE(buf);
+    GST_LOG_OBJECT (ke, "Encoding text: %s (%u bytes) from %f to %f", GST_BUFFER_DATA(buf), GST_BUFFER_SIZE(buf), t0, t1);
+    ret = kate_encode_text(&ke->k, t0, t1, text, text_len, &kp);
+    if (ret < 0) {
+      GST_WARNING_OBJECT (ke, "Failed to encode buffer (%d)", ret);
+      rflow = GST_FLOW_ERROR;
+    }
+    else {
+      rflow = gst_kate_push_and_free_kate_packet (ke, &kp, start, duration, FALSE);
+    }
+  }
+
+  gst_buffer_unref (buf);
+
+  gst_object_unref (ke);
+
+  return rflow;
+}

+
+static GstFlowReturn gst_kate_push_buffer(GstKateEnc *ke, GstBuffer *buffer)
+{
+  GstFlowReturn rflow;
+
+  ke->last_timestamp = GST_BUFFER_TIMESTAMP(buffer);
+  if (GST_BUFFER_TIMESTAMP(buffer)+GST_BUFFER_DURATION(buffer) > ke->latest_end_time) {
+    ke->latest_end_time = GST_BUFFER_TIMESTAMP(buffer)+GST_BUFFER_DURATION(buffer);
+  }
+
+  /* Hack to flush each packet on its own page - taken off the CMML encoder element */
+  GST_BUFFER_DURATION (buffer) = G_MAXINT64;
+
+GST_DEBUG_OBJECT (ke, "Pushing buffer to pad");
+  rflow = gst_pad_push (ke->srcpad, buffer);
+  if (rflow != GST_FLOW_OK) {
+    GST_ERROR_OBJECT (ke, "Failed to push buffer: %d", rflow);
+  }
+
+  return rflow;
+}
+
