Skip to content

Commit

Permalink
Update HLS/TS seek performance
Browse files Browse the repository at this point in the history
  • Loading branch information
numberwolf committed Sep 27, 2021
1 parent 0a667d6 commit b8dbb85
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 59 deletions.
2 changes: 2 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@

| 更新日志 | 内容 |
| ---- | ---- |
| 时间 | 2021/09/27 - 晚 |
| - | 0.M3u8/MpegTS 优化缓存区域外Seek速度性能 |
| 时间 | 2021/09/25 - 凌晨 |
| - | 0.HLS直播 解决长时直播内存泄露问题 |
| - | 1.HLS直播 解决HLS TS分片全路径不兼容问题 |
Expand Down
2 changes: 2 additions & 0 deletions README_EN.MD
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ Notice:

| Update | Content |
| ---- | ---- |
| Time | 2021/09/27 - Evening |
| - | 0.M3u8/MpegTS performance optimizing of Seek operation(out of cache area) |
| Time | 2021/09/25 - In the small hours |
| - | 0.HLS Live Fixed: Crash by OOM |
| - | 1.HLS Live Fixed: MPEG-TS full path |
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20210925');
require('./h265webjs-v20210927');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down
6 changes: 3 additions & 3 deletions example/dist/dist-play.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20210925');
require('./h265webjs-v20210927');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down
1 change: 1 addition & 0 deletions src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ source ./version.sh
!

REMOVE_FUNCS='"console.log","console.warn","alert"'
# REMOVE_FUNCS='"console.log"'
# REMOVE_FUNCS='"console.warn","alert"'
# REMOVE_FUNCS='"console.log","alert"'
# REMOVE_FUNCS=''
Expand Down
120 changes: 70 additions & 50 deletions src/src/h265webjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class H265webjsModule {
}; // configFormat
this.mediaExtFormat = this.configFormat.type;

alert(this.configFormat.type);
// alert(this.configFormat.type);

/*****************************************
*
Expand Down Expand Up @@ -354,6 +354,22 @@ class H265webjsModule {
};
}

_seekHLS(clickedValue, _self, callback) {
// alert("seekHLS" + clickedValue);
setTimeout(function() {
console.warn("this.player.getCachePTS()", _self.player.getCachePTS());
if (_self.player.getCachePTS() > clickedValue) {
// alert("start seekHLS");
// this.hlsObj.onSamples = null;
// this.hlsObj.seek(clickedValue);
callback();
return;
} else {
_self._seekHLS(clickedValue, _self, callback);
}
}, 100);
}

seek(clickedValue) {
console.log("============DEBUG===========> SEEK TO:", clickedValue);
let _this = this;
Expand Down Expand Up @@ -383,52 +399,56 @@ class H265webjsModule {
accurateSeek : _this.configFormat.accurateSeek
});
} else { // default core
this.player.seek(
() => { // call
if (_this.configFormat.type == def.PLAYER_IN_TYPE_MP4) {
// _this.mp4Obj.seek(_this.seekTarget);
_this.mp4Obj.seek(clickedValue);
} else if (
_this.configFormat.type == def.PLAYER_IN_TYPE_TS ||
_this.configFormat.type == def.PLAYER_IN_TYPE_MPEGTS)
{
// _this.mpegTsObj.seek(_this.seekTarget);
_this.mpegTsObj.seek(clickedValue);
} else if (_this.configFormat.type == def.PLAYER_IN_TYPE_M3U8)
{
/*
* reset HLS INFO
*/
// 这里去掉,不然append会影响
_this.hlsObj.onSamples = null;
// _this.hlsObj.onCacheProcess = null;

// _this.hlsObj.seek(_this.seekTarget);
_this.hlsObj.seek(clickedValue);
}
// seekPos
let seekFeedTime = function() {
let resTime = 0;
if (_this.configFormat.accurateSeek) {
resTime = clickedValue;
} else {
resTime = _this._getBoxBufSeekIDR();
this._seekHLS(clickedValue, this, function() {
_this.player.seek(
() => { // call
if (_this.configFormat.type == def.PLAYER_IN_TYPE_MP4) {
// _this.mp4Obj.seek(_this.seekTarget);
_this.mp4Obj.seek(clickedValue);
} else if (
_this.configFormat.type == def.PLAYER_IN_TYPE_TS ||
_this.configFormat.type == def.PLAYER_IN_TYPE_MPEGTS)
{
// _this.mpegTsObj.seek(_this.seekTarget);
_this.mpegTsObj.seek(clickedValue);
} else if (_this.configFormat.type == def.PLAYER_IN_TYPE_M3U8)
{
// alert("hls seek to" + clickedValue);
// _this._seekHLS(clickedValue);
/*
* reset HLS INFO
*/
// 这里去掉,不然append会影响
_this.hlsObj.onSamples = null;
// _this.hlsObj.onCacheProcess = null;

// _this.hlsObj.seek(_this.seekTarget);
_this.hlsObj.seek(clickedValue);
}
return parseInt(resTime);
} ();

// _this.feedMP4Data(_this._getBoxBufSeekIDR(), seekFeedTime);
let seekVIdr = parseInt(_this._getBoxBufSeekIDR()) || 0;
_this._avFeedMP4Data(
seekVIdr,
seekFeedTime);
},
{ // seek options
seekTime : seekTime,
mode : _this.playMode,
accurateSeek : _this.configFormat.accurateSeek
}
); // end seek
// seekPos
let seekFeedTime = function() {
let resTime = 0;
if (_this.configFormat.accurateSeek) {
resTime = clickedValue;
} else {
resTime = _this._getBoxBufSeekIDR();
}
return parseInt(resTime);
} ();

// _this.feedMP4Data(_this._getBoxBufSeekIDR(), seekFeedTime);
let seekVIdr = parseInt(_this._getBoxBufSeekIDR()) || 0;
_this._avFeedMP4Data(
seekVIdr,
seekFeedTime);
},
{ // seek options
seekTime : seekTime,
mode : _this.playMode,
accurateSeek : _this.configFormat.accurateSeek
}
); // end player.seek
}); // end seekHLS
} // end default core
}
return true;
Expand Down Expand Up @@ -827,7 +847,7 @@ class H265webjsModule {
/*
* Switch Media
*/
alert("type: " + this.configFormat.type);
// alert("type: " + this.configFormat.type);

if (this.configFormat.extInfo.core != undefined
&& this.configFormat.extInfo.core !== null
Expand Down Expand Up @@ -1158,7 +1178,7 @@ class H265webjsModule {
*
*/
_cDemuxDecoderEntry() {
alert("_cDemuxDecoderEntry" + this.configFormat.type);
// alert("_cDemuxDecoderEntry" + this.configFormat.type);
let _this = this;
this.player = new CNativeCore.CNativeCore({
width: this.configFormat.playerW,
Expand Down Expand Up @@ -1187,7 +1207,7 @@ class H265webjsModule {

if (_this.player.duration < 0) { // @TODO LIVE
_this.playMode = def.PLAYER_MODE_NOTIME_LIVE;
alert("LIVE");
// alert("LIVE");
}

_this.playParam.sampleRate = _this.player.config.sampleRate;
Expand Down Expand Up @@ -1292,7 +1312,7 @@ class H265webjsModule {
// default set 4096
_this.player && _this.player.setProbeSize(4096);
}
alert("cnative start fetch" + response.headers.get("Content-Length") + _this.configFormat.type);
// alert("cnative start fetch" + response.headers.get("Content-Length") + _this.configFormat.type);
let pump = function(reader) {
// console.log("start pump", reader);
return reader.read().then(function(result) {
Expand Down
2 changes: 1 addition & 1 deletion src/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20210925');
require('./h265webjs-v20210927');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down
2 changes: 1 addition & 1 deletion src/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
# * Github: https://github.com/numberwolf/h265web.js
# *
# **********************************************************/
VERSION='v20210925' # output version + index.js
VERSION='v20210927' # output version + index.js

0 comments on commit b8dbb85

Please sign in to comment.