BMediaFile: Move BBufferIO usage into the plugin manager

* Add InitCheck for the wrapper status.
This commit is contained in:
Dario Casalinuovo
2016-03-25 21:55:13 +01:00
parent a6b34a8c45
commit 6efbc4bb54
2 changed files with 37 additions and 21 deletions
-17
View File
@@ -11,7 +11,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <BufferIO.h>
#include <File.h> #include <File.h>
#include <MediaTrack.h> #include <MediaTrack.h>
@@ -454,22 +453,6 @@ BMediaFile::_InitReader(BDataIO* source, int32 flags)
return; return;
} }
if (dynamic_cast<BBufferIO *>(source)) {
// Already buffered
} else {
// Source needs to be at least a BPositionIO to wrap with a BBufferIO
if (dynamic_cast<BPositionIO *>(source)) {
fSource = new(std::nothrow) BBufferIO(dynamic_cast<BPositionIO *>(
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); fExtractor = new(std::nothrow) MediaExtractor(fSource, flags);
if (fExtractor == NULL) if (fExtractor == NULL)
fErr = B_NO_MEMORY; fErr = B_NO_MEMORY;
+37 -4
View File
@@ -3,10 +3,12 @@
* Distributed under the terms of the OpenBeOS License. * Distributed under the terms of the OpenBeOS License.
*/ */
#include <Path.h> #include <BufferIO.h>
#include <DataIO.h> #include <DataIO.h>
#include <File.h> #include <File.h>
#include <image.h> #include <image.h>
#include <Path.h>
#include <string.h> #include <string.h>
#include "AddOnManager.h" #include "AddOnManager.h"
@@ -25,11 +27,32 @@ public:
fData(NULL), fData(NULL),
fPosition(NULL), fPosition(NULL),
fMedia(NULL), fMedia(NULL),
fFile(NULL) fFile(NULL),
fErr(B_NO_ERROR)
{ {
fData = dynamic_cast<BDataIO*>(source);
fPosition = dynamic_cast<BPositionIO*>(source); fPosition = dynamic_cast<BPositionIO*>(source);
fMedia = dynamic_cast<BMediaIO*>(source); fMedia = dynamic_cast<BMediaIO*>(source);
// No need to do additional buffering if we have
// a BBufferIO or a BMediaIO.
if (dynamic_cast<BBufferIO *>(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<BDataIO*>(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<BFile*>(source); fFile = dynamic_cast<BFile*>(source);
} }
@@ -150,6 +173,11 @@ public:
return B_NOT_SUPPORTED; return B_NOT_SUPPORTED;
} }
status_t InitCheck() const
{
return fErr;
}
protected: protected:
// Utility methods // Utility methods
bool IsData() const bool IsData() const
@@ -172,6 +200,8 @@ private:
BPositionIO* fPosition; BPositionIO* fPosition;
BMediaIO* fMedia; BMediaIO* fMedia;
BFile* fFile; 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 // way, we create an instance which is buffering our reads and
// writes. // writes.
BMediaIOWrapper* buffered_source = new BMediaIOWrapper(source); 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 // get list of available readers from the server
entry_ref refs[MAX_READERS]; entry_ref refs[MAX_READERS];
int32 count; int32 count;
status_t ret = AddOnManager::GetInstance()->GetReaders(refs, &count, ret = AddOnManager::GetInstance()->GetReaders(refs, &count,
MAX_READERS); MAX_READERS);
if (ret != B_OK) { if (ret != B_OK) {
printf("PluginManager::CreateReader: can't get list of readers: %s\n", printf("PluginManager::CreateReader: can't get list of readers: %s\n",