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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
#include <gst/check/gstcheck.h>
#define fail_error_message(msg) \
G_STMT_START { \
GError *error; \
gst_message_parse_error(msg, &error, NULL); \
fail_unless(FALSE, "Error Message from %s : %s", \
GST_OBJECT_NAME (GST_MESSAGE_SRC(msg)), error->message); \
g_error_free (error); \
} G_STMT_END;
#define check_start_stop_duration(object, startval, stopval, durval) \
G_STMT_START { guint64 start, stop; \
gint64 duration; \
GST_DEBUG_OBJECT (object, "Checking for valid start/stop/duration values"); \
g_object_get (object, "start", &start, "stop", &stop, \
"duration", &duration, NULL); \
fail_unless_equals_uint64(start, startval); \
fail_unless_equals_uint64(stop, stopval); \
fail_unless_equals_int64(duration, durval); \
GST_DEBUG_OBJECT (object, "start/stop/duration values valid"); \
} G_STMT_END;
#define check_state_simple(object, expected_state) \
G_STMT_START { \
GstStateChangeReturn ret; \
GstState state, pending; \
ret = gst_element_get_state(GST_ELEMENT_CAST(object), &state, &pending, 5 * GST_SECOND); \
fail_if (ret == GST_STATE_CHANGE_FAILURE); \
fail_unless (state == expected_state, "Element state (%s) is not the expected one (%s)", \
gst_element_state_get_name(state), gst_element_state_get_name(expected_state)); \
} G_STMT_END;
typedef struct _Segment {
gdouble rate;
GstFormat format;
guint64 start, stop, position;
} Segment;
typedef struct _CollectStructure {
GstElement *comp;
GstElement *sink;
guint64 last_time;
gboolean gotsegment;
GList *seen_segments;
GList *expected_segments;
guint64 expected_base;
} CollectStructure;
static GstElement *
gst_element_factory_make_or_warn (const gchar * factoryname, const gchar * name)
{
GstElement * element;
element = gst_element_factory_make (factoryname, name);
fail_unless (element != NULL, "Failed to make element %s", factoryname);
return element;
}
static void
composition_pad_added_cb (GstElement *composition, GstPad *pad, CollectStructure * collect)
{
fail_if (!(gst_element_link_pads_full (composition, GST_OBJECT_NAME (pad), collect->sink, "sink",
GST_PAD_LINK_CHECK_NOTHING)));
}
/* return TRUE to discard the Segment */
static gboolean
compare_segments (CollectStructure *collect, Segment * segment, GstEvent * event)
{
const GstSegment *orig;
guint64 running_stop, running_start, running_duration;
gst_event_parse_segment (event, &orig);
GST_DEBUG ("Got Segment rate:%f, format:%s, start:%"GST_TIME_FORMAT
", stop:%"GST_TIME_FORMAT", time:%"GST_TIME_FORMAT
", base:%"GST_TIME_FORMAT", offset:%"GST_TIME_FORMAT,
orig->rate, gst_format_get_name(orig->format), GST_TIME_ARGS (orig->start),
GST_TIME_ARGS (orig->stop),
GST_TIME_ARGS (orig->time),
GST_TIME_ARGS (orig->base),
GST_TIME_ARGS (orig->offset));
GST_DEBUG ("[RUNNING] start:%"GST_TIME_FORMAT" [STREAM] start:%"GST_TIME_FORMAT,
GST_TIME_ARGS (gst_segment_to_running_time (orig, GST_FORMAT_TIME, orig->start)),
GST_TIME_ARGS (gst_segment_to_stream_time (orig, GST_FORMAT_TIME, orig->start)));
GST_DEBUG ("Expecting rate:%f, format:%s, start:%"GST_TIME_FORMAT
", stop:%"GST_TIME_FORMAT", position:%"GST_TIME_FORMAT", base:%"GST_TIME_FORMAT,
segment->rate, gst_format_get_name (segment->format),
GST_TIME_ARGS (segment->start),
GST_TIME_ARGS (segment->stop),
GST_TIME_ARGS (segment->position),
GST_TIME_ARGS (collect->expected_base));
running_start = gst_segment_to_running_time (orig, GST_FORMAT_TIME, orig->start);
running_stop = gst_segment_to_running_time (orig, GST_FORMAT_TIME, orig->stop);
running_duration = running_stop - running_start;
fail_if (orig->rate != segment->rate);
fail_if (orig->format != segment->format);
fail_unless_equals_int64 (orig->time, segment->position);
fail_unless_equals_int64 (orig->base, collect->expected_base);
fail_unless_equals_uint64 (orig->stop - orig->start, segment->stop -segment->start);
collect->expected_base += running_duration;
GST_DEBUG ("Segment was valid, discarding expected Segment");
return TRUE;
}
static GstPadProbeReturn
sinkpad_event_probe (GstPad * sinkpad, GstEvent * event, CollectStructure * collect)
{
Segment * segment;
GST_DEBUG_OBJECT (sinkpad, "event:%p (%s seqnum:%d) , collect:%p", event,
GST_EVENT_TYPE_NAME (event),
GST_EVENT_SEQNUM (event), collect);
if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
fail_if (collect->expected_segments == NULL, "Received unexpected segment");
if (!collect->gotsegment)
collect->seen_segments = g_list_append(NULL, GINT_TO_POINTER(GST_EVENT_SEQNUM(event)));
else {
fail_if(g_list_find(collect->seen_segments, GINT_TO_POINTER(GST_EVENT_SEQNUM(event))),
"Got a segment event we already saw before !");
collect->seen_segments = g_list_append(collect->seen_segments, GINT_TO_POINTER(GST_EVENT_SEQNUM(event)));
}
segment = (Segment *) collect->expected_segments->data;
if (compare_segments (collect, segment, event)) {
collect->expected_segments = g_list_remove (collect->expected_segments, segment);
g_free (segment);
}
collect->gotsegment = TRUE;
}
return GST_PAD_PROBE_OK;
}
static GstPadProbeReturn
sinkpad_buffer_probe (GstPad * sinkpad, GstBuffer * buffer, CollectStructure * collect)
{
GST_DEBUG_OBJECT (sinkpad, "buffer:%p (%"GST_TIME_FORMAT") , collect:%p", buffer,
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), collect);
fail_if(!collect->gotsegment, "Received a buffer without a preceding segment");
return GST_PAD_PROBE_OK;
}
static GstPadProbeReturn
sinkpad_probe (GstPad *sinkpad, GstPadProbeInfo * info, CollectStructure * collect)
{
if (info->type & GST_PAD_PROBE_TYPE_BUFFER)
return sinkpad_buffer_probe (sinkpad, (GstBuffer*) info->data, collect);
if (info->type & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM)
return sinkpad_event_probe (sinkpad, (GstEvent *) info->data, collect);
return GST_PAD_PROBE_OK;
}
static GstElement *
new_gnl_src (const gchar * name, guint64 start, gint64 duration, gint priority)
{
GstElement * gnlsource = NULL;
gnlsource = gst_element_factory_make_or_warn ("gnlsource", name);
fail_if (gnlsource == NULL);
g_object_set (G_OBJECT (gnlsource),
"start", start,
"duration", duration,
"media-start", start,
"media-duration", duration,
"priority", priority,
NULL);
return gnlsource;
}
static GstElement *
videotest_gnl_src (const gchar * name, guint64 start, gint64 duration,
gint pattern, guint priority)
{
GstElement * gnlsource = NULL;
GstElement * videotestsrc = NULL;
GstCaps * caps = gst_caps_from_string ("video/x-raw,format=(string)I420,framerate=(fraction)3/2");
fail_if (caps == NULL);
videotestsrc = gst_element_factory_make_or_warn ("videotestsrc", NULL);
g_object_set (G_OBJECT (videotestsrc), "pattern", pattern, NULL);
gnlsource = new_gnl_src (name, start, duration, priority);
g_object_set (G_OBJECT (gnlsource), "caps", caps, NULL);
gst_caps_unref(caps);
gst_bin_add (GST_BIN (gnlsource), videotestsrc);
return gnlsource;
}
static GstElement *
videotest_gnl_src_full (const gchar * name, guint64 start, gint64 duration,
guint64 mediastart, gint64 mediaduration,
gint pattern, guint priority)
{
GstElement * gnls;
gnls = videotest_gnl_src (name, start, duration, pattern, priority);
if (gnls) {
g_object_set (G_OBJECT (gnls),
"media-start", mediastart,
"media-duration", mediaduration,
NULL);
}
return gnls;
}
static GstElement *
videotest_in_bin_gnl_src (const gchar * name, guint64 start, gint64 duration, gint pattern, guint priority)
{
GstElement * gnlsource = NULL;
GstElement * videotestsrc = NULL;
GstElement * bin = NULL;
GstElement * alpha = NULL;
GstPad *srcpad = NULL;
alpha = gst_element_factory_make ("alpha", NULL);
if (alpha == NULL)
return NULL;
videotestsrc = gst_element_factory_make_or_warn ("videotestsrc", NULL);
g_object_set (G_OBJECT (videotestsrc), "pattern", pattern, NULL);
bin = gst_bin_new (NULL);
gnlsource = new_gnl_src (name, start, duration, priority);
gst_bin_add (GST_BIN (bin), videotestsrc);
gst_bin_add (GST_BIN (bin), alpha);
gst_element_link_pads_full (videotestsrc, "src", alpha, "sink",
GST_PAD_LINK_CHECK_NOTHING);
gst_bin_add (GST_BIN (gnlsource), bin);
srcpad = gst_element_get_static_pad (alpha, "src");
gst_element_add_pad (bin, gst_ghost_pad_new ("src", srcpad));
gst_object_unref (srcpad);
return gnlsource;
}
static GstElement *
audiotest_bin_src (const gchar * name, guint64 start,
gint64 duration, guint priority, gboolean intaudio)
{
GstElement * source = NULL;
GstElement * identity = NULL;
GstElement * audiotestsrc = NULL;
GstElement * audioconvert = NULL;
GstElement * bin = NULL;
GstCaps * caps;
GstPad *srcpad = NULL;
audiotestsrc = gst_element_factory_make_or_warn ("audiotestsrc", NULL);
identity = gst_element_factory_make_or_warn ("identity", NULL);
bin = gst_bin_new (NULL);
source = new_gnl_src (name, start, duration, priority);
audioconvert = gst_element_factory_make_or_warn ("audioconvert", NULL);
if (intaudio)
caps = gst_caps_from_string ("audio/x-raw,format=(string)S16LE");
else
caps = gst_caps_from_string ("audio/x-raw,format=(string)F32LE");
gst_bin_add_many (GST_BIN (bin), audiotestsrc, audioconvert, identity, NULL);
gst_element_link_pads_full (audiotestsrc, "src", audioconvert, "sink",
GST_PAD_LINK_CHECK_NOTHING);
fail_if ((gst_element_link_filtered (audioconvert, identity, caps)) != TRUE);
gst_caps_unref (caps);
gst_bin_add (GST_BIN (source), bin);
srcpad = gst_element_get_static_pad (identity, "src");
gst_element_add_pad (bin, gst_ghost_pad_new ("src", srcpad));
gst_object_unref (srcpad);
return source;
}
static GstElement *
new_operation (const gchar * name, const gchar * factory, guint64 start, gint64 duration, guint priority)
{
GstElement * gnloperation = NULL;
GstElement * operation = NULL;
operation = gst_element_factory_make_or_warn (factory, NULL);
gnloperation = gst_element_factory_make_or_warn ("gnloperation", name);
g_object_set (G_OBJECT (gnloperation),
"start", start,
"duration", duration,
"priority", priority,
NULL);
gst_bin_add (GST_BIN (gnloperation), operation);
return gnloperation;
}
static Segment *
segment_new (gdouble rate, GstFormat format, gint64 start, gint64 stop, gint64 position)
{
Segment * segment;
segment = g_new0 (Segment, 1);
segment->rate = rate;
segment->format = format;
segment->start = start;
segment->stop = stop;
segment->position = position;
return segment;
}
static GList *
copy_segment_list (GList *list)
{
GList *res = NULL;
while (list) {
Segment *pdata = (Segment*) list->data;
res = g_list_append(res, segment_new(pdata->rate, pdata->format, pdata->start, pdata->stop, pdata->position));
list = list->next;
}
return res;
}
|