From 67eeb4db482d7419ee55702ba706265f3705106c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= Date: Wed, 13 Jan 2021 15:36:07 +0100 Subject: [PATCH] MediaExtractor: go back to 3MB min cache size Should allow us to at least play the same files we could play before. Fixes #16738, though not its cause Change-Id: I2d23011696b730a891c802e8c2bfc23afe0041cf Reviewed-on: https://review.haiku-os.org/c/haiku/+/3628 Reviewed-by: Adrien Destugues --- src/kits/media/MediaExtractor.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/kits/media/MediaExtractor.cpp b/src/kits/media/MediaExtractor.cpp index 3019b4dada..b17491c07b 100644 --- a/src/kits/media/MediaExtractor.cpp +++ b/src/kits/media/MediaExtractor.cpp @@ -444,6 +444,11 @@ MediaExtractor::_ExtractorEntry(void* extractor) size_t MediaExtractor::_CalculateChunkBuffer(int32 stream) { + // WARNING: magic + // Your A/V may skip frames, chunks or not play at all if the cache size + // is insufficient. Unfortunately there's currently no safe way to + // calculate it. + size_t cacheSize = 3 * 1024 * 1024; const media_format* format = EncodedFormat(stream); @@ -452,12 +457,8 @@ MediaExtractor::_CalculateChunkBuffer(int32 stream) int32 rowSize = BPrivate::get_bytes_per_row(format->ColorSpace(), format->Width()); if (rowSize > 0) { - cacheSize = rowSize * format->Height() * 2; + cacheSize = max_c(cacheSize, rowSize * format->Height() * 2); } - } else if (format->IsAudio()) { - // For audio, have space for 2000 "frames" (that's 2000/44100 = 45ms - // at 44100Hz for example) - cacheSize = format->AudioFrameSize() * 2000; } return ROUND_UP_TO_PAGE(cacheSize); }