📄 gstevent.c
字号:
fail_unless (event != event2); /* this fail if the structure isn't writable */ gst_structure_remove_all_fields ((GstStructure *) gst_event_get_structure (event2)); gst_event_unref (event); gst_event_unref (event); gst_event_unref (event2); }}GST_END_TEST;GTimeVal sent_event_time;GstEvent *got_event_before_q, *got_event_after_q;GTimeVal got_event_time;static gbooleanevent_probe (GstPad * pad, GstMiniObject ** data, gpointer user_data){ gboolean before_q = (gboolean) GPOINTER_TO_INT (user_data); fail_unless (GST_IS_EVENT (data)); GST_DEBUG ("event probe called"); if (before_q) { switch (GST_EVENT_TYPE (GST_EVENT (data))) { case GST_EVENT_CUSTOM_UPSTREAM: case GST_EVENT_CUSTOM_BOTH: case GST_EVENT_CUSTOM_BOTH_OOB: if (got_event_before_q != NULL) break; gst_event_ref ((GstEvent *) data); g_get_current_time (&got_event_time); got_event_before_q = GST_EVENT (data); break; default: break; } } else { switch (GST_EVENT_TYPE (GST_EVENT (data))) { case GST_EVENT_CUSTOM_DOWNSTREAM: case GST_EVENT_CUSTOM_DOWNSTREAM_OOB: case GST_EVENT_CUSTOM_BOTH: case GST_EVENT_CUSTOM_BOTH_OOB: if (got_event_after_q != NULL) break; gst_event_ref ((GstEvent *) data); g_get_current_time (&got_event_time); got_event_after_q = GST_EVENT (data); break; default: break; } } return TRUE;}static void test_event (GstBin * pipeline, GstEventType type, GstPad * pad, gboolean expect_before_q, GstPad * fake_srcpad){ GstEvent *event; GstPad *peer; gint i; got_event_before_q = got_event_after_q = NULL; gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, GST_CLOCK_TIME_NONE); GST_DEBUG ("test event called"); event = gst_event_new_custom (type, gst_structure_empty_new ("application/x-custom")); g_get_current_time (&sent_event_time); got_event_time.tv_sec = 0; got_event_time.tv_usec = 0; /* We block the pad so the stream lock is released and we can send the event */ fail_unless (gst_pad_set_blocked (fake_srcpad, TRUE) == TRUE); /* We send on the peer pad, since the pad is blocked */ fail_unless ((peer = gst_pad_get_peer (pad)) != NULL); gst_pad_send_event (peer, event); gst_object_unref (peer); fail_unless (gst_pad_set_blocked (fake_srcpad, FALSE) == TRUE); if (expect_before_q) { /* Wait up to 5 seconds for the event to appear */ for (i = 0; i < 500; i++) { g_usleep (G_USEC_PER_SEC / 100); if (got_event_before_q != NULL) break; } fail_if (got_event_before_q == NULL, "Expected event failed to appear upstream of the queue " "within 5 seconds"); fail_unless (GST_EVENT_TYPE (got_event_before_q) == type); } else { /* Wait up to 10 seconds for the event to appear */ for (i = 0; i < 1000; i++) { g_usleep (G_USEC_PER_SEC / 100); if (got_event_after_q != NULL) break; } fail_if (got_event_after_q == NULL, "Expected event failed to appear after the queue within 10 seconds"); fail_unless (GST_EVENT_TYPE (got_event_after_q) == type); } gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED); gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, GST_CLOCK_TIME_NONE); if (got_event_before_q) gst_event_unref (got_event_before_q); if (got_event_after_q) gst_event_unref (got_event_after_q); got_event_before_q = got_event_after_q = NULL;}static gint64timediff (GTimeVal * end, GTimeVal * start){ return (end->tv_sec - start->tv_sec) * G_USEC_PER_SEC + (end->tv_usec - start->tv_usec);}GST_START_TEST (send_custom_events){ /* Run some tests on custom events. Checking for serialisation and whatnot. * pipeline is fakesrc ! queue ! fakesink */ GstBin *pipeline; GstElement *fakesrc, *fakesink, *queue; GstPad *srcpad, *sinkpad; fail_if ((pipeline = (GstBin *) gst_pipeline_new ("testpipe")) == NULL); fail_if ((fakesrc = gst_element_factory_make ("fakesrc", NULL)) == NULL); fail_if ((fakesink = gst_element_factory_make ("fakesink", NULL)) == NULL); fail_if ((queue = gst_element_factory_make ("queue", NULL)) == NULL); gst_bin_add_many (pipeline, fakesrc, queue, fakesink, NULL); fail_unless (gst_element_link_many (fakesrc, queue, fakesink, NULL)); g_object_set (G_OBJECT (fakesink), "sync", FALSE, NULL); /* Send 100 buffers per sec */ g_object_set (G_OBJECT (fakesrc), "silent", TRUE, "datarate", 100, "sizemax", 1, "sizetype", 2, NULL); g_object_set (G_OBJECT (queue), "max-size-buffers", 0, "max-size-time", (guint64) GST_SECOND, "max-size-bytes", 0, NULL); g_object_set (G_OBJECT (fakesink), "silent", TRUE, "sync", TRUE, NULL); fail_if ((srcpad = gst_element_get_pad (fakesrc, "src")) == NULL); gst_pad_add_event_probe (srcpad, (GCallback) event_probe, GINT_TO_POINTER (TRUE)); fail_if ((sinkpad = gst_element_get_pad (fakesink, "sink")) == NULL); gst_pad_add_event_probe (sinkpad, (GCallback) event_probe, GINT_TO_POINTER (FALSE)); /* Upstream events */ test_event (pipeline, GST_EVENT_CUSTOM_UPSTREAM, sinkpad, TRUE, srcpad); fail_unless (timediff (&got_event_time, &sent_event_time) < G_USEC_PER_SEC / 2, "GST_EVENT_CUSTOM_UP took too long to reach source: %" G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); test_event (pipeline, GST_EVENT_CUSTOM_BOTH, sinkpad, TRUE, srcpad); fail_unless (timediff (&got_event_time, &sent_event_time) < G_USEC_PER_SEC / 2, "GST_EVENT_CUSTOM_BOTH took too long to reach source: %" G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); test_event (pipeline, GST_EVENT_CUSTOM_BOTH_OOB, sinkpad, TRUE, srcpad); fail_unless (timediff (&got_event_time, &sent_event_time) < G_USEC_PER_SEC / 2, "GST_EVENT_CUSTOM_BOTH_OOB took too long to reach source: %" G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); /* Out of band downstream events */ test_event (pipeline, GST_EVENT_CUSTOM_DOWNSTREAM_OOB, srcpad, FALSE, srcpad); fail_unless (timediff (&got_event_time, &sent_event_time) < G_USEC_PER_SEC / 2, "GST_EVENT_CUSTOM_DS_OOB took too long to reach source: %" G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); test_event (pipeline, GST_EVENT_CUSTOM_BOTH_OOB, srcpad, FALSE, srcpad); fail_unless (timediff (&got_event_time, &sent_event_time) < G_USEC_PER_SEC / 2, "GST_EVENT_CUSTOM_BOTH_OOB took too long to reach source: %" G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); /* In-band downstream events are expected to take at least 1 second * to traverse the the queue */ test_event (pipeline, GST_EVENT_CUSTOM_DOWNSTREAM, srcpad, FALSE, srcpad); fail_unless (timediff (&got_event_time, &sent_event_time) >= G_USEC_PER_SEC / 2, "GST_EVENT_CUSTOM_DS arrived too quickly for an in-band event: %" G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); test_event (pipeline, GST_EVENT_CUSTOM_BOTH, srcpad, FALSE, srcpad); fail_unless (timediff (&got_event_time, &sent_event_time) >= G_USEC_PER_SEC / 2, "GST_EVENT_CUSTOM_BOTH arrived too quickly for an in-band event: %" G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL); gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, GST_CLOCK_TIME_NONE); gst_object_unref (pipeline);}GST_END_TEST;Suite *gst_event_suite (void){ Suite *s = suite_create ("GstEvent"); TCase *tc_chain = tcase_create ("customevents"); tcase_set_timeout (tc_chain, 20); suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, create_custom_events); tcase_add_test (tc_chain, send_custom_events); return s;}GST_CHECK_MAIN (gst_event);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -