Support multiple codecs per crypto instance

The initial drm hidl hal implementation assumed one
codec per crypto instance, but in fact there can be
multiple codecs per crypto instance. This change
extends the drm hal to allow multiple memory heaps
per crypto plugin. It fixes the issue of mapping
memory frequently during playback.

bug:35275191

Test: manual verification with Play Movies on angler
in passthrough mode and on marlin in binderized mode.

Change-Id: Icada005f515483d7bc214b08caf6eea46ca354a7
diff --git a/include/media/CryptoHal.h b/include/media/CryptoHal.h
index 1ace957..9d0c3e4 100644
--- a/include/media/CryptoHal.h
+++ b/include/media/CryptoHal.h
@@ -26,6 +26,8 @@
 
 #include "SharedLibrary.h"
 
+class IMemoryHeap;
+
 namespace android {
 
 struct CryptoHal : public BnCrypto {
@@ -70,7 +72,8 @@
      */
     status_t mInitCheck;
 
-    void *mHeapBase;
+    KeyedVector<void *, uint32_t> mHeapBases;
+    uint32_t mNextBufferId;
 
     sp<::android::hardware::drm::V1_0::ICryptoFactory>
             makeCryptoFactory();
@@ -78,7 +81,10 @@
             makeCryptoPlugin(const uint8_t uuid[16], const void *initData,
                 size_t size);
 
-    status_t setHeapBase(const sp<IMemory> &sharedBuffer);
+    void setHeapBase(const sp<IMemoryHeap>& heap);
+
+    status_t toSharedBuffer(const sp<IMemory>& memory,
+            ::android::hardware::drm::V1_0::SharedBuffer* buffer);
 
     DISALLOW_EVIL_CONSTRUCTORS(CryptoHal);
 };