check: Update gst_check_element_push_buffer to 0.11 style caps
authorOlivier Crête <olivier.crete@collabora.com>
Sat, 28 Jan 2012 07:38:03 +0000 (08:38 +0100)
committerOlivier Crête <olivier.crete@collabora.com>
Sat, 28 Jan 2012 16:42:38 +0000 (16:42 +0000)
Pass the desired caps explicitely

libs/gst/check/gstcheck.c
libs/gst/check/gstcheck.h

index e8292cb..745b68c 100644 (file)
@@ -375,11 +375,32 @@ gst_check_buffer_data (GstBuffer * buffer, gconstpointer data, gsize size)
   gst_buffer_unmap (buffer, &info);
 }
 
+static gboolean
+buffer_event_function (GstPad * pad, GstObject * noparent, GstEvent * event)
+{
+  if (GST_EVENT_TYPE (event) == GST_EVENT_CAPS) {
+    GstCaps *event_caps, *current_caps;
+
+    current_caps = gst_pad_get_current_caps (pad);
+    gst_event_parse_caps (event, &event_caps);
+    fail_unless (gst_caps_is_fixed (current_caps));
+    fail_unless (gst_caps_is_fixed (event_caps));
+    fail_unless (gst_caps_is_equal_fixed (event_caps, current_caps));
+    gst_caps_unref (current_caps);
+    gst_event_unref (event);
+    return TRUE;
+  }
+
+  return gst_pad_event_default (pad, noparent, event);
+}
+
 /**
  * gst_check_element_push_buffer_list:
  * @element_name: name of the element that needs to be created
- * @buffer_in: a list of buffers that needs to be puched to the element
- * @buffer_out: a list of buffers that we expect from the element
+ * @buffer_in: (element-type GstBuffer) (transfer full): a list of buffers that needs to be
+ *  puched to the element
+ * @buffer_out: (element-type GstBuffer) (transfer full): a list of buffers that we expect from
+ * the element
  * @last_flow_return: the last buffer push needs to give this GstFlowReturn
  *
  * Create an @element with the factory with the name and push the buffers in
@@ -396,12 +417,9 @@ gst_check_buffer_data (GstBuffer * buffer, gconstpointer data, gsize size)
 /* FIXME 0.11: rename this function now that there's GstBufferList? */
 void
 gst_check_element_push_buffer_list (const gchar * element_name,
-    GList * buffer_in, GList * buffer_out, GstFlowReturn last_flow_return)
+    GList * buffer_in, GstCaps * caps_in, GList * buffer_out,
+    GstCaps * caps_out, GstFlowReturn last_flow_return)
 {
-#if 0
-  GstCaps *sink_caps;
-  GstCaps *src_caps = NULL;
-#endif
   GstElement *element;
   GstPad *pad_peer;
   GstPad *sink_pad = NULL;
@@ -418,52 +436,50 @@ gst_check_element_push_buffer_list (const gchar * element_name,
   buffer = GST_BUFFER (buffer_in->data);
 
   fail_unless (GST_IS_BUFFER (buffer), "There should be a buffer in buffer_in");
-#if 0
-  src_caps = GST_BUFFER_CAPS (buffer);
-#endif
-  src_pad = gst_pad_new (NULL, GST_PAD_SRC);
-#if 0
-  gst_pad_set_caps (src_pad, src_caps);
-#endif
+  src_pad = gst_pad_new ("src", GST_PAD_SRC);
+  if (caps_in) {
+    fail_unless (gst_caps_is_fixed (caps_in));
+    gst_pad_use_fixed_caps (src_pad);
+  }
+  /* activate the pad */
+  gst_pad_set_active (src_pad, TRUE);
+  GST_DEBUG ("src pad activated");
+  if (caps_in)
+    fail_unless (gst_pad_set_caps (src_pad, caps_in));
   pad_peer = gst_element_get_static_pad (element, "sink");
   fail_if (pad_peer == NULL);
   fail_unless (gst_pad_link (src_pad, pad_peer) == GST_PAD_LINK_OK,
       "Could not link source and %s sink pads", GST_ELEMENT_NAME (element));
   gst_object_unref (pad_peer);
-  /* activate the pad */
-  gst_pad_set_active (src_pad, TRUE);
-  GST_DEBUG ("src pad activated");
   /* don't create the sink_pad if there is no buffer_out list */
   if (buffer_out != NULL) {
-#if 0
-    gchar *temp;
-#endif
 
     GST_DEBUG ("buffer out detected, creating the sink pad");
     /* get the sink caps */
-#if 0
-    sink_caps = GST_BUFFER_CAPS (GST_BUFFER (buffer_out->data));
-    fail_unless (GST_IS_CAPS (sink_caps), "buffer out don't have caps");
-    temp = gst_caps_to_string (sink_caps);
+    if (caps_out) {
+      gchar *temp;
+
+      fail_unless (gst_caps_is_fixed (caps_out));
+      temp = gst_caps_to_string (caps_out);
+
+      GST_DEBUG ("sink caps requested by buffer out: '%s'", temp);
+      g_free (temp);
+    }
 
-    GST_DEBUG ("sink caps requested by buffer out: '%s'", temp);
-    g_free (temp);
-    fail_unless (gst_caps_is_fixed (sink_caps), "we need fixed caps");
-#endif
     /* get the sink pad */
-    sink_pad = gst_pad_new (NULL, GST_PAD_SINK);
+    sink_pad = gst_pad_new ("sink", GST_PAD_SINK);
     fail_unless (GST_IS_PAD (sink_pad));
-#if 0
-    gst_pad_set_caps (sink_pad, sink_caps);
-#endif
+    /* configure the sink pad */
+    gst_pad_set_chain_function (sink_pad, gst_check_chain_func);
+    gst_pad_set_active (sink_pad, TRUE);
+    gst_pad_set_caps (sink_pad, caps_out);
+    if (caps_out)
+      gst_pad_set_event_function (sink_pad, buffer_event_function);
     /* get the peer pad */
     pad_peer = gst_element_get_static_pad (element, "src");
     fail_unless (gst_pad_link (pad_peer, sink_pad) == GST_PAD_LINK_OK,
         "Could not link sink and %s source pads", GST_ELEMENT_NAME (element));
     gst_object_unref (pad_peer);
-    /* configure the sink pad */
-    gst_pad_set_chain_function (sink_pad, gst_check_chain_func);
-    gst_pad_set_active (sink_pad, TRUE);
   }
   fail_unless (gst_element_set_state (element,
           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
@@ -543,7 +559,8 @@ gst_check_element_push_buffer_list (const gchar * element_name,
  */
 void
 gst_check_element_push_buffer (const gchar * element_name,
-    GstBuffer * buffer_in, GstBuffer * buffer_out)
+    GstBuffer * buffer_in, GstCaps * caps_in, GstBuffer * buffer_out,
+    GstCaps * caps_out)
 {
   GList *in = NULL;
   GList *out = NULL;
@@ -551,7 +568,8 @@ gst_check_element_push_buffer (const gchar * element_name,
   in = g_list_append (in, buffer_in);
   out = g_list_append (out, buffer_out);
 
-  gst_check_element_push_buffer_list (element_name, in, out, GST_FLOW_OK);
+  gst_check_element_push_buffer_list (element_name, in, caps_in, out, caps_out,
+      GST_FLOW_OK);
 }
 
 void
index c0d349f..ff66993 100644 (file)
@@ -83,9 +83,11 @@ void gst_check_drop_buffers (void);
 void gst_check_caps_equal (GstCaps * caps1, GstCaps * caps2);
 void gst_check_buffer_data (GstBuffer * buffer, gconstpointer data, gsize size);
 void gst_check_element_push_buffer_list (const gchar * element_name,
-    GList * buffer_in, GList * buffer_out, GstFlowReturn last_flow_return);
+    GList * buffer_in, GstCaps * caps_in, GList * buffer_out,
+    GstCaps * caps_out, GstFlowReturn last_flow_return);
 void gst_check_element_push_buffer (const gchar * element_name,
-    GstBuffer * buffer_in, GstBuffer * buffer_out);
+    GstBuffer * buffer_in, GstCaps * caps_in, GstBuffer * buffer_out,
+    GstCaps *caps_out);
 GstPad *gst_check_setup_sink_pad (GstElement * element,
     GstStaticPadTemplate * tmpl);
 void gst_check_teardown_sink_pad (GstElement * element);