MediaIOWrapper: IsEndless was not used the right way

* The idea is to just identify when a BMediaIO is able
to tell the whole size of the data, but caching needs
more complex policies to be successful.
This commit is contained in:
Dario Casalinuovo
2016-03-25 22:22:31 +01:00
parent 22c9314255
commit 25527aff5c
+30 -43
View File
@@ -43,7 +43,7 @@ public:
// a BBufferIO or a BMediaIO. // a BBufferIO or a BMediaIO.
if (dynamic_cast<BBufferIO *>(source) == NULL) { if (dynamic_cast<BBufferIO *>(source) == 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 (IsSeekable() && (IsMedia() && !fMedia->IsCached())) { if (IsSeekable()) {
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 +51,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 if (!IsMedia()) { } else {
// 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.
@@ -76,27 +76,25 @@ public:
if (IsSeekable()) if (IsSeekable())
return fPosition->ReadAt(position, buffer, size); return fPosition->ReadAt(position, buffer, size);
if (IsEndless()) { off_t bufSize = 0;
off_t bufSize = 0; ssize_t ret = B_NOT_SUPPORTED;
ssize_t ret = 0; fFallbackBuffer->GetSize(&bufSize);
fFallbackBuffer->GetSize(&bufSize);
if (fFallbackBuffer->Position() == position if (fFallbackBuffer->Position() == position
&& position+size > bufSize) { && position+size > bufSize) {
// TODO: Possibly part of the data we have // TODO: Possibly part of the data we have
// to supply is cached. // to supply is cached.
ret = fData->Read(buffer, size); ret = fData->Read(buffer, size);
if (ret > 0)
fFallbackBuffer->Write(buffer, ret); fFallbackBuffer->Write(buffer, ret);
return ret;
}
if (position+size <= bufSize) { return ret;
ret = fFallbackBuffer->ReadAt(position, buffer, size);
return ret;
}
} }
return B_NOT_SUPPORTED; if (position+size <= bufSize)
return fFallbackBuffer->ReadAt(position, buffer, size);
return ret;
} }
virtual ssize_t WriteAt(off_t position, const void* buffer, virtual ssize_t WriteAt(off_t position, const void* buffer,
@@ -105,13 +103,12 @@ public:
if (IsSeekable()) if (IsSeekable())
return fPosition->WriteAt(position, buffer, size); return fPosition->WriteAt(position, buffer, size);
if (IsEndless()) { off_t bufSize = 0;
off_t bufSize = 0; fFallbackBuffer->GetSize(&bufSize);
fFallbackBuffer->GetSize(&bufSize); if (position == bufSize) {
if (position == bufSize) { ssize_t ret = fData->Write(buffer, size);
fData->Write(buffer, size); fFallbackBuffer->WriteAt(bufSize, buffer, size);
fFallbackBuffer->WriteAt(bufSize, buffer, size); return ret;
}
} }
return B_NOT_SUPPORTED; return B_NOT_SUPPORTED;
@@ -122,12 +119,11 @@ public:
if (IsSeekable()) if (IsSeekable())
return fPosition->Seek(position, seekMode); return fPosition->Seek(position, seekMode);
if (IsEndless()) { off_t bufSize = 0;
off_t bufSize = 0; fFallbackBuffer->GetSize(&bufSize);
fFallbackBuffer->GetSize(&bufSize); if (position <= bufSize)
if (position <= bufSize) return fFallbackBuffer->Seek(position, seekMode);
return fFallbackBuffer->Seek(position, seekMode);
}
return B_NOT_SUPPORTED; return B_NOT_SUPPORTED;
} }
@@ -136,10 +132,7 @@ public:
if (IsSeekable()) if (IsSeekable())
return fPosition->Position(); return fPosition->Position();
if (IsEndless()) return fFallbackBuffer->Position();
return fFallbackBuffer->Position();
return B_NOT_SUPPORTED;
} }
virtual status_t SetSize(off_t size) virtual status_t SetSize(off_t size)
@@ -168,12 +161,6 @@ public:
return fPosition != NULL; return fPosition != NULL;
} }
virtual bool IsCached() const
{
// Our wrapper class is always cached
return true;
}
virtual bool IsEndless() const virtual bool IsEndless() const
{ {
if (IsMedia()) if (IsMedia())
@@ -592,8 +579,8 @@ PluginManager::CreateStreamer(Streamer** streamer, BUrl* url, BDataIO** source)
status_t ret = AddOnManager::GetInstance()->GetStreamers(refs, &count, status_t ret = AddOnManager::GetInstance()->GetStreamers(refs, &count,
MAX_STREAMERS); MAX_STREAMERS);
if (ret != B_OK) { if (ret != B_OK) {
printf("PluginManager::CreateStreamer: can't get list of readers: %s\n", printf("PluginManager::CreateStreamer: can't get list of streamers:"
strerror(ret)); " %s\n", strerror(ret));
return ret; return ret;
} }