Coverage Report

Created: 2026-02-14 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libheif/libheif/codecs/hevc_boxes.h
Line
Count
Source
1
/*
2
 * HEIF codec.
3
 * Copyright (c) 2017 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 HEIF_HEVC_BOXES_H
22
#define HEIF_HEVC_BOXES_H
23
24
#include "libheif/heif.h"
25
#include "box.h"
26
#include "error.h"
27
28
#include <memory>
29
#include <string>
30
#include <vector>
31
#include "image-items/image_item.h"
32
#include "sequences/seq_boxes.h"
33
34
35
struct HEVCDecoderConfigurationRecord
36
{
37
  uint8_t configuration_version;
38
  uint8_t general_profile_space;
39
  bool general_tier_flag;
40
  uint8_t general_profile_idc;
41
  uint32_t general_profile_compatibility_flags;
42
43
  static const int NUM_CONSTRAINT_INDICATOR_FLAGS = 48;
44
  std::bitset<NUM_CONSTRAINT_INDICATOR_FLAGS> general_constraint_indicator_flags;
45
46
  uint8_t general_level_idc;
47
48
  uint16_t min_spatial_segmentation_idc;
49
  uint8_t parallelism_type;
50
  uint8_t chroma_format;
51
  uint8_t bit_depth_luma;
52
  uint8_t bit_depth_chroma;
53
  uint16_t avg_frame_rate;
54
55
  uint8_t constant_frame_rate;
56
  uint8_t num_temporal_layers;
57
  uint8_t temporal_id_nested;
58
  uint8_t m_length_size = 4; // default: 4 bytes for NAL unit lengths
59
60
  struct NalArray
61
  {
62
    uint8_t m_array_completeness;
63
    uint8_t m_NAL_unit_type;
64
65
    std::vector<std::vector<uint8_t> > m_nal_units;
66
  };
67
68
  enum Profile {
69
    Profile_Main = 1,
70
    Profile_Main10 = 2,
71
    Profile_MainStillPicture = 3,
72
    Profile_RExt = 4,
73
    Profile_HighThroughput = 5,
74
    Profile_ScreenCoding = 9,
75
    Profile_HighTHroughputScreenCoding = 11
76
  };
77
78
  std::vector<NalArray> m_nal_array;
79
80
  Error parse(BitstreamRange& range, const heif_security_limits* limits);
81
82
  Error write(StreamWriter& writer) const;
83
84
  bool get_general_profile_compatibility_flag(int idx) const;
85
86
  bool is_profile_compatibile(Profile) const;
87
};
88
89
90
class Box_hvcC : public Box
91
{
92
// allow access to protected parse() method
93
friend class Box_mini;
94
95
public:
96
  Box_hvcC()
97
8.16k
  {
98
8.16k
    set_short_type(fourcc("hvcC"));
99
8.16k
  }
100
101
0
  bool is_essential() const override { return true; }
102
103
104
  std::string dump(Indent&) const override;
105
106
0
  const char* debug_box_name() const override { return "HEVC Configuration Item"; }
107
108
  bool get_header_nals(std::vector<uint8_t>* dest) const;
109
110
0
  void set_configuration(const HEVCDecoderConfigurationRecord& config) { m_configuration = config; }
111
112
9.07k
  const HEVCDecoderConfigurationRecord& get_configuration() const { return m_configuration; }
113
114
0
  HEVCDecoderConfigurationRecord& get_configuration() { return m_configuration; }
115
116
  // Add a header NAL to the hvcC. The data is the raw NAL data without any start-code or NAL size field.
117
  //
118
  // Note: we expect that all header NALs are added to the hvcC and
119
  // there are no additional header NALs in the bitstream.
120
  void append_nal_data(const std::vector<uint8_t>& nal);
121
122
  void append_nal_data(const uint8_t* data, size_t size);
123
124
  Error write(StreamWriter& writer) const override;
125
126
protected:
127
  Error parse(BitstreamRange& range, const heif_security_limits* limits) override;
128
129
private:
130
  HEVCDecoderConfigurationRecord m_configuration;
131
};
132
133
134
class Box_hvc1 : public Box_VisualSampleEntry
135
{
136
public:
137
  Box_hvc1()
138
5
  {
139
5
    set_short_type(fourcc("hvc1"));
140
5
  }
141
};
142
143
144
145
class SEIMessage
146
{
147
public:
148
0
  virtual ~SEIMessage() = default;
149
};
150
151
152
class SEIMessage_depth_representation_info : public SEIMessage,
153
                                             public heif_depth_representation_info
154
{
155
public:
156
};
157
158
159
Error decode_hevc_aux_sei_messages(const std::vector<uint8_t>& data,
160
                                   std::vector<std::shared_ptr<SEIMessage>>& msgs);
161
162
// Used for AVC, HEVC, and VVC.
163
std::vector<uint8_t> remove_start_code_emulation(const uint8_t* sps, size_t size);
164
165
Error parse_sps_for_hvcC_configuration(const uint8_t* sps, size_t size,
166
                                       HEVCDecoderConfigurationRecord* inout_config,
167
                                       int* width, int* height);
168
169
#endif