Skip to content

Commit

Permalink
Merge pull request #161 from girlbymirror/master
Browse files Browse the repository at this point in the history
test case check support wasm
  • Loading branch information
girlbymirror authored Jul 1, 2022
2 parents 1b4c79b + 277d652 commit 60a094c
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 60 deletions.
18 changes: 9 additions & 9 deletions dist-multi-thread/h265webjs-v20220701.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions dist/h265webjs-v20220701.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions example_normal/dist-multi-thread/h265webjs-v20220701.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions example_normal/dist/h265webjs-v20220701.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions example_vue/public/dist/h265webjs-v20220701.js

Large diffs are not rendered by default.

147 changes: 147 additions & 0 deletions src/src/decoder/av-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,158 @@ function GetScriptPath(foo) {
);
}

function BrowserJudge() {
let document = window.document,
navigator = window.navigator,
agent = navigator.userAgent.toLowerCase(),
//IE8+支持.返回浏览器渲染当前文档所用的模式
//IE6,IE7:undefined.IE8:8(兼容模式返回7).IE9:9(兼容模式返回7||8)
//IE10:10(兼容模式7||8||9)
IEMode = document.documentMode,
//chorme
chrome = window.chrome || false,
System = {
//user-agent
agent: agent,
//是否为IE
isIE: /msie/.test(agent),
//Gecko内核
isGecko: agent.indexOf("gecko") > 0 && agent.indexOf("like gecko") < 0,
//webkit内核
isWebkit: agent.indexOf("webkit") > 0,
//是否为标准模式
isStrict: document.compatMode === "CSS1Compat",
//是否支持subtitle
supportSubTitle: function () {
return "track" in document.createElement("track");
},
//是否支持scoped
supportScope: function () {
return "scoped" in document.createElement("style");
},
//获取IE的版本号
ieVersion: function () {
try {
return agent.match(/msie ([\d.]+)/)[1] || 0;
} catch (e) {
console.log("error");
return IEMode;
}
},
//Opera版本号
operaVersion: function () {
try {
if (window.opera) {
return agent.match(/opera.([\d.]+)/)[1];
} else if (agent.indexOf("opr") > 0) {
return agent.match(/opr\/([\d.]+)/)[1];
}
} catch (e) {
console.log("error");
return 0;
}
},
//描述:version过滤.如31.0.252.152 只保留31.0
versionFilter: function () {
if (arguments.length === 1 && typeof arguments[0] === "string") {
let version = arguments[0];
let start = version.indexOf(".");
if (start > 0) {
let end = version.indexOf(".", start + 1);
if (end !== -1) {
return version.substr(0, end);
}
}
return version;
} else if (arguments.length === 1) {
return arguments[0];
}
return 0;
}
};

try {
//浏览器类型(IE、Opera、Chrome、Safari、Firefox)
System.type = System.isIE ? "IE" :
window.opera || (agent.indexOf("opr") > 0) ? "Opera" :
(agent.indexOf("chrome") > 0) ? "Chrome" :
//safari也提供了专门的判定方式
window.openDatabase ? "Safari" :
(agent.indexOf("firefox") > 0) ? "Firefox" :
'unknow';

//版本号
System.version = (System.type === "IE") ? System.ieVersion() :
(System.type === "Firefox") ? agent.match(/firefox\/([\d.]+)/)[1] :
(System.type === "Chrome") ? agent.match(/chrome\/([\d.]+)/)[1] :
(System.type === "Opera") ? System.operaVersion() :
(System.type === "Safari") ? agent.match(/version\/([\d.]+)/)[1] :
"0";

//浏览器外壳
System.shell = function () {
//遨游浏览器
if (agent.indexOf("maxthon") > 0) {
System.version = agent.match(/maxthon\/([\d.]+)/)[1] || System.version;
return "傲游浏览器";
}
//QQ浏览器
if (agent.indexOf("qqbrowser") > 0) {
System.version = agent.match(/qqbrowser\/([\d.]+)/)[1] || System.version;
return "QQ浏览器";
}

//搜狗浏览器
if (agent.indexOf("se 2.x") > 0) {
return '搜狗浏览器';
}

//Chrome:也可以使用window.chrome && window.chrome.webstore判断
if (chrome && System.type !== "Opera") {
let external = window.external,
clientInfo = window.clientInformation,
//客户端语言:zh-cn,zh.360下面会返回undefined
clientLanguage = clientInfo.languages;

//猎豹浏览器:或者agent.indexOf("lbbrowser")>0
if (external && 'LiebaoGetVersion' in external) {
return '猎豹浏览器';
}
//百度浏览器
if (agent.indexOf("bidubrowser") > 0) {
System.version = agent.match(/bidubrowser\/([\d.]+)/)[1] ||
agent.match(/chrome\/([\d.]+)/)[1];
return "百度浏览器";
}
//360极速浏览器和360安全浏览器
if (System.supportSubTitle() && typeof clientLanguage === "undefined") {
//object.key()返回一个数组.包含可枚举属性和方法名称
let storeKeyLen = Object.keys(chrome.webstore).length,
v8Locale = "v8Locale" in window;
return storeKeyLen > 1 ? '360极速浏览器' : '360安全浏览器';
}
return "Chrome";
}
return System.type;
};

//浏览器名称(如果是壳浏览器,则返回壳名称)
System.name = System.shell();
//对版本号进行过滤过处理
System.version = System.versionFilter(System.version);

} catch (e) {
console.log("error", e);
}
return [System.type, System.version];
}

module.exports = {
frameDataAlignCrop : frameDataAlignCrop,
GetUriFormat : GetUriFormat,
GetFormatPlayCore : GetFormatPlayCore,
GetUriProtocol : GetUriProtocol,
GetMsTime : GetMsTime,
GetScriptPath : GetScriptPath,
BrowserJudge : BrowserJudge
}; // module exports
19 changes: 9 additions & 10 deletions src/src/demuxer/m3u8base.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,16 @@ class M3u8BaseParserModule {
if (mediaFile[0] === '/') {
const httpHostSplit = this._preURI.split("//");
const hostSplit = httpHostSplit[httpHostSplit.length-1].split('/'); // remove http

this._preURI = httpHostSplit[0] + "//" + hostSplit[0];
/*
this._preURI = "";
for (let httpHostSplitIdx = 0;
httpHostSplitIdx < httpHostSplit.length;
httpHostSplitIdx++)
{
this._preURI += httpHostSplit[httpHostSplitIdx];
} // end for httpHostSplitIdx
this._preURI += hostSplit[0];
*/
// this._preURI = "";
// for (let httpHostSplitIdx = 0;
// httpHostSplitIdx < httpHostSplit.length;
// httpHostSplitIdx++)
// {
// this._preURI += httpHostSplit[httpHostSplitIdx];
// } // end for httpHostSplitIdx
// this._preURI += hostSplit[0];
}
mediaURI = this._preURI + mediaFile;
}
Expand Down
69 changes: 68 additions & 1 deletion src/src/h265webjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,9 +1109,69 @@ class H265webjsModule {
}, 5);
} // _avFeedMP4Data

_isSupportWASM() {
const supported = (() => {
try {
if (typeof WebAssembly === "object"
&& typeof WebAssembly.instantiate === "function") {
const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
if (module instanceof WebAssembly.Module)
return new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
}
} catch (e) {
}
return false;
}) ();

console.log(supported ? "WebAssembly is supported" : "WebAssembly is not supported");

if (supported === false) {
return false;
}

if (supported === true) {
const browser_info = AVCOMMON.BrowserJudge();
const browser_type = browser_info[0];
const browser_version = browser_info[1];
if (browser_type === 'Chrome' && browser_version < 85) {
return false;
}

if (browser_type.indexOf("360") >= 0) {
return false;
}
}

return true;
}

_makeMP4Player() {
let _this = this;

console.log("_isSupportWASM", this._isSupportWASM());

if (this._isSupportWASM() === false) {
if (this.configFormat.type == def.PLAYER_IN_TYPE_MP4) {
console.log("go mp4");
this._makeNativePlayer();
} else if (
this.configFormat.type == def.PLAYER_IN_TYPE_TS ||
this.configFormat.type == def.PLAYER_IN_TYPE_MPEGTS)
{
console.log("go ts");
// this._mpegTsEntry();
return -1;
} else if (this.configFormat.type == def.PLAYER_IN_TYPE_M3U8) {
console.log("go m3u8");
this._videoJsPlayer(0);
} else if (this.configFormat.type === def.PLAYER_IN_TYPE_RAW_265) {
console.log("go raw265");
// this._raw265Entry();
return -1;
}
return 1;
}

/*
* Switch Media
*/
Expand Down Expand Up @@ -1282,7 +1342,7 @@ class H265webjsModule {
}
} // _makeMP4PlayerViewEvent

_makeNativePlayer(durationMs, fps, sampleRate, size, audioNone, videoCodec) {
_makeNativePlayer(durationMs=0, fps=0, sampleRate=0, size, audioNone=0, videoCodec) {
let _this = this;
// set play params in this entry
this.playParam.durationMs = durationMs;
Expand Down Expand Up @@ -1327,6 +1387,7 @@ class H265webjsModule {

this.player.onLoadFinish = () => {
_this.playParam.durationMs = _this.player.duration * 1000;
_this.playParam.size = _this.player.getSize();
_this.onLoadFinish && _this.onLoadFinish();
_this.onReadyShowDone && _this.onReadyShowDone();
};
Expand Down Expand Up @@ -2253,6 +2314,11 @@ class H265webjsModule {
*/
_m3u8Entry() {
let _this = this;

if (this._isSupportWASM() === false) {
return this._videoJsPlayer(0);
}

let readyFinState = false;
let durationMs = 0;
let durationSecFloat;
Expand Down Expand Up @@ -2362,6 +2428,7 @@ class H265webjsModule {

// getSize
_this.playParam.size = _this.player.getSize();
_this.playParam.videoCodec = 1; // AVC

if (_this.player.duration === Infinity || _this.player.duration < 0) {
_this.playParam.durationMs = -1;
Expand Down
9 changes: 9 additions & 0 deletions src/src/native/mp4-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ class Mp4PlayerModule {
canvasBox.appendChild(this.videoTag);
}

getSize() {
const width = this.videoTag.videoWidth > 0 ? this.videoTag.videoWidth : this.configFormat.width;
const height = this.videoTag.videoHeight > 0 ? this.videoTag.videoHeight : this.configFormat.height;
return {
width: width,
height: height
};
}

play() {
let _this = this;
this.videoTag.play();
Expand Down
16 changes: 12 additions & 4 deletions src/src/native/nv-videojs-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ const videojs = require('video.js');
class NvVideojsCoreModule {
constructor(config) {
this.configFormat = {
probeDurationMS: config.probeDurationMS || -1,
probeDurationMS: config.probeDurationMS,
width: config.width || def.DEFAULT_WIDTH,
height: config.height || def.DEFAULT_HEIGHT,
playerId: config.playerId || def.DEFAILT_WEBGL_PLAY_ID,
ignoreAudio: config.ignoreAudio,
autoPlay: config.autoPlay || false,
};
console.log("this.configFormat", this.configFormat);
this.audioVoice = 1.0;

this.myPlayerID = this.configFormat.playerId + '-vjs';
Expand Down Expand Up @@ -98,7 +99,7 @@ class NvVideojsCoreModule {
this.videoTag.style.height = this.configFormat.height + 'px';

this.duration = this.myPlayer.duration();
console.log("this.videoTag==>", this.videoTag, this.duration);
console.log("this.videoTag==>", this.videoTag, this.duration, this.getSize(), this.videoTag.videoWidth);

// this.onLoadFinish && this.onLoadFinish();
// this.onReadyShowDone && this.onReadyShowDone();
Expand Down Expand Up @@ -180,7 +181,8 @@ class NvVideojsCoreModule {
this.myPlayer = videojs(this.myPlayerID, options, function() {
alert("load vjs");
_this.myPlayer.on("canplaythrough", function() {
console.log("视频源数据加载完成");
console.log("视频源数据加载完成",
_this.getSize(), _this.videoTag.videoWidth);
// if (_this.configFormat.probeDurationMS > 0) {
// _this.onLoadFinish && _this.onLoadFinish();
// _this.onReadyShowDone && _this.onReadyShowDone();
Expand All @@ -190,7 +192,7 @@ class NvVideojsCoreModule {
_this.myPlayer.on("loadedmetadata", function(e) {
console.log("vjs loadedmetadata", e);
_this._onVideoJsReady();
if (_this.configFormat.probeDurationMS > 0) {
if (_this.configFormat.probeDurationMS >= 0) {
_this.onLoadFinish && _this.onLoadFinish();
_this.onReadyShowDone && _this.onReadyShowDone();
}
Expand Down Expand Up @@ -220,6 +222,12 @@ class NvVideojsCoreModule {
} // makeIt

getSize() {
if (this.myPlayer.videoWidth() <= 0) {
return {
width: this.videoTag.videoWidth,
height: this.videoTag.videoHeight
};
}
return {
width: this.myPlayer.videoWidth(),
height: this.myPlayer.videoHeight(),
Expand Down

0 comments on commit 60a094c

Please sign in to comment.