From b81b4e1a22004d83e30e6a0c8bc59862ae06fcc2 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Tue, 18 Apr 2023 21:02:55 +1000 Subject: [PATCH 1/2] improve group and property handling Prior to this change, property processing will throw if the association is not found in the item list. That can happen because the assocation is broken, and can also happen on a valid file if the property is associated with a group rather than a single item. This change links the property to either the item or the group, and protects against the case where the association is not valid against either. It also adds display of groups (including entity IDs, and properties) to the filereader UI. --- src/isofile-item-processing.js | 34 ++++++++++++++++++++++++--------- test/filereader.html | 3 +++ test/filereader.js | 35 ++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/isofile-item-processing.js b/src/isofile-item-processing.js index a3f85b9b..04e239af 100644 --- a/src/isofile-item-processing.js +++ b/src/isofile-item-processing.js @@ -1,9 +1,11 @@ ISOFile.prototype.items = []; +ISOFile.prototype.groups = []; /* size of the buffers allocated for samples */ ISOFile.prototype.itemsDataSize = 0; ISOFile.prototype.flattenItemInfo = function() { var items = this.items; + var groups = this.groups; var i, j; var item; var meta = this.meta; @@ -27,6 +29,15 @@ ISOFile.prototype.flattenItemInfo = function() { item.content_type = meta.iinf.item_infos[i].content_type; item.content_encoding = meta.iinf.item_infos[i].content_encoding; } + if (meta.grpl) { + for (i = 0; i < meta.grpl.boxes.length; i++) { + group = {}; + group.id = meta.grpl.boxes[i].group_id; + group.entity_ids = meta.grpl.boxes[i].entity_ids; + group.type = meta.grpl.boxes[i].type; + groups[group.id] = group; + } + } if (meta.iloc) { for(i = 0; i < meta.iloc.items.length; i++) { var offset; @@ -74,16 +85,21 @@ ISOFile.prototype.flattenItemInfo = function() { for (i = 0; i < ipma.associations.length; i++) { var association = ipma.associations[i]; item = items[association.id]; - if (item.properties === undefined) { - item.properties = {}; - item.properties.boxes = []; + if (!item) { + item = groups[association.id]; } - for (j = 0; j < association.props.length; j++) { - var propEntry = association.props[j]; - if (propEntry.property_index > 0 && propEntry.property_index-1 < meta.iprp.ipco.boxes.length) { - var propbox = meta.iprp.ipco.boxes[propEntry.property_index-1]; - item.properties[propbox.type] = propbox; - item.properties.boxes.push(propbox); + if (item) { + if (item.properties === undefined) { + item.properties = {}; + item.properties.boxes = []; + } + for (j = 0; j < association.props.length; j++) { + var propEntry = association.props[j]; + if (propEntry.property_index > 0 && propEntry.property_index-1 < meta.iprp.ipco.boxes.length) { + var propbox = meta.iprp.ipco.boxes[propEntry.property_index-1]; + item.properties[propbox.type] = propbox; + item.properties.boxes.push(propbox); + } } } } diff --git a/test/filereader.html b/test/filereader.html index 407cbfde..8f6d2f30 100644 --- a/test/filereader.html +++ b/test/filereader.html @@ -145,6 +145,7 @@

MP4Box.js / ISOBMFF Box Structure Viewer (see other demo
  • Sample View
  • Item View
  • Segment View
  • +
  • Group View
  • @@ -213,6 +214,8 @@

    MP4Box.js / ISOBMFF Box Structure Viewer (see other demo
    +
    +
    \ No newline at end of file diff --git a/test/filereader.js b/test/filereader.js index 0f39f0e8..ea10a87f 100644 --- a/test/filereader.js +++ b/test/filereader.js @@ -28,12 +28,14 @@ function finalizeAnalyzerUI(fileobj, loadbutton, success) { buildSampleView(); displayMovieInfo(fileobj.mp4boxfile.getInfo(), document.getElementById("movieview"), false); buildSegmentView(fileobj); + buildGroupTable(fileobj.mp4boxfile.groups); } else { resetBoxView(); $("#itemview").html(''); resetSampleView(); $("#movieview").html(''); resetSegmentView(); + $("#groupview").html(''); } } @@ -419,6 +421,39 @@ function buildSegmentView(fileobj) { buildSegmentGraph(sidx, startSeg, endSeg); } +function buildGroupTable(groups) { + var html; + var i, j; + html = ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + for (i in groups) { + var group = groups[i]; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + } + html += ""; + html += "
    Group IDTypeEntities [item ID]Properties [type]
    " + group.id + "" + group.type + "" + group.entity_ids.join() + ""; + if (group.properties) { + for (j = 0; j < group.properties.boxes.length; j++) { + html += "" + group.properties.boxes[j].type + " "; + } + } + html += "
    "; + $("#groupview").html(html); +} + + window.onload = function () { createLoadBar($('#menubar'), "File", "file", file, finalizeAnalyzerUI); From 916981e9eef383813b8bcd637136dbe8a087bcff Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Wed, 28 Jun 2023 16:26:38 +1000 Subject: [PATCH 2/2] update entity group variable names per PR feedback Also revise tab position per feedback. --- src/isofile-item-processing.js | 16 ++++++++-------- test/filereader.html | 7 ++++--- test/filereader.js | 26 +++++++++++++------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/isofile-item-processing.js b/src/isofile-item-processing.js index 04e239af..0fbbd748 100644 --- a/src/isofile-item-processing.js +++ b/src/isofile-item-processing.js @@ -1,11 +1,11 @@ ISOFile.prototype.items = []; -ISOFile.prototype.groups = []; +ISOFile.prototype.entity_groups = []; /* size of the buffers allocated for samples */ ISOFile.prototype.itemsDataSize = 0; ISOFile.prototype.flattenItemInfo = function() { var items = this.items; - var groups = this.groups; + var entity_groups = this.entity_groups; var i, j; var item; var meta = this.meta; @@ -31,11 +31,11 @@ ISOFile.prototype.flattenItemInfo = function() { } if (meta.grpl) { for (i = 0; i < meta.grpl.boxes.length; i++) { - group = {}; - group.id = meta.grpl.boxes[i].group_id; - group.entity_ids = meta.grpl.boxes[i].entity_ids; - group.type = meta.grpl.boxes[i].type; - groups[group.id] = group; + entity_group = {}; + entity_group.id = meta.grpl.boxes[i].group_id; + entity_group.entity_ids = meta.grpl.boxes[i].entity_ids; + entity_group.type = meta.grpl.boxes[i].type; + entity_groups[entity_group.id] = entity_group; } } if (meta.iloc) { @@ -86,7 +86,7 @@ ISOFile.prototype.flattenItemInfo = function() { var association = ipma.associations[i]; item = items[association.id]; if (!item) { - item = groups[association.id]; + item = entity_groups[association.id]; } if (item) { if (item.properties === undefined) { diff --git a/test/filereader.html b/test/filereader.html index 8f6d2f30..aa9e7caa 100644 --- a/test/filereader.html +++ b/test/filereader.html @@ -144,8 +144,9 @@

    MP4Box.js / ISOBMFF Box Structure Viewer (see other demo
  • Box View
  • Sample View
  • Item View
  • +
  • Entity Group View
  • Segment View
  • -
  • Group View
  • +
    @@ -202,6 +203,8 @@

    MP4Box.js / ISOBMFF Box Structure Viewer (see other demo
    +
    +