diff --git a/src/demux/amf-parser.js b/src/demux/amf-parser.js index b2e2c608..cc92562c 100644 --- a/src/demux/amf-parser.js +++ b/src/demux/amf-parser.js @@ -20,11 +20,7 @@ import Log from '../utils/logger.js'; import decodeUTF8 from '../utils/utf8-conv.js'; import {IllegalStateException} from '../utils/exception.js'; -let le = (function () { - let buf = new ArrayBuffer(2); - (new DataView(buf)).setInt16(0, 256, true); // little-endian write - return (new Int16Array(buf))[0] === 256; // platform-spec read, if equal then LE -})(); +let le = false; // amf use big-endian class AMF { @@ -70,7 +66,7 @@ class AMF { throw new IllegalStateException('Data not enough when parse String'); } let v = new DataView(arrayBuffer, dataOffset, dataSize); - let length = v.getUint16(0, !le); + let length = v.getUint16(0, le); let str; if (length > 0) { @@ -90,7 +86,7 @@ class AMF { throw new IllegalStateException('Data not enough when parse LongString'); } let v = new DataView(arrayBuffer, dataOffset, dataSize); - let length = v.getUint32(0, !le); + let length = v.getUint32(0, le); let str; if (length > 0) { @@ -110,8 +106,8 @@ class AMF { throw new IllegalStateException('Data size invalid when parse Date'); } let v = new DataView(arrayBuffer, dataOffset, dataSize); - let timestamp = v.getFloat64(0, !le); - let localTimeOffset = v.getInt16(8, !le); + let timestamp = v.getFloat64(0, le); + let localTimeOffset = v.getInt16(8, le); timestamp += localTimeOffset * 60 * 1000; // get UTC time return { @@ -135,7 +131,7 @@ class AMF { try { switch (type) { case 0: // Number(Double) type - value = v.getFloat64(1, !le); + value = v.getFloat64(1, le); offset += 8; break; case 1: { // Boolean type @@ -153,7 +149,7 @@ class AMF { case 3: { // Object(s) type value = {}; let terminal = 0; // workaround for malformed Objects which has missing ScriptDataObjectEnd - if ((v.getUint32(dataSize - 4, !le) & 0x00FFFFFF) === 9) { + if ((v.getUint32(dataSize - 4, le) & 0x00FFFFFF) === 9) { terminal = 3; } while (offset < dataSize - 4) { // 4 === type(UI8) + ScriptDataObjectEnd(UI24) @@ -164,7 +160,7 @@ class AMF { offset += amfobj.size; } if (offset <= dataSize - 3) { - let marker = v.getUint32(offset - 1, !le) & 0x00FFFFFF; + let marker = v.getUint32(offset - 1, le) & 0x00FFFFFF; if (marker === 9) { offset += 3; } @@ -175,7 +171,7 @@ class AMF { value = {}; offset += 4; // ECMAArrayLength(UI32) let terminal = 0; // workaround for malformed MixedArrays which has missing ScriptDataObjectEnd - if ((v.getUint32(dataSize - 4, !le) & 0x00FFFFFF) === 9) { + if ((v.getUint32(dataSize - 4, le) & 0x00FFFFFF) === 9) { terminal = 3; } while (offset < dataSize - 8) { // 8 === type(UI8) + ECMAArrayLength(UI32) + ScriptDataVariableEnd(UI24) @@ -186,7 +182,7 @@ class AMF { offset += amfvar.size; } if (offset <= dataSize - 3) { - let marker = v.getUint32(offset - 1, !le) & 0x00FFFFFF; + let marker = v.getUint32(offset - 1, le) & 0x00FFFFFF; if (marker === 9) { offset += 3; } @@ -201,7 +197,7 @@ class AMF { case 10: { // Strict array type // ScriptDataValue[n]. NOTE: according to video_file_format_spec_v10_1.pdf value = []; - let strictArrayLength = v.getUint32(1, !le); + let strictArrayLength = v.getUint32(1, le); offset += 4; for (let i = 0; i < strictArrayLength; i++) { let val = AMF.parseValue(arrayBuffer, dataOffset + offset, dataSize - offset); diff --git a/src/demux/flv-demuxer.js b/src/demux/flv-demuxer.js index 9cd1e27c..9f6f9af5 100644 --- a/src/demux/flv-demuxer.js +++ b/src/demux/flv-demuxer.js @@ -107,11 +107,7 @@ class FLVDemuxer { this._videoTrack = {type: 'video', id: 1, sequenceNumber: 0, samples: [], length: 0}; this._audioTrack = {type: 'audio', id: 2, sequenceNumber: 0, samples: [], length: 0}; - this._littleEndian = (function () { - let buf = new ArrayBuffer(2); - (new DataView(buf)).setInt16(0, 256, true); // little-endian write - return (new Int16Array(buf))[0] === 256; // platform-spec read, if equal then LE - })(); + this._littleEndian = false; // flv use big-endian } destroy() { @@ -289,7 +285,7 @@ class FLVDemuxer { } let v = new DataView(chunk, offset); - let prevTagSize0 = v.getUint32(0, !le); + let prevTagSize0 = v.getUint32(0, le); if (prevTagSize0 !== 0) { Log.w(this.TAG, 'PrevTagSize0 !== 0 !!!'); } @@ -307,7 +303,7 @@ class FLVDemuxer { } let tagType = v.getUint8(0); - let dataSize = v.getUint32(0, !le) & 0x00FFFFFF; + let dataSize = v.getUint32(0, le) & 0x00FFFFFF; if (offset + 11 + dataSize + 4 > chunk.byteLength) { // data not enough for parsing actual data body @@ -328,7 +324,7 @@ class FLVDemuxer { let timestamp = ts0 | (ts1 << 8) | (ts2 << 16) | (ts3 << 24); - let streamId = v.getUint32(7, !le) & 0x00FFFFFF; + let streamId = v.getUint32(7, le) & 0x00FFFFFF; if (streamId !== 0) { Log.w(this.TAG, 'Meet tag which has StreamID != 0!'); } @@ -347,7 +343,7 @@ class FLVDemuxer { break; } - let prevTagSize = v.getUint32(11 + dataSize, !le); + let prevTagSize = v.getUint32(11 + dataSize, le); if (prevTagSize !== 11 + dataSize) { Log.w(this.TAG, `Invalid PrevTagSize ${prevTagSize}`); } @@ -855,7 +851,7 @@ class FLVDemuxer { let v = new DataView(arrayBuffer, dataOffset, dataSize); let packetType = v.getUint8(0); - let cts_unsigned = v.getUint32(0, !le) & 0x00FFFFFF; + let cts_unsigned = v.getUint32(0, le) & 0x00FFFFFF; let cts = (cts_unsigned << 8) >> 8; // convert to 24-bit signed int if (packetType === 0) { // AVCDecoderConfigurationRecord @@ -925,7 +921,7 @@ class FLVDemuxer { let offset = 6; for (let i = 0; i < spsCount; i++) { - let len = v.getUint16(offset, !le); // sequenceParameterSetLength + let len = v.getUint16(offset, le); // sequenceParameterSetLength offset += 2; if (len === 0) { @@ -1010,7 +1006,7 @@ class FLVDemuxer { offset++; for (let i = 0; i < ppsCount; i++) { - let len = v.getUint16(offset, !le); // pictureParameterSetLength + let len = v.getUint16(offset, le); // pictureParameterSetLength offset += 2; if (len === 0) { @@ -1055,7 +1051,7 @@ class FLVDemuxer { break; // data not enough for next Nalu } // Nalu with length-header (AVC1) - let naluSize = v.getUint32(offset, !le); // Big-Endian read + let naluSize = v.getUint32(offset, le); // Big-Endian read if (lengthSize === 3) { naluSize >>>= 8; }