Fix memory leak in GStreamer code
authorCarlos Garcia Campos <carlosgc@webkit.org>
Fri, 6 Mar 2015 07:33:11 +0000 (07:33 +0000)
committerAlberto Garcia <berto@igalia.com>
Fri, 6 Mar 2015 07:33:11 +0000 (07:33 +0000)
===================================================================

Gbp-Pq: Name fix-gstreamer-leak.patch

Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayerPrivate.h
Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h

index a7f4b1eafb2357db9b29e62991f577a9663846af..b81d807270bb959c61727585bbd67ce6f3d9bd25 100644 (file)
@@ -130,7 +130,7 @@ public:
     virtual double minTimeSeekable() const { return 0; }
     virtual std::unique_ptr<PlatformTimeRanges> buffered() const { return PlatformTimeRanges::create(); }
 
-    virtual unsigned totalBytes() const { return 0; }
+    virtual unsigned long long totalBytes() const { return 0; }
     virtual bool didLoadingProgress() const { return false; }
 
     virtual void setSize(const IntSize&) { }
index 97ff181eccaede9c3b947548cbc7ccdd0ae3a5ea..c646ff5b8d51f797417718f9c8993c9961ce3e19 100644 (file)
@@ -130,6 +130,7 @@ public:
     virtual MediaTime minMediaTimeSeekable() const { return MediaTime::createWithDouble(minTimeSeekable()); }
     virtual std::unique_ptr<PlatformTimeRanges> buffered() const = 0;
 
+    virtual unsigned long long totalBytes() const { return 0; }
     virtual bool didLoadingProgress() const = 0;
 
     virtual void setSize(const IntSize&) = 0;
@@ -242,8 +243,16 @@ public:
 
     virtual String languageOfPrimaryAudioTrack() const { return emptyString(); }
 
-    virtual size_t extraMemoryCost() const { return 0; }
-    
+    virtual size_t extraMemoryCost() const
+    {
+        MediaTime duration = this->durationMediaTime();
+        if (!duration)
+            return 0;
+
+        unsigned long long extra = totalBytes() * buffered()->totalDuration().toDouble() / duration.toDouble();
+        return static_cast<unsigned>(extra);
+    }
+
     virtual unsigned long long fileSize() const { return 0; }
 
 #if ENABLE(MEDIA_SOURCE)
index 02b5a59099ec5c22bd23a59537a13dde05ab8777..0b17288f405d0459e9bfaf8506a72aa0b7e8b3fe 100644 (file)
@@ -211,7 +211,7 @@ MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer(MediaPlayer* player)
     , m_volumeAndMuteInitialized(false)
     , m_hasVideo(false)
     , m_hasAudio(false)
-    , m_totalBytes(-1)
+    , m_totalBytes(0)
     , m_preservesPitch(false)
     , m_requestedState(GST_STATE_VOID_PENDING)
     , m_missingPlugins(false)
@@ -1228,12 +1228,12 @@ bool MediaPlayerPrivateGStreamer::didLoadingProgress() const
     return didLoadingProgress;
 }
 
-unsigned MediaPlayerPrivateGStreamer::totalBytes() const
+unsigned long long MediaPlayerPrivateGStreamer::totalBytes() const
 {
     if (m_errorOccured)
         return 0;
 
-    if (m_totalBytes != -1)
+    if (m_totalBytes)
         return m_totalBytes;
 
     if (!m_source)
@@ -1243,7 +1243,7 @@ unsigned MediaPlayerPrivateGStreamer::totalBytes() const
     gint64 length = 0;
     if (gst_element_query_duration(m_source.get(), fmt, &length)) {
         INFO_MEDIA_MESSAGE("totalBytes %" G_GINT64_FORMAT, length);
-        m_totalBytes = static_cast<unsigned>(length);
+        m_totalBytes = static_cast<unsigned long long>(length);
         m_isStreaming = !length;
         return m_totalBytes;
     }
@@ -1278,7 +1278,7 @@ unsigned MediaPlayerPrivateGStreamer::totalBytes() const
     gst_iterator_free(iter);
 
     INFO_MEDIA_MESSAGE("totalBytes %" G_GINT64_FORMAT, length);
-    m_totalBytes = static_cast<unsigned>(length);
+    m_totalBytes = static_cast<unsigned long long>(length);
     m_isStreaming = !length;
     return m_totalBytes;
 }
index 5084921982c618432a1aa2f1ffa9c0f81c31ba76..7720015e34817a9835b2f4778aa2913e4cb4b2d5 100644 (file)
@@ -92,7 +92,7 @@ public:
     std::unique_ptr<PlatformTimeRanges> buffered() const;
     float maxTimeSeekable() const;
     bool didLoadingProgress() const;
-    unsigned totalBytes() const;
+    unsigned long long totalBytes() const;
     float maxTimeLoaded() const;
 
     void loadStateChanged();
@@ -207,7 +207,7 @@ private:
     GThreadSafeMainLoopSource m_videoTimerHandler;
     GThreadSafeMainLoopSource m_videoCapsTimerHandler;
     GThreadSafeMainLoopSource m_readyTimerHandler;
-    mutable long m_totalBytes;
+    mutable unsigned long long m_totalBytes;
     URL m_url;
     bool m_preservesPitch;
     GstState m_requestedState;