Skip to content

Commit

Permalink
FLVDemuxer: Support negative cts offset
Browse files Browse the repository at this point in the history
  • Loading branch information
xqq committed Dec 24, 2017
1 parent 6a1274b commit c109921
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/demux/flv-demuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ function ReadBig32(array, index) {
(array[index + 3]));
}

function OverflowPlus(a, b) {
let value = a + b;
if (value > 0xFFFFFFFF) {
value = value - 0xFFFFFFFF - 1;
} else if (value < 0) {
value = 0xFFFFFFFF + value + 1;
}
return value;
}

function ReadBigSI24FromView(v, index) {
let val = (v.getUint8(index) << 16) |
(v.getUint8(index + 1) << 8) |
(v.getUint8(index + 2));
val = OverflowPlus(val, 0xFF800000) ^ 0xFF800000;
return val;
}


class FLVDemuxer {

Expand Down Expand Up @@ -825,7 +843,7 @@ class FLVDemuxer {
let v = new DataView(arrayBuffer, dataOffset, dataSize);

let packetType = v.getUint8(0);
let cts = v.getUint32(0, !le) & 0x00FFFFFF;
let cts = ReadBigSI24FromView(v, 1);

if (packetType === 0) { // AVCDecoderConfigurationRecord
this._parseAVCDecoderConfigurationRecord(arrayBuffer, dataOffset + 4, dataSize - 4);
Expand Down

0 comments on commit c109921

Please sign in to comment.