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 | |
| 22 | #include <media/stagefright/foundation/ADebug.h> |
| 23 | #include <utils/KeyedVector.h> |
| 24 | #include <utils/RefBase.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
Marco Nelissen | 2a243f0 | 2018-01-30 08:29:57 -0800 | [diff] [blame] | 28 | class DataSourceBase; |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 29 | class MetaData; |
| 30 | |
| 31 | namespace heif { |
| 32 | |
| 33 | struct AssociationEntry; |
| 34 | struct ImageItem; |
Chong Zhang | 01a7601 | 2018-03-14 18:19:49 -0700 | [diff] [blame^] | 35 | struct ExifItem; |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 36 | struct ItemLoc; |
| 37 | struct ItemInfo; |
| 38 | struct ItemProperty; |
| 39 | struct ItemReference; |
| 40 | |
| 41 | /* |
| 42 | * ItemTable keeps track of all image items (including coded images, grids and |
| 43 | * tiles) inside a HEIF still image (ISO/IEC FDIS 23008-12.2:2017(E)). |
| 44 | */ |
| 45 | |
| 46 | class ItemTable : public RefBase { |
| 47 | public: |
Marco Nelissen | 2a243f0 | 2018-01-30 08:29:57 -0800 | [diff] [blame] | 48 | explicit ItemTable(DataSourceBase *source); |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 49 | |
| 50 | status_t parse(uint32_t type, off64_t offset, size_t size); |
| 51 | |
| 52 | bool isValid() { return mImageItemsValid; } |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 53 | uint32_t countImages() const; |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 54 | sp<MetaData> getImageMeta(const uint32_t imageIndex); |
| 55 | status_t findImageItem(const uint32_t imageIndex, uint32_t *itemIndex); |
| 56 | status_t findThumbnailItem(const uint32_t imageIndex, uint32_t *itemIndex); |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 57 | status_t getImageOffsetAndSize( |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 58 | uint32_t *itemIndex, off64_t *offset, size_t *size); |
Chong Zhang | 01a7601 | 2018-03-14 18:19:49 -0700 | [diff] [blame^] | 59 | status_t getExifOffsetAndSize(off64_t *offset, size_t *size); |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 60 | |
| 61 | protected: |
| 62 | ~ItemTable(); |
| 63 | |
| 64 | private: |
Marco Nelissen | 2a243f0 | 2018-01-30 08:29:57 -0800 | [diff] [blame] | 65 | DataSourceBase *mDataSource; |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 66 | |
| 67 | KeyedVector<uint32_t, ItemLoc> mItemLocs; |
| 68 | Vector<ItemInfo> mItemInfos; |
| 69 | Vector<AssociationEntry> mAssociations; |
| 70 | Vector<sp<ItemProperty> > mItemProperties; |
| 71 | Vector<sp<ItemReference> > mItemReferences; |
| 72 | |
| 73 | uint32_t mPrimaryItemId; |
| 74 | off64_t mIdatOffset; |
| 75 | size_t mIdatSize; |
| 76 | |
| 77 | std::set<uint32_t> mRequiredBoxes; |
| 78 | std::set<uint32_t> mBoxesSeen; |
| 79 | |
| 80 | bool mImageItemsValid; |
Chong Zhang | ecd0813 | 2017-10-05 16:09:29 -0700 | [diff] [blame] | 81 | uint32_t mCurrentItemIndex; |
| 82 | KeyedVector<uint32_t, ImageItem> mItemIdToItemMap; |
Chong Zhang | 01a7601 | 2018-03-14 18:19:49 -0700 | [diff] [blame^] | 83 | KeyedVector<uint32_t, ExifItem> mItemIdToExifMap; |
Chong Zhang | d3e0d86 | 2017-10-03 13:17:13 -0700 | [diff] [blame] | 84 | Vector<uint32_t> mDisplayables; |
Chong Zhang | b51ca28 | 2017-07-26 16:25:28 -0700 | [diff] [blame] | 85 | |
| 86 | status_t parseIlocBox(off64_t offset, size_t size); |
| 87 | status_t parseIinfBox(off64_t offset, size_t size); |
| 88 | status_t parsePitmBox(off64_t offset, size_t size); |
| 89 | status_t parseIprpBox(off64_t offset, size_t size); |
| 90 | status_t parseIdatBox(off64_t offset, size_t size); |
| 91 | status_t parseIrefBox(off64_t offset, size_t size); |
| 92 | |
| 93 | void attachProperty(const AssociationEntry &association); |
| 94 | status_t buildImageItemsIfPossible(uint32_t type); |
| 95 | |
| 96 | DISALLOW_EVIL_CONSTRUCTORS(ItemTable); |
| 97 | }; |
| 98 | |
| 99 | } // namespace heif |
| 100 | } // namespace android |
| 101 | |
| 102 | #endif // ITEM_TABLE_H_ |