Bug 1180214 - Part 3: Do not override known duration with approximated one. r=edwin, a=ritu
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 19 Aug 2015 15:47:57 +1000
changeset 288910 75c607b4bce13e2a174d42cf05f259027544cde5
parent 288909 294ec17f7f4661a3372dc5748b55e8bfcecec397
child 288911 87594f1a9a2189e7dd9fe1629acac555b52fdb36
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin, ritu
bugs1180214
milestone42.0a2
Bug 1180214 - Part 3: Do not override known duration with approximated one. r=edwin, a=ritu Some gstreamer plugin return nonsensical values
dom/media/gstreamer/GStreamerReader.cpp
--- a/dom/media/gstreamer/GStreamerReader.cpp
+++ b/dom/media/gstreamer/GStreamerReader.cpp
@@ -898,33 +898,49 @@ media::TimeIntervals GStreamerReader::Ge
       media::TimeInterval(media::TimeUnit::FromMicroseconds(0),
                           media::TimeUnit::FromMicroseconds(duration));
     return buffered;
   }
 
   for(uint32_t index = 0; index < ranges.Length(); index++) {
     int64_t startOffset = ranges[index].mStart;
     int64_t endOffset = ranges[index].mEnd;
-    gint64 startTime, endTime;
+    gint64 startTime, endTime, duration;
+    bool haveDuration = false;
 
 #if GST_VERSION_MAJOR >= 1
     if (!gst_element_query_convert(GST_ELEMENT(mPlayBin), GST_FORMAT_BYTES,
       startOffset, GST_FORMAT_TIME, &startTime))
       continue;
     if (!gst_element_query_convert(GST_ELEMENT(mPlayBin), GST_FORMAT_BYTES,
       endOffset, GST_FORMAT_TIME, &endTime))
       continue;
+    if (gst_element_query_duration(GST_ELEMENT(mPlayBin),
+      GST_FORMAT_TIME, &duration)) {
+      haveDuration = true;
+    }
 #else
     if (!gst_element_query_convert(GST_ELEMENT(mPlayBin), GST_FORMAT_BYTES,
       startOffset, &format, &startTime) || format != GST_FORMAT_TIME)
       continue;
     if (!gst_element_query_convert(GST_ELEMENT(mPlayBin), GST_FORMAT_BYTES,
       endOffset, &format, &endTime) || format != GST_FORMAT_TIME)
       continue;
+    if (gst_element_query_duration(GST_ELEMENT(mPlayBin),
+      &format, &duration) && format == GST_FORMAT_TIME) {
+      haveDuration = true;
+    }
 #endif
+    // Check that the estimated time doesn't go beyond known duration
+    // as this indicates a buggy gst plugin.
+    if (haveDuration && endTime > duration) {
+      LOG(LogLevel::Debug, "Have duration %" GST_TIME_FORMAT "contradicting endTime %" GST_TIME_FORMAT,
+          GST_TIME_ARGS(duration), GST_TIME_ARGS(endTime));
+      endTime = std::min(endTime, duration);
+    }
 
     LOG(LogLevel::Debug, "adding range [%f, %f] for [%li %li] size %li",
         (double) GST_TIME_AS_USECONDS (startTime) / GST_MSECOND,
         (double) GST_TIME_AS_USECONDS (endTime) / GST_MSECOND,
         startOffset, endOffset, GetDataLength());
     buffered +=
       media::TimeInterval(media::TimeUnit::FromMicroseconds(GST_TIME_AS_USECONDS(startTime)),
                           media::TimeUnit::FromMicroseconds(GST_TIME_AS_USECONDS(endTime)));