From 95fa47a92d425f5ca10cd52bd2c1bda05d3ff26f Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sun, 18 Feb 2024 13:36:37 +0100 Subject: [PATCH 1/2] use GetDataStart() to estimate the position of an element relative to a Segment --- src/KaxSegment.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/KaxSegment.cpp b/src/KaxSegment.cpp index f0b1ca89..56f7f12b 100644 --- a/src/KaxSegment.cpp +++ b/src/KaxSegment.cpp @@ -39,7 +39,7 @@ KaxSegment::KaxSegment(const KaxSegment & ElementToClone) std::uint64_t KaxSegment::GetRelativePosition(std::uint64_t aGlobalPosition) const { - return aGlobalPosition - GetElementPosition() - HeadSize(); + return aGlobalPosition - GetDataStart(); } std::uint64_t KaxSegment::GetRelativePosition(const EbmlElement & Elt) const @@ -49,7 +49,7 @@ std::uint64_t KaxSegment::GetRelativePosition(const EbmlElement & Elt) const std::uint64_t KaxSegment::GetGlobalPosition(std::uint64_t aRelativePosition) const { - return aRelativePosition + GetElementPosition() + HeadSize(); + return aRelativePosition + GetDataStart(); } } // namespace libmatroska From 3c6bbc011a82df96e30f656228bb557f6e1b905a Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sun, 18 Feb 2024 13:42:01 +0100 Subject: [PATCH 2/2] test6: don't read compute the head size again It's always going to be 4+5, ie the minimum set in this case. --- test/mux/test6.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/mux/test6.cpp b/test/mux/test6.cpp index f3ae9a72..3c32f92c 100644 --- a/test/mux/test6.cpp +++ b/test/mux/test6.cpp @@ -59,7 +59,7 @@ int main(int /*argc*/, char **/*argv*/) KaxSegment FileSegment; // size is unknown and will always be, we can render it right away - std::uint64_t SegmentSize = FileSegment.WriteHead(out_file, 5, bWriteDefaultValues); + FileSegment.WriteHead(out_file, 5, bWriteDefaultValues); KaxTracks & MyTracks = GetChild(FileSegment); @@ -335,8 +335,7 @@ int main(int /*argc*/, char **/*argv*/) #endif // VOID_TEST // let's assume we know the size of the Segment element - // the size of the FileSegment is also computed because mandatory elements we don't write ourself exist - if (FileSegment.ForceSize(SegmentSize - FileSegment.HeadSize() + MetaSeekSize + if (FileSegment.ForceSize(MetaSeekSize + TrackSize + ClusterSize + CueSize + InfoSize + TagsSize + ChapterSize)) { FileSegment.OverwriteHead(out_file); }