Skip to content

Commit

Permalink
Fix some bugs for parsing MV HEVC
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Feb 19, 2024
1 parent e9240e7 commit 0b5796a
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 59 deletions.
2 changes: 1 addition & 1 deletion YUViewLib/src/parser/HEVC/ParserAnnexBHEVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ ParserAnnexBHEVC::parseAndAddNALUnit(int
else if (nalHEVC->header.nal_unit_type == hevc::NalType::SPS_NUT)
{
auto newSPS = std::make_shared<seq_parameter_set_rbsp>();
newSPS->parse(reader);
newSPS->parse(reader, nalHEVC->header);

this->activeParameterSets.spsMap[newSPS->sps_seq_parameter_set_id] = newSPS;

Expand Down
6 changes: 3 additions & 3 deletions YUViewLib/src/parser/HEVC/pic_parameter_set_rbsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ void pic_parameter_set_rbsp::parse(SubByteReaderLogging &reader)

// This would also be interesting but later.
if (this->pps_multilayer_extension_flag)
reader.logArbitrary("pps_multilayer_extension()", 0, "", "", "Not implemented yet...");
reader.logArbitrary("pps_multilayer_extension()", "", "", "", "Not implemented yet...");

if (this->pps_3d_extension_flag)
reader.logArbitrary("pps_3d_extension()", 0, "", "", "Not implemented yet...");
reader.logArbitrary("pps_3d_extension()", "", "", "", "Not implemented yet...");

if (this->pps_extension_5bits != 0)
reader.logArbitrary("pps_extension_data_flag()", 0, "", "", "Not implemented yet...");
reader.logArbitrary("pps_extension_data_flag()", "", "", "", "Not implemented yet...");

// There is more to parse but we are not interested in this information (for now)
// this->rbspTrailingBits.parse(reader);
Expand Down
119 changes: 70 additions & 49 deletions YUViewLib/src/parser/HEVC/seq_parameter_set_rbsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,62 +41,83 @@ namespace parser::hevc

using namespace reader;

void seq_parameter_set_rbsp::parse(SubByteReaderLogging &reader)
void seq_parameter_set_rbsp::parse(SubByteReaderLogging & reader,
const nal_unit_header &nalUnitHeader)
{
SubByteReaderLoggingSubLevel subLevel(reader, "seq_parameter_set_rbsp()");

this->sps_video_parameter_set_id = reader.readBits("sps_video_parameter_set_id", 4);
this->sps_max_sub_layers_minus1 = reader.readBits("sps_max_sub_layers_minus1", 3);
this->sps_temporal_id_nesting_flag = reader.readFlag("sps_temporal_id_nesting_flag");
this->sps_video_parameter_set_id = reader.readBits("sps_video_parameter_set_id", 4);
if (nalUnitHeader.nuh_layer_id == 0)
this->sps_max_sub_layers_minus1 = reader.readBits("sps_max_sub_layers_minus1", 3);
else
this->sps_ext_or_max_sub_layers_minus1 = reader.readBits("sps_max_sub_layers_minus1", 3);

// parse profile tier level
this->profileTierLevel.parse(reader, true, sps_max_sub_layers_minus1);
const auto MultiLayerExtSpsFlag =
(nalUnitHeader.nuh_layer_id != 0 && this->sps_ext_or_max_sub_layers_minus1 == 7);
if (!MultiLayerExtSpsFlag)
{
this->sps_temporal_id_nesting_flag = reader.readFlag("sps_temporal_id_nesting_flag");
this->profileTierLevel.parse(reader, true, sps_max_sub_layers_minus1);
}

/// Back to the seq_parameter_set_rbsp
this->sps_seq_parameter_set_id = reader.readUEV("sps_seq_parameter_set_id");
this->chroma_format_idc = reader.readUEV(
"chroma_format_idc",
Options().withMeaningVector({"moochrome", "4:2:0", "4:2:2", "4:4:4", "4:4:4"}));
if (this->chroma_format_idc == 3)
this->separate_colour_plane_flag = reader.readFlag("separate_colour_plane_flag");
this->ChromaArrayType = (this->separate_colour_plane_flag) ? 0 : this->chroma_format_idc;
reader.logCalculatedValue("ChromaArrayType", this->ChromaArrayType);

// Rec. ITU-T H.265 v3 (04/2015) - 6.2 - Table 6-1
this->SubWidthC = (this->chroma_format_idc == 1 || this->chroma_format_idc == 2) ? 2 : 1;
this->SubHeightC = (this->chroma_format_idc == 1) ? 2 : 1;
reader.logCalculatedValue("SubWidthC", this->SubWidthC);
reader.logCalculatedValue("SubHeightC", this->SubHeightC);

this->pic_width_in_luma_samples = reader.readUEV("pic_width_in_luma_samples");
this->pic_height_in_luma_samples = reader.readUEV("pic_height_in_luma_samples");
this->conformance_window_flag = reader.readFlag("conformance_window_flag");

if (this->conformance_window_flag)

if (MultiLayerExtSpsFlag)
{
this->conf_win_left_offset = reader.readUEV("conf_win_left_offset");
this->conf_win_right_offset = reader.readUEV("conf_win_right_offset");
this->conf_win_top_offset = reader.readUEV("conf_win_top_offset");
this->conf_win_bottom_offset = reader.readUEV("conf_win_bottom_offset");
this->update_rep_format_flag = reader.readFlag("update_rep_format_flag");
if (this->update_rep_format_flag)
this->sps_rep_format_idx = reader.readBits("sps_rep_format_idx", 8);
}
else
{
this->chroma_format_idc = reader.readUEV(
"chroma_format_idc",
Options().withMeaningVector({"moochrome", "4:2:0", "4:2:2", "4:4:4", "4:4:4"}));
if (this->chroma_format_idc == 3)
this->separate_colour_plane_flag = reader.readFlag("separate_colour_plane_flag");
this->ChromaArrayType = (this->separate_colour_plane_flag) ? 0 : this->chroma_format_idc;
reader.logCalculatedValue("ChromaArrayType", this->ChromaArrayType);

// Rec. ITU-T H.265 v3 (04/2015) - 6.2 - Table 6-1
this->SubWidthC = (this->chroma_format_idc == 1 || this->chroma_format_idc == 2) ? 2 : 1;
this->SubHeightC = (this->chroma_format_idc == 1) ? 2 : 1;
reader.logCalculatedValue("SubWidthC", this->SubWidthC);
reader.logCalculatedValue("SubHeightC", this->SubHeightC);

this->pic_width_in_luma_samples = reader.readUEV("pic_width_in_luma_samples");
this->pic_height_in_luma_samples = reader.readUEV("pic_height_in_luma_samples");
this->conformance_window_flag = reader.readFlag("conformance_window_flag");

if (this->conformance_window_flag)
{
this->conf_win_left_offset = reader.readUEV("conf_win_left_offset");
this->conf_win_right_offset = reader.readUEV("conf_win_right_offset");
this->conf_win_top_offset = reader.readUEV("conf_win_top_offset");
this->conf_win_bottom_offset = reader.readUEV("conf_win_bottom_offset");
}

this->bit_depth_luma_minus8 = reader.readUEV("bit_depth_luma_minus8");
this->bit_depth_chroma_minus8 = reader.readUEV("bit_depth_chroma_minus8");
this->log2_max_pic_order_cnt_lsb_minus4 = reader.readUEV("log2_max_pic_order_cnt_lsb_minus4");
this->bit_depth_luma_minus8 = reader.readUEV("bit_depth_luma_minus8");
this->bit_depth_chroma_minus8 = reader.readUEV("bit_depth_chroma_minus8");
}

this->sps_sub_layer_ordering_info_present_flag =
reader.readFlag("sps_sub_layer_ordering_info_present_flag");
for (unsigned i =
(this->sps_sub_layer_ordering_info_present_flag ? 0 : this->sps_max_sub_layers_minus1);
i <= this->sps_max_sub_layers_minus1;
i++)
if (!MultiLayerExtSpsFlag)
{
this->sps_max_dec_pic_buffering_minus1.push_back(
reader.readUEV(formatArray("sps_max_dec_pic_buffering_minus1", i)));
this->sps_max_num_reorder_pics.push_back(
reader.readUEV(formatArray("sps_max_num_reorder_pics", i)));
this->sps_max_latency_increase_plus1.push_back(
reader.readUEV(formatArray("sps_max_latency_increase_plus1", i)));
this->log2_max_pic_order_cnt_lsb_minus4 = reader.readUEV("log2_max_pic_order_cnt_lsb_minus4");

this->sps_sub_layer_ordering_info_present_flag =
reader.readFlag("sps_sub_layer_ordering_info_present_flag");
for (unsigned i =
(this->sps_sub_layer_ordering_info_present_flag ? 0 : this->sps_max_sub_layers_minus1);
i <= this->sps_max_sub_layers_minus1;
i++)
{
this->sps_max_dec_pic_buffering_minus1.push_back(
reader.readUEV(formatArray("sps_max_dec_pic_buffering_minus1", i)));
this->sps_max_num_reorder_pics.push_back(
reader.readUEV(formatArray("sps_max_num_reorder_pics", i)));
this->sps_max_latency_increase_plus1.push_back(
reader.readUEV(formatArray("sps_max_latency_increase_plus1", i)));
}
}

this->log2_min_luma_coding_block_size_minus3 =
Expand Down Expand Up @@ -177,16 +198,16 @@ void seq_parameter_set_rbsp::parse(SubByteReaderLogging &reader)
// Now the extensions follow ...
// This would also be interesting but later.
if (this->sps_range_extension_flag)
reader.logArbitrary("sps_range_extension()", 0, "", "", "Not implemented yet...");
reader.logArbitrary("sps_range_extension()", "", "", "", "Not implemented yet...");

if (this->sps_multilayer_extension_flag)
reader.logArbitrary("sps_multilayer_extension()", 0, "", "", "Not implemented yet...");
reader.logArbitrary("sps_multilayer_extension()", "", "", "", "Not implemented yet...");

if (this->sps_3d_extension_flag)
reader.logArbitrary("sps_3d_extension()", 0, "", "", "Not implemented yet...");
reader.logArbitrary("sps_3d_extension()", "", "", "", "Not implemented yet...");

if (this->sps_extension_5bits != 0)
reader.logArbitrary("sps_extension_data_flag()", 0, "", "", "Not implemented yet...");
reader.logArbitrary("sps_extension_data_flag()", "", "", "", "Not implemented yet...");

// rbspTrailingBits.parse(reader);

Expand Down
9 changes: 7 additions & 2 deletions YUViewLib/src/parser/HEVC/seq_parameter_set_rbsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
#include "NalUnitHEVC.h"
#include "parser/common/SubByteReaderLogging.h"
#include "profile_tier_level.h"
#include "rbsp_trailing_bits.h"
#include "scaling_list_data.h"
#include "st_ref_pic_set.h"
#include "vui_parameters.h"
#include "rbsp_trailing_bits.h"

namespace parser::hevc
{
Expand All @@ -48,7 +48,7 @@ class seq_parameter_set_rbsp : public NalRBSP
public:
seq_parameter_set_rbsp() {}

void parse(reader::SubByteReaderLogging &reader);
void parse(reader::SubByteReaderLogging &reader, const nal_unit_header &nalUnitHeader);

unsigned sps_video_parameter_set_id{};
unsigned sps_max_sub_layers_minus1{};
Expand Down Expand Up @@ -124,6 +124,11 @@ class seq_parameter_set_rbsp : public NalRBSP
unsigned PicHeightInCtbsY{};
unsigned PicSizeInCtbsY{};

// Annex F.7.3.2.2.1
unsigned sps_ext_or_max_sub_layers_minus1{};
bool update_rep_format_flag{};
unsigned sps_rep_format_idx{};

// Get the actual size of the image that will be returned. Internally the image might be bigger.
unsigned get_conformance_cropping_width() const
{
Expand Down
11 changes: 7 additions & 4 deletions YUViewLib/src/parser/HEVC/slice_segment_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
#include "slice_segment_header.h"

#include "parser/common/CodingEnum.h"
#include <parser/common/Functions.h>
#include "pic_parameter_set_rbsp.h"
#include "seq_parameter_set_rbsp.h"
#include "slice_segment_layer_rbsp.h"

#include <parser/common/Functions.h>

#include <cmath>

Expand All @@ -56,7 +55,10 @@ static parser::CodingEnum<SliceType> sliceTypeCoding({{0, SliceType::B, "B", "B-

using namespace reader;

std::string to_string(SliceType sliceType) { return sliceTypeCoding.getMeaning(sliceType); }
std::string to_string(SliceType sliceType)
{
return sliceTypeCoding.getMeaning(sliceType);
}

void slice_segment_header::parse(SubByteReaderLogging & reader,
bool firstAUInDecodingOrder,
Expand Down Expand Up @@ -148,7 +150,8 @@ void slice_segment_header::parse(SubByteReaderLogging & reader,
this->lt_idx_sps[i] = reader.readBits(formatArray("lt_idx_sps", i), nrBits);
}

this->UsedByCurrPicLt.push_back(sps->used_by_curr_pic_lt_sps_flag[this->lt_idx_sps[i]]);
this->UsedByCurrPicLt.push_back(
sps->used_by_curr_pic_lt_sps_flag.at(this->lt_idx_sps[i]));
}
else
{
Expand Down

0 comments on commit 0b5796a

Please sign in to comment.