From 40379e325c1960b6120e34f0a50131b9029c5a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 21 Sep 2010 15:58:28 +0000 Subject: [PATCH] * Always assign fSource in _InitReader(), even if we will wrap it in a BBufferIO. Makes the code cleaner. * Check if source is a BFile and propagate InitCheck() of the BFile. When trying to open a BMediaFile on a non-existant file, it will correctly say the file does not exist instead that there is no handler for it. (IIRC there is a ticket for this.) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38760 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/media/MediaFile.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/kits/media/MediaFile.cpp b/src/kits/media/MediaFile.cpp index f5fce00905..1356571203 100644 --- a/src/kits/media/MediaFile.cpp +++ b/src/kits/media/MediaFile.cpp @@ -446,22 +446,28 @@ BMediaFile::_InitReader(BDataIO* source, int32 flags) return; } + fSource = source; + + if (BFile* file = dynamic_cast(source)) { + fErr = file->InitCheck(); + if (fErr != B_OK) + return; + } + if (dynamic_cast(source)) { // Already buffered - fSource = source; } 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); + fSource = new(std::nothrow) BBufferIO(dynamic_cast( + source), 65536, fDeleteSource); if (fSource == NULL) { fErr = B_NO_MEMORY; return; } fDeleteSource = true; - } else { + } else TRACE("Unable to improve performance with a BufferIO\n"); - fSource = source; - } } fExtractor = new(std::nothrow) MediaExtractor(fSource, flags);