dashdemux: reuse seeking function to reduce repeated code
authorThiago Santos <thiagoss@osg.samsung.com>
Fri, 8 May 2015 19:49:02 +0000 (16:49 -0300)
committerThiago Santos <thiagoss@osg.samsung.com>
Wed, 13 May 2015 16:35:14 +0000 (13:35 -0300)
Instead of writing a seek routine, just use the mpdparser function.

Also remove function that is not needed anymore

ext/dash/gstdashdemux.c
ext/dash/gstmpdparser.c
ext/dash/gstmpdparser.h

index b202347..060f274 100644 (file)
@@ -591,30 +591,13 @@ gst_dash_demux_setup_streams (GstAdaptiveDemux * demux)
   /* If stream is live, try to find the segment that
    * is closest to current time */
   if (gst_mpd_client_is_live (dashdemux->client)) {
-    GList *iter;
-    gint seg_idx;
+    GDateTime *gnow;
 
     GST_DEBUG_OBJECT (demux, "Seeking to current time of day for live stream ");
-    for (iter = demux->next_streams; iter; iter = g_list_next (iter)) {
-      GstDashDemuxStream *stream = iter->data;
-      GstActiveStream *active_stream = stream->active_stream;
-
-      /* Get segment index corresponding to current time. */
-      seg_idx =
-          gst_mpd_client_get_segment_index_at_time (dashdemux->client,
-          active_stream, now);
-      if (seg_idx < 0) {
-        GST_WARNING_OBJECT (demux,
-            "Failed to find a segment that is available "
-            "at this point in time for stream %d.", stream->index);
-        seg_idx = 0;
-      }
-      GST_INFO_OBJECT (demux,
-          "Segment index corresponding to current time for stream "
-          "%d is %d.", stream->index, seg_idx);
-      gst_mpd_client_set_segment_index (active_stream, seg_idx);
-    }
 
+    gnow = gst_date_time_to_g_date_time (now);
+    gst_mpd_client_seek_to_time (dashdemux->client, gnow);
+    g_date_time_unref (gnow);
   } else {
     GST_DEBUG_OBJECT (demux, "Seeking to first segment for on-demand stream ");
 
index 5243b85..9b2015f 100644 (file)
@@ -3527,42 +3527,6 @@ gst_mpd_client_add_time_difference (GstDateTime * t1, gint64 usecs)
   return rv;
 }
 
-gint
-gst_mpd_client_get_segment_index_at_time (GstMpdClient * client,
-    GstActiveStream * stream, const GstDateTime * time)
-{
-  GstClockTime seg_duration;
-  gint64 diff;
-  GstDateTime *avail_start =
-      gst_mpd_client_get_availability_start_time (client);
-  GstStreamPeriod *stream_period = gst_mpdparser_get_stream_period (client);
-
-  if (avail_start == NULL)
-    return -1;
-
-  if (stream_period && stream_period->period) {
-    GstDateTime *t;
-
-    t = gst_mpd_client_add_time_difference (avail_start,
-        stream_period->period->start * 1000);
-    gst_date_time_unref (avail_start);
-    avail_start = t;
-  }
-  diff = gst_mpd_client_calculate_time_difference (avail_start, time);
-  gst_date_time_unref (avail_start);
-
-  if (diff < 0)
-    return -2;
-  if (diff > gst_mpd_client_get_media_presentation_duration (client))
-    return -3;
-
-  /* TODO: Assumes all fragments are roughly the same duration */
-  seg_duration = gst_mpd_client_get_next_fragment_duration (client, stream);
-  if (seg_duration == 0)
-    return -1;
-  return diff / seg_duration;
-}
-
 static GstDateTime *
 gst_mpd_client_get_availability_start_time (GstMpdClient * client)
 {
index 7298d3c..98ac1b2 100644 (file)
@@ -505,7 +505,6 @@ gboolean gst_mpd_client_is_live (GstMpdClient * client);
 gboolean gst_mpd_client_stream_seek (GstMpdClient * client, GstActiveStream * stream, GstClockTime ts);
 gboolean gst_mpd_client_seek_to_time (GstMpdClient * client, GDateTime * time);
 GstDateTime *gst_mpd_client_add_time_difference (GstDateTime * t1, gint64 usecs);
-gint gst_mpd_client_get_segment_index_at_time (GstMpdClient *client, GstActiveStream * stream, const GstDateTime *time);
 gint gst_mpd_client_check_time_position (GstMpdClient * client, GstActiveStream * stream, GstClockTime ts, gint64 * diff);
 GstClockTime gst_mpd_parser_get_stream_presentation_offset (GstMpdClient *client, guint stream_idx);