/src/libheif/libheif/codecs/avc_boxes.h
Line | Count | Source |
1 | | /* |
2 | | * HEIF AVC codec. |
3 | | * Copyright (c) 2023 Brad Hards <bradh@frogmouth.net> |
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 HEIF_AVC_BOXES_H |
22 | | #define HEIF_AVC_BOXES_H |
23 | | |
24 | | #include "box.h" |
25 | | #include "error.h" |
26 | | #include <cstdint> |
27 | | #include <vector> |
28 | | #include <string> |
29 | | #include <memory> |
30 | | #include "image-items/image_item.h" |
31 | | #include "sequences/seq_boxes.h" |
32 | | |
33 | | |
34 | | class Box_avcC : public Box { |
35 | | public: |
36 | 3.04k | Box_avcC() { set_short_type(fourcc("avcC")); } |
37 | | |
38 | 0 | bool is_essential() const override { return true; } |
39 | | |
40 | | struct configuration { |
41 | | uint8_t configuration_version = 0; |
42 | | uint8_t AVCProfileIndication = 0; // profile_idc |
43 | | uint8_t profile_compatibility = 0; // constraint set flags |
44 | | uint8_t AVCLevelIndication = 0; // level_idc |
45 | | uint8_t lengthSize = 0; // length of NAL size field. Must be one of: 1,2,4 |
46 | | heif_chroma chroma_format = heif_chroma_420; // Note: avcC integer value can be cast to heif_chroma enum |
47 | | uint8_t bit_depth_luma = 8; |
48 | | uint8_t bit_depth_chroma = 8; |
49 | | }; |
50 | | |
51 | | void set_configuration(const configuration& config) |
52 | 0 | { |
53 | 0 | m_configuration = config; |
54 | 0 | } |
55 | | |
56 | | const configuration& get_configuration() const |
57 | 0 | { |
58 | 0 | return m_configuration; |
59 | 0 | } |
60 | | |
61 | | configuration& get_configuration() |
62 | 0 | { |
63 | 0 | return m_configuration; |
64 | 0 | } |
65 | | |
66 | | const std::vector< std::vector<uint8_t> > getSequenceParameterSets() const |
67 | 0 | { |
68 | 0 | return m_sps; |
69 | 0 | } |
70 | | |
71 | | const std::vector< std::vector<uint8_t> > getPictureParameterSets() const |
72 | 0 | { |
73 | 0 | return m_pps; |
74 | 0 | } |
75 | | |
76 | | const std::vector< std::vector<uint8_t> > getSequenceParameterSetExt() const |
77 | 0 | { |
78 | 0 | return m_sps_ext; |
79 | 0 | } |
80 | | |
81 | | void get_header_nals(std::vector<uint8_t>& data) const; |
82 | | |
83 | | void append_sps_nal(const uint8_t* data, size_t size); |
84 | | |
85 | | void append_sps_ext_nal(const uint8_t* data, size_t size); |
86 | | |
87 | | void append_pps_nal(const uint8_t* data, size_t size); |
88 | | |
89 | | std::string dump(Indent &) const override; |
90 | | |
91 | | Error write(StreamWriter &writer) const override; |
92 | | |
93 | | protected: |
94 | | Error parse(BitstreamRange &range, const heif_security_limits* limits) override; |
95 | | |
96 | | std::string profileIndicationAsText() const; |
97 | | |
98 | | private: |
99 | | configuration m_configuration; |
100 | | std::vector< std::vector<uint8_t> > m_sps; |
101 | | std::vector< std::vector<uint8_t> > m_pps; |
102 | | std::vector< std::vector<uint8_t> > m_sps_ext; |
103 | | }; |
104 | | |
105 | | |
106 | | |
107 | | class Box_avc1 : public Box_VisualSampleEntry |
108 | | { |
109 | | public: |
110 | | Box_avc1() |
111 | 47 | { |
112 | 47 | set_short_type(fourcc("avc1")); |
113 | 47 | } |
114 | | }; |
115 | | |
116 | | Error parse_sps_for_avcC_configuration(const uint8_t* sps, size_t size, |
117 | | Box_avcC::configuration* inout_config, |
118 | | int* width, int* height); |
119 | | |
120 | | #endif |