IOMX: add API for setPortMode

- Add setPortMode to centralize port mode configuration

- Remove storeMetaDataInBuffers and enableNativeBuffers. These are
  no longer exposed to the client. Metadata mode and native/secure
  buffer mode will be enabled by OMX as needed by the port mode.

- Move handling of legacy adpative experiment (legacy metadata mode)
  to OMX side. Legacy mode will now appear the same as non-metadata
  mode to client.

bug: 31399200

Change-Id: Iaf33bd7c30fab4acbc19e9fb8c19e322f9b4a0a0
diff --git a/media/libmedia/IOMX.cpp b/media/libmedia/IOMX.cpp
index 1a6d6b8..c1fe87f 100644
--- a/media/libmedia/IOMX.cpp
+++ b/media/libmedia/IOMX.cpp
@@ -37,19 +37,18 @@
     CONNECT = IBinder::FIRST_CALL_TRANSACTION,
     LIST_NODES,
     ALLOCATE_NODE,
+    CREATE_INPUT_SURFACE,
     FREE_NODE,
     SEND_COMMAND,
     GET_PARAMETER,
     SET_PARAMETER,
     GET_CONFIG,
     SET_CONFIG,
-    ENABLE_NATIVE_BUFFERS,
-    USE_BUFFER,
-    CREATE_INPUT_SURFACE,
+    SET_PORT_MODE,
     SET_INPUT_SURFACE,
-    STORE_META_DATA_IN_BUFFERS,
     PREPARE_FOR_ADAPTIVE_PLAYBACK,
     ALLOC_SECURE_BUFFER,
+    USE_BUFFER,
     FREE_BUFFER,
     FILL_BUFFER,
     EMPTY_BUFFER,
@@ -225,17 +224,15 @@
         return reply.readInt32();
     }
 
-    virtual status_t enableNativeBuffers(
-            OMX_U32 port_index, OMX_BOOL graphic, OMX_BOOL enable) {
+    virtual status_t setPortMode(
+            OMX_U32 port_index, IOMX::PortMode mode) {
         Parcel data, reply;
         data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor());
         data.writeInt32(port_index);
-        data.writeInt32((uint32_t)graphic);
-        data.writeInt32((uint32_t)enable);
-        remote()->transact(ENABLE_NATIVE_BUFFERS, data, &reply);
+        data.writeInt32(mode);
+        remote()->transact(SET_PORT_MODE, data, &reply);
 
-        status_t err = reply.readInt32();
-        return err;
+        return reply.readInt32();
     }
 
     virtual status_t getGraphicBufferUsage(
@@ -294,25 +291,6 @@
         return err;
     }
 
-    virtual status_t storeMetaDataInBuffers(
-            OMX_U32 port_index, OMX_BOOL enable, MetadataBufferType *type) {
-        Parcel data, reply;
-        data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor());
-        data.writeInt32(port_index);
-        data.writeInt32((int32_t)enable);
-        data.writeInt32(type == NULL ? kMetadataBufferTypeANWBuffer : *type);
-
-        remote()->transact(STORE_META_DATA_IN_BUFFERS, data, &reply);
-
-        // read type even storeMetaDataInBuffers failed
-        int negotiatedType = reply.readInt32();
-        if (type != NULL) {
-            *type = (MetadataBufferType)negotiatedType;
-        }
-
-        return reply.readInt32();
-    }
-
     virtual status_t prepareForAdaptivePlayback(
             OMX_U32 port_index, OMX_BOOL enable,
             OMX_U32 max_width, OMX_U32 max_height) {
@@ -670,16 +648,12 @@
             return NO_ERROR;
         }
 
-        case ENABLE_NATIVE_BUFFERS:
+        case SET_PORT_MODE:
         {
             CHECK_OMX_INTERFACE(IOMXNode, data, reply);
-
             OMX_U32 port_index = data.readInt32();
-            OMX_BOOL graphic = (OMX_BOOL)data.readInt32();
-            OMX_BOOL enable = (OMX_BOOL)data.readInt32();
-
-            status_t err = enableNativeBuffers(port_index, graphic, enable);
-            reply->writeInt32(err);
+            IOMX::PortMode mode = (IOMX::PortMode) data.readInt32();
+            reply->writeInt32(setPortMode(port_index, mode));
 
             return NO_ERROR;
         }
@@ -734,22 +708,6 @@
             return NO_ERROR;
         }
 
-        case STORE_META_DATA_IN_BUFFERS:
-        {
-            CHECK_OMX_INTERFACE(IOMXNode, data, reply);
-
-            OMX_U32 port_index = data.readInt32();
-            OMX_BOOL enable = (OMX_BOOL)data.readInt32();
-
-            MetadataBufferType type = (MetadataBufferType)data.readInt32();
-            status_t err = storeMetaDataInBuffers(port_index, enable, &type);
-
-            reply->writeInt32(type);
-            reply->writeInt32(err);
-
-            return NO_ERROR;
-        }
-
         case PREPARE_FOR_ADAPTIVE_PLAYBACK:
         {
             CHECK_OMX_INTERFACE(IOMXNode, data, reply);