/src/vvenc/source/Lib/CommonLib/dtrace_buffer.h
Line | Count | Source |
1 | | /* ----------------------------------------------------------------------------- |
2 | | The copyright in this software is being made available under the Clear BSD |
3 | | License, included below. No patent rights, trademark rights and/or |
4 | | other Intellectual Property Rights other than the copyrights concerning |
5 | | the Software are granted under this license. |
6 | | |
7 | | The Clear BSD License |
8 | | |
9 | | Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors. |
10 | | All rights reserved. |
11 | | |
12 | | Redistribution and use in source and binary forms, with or without modification, |
13 | | are permitted (subject to the limitations in the disclaimer below) provided that |
14 | | the following conditions are met: |
15 | | |
16 | | * Redistributions of source code must retain the above copyright notice, |
17 | | this list of conditions and the following disclaimer. |
18 | | |
19 | | * Redistributions in binary form must reproduce the above copyright |
20 | | notice, this list of conditions and the following disclaimer in the |
21 | | documentation and/or other materials provided with the distribution. |
22 | | |
23 | | * Neither the name of the copyright holder nor the names of its |
24 | | contributors may be used to endorse or promote products derived from this |
25 | | software without specific prior written permission. |
26 | | |
27 | | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY |
28 | | THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
29 | | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
30 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
31 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
32 | | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
33 | | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
34 | | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
35 | | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
36 | | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
37 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
38 | | POSSIBILITY OF SUCH DAMAGE. |
39 | | |
40 | | |
41 | | ------------------------------------------------------------------------------------------- */ |
42 | | /** \file dtrace_buffer.h |
43 | | * \brief Easy to use dtrace calls concerning buffers |
44 | | */ |
45 | | |
46 | | #pragma once |
47 | | |
48 | | #include "dtrace.h" |
49 | | #include "dtrace_next.h" |
50 | | #include "CommonDef.h" |
51 | | #include "Unit.h" |
52 | | #include "UnitTools.h" |
53 | | |
54 | | //! \ingroup CommonLib |
55 | | //! \{ |
56 | | |
57 | | namespace vvenc { |
58 | | |
59 | | inline unsigned calcCheckSum( const int iWidth, const int iHeight, const Pel* p, const uint32_t stride, const int bitdepth ) |
60 | 0 | { |
61 | 0 | unsigned checksum = 0; |
62 | 0 | for( unsigned y = 0; y < iHeight; y++) |
63 | 0 | { |
64 | 0 | for( unsigned x = 0; x < iWidth; x++) |
65 | 0 | { |
66 | 0 | uint8_t xor_mask = (x & 0xff) ^ (y & 0xff) ^ (x >> 8) ^ (y >> 8); |
67 | 0 | checksum = (checksum + ((p[y*stride+x] & 0xff) ^ xor_mask)) & 0xffffffff; |
68 | 0 |
|
69 | 0 | if(bitdepth > 8) |
70 | 0 | { |
71 | 0 | checksum = (checksum + ((p[y*stride+x]>>8) ^ xor_mask)) & 0xffffffff; |
72 | 0 | } |
73 | 0 | } |
74 | 0 | } |
75 | 0 | return checksum; |
76 | 0 | } |
77 | | |
78 | | inline unsigned calcCheckSum( const CPelBuf& buf, int bitdepth ) |
79 | 0 | { |
80 | 0 | return calcCheckSum( buf.width, buf.height, buf.buf, buf.stride, bitdepth ); |
81 | 0 | } |
82 | | |
83 | | #if ENABLE_TRACING |
84 | | |
85 | | ////////////////////////////////////////////////////////////////////////// |
86 | | // |
87 | | // Specialized helper functions |
88 | | // |
89 | | ////////////////////////////////////////////////////////////////////////// |
90 | | template<typename T> |
91 | | inline void dtraceCoeffBuf( DTRACE_CHANNEL channnel, const AreaBuf<T>& coefBuf, const UnitArea& ua, PredMode predMode, const ComponentID compId, uint32_t zIdx = 0 ) |
92 | | { |
93 | | int x0 = ua.blocks[compId].x; |
94 | | int y0 = ua.blocks[compId].y; |
95 | | const uint32_t uiStride = coefBuf.stride; |
96 | | const T* piReco = coefBuf.buf; |
97 | | const uint32_t uiWidth = ua.blocks[compId].width; |
98 | | const uint32_t uiHeight = ua.blocks[compId].height; |
99 | | DTRACE(g_trace_ctx, channnel, "@(%4d,%4d) [%2dx%2d] comp=%d predmode=%d \n", x0, y0, uiWidth, uiHeight, compId, predMode); |
100 | | DTRACE_BLOCK(g_trace_ctx, channnel, piReco, uiStride, uiWidth, uiHeight); |
101 | | } |
102 | | |
103 | | inline void dtracePelBuf( DTRACE_CHANNEL channnel, const CPelBuf& pelBuf, const UnitArea& ua, PredMode predMode, const ComponentID compId ) |
104 | | { |
105 | | int x0 = ua.block(compId).x; |
106 | | int y0 = ua.block(compId).y; |
107 | | const uint32_t uiStride = pelBuf.stride; |
108 | | const Pel* piReco = pelBuf.buf; |
109 | | const uint32_t uiWidth = ua.block(compId).width; |
110 | | const uint32_t uiHeight = ua.block(compId).height; |
111 | | DTRACE ( g_trace_ctx, channnel, "@(%4d,%4d) [%2dx%2d] comp=%d predmode=%d \n", x0, y0, uiWidth, uiHeight, compId, predMode ); |
112 | | DTRACE_BLOCK( g_trace_ctx, channnel, piReco, uiStride, uiWidth, uiHeight ); |
113 | | } |
114 | | |
115 | | inline void dtraceBlockRec( const CPelUnitBuf& pelUnitBuf, const UnitArea& ua, PredMode predMode, uint32_t zIdx = 0 ) |
116 | | { |
117 | | if( ua.blocks[COMP_Y].valid() ) |
118 | | { |
119 | | const int x0 = ua.lumaPos().x; |
120 | | const int y0 = ua.lumaPos().y; |
121 | | const uint32_t uiStride = pelUnitBuf.Y().stride; |
122 | | const Pel* piReco = pelUnitBuf.Y().buf; |
123 | | const uint32_t uiWidth = ua.lumaSize().width; |
124 | | const uint32_t uiHeight = ua.lumaSize().height; |
125 | | DTRACE ( g_trace_ctx, D_REC_CB_LUMA, "%d, x=%d, y=%d, size=%dx%d, predmode=%d \n", zIdx, x0, y0, uiWidth, uiHeight, predMode ); |
126 | | DTRACE_BLOCK( g_trace_ctx, D_REC_CB_LUMA, piReco, uiStride, uiWidth, uiHeight ); |
127 | | } |
128 | | if( ua.blocks.size() > 2 && ua.blocks[COMP_Cb].valid() ) |
129 | | { |
130 | | const int x0 = ua.blocks[1].x; |
131 | | const int y0 = ua.blocks[1].y; |
132 | | const uint32_t uiWidth = ua.blocks[1].width; |
133 | | const uint32_t uiHeight = ua.blocks[1].height; |
134 | | const uint32_t uiCStride = pelUnitBuf.Cb().stride; |
135 | | const Pel* piRecoU = pelUnitBuf.Cb().buf; |
136 | | const Pel* piRecoV = pelUnitBuf.Cr().buf; |
137 | | DTRACE ( g_trace_ctx, D_REC_CB_CHROMA, "%d, x=%d, y=%d, size=%dx%d, predmode=%d \n", zIdx, x0, y0, uiWidth, uiHeight, predMode ); |
138 | | DTRACE_BLOCK( g_trace_ctx, D_REC_CB_CHROMA, piRecoU, uiCStride, uiWidth, uiHeight ); |
139 | | DTRACE_BLOCK( g_trace_ctx, D_REC_CB_CHROMA, piRecoV, uiCStride, uiWidth, uiHeight ); |
140 | | } |
141 | | } |
142 | | |
143 | | inline void dtraceUnitComp( DTRACE_CHANNEL channel, CPelUnitBuf& pelUnitBuf, const UnitArea& ua, ComponentID compId, PredMode predMode, uint32_t zIdx = 0 ) |
144 | | { |
145 | | if( !g_trace_ctx ) return; |
146 | | if( pelUnitBuf.chromaFormat == CHROMA_400 && compId != COMP_Y ) return; |
147 | | const Pel* piReco = pelUnitBuf.bufs[compId].buf; |
148 | | uint32_t uiStride = pelUnitBuf.bufs[compId].stride; |
149 | | uint32_t uiWidth = ua.blocks[compId].width; |
150 | | uint32_t uiHeight = ua.blocks[compId].height; |
151 | | int x0 = ua.lumaPos().x; |
152 | | int y0 = ua.lumaPos().y; |
153 | | |
154 | | DTRACE ( g_trace_ctx, channel, "%s: %d, x=%d, y=%d, size=%dx%d, predmode=%d \n", g_trace_ctx->getChannelName(channel), zIdx, x0, y0, uiWidth, uiHeight, predMode ); |
155 | | DTRACE_BLOCK( g_trace_ctx, channel, piReco, uiStride, uiWidth, uiHeight ); |
156 | | } |
157 | | |
158 | | inline void dtraceMotField( CDTrace *trace_ctx, const CodingUnit& cu ) |
159 | | { |
160 | | DTRACE( trace_ctx, D_MOT_FIELD, "CU %d,%d @ %d,%d\n", cu.lwidth(), cu.lheight(), cu.lx(), cu.ly() ); |
161 | | const CMotionBuf mb = cu.getMotionBuf(); |
162 | | for( uint32_t listIdx = 0; listIdx < 2; listIdx++ ) |
163 | | { |
164 | | RefPicList eListIdx = RefPicList( listIdx ); |
165 | | for( int y = 0, i = 0; y < cu.lheight(); y += 4 ) |
166 | | { |
167 | | for( int x = 0; x < cu.lwidth(); x += 4, i++ ) |
168 | | { |
169 | | const MotionInfo &mi = mb.at( x >> 2, y >> 2 ); |
170 | | DTRACE( trace_ctx, D_MOT_FIELD, "%d,%d:%d ", mi.mv[eListIdx].hor, mi.mv[eListIdx].ver, mi.miRefIdx[eListIdx] ); |
171 | | } |
172 | | DTRACE( trace_ctx, D_MOT_FIELD, "\n" ); |
173 | | } |
174 | | DTRACE( trace_ctx, D_MOT_FIELD, "\n" ); |
175 | | } |
176 | | } |
177 | | |
178 | | inline void dtraceCRC( CDTrace *trace_ctx, DTRACE_CHANNEL channel, const CodingStructure& cs, const CPelUnitBuf& pelUnitBuf, const Area* parea = NULL ) |
179 | | { |
180 | | const Area& area = parea ? *parea : cs.area.Y(); |
181 | | if( cs.pcv->chrFormat == VVENC_CHROMA_400) |
182 | | { |
183 | | DTRACE( trace_ctx, channel, " CRC: %6lld %3d @(%4d,%4d) [%2dx%2d] ,Checksum(%x)\n", |
184 | | DTRACE_GET_COUNTER( g_trace_ctx, channel ), |
185 | | cs.slice->poc, |
186 | | area.x, area.y, area.width, area.height, |
187 | | calcCheckSum( pelUnitBuf.bufs[COMP_Y], cs.sps->bitDepths[CH_L])); |
188 | | } |
189 | | else |
190 | | { |
191 | | DTRACE( trace_ctx, channel, " CRC: %6lld %3d @(%4d,%4d) [%2dx%2d] ,Checksum(%x %x %x)\n", |
192 | | DTRACE_GET_COUNTER( g_trace_ctx, channel ), |
193 | | cs.slice->poc, |
194 | | area.x, area.y, area.width, area.height, |
195 | | calcCheckSum( pelUnitBuf.bufs[COMP_Y], cs.sps->bitDepths[CH_L]), |
196 | | calcCheckSum( pelUnitBuf.bufs[COMP_Cb], cs.sps->bitDepths[CH_C]), |
197 | | calcCheckSum( pelUnitBuf.bufs[COMP_Cr], cs.sps->bitDepths[CH_C])); |
198 | | } |
199 | | } |
200 | | |
201 | | inline void dtraceCCRC( CDTrace *trace_ctx, DTRACE_CHANNEL channel, const CodingStructure& cs, const CPelBuf& pelBuf, ComponentID compId, const Area* parea = NULL ) |
202 | | { |
203 | | const Area& area = parea ? *parea : cs.area.Y(); |
204 | | DTRACE( trace_ctx, channel, "CCRC: %6lld %3d @(%4d,%4d) [%2dx%2d] ,comp %d Checksum(%x)\n", |
205 | | DTRACE_GET_COUNTER( g_trace_ctx, channel ), |
206 | | cs.slice->poc, |
207 | | area.x, area.y, area.width, area.height, compId, |
208 | | calcCheckSum( pelBuf, cs.sps->bitDepths[ toChannelType(compId) ])); |
209 | | } |
210 | | |
211 | | |
212 | | inline void dtraceAreaCRC( CDTrace *trace_ctx, DTRACE_CHANNEL channel, const CodingStructure& cs, const UnitArea& ctuArea ) |
213 | | { |
214 | | dtraceCRC( g_trace_ctx, channel, cs, cs.picture->getRecoBuf( clipArea( ctuArea, *cs.picture ) ), &ctuArea.Y() ); |
215 | | |
216 | | for( auto &currCU : cs.traverseCUs( CS::getArea( cs, ctuArea, CH_L, TREE_D ), CH_L ) ) |
217 | | { |
218 | | if( currCU.Y().valid() ) |
219 | | { |
220 | | dtraceCCRC(g_trace_ctx, channel, *currCU.cs, currCU.cs->picture->getRecoBuf(currCU.Y()), COMP_Y, &currCU.Y()); |
221 | | } |
222 | | } |
223 | | |
224 | | if( cs.pcv->chrFormat != VVENC_CHROMA_400 ) |
225 | | { |
226 | | for( auto &currCU : cs.traverseCUs( CS::getArea( cs, ctuArea, CH_C, TREE_D ), CH_C ) ) |
227 | | { |
228 | | if( currCU.Cb().valid() ) |
229 | | { |
230 | | dtraceCCRC(g_trace_ctx, channel, *currCU.cs, currCU.cs->picture->getRecoBuf(currCU.Cb()), COMP_Cb, &currCU.Cb()); |
231 | | dtraceCCRC(g_trace_ctx, channel, *currCU.cs, currCU.cs->picture->getRecoBuf(currCU.Cr()), COMP_Cr, &currCU.Cb()); |
232 | | } |
233 | | } |
234 | | } |
235 | | } |
236 | | |
237 | | |
238 | | #define DTRACE_PEL_BUF(...) dtracePelBuf( __VA_ARGS__ ) |
239 | | #define DTRACE_COEFF_BUF(...) dtraceCoeffBuf( __VA_ARGS__ ) |
240 | | #define DTRACE_BLOCK_REC(...) dtraceBlockRec( __VA_ARGS__ ) |
241 | | #define DTRACE_PEL_BUF_COND(_cond,...) { if((_cond)) dtracePelBuf( __VA_ARGS__ ); } |
242 | | #define DTRACE_COEFF_BUF_COND(_cond,...) { if((_cond)) dtraceCoeffBuf( __VA_ARGS__ ); } |
243 | | #define DTRACE_BLOCK_REC_COND(_cond,...) { if((_cond)) dtraceBlockRec( __VA_ARGS__ ); } |
244 | | #define DTRACE_UNIT_COMP(...) dtraceUnitComp( __VA_ARGS__ ) |
245 | | #define DTRACE_MOT_FIELD(...) dtraceMotField( __VA_ARGS__ ) |
246 | | #define DTRACE_CRC(...) dtraceCRC( __VA_ARGS__ ) |
247 | | #define DTRACE_CCRC(...) dtraceCCRC( __VA_ARGS__ ) |
248 | | #define DTRACE_AREA_CRC(...) dtraceAreaCRC( __VA_ARGS__ ) |
249 | | |
250 | | #else |
251 | | |
252 | | #define DTRACE_PEL_BUF(...) |
253 | | #define DTRACE_COEFF_BUF(...) |
254 | | #define DTRACE_BLOCK_REC(...) |
255 | | #define DTRACE_PEL_BUF_COND(...) |
256 | | #define DTRACE_COEFF_BUF_COND(...) |
257 | | #define DTRACE_BLOCK_REC_COND(...) |
258 | | #define DTRACE_UNIT_COMP(...) |
259 | | #define DTRACE_MOT_FIELD(...) |
260 | | #define DTRACE_CRC(...) |
261 | | #define DTRACE_CCRC(...) |
262 | | #define DTRACE_AREA_CRC(...) |
263 | | #endif |
264 | | |
265 | | } // namespace vvenc |
266 | | |
267 | | //! \} |
268 | | |