[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdemultimedia/phonon-xine
From:       Matthias Kretz <kretz () kde ! org>
Date:       2007-05-31 10:58:35
Message-ID: 1180609115.433618.30742.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 670121 by mkretz:

block when xine asks for the stream size and it's still 0

 M  +18 -1     bytestream.cpp  
 M  +7 -1      bytestream.h  


--- trunk/KDE/kdemultimedia/phonon-xine/bytestream.cpp #670120:670121
@@ -349,9 +349,11 @@
 void ByteStream::setStreamSize(qint64 x)
 {
     PXINE_VDEBUG << k_funcinfo << x << endl;
+    QMutexLocker lock(&m_streamSizeMutex);
     m_streamSize = x;
-    if (m_streamSize > 0) {
+    if (m_streamSize != 0) {
         emit needDataQueued();
+        m_waitForStreamSize.wakeAll();
 //X         setMrl();
     }
 }
@@ -453,12 +455,25 @@
 //X     MediaObject::play(); // goes into Phonon::BufferingState/PlayingState
 //X }
 
+qint64 ByteStream::streamSize() const
+{
+    if (m_streamSize == 0) {
+        // stream size has not been set yet
+        QMutexLocker lock(&m_streamSizeMutex);
+        if (m_streamSize == 0) {
+            m_waitForStreamSize.wait(&m_streamSizeMutex);
+        }
+    }
+    return m_streamSize;
+}
+
 void ByteStream::stop()
 {
     PXINE_VDEBUG << k_funcinfo << endl;
 
     m_mutex.lock();
     m_seekMutex.lock();
+    m_streamSizeMutex.lock();
     m_stopped = true;
     // the other thread is now not between m_mutex.lock() and m_waitingForData.wait(&m_mutex), so it
     // won't get stuck in m_waitingForData.wait if it's not there right now
@@ -466,6 +481,8 @@
     m_seekMutex.unlock();
     m_waitingForData.wakeAll();
     m_mutex.unlock();
+    m_waitForStreamSize.wakeAll();
+    m_streamSizeMutex.unlock();
 }
 
 }} //namespace Phonon::Xine
--- trunk/KDE/kdemultimedia/phonon-xine/bytestream.h #670120:670121
@@ -49,9 +49,13 @@
             ~ByteStream();
 
             QByteArray mrl() const;
+
+            // does not block, but might change later
             bool streamSeekable() const { return m_seekable; }
-            qint64 streamSize() const { return m_streamSize; }
 
+            // blocks until the size is known
+            qint64 streamSize() const;
+
             void stop();
 
         public slots:
@@ -84,6 +88,8 @@
             QByteArray m_preview;
             QMutex m_mutex;
             QMutex m_seekMutex;
+            mutable QMutex m_streamSizeMutex;
+            mutable QWaitCondition m_waitForStreamSize;
             QWaitCondition m_waitingForData;
             QWaitCondition m_seekWaitCondition;
             QQueue<QByteArray> m_buffers;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic