Bug 975928 - Use our estimate for MP3 duration rather than GStreamer's for buffered range end when fully buffered in MP3/GStreamer. r=alessandro.d
authorChris Pearce <cpearce@mozilla.com>
Wed, 26 Feb 2014 13:36:54 +1300
changeset 170935 0ad7988d53c994f7c4a31facfee80d1507959df4
parent 170934 59f6a07a619a71cce1f32442277a2c3b24f2fc34
child 170936 1fffb30a79f2d476d7e6a977ce44fbd947ac40dc
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersalessandro
bugs975928
milestone30.0a1
Bug 975928 - Use our estimate for MP3 duration rather than GStreamer's for buffered range end when fully buffered in MP3/GStreamer. r=alessandro.d
content/media/gstreamer/GStreamerReader.cpp
content/media/gstreamer/GStreamerReader.h
--- a/content/media/gstreamer/GStreamerReader.cpp
+++ b/content/media/gstreamer/GStreamerReader.cpp
@@ -784,17 +784,21 @@ nsresult GStreamerReader::GetBuffered(do
   MediaResource* resource = mDecoder->GetResource();
   nsTArray<MediaByteRange> ranges;
   resource->GetCachedRanges(ranges);
 
   if (resource->IsDataCachedToEndOfResource(0)) {
     /* fast path for local or completely cached files */
     gint64 duration = 0;
 
-    duration = QueryDuration();
+    {
+      ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
+      duration = mDecoder->GetMediaDuration();
+    }
+
     double end = (double) duration / GST_MSECOND;
     LOG(PR_LOG_DEBUG, "complete range [0, %f] for [0, %li]",
           end, resource->GetLength());
     aBuffered->Add(0, end);
     return NS_OK;
   }
 
   for(uint32_t index = 0; index < ranges.Length(); index++) {
@@ -885,48 +889,16 @@ void GStreamerReader::ReadAndPushData(gu
 
   /* Ensure offset change is consistent in this function.
    * If there are other stream operations on another thread at the same time,
    * it will disturb the GStreamer state machine.
    */
   MOZ_ASSERT(offset1 + bytesRead == offset2);
 }
 
-int64_t GStreamerReader::QueryDuration()
-{
-  gint64 duration = 0;
-  GstFormat format = GST_FORMAT_TIME;
-
-#if GST_VERSION_MAJOR >= 1
-  if (gst_element_query_duration(GST_ELEMENT(mPlayBin),
-      format, &duration)) {
-#else
-  if (gst_element_query_duration(GST_ELEMENT(mPlayBin),
-      &format, &duration)) {
-#endif
-    if (format == GST_FORMAT_TIME) {
-      LOG(PR_LOG_DEBUG, "pipeline duration %" GST_TIME_FORMAT,
-            GST_TIME_ARGS (duration));
-      duration = GST_TIME_AS_USECONDS (duration);
-    }
-  }
-
-  {
-    ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
-    int64_t media_duration = mDecoder->GetMediaDuration();
-    if (media_duration != -1 && media_duration > duration) {
-      // We decoded more than the reported duration (which could be estimated)
-      LOG(PR_LOG_DEBUG, "decoded duration > estimated duration");
-      duration = media_duration;
-    }
-  }
-
-  return duration;
-}
-
 void GStreamerReader::NeedDataCb(GstAppSrc* aSrc,
                                  guint aLength,
                                  gpointer aUserData)
 {
   GStreamerReader* reader = reinterpret_cast<GStreamerReader*>(aUserData);
   reader->NeedData(aSrc, aLength);
 }
 
--- a/content/media/gstreamer/GStreamerReader.h
+++ b/content/media/gstreamer/GStreamerReader.h
@@ -66,17 +66,16 @@ public:
     return mInfo.HasVideo();
   }
 
   layers::ImageContainer* GetImageContainer() { return mDecoder->GetImageContainer(); }
 
 private:
 
   void ReadAndPushData(guint aLength);
-  int64_t QueryDuration();
   nsRefPtr<layers::PlanarYCbCrImage> GetImageFromBuffer(GstBuffer* aBuffer);
   void CopyIntoImageBuffer(GstBuffer *aBuffer, GstBuffer** aOutBuffer, nsRefPtr<layers::PlanarYCbCrImage> &image);
   GstCaps* BuildAudioSinkCaps();
   void InstallPadCallbacks();
 
 #if GST_VERSION_MAJOR >= 1
   void ImageDataFromVideoFrame(GstVideoFrame *aFrame, layers::PlanarYCbCrImage::Data *aData);
 #endif