From 014b8d5f46204c6c35bc2af64353f092b0f46196 Mon Sep 17 00:00:00 2001 From: Nikos Fotos Date: Sun, 29 Oct 2023 18:08:02 +0200 Subject: [PATCH] Support the signaling of Jumbf Box size using XLBox even if the size is less than 2^32 bytes (LBox) --- .../main/java/org/mipams/jumbf/entities/BmffBox.java | 8 ++++++-- .../mipams/jumbf/services/BmffBoxServiceTests.java | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/jumbf/src/main/java/org/mipams/jumbf/entities/BmffBox.java b/jumbf/src/main/java/org/mipams/jumbf/entities/BmffBox.java index f3371dc..f732051 100644 --- a/jumbf/src/main/java/org/mipams/jumbf/entities/BmffBox.java +++ b/jumbf/src/main/java/org/mipams/jumbf/entities/BmffBox.java @@ -58,7 +58,7 @@ private void updateBmffHeadersBasedOnBox() throws MipamsException { long size = calculateSizeFromBox(); - if (isXBoxRequiredBasedOnSize(size)) { + if (shouldEnableXlBox(size)) { setLBox(1); setXlBox(size); } else { @@ -69,13 +69,17 @@ private void updateBmffHeadersBasedOnBox() throws MipamsException { public long calculateSizeFromBox() throws MipamsException { long sum = Long.valueOf(getLBoxSize() + getTBoxSize()) + calculatePayloadSize(); - if (isXBoxRequiredBasedOnSize(sum)) { + if (shouldEnableXlBox(sum)) { sum += getXBoxSize(); } return sum; } + private boolean shouldEnableXlBox(long size) { + return getLBox() == 1 || isXBoxRequiredBasedOnSize(size); + } + private boolean isXBoxRequiredBasedOnSize(long size) { return CoreUtils.numberOfHexCharsToRepresentLong(size) > getLBoxSize() * 2; } diff --git a/jumbf/src/test/java/org/mipams/jumbf/services/BmffBoxServiceTests.java b/jumbf/src/test/java/org/mipams/jumbf/services/BmffBoxServiceTests.java index cf56ce5..5119306 100644 --- a/jumbf/src/test/java/org/mipams/jumbf/services/BmffBoxServiceTests.java +++ b/jumbf/src/test/java/org/mipams/jumbf/services/BmffBoxServiceTests.java @@ -91,6 +91,18 @@ void testParsingLBox() throws IOException { } } + @Test + void testUpdatingBmffHeadersWhenEnablingXlBoxOnSmallBox() throws MipamsException { + JsonBox jsonBox = new JsonBox(); + jsonBox.setLBox(1); + jsonBox.setContent("test".getBytes()); + jsonBox.updateFieldsBasedOnExistingData(); + + long expectedSize = CoreUtils.INT_BYTE_SIZE * 2 + CoreUtils.LONG_BYTE_SIZE + jsonBox.getContent().length; + + assertEquals(expectedSize, jsonBox.getXlBox()); + } + @Test void testUpdatingBmffHeadersOfLongBox() throws MipamsException { MockLongBox mockBox = new MockLongBox();