diff --git a/headers/private/media/AdapterIO.h b/headers/private/media/AdapterIO.h index 119b31f0cc..bf09c16219 100644 --- a/headers/private/media/AdapterIO.h +++ b/headers/private/media/AdapterIO.h @@ -58,6 +58,8 @@ public: virtual status_t Open(); virtual void Close(); + virtual bool IsRunning() const; + void SeekCompleted(); status_t SetBuffer(BPositionIO* buffer); diff --git a/src/kits/media/AdapterIO.cpp b/src/kits/media/AdapterIO.cpp index 1c38ca28a9..d3ef49068a 100644 --- a/src/kits/media/AdapterIO.cpp +++ b/src/kits/media/AdapterIO.cpp @@ -67,7 +67,7 @@ public: return B_OK; } - status_t WaitForData(off_t position) + status_t WaitForData(off_t position, off_t size) { off_t bufferSize = 0; status_t ret = GetSize(&bufferSize); @@ -76,7 +76,12 @@ public: bigtime_t totalTimeOut = 0; - while(bufferSize <= position) { + while(bufferSize < position+size) { + // We are not running, no luck to receive + // more data, let's return and avoid locking. + if (!fOwner->IsRunning()) + return B_NOT_SUPPORTED; + if (fTimeout != B_INFINITE_TIMEOUT && totalTimeOut >= fTimeout) return B_TIMED_OUT; @@ -346,6 +351,13 @@ BAdapterIO::Close() } +bool +BAdapterIO::IsRunning() const +{ + return fOpened; +} + + void BAdapterIO::SeekCompleted() { @@ -415,7 +427,7 @@ BAdapterIO::_EvaluateWait(off_t pos, off_t size) TRACE("BAdapterIO::_EvaluateWait: waiting for data\n"); - return fBuffer->WaitForData(pos+size); + return fBuffer->WaitForData(pos, size); }