[2] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
| 6 | * Copyright (c) 2010-2012, ITU/ISO/IEC |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file TEncRateCtrl.h |
---|
| 35 | \brief Rate control manager class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #ifndef _HM_TENCRATECTRL_H_ |
---|
| 39 | #define _HM_TENCRATECTRL_H_ |
---|
| 40 | |
---|
| 41 | #if _MSC_VER > 1000 |
---|
| 42 | #pragma once |
---|
| 43 | #endif // _MSC_VER > 1000 |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | #include "../TLibCommon/CommonDef.h" |
---|
| 47 | #include "../TLibCommon/TComDataCU.h" |
---|
| 48 | |
---|
| 49 | #include <vector> |
---|
| 50 | #include <algorithm> |
---|
| 51 | |
---|
| 52 | using namespace std; |
---|
| 53 | |
---|
| 54 | //! \ingroup TLibEncoder |
---|
| 55 | //! \{ |
---|
| 56 | |
---|
| 57 | // ==================================================================================================================== |
---|
| 58 | // Class definition |
---|
| 59 | // ==================================================================================================================== |
---|
| 60 | #define MAX_DELTA_QP 2 |
---|
| 61 | #define MAX_CUDQP_DEPTH 0 |
---|
| 62 | |
---|
| 63 | typedef struct FrameData |
---|
| 64 | { |
---|
| 65 | Bool m_isReferenced; |
---|
| 66 | Int m_qp; |
---|
| 67 | Int m_bits; |
---|
| 68 | Double m_costMAD; |
---|
| 69 | }FrameData; |
---|
| 70 | |
---|
| 71 | typedef struct LCUData |
---|
| 72 | { |
---|
| 73 | Int m_qp; ///< coded QP |
---|
| 74 | Int m_bits; ///< actually generated bits |
---|
| 75 | Int m_pixels; ///< number of pixels for a unit |
---|
| 76 | Int m_widthInPixel; ///< number of pixels for width |
---|
| 77 | Int m_heightInPixel; ///< number of pixels for height |
---|
| 78 | Double m_costMAD; ///< texture complexity for a unit |
---|
| 79 | }LCUData; |
---|
| 80 | |
---|
| 81 | class MADLinearModel |
---|
| 82 | { |
---|
| 83 | private: |
---|
| 84 | Bool m_activeOn; |
---|
| 85 | Double m_paramY1; |
---|
| 86 | Double m_paramY2; |
---|
| 87 | Double m_costMADs[3]; |
---|
| 88 | |
---|
| 89 | public: |
---|
| 90 | MADLinearModel () {}; |
---|
| 91 | ~MADLinearModel() {}; |
---|
| 92 | |
---|
| 93 | Void initMADLinearModel (); |
---|
| 94 | Double getMAD (); |
---|
| 95 | Void updateMADLiearModel (); |
---|
| 96 | Void updateMADHistory (Double costMAD); |
---|
| 97 | Bool IsUpdateAvailable () { return m_activeOn; } |
---|
| 98 | }; |
---|
| 99 | |
---|
| 100 | class PixelBaseURQQuadraticModel |
---|
| 101 | { |
---|
| 102 | private: |
---|
| 103 | Double m_paramHighX1; |
---|
| 104 | Double m_paramHighX2; |
---|
| 105 | Double m_paramLowX1; |
---|
| 106 | Double m_paramLowX2; |
---|
| 107 | public: |
---|
| 108 | PixelBaseURQQuadraticModel () {}; |
---|
| 109 | ~PixelBaseURQQuadraticModel() {}; |
---|
| 110 | |
---|
| 111 | Void initPixelBaseQuadraticModel (); |
---|
| 112 | Int getQP (Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD); |
---|
| 113 | Void updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD); |
---|
| 114 | Bool checkUpdateAvailable (Int qpReference ); |
---|
| 115 | Double xConvertQP2QStep (Int qp ); |
---|
| 116 | Int xConvertQStep2QP (Double qStep ); |
---|
| 117 | }; |
---|
| 118 | |
---|
| 119 | class TEncRateCtrl |
---|
| 120 | { |
---|
| 121 | private: |
---|
| 122 | Bool m_isLowdelay; |
---|
| 123 | Int m_prevBitrate; |
---|
| 124 | Int m_currBitrate; |
---|
| 125 | Int m_frameRate; |
---|
| 126 | Int m_refFrameNum; |
---|
| 127 | Int m_nonRefFrameNum; |
---|
| 128 | Int m_numOfPixels; |
---|
| 129 | Int m_sourceWidthInLCU; |
---|
| 130 | Int m_sourceHeightInLCU; |
---|
| 131 | Int m_sizeGOP; |
---|
| 132 | Int m_indexGOP; |
---|
| 133 | Int m_indexFrame; |
---|
| 134 | Int m_indexLCU; |
---|
| 135 | Int m_indexUnit; |
---|
| 136 | Int m_indexRefFrame; |
---|
| 137 | Int m_indexNonRefFrame; |
---|
| 138 | Int m_indexPOCInGOP; |
---|
| 139 | Int m_indexPrevPOCInGOP; |
---|
| 140 | Int m_occupancyVB; |
---|
| 141 | Int m_initialOVB; |
---|
| 142 | Int m_targetBufLevel; |
---|
| 143 | Int m_initialTBL; |
---|
| 144 | Int m_remainingBitsInGOP; |
---|
| 145 | Int m_remainingBitsInFrame; |
---|
| 146 | Int m_occupancyVBInFrame; |
---|
| 147 | Int m_targetBits; |
---|
| 148 | Int m_numUnitInFrame; |
---|
| 149 | Int m_codedPixels; |
---|
| 150 | Bool m_activeUnitLevelOn; |
---|
| 151 | Double m_costNonRefAvgWeighting; |
---|
| 152 | Double m_costRefAvgWeighting; |
---|
| 153 | Double m_costAvgbpp; |
---|
| 154 | |
---|
| 155 | FrameData* m_pcFrameData; |
---|
| 156 | LCUData* m_pcLCUData; |
---|
| 157 | |
---|
| 158 | MADLinearModel m_cMADLinearModel; |
---|
| 159 | PixelBaseURQQuadraticModel m_cPixelURQQuadraticModel; |
---|
| 160 | |
---|
| 161 | public: |
---|
| 162 | TEncRateCtrl () {}; |
---|
| 163 | virtual ~TEncRateCtrl() {}; |
---|
| 164 | |
---|
| 165 | Void create (Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight); |
---|
| 166 | Void destroy (); |
---|
| 167 | |
---|
| 168 | Void initFrameData (Int qp = 0); |
---|
| 169 | Void initUnitData (Int qp = 0); |
---|
| 170 | Int getFrameQP (Bool isReferenced, Int POC); |
---|
| 171 | Bool calculateUnitQP (); |
---|
| 172 | Int getUnitQP () { return m_pcLCUData[m_indexLCU].m_qp; } |
---|
| 173 | Void updateRCGOPStatus (); |
---|
| 174 | Void updataRCFrameStatus (Int frameBits, SliceType eSliceType); |
---|
| 175 | Void updataRCUnitStatus (); |
---|
| 176 | Void updateLCUData (TComDataCU* pcCU, UInt64 actualLCUBits, Int qp); |
---|
| 177 | Void updateFrameData (UInt64 actualFrameBits); |
---|
| 178 | Double xAdjustmentBits (Int& reductionBits, Int& compensationBits); |
---|
| 179 | Int getGOPId () { return m_indexFrame; } |
---|
| 180 | }; |
---|
| 181 | #endif |
---|
| 182 | |
---|
| 183 | |
---|