From 3070eb1e699e49800c012d4aef0c2b044be3303f Mon Sep 17 00:00:00 2001 From: dukesook Date: Wed, 6 Mar 2024 15:45:34 -0700 Subject: [PATCH] Move EntityGroup from Box_grpl to its own class With this new group list architecture, libheif is better suited for handling Entity Groups with remaining data --- libheif/box.cc | 92 ++++++++++++++++++++++++++++++++++---------------- libheif/box.h | 40 ++++++++++++++++++---- 2 files changed, 96 insertions(+), 36 deletions(-) diff --git a/libheif/box.cc b/libheif/box.cc index 49c555eb34..43b1c7c6b1 100644 --- a/libheif/box.cc +++ b/libheif/box.cc @@ -520,6 +520,14 @@ Error Box::read(BitstreamRange& range, std::shared_ptr* result) box = std::make_shared(); break; + case fourcc("altr"): + box = std::make_shared(fourcc("altr")); + break; + + case fourcc("ster"): + box = std::make_shared(); + break; + case fourcc("dinf"): box = std::make_shared(); break; @@ -2925,54 +2933,78 @@ Error Box_grpl::parse(BitstreamRange& range) { //parse_full_box_header(range); - //return read_children(range); + return read_children(range); +} - while (!range.eof()) { - EntityGroup group; - Error err = group.header.parse_header(range); - if (err != Error::Ok) { - return err; - } - err = group.header.parse_full_box_header(range); - if (err != Error::Ok) { - return err; - } +std::string Box_grpl::dump(Indent& indent) const +{ + std::ostringstream sstr; + sstr << Box::dump(indent); - group.group_id = range.read32(); - uint32_t nEntities = range.read32(); - for (uint32_t i = 0; i < nEntities; i++) { - if (range.eof()) { - break; - } + sstr << dump_children(indent); - group.entity_ids.push_back(range.read32()); - } + return sstr.str(); +} + + +Error EntityGroup::parse(BitstreamRange& range) +{ + + Error err = parse_full_box_header(range); + if (err != Error::Ok) { + return err; + } - m_entity_groups.push_back(group); + m_group_id = range.read32(); + uint32_t nEntities = range.read32(); + for (uint32_t i = 0; i < nEntities; i++) { + if (range.eof()) { + break; + } + m_entity_ids.push_back(range.read32()); } + parse_remaining(range); + return range.get_error(); } -std::string Box_grpl::dump(Indent& indent) const +std::string EntityGroup::dump(Indent& indent) const { std::ostringstream sstr; sstr << Box::dump(indent); - for (const auto& group : m_entity_groups) { - sstr << indent << "group type: " << group.header.get_type_string() << "\n" - << indent << "| group id: " << group.group_id << "\n" - << indent << "| entity IDs: "; - - for (uint32_t id : group.entity_ids) { - sstr << id << " "; - } + sstr << indent << "group type: " << get_type_string() << "\n" + << indent << "| group id: " << m_group_id << "\n" + << indent << "| entity IDs: "; - sstr << "\n"; + for (uint32_t id : m_entity_ids) { + sstr << id << " "; } + sstr << dump_remaining(indent); + + sstr << "\n"; + + return sstr.str(); +} + + +Error Box_ster::parse_remaining(BitstreamRange& range) +{ + uint32_t flags = range.read32(); + m_left_view_flag = flags & 1; + return Error::Ok; +} + + +std::string Box_ster::dump_remaining(Indent& indent) const +{ + std::ostringstream sstr; + sstr << indent << "left view flag: " << m_left_view_flag << "\n"; + return sstr.str(); } diff --git a/libheif/box.h b/libheif/box.h index 3a651f6ea9..edd3edcbe0 100644 --- a/libheif/box.h +++ b/libheif/box.h @@ -809,21 +809,49 @@ class Box_idat : public Box }; -class Box_grpl : public Box +class EntityGroup : public FullBox { public: + EntityGroup(uint32_t fourcc) + { + set_short_type(fourcc); + } std::string dump(Indent&) const override; protected: Error parse(BitstreamRange& range) override; + virtual Error parse_remaining(BitstreamRange& range) { return Error::Ok; } + virtual std::string dump_remaining(Indent&) const { return ""; } + +public: + uint32_t m_group_id; + std::vector m_entity_ids; +}; - struct EntityGroup + +class Box_ster : public EntityGroup +{ +public: + Box_ster() : EntityGroup(fourcc("ster")) { - FullBox header; - uint32_t group_id; + } - std::vector entity_ids; - }; +private: + bool m_left_view_flag; + +protected: + Error parse_remaining(BitstreamRange& range) override; + std::string dump_remaining(Indent&) const override; +}; + + +class Box_grpl : public Box +{ +public: + std::string dump(Indent&) const override; + +protected: + Error parse(BitstreamRange& range) override; std::vector m_entity_groups; };