diff --git a/headers/private/media/experimental/AdapterIO.h b/headers/private/media/experimental/AdapterIO.h index 81910065e3..7abaec5737 100644 --- a/headers/private/media/experimental/AdapterIO.h +++ b/headers/private/media/experimental/AdapterIO.h @@ -62,6 +62,8 @@ public: void SeekCompleted(); status_t SetBuffer(BPositionIO* buffer); + status_t FlushBefore(off_t position); + BInputAdapter* BuildInputAdapter(); protected: diff --git a/src/kits/media/experimental/AdapterIO.cpp b/src/kits/media/experimental/AdapterIO.cpp index 642a622bd5..0bc8107386 100644 --- a/src/kits/media/experimental/AdapterIO.cpp +++ b/src/kits/media/experimental/AdapterIO.cpp @@ -46,6 +46,28 @@ public: return B_OK; } + status_t FlushBefore(off_t position, BPositionIO* buffer, const void* oldBuffer, + size_t oldLength) + { + AutoWriteLocker _(fLock); + off_t relative = _PositionToRelative(position); + if (relative < 0) + return B_OK; + if (relative > (off_t)oldLength) + return B_BAD_VALUE; + status_t status = buffer->WriteAt(0, (void*)((addr_t)oldBuffer + relative), + oldLength - relative); + if (status < B_OK) + return status; + status = buffer->Seek(fBuffer->Position() - relative, SEEK_SET); + if (status < B_OK) + return status; + fBackPosition -= relative; + fStartOffset += relative; + SetBuffer(buffer); + return B_OK; + } + status_t EvaluatePosition(off_t position, off_t totalSize) { if (position < 0) @@ -182,6 +204,11 @@ public: return ((flags & B_MEDIA_SEEKABLE) == B_MEDIA_SEEKABLE); } + const BPositionIO* Buffer() const + { + return fBuffer; + } + private: off_t _PositionToRelative(off_t position) const @@ -382,6 +409,16 @@ BAdapterIO::SetBuffer(BPositionIO* buffer) } +status_t +BAdapterIO::FlushBefore(off_t position) +{ + BMallocIO* buffer = new BMallocIO(); + BMallocIO* oldBuffer = (BMallocIO*)fBuffer->Buffer(); + fBuffer->FlushBefore(position, buffer, oldBuffer->Buffer(), oldBuffer->BufferLength()); + return B_OK; +} + + BInputAdapter* BAdapterIO::BuildInputAdapter() {