diff --git a/headers/private/media/MediaExtractor.h b/headers/private/media/MediaExtractor.h index 5f58b02d40..3645bd652c 100644 --- a/headers/private/media/MediaExtractor.h +++ b/headers/private/media/MediaExtractor.h @@ -79,6 +79,7 @@ private: void _RecycleLastChunk(stream_info& info); static int32 _ExtractorEntry(void* arg); void _ExtractorThread(); + size_t _CalculateChunkBuffer(int32 stream); private: status_t fInitStatus; diff --git a/src/kits/media/Jamfile b/src/kits/media/Jamfile index 3416670e31..c07fae9d1e 100644 --- a/src/kits/media/Jamfile +++ b/src/kits/media/Jamfile @@ -4,6 +4,7 @@ AddResources libmedia.so : libmedia.rdef ; UsePrivateHeaders app media shared ; UsePrivateHeaders [ FDirName media experimental ] ; +UsePrivateHeaders [ FDirName interface ] ; if $(CHECK_MALLOC) { SubDirC++Flags -D_NO_INLINE_ASM -fcheck-memory-usage ; diff --git a/src/kits/media/MediaExtractor.cpp b/src/kits/media/MediaExtractor.cpp index 058f6afeb0..15d0451aca 100644 --- a/src/kits/media/MediaExtractor.cpp +++ b/src/kits/media/MediaExtractor.cpp @@ -14,9 +14,11 @@ #include #include +#include #include "ChunkCache.h" #include "MediaDebug.h" +#include "MediaMisc.h" #include "PluginManager.h" @@ -24,9 +26,6 @@ #define DISABLE_CHUNK_CACHE 0 -static const size_t kMaxCacheBytes = 3 * 1024 * 1024; - - class MediaExtractorChunkProvider : public ChunkProvider { public: MediaExtractorChunkProvider(MediaExtractor* extractor, int32 stream) @@ -93,15 +92,9 @@ MediaExtractor::_Init(BDataIO* source, int32 flags) fStreamInfo[i].hasCookie = false; fStreamInfo[i].infoBuffer = 0; fStreamInfo[i].infoBufferSize = 0; - fStreamInfo[i].chunkCache - = new ChunkCache(fExtractorWaitSem, kMaxCacheBytes); fStreamInfo[i].lastChunk = NULL; + fStreamInfo[i].chunkCache = NULL; fStreamInfo[i].encodedFormat.Clear(); - - if (fStreamInfo[i].chunkCache->InitCheck() != B_OK) { - fInitStatus = B_NO_MEMORY; - return; - } } // create all stream cookies @@ -131,6 +124,15 @@ MediaExtractor::_Init(BDataIO* source, int32 flags) ERROR("MediaExtractor::MediaExtractor: GetStreamInfo for " "stream %" B_PRId32 " failed\n", i); } + + // Allocate our ChunkCache + size_t chunkCacheMaxBytes = _CalculateChunkBuffer(i); + fStreamInfo[i].chunkCache + = new ChunkCache(fExtractorWaitSem, chunkCacheMaxBytes); + if (fStreamInfo[i].chunkCache->InitCheck() != B_OK) { + fInitStatus = B_NO_MEMORY; + return; + } } #if !DISABLE_CHUNK_CACHE @@ -433,6 +435,21 @@ MediaExtractor::_ExtractorEntry(void* extractor) } +size_t +MediaExtractor::_CalculateChunkBuffer(int32 stream) +{ + const media_format* format = EncodedFormat(stream); + size_t cacheSize = 3 * 1024 * 1024; + int32 rowSize = BPrivate::get_bytes_per_row(format->ColorSpace(), + format->Width()); + if (rowSize > 0) { + // Frame size, multipled by 2 for good measure + cacheSize = rowSize * format->Height() * 2; + } + return ROUND_UP_TO_PAGE(cacheSize); +} + + void MediaExtractor::_ExtractorThread() {