good: 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-11 14:20:15 +02:00 committed by Sebastian Dröge
parent 3f21c89bb0
commit 8e1c224fbc
12 changed files with 35 additions and 56 deletions

View file

@ -99,21 +99,19 @@ static GstFlowReturn
gst_cpu_report_transform_ip (GstBaseTransform * trans, GstBuffer * buf) gst_cpu_report_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{ {
GstCpuReport *filter; GstCpuReport *filter;
GTimeVal cur_time; GstClockTime cur_time;
clock_t cur_cpu_time; clock_t cur_cpu_time;
GstMessage *msg; GstMessage *msg;
GstStructure *s; GstStructure *s;
gint64 time_taken; GstClockTimeDiff time_taken;
cur_time = g_get_real_time () * GST_USECOND;
g_get_current_time (&cur_time);
cur_cpu_time = clock (); cur_cpu_time = clock ();
filter = GST_CPU_REPORT (trans); filter = GST_CPU_REPORT (trans);
time_taken = GST_TIMEVAL_TO_TIME (cur_time) - time_taken = cur_time - filter->last_time;
GST_TIMEVAL_TO_TIME (filter->last_time);
s = gst_structure_new ("cpu-report", "cpu-time", G_TYPE_DOUBLE, s = gst_structure_new ("cpu-report", "cpu-time", G_TYPE_DOUBLE,
((gdouble) (cur_cpu_time - filter->last_cpu_time)), ((gdouble) (cur_cpu_time - filter->last_cpu_time)),
@ -135,8 +133,7 @@ gst_cpu_report_start (GstBaseTransform * trans)
filter = GST_CPU_REPORT (trans); filter = GST_CPU_REPORT (trans);
g_get_current_time (&filter->last_time); filter->start_time = filter->last_time = g_get_real_time () * GST_USECOND;
filter->start_time = filter->last_time;
filter->last_cpu_time = clock (); filter->last_cpu_time = clock ();
return TRUE; return TRUE;
} }

View file

@ -42,8 +42,8 @@ struct _GstCpuReport
{ {
GstBaseTransform basetransform; GstBaseTransform basetransform;
GTimeVal start_time; GstClockTime start_time;
GTimeVal last_time; GstClockTime last_time;
clock_t last_cpu_time; clock_t last_cpu_time;
}; };

View file

@ -325,7 +325,7 @@ gst_progress_report_do_query (GstProgressReport * filter, GstFormat format,
} }
static void static void
gst_progress_report_report (GstProgressReport * filter, GTimeVal cur_time, gst_progress_report_report (GstProgressReport * filter, gint64 cur_time_s,
GstBuffer * buf) GstBuffer * buf)
{ {
GstFormat try_formats[] = { GST_FORMAT_TIME, GST_FORMAT_BYTES, 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; glong run_time;
gint hh, mm, ss; 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; hh = (run_time / 3600) % 100;
mm = (run_time / 60) % 60; mm = (run_time / 60) % 60;
@ -387,10 +387,9 @@ gst_progress_report_sink_event (GstBaseTransform * trans, GstEvent * event)
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_EOS: 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_s, NULL);
gst_progress_report_report (filter, cur_time, NULL);
break; break;
} }
default: default:
@ -404,23 +403,22 @@ gst_progress_report_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{ {
GstProgressReport *filter; GstProgressReport *filter;
gboolean need_update; 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); filter = GST_PROGRESS_REPORT (trans);
/* Check if update_freq seconds have passed since the last update */ /* Check if update_freq seconds have passed since the last update */
GST_OBJECT_LOCK (filter); GST_OBJECT_LOCK (filter);
need_update = need_update = (cur_time - filter->last_report_s) >= filter->update_freq;
((cur_time.tv_sec - filter->last_report.tv_sec) >= filter->update_freq);
filter->buffer_count++; filter->buffer_count++;
GST_OBJECT_UNLOCK (filter); GST_OBJECT_UNLOCK (filter);
if (need_update) { if (need_update) {
gst_progress_report_report (filter, cur_time, buf); gst_progress_report_report (filter, cur_time, buf);
GST_OBJECT_LOCK (filter); GST_OBJECT_LOCK (filter);
filter->last_report = cur_time; filter->last_report_s = cur_time;
GST_OBJECT_UNLOCK (filter); GST_OBJECT_UNLOCK (filter);
} }
@ -434,8 +432,8 @@ gst_progress_report_start (GstBaseTransform * trans)
filter = GST_PROGRESS_REPORT (trans); filter = GST_PROGRESS_REPORT (trans);
g_get_current_time (&filter->last_report); filter->start_time_s = filter->last_report_s =
filter->start_time = filter->last_report; g_get_real_time () / G_USEC_PER_SEC;
filter->buffer_count = 0; filter->buffer_count = 0;
return TRUE; return TRUE;

View file

@ -48,8 +48,8 @@ struct _GstProgressReport
gint update_freq; gint update_freq;
gboolean silent; gboolean silent;
gboolean do_query; gboolean do_query;
GTimeVal start_time; gint64 start_time_s;
GTimeVal last_report; gint64 last_report_s;
gint64 buffer_count; gint64 buffer_count;
/* Format used for querying. Using a string here because the /* Format used for querying. Using a string here because the

View file

@ -1083,7 +1083,6 @@ tags:
tags_written++; tags_written++;
{ {
GTimeVal tv = { 0, };
time_t secs; time_t secs;
struct tm *tm; struct tm *tm;
gchar *s; gchar *s;
@ -1095,8 +1094,7 @@ tags:
"Aug", "Sep", "Oct", "Nov", "Dec" "Aug", "Sep", "Oct", "Nov", "Dec"
}; };
g_get_current_time (&tv); secs = g_get_real_time () / G_USEC_PER_SEC;
secs = tv.tv_sec;
tm = gmtime (&secs); tm = gmtime (&secs);
s = g_strdup_printf ("%s %s %d %02d:%02d:%02d %d", weekdays[tm->tm_wday], s = g_strdup_printf ("%s %s %d %02d:%02d:%02d %d", weekdays[tm->tm_wday],

View file

@ -78,11 +78,10 @@ atoms_context_free (AtomsContext * context)
guint64 guint64
atoms_get_current_qt_time (void) 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 */ /* 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; LEAP_YEARS_FROM_1904_TO_1970) * SECS_PER_DAY;
} }

View file

@ -14161,12 +14161,12 @@ qtdemux_parse_tree (GstQTDemux * qtdemux)
if (creation_time != 0) { if (creation_time != 0) {
/* Try to use epoch first as it should be faster and more commonly found */ /* Try to use epoch first as it should be faster and more commonly found */
if (creation_time >= QTDEMUX_SECONDS_FROM_1904_TO_1970) { if (creation_time >= QTDEMUX_SECONDS_FROM_1904_TO_1970) {
GTimeVal now; gint64 now_s;
creation_time -= QTDEMUX_SECONDS_FROM_1904_TO_1970; creation_time -= QTDEMUX_SECONDS_FROM_1904_TO_1970;
/* some data cleansing sanity */ /* some data cleansing sanity */
g_get_current_time (&now); now_s = g_get_real_time () / G_USEC_PER_SEC;
if (now.tv_sec + 24 * 3600 < creation_time) { if (now_s + 24 * 3600 < creation_time) {
GST_DEBUG_OBJECT (qtdemux, "discarding bogus future creation time"); GST_DEBUG_OBJECT (qtdemux, "discarding bogus future creation time");
} else { } else {
datetime = gst_date_time_new_from_unix_epoch_utc (creation_time); datetime = gst_date_time_new_from_unix_epoch_utc (creation_time);

View file

@ -2960,7 +2960,6 @@ gst_matroska_mux_start (GstMatroskaMux * mux, GstMatroskaPad * first_pad,
GstClockTime earliest_time = GST_CLOCK_TIME_NONE; GstClockTime earliest_time = GST_CLOCK_TIME_NONE;
GstClockTime duration = 0; GstClockTime duration = 0;
guint32 segment_uid[4]; guint32 segment_uid[4];
GTimeVal time = { 0, 0 };
gchar s_id[32]; gchar s_id[32];
GstToc *toc; GstToc *toc;
@ -3098,8 +3097,8 @@ gst_matroska_mux_start (GstMatroskaMux * mux, GstMatroskaPad * first_pad,
if (mux->writing_app && mux->writing_app[0]) { if (mux->writing_app && mux->writing_app[0]) {
gst_ebml_write_utf8 (ebml, GST_MATROSKA_ID_WRITINGAPP, mux->writing_app); 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,
gst_ebml_write_date (ebml, GST_MATROSKA_ID_DATEUTC, time.tv_sec); g_get_real_time () / G_USEC_PER_SEC);
gst_ebml_write_master_finish (ebml, master); gst_ebml_write_master_finish (ebml, master);
/* tracks */ /* tracks */

View file

@ -1214,11 +1214,8 @@ get_current_times (GstRtpBin * bin, GstClockTime * running_time,
switch (bin->ntp_time_source) { switch (bin->ntp_time_source) {
case GST_RTP_NTP_TIME_SOURCE_NTP: case GST_RTP_NTP_TIME_SOURCE_NTP:
case GST_RTP_NTP_TIME_SOURCE_UNIX:{ case GST_RTP_NTP_TIME_SOURCE_UNIX:{
GTimeVal current;
/* get current NTP time */ /* get current NTP time */
g_get_current_time (&current); ntpns = g_get_real_time () * GST_USECOND;
ntpns = GST_TIMEVAL_TO_TIME (current);
/* add constant to convert from 1970 based time to 1900 based time */ /* add constant to convert from 1970 based time to 1900 based time */
if (bin->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP) if (bin->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP)

View file

@ -1064,11 +1064,8 @@ get_current_times (GstRtpSession * rtpsession, GstClockTime * running_time,
switch (rtpsession->priv->ntp_time_source) { switch (rtpsession->priv->ntp_time_source) {
case GST_RTP_NTP_TIME_SOURCE_NTP: case GST_RTP_NTP_TIME_SOURCE_NTP:
case GST_RTP_NTP_TIME_SOURCE_UNIX:{ case GST_RTP_NTP_TIME_SOURCE_UNIX:{
GTimeVal current;
/* get current NTP time */ /* get current NTP time */
g_get_current_time (&current); ntpns = g_get_real_time () * GST_USECOND;
ntpns = GST_TIMEVAL_TO_TIME (current);
/* add constant to convert from 1970 based time to 1900 based time */ /* add constant to convert from 1970 based time to 1900 based time */
if (rtpsession->priv->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP) if (rtpsession->priv->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP)

View file

@ -211,8 +211,9 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass)
* *
* Get the statistics of the client with destination @host and @port. * Get the statistics of the client with destination @host and @port.
* *
* Returns: a GstStructure: bytes_sent, packets_sent, * Returns: a GstStructure: bytes_sent, packets_sent, connect_time
* connect_time (in epoch seconds), disconnect_time (in epoch seconds) * (in epoch nanoseconds), disconnect_time (in epoch
* nanoseconds)
*/ */
gst_multiudpsink_signals[SIGNAL_GET_STATS] = gst_multiudpsink_signals[SIGNAL_GET_STATS] =
g_signal_new ("get-stats", G_TYPE_FROM_CLASS (klass), 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; GSocketFamily family;
GstUDPClient *client; GstUDPClient *client;
GstUDPClient udpclient; GstUDPClient udpclient;
GTimeVal now;
GList *find; GList *find;
udpclient.host = (gchar *) host; 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); family = g_socket_address_get_family (client->addr);
g_get_current_time (&now); client->connect_time = g_get_real_time () * GST_USECOND;
client->connect_time = GST_TIMEVAL_TO_TIME (now);
if (sink->used_socket) if (sink->used_socket)
gst_multiudpsink_configure_client (sink, client); gst_multiudpsink_configure_client (sink, client);
@ -1619,7 +1618,6 @@ gst_multiudpsink_remove (GstMultiUDPSink * sink, const gchar * host, gint port)
GList *find; GList *find;
GstUDPClient udpclient; GstUDPClient udpclient;
GstUDPClient *client; GstUDPClient *client;
GTimeVal now;
udpclient.host = (gchar *) host; udpclient.host = (gchar *) host;
udpclient.port = port; 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); GST_DEBUG_OBJECT (sink, "remove client with host %s, port %d", host, port);
g_get_current_time (&now); client->disconnect_time = g_get_real_time () * GST_USECOND;
client->disconnect_time = GST_TIMEVAL_TO_TIME (now);
if (socket && sink->auto_multicast if (socket && sink->auto_multicast
&& g_inet_address_get_is_multicast (addr)) { && g_inet_address_get_is_multicast (addr)) {

View file

@ -879,11 +879,8 @@ retry:
gstnow = GST_TIMESPEC_TO_TIME (now); gstnow = GST_TIMESPEC_TO_TIME (now);
if (timestamp > gstnow || (gstnow - timestamp) > (10 * GST_SECOND)) { if (timestamp > gstnow || (gstnow - timestamp) > (10 * GST_SECOND)) {
GTimeVal now;
/* very large diff, fall back to system time */ /* very large diff, fall back to system time */
g_get_current_time (&now); gstnow = g_get_real_time () * GST_USECOND;
gstnow = GST_TIMEVAL_TO_TIME (now);
} }
/* Detect buggy drivers here, and stop using their timestamp. Failing any /* Detect buggy drivers here, and stop using their timestamp. Failing any