mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
dashdemux: Find the current period in a live stream
Start from the correct period on a live stream https://bugzilla.gnome.org/show_bug.cgi?id=737421
This commit is contained in:
parent
306ca0cdf6
commit
95c3fdc193
3 changed files with 67 additions and 9 deletions
|
@ -488,9 +488,37 @@ gst_dash_demux_setup_streams (GstAdaptiveDemux * demux)
|
||||||
{
|
{
|
||||||
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
||||||
gboolean ret = TRUE;
|
gboolean ret = TRUE;
|
||||||
|
GstDateTime *now = NULL;
|
||||||
|
guint period_idx;
|
||||||
|
|
||||||
/* setup video, audio and subtitle streams, starting from first Period */
|
/* setup video, audio and subtitle streams, starting from first Period if
|
||||||
if (!gst_mpd_client_set_period_index (dashdemux->client, 0) ||
|
* non-live */
|
||||||
|
period_idx = 0;
|
||||||
|
if (gst_mpd_client_is_live (dashdemux->client)) {
|
||||||
|
|
||||||
|
/* get period index for period encompassing the current time */
|
||||||
|
now = gst_date_time_new_now_utc ();
|
||||||
|
if (dashdemux->client->mpd_node->suggestedPresentationDelay != -1) {
|
||||||
|
GstDateTime *target = gst_mpd_client_add_time_difference (now,
|
||||||
|
dashdemux->client->mpd_node->suggestedPresentationDelay * -1000);
|
||||||
|
gst_date_time_unref (now);
|
||||||
|
now = target;
|
||||||
|
}
|
||||||
|
period_idx =
|
||||||
|
gst_mpd_client_get_period_index_at_time (dashdemux->client, now);
|
||||||
|
if (period_idx == G_MAXUINT) {
|
||||||
|
#ifndef GST_DISABLE_GST_DEBUG
|
||||||
|
gchar *date_str = gst_date_time_to_iso8601_string (now);
|
||||||
|
GST_DEBUG_OBJECT (demux, "Unable to find live period active at %s",
|
||||||
|
date_str);
|
||||||
|
g_free (date_str);
|
||||||
|
#endif
|
||||||
|
ret = FALSE;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gst_mpd_client_set_period_index (dashdemux->client, period_idx) ||
|
||||||
!gst_dash_demux_setup_all_streams (dashdemux)) {
|
!gst_dash_demux_setup_all_streams (dashdemux)) {
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -500,16 +528,9 @@ gst_dash_demux_setup_streams (GstAdaptiveDemux * demux)
|
||||||
* is closest to current time */
|
* is closest to current time */
|
||||||
if (gst_mpd_client_is_live (dashdemux->client)) {
|
if (gst_mpd_client_is_live (dashdemux->client)) {
|
||||||
GList *iter;
|
GList *iter;
|
||||||
GstDateTime *now = gst_date_time_new_now_utc ();
|
|
||||||
gint seg_idx;
|
gint seg_idx;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (demux, "Seeking to current time of day for live stream ");
|
GST_DEBUG_OBJECT (demux, "Seeking to current time of day for live stream ");
|
||||||
if (dashdemux->client->mpd_node->suggestedPresentationDelay != -1) {
|
|
||||||
GstDateTime *target = gst_mpd_client_add_time_difference (now,
|
|
||||||
dashdemux->client->mpd_node->suggestedPresentationDelay * -1000);
|
|
||||||
gst_date_time_unref (now);
|
|
||||||
now = target;
|
|
||||||
}
|
|
||||||
for (iter = demux->streams; iter; iter = g_list_next (iter)) {
|
for (iter = demux->streams; iter; iter = g_list_next (iter)) {
|
||||||
GstDashDemuxStream *stream = iter->data;
|
GstDashDemuxStream *stream = iter->data;
|
||||||
GstActiveStream *active_stream = stream->active_stream;
|
GstActiveStream *active_stream = stream->active_stream;
|
||||||
|
@ -539,6 +560,8 @@ gst_dash_demux_setup_streams (GstAdaptiveDemux * demux)
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
if (now != NULL)
|
||||||
|
gst_date_time_unref (now);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2598,6 +2598,40 @@ gst_mpdparser_build_URL_from_template (const gchar * url_template,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guint
|
||||||
|
gst_mpd_client_get_period_index_at_time (GstMpdClient * client,
|
||||||
|
GstDateTime * time)
|
||||||
|
{
|
||||||
|
GList *iter;
|
||||||
|
guint period_idx = G_MAXUINT;
|
||||||
|
guint idx;
|
||||||
|
gint64 time_offset;
|
||||||
|
GstDateTime *avail_start =
|
||||||
|
gst_mpd_client_get_availability_start_time (client);
|
||||||
|
GstStreamPeriod *stream_period;
|
||||||
|
|
||||||
|
if (avail_start == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
time_offset = gst_mpd_client_calculate_time_difference (avail_start, time);
|
||||||
|
gst_date_time_unref (avail_start);
|
||||||
|
|
||||||
|
if (time_offset < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (idx = 0, iter = client->periods; iter;
|
||||||
|
idx++, iter = g_list_next (iter)) {
|
||||||
|
stream_period = iter->data;
|
||||||
|
if (stream_period->start <= time_offset
|
||||||
|
&& stream_period->start + stream_period->duration > time_offset) {
|
||||||
|
period_idx = idx;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return period_idx;
|
||||||
|
}
|
||||||
|
|
||||||
static GstStreamPeriod *
|
static GstStreamPeriod *
|
||||||
gst_mpdparser_get_stream_period (GstMpdClient * client)
|
gst_mpdparser_get_stream_period (GstMpdClient * client)
|
||||||
{
|
{
|
||||||
|
|
|
@ -502,6 +502,7 @@ gint gst_mpd_client_get_segment_index_at_time (GstMpdClient *client, GstActiveSt
|
||||||
gint gst_mpd_client_check_time_position (GstMpdClient * client, GstActiveStream * stream, GstClockTime ts, gint64 * diff);
|
gint gst_mpd_client_check_time_position (GstMpdClient * client, GstActiveStream * stream, GstClockTime ts, gint64 * diff);
|
||||||
|
|
||||||
/* Period selection */
|
/* Period selection */
|
||||||
|
guint gst_mpd_client_get_period_index_at_time (GstMpdClient * client, GstDateTime * time);
|
||||||
gboolean gst_mpd_client_set_period_index (GstMpdClient *client, guint period_idx);
|
gboolean gst_mpd_client_set_period_index (GstMpdClient *client, guint period_idx);
|
||||||
gboolean gst_mpd_client_set_period_id (GstMpdClient *client, const gchar * period_id);
|
gboolean gst_mpd_client_set_period_id (GstMpdClient *client, const gchar * period_id);
|
||||||
guint gst_mpd_client_get_period_index (GstMpdClient *client);
|
guint gst_mpd_client_get_period_index (GstMpdClient *client);
|
||||||
|
|
Loading…
Reference in a new issue