Skip to content

Commit

Permalink
Support the signaling of Jumbf Box size using XLBox even if the size …
Browse files Browse the repository at this point in the history
…is less than 2^32 bytes (LBox)
  • Loading branch information
nickft committed Oct 29, 2023
1 parent 8370c74 commit 014b8d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions jumbf/src/main/java/org/mipams/jumbf/entities/BmffBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void updateBmffHeadersBasedOnBox() throws MipamsException {

long size = calculateSizeFromBox();

if (isXBoxRequiredBasedOnSize(size)) {
if (shouldEnableXlBox(size)) {
setLBox(1);
setXlBox(size);
} else {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 014b8d5

Please sign in to comment.