/src/libheif/libheif/sequences/chunk.h
Line | Count | Source |
1 | | /* |
2 | | * HEIF image base codec. |
3 | | * Copyright (c) 2024 Dirk Farin <dirk.farin@gmail.com> |
4 | | * |
5 | | * This file is part of libheif. |
6 | | * |
7 | | * libheif is free software: you can redistribute it and/or modify |
8 | | * it under the terms of the GNU Lesser General Public License as |
9 | | * published by the Free Software Foundation, either version 3 of |
10 | | * the License, or (at your option) any later version. |
11 | | * |
12 | | * libheif is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public License |
18 | | * along with libheif. If not, see <http://www.gnu.org/licenses/>. |
19 | | */ |
20 | | |
21 | | #ifndef LIBHEIF_CHUNK_H |
22 | | #define LIBHEIF_CHUNK_H |
23 | | |
24 | | #include "codecs/decoder.h" |
25 | | #include <memory> |
26 | | #include <utility> |
27 | | #include <vector> |
28 | | |
29 | | |
30 | | class HeifContext; |
31 | | |
32 | | class Box_VisualSampleEntry; |
33 | | |
34 | | |
35 | | class Chunk |
36 | | { |
37 | | public: |
38 | | Chunk(HeifContext* ctx, uint32_t track_id, heif_compression_format format); |
39 | | |
40 | | // Returns nullptr if the chunk cannot be constructed validly (e.g. the |
41 | | // running file offset would wrap uint64_t). |
42 | | static std::shared_ptr<Chunk> create(HeifContext* ctx, uint32_t track_id, |
43 | | uint32_t first_sample, uint32_t num_samples, |
44 | | uint64_t file_offset, |
45 | | const std::shared_ptr<const Box_stsz>& sample_sizes); |
46 | | |
47 | 1.40k | virtual ~Chunk() = default; |
48 | | |
49 | | // Size in bytes of one entry in the internal sample-range table. Used by the |
50 | | // owning Track to reserve the aggregate memory for all chunks up front |
51 | | // (GHSA-xw34-mjcp-jqh8, variants V2/V3). |
52 | | static size_t sample_range_entry_size(); |
53 | | |
54 | 0 | heif_compression_format get_compression_format() const { return m_compression_format; } |
55 | | |
56 | 802 | virtual std::shared_ptr<class Decoder> get_decoder() const { return m_decoder; } |
57 | | |
58 | 0 | virtual std::shared_ptr<class Encoder> get_encoder() const { return m_encoder; } |
59 | | |
60 | 0 | uint32_t first_sample_number() const { return m_first_sample; } |
61 | | |
62 | 7.77k | uint32_t last_sample_number() const { return m_last_sample; } |
63 | | |
64 | | DataExtent get_data_extent_for_sample(uint32_t n) const; |
65 | | |
66 | 901 | void set_decoder(std::shared_ptr<class Decoder> dec) { m_decoder = std::move(dec); } |
67 | | |
68 | | private: |
69 | | // Sets `success` to false if the chunk cannot be constructed validly |
70 | | // (e.g. the running file offset would wrap uint64_t). Otherwise leaves it |
71 | | // unchanged. |
72 | | Chunk(HeifContext* ctx, uint32_t track_id, |
73 | | uint32_t first_sample, uint32_t num_samples, uint64_t file_offset, |
74 | | const std::shared_ptr<const Box_stsz>& sample_sizes, bool& success); |
75 | | |
76 | | HeifContext* m_ctx = nullptr; |
77 | | uint32_t m_track_id = 0; |
78 | | |
79 | | heif_compression_format m_compression_format = heif_compression_undefined; |
80 | | |
81 | | uint32_t m_first_sample = 0; |
82 | | uint32_t m_last_sample = 0; |
83 | | |
84 | | //uint32_t m_sample_description_index = 0; |
85 | | |
86 | | uint32_t m_next_sample_to_be_decoded = 0; |
87 | | |
88 | | struct SampleFileRange |
89 | | { |
90 | | uint64_t offset = 0; |
91 | | uint32_t size = 0; |
92 | | }; |
93 | | |
94 | | std::vector<SampleFileRange> m_sample_ranges; |
95 | | |
96 | | std::shared_ptr<class Decoder> m_decoder; |
97 | | std::shared_ptr<class Encoder> m_encoder; |
98 | | }; |
99 | | |
100 | | |
101 | | #endif //LIBHEIF_CHUNK_H |