From 0d88bf3ac4e708ae0f21087ae943030903d63471 Mon Sep 17 00:00:00 2001 From: Dario Casalinuovo Date: Fri, 11 Mar 2016 02:03:39 +0100 Subject: [PATCH] MediaIO: Review behavior regarding object inheritance --- src/kits/media/PluginManager.cpp | 34 +++++++++++++++----------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/kits/media/PluginManager.cpp b/src/kits/media/PluginManager.cpp index f4bf937888..817335a11c 100644 --- a/src/kits/media/PluginManager.cpp +++ b/src/kits/media/PluginManager.cpp @@ -40,10 +40,9 @@ public: // No need to do additional buffering if we have // a BBufferIO or a BMediaIO. - if (dynamic_cast(source) == NULL - && fMedia == NULL) { + if (dynamic_cast(source) == NULL) { // Source needs to be at least a BPositionIO to wrap with a BBufferIO - if (fPosition != NULL) { + if (IsSeekable() && (IsMedia() && !fMedia->IsCached())) { fPosition = new(std::nothrow) BBufferIO(fPosition, 65536, true); if (fPosition == NULL) { fErr = B_NO_MEMORY; @@ -51,7 +50,7 @@ public: } // We have to reset our BDataIO reference too fData = dynamic_cast(fPosition); - } else { + } else if (!IsMedia()) { // In this case we have to supply our own form // of pseudo-seekable object from a non-seekable // BDataIO. @@ -83,6 +82,8 @@ public: if (fFallbackBuffer->Position() == position && position+size > bufSize) { + // TODO: Possibly part of the data we have + // to supply is cached. ret = fData->Read(buffer, size); fFallbackBuffer->Write(buffer, ret); return ret; @@ -120,11 +121,12 @@ public: if (IsSeekable()) return fPosition->Seek(position, seekMode); - off_t bufSize = 0; - fFallbackBuffer->GetSize(&bufSize); - if (IsEndless() && position <= bufSize) - return fFallbackBuffer->Seek(position, seekMode); - + if (IsEndless()) { + off_t bufSize = 0; + fFallbackBuffer->GetSize(&bufSize); + if (position <= bufSize) + return fFallbackBuffer->Seek(position, seekMode); + } return B_NOT_SUPPORTED; } @@ -162,12 +164,13 @@ public: if (IsMedia()) return fMedia->IsSeekable(); - return IsPosition(); + return fPosition != NULL; } - virtual bool IsFile() const + virtual bool IsCached() const { - return fFile != NULL; + // Our wrapper class is always cached + return true; } virtual bool IsEndless() const @@ -175,7 +178,7 @@ public: if (IsMedia()) return fMedia->IsEndless(); - if (IsPosition()) + if (IsSeekable()) return false; return true; @@ -190,11 +193,6 @@ public: protected: - bool IsPosition() const - { - return fPosition != NULL; - } - bool IsMedia() const { return fMedia != NULL;