Coverage Report

Created: 2022-08-24 06:17

/src/libde265/libde265/nal.cc
Line
Count
Source (jump to first uncovered line)
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
void nal_header::read(bitreader* reader)
27
45.6k
{
28
45.6k
  skip_bits(reader,1);
29
45.6k
  nal_unit_type = get_bits(reader,6);
30
45.6k
  nuh_layer_id  = get_bits(reader,6);
31
45.6k
  nuh_temporal_id = get_bits(reader,3) -1;
32
45.6k
}
33
34
35
void nal_header::write(CABAC_encoder& out) const
36
0
{
37
0
  out.skip_bits(1);
38
0
  out.write_bits(nal_unit_type,6);
39
0
  out.write_bits(nuh_layer_id ,6);
40
0
  out.write_bits(nuh_temporal_id+1,3);
41
0
}
42
43
44
bool isIDR(uint8_t unit_type)
45
7.39k
{
46
7.39k
  return (unit_type == NAL_UNIT_IDR_W_RADL ||
47
7.39k
          unit_type == NAL_UNIT_IDR_N_LP);
48
7.39k
}
49
50
bool isBLA(uint8_t unit_type)
51
139
{
52
139
  return (unit_type == NAL_UNIT_BLA_W_LP ||
53
139
          unit_type == NAL_UNIT_BLA_W_RADL ||
54
139
          unit_type == NAL_UNIT_BLA_N_LP);
55
139
}
56
57
bool isCRA(uint8_t unit_type)
58
0
{
59
0
  return unit_type == NAL_UNIT_CRA_NUT;
60
0
}
61
62
bool isRAP(uint8_t unit_type)
63
0
{
64
0
  return isIDR(unit_type) || isBLA(unit_type) || isCRA(unit_type);
65
0
}
66
67
bool isRASL(uint8_t unit_type)
68
7.40k
{
69
7.40k
  return (unit_type == NAL_UNIT_RASL_N ||
70
7.40k
          unit_type == NAL_UNIT_RASL_R);
71
7.40k
}
72
73
bool isIRAP(uint8_t unit_type)
74
11.1k
{
75
11.1k
  return (unit_type >= NAL_UNIT_BLA_W_LP &&
76
11.1k
          unit_type <= NAL_UNIT_RESERVED_IRAP_VCL23);
77
11.1k
}
78
79
bool isRADL(uint8_t unit_type)
80
3.70k
{
81
3.70k
  return (unit_type == NAL_UNIT_RADL_N ||
82
3.70k
          unit_type == NAL_UNIT_RADL_R);
83
3.70k
}
84
85
86
bool isReferenceNALU(uint8_t unit_type)
87
0
{
88
0
  return ( ((unit_type <= NAL_UNIT_RESERVED_VCL_R15) && (unit_type%2 != 0)) ||
89
0
           ((unit_type >= NAL_UNIT_BLA_W_LP) &&
90
0
            (unit_type <= NAL_UNIT_RESERVED_IRAP_VCL23)) );
91
0
}
92
93
bool isSublayerNonReference(uint8_t unit_type)
94
3.70k
{
95
3.70k
  switch (unit_type) {
96
0
  case NAL_UNIT_TRAIL_N:
97
0
  case NAL_UNIT_TSA_N:
98
0
  case NAL_UNIT_STSA_N:
99
4
  case NAL_UNIT_RADL_N:
100
4
  case NAL_UNIT_RASL_N:
101
4
  case NAL_UNIT_RESERVED_VCL_N10:
102
4
  case NAL_UNIT_RESERVED_VCL_N12:
103
4
  case NAL_UNIT_RESERVED_VCL_N14:
104
4
    return true;
105
106
3.70k
  default:
107
3.70k
    return false;
108
3.70k
  }
109
3.70k
}
110
111
static const char* NAL_unit_name[] = {
112
  "TRAIL_N", // 0
113
  "TRAIL_R",
114
  "TSA_N",
115
  "TSA_R",
116
  "STSA_N",
117
  "STSA_R",  // 5
118
  "RADL_N",
119
  "RADL_R",
120
  "RASL_N",
121
  "RASL_R",
122
  "RESERVED_VCL_N10", // 10
123
  "RESERVED_VCL_R11",
124
  "RESERVED_VCL_N12",
125
  "RESERVED_VCL_R13",
126
  "RESERVED_VCL_N14",
127
  "RESERVED_VCL_R15", // 15
128
  "BLA_W_LP",
129
  "BLA_W_RADL",
130
  "BLA_N_LP",
131
  "IDR_W_RADL",
132
  "IDR_N_LP",     // 20
133
  "CRA_NUT",
134
  "RESERVED_IRAP_VCL22",
135
  "RESERVED_IRAP_VCL23",
136
  "RESERVED_VCL24",
137
  "RESERVED_VCL25", // 25
138
  "RESERVED_VCL26",
139
  "RESERVED_VCL27",
140
  "RESERVED_VCL28",
141
  "RESERVED_VCL29",
142
  "RESERVED_VCL30", // 30
143
  "RESERVED_VCL31",
144
  "VPS",
145
  "SPS",
146
  "PPS",
147
  "AUD", // 35
148
  "EOS",
149
  "EOB",
150
  "FD",
151
  "PREFIX_SEI",
152
  "SUFFIX_SEI", // 40
153
  "RESERVED_NVCL41",
154
  "RESERVED_NVCL42",
155
  "RESERVED_NVCL43",
156
  "RESERVED_NVCL44",
157
  "RESERVED_NVCL45", // 45
158
  "RESERVED_NVCL46",
159
  "RESERVED_NVCL47"
160
};
161
162
const char* get_NAL_name(uint8_t unit_type)
163
0
{
164
0
  if (unit_type >= 48) { return "INVALID NAL >= 48"; }
165
0
  return NAL_unit_name[unit_type];
166
0
}