Skip to content

Commit

Permalink
Merge pull request #412 from paulhiggs/issue-399
Browse files Browse the repository at this point in the history
add string formatters so [Object Object] does not show in output
  • Loading branch information
DenizUgur authored Nov 8, 2024
2 parents 685f491 + e9f0976 commit 57463b4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/parsing/avcC.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
function printPS(ps) {
var str = "<table class='inner-table'>";
str += "<thead><tr><th>length</th><th>nalu_data</th></tr></thead>";
str += "<tbody>";

for (var i=0; i < ps.length; i++) {
var nalu = ps[i];
str += "<tr>";
str += "<td>"+nalu.length+"</td>";
str += "<td>";
str += nalu.nalu.reduce(function(str, byte) {
return str + byte.toString(16).padStart(2, "0");
}, "0x");
str += "</td></tr>";
}
str += "</tbody></table>";
return str;
}

BoxParser.createBoxCtor("avcC", function(stream) {
var i;
var toparse;
Expand All @@ -9,6 +28,9 @@ BoxParser.createBoxCtor("avcC", function(stream) {
this.nb_SPS_nalus = (stream.readUint8() & 0x1F);
toparse = this.size - this.hdr_size - 6;
this.SPS = [];
this.SPS.toString = function () {
return printPS(this);
}
for (i = 0; i < this.nb_SPS_nalus; i++) {
this.SPS[i] = {};
this.SPS[i].length = stream.readUint16();
Expand All @@ -18,6 +40,9 @@ BoxParser.createBoxCtor("avcC", function(stream) {
this.nb_PPS_nalus = stream.readUint8();
toparse--;
this.PPS = [];
this.PPS.toString = function () {
return printPS(this);
}
for (i = 0; i < this.nb_PPS_nalus; i++) {
this.PPS[i] = {};
this.PPS[i].length = stream.readUint16();
Expand Down
23 changes: 23 additions & 0 deletions src/parsing/hvcC.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ BoxParser.createBoxCtor("hvcC", function(stream) {
this.lengthSizeMinusOne = (tmp_byte & 0X3);

this.nalu_arrays = [];
this.nalu_arrays.toString = function () {
var str = "<table class='inner-table'>";
str += "<thead><tr><th>completeness</th><th>nalu_type</th><th>nalu_data</th></tr></thead>";
str += "<tbody>";

for (var i=0; i<this.length; i++) {
var nalu_array = this[i];
str += "<tr>";
str += "<td rowspan='"+nalu_array.length+"'>"+nalu_array.completeness+"</td>";
str += "<td rowspan='"+nalu_array.length+"'>"+nalu_array.nalu_type+"</td>";
for (var j=0; j<nalu_array.length; j++) {
var nalu = nalu_array[j];
if (j !== 0) str += "<tr>";
str += "<td>";
str += nalu.data.reduce(function(str, byte) {
return str + byte.toString(16).padStart(2, "0");
}, "0x");
str += "</td></tr>";
}
}
str += "</tbody></table>";
return str;
}
var numOfArrays = stream.readUint8();
for (i = 0; i < numOfArrays; i++) {
var nalu_array = [];
Expand Down
5 changes: 5 additions & 0 deletions test/filereader.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@
vertical-align: middle;
}

.inner-table {
width: unset;
margin: 0;
}

</style>
<link rel="stylesheet" href="style.css" />
</head>
Expand Down

0 comments on commit 57463b4

Please sign in to comment.