Wait for iref box if the heic file has Exif data

When exif items are present, iref box must be present to
associate exif with image items.

bug: 123094535
test: use ExifInterface on files without grid, should be
      able to extract exif if available.

Change-Id: Ia0728cdeefe28318a4ca03193ad93c3b64d78f7a
diff --git a/media/extractors/mp4/ItemTable.cpp b/media/extractors/mp4/ItemTable.cpp
index eb6602c..a72e589 100644
--- a/media/extractors/mp4/ItemTable.cpp
+++ b/media/extractors/mp4/ItemTable.cpp
@@ -17,6 +17,8 @@
 //#define LOG_NDEBUG 0
 #define LOG_TAG "ItemTable"
 
+#include <unordered_set>
+
 #include <ItemTable.h>
 #include <media/MediaExtractorPluginApi.h>
 #include <media/MediaExtractorPluginHelper.h>
@@ -1129,19 +1131,18 @@
 
 struct IinfBox : public FullBox {
     IinfBox(DataSourceHelper *source, Vector<ItemInfo> *itemInfos) :
-        FullBox(source, FOURCC("iinf")),
-        mItemInfos(itemInfos), mHasGrids(false) {}
+        FullBox(source, FOURCC("iinf")), mItemInfos(itemInfos) {}
 
     status_t parse(off64_t offset, size_t size);
 
-    bool hasGrids() { return mHasGrids; }
+    bool hasFourCC(uint32_t type) { return mFourCCSeen.count(type) > 0; }
 
 protected:
     status_t onChunkData(uint32_t type, off64_t offset, size_t size) override;
 
 private:
     Vector<ItemInfo> *mItemInfos;
-    bool mHasGrids;
+    std::unordered_set<uint32_t> mFourCCSeen;
 };
 
 status_t IinfBox::parse(off64_t offset, size_t size) {
@@ -1188,7 +1189,7 @@
     status_t err = infeBox.parse(offset, size, &itemInfo);
     if (err == OK) {
         mItemInfos->push_back(itemInfo);
-        mHasGrids |= (itemInfo.itemType == FOURCC("grid"));
+        mFourCCSeen.insert(itemInfo.itemType);
     }
     // InfeBox parse returns ERROR_UNSUPPORTED if the box if an unsupported
     // version. Ignore this error as it's not fatal.
@@ -1277,7 +1278,7 @@
         return err;
     }
 
-    if (iinfBox.hasGrids()) {
+    if (iinfBox.hasFourCC(FOURCC("grid")) || iinfBox.hasFourCC(FOURCC("Exif"))) {
         mRequiredBoxes.insert('iref');
     }