diff options
Diffstat (limited to 'src/3rdparty/phonon/ds9/qasyncreader.cpp')
-rw-r--r-- | src/3rdparty/phonon/ds9/qasyncreader.cpp | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/src/3rdparty/phonon/ds9/qasyncreader.cpp b/src/3rdparty/phonon/ds9/qasyncreader.cpp index a3f9cda..68ec1f8 100644 --- a/src/3rdparty/phonon/ds9/qasyncreader.cpp +++ b/src/3rdparty/phonon/ds9/qasyncreader.cpp @@ -15,6 +15,8 @@ You should have received a copy of the GNU Lesser General Public License along with this library. If not, see <http://www.gnu.org/licenses/>. */ +#include <QtCore/QFile> + #include "qasyncreader.h" #include "qbasefilter.h" @@ -78,7 +80,8 @@ namespace Phonon STDMETHODIMP QAsyncReader::Request(IMediaSample *sample,DWORD_PTR user) { - QMutexLocker locker(&m_mutex); + QMutexLocker mutexLocker(&m_mutexWait); + QWriteLocker locker(&m_lock); if (m_flushing) { return VFW_E_WRONG_STATE; } @@ -90,28 +93,33 @@ namespace Phonon STDMETHODIMP QAsyncReader::WaitForNext(DWORD timeout, IMediaSample **sample, DWORD_PTR *user) { - QMutexLocker locker(&m_mutex); + QMutexLocker locker(&m_mutexWait); if (!sample ||!user) { return E_POINTER; } - //msdn says to return immediately if we're flushing but that doesn't seem to be true - //since it triggers a dead-lock somewhere inside directshow (see task 258830) - *sample = 0; *user = 0; - if (m_requestQueue.isEmpty()) { - if (m_requestWait.wait(&m_mutex, timeout) == false) { - return VFW_E_TIMEOUT; - } - if (m_requestQueue.isEmpty()) { + AsyncRequest r = getNextRequest(); + + if (r.sample == 0) { + //there is no request in the queue + if (isFlushing()) { return VFW_E_WRONG_STATE; + } else { + //First we need to lock the mutex + if (m_requestWait.wait(&m_mutexWait, timeout) == false) { + return VFW_E_TIMEOUT; + } + if (isFlushing()) { + return VFW_E_WRONG_STATE; + } + + r = getNextRequest(); } } - AsyncRequest r = m_requestQueue.dequeue(); - //at this point we're sure to have a request to proceed if (r.sample == 0) { return E_FAIL; @@ -119,12 +127,14 @@ namespace Phonon *sample = r.sample; *user = r.user; - return syncReadAlignedUnlocked(r.sample); + + return SyncReadAligned(r.sample); } STDMETHODIMP QAsyncReader::BeginFlush() { - QMutexLocker locker(&m_mutex); + QMutexLocker mutexLocker(&m_mutexWait); + QWriteLocker locker(&m_lock); m_flushing = true; m_requestWait.wakeOne(); return S_OK; @@ -132,28 +142,13 @@ namespace Phonon STDMETHODIMP QAsyncReader::EndFlush() { - QMutexLocker locker(&m_mutex); + QWriteLocker locker(&m_lock); m_flushing = false; return S_OK; } STDMETHODIMP QAsyncReader::SyncReadAligned(IMediaSample *sample) { - QMutexLocker locker(&m_mutex); - return syncReadAlignedUnlocked(sample); - } - - STDMETHODIMP QAsyncReader::SyncRead(LONGLONG pos, LONG length, BYTE *buffer) - { - QMutexLocker locker(&m_mutex); - return read(pos, length, buffer, 0); - } - - - STDMETHODIMP QAsyncReader::syncReadAlignedUnlocked(IMediaSample *sample) - { - Q_ASSERT(!m_mutex.tryLock()); - if (!sample) { return E_POINTER; } @@ -180,6 +175,23 @@ namespace Phonon return sample->SetActualDataLength(actual); } + STDMETHODIMP QAsyncReader::SyncRead(LONGLONG pos, LONG length, BYTE *buffer) + { + return read(pos, length, buffer, 0); + } + + + //addition + QAsyncReader::AsyncRequest QAsyncReader::getNextRequest() + { + QWriteLocker locker(&m_lock); + AsyncRequest ret; + if (!m_requestQueue.isEmpty()) { + ret = m_requestQueue.dequeue(); + } + + return ret; + } } } |