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.
*

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
* 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 "CommonLib/ProfileLevelTier.h"

Karsten Suehring
committed
#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;

Karsten Suehring
committed
m_lastRasPoc = MAX_INT;
m_pcCfg = NULL;
m_pcSliceEncoder = NULL;
m_pcListPic = NULL;
m_HLSWriter = NULL;
m_bSeqFirst = true;
Zhipin Deng
committed
m_audIrapOrGdrAuFlag = false;

Karsten Suehring
committed
m_bRefreshPending = 0;
m_pocCRA = 0;
m_numLongTermRefPicSPS = 0;
::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
::memset(m_ltRefPicUsedByCurrPicFlag, 0, sizeof(m_ltRefPicUsedByCurrPicFlag));
::memset(m_lastBPSEI, 0, sizeof(m_lastBPSEI));
m_rapWithLeading = false;

Karsten Suehring
committed
m_bufferingPeriodSEIPresentInAU = false;
for (int i = 0; i < MAX_VPS_LAYERS; i++)
{
m_associatedIRAPType[i] = NAL_UNIT_CODED_SLICE_IDR_N_LP;
}
::memset(m_associatedIRAPPOC, 0, sizeof(m_associatedIRAPPOC));

Karsten Suehring
committed
#if W0038_DB_OPT
m_pcDeblockingTempPicYuv = NULL;
#endif
#if JVET_O0756_CALCULATE_HDRMETRICS
m_ppcFrameOrg = nullptr;
m_ppcFrameRec = nullptr;
m_pcConvertFormat = nullptr;
m_pcConvertIQuantize = nullptr;
m_pcColorTransform = nullptr;
m_pcDistortionDeltaE = nullptr;
m_pcTransferFct = nullptr;
m_pcColorTransformParams = nullptr;
m_pcFrameFormat = nullptr;
m_metricTime = std::chrono::milliseconds(0);
#endif

Karsten Suehring
committed
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
}
EncGOP::~EncGOP()
{
if( !m_pcCfg->getDecodeBitstream(0).empty() || !m_pcCfg->getDecodeBitstream(1).empty() )
{
// reset potential decoder resources
tryDecodePicture( NULL, 0, std::string("") );
}
#if JVET_O0756_CALCULATE_HDRMETRICS
delete [] m_ppcFrameOrg;
delete [] m_ppcFrameRec;
m_ppcFrameOrg = m_ppcFrameRec = nullptr;
delete m_pcConvertFormat;
delete m_pcConvertIQuantize;
delete m_pcColorTransform;
delete m_pcDistortionDeltaE;
delete m_pcTransferFct;
delete m_pcColorTransformParams;
delete m_pcFrameFormat;
m_pcConvertFormat = nullptr;
m_pcConvertIQuantize = nullptr;
m_pcColorTransform = nullptr;
m_pcDistortionDeltaE = nullptr;
m_pcTransferFct = nullptr;
m_pcColorTransformParams = nullptr;
m_pcFrameFormat = nullptr;

Karsten Suehring
committed
}
/** Create list to contain pointers to CTU start addresses of slice.
*/
void EncGOP::create()
{
m_bLongtermTestPictureHasBeenCoded = 0;
m_bLongtermTestPictureHasBeenCoded2 = 0;
#if JVET_V0094_BILATERAL_FILTER || JVET_X0071_CHROMA_BILATERAL_FILTER

Karsten Suehring
committed
}
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;
Loading
Loading full blame...