From d753645e3f58d685c3c3ab0f27f3c3e8a8dccd1b Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 6 Jan 2021 18:32:29 +0100 Subject: [PATCH] MediaExtractor: fix cache size computation for audio Untested. If audio is not decoding well, try increasing the constant. Change-Id: I151764e6bb3e69088904d33bfeb683bf0569bd23 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3605 Reviewed-by: Alex von Gluck IV --- src/kits/media/MediaExtractor.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/kits/media/MediaExtractor.cpp b/src/kits/media/MediaExtractor.cpp index 15d0451aca..bf12208c56 100644 --- a/src/kits/media/MediaExtractor.cpp +++ b/src/kits/media/MediaExtractor.cpp @@ -438,13 +438,20 @@ 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; + + const media_format* format = EncodedFormat(stream); + if (format->IsVideo()) { + // For video, have space for at least two frames + int32 rowSize = BPrivate::get_bytes_per_row(format->ColorSpace(), + format->Width()); + if (rowSize > 0) { + 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); }