Skip to content

Commit

Permalink
Decoder.clearSequenceHeader & options.onSocketMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Dec 15, 2019
1 parent 9cf21d3 commit 26f97f4
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 10 deletions.
1 change: 1 addition & 0 deletions build.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ emcc \
'_mpeg1_decoder_set_index',
'_mpeg1_decoder_did_write',
'_mpeg1_decoder_has_sequence_header',
'_mpeg1_decoder_clear_sequence_header',
'_mpeg1_decoder_get_frame_rate',
'_mpeg1_decoder_get_coded_size',
'_mpeg1_decoder_get_width',
Expand Down
9 changes: 4 additions & 5 deletions jsmpeg.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ BaseDecoder.prototype.getCurrentTime = function() {
return this.decodedTime;
};

BaseDecoder.prototype.clearSequenceHeader = function() {
};

return BaseDecoder;

})();
Expand Down
14 changes: 14 additions & 0 deletions src/mpeg1-wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var MPEG1WASM = function(options) {
JSMpeg.Decoder.Base.call(this, options);

this.onDecodeCallback = options.onVideoDecode;
this.onDecodeSequenceHeaderCallback = options.onVideoDecodeSequenceHeader;

this.module = options.wasmModule;

this.bufferSize = options.videoBufferSize || 512*1024;
Expand Down Expand Up @@ -91,6 +93,18 @@ MPEG1WASM.prototype.loadSequnceHeader = function() {
if (this.decodeFirstFrame) {
this.decode();
}

if (this.onDecodeSequenceHeaderCallback) {
this.onDecodeSequenceHeaderCallback(this);
}
};

MPEG1WASM.prototype.clearSequenceHeader = function() {
if (!this.decoder) {
return false
}
this.hasSequenceHeader = false;
this.functions._mpeg1_decoder_clear_sequence_header(this.decoder);
};

MPEG1WASM.prototype.decode = function() {
Expand Down
12 changes: 10 additions & 2 deletions src/mpeg1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var MPEG1 = function(options) {
JSMpeg.Decoder.Base.call(this, options);

this.onDecodeCallback = options.onVideoDecode;

this.onDecodeSequenceHeaderCallback = options.onVideoDecodeSequenceHeader;

var bufferSize = options.videoBufferSize || 512*1024;
var bufferMode = options.streaming
? JSMpeg.BitBuffer.MODE.EVICT
Expand Down Expand Up @@ -114,7 +115,14 @@ MPEG1.prototype.decodeSequenceHeader = function() {
}

this.hasSequenceHeader = true;
};
if (this.onDecodeSequenceHeaderCallback) {
this.onDecodeSequenceHeaderCallback(this);
}
};

MPEG1.prototype.clearSequenceHeader = function() {
this.hasSequenceHeader = false;
}

MPEG1.prototype.initBuffers = function() {
this.intraQuantMatrix = MPEG1.DEFAULT_INTRA_QUANT_MATRIX;
Expand Down
4 changes: 4 additions & 0 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ var Player = function(url, options) {

this.demuxer.connect(JSMpeg.Demuxer.TS.STREAM.VIDEO_1, this.video);
this.video.connect(this.renderer);

if (options.streaming) {
this.source.video = this.video;
}
}

if (options.audio !== false && JSMpeg.AudioOutput.WebAudio.IsSupported()) {
Expand Down
15 changes: 15 additions & 0 deletions src/wasm/mpeg1.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,21 @@ int mpeg1_decoder_has_sequence_header(mpeg1_decoder_t *self) {
return self->has_sequence_header;
}

void mpeg1_decoder_clear_sequence_header(mpeg1_decoder_t *self) {
if (self->has_sequence_header) {
free(self->planes_current.y);
free(self->planes_current.cr);
free(self->planes_current.cb);

free(self->planes_forward.y);
free(self->planes_forward.cr);
free(self->planes_forward.cb);

self->has_sequence_header = false;
}

}

float mpeg1_decoder_get_frame_rate(mpeg1_decoder_t *self) {
return self->frame_rate;
}
Expand Down
1 change: 1 addition & 0 deletions src/wasm/mpeg1.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void mpeg1_decoder_set_index(mpeg1_decoder_t *self, unsigned int index);
void mpeg1_decoder_did_write(mpeg1_decoder_t *self, unsigned int byte_size);

int mpeg1_decoder_has_sequence_header(mpeg1_decoder_t *self);
void mpeg1_decoder_clear_sequence_header(mpeg1_decoder_t *self);
float mpeg1_decoder_get_frame_rate(mpeg1_decoder_t *self);
int mpeg1_decoder_get_coded_size(mpeg1_decoder_t *self);
int mpeg1_decoder_get_width(mpeg1_decoder_t *self);
Expand Down
1 change: 1 addition & 0 deletions src/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ WebGLRenderer.prototype.resize = function(width, height) {
this.canvas.width = this.width;
this.canvas.height = this.height;

this.hasTextureData = {};
this.gl.useProgram(this.program);

var codedWidth = ((this.width + 15) >> 4) << 4;
Expand Down
14 changes: 11 additions & 3 deletions src/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ var WSSource = function(url, options) {
this.options = options;
this.socket = null;
this.streaming = true;

this.callbacks = {connect: [], data: []};
this.destination = null;

this.video = null;

this.reconnectInterval = options.reconnectInterval !== undefined
? options.reconnectInterval
: 5;
Expand Down Expand Up @@ -72,8 +73,15 @@ WSSource.prototype.onMessage = function(ev) {
this.onEstablishedCallback(this);
}

var data;
if (this.options.onSocketMessage) {
data = this.options.onSocketMessage(this, ev);
} else {
data = new Uint8Array(ev.data);
}

if (this.destination) {
this.destination.write(ev.data);
this.destination.write(data);
}
};

Expand Down

0 comments on commit 26f97f4

Please sign in to comment.