From 7e15865d2736fa6dc7d978215912b52a6d1a9cec Mon Sep 17 00:00:00 2001 From: Hubert Mazur <hmazur@google.com> Date: Tue, 27 Feb 2024 13:42:46 +0100 Subject: [PATCH] v4l2: Increase the buffer size of bitstream The allocated buffer size for the encoded bitstream is always set to 1MB which might not be always accurate. It is possible to exceed it when high bitrates are used, like 10Mb/s. The encoder might put zeros to the output buffer to meet required bitstream. Also in case of slow devices the encoder might put zeros to meet the time constraints. For the sake of compatibility, set it to the same values as the Chrome browser does for a 1080p stream. Bug: 326164993 Test: CtsMediaCodecTestCases Change-Id: I4c2d06da588d2a12a593bbba3461384d8b3dffca --- components/DecodeInterface.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/DecodeInterface.cpp b/components/DecodeInterface.cpp index 3f0706a..53689bd 100644 --- a/components/DecodeInterface.cpp +++ b/components/DecodeInterface.cpp @@ -22,7 +22,11 @@ namespace { constexpr size_t k1080pArea = 1920 * 1088; constexpr size_t k4KArea = 3840 * 2160; // Input bitstream buffer size for up to 1080p streams. -constexpr size_t kInputBufferSizeFor1080p = 1024 * 1024; // 1MB +// Set it to 2MB since it is possible for the encoded bitstream to exceed the size of 1MB +// when using higher bitrates, like 1Mb/s on slower devices. Also, this brings up compability +// with the Chrome browser as it is using 2MB buffer size for a 1080p stream, ref: +// https://source.chromium.org/chromium/chromium/src/+/main:media/gpu/gpu_video_encode_accelerator_helpers.cc;l=25 +constexpr size_t kInputBufferSizeFor1080p = 2 * 1024 * 1024; // 2MB // Input bitstream buffer size for up to 4k streams. constexpr size_t kInputBufferSizeFor4K = 4 * kInputBufferSizeFor1080p; -- GitLab