3 * Unit tests for basetransform collation/separation
5 * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
27 #include <gst/check/gstcheck.h>
28 #include <gst/base/gstbasetransform.h>
30 #include "test_transform.c"
32 GstBuffer *buf1, *buf2;
34 /* Output buffers are twice the size as input */
36 transform_size_collate (GstBaseTransform * trans, GstPadDirection direction,
37 GstCaps * caps, gsize size, GstCaps * othercaps, gsize * othersize)
39 if (direction == GST_PAD_SINK) {
40 *othersize = size * 2;
42 *othersize = size / 2;
49 collate_submit_input_buffer (GstBaseTransform * trans,
50 gboolean is_discont, GstBuffer * input)
52 GstBaseTransformClass *tt_parent_class;
56 g_type_class_peek_parent (GST_BASE_TRANSFORM_GET_CLASS (trans));
58 ret = tt_parent_class->submit_input_buffer (trans, is_discont, input);
60 if (ret != GST_FLOW_OK)
63 fail_unless (buf1 == NULL || buf2 == NULL);
66 buf1 = trans->queued_buf;
67 trans->queued_buf = NULL;
68 } else if (buf2 == NULL) {
69 buf2 = trans->queued_buf;
70 trans->queued_buf = NULL;
77 collate_generate_output (GstBaseTransform * trans, GstBuffer ** outbuf)
79 /* Not ready to generate output unless we've collected 2 buffers */
80 if (buf1 == NULL || buf2 == NULL)
81 return GST_BASE_TRANSFORM_FLOW_DROPPED;
83 fail_unless (buf1 != NULL && buf2 != NULL);
84 *outbuf = gst_buffer_new_and_alloc (40);
86 gst_buffer_unref (buf1);
87 gst_buffer_unref (buf2);
94 /* Take 2 input buffers, generate 1 output
95 * buffer with twice the size
97 GST_START_TEST (basetransform_chain_collate)
102 GstCaps *incaps, *outcaps;
104 src_template = &gst_test_trans_src_template;
105 klass_passthrough_on_same_caps = FALSE;
106 klass_transform_size = transform_size_collate;
107 klass_submit_input_buffer = collate_submit_input_buffer;
108 klass_generate_output = collate_generate_output;
110 trans = gst_test_trans_new ();
112 incaps = gst_caps_new_empty_simple ("foo/x-bar");
113 outcaps = gst_caps_new_empty_simple ("foo/x-bar");
115 gst_test_trans_push_segment (trans);
117 gst_pad_push_event (trans->srcpad, gst_event_new_flush_start ());
118 gst_pad_push_event (trans->srcpad, gst_event_new_flush_stop (TRUE));
120 GST_DEBUG_OBJECT (trans, "buffer with caps %" GST_PTR_FORMAT, incaps);
121 gst_test_trans_setcaps (trans, incaps);
122 gst_test_trans_push_segment (trans);
124 buffer = gst_buffer_new_and_alloc (20);
125 res = gst_test_trans_push (trans, buffer);
126 fail_unless (res == GST_FLOW_OK);
128 /* We do not expect an output buffer after only pushing one input */
129 buffer = gst_test_trans_pop (trans);
130 fail_unless (buffer == NULL);
132 buffer = gst_buffer_new_and_alloc (20);
133 res = gst_test_trans_push (trans, buffer);
134 fail_unless (res == GST_FLOW_OK);
136 buffer = gst_test_trans_pop (trans);
137 fail_unless (buffer != NULL);
138 fail_unless (gst_buffer_get_size (buffer) == 40);
140 /* output buffer has refcount 1 */
141 fail_unless (GST_MINI_OBJECT_REFCOUNT_VALUE (buffer) == 1);
142 gst_buffer_unref (buffer);
144 gst_caps_unref (incaps);
145 gst_caps_unref (outcaps);
147 gst_test_trans_free (trans);
154 gst_basetransform_collate_suite (void)
156 Suite *s = suite_create ("GstBaseTransformCollate");
157 TCase *tc = tcase_create ("general");
159 suite_add_tcase (s, tc);
160 tcase_add_test (tc, basetransform_chain_collate);
165 GST_CHECK_MAIN (gst_basetransform_collate);