Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vvdec/source/Lib/DecoderLib/NALread.cpp
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2018-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVdeC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
41
------------------------------------------------------------------------------------------- */
42
43
/**
44
 \file     NALread.cpp
45
 \brief    reading functionality for NAL units
46
 */
47
48
49
#include <vector>
50
#include <algorithm>
51
#include <ostream>
52
53
#include "NALread.h"
54
55
#include "CommonLib/NAL.h"
56
#include "CommonLib/BitStream.h"
57
#include "CommonLib/Rom.h"
58
#include "CommonLib/dtrace_next.h"
59
60
namespace vvdec
61
{
62
63
//! \ingroup DecoderLib
64
//! \{
65
66
#if ENABLE_TRACING
67
static void xTraceNalUnitHeader(InputNALUnit& nalu)
68
{
69
  DTRACE( g_trace_ctx, D_NALUNITHEADER, "*********** NAL UNIT (%s) ***********\n", nalUnitTypeToString(nalu.m_nalUnitType) );
70
  bool zeroTidRequiredFlag = 0;
71
  if((nalu.m_nalUnitType >= 16) && (nalu.m_nalUnitType <= 31)) {
72
    zeroTidRequiredFlag = 1;
73
  }
74
  DTRACE( g_trace_ctx, D_NALUNITHEADER, "%-50s u(%d)  : %u\n", "zero_tid_required_flag", 1, zeroTidRequiredFlag );
75
  DTRACE( g_trace_ctx, D_NALUNITHEADER, "%-50s u(%d)  : %u\n", "nuh_temporal_id_plus1", 3, nalu.m_temporalId + 1 );
76
  DTRACE( g_trace_ctx, D_NALUNITHEADER, "%-50s u(%d)  : %u\n", "nal_unit_type_lsb", 4, (nalu.m_nalUnitType) - (zeroTidRequiredFlag << 4));
77
  DTRACE( g_trace_ctx, D_NALUNITHEADER, "%-50s u(%d)  : %u\n", "nuh_layer_id_plus1", 7, nalu.m_nuhLayerId+1);
78
  DTRACE( g_trace_ctx, D_NALUNITHEADER, "%-50s u(%d)  : %u\n", "nuh_reserved_zero_bit", 1, 0 );
79
}
80
#endif
81
82
void InputNALUnit::readNalUnitHeader()
83
0
{
84
0
  InputNALUnit&   nalu = *this;
85
0
  InputBitstream& bs   = nalu.getBitstream();
86
87
0
  nalu.m_forbiddenZeroBit   = bs.read(1);                 // forbidden zero bit
88
0
  nalu.m_nuhReservedZeroBit = bs.read(1);                 // nuh_reserved_zero_bit
89
0
  nalu.m_nuhLayerId         = bs.read(6);                 // nuh_layer_id
90
0
  CHECK( nalu.m_nuhLayerId < 0, "this needs to be adjusted for the reco yuv output" );
91
0
  CHECK( nalu.m_nuhLayerId > 55, "The value of nuh_layer_id shall be in the range of 0 to 55, inclusive" );
92
0
  nalu.m_nalUnitType        = (NalUnitType) bs.read(5);   // nal_unit_type
93
0
  nalu.m_temporalId         = bs.read(3) - 1;             // nuh_temporal_id_plus1
94
95
#if ENABLE_TRACING
96
  xTraceNalUnitHeader(nalu);
97
#endif
98
99
  // only check these rules for base layer
100
0
  if (nalu.m_nuhLayerId == 0)
101
0
  {
102
0
    if ( nalu.m_temporalId )
103
0
    {
104
0
    }
105
0
    else
106
0
    {
107
0
      CHECK( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA, "When NAL unit type is equal to STSA_NUT, TemporalId shall not be equal to 0" );
108
0
    }
109
0
  }
110
0
}
111
}