C2SoftAvcEnc: Allocate output buffer as per clip's dimensions
Instead of allocating a fixed size output buffer, allocate it as per
width and height of the input being encoded. To ensure for very low
resolutions, this size doesn't become too small, use a minimum size of
512K Bytes.
Bug: 144928581
Test: h264 related tests in android.media.cts.VideoEncoderTest
Change-Id: I01c1aa03456043824354005f1708f07b3268d97e
diff --git a/media/codec2/components/avc/C2SoftAvcEnc.cpp b/media/codec2/components/avc/C2SoftAvcEnc.cpp
index b41c271..e3d419c 100644
--- a/media/codec2/components/avc/C2SoftAvcEnc.cpp
+++ b/media/codec2/components/avc/C2SoftAvcEnc.cpp
@@ -40,7 +40,7 @@
namespace {
constexpr char COMPONENT_NAME[] = "c2.android.avc.encoder";
-
+constexpr uint32_t kMinOutBufferSize = 524288;
void ParseGop(
const C2StreamGopTuning::output &gop,
uint32_t *syncInterval, uint32_t *iInterval, uint32_t *maxBframes) {
@@ -440,8 +440,7 @@
mSignalledError(false),
mCodecCtx(nullptr),
mOutBlock(nullptr),
- // TODO: output buffer size
- mOutBufferSize(524288) {
+ mOutBufferSize(kMinOutBufferSize) {
// If dump is enabled, then open create an empty file
GENERATE_FILE_NAMES();
@@ -951,6 +950,9 @@
mStride = width;
+ // Assume worst case output buffer size to be equal to number of bytes in input
+ mOutBufferSize = std::max(width * height * 3 / 2, kMinOutBufferSize);
+
// TODO
mIvVideoColorFormat = IV_YUV_420P;