Skip to content

Commit

Permalink
Move EntityGroup from Box_grpl to its own class
Browse files Browse the repository at this point in the history
With this new group list architecture, libheif is better suited for handling Entity Groups with remaining data
  • Loading branch information
dukesook committed Mar 6, 2024
1 parent a28d02f commit 3070eb1
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 36 deletions.
92 changes: 62 additions & 30 deletions libheif/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,14 @@ Error Box::read(BitstreamRange& range, std::shared_ptr<Box>* result)
box = std::make_shared<Box_grpl>();
break;

case fourcc("altr"):
box = std::make_shared<EntityGroup>(fourcc("altr"));
break;

case fourcc("ster"):
box = std::make_shared<Box_ster>();
break;

case fourcc("dinf"):
box = std::make_shared<Box_dinf>();
break;
Expand Down Expand Up @@ -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();
}

Expand Down
40 changes: 34 additions & 6 deletions libheif/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<heif_item_id> m_entity_ids;
};

struct EntityGroup

class Box_ster : public EntityGroup
{
public:
Box_ster() : EntityGroup(fourcc("ster"))
{
FullBox header;
uint32_t group_id;
}

std::vector<heif_item_id> 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<EntityGroup> m_entity_groups;
};
Expand Down

0 comments on commit 3070eb1

Please sign in to comment.