Skip to content

Commit

Permalink
readme file updated
Browse files Browse the repository at this point in the history
  • Loading branch information
samirkumardas committed May 13, 2021
1 parent 5b331d8 commit ba5e06f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5,506 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ h264_feeder.pipe(jmuxer.createStream()).pipe(http_or_ws_or_any);
| ------------- |:-------------:| -----:|
| feed | data object | object properites may have audio, video and duration. At least one media property i.e audio or video must be provided. If no duration is provided, it will calculate duration based on fps value |
| createStream | - | Get a writeable stream to feed buffer. Available on NodeJS only |
| reset | - | Reset the jmuxer and start over |
| destroy | - | Destroy the jmuxer instance and release the resources |

**Typescript definition**
Expand Down
95 changes: 55 additions & 40 deletions dist/jmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,6 @@

this.remuxer = remuxer;
this.track = remuxer.mp4track;
this.isSafari = remuxer.env == 'browser' && /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);
}

_createClass(H264Parser, [{
Expand Down Expand Up @@ -931,10 +930,7 @@
}
}

if (!this.isSafari) {
push = true;
}

push = true;
break;

case NALU.AUD:
Expand Down Expand Up @@ -1651,7 +1647,7 @@

var _super = _createSuper(AACRemuxer);

function AACRemuxer(timescale, env) {
function AACRemuxer(timescale) {
var _this;

_classCallCheck(this, AACRemuxer);
Expand All @@ -1660,7 +1656,6 @@
_this.readyToDecode = false;
_this.nextDts = 0;
_this.dts = 0;
_this.env = env;
_this.mp4track = {
id: BaseRemuxer.getTrackID(),
type: 'audio',
Expand All @@ -1686,6 +1681,8 @@
this.mp4track.channelCount = '';
this.mp4track.config = '';
this.mp4track.timescale = this.timescale;
this.nextDts = 0;
this.dts = 0;
}
}, {
key: "remux",
Expand Down Expand Up @@ -1763,7 +1760,7 @@

var _super = _createSuper(H264Remuxer);

function H264Remuxer(timescale, env) {
function H264Remuxer(timescale) {
var _this;

_classCallCheck(this, H264Remuxer);
Expand All @@ -1772,7 +1769,6 @@
_this.readyToDecode = false;
_this.nextDts = 0;
_this.dts = 0;
_this.env = env;
_this.mp4track = {
id: BaseRemuxer.getTrackID(),
type: 'video',
Expand All @@ -1797,6 +1793,8 @@
this.readyToDecode = false;
this.mp4track.sps = '';
this.mp4track.pps = '';
this.nextDts = 0;
this.dts = 0;
}
}, {
key: "remux",
Expand Down Expand Up @@ -1934,12 +1932,12 @@
key: "addTrack",
value: function addTrack(type) {
if (type === 'video' || type === 'both') {
this.tracks.video = new H264Remuxer(this.timescale, this.env);
this.tracks.video = new H264Remuxer(this.timescale);
this.trackTypes.push('video');
}

if (type === 'audio' || type === 'both') {
this.tracks.audio = new AACRemuxer(this.timescale, this.env);
this.tracks.audio = new AACRemuxer(this.timescale);
this.trackTypes.push('audio');
}
}
Expand Down Expand Up @@ -2308,7 +2306,6 @@
this.node = typeof this.options.node === 'string' ? document.getElementById(this.options.node) : this.options.node;
this.mseReady = false;
this.setupMSE();
this.sourceBuffers = {};
}
}, {
key: "createStream",
Expand Down Expand Up @@ -2340,12 +2337,26 @@

this.isMSESupported = !!window.MediaSource;
this.mediaSource = new MediaSource();
this.node.src = URL.createObjectURL(this.mediaSource);
this.url = URL.createObjectURL(this.mediaSource);
this.node.src = this.url;
this.mseEnded = false;
this.mediaSource.addEventListener('sourceopen', this.onMSEOpen.bind(this));
this.mediaSource.addEventListener('sourceclose', this.onMSEClose.bind(this));
this.mediaSource.addEventListener('webkitsourceopen', this.onMSEOpen.bind(this));
this.mediaSource.addEventListener('webkitsourceclose', this.onMSEClose.bind(this));
}
}, {
key: "endMSE",
value: function endMSE() {
if (!this.mseEnded) {
try {
this.mseEnded = true;
this.mediaSource.endOfStream();
} catch (e) {
error('mediasource is not available to end');
}
}
}
}, {
key: "feed",
value: function feed(data) {
Expand Down Expand Up @@ -2523,18 +2534,6 @@
value: function destroy() {
this.stopInterval();

if (this.mediaSource) {
try {
if (this.bufferControllers) {
this.mediaSource.endOfStream();
}
} catch (e) {
error("mediasource is not available to end ".concat(e.message));
}

this.mediaSource = null;
}

if (this.stream) {
this.remuxController.flush();
this.stream.push(null);
Expand All @@ -2552,11 +2551,37 @@
}

this.bufferControllers = null;
this.endMSE();
}

this.node = false;
this.mseReady = false;
this.videoStarted = false;
this.mediaSource = null;
}
}, {
key: "reset",
value: function reset() {
this.node.pause();

if (this.remuxController) {
this.remuxController.reset();
}

if (this.bufferControllers) {
for (var type in this.bufferControllers) {
this.bufferControllers[type].destroy();
}

this.bufferControllers = null;
this.endMSE();
}

if (this.env == 'browser') {
this.initBrowser();
}

log('JMuxer was reset');
}
}, {
key: "createBuffer",
Expand All @@ -2574,7 +2599,6 @@

var sb = this.mediaSource.addSourceBuffer("".concat(type, "/mp4; codecs=\"").concat(track.mp4track.codec, "\""));
this.bufferControllers[type] = new BufferController(sb, type);
this.sourceBuffers[type] = sb;
this.bufferControllers[type].on('error', this.onBufferError.bind(this));
}
}
Expand Down Expand Up @@ -2665,6 +2689,7 @@
this.options.onReady.call(null);
}

URL.revokeObjectURL(this.url);
this.createBuffer();
}
}, {
Expand All @@ -2676,25 +2701,15 @@
}, {
key: "onBufferError",
value: function onBufferError(data) {
if (typeof this.options.onError === 'function') {
this.options.onError.call(null, data);
}

if (data.name == 'QuotaExceeded') {
this.bufferControllers[data.type].initCleanup(this.node.currentTime);
return;
} else {
this.endMSE();
}

if (this.mediaSource.sourceBuffers.length > 0 && this.sourceBuffers[data.type]) {
this.mediaSource.removeSourceBuffer(this.sourceBuffers[data.type]);
}

if (this.mediaSource.sourceBuffers.length == 0) {
try {
this.mediaSource.endOfStream();
} catch (e) {
error('mediasource is not available to end');
}
if (typeof this.options.onError === 'function') {
this.options.onError.call(null, data);
}
}
}]);
Expand Down
Loading

0 comments on commit ba5e06f

Please sign in to comment.