/src/libheif/libheif/file_layout.h
Line | Count | Source |
1 | | /* |
2 | | * HEIF 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_FILELAYOUT_H |
22 | | #define LIBHEIF_FILELAYOUT_H |
23 | | |
24 | | #include "error.h" |
25 | | #include "bitstream.h" |
26 | | #include "box.h" |
27 | | #if ENABLE_EXPERIMENTAL_MINI_FORMAT |
28 | | #include "mini.h" |
29 | | #endif |
30 | | |
31 | | #include <memory> |
32 | | #include <vector> |
33 | | |
34 | | class Box_moov; |
35 | | |
36 | | |
37 | | class FileLayout |
38 | | { |
39 | | public: |
40 | | enum class WriteMode { |
41 | | Streaming, // 'mdat' data will be written to output immediately |
42 | | Floating, // 'mdat' data will be held in memory until written |
43 | | TmpFile // 'mdat' data will be written to temporary file and copied into final file |
44 | | }; |
45 | | |
46 | | // Generate a file in WriteMode::Floating |
47 | | FileLayout(); |
48 | | |
49 | | Error read(const std::shared_ptr<StreamReader>& stream, const heif_security_limits* limits); |
50 | | |
51 | | // For WriteMode::Streaming, writer cannot be null. |
52 | | void set_write_mode(WriteMode writeMode, const std::shared_ptr<StreamWriter>& writer = nullptr); |
53 | | |
54 | | // For WriteMode::Streaming, stream must be null. |
55 | | Error write(std::shared_ptr<StreamWriter>& stream); |
56 | | |
57 | | |
58 | | // --- access to boxes |
59 | | |
60 | 4.81k | std::shared_ptr<Box_ftyp> get_ftyp_box() { return m_ftyp_box; } |
61 | | |
62 | 4.27k | std::shared_ptr<Box_meta> get_meta_box() { return m_meta_box; } |
63 | | |
64 | | #if ENABLE_EXPERIMENTAL_MINI_FORMAT |
65 | | std::shared_ptr<Box_mini> get_mini_box() { return m_mini_box; } |
66 | | #endif |
67 | | |
68 | 4.27k | std::shared_ptr<Box_moov> get_moov_box() { return m_moov_box; } |
69 | | |
70 | | private: |
71 | | WriteMode m_writeMode = WriteMode::Floating; |
72 | | |
73 | | const static uint64_t INVALID_FILE_SIZE = 0xFFFFFFFFFFFFFFFF; |
74 | | |
75 | | uint64_t m_file_size = INVALID_FILE_SIZE; |
76 | | |
77 | | // the first one is always 'ftyp' |
78 | | std::vector<std::shared_ptr<Box>> m_boxes; // TODO: do we need this ? |
79 | | |
80 | | std::shared_ptr<Box_ftyp> m_ftyp_box; |
81 | | std::shared_ptr<Box_meta> m_meta_box; |
82 | | #if ENABLE_EXPERIMENTAL_MINI_FORMAT |
83 | | std::shared_ptr<Box_mini> m_mini_box; |
84 | | #endif |
85 | | std::shared_ptr<Box_moov> m_moov_box; |
86 | | |
87 | | |
88 | | uint64_t m_max_length = 0; // Length seen so far. It can grow over time. |
89 | | |
90 | | std::shared_ptr<StreamReader> m_stream_reader; |
91 | | std::shared_ptr<StreamWriter> m_stream_writer; |
92 | | |
93 | | static const uint64_t INITIAL_FTYP_REQUEST = 1024; // should be enough to read ftyp and next box header |
94 | | static const uint16_t MAXIMUM_BOX_HEADER_SIZE = 32; |
95 | | }; |
96 | | |
97 | | #endif //LIBHEIF_FILELAYOUT_H |