From 8e1c224fbc217d43f5b34cf63b3883c871dcecf2 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Fri, 11 Oct 2019 14:20:15 +0200 Subject: [PATCH] good: Avoid usage of deprecated API GTimeval and related functions are now deprecated in glib. Replacement APIs have been present since 2.26 --- gst/debugutils/cpureport.c | 13 +++++-------- gst/debugutils/cpureport.h | 4 ++-- gst/debugutils/progressreport.c | 22 ++++++++++------------ gst/debugutils/progressreport.h | 4 ++-- gst/flv/gstflvmux.c | 4 +--- gst/isomp4/atoms.c | 5 ++--- gst/isomp4/qtdemux.c | 6 +++--- gst/matroska/matroska-mux.c | 5 ++--- gst/rtpmanager/gstrtpbin.c | 5 +---- gst/rtpmanager/gstrtpsession.c | 5 +---- gst/udp/gstmultiudpsink.c | 13 +++++-------- sys/v4l2/gstv4l2src.c | 5 +---- 12 files changed, 35 insertions(+), 56 deletions(-) diff --git a/gst/debugutils/cpureport.c b/gst/debugutils/cpureport.c index f61c38e390..c9e7da3234 100644 --- a/gst/debugutils/cpureport.c +++ b/gst/debugutils/cpureport.c @@ -99,21 +99,19 @@ static GstFlowReturn gst_cpu_report_transform_ip (GstBaseTransform * trans, GstBuffer * buf) { GstCpuReport *filter; - GTimeVal cur_time; + GstClockTime cur_time; clock_t cur_cpu_time; GstMessage *msg; GstStructure *s; - gint64 time_taken; + GstClockTimeDiff time_taken; - - g_get_current_time (&cur_time); + cur_time = g_get_real_time () * GST_USECOND; cur_cpu_time = clock (); filter = GST_CPU_REPORT (trans); - time_taken = GST_TIMEVAL_TO_TIME (cur_time) - - GST_TIMEVAL_TO_TIME (filter->last_time); + time_taken = cur_time - filter->last_time; s = gst_structure_new ("cpu-report", "cpu-time", G_TYPE_DOUBLE, ((gdouble) (cur_cpu_time - filter->last_cpu_time)), @@ -135,8 +133,7 @@ gst_cpu_report_start (GstBaseTransform * trans) filter = GST_CPU_REPORT (trans); - g_get_current_time (&filter->last_time); - filter->start_time = filter->last_time; + filter->start_time = filter->last_time = g_get_real_time () * GST_USECOND; filter->last_cpu_time = clock (); return TRUE; } diff --git a/gst/debugutils/cpureport.h b/gst/debugutils/cpureport.h index 35055598d4..1735e733cc 100644 --- a/gst/debugutils/cpureport.h +++ b/gst/debugutils/cpureport.h @@ -42,8 +42,8 @@ struct _GstCpuReport { GstBaseTransform basetransform; - GTimeVal start_time; - GTimeVal last_time; + GstClockTime start_time; + GstClockTime last_time; clock_t last_cpu_time; }; diff --git a/gst/debugutils/progressreport.c b/gst/debugutils/progressreport.c index 2767f29404..7de0bfb905 100644 --- a/gst/debugutils/progressreport.c +++ b/gst/debugutils/progressreport.c @@ -325,7 +325,7 @@ gst_progress_report_do_query (GstProgressReport * filter, GstFormat format, } static void -gst_progress_report_report (GstProgressReport * filter, GTimeVal cur_time, +gst_progress_report_report (GstProgressReport * filter, gint64 cur_time_s, GstBuffer * buf) { GstFormat try_formats[] = { GST_FORMAT_TIME, GST_FORMAT_BYTES, @@ -338,7 +338,7 @@ gst_progress_report_report (GstProgressReport * filter, GTimeVal cur_time, glong run_time; gint hh, mm, ss; - run_time = cur_time.tv_sec - filter->start_time.tv_sec; + run_time = cur_time_s - filter->start_time_s; hh = (run_time / 3600) % 100; mm = (run_time / 60) % 60; @@ -387,10 +387,9 @@ gst_progress_report_sink_event (GstBaseTransform * trans, GstEvent * event) switch (GST_EVENT_TYPE (event)) { case GST_EVENT_EOS: { - GTimeVal cur_time; + gint64 cur_time_s = g_get_real_time () / G_USEC_PER_SEC; - g_get_current_time (&cur_time); - gst_progress_report_report (filter, cur_time, NULL); + gst_progress_report_report (filter, cur_time_s, NULL); break; } default: @@ -404,23 +403,22 @@ gst_progress_report_transform_ip (GstBaseTransform * trans, GstBuffer * buf) { GstProgressReport *filter; gboolean need_update; - GTimeVal cur_time; + gint64 cur_time; - g_get_current_time (&cur_time); + cur_time = g_get_real_time () / G_USEC_PER_SEC; filter = GST_PROGRESS_REPORT (trans); /* Check if update_freq seconds have passed since the last update */ GST_OBJECT_LOCK (filter); - need_update = - ((cur_time.tv_sec - filter->last_report.tv_sec) >= filter->update_freq); + need_update = (cur_time - filter->last_report_s) >= filter->update_freq; filter->buffer_count++; GST_OBJECT_UNLOCK (filter); if (need_update) { gst_progress_report_report (filter, cur_time, buf); GST_OBJECT_LOCK (filter); - filter->last_report = cur_time; + filter->last_report_s = cur_time; GST_OBJECT_UNLOCK (filter); } @@ -434,8 +432,8 @@ gst_progress_report_start (GstBaseTransform * trans) filter = GST_PROGRESS_REPORT (trans); - g_get_current_time (&filter->last_report); - filter->start_time = filter->last_report; + filter->start_time_s = filter->last_report_s = + g_get_real_time () / G_USEC_PER_SEC; filter->buffer_count = 0; return TRUE; diff --git a/gst/debugutils/progressreport.h b/gst/debugutils/progressreport.h index d99093779b..904ba38699 100644 --- a/gst/debugutils/progressreport.h +++ b/gst/debugutils/progressreport.h @@ -48,8 +48,8 @@ struct _GstProgressReport gint update_freq; gboolean silent; gboolean do_query; - GTimeVal start_time; - GTimeVal last_report; + gint64 start_time_s; + gint64 last_report_s; gint64 buffer_count; /* Format used for querying. Using a string here because the diff --git a/gst/flv/gstflvmux.c b/gst/flv/gstflvmux.c index 4053f8a742..00307c681b 100644 --- a/gst/flv/gstflvmux.c +++ b/gst/flv/gstflvmux.c @@ -1083,7 +1083,6 @@ tags: tags_written++; { - GTimeVal tv = { 0, }; time_t secs; struct tm *tm; gchar *s; @@ -1095,8 +1094,7 @@ tags: "Aug", "Sep", "Oct", "Nov", "Dec" }; - g_get_current_time (&tv); - secs = tv.tv_sec; + secs = g_get_real_time () / G_USEC_PER_SEC; tm = gmtime (&secs); s = g_strdup_printf ("%s %s %d %02d:%02d:%02d %d", weekdays[tm->tm_wday], diff --git a/gst/isomp4/atoms.c b/gst/isomp4/atoms.c index c525c20781..e1441d468c 100644 --- a/gst/isomp4/atoms.c +++ b/gst/isomp4/atoms.c @@ -78,11 +78,10 @@ atoms_context_free (AtomsContext * context) guint64 atoms_get_current_qt_time (void) { - GTimeVal timeval; + gint64 curtime_s = g_get_real_time () / G_USEC_PER_SEC; - g_get_current_time (&timeval); /* FIXME this should use UTC coordinated time */ - return timeval.tv_sec + (((1970 - 1904) * (guint64) 365) + + return curtime_s + (((1970 - 1904) * (guint64) 365) + LEAP_YEARS_FROM_1904_TO_1970) * SECS_PER_DAY; } diff --git a/gst/isomp4/qtdemux.c b/gst/isomp4/qtdemux.c index 2c24040d31..f7b4f3c12c 100644 --- a/gst/isomp4/qtdemux.c +++ b/gst/isomp4/qtdemux.c @@ -14161,12 +14161,12 @@ qtdemux_parse_tree (GstQTDemux * qtdemux) if (creation_time != 0) { /* Try to use epoch first as it should be faster and more commonly found */ if (creation_time >= QTDEMUX_SECONDS_FROM_1904_TO_1970) { - GTimeVal now; + gint64 now_s; creation_time -= QTDEMUX_SECONDS_FROM_1904_TO_1970; /* some data cleansing sanity */ - g_get_current_time (&now); - if (now.tv_sec + 24 * 3600 < creation_time) { + now_s = g_get_real_time () / G_USEC_PER_SEC; + if (now_s + 24 * 3600 < creation_time) { GST_DEBUG_OBJECT (qtdemux, "discarding bogus future creation time"); } else { datetime = gst_date_time_new_from_unix_epoch_utc (creation_time); diff --git a/gst/matroska/matroska-mux.c b/gst/matroska/matroska-mux.c index 1a5d5ca1b2..e02cb39524 100644 --- a/gst/matroska/matroska-mux.c +++ b/gst/matroska/matroska-mux.c @@ -2960,7 +2960,6 @@ gst_matroska_mux_start (GstMatroskaMux * mux, GstMatroskaPad * first_pad, GstClockTime earliest_time = GST_CLOCK_TIME_NONE; GstClockTime duration = 0; guint32 segment_uid[4]; - GTimeVal time = { 0, 0 }; gchar s_id[32]; GstToc *toc; @@ -3098,8 +3097,8 @@ gst_matroska_mux_start (GstMatroskaMux * mux, GstMatroskaPad * first_pad, if (mux->writing_app && mux->writing_app[0]) { gst_ebml_write_utf8 (ebml, GST_MATROSKA_ID_WRITINGAPP, mux->writing_app); } - g_get_current_time (&time); - gst_ebml_write_date (ebml, GST_MATROSKA_ID_DATEUTC, time.tv_sec); + gst_ebml_write_date (ebml, GST_MATROSKA_ID_DATEUTC, + g_get_real_time () / G_USEC_PER_SEC); gst_ebml_write_master_finish (ebml, master); /* tracks */ diff --git a/gst/rtpmanager/gstrtpbin.c b/gst/rtpmanager/gstrtpbin.c index d7d5ef3044..ebcba9e575 100644 --- a/gst/rtpmanager/gstrtpbin.c +++ b/gst/rtpmanager/gstrtpbin.c @@ -1214,11 +1214,8 @@ get_current_times (GstRtpBin * bin, GstClockTime * running_time, switch (bin->ntp_time_source) { case GST_RTP_NTP_TIME_SOURCE_NTP: case GST_RTP_NTP_TIME_SOURCE_UNIX:{ - GTimeVal current; - /* get current NTP time */ - g_get_current_time (¤t); - ntpns = GST_TIMEVAL_TO_TIME (current); + ntpns = g_get_real_time () * GST_USECOND; /* add constant to convert from 1970 based time to 1900 based time */ if (bin->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP) diff --git a/gst/rtpmanager/gstrtpsession.c b/gst/rtpmanager/gstrtpsession.c index b8b2b73a35..6825e3aff9 100644 --- a/gst/rtpmanager/gstrtpsession.c +++ b/gst/rtpmanager/gstrtpsession.c @@ -1064,11 +1064,8 @@ get_current_times (GstRtpSession * rtpsession, GstClockTime * running_time, switch (rtpsession->priv->ntp_time_source) { case GST_RTP_NTP_TIME_SOURCE_NTP: case GST_RTP_NTP_TIME_SOURCE_UNIX:{ - GTimeVal current; - /* get current NTP time */ - g_get_current_time (¤t); - ntpns = GST_TIMEVAL_TO_TIME (current); + ntpns = g_get_real_time () * GST_USECOND; /* add constant to convert from 1970 based time to 1900 based time */ if (rtpsession->priv->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP) diff --git a/gst/udp/gstmultiudpsink.c b/gst/udp/gstmultiudpsink.c index f7aa31165d..3caa8792e0 100644 --- a/gst/udp/gstmultiudpsink.c +++ b/gst/udp/gstmultiudpsink.c @@ -211,8 +211,9 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass) * * Get the statistics of the client with destination @host and @port. * - * Returns: a GstStructure: bytes_sent, packets_sent, - * connect_time (in epoch seconds), disconnect_time (in epoch seconds) + * Returns: a GstStructure: bytes_sent, packets_sent, connect_time + * (in epoch nanoseconds), disconnect_time (in epoch + * nanoseconds) */ gst_multiudpsink_signals[SIGNAL_GET_STATS] = g_signal_new ("get-stats", G_TYPE_FROM_CLASS (klass), @@ -1525,7 +1526,6 @@ gst_multiudpsink_add_internal (GstMultiUDPSink * sink, const gchar * host, GSocketFamily family; GstUDPClient *client; GstUDPClient udpclient; - GTimeVal now; GList *find; udpclient.host = (gchar *) host; @@ -1560,8 +1560,7 @@ gst_multiudpsink_add_internal (GstMultiUDPSink * sink, const gchar * host, family = g_socket_address_get_family (client->addr); - g_get_current_time (&now); - client->connect_time = GST_TIMEVAL_TO_TIME (now); + client->connect_time = g_get_real_time () * GST_USECOND; if (sink->used_socket) gst_multiudpsink_configure_client (sink, client); @@ -1619,7 +1618,6 @@ gst_multiudpsink_remove (GstMultiUDPSink * sink, const gchar * host, gint port) GList *find; GstUDPClient udpclient; GstUDPClient *client; - GTimeVal now; udpclient.host = (gchar *) host; udpclient.port = port; @@ -1656,8 +1654,7 @@ gst_multiudpsink_remove (GstMultiUDPSink * sink, const gchar * host, gint port) GST_DEBUG_OBJECT (sink, "remove client with host %s, port %d", host, port); - g_get_current_time (&now); - client->disconnect_time = GST_TIMEVAL_TO_TIME (now); + client->disconnect_time = g_get_real_time () * GST_USECOND; if (socket && sink->auto_multicast && g_inet_address_get_is_multicast (addr)) { diff --git a/sys/v4l2/gstv4l2src.c b/sys/v4l2/gstv4l2src.c index aebb1839d0..fd35a5272b 100644 --- a/sys/v4l2/gstv4l2src.c +++ b/sys/v4l2/gstv4l2src.c @@ -879,11 +879,8 @@ retry: gstnow = GST_TIMESPEC_TO_TIME (now); if (timestamp > gstnow || (gstnow - timestamp) > (10 * GST_SECOND)) { - GTimeVal now; - /* very large diff, fall back to system time */ - g_get_current_time (&now); - gstnow = GST_TIMEVAL_TO_TIME (now); + gstnow = g_get_real_time () * GST_USECOND; } /* Detect buggy drivers here, and stop using their timestamp. Failing any