IOMX: do not allocate if output port is in metadata mode

We used to always use useBuffer() for output meta. If we let
the component allocate, some components (eg. secure decoder)
could give us a buffer that we can't update.

bug: 32136559
Change-Id: I1eefe5cbde2d0b1944ff3e72e31663693f6c1fdb
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index 478de35..0ee3967 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -1215,7 +1215,6 @@
         info.mCodecData = info.mData;
         info.mCodecRef = mem;
 
-        // we use useBuffer for metadata regardless of quirks
         err = mOMXNode->useBuffer(
                 kPortIndexOutput, mem, &info.mBufferID, mem->size());
         mBuffers[kPortIndexOutput].push(info);
diff --git a/media/libstagefright/omx/OMXNodeInstance.cpp b/media/libstagefright/omx/OMXNodeInstance.cpp
index ef18958..2a4bd15 100644
--- a/media/libstagefright/omx/OMXNodeInstance.cpp
+++ b/media/libstagefright/omx/OMXNodeInstance.cpp
@@ -912,13 +912,17 @@
     OMX_BUFFERHEADERTYPE *header;
     OMX_ERRORTYPE err = OMX_ErrorNone;
     bool isMetadata = mMetadataType[portIndex] != kMetadataBufferTypeInvalid;
+    bool isOutputGraphicMetadata = (portIndex == kPortIndexOutput) &&
+            (mMetadataType[portIndex] == kMetadataBufferTypeGrallocSource ||
+                    mMetadataType[portIndex] == kMetadataBufferTypeANWBuffer);
 
     uint32_t requiresAllocateBufferBit =
         (portIndex == kPortIndexInput)
             ? kRequiresAllocateBufferOnInputPorts
             : kRequiresAllocateBufferOnOutputPorts;
 
-    if (mQuirks & requiresAllocateBufferBit) {
+    // we use useBuffer for output metadata regardless of quirks
+    if (!isOutputGraphicMetadata && (mQuirks & requiresAllocateBufferBit)) {
         // metadata buffers are not connected cross process; only copy if not meta.
         buffer_meta = new BufferMeta(
                     params, portIndex, !isMetadata /* copy */, NULL /* data */);