Newer
Older

Karsten Suehring
committed
/* 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-2019, ITU/ISO/IEC

Karsten Suehring
committed
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
109
110
111
112
* 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 EncGOP.cpp
\brief GOP encoder class
*/
#include <list>
#include <algorithm>
#include <functional>
#include "EncLib.h"
#include "EncGOP.h"
#include "Analyze.h"
#include "libmd5/MD5.h"
#include "CommonLib/SEI.h"
#include "CommonLib/NAL.h"
#include "NALwrite.h"
#include <math.h>
#include <deque>
#include <chrono>
#include <cinttypes>
#include "CommonLib/UnitTools.h"
#include "CommonLib/dtrace_codingstruct.h"
#include "CommonLib/dtrace_buffer.h"
#include "DecoderLib/DecLib.h"
#define ENCODE_SUB_SET 0
using namespace std;
//! \ingroup EncoderLib
//! \{
// ====================================================================================================================
// Constructor / destructor / initialization / destroy
// ====================================================================================================================
int getLSB(int poc, int maxLSB)
{
if (poc >= 0)
{
return poc % maxLSB;
}
else
{
return (maxLSB - ((-poc) % maxLSB)) % maxLSB;
}
}
EncGOP::EncGOP()
{
m_iLastIDR = 0;
m_iGopSize = 0;
m_iNumPicCoded = 0; //Niko
m_bFirst = true;
m_iLastRecoveryPicPOC = 0;
m_lastRasPoc = MAX_INT;
m_pcCfg = NULL;
m_pcSliceEncoder = NULL;
m_pcListPic = NULL;
m_HLSWriter = NULL;
m_bSeqFirst = true;
m_bRefreshPending = 0;
m_pocCRA = 0;
m_numLongTermRefPicSPS = 0;
::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
::memset(m_ltRefPicUsedByCurrPicFlag, 0, sizeof(m_ltRefPicUsedByCurrPicFlag));
m_lastBPSEI = 0;
m_bufferingPeriodSEIPresentInAU = false;
m_associatedIRAPType = NAL_UNIT_CODED_SLICE_IDR_N_LP;
m_associatedIRAPPOC = 0;
#if W0038_DB_OPT
m_pcDeblockingTempPicYuv = NULL;
#endif
m_bInitAMaxBT = true;
m_bgPOC = -1;
m_picBg = NULL;
m_picOrig = NULL;
m_isEncodedLTRef = false;
m_isUseLTRef = false;
m_isPrepareLTRef = true;
m_lastLTRefPoc = 0;

Karsten Suehring
committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
}
EncGOP::~EncGOP()
{
if( !m_pcCfg->getDecodeBitstream(0).empty() || !m_pcCfg->getDecodeBitstream(1).empty() )
{
// reset potential decoder resources
tryDecodePicture( NULL, 0, std::string("") );
}
}
/** Create list to contain pointers to CTU start addresses of slice.
*/
void EncGOP::create()
{
m_bLongtermTestPictureHasBeenCoded = 0;
m_bLongtermTestPictureHasBeenCoded2 = 0;
}
void EncGOP::destroy()
{
#if W0038_DB_OPT
if (m_pcDeblockingTempPicYuv)
{
m_pcDeblockingTempPicYuv->destroy();
delete m_pcDeblockingTempPicYuv;
m_pcDeblockingTempPicYuv = NULL;
}
#endif
if (m_picBg)
{
m_picBg->destroy();
delete m_picBg;
m_picBg = NULL;
}
if (m_picOrig)
{
m_picOrig->destroy();
delete m_picOrig;
m_picOrig = NULL;
}

Karsten Suehring
committed
}
void EncGOP::init ( EncLib* pcEncLib )
{
m_pcEncLib = pcEncLib;
m_pcCfg = pcEncLib;
m_seiEncoder.init(m_pcCfg, pcEncLib, this);
m_pcSliceEncoder = pcEncLib->getSliceEncoder();
m_pcListPic = pcEncLib->getListPic();
m_HLSWriter = pcEncLib->getHLSWriter();
m_pcLoopFilter = pcEncLib->getLoopFilter();
m_pcSAO = pcEncLib->getSAO();
m_pcALF = pcEncLib->getALF();
m_pcRateCtrl = pcEncLib->getRateCtrl();
m_lastBPSEI = 0;
m_totalCoded = 0;
m_AUWriterIf = pcEncLib->getAUWriterIf();

Karsten Suehring
committed
#if WCG_EXT
#if JVET_M0427_INLOOP_RESHAPER
if (m_pcCfg->getReshaper())
{
pcEncLib->getRdCost()->setReshapeInfo(m_pcCfg->getReshapeSignalType(), m_pcCfg->getBitDepth(CHANNEL_TYPE_LUMA));
pcEncLib->getRdCost()->initLumaLevelToWeightTableReshape();
}
else if (m_pcCfg->getLumaLevelToDeltaQPMapping().mode)
{
#if JVET_M0427_INLOOP_RESHAPER
memcpy(pcEncLib->getALF()->getLumaLevelWeightTable(), pcEncLib->getRdCost()->getLumaLevelWeightTable(), LUMA_LEVEL_TO_DQP_LUT_MAXSIZE * sizeof(double));
int alfWSSD = 0;
if (m_pcCfg->getReshaper() && m_pcCfg->getReshapeSignalType() == RESHAPE_SIGNAL_PQ )
{
alfWSSD = 1;
}
pcEncLib->getALF()->setAlfWSSD(alfWSSD);
pcEncLib->getRdCost()->initLumaLevelToWeightTable();
Loading
Loading full blame...