C2VDAComponent: Add a parameter for maximum input size

App may set a smaller value for maximum of input buffer size than actually required by mistake.
C2VDAComponent overrides it to 1MB if the value specified by app is smaller than 1MB.

Bug: 116284248
Test: com.google.android.exoplayer.gts.DashTest#testVp9Fixed360p
Change-Id: I0b3b0c945f8b3d66b0f3043d5648c9fda6d2f527
(cherry picked from commit a0adcdfec9dfbf87f5382303594935a9b34f380c)
diff --git a/C2VDAComponent.cpp b/C2VDAComponent.cpp
index e0185ea..34eef94 100644
--- a/C2VDAComponent.cpp
+++ b/C2VDAComponent.cpp
@@ -169,6 +169,35 @@
                          .withSetter(LocalSetter::SizeSetter)
                          .build());
 
+    // App may set a smaller value for maximum of input buffer size than actually required
+    // by mistake. C2VDAComponent overrides it if the value specified by app is smaller than
+    // the calculated value in MaxSizeCalculator().
+    // This value is the default maximum of linear buffer size (kLinearBufferSize) in
+    // CCodecBufferChannel.cpp.
+    constexpr static size_t kLinearBufferSize = 1048576;
+    struct LocalCalculator {
+        static C2R MaxSizeCalculator(bool mayBlock, C2P<C2StreamMaxBufferSizeInfo::input>& me,
+                                     const C2P<C2StreamPictureSizeInfo::output>& size) {
+            (void)mayBlock;
+            // TODO: Need larger size?
+            me.set().value = kLinearBufferSize;
+            const uint32_t width = size.v.width;
+            const uint32_t height = size.v.height;
+            // Enlarge the input buffer for 4k video
+            if ((width > 1920 && height > 1080)) {
+                me.set().value = 4 * kLinearBufferSize;
+            }
+            return C2R::Ok();
+        }
+    };
+    addParameter(DefineParam(mMaxInputSize, C2_PARAMKEY_INPUT_MAX_BUFFER_SIZE)
+                         .withDefault(new C2StreamMaxBufferSizeInfo::input(0u, kLinearBufferSize))
+                         .withFields({
+                                 C2F(mMaxInputSize, value).any(),
+                         })
+                         .calculatedAs(LocalCalculator::MaxSizeCalculator, mSize)
+                         .build());
+
     bool secureMode = name.find(".secure") != std::string::npos;
     C2Allocator::id_t inputAllocators[] = {secureMode ? C2VDAAllocatorStore::SECURE_LINEAR
                                                       : C2PlatformAllocatorStore::ION};
diff --git a/include/C2VDAComponent.h b/include/C2VDAComponent.h
index 477bc1c..ed8007b 100644
--- a/include/C2VDAComponent.h
+++ b/include/C2VDAComponent.h
@@ -59,6 +59,8 @@
         std::shared_ptr<C2PortMediaTypeSetting::output> mOutputMediaType;
         // Decoded video size for output.
         std::shared_ptr<C2StreamPictureSizeInfo::output> mSize;
+        // Maximum size of one input buffer.
+        std::shared_ptr<C2StreamMaxBufferSizeInfo::input> mMaxInputSize;
         // The suggested usage of input buffer allocator ID.
         std::shared_ptr<C2PortAllocatorsTuning::input> mInputAllocatorIds;
         // The suggested usage of output buffer allocator ID.