| Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2017 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 | #ifndef ITEM_TABLE_H_ | 
 | 18 | #define ITEM_TABLE_H_ | 
 | 19 |  | 
 | 20 | #include <set> | 
 | 21 |  | 
| Marco Nelissen | dba610b | 2018-11-01 16:07:03 -0700 | [diff] [blame^] | 22 | #include <media/NdkMediaFormat.h> | 
 | 23 |  | 
| Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 24 | #include <media/stagefright/foundation/ADebug.h> | 
 | 25 | #include <utils/KeyedVector.h> | 
 | 26 | #include <utils/RefBase.h> | 
 | 27 |  | 
 | 28 | namespace android { | 
 | 29 |  | 
| Marco Nelissen | cec44d0 | 2018-06-17 22:21:09 -0700 | [diff] [blame] | 30 | class DataSourceHelper; | 
| Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 31 | class MetaData; | 
 | 32 |  | 
 | 33 | namespace heif { | 
 | 34 |  | 
 | 35 | struct AssociationEntry; | 
 | 36 | struct ImageItem; | 
| Chong Zhang | 01a7601 | 2018-03-14 18:19:49 -0700 | [diff] [blame] | 37 | struct ExifItem; | 
| Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 38 | struct ItemLoc; | 
 | 39 | struct ItemInfo; | 
 | 40 | struct ItemProperty; | 
 | 41 | struct ItemReference; | 
 | 42 |  | 
 | 43 | /* | 
 | 44 |  * ItemTable keeps track of all image items (including coded images, grids and | 
 | 45 |  * tiles) inside a HEIF still image (ISO/IEC FDIS 23008-12.2:2017(E)). | 
 | 46 |  */ | 
 | 47 |  | 
 | 48 | class ItemTable : public RefBase { | 
 | 49 | public: | 
| Marco Nelissen | cec44d0 | 2018-06-17 22:21:09 -0700 | [diff] [blame] | 50 |     explicit ItemTable(DataSourceHelper *source); | 
| Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 51 |  | 
 | 52 |     status_t parse(uint32_t type, off64_t offset, size_t size); | 
 | 53 |  | 
 | 54 |     bool isValid() { return mImageItemsValid; } | 
| Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 55 |     uint32_t countImages() const; | 
| Marco Nelissen | dba610b | 2018-11-01 16:07:03 -0700 | [diff] [blame^] | 56 |     AMediaFormat *getImageMeta(const uint32_t imageIndex); | 
| Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 57 |     status_t findImageItem(const uint32_t imageIndex, uint32_t *itemIndex); | 
 | 58 |     status_t findThumbnailItem(const uint32_t imageIndex, uint32_t *itemIndex); | 
| Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 59 |     status_t getImageOffsetAndSize( | 
| Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 60 |             uint32_t *itemIndex, off64_t *offset, size_t *size); | 
| Chong Zhang | 01a7601 | 2018-03-14 18:19:49 -0700 | [diff] [blame] | 61 |     status_t getExifOffsetAndSize(off64_t *offset, size_t *size); | 
| Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 62 |  | 
 | 63 | protected: | 
 | 64 |     ~ItemTable(); | 
 | 65 |  | 
 | 66 | private: | 
| Marco Nelissen | cec44d0 | 2018-06-17 22:21:09 -0700 | [diff] [blame] | 67 |     DataSourceHelper *mDataSource; | 
| Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 68 |  | 
 | 69 |     KeyedVector<uint32_t, ItemLoc> mItemLocs; | 
 | 70 |     Vector<ItemInfo> mItemInfos; | 
 | 71 |     Vector<AssociationEntry> mAssociations; | 
 | 72 |     Vector<sp<ItemProperty> > mItemProperties; | 
 | 73 |     Vector<sp<ItemReference> > mItemReferences; | 
 | 74 |  | 
 | 75 |     uint32_t mPrimaryItemId; | 
 | 76 |     off64_t mIdatOffset; | 
 | 77 |     size_t mIdatSize; | 
 | 78 |  | 
 | 79 |     std::set<uint32_t> mRequiredBoxes; | 
 | 80 |     std::set<uint32_t> mBoxesSeen; | 
 | 81 |  | 
 | 82 |     bool mImageItemsValid; | 
| Chong Zhang | ecd0813 | 2017-10-05 16:09:29 -0700 | [diff] [blame] | 83 |     uint32_t mCurrentItemIndex; | 
 | 84 |     KeyedVector<uint32_t, ImageItem> mItemIdToItemMap; | 
| Chong Zhang | 01a7601 | 2018-03-14 18:19:49 -0700 | [diff] [blame] | 85 |     KeyedVector<uint32_t, ExifItem> mItemIdToExifMap; | 
| Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 86 |     Vector<uint32_t> mDisplayables; | 
| Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 87 |  | 
 | 88 |     status_t parseIlocBox(off64_t offset, size_t size); | 
 | 89 |     status_t parseIinfBox(off64_t offset, size_t size); | 
 | 90 |     status_t parsePitmBox(off64_t offset, size_t size); | 
 | 91 |     status_t parseIprpBox(off64_t offset, size_t size); | 
 | 92 |     status_t parseIdatBox(off64_t offset, size_t size); | 
 | 93 |     status_t parseIrefBox(off64_t offset, size_t size); | 
 | 94 |  | 
 | 95 |     void attachProperty(const AssociationEntry &association); | 
 | 96 |     status_t buildImageItemsIfPossible(uint32_t type); | 
 | 97 |  | 
 | 98 |     DISALLOW_EVIL_CONSTRUCTORS(ItemTable); | 
 | 99 | }; | 
 | 100 |  | 
 | 101 | } // namespace heif | 
 | 102 | } // namespace android | 
 | 103 |  | 
 | 104 | #endif  // ITEM_TABLE_H_ |