From 5192181ef51eca79857746dfea76168017400c22 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Fri, 14 Oct 2022 23:30:59 +1100 Subject: [PATCH] adaptivedemux2: Add most recent data time and offset helper Add a field to the DownloadRequest that reports the most recent time at which data arrived. Update it in the DownloadHelper. Add a method to retrieve the GST_BUFFER_OFFSET() for the DownloadRequest's data buffer (if any). Part-of: --- .../ext/adaptivedemux2/downloadhelper.c | 15 ++++++++------- .../ext/adaptivedemux2/downloadrequest.c | 16 ++++++++++++++++ .../ext/adaptivedemux2/downloadrequest.h | 2 ++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadhelper.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadhelper.c index bd6aa15885..3ef1cae824 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadhelper.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadhelper.c @@ -309,19 +309,20 @@ on_read_ready (GObject * source, GAsyncResult * result, gpointer user_data) } } - if (request->download_start_time == GST_CLOCK_TIME_NONE) { - GST_LOG ("Got first data for URI %s", request->uri); - request->download_start_time = now; - } - if (gst_buffer != NULL) { /* Unsent means cancellation is in progress, so don't override * the state. Otherwise make sure it is LOADING */ if (request->state != DOWNLOAD_REQUEST_STATE_UNSENT) request->state = DOWNLOAD_REQUEST_STATE_LOADING; - GST_LOG ("Adding %u bytes to buffer", - (guint) (gst_buffer_get_size (gst_buffer))); + if (request->download_start_time == GST_CLOCK_TIME_NONE) { + GST_LOG ("Got first data for URI %s", request->uri); + request->download_start_time = now; + } + request->download_newest_data_time = now; + + GST_LOG ("Adding %u bytes to buffer (request URI %s)", + (guint) (gst_buffer_get_size (gst_buffer)), request->uri); download_request_add_buffer (request, gst_buffer); diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.c index ad51c6ff77..878dac1c68 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.c @@ -328,6 +328,22 @@ download_request_get_bytes_available (DownloadRequest * request) return ret; } +guint64 +download_request_get_cur_offset (DownloadRequest * request) +{ + DownloadRequestPrivate *priv = DOWNLOAD_REQUEST_PRIVATE (request); + guint64 ret = GST_BUFFER_OFFSET_NONE; + + g_rec_mutex_lock (&priv->lock); + + if (priv->buffer != NULL) + ret = GST_BUFFER_OFFSET (priv->buffer); + + g_rec_mutex_unlock (&priv->lock); + + return ret; +} + void download_request_set_uri (DownloadRequest * request, const gchar * uri, gint64 range_start, gint64 range_end) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.h index 13827d6fbf..8fbaa000b7 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/downloadrequest.h @@ -68,6 +68,7 @@ struct _DownloadRequest guint64 download_request_time; /* Epoch time when the download started */ guint64 download_start_time; /* Epoch time when the first data for the download arrived */ + guint64 download_newest_data_time; /* Epoch time when the most recent data for the download arrived */ guint64 download_end_time; /* Epoch time when the download finished */ }; @@ -87,6 +88,7 @@ void download_request_add_buffer (DownloadRequest *request, GstBuffer *buffer); GstBuffer * download_request_take_buffer (DownloadRequest *request); GstBuffer * download_request_take_buffer_range (DownloadRequest *request, gint64 range_start, gint64 range_end); guint64 download_request_get_bytes_available (DownloadRequest *request); +guint64 download_request_get_cur_offset (DownloadRequest *request); DownloadRequest * download_request_new (void); DownloadRequest * download_request_new_uri (const gchar * uri);