3 * unit test for GstMeta
5 * Copyright (C) <2009> 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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
27 #ifdef HAVE_VALGRIND_H
28 # include <valgrind/valgrind.h>
30 # define RUNNING_ON_VALGRIND FALSE
33 #include <gst/check/gstcheck.h>
35 /* test metadata for PTS/DTS and duration */
42 GstClockTime duration;
43 GstClockTime clock_rate;
46 static const GstMetaInfo *gst_meta_test_get_info (void);
47 #define GST_META_TEST_INFO (gst_meta_test_get_info())
49 #define GST_META_TEST_GET(buf) ((GstMetaTest *)gst_buffer_get_meta(buf,GST_META_TEST_INFO))
50 #define GST_META_TEST_ADD(buf) ((GstMetaTest *)gst_buffer_add_meta(buf,GST_META_TEST_INFO,NULL))
53 /* unused currently. This is a user function to fill the metadata with default
54 * values. We don't call this from the init function because the user is mostly
55 * likely going to override the values immediately after */
57 gst_meta_test_init (GstMetaTest * meta)
59 meta->pts = GST_CLOCK_TIME_NONE;
60 meta->dts = GST_CLOCK_TIME_NONE;
61 meta->duration = GST_CLOCK_TIME_NONE;
62 meta->clock_rate = GST_SECOND;
67 test_init_func (GstMetaTest * meta, GstBuffer * buffer)
69 GST_DEBUG ("init called on buffer %p, meta %p", buffer, meta);
70 /* nothing to init really, the init function is mostly for allocating
71 * additional memory or doing special setup as part of adding the metadata to
76 test_free_func (GstMetaTest * meta, GstBuffer * buffer)
78 GST_DEBUG ("free called on buffer %p, meta %p", buffer, meta);
79 /* nothing to free really */
83 test_copy_func (GstBuffer * copybuf, GstMetaTest * meta,
84 GstBuffer * buffer, gsize offset, gsize size)
88 GST_DEBUG ("copy called from buffer %p to %p, meta %p, %u-%u", buffer,
89 copybuf, meta, offset, size);
91 test = GST_META_TEST_ADD (copybuf);
93 /* same offset, copy timestamps */
94 test->pts = meta->pts;
95 test->dts = meta->dts;
96 if (size == gst_buffer_get_size (buffer)) {
97 /* same size, copy duration */
98 test->duration = meta->duration;
101 test->duration = GST_CLOCK_TIME_NONE;
108 test->clock_rate = meta->clock_rate;
111 static const GstMetaInfo *
112 gst_meta_test_get_info (void)
114 static const GstMetaInfo *meta_test_info = NULL;
116 if (meta_test_info == NULL) {
117 meta_test_info = gst_meta_register ("GstMetaTest", "GstMetaTest",
118 sizeof (GstMetaTest),
119 (GstMetaInitFunction) test_init_func,
120 (GstMetaFreeFunction) test_free_func,
121 (GstMetaCopyFunction) test_copy_func,
122 (GstMetaTransformFunction) NULL, NULL, NULL);
124 return meta_test_info;
127 GST_START_TEST (test_meta_test)
129 GstBuffer *buffer, *copy, *subbuf;
133 buffer = gst_buffer_new_and_alloc (4);
135 data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
137 gst_buffer_unmap (buffer, data, 4);
139 /* add some metadata */
140 meta = GST_META_TEST_ADD (buffer);
141 fail_if (meta == NULL);
142 /* fill some values */
145 meta->duration = 1000;
146 meta->clock_rate = 1000;
148 /* copy of the buffer */
149 copy = gst_buffer_copy (buffer);
150 /* get metadata of the buffer */
151 meta = GST_META_TEST_GET (copy);
152 fail_if (meta == NULL);
153 fail_if (meta->pts != 1000);
154 fail_if (meta->dts != 2000);
155 fail_if (meta->duration != 1000);
156 fail_if (meta->clock_rate != 1000);
157 gst_buffer_unref (copy);
160 subbuf = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 0, 1);
161 /* get metadata of the buffer */
162 meta = GST_META_TEST_GET (subbuf);
163 fail_if (meta == NULL);
164 fail_if (meta->pts != 1000);
165 fail_if (meta->dts != 2000);
166 fail_if (meta->duration != -1);
167 fail_if (meta->clock_rate != 1000);
168 gst_buffer_unref (subbuf);
170 /* make another subbuffer */
171 subbuf = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 1, 3);
172 /* get metadata of the buffer */
173 meta = GST_META_TEST_GET (subbuf);
174 fail_if (meta == NULL);
175 fail_if (meta->pts != -1);
176 fail_if (meta->dts != -1);
177 fail_if (meta->duration != -1);
178 fail_if (meta->clock_rate != 1000);
179 gst_buffer_unref (subbuf);
182 gst_buffer_unref (buffer);
188 gst_buffermeta_suite (void)
190 Suite *s = suite_create ("GstMeta");
191 TCase *tc_chain = tcase_create ("general");
193 suite_add_tcase (s, tc_chain);
194 tcase_add_test (tc_chain, test_meta_test);
199 GST_CHECK_MAIN (gst_buffermeta);