Commit 4a533dc4 for libheif
commit 4a533dc4d271729393f84961b0ab41d8dcd03f8a
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Sun Dec 14 14:52:21 2025 +0100
[BSD3] write 'dinf' box
diff --git a/libheif/box.cc b/libheif/box.cc
index 5c2822c4..f8c5269d 100644
--- a/libheif/box.cc
+++ b/libheif/box.cc
@@ -4251,6 +4251,18 @@ Error Box_dref::parse(BitstreamRange& range, const heif_security_limits* limits)
}
+Error Box_dref::write(StreamWriter& writer) const
+{
+ size_t box_start = reserve_box_header_space(writer);
+
+ writer.write32(m_children.size());
+ write_children(writer);
+
+ prepend_header(writer, box_start);
+ return Error::Ok;
+}
+
+
std::string Box_dref::dump(Indent& indent) const
{
std::ostringstream sstr;
@@ -4281,6 +4293,23 @@ Error Box_url::parse(BitstreamRange& range, const heif_security_limits* limits)
}
+Error Box_url::write(StreamWriter& writer) const
+{
+ size_t box_start = reserve_box_header_space(writer);
+
+ if (m_location.empty()) {
+ assert(get_flags() == 1);
+ }
+ else {
+ assert(get_flags() == 0);
+ writer.write(m_location);
+ }
+
+ prepend_header(writer, box_start);
+ return Error::Ok;
+}
+
+
std::string Box_url::dump(Indent& indent) const
{
std::ostringstream sstr;
diff --git a/libheif/box.h b/libheif/box.h
index fc7f7507..c6bb97d8 100644
--- a/libheif/box.h
+++ b/libheif/box.h
@@ -1188,6 +1188,11 @@ protected:
class Box_dinf : public Box
{
public:
+ Box_dinf()
+ {
+ set_short_type(fourcc("dinf"));
+ }
+
std::string dump(Indent&) const override;
const char* debug_box_name() const override { return "Data Information"; }
@@ -1200,10 +1205,17 @@ protected:
class Box_dref : public FullBox
{
public:
+ Box_dref()
+ {
+ set_short_type(fourcc("dref"));
+ }
+
std::string dump(Indent&) const override;
const char* debug_box_name() const override { return "Data Reference"; }
+ Error write(StreamWriter& writer) const override;
+
protected:
Error parse(BitstreamRange& range, const heif_security_limits*) override;
};
@@ -1212,12 +1224,24 @@ protected:
class Box_url : public FullBox
{
public:
+ Box_url()
+ {
+ set_short_type(fourcc("url "));
+ set_flags(1);
+ }
+
std::string dump(Indent&) const override;
const char* debug_box_name() const override { return "Data Entry URL"; }
bool is_same_file() const { return m_location.empty(); }
+ void set_location(const std::string& loc) { m_location = loc; set_flags(m_location.empty() ? 1 : 0); }
+
+ void set_location_same_file() { m_location.clear(); set_flags(1); }
+
+ Error write(StreamWriter& writer) const override;
+
protected:
Error parse(BitstreamRange& range, const heif_security_limits*) override;
diff --git a/libheif/sequences/track.cc b/libheif/sequences/track.cc
index f415d0b8..5cd2153f 100644
--- a/libheif/sequences/track.cc
+++ b/libheif/sequences/track.cc
@@ -460,6 +460,15 @@ Track::Track(HeifContext* ctx, uint32_t track_id, const TrackOptions* options, u
m_minf = std::make_shared<Box_minf>();
mdia->append_child_box(m_minf);
+ // add (unused) 'dinf'
+
+ auto dinf = std::make_shared<Box_dinf>();
+ auto dref = std::make_shared<Box_dref>();
+ auto url = std::make_shared<Box_url>();
+ m_minf->append_child_box(dinf);
+ dinf->append_child_box(dref);
+ dref->append_child_box(url);
+
// vmhd is added in Track_Visual
m_stbl = std::make_shared<Box_stbl>();