codingparameter.cpp
来自「SVC最新更新代码」· C++ 代码 · 共 970 行 · 第 1/4 页
CPP
970 行
/*
********************************************************************************
NOTE - One of the two copyright statements below may be chosen
that applies for the software.
********************************************************************************
This software module was originally developed by
Heiko Schwarz (Fraunhofer HHI),
Tobias Hinz (Fraunhofer HHI),
Karsten Suehring (Fraunhofer HHI)
in the course of development of the ISO/IEC 14496-10:2005 Amd.1 (Scalable Video
Coding) for reference purposes and its performance may not have been optimized.
This software module is an implementation of one or more tools as specified by
the ISO/IEC 14496-10:2005 Amd.1 (Scalable Video Coding).
Those intending to use this software module in products are advised that its
use may infringe existing patents. ISO/IEC have no liability for use of this
software module or modifications thereof.
Assurance that the originally developed software module can be used
(1) in the ISO/IEC 14496-10:2005 Amd.1 (Scalable Video Coding) once the
ISO/IEC 14496-10:2005 Amd.1 (Scalable Video Coding) has been adopted; and
(2) to develop the ISO/IEC 14496-10:2005 Amd.1 (Scalable Video Coding):
To the extent that Fraunhofer HHI owns patent rights that would be required to
make, use, or sell the originally developed software module or portions thereof
included in the ISO/IEC 14496-10:2005 Amd.1 (Scalable Video Coding) in a
conforming product, Fraunhofer HHI will assure the ISO/IEC that it is willing
to negotiate licenses under reasonable and non-discriminatory terms and
conditions with applicants throughout the world.
Fraunhofer HHI retains full right to modify and use the code for its own
purpose, assign or donate the code to a third party and to inhibit third
parties from using the code for products that do not conform to MPEG-related
ITU Recommendations and/or ISO/IEC International Standards.
This copyright notice must be included in all copies or derivative works.
Copyright (c) ISO/IEC 2005.
********************************************************************************
COPYRIGHT AND WARRANTY INFORMATION
Copyright 2005, International Telecommunications Union, Geneva
The Fraunhofer HHI hereby donate this source code to the ITU, with the following
understanding:
1. Fraunhofer HHI retain the right to do whatever they wish with the
contributed source code, without limit.
2. Fraunhofer HHI retain full patent rights (if any exist) in the technical
content of techniques and algorithms herein.
3. The ITU shall make this code available to anyone, free of license or
royalty fees.
DISCLAIMER OF WARRANTY
These software programs are available to the user without any license fee or
royalty on an "as is" basis. The ITU disclaims any and all warranties, whether
express, implied, or statutory, including any implied warranties of
merchantability or of fitness for a particular purpose. In no event shall the
contributor or the ITU be liable for any incidental, punitive, or consequential
damages of any kind whatsoever arising from the use of these programs.
This disclaimer of warranty extends to the user of these programs and user's
customers, employees, agents, transferees, successors, and assigns.
The ITU does not represent or warrant that the programs furnished hereunder are
free of infringement of any third-party patents. Commercial implementations of
ITU-T Recommendations, including shareware, may be subject to royalty fees to
patent holders. Information regarding the ITU-T patent policy is available from
the ITU Web site at http://www.itu.int.
THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE ITU-T PATENT POLICY.
********************************************************************************
*/
#include "H264AVCEncoderLib.h"
#include "H264AVCCommonLib.h"
#include "CodingParameter.h"
#include "SequenceStructure.h"
#include <math.h>
#define ROTREPORT(x,t) {if(x) {::printf("\n%s\n",t); assert(0); return Err::m_nInvalidParameter;} }
#define SETREPORT(x,v,s) {if(x!=v) {x=v; ::printf("in layer %d: %s\n",m_uiLayerId,s);}}
// h264 namepace begin
H264AVC_NAMESPACE_BEGIN
ErrVal MotionVectorSearchParams::check()
{
ROTREPORT( 4 < m_uiSearchMode, "No Such Search Mode 0==Block,1==Spiral,2==Log,3==Fast, 4==NewFast" )
ROTREPORT( 3 < m_uiFullPelDFunc, "No Such Search Func (Full Pel) 0==SAD,1==SSE,2==Hadamard,3==YUV-SAD" )
ROTREPORT( 3 == m_uiFullPelDFunc && (m_uiSearchMode==2 || m_uiSearchMode==3), "Log and Fast search not possible in comb. with distortion measure 3" )
ROTREPORT( 2 < m_uiSubPelDFunc, "No Such Search Func (Sub Pel) 0==SAD,1==SSE,2==Hadamard" )
ROTREPORT( 1 < m_uiDirectMode, "Direct Mode Exceeds Supported Range 0==Temporal, 1==Spatial");
if( m_uiELSearchRange == 0 )
{
m_uiELSearchRange = m_uiSearchRange;
m_bELSearch = false;
}
else
{
m_bELSearch = true;
}
return Err::m_nOK;
}
ErrVal LoopFilterParams::check() const
{
//V032 of FSL for extending the Idc value to 3 and 4 w.r.t. 0 and 2 in the enhanced layer
//for disabling chroma deblocking in enhanced layer
ROTREPORT( 6 < getFilterIdc(), "Loop Filter Idc exceeds supported range 0..6");
if( 69 != getAlphaOffset() )
{
ROTREPORT( 26 < getAlphaOffset(), "Loop Filter Alpha Offset exceeds supported range -26..26");
ROTREPORT( -26 > getAlphaOffset(), "Loop Filter Alpha Offset exceeds supported range -26..26");
}
if( 69 != getBetaOffset() )
{
ROTREPORT( 26 < getBetaOffset(), "Loop Filter Beta Offset exceeds supported range -26..26");
ROTREPORT( -26 > getBetaOffset(), "Loop Filter Beta Offset exceeds supported range -26..26");
}
return Err::m_nOK;
}
UInt LayerParameters::getNumberOfQualityLevelsCGSSNR() const
{
UInt uiVectPos = 0;
UInt uiQLs;
for( uiQLs = 0; uiVectPos != 16; uiQLs++ )
{
uiVectPos += getMGSVect( uiQLs );
}
return uiQLs;
}
ErrVal LayerParameters::check()
{
ROTREPORT( getFrameWidthInSamples () % 2, "Frame Width must be a multiple of 2" );
ROTREPORT( getFrameHeightInSamples () % 2, "Frame Height must be a multiple of 2" );
ROTREPORT( getFrameHeightInSamples () % 4
&& isInterlaced (), "Frame Height must be a multiple of 4 for interlace" );
ROTREPORT( getInputFrameRate () <
getOutputFrameRate (), "Output frame rate must be less than or equal to input frame rate" );
ROTREPORT( getEnable8x8Trafo () > 1, "The value for Enable8x8Transform is not supported" );
ROTREPORT( getScalingMatricesPresent () > 1, "The value for ScalingMatricesPresent is not supported" );
ROTREPORT( getBiPred8x8Disable () > 1, "The value for BiPredLT8x8Disable is not supported" );
ROTREPORT( getMCBlks8x8Disable () > 1, "The value for MCBlocksLT8x8Disable is not supported" );
ROTREPORT( getPicCodingType () > 1, "The value for DisableBSlices is not supported" );
ROTREPORT( getMaxAbsDeltaQP () > 7, "MaxAbsDeltaQP not supported" );
ROTREPORT( getInterLayerPredictionMode() > 2, "Unsupported inter-layer prediction mode" );
ROTREPORT( getMotionInfoMode () > 2, "Motion info mode not supported" );
ROTREPORT( getBaseLayerId() != MSYS_UINT_MAX && getBaseLayerId() >= getDependencyId(), "BaseLayerId is not possible" );
ROTREPORT( m_uiSliceMode != 0 && m_uiSliceMode != 1 && m_uiSliceMode != 2, "Invalid slice mode" );
ROTREPORT( m_uiSliceMode != 0 && m_uiSliceArgument == 0, "Invalid slice argument" );
UInt uiVectPos = 0;
UInt ui;
for( ui = 0; uiVectPos < 16; ui++ )
{
uiVectPos += getMGSVect( ui );
ROTREPORT( uiVectPos > 16 || (ui == 15 && uiVectPos < 16), "Sum over elements of MGSVector does not equal 16." );
}
Bool bTrailingZeros = true;
for( ui = 15; ui > 0; ui-- )
{
if( getMGSVect( ui ) != 0 )
bTrailingZeros = false;
ROTREPORT( !bTrailingZeros && getMGSVect( ui ) == 0, "Zeros inside of the MGSVector are not allowed (except for the first element and the end of the vector)." );
}
Bool bUseMGSVectors = getMGSVect( 0 ) != 16;
ROTREPORT( ( getTCoeffLevelPredictionFlag() || getAVCAdaptiveRewriteFlag() ) && bUseMGSVectors, "MGS Vectors are not allowed with AVC rewriting enabled." );
ROTREPORT( m_uiSliceMode == 2 && bUseMGSVectors, "SliceMode 2 not supported in connection with MGS Vectors" );
if( bUseMGSVectors && m_uiMaxAbsDeltaQP )
{
m_uiMaxAbsDeltaQP = 0;
printf("\nInfo: MaxDeltaQP was set to 0 for layer with MGSVectorMode\n\n");
}
if ((getBaseLayerId() == MSYS_UINT_MAX) && (getTCoeffLevelPredictionFlag() == true))
{
printf( "AvcRewriteFlag should be false for base layer, reset to 0\n" );
m_bAVCRewriteFlag = 0;
}
if( m_dQpModeDecisionLP == -1.0 )
{
m_dQpModeDecisionLP = m_dBaseQpResidual;
}
if ( m_uiNumSliceGroupsMinus1 > 0 && m_uiSliceGroupMapType == 2 && ( m_uiSliceMode == 0 || m_uiSliceMode == 1 ) )
{
ROT( m_uiSliceMode == 1 && m_uiSliceArgument == 0 );
ROTREPORT( isInterlaced(), "Slice groups and interlaced are not supported in the same profile" );
UInt uiMaxSliceSize = ( m_uiSliceMode == 1 ? m_uiSliceArgument : MSYS_UINT_MAX );
UInt uiMapWidth = getFrameWidthInMbs ();
UInt uiMapHeight = getFrameHeightInMbs ();
UInt uiMapSize = uiMapHeight * uiMapWidth;
UInt* pauiSGMap = new UInt [ uiMapSize ];
UInt* pauiROIMap = new UInt [ uiMapSize ];
UInt* pauiROIFirstMB = new UInt [ uiMapSize ];
UInt* pauiROILastMB = new UInt [ uiMapSize ];
UInt* pauiROIWidth = new UInt [ uiMapSize ];
UInt* pauiROIHeight = new UInt [ uiMapSize ];
ROF( pauiSGMap && pauiROIMap && pauiROIFirstMB && pauiROILastMB && pauiROIWidth && pauiROIHeight );
//----- set slice group Id's in map -----
for( Int iIdx0 = 0; iIdx0 < (Int)uiMapSize; iIdx0++ )
{
pauiSGMap[iIdx0] = m_uiNumSliceGroupsMinus1;
}
for( Int iGroup0 = m_uiNumSliceGroupsMinus1 - 1; iGroup0 >= 0; iGroup0-- )
{
Int iY0 = m_uiTopLeft [ iGroup0 ] / uiMapWidth;
Int iX0 = m_uiTopLeft [ iGroup0 ] % uiMapWidth;
Int iY1 = m_uiBottomRight[ iGroup0 ] / uiMapWidth;
Int iX1 = m_uiBottomRight[ iGroup0 ] % uiMapWidth;
for( Int iY = iY0; iY <= iY1; iY++ )
for( Int iX = iX0; iX <= iX1; iX++ )
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?