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-2015, 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 Debug.h |
---|
35 | \brief Defines types and objects for environment-variable-based debugging and feature control |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef __DEBUG__ |
---|
39 | #define __DEBUG__ |
---|
40 | |
---|
41 | #include <iostream> |
---|
42 | #include <iomanip> |
---|
43 | #include <string> |
---|
44 | #include <list> |
---|
45 | #include <stdlib.h> |
---|
46 | #include <sstream> |
---|
47 | #include <TLibCommon/CommonDef.h> |
---|
48 | |
---|
49 | #ifdef DEBUG_STRING |
---|
50 | extern const Char *debug_reorder_data_inter_token[MAX_NUM_COMPONENT+1]; |
---|
51 | extern const Char *partSizeToString[NUMBER_OF_PART_SIZES]; |
---|
52 | #endif |
---|
53 | |
---|
54 | // ---------------------------------------------------------------------------------------------- // |
---|
55 | |
---|
56 | //constant print-out macro |
---|
57 | |
---|
58 | #define PRINT_CONSTANT(NAME, NAME_WIDTH, VALUE_WIDTH) std::cout << std::setw(NAME_WIDTH) << #NAME << " = " << std::setw(VALUE_WIDTH) << NAME << std::endl; |
---|
59 | |
---|
60 | // ---------------------------------------------------------------------------------------------- // |
---|
61 | |
---|
62 | // ---- Environment variables for test/debug ---- // |
---|
63 | |
---|
64 | class EnvVar |
---|
65 | { |
---|
66 | private: |
---|
67 | std::string m_sName; |
---|
68 | std::string m_sHelp; |
---|
69 | std::string m_sVal; |
---|
70 | Double m_dVal; |
---|
71 | Int m_iVal; |
---|
72 | Bool m_bSet; |
---|
73 | |
---|
74 | public: |
---|
75 | |
---|
76 | static std::list< std::pair<std::string, std::string> > &getEnvVarList(); |
---|
77 | static std::list<EnvVar*> &getEnvVarInUse(); |
---|
78 | static Void printEnvVar(); |
---|
79 | static Void printEnvVarInUse(); |
---|
80 | |
---|
81 | EnvVar(const std::string &sName, const std::string &sDefault, const std::string &sHelp); |
---|
82 | |
---|
83 | Double getDouble() const { return m_dVal; } |
---|
84 | Int getInt() const { return m_iVal; } |
---|
85 | const std::string &getString() const { return m_sVal; } |
---|
86 | Bool isSet() const { return m_bSet; } |
---|
87 | Bool isTrue() const { return m_iVal!=0; } |
---|
88 | const std::string &getName() const { return m_sName; } |
---|
89 | |
---|
90 | }; |
---|
91 | |
---|
92 | |
---|
93 | // ---------------------------------------------------------------------------------------------- // |
---|
94 | |
---|
95 | // ---- Control switches for debugging and feature control ---- // |
---|
96 | |
---|
97 | namespace DebugOptionList |
---|
98 | { |
---|
99 | extern EnvVar DebugSBAC; |
---|
100 | extern EnvVar DebugRQT; |
---|
101 | extern EnvVar DebugPred; |
---|
102 | extern EnvVar ForceLumaMode; |
---|
103 | extern EnvVar ForceChromaMode; |
---|
104 | |
---|
105 | #ifdef DEBUG_STRING |
---|
106 | extern EnvVar DebugString_Structure; |
---|
107 | extern EnvVar DebugString_Pred; |
---|
108 | extern EnvVar DebugString_Resi; |
---|
109 | extern EnvVar DebugString_Reco; |
---|
110 | extern EnvVar DebugString_InvTran; |
---|
111 | #endif |
---|
112 | } |
---|
113 | |
---|
114 | // ---------------------------------------------------------------------------------------------- // |
---|
115 | |
---|
116 | Void printMacroSettings(); |
---|
117 | |
---|
118 | // ---------------------------------------------------------------------------------------------- // |
---|
119 | |
---|
120 | //Debugging |
---|
121 | |
---|
122 | extern UInt g_debugCounter; |
---|
123 | |
---|
124 | #ifdef DEBUG_ENCODER_SEARCH_BINS |
---|
125 | extern const UInt debugEncoderSearchBinTargetLine; |
---|
126 | extern const UInt debugEncoderSearchBinWindow; |
---|
127 | #endif |
---|
128 | |
---|
129 | #ifdef DEBUG_CABAC_BINS |
---|
130 | extern const UInt debugCabacBinTargetLine; |
---|
131 | extern const UInt debugCabacBinWindow; |
---|
132 | #endif |
---|
133 | |
---|
134 | |
---|
135 | Void printSBACCoeffData( const UInt lastX, |
---|
136 | const UInt lastY, |
---|
137 | const UInt width, |
---|
138 | const UInt height, |
---|
139 | const UInt chan, |
---|
140 | const UInt absPart, |
---|
141 | const UInt scanIdx, |
---|
142 | const TCoeff *const pCoeff, |
---|
143 | const Bool finalEncode=true |
---|
144 | ); |
---|
145 | |
---|
146 | |
---|
147 | Void printCbfArray( class TComDataCU* pcCU ); |
---|
148 | |
---|
149 | UInt getDecimalWidth(const Double value); |
---|
150 | UInt getZScanIndex(const UInt x, const UInt y); |
---|
151 | |
---|
152 | //template specialisation for Char types to get it to render as a number |
---|
153 | template <typename ValueType> inline Void writeValueToStream (const ValueType &value, std::ostream &stream, const UInt outputWidth) { stream << std::setw(outputWidth) << value; } |
---|
154 | template <> inline Void writeValueToStream<Char >(const Char &value, std::ostream &stream, const UInt outputWidth) { stream << std::setw(outputWidth) << Int(value); } |
---|
155 | template <> inline Void writeValueToStream<UChar>(const UChar &value, std::ostream &stream, const UInt outputWidth) { stream << std::setw(outputWidth) << UInt(value); } |
---|
156 | |
---|
157 | template <typename ValueType> |
---|
158 | Void printBlock(const ValueType *const source, |
---|
159 | const UInt width, |
---|
160 | const UInt height, |
---|
161 | const UInt stride, |
---|
162 | const UInt outputValueWidth = 0, //if set to 0, the maximum output width will be calculated and used |
---|
163 | const Bool onlyPrintEdges = false, //print only the top row and left column for printing prediction reference samples |
---|
164 | const Bool printInZScan = false, //output values in Z-scan format (useful for values addressed by AbsPartIdxes) |
---|
165 | const Int shiftLeftBy = 0, //set a negative value to right-shift instead |
---|
166 | const Bool printAverage = false, //also print the average of the values in the block |
---|
167 | std::ostream & stream = std::cout) |
---|
168 | { |
---|
169 | //find the maximum output width |
---|
170 | UInt outputWidth = outputValueWidth; |
---|
171 | |
---|
172 | if (outputWidth == 0) |
---|
173 | { |
---|
174 | ValueType minimumValue = leftShift(source[0], shiftLeftBy); |
---|
175 | ValueType maximumValue = minimumValue; |
---|
176 | |
---|
177 | for (UInt y = 0; y < height; y++) |
---|
178 | { |
---|
179 | for (UInt x = 0; x < width; x++) |
---|
180 | { |
---|
181 | ValueType value = 0; |
---|
182 | |
---|
183 | if (!onlyPrintEdges || (x == 0) || (y == 0)) |
---|
184 | { |
---|
185 | value = leftShift(source[printInZScan ? getZScanIndex(x, y) : ((y * stride) + x)], shiftLeftBy); |
---|
186 | } |
---|
187 | |
---|
188 | if (value < minimumValue) |
---|
189 | { |
---|
190 | minimumValue = value; |
---|
191 | } |
---|
192 | else if (value > maximumValue) |
---|
193 | { |
---|
194 | maximumValue = value; |
---|
195 | } |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | outputWidth = std::max<UInt>(getDecimalWidth(Double(minimumValue)), getDecimalWidth(Double(maximumValue))) + 1; //+1 so the numbers don't run into each other |
---|
200 | } |
---|
201 | |
---|
202 | //------------------ |
---|
203 | //print out the block |
---|
204 | |
---|
205 | ValueType valueSum = 0; |
---|
206 | |
---|
207 | for (UInt y = 0; y < height; y++) |
---|
208 | { |
---|
209 | for (UInt x = 0; x < width; x++) |
---|
210 | { |
---|
211 | ValueType value = 0; |
---|
212 | |
---|
213 | if (!onlyPrintEdges || (x == 0) || (y == 0)) |
---|
214 | { |
---|
215 | value = leftShift(source[printInZScan ? getZScanIndex(x, y) : ((y * stride) + x)], shiftLeftBy); |
---|
216 | valueSum += value; |
---|
217 | } |
---|
218 | |
---|
219 | writeValueToStream(value, stream, outputWidth); |
---|
220 | } |
---|
221 | stream << "\n"; |
---|
222 | } |
---|
223 | |
---|
224 | const Int valueCount = onlyPrintEdges ? Int((width + height) - 1) : Int(width * height); |
---|
225 | if (printAverage) |
---|
226 | { |
---|
227 | stream << "Average: " << (valueSum / valueCount) << "\n"; |
---|
228 | } |
---|
229 | stream << "\n"; |
---|
230 | } |
---|
231 | |
---|
232 | |
---|
233 | template <typename T> |
---|
234 | Void printBlockToStream( std::ostream &ss, const Char *pLinePrefix, const T * blkSrc, const UInt width, const UInt height, const UInt stride, const UInt subBlockWidth=0, const UInt subBlockHeight=0, const UInt defWidth=3 ) |
---|
235 | { |
---|
236 | for (UInt y=0; y<height; y++) |
---|
237 | { |
---|
238 | if (subBlockHeight!=0 && (y%subBlockHeight)==0 && y!=0) |
---|
239 | { |
---|
240 | ss << pLinePrefix << '\n'; |
---|
241 | } |
---|
242 | |
---|
243 | ss << pLinePrefix; |
---|
244 | for (UInt x=0; x<width; x++) |
---|
245 | { |
---|
246 | if (subBlockWidth!=0 && (x%subBlockWidth)==0 && x!=0) |
---|
247 | { |
---|
248 | ss << std::setw(defWidth+2) << ""; |
---|
249 | } |
---|
250 | |
---|
251 | ss << std::setw(defWidth) << blkSrc[y*stride + x] << ' '; |
---|
252 | } |
---|
253 | ss << '\n'; |
---|
254 | } |
---|
255 | } |
---|
256 | |
---|
257 | class TComYuv; |
---|
258 | Void printBlockToStream( std::ostream &ss, const Char *pLinePrefix, TComYuv &src, const UInt numSubBlocksAcross=1, const UInt numSubBlocksUp=1, const UInt defWidth=3 ); |
---|
259 | |
---|
260 | // ---------------------------------------------------------------------------------------------- // |
---|
261 | |
---|
262 | //String manipulation functions for aligning and wrapping printed text |
---|
263 | |
---|
264 | std::string splitOnSettings(const std::string &input); |
---|
265 | |
---|
266 | std::string lineWrap(const std::string &input, const UInt maximumLineLength); |
---|
267 | |
---|
268 | std::string indentNewLines(const std::string &input, const UInt indentBy); |
---|
269 | |
---|
270 | // ---------------------------------------------------------------------------------------------- // |
---|
271 | |
---|
272 | #ifdef DEBUG_STRING |
---|
273 | Int DebugStringGetPredModeMask(PredMode mode); |
---|
274 | Void DebugInterPredResiReco(std::string &sDebug, TComYuv &pred, TComYuv &resi, TComYuv &reco, Int predmode_mask); |
---|
275 | #endif |
---|
276 | |
---|
277 | |
---|
278 | #endif /* __DEBUG__ */ |
---|