Newer
Older

Karsten Suehring
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2018, ITU/ISO/IEC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file EncSlice.h
\brief slice encoder class (header)
*/
#ifndef __ENCSLICE__
#define __ENCSLICE__
// Include files
#include "EncCu.h"
#include "WeightPredAnalysis.h"
#include "RateCtrl.h"
#include "CommonLib/CommonDef.h"
#include "CommonLib/Picture.h"
//! \ingroup EncoderLib
//! \{
class EncLib;
class EncGOP;
// ====================================================================================================================
// Class definition
// ====================================================================================================================
/// slice encoder class
class EncSlice
: public WeightPredAnalysis
{
private:
// encoder configuration
EncCfg* m_pcCfg; ///< encoder configuration class
EncLib* m_pcLib;
// pictures
PicList* m_pcListPic; ///< list of pictures
// processing units
EncGOP* m_pcGOPEncoder; ///< GOP encoder
EncCu* m_pcCuEncoder; ///< CU encoder
// encoder search
InterSearch* m_pcInterSearch; ///< encoder search class
// coding tools
CABACWriter* m_CABACWriter;
TrQuant* m_pcTrQuant; ///< transform & quantization
// RD optimization
RdCost* m_pcRdCost; ///< RD cost computation
CABACWriter* m_CABACEstimator;
uint64_t m_uiPicTotalBits; ///< total bits for the picture
uint64_t m_uiPicDist; ///< total distortion for the picture
std::vector<double> m_vdRdPicLambda; ///< array of lambda candidates
std::vector<double> m_vdRdPicQp; ///< array of picture QP candidates (double-type for lambda)
std::vector<int> m_viRdPicQp; ///< array of picture QP candidates (int-type)
RateCtrl* m_pcRateCtrl; ///< Rate control manager
uint32_t m_uiSliceSegmentIdx;
#if HEVC_DEPENDENT_SLICES
Ctx m_lastSliceSegmentEndContextState; ///< context storage for state at the end of the previous slice-segment (used for dependent slices only).
#endif
#if HEVC_TILES_WPP
Ctx m_entropyCodingSyncContextState; ///< context storage for state of contexts at the wavefront/WPP/entropy-coding-sync second CTU of tile-row
#endif
SliceType m_encCABACTableIdx;
#if SHARP_LUMA_DELTA_QP
int m_gopID;
#endif
#if SHARP_LUMA_DELTA_QP
public:
int getGopId() const { return m_gopID; }
double calculateLambda( const Slice* slice, const int GOPid, const int depth, const double refQP, const double dQP, int &iQP );
void setUpLambda( Slice* slice, const double dLambda, int iQP );

Karsten Suehring
committed
private:
#endif
#if HEVC_TILES_WPP
void calculateBoundingCtuTsAddrForSlice( uint32_t &startCtuTSAddrSlice, uint32_t &boundingCtuTSAddrSlice, bool &haveReachedTileBoundary, Picture* pcPic, const int sliceMode, const int sliceArgument );
#else
void calculateBoundingCtuTsAddrForSlice( uint32_t &startCtuTSAddrSlice, uint32_t &boundingCtuTSAddrSlice, Picture* pcPic, const int sliceMode, const int sliceArgument );
#endif
public:
#if ENABLE_QPA
int m_adaptedLumaQP;
#endif

Karsten Suehring
committed
EncSlice();
virtual ~EncSlice();
void create ( int iWidth, int iHeight, ChromaFormat chromaFormat, uint32_t iMaxCUWidth, uint32_t iMaxCUHeight, uint8_t uhTotalDepth );
void destroy ();
void init ( EncLib* pcEncLib, const SPS& sps );
/// preparation of slice encoding (reference marking, QP and lambda)
void initEncSlice ( Picture* pcPic, const int pocLast, const int pocCurr,
const int iGOPid, Slice*& rpcSlice, const bool isField
, bool isEncodeLtRef
);

Karsten Suehring
committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
void resetQP ( Picture* pic, int sliceQP, double lambda );
// compress and encode slice
void precompressSlice ( Picture* pcPic ); ///< precompress slice for multi-loop slice-level QP opt.
void compressSlice ( Picture* pcPic, const bool bCompressEntireSlice, const bool bFastDeltaQP ); ///< analysis stage of slice
void calCostSliceI ( Picture* pcPic );
void encodeSlice ( Picture* pcPic, OutputBitstream* pcSubstreams, uint32_t &numBinsCoded );
#if ENABLE_WPP_PARALLELISM
static
#endif
void encodeCtus ( Picture* pcPic, const bool bCompressEntireSlice, const bool bFastDeltaQP, uint32_t startCtuTsAddr, uint32_t boundingCtuTsAddr, EncLib* pcEncLib );
// misc. functions
void setSearchRange ( Slice* pcSlice ); ///< set ME range adaptively
EncCu* getCUEncoder () { return m_pcCuEncoder; } ///< CU encoder
void xDetermineStartAndBoundingCtuTsAddr ( uint32_t& startCtuTsAddr, uint32_t& boundingCtuTsAddr, Picture* pcPic );
uint32_t getSliceSegmentIdx () { return m_uiSliceSegmentIdx; }
void setSliceSegmentIdx (uint32_t i) { m_uiSliceSegmentIdx = i; }
SliceType getEncCABACTableIdx() const { return m_encCABACTableIdx; }
private:
double xGetQPValueAccordingToLambda ( double lambda );
};
//! \}
#endif // __ENCSLICE__