Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vvenc/source/Lib/EncoderLib/VLCWriter.h
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) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC 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
/** \file     VLCWriter.h
43
 *  \brief    Writer for high level syntax
44
 */
45
46
#pragma once
47
48
#include "CABACWriter.h"
49
#include "CommonLib/CommonDef.h"
50
#include "CommonLib/BitStream.h"
51
#include "CommonLib/Rom.h"
52
#include "CommonLib/Slice.h"
53
54
//! \ingroup EncoderLib
55
//! \{
56
57
namespace vvenc {
58
59
struct GeneralHrdParams;
60
struct OlsHrdParams;
61
62
#if ENABLE_TRACING
63
64
#define WRITE_SCODE( value, length, name)   xWriteSCodeTr ( value, length, name )
65
#define WRITE_CODE( value, length, name)    xWriteCodeTr ( value, length, name )
66
#define WRITE_UVLC( value,         name)    xWriteUvlcTr ( value,         name )
67
#define WRITE_SVLC( value,         name)    xWriteSvlcTr ( value,         name )
68
#define WRITE_FLAG( value,         name)    xWriteFlagTr ( value,         name )
69
70
extern bool g_HLSTraceEnable;
71
#else
72
0
#define WRITE_SCODE( value, length, name)    xWriteSCode ( value, length )
73
0
#define WRITE_CODE( value, length, name)     xWriteCode ( value, length )
74
0
#define WRITE_UVLC( value,         name)     xWriteUvlc ( value )
75
0
#define WRITE_SVLC( value,         name)     xWriteSvlc ( value )
76
0
#define WRITE_FLAG( value,         name)     xWriteFlag ( value )
77
78
#endif
79
80
81
class VLCWriter
82
{
83
protected:
84
85
  OutputBitstream*    m_pcBitIf;
86
87
0
  VLCWriter() : m_pcBitIf(NULL) {}
88
0
  virtual ~VLCWriter() {}
89
90
0
  void  setBitstream          ( OutputBitstream* p )  { m_pcBitIf = p;  }
91
  void  xWriteSCode           ( int  code,  uint32_t length );
92
  void  xWriteCode            ( uint32_t uiCode, uint32_t uiLength );
93
  void  xWriteUvlc            ( uint32_t uiCode );
94
  void  xWriteSvlc            ( int  iCode   );
95
  void  xWriteFlag            ( bool flag );
96
#if ENABLE_TRACING
97
  void  xWriteSCodeTr         ( int value,  uint32_t  length, const char *pSymbolName);
98
  void  xWriteCodeTr          ( uint32_t value, uint32_t  length, const char *pSymbolName);
99
  void  xWriteUvlcTr          ( uint32_t value,               const char *pSymbolName);
100
  void  xWriteSvlcTr          ( int  value,                   const char *pSymbolName);
101
  void  xWriteFlagTr          ( bool flag,                    const char *pSymbolName);
102
#endif
103
  void  xWriteRbspTrailingBits();
104
0
  bool isByteAligned()      { return (m_pcBitIf->getNumBitsUntilByteAligned() == 0); } ;
105
};
106
107
108
class HLSWriter : private VLCWriter
109
{
110
public:
111
0
  HLSWriter() {}
112
0
  virtual ~HLSWriter() {}
113
114
0
  void  setBitstream            ( OutputBitstream* p )  { m_pcBitIf = p;  }
115
0
  uint32_t  getNumberOfWrittenBits  ()                      { return m_pcBitIf->getNumberOfWrittenBits();  }
116
  void  codeVUI                 ( const VUI *pcVUI, const SPS* pcSPS );
117
  void  codeSPS                 ( const SPS* pcSPS );
118
  void  codePPS                 ( const PPS* pcPPS, const SPS* pcSPS );
119
  void  codeAPS                 ( const APS* pcAPS );
120
  void  codeAlfAps              ( const APS* pcAPS );
121
  void  codeLmcsAps             ( const APS* aps );
122
  void  codeVPS                 ( const VPS* pcVPS );
123
  void  codeDCI                 ( const DCI* dci );
124
  void  codePictureHeader       ( const PicHeader* picHeader, bool writeRbspTrailingBits );
125
  void  codeSliceHeader         ( const Slice* slice );
126
  void  codeConstraintInfo      ( const ConstraintInfo* cinfo );
127
  void  codeProfileTierLevel    ( const ProfileTierLevel* ptl, bool profileTierPresent, int maxNumSubLayersMinus1 );
128
  void  codeOlsHrdParameters    ( const GeneralHrdParams * generalHrd, const OlsHrdParams *olsHrd , const uint32_t firstSubLayer, const uint32_t maxNumSubLayersMinus1);
129
130
  void codeGeneralHrdparameters ( const GeneralHrdParams *hrd);
131
  void  codeAUD                 ( const int audIrapOrGdrAuFlag, const int pictureType );
132
  void  codeTilesWPPEntryPoint  ( Slice* pSlice );
133
134
  void alfFilter                ( const AlfParam& alfParam, const bool isChroma, const int altIdx );
135
136
private:
137
  void dpb_parameters           ( int maxSubLayersMinus1, bool subLayerInfoFlag, const SPS *pcSPS);
138
  void xCodeRefPicList          ( const ReferencePictureList* rpl, bool isLongTermPresent, uint32_t ltLsbBitsCount, const bool isForbiddenZeroDeltaPoc, int rplIdx );
139
  void xCodePredWeightTable     ( const PicHeader *picHeader, const PPS *pps, const SPS *sps );
140
  void xCodePredWeightTable     ( const Slice* slice );
141
};
142
143
} // namespace vvenc
144
145
//! \}
146