From 6efbc4bb54d6eae2cc56e27d6301c0d5eae6191c Mon Sep 17 00:00:00 2001 From: Dario Casalinuovo Date: Sun, 6 Mar 2016 17:52:14 +0100 Subject: [PATCH] BMediaFile: Move BBufferIO usage into the plugin manager * Add InitCheck for the wrapper status. --- src/kits/media/MediaFile.cpp | 17 ------------- src/kits/media/PluginManager.cpp | 41 ++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/kits/media/MediaFile.cpp b/src/kits/media/MediaFile.cpp index 1356571203..acedc12057 100644 --- a/src/kits/media/MediaFile.cpp +++ b/src/kits/media/MediaFile.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include @@ -454,22 +453,6 @@ BMediaFile::_InitReader(BDataIO* source, int32 flags) return; } - if (dynamic_cast(source)) { - // Already buffered - } else { - // Source needs to be at least a BPositionIO to wrap with a BBufferIO - if (dynamic_cast(source)) { - fSource = new(std::nothrow) BBufferIO(dynamic_cast( - source), 65536, fDeleteSource); - if (fSource == NULL) { - fErr = B_NO_MEMORY; - return; - } - fDeleteSource = true; - } else - TRACE("Unable to improve performance with a BufferIO\n"); - } - fExtractor = new(std::nothrow) MediaExtractor(fSource, flags); if (fExtractor == NULL) fErr = B_NO_MEMORY; diff --git a/src/kits/media/PluginManager.cpp b/src/kits/media/PluginManager.cpp index e8d8aee3e2..7247cdef6b 100644 --- a/src/kits/media/PluginManager.cpp +++ b/src/kits/media/PluginManager.cpp @@ -3,10 +3,12 @@ * Distributed under the terms of the OpenBeOS License. */ -#include +#include #include #include #include +#include + #include #include "AddOnManager.h" @@ -25,11 +27,32 @@ public: fData(NULL), fPosition(NULL), fMedia(NULL), - fFile(NULL) + fFile(NULL), + fErr(B_NO_ERROR) { - fData = dynamic_cast(source); fPosition = dynamic_cast(source); fMedia = dynamic_cast(source); + + // No need to do additional buffering if we have + // a BBufferIO or a BMediaIO. + if (dynamic_cast(source) == NULL + && fMedia == NULL) { + // Source needs to be at least a BPositionIO to wrap with a BBufferIO + if (fPosition != NULL) { + fPosition = new(std::nothrow) BBufferIO(fPosition, 65536, true); + // We have to reset our BDataIO reference + fData = dynamic_cast(fPosition); + if (fPosition == NULL) { + fErr = B_NO_MEMORY; + return; + } + } else { + TRACE("Unable to improve performance with a BufferIO\n"); + // TODO: fallback buffering + } + } else { + fData = source; + } fFile = dynamic_cast(source); } @@ -150,6 +173,11 @@ public: return B_NOT_SUPPORTED; } + status_t InitCheck() const + { + return fErr; + } + protected: // Utility methods bool IsData() const @@ -172,6 +200,8 @@ private: BPositionIO* fPosition; BMediaIO* fMedia; BFile* fFile; + + status_t fErr; }; @@ -188,12 +218,15 @@ PluginManager::CreateReader(Reader** reader, int32* streamCount, // way, we create an instance which is buffering our reads and // writes. BMediaIOWrapper* buffered_source = new BMediaIOWrapper(source); + status_t ret = buffered_source->InitCheck(); + if (ret != B_OK) + return ret; // get list of available readers from the server entry_ref refs[MAX_READERS]; int32 count; - status_t ret = AddOnManager::GetInstance()->GetReaders(refs, &count, + ret = AddOnManager::GetInstance()->GetReaders(refs, &count, MAX_READERS); if (ret != B_OK) { printf("PluginManager::CreateReader: can't get list of readers: %s\n",