Coverage Report

Created: 2026-04-01 07:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libde265/libde265/nal.cc
Line
Count
Source
1
/*
2
 * H.265 video codec.
3
 * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de>
4
 *
5
 * This file is part of libde265.
6
 *
7
 * libde265 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
 * libde265 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 libde265.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "nal.h"
22
#include "cabac.h"
23
#include <assert.h>
24
25
26
de265_error nal_header::read(bitreader* reader)
27
28.8k
{
28
28.8k
  reader->skip_bits(1);
29
28.8k
  nal_unit_type = reader->get_bits(6);
30
28.8k
  nuh_layer_id  = reader->get_bits(6);
31
28.8k
  uint32_t nuh_temporal_id_plus1 = reader->get_bits(3);
32
28.8k
  if (nuh_temporal_id_plus1 == 0) {
33
3.18k
    return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE;
34
3.18k
  }
35
25.7k
  nuh_temporal_id = nuh_temporal_id_plus1 - 1;
36
25.7k
  return DE265_OK;
37
28.8k
}
38
39
40
void nal_header::write(CABAC_encoder& out) const
41
0
{
42
0
  out.skip_bits(1);
43
0
  out.write_bits(nal_unit_type,6);
44
0
  out.write_bits(nuh_layer_id ,6);
45
0
  out.write_bits(nuh_temporal_id+1,3);
46
0
}
47
48
49
bool isIDR(uint8_t unit_type)
50
8.94k
{
51
8.94k
  return (unit_type == NAL_UNIT_IDR_W_RADL ||
52
8.58k
          unit_type == NAL_UNIT_IDR_N_LP);
53
8.94k
}
54
55
bool isBLA(uint8_t unit_type)
56
2.61k
{
57
2.61k
  return (unit_type == NAL_UNIT_BLA_W_LP ||
58
2.49k
          unit_type == NAL_UNIT_BLA_W_RADL ||
59
1.43k
          unit_type == NAL_UNIT_BLA_N_LP);
60
2.61k
}
61
62
bool isCRA(uint8_t unit_type)
63
0
{
64
0
  return unit_type == NAL_UNIT_CRA_NUT;
65
0
}
66
67
bool isRAP(uint8_t unit_type)
68
0
{
69
0
  return isIDR(unit_type) || isBLA(unit_type) || isCRA(unit_type);
70
0
}
71
72
bool isRASL(uint8_t unit_type)
73
9.85k
{
74
9.85k
  return (unit_type == NAL_UNIT_RASL_N ||
75
9.84k
          unit_type == NAL_UNIT_RASL_R);
76
9.85k
}
77
78
bool isIRAP(uint8_t unit_type)
79
15.2k
{
80
15.2k
  return (unit_type >= NAL_UNIT_BLA_W_LP &&
81
14.2k
          unit_type <= NAL_UNIT_RESERVED_IRAP_VCL23);
82
15.2k
}
83
84
bool isRADL(uint8_t unit_type)
85
4.77k
{
86
4.77k
  return (unit_type == NAL_UNIT_RADL_N ||
87
4.77k
          unit_type == NAL_UNIT_RADL_R);
88
4.77k
}
89
90
91
bool isReferenceNALU(uint8_t unit_type)
92
0
{
93
0
  return ( ((unit_type <= NAL_UNIT_RESERVED_VCL_R15) && (unit_type%2 != 0)) ||
94
0
           ((unit_type >= NAL_UNIT_BLA_W_LP) &&
95
0
            (unit_type <= NAL_UNIT_RESERVED_IRAP_VCL23)) );
96
0
}
97
98
bool isSublayerNonReference(uint8_t unit_type)
99
5.06k
{
100
5.06k
  switch (unit_type) {
101
133
  case NAL_UNIT_TRAIL_N:
102
133
  case NAL_UNIT_TSA_N:
103
133
  case NAL_UNIT_STSA_N:
104
133
  case NAL_UNIT_RADL_N:
105
143
  case NAL_UNIT_RASL_N:
106
143
  case NAL_UNIT_RESERVED_VCL_N10:
107
143
  case NAL_UNIT_RESERVED_VCL_N12:
108
277
  case NAL_UNIT_RESERVED_VCL_N14:
109
277
    return true;
110
111
4.78k
  default:
112
4.78k
    return false;
113
5.06k
  }
114
5.06k
}
115
116
static const char* NAL_unit_name[] = {
117
  "TRAIL_N", // 0
118
  "TRAIL_R",
119
  "TSA_N",
120
  "TSA_R",
121
  "STSA_N",
122
  "STSA_R",  // 5
123
  "RADL_N",
124
  "RADL_R",
125
  "RASL_N",
126
  "RASL_R",
127
  "RESERVED_VCL_N10", // 10
128
  "RESERVED_VCL_R11",
129
  "RESERVED_VCL_N12",
130
  "RESERVED_VCL_R13",
131
  "RESERVED_VCL_N14",
132
  "RESERVED_VCL_R15", // 15
133
  "BLA_W_LP",
134
  "BLA_W_RADL",
135
  "BLA_N_LP",
136
  "IDR_W_RADL",
137
  "IDR_N_LP",     // 20
138
  "CRA_NUT",
139
  "RESERVED_IRAP_VCL22",
140
  "RESERVED_IRAP_VCL23",
141
  "RESERVED_VCL24",
142
  "RESERVED_VCL25", // 25
143
  "RESERVED_VCL26",
144
  "RESERVED_VCL27",
145
  "RESERVED_VCL28",
146
  "RESERVED_VCL29",
147
  "RESERVED_VCL30", // 30
148
  "RESERVED_VCL31",
149
  "VPS",
150
  "SPS",
151
  "PPS",
152
  "AUD", // 35
153
  "EOS",
154
  "EOB",
155
  "FD",
156
  "PREFIX_SEI",
157
  "SUFFIX_SEI", // 40
158
  "RESERVED_NVCL41",
159
  "RESERVED_NVCL42",
160
  "RESERVED_NVCL43",
161
  "RESERVED_NVCL44",
162
  "RESERVED_NVCL45", // 45
163
  "RESERVED_NVCL46",
164
  "RESERVED_NVCL47"
165
};
166
167
const char* get_NAL_name(uint8_t unit_type)
168
0
{
169
0
  if (unit_type >= 48) { return "INVALID NAL >= 48"; }
170
0
  return NAL_unit_name[unit_type];
171
0
}