1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
/* GStreamer
*
* unit test for GstMeta
*
* Copyright (C) <2009> Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_VALGRIND_H
# include <valgrind/valgrind.h>
#else
# define RUNNING_ON_VALGRIND FALSE
#endif
#include <gst/check/gstcheck.h>
/* test metadata for PTS/DTS and duration */
typedef struct
{
GstMeta meta;
GstClockTime pts;
GstClockTime dts;
GstClockTime duration;
GstClockTime clock_rate;
} GstMetaTest;
static const GstMetaInfo *gst_meta_test_get_info (void);
#define GST_META_TEST_INFO (gst_meta_test_get_info())
#define GST_META_TEST_GET(buf) ((GstMetaTest *)gst_buffer_get_meta(buf,GST_META_TEST_INFO))
#define GST_META_TEST_ADD(buf) ((GstMetaTest *)gst_buffer_add_meta(buf,GST_META_TEST_INFO,NULL))
#if 0
/* unused currently. This is a user function to fill the metadata with default
* values. We don't call this from the init function because the user is mostly
* likely going to override the values immediately after */
static void
gst_meta_test_init (GstMetaTest * meta)
{
meta->pts = GST_CLOCK_TIME_NONE;
meta->dts = GST_CLOCK_TIME_NONE;
meta->duration = GST_CLOCK_TIME_NONE;
meta->clock_rate = GST_SECOND;
}
#endif
static void
test_init_func (GstMetaTest * meta, GstBuffer * buffer)
{
GST_DEBUG ("init called on buffer %p, meta %p", buffer, meta);
/* nothing to init really, the init function is mostly for allocating
* additional memory or doing special setup as part of adding the metadata to
* the buffer*/
}
static void
test_free_func (GstMetaTest * meta, GstBuffer * buffer)
{
GST_DEBUG ("free called on buffer %p, meta %p", buffer, meta);
/* nothing to free really */
}
static void
test_copy_func (GstBuffer * copy, GstMetaTest * meta, GstBuffer * buffer)
{
GstMetaTest *test;
GST_DEBUG ("copy called from buffer %p to %p, meta %p", buffer, copy, meta);
test = GST_META_TEST_ADD (copy);
test->pts = meta->pts;
test->dts = meta->dts;
test->duration = meta->duration;
test->clock_rate = meta->clock_rate;
}
static void
test_sub_func (GstBuffer * sub, GstMetaTest * meta, GstBuffer * buffer,
guint offset, guint size)
{
GstMetaTest *test;
GST_DEBUG ("sub called from buffer %p to %p, meta %p, %u-%u", buffer, sub,
meta, offset, size);
test = GST_META_TEST_ADD (sub);
if (offset == 0) {
/* same offset, copy timestamps */
test->pts = meta->pts;
test->dts = meta->dts;
if (size == GST_BUFFER_SIZE (buffer)) {
/* same size, copy duration */
test->duration = meta->duration;
} else {
/* else clear */
test->duration = GST_CLOCK_TIME_NONE;
}
} else {
test->pts = -1;
test->dts = -1;
test->duration = -1;
}
test->clock_rate = meta->clock_rate;
}
static const GstMetaInfo *
gst_meta_test_get_info (void)
{
static const GstMetaInfo *meta_test_info = NULL;
if (meta_test_info == NULL) {
meta_test_info = gst_meta_register ("GstMetaTest", "GstMetaTest",
sizeof (GstMetaTest),
(GstMetaInitFunction) test_init_func,
(GstMetaFreeFunction) test_free_func,
(GstMetaCopyFunction) test_copy_func,
(GstMetaSubFunction) test_sub_func, NULL, NULL);
}
return meta_test_info;
}
GST_START_TEST (test_meta_test)
{
GstBuffer *buffer, *copy, *subbuf;
GstMetaTest *meta;
buffer = gst_buffer_new_and_alloc (4);
memset (GST_BUFFER_DATA (buffer), 0, 4);
/* add some metadata */
meta = GST_META_TEST_ADD (buffer);
fail_if (meta == NULL);
/* fill some values */
meta->pts = 1000;
meta->dts = 2000;
meta->duration = 1000;
meta->clock_rate = 1000;
/* copy of the buffer */
copy = gst_buffer_copy (buffer);
/* get metadata of the buffer */
meta = GST_META_TEST_GET (copy);
fail_if (meta == NULL);
fail_if (meta->pts != 1000);
fail_if (meta->dts != 2000);
fail_if (meta->duration != 1000);
fail_if (meta->clock_rate != 1000);
gst_buffer_unref (copy);
/* make subbuffer */
subbuf = gst_buffer_create_sub (buffer, 0, 1);
/* get metadata of the buffer */
meta = GST_META_TEST_GET (subbuf);
fail_if (meta == NULL);
fail_if (meta->pts != 1000);
fail_if (meta->dts != 2000);
fail_if (meta->duration != -1);
fail_if (meta->clock_rate != 1000);
gst_buffer_unref (subbuf);
/* make another subbuffer */
subbuf = gst_buffer_create_sub (buffer, 1, 3);
/* get metadata of the buffer */
meta = GST_META_TEST_GET (subbuf);
fail_if (meta == NULL);
fail_if (meta->pts != -1);
fail_if (meta->dts != -1);
fail_if (meta->duration != -1);
fail_if (meta->clock_rate != 1000);
gst_buffer_unref (subbuf);
/* clean up */
gst_buffer_unref (buffer);
}
GST_END_TEST;
GST_START_TEST (test_meta_memory)
{
GstBuffer *buffer, *copy;
GstMetaMemory *meta;
guint8 *data;
gsize size;
guint i;
buffer = gst_buffer_new ();
/* add some memory metadata */
meta = gst_buffer_add_meta_memory (buffer, g_malloc (4), g_free, 4, 0);
fail_if (meta == NULL);
fail_if (meta->mmap_func == NULL);
fail_if (meta->munmap_func == NULL);
/* prepare for writing */
data = gst_meta_memory_map (meta, 0, &size, GST_META_MAP_WRITE);
fail_if (data == NULL);
fail_if (size != 4);
for (i = 0; i < 4; i++)
data[i] = i;
gst_meta_memory_unmap (meta, data, size);
/* reading */
meta = gst_buffer_get_meta_memory (buffer);
fail_if (meta == NULL);
data = gst_meta_memory_map (meta, 0, &size, GST_META_MAP_READ);
fail_if (data == NULL);
fail_if (size != 4);
for (i = 0; i < 4; i++)
fail_if (data[i] != i);
gst_meta_memory_unmap (meta, data, size);
/* copy of the buffer */
copy = gst_buffer_copy (buffer);
/* get metadata of the buffer */
meta = gst_buffer_get_meta_memory (copy);
fail_if (meta == NULL);
data = gst_meta_memory_map (meta, 0, &size, GST_META_MAP_READ);
fail_if (data == NULL);
fail_if (size != 4);
for (i = 0; i < 4; i++)
fail_if (data[i] != i);
gst_meta_memory_unmap (meta, data, size);
gst_buffer_unref (copy);
#if 0
/* FIXME, does not work yet */
/* make a subbuffer */
subbuf = gst_buffer_create_sub (buffer, 1, 3);
meta = gst_buffer_get_meta_memory (subbuf);
fail_if (meta == NULL);
data = gst_meta_memory_map (meta, 0, &size, GST_META_MAP_READ);
fail_if (data == NULL);
fail_if (size != 3);
for (i = 0; i < 3; i++)
fail_if (data[i] != i + 1);
gst_meta_memory_unmap (meta, data, size);
gst_buffer_unref (subbuf);
#endif
/* clean up */
gst_buffer_unref (buffer);
}
GST_END_TEST;
static Suite *
gst_buffermeta_suite (void)
{
Suite *s = suite_create ("GstMeta");
TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_meta_test);
tcase_add_test (tc_chain, test_meta_memory);
return s;
}
GST_CHECK_MAIN (gst_buffermeta);
|