MediaIO: Review behavior regarding object inheritance

This commit is contained in:
Dario Casalinuovo
2016-03-25 22:07:50 +01:00
parent 050118ef53
commit 0d88bf3ac4
+16 -18
View File
@@ -40,10 +40,9 @@ public:
// No need to do additional buffering if we have // No need to do additional buffering if we have
// a BBufferIO or a BMediaIO. // a BBufferIO or a BMediaIO.
if (dynamic_cast<BBufferIO *>(source) == NULL if (dynamic_cast<BBufferIO *>(source) == NULL) {
&& fMedia == NULL) {
// Source needs to be at least a BPositionIO to wrap with a BBufferIO // 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); fPosition = new(std::nothrow) BBufferIO(fPosition, 65536, true);
if (fPosition == NULL) { if (fPosition == NULL) {
fErr = B_NO_MEMORY; fErr = B_NO_MEMORY;
@@ -51,7 +50,7 @@ public:
} }
// We have to reset our BDataIO reference too // We have to reset our BDataIO reference too
fData = dynamic_cast<BDataIO*>(fPosition); fData = dynamic_cast<BDataIO*>(fPosition);
} else { } else if (!IsMedia()) {
// In this case we have to supply our own form // In this case we have to supply our own form
// of pseudo-seekable object from a non-seekable // of pseudo-seekable object from a non-seekable
// BDataIO. // BDataIO.
@@ -83,6 +82,8 @@ public:
if (fFallbackBuffer->Position() == position if (fFallbackBuffer->Position() == position
&& position+size > bufSize) { && position+size > bufSize) {
// TODO: Possibly part of the data we have
// to supply is cached.
ret = fData->Read(buffer, size); ret = fData->Read(buffer, size);
fFallbackBuffer->Write(buffer, ret); fFallbackBuffer->Write(buffer, ret);
return ret; return ret;
@@ -120,11 +121,12 @@ public:
if (IsSeekable()) if (IsSeekable())
return fPosition->Seek(position, seekMode); return fPosition->Seek(position, seekMode);
off_t bufSize = 0; if (IsEndless()) {
fFallbackBuffer->GetSize(&bufSize); off_t bufSize = 0;
if (IsEndless() && position <= bufSize) fFallbackBuffer->GetSize(&bufSize);
return fFallbackBuffer->Seek(position, seekMode); if (position <= bufSize)
return fFallbackBuffer->Seek(position, seekMode);
}
return B_NOT_SUPPORTED; return B_NOT_SUPPORTED;
} }
@@ -162,12 +164,13 @@ public:
if (IsMedia()) if (IsMedia())
return fMedia->IsSeekable(); 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 virtual bool IsEndless() const
@@ -175,7 +178,7 @@ public:
if (IsMedia()) if (IsMedia())
return fMedia->IsEndless(); return fMedia->IsEndless();
if (IsPosition()) if (IsSeekable())
return false; return false;
return true; return true;
@@ -190,11 +193,6 @@ public:
protected: protected:
bool IsPosition() const
{
return fPosition != NULL;
}
bool IsMedia() const bool IsMedia() const
{ {
return fMedia != NULL; return fMedia != NULL;