GSaha567/seq_level_training_data
052
1text,length,is_long_context,metric_val,label_metric2"/* The copyright in this software is being made available under the BSD3 * License, included below. This software may be subject to other third party4 * and contributor rights, including patent rights, and no such rights are5 * granted under this license.6 *7 * Copyright (c) 2010-2019, ITU/ISO/IEC8 * All rights reserved.9 *10 * Redistribution and use in source and binary forms, with or without11 * modification, are permitted provided that the following conditions are met:12 *13 * * Redistributions of source code must retain the above copyright notice,14 * this list of conditions and the following disclaimer.15 * * Redistributions in binary form must reproduce the above copyright notice,16 * this list of conditions and the following disclaimer in the documentation17 * and/or other materials provided with the distribution.18 * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may19 * be used to endorse or promote products derived from this software without20 * specific prior written permission.21 *22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF32 * THE POSSIBILITY OF SUCH DAMAGE.33 */34 35/** \\file dtrace_blockstatistics.cpp36 * \\brief DTrace block statistcis support for next software37 */38 39#include ""dtrace_blockstatistics.h""40#include ""dtrace.h""41#include ""dtrace_next.h""42#include ""CommonLib/Unit.h""43#include ""CommonLib/Picture.h""44#include ""CommonLib/UnitTools.h""45//#include ""CommonLib/CodingStructure.h""46#define BLOCK_STATS_POLYGON_MIN_POINTS 347#define BLOCK_STATS_POLYGON_MAX_POINTS 548 49#if K0149_BLOCK_STATISTICS50std::string GetBlockStatisticName(BlockStatistic statistic)51{52 auto statisticIterator = blockstatistic2description.find(statistic);53 // enforces that all delcared statistic enum items are also part of the map54 assert(statisticIterator != blockstatistic2description.end() && ""A block statistics declared in the enum is missing in the map for statistic description."");55 56 return std::get<0>(statisticIterator->second);57}58 59std::string GetBlockStatisticTypeString(BlockStatistic statistic)60{61 auto statisticIterator = blockstatistic2description.find(statistic);62 // enforces that all delcared statistic enum items are also part of the map63 assert(statisticIterator != blockstatistic2description.end() && ""A block statistics declared in the enum is missing in the map for statistic description."");64 65 BlockStatisticType statisticType = std::get<1>(statisticIterator->second);66 switch (statisticType) {67 case BlockStatisticType::Flag:68 return std::string(""Flag"");69 break;70 case BlockStatisticType::Vector:71 return std::string(""Vector"");72 break;73 case BlockStatisticType::Integer:74 return std::string(""Integer"");75 break;76 case BlockStatisticType::AffineTFVectors:77 return std::string(""AffineTFVectors"");78 break;79 case BlockStatisticType::Line:80 return std::string(""Line"");81 break;82 case BlockStatisticType::FlagPolygon:83 return std::string(""FlagPolygon"");84 break;85 case BlockStatisticType::VectorPolygon:86 return std::string(""VectorPolygon"");87 break;88 case BlockStatisticType::IntegerPolygon:89 return std::string(""IntegerPolygon"");90 break;91 default:92 assert(0);93 break;94 }95 return std::string();96}97 98std::string GetBlockStatisticTypeSpecificInfo(BlockStatistic statistic)99{100 auto statisticIterator = blockstatistic2description.find(statistic);101 // enforces that all delcared statistic enum items are also part of the map102 assert(statisticIterator != blockstatistic2description.end() && ""A block statistics declared in the enum is missing in the map for statistic description."");103 104 return std::get<2>(statisticIterator->second);105}106 107void CDTrace::dtrace_block_scalar( int k, const CodingStructure &cs, std::string stat_type, signed value )108{109#if BLOCK_STATS_AS_CSV110 dtrace<false>( k, ""BlockStat;%d;%4d;%4d;%2d;%2d;%s;%d\\n"", cs.picture->poc, cs.area.lx(), cs.area.ly(), cs.area.lwidth(), cs.area.lheight(), stat_type.c_str(), value );111#else112 dtrace<false>( k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s=%d\\n"", cs.picture->poc, cs.area.lx(), cs.area.ly(), cs.area.lwidth(), cs.area.lheight(), stat_type.c_str(), value );113#endif114}115 116void CDTrace::dtrace_block_scalar( int k, const CodingUnit &cu, std::string stat_type, signed value, bool isChroma /*= false*/ )117{118 const CodingStructure& cs = *cu.cs;119#if BLOCK_STATS_AS_CSV120 if(isChroma)121 {122 dtrace<false>( k, ""BlockStat;%d;%4d;%4d;%2d;%2d;%s;%d\\n"", cs.picture->poc, cu.Cb().x*2, cu.Cb().y*2, cu.Cb().width*2, cu.Cb().height*2, stat_type.c_str(), value );123 }124 else125 {126 dtrace<false>( k, ""BlockStat;%d;%4d;%4d;%2d;%2d;%s;%d\\n"", cs.picture->poc, cu.lx(), cu.ly(), cu.lwidth(), cu.lheight(), stat_type.c_str(), value );127 }128#else129 if(isChroma)130 {131 dtrace<false>( k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s=%d\\n"", cs.picture->poc, cu.Cb().x*2, cu.Cb().y*2, cu.Cb().width*2, cu.Cb().height*2, stat_type.c_str(), value );132 }133 else134 {135 dtrace<false>( k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s=%d\\n"", cs.picture->poc, cu.lx(), cu.ly(), cu.lwidth(), cu.lheight(), stat_type.c_str(), value );136 }137#endif138}139 140void CDTrace::dtrace_block_vector( int k, const CodingUnit &cu, std::string stat_type, signed val_x, signed val_y )141{142 const CodingStructure& cs = *cu.cs;143#if BLOCK_STATS_AS_CSV144 dtrace<false>( k, ""BlockStat;%d;%4d;%4d;%2d;%2d;%s;%4d;%4d\\n"", cs.picture->poc, cu.lx(), cu.ly(), cu.lwidth(), cu.lheight(), stat_type.c_str(), val_x, val_y );145#else146 dtrace<false>( k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s={%4d,%4d}\\n"", cs.picture->poc, cu.lx(), cu.ly(), cu.lwidth(), cu.lheight(), stat_type.c_str(), val_x, val_y );147#endif148}149 150void CDTrace::dtrace_block_scalar( int k, const PredictionUnit &pu, std::string stat_type, signed value, bool isChroma /*= false*/ )151{152 const CodingStructure& cs = *pu.cs;153#if BLOCK_STATS_AS_CSV154 if(isChroma)155 {156 dtrace<false>( k, ""BlockStat;%d;%4d;%4d;%2d;%2d;%s;%d\\n"", cs.picture->poc, pu.Cb().x*2, pu.Cb().y*2, pu.Cb().width*2, pu.Cb().height*2, stat_type.c_str(), value );157 }158 else159 {160 dtrace<false>( k, ""BlockStat;%d;%4d;%4d;%2d;%2d;%s;%d\\n"", cs.picture->poc, pu.lx(), pu.ly(), pu.lwidth(), pu.lheight(), stat_type.c_str(), value );161 }162#else163 if(isChroma)164 {165 dtrace<false>( k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s=%d\\n"", cs.picture->poc, pu.Cb().x*2, pu.Cb().y*2, pu.Cb().width*2, pu.Cb().height*2, stat_type.c_str(), value );166 }167 else168 {169 dtrace<false>( k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s=%d\\n"", cs.picture->poc, pu.lx(), pu.ly(), pu.lwidth(), pu.lheight(), stat_type.c_str(), value );170 }171#endif172}173 174void CDTrace::dtrace_block_vector( int k, const PredictionUnit &pu, std::string stat_type, signed val_x, signed val_y, bool isChroma /*= false*/ )175{176 const CodingStructure& cs = *pu.cs;177#if BLOCK_STATS_AS_CSV178 if(isChroma)179 {180 dtrace<false>( k, ""BlockStat;%d;%4d;%4d;%2d;%2d;%s;%4d;%4d\\n"", cs.picture->poc, pu.Cb().x*2, pu.Cb().y*2, pu.Cb().width*2, pu.Cb().height*2, stat_type.c_str(), val_x*2, val_y*2 );181 }182 else183 {184 dtrace<false>( k, ""BlockStat;%d;%4d;%4d;%2d;%2d;%s;%4d;%4d\\n"", cs.picture->poc, pu.lx(), pu.ly(), pu.lwidth(), pu.lheight(), stat_type.c_str(), val_x, val_y );185 }186#else187 if(isChroma)188 {189 dtrace<false>( k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s={%4d,%4d}\\n"", cs.picture->poc, pu.Cb().x*2, pu.Cb().y*2, pu.Cb().width*2, pu.Cb().height*2, stat_type.c_str(), val_x*2, val_y*2 );190 }191 else192 {193 dtrace<false>( k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s={%4d,%4d}\\n"", cs.picture->poc, pu.lx(), pu.ly(), pu.lwidth(), pu.lheight(), stat_type.c_str(), val_x, val_y );194 }195#endif196}197 198void CDTrace::dtrace_block_scalar(int k, const TransformUnit &tu, std::string stat_type, signed value, bool isChroma /*= false*/ )199{200 const CodingStructure& cs = *tu.cs;201#if BLOCK_STATS_AS_CSV202 if(isChroma)203 {204 dtrace<false>( k, ""BlockStat;%d;%4d;%4d;%2d;%2d;%s;%d\\n"", cs.picture->poc, tu.Cb().x*2, tu.Cb().y*2, tu.Cb().width*2, tu.Cb().height*2, stat_type.c_str(), value );205 }206 else207 {208 dtrace<false>( k, ""BlockStat;%d;%4d;%4d;%2d;%2d;%s;%d\\n"", cs.picture->poc, tu.lx(), tu.ly(), tu.lwidth(), tu.lheight(), stat_type.c_str(), value );209 }210#else211 if(isChroma)212 {213 dtrace<false>( k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s=%d\\n"", cs.picture->poc, tu.Cb().x*2, tu.Cb().y*2, tu.Cb().width*2, tu.Cb().height*2, stat_type.c_str(), value );214 }215 else216 {217 dtrace<false>( k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s=%d\\n"", cs.picture->poc, tu.lx(), tu.ly(), tu.lwidth(), tu.lheight(), stat_type.c_str(), value );218 }219#endif220}221 222void CDTrace::dtrace_block_vector(int k, const TransformUnit &tu, std::string stat_type, signed val_x, signed val_y)223{224 const CodingStructure& cs = *tu.cs;225#if BLOCK_STATS_AS_CSV226 dtrace<false>(k, ""BlockStat;%d;%4d;%4d;%2d;%2d;%s;%4d;%4d\\n"", cs.picture->poc, pu.lx(), pu.ly(), pu.lwidth(), pu.lheight(), stat_type.c_str(), val_x, val_y);227#else228 dtrace<false>(k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s={%4d,%4d}\\n"", cs.picture->poc, tu.lx(), tu.ly(), tu.lwidth(), tu.lheight(), stat_type.c_str(), val_x, val_y);229#endif230}231 232void CDTrace::dtrace_block_affinetf( int k, const PredictionUnit &pu, std::string stat_type, signed val_x0, signed val_y0, signed val_x1, signed val_y1, signed val_x2, signed val_y2 )233{234 const CodingStructure& cs = *pu.cs;235#if BLOCK_STATS_AS_CSV236 dtrace<false>( k, ""BlockStat;%d;%4d;%4d;%2d;%2d;%s;%4d;%4d;%4d;%4d;%4d;%4d\\n"",237 cs.picture->poc, pu.lx(), pu.ly(), pu.lwidth(), pu.lheight(), stat_type.c_str(),238 val_x0, val_y0, val_x1, val_y1 , val_x2, val_y2 );239#else240 dtrace<false>( k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s={%4d,%4d,%4d,%4d,%4d,%4d}\\n"",241 cs.picture->poc, pu.lx(), pu.ly(), pu.lwidth(), pu.lheight(), stat_type.c_str(),242 val_x0, val_y0, val_x1, val_y1 , val_x2, val_y2 );243#endif244}245 246void CDTrace::dtrace_block_line(int k, const CodingUnit &cu, std::string stat_type, int x0, int y0, int x1, int y1)247{248 dtrace<false>(k, ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s={%4d,%4d,%4d,%4d}\\n"", cu.slice->getPOC(), cu.lx(), cu.ly(), cu.lwidth(), cu.lheight(), stat_type.c_str(), x0, y0, x1, y1);249}250 251void CDTrace::dtrace_polygon_scalar(int k, int poc, const std::vector<Position> &polygon, std::string stat_type, signed value)252{253 assert(polygon.size() >= BLOCK_STATS_POLYGON_MIN_POINTS && ""Not enough points to from polygon!"");254 assert(polygon.size() <= BLOCK_STATS_POLYGON_MAX_POINTS && ""Too many points. Unsupported polygon!"");255 std::string polygonDescription;256 for (auto position : polygon)257 {258 polygonDescription += ""("" + std::to_string(position.x) + "", "" + std::to_string(position.y) + "")--"";259 }260 dtrace<false>(k, ""BlockStat: POC %d @[%s] %s=%d\\n"", poc, polygonDescription.c_str(), stat_type.c_str(), value);261}262 263void CDTrace::dtrace_polygon_vector(int k, int poc, const std::vector<Position> &polygon, std::string stat_type, signed val_x, signed val_y)264{265 assert(polygon.size() >= BLOCK_STATS_POLYGON_MIN_POINTS && ""Not enough points to from polygon!"");266 assert(polygon.size() <= BLOCK_STATS_POLYGON_MAX_POINTS && ""Too many points. Unsupported polygon!"");267 std::string polygonDescription;268 for (auto position : polygon)269 {270 polygonDescription += ""("" + std::to_string(position.x) + "", "" + std::to_string(position.y) + "")--"";271 }272 dtrace<false>(k, ""BlockStat: POC %d @[%s] %s={%4d,%4d}\\n"", poc, polygonDescription.c_str(), stat_type.c_str(), val_x, val_y);273}274 275void retrieveTriangularMvInfo(const PredictionUnit& pu, MotionInfo& mi0, MotionInfo& mi1)276{277 int triangleDir = pu.triangleSplitDir;278 CMotionBuf mb = pu.getMotionBuf();279 bool foundMv[2] = { false, false };280 bool foundBi = false;281 int32_t idxW = (int32_t)(floorLog2(pu.lwidth() ) - MIN_CU_LOG2);282 int32_t idxH = (int32_t)(floorLog2(pu.lheight()) - MIN_CU_LOG2);283 for (int32_t y = 0; y < mb.height; y++)284 {285 for (int32_t x = 0; x < mb.width; x++)286 {287 if (g_triangleMvStorage[triangleDir][idxH][idxW][y][x] == 0 && foundMv[0] == false)288 {289 mi0.mv[0] = mb.at(x, y).mv[0];290 mi0.mv[1] = mb.at(x, y).mv[1];291 mi0.refIdx[0] = mb.at(x, y).refIdx[0];292 mi0.refIdx[1] = mb.at(x, y).refIdx[1];293 foundMv[0] = true;294 }295 if (g_triangleMvStorage[triangleDir][idxH][idxW][y][x] == 1 && foundMv[1] == false)296 {297 mi1.mv[0] = mb.at(x, y).mv[0];298 mi1.mv[1] = mb.at(x, y).mv[1];299 mi1.refIdx[0] = mb.at(x, y).refIdx[0];300 mi1.refIdx[1] = mb.at(x, y).refIdx[1];301 foundMv[1] = true;302 }303 if (g_triangleMvStorage[triangleDir][idxH][idxW][y][x] == 2 && foundMv[0] == false && foundMv[1] == false)304 {305 mi0.mv[0] = Mv(0, 0);306 mi0.mv[1] = Mv(0, 0);307 mi1.mv[0] = Mv(0, 0);308 mi1.mv[1] = Mv(0, 0);309 mi0.refIdx[0] = -1;310 mi0.refIdx[1] = -1;311 mi1.refIdx[0] = -1;312 mi1.refIdx[1] = -1;313 if (mb.at(x, y).interDir == 3)314 {315 mi0.mv[0] = mb.at(x, y).mv[0];316 mi1.mv[0] = mb.at(x, y).mv[1];317 mi0.refIdx[0] = mb.at(x, y).refIdx[0];318 mi1.refIdx[0] = mb.at(x, y).refIdx[1];319 foundBi = true;320 }321 }322 if ((foundMv[0] == true && foundMv[1] == true) || foundBi == true)323 return;324 }325 }326}327void retrieveTrianglePolygon(const PredictionUnit& pu, std::vector<Position>& triangle0, std::vector<Position>& triangle1, Position& S, Position& E)328{329 TriangleSplit triangleDir = TriangleSplit(pu.triangleSplitDir);330 Position TL = pu.Y().topLeft();331 Position TR = pu.Y().topRight(); TR = TR.offset(1, 0);332 Position BL = pu.Y().bottomLeft(); BL = BL.offset(0, 1);333 Position BR = pu.Y().bottomRight(); BR = BR.offset(1, 1);334 335 if (triangleDir == TRIANGLE_DIR_135)336 {337 S = Position(0, 0);338 E = Position(pu.Y().width, pu.Y().height);339 triangle0.push_back(TL);340 triangle0.push_back(TR);341 triangle0.push_back(BR);342 triangle1.push_back(TL);343 triangle1.push_back(BL);344 triangle1.push_back(BR);345 }346 else if (triangleDir == TRIANGLE_DIR_45)347 {348 S = Position(0, pu.Y().height);349 E = Position(pu.Y().width, 0);350 triangle0.push_back(TL);351 triangle0.push_back(TR);352 triangle0.push_back(BL);353 triangle1.push_back(TR);354 triangle1.push_back(BL);355 triangle1.push_back(BR);356 }357 else358 {359 CHECK(triangleDir != TRIANGLE_DIR_45 && triangleDir != TRIANGLE_DIR_135, ""Unknown triangle type"");360 }361}362 363void writeBlockStatisticsHeader(const SPS *sps)364{365 static bool has_header_been_written = false;366 if (has_header_been_written)367 {368 return;369 }370 371 // only write header when block statistics are used372 bool write_blockstatistics = g_trace_ctx->isChannelActive( D_BLOCK_STATISTICS_ALL) || g_trace_ctx->isChannelActive( D_BLOCK_STATISTICS_CODED);373 if(!write_blockstatistics)374 {375 return;376 }377 378 DTRACE_HEADER( g_trace_ctx, ""# VTMBMS Block Statistics\\n"");379 // sequence info380#if JVET_O1164_PS381 DTRACE_HEADER( g_trace_ctx, ""# Sequence size: [%dx %d]\\n"", sps->getMaxPicWidthInLumaSamples(), sps->getMaxPicHeightInLumaSamples() );382#else383 DTRACE_HEADER( g_trace_ctx, ""# Sequence size: [%dx %d]\\n"", sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples());384#endif385 // list statistics386 for( auto i = static_cast<int>(BlockStatistic::PredMode); i < static_cast<int>(BlockStatistic::NumBlockStatistics); i++)387 {388 BlockStatistic statistic = BlockStatistic(i);389 std::string statitic_name = GetBlockStatisticName(statistic);390 std::string statitic_type = GetBlockStatisticTypeString(statistic);391 std::string statitic_type_specific_info = GetBlockStatisticTypeSpecificInfo(statistic);392 DTRACE_HEADER( g_trace_ctx, ""# Block Statistic Type: %s; %s; %s\\n"", statitic_name.c_str(), statitic_type.c_str(), statitic_type_specific_info.c_str());393 }394 395 has_header_been_written = true;396}397 398void getAndStoreBlockStatistics(const CodingStructure& cs, const UnitArea& ctuArea)399{400 // two differemt behaviors, depending on which information is needed401 bool writeAll = g_trace_ctx->isChannelActive( D_BLOCK_STATISTICS_ALL);402 bool writeCoded = g_trace_ctx->isChannelActive( D_BLOCK_STATISTICS_CODED);403 404 CHECK(writeAll && writeCoded, ""Either used D_BLOCK_STATISTICS_ALL or D_BLOCK_STATISTICS_CODED. Not both at once!"")405 406 if (writeCoded)407 writeAllCodedData(cs, ctuArea); // this will write out important cu-based data, only if it is actually decoded and used408 else if (writeAll)409 writeAllData(cs, ctuArea); // this will write out all inter- or intra-prediction related data410}411 412void writeAllData(const CodingStructure& cs, const UnitArea& ctuArea)413{414 const int maxNumChannelType = cs.pcv->chrFormat != CHROMA_400 && CS::isDualITree( cs ) ? 2 : 1;415 const int nShift = MV_FRACTIONAL_BITS_DIFF;416 const int nOffset = 1 << (nShift - 1);417 for( int ch = 0; ch < maxNumChannelType; ch++ )418 {419 const ChannelType chType = ChannelType( ch );420 421 for( const CodingUnit &cu : cs.traverseCUs( CS::getArea( cs, ctuArea, chType ), chType ) )422 {423 if( chType == CHANNEL_TYPE_LUMA )424 {425 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::PredMode), cu.predMode);426 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::Depth), cu.depth);427 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::QT_Depth), cu.qtDepth);428 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::BT_Depth), cu.btDepth);429 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::MT_Depth), cu.mtDepth);430 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::ChromaQPAdj), cu.chromaQpAdj);431 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::QP), cu.qp);432 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::SplitSeries), (int)cu.splitSeries);433 434 if (cs.pps->getTransquantBypassEnabledFlag())435 {436 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::TransQuantBypassFlag), cu.transQuantBypass);437 }438 439 // skip flag440 if (!cs.slice->isIntra())441 {442 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::SkipFlag), cu.skip);443 }444 445 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::BDPCM), cu.bdpcmMode);446 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::TileIdx), cu.tileIdx);447 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::IndependentSliceIdx), cu.slice->getIndependentSliceIdx());448 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::LFNSTIdx), cu.lfnstIdx);449 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::MMVDSkipFlag), cu.mmvdSkip);450 }451 else if( chType == CHANNEL_TYPE_CHROMA )452 {453 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::Depth_Chroma), cu.depth);454 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::QT_Depth_Chroma), cu.qtDepth);455 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::BT_Depth_Chroma), cu.btDepth);456 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::MT_Depth_Chroma), cu.mtDepth);457 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::ChromaQPAdj_Chroma), cu.chromaQpAdj);458 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::QP_Chroma), cu.qp);459 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::SplitSeries_Chroma), (int)cu.splitSeries);460 461 if (cs.pps->getTransquantBypassEnabledFlag())462 {463 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::TransQuantBypassFlag_Chroma), cu.transQuantBypass);464 }465 466 }467 468 469 switch( cu.predMode )470 {471 case MODE_INTER:472 {473 for( const PredictionUnit &pu : CU::traversePUs( cu ) )474 {475 if (!pu.cu->skip)476 {477 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MergeFlag), pu.mergeFlag);478 }479 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::RegularMergeFlag), pu.regularMergeFlag);480 if( pu.mergeFlag )481 {482 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MergeIdx), pu.mergeIdx);483 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MergeType), pu.mergeType);484 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MMVDMergeFlag), pu.mmvdMergeFlag);485 if (cu.mmvdSkip || pu.mmvdMergeFlag)486 {487 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MMVDMergeIdx), pu.mmvdMergeIdx);488 }489 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MHIntraFlag), pu.mhIntraFlag);490 if (pu.mhIntraFlag)491 {492 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::Luma_IntraMode), pu.intraDir[COMPONENT_Y]);493 }494 }495 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::AffineFlag), pu.cu->affine);496 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::AffineType), pu.cu->affineType);497 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::InterDir), pu.interDir);498 499 if (pu.interDir != 2 /* PRED_L1 */)500 {501 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MVPIdxL0), pu.mvpIdx[REF_PIC_LIST_0]);502 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::RefIdxL0), pu.refIdx[REF_PIC_LIST_0]);503 }504 if (pu.interDir != 1 /* PRED_L1 */)505 {506 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MVPIdxL1), pu.mvpIdx[REF_PIC_LIST_1]);507 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::RefIdxL1), pu.refIdx[REF_PIC_LIST_1]);508 }509 if (!pu.cu->affine && !pu.cu->triangle)510 {511 if (pu.interDir != 2 /* PRED_L1 */)512 {513 Mv mv = pu.mv[REF_PIC_LIST_0];514 Mv mvd = pu.mvd[REF_PIC_LIST_0];515 mv.hor = mv.hor >= 0 ? (mv.hor + nOffset) >> nShift : -((-mv.hor + nOffset) >> nShift);516 mv.ver = mv.ver >= 0 ? (mv.ver + nOffset) >> nShift : -((-mv.ver + nOffset) >> nShift);517 mvd.hor = mvd.hor >= 0 ? (mvd.hor + nOffset) >> nShift : -((-mvd.hor + nOffset) >> nShift);518 mvd.ver = mvd.ver >= 0 ? (mvd.ver + nOffset) >> nShift : -((-mvd.ver + nOffset) >> nShift);519 DTRACE_BLOCK_VECTOR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MVDL0), mvd.hor, mvd.ver);520 DTRACE_BLOCK_VECTOR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MVL0), mv.hor, mv.ver);521 }522 if (pu.interDir != 1 /* PRED_L1 */)523 {524 Mv mv = pu.mv[REF_PIC_LIST_1];525 Mv mvd = pu.mvd[REF_PIC_LIST_1];526 mv.hor = mv.hor >= 0 ? (mv.hor + nOffset) >> nShift : -((-mv.hor + nOffset) >> nShift);527 mv.ver = mv.ver >= 0 ? (mv.ver + nOffset) >> nShift : -((-mv.ver + nOffset) >> nShift);528 mvd.hor = mvd.hor >= 0 ? (mvd.hor + nOffset) >> nShift : -((-mvd.hor + nOffset) >> nShift);529 mvd.ver = mvd.ver >= 0 ? (mvd.ver + nOffset) >> nShift : -((-mvd.ver + nOffset) >> nShift);530 DTRACE_BLOCK_VECTOR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MVDL1), mvd.hor, mvd.ver);531 DTRACE_BLOCK_VECTOR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MVL1), mv.hor, mv.ver);532 }533 }534 else if (pu.cu->triangle)535 {536 MotionInfo mi[2];537 std::vector<Position> triangleCorners[2];538 Position S, E;539 retrieveTrianglePolygon(pu, triangleCorners[0], triangleCorners[1], S, E);540 DTRACE_LINE(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::TrianglePartitioning), S.x, S.y, E.x, E.y);541 retrieveTriangularMvInfo(pu, mi[0], mi[1]);542 for (int triangleIdx = 0; triangleIdx < 2; triangleIdx++)543 {544 for (int refIdx = 0; refIdx < 2; refIdx++)545 {546 mi[triangleIdx].mv[refIdx].hor = mi[triangleIdx].mv[refIdx].hor >= 0 ? (mi[triangleIdx].mv[refIdx].hor + nOffset) >> nShift : -((-mi[triangleIdx].mv[refIdx].hor + nOffset) >> nShift);547 mi[triangleIdx].mv[refIdx].ver = mi[triangleIdx].mv[refIdx].ver >= 0 ? (mi[triangleIdx].mv[refIdx].ver + nOffset) >> nShift : -((-mi[triangleIdx].mv[refIdx].ver + nOffset) >> nShift);548 if (mi[triangleIdx].refIdx[refIdx] != -1)549 {550 DTRACE_POLYGON_VECTOR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu.cu->slice->getPOC(), triangleCorners[triangleIdx], GetBlockStatisticName(refIdx==0?BlockStatistic::TriangleMVL0:BlockStatistic::TriangleMVL1), mi[triangleIdx].mv[refIdx].hor, mi[triangleIdx].mv[refIdx].ver);551 }552 }553 }554 }555 else556 {557 if (pu.interDir != 2 /* PRED_L1 */)558 {559 Mv mv[3];560 const CMotionBuf &mb = pu.getMotionBuf();561 mv[0] = mb.at(0, 0).mv[REF_PIC_LIST_0];562 mv[1] = mb.at(mb.width - 1, 0).mv[REF_PIC_LIST_0];563 mv[2] = mb.at(0, mb.height - 1).mv[REF_PIC_LIST_0];564 // motion vectors should use low precision or they will appear to large565 mv[0].hor = mv[0].hor >= 0 ? (mv[0].hor + nOffset) >> nShift : -((-mv[0].hor + nOffset) >> nShift);566 mv[0].ver = mv[0].ver >= 0 ? (mv[0].ver + nOffset) >> nShift : -((-mv[0].ver + nOffset) >> nShift);567 mv[1].hor = mv[1].hor >= 0 ? (mv[1].hor + nOffset) >> nShift : -((-mv[1].hor + nOffset) >> nShift);568 mv[1].ver = mv[1].ver >= 0 ? (mv[1].ver + nOffset) >> nShift : -((-mv[1].ver + nOffset) >> nShift);569 mv[2].hor = mv[2].hor >= 0 ? (mv[2].hor + nOffset) >> nShift : -((-mv[2].hor + nOffset) >> nShift);570 mv[2].ver = mv[2].ver >= 0 ? (mv[2].ver + nOffset) >> nShift : -((-mv[2].ver + nOffset) >> nShift);571 DTRACE_BLOCK_AFFINETF(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::AffineMVL0), mv[0].hor, mv[0].ver, mv[1].hor, mv[1].ver, mv[2].hor, mv[2].ver);572 }573 if (pu.interDir != 1 /* PRED_L1 */)574 {575 Mv mv[3];576 const CMotionBuf &mb = pu.getMotionBuf();577 mv[0] = mb.at(0, 0).mv[REF_PIC_LIST_1];578 mv[1] = mb.at(mb.width - 1, 0).mv[REF_PIC_LIST_1];579 mv[2] = mb.at(0, mb.height - 1).mv[REF_PIC_LIST_1];580 // motion vectors should use low precision or they will appear to large581 mv[0].hor = mv[0].hor >= 0 ? (mv[0].hor + nOffset) >> nShift : -((-mv[0].hor + nOffset) >> nShift);582 mv[0].ver = mv[0].ver >= 0 ? (mv[0].ver + nOffset) >> nShift : -((-mv[0].ver + nOffset) >> nShift);583 mv[1].hor = mv[1].hor >= 0 ? (mv[1].hor + nOffset) >> nShift : -((-mv[1].hor + nOffset) >> nShift);584 mv[1].ver = mv[1].ver >= 0 ? (mv[1].ver + nOffset) >> nShift : -((-mv[1].ver + nOffset) >> nShift);585 mv[2].hor = mv[2].hor >= 0 ? (mv[2].hor + nOffset) >> nShift : -((-mv[2].hor + nOffset) >> nShift);586 mv[2].ver = mv[2].ver >= 0 ? (mv[2].ver + nOffset) >> nShift : -((-mv[2].ver + nOffset) >> nShift);587 DTRACE_BLOCK_AFFINETF(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::AffineMVL1), mv[0].hor, mv[0].ver, mv[1].hor, mv[1].ver, mv[2].hor, mv[2].ver);588 }589 }590 591 // tracing Motion buffers592 CMotionBuf mb = pu.getMotionBuf();593 // todo: assuming granulatiry == 4. can it be derived?594 for( int y = 0; y < mb.height; y++ )595 {596 for( int x = 0; x < mb.width; x++ )597 {598 const MotionInfo &pixMi = mb.at( x, y );599 600 if( pixMi.interDir == 1)601 {602 const Mv mv = pixMi.mv[REF_PIC_LIST_0];603 g_trace_ctx->dtrace<false>(604 D_BLOCK_STATISTICS_ALL,605 ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s={%4d,%4d}\\n"",606 cs.picture->poc,607 pu.lx() + 4*x,608 pu.ly() + 4*y,609 4,610 4,611 GetBlockStatisticName(BlockStatistic::MotionBufL0).c_str(),612 mv.hor,613 mv.ver);614 }615 else if( pixMi.interDir == 2)616 {617 const Mv mv = pixMi.mv[REF_PIC_LIST_1];618 g_trace_ctx->dtrace<false>(619 D_BLOCK_STATISTICS_ALL,620 ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s={%4d,%4d}\\n"",621 cs.picture->poc,622 pu.lx() + 4*x,623 pu.ly() + 4*y,624 4,625 4,626 GetBlockStatisticName(BlockStatistic::MotionBufL1).c_str(),627 mv.hor,628 mv.ver);629 }630 else if( pixMi.interDir == 3)631 {632 {633 const Mv mv = pixMi.mv[REF_PIC_LIST_0];634 g_trace_ctx->dtrace<false>(635 D_BLOCK_STATISTICS_ALL,636 ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s={%4d,%4d}\\n"",637 cs.picture->poc,638 pu.lx() + 4*x,639 pu.ly() + 4*y,640 4,641 4,642 GetBlockStatisticName(BlockStatistic::MotionBufL0).c_str(),643 mv.hor,644 mv.ver);645 }646 {647 const Mv mv = pixMi.mv[REF_PIC_LIST_1];648 g_trace_ctx->dtrace<false>(649 D_BLOCK_STATISTICS_ALL,650 ""BlockStat: POC %d @(%4d,%4d) [%2dx%2d] %s={%4d,%4d}\\n"",651 cs.picture->poc,652 pu.lx() + 4*x,653 pu.ly() + 4*y,654 4,655 4,656 GetBlockStatisticName(BlockStatistic::MotionBufL1).c_str(),657 mv.hor,658 mv.ver);659 }660 }661 662 }663 }664 665 666 667 668 }669 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::SMVDFlag), cu.smvdMode);670 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::IMVMode), cu.imv);671 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::RootCbf), cu.rootCbf);672 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::GBIIndex), cu.GBiIdx);673 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::SbtIdx), cu.getSbtIdx());674 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::SbtPos), cu.getSbtPos());675 }676 break;677 case MODE_INTRA:678 {679 if(chType == CHANNEL_TYPE_LUMA)680 {681#if !JVET_O0525_REMOVE_PCM682 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::IPCM), cu.ipcm);683#endif684 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::MIPFlag), cu.mipFlag);685 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::ISPMode), cu.ispMode);686 }687#if !JVET_O0525_REMOVE_PCM688 else if(chType == CHANNEL_TYPE_CHROMA)689 {690 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::IPCM_Chroma), cu.ipcm);691 }692#endif693 694 const uint32_t numChType = ::getNumberValidChannels( cu.chromaFormat );695 696 for( uint32_t chType = CHANNEL_TYPE_LUMA; chType < numChType; chType++ )697 {698 if( cu.blocks[chType].valid() )699 {700 for( const PredictionUnit &pu : CU::traversePUs( cu ) )701 {702 if( isLuma( ChannelType( chType ) ) )703 {704 const uint32_t uiChFinalMode = PU::getFinalIntraMode( pu, ChannelType( chType ) );705 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::Luma_IntraMode), uiChFinalMode);706 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::MultiRefIdx), pu.multiRefIdx);707 }708 else709 {710 const uint32_t uiChFinalMode = PU::getFinalIntraMode( pu, ChannelType( chType ) );711 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_ALL, pu, GetBlockStatisticName(BlockStatistic::Chroma_IntraMode), uiChFinalMode);712 assert(0);713 }714 }715 }716 }717 }718 break;719 default:720 THROW( ""Invalid prediction mode"" );721 break;722 }723 724 for (const TransformUnit &tu : CU::traverseTUs(cu))725 {726 if (tu.Y().valid())727 {728 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, tu, GetBlockStatisticName(BlockStatistic::Cbf_Y), tu.cbf[COMPONENT_Y]);729 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, tu, GetBlockStatisticName(BlockStatistic::MTSIdx), tu.mtsIdx);730 }731 if ( tu.Cb().valid() )732 {733 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, tu, GetBlockStatisticName(BlockStatistic::JointCbCr), tu.jointCbCr);734 }735 736 if( !CU::isIntra(cu) && CU::isRDPCMEnabled(cu) && ( tu.mtsIdx==MTS_SKIP || cu.transQuantBypass ) )737 {738 if (tu.Y().valid())739 {740 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, tu, GetBlockStatisticName(BlockStatistic::RDPCM_Y), tu.rdpcm[COMPONENT_Y]);741 }742 if (tu.Cb().valid())743 {744 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, tu, GetBlockStatisticName(BlockStatistic::RDPCM_Cb), tu.rdpcm[COMPONENT_Cb]);745 }746 if (tu.Cr().valid())747 {748 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, tu, GetBlockStatisticName(BlockStatistic::RDPCM_Cr), tu.rdpcm[COMPONENT_Cr]);749 }750 }751 752 bool lumaOnly = ( cu.chromaFormat == CHROMA_400 || !tu.blocks[COMPONENT_Cb].valid() );753 if( !lumaOnly )754 {755 if( TU::hasCrossCompPredInfo( tu, COMPONENT_Cb ) )756 {757 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, tu, GetBlockStatisticName(BlockStatistic::CompAlphaCb), tu.compAlpha[COMPONENT_Cb] );758 }759 if( TU::hasCrossCompPredInfo( tu, COMPONENT_Cr ) )760 {761 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, tu, GetBlockStatisticName(BlockStatistic::CompAlphaCr), tu.compAlpha[COMPONENT_Cr] );762 }763 }764 765#if JVET_O0050_LOCAL_DUAL_TREE766 if( !(cu.chromaFormat == CHROMA_400 || (cu.isSepTree() && cu.chType == CHANNEL_TYPE_LUMA)) )767#else768 if (!(cu.chromaFormat == CHROMA_400 || (CS::isDualITree(*cu.cs) && cu.chType == CHANNEL_TYPE_LUMA)))769#endif770 {771 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_ALL, tu, GetBlockStatisticName(BlockStatistic::Cbf_Cb), tu.cbf[COMPONENT_Cb]);772 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_ALL, tu, GetBlockStatisticName(BlockStatistic::Cbf_Cr), tu.cbf[COMPONENT_Cr]);773 }774 }775 }776 }777}778 779void writeAllCodedData(const CodingStructure & cs, const UnitArea & ctuArea)780{781 const int nShift = MV_FRACTIONAL_BITS_DIFF;782 const int nOffset = 1 << (nShift - 1);783 const int maxNumChannelType = cs.pcv->chrFormat != CHROMA_400 && CS::isDualITree(cs) ? 2 : 1;784 785 for (int ch = 0; ch < maxNumChannelType; ch++)786 {787 const ChannelType chType = ChannelType(ch);788#if !JVET_O0525_REMOVE_PCM789 const SPS& sps = *cs.sps;790#endif791 792 for (const CodingUnit &cu : cs.traverseCUs(CS::getArea(cs, ctuArea, chType), chType))793 {794 if( chType == CHANNEL_TYPE_LUMA )795 {796 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::Depth), cu.depth);797 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::QT_Depth), cu.qtDepth);798 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::BT_Depth), cu.btDepth);799 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::MT_Depth), cu.mtDepth);800 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::ChromaQPAdj), cu.chromaQpAdj);801 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::QP), cu.qp);802 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::SplitSeries), (int)cu.splitSeries);803 // transquant bypass flag804 if (cs.pps->getTransquantBypassEnabledFlag())805 {806 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::TransQuantBypassFlag), cu.transQuantBypass);807 }808 // skip flag809 if (!cs.slice->isIntra() && cu.Y().valid())810 {811 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::SkipFlag), cu.skip);812 if (cu.skip)813 {814 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::MMVDSkipFlag), cu.mmvdSkip);815 }816 }817 818 // prediction mode and partitioning data819 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::PredMode), cu.predMode);820 821#if !JVET_O0525_REMOVE_PCM822 if (CU::isIntra(cu))823 {824 if (!(!sps.getPCMEnabledFlag() || cu.lumaSize().width > (1 << sps.getPCMLog2MaxSize()) || cu.lumaSize().width < (1 << sps.getPCMLog2MinSize())))825 {826 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::IPCM), cu.ipcm);827 }828 }829#endif830 }831 else if (chType == CHANNEL_TYPE_CHROMA )832 {833 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::Depth_Chroma), cu.depth);834 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::QT_Depth_Chroma), cu.qtDepth);835 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::BT_Depth_Chroma), cu.btDepth);836 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::MT_Depth_Chroma), cu.mtDepth);837 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::ChromaQPAdj_Chroma), cu.chromaQpAdj);838 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::QP_Chroma), cu.qp);839 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::SplitSeries_Chroma), (int)cu.splitSeries);840 // transquant bypass flag841 if (cs.pps->getTransquantBypassEnabledFlag())842 {843 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::TransQuantBypassFlag_Chroma), cu.transQuantBypass);844 }845 846#if !JVET_O0525_REMOVE_PCM847 if (CU::isIntra(cu))848 {849 if (!(!sps.getPCMEnabledFlag() || cu.lumaSize().width > (1 << sps.getPCMLog2MaxSize()) || cu.lumaSize().width < (1 << sps.getPCMLog2MinSize())))850 {851 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::IPCM_Chroma), cu.ipcm);852 }853 }854#endif855 }856 857 for (const PredictionUnit &pu : CU::traversePUs(cu))858 {859 switch (pu.cu->predMode)860 {861 case MODE_INTRA:862 {863 if (pu.Y().valid())864 {865 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::Luma_IntraMode), PU::getFinalIntraMode(pu, ChannelType(chType)));866 }867#if JVET_O0050_LOCAL_DUAL_TREE868 if (!(pu.chromaFormat == CHROMA_400 || (pu.cu->isSepTree() && pu.chType == CHANNEL_TYPE_LUMA)))869#else870 if (!(pu.chromaFormat == CHROMA_400 || (CS::isDualITree(*pu.cs) && pu.chType == CHANNEL_TYPE_LUMA)))871#endif872 {873 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::Chroma_IntraMode), PU::getFinalIntraMode(pu, CHANNEL_TYPE_CHROMA));874 }875 if (cu.Y().valid() && isLuma(cu.chType))876 {877 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MultiRefIdx), pu.multiRefIdx);878 }879 break;880 }881 case MODE_INTER:882 {883 if (!pu.cu->skip)884 {885 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MergeFlag), pu.mergeFlag);886 }887 if (pu.mergeFlag)888 {889 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MergeIdx), pu.mergeIdx);890 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MergeType), pu.mergeType);891 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MMVDMergeFlag), pu.mmvdMergeFlag);892 if (pu.mmvdMergeFlag)893 {894 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MMVDMergeIdx), pu.mmvdMergeIdx);895 }896 if (!cu.cs->slice->isIntra() && cu.cs->sps->getUseAffine() && cu.lumaSize().width >= 8 && cu.lumaSize().height >= 8897 && !pu.mmvdMergeFlag && !cu.mmvdSkip898 )899 {900 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::AffineFlag), pu.cu->affine);901 }902 if (pu.cs->sps->getUseMHIntra() && !pu.cu->skip && !pu.cu->affine && !(pu.cu->lwidth() * pu.cu->lheight() < 64 || pu.cu->lwidth() >= MAX_CU_SIZE || pu.cu->lheight() >= MAX_CU_SIZE)903 && !pu.mmvdMergeFlag904 )905 {906 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MHIntraFlag), pu.mhIntraFlag);907 if (pu.mhIntraFlag)908 {909 if (cu.Y().valid())910 {911 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::Luma_IntraMode), pu.intraDir[0]);912 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::Chroma_IntraMode), pu.intraDir[1]);913 }914 }915 }916 }917 else918 {919 if (!pu.cs->slice->isInterP())920 {921 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::InterDir), pu.interDir);922 }923 if (!cu.cs->slice->isIntra() && cu.cs->sps->getUseAffine() && cu.lumaSize().width > 8 && cu.lumaSize().height > 8)924 {925 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::AffineFlag), pu.cu->affine);926 if (cu.affine && !cu.firstPU->mergeFlag && cu.cs->sps->getUseAffineType())927 {928 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::AffineType), pu.cu->affineType);929 }930 }931 }932 if (pu.interDir != 2 /* PRED_L1 */)933 {934 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MVPIdxL0), pu.mvpIdx[REF_PIC_LIST_0]);935 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::RefIdxL0), pu.refIdx[REF_PIC_LIST_0]);936 }937 if (pu.interDir != 1 /* PRED_L1 */)938 {939 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MVPIdxL1), pu.mvpIdx[REF_PIC_LIST_1]);940 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::RefIdxL1), pu.refIdx[REF_PIC_LIST_1]);941 }942 if (!pu.cu->affine && !pu.cu->triangle)943 {944 if (pu.interDir != 2 /* PRED_L1 */)945 {946 Mv mv = pu.mv[REF_PIC_LIST_0];947 Mv mvd = pu.mvd[REF_PIC_LIST_0];948 mv.hor = mv.hor >= 0 ? (mv.hor + nOffset) >> nShift : -((-mv.hor + nOffset) >> nShift);949 mv.ver = mv.ver >= 0 ? (mv.ver + nOffset) >> nShift : -((-mv.ver + nOffset) >> nShift);950 mvd.hor = mvd.hor >= 0 ? (mvd.hor + nOffset) >> nShift : -((-mvd.hor + nOffset) >> nShift);951 mvd.ver = mvd.ver >= 0 ? (mvd.ver + nOffset) >> nShift : -((-mvd.ver + nOffset) >> nShift);952 DTRACE_BLOCK_VECTOR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MVDL0), mvd.hor, mvd.ver);953 DTRACE_BLOCK_VECTOR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MVL0), mv.hor, mv.ver);954 }955 if (pu.interDir != 1 /* PRED_L1 */)956 {957 Mv mv = pu.mv[REF_PIC_LIST_1];958 Mv mvd = pu.mvd[REF_PIC_LIST_1];959 mv.hor = mv.hor >= 0 ? (mv.hor + nOffset) >> nShift : -((-mv.hor + nOffset) >> nShift);960 mv.ver = mv.ver >= 0 ? (mv.ver + nOffset) >> nShift : -((-mv.ver + nOffset) >> nShift);961 mvd.hor = mvd.hor >= 0 ? (mvd.hor + nOffset) >> nShift : -((-mvd.hor + nOffset) >> nShift);962 mvd.ver = mvd.ver >= 0 ? (mvd.ver + nOffset) >> nShift : -((-mvd.ver + nOffset) >> nShift);963 DTRACE_BLOCK_VECTOR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MVDL1), mvd.hor, mvd.ver);964 DTRACE_BLOCK_VECTOR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::MVL1), mv.hor, mv.ver);965 }966 }967 else if (pu.cu->triangle)968 {969 MotionInfo mi[2];970 std::vector<Position> triangleCorners[2];971 Position S, E;972 retrieveTrianglePolygon(pu, triangleCorners[0], triangleCorners[1], S, E);973 DTRACE_LINE(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::TrianglePartitioning), S.x, S.y, E.x, E.y);974 retrieveTriangularMvInfo(pu, mi[0], mi[1]);975 for (int triangleIdx = 0; triangleIdx < 2; triangleIdx++)976 {977 for (int refIdx = 0; refIdx < 2; refIdx++)978 {979 mi[triangleIdx].mv[refIdx].hor = mi[triangleIdx].mv[refIdx].hor >= 0 ? (mi[triangleIdx].mv[refIdx].hor + nOffset) >> nShift : -((-mi[triangleIdx].mv[refIdx].hor + nOffset) >> nShift);980 mi[triangleIdx].mv[refIdx].ver = mi[triangleIdx].mv[refIdx].ver >= 0 ? (mi[triangleIdx].mv[refIdx].ver + nOffset) >> nShift : -((-mi[triangleIdx].mv[refIdx].ver + nOffset) >> nShift);981 if (mi[triangleIdx].refIdx[refIdx] != -1)982 {983 DTRACE_POLYGON_VECTOR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu.cu->slice->getPOC(), triangleCorners[triangleIdx], GetBlockStatisticName(refIdx==0?BlockStatistic::TriangleMVL0:BlockStatistic::TriangleMVL1), mi[triangleIdx].mv[refIdx].hor, mi[triangleIdx].mv[refIdx].ver);984 }985 }986 }987 }988 else989 {990 if (pu.interDir != 2 /* PRED_L1 */)991 {992 Mv mv[3];993 const CMotionBuf &mb = pu.getMotionBuf();994 mv[0] = mb.at(0, 0).mv[REF_PIC_LIST_0];995 mv[1] = mb.at(mb.width - 1, 0).mv[REF_PIC_LIST_0];996 mv[2] = mb.at(0, mb.height - 1).mv[REF_PIC_LIST_0];997 // motion vectors should use low precision or they will appear to large998 mv[0].hor = mv[0].hor >= 0 ? (mv[0].hor + nOffset) >> nShift : -((-mv[0].hor + nOffset) >> nShift);999 mv[0].ver = mv[0].ver >= 0 ? (mv[0].ver + nOffset) >> nShift : -((-mv[0].ver + nOffset) >> nShift);1000 mv[1].hor = mv[1].hor >= 0 ? (mv[1].hor + nOffset) >> nShift : -((-mv[1].hor + nOffset) >> nShift);1001 mv[1].ver = mv[1].ver >= 0 ? (mv[1].ver + nOffset) >> nShift : -((-mv[1].ver + nOffset) >> nShift);1002 mv[2].hor = mv[2].hor >= 0 ? (mv[2].hor + nOffset) >> nShift : -((-mv[2].hor + nOffset) >> nShift);1003 mv[2].ver = mv[2].ver >= 0 ? (mv[2].ver + nOffset) >> nShift : -((-mv[2].ver + nOffset) >> nShift);1004 DTRACE_BLOCK_AFFINETF(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::AffineMVL0), mv[0].hor, mv[0].ver, mv[1].hor, mv[1].ver, mv[2].hor, mv[2].ver);1005 }1006 if (pu.interDir != 1 /* PRED_L1 */)1007 {1008 Mv mv[3];1009 const CMotionBuf &mb = pu.getMotionBuf();1010 mv[0] = mb.at(0, 0).mv[REF_PIC_LIST_1];1011 mv[1] = mb.at(mb.width - 1, 0).mv[REF_PIC_LIST_1];1012 mv[2] = mb.at(0, mb.height - 1).mv[REF_PIC_LIST_1];1013 // motion vectors should use low precision or they will appear to large1014 mv[0].hor = mv[0].hor >= 0 ? (mv[0].hor + nOffset) >> nShift : -((-mv[0].hor + nOffset) >> nShift);1015 mv[0].ver = mv[0].ver >= 0 ? (mv[0].ver + nOffset) >> nShift : -((-mv[0].ver + nOffset) >> nShift);1016 mv[1].hor = mv[1].hor >= 0 ? (mv[1].hor + nOffset) >> nShift : -((-mv[1].hor + nOffset) >> nShift);1017 mv[1].ver = mv[1].ver >= 0 ? (mv[1].ver + nOffset) >> nShift : -((-mv[1].ver + nOffset) >> nShift);1018 mv[2].hor = mv[2].hor >= 0 ? (mv[2].hor + nOffset) >> nShift : -((-mv[2].hor + nOffset) >> nShift);1019 mv[2].ver = mv[2].ver >= 0 ? (mv[2].ver + nOffset) >> nShift : -((-mv[2].ver + nOffset) >> nShift);1020 DTRACE_BLOCK_AFFINETF(g_trace_ctx, D_BLOCK_STATISTICS_CODED, pu, GetBlockStatisticName(BlockStatistic::AffineMVL1), mv[0].hor, mv[0].ver, mv[1].hor, mv[1].ver, mv[2].hor, mv[2].ver);1021 }1022 }1023 if (cu.cs->sps->getAMVREnabledFlag() && CU::hasSubCUNonZeroMVd(cu))1024 {1025 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::IMVMode), cu.imv);1026 }1027 if (CU::isGBiIdxCoded(cu))1028 {1029 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_ALL, cu, GetBlockStatisticName(BlockStatistic::GBIIndex), cu.GBiIdx);1030 }1031 break;1032 }1033 default:1034 {1035 CHECK(1, ""Invalid prediction mode"");1036 break;1037 }1038 }1039 } // end pu1040 if (CU::isInter(cu))1041 {1042 const PredictionUnit &pu = *cu.firstPU;1043 if ( !pu.mergeFlag )1044 {1045 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, cu, GetBlockStatisticName(BlockStatistic::RootCbf), cu.rootCbf);1046 }1047 }1048 if (cu.rootCbf || CU::isIntra(cu))1049 {1050 for (const TransformUnit &tu : CU::traverseTUs(cu))1051 {1052 if (tu.Y().valid())1053 {1054 DTRACE_BLOCK_SCALAR(g_trace_ctx, D_BLOCK_STATISTICS_CODED, tu, GetBlockStatisticName(BlockStatistic::Cbf_Y), tu.cbf[COMPONENT_Y]);1055 DTRACE_BLOCK_SCALAR( g_trace_ctx, D_BLOCK_STATISTICS_CODED, tu, GetBlockStatisticName( BlockStatistic::MTSIdx ), tu.mtsIdx );1056 }1057#if JVET_O0050_LOCAL_DUAL_TREE1058 if (!(cu.chromaFormat == CHROMA_400 || (cu.isSepTree() && cu.chType == CHANNEL_TYPE_LUMA)))1059#else1060 if (!(cu.chromaFormat == CHROMA_400 || (CS::isDualITree(*cu.cs) && cu.chType == CHANNEL_TYPE_LUMA)))1061#endif1062 {1063 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_CODED, tu, GetBlockStatisticName(BlockStatistic::Cbf_Cb), tu.cbf[COMPONENT_Cb]);1064 DTRACE_BLOCK_SCALAR_CHROMA(g_trace_ctx, D_BLOCK_STATISTICS_CODED, tu, GetBlockStatisticName(BlockStatistic::Cbf_Cr), tu.cbf[COMPONENT_Cr]);1065 }1066 }1067 }1068 }1069 }1070}1071#endif1072",16252,True,3266.1720085191664,median1073"/* PS2X Brute Force Hexapod1074//-------1---------2---------3---------4---------5---------6---------7--1075// WARNING: declaration int i, j, or k must always be local scope because they are used in various places1076v01 ?/?/? by Bill Porter1077 PS2X_Example from GitHub1078v02 07/19/15 by Ari McEntire1079 Brute force forward, reverse, ccw, cw controlled by PS2 remote1080v03 07/19/15 by Ari McEntire 1081 changed to L analog joystick, no blend, must be at maximums to work. 1082 Verified all 4 motions. Added check at begin of moveHex to see if no motion commanded.1083 Improvement: spins fall on belly but do spin, torque of rotation may be pulling arms outward1084 recovers when walking forward or backward1085v04 07/20/15 by Ari McEntire1086 fixed issue from v03 by removing return from default statement1087 added speed value to call motion with - to be used for robot speed control1088 added global cornerAdd values to all corner angles to compensate for mid larger step1089 adjusted delay timings1090 added function to lower & raise body ""Bang, your dead""1091 ToDo: modify copy of neutral position array on the fly with input & still walk from there1092v06 07/20/15 by Ari McEntire1093 added slow lower1094 bug: slow raise is super fast.1095 BUG: big bug: became worse, caused all buttons to be read. Also some feedback causing receibver to be powered w/o Vcc1096 bug repeated with new receiver, Wayne's Arduino & shield/receiver, Eric's transmitter1097v10 07/22/15 by Ari McEntire1098 re-ported to PS2X_Example as base program & error rate reduced from 1 per 1-5 sec to 1 per 1-10 minutes1099 filtered out comm error (do not continue loop)1100 removed 2nd baud rate & changed baud rate to 96001101 updates & confirmed working: walk forward/backward, spin L/R, raise/lower fast, raise/lower slow, rumble1102v11 07/22/15 by Ari McEntire1103 added jaw definition & moves1104v12 07/22/15 by Nathan Hogge1105 added moveNeutralPosition function (with wiggle option)1106 added wave function (makes the robot lift its front right leg and waves)1107 bind moveNeutralPosition to CIRCLE1108 bind wave to SQUARE1109 add elses so that two robot actions do not occur in same loop (will enforce button prioirity)1110v13 07/22/15 by Ari McEntire 1111 corrected jaw definitions1112 added function tap() to TRIANGLE1113v14 07/23/15 by Ari McEntire1114 added loop around ps2x call1115v15 07/24/15 by Nathan Hogge1116 add button logging1117 added more communication bug blocking1118 put each action into a function1119v16 07/25/15 by Ari McEntire1120 added counter for loops since last bug screened1121 measure milliseconds per loop & print - can be annoying (note: loop time is affected by the baud rate)1122 cleaned up some move actions ( moved delays at end of move groups that can happen all at once )1123 todo wishlist: walk gait: lower leg neutral position, leg down dif than up delay, move delays to actual moves1124*/1125#include <PS2X_lib.h> //for v1.61126#include <Servo.h> // servo library1127 1128/******************************************************************1129 * set pins connected to PS2 controller:1130 * - 1e column: original 1131 * - 2e colmun: Stef?1132 * replace pin numbers by the ones you use1133 ******************************************************************/1134#define PS2_DAT 12 //14 1135#define PS2_CMD 11 //151136#define PS2_SEL 10 //161137#define PS2_CLK 9 //171138 1139/******************************************************************1140 * select modes of PS2 controller:1141 * - pressures = analog reading of push-butttons 1142 * - rumble = motor rumbling1143 * uncomment 1 of the lines for each mode selection1144 ******************************************************************/1145//#define pressures true1146#define pressures false1147#define rumble true1148//#define rumble false1149 1150PS2X ps2x; // create PS2 Controller Class1151 1152//right now, the library does NOT support hot pluggable controllers, meaning 1153//you must always either restart your Arduino after you connect the controller, 1154//or call config_gamepad(pins) again after connecting the controller.1155 1156int error = 0;1157byte type = 0;1158byte vibrate = 0;1159 1160/*************************************************************************************************1161SERVO Initializations1162******************************************************************************************/1163// Initialize Global Variables1164int pLed = 13; // LED pin1165Servo servo[3][2][3]; // servo control object, Arms1166Servo jaw; // servo control object, jaw1167 1168// array of 12 servos for 3 joints on 6 arms1169// initialize servo array indexes1170int frt = 0; // front row, head end1171int mid = 1; // middle row1172int bck = 2; // back row, tail end1173//----------1174int lft = 0; // left side, as viewed from above1175int rgt = 1; // right side, as viewed from above1176//----------1177int sdr = 0; // shoulder joint1178int elb = 1; // elbow joint1179int rst = 2; // wrist joint (if installed)1180/********************************************************************************************************1181******* Determine zero position joint values ***********************************************************1182 \\ / While robot is on its back, find joint angles that straighten 1183 /Head \\ all the leg joints like so: 1184 ---I---o o---I--- -Shoulder: all legs parallel like painting to the left,1185 ---I---o o---I--- -Elbow: parallel with table or floor (while on, pull toward floor)1186 ---I---o Tail o---I--- 1187 \\ / 1188 V1189 Coordinates for robot when resting on belly: 1190 Y1191 |1192 o-> X Z is up1193*/1194// Zero Point Array & JawMinMax for initial calibration - must match the robot1195// ****************** Ari's Robot array *************************1196const int zpa[3][2][3] = { // zero values array (for common reference from robot to robot)1197 {{56, 60, 70}, {117, 55, 50}}, // Front L & R values for sdr,elb,rst1198 {{80, 80, 70}, {88, 60, 55}}, // Middle L & R values for sdr,elb,rst1199 {{115, 35, 70}, {62, 60, 65}} // Back L & R values for sdr,elb,rst1200 };