Revert "RESTRICT AUTOMERGE Gate input buffers from input surface"

This reverts commit 520e1d07a7870f4256434d33e3ef9a21e6796d41.

Reason for revert: <INSERT REASONING HERE>

Bug: 133471707
Change-Id: I6f7a82c7b68ff02f9cb6802dc074c3227175c9eb
(cherry picked from commit 921dc7a9d2e7ad2ab117d2ee033e3753542ea951)
diff --git a/media/sfplugin/C2OMXNode.cpp b/media/sfplugin/C2OMXNode.cpp
index 92b86b6..73cbbc6 100644
--- a/media/sfplugin/C2OMXNode.cpp
+++ b/media/sfplugin/C2OMXNode.cpp
@@ -49,10 +49,8 @@
 
 }  // namespace
 
-C2OMXNode::C2OMXNode(const std::shared_ptr<Codec2Client::Component> &comp,
-                     const std::shared_ptr<InputGater> &inputGater)
-    : mComp(comp), mInputGater(inputGater),
-      mFrameIndex(0), mWidth(0), mHeight(0),
+C2OMXNode::C2OMXNode(const std::shared_ptr<Codec2Client::Component> &comp)
+    : mComp(comp), mFrameIndex(0), mWidth(0), mHeight(0),
       mAdjustTimestampGapUs(0), mFirstInputFrame(true) {
     // TODO: read from intf()
     if (!strncmp(comp->getName().c_str(), "c2.android.", 11)) {
@@ -214,7 +212,6 @@
         sp<Fence> fence = new Fence(fenceFd);
         fence->waitForever(LOG_TAG);
     }
-
     std::shared_ptr<Codec2Client::Component> comp = mComp.lock();
     if (!comp) {
         return NO_INIT;
@@ -290,11 +287,6 @@
     std::list<std::unique_ptr<C2Work>> items;
     items.push_back(std::move(work));
 
-    std::shared_ptr<InputGater> inputGater = mInputGater.lock();
-    if (!inputGater || !inputGater->canQueue()) {
-        return OK;
-    }
-
     c2_status_t err = comp->queue(&items);
     if (err != C2_OK) {
         return UNKNOWN_ERROR;
diff --git a/media/sfplugin/C2OMXNode.h b/media/sfplugin/C2OMXNode.h
index a81a993..b5a815e 100644
--- a/media/sfplugin/C2OMXNode.h
+++ b/media/sfplugin/C2OMXNode.h
@@ -24,8 +24,6 @@
 #include <media/OMXBuffer.h>
 #include <codec2/hidl/client.h>
 
-#include "InputSurfaceWrapper.h"
-
 namespace android {
 
 /**
@@ -35,12 +33,7 @@
  * to work in any other usage than IGraphicBufferSource.
  */
 struct C2OMXNode : public BnOMXNode {
-
-    using InputGater = InputSurfaceWrapper::InputGater;
-
-    explicit C2OMXNode(
-            const std::shared_ptr<Codec2Client::Component> &comp,
-            const std::shared_ptr<InputGater> &inputGater);
+    explicit C2OMXNode(const std::shared_ptr<Codec2Client::Component> &comp);
     ~C2OMXNode() override = default;
 
     // IOMXNode
@@ -87,7 +80,6 @@
 
 private:
     std::weak_ptr<Codec2Client::Component> mComp;
-    std::weak_ptr<InputGater> mInputGater;
     sp<IOMXBufferSource> mBufferSource;
     std::shared_ptr<C2Allocator> mAllocator;
     std::atomic_uint64_t mFrameIndex;
diff --git a/media/sfplugin/CCodec.cpp b/media/sfplugin/CCodec.cpp
index e370edd..20c3de3 100644
--- a/media/sfplugin/CCodec.cpp
+++ b/media/sfplugin/CCodec.cpp
@@ -139,8 +139,7 @@
 
     ~C2InputSurfaceWrapper() override = default;
 
-    status_t connect(const std::shared_ptr<Codec2Client::Component> &comp,
-                     const std::shared_ptr<InputGater>& /*inputGater*/) override {
+    status_t connect(const std::shared_ptr<Codec2Client::Component> &comp) override {
         if (mConnection != nullptr) {
             return ALREADY_EXISTS;
         }
@@ -192,9 +191,8 @@
     }
     ~GraphicBufferSourceWrapper() override = default;
 
-    status_t connect(const std::shared_ptr<Codec2Client::Component> &comp,
-                     const std::shared_ptr<InputGater> &inputGater) override {
-        mNode = new C2OMXNode(comp, inputGater);
+    status_t connect(const std::shared_ptr<Codec2Client::Component> &comp) override {
+        mNode = new C2OMXNode(comp);
         mNode->setFrameSize(mWidth, mHeight);
 
         // NOTE: we do not use/pass through color aspects from GraphicBufferSource as we
@@ -375,7 +373,6 @@
     sp<C2OMXNode> mNode;
     uint32_t mWidth;
     uint32_t mHeight;
-    std::shared_ptr<C2OMXNode::InputGater> mInputGater;
     Config mConfig;
 };
 
diff --git a/media/sfplugin/CCodecBufferChannel.cpp b/media/sfplugin/CCodecBufferChannel.cpp
index d6d6d68..2cdea6e 100644
--- a/media/sfplugin/CCodecBufferChannel.cpp
+++ b/media/sfplugin/CCodecBufferChannel.cpp
@@ -1428,31 +1428,6 @@
     return false;
 }
 
-bool CCodecBufferChannel::PipelineCapacity::allocateOutput(const char* callerTag) {
-    int prevComponent = component.fetch_sub(1, std::memory_order_relaxed);
-    int prevOutput = output.fetch_sub(1, std::memory_order_relaxed);
-    if (prevComponent > 0 && prevOutput > 1) { // One output reserved for csd.
-        ALOGV("[%s] %s -- PipelineCapacity::allocateOutput() returns true: "
-              "pipeline availability -1 output and -1 component ==> "
-              "input = %d, component = %d, output = %d",
-                mName, callerTag ? callerTag : "*",
-                input.load(std::memory_order_relaxed),
-                prevComponent - 1,
-                prevOutput - 1);
-        return true;
-    }
-    component.fetch_add(1, std::memory_order_relaxed);
-    output.fetch_add(1, std::memory_order_relaxed);
-    ALOGV("[%s] %s -- PipelineCapacity::allocateOutput() returns false: "
-          "pipeline availability unchanged ==> "
-          "input = %d, component = %d, output = %d",
-            mName, callerTag ? callerTag : "*",
-            input.load(std::memory_order_relaxed),
-            prevComponent,
-            prevOutput);
-    return false;
-}
-
 void CCodecBufferChannel::PipelineCapacity::free(const char* callerTag) {
     int prevInput = input.fetch_add(1, std::memory_order_relaxed);
     int prevComponent = component.fetch_add(1, std::memory_order_relaxed);
@@ -1509,23 +1484,6 @@
     return prevOutput + 1;
 }
 
-// InputGater
-struct CCodecBufferChannel::InputGater : public InputSurfaceWrapper::InputGater {
-    InputGater(const std::shared_ptr<CCodecBufferChannel>& owner)
-          : mOwner(owner) {}
-    virtual bool canQueue() override {
-        std::shared_ptr<CCodecBufferChannel> owner = mOwner.lock();
-        if (!owner) {
-            return false;
-        }
-        QueueGuard guard(owner->mSync);
-        return guard.isRunning() &&
-                owner->mAvailablePipelineCapacity.allocateOutput("InputGater");
-    }
-private:
-    std::weak_ptr<CCodecBufferChannel> mOwner;
-};
-
 // CCodecBufferChannel
 
 CCodecBufferChannel::CCodecBufferChannel(
@@ -1559,8 +1517,7 @@
         const std::shared_ptr<InputSurfaceWrapper> &surface) {
     ALOGV("[%s] setInputSurface", mName);
     mInputSurface = surface;
-    mInputGater = std::make_shared<InputGater>(shared_from_this());
-    return mInputSurface->connect(mComponent, mInputGater);
+    return mInputSurface->connect(mComponent);
 }
 
 status_t CCodecBufferChannel::signalEndOfInputStream() {
@@ -2361,7 +2318,6 @@
     if (mInputSurface != nullptr) {
         mInputSurface.reset();
     }
-    mInputGater.reset();
 }
 
 void CCodecBufferChannel::flush(const std::list<std::unique_ptr<C2Work>> &flushedWork) {
diff --git a/media/sfplugin/CCodecBufferChannel.h b/media/sfplugin/CCodecBufferChannel.h
index 3ef58be..86739ab 100644
--- a/media/sfplugin/CCodecBufferChannel.h
+++ b/media/sfplugin/CCodecBufferChannel.h
@@ -308,18 +308,6 @@
         // onInputBufferAvailable() can (and will) be called afterwards.
         bool allocate(const char* callerTag = nullptr);
 
-        // Return true and decrease #component and #output by one if they are
-        // all greater than zero; return false otherwise.
-        //
-        // callerTag is used for logging only.
-        //
-        // allocateOutput() is called by CCodecBufferChannel::InputGater to
-        // check whether the component can accept a queue operation. This is
-        // used when the input comes from an input surface rather than from
-        // queueInputBuffer(). Calling allocateOutput() is similar to calling
-        // allocate() when the input capacity is infinite.
-        bool allocateOutput(const char* callerTag = nullptr);
-
         // Increase #input, #component and #output by one.
         //
         // callerTag is used for logging only.
@@ -368,9 +356,6 @@
     inline bool hasCryptoOrDescrambler() {
         return mCrypto != NULL || mDescrambler != NULL;
     }
-
-    struct InputGater;
-    std::shared_ptr<InputGater> mInputGater;
 };
 
 // Conversion of a c2_status_t value to a status_t value may depend on the
diff --git a/media/sfplugin/InputSurfaceWrapper.h b/media/sfplugin/InputSurfaceWrapper.h
index 12e58b2..d9c4eec 100644
--- a/media/sfplugin/InputSurfaceWrapper.h
+++ b/media/sfplugin/InputSurfaceWrapper.h
@@ -33,33 +33,15 @@
 
     virtual ~InputSurfaceWrapper() = default;
 
-    struct InputGater {
-        /**
-         * Try to reserve an input in the pipeline. If this function returns
-         * true, the pipeline slot is reserved. An implementation of
-         * InputSurfaceWrapper should not call Component::queue() if canQueue()
-         * returns false.
-         *
-         * \return true if the input can be reserved; false otherwise.
-         */
-        virtual bool canQueue() = 0;
-        virtual ~InputGater() = default;
-    };
-
     /**
      * Connect the surface with |comp|. A surface can
      * connect to at most one component at a time.
      *
-     * `inputGater->canQueue()` will be called before queuing a buffer. If it
-     * returns false, the buffer will not be queued to `comp` and simply
-     * dropped.
-     *
      * \return OK               successfully connected to |comp|
      * \return ALREADY_EXISTS   already connected to another component.
      */
     virtual status_t connect(
-            const std::shared_ptr<Codec2Client::Component> &comp,
-            const std::shared_ptr<InputGater> &inputGater) = 0;
+            const std::shared_ptr<Codec2Client::Component> &comp) = 0;
 
     /**
      * Disconnect the surface from the component if any.