Skip to content

Commit

Permalink
修复videobuffer时间戳为负数的情况造成播放卡顿
Browse files Browse the repository at this point in the history
  • Loading branch information
bosscheng committed Jun 20, 2022
1 parent cc862dc commit 1cbaff2
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 37 deletions.
22 changes: 16 additions & 6 deletions demo/public/decoder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion demo/public/decoder.js.map

Large diffs are not rendered by default.

29 changes: 21 additions & 8 deletions demo/public/jessibuca.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion demo/public/jessibuca.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions demo/public/ws-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
},
forceNoOffscreen: forceNoOffscreen,
isNotMute: false,
heartTimeout: 100
heartTimeout: 100,
},);

jessibuca.onLog = msg => console.error(msg);
Expand All @@ -145,9 +145,9 @@
jessibuca.onPlay = () => console.log('onPlay');
jessibuca.onFullscreen = msg => console.log('onFullscreen', msg);
jessibuca.onMute = msg => console.log('onMute', msg);
jessibuca.on('stats', (stats) => {
console.log('stats', stats);
})
// jessibuca.on('stats', (stats) => {
// console.log('stats', stats);
// })
$player.style.display = 'inline-block';
$pause.style.display = 'none';
$destroy.style.display = 'none';
Expand Down
2 changes: 1 addition & 1 deletion dist/decoder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jessibuca.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/constant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const DEMUX_TYPE = {
// default player options
export const DEFAULT_PLAYER_OPTIONS = {
videoBuffer: 1000, //1000ms == 1 second
videoBufferDelay: 1000,// 1000ms
isResize: true,
isFullResize: false, //
isFlv: false,
Expand Down
4 changes: 2 additions & 2 deletions src/decoder/mediaSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ export default class MseDecoder extends Emitter {
let dts = ts;
// player.debug.log('MediaSource', '_decodeVideo', ts);
const $video = player.video.$videoElement;

const videoBufferDelay = player._opt.videoBufferDelay;
if ($video.buffered.length > 1) {
this.removeBuffer($video.buffered.start(0), $video.buffered.end(0));
this.timeInit = false;
}
if (this.dropping && dts - this.cacheTrack.dts > 1000) {
if (this.dropping && dts - this.cacheTrack.dts > videoBufferDelay) {
this.dropping = false;
this.cacheTrack = {};
} else if (this.cacheTrack && dts > this.cacheTrack.dts) {
Expand Down
11 changes: 9 additions & 2 deletions src/demux/commonLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ export default class CommonLoader extends Emitter {
this.delay = -1;
} else {
if (timestamp) {
this.delay = (Date.now() - this.startTimestamp) - (timestamp - this.firstTimestamp)
const localTimestamp = (Date.now() - this.startTimestamp);
const timeTimestamp = (timestamp - this.firstTimestamp);
if (localTimestamp >= timeTimestamp) {
this.delay = localTimestamp - timeTimestamp;
} else {
this.delay = timeTimestamp - localTimestamp;
}
}
}
return this.delay
Expand All @@ -57,6 +63,7 @@ export default class CommonLoader extends Emitter {
let _loop = () => {
let data;
const videoBuffer = this.player._opt.videoBuffer;
const videoBufferDelay = this.player._opt.videoBufferDelay;
if (this.bufferList.length) {
if (this.dropping) {
// this.player.debug.log('common dumex', `is dropping`);
Expand All @@ -81,7 +88,7 @@ export default class CommonLoader extends Emitter {
// this.player.debug.log('common dumex', `delay is -1`);
this.bufferList.shift()
this._doDecoderDecode(data);
} else if (this.delay > videoBuffer + 1000) {
} else if (this.delay > videoBuffer + videoBufferDelay) {
// this.player.debug.log('common dumex', `delay is ${this.delay}, set dropping is true`);
this.resetDelay();
this.dropping = true
Expand Down
18 changes: 7 additions & 11 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ Module.postRun = function () {
forceNoOffscreen: DEFAULT_PLAYER_OPTIONS.forceNoOffscreen,
useWCS: DEFAULT_PLAYER_OPTIONS.useWCS,
videoBuffer: DEFAULT_PLAYER_OPTIONS.videoBuffer,
openWebglAlignment: DEFAULT_PLAYER_OPTIONS.openWebglAlignment
openWebglAlignment: DEFAULT_PLAYER_OPTIONS.openWebglAlignment,
videoBufferDelay: DEFAULT_PLAYER_OPTIONS.videoBufferDelay
},
useOffscreen: function () {
return !decoder.opt.forceNoOffscreen && typeof OffscreenCanvas != 'undefined';
Expand Down Expand Up @@ -246,27 +247,22 @@ Module.postRun = function () {
} else {
var data = buffer[0];
if (this.getDelay(data.ts) === -1) {
decoder.opt.debug && console.log('Jessibuca: [worker]: common dumex delay is -1');
// decoder.opt.debug && console.log('Jessibuca: [worker]: common dumex delay is -1');
buffer.shift();
_doDecode(data);
} else if (this.delay > decoder.opt.videoBuffer + 1000) {
decoder.opt.debug && console.log('Jessibuca: [worker]:', `delay is ${this.delay}, set dropping is true`);
} else if (this.delay > decoder.opt.videoBuffer + decoder.opt.videoBufferDelay) {
// decoder.opt.debug && console.log('Jessibuca: [worker]:', `delay is ${this.delay}, set dropping is true`);
this.resetDelay();
this.dropping = true;
} else {
while (buffer.length) {
data = buffer[0];
if (this.getDelay(data.ts) > decoder.opt.videoBuffer) {
decoder.opt.debug && console.log('Jessibuca: [worker]:', `delay is ${this.delay}, decode`);
// decoder.opt.debug && console.log('Jessibuca: [worker]:', `delay is ${this.delay}, decode`);
buffer.shift();
_doDecode(data);
} else {
decoder.opt.debug && console.log('Jessibuca: [worker]:', `delay is ${this.delay},opt.videoBuffer is ${decoder.opt.videoBuffer}`);
// if (this.delay < -1) {
// this.resetDelay();
// this.dropping = true;
// break;
// }
// decoder.opt.debug && console.log('Jessibuca: [worker]:', `delay is ${this.delay},opt.videoBuffer is ${decoder.opt.videoBuffer}`);
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default class DecoderWorker {
forceNoOffscreen: this.player._opt.forceNoOffscreen,
useWCS: this.player._opt.useWCS,
videoBuffer: this.player._opt.videoBuffer,
videoBufferDelay: this.player._opt.videoBufferDelay,
openWebglAlignment: this.player._opt.openWebglAlignment
}
this.decoderWorker.postMessage({
Expand Down

1 comment on commit 1cbaff2

@vercel
Copy link

@vercel vercel bot commented on 1cbaff2 Jun 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.