blob: 62826b6b2548b211f3e81b7bbab7aa0755344227 [file] [log] [blame]
Chong Zhangb51ca282017-07-26 16:25:28 -07001/*
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 Nelissendba610b2018-11-01 16:07:03 -070022#include <media/NdkMediaFormat.h>
23
Chong Zhangb51ca282017-07-26 16:25:28 -070024#include <media/stagefright/foundation/ADebug.h>
25#include <utils/KeyedVector.h>
26#include <utils/RefBase.h>
27
28namespace android {
29
Marco Nelissencec44d02018-06-17 22:21:09 -070030class DataSourceHelper;
Chong Zhangb51ca282017-07-26 16:25:28 -070031class MetaData;
32
33namespace heif {
34
35struct AssociationEntry;
36struct ImageItem;
Chong Zhangaf638822020-12-09 17:19:25 -080037struct ExternalMetaItem;
Chong Zhangb51ca282017-07-26 16:25:28 -070038struct ItemLoc;
39struct ItemInfo;
40struct ItemProperty;
41struct ItemReference;
42
43/*
44 * ItemTable keeps track of all image items (including coded images, grids and
Vignesh Venkatasubramanianf89bf3c2020-10-05 17:28:45 -070045 * tiles) inside a HEIF/AVIF still image (ISO/IEC FDIS 23008-12.2:2017(E)).
Chong Zhangb51ca282017-07-26 16:25:28 -070046 */
47
48class ItemTable : public RefBase {
49public:
Vignesh Venkatasubramanianf89bf3c2020-10-05 17:28:45 -070050 ItemTable(DataSourceHelper *source, bool isHeif);
Chong Zhangb51ca282017-07-26 16:25:28 -070051
52 status_t parse(uint32_t type, off64_t offset, size_t size);
53
54 bool isValid() { return mImageItemsValid; }
Chong Zhangb51ca282017-07-26 16:25:28 -070055 uint32_t countImages() const;
Marco Nelissendba610b2018-11-01 16:07:03 -070056 AMediaFormat *getImageMeta(const uint32_t imageIndex);
Chong Zhangd3e0d862017-10-03 13:17:13 -070057 status_t findImageItem(const uint32_t imageIndex, uint32_t *itemIndex);
58 status_t findThumbnailItem(const uint32_t imageIndex, uint32_t *itemIndex);
Chong Zhangb51ca282017-07-26 16:25:28 -070059 status_t getImageOffsetAndSize(
Chong Zhangd3e0d862017-10-03 13:17:13 -070060 uint32_t *itemIndex, off64_t *offset, size_t *size);
Chong Zhang01a76012018-03-14 18:19:49 -070061 status_t getExifOffsetAndSize(off64_t *offset, size_t *size);
Chong Zhangaf638822020-12-09 17:19:25 -080062 status_t getXmpOffsetAndSize(off64_t *offset, size_t *size);
Chong Zhangb51ca282017-07-26 16:25:28 -070063
64protected:
65 ~ItemTable();
66
67private:
Marco Nelissencec44d02018-06-17 22:21:09 -070068 DataSourceHelper *mDataSource;
Vignesh Venkatasubramanianf89bf3c2020-10-05 17:28:45 -070069 // If this is true, then this item table is for a HEIF image. Otherwise it is for an AVIF image.
70 bool mIsHeif;
Chong Zhangb51ca282017-07-26 16:25:28 -070071
72 KeyedVector<uint32_t, ItemLoc> mItemLocs;
73 Vector<ItemInfo> mItemInfos;
74 Vector<AssociationEntry> mAssociations;
75 Vector<sp<ItemProperty> > mItemProperties;
76 Vector<sp<ItemReference> > mItemReferences;
77
78 uint32_t mPrimaryItemId;
79 off64_t mIdatOffset;
80 size_t mIdatSize;
81
82 std::set<uint32_t> mRequiredBoxes;
83 std::set<uint32_t> mBoxesSeen;
84
85 bool mImageItemsValid;
Chong Zhangecd08132017-10-05 16:09:29 -070086 uint32_t mCurrentItemIndex;
87 KeyedVector<uint32_t, ImageItem> mItemIdToItemMap;
Chong Zhangaf638822020-12-09 17:19:25 -080088 KeyedVector<uint32_t, ExternalMetaItem> mItemIdToMetaMap;
Chong Zhangd3e0d862017-10-03 13:17:13 -070089 Vector<uint32_t> mDisplayables;
Chong Zhangb51ca282017-07-26 16:25:28 -070090
91 status_t parseIlocBox(off64_t offset, size_t size);
92 status_t parseIinfBox(off64_t offset, size_t size);
93 status_t parsePitmBox(off64_t offset, size_t size);
94 status_t parseIprpBox(off64_t offset, size_t size);
95 status_t parseIdatBox(off64_t offset, size_t size);
96 status_t parseIrefBox(off64_t offset, size_t size);
97
98 void attachProperty(const AssociationEntry &association);
99 status_t buildImageItemsIfPossible(uint32_t type);
100
101 DISALLOW_EVIL_CONSTRUCTORS(ItemTable);
102};
103
104} // namespace heif
105} // namespace android
106
107#endif // ITEM_TABLE_H_