Skip to content

Commit

Permalink
Merge pull request #565 from IENT/bugfix/multiviewHEVCParsing
Browse files Browse the repository at this point in the history
Add support and fix multiview HEVC parsing
  • Loading branch information
ChristianFeldmann authored Feb 25, 2024
2 parents e9240e7 + 97a4af5 commit 50e6941
Show file tree
Hide file tree
Showing 51 changed files with 3,150 additions and 119 deletions.
4 changes: 4 additions & 0 deletions YUViewLib/src/common/Typedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ typedef QPair<unsigned int, unsigned int> QUIntPair;
template <typename T> using umap_1d = std::map<unsigned, T>;
template <typename T> using umap_2d = std::map<unsigned, umap_1d<T>>;
template <typename T> using umap_3d = std::map<unsigned, umap_2d<T>>;
template <typename T> using umap_4d = std::map<unsigned, umap_3d<T>>;
template <typename T> using umap_5d = std::map<unsigned, umap_4d<T>>;

template <typename T> using vector = std::vector<T>;
template <typename T> using vector2d = std::vector<vector<T>>;
Expand All @@ -226,6 +228,8 @@ template <typename T> using vector4d = std::vector<vector3d<T>>;

template <typename T, size_t N> using array = std::array<T, N>;
template <typename T, size_t N1, size_t N2> using array2d = std::array<std::array<T, N2>, N1>;
template <typename T, size_t N1, size_t N2, size_t N3>
using array3d = std::array<std::array<std::array<T, N3>, N2>, N1>;

template <typename T> int indexInVec(const std::vector<T> &vec, const T &item)
{
Expand Down
6 changes: 4 additions & 2 deletions YUViewLib/src/parser/AVC/ParserAnnexBAVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ ParserAnnexBAVC::parseAndAddNALUnit(int
// Save the info of the last frame
if (!this->addFrameToList(*this->curFrameData->poc,
this->curFrameData->fileStartEndPos,
this->curFrameData->isRandomAccess))
this->curFrameData->isRandomAccess,
0))
{
if (parent)
parent->createChildItem("Error - POC " + std::to_string(*this->curFrameData->poc) +
Expand Down Expand Up @@ -481,7 +482,8 @@ ParserAnnexBAVC::parseAndAddNALUnit(int
// Save the info of the last frame
if (!this->addFrameToList(*this->curFrameData->poc,
this->curFrameData->fileStartEndPos,
this->curFrameData->isRandomAccess))
this->curFrameData->isRandomAccess,
0))
{
throw std::logic_error("Error - POC " + std::to_string(*this->curFrameData->poc) +
" already in the POC list");
Expand Down
120 changes: 120 additions & 0 deletions YUViewLib/src/parser/HEVC/Extensions/colour_mapping_octants.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/* This file is part of YUView - The YUV player with advanced analytics toolset
* <https://github.com/IENT/YUView>
* Copyright (C) 2015 Institut f�r Nachrichtentechnik, RWTH Aachen University, GERMANY
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*
* You must obey the GNU General Public License in all respects for all
* of the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version. If you delete
* this exception statement from all source files in the program, then
* also delete it here.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "colour_mapping_octants.h"

#include <parser/common/Functions.h>

namespace parser::hevc
{

using namespace reader;

void colour_mapping_octants::parse(SubByteReaderLogging &reader,
const unsigned cm_octant_depth,
const unsigned cm_y_part_num_log2,
const unsigned CMResLSBits,
const unsigned inpDepth,
const unsigned idxY,
const unsigned idxCb,
const unsigned idxCr,
const unsigned inpLength)
{
std::string subLevelName = "colour_mapping_octants(";
subLevelName += "inpDepth=" + std::to_string(inpDepth);
subLevelName += ", idxY=" + std::to_string(idxY);
subLevelName += ", idxCb=" + std::to_string(idxCb);
subLevelName += ", idxCr=" + std::to_string(idxCr);
subLevelName += ", inpLength=" + std::to_string(inpLength);
subLevelName += ")";

SubByteReaderLoggingSubLevel subLevel(reader, subLevelName);

// F.7.4.3.3.5 (F-43)
const auto PartNumY = 1u << cm_y_part_num_log2;

if (inpDepth < cm_octant_depth)
this->split_octant_flag = reader.readFlag("split_octant_flag");
if (this->split_octant_flag)
{
for (int k = 0; k < 2; k++)
{
for (int m = 0; m < 2; m++)
{
for (int n = 0; n < 2; n++)
{
this->colourMappingOctants = std::make_unique<array3d<colour_mapping_octants, 2, 2, 2>>();
(*this->colourMappingOctants)[k][m][n].parse(reader,
cm_octant_depth,
cm_y_part_num_log2,
CMResLSBits,
inpDepth + 1,
idxY + PartNumY * k * inpLength / 2,
idxCb + m * inpLength / 2,
idxCr + n * inpLength / 2,
inpLength / 2);
}
}
}
}
else
{
for (unsigned i = 0; i < PartNumY; i++)
{
const auto idxShiftY = idxY + (i << (cm_octant_depth - inpDepth));
for (unsigned j = 0; j < 4; j++)
{
this->coded_res_flag[idxShiftY][idxCb][idxCr][j] =
reader.readFlag(formatArray("coded_res_flag", idxShiftY, idxCb, idxCr, j));
if (this->coded_res_flag[idxShiftY][idxCb][idxCr][j])
{
for (unsigned c = 0; c < 3; c++)
{
this->res_coeff_q[idxShiftY][idxCb][idxCr][j][c] =
reader.readUEV(formatArray("res_coeff_q", idxShiftY, idxCb, idxCr, j, c));
if (CMResLSBits == 0)
this->res_coeff_r[idxShiftY][idxCb][idxCr][j][c] = 0;
else
this->res_coeff_r[idxShiftY][idxCb][idxCr][j][c] = reader.readBits(
formatArray("res_coeff_r", idxShiftY, idxCb, idxCr, j, c), CMResLSBits);
if (this->res_coeff_q[idxShiftY][idxCb][idxCr][j][c] ||
this->res_coeff_r[idxShiftY][idxCb][idxCr][j][c])
this->res_coeff_s[idxShiftY][idxCb][idxCr][j][c] =
reader.readFlag(formatArray("res_coeff_s", idxShiftY, idxCb, idxCr, j, c));
}
}
}
}
}
}

} // namespace parser::hevc
66 changes: 66 additions & 0 deletions YUViewLib/src/parser/HEVC/Extensions/colour_mapping_octants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* This file is part of YUView - The YUV player with advanced analytics toolset
* <https://github.com/IENT/YUView>
* Copyright (C) 2015 Institut f�r Nachrichtentechnik, RWTH Aachen University, GERMANY
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*
* You must obey the GNU General Public License in all respects for all
* of the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version. If you delete
* this exception statement from all source files in the program, then
* also delete it here.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "parser/common/SubByteReaderLogging.h"

namespace parser::hevc
{

// F.7.3.2.3.6 Colour mapping octants syntax
class colour_mapping_octants
{
public:
colour_mapping_octants() {}

void parse(reader::SubByteReaderLogging &reader,
const unsigned cm_octant_depth,
const unsigned cm_y_part_num_log2,
const unsigned CMResLSBits,
const unsigned inpDepth,
const unsigned idxY,
const unsigned idxCb,
const unsigned idxCr,
const unsigned inpLength);

bool split_octant_flag{};

std::unique_ptr<array3d<colour_mapping_octants, 2, 2, 2>> colourMappingOctants;

umap_4d<bool> coded_res_flag;
umap_5d<unsigned> res_coeff_q;
umap_5d<unsigned> res_coeff_r;
umap_5d<unsigned> res_coeff_s;
};

} // namespace parser::hevc
81 changes: 81 additions & 0 deletions YUViewLib/src/parser/HEVC/Extensions/colour_mapping_table.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* This file is part of YUView - The YUV player with advanced analytics toolset
* <https://github.com/IENT/YUView>
* Copyright (C) 2015 Institut f�r Nachrichtentechnik, RWTH Aachen University, GERMANY
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*
* You must obey the GNU General Public License in all respects for all
* of the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version. If you delete
* this exception statement from all source files in the program, then
* also delete it here.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "colour_mapping_table.h"

#include <parser/common/Functions.h>

namespace parser::hevc
{

using namespace reader;

void colour_mapping_table::parse(SubByteReaderLogging &reader)
{
SubByteReaderLoggingSubLevel subLevel(reader, "colour_mapping_table()");

this->num_cm_ref_layers_minus1 = reader.readUEV("num_cm_ref_layers_minus1");
for (unsigned i = 0; i <= this->num_cm_ref_layers_minus1; i++)
this->cm_ref_layer_id.push_back(reader.readBits(formatArray("cm_ref_layer_id", i), 6));
this->cm_octant_depth = reader.readBits("cm_octant_depth", 2);
this->cm_y_part_num_log2 = reader.readBits("cm_y_part_num_log2", 2);
this->luma_bit_depth_cm_input_minus8 = reader.readUEV("luma_bit_depth_cm_input_minus8");
this->chroma_bit_depth_cm_input_minus8 = reader.readUEV("chroma_bit_depth_cm_input_minus8");
this->luma_bit_depth_cm_output_minus8 = reader.readUEV("luma_bit_depth_cm_output_minus8");
this->chroma_bit_depth_cm_output_minus8 = reader.readUEV("chroma_bit_depth_cm_output_minus8");
this->cm_res_quant_bits = reader.readBits("cm_res_quant_bits", 2);
this->cm_delta_flc_bits_minus1 = reader.readBits("cm_delta_flc_bits_minus1", 2);
if (this->cm_octant_depth == 1)
{
this->cm_adapt_threshold_u_delta = reader.readSEV("cm_adapt_threshold_u_delta");
this->cm_adapt_threshold_v_delta = reader.readSEV("cm_adapt_threshold_v_delta");
}

const auto BitDepthCmInputY = 8 + this->luma_bit_depth_cm_input_minus8;
const auto BitDepthCmOutputY = 8 + luma_bit_depth_cm_output_minus8;
const auto CMResLSBits =
std::max(0u,
(10 + BitDepthCmInputY - BitDepthCmOutputY - this->cm_res_quant_bits -
(this->cm_delta_flc_bits_minus1 + 1)));

this->colourMappingOctants.parse(reader,
this->cm_octant_depth,
cm_y_part_num_log2,
CMResLSBits,
0,
0,
0,
0,
1 << this->cm_octant_depth);
}

} // namespace parser::hevc
64 changes: 64 additions & 0 deletions YUViewLib/src/parser/HEVC/Extensions/colour_mapping_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* This file is part of YUView - The YUV player with advanced analytics toolset
* <https://github.com/IENT/YUView>
* Copyright (C) 2015 Institut f�r Nachrichtentechnik, RWTH Aachen University, GERMANY
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*
* You must obey the GNU General Public License in all respects for all
* of the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version. If you delete
* this exception statement from all source files in the program, then
* also delete it here.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "colour_mapping_octants.h"
#include "parser/common/SubByteReaderLogging.h"

namespace parser::hevc
{

// F.7.3.2.3.5 General colour mapping table syntax
class colour_mapping_table
{
public:
colour_mapping_table() {}

void parse(reader::SubByteReaderLogging &reader);

unsigned num_cm_ref_layers_minus1{};
vector<unsigned> cm_ref_layer_id;
unsigned cm_octant_depth{};
unsigned cm_y_part_num_log2{};
unsigned luma_bit_depth_cm_input_minus8{};
unsigned chroma_bit_depth_cm_input_minus8{};
unsigned luma_bit_depth_cm_output_minus8{};
unsigned chroma_bit_depth_cm_output_minus8{};
unsigned cm_res_quant_bits{};
unsigned cm_delta_flc_bits_minus1{};
int cm_adapt_threshold_u_delta{};
int cm_adapt_threshold_v_delta{};
colour_mapping_octants colourMappingOctants{};
};

} // namespace parser::hevc
Loading

0 comments on commit 50e6941

Please sign in to comment.