diff --git a/src/byte-helpers.js b/src/byte-helpers.js index 22d5a6c..80fd5b6 100644 --- a/src/byte-helpers.js +++ b/src/byte-helpers.js @@ -35,18 +35,24 @@ export const toUint8 = function(bytes) { export const toHexString = function(bytes) { bytes = toUint8(bytes); + let str = ''; - return bytes.reduce(function(acc, b) { - return acc + padStart(b.toString(16), 2, '0'); - }, ''); + for (let i = 0; i < bytes.length; i++) { + str += padStart(bytes[i].toString(16), 2, '0'); + } + + return str; }; export const toBinaryString = function(bytes) { bytes = toUint8(bytes); + let str = ''; + + for (let i = 0; i < bytes.length; i++) { + str += padStart(bytes[i].toString(2), 8, '0'); + } - return bytes.reduce(function(acc, b) { - return acc + padStart(b.toString(2), 8, '0'); - }, ''); + return str; }; const BigInt = window.BigInt || Number; diff --git a/src/codec-helpers.js b/src/codec-helpers.js index 4251191..372869d 100644 --- a/src/codec-helpers.js +++ b/src/codec-helpers.js @@ -85,16 +85,18 @@ export const getHvcCodec = function(bytes) { codec += levelId; - const constraints = constraintIds.reduce((acc, v) => { + let constraints = ''; + + for (let i = 0; i < constraintIds.length; i++) { + const v = constraintIds[i]; + if (v) { - if (acc) { - acc += '.'; + if (constraints) { + constraints += '.'; } - acc += v.toString(16); + constraints += v.toString(16); } - - return acc; - }, ''); + } if (constraints) { codec += `.${constraints}`; diff --git a/test/container.test.js b/test/container.test.js index da84d30..cf4e2c6 100644 --- a/test/container.test.js +++ b/test/container.test.js @@ -71,14 +71,14 @@ const h265seq = toUint8([ 0x00, 0x00, 0x00, 0x01 ]); -const h264shortnal = Array.prototype.slice.call(testData.h264.slice()); +const h264shortnal = Array.prototype.slice.call(testData.h264); // remove 0x00 from the front h264shortnal.splice(0, 1); // remove 0x00 from the back h264shortnal.splice(h264shortnal.length - 2, 1); -const h265shortnal = Array.prototype.slice.call(testData.h265.slice()); +const h265shortnal = Array.prototype.slice.call(testData.h265); // remove 0x00 from the front h265shortnal.splice(0, 1);