1 /* GStreamer
2 *
3 * Unit tests for basetransform collation/separation
4 *
5 * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.com>
6 *
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.
11 *
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.
16 *
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.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 #include <gst/gst.h>
27 #include <gst/check/gstcheck.h>
28 #include <gst/base/gstbasetransform.h>
29
30 #include "test_transform.c"
31
32 GstBuffer *buf1, *buf2;
33
34 /* Output buffers are twice the size as input */
35 static gboolean
transform_size_collate(GstBaseTransform * trans,GstPadDirection direction,GstCaps * caps,gsize size,GstCaps * othercaps,gsize * othersize)36 transform_size_collate (GstBaseTransform * trans, GstPadDirection direction,
37 GstCaps * caps, gsize size, GstCaps * othercaps, gsize * othersize)
38 {
39 if (direction == GST_PAD_SINK) {
40 *othersize = size * 2;
41 } else {
42 *othersize = size / 2;
43 }
44
45 return TRUE;
46 }
47
48 static GstFlowReturn
collate_submit_input_buffer(GstBaseTransform * trans,gboolean is_discont,GstBuffer * input)49 collate_submit_input_buffer (GstBaseTransform * trans,
50 gboolean is_discont, GstBuffer * input)
51 {
52 GstBaseTransformClass *tt_parent_class;
53 GstFlowReturn ret;
54
55 tt_parent_class =
56 g_type_class_peek_parent (GST_BASE_TRANSFORM_GET_CLASS (trans));
57
58 ret = tt_parent_class->submit_input_buffer (trans, is_discont, input);
59
60 if (ret != GST_FLOW_OK)
61 return ret;
62
63 fail_unless (buf1 == NULL || buf2 == NULL);
64
65 if (buf1 == 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;
71 }
72
73 return ret;
74 }
75
76 static GstFlowReturn
collate_generate_output(GstBaseTransform * trans,GstBuffer ** outbuf)77 collate_generate_output (GstBaseTransform * trans, GstBuffer ** outbuf)
78 {
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;
82
83 fail_unless (buf1 != NULL && buf2 != NULL);
84 *outbuf = gst_buffer_new_and_alloc (40);
85
86 gst_buffer_unref (buf1);
87 gst_buffer_unref (buf2);
88 buf1 = NULL;
89 buf2 = NULL;
90
91 return GST_FLOW_OK;
92 }
93
94 /* Take 2 input buffers, generate 1 output
95 * buffer with twice the size
96 */
GST_START_TEST(basetransform_chain_collate)97 GST_START_TEST (basetransform_chain_collate)
98 {
99 TestTransData *trans;
100 GstBuffer *buffer;
101 GstFlowReturn res;
102 GstCaps *incaps, *outcaps;
103
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;
109
110 trans = gst_test_trans_new ();
111
112 incaps = gst_caps_new_empty_simple ("foo/x-bar");
113 outcaps = gst_caps_new_empty_simple ("foo/x-bar");
114
115 gst_test_trans_push_segment (trans);
116
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));
119
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);
123
124 buffer = gst_buffer_new_and_alloc (20);
125 res = gst_test_trans_push (trans, buffer);
126 fail_unless (res == GST_FLOW_OK);
127
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);
131
132 buffer = gst_buffer_new_and_alloc (20);
133 res = gst_test_trans_push (trans, buffer);
134 fail_unless (res == GST_FLOW_OK);
135
136 buffer = gst_test_trans_pop (trans);
137 fail_unless (buffer != NULL);
138 fail_unless (gst_buffer_get_size (buffer) == 40);
139
140 /* output buffer has refcount 1 */
141 fail_unless (GST_MINI_OBJECT_REFCOUNT_VALUE (buffer) == 1);
142 gst_buffer_unref (buffer);
143
144 gst_caps_unref (incaps);
145 gst_caps_unref (outcaps);
146
147 gst_test_trans_free (trans);
148 }
149
150 GST_END_TEST;
151
152
153 static Suite *
gst_basetransform_collate_suite(void)154 gst_basetransform_collate_suite (void)
155 {
156 Suite *s = suite_create ("GstBaseTransformCollate");
157 TCase *tc = tcase_create ("general");
158
159 suite_add_tcase (s, tc);
160 tcase_add_test (tc, basetransform_chain_collate);
161
162 return s;
163 }
164
165 GST_CHECK_MAIN (gst_basetransform_collate);
166