core: Avoid usage of deprecated API

GTimeval and related functions are now deprecated in glib.
Replacement APIs have been present since 2.26
This commit is contained in:
Edward Hervey 2019-10-10 15:53:16 +02:00 committed by Edward Hervey
parent e17bde51b3
commit 6babf1f086
3 changed files with 29 additions and 44 deletions

View file

@ -503,7 +503,7 @@ gst_bus_timed_pop_filtered (GstBus * bus, GstClockTime timeout,
GstMessageType types) GstMessageType types)
{ {
GstMessage *message; GstMessage *message;
GTimeVal now, then; gint64 now, then;
gboolean first_round = TRUE; gboolean first_round = TRUE;
GstClockTime elapsed = 0; GstClockTime elapsed = 0;
@ -563,12 +563,12 @@ gst_bus_timed_pop_filtered (GstBus * bus, GstClockTime timeout,
else if (timeout != GST_CLOCK_TIME_NONE) { else if (timeout != GST_CLOCK_TIME_NONE) {
if (first_round) { if (first_round) {
g_get_current_time (&then); then = g_get_monotonic_time ();
first_round = FALSE; first_round = FALSE;
} else { } else {
g_get_current_time (&now); now = g_get_monotonic_time ();
elapsed = GST_TIMEVAL_TO_TIME (now) - GST_TIMEVAL_TO_TIME (then); elapsed = (now - then) * GST_USECOND;
if (elapsed > timeout) if (elapsed > timeout)
break; break;

View file

@ -178,13 +178,12 @@ GST_END_TEST;
GST_START_TEST (test_GstDateTime_get_microsecond) GST_START_TEST (test_GstDateTime_get_microsecond)
{ {
GTimeVal tv; gint64 now_us;
GstDateTime *dt; GstDateTime *dt;
g_get_current_time (&tv); now_us = g_get_real_time () % GST_USECOND;
dt = gst_date_time_new (0, 2010, 7, 15, 11, 12, dt = gst_date_time_new (0, 2010, 7, 15, 11, 12, 13 + (now_us / 1000000.0));
13 + (tv.tv_usec / 1000000.0)); assert_almost_equals_int (now_us, gst_date_time_get_microsecond (dt));
assert_almost_equals_int (tv.tv_usec, gst_date_time_get_microsecond (dt));
gst_date_time_unref (dt); gst_date_time_unref (dt);
} }

View file

@ -433,9 +433,10 @@ GST_START_TEST (create_events)
GST_END_TEST; GST_END_TEST;
static GTimeVal sent_event_time;
static GstEvent *got_event_before_q, *got_event_after_q; static GstEvent *got_event_before_q, *got_event_after_q;
static GTimeVal got_event_time; /* both time are in microseconds */
static gint64 sent_event_time;
static gint64 got_event_time;
static GstPadProbeReturn static GstPadProbeReturn
event_probe (GstPad * pad, GstPadProbeInfo * info, gpointer user_data) event_probe (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
@ -455,7 +456,7 @@ event_probe (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
if (got_event_before_q != NULL) if (got_event_before_q != NULL)
break; break;
gst_event_ref ((GstEvent *) data); gst_event_ref ((GstEvent *) data);
g_get_current_time (&got_event_time); got_event_time = g_get_real_time ();
got_event_before_q = GST_EVENT (data); got_event_before_q = GST_EVENT (data);
break; break;
default: default:
@ -470,7 +471,7 @@ event_probe (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
if (got_event_after_q != NULL) if (got_event_after_q != NULL)
break; break;
gst_event_ref ((GstEvent *) data); gst_event_ref ((GstEvent *) data);
g_get_current_time (&got_event_time); got_event_time = g_get_real_time ();
got_event_after_q = GST_EVENT (data); got_event_after_q = GST_EVENT (data);
break; break;
default: default:
@ -559,9 +560,8 @@ static void test_event
event = gst_event_new_custom (type, event = gst_event_new_custom (type,
gst_structure_new_empty ("application/x-custom")); gst_structure_new_empty ("application/x-custom"));
g_get_current_time (&sent_event_time); sent_event_time = g_get_real_time ();
got_event_time.tv_sec = 0; got_event_time = 0;
got_event_time.tv_usec = 0;
signal_data_init (&data); signal_data_init (&data);
@ -617,13 +617,6 @@ static void test_event
signal_data_cleanup (&data); signal_data_cleanup (&data);
} }
static gint64
timediff (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) GST_START_TEST (send_custom_events)
{ {
/* Run some tests on custom events. Checking for serialisation and whatnot. /* Run some tests on custom events. Checking for serialisation and whatnot.
@ -660,49 +653,42 @@ GST_START_TEST (send_custom_events)
/* Upstream events */ /* Upstream events */
test_event (pipeline, GST_EVENT_CUSTOM_UPSTREAM, sinkpad, TRUE, srcpad); test_event (pipeline, GST_EVENT_CUSTOM_UPSTREAM, sinkpad, TRUE, srcpad);
fail_unless (timediff (&got_event_time, fail_unless ((got_event_time - sent_event_time) < G_USEC_PER_SEC / 2,
&sent_event_time) < G_USEC_PER_SEC / 2,
"GST_EVENT_CUSTOM_UP took too long to reach source: %" "GST_EVENT_CUSTOM_UP took too long to reach source: %"
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); G_GINT64_FORMAT " us", got_event_time - sent_event_time);
test_event (pipeline, GST_EVENT_CUSTOM_BOTH, sinkpad, TRUE, srcpad); test_event (pipeline, GST_EVENT_CUSTOM_BOTH, sinkpad, TRUE, srcpad);
fail_unless (timediff (&got_event_time, fail_unless ((got_event_time - sent_event_time) < G_USEC_PER_SEC / 2,
&sent_event_time) < G_USEC_PER_SEC / 2,
"GST_EVENT_CUSTOM_BOTH took too long to reach source: %" "GST_EVENT_CUSTOM_BOTH took too long to reach source: %"
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); G_GINT64_FORMAT " us", got_event_time - sent_event_time);
test_event (pipeline, GST_EVENT_CUSTOM_BOTH_OOB, sinkpad, TRUE, srcpad); test_event (pipeline, GST_EVENT_CUSTOM_BOTH_OOB, sinkpad, TRUE, srcpad);
fail_unless (timediff (&got_event_time, fail_unless ((got_event_time - sent_event_time) < G_USEC_PER_SEC / 2,
&sent_event_time) < G_USEC_PER_SEC / 2,
"GST_EVENT_CUSTOM_BOTH_OOB took too long to reach source: %" "GST_EVENT_CUSTOM_BOTH_OOB took too long to reach source: %"
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); G_GINT64_FORMAT " us", got_event_time - sent_event_time);
/* Out of band downstream events */ /* Out of band downstream events */
test_event (pipeline, GST_EVENT_CUSTOM_DOWNSTREAM_OOB, srcpad, FALSE, srcpad); test_event (pipeline, GST_EVENT_CUSTOM_DOWNSTREAM_OOB, srcpad, FALSE, srcpad);
fail_unless (timediff (&got_event_time, fail_unless ((got_event_time - sent_event_time) < G_USEC_PER_SEC / 2,
&sent_event_time) < G_USEC_PER_SEC / 2,
"GST_EVENT_CUSTOM_DS_OOB took too long to reach source: %" "GST_EVENT_CUSTOM_DS_OOB took too long to reach source: %"
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); G_GINT64_FORMAT " us", got_event_time - sent_event_time);
test_event (pipeline, GST_EVENT_CUSTOM_BOTH_OOB, srcpad, FALSE, srcpad); test_event (pipeline, GST_EVENT_CUSTOM_BOTH_OOB, srcpad, FALSE, srcpad);
fail_unless (timediff (&got_event_time, fail_unless ((got_event_time - sent_event_time) < G_USEC_PER_SEC / 2,
&sent_event_time) < G_USEC_PER_SEC / 2,
"GST_EVENT_CUSTOM_BOTH_OOB took too long to reach source: %" "GST_EVENT_CUSTOM_BOTH_OOB took too long to reach source: %"
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); G_GINT64_FORMAT " us", got_event_time - sent_event_time);
/* In-band downstream events are expected to take at least 1 second /* In-band downstream events are expected to take at least 1 second
* to traverse the queue */ * to traverse the queue */
test_event (pipeline, GST_EVENT_CUSTOM_DOWNSTREAM, srcpad, FALSE, srcpad); test_event (pipeline, GST_EVENT_CUSTOM_DOWNSTREAM, srcpad, FALSE, srcpad);
fail_unless (timediff (&got_event_time, fail_unless ((got_event_time - sent_event_time) >= G_USEC_PER_SEC / 2,
&sent_event_time) >= G_USEC_PER_SEC / 2,
"GST_EVENT_CUSTOM_DS arrived too quickly for an in-band event: %" "GST_EVENT_CUSTOM_DS arrived too quickly for an in-band event: %"
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); G_GINT64_FORMAT " us", got_event_time - sent_event_time);
test_event (pipeline, GST_EVENT_CUSTOM_BOTH, srcpad, FALSE, srcpad); test_event (pipeline, GST_EVENT_CUSTOM_BOTH, srcpad, FALSE, srcpad);
fail_unless (timediff (&got_event_time, fail_unless ((got_event_time - sent_event_time) >= G_USEC_PER_SEC / 2,
&sent_event_time) >= G_USEC_PER_SEC / 2,
"GST_EVENT_CUSTOM_BOTH arrived too quickly for an in-band event: %" "GST_EVENT_CUSTOM_BOTH arrived too quickly for an in-band event: %"
G_GINT64_FORMAT " us", timediff (&got_event_time, &sent_event_time)); G_GINT64_FORMAT " us", got_event_time - sent_event_time);
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL); gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL,