Skip to content

Commit

Permalink
evc: decode profile and NAL unit types when dumping
Browse files Browse the repository at this point in the history
  • Loading branch information
bradh committed Nov 2, 2024
1 parent cccc293 commit 9504735
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
46 changes: 44 additions & 2 deletions libheif/codecs/evc_boxes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ std::string Box_evcC::dump(Indent& indent) const
sstr << Box::dump(indent);
// TODO: decode more of this
sstr << indent << "configurationVersion: " << ((int)m_configuration.configurationVersion) << "\n";
sstr << indent << "profile_idc: " << ((int)m_configuration.profile_idc) << "\n";
sstr << indent << "profile_idc: " << ((int)m_configuration.profile_idc)
<< " (" << get_profile_as_text() << ")" << "\n";
sstr << indent << "level_idc: " << ((int)m_configuration.level_idc) << "\n";
sstr << indent << "toolset_idc_h: " << m_configuration.toolset_idc_h << "\n";
sstr << indent << "toolset_idc_l: " << m_configuration.toolset_idc_l << "\n";
Expand All @@ -103,7 +104,8 @@ std::string Box_evcC::dump(Indent& indent) const

indent++;
sstr << indent << "array_completeness: " << (array.array_completeness ? "true" : "false") << "\n"
<< indent << "NAL_unit_type: " << ((int) array.NAL_unit_type) << "\n";
<< indent << "NAL_unit_type: " << ((int) array.NAL_unit_type) << " ("
<< get_NAL_unit_type_as_text(array.NAL_unit_type) << ")" << "\n";

for (const auto& unit : array.nal_units) {
sstr << indent;
Expand All @@ -119,6 +121,23 @@ std::string Box_evcC::dump(Indent& indent) const
return sstr.str();
}

std::string Box_evcC::get_profile_as_text() const
{
switch (m_configuration.profile_idc)
{
case 0:
return "Baseline";
case 1:
return "Main";
case 2:
return "Baseline Still";
case 3:
return "Main Still";
default:
return std::string("Unknown");
}
}

std::string Box_evcC::get_chroma_format_as_text() const
{
switch (m_configuration.chroma_format_idc)
Expand All @@ -136,6 +155,29 @@ std::string Box_evcC::get_chroma_format_as_text() const
}
}

std::string Box_evcC::get_NAL_unit_type_as_text(uint8_t nal_unit_type) const
{
switch (nal_unit_type)
{
case 0:
return "NONIDR_NUT";
case 1:
return "IDR_NUT";
case 24:
return "SPS_NUT";
case 25:
return "PPS_NUT";
case 26:
return "APS_NUT";
case 27:
return "FD_NUT";
case 28:
return "SEI_NUT";
default:
return std::string("Unknown");
}
}

Error Box_evcC::write(StreamWriter& writer) const
{
size_t box_start = reserve_box_header_space(writer);
Expand Down
2 changes: 2 additions & 0 deletions libheif/codecs/evc_boxes.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ class Box_evcC : public Box {

std::vector<NalArray> m_nal_array;

std::string get_profile_as_text() const;
std::string get_chroma_format_as_text() const;
std::string get_NAL_unit_type_as_text(uint8_t nal_unit_type) const;
};

#endif
10 changes: 5 additions & 5 deletions tests/evc_box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
TEST_CASE("evcC") {
std::vector<uint8_t> byteArray{
0x00, 0x00, 0x00, 0x3d, 0x65, 0x76, 0x63, 0x43,
0x01, 0x00, 0xd7, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x02, 0xd7, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x52, 0x01, 0x40, 0x00, 0xf0,
0x03, 0x02, 0x98, 0x00, 0x01, 0x00, 0x15, 0x32,
0x00, 0x80, 0x6b, 0x80, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -56,7 +56,7 @@ TEST_CASE("evcC") {
std::shared_ptr<Box_evcC> evcC = std::dynamic_pointer_cast<Box_evcC>(box);
Box_evcC::configuration configuration = evcC->get_configuration();
REQUIRE(configuration.configurationVersion == 1);
REQUIRE(configuration.profile_idc == 0);
REQUIRE(configuration.profile_idc == 2);
REQUIRE(configuration.level_idc == 215);
REQUIRE(configuration.toolset_idc_h == 0);
REQUIRE(configuration.toolset_idc_l == 0);
Expand All @@ -71,7 +71,7 @@ TEST_CASE("evcC") {
REQUIRE(dumpResult == "Box: evcC -----\n"
"size: 61 (header size: 8)\n"
"configurationVersion: 1\n"
"profile_idc: 0\n"
"profile_idc: 2 (Baseline Still)\n"
"level_idc: 215\n"
"toolset_idc_h: 0\n"
"toolset_idc_l: 0\n"
Expand All @@ -83,11 +83,11 @@ TEST_CASE("evcC") {
"length_size: 4\n"
"<array>\n"
"| array_completeness: true\n"
"| NAL_unit_type: 24\n"
"| NAL_unit_type: 24 (SPS_NUT)\n"
"| 32 00 80 6b 80 00 00 00 00 00 00 00 20 0a 08 0f 16 c0 00 54 00 \n"
"<array>\n"
"| array_completeness: true\n"
"| NAL_unit_type: 25\n"
"| NAL_unit_type: 25 (PPS_NUT)\n"
"| 34 00 fb 00 \n");

StreamWriter writer;
Expand Down

0 comments on commit 9504735

Please sign in to comment.