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