1 /* -----------------------------------------------------------------------------
2 The copyright in this software is being made available under the 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 For any license concerning other Intellectual Property rights than the software,
8 especially patent licenses, a separate Agreement needs to be closed.
9 For more information please contact:
10
11 Fraunhofer Heinrich Hertz Institute
12 Einsteinufer 37
13 10587 Berlin, Germany
14 www.hhi.fraunhofer.de/vvc
15 vvc@hhi.fraunhofer.de
16
17 Copyright (c) 2018-2021, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
18 All rights reserved.
19
20 Redistribution and use in source and binary forms, with or without
21 modification, are permitted provided that the following conditions are met:
22
23 * Redistributions of source code must retain the above copyright notice,
24 this list of conditions and the following disclaimer.
25 * Redistributions in binary form must reproduce the above copyright notice,
26 this list of conditions and the following disclaimer in the documentation
27 and/or other materials provided with the distribution.
28 * Neither the name of Fraunhofer nor the names of its contributors may
29 be used to endorse or promote products derived from this software without
30 specific prior written permission.
31
32 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
36 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
42 THE POSSIBILITY OF SUCH DAMAGE.
43
44
45 ------------------------------------------------------------------------------------------- */
46
47 /** \file dtrace_buffer.h
48 * \brief Easy to use dtrace calls concerning buffers
49 */
50
51 #pragma once
52
53 #include "dtrace.h"
54 #include "dtrace_next.h"
55
56 #include "CommonLib/CommonDef.h"
57 #include "CommonLib/Buffer.h"
58 #include "CommonLib/Unit.h"
59
60 namespace vvdec
61 {
62
calcCheckSum(const int iWidth,const int iHeight,const Pel * p,const ptrdiff_t stride,const int bitdepth)63 inline unsigned calcCheckSum( const int iWidth, const int iHeight, const Pel* p, const ptrdiff_t stride, const int bitdepth )
64 {
65 unsigned checksum = 0;
66 for( unsigned y = 0; y < iHeight; y++)
67 {
68 for( unsigned x = 0; x < iWidth; x++)
69 {
70 uint8_t xor_mask = (x & 0xff) ^ (y & 0xff) ^ (x >> 8) ^ (y >> 8);
71 checksum = (checksum + ((p[y*stride+x] & 0xff) ^ xor_mask)) & 0xffffffff;
72
73 if(bitdepth > 8)
74 {
75 checksum = (checksum + ((p[y*stride+x]>>8) ^ xor_mask)) & 0xffffffff;
76 }
77 }
78 }
79 return checksum;
80 }
81
calcCheckSum(const CPelBuf & buf,int bitdepth)82 inline unsigned calcCheckSum( const CPelBuf& buf, int bitdepth )
83 {
84 return calcCheckSum( buf.width, buf.height, buf.buf, buf.stride, bitdepth );
85 }
86
87 #if ENABLE_TRACING
88
89 //////////////////////////////////////////////////////////////////////////
90 //
91 // Specialized helper functions
92 //
93 //////////////////////////////////////////////////////////////////////////
94 inline void dtraceCoeffBuf( DTRACE_CHANNEL channnel, const CCoeffBuf& coefBuf, const UnitArea& ua, PredMode predMode, const ComponentID compId, uint32_t zIdx = 0 )
95 {
96 int x0 = ua.blocks[compId].x;
97 int y0 = ua.blocks[compId].y;
98 const ptrdiff_t uiStride = coefBuf.stride;
99 const TCoeff* piReco = coefBuf.buf;
100 const uint32_t uiWidth = ua.blocks[compId].width;
101 const uint32_t uiHeight = ua.blocks[compId].height;
102 DTRACE(g_trace_ctx, channnel, "@(%4d,%4d) [%2dx%2d] comp=%d predmode=%d \n", x0, y0, uiWidth, uiHeight, compId, predMode);
103 DTRACE_BLOCK(g_trace_ctx, channnel, piReco, uiStride, uiWidth, uiHeight);
104 }
105
dtracePelBuf(DTRACE_CHANNEL channnel,const CPelBuf & pelBuf,const UnitArea & ua,PredMode predMode,const ComponentID compId)106 inline void dtracePelBuf( DTRACE_CHANNEL channnel, const CPelBuf& pelBuf, const UnitArea& ua, PredMode predMode, const ComponentID compId )
107 {
108 int x0 = ua.block(compId).x;
109 int y0 = ua.block(compId).y;
110 const ptrdiff_t uiStride = pelBuf.stride;
111 const Pel* piReco = pelBuf.buf;
112 const uint32_t uiWidth = ua.block(compId).width;
113 const uint32_t uiHeight = ua.block(compId).height;
114 DTRACE ( g_trace_ctx, channnel, "@(%4d,%4d) [%2dx%2d] comp=%d predmode=%d \n", x0, y0, uiWidth, uiHeight, compId, predMode );
115 DTRACE_BLOCK( g_trace_ctx, channnel, piReco, uiStride, uiWidth, uiHeight );
116 }
117
118 inline void dtraceBlockRec( const CPelUnitBuf& pelUnitBuf, const UnitArea& ua, PredMode predMode, uint32_t zIdx = 0 )
119 {
120 if( ua.blocks[COMPONENT_Y].valid() )
121 {
122 const int x0 = ua.lumaPos().x;
123 const int y0 = ua.lumaPos().y;
124 const ptrdiff_t uiStride = pelUnitBuf.Y().stride;
125 const Pel* piReco = pelUnitBuf.Y().buf;
126 const uint32_t uiWidth = ua.lumaSize().width;
127 const uint32_t uiHeight = ua.lumaSize().height;
128 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 );
129 DTRACE_BLOCK( g_trace_ctx, D_REC_CB_LUMA, piReco, uiStride, uiWidth, uiHeight );
130 }
131 if( ua.blocks[COMPONENT_Cb].valid() )
132 {
133 const int x0 = ua.blocks[1].x;
134 const int y0 = ua.blocks[1].y;
135 const uint32_t uiWidth = ua.blocks[1].width;
136 const uint32_t uiHeight = ua.blocks[1].height;
137 const ptrdiff_t uiCStride = pelUnitBuf.Cb().stride;
138 const Pel* piRecoU = pelUnitBuf.Cb().buf;
139 const Pel* piRecoV = pelUnitBuf.Cr().buf;
140 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 );
141 DTRACE_BLOCK( g_trace_ctx, D_REC_CB_CHROMA, piRecoU, uiCStride, uiWidth, uiHeight );
142 DTRACE_BLOCK( g_trace_ctx, D_REC_CB_CHROMA, piRecoV, uiCStride, uiWidth, uiHeight );
143 }
144 }
145
146 inline void dtraceUnitComp( DTRACE_CHANNEL channel, CPelUnitBuf& pelUnitBuf, const UnitArea& ua, ComponentID compId, PredMode predMode, uint32_t zIdx = 0 )
147 {
148 if( !g_trace_ctx ) return;
149 if( pelUnitBuf.chromaFormat == CHROMA_400 && compId != COMPONENT_Y ) return;
150 const Pel* piReco = pelUnitBuf.bufs[compId].buf;
151 ptrdiff_t uiStride = pelUnitBuf.bufs[compId].stride;
152 uint32_t uiWidth = ua.blocks[compId].width;
153 uint32_t uiHeight = ua.blocks[compId].height;
154 int x0 = ua.lumaPos().x;
155 int y0 = ua.lumaPos().y;
156
157 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 );
158 DTRACE_BLOCK( g_trace_ctx, channel, piReco, uiStride, uiWidth, uiHeight );
159 }
160
161 inline void dtraceCRC( CDTrace *trace_ctx, DTRACE_CHANNEL channel, const CodingStructure& cs, const CPelUnitBuf& pelUnitBuf, const Area* parea = NULL )
162 {
163 const Area& area = parea ? *parea : cs.area.Y();
164 DTRACE( trace_ctx, channel, " CRC: %6lld %3d @(%4d,%4d) [%2dx%2d] ,Checksum(%x %x %x)\n",
165 DTRACE_GET_COUNTER( g_trace_ctx, channel ),
166 cs.picture->poc,
167 area.x, area.y, area.width, area.height,
168 calcCheckSum( pelUnitBuf.bufs[COMPONENT_Y], cs.sps->getBitDepth (CHANNEL_TYPE_LUMA)),
169 calcCheckSum( pelUnitBuf.bufs[COMPONENT_Cb], cs.sps->getBitDepth (CHANNEL_TYPE_CHROMA)),
170 calcCheckSum( pelUnitBuf.bufs[COMPONENT_Cr], cs.sps->getBitDepth (CHANNEL_TYPE_CHROMA)));
171 }
172
173 inline void dtraceCCRC( CDTrace *trace_ctx, DTRACE_CHANNEL channel, const CodingStructure& cs, const CPelBuf& pelBuf, ComponentID compId, const Area* parea = NULL )
174 {
175 const Area& area = parea ? *parea : cs.area.Y();
176 DTRACE( trace_ctx, channel, "CRC: %6lld %3d @(%4d,%4d) [%2dx%2d] ,comp %d Checksum(%x)\n",
177 DTRACE_GET_COUNTER( g_trace_ctx, channel ),
178 cs.picture->poc,
179 area.x, area.y, area.width, area.height, compId,
180 calcCheckSum( pelBuf, cs.sps->getBitDepth ( toChannelType(compId) )));
181 }
182
183
184 #define DTRACE_PEL_BUF(...) dtracePelBuf( __VA_ARGS__ )
185 #define DTRACE_COEFF_BUF(...) dtraceCoeffBuf( __VA_ARGS__ )
186 #define DTRACE_BLOCK_REC(...) dtraceBlockRec( __VA_ARGS__ )
187 #define DTRACE_PEL_BUF_COND(_cond,...) { if((_cond)) dtracePelBuf( __VA_ARGS__ ); }
188 #define DTRACE_COEFF_BUF_COND(_cond,...) { if((_cond)) dtraceCoeffBuf( __VA_ARGS__ ); }
189 #define DTRACE_BLOCK_REC_COND(_cond,...) { if((_cond)) dtraceBlockRec( __VA_ARGS__ ); }
190 #define DTRACE_UNIT_COMP(...) dtraceUnitComp( __VA_ARGS__ )
191 #define DTRACE_CRC(...) dtraceCRC( __VA_ARGS__ )
192 #define DTRACE_CCRC(...) dtraceCCRC( __VA_ARGS__ )
193
194 #else
195
196 #define DTRACE_PEL_BUF(...)
197 #define DTRACE_COEFF_BUF(...)
198 #define DTRACE_BLOCK_REC(...)
199 #define DTRACE_PEL_BUF_COND(...)
200 #define DTRACE_COEFF_BUF_COND(...)
201 #define DTRACE_BLOCK_REC_COND(...)
202 #define DTRACE_UNIT_COMP(...)
203 #define DTRACE_CRC(...)
204 #define DTRACE_CCRC(...)
205
206 #endif
207
208 }
209