Skip to content

Commit

Permalink
* v0.3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
kreopt committed Nov 4, 2017
1 parent fa30ebf commit f87614e
Show file tree
Hide file tree
Showing 15 changed files with 369 additions and 245 deletions.
402 changes: 252 additions & 150 deletions example/streamedian.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/streamedian.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "streamedian",
"version": "0.3.8",
"version": "0.3.9",
"description": "HTML5 MSE RTSP player over websockets",
"license": "Apache2",
"author": "Streamedian <[email protected]> (http://streamedian.com/)",
Expand Down
7 changes: 7 additions & 0 deletions src/client/rtsp/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ class AuthError extends Error {
}
}

export class RTSPError extends Error {
constructor(data) {
super(data.msg);
this.data = data;
}
}

export class RTSPClientSM extends StateMachine {
static get USER_AGENT() {return 'SFRtsp 0.3';}
static get STATE_INITIAL() {return 1 << 0;}
Expand Down
1 change: 1 addition & 0 deletions src/client/rtsp/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {getTagged} from '../../deps/bp_logger.js';

import {RTSPClientSM as RTSPClient} from './client.js';
import {Url} from '../../core/util/url.js';
import {RTSPError} from "./client";

const LOG_TAG = "rtsp:stream";
const Log = getTagged(LOG_TAG);
Expand Down
10 changes: 10 additions & 0 deletions src/core/base_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,14 @@ export class BaseClient {
onDisconnected() {
this.connected = false;
}

queryCredentials() {
return Promise.resolve();
}

setCredentials(user, password) {
this.endpoint.user = user;
this.endpoint.pass = password;
this.endpoint.auth = `${user}:${password}`;
}
}
2 changes: 2 additions & 0 deletions src/core/elementary/NALU.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export class NALU {
static get SEI() {return 6;}
static get SPS() {return 7;}
static get PPS() {return 8;}
static get STAP_A() {return 24;}
static get STAP_B() {return 25;}
static get FU_A() {return 28;}
static get FU_B() {return 29;}

Expand Down
156 changes: 77 additions & 79 deletions src/core/elementary/NALUAsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,101 +5,99 @@ import {NALU} from './NALU.js';
export class NALUAsm {

constructor() {
this.nalu_l = null;
this.nalu_t = null;
this.dts_l = 0;
this.fragmented_nalu = null;
}

shiftTemp(val) {
let ret;
if (this.nalu_t != null) {
ret = this.nalu_t;
this.nalu_t = val;
} else {
ret = val;

static parseNALHeader(hdr) {
return {
nri: hdr & 0x60,
type: hdr & 0x1F
}
return ret ? [ret] : null;
}

onNALUFragment(rawData, dts, pts) {
parseSingleNALUPacket(rawData, header, dts, pts) {
return new NALU(header.type, header.nri, rawData.subarray(0), dts, pts);
}

parseAggregationPacket(rawData, header, dts, pts) {
let data = new DataView(rawData.buffer, rawData.byteOffset, rawData.byteLength);
let nal_start_idx = 0;
let don = null;
if (NALU.STAP_B === header.type) {
don = data.getUint16(nal_start_idx);
nal_start_idx += 2;
}
let ret = [];
while (nal_start_idx < data.byteLength) {
let size = data.getUint16(nal_start_idx);
nal_start_idx += 2;
let header = NALUAsm.parseNALHeader(data.getInt8(nal_start_idx));
nal_start_idx++;
let nalu = this.parseSingleNALUPacket(rawData.subarray(nal_start_idx, nal_start_idx+size), header, dts, pts);
if (nalu !== null) {
ret.push(nalu);
}
nal_start_idx+=size;
}
return ret;
}

let nalhdr = data.getUint8(0);
parseFragmentationUnit(rawData, header, dts, pts) {
let data = new DataView(rawData.buffer, rawData.byteOffset, rawData.byteLength);
let nal_start_idx = 0;
let fu_header = data.getUint8(nal_start_idx);
let is_start = (fu_header & 0x80) >>> 7;
let is_end = (fu_header & 0x40) >>> 6;
let payload_type = fu_header & 0x1F;
let ret = null;

let nri = nalhdr & 0x60;
let naltype = nalhdr & 0x1F;
nal_start_idx++;
let don = 0;
if (NALU.FU_B === header.type) {
don = data.getUint16(nal_start_idx);
nal_start_idx += 2;
}

let nal_start_idx = 1;
let ret = null;
if (is_start) {
this.fragmented_nalu = new NALU(payload_type, header.nri, rawData.subarray(nal_start_idx), dts, pts);
} else {
if (this.fragmented_nalu && this.fragmented_nalu.ntype === payload_type) {
this.fragmented_nalu.appendData(rawData.subarray(nal_start_idx));

if ((7 > naltype && 0 < naltype) || (28 > naltype && 8 < naltype)) {
if (this.dts_l != dts) {
this.dts_l = dts;
ret = this.shiftTemp(this.nalu_l);
this.nalu_l = new NALU(naltype, nri, rawData.subarray(nal_start_idx), dts, pts);
} else {
ret = this.shiftTemp(null);
if (this.nalu_l != null) {
this.nalu_l.appendData(new Uint8Array([0, 0, 1]));
this.nalu_l.appendData(rawData.subarray(0));
if (is_end) {
ret = this.fragmented_nalu;
this.fragmented_nalu = null;
return ret;
}
}
return ret;
} else if (naltype == NALU.SPS || naltype == NALU.PPS) {
return [new NALU(naltype, nri, rawData.subarray(nal_start_idx), dts, pts)];
} else if (NALU.FU_A == naltype || NALU.FU_B == naltype) {
let nalfrag = data.getUint8(1);
let nfstart = (nalfrag & 0x80) >>> 7;
let nfend = (nalfrag & 0x40) >>> 6;
let nftype = nalfrag & 0x1F;
}
return null;
}

nal_start_idx++;
let nfdon = 0;
if (NALU.FU_B === naltype) {
nfdon = data.getUint16(2);
nal_start_idx += 2;
}
if (this.dts_l != dts) {
if (nfstart) {
ret = this.shiftTemp(this.nalu_l);
this.nalu_l = new NALU(nftype, nri + nftype, rawData.subarray(nal_start_idx), dts, pts);
this.dts_l = dts;
} else {
ret = this.shiftTemp(null);
console.log("fu packet error");
}
} else {
if (this.nalu_l != null) {
if (this.nalu_l.ntype == nftype) {
ret = this.shiftTemp(null);
if (nfstart) {
this.nalu_l.appendData(new Uint8Array([0, 0, 1, nri + nftype]));
this.nalu_l.appendData(rawData.subarray(nal_start_idx));
} else {
this.nalu_l.appendData(rawData.subarray(nal_start_idx));
}
} else {
if (nfstart) {
ret = this.shiftTemp(this.nalu_l);
this.nalu_l = new NALU(nftype, nri + nftype, rawData.subarray(nal_start_idx), dts, pts);
this.dts_l = dts;
} else {
ret = this.shiftTemp(null);
console.log("fu packet error");
}
}
} else {
ret = this.shiftTemp(null);
console.log("fu packet start without head");
}
}
return ret;
onNALUFragment(rawData, dts, pts) {

let data = new DataView(rawData.buffer, rawData.byteOffset, rawData.byteLength);

let header = NALUAsm.parseNALHeader(data.getUint8(0));

let nal_start_idx = 1;

let unit = null;
if (header.type > 0 && header.type < 24) {
unit = this.parseSingleNALUPacket(rawData.subarray(nal_start_idx), header, dts, pts);
} else if (NALU.FU_A === header.type || NALU.FU_B === header.type) {
unit = this.parseFragmentationUnit(rawData.subarray(nal_start_idx), header, dts, pts);
} else if (NALU.STAP_A === header.type || NALU.STAP_B === header.type) {
return this.parseAggregationPacket(rawData.subarray(nal_start_idx), header, dts, pts);
} else {
/* 30 - 31 is undefined, ignore those (RFC3984). */
Log.log('Undefined NAL unit, type: ' + naltype);
ret = this.shiftTemp(null);
return ret;
Log.log('Undefined NAL unit, type: ' + header.type);
return null;
}
if (unit) {
return [unit];
}
return null;
}
}
3 changes: 3 additions & 0 deletions src/core/parsers/h264.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export class H264Parser {
break;
default:
}
if (unit.nri!=0) {
push=true;
}
return push;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/parsers/sdp.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class SDPParser {
}

_parseOrigin(line) {
let matches = line.match(/^o=([^ ]+) ([0-9]+) ([0-9]+) (IN) (IP4|IP6) ([^ ]+)$/);
let matches = line.match(/^o=([^ ]+) (-?[0-9]+) (-?[0-9]+) (IN) (IP4|IP6) ([^ ]+)$/);
if (!matches || !matches.length) {
Log.log('\'o=\' (Origin) formatted incorrectly: ' + line);
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/core/remuxer/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export class BaseRemuxer {
}

init(initPTS, initDTS, shouldInitialize=true) {
this.initPTS = Math.min(initPTS, this.samples[0].dts - this.unscaled(this.timeOffset));
this.initDTS = Math.min(initDTS, this.samples[0].dts - this.unscaled(this.timeOffset));
this.initPTS = Math.min(initPTS, this.samples[0].dts /*- this.unscaled(this.timeOffset)*/);
this.initDTS = Math.min(initDTS, this.samples[0].dts /*- this.unscaled(this.timeOffset)*/);
Log.debug(`Initial pts=${this.initPTS} dts=${this.initDTS} offset=${this.unscaled(this.timeOffset)}`);
this.initialized = shouldInitialize;
}
Expand Down
18 changes: 9 additions & 9 deletions src/core/remuxer/h264.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ export class H264Remuxer extends BaseRemuxer {
if (this.lastGopDTS < nalu.dts) {
this.gop.sort(BaseRemuxer.dtsSortFunc);
for (let unit of this.gop) {
if (this.h264.parseNAL(unit)){
if (this.firstUnit) {
unit.ntype = 5;//NALU.IDR;
this.firstUnit = false;
}
if (super.remux.call(this, unit)) {
this.mp4track.len += unit.getSize();
}
// if (this.firstUnit) {
// unit.ntype = 5;//NALU.IDR;
// this.firstUnit = false;
// }
if (super.remux.call(this, unit)) {
this.mp4track.len += unit.getSize();
}
}
this.gop = [];
this.lastGopDTS = nalu.dts
}
this.gop.push(nalu);
if (this.h264.parseNAL(nalu)) {
this.gop.push(nalu);
}
}

getPayload() {
Expand Down
2 changes: 1 addition & 1 deletion src/core/remuxer/remuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class Remuxer {
initmse.push(this.initMSE(track_type, track.mp4track.codec));
}
this.initialized = true;
Promise.all(initmse).then(()=>{
return Promise.all(initmse).then(()=>{
//this.mse.play();
this.enabled = true;
});
Expand Down
2 changes: 1 addition & 1 deletion src/core/util/exp-golomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class ExpGolomb {
} else {
count -= this.bitsAvailable;
skipBytes = count >> 3;
count -= (skipBytes >> 3);
count -= (skipBytes << 3);
this.bytesAvailable -= skipBytes;
this.loadWord();
this.word <<= count;
Expand Down
1 change: 1 addition & 0 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class WSPlayer {
}
};
this.errorHandler = opts.errorHandler || null;
this.queryCredentials = opts.queryCredentials || null;

this.modules = {};
for (let module of modules) {
Expand Down

0 comments on commit f87614e

Please sign in to comment.