base: avoid using buffer caps

Comment all code using buffer caps.
Rework capsfilter code a little.
Fix some unit tests
This commit is contained in:
Wim Taymans 2011-05-08 12:46:17 +02:00
parent bf7c80b5f6
commit ba6b915651
8 changed files with 60 additions and 114 deletions

View file

@ -1784,11 +1784,14 @@ gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
gboolean want_in_place;
GstClockTime running_time;
GstClockTime timestamp;
#if 0
GstCaps *incaps;
#endif
gsize insize;
bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
#if 0
if (G_LIKELY ((incaps = GST_BUFFER_CAPS (inbuf)))) {
gboolean reconfigure;
@ -1813,6 +1816,7 @@ gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
goto not_negotiated;
}
}
#endif
insize = gst_buffer_get_size (inbuf);

View file

@ -79,7 +79,9 @@ helper_find_peek (gpointer data, gint64 offset, guint size)
GSList *insert_pos = NULL;
gsize buf_size;
guint64 buf_offset;
#if 0
GstCaps *caps;
#endif
helper = (GstTypeFindHelper *) data;
@ -136,6 +138,7 @@ helper_find_peek (gpointer data, gint64 offset, guint size)
if (ret != GST_FLOW_OK)
goto error;
#if 0
caps = GST_BUFFER_CAPS (buffer);
if (caps && !gst_caps_is_empty (caps) && !gst_caps_is_any (caps)) {
@ -148,6 +151,7 @@ helper_find_peek (gpointer data, gint64 offset, guint size)
gst_buffer_unref (buffer);
return NULL;
}
#endif
/* getrange might silently return shortened buffers at the end of a file,
* we must, however, always return either the full requested data or NULL */

View file

@ -406,8 +406,10 @@ void
gst_check_element_push_buffer_list (const gchar * element_name,
GList * buffer_in, GList * buffer_out, GstFlowReturn last_flow_return)
{
#if 0
GstCaps *sink_caps;
GstCaps *src_caps = NULL;
#endif
GstElement *element;
GstPad *pad_peer;
GstPad *sink_pad = NULL;
@ -424,9 +426,13 @@ 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
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,
@ -437,10 +443,13 @@ gst_check_element_push_buffer_list (const gchar * element_name,
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);
@ -448,10 +457,13 @@ gst_check_element_push_buffer_list (const gchar * element_name,
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);
fail_unless (GST_IS_PAD (sink_pad));
#if 0
gst_pad_set_caps (sink_pad, sink_caps);
#endif
/* 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,
@ -494,10 +506,8 @@ gst_check_element_push_buffer_list (const gchar * element_name,
newdata = gst_buffer_map (new, &newsize, NULL, GST_MAP_READ);
origdata = gst_buffer_map (orig, &origsize, NULL, GST_MAP_READ);
GST_LOG ("orig buffer: size %u, caps %" GST_PTR_FORMAT,
origsize, GST_BUFFER_CAPS (orig));
GST_LOG ("new buffer: size %u, caps %" GST_PTR_FORMAT,
newsize, GST_BUFFER_CAPS (new));
GST_LOG ("orig buffer: size %u", origsize);
GST_LOG ("new buffer: size %u", newsize);
GST_MEMDUMP ("orig buffer", origdata, origsize);
GST_MEMDUMP ("new buffer", newdata, newsize);
@ -508,7 +518,9 @@ gst_check_element_push_buffer_list (const gchar * element_name,
fail_unless (origsize == newsize, "size of the buffers are not the same");
fail_unless (memcmp (origdata, newdata, newsize) == 0,
"data is not the same");
#if 0
gst_check_caps_equal (GST_BUFFER_CAPS (orig), GST_BUFFER_CAPS (new));
#endif
gst_buffer_unmap (orig, origdata, origsize);
gst_buffer_unmap (new, newdata, newsize);

View file

@ -322,34 +322,16 @@ gst_capsfilter_prepare_buf (GstBaseTransform * trans, GstBuffer * input,
{
GstFlowReturn ret = GST_FLOW_OK;
if (GST_BUFFER_CAPS (input) != NULL) {
/* Output buffer already has caps */
GST_LOG_OBJECT (trans, "Input buffer already has caps (implicitely fixed)");
/* FIXME : Move this behaviour to basetransform. The given caps are the ones
* of the source pad, therefore our outgoing buffers should always have
* those caps. */
if (GST_BUFFER_CAPS (input) != caps) {
/* caps are different, make a metadata writable output buffer to set
* caps */
if (gst_buffer_is_writable (input)) {
/* input is writable, just set caps and use this as the output */
*buf = input;
gst_buffer_set_caps (*buf, caps);
gst_buffer_ref (input);
} else {
GST_DEBUG_OBJECT (trans, "Creating sub-buffer and setting caps");
*buf = gst_buffer_copy (input);
gst_buffer_set_caps (*buf, caps);
}
} else {
/* caps are right, just use a ref of the input as the outbuf */
*buf = input;
gst_buffer_ref (input);
}
} else {
/* always ref input as output buffer */
*buf = input;
gst_buffer_ref (input);
if (!gst_pad_has_current_caps (trans->sinkpad)) {
/* Buffer has no caps. See if the output pad only supports fixed caps */
GstCaps *out_caps;
GST_LOG_OBJECT (trans, "Input pad does not have caps");
out_caps = gst_pad_get_current_caps (trans->srcpad);
if (out_caps == NULL) {
out_caps = gst_pad_get_allowed_caps (trans->srcpad);
@ -361,15 +343,7 @@ gst_capsfilter_prepare_buf (GstBaseTransform * trans, GstBuffer * input,
if (gst_caps_is_fixed (out_caps) && !gst_caps_is_empty (out_caps)) {
GST_DEBUG_OBJECT (trans, "Have fixed output caps %"
GST_PTR_FORMAT " to apply to buffer with no caps", out_caps);
if (gst_buffer_is_writable (input)) {
gst_buffer_ref (input);
*buf = input;
} else {
GST_DEBUG_OBJECT (trans, "Creating sub-buffer and setting caps");
*buf = gst_buffer_copy (input);
}
GST_BUFFER_CAPS (*buf) = out_caps;
GST_PTR_FORMAT " to apply to srcpad", out_caps);
if (!gst_pad_has_current_caps (trans->srcpad))
gst_pad_set_caps (trans->srcpad, out_caps);

View file

@ -480,9 +480,6 @@ stop_typefinding (GstTypeFindElement * typefind)
goto no_data;
buffer = gst_adapter_take_buffer (typefind->adapter, avail);
buffer = gst_buffer_make_writable (buffer);
gst_buffer_set_caps (buffer, typefind->caps);
GST_OBJECT_UNLOCK (typefind);
if (!push_cached_buffers) {
@ -628,8 +625,6 @@ gst_type_find_element_setcaps (GstPad * pad, GstCaps * caps)
goto no_data;
buffer = gst_adapter_take_buffer (typefind->adapter, avail);
buffer = gst_buffer_make_writable (buffer);
gst_buffer_set_caps (buffer, typefind->caps);
GST_OBJECT_UNLOCK (typefind);
GST_DEBUG_OBJECT (typefind, "Pushing buffer: %d", avail);
@ -744,8 +739,6 @@ gst_type_find_element_chain (GstPad * pad, GstBuffer * buffer)
return GST_FLOW_ERROR;
case MODE_NORMAL:
/* don't take object lock as typefind->caps should not change anymore */
buffer = gst_buffer_make_writable (buffer);
gst_buffer_set_caps (buffer, typefind->caps);
return gst_pad_push (typefind->src, buffer);
case MODE_TYPEFIND:
{
@ -879,12 +872,6 @@ gst_type_find_element_getrange (GstPad * srcpad,
ret = gst_pad_pull_range (typefind->sink, offset, length, buffer);
if (ret == GST_FLOW_OK && buffer && *buffer) {
/* don't take object lock as typefind->caps should not change anymore */
/* we assume that pulled buffers are meta-data writable */
gst_buffer_set_caps (*buffer, typefind->caps);
}
return ret;
}

View file

@ -32,50 +32,6 @@
#include <gst/check/gstcheck.h>
GST_START_TEST (test_caps)
{
GstBuffer *buffer;
GstCaps *caps, *caps2;
buffer = gst_buffer_new_and_alloc (4);
caps = gst_caps_from_string ("audio/x-raw-int");
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
fail_unless (GST_BUFFER_CAPS (buffer) == NULL);
gst_buffer_set_caps (buffer, caps);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
fail_unless (GST_BUFFER_CAPS (buffer) == caps);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
fail_unless (gst_buffer_get_caps (buffer) == caps);
gst_caps_unref (caps);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
caps2 = gst_caps_from_string ("audio/x-raw-float");
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 1);
gst_buffer_set_caps (buffer, caps2);
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 2);
gst_buffer_set_caps (buffer, NULL);
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 1);
/* clean up, with caps2 still set as caps */
gst_buffer_set_caps (buffer, caps2);
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 2);
gst_buffer_unref (buffer);
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 1);
gst_caps_unref (caps);
gst_caps_unref (caps2);
}
GST_END_TEST;
GST_START_TEST (test_subbuffer)
{
GstBuffer *buffer, *sub;
@ -492,7 +448,6 @@ gst_buffer_suite (void)
TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_caps);
tcase_add_test (tc_chain, test_subbuffer);
tcase_add_test (tc_chain, test_subbuffer_make_writable);
tcase_add_test (tc_chain, test_make_writable);

View file

@ -89,6 +89,7 @@ GST_START_TEST (test_link_unlink_threaded)
caps = gst_caps_from_string ("foo/bar");
gst_pad_set_caps (src, caps);
gst_pad_set_active (sink, TRUE);
gst_pad_set_caps (sink, caps);
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
@ -100,10 +101,10 @@ GST_START_TEST (test_link_unlink_threaded)
}
MAIN_STOP_THREADS ();
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
gst_caps_unref (caps);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
gst_object_unref (src);
gst_object_unref (sink);
}
@ -126,17 +127,23 @@ GST_START_TEST (test_refcount)
/* one for me */
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
gst_pad_set_caps (src, caps);
gst_pad_set_caps (sink, caps);
fail_unless (gst_pad_set_caps (src, caps) == TRUE);
/* can't set caps on flushing sinkpad */
fail_if (gst_pad_set_caps (sink, caps) == TRUE);
/* one for me and one for each set_caps */
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
gst_pad_set_active (sink, TRUE);
fail_unless (gst_pad_set_caps (sink, caps) == TRUE);
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
plr = gst_pad_link (src, sink);
fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
/* caps replaced by src caps */
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
gst_pad_unlink (src, sink);
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
/* cleanup */
gst_object_unref (src);
@ -169,8 +176,12 @@ GST_START_TEST (test_get_allowed_caps)
caps = gst_caps_from_string ("foo/bar");
sink = gst_pad_new ("sink", GST_PAD_SINK);
gst_pad_set_caps (src, caps);
gst_pad_set_caps (sink, caps);
fail_unless (gst_pad_set_caps (src, caps) == TRUE);
fail_if (gst_pad_set_caps (sink, caps) == TRUE);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
gst_pad_set_active (sink, TRUE);
fail_unless (gst_pad_set_caps (sink, caps) == TRUE);
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
plr = gst_pad_link (src, sink);
@ -186,7 +197,7 @@ GST_START_TEST (test_get_allowed_caps)
gst_pad_unlink (src, sink);
/* cleanup */
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
@ -324,13 +335,14 @@ GST_START_TEST (test_push_linked)
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
gst_pad_set_caps (src, caps);
gst_pad_set_active (sink, TRUE);
gst_pad_set_caps (sink, caps);
/* one for me and one for each set_caps */
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
plr = gst_pad_link (src, sink);
fail_unless (GST_PAD_LINK_SUCCESSFUL (plr));
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
buffer = gst_buffer_new ();
#if 0
@ -389,7 +401,7 @@ GST_START_TEST (test_push_linked)
/* teardown */
gst_pad_unlink (src, sink);
ASSERT_CAPS_REFCOUNT (caps, "caps", 3);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
gst_object_unref (src);
gst_object_unref (sink);
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
@ -451,6 +463,7 @@ GST_START_TEST (test_push_buffer_list_compat)
caps = gst_caps_from_string ("foo/bar");
gst_pad_set_caps (src, caps);
gst_pad_set_active (sink, TRUE);
gst_pad_set_caps (sink, caps);
plr = gst_pad_link (src, sink);
@ -579,11 +592,7 @@ GST_START_TEST (test_push_negotiation)
/* Should fail if src pad caps are incompatible with sink pad caps */
gst_pad_set_caps (src, caps);
gst_buffer_set_caps (buffer, caps);
gst_buffer_ref (buffer);
fail_unless (gst_pad_push (src, buffer) == GST_FLOW_NOT_NEGOTIATED);
ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
gst_buffer_unref (buffer);
fail_unless (gst_pad_set_caps (sink, caps) == FALSE);
/* teardown */
gst_pad_unlink (src, sink);
@ -612,6 +621,7 @@ GST_START_TEST (test_src_unref_unlink)
caps = gst_caps_from_string ("foo/bar");
gst_pad_set_caps (src, caps);
gst_pad_set_active (sink, TRUE);
gst_pad_set_caps (sink, caps);
plr = gst_pad_link (src, sink);
@ -646,6 +656,7 @@ GST_START_TEST (test_sink_unref_unlink)
caps = gst_caps_from_string ("foo/bar");
gst_pad_set_caps (src, caps);
gst_pad_set_active (sink, TRUE);
gst_pad_set_caps (sink, caps);
plr = gst_pad_link (src, sink);

View file

@ -368,8 +368,7 @@ print_tag (const GstTagList * list, const gchar * tag, gpointer unused)
if (img) {
gchar *caps_str;
caps_str = GST_BUFFER_CAPS (img) ?
gst_caps_to_string (GST_BUFFER_CAPS (img)) : g_strdup ("unknown");
caps_str = g_strdup ("unknown");
str = g_strdup_printf ("buffer of %" G_GSIZE_FORMAT " bytes, type: %s",
gst_buffer_get_size (img), caps_str);
g_free (caps_str);