Author: dlmcpaul Date: 2009-12-29 01:41:08 +0100 (Tue, 29 Dec 2009) New Revision: 34793 Changeset: http://dev.haiku-os.org/changeset/34793/haiku Modified: haiku/trunk/src/kits/media/MediaFile.cpp Log: Improve IO performance for all media files Modified: haiku/trunk/src/kits/media/MediaFile.cpp =================================================================== --- haiku/trunk/src/kits/media/MediaFile.cpp 2009-12-28 14:23:23 UTC (rev 34792) +++ haiku/trunk/src/kits/media/MediaFile.cpp 2009-12-29 00:41:08 UTC (rev 34793) @@ -11,6 +11,7 @@ #include <stdlib.h> #include <string.h> +#include <BufferIO.h> #include <File.h> #include <MediaTrack.h> @@ -432,9 +433,25 @@ return; } - fSource = source; + if (dynamic_cast<BBufferIO *>(source)) { + // Already buffered + fSource = source; + } 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"); + fSource = source; + } + } - fExtractor = new(std::nothrow) MediaExtractor(source, flags); + fExtractor = new(std::nothrow) MediaExtractor(fSource, flags); if (fExtractor == NULL) fErr = B_NO_MEMORY; else