CCodecBufferChannel: regard max-input-size for secure linear input buffers

For UHD secure decoding, the current size of encrypted input buffer may be not
enough. We should regard max-input-size to increase the buffer size as well as
LinearInputBuffers.

Bug: 116284279
Test: com.google.android.media.gts.WidevineH264PlaybackTests#testL1WithUHD30
Test: com.google.android.media.gts.WidevineH264PlaybackTests#testL3WithUHD30
Change-Id: Ifc26b72dc4c90cee9a9633d1513f1066bb247484
Merged-In: Ifc26b72dc4c90cee9a9633d1513f1066bb247484
(cherry picked from commit 1aaba7c6e0b6b88d3e824781b076cd2421f8d695)
(cherry picked from commit e63780359f50de33b5adc0743fedf16ac4444998)
diff --git a/media/sfplugin/CCodecBufferChannel.cpp b/media/sfplugin/CCodecBufferChannel.cpp
index 6e8bd90..128061c 100644
--- a/media/sfplugin/CCodecBufferChannel.cpp
+++ b/media/sfplugin/CCodecBufferChannel.cpp
@@ -807,6 +807,7 @@
             const sp<MemoryDealer> &dealer,
             const sp<ICrypto> &crypto,
             int32_t heapSeqNum,
+            size_t capacity,
             const char *componentName, const char *name = "EncryptedInput")
         : LinearInputBuffers(componentName, name),
           mUsage({0, 0}),
@@ -819,7 +820,7 @@
             mUsage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE };
         }
         for (size_t i = 0; i < kMinInputBufferArraySize; ++i) {
-            sp<IMemory> memory = mDealer->allocate(kLinearBufferSize);
+            sp<IMemory> memory = mDealer->allocate(capacity);
             if (memory == nullptr) {
                 ALOGD("[%s] Failed to allocate memory from dealer: only %zu slots allocated", mName, i);
                 break;
@@ -1992,12 +1993,18 @@
             }
         } else {
             if (hasCryptoOrDescrambler()) {
+                int32_t capacity = kLinearBufferSize;
+                (void)inputFormat->findInt32(KEY_MAX_INPUT_SIZE, &capacity);
+                if ((size_t)capacity > kMaxLinearBufferSize) {
+                    ALOGD("client requested %d, capped to %zu", capacity, kMaxLinearBufferSize);
+                    capacity = kMaxLinearBufferSize;
+                }
                 if (mDealer == nullptr) {
                     mDealer = new MemoryDealer(
-                            align(kLinearBufferSize, MemoryDealer::getAllocationAlignment())
+                            align(capacity, MemoryDealer::getAllocationAlignment())
                                 * (kMinInputBufferArraySize + 1),
                             "EncryptedLinearInputBuffers");
-                    mDecryptDestination = mDealer->allocate(kLinearBufferSize);
+                    mDecryptDestination = mDealer->allocate((size_t)capacity);
                 }
                 if (mCrypto != nullptr && mHeapSeqNum < 0) {
                     mHeapSeqNum = mCrypto->setHeap(mDealer->getMemoryHeap());
@@ -2005,7 +2012,7 @@
                     mHeapSeqNum = -1;
                 }
                 buffers->reset(new EncryptedLinearInputBuffers(
-                        secure, mDealer, mCrypto, mHeapSeqNum, mName));
+                        secure, mDealer, mCrypto, mHeapSeqNum, (size_t)capacity, mName));
             } else {
                 buffers->reset(new LinearInputBuffers(mName));
             }