From 873f7e393edf1994bbc4459f2133f3fede78e7d2 Mon Sep 17 00:00:00 2001 From: autosubmit Date: Wed, 10 Jan 2024 17:20:04 +0800 Subject: [PATCH] Auto Submit --- ...5f1436e.async.js => 6305.fa1934c4.async.js | 8 +- index.html | 2 +- ..._Exercise__Detail__index.eff1dc90.async.js | 1047 +- ...Exercise__Detail__index.f7d9c0af.chunk.css | 23 + ...08f.async.js => p__index.7ccfc406.async.js | 8 +- umi.5719b1df.js => umi.b8fecdfb.js | 15660 +++++++++------- 6 files changed, 9761 insertions(+), 6987 deletions(-) rename 6305.45f1436e.async.js => 6305.fa1934c4.async.js (99%) rename p__Classrooms__Lists__Exercise__Detail__index.2d0aafb0.async.js => p__Classrooms__Lists__Exercise__Detail__index.eff1dc90.async.js (97%) rename p__Classrooms__Lists__Exercise__Detail__index.06403803.chunk.css => p__Classrooms__Lists__Exercise__Detail__index.f7d9c0af.chunk.css (99%) rename p__index.33bc908f.async.js => p__index.7ccfc406.async.js (99%) rename umi.5719b1df.js => umi.b8fecdfb.js (97%) diff --git a/6305.45f1436e.async.js b/6305.fa1934c4.async.js similarity index 99% rename from 6305.45f1436e.async.js rename to 6305.fa1934c4.async.js index 7a47fce895..9cf1fd32ce 100644 --- a/6305.45f1436e.async.js +++ b/6305.fa1934c4.async.js @@ -30,8 +30,8 @@ var message = __webpack_require__(8591); var dropdown = __webpack_require__(38854); // EXTERNAL MODULE: ./node_modules/_flv.js@1.5.0@flv.js/src/flv.js + 38 modules var flv = __webpack_require__(31087); -// EXTERNAL MODULE: ./node_modules/_hls.js@1.4.14@hls.js/dist/hls.mjs -var dist_hls = __webpack_require__(76980); +// EXTERNAL MODULE: ./node_modules/_hls.js@1.5.0@hls.js/dist/hls.mjs +var dist_hls = __webpack_require__(49243); // EXTERNAL MODULE: ./src/utils/authority.ts var authority = __webpack_require__(19654); // EXTERNAL MODULE: ./node_modules/_react-copy-to-clipboard@5.0.2@react-copy-to-clipboard/lib/index.js @@ -511,8 +511,8 @@ var regex = /(android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini)/i; if ((src === null || src === void 0 ? void 0 : src.indexOf('.m3u8')) > -1) { if (el.current.canPlayType('application/vnd.apple.mpegurl')) { el.current.src = src; - } else if (dist_hls/* default */.Z.isSupported()) { - var hls = new dist_hls/* default */.Z(); + } else if (dist_hls/* default.isSupported */.ZP.isSupported()) { + var hls = new dist_hls/* default */.ZP(); hls.loadSource(src); hls.attachMedia(el.current); } diff --git a/index.html b/index.html index d9268d3bcf..09483a21ba 100644 --- a/index.html +++ b/index.html @@ -25,7 +25,7 @@ display: block !important; } - + \ No newline at end of file diff --git a/p__Classrooms__Lists__Exercise__Detail__index.2d0aafb0.async.js b/p__Classrooms__Lists__Exercise__Detail__index.eff1dc90.async.js similarity index 97% rename from p__Classrooms__Lists__Exercise__Detail__index.2d0aafb0.async.js rename to p__Classrooms__Lists__Exercise__Detail__index.eff1dc90.async.js index fc69d58151..22e3edc141 100644 --- a/p__Classrooms__Lists__Exercise__Detail__index.2d0aafb0.async.js +++ b/p__Classrooms__Lists__Exercise__Detail__index.eff1dc90.async.js @@ -6266,8 +6266,8 @@ var lodash = __webpack_require__(89392); var lodash_default = /*#__PURE__*/__webpack_require__.n(lodash); // EXTERNAL MODULE: ./node_modules/_flv.js@1.5.0@flv.js/src/flv.js + 38 modules var flv = __webpack_require__(31087); -// EXTERNAL MODULE: ./node_modules/_hls.js@1.4.14@hls.js/dist/hls.mjs -var hls = __webpack_require__(76980); +// EXTERNAL MODULE: ./node_modules/_hls.js@1.5.0@hls.js/dist/hls.mjs +var hls = __webpack_require__(49243); ;// CONCATENATED MODULE: ./src/components/Video/LivePlay/index.jsx @@ -15662,7 +15662,7 @@ var MinusCircleOutlined = __webpack_require__(87306); var PlusCircleOutlined = __webpack_require__(71029); ;// CONCATENATED MODULE: ./src/pages/Classrooms/Lists/Exercise/Detail/components/ConfigWorks/index.less?modules // extracted by mini-css-extract-plugin -/* harmony default export */ var ConfigWorksmodules = ({"flex_box_center":"flex_box_center___Onpg9","flex_space_between":"flex_space_between___nYRpC","flex_box_vertical_center":"flex_box_vertical_center___NGA7H","flex_box_center_end":"flex_box_center_end___a2dUm","flex_box_column":"flex_box_column___c5CN2","form":"form___TDc55","buttonFixed":"buttonFixed___oKPiL","buttonWrap":"buttonWrap___LDtpG","button":"button___ydPRd","scoreSettingWrapper":"scoreSettingWrapper___L7weV","ipItem":"ipItem___nAf_u","ipWrp":"ipWrp___x3LTQ","tagWrap":"tagWrap___PMN4b","tag":"tag___Auf1J","padding":"padding___veqnd","unlockKeyWrapper":"unlockKeyWrapper___UOERJ","unlockKeyInput":"unlockKeyInput___ItI9I","mb40":"mb40___eMjps","mb28":"mb28___ZxJPY","mainRuleText":"mainRuleText___U5cJS","minorRuleText":"minorRuleText___aZezx","contentInterval":"contentInterval___slPV9","numberInput":"numberInput____ONIt","publishRuleIndex":"publishRuleIndex___s2cVA","publishRuleContent":"publishRuleContent___HohmS","groupSelector":"groupSelector___Zxqsw","addAndDelete":"addAndDelete___saTVM","deleteIcon":"deleteIcon___vnkck","addIcon":"addIcon___Yz7Ef","cancelBtn":"cancelBtn___p8Klw","submitBtn":"submitBtn___pmm2G","remindForm":"remindForm___K6X21","remindItem":"remindItem___Z7rRb","remindInput":"remindInput___r_wq3","addRemind":"addRemind___jbnIp","disabled":"disabled___ebijK"}); +/* harmony default export */ var ConfigWorksmodules = ({"flex_box_center":"flex_box_center___Onpg9","flex_space_between":"flex_space_between___nYRpC","flex_box_vertical_center":"flex_box_vertical_center___NGA7H","flex_box_center_end":"flex_box_center_end___a2dUm","flex_box_column":"flex_box_column___c5CN2","formDom":"formDom___ahHwX","form":"form___TDc55","buttonFixed":"buttonFixed___oKPiL","buttonWrap":"buttonWrap___LDtpG","button":"button___ydPRd","scoreSettingWrapper":"scoreSettingWrapper___L7weV","ipItem":"ipItem___nAf_u","ipWrp":"ipWrp___x3LTQ","tagWrap":"tagWrap___PMN4b","tag":"tag___Auf1J","padding":"padding___veqnd","unlockKeyWrapper":"unlockKeyWrapper___UOERJ","unlockKeyInput":"unlockKeyInput___ItI9I","mb40":"mb40___eMjps","mb28":"mb28___ZxJPY","mainRuleText":"mainRuleText___U5cJS","minorRuleText":"minorRuleText___aZezx","contentInterval":"contentInterval___slPV9","numberInput":"numberInput____ONIt","publishRuleIndex":"publishRuleIndex___s2cVA","publishRuleContent":"publishRuleContent___HohmS","groupSelector":"groupSelector___Zxqsw","addAndDelete":"addAndDelete___saTVM","deleteIcon":"deleteIcon___vnkck","addIcon":"addIcon___Yz7Ef","cancelBtn":"cancelBtn___p8Klw","submitBtn":"submitBtn___pmm2G","remindForm":"remindForm___K6X21","remindItem":"remindItem___Z7rRb","remindInput":"remindInput___r_wq3","addRemind":"addRemind___jbnIp","disabled":"disabled___ebijK"}); // EXTERNAL MODULE: ./node_modules/_@ant-design_icons@5.2.6@@ant-design/icons/es/icons/QuestionCircleOutlined.js + 1 modules var QuestionCircleOutlined = __webpack_require__(98815); ;// CONCATENATED MODULE: ./src/pages/Classrooms/Lists/Exercise/Detail/components/ConfigWorks/components/MakeUp.tsx @@ -17289,15 +17289,17 @@ var AddIPRange_AddIPRange = function AddIPRange(_ref) { - var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { - var _data$public_ip2, _data$public_ip3, _data$inner_ip2, _data$inner_ip3, _exercise$commonHeade; + var _data$public_ip, _data$public_ip2, _data$inner_ip, _data$inner_ip2, _exercise$commonHeade; var exercise = _ref.exercise, globalSetting = _ref.globalSetting, loading = _ref.loading, dispatch = _ref.dispatch; var workSetting = exercise.workSetting, commonHeader = exercise.commonHeader; + var _Form$useForm = es_form/* default */.Z.useForm(), + _Form$useForm2 = slicedToArray_default()(_Form$useForm, 1), + form = _Form$useForm2[0]; var params = (0,_umi_production_exports.useParams)(); params.category = params.categoryId; var _useState = (0,_react_17_0_2_react.useState)(false), @@ -17308,45 +17310,52 @@ var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { _useState4 = slicedToArray_default()(_useState3, 2), pageLoading = _useState4[0], setPageLoading = _useState4[1]; - var _useState5 = (0,_react_17_0_2_react.useState)({ - question_random: false, - choice_random: false, - start_password: "", - login_restrict: false, - is_start_locked: false, - use_blank_score: false, - ip_limit: 'no', - identity_verify: false, - //考试前人脸身份核验 - open_phone_video_recording: false, - //考试中开启手机视频录制 - open_camera: false, - //考试中启用拍照监考 - photo_count: 5, - //本场考试最多拍摄次数 - screen_open: false, - //切屏后强制交卷 - screen_num: 3, - //切屏后强制交卷次数 - screen_sec: 5, - //切屏后强制交卷时间 - ip_bind: false, - //限制考试访问IP选择框 - public_ip: [], - //限制考试访问公网IP地址范围 - inner_ip: [], - //限制考试访问内网IP地址范围 - is_locked: false, - //是否开启考试解锁码 - unlock_key: '', - //考试解锁码 - screen_shot_open: false, - //考试截图功能 - part_score: false //选择题部分得分 - }), + var initData = { + question_random: false, + choice_random: false, + start_password: "", + login_restrict: false, + is_start_locked: false, + use_blank_score: false, + //多选题部分得分 + ip_limit: false, + // false:"no",true:"pub" + identity_verify: false, + //考试前人脸身份核验 + open_phone_video_recording: false, + //考试中开启手机视频录制 + open_camera: false, + //考试中启用拍照监考 + photo_count: 5, + //本场考试最多拍摄次数 + screen_open: false, + //切屏后强制交卷 + screen_num: 3, + //切屏后强制交卷次数 + screen_sec: 5, + //切屏后强制交卷时间 + ip_bind: false, + //限制考试访问IP选择框 + public_ip: [], + //限制考试访问公网IP地址范围 + inner_ip: [], + //限制考试访问内网IP地址范围 + is_locked: false, + //是否开启考试解锁码 + unlock_key: '', + //考试解锁码 + screen_shot_open: false, + //考试截图功能 + part_score: false //选择题部分得分 + }; + var _useState5 = (0,_react_17_0_2_react.useState)(initData), _useState6 = slicedToArray_default()(_useState5, 2), data = _useState6[0], setData = _useState6[1]; + var _useState7 = (0,_react_17_0_2_react.useState)(false), + _useState8 = slicedToArray_default()(_useState7, 2), + isChangeData = _useState8[0], + setIsChangeData = _useState8[1]; (0,_react_17_0_2_react.useEffect)(function () { setDefaultData(); }, [workSetting]); @@ -17360,6 +17369,7 @@ var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { if (exercise.actionTabs.key === 'insterIp') { if (exercise.actionTabs.data.ip) data[exercise.actionTabs.type] = [].concat(toConsumableArray_default()(data[exercise.actionTabs.type] || []), toConsumableArray_default()(exercise.actionTabs.data.ip));else data[exercise.actionTabs.type] = [].concat(toConsumableArray_default()(data[exercise.actionTabs.type] || []), ["".concat(exercise.actionTabs.data.startIP, ",").concat(exercise.actionTabs.data.startIP.substring(0, exercise.actionTabs.data.startIP.lastIndexOf(".")) + '.' + exercise.actionTabs.data.endIP)]); setData(objectSpread2_default()({}, data)); + setIsChangeData(true); } }, [exercise.actionTabs]); var setDefaultData = function setDefaultData() { @@ -17368,31 +17378,38 @@ var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { var _res$exercise; data[item] = res === null || res === void 0 || (_res$exercise = res['exercise']) === null || _res$exercise === void 0 ? void 0 : _res$exercise[item]; }); - setData(data); - handleIsSetData(""); + upDataForm(objectSpread2_default()(objectSpread2_default()({}, data), {}, { + ip_limit: data.ip_limit !== "no" + })); }; - var handleSubmit = function handleSubmit() { - var _data$public_ip, _data$inner_ip; - var bodyData = JSON.parse(JSON.stringify(data)); - bodyData.categoryId = params.categoryId; - if (data.open_camera && data.photo_count < 1) { + var upDataForm = function upDataForm(ValueAll) { + setData(ValueAll); + form.setFieldsValue(ValueAll); + }; + var handleSubmit = function handleSubmit(ValueAll) { + var _ValueAll$public_ip, _ValueAll$inner_ip; + // const bodyData = JSON.parse(JSON.stringify(data)); + // bodyData.categoryId = params.categoryId + ValueAll.categoryId = params.categoryId; + ValueAll.ip_limit = ValueAll.ip_limit ? "pub" : "no"; + if (ValueAll.open_camera && ValueAll.photo_count < 1) { message/* default */.ZP.error('请填写本场考试最大拍摄次数'); throw new String("请填写本场考试最大拍摄次数"); } - if (!data.start_password && data.is_start_locked) { + if (!ValueAll.start_password && ValueAll.is_start_locked) { message/* default */.ZP.error('请填写开考密码'); return; } - // if (data.ip_limit !== "no" && !data.public_ip?.length) { + // if (ValueAll.ip_limit !== "no" && !ValueAll.public_ip?.length) { // message.error('请填写公网IP地址') // throw new String("请填写公网IP地址"); // } - if (data.ip_limit !== "no" && !((_data$public_ip = data.public_ip) !== null && _data$public_ip !== void 0 && _data$public_ip.length) && !((_data$inner_ip = data.inner_ip) !== null && _data$inner_ip !== void 0 && _data$inner_ip.length)) { + if (ValueAll.ip_limit !== "no" && !((_ValueAll$public_ip = ValueAll.public_ip) !== null && _ValueAll$public_ip !== void 0 && _ValueAll$public_ip.length) && !((_ValueAll$inner_ip = ValueAll.inner_ip) !== null && _ValueAll$inner_ip !== void 0 && _ValueAll$inner_ip.length)) { message/* default */.ZP.error('请填写公网IP或内网IP地址'); throw new String("请填写内网IP地址"); } - if (data.open_camera || data.screen_open) { + if (ValueAll.open_camera || ValueAll.screen_open) { var modal = es_modal/* default */.Z.confirm({ title: "考试说明", className: "custom-modal-divider", @@ -17400,7 +17417,7 @@ var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { width: 750, content: /*#__PURE__*/(0,jsx_runtime.jsxs)("div", { className: "font16 p20", - children: [data.open_camera && /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { + children: [ValueAll.open_camera && /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { justify: "start", className: "mt20", children: [/*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { @@ -17415,7 +17432,7 @@ var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { children: "\u8FD9\u9700\u8981\u8C03\u7528\u5B66\u751F\u7528\u6237\u7684\u6444\u50CF\u8BBE\u5907" }), "\u3002Educoder\u5E73\u53F0\u5C06\u4F1A\u4E25\u683C\u4FDD\u62A4\u6240\u6709\u5B66\u751F\u7684\u7167\u7247\u548C\u89C6\u9891\uFF0C\u5E76\u627F\u8BFA\u4E0D\u5728\u672C\u5E73\u53F0\u4EE5\u5916\u4F7F\u7528\u3002", /*#__PURE__*/(0,jsx_runtime.jsx)("br", {}), "\u8BF7\u786E\u8BA4\uFF1A\u4E3A\u4E25\u683C\u76D1\u7763\u8003\u8BD5\u4EE5\u83B7\u5F97\u516C\u5E73\uFF0C\u60A8\u540C\u610F\u5E76\u548C\u8981\u6C42Educoder\u5E73\u53F0\u5728\u672C\u6B21\u8003\u8BD5\u4E2D\u8C03\u7528\u5B66\u751F\u7528\u6237\u7684\u6444\u50CF\u8BBE\u5907\u5E76\u83B7\u53D6\u5B66\u751F\u7684\u5F71\u50CF\u4FE1\u606F\u3002"] })] - }), data.screen_open && /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { + }), ValueAll.screen_open && /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { justify: "start", className: "mt20", children: [/*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { @@ -17455,14 +17472,14 @@ var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { })] }), onOk: function onOk() { - handleUpdate(bodyData); + handleUpdate(ValueAll); }, okButtonProps: { disabled: true } }); } else { - handleUpdate(bodyData); + handleUpdate(ValueAll); } }; var handleUpdate = /*#__PURE__*/function () { @@ -17482,7 +17499,7 @@ var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { setPageLoading(false); if (res.status === 0) { message/* default */.ZP.success('保存成功'); - handleIsSetData(""); + setIsChangeData(false); dispatch({ type: 'exercise/getCommonHeader', payload: objectSpread2_default()({}, params) @@ -17504,12 +17521,16 @@ var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { }; }(); (0,_react_17_0_2_react.useEffect)(function () { - handleIsSetData("表单未保存"); - window.addEventListener('beforeunload', handleBeforeunload); + if (isChangeData) { + handleIsSetData("表单未保存"); + window.addEventListener('beforeunload', handleBeforeunload); + } else { + handleIsSetData(""); + } return function () { window.removeEventListener('beforeunload', handleBeforeunload); }; - }, [data]); + }, [isChangeData]); var handleBeforeunload = function handleBeforeunload(event) { event.preventDefault(); event.returnValue = ''; @@ -17524,305 +17545,451 @@ var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { }); }; return /*#__PURE__*/(0,jsx_runtime.jsxs)("section", { - className: ConfigWorksmodules.form, - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(spin/* default */.Z, { + className: ConfigWorksmodules.formDom, + children: [/*#__PURE__*/(0,jsx_runtime.jsxs)(spin/* default */.Z, { spinning: loading['exercise/getWorkSetting'] || pageLoading, - children: /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { - align: "top", - wrap: false, - justify: "space-between", - className: "mt30 ".concat(ConfigWorksmodules.mb28), - children: [/*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - children: [!(commonHeader !== null && commonHeader !== void 0 && commonHeader.is_random) && /*#__PURE__*/(0,jsx_runtime.jsx)(row/* default */.Z, { - className: "".concat(ConfigWorksmodules.mb28), + children: [/*#__PURE__*/(0,jsx_runtime.jsxs)(es_form/* default */.Z, { + form: form, + name: "basicForm", + initialValues: initData, + colon: false, + onValuesChange: function onValuesChange(changeValue, ValueAll) { + console.log("onValuesChange", ValueAll); + var Values = ValueAll; + var _loop = function _loop() { + if (name == "is_locked" && !ValueAll[name]) { + Values.login_restrict = false; + } + if (name == "login_restrict" && ValueAll[name]) { + Values.is_locked = true; + } + if (name == "screen_shot_open" && ValueAll[name]) { + var modal = es_modal/* default */.Z.confirm({ + title: '提示', + icon: null, + centered: true, + okText: '确定', + cancelText: '取消', + content: /*#__PURE__*/(0,jsx_runtime.jsxs)("div", { + children: [/*#__PURE__*/(0,jsx_runtime.jsxs)("div", { + className: "mb10", + children: ["1.\u5F00\u542F\u540E\uFF0C\u5B66\u751F\u4F5C\u7B54\u524D", /*#__PURE__*/(0,jsx_runtime.jsx)("span", { + style: { + color: '#F59A23' + }, + children: "\u9700\u8981\u9009\u62E9\u4E3B\u5C4F\u5E55\u8FDB\u884C\u5171\u4EAB\uFF0C\u8003\u8BD5\u4F5C\u7B54\u8FC7\u7A0B\u4E2D\u4E5F\u4E0D\u5141\u8BB8\u5173\u95ED\u5C4F\u5E55\u5171\u4EAB\uFF0C\u5426\u5219\u5C06\u4F1A\u76F4\u63A5\u9000\u51FA\u8003\u8BD5\uFF1B" + })] + }), /*#__PURE__*/(0,jsx_runtime.jsx)("div", { + children: "2.\u6559\u5E08\u53EF\u5728\u8003\u8BD5\u76D1\u63A7\u9875\u9762\u67E5\u770B\u622A\u5C4F\u8BB0\u5F55\u3002" + })] + }), + onOk: function () { + var _onOk = asyncToGenerator_default()( /*#__PURE__*/regeneratorRuntime_default()().mark(function _callee2() { + return regeneratorRuntime_default()().wrap(function _callee2$(_context2) { + while (1) switch (_context2.prev = _context2.next) { + case 0: + Values.screen_shot_open = true; + upDataForm(Values); + case 2: + case "end": + return _context2.stop(); + } + }, _callee2); + })); + function onOk() { + return _onOk.apply(this, arguments); + } + return onOk; + }(), + onCancel: function onCancel() { + Values.screen_shot_open = false; + upDataForm(Values); + modal.destroy(); + } + }); + return 1; // break + } + if ((name == "ip_bind" || name == "ip_limit") && !ValueAll["is_locked"] && ValueAll[name]) { + Values.is_locked = true; + } + if (name == "open_camera") { + Values.photo_count = Values.photo_count || 5; + } + }; + for (var name in changeValue) { + if (_loop()) break; + } + upDataForm(Values); + setIsChangeData(true); + }, + onFinish: handleSubmit, + children: [/*#__PURE__*/(0,jsx_runtime.jsxs)(es_form/* default */.Z.Item, { + children: [/*#__PURE__*/(0,jsx_runtime.jsx)("strong", { + children: "\u4F7F\u7528\u63A8\u8350\u8BBE\u7F6E" + }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { + overlayStyle: { + maxWidth: 600 + }, + title: "点击不同的考试模式,系统会自动勾选对应模式推荐的防作弊设置,设置项支持进行修改。", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { + style: { + cursor: 'pointer', + color: '#4C6FFF', + marginLeft: 8 + } + }) + }), /*#__PURE__*/(0,jsx_runtime.jsx)(es_button/* default */.ZP, { + className: "ml20", + onClick: function onClick() { + upDataForm(objectSpread2_default()(objectSpread2_default()({}, initData), {}, { + question_random: true, + choice_random: true, + is_start_locked: true, + is_locked: true, + login_restrict: true, + screen_open: true, + ip_bind: true + })); + }, + children: "\u6B63\u5F0F\u8003\u8BD5\u6A21\u5F0F" + }), /*#__PURE__*/(0,jsx_runtime.jsx)(es_button/* default */.ZP, { + className: "ml20", + onClick: function onClick() { + upDataForm(objectSpread2_default()(objectSpread2_default()({}, initData), {}, { + question_random: true, + choice_random: true + })); + }, + children: "\u6A21\u62DF\u8003\u8BD5\u6A21\u5F0F" + })] + }), /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "question_random", + valuePropName: "checked", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { + disabled: disabled, + children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { + children: "\u5C0F\u9898\u9898\u76EE\u987A\u5E8F\u968F\u673A\u6253\u4E71" + }) + }) + }), /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "choice_random", + valuePropName: "checked", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { + disabled: disabled, + children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { + children: "\u9009\u62E9\u9898\u9009\u9879\u987A\u5E8F\u968F\u673A\u6253\u4E71" + }) + }) + }), /*#__PURE__*/(0,jsx_runtime.jsxs)("div", { + className: "ant-form-item", + children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "is_start_locked", + valuePropName: "checked", + style: { + marginBottom: 0 + }, children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { - checked: data.question_random, disabled: disabled, - onChange: function onChange(e) { - data.question_random = e.target.checked; - setData(Object.assign({}, data)); - }, - children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { - children: "\u5C0F\u9898\u9898\u76EE\u987A\u5E8F\u968F\u673A\u6253\u4E71" + children: /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, { + children: [/*#__PURE__*/(0,jsx_runtime.jsx)("strong", { + children: "\u5F00\u8003\u5BC6\u7801" + }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { + placement: "right", + overlayStyle: { + maxWidth: 600 + }, + title: "勾选后,学生第一次进入考试时,需要输入开考密码才能进入考试答题页面。", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { + style: { + cursor: 'pointer', + color: '#4C6FFF', + marginLeft: 8 + } + }) + })] }) }) - }), !(commonHeader !== null && commonHeader !== void 0 && commonHeader.is_random) && /*#__PURE__*/(0,jsx_runtime.jsx)(row/* default */.Z, { - className: ConfigWorksmodules.mb28, - children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { - checked: data.choice_random, - disabled: disabled, - onChange: function onChange(e) { - data.choice_random = e.target.checked; - setData(Object.assign({}, data)); + }), data.is_start_locked && (0,authority/* isAdmin */.GJ)() ? /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { + className: ConfigWorksmodules.unlockKeyWrapper, + align: "middle", + children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "start_password", + style: { + marginBottom: 0 }, - children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { - children: "\u9009\u62E9\u9898\u9009\u9879\u987A\u5E8F\u968F\u673A\u6253\u4E71" + children: /*#__PURE__*/(0,jsx_runtime.jsx)(input/* default */.Z, { + className: ConfigWorksmodules.unlockKeyInput, + disabled: disabled, + placeholder: "\u8BF7\u8F93\u5165\u5F00\u8003\u5BC6\u7801" }) - }) - }), !(commonHeader !== null && commonHeader !== void 0 && commonHeader.is_random) && /*#__PURE__*/(0,jsx_runtime.jsx)(row/* default */.Z, { - className: ConfigWorksmodules.mb28, + }), /*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { + children: !disabled && /*#__PURE__*/(0,jsx_runtime.jsx)(es_button/* default */.ZP, { + type: "link", + onClick: function onClick() { + form.setFieldsValue({ + start_password: Math.floor(Math.random() * 1000000).toString().padStart(6, '0') + }); + }, + children: "\u6362\u4E00\u6362" + }) + })] + }) : /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + hidden: true, + name: "start_password", + label: "开考密码(只用来在被隐藏的是时候进行收集数据)" + })] + }), /*#__PURE__*/(0,jsx_runtime.jsxs)("div", { + className: "ant-form-item", + children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "is_locked", + valuePropName: "checked", + style: { + marginBottom: 0 + }, children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { - checked: data.part_score, disabled: disabled, - onChange: function onChange(e) { - data.part_score = e.target.checked; - setData(Object.assign({}, data)); - }, - children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { - children: "\u591A\u9009\u9898\u90E8\u5206\u5F97\u5206" + children: /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, { + children: [/*#__PURE__*/(0,jsx_runtime.jsx)("strong", { + children: "\u8003\u8BD5\u89E3\u9501\u7801" + }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { + placement: "right", + overlayStyle: { + maxWidth: 600 + }, + title: "勾选后,如果学生在考试中途退出想再继续考试,需要使用解锁码进行解锁。", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { + style: { + cursor: 'pointer', + color: '#4C6FFF', + marginLeft: 8 + } + }) + })] }) }) - }), /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { - children: [/*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - span: 24, - className: ConfigWorksmodules.mb28, - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { - checked: data.identity_verify, - disabled: !(0,authority/* isAdmin */.GJ)() || disabled, - onChange: function onChange(e) { - data.identity_verify = e.target.checked; - setData(Object.assign({}, data)); - }, - children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { - children: "\u8003\u8BD5\u524D\u4EBA\u8138\u8EAB\u4EFD\u6838\u9A8C" - }) - }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { - placement: "right", - overlayStyle: { - maxWidth: 600 - }, - title: /*#__PURE__*/(0,jsx_runtime.jsx)("div", { - children: "\u52FE\u9009\u540E\uFF0C\u5B66\u751F\u5F00\u59CB\u8003\u8BD5\u524D\u5C06\u4F1A\u8981\u6C42\u8C03\u7528\u6444\u50CF\u5934\u5B8C\u6210\u62CD\u7167\u91C7\u96C6\uFF0C\u7CFB\u7EDF\u5C06\u81EA\u52A8\u5BF9\u91C7\u96C6\u7684\u5B66\u751F\u7167\u7247\u4E0E\u5DF2\u5F55\u5165\u7167\u7247\u8FDB\u884C\u6BD4\u5BF9\u5BA1\u6838\uFF08\u6559\u5E08/\u52A9\u6559\u4E5F\u53EF\u8FDB\u884C\u624B\u52A8\u5BA1\u6838\uFF09\uFF0C\u5BA1\u6838\u901A\u8FC7\u4E4B\u540E\u5B66\u751F\u624D\u80FD\u5F00\u59CB\u8003\u8BD5\u3002" - }), - children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { - style: { - marginLeft: 4, - cursor: 'pointer', - color: '#4C6FFF' - } - }) - })] - }), /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - span: 24, - className: data.open_camera ? 'mb20' : ConfigWorksmodules.mb28, - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { - checked: data.open_camera, + }), data.is_locked && (0,authority/* isAdmin */.GJ)() ? /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { + className: ConfigWorksmodules.unlockKeyWrapper, + align: "middle", + children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + style: { + marginBottom: 0 + }, + name: "unlock_key", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(input/* default */.Z, { + className: ConfigWorksmodules.unlockKeyInput, disabled: disabled, - onChange: function onChange(e) { - // if (!data.time) { - // message.error('不限时长的考试不可开启摄像头,请填写考试时长') - // return; - // } - data.open_camera = e.target.checked; - data.photo_count = data.photo_count || 5; - setData(Object.assign({}, data)); + placeholder: "\u8BF7\u8F93\u5165\u8003\u8BD5\u89E3\u9501\u7801" + }) + }), /*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { + children: !disabled && /*#__PURE__*/(0,jsx_runtime.jsx)(es_button/* default */.ZP, { + type: "link", + onClick: function onClick() { + form.setFieldsValue({ + unlock_key: Math.floor(Math.random() * 1000000).toString().padStart(6, '0') + }); }, - children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { - children: "\u8003\u8BD5\u4E2D\u542F\u7528\u62CD\u7167\u76D1\u8003" - }) + children: "\u6362\u4E00\u6362" + }) + })] + }) : /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + hidden: true, + name: "unlock_key", + label: "考试解锁码(只用来在被隐藏的是时候进行收集数据)" + })] + }), /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "login_restrict", + valuePropName: "checked", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { + disabled: disabled, + children: /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, { + children: [/*#__PURE__*/(0,jsx_runtime.jsx)("strong", { + children: "\u8003\u8BD5\u767B\u5F55\u9650\u5236" }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { placement: "right", overlayStyle: { maxWidth: 600 }, - title: /*#__PURE__*/(0,jsx_runtime.jsx)("div", { - children: "\u52FE\u9009\u540E\uFF0C\u5B66\u751F\u5728\u8003\u8BD5\u4E2D\u5C06\u4F1A\u8C03\u7528\u6444\u50CF\u5934\u8FDB\u884C\u62CD\u7167\u3002" - }), + title: "勾选后,学生在考试期间第二次及后续登录系统时,需要监考老师输入考试解锁码才能登录系统。", children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { style: { cursor: 'pointer', - color: '#4C6FFF' + color: '#4C6FFF', + marginLeft: 8 } }) })] - }), data.open_camera && /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - span: 24, - className: "".concat(ConfigWorksmodules.contentInterval, " ").concat(ConfigWorksmodules.mb28), - children: [/*#__PURE__*/(0,jsx_runtime.jsx)("span", { - children: "\u672C\u573A\u8003\u8BD5\u6700\u591A\u62CD\u6444\uFF1A" - }), /*#__PURE__*/(0,jsx_runtime.jsx)(input_number/* default */.Z, { - size: 'middle', - disabled: disabled || !data.open_camera, - min: 1, - defaultValue: 5, - max: (0,authority/* isSuperAdmins */.Ny)() ? 1000 : 10, - value: data.photo_count, - onChange: function onChange(value) { - data.photo_count = value; - setData(objectSpread2_default()({}, data)); - } - }), /*#__PURE__*/(0,jsx_runtime.jsx)("span", { - className: "ml10", - children: "(\u6B21)" - }), /*#__PURE__*/(0,jsx_runtime.jsx)("span", { - className: "c-grey-c font12 ml10", - children: "(\u8BF7\u586B\u5199\u4E0D\u5927\u4E8E10\u7684\u6B63\u6574\u6570)" - })] - }), /*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { - span: 24, - className: data.screen_open ? 'mb20' : ConfigWorksmodules.mb28, - children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { - checked: data.screen_open, - disabled: disabled, - onChange: function onChange(e) { - data.screen_open = e.target.checked; - setData(Object.assign({}, data)); - }, - children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { - children: "\u5207\u5C4F\u540E\u5F3A\u5236\u4EA4\u5377" - }) + }) + }) + }), /*#__PURE__*/(0,jsx_runtime.jsxs)("div", { + className: "ant-form-item", + children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "screen_open", + valuePropName: "checked", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { + disabled: disabled, + children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { + children: "\u5207\u5C4F\u540E\u5F3A\u5236\u4EA4\u5377" }) - }), data.screen_open && /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - span: 24, - className: "".concat(ConfigWorksmodules.contentInterval, " mb20"), - children: [/*#__PURE__*/(0,jsx_runtime.jsx)("span", { - className: "c-grey-333 mr10", + }) + }), data.screen_open ? /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, { + children: [/*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { + gutter: 10, + className: "c-grey-333 ".concat(ConfigWorksmodules.unlockKeyWrapper), + align: "middle", + wrap: false, + children: [/*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { children: "\u8003\u8BD5\u8FC7\u7A0B\u4E2D\u5207\u6362\u9875\u9762\u8D85\u8FC7" - }), /*#__PURE__*/(0,jsx_runtime.jsx)(input_number/* default */.Z, { - size: 'middle', - disabled: disabled, - min: 0, - defaultValue: 3, - max: 10, - value: data.screen_num, - onChange: function onChange(value) { - data.screen_num = value; - setData(objectSpread2_default()({}, data)); - } - }), /*#__PURE__*/(0,jsx_runtime.jsx)("span", { - className: "c-grey-333 mr10", + }), /*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "screen_num", + style: { + marginBottom: 0 + }, + children: /*#__PURE__*/(0,jsx_runtime.jsx)(input_number/* default */.Z, { + size: 'middle', + disabled: disabled, + min: 0, + max: 10 + }) + }) + }), /*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { children: "\uFF08\u6B21\uFF09\u540E\u5C06\u88AB\u5F3A\u5236\u4EA4\u5377\uFF0C\u5207\u6362\u5230\u5176\u4ED6\u9875\u9762" - }), /*#__PURE__*/(0,jsx_runtime.jsx)(input_number/* default */.Z, { - size: 'middle', - disabled: disabled, - min: 0, - defaultValue: 5, - max: 60, - value: data.screen_sec, - onChange: function onChange(value) { - data.screen_sec = value; - setData(objectSpread2_default()({}, data)); - } - }), /*#__PURE__*/(0,jsx_runtime.jsx)("span", { - className: "c-grey-333", + }), /*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "screen_sec", + style: { + marginBottom: 0 + }, + children: /*#__PURE__*/(0,jsx_runtime.jsx)(input_number/* default */.Z, { + size: 'middle', + disabled: disabled, + min: 0, + max: 60 + }) + }) + }), /*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { children: "\uFF08\u79D2\uFF09\u540E\u5373\u5224\u5B9A\u4E3A\u5207\u5C4F\u3002" })] - }), data.screen_open && /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - span: 24, - className: "".concat(ConfigWorksmodules.contentInterval, " ").concat(ConfigWorksmodules.mb28), - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_switch/* default */.Z, { - disabled: disabled || !data.screen_open, - checked: data.screen_shot_open, - onChange: function onChange(value) { - if (value) { - es_modal/* default */.Z.confirm({ - icon: null, - centered: true, - okText: '确定', - cancelText: '取消', - title: '提示', - content: /*#__PURE__*/(0,jsx_runtime.jsxs)("div", { - children: [/*#__PURE__*/(0,jsx_runtime.jsxs)("div", { - className: "mb10", - children: ["1.\u5F00\u542F\u540E\uFF0C\u5B66\u751F\u4F5C\u7B54\u524D", /*#__PURE__*/(0,jsx_runtime.jsx)("span", { - style: { - color: '#F59A23' - }, - children: "\u9700\u8981\u9009\u62E9\u4E3B\u5C4F\u5E55\u8FDB\u884C\u5171\u4EAB\uFF0C\u8003\u8BD5\u4F5C\u7B54\u8FC7\u7A0B\u4E2D\u4E5F\u4E0D\u5141\u8BB8\u5173\u95ED\u5C4F\u5E55\u5171\u4EAB\uFF0C\u5426\u5219\u5C06\u4F1A\u76F4\u63A5\u9000\u51FA\u8003\u8BD5\uFF1B" - })] - }), /*#__PURE__*/(0,jsx_runtime.jsx)("div", { - children: "2.\u6559\u5E08\u53EF\u5728\u8003\u8BD5\u76D1\u63A7\u9875\u9762\u67E5\u770B\u622A\u5C4F\u8BB0\u5F55\u3002" - })] - }), - onOk: function () { - var _onOk = asyncToGenerator_default()( /*#__PURE__*/regeneratorRuntime_default()().mark(function _callee2() { - return regeneratorRuntime_default()().wrap(function _callee2$(_context2) { - while (1) switch (_context2.prev = _context2.next) { - case 0: - data.screen_shot_open = value; - setData(objectSpread2_default()({}, data)); - case 2: - case "end": - return _context2.stop(); - } - }, _callee2); - })); - function onOk() { - return _onOk.apply(this, arguments); - } - return onOk; - }() - }); - return; - } - data.screen_shot_open = value; - setData(objectSpread2_default()({}, data)); - } - }), /*#__PURE__*/(0,jsx_runtime.jsx)("span", { - className: "ml10", + }), /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { + gutter: 10, + className: "c-grey-333 ".concat(ConfigWorksmodules.unlockKeyWrapper), + align: "middle", + wrap: false, + children: [/*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "screen_shot_open", + valuePropName: "checked", + style: { + marginBottom: 0 + }, + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_switch/* default */.Z, { + disabled: disabled || !data.screen_open + }) + }) + }), /*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { children: "\u5B66\u751F\u9000\u51FA\u5168\u5C4F\u6216\u5207\u6362\u9875\u9762\u540E\u8FDB\u884C\u622A\u5C4F" })] - }), /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - span: 24, - className: ConfigWorksmodules.mb28, - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { - checked: data.ip_limit !== 'no', - disabled: disabled, - onChange: function onChange(e) { - // data.ip_bind = e.target.checked; - // if (data.ip_bind) { - // data.ip_limit = data.ip_limit === "no" ? 'pub' : data.ip_limit - // } - if (data.ip_limit === 'no') { - data.ip_limit = 'pub'; - if (!data.is_locked) { - data.is_locked = true; - } - } else { - data.ip_limit = 'no'; - } - setData(Object.assign({}, data)); - }, - children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { - children: "\u9650\u5236\u8003\u8BD5\u8BBF\u95EEIP" - }) + })] + }) : /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, { + children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + hidden: true, + name: "screen_num", + label: "(只用来在被隐藏的是时候进行收集数据)" + }), /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + hidden: true, + name: "screen_sec", + label: "(只用来在被隐藏的是时候进行收集数据)" + }), /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + hidden: true, + name: "screen_shot_open", + label: "(只用来在被隐藏的是时候进行收集数据)" + })] + })] + }), /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "ip_bind", + valuePropName: "checked", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { + disabled: disabled, + children: /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, { + children: [/*#__PURE__*/(0,jsx_runtime.jsx)("strong", { + children: "IP\u5730\u5740\u7ED1\u5B9A" }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { placement: "right", overlayStyle: { maxWidth: 600 }, - title: /*#__PURE__*/(0,jsx_runtime.jsx)("div", { - children: "\u52FE\u9009\u540E\uFF0C\u4E0D\u5728IP\u8303\u56F4\u4E2D\u7684\u8BBE\u5907\u5C06\u65E0\u6CD5\u53C2\u52A0\u8003\u8BD5\u3002" - }), + title: "勾选后,开始考试的学生账号将自动与设备公网IP进行绑定。如遇特殊情况,可由教师/助教进行IP解绑。", children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { style: { cursor: 'pointer', - color: '#4C6FFF' + color: '#4C6FFF', + marginLeft: 8 } }) })] - }), data.ip_limit !== 'no' && /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - className: "mt15 ".concat(ConfigWorksmodules.contentInterval), + }) + }) + }), /*#__PURE__*/(0,jsx_runtime.jsxs)("div", { + className: "ant-form-item", + children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "ip_limit", + valuePropName: "checked", + style: { + marginBottom: 0 + }, + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { + disabled: disabled, + children: /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, { + children: [/*#__PURE__*/(0,jsx_runtime.jsx)("strong", { + children: "\u9650\u5236\u8003\u8BD5\u8BBF\u95EEIP" + }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { + placement: "right", + overlayStyle: { + maxWidth: 600 + }, + title: "勾选后,不在IP范围中的设备将无法参加考试。", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { + style: { + cursor: 'pointer', + color: '#4C6FFF', + marginLeft: 8 + } + }) + })] + }) + }) + }), /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "public_ip", + label: "公网IP地址范围(只用来在被隐藏的是时候进行收集数据)", + hidden: true + }), /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "inner_ip", + label: "内网IP地址范围(只用来在被隐藏的是时候进行收集数据)", + hidden: true + }), (data === null || data === void 0 ? void 0 : data.ip_limit) && /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { + className: ConfigWorksmodules.unlockKeyWrapper, + style: { + flexDirection: "column" + }, + children: [/*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { + className: "mb10", children: [/*#__PURE__*/(0,jsx_runtime.jsx)("span", { className: "c-red", children: "\uFF08\u53EA\u5141\u8BB8\u5728Chrome\u8C37\u6B4C\u6D4F\u89C8\u5668\u4F5C\u7B54\uFF0C\u5E76\u4E14\u8981\u6C42\u5B66\u751F\u5B89\u88C5WebRTC Leak Prevent\u63D2\u4EF6\uFF09" - }), /*#__PURE__*/(0,jsx_runtime.jsx)(es_button/* default */.ZP, { - onClick: util/* showInstallWebRtcDoc */.jt, - type: "link", + }), /*#__PURE__*/(0,jsx_runtime.jsx)("a", { + className: "c-blue", + target: "_blank", + href: "https://www.educoder.net/forums/4478", children: "\u5982\u4F55\u5B89\u88C5WebRTC Leak Prevent\u63D2\u4EF6?" })] - })] - }), data.ip_limit !== 'no' && /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, { - children: [/*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { - className: "mt15 ".concat(ConfigWorksmodules.contentInterval, " ").concat(ConfigWorksmodules.ipWrp), + }), /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { + className: "mt15 ".concat(ConfigWorksmodules.ipWrp), children: [/*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { - children: /*#__PURE__*/(0,jsx_runtime.jsx)("span", { - children: "\u516C\u7F51IP\u5730\u5740\u8303\u56F4\uFF1A" - }) + children: "\u516C\u7F51IP\u5730\u5740\u8303\u56F4\uFF1A" }), /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - children: [!((_data$public_ip2 = data.public_ip) !== null && _data$public_ip2 !== void 0 && _data$public_ip2.length) && /*#__PURE__*/(0,jsx_runtime.jsx)("span", { + children: [!((_data$public_ip = data.public_ip) !== null && _data$public_ip !== void 0 && _data$public_ip.length) && /*#__PURE__*/(0,jsx_runtime.jsx)("span", { children: "\u5F53\u524D\u8FD8\u672A\u8BBE\u7F6EIP\u8303\u56F4" - }), (_data$public_ip3 = data.public_ip) === null || _data$public_ip3 === void 0 ? void 0 : _data$public_ip3.map(function (item, key) { + }), (_data$public_ip2 = data.public_ip) === null || _data$public_ip2 === void 0 ? void 0 : _data$public_ip2.map(function (item, key) { return /*#__PURE__*/(0,jsx_runtime.jsxs)("span", { className: ConfigWorksmodules.ipItem, children: [/*#__PURE__*/(0,jsx_runtime.jsxs)("i", { @@ -17860,15 +18027,15 @@ var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { })] })] }), /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { - className: "mt15 ".concat(ConfigWorksmodules.contentInterval, " ").concat(ConfigWorksmodules.ipWrp, " ").concat(ConfigWorksmodules.mb28), + className: "mt15 ".concat(ConfigWorksmodules.ipWrp), children: [/*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { children: /*#__PURE__*/(0,jsx_runtime.jsx)("span", { children: "\u5185\u7F51IP\u5730\u5740\u8303\u56F4\uFF1A" }) }), /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - children: [!((_data$inner_ip2 = data.inner_ip) !== null && _data$inner_ip2 !== void 0 && _data$inner_ip2.length) && /*#__PURE__*/(0,jsx_runtime.jsx)("span", { + children: [!((_data$inner_ip = data.inner_ip) !== null && _data$inner_ip !== void 0 && _data$inner_ip.length) && /*#__PURE__*/(0,jsx_runtime.jsx)("span", { children: "\u5F53\u524D\u8FD8\u672A\u8BBE\u7F6EIP\u8303\u56F4" - }), (_data$inner_ip3 = data.inner_ip) === null || _data$inner_ip3 === void 0 ? void 0 : _data$inner_ip3.map(function (item, key) { + }), (_data$inner_ip2 = data.inner_ip) === null || _data$inner_ip2 === void 0 ? void 0 : _data$inner_ip2.map(function (item, key) { return /*#__PURE__*/(0,jsx_runtime.jsxs)("span", { className: ConfigWorksmodules.ipItem, children: [/*#__PURE__*/(0,jsx_runtime.jsxs)("i", { @@ -17904,182 +18071,99 @@ var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { })] })] })] - }), /*#__PURE__*/(0,jsx_runtime.jsx)(row/* default */.Z, { - children: /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - span: 24, - className: ConfigWorksmodules.mb28, - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { - checked: data.ip_bind, - disabled: disabled, - onChange: function onChange(e) { - data.ip_bind = e.target.checked; - if (!data.is_locked && data.ip_bind) { - data.is_locked = true; - } - setData(Object.assign({}, data)); - }, - children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { - children: "IP\u5730\u5740\u7ED1\u5B9A" - }) - }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { - placement: "right", - overlayStyle: { - maxWidth: 600 - }, - title: /*#__PURE__*/(0,jsx_runtime.jsx)("div", { - children: "\u52FE\u9009\u540E\uFF0C\u5F00\u59CB\u8003\u8BD5\u7684\u5B66\u751F\u8D26\u53F7\u5C06\u81EA\u52A8\u4E0E\u8BBE\u5907\u516C\u7F51IP\u8FDB\u884C\u7ED1\u5B9A\u3002\u5982\u9047\u7279\u6B8A\u60C5\u51B5\uFF0C\u53EF\u7531\u6559\u5E08/\u52A9\u6559\u8FDB\u884CIP\u89E3\u7ED1\u3002" - }), - children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { - style: { - cursor: 'pointer', - color: '#4C6FFF' - } - }) - })] - }) - }), /*#__PURE__*/(0,jsx_runtime.jsx)(row/* default */.Z, { - children: /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - span: 24, - className: ConfigWorksmodules.mb28, - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { - checked: data.is_locked, - disabled: disabled, - onChange: function onChange(e) { - data.is_locked = e.target.checked; - if (!e.target.checked) data.login_restrict = false; - setData(Object.assign({}, data)); - }, - children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { - children: "\u8003\u8BD5\u89E3\u9501\u7801" - }) - }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { - placement: "right", - overlayStyle: { - maxWidth: 600 - }, - title: /*#__PURE__*/(0,jsx_runtime.jsx)("div", { - children: "\u52FE\u9009\u540E\uFF0C\u5982\u679C\u5B66\u751F\u5728\u8003\u8BD5\u4E2D\u9014\u9000\u51FA\u60F3\u518D\u7EE7\u7EED\u8003\u8BD5\uFF0C\u9700\u8981\u4F7F\u7528\u89E3\u9501\u7801\u8FDB\u884C\u89E3\u9501\u3002" - }), - children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { - style: { - cursor: 'pointer', - color: '#4C6FFF' - } - }) - }), /*#__PURE__*/(0,jsx_runtime.jsx)("br", {}), data.is_locked && (0,authority/* isAdmin */.GJ)() && /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { - className: ConfigWorksmodules.unlockKeyWrapper, - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(input/* default */.Z, { - placeholder: "\u8BF7\u8F93\u5165\u8003\u8BD5\u89E3\u9501\u7801", - value: data.unlock_key, - disabled: disabled, - onChange: function onChange(e) { - return setData(function (prevData) { - return objectSpread2_default()(objectSpread2_default()({}, prevData), {}, { - unlock_key: e.target.value - }); - }); - }, - className: ConfigWorksmodules.unlockKeyInput - }), data.is_locked && !disabled && /*#__PURE__*/(0,jsx_runtime.jsx)(es_button/* default */.ZP, { - type: "link", - onClick: function onClick() { - data.unlock_key = Math.floor(Math.random() * 1000000); - setData(objectSpread2_default()({}, data)); + })] + }), /*#__PURE__*/(0,jsx_runtime.jsxs)("div", { + className: "ant-form-item", + children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "open_camera", + valuePropName: "checked", + style: { + marginBottom: 0 + }, + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { + disabled: disabled, + children: /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, { + children: [/*#__PURE__*/(0,jsx_runtime.jsx)("strong", { + children: "\u8003\u8BD5\u4E2D\u542F\u7528\u62CD\u7167\u76D1\u8003" + }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { + placement: "right", + overlayStyle: { + maxWidth: 600 }, - children: "\u6362\u4E00\u6362" + title: "勾选后,学生在考试中将会调用摄像头进行拍照。", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { + style: { + cursor: 'pointer', + color: '#4C6FFF', + marginLeft: 8 + } + }) })] - })] + }) }) - }), /*#__PURE__*/(0,jsx_runtime.jsx)(row/* default */.Z, { - children: /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - span: 24, - className: ConfigWorksmodules.mb28, - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { - checked: data.login_restrict, - disabled: disabled, - onChange: function onChange(e) { - data.login_restrict = e.target.checked; - if (e.target.checked) data.is_locked = true; - setData(Object.assign({}, data)); - }, - children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { - children: "\u8003\u8BD5\u767B\u5F55\u9650\u5236" - }) - }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { - placement: "right", - overlayStyle: { - maxWidth: 600 + }), data.open_camera ? /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, { + gutter: 10, + className: "c-grey-333 ".concat(ConfigWorksmodules.unlockKeyWrapper), + align: "middle", + wrap: false, + children: [/*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { + children: "\u672C\u573A\u8003\u8BD5\u6700\u591A\u62CD\u6444\uFF1A" + }), /*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "photo_count", + style: { + marginBottom: 0 }, - title: /*#__PURE__*/(0,jsx_runtime.jsx)("div", { - children: "\u52FE\u9009\u540E\uFF0C\u5B66\u751F\u5728\u8003\u8BD5\u671F\u95F4\u7B2C\u4E8C\u6B21\u53CA\u540E\u7EED\u767B\u5F55\u7CFB\u7EDF\u65F6\uFF0C\u9700\u8981\u76D1\u8003\u8001\u5E08\u8F93\u5165\u8003\u8BD5\u89E3\u9501\u7801\u624D\u80FD\u767B\u5F55\u7CFB\u7EDF" - }), - children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { - style: { - cursor: 'pointer', - color: '#4C6FFF' - } + children: /*#__PURE__*/(0,jsx_runtime.jsx)(input_number/* default */.Z, { + size: 'middle', + disabled: disabled || !data.open_camera, + min: 1, + max: (0,authority/* isSuperAdmins */.Ny)() ? 1000 : 10 }) + }) + }), /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { + children: ["\uFF08\u6B21\uFF09", /*#__PURE__*/(0,jsx_runtime.jsx)("span", { + className: "c-grey-c font12 ml10", + children: "\u8BF7\u586B\u5199\u4E0D\u5927\u4E8E10\u7684\u6B63\u6574\u6570" })] - }) - }), /*#__PURE__*/(0,jsx_runtime.jsx)(row/* default */.Z, { - children: /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - span: 24, - className: ConfigWorksmodules.mb28, - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { - checked: data.is_start_locked, - disabled: disabled, - onChange: function onChange(e) { - data.is_start_locked = e.target.checked; - setData(Object.assign({}, data)); - }, - children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { - children: "\u5F00\u8003\u5BC6\u7801" - }) + })] + }) : /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + hidden: true, + name: "photo_count", + label: "(只用来在被隐藏的是时候进行收集数据)" + })] + }), /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "identity_verify", + valuePropName: "checked", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { + disabled: !(0,authority/* isAdmin */.GJ)() || disabled, + children: /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, { + children: [/*#__PURE__*/(0,jsx_runtime.jsx)("strong", { + children: "\u8003\u8BD5\u524D\u4EBA\u8138\u8EAB\u4EFD\u6838\u9A8C" }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { placement: "right", overlayStyle: { maxWidth: 600 }, - title: /*#__PURE__*/(0,jsx_runtime.jsx)("div", { - children: "\u52FE\u9009\u540E\uFF0C\u5B66\u751F\u7B2C\u4E00\u6B21\u8FDB\u5165\u8003\u8BD5\u65F6\uFF0C\u9700\u8981\u8F93\u5165\u5F00\u8003\u5BC6\u7801\u624D\u80FD\u8FDB\u5165\u8003\u8BD5\u7B54\u9898\u9875\u9762" - }), + title: "勾选后,学生开始考试前将会要求调用摄像头完成拍照采集,系统将自动对采集的学生照片与已录入照片进行比对审核(教师/助教也可进行手动审核),审核通过之后学生才能开始考试。", children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { style: { cursor: 'pointer', - color: '#4C6FFF' + color: '#4C6FFF', + marginLeft: 8 } }) - }), /*#__PURE__*/(0,jsx_runtime.jsx)("br", {}), data.is_start_locked && (0,authority/* isAdmin */.GJ)() && /*#__PURE__*/(0,jsx_runtime.jsx)(row/* default */.Z, { - className: ConfigWorksmodules.unlockKeyWrapper, - children: /*#__PURE__*/(0,jsx_runtime.jsx)(input/* default */.Z, { - value: data.start_password, - disabled: disabled, - placeholder: "\u8BF7\u8F93\u5165\u5F00\u8003\u5BC6\u7801", - onChange: function onChange(e) { - return setData(function (prevData) { - return objectSpread2_default()(objectSpread2_default()({}, prevData), {}, { - start_password: e.target.value - }); - }); - }, - className: ConfigWorksmodules.unlockKeyInput - }) })] }) - }), (commonHeader === null || commonHeader === void 0 ? void 0 : commonHeader.is_random) && /*#__PURE__*/(0,jsx_runtime.jsx)(row/* default */.Z, { - children: /*#__PURE__*/(0,jsx_runtime.jsxs)(col/* default */.Z, { - span: 24, - className: ConfigWorksmodules.mb28, - children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { - checked: data.use_blank_score, - disabled: (commonHeader === null || commonHeader === void 0 ? void 0 : commonHeader.exercise_status) != 1 ? true : disabled, - onChange: function onChange(e) { - data.use_blank_score = e.target.checked; - setData(Object.assign({}, data)); - }, - children: /*#__PURE__*/(0,jsx_runtime.jsx)("strong", { - children: "\u591A\u9009\u9898\u90E8\u5206\u5F97\u5206" - }) + }) + }), (commonHeader === null || commonHeader === void 0 ? void 0 : commonHeader.is_random) && /*#__PURE__*/(0,jsx_runtime.jsx)(es_form/* default */.Z.Item, { + name: "use_blank_score", + valuePropName: "checked", + children: /*#__PURE__*/(0,jsx_runtime.jsx)(es_checkbox/* default */.Z, { + disabled: (commonHeader === null || commonHeader === void 0 ? void 0 : commonHeader.exercise_status) != 1 ? true : disabled, + children: /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, { + children: [/*#__PURE__*/(0,jsx_runtime.jsx)("strong", { + children: "\u591A\u9009\u9898\u90E8\u5206\u5F97\u5206" }), /*#__PURE__*/(0,jsx_runtime.jsx)(tooltip/* default */.Z, { placement: "right", overlayStyle: { @@ -18091,22 +18175,23 @@ var PreventCheatingSettings_PublishSettings = function PublishSettings(_ref) { children: /*#__PURE__*/(0,jsx_runtime.jsx)(QuestionCircleOutlined/* default */.Z, { style: { cursor: 'pointer', - color: '#4C6FFF' + color: '#4C6FFF', + marginLeft: 8 } }) - }), /*#__PURE__*/(0,jsx_runtime.jsx)("br", {})] + })] }) - })] - }), /*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, { - children: ((0,authority/* isAdminOrCreator */.aN)() || (exercise === null || exercise === void 0 || (_exercise$commonHeade = exercise.commonHeader) === null || _exercise$commonHeade === void 0 ? void 0 : _exercise$commonHeade.exercise_author)) && /*#__PURE__*/(0,jsx_runtime.jsx)(FixedButton/* FixedButton */.t, { - okText: "\u4FDD\u5B58\u8BBE\u7F6E", - onCancel: function onCancel() { - setDefaultData(); - }, - onOk: handleSubmit }) })] - }) + }), ((0,authority/* isAdminOrCreator */.aN)() || (exercise === null || exercise === void 0 || (_exercise$commonHeade = exercise.commonHeader) === null || _exercise$commonHeade === void 0 ? void 0 : _exercise$commonHeade.exercise_author)) && /*#__PURE__*/(0,jsx_runtime.jsx)(FixedButton/* FixedButton */.t, { + okText: "\u4FDD\u5B58\u8BBE\u7F6E", + onCancel: function onCancel() { + setDefaultData(); + }, + onOk: function onOk() { + form.submit(); + } + })] }), /*#__PURE__*/(0,jsx_runtime.jsx)(components_AddIPRange, {})] }); }; diff --git a/p__Classrooms__Lists__Exercise__Detail__index.06403803.chunk.css b/p__Classrooms__Lists__Exercise__Detail__index.f7d9c0af.chunk.css similarity index 99% rename from p__Classrooms__Lists__Exercise__Detail__index.06403803.chunk.css rename to p__Classrooms__Lists__Exercise__Detail__index.f7d9c0af.chunk.css index 6585d534b8..637224cf28 100644 --- a/p__Classrooms__Lists__Exercise__Detail__index.06403803.chunk.css +++ b/p__Classrooms__Lists__Exercise__Detail__index.f7d9c0af.chunk.css @@ -4919,6 +4919,29 @@ ul.s-navs a.active { flex-direction: column; box-orient: block-axis; } +.formDom___ahHwX { + margin-top: 30px; + margin-bottom: 20px; + padding-bottom: 40px; +} +.formDom___ahHwX strong { + font-weight: normal; + color: #333; + font-size: 16px; +} +.formDom___ahHwX label[class~='ant-radio-wrapper'], +.formDom___ahHwX label[class~='ant-checkbox-wrapper'] { + font-size: 16px; + font-weight: 500; + color: #333333; +} +.formDom___ahHwX label[class~='ant-radio-wrapper'] span, +.formDom___ahHwX label[class~='ant-checkbox-wrapper'] span { + color: #333333; +} +.formDom___ahHwX div[class~='ant-form-item'] { + margin-bottom: 28px; +} .form___TDc55 { margin-bottom: 20px; padding-bottom: 40px; diff --git a/p__index.33bc908f.async.js b/p__index.7ccfc406.async.js similarity index 99% rename from p__index.33bc908f.async.js rename to p__index.7ccfc406.async.js index d49fd29647..d5fa7f1efd 100644 --- a/p__index.33bc908f.async.js +++ b/p__index.7ccfc406.async.js @@ -103,8 +103,8 @@ var message = __webpack_require__(8591); var dropdown = __webpack_require__(38854); // EXTERNAL MODULE: ./node_modules/_flv.js@1.5.0@flv.js/src/flv.js + 38 modules var flv = __webpack_require__(31087); -// EXTERNAL MODULE: ./node_modules/_hls.js@1.4.14@hls.js/dist/hls.mjs -var dist_hls = __webpack_require__(76980); +// EXTERNAL MODULE: ./node_modules/_hls.js@1.5.0@hls.js/dist/hls.mjs +var dist_hls = __webpack_require__(49243); // EXTERNAL MODULE: ./src/utils/authority.ts var authority = __webpack_require__(19654); // EXTERNAL MODULE: ./node_modules/_react-copy-to-clipboard@5.0.2@react-copy-to-clipboard/lib/index.js @@ -584,8 +584,8 @@ var regex = /(android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini)/i; if ((src === null || src === void 0 ? void 0 : src.indexOf('.m3u8')) > -1) { if (el.current.canPlayType('application/vnd.apple.mpegurl')) { el.current.src = src; - } else if (dist_hls/* default */.Z.isSupported()) { - var hls = new dist_hls/* default */.Z(); + } else if (dist_hls/* default.isSupported */.ZP.isSupported()) { + var hls = new dist_hls/* default */.ZP(); hls.loadSource(src); hls.attachMedia(el.current); } diff --git a/umi.5719b1df.js b/umi.b8fecdfb.js similarity index 97% rename from umi.5719b1df.js rename to umi.b8fecdfb.js index de42d2cca9..c29fac36bd 100644 --- a/umi.5719b1df.js +++ b/umi.b8fecdfb.js @@ -33863,8 +33863,8 @@ marked_default().use({ /* harmony default export */ var utils_marked = ((marked_default())); // EXTERNAL MODULE: ./node_modules/_code-prettify@0.1.0@code-prettify/src/prettify.js var prettify = __webpack_require__(64018); -// EXTERNAL MODULE: ./node_modules/_hls.js@1.4.14@hls.js/dist/hls.mjs -var dist_hls = __webpack_require__(76980); +// EXTERNAL MODULE: ./node_modules/_hls.js@1.5.0@hls.js/dist/hls.mjs +var dist_hls = __webpack_require__(49243); // EXTERNAL MODULE: ./src/utils/env.ts + 1 modules var env = __webpack_require__(80548); // EXTERNAL MODULE: ./node_modules/_katex@0.11.1@katex/dist/katex.js @@ -34150,8 +34150,8 @@ function _unescape(str) { return false; }; if (item.src.indexOf('.m3u8') > -1) { - if (item.canPlayType('application/vnd.apple.mpegurl')) {} else if (dist_hls/* default */.Z.isSupported()) { - var hls = new dist_hls/* default */.Z(); + if (item.canPlayType('application/vnd.apple.mpegurl')) {} else if (dist_hls/* default.isSupported */.ZP.isSupported()) { + var hls = new dist_hls/* default */.ZP(); hls.loadSource(item.src); hls.attachMedia(item); } @@ -175113,16 +175113,17 @@ function _unsupportedIterableToArray(o, minLen) { /***/ }), -/***/ 76980: -/*!*********************************************************!*\ - !*** ./node_modules/_hls.js@1.4.14@hls.js/dist/hls.mjs ***! - \*********************************************************/ +/***/ 49243: +/*!********************************************************!*\ + !*** ./node_modules/_hls.js@1.5.0@hls.js/dist/hls.mjs ***! + \********************************************************/ /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ Z: function() { return /* binding */ Hls; } +/* harmony export */ ZP: function() { return /* binding */ Hls; } /* harmony export */ }); +/* unused harmony exports AbrController, AttrList, AudioStreamController, AudioTrackController, BasePlaylistController, BaseSegment, BaseStreamController, BufferController, CMCDController, CapLevelController, ChunkMetadata, ContentSteeringController, DateRange, EMEController, ErrorActionFlags, ErrorController, ErrorDetails, ErrorTypes, Events, FPSController, Fragment, Hls, HlsSkip, HlsUrlParameters, KeySystemFormats, KeySystems, Level, LevelDetails, LevelKey, LoadStats, MetadataSchema, NetworkErrorAction, Part, PlaylistLevelType, SubtitleStreamController, SubtitleTrackController, TimelineController, getMediaSource, isMSESupported, isSupported */ function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } @@ -175301,26 +175302,40 @@ var urlToolkit = {exports: {}}; var urlToolkitExports = urlToolkit.exports; -function ownKeys(object, enumerableOnly) { - var keys = Object.keys(object); +function ownKeys(e, r) { + var t = Object.keys(e); if (Object.getOwnPropertySymbols) { - var symbols = Object.getOwnPropertySymbols(object); - enumerableOnly && (symbols = symbols.filter(function (sym) { - return Object.getOwnPropertyDescriptor(object, sym).enumerable; - })), keys.push.apply(keys, symbols); + var o = Object.getOwnPropertySymbols(e); + r && (o = o.filter(function (r) { + return Object.getOwnPropertyDescriptor(e, r).enumerable; + })), t.push.apply(t, o); } - return keys; + return t; } -function _objectSpread2(target) { - for (var i = 1; i < arguments.length; i++) { - var source = null != arguments[i] ? arguments[i] : {}; - i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { - _defineProperty(target, key, source[key]); - }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { - Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); +function _objectSpread2(e) { + for (var r = 1; r < arguments.length; r++) { + var t = null != arguments[r] ? arguments[r] : {}; + r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { + _defineProperty(e, r, t[r]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { + Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } - return target; + return e; +} +function _toPrimitive(t, r) { + if ("object" != typeof t || !t) return t; + var e = t[Symbol.toPrimitive]; + if (void 0 !== e) { + var i = e.call(t, r || "default"); + if ("object" != typeof i) return i; + throw new TypeError("@@toPrimitive must return a primitive value."); + } + return ("string" === r ? String : Number)(t); +} +function _toPropertyKey(t) { + var i = _toPrimitive(t, "string"); + return "symbol" == typeof i ? i : String(i); } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); @@ -175350,20 +175365,6 @@ function _extends() { }; return _extends.apply(this, arguments); } -function _toPrimitive(input, hint) { - if (typeof input !== "object" || input === null) return input; - var prim = input[Symbol.toPrimitive]; - if (prim !== undefined) { - var res = prim.call(input, hint || "default"); - if (typeof res !== "object") return res; - throw new TypeError("@@toPrimitive must return a primitive value."); - } - return (hint === "string" ? String : Number)(input); -} -function _toPropertyKey(arg) { - var key = _toPrimitive(arg, "string"); - return typeof key === "symbol" ? key : String(key); -} // https://caniuse.com/mdn-javascript_builtins_number_isfinite const isFiniteNumber = Number.isFinite || function (value) { @@ -175425,12 +175426,14 @@ let Events = /*#__PURE__*/function (Events) { Events["FRAG_CHANGED"] = "hlsFragChanged"; Events["FPS_DROP"] = "hlsFpsDrop"; Events["FPS_DROP_LEVEL_CAPPING"] = "hlsFpsDropLevelCapping"; + Events["MAX_AUTO_LEVEL_UPDATED"] = "hlsMaxAutoLevelUpdated"; Events["ERROR"] = "hlsError"; Events["DESTROYING"] = "hlsDestroying"; Events["KEY_LOADING"] = "hlsKeyLoading"; Events["KEY_LOADED"] = "hlsKeyLoaded"; Events["LIVE_BACK_BUFFER_REACHED"] = "hlsLiveBackBufferReached"; Events["BACK_BUFFER_REACHED"] = "hlsBackBufferReached"; + Events["STEERING_MANIFEST_LOADED"] = "hlsSteeringManifestLoaded"; return Events; }({}); @@ -175526,7 +175529,7 @@ function exportLoggerFunctions(debugConfig, ...functions) { } function enableLogs(debugConfig, id) { // check that console is available - if (self.console && debugConfig === true || typeof debugConfig === 'object') { + if (typeof console === 'object' && debugConfig === true || typeof debugConfig === 'object') { exportLoggerFunctions(debugConfig, // Remove out from list here to hard-disable a log-level // 'trace', @@ -175534,7 +175537,7 @@ function enableLogs(debugConfig, id) { // Some browsers don't allow to use bind on console object anyway // fallback to default if needed try { - exportedLogger.log(`Debug logs enabled for "${id}" in hls.js version ${"1.4.14"}`); + exportedLogger.log(`Debug logs enabled for "${id}" in hls.js version ${"1.5.0"}`); } catch (e) { exportedLogger = fakeLogger; } @@ -175553,15 +175556,10 @@ class AttrList { if (typeof attrs === 'string') { attrs = AttrList.parseAttrList(attrs); } - for (const attr in attrs) { - if (attrs.hasOwnProperty(attr)) { - if (attr.substring(0, 2) === 'X-') { - this.clientAttrs = this.clientAttrs || []; - this.clientAttrs.push(attr); - } - this[attr] = attrs[attr]; - } - } + _extends(this, attrs); + } + get clientAttrs() { + return Object.keys(this).filter(attr => attr.substring(0, 2) === 'X-'); } decimalInteger(attrName) { const intValue = parseInt(this[attrName], 10); @@ -175740,17 +175738,14 @@ var ElementaryStreamTypes = { AUDIOVIDEO: "audiovideo" }; class BaseSegment { - // baseurl is the URL to the playlist - - // relurl is the portion of the URL that comes from inside the playlist. - - // Holds the types of data this fragment supports - constructor(baseurl) { this._byteRange = null; this._url = null; + // baseurl is the URL to the playlist this.baseurl = void 0; + // relurl is the portion of the URL that comes from inside the playlist. this.relurl = void 0; + // Holds the types of data this fragment supports this.elementaryStreams = { [ElementaryStreamTypes.AUDIO]: null, [ElementaryStreamTypes.VIDEO]: null, @@ -175762,14 +175757,13 @@ class BaseSegment { // setByteRange converts a EXT-X-BYTERANGE attribute into a two element array setByteRange(value, previous) { const params = value.split('@', 2); - const byteRange = []; + let start; if (params.length === 1) { - byteRange[0] = previous ? previous.byteRangeEndOffset : 0; + start = (previous == null ? void 0 : previous.byteRangeEndOffset) || 0; } else { - byteRange[0] = parseInt(params[1]); + start = parseInt(params[1]); } - byteRange[1] = parseInt(params[0]) + byteRange[0]; - this._byteRange = byteRange; + this._byteRange = [start, parseInt(params[0]) + start]; } get byteRange() { if (!this._byteRange) { @@ -175800,62 +175794,62 @@ class BaseSegment { * Object representing parsed data from an HLS Segment. Found in {@link hls.js#LevelDetails.fragments}. */ class Fragment extends BaseSegment { - // EXTINF has to be present for a m3u8 to be considered valid - - // sn notates the sequence number for a segment, and if set to a string can be 'initSegment' - - // levelkeys are the EXT-X-KEY tags that apply to this segment for decryption - // core difference from the private field _decryptdata is the lack of the initialized IV - // _decryptdata will set the IV for this segment based on the segment number in the fragment - // A string representing the fragment type - // A reference to the loader. Set while the fragment is loading, and removed afterwards. Used to abort fragment loading - // A reference to the key loader. Set while the key is loading, and removed afterwards. Used to abort key loading - // The level/track index to which the fragment belongs - // The continuity counter of the fragment - // The starting Presentation Time Stamp (PTS) of the fragment. Set after transmux complete. - // The ending Presentation Time Stamp (PTS) of the fragment. Set after transmux complete. - // The starting Decode Time Stamp (DTS) of the fragment. Set after transmux complete. - // The ending Decode Time Stamp (DTS) of the fragment. Set after transmux complete. - // The start time of the fragment, as listed in the manifest. Updated after transmux complete. - // Set by `updateFragPTSDTS` in level-helper - // The maximum starting Presentation Time Stamp (audio/video PTS) of the fragment. Set after transmux complete. - // The minimum ending Presentation Time Stamp (audio/video PTS) of the fragment. Set after transmux complete. - // Load/parse timing information - // A flag indicating whether the segment was downloaded in order to test bitrate, and was not buffered - // #EXTINF segment title - // The Media Initialization Section for this segment - // Fragment is the last fragment in the media playlist - // Fragment is marked by an EXT-X-GAP tag indicating that it does not contain media data and should not be loaded constructor(type, baseurl) { super(baseurl); this._decryptdata = null; this.rawProgramDateTime = null; this.programDateTime = null; this.tagList = []; + // EXTINF has to be present for a m3u8 to be considered valid this.duration = 0; + // sn notates the sequence number for a segment, and if set to a string can be 'initSegment' this.sn = 0; + // levelkeys are the EXT-X-KEY tags that apply to this segment for decryption + // core difference from the private field _decryptdata is the lack of the initialized IV + // _decryptdata will set the IV for this segment based on the segment number in the fragment this.levelkeys = void 0; + // A string representing the fragment type this.type = void 0; + // A reference to the loader. Set while the fragment is loading, and removed afterwards. Used to abort fragment loading this.loader = null; + // A reference to the key loader. Set while the key is loading, and removed afterwards. Used to abort key loading this.keyLoader = null; + // The level/track index to which the fragment belongs this.level = -1; + // The continuity counter of the fragment this.cc = 0; + // The starting Presentation Time Stamp (PTS) of the fragment. Set after transmux complete. this.startPTS = void 0; + // The ending Presentation Time Stamp (PTS) of the fragment. Set after transmux complete. this.endPTS = void 0; + // The starting Decode Time Stamp (DTS) of the fragment. Set after transmux complete. this.startDTS = void 0; + // The ending Decode Time Stamp (DTS) of the fragment. Set after transmux complete. this.endDTS = void 0; + // The start time of the fragment, as listed in the manifest. Updated after transmux complete. this.start = 0; + // Set by `updateFragPTSDTS` in level-helper this.deltaPTS = void 0; + // The maximum starting Presentation Time Stamp (audio/video PTS) of the fragment. Set after transmux complete. this.maxStartPTS = void 0; + // The minimum ending Presentation Time Stamp (audio/video PTS) of the fragment. Set after transmux complete. this.minEndPTS = void 0; + // Load/parse timing information this.stats = new LoadStats(); - this.urlId = 0; + // Init Segment bytes (unset for media segments) this.data = void 0; + // A flag indicating whether the segment was downloaded in order to test bitrate, and was not buffered this.bitrateTest = false; + // #EXTINF segment title this.title = null; + // The Media Initialization Section for this segment this.initSegment = null; + // Fragment is the last fragment in the media playlist this.endList = void 0; + // Fragment is marked by an EXT-X-GAP tag indicating that it does not contain media data and should not be loaded this.gap = void 0; + // Deprecated + this.urlId = 0; this.type = type; } get decryptdata() { @@ -175998,8 +175992,6 @@ const DEFAULT_TARGET_DURATION = 10; * Object representing parsed data from an HLS Media Playlist. Found in {@link hls.js#Level.details}. */ class LevelDetails { - // Manifest reload synchronization - constructor(baseUrl) { this.PTSKnown = false; this.alignedSliding = false; @@ -176016,6 +176008,7 @@ class LevelDetails { this.updated = true; this.advanced = true; this.availabilityDelay = void 0; + // Manifest reload synchronization this.misses = 0; this.startCC = 0; this.startSN = 0; @@ -176169,6 +176162,9 @@ function strToUtf8array(str) { return Uint8Array.from(unescape(encodeURIComponent(str)), c => c.charCodeAt(0)); } +/** returns `undefined` is `self` is missing, e.g. in node */ +const optionalSelf = typeof self !== 'undefined' ? self : undefined; + /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/requestMediaKeySystemAccess */ @@ -176212,7 +176208,6 @@ function keySystemIdToKeySystemDomain(systemId) { // return KeySystems.CLEARKEY; } } - function keySystemDomainToKeySystemFormat(keySystem) { switch (keySystem) { case KeySystems.FAIRPLAY: @@ -176236,8 +176231,8 @@ function getKeySystemsForConfig(config) { } return keySystemsToAttempt; } -const requestMediaKeySystemAccess = function () { - if (typeof self !== 'undefined' && self.navigator && self.navigator.requestMediaKeySystemAccess) { +const requestMediaKeySystemAccess = function (_optionalSelf$navigat) { + if (optionalSelf != null && (_optionalSelf$navigat = optionalSelf.navigator) != null && _optionalSelf$navigat.requestMediaKeySystemAccess) { return self.navigator.requestMediaKeySystemAccess.bind(self.navigator); } else { return null; @@ -176268,8 +176263,8 @@ function getSupportedMediaKeySystemConfigurations(keySystem, audioCodecs, videoC function createMediaKeySystemConfigurations(initDataTypes, audioCodecs, videoCodecs, drmSystemOptions) { const baseConfig = { initDataTypes: initDataTypes, - persistentState: drmSystemOptions.persistentState || 'not-allowed', - distinctiveIdentifier: drmSystemOptions.distinctiveIdentifier || 'not-allowed', + persistentState: drmSystemOptions.persistentState || 'optional', + distinctiveIdentifier: drmSystemOptions.distinctiveIdentifier || 'optional', sessionTypes: drmSystemOptions.sessionTypes || [drmSystemOptions.sessionType || 'temporary'], audioCapabilities: audioCodecs.map(codec => ({ contentType: `audio/mp4; codecs="${codec}"`, @@ -176691,6 +176686,19 @@ function writeUint32(buffer, offset, value) { buffer[offset + 3] = value & 0xff; } +// Find "moof" box +function hasMoofData(data) { + const end = data.byteLength; + for (let i = 0; i < end;) { + const size = readUint32(data, i); + if (size > 8 && data[i + 4] === 0x6d && data[i + 5] === 0x6f && data[i + 6] === 0x6f && data[i + 7] === 0x66) { + return true; + } + i = size > 1 ? i + size : end; + } + return false; +} + // Find the data for a box specified by its path function findBox(data, path) { const results = []; @@ -176814,13 +176822,11 @@ function parseInitSegment(initSegment) { const tkhd = findBox(trak, ['tkhd'])[0]; if (tkhd) { let version = tkhd[0]; - let index = version === 0 ? 12 : 20; - const trackId = readUint32(tkhd, index); + const trackId = readUint32(tkhd, version === 0 ? 12 : 20); const mdhd = findBox(trak, ['mdia', 'mdhd'])[0]; if (mdhd) { version = mdhd[0]; - index = version === 0 ? 12 : 20; - const timescale = readUint32(mdhd, index); + const timescale = readUint32(mdhd, version === 0 ? 12 : 20); const hdlr = findBox(trak, ['mdia', 'hdlr'])[0]; if (hdlr) { const hdlrType = bin2str(hdlr.subarray(8, 12)); @@ -176831,26 +176837,15 @@ function parseInitSegment(initSegment) { if (type) { // Parse codec details const stsd = findBox(trak, ['mdia', 'minf', 'stbl', 'stsd'])[0]; - let codec; - if (stsd) { - codec = bin2str(stsd.subarray(12, 16)); - // TODO: Parse codec details to be able to build MIME type. - // stsd.start += 8; - // const codecBox = findBox(stsd, [codec])[0]; - // if (codecBox) { - // TODO: Codec parsing support for avc1, mp4a, hevc, av01... - // } - } - + const stsdData = parseStsd(stsd); result[trackId] = { timescale, type }; - result[type] = { + result[type] = _objectSpread2({ timescale, - id: trackId, - codec - }; + id: trackId + }, stsdData); } } } @@ -176869,6 +176864,169 @@ function parseInitSegment(initSegment) { }); return result; } +function parseStsd(stsd) { + const sampleEntries = stsd.subarray(8); + const sampleEntriesEnd = sampleEntries.subarray(8 + 78); + const fourCC = bin2str(sampleEntries.subarray(4, 8)); + let codec = fourCC; + const encrypted = fourCC === 'enca' || fourCC === 'encv'; + if (encrypted) { + const encBox = findBox(sampleEntries, [fourCC])[0]; + const encBoxChildren = encBox.subarray(fourCC === 'enca' ? 28 : 78); + const sinfs = findBox(encBoxChildren, ['sinf']); + sinfs.forEach(sinf => { + const schm = findBox(sinf, ['schm'])[0]; + if (schm) { + const scheme = bin2str(schm.subarray(4, 8)); + if (scheme === 'cbcs' || scheme === 'cenc') { + const frma = findBox(sinf, ['frma'])[0]; + if (frma) { + // for encrypted content codec fourCC will be in frma + codec = bin2str(frma); + } + } + } + }); + } + switch (codec) { + case 'avc1': + case 'avc2': + case 'avc3': + case 'avc4': + { + // extract profile + compatibility + level out of avcC box + const avcCBox = findBox(sampleEntriesEnd, ['avcC'])[0]; + codec += '.' + toHex(avcCBox[1]) + toHex(avcCBox[2]) + toHex(avcCBox[3]); + break; + } + case 'mp4a': + { + const codecBox = findBox(sampleEntries, [fourCC])[0]; + const esdsBox = findBox(codecBox.subarray(28), ['esds'])[0]; + if (esdsBox && esdsBox.length > 12) { + let i = 4; + // ES Descriptor tag + if (esdsBox[i++] !== 0x03) { + break; + } + i = skipBERInteger(esdsBox, i); + i += 2; // skip es_id; + const flags = esdsBox[i++]; + if (flags & 0x80) { + i += 2; // skip dependency es_id + } + if (flags & 0x40) { + i += esdsBox[i++]; // skip URL + } + // Decoder config descriptor + if (esdsBox[i++] !== 0x04) { + break; + } + i = skipBERInteger(esdsBox, i); + const objectType = esdsBox[i++]; + if (objectType === 0x40) { + codec += '.' + toHex(objectType); + } else { + break; + } + i += 12; + // Decoder specific info + if (esdsBox[i++] !== 0x05) { + break; + } + i = skipBERInteger(esdsBox, i); + const firstByte = esdsBox[i++]; + let audioObjectType = (firstByte & 0xf8) >> 3; + if (audioObjectType === 31) { + audioObjectType += 1 + ((firstByte & 0x7) << 3) + ((esdsBox[i] & 0xe0) >> 5); + } + codec += '.' + audioObjectType; + } + break; + } + case 'hvc1': + case 'hev1': + { + const hvcCBox = findBox(sampleEntriesEnd, ['hvcC'])[0]; + const profileByte = hvcCBox[1]; + const profileSpace = ['', 'A', 'B', 'C'][profileByte >> 6]; + const generalProfileIdc = profileByte & 0x1f; + const profileCompat = readUint32(hvcCBox, 2); + const tierFlag = (profileByte & 0x20) >> 5 ? 'H' : 'L'; + const levelIDC = hvcCBox[12]; + const constraintIndicator = hvcCBox.subarray(6, 12); + codec += '.' + profileSpace + generalProfileIdc; + codec += '.' + profileCompat.toString(16).toUpperCase(); + codec += '.' + tierFlag + levelIDC; + let constraintString = ''; + for (let i = constraintIndicator.length; i--;) { + const byte = constraintIndicator[i]; + if (byte || constraintString) { + const encodedByte = byte.toString(16).toUpperCase(); + constraintString = '.' + encodedByte + constraintString; + } + } + codec += constraintString; + break; + } + case 'dvh1': + case 'dvhe': + { + const dvcCBox = findBox(sampleEntriesEnd, ['dvcC'])[0]; + const profile = dvcCBox[2] >> 1 & 0x7f; + const level = dvcCBox[2] << 5 & 0x20 | dvcCBox[3] >> 3 & 0x1f; + codec += '.' + addLeadingZero(profile) + '.' + addLeadingZero(level); + break; + } + case 'vp09': + { + const vpcCBox = findBox(sampleEntriesEnd, ['vpcC'])[0]; + const profile = vpcCBox[4]; + const level = vpcCBox[5]; + const bitDepth = vpcCBox[6] >> 4 & 0x0f; + codec += '.' + addLeadingZero(profile) + '.' + addLeadingZero(level) + '.' + addLeadingZero(bitDepth); + break; + } + case 'av01': + { + const av1CBox = findBox(sampleEntriesEnd, ['av1C'])[0]; + const profile = av1CBox[1] >>> 5; + const level = av1CBox[1] & 0x1f; + const tierFlag = av1CBox[2] >>> 7 ? 'H' : 'M'; + const highBitDepth = (av1CBox[2] & 0x40) >> 6; + const twelveBit = (av1CBox[2] & 0x20) >> 5; + const bitDepth = profile === 2 && highBitDepth ? twelveBit ? 12 : 10 : highBitDepth ? 10 : 8; + const monochrome = (av1CBox[2] & 0x10) >> 4; + const chromaSubsamplingX = (av1CBox[2] & 0x08) >> 3; + const chromaSubsamplingY = (av1CBox[2] & 0x04) >> 2; + const chromaSamplePosition = av1CBox[2] & 0x03; + // TODO: parse color_description_present_flag + // default it to BT.709/limited range for now + // more info https://aomediacodec.github.io/av1-isobmff/#av1codecconfigurationbox-syntax + const colorPrimaries = 1; + const transferCharacteristics = 1; + const matrixCoefficients = 1; + const videoFullRangeFlag = 0; + codec += '.' + profile + '.' + addLeadingZero(level) + tierFlag + '.' + addLeadingZero(bitDepth) + '.' + monochrome + '.' + chromaSubsamplingX + chromaSubsamplingY + chromaSamplePosition + '.' + addLeadingZero(colorPrimaries) + '.' + addLeadingZero(transferCharacteristics) + '.' + addLeadingZero(matrixCoefficients) + '.' + videoFullRangeFlag; + break; + } + } + return { + codec, + encrypted + }; +} +function skipBERInteger(bytes, i) { + const limit = i + 5; + while (bytes[i++] & 0x80 && i < limit) {} + return i; +} +function toHex(x) { + return ('0' + x.toString(16).toUpperCase()).slice(-2); +} +function addLeadingZero(num) { + return (num < 10 ? '0' : '') + num; +} function patchEncyptionData(initSegment, decryptdata) { if (!initSegment || !decryptdata) { return initSegment; @@ -177123,20 +177281,23 @@ function offsetStartDTS(initData, fmp4, timeOffset) { // get the base media decode time from the tfdt findBox(traf, ['tfdt']).forEach(tfdt => { const version = tfdt[0]; - let baseMediaDecodeTime = readUint32(tfdt, 4); - if (version === 0) { - baseMediaDecodeTime -= timeOffset * timescale; - baseMediaDecodeTime = Math.max(baseMediaDecodeTime, 0); - writeUint32(tfdt, 4, baseMediaDecodeTime); - } else { - baseMediaDecodeTime *= Math.pow(2, 32); - baseMediaDecodeTime += readUint32(tfdt, 8); - baseMediaDecodeTime -= timeOffset * timescale; - baseMediaDecodeTime = Math.max(baseMediaDecodeTime, 0); - const upper = Math.floor(baseMediaDecodeTime / (UINT32_MAX$1 + 1)); - const lower = Math.floor(baseMediaDecodeTime % (UINT32_MAX$1 + 1)); - writeUint32(tfdt, 4, upper); - writeUint32(tfdt, 8, lower); + const offset = timeOffset * timescale; + if (offset) { + let baseMediaDecodeTime = readUint32(tfdt, 4); + if (version === 0) { + baseMediaDecodeTime -= offset; + baseMediaDecodeTime = Math.max(baseMediaDecodeTime, 0); + writeUint32(tfdt, 4, baseMediaDecodeTime); + } else { + baseMediaDecodeTime *= Math.pow(2, 32); + baseMediaDecodeTime += readUint32(tfdt, 8); + baseMediaDecodeTime -= offset; + baseMediaDecodeTime = Math.max(baseMediaDecodeTime, 0); + const upper = Math.floor(baseMediaDecodeTime / (UINT32_MAX$1 + 1)); + const lower = Math.floor(baseMediaDecodeTime % (UINT32_MAX$1 + 1)); + writeUint32(tfdt, 4, upper); + writeUint32(tfdt, 8, lower); + } } }); }); @@ -177150,9 +177311,7 @@ function segmentValidRange(data) { remainder: null }; const moofs = findBox(data, ['moof']); - if (!moofs) { - return segmentedRange; - } else if (moofs.length < 2) { + if (moofs.length < 2) { segmentedRange.remainder = data; return segmentedRange; } @@ -177320,7 +177479,6 @@ function parseSEIMessageFromNALu(unescapedData, headerSize, pts, samples) { seiPtr += headerSize; let payloadType = 0; let payloadSize = 0; - let endOfCaptions = false; let b = 0; while (seiPtr < data.length) { payloadType = 0; @@ -177342,21 +177500,32 @@ function parseSEIMessageFromNALu(unescapedData, headerSize, pts, samples) { payloadSize += b; } while (b === 0xff); const leftOver = data.length - seiPtr; - if (!endOfCaptions && payloadType === 4 && seiPtr < data.length) { - endOfCaptions = true; - const countryCode = data[seiPtr++]; + // Create a variable to process the payload + let payPtr = seiPtr; + + // Increment the seiPtr to the end of the payload + if (payloadSize < leftOver) { + seiPtr += payloadSize; + } else if (payloadSize > leftOver) { + // Some type of corruption has happened? + logger.error(`Malformed SEI payload. ${payloadSize} is too small, only ${leftOver} bytes left to parse.`); + // We might be able to parse some data, but let's be safe and ignore it. + break; + } + if (payloadType === 4) { + const countryCode = data[payPtr++]; if (countryCode === 181) { - const providerCode = readUint16(data, seiPtr); - seiPtr += 2; + const providerCode = readUint16(data, payPtr); + payPtr += 2; if (providerCode === 49) { - const userStructure = readUint32(data, seiPtr); - seiPtr += 4; + const userStructure = readUint32(data, payPtr); + payPtr += 4; if (userStructure === 0x47413934) { - const userDataType = data[seiPtr++]; + const userDataType = data[payPtr++]; // Raw CEA-608 bytes wrapped in CEA-708 packet if (userDataType === 3) { - const firstByte = data[seiPtr++]; + const firstByte = data[payPtr++]; const totalCCs = 0x1f & firstByte; const enabled = 0x40 & firstByte; const totalBytes = enabled ? 2 + totalCCs * 3 : 0; @@ -177364,7 +177533,7 @@ function parseSEIMessageFromNALu(unescapedData, headerSize, pts, samples) { if (enabled) { byteArray[0] = firstByte; for (let i = 1; i < totalBytes; i++) { - byteArray[i] = data[seiPtr++]; + byteArray[i] = data[payPtr++]; } } samples.push({ @@ -177377,12 +177546,11 @@ function parseSEIMessageFromNALu(unescapedData, headerSize, pts, samples) { } } } - } else if (payloadType === 5 && payloadSize < leftOver) { - endOfCaptions = true; + } else if (payloadType === 5) { if (payloadSize > 16) { const uuidStrArray = []; for (let i = 0; i < 16; i++) { - const _b = data[seiPtr++].toString(16); + const _b = data[payPtr++].toString(16); uuidStrArray.push(_b.length == 1 ? '0' + _b : _b); if (i === 3 || i === 5 || i === 7 || i === 9) { uuidStrArray.push('-'); @@ -177391,7 +177559,7 @@ function parseSEIMessageFromNALu(unescapedData, headerSize, pts, samples) { const length = payloadSize - 16; const userDataBytes = new Uint8Array(length); for (let i = 0; i < length; i++) { - userDataBytes[i] = data[seiPtr++]; + userDataBytes[i] = data[payPtr++]; } samples.push({ payloadType, @@ -177401,10 +177569,6 @@ function parseSEIMessageFromNALu(unescapedData, headerSize, pts, samples) { userDataBytes }); } - } else if (payloadSize < leftOver) { - seiPtr += payloadSize; - } else if (payloadSize > leftOver) { - break; } } } @@ -177827,92 +177991,166 @@ function importVariableDefinition(parsed, attr, sourceVariableList) { * MediaSource helper */ -function getMediaSource() { +function getMediaSource(preferManagedMediaSource = true) { if (typeof self === 'undefined') return undefined; - return self.MediaSource || self.WebKitMediaSource; + const mms = (preferManagedMediaSource || !self.MediaSource) && self.ManagedMediaSource; + return mms || self.MediaSource || self.WebKitMediaSource; } // from http://mp4ra.org/codecs.html +// values indicate codec selection preference (lower is higher priority) const sampleEntryCodesISO = { audio: { - a3ds: true, - 'ac-3': true, - 'ac-4': true, - alac: true, - alaw: true, - dra1: true, - 'dts+': true, - 'dts-': true, - dtsc: true, - dtse: true, - dtsh: true, - 'ec-3': true, - enca: true, - g719: true, - g726: true, - m4ae: true, - mha1: true, - mha2: true, - mhm1: true, - mhm2: true, - mlpa: true, - mp4a: true, - 'raw ': true, - Opus: true, - opus: true, + a3ds: 1, + 'ac-3': 0.95, + 'ac-4': 1, + alac: 0.9, + alaw: 1, + dra1: 1, + 'dts+': 1, + 'dts-': 1, + dtsc: 1, + dtse: 1, + dtsh: 1, + 'ec-3': 0.9, + enca: 1, + fLaC: 0.9, + // MP4-RA listed codec entry for FLAC + flac: 0.9, + // legacy browser codec name for FLAC + FLAC: 0.9, + // some manifests may list "FLAC" with Apple's tools + g719: 1, + g726: 1, + m4ae: 1, + mha1: 1, + mha2: 1, + mhm1: 1, + mhm2: 1, + mlpa: 1, + mp4a: 1, + 'raw ': 1, + Opus: 1, + opus: 1, // browsers expect this to be lowercase despite MP4RA says 'Opus' - samr: true, - sawb: true, - sawp: true, - sevc: true, - sqcp: true, - ssmv: true, - twos: true, - ulaw: true + samr: 1, + sawb: 1, + sawp: 1, + sevc: 1, + sqcp: 1, + ssmv: 1, + twos: 1, + ulaw: 1 }, video: { - avc1: true, - avc2: true, - avc3: true, - avc4: true, - avcp: true, - av01: true, - drac: true, - dva1: true, - dvav: true, - dvh1: true, - dvhe: true, - encv: true, - hev1: true, - hvc1: true, - mjp2: true, - mp4v: true, - mvc1: true, - mvc2: true, - mvc3: true, - mvc4: true, - resv: true, - rv60: true, - s263: true, - svc1: true, - svc2: true, - 'vc-1': true, - vp08: true, - vp09: true + avc1: 1, + avc2: 1, + avc3: 1, + avc4: 1, + avcp: 1, + av01: 0.8, + drac: 1, + dva1: 1, + dvav: 1, + dvh1: 0.7, + dvhe: 0.7, + encv: 1, + hev1: 0.75, + hvc1: 0.75, + mjp2: 1, + mp4v: 1, + mvc1: 1, + mvc2: 1, + mvc3: 1, + mvc4: 1, + resv: 1, + rv60: 1, + s263: 1, + svc1: 1, + svc2: 1, + 'vc-1': 1, + vp08: 1, + vp09: 0.9 }, text: { - stpp: true, - wvtt: true + stpp: 1, + wvtt: 1 } }; -const MediaSource$2 = getMediaSource(); function isCodecType(codec, type) { const typeCodes = sampleEntryCodesISO[type]; - return !!typeCodes && typeCodes[codec.slice(0, 4)] === true; + return !!typeCodes && !!typeCodes[codec.slice(0, 4)]; } -function isCodecSupportedInMp4(codec, type) { +function areCodecsMediaSourceSupported(codecs, type, preferManagedMediaSource = true) { + return !codecs.split(',').some(codec => !isCodecMediaSourceSupported(codec, type, preferManagedMediaSource)); +} +function isCodecMediaSourceSupported(codec, type, preferManagedMediaSource = true) { var _MediaSource$isTypeSu; - return (_MediaSource$isTypeSu = MediaSource$2 == null ? void 0 : MediaSource$2.isTypeSupported(`${type || 'video'}/mp4;codecs="${codec}"`)) != null ? _MediaSource$isTypeSu : false; + const MediaSource = getMediaSource(preferManagedMediaSource); + return (_MediaSource$isTypeSu = MediaSource == null ? void 0 : MediaSource.isTypeSupported(mimeTypeForCodec(codec, type))) != null ? _MediaSource$isTypeSu : false; +} +function mimeTypeForCodec(codec, type) { + return `${type}/mp4;codecs="${codec}"`; +} +function videoCodecPreferenceValue(videoCodec) { + if (videoCodec) { + const fourCC = videoCodec.substring(0, 4); + return sampleEntryCodesISO.video[fourCC]; + } + return 2; +} +function codecsSetSelectionPreferenceValue(codecSet) { + return codecSet.split(',').reduce((num, fourCC) => { + const preferenceValue = sampleEntryCodesISO.video[fourCC]; + if (preferenceValue) { + return (preferenceValue * 2 + num) / (num ? 3 : 2); + } + return (sampleEntryCodesISO.audio[fourCC] + num) / (num ? 2 : 1); + }, 0); +} +const CODEC_COMPATIBLE_NAMES = {}; +function getCodecCompatibleNameLower(lowerCaseCodec, preferManagedMediaSource = true) { + if (CODEC_COMPATIBLE_NAMES[lowerCaseCodec]) { + return CODEC_COMPATIBLE_NAMES[lowerCaseCodec]; + } + + // Idealy fLaC and Opus would be first (spec-compliant) but + // some browsers will report that fLaC is supported then fail. + // see: https://bugs.chromium.org/p/chromium/issues/detail?id=1422728 + const codecsToCheck = { + flac: ['flac', 'fLaC', 'FLAC'], + opus: ['opus', 'Opus'] + }[lowerCaseCodec]; + for (let i = 0; i < codecsToCheck.length; i++) { + if (isCodecMediaSourceSupported(codecsToCheck[i], 'audio', preferManagedMediaSource)) { + CODEC_COMPATIBLE_NAMES[lowerCaseCodec] = codecsToCheck[i]; + return codecsToCheck[i]; + } + } + return lowerCaseCodec; +} +const AUDIO_CODEC_REGEXP = /flac|opus/i; +function getCodecCompatibleName(codec, preferManagedMediaSource = true) { + return codec.replace(AUDIO_CODEC_REGEXP, m => getCodecCompatibleNameLower(m.toLowerCase(), preferManagedMediaSource)); +} +function pickMostCompleteCodecName(parsedCodec, levelCodec) { + // Parsing of mp4a codecs strings in mp4-tools from media is incomplete as of d8c6c7a + // so use level codec is parsed codec is unavailable or incomplete + if (parsedCodec && parsedCodec !== 'mp4a') { + return parsedCodec; + } + return levelCodec; +} +function convertAVC1ToAVCOTI(codec) { + // Convert avc1 codec string from RFC-4281 to RFC-6381 for MediaSource.isTypeSupported + const avcdata = codec.split('.'); + if (avcdata.length > 2) { + let result = avcdata.shift() + '.'; + result += parseInt(avcdata.shift()).toString(16); + result += ('000' + parseInt(avcdata.shift()).toString(16)).slice(-4); + return result; + } + return codec; } const MASTER_PLAYLIST_REGEX = /#EXT-X-STREAM-INF:([^\r\n]*)(?:[\r\n](?:#[^\r\n]*)?)*([^\r\n]+)|#EXT-X-(SESSION-DATA|SESSION-KEY|DEFINE|CONTENT-STEERING|START):([^\r\n]*)[\r\n]+/g; @@ -177929,7 +178167,7 @@ const LEVEL_PLAYLIST_REGEX_FAST = new RegExp([/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.* // next segment's program date/time group 5 => the datetime spec /#.*/.source // All other non-segment oriented tags will match with all groups empty ].join('|'), 'g'); -const LEVEL_PLAYLIST_REGEX_SLOW = new RegExp([/#(EXTM3U)/.source, /#EXT-X-(DATERANGE|DEFINE|KEY|MAP|PART|PART-INF|PLAYLIST-TYPE|PRELOAD-HINT|RENDITION-REPORT|SERVER-CONTROL|SKIP|START):(.+)/.source, /#EXT-X-(BITRATE|DISCONTINUITY-SEQUENCE|MEDIA-SEQUENCE|TARGETDURATION|VERSION): *(\d+)/.source, /#EXT-X-(DISCONTINUITY|ENDLIST|GAP)/.source, /(#)([^:]*):(.*)/.source, /(#)(.*)(?:.*)\r?\n?/.source].join('|')); +const LEVEL_PLAYLIST_REGEX_SLOW = new RegExp([/#(EXTM3U)/.source, /#EXT-X-(DATERANGE|DEFINE|KEY|MAP|PART|PART-INF|PLAYLIST-TYPE|PRELOAD-HINT|RENDITION-REPORT|SERVER-CONTROL|SKIP|START):(.+)/.source, /#EXT-X-(BITRATE|DISCONTINUITY-SEQUENCE|MEDIA-SEQUENCE|TARGETDURATION|VERSION): *(\d+)/.source, /#EXT-X-(DISCONTINUITY|ENDLIST|GAP|INDEPENDENT-SEGMENTS)/.source, /(#)([^:]*):(.*)/.source, /(#)(.*)(?:.*)\r?\n?/.source].join('|')); class M3U8Parser { static findGroup(groups, mediaGroupId) { for (let i = 0; i < groups.length; i++) { @@ -177939,17 +178177,6 @@ class M3U8Parser { } } } - static convertAVC1ToAVCOTI(codec) { - // Convert avc1 codec string from RFC-4281 to RFC-6381 for MediaSource.isTypeSupported - const avcdata = codec.split('.'); - if (avcdata.length > 2) { - let result = avcdata.shift() + '.'; - result += parseInt(avcdata.shift()).toString(16); - result += ('000' + parseInt(avcdata.shift()).toString(16)).slice(-4); - return result; - } - return codec; - } static resolve(url, baseUrl) { return urlToolkitExports.buildAbsoluteURL(baseUrl, url, { alwaysNormalize: true @@ -177984,7 +178211,7 @@ class M3U8Parser { const uri = substituteVariables(parsed, result[2]) ; const level = { attrs, - bitrate: attrs.decimalInteger('AVERAGE-BANDWIDTH') || attrs.decimalInteger('BANDWIDTH'), + bitrate: attrs.decimalInteger('BANDWIDTH') || attrs.decimalInteger('AVERAGE-BANDWIDTH'), name: attrs.NAME, url: M3U8Parser.resolve(uri, baseurl) }; @@ -177993,10 +178220,7 @@ class M3U8Parser { level.width = resolution.width; level.height = resolution.height; } - setCodecs((attrs.CODECS || '').split(/[ ,]+/).filter(c => c), level); - if (level.videoCodec && level.videoCodec.indexOf('avc1') !== -1) { - level.videoCodec = M3U8Parser.convertAVC1ToAVCOTI(level.videoCodec); - } + setCodecs(attrs.CODECS, level); if (!((_level$unknownCodecs = level.unknownCodecs) != null && _level$unknownCodecs.length)) { levelsWithKnownCodecs.push(level); } @@ -178102,20 +178326,36 @@ class M3U8Parser { { substituteVariablesInAttributes(parsed, attrs, ['URI', 'GROUP-ID', 'LANGUAGE', 'ASSOC-LANGUAGE', 'STABLE-RENDITION-ID', 'NAME', 'INSTREAM-ID', 'CHARACTERISTICS', 'CHANNELS']); } + const lang = attrs.LANGUAGE; + const assocLang = attrs['ASSOC-LANGUAGE']; + const channels = attrs.CHANNELS; + const characteristics = attrs.CHARACTERISTICS; + const instreamId = attrs['INSTREAM-ID']; const media = { attrs, bitrate: 0, id: id++, groupId: attrs['GROUP-ID'] || '', - instreamId: attrs['INSTREAM-ID'], - name: attrs.NAME || attrs.LANGUAGE || '', + name: attrs.NAME || lang || '', type, default: attrs.bool('DEFAULT'), autoselect: attrs.bool('AUTOSELECT'), forced: attrs.bool('FORCED'), - lang: attrs.LANGUAGE, + lang, url: attrs.URI ? M3U8Parser.resolve(attrs.URI, baseurl) : '' }; + if (assocLang) { + media.assocLang = assocLang; + } + if (channels) { + media.channels = channels; + } + if (characteristics) { + media.characteristics = characteristics; + } + if (instreamId) { + media.instreamId = instreamId; + } if (groups != null && groups.length) { // If there are audio or text groups signalled in the manifest, let's look for a matching codec string for this track // If we don't find the track signalled, lets use the first audio groups codec we have @@ -178145,6 +178385,7 @@ class M3U8Parser { let levelkeys; let firstPdtIndex = -1; let createNextFrag = false; + let nextByteRange = null; LEVEL_PLAYLIST_REGEX_FAST.lastIndex = 0; level.m3u8 = string; level.hasVariableRefs = hasVariableReferences(string) ; @@ -178161,6 +178402,10 @@ class M3U8Parser { frag.initSegment = currentInitSegment; frag.rawProgramDateTime = currentInitSegment.rawProgramDateTime; currentInitSegment.rawProgramDateTime = null; + if (nextByteRange) { + frag.setByteRange(nextByteRange); + nextByteRange = null; + } } } const duration = result[1]; @@ -178181,7 +178426,6 @@ class M3U8Parser { frag.sn = currentSN; frag.level = id; frag.cc = discontinuityCounter; - frag.urlId = levelUrlId; fragments.push(frag); // avoid sliced strings https://github.com/video-dev/hls.js/issues/939 const uri = (' ' + result[3]).slice(1); @@ -178259,6 +178503,7 @@ class M3U8Parser { case 'VERSION': level.version = parseInt(value1); break; + case 'INDEPENDENT-SEGMENTS': case 'EXTM3U': break; case 'ENDLIST': @@ -178355,6 +178600,14 @@ class M3U8Parser { } } else { // Initial segment tag is before segment duration tag + // Handle case where EXT-X-MAP is declared after EXT-X-BYTERANGE + const end = frag.byteRangeEndOffset; + if (end) { + const start = frag.byteRangeStartOffset; + nextByteRange = `${end - start}@${start}`; + } else { + nextByteRange = null; + } setInitSegment(frag, mapAttrs, id, levelkeys); currentInitSegment = frag; createNextFrag = true; @@ -178502,16 +178755,14 @@ function parseStartTimeOffset(startAttributes) { } return null; } -function setCodecs(codecs, level) { +function setCodecs(codecsAttributeValue, level) { + let codecs = (codecsAttributeValue || '').split(/[ ,]+/).filter(c => c); ['video', 'audio', 'text'].forEach(type => { const filtered = codecs.filter(codec => isCodecType(codec, type)); if (filtered.length) { - const preferred = filtered.filter(codec => { - return codec.lastIndexOf('avc1', 0) === 0 || codec.lastIndexOf('mp4a', 0) === 0; - }); - level[`${type}Codec`] = preferred.length > 0 ? preferred[0] : filtered[0]; - - // remove from list + // Comma separated list of all codecs for type + level[`${type}Codec`] = filtered.join(','); + // Remove known codecs so that only unknownCodecs are left after iterating through each type codecs = codecs.filter(codec => filtered.indexOf(codec) === -1); } }); @@ -178690,12 +178941,14 @@ class PlaylistLoader { const { id, level, + pathwayId, url, deliveryDirectives } = data; this.load({ id, level, + pathwayId, responseType: 'text', type: PlaylistContextType.LEVEL, url, @@ -178746,7 +178999,7 @@ class PlaylistLoader { let loader = this.getInternalLoader(context); if (loader) { const loaderContext = loader.context; - if (loaderContext && loaderContext.url === context.url) { + if (loaderContext && loaderContext.url === context.url && loaderContext.level === context.level) { // same URL can't overlap logger.trace('[playlist-loader]: playlist request ongoing'); return; @@ -178770,7 +179023,7 @@ class PlaylistLoader { // Override level/track timeout for LL-HLS requests // (the default of 10000ms is counter productive to blocking playlist reload requests) - if ((_context$deliveryDire = context.deliveryDirectives) != null && _context$deliveryDire.part) { + if (isFiniteNumber((_context$deliveryDire = context.deliveryDirectives) == null ? void 0 : _context$deliveryDire.part)) { let levelDetails; if (context.type === PlaylistContextType.LEVEL && context.level !== null) { levelDetails = this.hls.levels[context.level].details; @@ -178899,8 +179152,8 @@ class PlaylistLoader { type } = context; const url = getResponseUrl(response, context); - const levelUrlId = isFiniteNumber(id) ? id : 0; - const levelId = isFiniteNumber(level) ? level : levelUrlId; + const levelUrlId = 0; + const levelId = isFiniteNumber(level) ? level : isFiniteNumber(id) ? id : 0; const levelType = mapContextToLevelType(context); const levelDetails = M3U8Parser.parseLevelPlaylist(response.data, url, levelId, levelType, levelUrlId, this.variableList); @@ -179220,6 +179473,17 @@ function getCuesInRange(cues, start, end) { } return cuesFound; } +function filterSubtitleTracks(textTrackList) { + const tracks = []; + for (let i = 0; i < textTrackList.length; i++) { + const track = textTrackList[i]; + // Edge adds a track without a label; we don't want to use it + if ((track.kind === 'subtitles' || track.kind === 'captions') && track.label) { + tracks.push(textTrackList[i]); + } + } + return tracks; +} var MetadataSchema = { audioId3: "org.id3", @@ -179478,28 +179742,35 @@ class ID3TrackController { for (let i = 0; i < ids.length; i++) { const id = ids[i]; const dateRange = dateRanges[id]; + const startTime = dateRangeDateToTimelineSeconds(dateRange.startDate, dateTimeOffset); + + // Process DateRanges to determine end-time (known DURATION, END-DATE, or END-ON-NEXT) const appendedDateRangeCues = dateRangeCuesAppended[id]; const cues = (appendedDateRangeCues == null ? void 0 : appendedDateRangeCues.cues) || {}; let durationKnown = (appendedDateRangeCues == null ? void 0 : appendedDateRangeCues.durationKnown) || false; - const startTime = dateRangeDateToTimelineSeconds(dateRange.startDate, dateTimeOffset); let endTime = MAX_CUE_ENDTIME; const endDate = dateRange.endDate; if (endDate) { endTime = dateRangeDateToTimelineSeconds(endDate, dateTimeOffset); durationKnown = true; } else if (dateRange.endOnNext && !durationKnown) { - const nextDateRangeWithSameClass = ids.reduce((filterMapArray, id) => { - const candidate = dateRanges[id]; - if (candidate.class === dateRange.class && candidate.id !== id && candidate.startDate > dateRange.startDate) { - filterMapArray.push(candidate); + const nextDateRangeWithSameClass = ids.reduce((candidateDateRange, id) => { + if (id !== dateRange.id) { + const otherDateRange = dateRanges[id]; + if (otherDateRange.class === dateRange.class && otherDateRange.startDate > dateRange.startDate && (!candidateDateRange || dateRange.startDate < candidateDateRange.startDate)) { + return otherDateRange; + } } - return filterMapArray; - }, []).sort((a, b) => a.startDate.getTime() - b.startDate.getTime())[0]; + return candidateDateRange; + }, null); if (nextDateRangeWithSameClass) { endTime = dateRangeDateToTimelineSeconds(nextDateRangeWithSameClass.startDate, dateTimeOffset); durationKnown = true; } } + + // Create TextTrack Cues for each MetadataGroup Item (select DateRange attribute) + // This is to emulate Safari HLS playback handling of DateRange tags const attributes = Object.keys(dateRange.attr); for (let j = 0; j < attributes.length; j++) { const key = attributes[j]; @@ -179527,6 +179798,8 @@ class ID3TrackController { } } } + + // Keep track of processed DateRanges by ID for updating cues with new DateRange tag attributes dateRangeCuesAppended[id] = { cues, dateRange, @@ -179709,7 +179982,7 @@ class LatencyController { lowLatencyMode, maxLiveSyncPlaybackRate } = this.config; - if (!lowLatencyMode || maxLiveSyncPlaybackRate === 1) { + if (!lowLatencyMode || maxLiveSyncPlaybackRate === 1 || !levelDetails.live) { return; } const targetLatency = this.targetLatency; @@ -179722,7 +179995,7 @@ class LatencyController { // Playback further than one target duration from target can be considered DVR playback. const liveMinLatencyDuration = Math.min(this.maxLatency, targetLatency + levelDetails.targetduration); const inLiveRange = distanceFromTarget < liveMinLatencyDuration; - if (levelDetails.live && inLiveRange && distanceFromTarget > 0.05 && this.forwardBufferLength > 1) { + if (inLiveRange && distanceFromTarget > 0.05 && this.forwardBufferLength > 1) { const max = Math.min(2, Math.max(1.0, maxLiveSyncPlaybackRate)); const rate = Math.round(2 / (1 + Math.exp(-0.75 * distanceFromTarget - this.edgeStalled)) * 20) / 20; media.playbackRate = Math.min(max, Math.max(1, rate)); @@ -179749,6 +180022,13 @@ class LatencyController { } const HdcpLevels = ['NONE', 'TYPE-0', 'TYPE-1', null]; +function isHdcpLevel(value) { + return HdcpLevels.indexOf(value) > -1; +} +const VideoRangeValues = ['SDR', 'PQ', 'HLG']; +function isVideoRange(value) { + return !!value && VideoRangeValues.indexOf(value) > -1; +} var HlsSkip = { No: "", Yes: "YES", @@ -179798,20 +180078,24 @@ class Level { this.audioCodec = void 0; this.bitrate = void 0; this.codecSet = void 0; + this.url = void 0; + this.frameRate = void 0; this.height = void 0; this.id = void 0; this.name = void 0; this.videoCodec = void 0; this.width = void 0; - this.unknownCodecs = void 0; - this.audioGroupIds = void 0; this.details = void 0; this.fragmentError = 0; this.loadError = 0; this.loaded = void 0; this.realBitrate = 0; - this.textGroupIds = void 0; - this.url = void 0; + this.supportedPromise = void 0; + this.supportedResult = void 0; + this._avgBitrate = 0; + this._audioGroups = void 0; + this._subtitleGroups = void 0; + // Deprecated (retained for backwards compatibility) this._urlId = 0; this.url = [data.url]; this._attrs = [data.attrs]; @@ -179823,47 +180107,99 @@ class Level { this.name = data.name; this.width = data.width || 0; this.height = data.height || 0; + this.frameRate = data.attrs.optionalFloat('FRAME-RATE', 0); + this._avgBitrate = data.attrs.decimalInteger('AVERAGE-BANDWIDTH'); this.audioCodec = data.audioCodec; this.videoCodec = data.videoCodec; - this.unknownCodecs = data.unknownCodecs; - this.codecSet = [data.videoCodec, data.audioCodec].filter(c => c).join(',').replace(/\.[^.,]+/g, ''); + this.codecSet = [data.videoCodec, data.audioCodec].filter(c => !!c).map(s => s.substring(0, 4)).join(','); + this.addGroupId('audio', data.attrs.AUDIO); + this.addGroupId('text', data.attrs.SUBTITLES); } get maxBitrate() { return Math.max(this.realBitrate, this.bitrate); } + get averageBitrate() { + return this._avgBitrate || this.realBitrate || this.bitrate; + } get attrs() { - return this._attrs[this._urlId]; + return this._attrs[0]; + } + get codecs() { + return this.attrs.CODECS || ''; } get pathwayId() { return this.attrs['PATHWAY-ID'] || '.'; } + get videoRange() { + return this.attrs['VIDEO-RANGE'] || 'SDR'; + } + get score() { + return this.attrs.optionalFloat('SCORE', 0); + } get uri() { - return this.url[this._urlId] || ''; + return this.url[0] || ''; } - get urlId() { - return this._urlId; + hasAudioGroup(groupId) { + return hasGroup(this._audioGroups, groupId); + } + hasSubtitleGroup(groupId) { + return hasGroup(this._subtitleGroups, groupId); + } + get audioGroups() { + return this._audioGroups; + } + get subtitleGroups() { + return this._subtitleGroups; } - set urlId(value) { - const newValue = value % this.url.length; - if (this._urlId !== newValue) { - this.fragmentError = 0; - this.loadError = 0; - this.details = undefined; - this._urlId = newValue; + addGroupId(type, groupId) { + if (!groupId) { + return; } + if (type === 'audio') { + let audioGroups = this._audioGroups; + if (!audioGroups) { + audioGroups = this._audioGroups = []; + } + if (audioGroups.indexOf(groupId) === -1) { + audioGroups.push(groupId); + } + } else if (type === 'text') { + let subtitleGroups = this._subtitleGroups; + if (!subtitleGroups) { + subtitleGroups = this._subtitleGroups = []; + } + if (subtitleGroups.indexOf(groupId) === -1) { + subtitleGroups.push(groupId); + } + } + } + + // Deprecated methods (retained for backwards compatibility) + get urlId() { + return 0; + } + set urlId(value) {} + get audioGroupIds() { + return this.audioGroups ? [this.audioGroupId] : undefined; + } + get textGroupIds() { + return this.subtitleGroups ? [this.textGroupId] : undefined; } get audioGroupId() { - var _this$audioGroupIds; - return (_this$audioGroupIds = this.audioGroupIds) == null ? void 0 : _this$audioGroupIds[this.urlId]; + var _this$audioGroups; + return (_this$audioGroups = this.audioGroups) == null ? void 0 : _this$audioGroups[0]; } get textGroupId() { - var _this$textGroupIds; - return (_this$textGroupIds = this.textGroupIds) == null ? void 0 : _this$textGroupIds[this.urlId]; + var _this$subtitleGroups; + return (_this$subtitleGroups = this.subtitleGroups) == null ? void 0 : _this$subtitleGroups[0]; } - addFallback(data) { - this.url.push(data.url); - this._attrs.push(data.attrs); + addFallback() {} +} +function hasGroup(groups, groupId) { + if (!groupId || !groups) { + return false; } + return groups.indexOf(groupId) !== -1; } function updateFromToPTS(fragFrom, fragTo) { @@ -180007,7 +180343,6 @@ function mergeDetails(oldDetails, newDetails) { newFrag.elementaryStreams = oldFrag.elementaryStreams; newFrag.loader = oldFrag.loader; newFrag.stats = oldFrag.stats; - newFrag.urlId = oldFrag.urlId; if (oldFrag.initSegment) { newFrag.initSegment = oldFrag.initSegment; currentInitSegment = oldFrag.initSegment; @@ -180017,7 +180352,7 @@ function mergeDetails(oldDetails, newDetails) { const fragmentsToCheck = newDetails.fragmentHint ? newDetails.fragments.concat(newDetails.fragmentHint) : newDetails.fragments; fragmentsToCheck.forEach(frag => { var _currentInitSegment; - if (!frag.initSegment || frag.initSegment.relurl === ((_currentInitSegment = currentInitSegment) == null ? void 0 : _currentInitSegment.relurl)) { + if (frag && (!frag.initSegment || frag.initSegment.relurl === ((_currentInitSegment = currentInitSegment) == null ? void 0 : _currentInitSegment.relurl))) { frag.initSegment = currentInitSegment; } }); @@ -180207,6 +180542,18 @@ function findPart(partList, sn, partIndex) { } return null; } +function reassignFragmentLevelIndexes(levels) { + levels.forEach((level, index) => { + const { + details + } = level; + if (details != null && details.fragments) { + details.fragments.forEach(fragment => { + fragment.level = index; + }); + } + }); +} function isTimeoutError(error) { switch (error.details) { @@ -180233,8 +180580,13 @@ function getLoaderConfigWithoutReties(loderConfig) { timeoutRetry: null }); } -function shouldRetry(retryConfig, retryCount, isTimeout, httpStatus) { - return !!retryConfig && retryCount < retryConfig.maxNumRetry && (retryForHttpStatus(httpStatus) || !!isTimeout); +function shouldRetry(retryConfig, retryCount, isTimeout, loaderResponse) { + if (!retryConfig) { + return false; + } + const httpStatus = loaderResponse == null ? void 0 : loaderResponse.code; + const retry = retryCount < retryConfig.maxNumRetry && (retryForHttpStatus(httpStatus) || !!isTimeout); + return retryConfig.shouldRetry ? retryConfig.shouldRetry(retryConfig, retryCount, isTimeout, loaderResponse, retry) : retry; } function retryForHttpStatus(httpStatus) { // Do not retry on status 4xx, status 0 (CORS error), or undefined (decrypt/gap/parse error) @@ -180322,11 +180674,16 @@ function findFragmentByPTS(fragPrevious, fragments, bufferEnd = 0, maxFragLookUp let fragNext = null; if (fragPrevious) { fragNext = fragments[fragPrevious.sn - fragments[0].sn + 1] || null; + // check for buffer-end rounding error + const bufferEdgeError = fragPrevious.endDTS - bufferEnd; + if (bufferEdgeError > 0 && bufferEdgeError < 0.0000015) { + bufferEnd += 0.0000015; + } } else if (bufferEnd === 0 && fragments[0].start === 0) { fragNext = fragments[0]; } // Prefer the next fragment if it's within tolerance - if (fragNext && fragmentWithinToleranceTest(bufferEnd, maxFragLookUpTolerance, fragNext) === 0) { + if (fragNext && (!fragPrevious || fragPrevious.level === fragNext.level) && fragmentWithinToleranceTest(bufferEnd, maxFragLookUpTolerance, fragNext) === 0) { return fragNext; } // We might be seeking past the tolerance so find the best match @@ -180401,7 +180758,6 @@ function findFragWithCC(fragments, cc) { }); } -const RENDITION_PENALTY_DURATION_MS = 300000; var NetworkErrorAction = { DoNothing: 0, SendEndCallback: 1, @@ -180452,10 +180808,10 @@ class ErrorController { this.hls = null; this.penalizedRenditions = {}; } - startLoad(startPosition) { + startLoad(startPosition) {} + stopLoad() { this.playlistError = 0; } - stopLoad() {} getVariantLevelIndex(frag) { return (frag == null ? void 0 : frag.type) === PlaylistLevelType.MAIN ? frag.level : this.hls.loadLevel; } @@ -180525,7 +180881,7 @@ class ErrorController { case ErrorDetails.SUBTITLE_TRACK_LOAD_TIMEOUT: if (context) { const level = hls.levels[hls.loadLevel]; - if (level && (context.type === PlaylistContextType.AUDIO_TRACK && context.groupId === level.audioGroupId || context.type === PlaylistContextType.SUBTITLE_TRACK && context.groupId === level.textGroupId)) { + if (level && (context.type === PlaylistContextType.AUDIO_TRACK && level.hasAudioGroup(context.groupId) || context.type === PlaylistContextType.SUBTITLE_TRACK && level.hasSubtitleGroup(context.groupId))) { // Perform Pathway switch or Redundant failover if possible for fastest recovery // otherwise allow playlist retry count to reach max error retries data.errorAction = this.getPlaylistRetryOrSwitchAction(data, hls.loadLevel); @@ -180545,16 +180901,18 @@ class ErrorController { flags: ErrorActionFlags.MoveAllAlternatesMatchingHDCP, hdcpLevel: restrictedHdcpLevel }; + } else { + this.keySystemError(data); } } return; case ErrorDetails.BUFFER_ADD_CODEC_ERROR: case ErrorDetails.REMUX_ALLOC_ERROR: + case ErrorDetails.BUFFER_APPEND_ERROR: data.errorAction = this.getLevelSwitchAction(data, (_data$level = data.level) != null ? _data$level : hls.loadLevel); return; case ErrorDetails.INTERNAL_EXCEPTION: case ErrorDetails.BUFFER_APPENDING_ERROR: - case ErrorDetails.BUFFER_APPEND_ERROR: case ErrorDetails.BUFFER_FULL_ERROR: case ErrorDetails.LEVEL_SWITCH_ERROR: case ErrorDetails.BUFFER_STALLED_ERROR: @@ -180567,20 +180925,20 @@ class ErrorController { return; } if (data.type === ErrorTypes.KEY_SYSTEM_ERROR) { - const levelIndex = this.getVariantLevelIndex(data.frag); - // Do not retry level. Escalate to fatal if switching levels fails. - data.levelRetry = false; - data.errorAction = this.getLevelSwitchAction(data, levelIndex); - return; + this.keySystemError(data); } } + keySystemError(data) { + const levelIndex = this.getVariantLevelIndex(data.frag); + // Do not retry level. Escalate to fatal if switching levels fails. + data.levelRetry = false; + data.errorAction = this.getLevelSwitchAction(data, levelIndex); + } getPlaylistRetryOrSwitchAction(data, levelIndex) { - var _data$response; const hls = this.hls; const retryConfig = getRetryConfig(hls.config.playlistLoadPolicy, data); const retryCount = this.playlistError++; - const httpStatus = (_data$response = data.response) == null ? void 0 : _data$response.code; - const retry = shouldRetry(retryConfig, retryCount, isTimeoutError(data), httpStatus); + const retry = shouldRetry(retryConfig, retryCount, isTimeoutError(data), data.response); if (retry) { return { action: NetworkErrorAction.RetryRequest, @@ -180610,12 +180968,10 @@ class ErrorController { const fragmentErrors = hls.levels.reduce((acc, level) => acc + level.fragmentError, 0); // Switch levels when out of retried or level index out of bounds if (level) { - var _data$response2; if (data.details !== ErrorDetails.FRAG_GAP) { level.fragmentError++; } - const httpStatus = (_data$response2 = data.response) == null ? void 0 : _data$response2.code; - const retry = shouldRetry(retryConfig, fragmentErrors, isTimeoutError(data), httpStatus); + const retry = shouldRetry(retryConfig, fragmentErrors, isTimeoutError(data), data.response); if (retry) { return { action: NetworkErrorAction.RetryRequest, @@ -180642,55 +180998,72 @@ class ErrorController { } const level = this.hls.levels[levelIndex]; if (level) { + var _data$frag2, _data$context2; + const errorDetails = data.details; level.loadError++; - if (hls.autoLevelEnabled) { - var _data$frag2, _data$context2; - // Search for next level to retry - let nextLevel = -1; - const { - levels, - loadLevel, - minAutoLevel, - maxAutoLevel - } = hls; - const fragErrorType = (_data$frag2 = data.frag) == null ? void 0 : _data$frag2.type; - const { - type: playlistErrorType, - groupId: playlistErrorGroupId - } = (_data$context2 = data.context) != null ? _data$context2 : {}; - for (let i = levels.length; i--;) { - const candidate = (i + loadLevel) % levels.length; - if (candidate !== loadLevel && candidate >= minAutoLevel && candidate <= maxAutoLevel && levels[candidate].loadError === 0) { - const levelCandidate = levels[candidate]; - // Skip level switch if GAP tag is found in next level at same position - if (data.details === ErrorDetails.FRAG_GAP && data.frag) { - const levelDetails = levels[candidate].details; - if (levelDetails) { - const fragCandidate = findFragmentByPTS(data.frag, levelDetails.fragments, data.frag.start); - if (fragCandidate != null && fragCandidate.gap) { - continue; - } + if (errorDetails === ErrorDetails.BUFFER_APPEND_ERROR) { + level.fragmentError++; + } + // Search for next level to retry + let nextLevel = -1; + const { + levels, + loadLevel, + minAutoLevel, + maxAutoLevel + } = hls; + if (!hls.autoLevelEnabled) { + hls.loadLevel = -1; + } + const fragErrorType = (_data$frag2 = data.frag) == null ? void 0 : _data$frag2.type; + // Find alternate audio codec if available on audio codec error + const isAudioCodecError = fragErrorType === PlaylistLevelType.AUDIO && errorDetails === ErrorDetails.FRAG_PARSING_ERROR || data.sourceBufferName === 'audio' && (errorDetails === ErrorDetails.BUFFER_ADD_CODEC_ERROR || errorDetails === ErrorDetails.BUFFER_APPEND_ERROR); + const findAudioCodecAlternate = isAudioCodecError && levels.some(({ + audioCodec + }) => level.audioCodec !== audioCodec); + // Find alternate video codec if available on video codec error + const isVideoCodecError = data.sourceBufferName === 'video' && (errorDetails === ErrorDetails.BUFFER_ADD_CODEC_ERROR || errorDetails === ErrorDetails.BUFFER_APPEND_ERROR); + const findVideoCodecAlternate = isVideoCodecError && levels.some(({ + codecSet, + audioCodec + }) => level.codecSet !== codecSet && level.audioCodec === audioCodec); + const { + type: playlistErrorType, + groupId: playlistErrorGroupId + } = (_data$context2 = data.context) != null ? _data$context2 : {}; + for (let i = levels.length; i--;) { + const candidate = (i + loadLevel) % levels.length; + if (candidate !== loadLevel && candidate >= minAutoLevel && candidate <= maxAutoLevel && levels[candidate].loadError === 0) { + var _level$audioGroups, _level$subtitleGroups; + const levelCandidate = levels[candidate]; + // Skip level switch if GAP tag is found in next level at same position + if (errorDetails === ErrorDetails.FRAG_GAP && data.frag) { + const levelDetails = levels[candidate].details; + if (levelDetails) { + const fragCandidate = findFragmentByPTS(data.frag, levelDetails.fragments, data.frag.start); + if (fragCandidate != null && fragCandidate.gap) { + continue; } - } else if (playlistErrorType === PlaylistContextType.AUDIO_TRACK && playlistErrorGroupId === levelCandidate.audioGroupId || playlistErrorType === PlaylistContextType.SUBTITLE_TRACK && playlistErrorGroupId === levelCandidate.textGroupId) { - // For audio/subs playlist errors find another group ID or fallthrough to redundant fail-over - continue; - } else if (fragErrorType === PlaylistLevelType.AUDIO && level.audioGroupId === levelCandidate.audioGroupId || fragErrorType === PlaylistLevelType.SUBTITLE && level.textGroupId === levelCandidate.textGroupId) { - // For audio/subs frag errors find another group ID or fallthrough to redundant fail-over - continue; } - nextLevel = candidate; - break; + } else if (playlistErrorType === PlaylistContextType.AUDIO_TRACK && levelCandidate.hasAudioGroup(playlistErrorGroupId) || playlistErrorType === PlaylistContextType.SUBTITLE_TRACK && levelCandidate.hasSubtitleGroup(playlistErrorGroupId)) { + // For audio/subs playlist errors find another group ID or fallthrough to redundant fail-over + continue; + } else if (fragErrorType === PlaylistLevelType.AUDIO && (_level$audioGroups = level.audioGroups) != null && _level$audioGroups.some(groupId => levelCandidate.hasAudioGroup(groupId)) || fragErrorType === PlaylistLevelType.SUBTITLE && (_level$subtitleGroups = level.subtitleGroups) != null && _level$subtitleGroups.some(groupId => levelCandidate.hasSubtitleGroup(groupId)) || findAudioCodecAlternate && level.audioCodec === levelCandidate.audioCodec || !findAudioCodecAlternate && level.audioCodec !== levelCandidate.audioCodec || findVideoCodecAlternate && level.codecSet === levelCandidate.codecSet) { + // For video/audio/subs frag errors find another group ID or fallthrough to redundant fail-over + continue; } + nextLevel = candidate; + break; } - if (nextLevel > -1 && hls.loadLevel !== nextLevel) { - data.levelRetry = true; - this.playlistError = 0; - return { - action: NetworkErrorAction.SendAlternateToPenaltyBox, - flags: ErrorActionFlags.None, - nextAutoLevel: nextLevel - }; - } + } + if (nextLevel > -1 && hls.loadLevel !== nextLevel) { + data.levelRetry = true; + this.playlistError = 0; + return { + action: NetworkErrorAction.SendAlternateToPenaltyBox, + flags: ErrorActionFlags.None, + nextAutoLevel: nextLevel + }; } } // No levels to switch / Manual level selection / Level not found @@ -180709,8 +181082,14 @@ class ErrorController { this.sendAlternateToPenaltyBox(data); if (!data.errorAction.resolved && data.details !== ErrorDetails.FRAG_GAP) { data.fatal = true; + } else if (/MediaSource readyState: ended/.test(data.error.message)) { + this.warn(`MediaSource ended after "${data.sourceBufferName}" sourceBuffer append error. Attempting to recover from media error.`); + this.hls.recoverMediaError(); } break; + case NetworkErrorAction.RetryRequest: + // handled by stream and playlist/level controllers + break; } if (data.fatal) { this.hls.stopLoad(); @@ -180732,14 +181111,6 @@ class ErrorController { case ErrorActionFlags.None: this.switchLevel(data, nextAutoLevel); break; - case ErrorActionFlags.MoveAllAlternatesMatchingHost: - { - // Handle Redundant Levels here. Pathway switching is handled by content-steering-controller - if (!errorAction.resolved) { - errorAction.resolved = this.redundantFailover(data); - } - } - break; case ErrorActionFlags.MoveAllAlternatesMatchingHDCP: if (hdcpLevel) { hls.maxHdcpLevel = HdcpLevels[HdcpLevels.indexOf(hdcpLevel) - 1]; @@ -180762,73 +181133,6 @@ class ErrorController { this.hls.nextLoadLevel = this.hls.nextAutoLevel; } } - redundantFailover(data) { - const { - hls, - penalizedRenditions - } = this; - const levelIndex = data.parent === PlaylistLevelType.MAIN ? data.level : hls.loadLevel; - const level = hls.levels[levelIndex]; - const redundantLevels = level.url.length; - const errorUrlId = data.frag ? data.frag.urlId : level.urlId; - if (level.urlId === errorUrlId && (!data.frag || level.details)) { - this.penalizeRendition(level, data); - } - for (let i = 1; i < redundantLevels; i++) { - const newUrlId = (errorUrlId + i) % redundantLevels; - const penalizedRendition = penalizedRenditions[newUrlId]; - // Check if rendition is penalized and skip if it is a bad fit for failover - if (!penalizedRendition || checkExpired(penalizedRendition, data, penalizedRenditions[errorUrlId])) { - // delete penalizedRenditions[newUrlId]; - // Update the url id of all levels so that we stay on the same set of variants when level switching - this.warn(`Switching to Redundant Stream ${newUrlId + 1}/${redundantLevels}: "${level.url[newUrlId]}" after ${data.details}`); - this.playlistError = 0; - hls.levels.forEach(lv => { - lv.urlId = newUrlId; - }); - hls.nextLoadLevel = levelIndex; - return true; - } - } - return false; - } - penalizeRendition(level, data) { - const { - penalizedRenditions - } = this; - const penalizedRendition = penalizedRenditions[level.urlId] || { - lastErrorPerfMs: 0, - errors: [], - details: undefined - }; - penalizedRendition.lastErrorPerfMs = performance.now(); - penalizedRendition.errors.push(data); - penalizedRendition.details = level.details; - penalizedRenditions[level.urlId] = penalizedRendition; - } -} -function checkExpired(penalizedRendition, data, currentPenaltyState) { - // Expire penalty for switching back to rendition after RENDITION_PENALTY_DURATION_MS - if (performance.now() - penalizedRendition.lastErrorPerfMs > RENDITION_PENALTY_DURATION_MS) { - return true; - } - // Expire penalty on GAP tag error if rendition has no GAP at position (does not cover media tracks) - const lastErrorDetails = penalizedRendition.details; - if (data.details === ErrorDetails.FRAG_GAP && lastErrorDetails && data.frag) { - const position = data.frag.start; - const candidateFrag = findFragmentByPTS(null, lastErrorDetails.fragments, position); - if (candidateFrag && !candidateFrag.gap) { - return true; - } - } - // Expire penalty if there are more errors in currentLevel than in penalizedRendition - if (currentPenaltyState && penalizedRendition.errors.length < currentPenaltyState.errors.length) { - const lastCandidateError = penalizedRendition.errors[penalizedRendition.errors.length - 1]; - if (lastErrorDetails && lastCandidateError.frag && data.frag && Math.abs(lastCandidateError.frag.start - data.frag.start) > lastErrorDetails.targetduration * 3) { - return true; - } - } - return false; } class BasePlaylistController { @@ -180849,8 +181153,10 @@ class BasePlaylistController { this.hls = this.log = this.warn = null; } clearTimer() { - clearTimeout(this.timer); - this.timer = -1; + if (this.timer !== -1) { + self.clearTimeout(this.timer); + this.timer = -1; + } } startLoad() { this.canLoad = true; @@ -180903,7 +181209,6 @@ class BasePlaylistController { } // Loading is handled by the subclasses } - shouldLoadPlaylist(playlist) { return this.canLoad && !!playlist && !!playlist.url && (!playlist.details || playlist.details.live); } @@ -181064,507 +181369,1308 @@ class BasePlaylistController { } } -let chromeOrFirefox; -class LevelController extends BasePlaylistController { - constructor(hls, contentSteeringController) { - super(hls, '[level-controller]'); - this._levels = []; - this._firstLevel = -1; - this._startLevel = void 0; - this.currentLevel = null; - this.currentLevelIndex = -1; - this.manualLevelIndex = -1; - this.steering = void 0; - this.onParsedComplete = void 0; - this.steering = contentSteeringController; - this._registerListeners(); +/* + * compute an Exponential Weighted moving average + * - https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average + * - heavily inspired from shaka-player + */ + +class EWMA { + // About half of the estimated value will be from the last |halfLife| samples by weight. + constructor(halfLife, estimate = 0, weight = 0) { + this.halfLife = void 0; + this.alpha_ = void 0; + this.estimate_ = void 0; + this.totalWeight_ = void 0; + this.halfLife = halfLife; + // Larger values of alpha expire historical data more slowly. + this.alpha_ = halfLife ? Math.exp(Math.log(0.5) / halfLife) : 0; + this.estimate_ = estimate; + this.totalWeight_ = weight; } - _registerListeners() { - const { - hls - } = this; - hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this); - hls.on(Events.MANIFEST_LOADED, this.onManifestLoaded, this); - hls.on(Events.LEVEL_LOADED, this.onLevelLoaded, this); - hls.on(Events.LEVELS_UPDATED, this.onLevelsUpdated, this); - hls.on(Events.AUDIO_TRACK_SWITCHED, this.onAudioTrackSwitched, this); - hls.on(Events.FRAG_LOADED, this.onFragLoaded, this); - hls.on(Events.ERROR, this.onError, this); + sample(weight, value) { + const adjAlpha = Math.pow(this.alpha_, weight); + this.estimate_ = value * (1 - adjAlpha) + adjAlpha * this.estimate_; + this.totalWeight_ += weight; } - _unregisterListeners() { + getTotalWeight() { + return this.totalWeight_; + } + getEstimate() { + if (this.alpha_) { + const zeroFactor = 1 - Math.pow(this.alpha_, this.totalWeight_); + if (zeroFactor) { + return this.estimate_ / zeroFactor; + } + } + return this.estimate_; + } +} + +/* + * EWMA Bandwidth Estimator + * - heavily inspired from shaka-player + * Tracks bandwidth samples and estimates available bandwidth. + * Based on the minimum of two exponentially-weighted moving averages with + * different half-lives. + */ + +class EwmaBandWidthEstimator { + constructor(slow, fast, defaultEstimate, defaultTTFB = 100) { + this.defaultEstimate_ = void 0; + this.minWeight_ = void 0; + this.minDelayMs_ = void 0; + this.slow_ = void 0; + this.fast_ = void 0; + this.defaultTTFB_ = void 0; + this.ttfb_ = void 0; + this.defaultEstimate_ = defaultEstimate; + this.minWeight_ = 0.001; + this.minDelayMs_ = 50; + this.slow_ = new EWMA(slow); + this.fast_ = new EWMA(fast); + this.defaultTTFB_ = defaultTTFB; + this.ttfb_ = new EWMA(slow); + } + update(slow, fast) { const { - hls + slow_, + fast_, + ttfb_ } = this; - hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this); - hls.off(Events.MANIFEST_LOADED, this.onManifestLoaded, this); - hls.off(Events.LEVEL_LOADED, this.onLevelLoaded, this); - hls.off(Events.LEVELS_UPDATED, this.onLevelsUpdated, this); - hls.off(Events.AUDIO_TRACK_SWITCHED, this.onAudioTrackSwitched, this); - hls.off(Events.FRAG_LOADED, this.onFragLoaded, this); - hls.off(Events.ERROR, this.onError, this); + if (slow_.halfLife !== slow) { + this.slow_ = new EWMA(slow, slow_.getEstimate(), slow_.getTotalWeight()); + } + if (fast_.halfLife !== fast) { + this.fast_ = new EWMA(fast, fast_.getEstimate(), fast_.getTotalWeight()); + } + if (ttfb_.halfLife !== slow) { + this.ttfb_ = new EWMA(slow, ttfb_.getEstimate(), ttfb_.getTotalWeight()); + } } - destroy() { - this._unregisterListeners(); - this.steering = null; - this.resetLevels(); - super.destroy(); + sample(durationMs, numBytes) { + durationMs = Math.max(durationMs, this.minDelayMs_); + const numBits = 8 * numBytes; + // weight is duration in seconds + const durationS = durationMs / 1000; + // value is bandwidth in bits/s + const bandwidthInBps = numBits / durationS; + this.fast_.sample(durationS, bandwidthInBps); + this.slow_.sample(durationS, bandwidthInBps); } - startLoad() { - const levels = this._levels; - - // clean up live level details to force reload them, and reset load errors - levels.forEach(level => { - level.loadError = 0; - level.fragmentError = 0; - }); - super.startLoad(); + sampleTTFB(ttfb) { + // weight is frequency curve applied to TTFB in seconds + // (longer times have less weight with expected input under 1 second) + const seconds = ttfb / 1000; + const weight = Math.sqrt(2) * Math.exp(-Math.pow(seconds, 2) / 2); + this.ttfb_.sample(weight, Math.max(ttfb, 5)); } - resetLevels() { - this._startLevel = undefined; - this.manualLevelIndex = -1; - this.currentLevelIndex = -1; - this.currentLevel = null; - this._levels = []; + canEstimate() { + return this.fast_.getTotalWeight() >= this.minWeight_; } - onManifestLoading(event, data) { - this.resetLevels(); + getEstimate() { + if (this.canEstimate()) { + // console.log('slow estimate:'+ Math.round(this.slow_.getEstimate())); + // console.log('fast estimate:'+ Math.round(this.fast_.getEstimate())); + // Take the minimum of these two estimates. This should have the effect of + // adapting down quickly, but up more slowly. + return Math.min(this.fast_.getEstimate(), this.slow_.getEstimate()); + } else { + return this.defaultEstimate_; + } } - onManifestLoaded(event, data) { - const levels = []; - const levelSet = {}; - let levelFromSet; - - // regroup redundant levels together - data.levels.forEach(levelParsed => { - var _levelParsed$audioCod; - const attributes = levelParsed.attrs; + getEstimateTTFB() { + if (this.ttfb_.getTotalWeight() >= this.minWeight_) { + return this.ttfb_.getEstimate(); + } else { + return this.defaultTTFB_; + } + } + destroy() {} +} - // erase audio codec info if browser does not support mp4a.40.34. - // demuxer will autodetect codec and fallback to mpeg/audio - if (((_levelParsed$audioCod = levelParsed.audioCodec) == null ? void 0 : _levelParsed$audioCod.indexOf('mp4a.40.34')) !== -1) { - chromeOrFirefox || (chromeOrFirefox = /chrome|firefox/i.test(navigator.userAgent)); - if (chromeOrFirefox) { - levelParsed.audioCodec = undefined; - } - } - const { - AUDIO, - CODECS, - 'FRAME-RATE': FRAMERATE, - 'PATHWAY-ID': PATHWAY, - RESOLUTION, - SUBTITLES - } = attributes; - const contentSteeringPrefix = `${PATHWAY || '.'}-` ; - const levelKey = `${contentSteeringPrefix}${levelParsed.bitrate}-${RESOLUTION}-${FRAMERATE}-${CODECS}`; - levelFromSet = levelSet[levelKey]; - if (!levelFromSet) { - levelFromSet = new Level(levelParsed); - levelSet[levelKey] = levelFromSet; - levels.push(levelFromSet); +const SUPPORTED_INFO_DEFAULT = { + supported: true, + configurations: [], + decodingInfoResults: [{ + supported: true, + powerEfficient: true, + smooth: true + }] +}; +const SUPPORTED_INFO_CACHE = {}; +function requiresMediaCapabilitiesDecodingInfo(level, audioTracksByGroup, currentVideoRange, currentFrameRate, currentBw, audioPreference) { + // Only test support when configuration is exceeds minimum options + const audioGroups = level.audioCodec ? level.audioGroups : null; + const audioCodecPreference = audioPreference == null ? void 0 : audioPreference.audioCodec; + const channelsPreference = audioPreference == null ? void 0 : audioPreference.channels; + const maxChannels = channelsPreference ? parseInt(channelsPreference) : audioCodecPreference ? Infinity : 2; + let audioChannels = null; + if (audioGroups != null && audioGroups.length) { + try { + if (audioGroups.length === 1 && audioGroups[0]) { + audioChannels = audioTracksByGroup.groups[audioGroups[0]].channels; } else { - levelFromSet.addFallback(levelParsed); + audioChannels = audioGroups.reduce((acc, groupId) => { + if (groupId) { + const audioTrackGroup = audioTracksByGroup.groups[groupId]; + if (!audioTrackGroup) { + throw new Error(`Audio track group ${groupId} not found`); + } + // Sum all channel key values + Object.keys(audioTrackGroup.channels).forEach(key => { + acc[key] = (acc[key] || 0) + audioTrackGroup.channels[key]; + }); + } + return acc; + }, { + 2: 0 + }); + } + } catch (error) { + return true; + } + } + return level.videoCodec !== undefined && (level.width > 1920 && level.height > 1088 || level.height > 1920 && level.width > 1088 || level.frameRate > Math.max(currentFrameRate, 30) || level.videoRange !== 'SDR' && level.videoRange !== currentVideoRange || level.bitrate > Math.max(currentBw, 8e6)) || !!audioChannels && isFiniteNumber(maxChannels) && Object.keys(audioChannels).some(channels => parseInt(channels) > maxChannels); +} +function getMediaDecodingInfoPromise(level, audioTracksByGroup, mediaCapabilities) { + const videoCodecs = level.videoCodec; + const audioCodecs = level.audioCodec; + if (!videoCodecs || !audioCodecs || !mediaCapabilities) { + return Promise.resolve(SUPPORTED_INFO_DEFAULT); + } + const baseVideoConfiguration = { + width: level.width, + height: level.height, + bitrate: Math.ceil(Math.max(level.bitrate * 0.9, level.averageBitrate)), + // Assume a framerate of 30fps since MediaCapabilities will not accept Level default of 0. + framerate: level.frameRate || 30 + }; + const videoRange = level.videoRange; + if (videoRange !== 'SDR') { + baseVideoConfiguration.transferFunction = videoRange.toLowerCase(); + } + const configurations = videoCodecs.split(',').map(videoCodec => ({ + type: 'media-source', + video: _objectSpread2(_objectSpread2({}, baseVideoConfiguration), {}, { + contentType: mimeTypeForCodec(videoCodec, 'video') + }) + })); + if (audioCodecs && level.audioGroups) { + level.audioGroups.forEach(audioGroupId => { + var _audioTracksByGroup$g; + if (!audioGroupId) { + return; } - addGroupId(levelFromSet, 'audio', AUDIO); - addGroupId(levelFromSet, 'text', SUBTITLES); + (_audioTracksByGroup$g = audioTracksByGroup.groups[audioGroupId]) == null ? void 0 : _audioTracksByGroup$g.tracks.forEach(audioTrack => { + if (audioTrack.groupId === audioGroupId) { + const channels = audioTrack.channels || ''; + const channelsNumber = parseFloat(channels); + if (isFiniteNumber(channelsNumber) && channelsNumber > 2) { + configurations.push.apply(configurations, audioCodecs.split(',').map(audioCodec => ({ + type: 'media-source', + audio: { + contentType: mimeTypeForCodec(audioCodec, 'audio'), + channels: '' + channelsNumber + // spatialRendering: + // audioCodec === 'ec-3' && channels.indexOf('JOC'), + } + }))); + } + } + }); }); - this.filterAndSortMediaOptions(levels, data); } - filterAndSortMediaOptions(unfilteredLevels, data) { - let audioTracks = []; - let subtitleTracks = []; - let resolutionFound = false; - let videoCodecFound = false; - let audioCodecFound = false; + return Promise.all(configurations.map(configuration => { + // Cache MediaCapabilities promises + const decodingInfoKey = getMediaDecodingInfoKey(configuration); + return SUPPORTED_INFO_CACHE[decodingInfoKey] || (SUPPORTED_INFO_CACHE[decodingInfoKey] = mediaCapabilities.decodingInfo(configuration)); + })).then(decodingInfoResults => ({ + supported: !decodingInfoResults.some(info => !info.supported), + configurations, + decodingInfoResults + })).catch(error => ({ + supported: false, + configurations, + decodingInfoResults: [], + error + })); +} +function getMediaDecodingInfoKey(config) { + const { + audio, + video + } = config; + const mediaConfig = video || audio; + if (mediaConfig) { + const codec = mediaConfig.contentType.split('"')[1]; + if (video) { + return `r${video.height}x${video.width}f${Math.ceil(video.framerate)}${video.transferFunction || 'sd'}_${codec}_${Math.ceil(video.bitrate / 1e5)}`; + } + if (audio) { + return `c${audio.channels}${audio.spatialRendering ? 's' : 'n'}_${codec}`; + } + } + return ''; +} - // only keep levels with supported audio/video codecs - let levels = unfilteredLevels.filter(({ - audioCodec, - videoCodec, - width, - height, - unknownCodecs - }) => { - resolutionFound || (resolutionFound = !!(width && height)); - videoCodecFound || (videoCodecFound = !!videoCodec); - audioCodecFound || (audioCodecFound = !!audioCodec); - return !(unknownCodecs != null && unknownCodecs.length) && (!audioCodec || isCodecSupportedInMp4(audioCodec, 'audio')) && (!videoCodec || isCodecSupportedInMp4(videoCodec, 'video')); - }); +/** + * @returns Whether we can detect and validate HDR capability within the window context + */ +function isHdrSupported() { + if (typeof matchMedia === 'function') { + const mediaQueryList = matchMedia('(dynamic-range: high)'); + const badQuery = matchMedia('bad query'); + if (mediaQueryList.media !== badQuery.media) { + return mediaQueryList.matches === true; + } + } + return false; +} - // remove audio-only level if we also have levels with video codecs or RESOLUTION signalled - if ((resolutionFound || videoCodecFound) && audioCodecFound) { - levels = levels.filter(({ - videoCodec, - width, - height - }) => !!videoCodec || !!(width && height)); +/** + * Sanitizes inputs to return the active video selection options for HDR/SDR. + * When both inputs are null: + * + * `{ preferHDR: false, allowedVideoRanges: [] }` + * + * When `currentVideoRange` non-null, maintain the active range: + * + * `{ preferHDR: currentVideoRange !== 'SDR', allowedVideoRanges: [currentVideoRange] }` + * + * When VideoSelectionOption non-null: + * + * - Allow all video ranges if `allowedVideoRanges` unspecified. + * - If `preferHDR` is non-null use the value to filter `allowedVideoRanges`. + * - Else check window for HDR support and set `preferHDR` to the result. + * + * @param currentVideoRange + * @param videoPreference + */ +function getVideoSelectionOptions(currentVideoRange, videoPreference) { + let preferHDR = false; + let allowedVideoRanges = []; + if (currentVideoRange) { + preferHDR = currentVideoRange !== 'SDR'; + allowedVideoRanges = [currentVideoRange]; + } + if (videoPreference) { + allowedVideoRanges = videoPreference.allowedVideoRanges || VideoRangeValues.slice(0); + preferHDR = videoPreference.preferHDR !== undefined ? videoPreference.preferHDR : isHdrSupported(); + if (preferHDR) { + allowedVideoRanges = allowedVideoRanges.filter(range => range !== 'SDR'); + } else { + allowedVideoRanges = ['SDR']; } - if (levels.length === 0) { - // Dispatch error after MANIFEST_LOADED is done propagating - Promise.resolve().then(() => { - if (this.hls) { - const error = new Error('no level with compatible codecs found in manifest'); - this.hls.trigger(Events.ERROR, { - type: ErrorTypes.MEDIA_ERROR, - details: ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR, - fatal: true, - url: data.url, - error, - reason: error.message - }); + } + return { + preferHDR, + allowedVideoRanges + }; +} + +function getStartCodecTier(codecTiers, currentVideoRange, currentBw, audioPreference, videoPreference) { + const codecSets = Object.keys(codecTiers); + const channelsPreference = audioPreference == null ? void 0 : audioPreference.channels; + const audioCodecPreference = audioPreference == null ? void 0 : audioPreference.audioCodec; + const preferStereo = channelsPreference && parseInt(channelsPreference) === 2; + // Use first level set to determine stereo, and minimum resolution and framerate + let hasStereo = true; + let hasCurrentVideoRange = false; + let minHeight = Infinity; + let minFramerate = Infinity; + let minBitrate = Infinity; + let selectedScore = 0; + let videoRanges = []; + const { + preferHDR, + allowedVideoRanges + } = getVideoSelectionOptions(currentVideoRange, videoPreference); + for (let i = codecSets.length; i--;) { + const tier = codecTiers[codecSets[i]]; + hasStereo = tier.channels[2] > 0; + minHeight = Math.min(minHeight, tier.minHeight); + minFramerate = Math.min(minFramerate, tier.minFramerate); + minBitrate = Math.min(minBitrate, tier.minBitrate); + const matchingVideoRanges = allowedVideoRanges.filter(range => tier.videoRanges[range] > 0); + if (matchingVideoRanges.length > 0) { + hasCurrentVideoRange = true; + videoRanges = matchingVideoRanges; + } + } + minHeight = isFiniteNumber(minHeight) ? minHeight : 0; + minFramerate = isFiniteNumber(minFramerate) ? minFramerate : 0; + const maxHeight = Math.max(1080, minHeight); + const maxFramerate = Math.max(30, minFramerate); + minBitrate = isFiniteNumber(minBitrate) ? minBitrate : currentBw; + currentBw = Math.max(minBitrate, currentBw); + // If there are no variants with matching preference, set currentVideoRange to undefined + if (!hasCurrentVideoRange) { + currentVideoRange = undefined; + videoRanges = []; + } + const codecSet = codecSets.reduce((selected, candidate) => { + // Remove candiates which do not meet bitrate, default audio, stereo or channels preference, 1080p or lower, 30fps or lower, or SDR/HDR selection if present + const candidateTier = codecTiers[candidate]; + if (candidate === selected) { + return selected; + } + if (candidateTier.minBitrate > currentBw) { + logStartCodecCandidateIgnored(candidate, `min bitrate of ${candidateTier.minBitrate} > current estimate of ${currentBw}`); + return selected; + } + if (!candidateTier.hasDefaultAudio) { + logStartCodecCandidateIgnored(candidate, `no renditions with default or auto-select sound found`); + return selected; + } + if (audioCodecPreference && candidate.indexOf(audioCodecPreference.substring(0, 4)) % 5 !== 0) { + logStartCodecCandidateIgnored(candidate, `audio codec preference "${audioCodecPreference}" not found`); + return selected; + } + if (channelsPreference && !preferStereo) { + if (!candidateTier.channels[channelsPreference]) { + logStartCodecCandidateIgnored(candidate, `no renditions with ${channelsPreference} channel sound found (channels options: ${Object.keys(candidateTier.channels)})`); + return selected; + } + } else if ((!audioCodecPreference || preferStereo) && hasStereo && candidateTier.channels['2'] === 0) { + logStartCodecCandidateIgnored(candidate, `no renditions with stereo sound found`); + return selected; + } + if (candidateTier.minHeight > maxHeight) { + logStartCodecCandidateIgnored(candidate, `min resolution of ${candidateTier.minHeight} > maximum of ${maxHeight}`); + return selected; + } + if (candidateTier.minFramerate > maxFramerate) { + logStartCodecCandidateIgnored(candidate, `min framerate of ${candidateTier.minFramerate} > maximum of ${maxFramerate}`); + return selected; + } + if (!videoRanges.some(range => candidateTier.videoRanges[range] > 0)) { + logStartCodecCandidateIgnored(candidate, `no variants with VIDEO-RANGE of ${JSON.stringify(videoRanges)} found`); + return selected; + } + if (candidateTier.maxScore < selectedScore) { + logStartCodecCandidateIgnored(candidate, `max score of ${candidateTier.maxScore} < selected max of ${selectedScore}`); + return selected; + } + // Remove candiates with less preferred codecs or more errors + if (selected && (codecsSetSelectionPreferenceValue(candidate) >= codecsSetSelectionPreferenceValue(selected) || candidateTier.fragmentError > codecTiers[selected].fragmentError)) { + return selected; + } + selectedScore = candidateTier.maxScore; + return candidate; + }, undefined); + return { + codecSet, + videoRanges, + preferHDR, + minFramerate, + minBitrate + }; +} +function logStartCodecCandidateIgnored(codeSet, reason) { + logger.log(`[abr] start candidates with "${codeSet}" ignored because ${reason}`); +} +function getAudioTracksByGroup(allAudioTracks) { + return allAudioTracks.reduce((audioTracksByGroup, track) => { + let trackGroup = audioTracksByGroup.groups[track.groupId]; + if (!trackGroup) { + trackGroup = audioTracksByGroup.groups[track.groupId] = { + tracks: [], + channels: { + 2: 0 + }, + hasDefault: false, + hasAutoSelect: false + }; + } + trackGroup.tracks.push(track); + const channelsKey = track.channels || '2'; + trackGroup.channels[channelsKey] = (trackGroup.channels[channelsKey] || 0) + 1; + trackGroup.hasDefault = trackGroup.hasDefault || track.default; + trackGroup.hasAutoSelect = trackGroup.hasAutoSelect || track.autoselect; + if (trackGroup.hasDefault) { + audioTracksByGroup.hasDefaultAudio = true; + } + if (trackGroup.hasAutoSelect) { + audioTracksByGroup.hasAutoSelectAudio = true; + } + return audioTracksByGroup; + }, { + hasDefaultAudio: false, + hasAutoSelectAudio: false, + groups: {} + }); +} +function getCodecTiers(levels, audioTracksByGroup, minAutoLevel, maxAutoLevel) { + return levels.slice(minAutoLevel, maxAutoLevel + 1).reduce((tiers, level) => { + if (!level.codecSet) { + return tiers; + } + const audioGroups = level.audioGroups; + let tier = tiers[level.codecSet]; + if (!tier) { + tiers[level.codecSet] = tier = { + minBitrate: Infinity, + minHeight: Infinity, + minFramerate: Infinity, + maxScore: 0, + videoRanges: { + SDR: 0 + }, + channels: { + '2': 0 + }, + hasDefaultAudio: !audioGroups, + fragmentError: 0 + }; + } + tier.minBitrate = Math.min(tier.minBitrate, level.bitrate); + const lesserWidthOrHeight = Math.min(level.height, level.width); + tier.minHeight = Math.min(tier.minHeight, lesserWidthOrHeight); + tier.minFramerate = Math.min(tier.minFramerate, level.frameRate); + tier.maxScore = Math.max(tier.maxScore, level.score); + tier.fragmentError += level.fragmentError; + tier.videoRanges[level.videoRange] = (tier.videoRanges[level.videoRange] || 0) + 1; + if (audioGroups) { + audioGroups.forEach(audioGroupId => { + if (!audioGroupId) { + return; } + const audioGroup = audioTracksByGroup.groups[audioGroupId]; + // Default audio is any group with DEFAULT=YES, or if missing then any group with AUTOSELECT=YES, or all variants + tier.hasDefaultAudio = tier.hasDefaultAudio || audioTracksByGroup.hasDefaultAudio ? audioGroup.hasDefault : audioGroup.hasAutoSelect || !audioTracksByGroup.hasDefaultAudio && !audioTracksByGroup.hasAutoSelectAudio; + Object.keys(audioGroup.channels).forEach(channels => { + tier.channels[channels] = (tier.channels[channels] || 0) + audioGroup.channels[channels]; + }); }); - return; } - if (data.audioTracks) { - audioTracks = data.audioTracks.filter(track => !track.audioCodec || isCodecSupportedInMp4(track.audioCodec, 'audio')); - // Assign ids after filtering as array indices by group-id - assignTrackIdsByGroup(audioTracks); + return tiers; + }, {}); +} +function findMatchingOption(option, tracks, matchPredicate) { + if ('attrs' in option) { + const index = tracks.indexOf(option); + if (index !== -1) { + return index; } - if (data.subtitles) { - subtitleTracks = data.subtitles; - assignTrackIdsByGroup(subtitleTracks); + } + for (let i = 0; i < tracks.length; i++) { + const track = tracks[i]; + if (matchesOption(option, track, matchPredicate)) { + return i; } - // start bitrate is the first bitrate of the manifest - const unsortedLevels = levels.slice(0); - // sort levels from lowest to highest - levels.sort((a, b) => { - if (a.attrs['HDCP-LEVEL'] !== b.attrs['HDCP-LEVEL']) { - return (a.attrs['HDCP-LEVEL'] || '') > (b.attrs['HDCP-LEVEL'] || '') ? 1 : -1; + } + return -1; +} +function matchesOption(option, track, matchPredicate) { + const { + groupId, + name, + lang, + assocLang, + characteristics + } = option; + return (groupId === undefined || track.groupId === groupId) && (name === undefined || track.name === name) && (lang === undefined || track.lang === lang) && (lang === undefined || track.assocLang === assocLang) && (characteristics === undefined || characteristicsMatch(characteristics, track.characteristics)) && (matchPredicate === undefined || matchPredicate(option, track)); +} +function characteristicsMatch(characteristicsA, characteristicsB = '') { + const arrA = characteristicsA.split(','); + const arrB = characteristicsB.split(','); + // Expects each item to be unique: + return arrA.length === arrB.length && !arrA.some(el => arrB.indexOf(el) === -1); +} +function audioMatchPredicate(option, track) { + const { + audioCodec, + channels + } = option; + return (audioCodec === undefined || (track.audioCodec || '').substring(0, 4) === audioCodec.substring(0, 4)) && (channels === undefined || channels === (track.channels || '2')); +} +function findClosestLevelWithAudioGroup(option, levels, allAudioTracks, searchIndex, matchPredicate) { + const currentLevel = levels[searchIndex]; + // Are there variants with same URI as current level? + // If so, find a match that does not require any level URI change + const variants = levels.reduce((variantMap, level, index) => { + const uri = level.uri; + const renditions = variantMap[uri] || (variantMap[uri] = []); + renditions.push(index); + return variantMap; + }, {}); + const renditions = variants[currentLevel.uri]; + if (renditions.length > 1) { + searchIndex = Math.max.apply(Math, renditions); + } + // Find best match + const currentVideoRange = currentLevel.videoRange; + const currentFrameRate = currentLevel.frameRate; + const currentVideoCodec = currentLevel.codecSet.substring(0, 4); + const matchingVideo = searchDownAndUpList(levels, searchIndex, level => { + if (level.videoRange !== currentVideoRange || level.frameRate !== currentFrameRate || level.codecSet.substring(0, 4) !== currentVideoCodec) { + return false; + } + const audioGroups = level.audioGroups; + const tracks = allAudioTracks.filter(track => !audioGroups || audioGroups.indexOf(track.groupId) !== -1); + return findMatchingOption(option, tracks, matchPredicate) > -1; + }); + if (matchingVideo > -1) { + return matchingVideo; + } + return searchDownAndUpList(levels, searchIndex, level => { + const audioGroups = level.audioGroups; + const tracks = allAudioTracks.filter(track => !audioGroups || audioGroups.indexOf(track.groupId) !== -1); + return findMatchingOption(option, tracks, matchPredicate) > -1; + }); +} +function searchDownAndUpList(arr, searchIndex, predicate) { + for (let i = searchIndex; i; i--) { + if (predicate(arr[i])) { + return i; + } + } + for (let i = searchIndex + 1; i < arr.length; i++) { + if (predicate(arr[i])) { + return i; + } + } + return -1; +} + +class AbrController { + constructor(_hls) { + this.hls = void 0; + this.lastLevelLoadSec = 0; + this.lastLoadedFragLevel = -1; + this.firstSelection = -1; + this._nextAutoLevel = -1; + this.nextAutoLevelKey = ''; + this.audioTracksByGroup = null; + this.codecTiers = null; + this.timer = -1; + this.fragCurrent = null; + this.partCurrent = null; + this.bitrateTestDelay = 0; + this.bwEstimator = void 0; + /* + This method monitors the download rate of the current fragment, and will downswitch if that fragment will not load + quickly enough to prevent underbuffering + */ + this._abandonRulesCheck = () => { + const { + fragCurrent: frag, + partCurrent: part, + hls + } = this; + const { + autoLevelEnabled, + media + } = hls; + if (!frag || !media) { + return; } - if (a.bitrate !== b.bitrate) { - return a.bitrate - b.bitrate; + const now = performance.now(); + const stats = part ? part.stats : frag.stats; + const duration = part ? part.duration : frag.duration; + const timeLoading = now - stats.loading.start; + const minAutoLevel = hls.minAutoLevel; + // If frag loading is aborted, complete, or from lowest level, stop timer and return + if (stats.aborted || stats.loaded && stats.loaded === stats.total || frag.level <= minAutoLevel) { + this.clearTimer(); + // reset forced auto level value so that next level will be selected + this._nextAutoLevel = -1; + return; + } + + // This check only runs if we're in ABR mode and actually playing + if (!autoLevelEnabled || media.paused || !media.playbackRate || !media.readyState) { + return; } - if (a.attrs['FRAME-RATE'] !== b.attrs['FRAME-RATE']) { - return a.attrs.decimalFloatingPoint('FRAME-RATE') - b.attrs.decimalFloatingPoint('FRAME-RATE'); + const bufferInfo = hls.mainForwardBufferInfo; + if (bufferInfo === null) { + return; } - if (a.attrs.SCORE !== b.attrs.SCORE) { - return a.attrs.decimalFloatingPoint('SCORE') - b.attrs.decimalFloatingPoint('SCORE'); + const ttfbEstimate = this.bwEstimator.getEstimateTTFB(); + const playbackRate = Math.abs(media.playbackRate); + // To maintain stable adaptive playback, only begin monitoring frag loading after half or more of its playback duration has passed + if (timeLoading <= Math.max(ttfbEstimate, 1000 * (duration / (playbackRate * 2)))) { + return; } - if (resolutionFound && a.height !== b.height) { - return a.height - b.height; + + // bufferStarvationDelay is an estimate of the amount time (in seconds) it will take to exhaust the buffer + const bufferStarvationDelay = bufferInfo.len / playbackRate; + const ttfb = stats.loading.first ? stats.loading.first - stats.loading.start : -1; + const loadedFirstByte = stats.loaded && ttfb > -1; + const bwEstimate = this.getBwEstimate(); + const levels = hls.levels; + const level = levels[frag.level]; + const expectedLen = stats.total || Math.max(stats.loaded, Math.round(duration * level.maxBitrate / 8)); + let timeStreaming = loadedFirstByte ? timeLoading - ttfb : timeLoading; + if (timeStreaming < 1 && loadedFirstByte) { + timeStreaming = Math.min(timeLoading, stats.loaded * 8 / bwEstimate); + } + const loadRate = loadedFirstByte ? stats.loaded * 1000 / timeStreaming : 0; + // fragLoadDelay is an estimate of the time (in seconds) it will take to buffer the remainder of the fragment + const fragLoadedDelay = loadRate ? (expectedLen - stats.loaded) / loadRate : expectedLen * 8 / bwEstimate + ttfbEstimate / 1000; + // Only downswitch if the time to finish loading the current fragment is greater than the amount of buffer left + if (fragLoadedDelay <= bufferStarvationDelay) { + return; } - return 0; - }); - let firstLevelInPlaylist = unsortedLevels[0]; - if (this.steering) { - levels = this.steering.filterParsedLevels(levels); - if (levels.length !== unsortedLevels.length) { - for (let i = 0; i < unsortedLevels.length; i++) { - if (unsortedLevels[i].pathwayId === levels[0].pathwayId) { - firstLevelInPlaylist = unsortedLevels[i]; - break; - } + const bwe = loadRate ? loadRate * 8 : bwEstimate; + let fragLevelNextLoadedDelay = Number.POSITIVE_INFINITY; + let nextLoadLevel; + // Iterate through lower level and try to find the largest one that avoids rebuffering + for (nextLoadLevel = frag.level - 1; nextLoadLevel > minAutoLevel; nextLoadLevel--) { + // compute time to load next fragment at lower level + // 8 = bits per byte (bps/Bps) + const levelNextBitrate = levels[nextLoadLevel].maxBitrate; + fragLevelNextLoadedDelay = this.getTimeToLoadFrag(ttfbEstimate / 1000, bwe, duration * levelNextBitrate, !levels[nextLoadLevel].details); + if (fragLevelNextLoadedDelay < bufferStarvationDelay) { + break; } } - } - this._levels = levels; - - // find index of first level in sorted levels - for (let i = 0; i < levels.length; i++) { - if (levels[i] === firstLevelInPlaylist) { - this._firstLevel = i; - this.log(`manifest loaded, ${levels.length} level(s) found, first bitrate: ${firstLevelInPlaylist.bitrate}`); - break; + // Only emergency switch down if it takes less time to load a new fragment at lowest level instead of continuing + // to load the current one + if (fragLevelNextLoadedDelay >= fragLoadedDelay) { + return; } - } - // Audio is only alternate if manifest include a URI along with the audio group tag, - // and this is not an audio-only stream where levels contain audio-only - const audioOnly = audioCodecFound && !videoCodecFound; - const edata = { - levels, - audioTracks, - subtitleTracks, - sessionData: data.sessionData, - sessionKeys: data.sessionKeys, - firstLevel: this._firstLevel, - stats: data.stats, - audio: audioCodecFound, - video: videoCodecFound, - altAudio: !audioOnly && audioTracks.some(t => !!t.url) + // if estimated load time of new segment is completely unreasonable, ignore and do not emergency switch down + if (fragLevelNextLoadedDelay > duration * 10) { + return; + } + hls.nextLoadLevel = hls.nextAutoLevel = nextLoadLevel; + if (loadedFirstByte) { + // If there has been loading progress, sample bandwidth using loading time offset by minimum TTFB time + this.bwEstimator.sample(timeLoading - Math.min(ttfbEstimate, ttfb), stats.loaded); + } else { + // If there has been no loading progress, sample TTFB + this.bwEstimator.sampleTTFB(timeLoading); + } + const nextLoadLevelBitrate = levels[nextLoadLevel].bitrate; + if (this.getBwEstimate() * this.hls.config.abrBandWidthUpFactor > nextLoadLevelBitrate) { + this.resetEstimator(nextLoadLevelBitrate); + } + this.clearTimer(); + logger.warn(`[abr] Fragment ${frag.sn}${part ? ' part ' + part.index : ''} of level ${frag.level} is loading too slowly; + Time to underbuffer: ${bufferStarvationDelay.toFixed(3)} s + Estimated load time for current fragment: ${fragLoadedDelay.toFixed(3)} s + Estimated load time for down switch fragment: ${fragLevelNextLoadedDelay.toFixed(3)} s + TTFB estimate: ${ttfb | 0} ms + Current BW estimate: ${isFiniteNumber(bwEstimate) ? bwEstimate | 0 : 'Unknown'} bps + New BW estimate: ${this.getBwEstimate() | 0} bps + Switching to level ${nextLoadLevel} @ ${nextLoadLevelBitrate | 0} bps`); + hls.trigger(Events.FRAG_LOAD_EMERGENCY_ABORTED, { + frag, + part, + stats + }); }; - this.hls.trigger(Events.MANIFEST_PARSED, edata); - - // Initiate loading after all controllers have received MANIFEST_PARSED - if (this.hls.config.autoStartLoad || this.hls.forceStartLoad) { - this.hls.startLoad(this.hls.config.startPosition); - } + this.hls = _hls; + this.bwEstimator = this.initEstimator(); + this.registerListeners(); } - get levels() { - if (this._levels.length === 0) { - return null; + resetEstimator(abrEwmaDefaultEstimate) { + if (abrEwmaDefaultEstimate) { + logger.log(`setting initial bwe to ${abrEwmaDefaultEstimate}`); + this.hls.config.abrEwmaDefaultEstimate = abrEwmaDefaultEstimate; } - return this._levels; + this.firstSelection = -1; + this.bwEstimator = this.initEstimator(); } - get level() { - return this.currentLevelIndex; + initEstimator() { + const config = this.hls.config; + return new EwmaBandWidthEstimator(config.abrEwmaSlowVoD, config.abrEwmaFastVoD, config.abrEwmaDefaultEstimate); } - set level(newLevel) { - const levels = this._levels; - if (levels.length === 0) { + registerListeners() { + const { + hls + } = this; + hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this); + hls.on(Events.FRAG_LOADING, this.onFragLoading, this); + hls.on(Events.FRAG_LOADED, this.onFragLoaded, this); + hls.on(Events.FRAG_BUFFERED, this.onFragBuffered, this); + hls.on(Events.LEVEL_SWITCHING, this.onLevelSwitching, this); + hls.on(Events.LEVEL_LOADED, this.onLevelLoaded, this); + hls.on(Events.LEVELS_UPDATED, this.onLevelsUpdated, this); + hls.on(Events.MAX_AUTO_LEVEL_UPDATED, this.onMaxAutoLevelUpdated, this); + hls.on(Events.ERROR, this.onError, this); + } + unregisterListeners() { + const { + hls + } = this; + if (!hls) { return; } - // check if level idx is valid - if (newLevel < 0 || newLevel >= levels.length) { - // invalid level id given, trigger error - const error = new Error('invalid level idx'); - const fatal = newLevel < 0; - this.hls.trigger(Events.ERROR, { - type: ErrorTypes.OTHER_ERROR, - details: ErrorDetails.LEVEL_SWITCH_ERROR, - level: newLevel, - fatal, - error, - reason: error.message - }); - if (fatal) { - return; - } - newLevel = Math.min(newLevel, levels.length - 1); + hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this); + hls.off(Events.FRAG_LOADING, this.onFragLoading, this); + hls.off(Events.FRAG_LOADED, this.onFragLoaded, this); + hls.off(Events.FRAG_BUFFERED, this.onFragBuffered, this); + hls.off(Events.LEVEL_SWITCHING, this.onLevelSwitching, this); + hls.off(Events.LEVEL_LOADED, this.onLevelLoaded, this); + hls.off(Events.LEVELS_UPDATED, this.onLevelsUpdated, this); + hls.off(Events.MAX_AUTO_LEVEL_UPDATED, this.onMaxAutoLevelUpdated, this); + hls.off(Events.ERROR, this.onError, this); + } + destroy() { + this.unregisterListeners(); + this.clearTimer(); + // @ts-ignore + this.hls = this._abandonRulesCheck = null; + this.fragCurrent = this.partCurrent = null; + } + onManifestLoading(event, data) { + this.lastLoadedFragLevel = -1; + this.firstSelection = -1; + this.lastLevelLoadSec = 0; + this.fragCurrent = this.partCurrent = null; + this.onLevelsUpdated(); + this.clearTimer(); + } + onLevelsUpdated() { + if (this.lastLoadedFragLevel > -1 && this.fragCurrent) { + this.lastLoadedFragLevel = this.fragCurrent.level; } - const lastLevelIndex = this.currentLevelIndex; - const lastLevel = this.currentLevel; - const lastPathwayId = lastLevel ? lastLevel.attrs['PATHWAY-ID'] : undefined; - const level = levels[newLevel]; - const pathwayId = level.attrs['PATHWAY-ID']; - this.currentLevelIndex = newLevel; - this.currentLevel = level; - if (lastLevelIndex === newLevel && level.details && lastLevel && lastPathwayId === pathwayId) { + this._nextAutoLevel = -1; + this.onMaxAutoLevelUpdated(); + this.codecTiers = null; + this.audioTracksByGroup = null; + } + onMaxAutoLevelUpdated() { + this.firstSelection = -1; + this.nextAutoLevelKey = ''; + } + onFragLoading(event, data) { + const frag = data.frag; + if (this.ignoreFragment(frag)) { return; } - this.log(`Switching to level ${newLevel}${pathwayId ? ' with Pathway ' + pathwayId : ''} from level ${lastLevelIndex}${lastPathwayId ? ' with Pathway ' + lastPathwayId : ''}`); - const levelSwitchingData = _extends({}, level, { - level: newLevel, - maxBitrate: level.maxBitrate, - attrs: level.attrs, - uri: level.uri, - urlId: level.urlId - }); - // @ts-ignore - delete levelSwitchingData._attrs; - // @ts-ignore - delete levelSwitchingData._urlId; - this.hls.trigger(Events.LEVEL_SWITCHING, levelSwitchingData); - // check if we need to load playlist for this level - const levelDetails = level.details; - if (!levelDetails || levelDetails.live) { - // level not retrieved yet, or live playlist we need to (re)load it - const hlsUrlParameters = this.switchParams(level.uri, lastLevel == null ? void 0 : lastLevel.details); - this.loadPlaylist(hlsUrlParameters); + if (!frag.bitrateTest) { + var _data$part; + this.fragCurrent = frag; + this.partCurrent = (_data$part = data.part) != null ? _data$part : null; } + this.clearTimer(); + this.timer = self.setInterval(this._abandonRulesCheck, 100); } - get manualLevel() { - return this.manualLevelIndex; + onLevelSwitching(event, data) { + this.clearTimer(); } - set manualLevel(newLevel) { - this.manualLevelIndex = newLevel; - if (this._startLevel === undefined) { - this._startLevel = newLevel; + onError(event, data) { + if (data.fatal) { + return; } - if (newLevel !== -1) { - this.level = newLevel; + switch (data.details) { + case ErrorDetails.BUFFER_ADD_CODEC_ERROR: + case ErrorDetails.BUFFER_APPEND_ERROR: + // Reset last loaded level so that a new selection can be made after calling recoverMediaError + this.lastLoadedFragLevel = -1; + this.firstSelection = -1; + break; + case ErrorDetails.FRAG_LOAD_TIMEOUT: + { + const frag = data.frag; + const { + fragCurrent, + partCurrent: part + } = this; + if (frag && fragCurrent && frag.sn === fragCurrent.sn && frag.level === fragCurrent.level) { + const now = performance.now(); + const stats = part ? part.stats : frag.stats; + const timeLoading = now - stats.loading.start; + const ttfb = stats.loading.first ? stats.loading.first - stats.loading.start : -1; + const loadedFirstByte = stats.loaded && ttfb > -1; + if (loadedFirstByte) { + const ttfbEstimate = this.bwEstimator.getEstimateTTFB(); + this.bwEstimator.sample(timeLoading - Math.min(ttfbEstimate, ttfb), stats.loaded); + } else { + this.bwEstimator.sampleTTFB(timeLoading); + } + } + break; + } } } - get firstLevel() { - return this._firstLevel; - } - set firstLevel(newLevel) { - this._firstLevel = newLevel; + getTimeToLoadFrag(timeToFirstByteSec, bandwidth, fragSizeBits, isSwitch) { + const fragLoadSec = timeToFirstByteSec + fragSizeBits / bandwidth; + const playlistLoadSec = isSwitch ? this.lastLevelLoadSec : 0; + return fragLoadSec + playlistLoadSec; } - get startLevel() { - // hls.startLevel takes precedence over config.startLevel - // if none of these values are defined, fallback on this._firstLevel (first quality level appearing in variant manifest) - if (this._startLevel === undefined) { - const configStartLevel = this.hls.config.startLevel; - if (configStartLevel !== undefined) { - return configStartLevel; - } else { - return this._firstLevel; - } + onLevelLoaded(event, data) { + const config = this.hls.config; + const { + loading + } = data.stats; + const timeLoadingMs = loading.end - loading.start; + if (isFiniteNumber(timeLoadingMs)) { + this.lastLevelLoadSec = timeLoadingMs / 1000; + } + if (data.details.live) { + this.bwEstimator.update(config.abrEwmaSlowLive, config.abrEwmaFastLive); } else { - return this._startLevel; + this.bwEstimator.update(config.abrEwmaSlowVoD, config.abrEwmaFastVoD); } } - set startLevel(newLevel) { - this._startLevel = newLevel; - } - onError(event, data) { - if (data.fatal || !data.context) { + onFragLoaded(event, { + frag, + part + }) { + const stats = part ? part.stats : frag.stats; + if (frag.type === PlaylistLevelType.MAIN) { + this.bwEstimator.sampleTTFB(stats.loading.first - stats.loading.start); + } + if (this.ignoreFragment(frag)) { return; } - if (data.context.type === PlaylistContextType.LEVEL && data.context.level === this.level) { - this.checkRetry(data); + // stop monitoring bw once frag loaded + this.clearTimer(); + // reset forced auto level value so that next level will be selected + if (frag.level === this._nextAutoLevel) { + this._nextAutoLevel = -1; } - } + this.firstSelection = -1; - // reset errors on the successful load of a fragment - onFragLoaded(event, { - frag - }) { - if (frag !== undefined && frag.type === PlaylistLevelType.MAIN) { - const level = this._levels[frag.level]; - if (level !== undefined) { - level.loadError = 0; - } + // compute level average bitrate + if (this.hls.config.abrMaxWithRealBitrate) { + const duration = part ? part.duration : frag.duration; + const level = this.hls.levels[frag.level]; + const loadedBytes = (level.loaded ? level.loaded.bytes : 0) + stats.loaded; + const loadedDuration = (level.loaded ? level.loaded.duration : 0) + duration; + level.loaded = { + bytes: loadedBytes, + duration: loadedDuration + }; + level.realBitrate = Math.round(8 * loadedBytes / loadedDuration); + } + if (frag.bitrateTest) { + const fragBufferedData = { + stats, + frag, + part, + id: frag.type + }; + this.onFragBuffered(Events.FRAG_BUFFERED, fragBufferedData); + frag.bitrateTest = false; + } else { + // store level id after successful fragment load for playback + this.lastLoadedFragLevel = frag.level; } } - onLevelLoaded(event, data) { - var _data$deliveryDirecti2; + onFragBuffered(event, data) { const { - level, - details + frag, + part } = data; - const curLevel = this._levels[level]; - if (!curLevel) { - var _data$deliveryDirecti; - this.warn(`Invalid level index ${level}`); - if ((_data$deliveryDirecti = data.deliveryDirectives) != null && _data$deliveryDirecti.skip) { - details.deltaUpdateFailed = true; - } + const stats = part != null && part.stats.loaded ? part.stats : frag.stats; + if (stats.aborted) { return; } - - // only process level loaded events matching with expected level - if (level === this.currentLevelIndex) { - // reset level load error counter on successful level loaded only if there is no issues with fragments - if (curLevel.fragmentError === 0) { - curLevel.loadError = 0; - } - this.playlistLoaded(level, data, curLevel.details); - } else if ((_data$deliveryDirecti2 = data.deliveryDirectives) != null && _data$deliveryDirecti2.skip) { - // received a delta playlist update that cannot be merged - details.deltaUpdateFailed = true; + if (this.ignoreFragment(frag)) { + return; + } + // Use the difference between parsing and request instead of buffering and request to compute fragLoadingProcessing; + // rationale is that buffer appending only happens once media is attached. This can happen when config.startFragPrefetch + // is used. If we used buffering in that case, our BW estimate sample will be very large. + const processingMs = stats.parsing.end - stats.loading.start - Math.min(stats.loading.first - stats.loading.start, this.bwEstimator.getEstimateTTFB()); + this.bwEstimator.sample(processingMs, stats.loaded); + stats.bwEstimate = this.getBwEstimate(); + if (frag.bitrateTest) { + this.bitrateTestDelay = processingMs / 1000; + } else { + this.bitrateTestDelay = 0; } } - onAudioTrackSwitched(event, data) { - const currentLevel = this.currentLevel; - if (!currentLevel) { - return; + ignoreFragment(frag) { + // Only count non-alt-audio frags which were actually buffered in our BW calculations + return frag.type !== PlaylistLevelType.MAIN || frag.sn === 'initSegment'; + } + clearTimer() { + if (this.timer > -1) { + self.clearInterval(this.timer); + this.timer = -1; } - const audioGroupId = this.hls.audioTracks[data.id].groupId; - if (currentLevel.audioGroupIds && currentLevel.audioGroupId !== audioGroupId) { - let urlId = -1; - for (let i = 0; i < currentLevel.audioGroupIds.length; i++) { - if (currentLevel.audioGroupIds[i] === audioGroupId) { - urlId = i; - break; - } - } - if (urlId !== -1 && urlId !== currentLevel.urlId) { - currentLevel.urlId = urlId; - if (this.canLoad) { - this.startLoad(); - } - } + } + get firstAutoLevel() { + const { + maxAutoLevel, + minAutoLevel + } = this.hls; + const bwEstimate = this.getBwEstimate(); + const maxStartDelay = this.hls.config.maxStarvationDelay; + const abrAutoLevel = this.findBestLevel(bwEstimate, minAutoLevel, maxAutoLevel, 0, maxStartDelay, 1, 1); + if (abrAutoLevel > -1) { + return abrAutoLevel; + } + const firstLevel = this.hls.firstLevel; + const clamped = Math.min(Math.max(firstLevel, minAutoLevel), maxAutoLevel); + logger.warn(`[abr] Could not find best starting auto level. Defaulting to first in playlist ${firstLevel} clamped to ${clamped}`); + return clamped; + } + get forcedAutoLevel() { + if (this.nextAutoLevelKey) { + return -1; } + return this._nextAutoLevel; } - loadPlaylist(hlsUrlParameters) { - super.loadPlaylist(); - const currentLevelIndex = this.currentLevelIndex; - const currentLevel = this.currentLevel; - if (currentLevel && this.shouldLoadPlaylist(currentLevel)) { - const id = currentLevel.urlId; - let url = currentLevel.uri; - if (hlsUrlParameters) { - try { - url = hlsUrlParameters.addDirectives(url); - } catch (error) { - this.warn(`Could not construct new URL with HLS Delivery Directives: ${error}`); - } - } - const pathwayId = currentLevel.attrs['PATHWAY-ID']; - this.log(`Loading level index ${currentLevelIndex}${(hlsUrlParameters == null ? void 0 : hlsUrlParameters.msn) !== undefined ? ' at sn ' + hlsUrlParameters.msn + ' part ' + hlsUrlParameters.part : ''} with${pathwayId ? ' Pathway ' + pathwayId : ''} URI ${id + 1}/${currentLevel.url.length} ${url}`); - // console.log('Current audio track group ID:', this.hls.audioTracks[this.hls.audioTrack].groupId); - // console.log('New video quality level audio group id:', levelObject.attrs.AUDIO, level); - this.clearTimer(); - this.hls.trigger(Events.LEVEL_LOADING, { - url, - level: currentLevelIndex, - id, - deliveryDirectives: hlsUrlParameters || null - }); + // return next auto level + get nextAutoLevel() { + const forcedAutoLevel = this.forcedAutoLevel; + const bwEstimator = this.bwEstimator; + const useEstimate = bwEstimator.canEstimate(); + const loadedFirstFrag = this.lastLoadedFragLevel > -1; + // in case next auto level has been forced, and bw not available or not reliable, return forced value + if (forcedAutoLevel !== -1 && (!useEstimate || !loadedFirstFrag || this.nextAutoLevelKey === this.getAutoLevelKey())) { + return forcedAutoLevel; } - } - get nextLoadLevel() { - if (this.manualLevelIndex !== -1) { - return this.manualLevelIndex; - } else { - return this.hls.nextAutoLevel; + + // compute next level using ABR logic + const nextABRAutoLevel = useEstimate && loadedFirstFrag ? this.getNextABRAutoLevel() : this.firstAutoLevel; + + // use forced auto level while it hasn't errored more than ABR selection + if (forcedAutoLevel !== -1) { + const levels = this.hls.levels; + if (levels.length > Math.max(forcedAutoLevel, nextABRAutoLevel) && levels[forcedAutoLevel].loadError <= levels[nextABRAutoLevel].loadError) { + return forcedAutoLevel; + } } + + // save result until state has changed + this._nextAutoLevel = nextABRAutoLevel; + this.nextAutoLevelKey = this.getAutoLevelKey(); + return nextABRAutoLevel; } - set nextLoadLevel(nextLevel) { - this.level = nextLevel; - if (this.manualLevelIndex === -1) { - this.hls.nextAutoLevel = nextLevel; + getAutoLevelKey() { + var _this$hls$mainForward; + return `${this.getBwEstimate()}_${(_this$hls$mainForward = this.hls.mainForwardBufferInfo) == null ? void 0 : _this$hls$mainForward.len}`; + } + getNextABRAutoLevel() { + const { + fragCurrent, + partCurrent, + hls + } = this; + const { + maxAutoLevel, + config, + minAutoLevel, + media + } = hls; + const currentFragDuration = partCurrent ? partCurrent.duration : fragCurrent ? fragCurrent.duration : 0; + + // playbackRate is the absolute value of the playback rate; if media.playbackRate is 0, we use 1 to load as + // if we're playing back at the normal rate. + const playbackRate = media && media.playbackRate !== 0 ? Math.abs(media.playbackRate) : 1.0; + const avgbw = this.getBwEstimate(); + // bufferStarvationDelay is the wall-clock time left until the playback buffer is exhausted. + const bufferInfo = hls.mainForwardBufferInfo; + const bufferStarvationDelay = (bufferInfo ? bufferInfo.len : 0) / playbackRate; + let bwFactor = config.abrBandWidthFactor; + let bwUpFactor = config.abrBandWidthUpFactor; + + // First, look to see if we can find a level matching with our avg bandwidth AND that could also guarantee no rebuffering at all + if (bufferStarvationDelay) { + const _bestLevel = this.findBestLevel(avgbw, minAutoLevel, maxAutoLevel, bufferStarvationDelay, 0, bwFactor, bwUpFactor); + if (_bestLevel >= 0) { + return _bestLevel; + } + } + // not possible to get rid of rebuffering... try to find level that will guarantee less than maxStarvationDelay of rebuffering + let maxStarvationDelay = currentFragDuration ? Math.min(currentFragDuration, config.maxStarvationDelay) : config.maxStarvationDelay; + if (!bufferStarvationDelay) { + // in case buffer is empty, let's check if previous fragment was loaded to perform a bitrate test + const bitrateTestDelay = this.bitrateTestDelay; + if (bitrateTestDelay) { + // if it is the case, then we need to adjust our max starvation delay using maxLoadingDelay config value + // max video loading delay used in automatic start level selection : + // in that mode ABR controller will ensure that video loading time (ie the time to fetch the first fragment at lowest quality level + + // the time to fetch the fragment at the appropriate quality level is less than ```maxLoadingDelay``` ) + // cap maxLoadingDelay and ensure it is not bigger 'than bitrate test' frag duration + const maxLoadingDelay = currentFragDuration ? Math.min(currentFragDuration, config.maxLoadingDelay) : config.maxLoadingDelay; + maxStarvationDelay = maxLoadingDelay - bitrateTestDelay; + logger.info(`[abr] bitrate test took ${Math.round(1000 * bitrateTestDelay)}ms, set first fragment max fetchDuration to ${Math.round(1000 * maxStarvationDelay)} ms`); + // don't use conservative factor on bitrate test + bwFactor = bwUpFactor = 1; + } } + const bestLevel = this.findBestLevel(avgbw, minAutoLevel, maxAutoLevel, bufferStarvationDelay, maxStarvationDelay, bwFactor, bwUpFactor); + logger.info(`[abr] ${bufferStarvationDelay ? 'rebuffering expected' : 'buffer is empty'}, optimal quality level ${bestLevel}`); + if (bestLevel > -1) { + return bestLevel; + } + // If no matching level found, see if min auto level would be a better option + const minLevel = hls.levels[minAutoLevel]; + const autoLevel = hls.levels[hls.loadLevel]; + if ((minLevel == null ? void 0 : minLevel.bitrate) < (autoLevel == null ? void 0 : autoLevel.bitrate)) { + return minAutoLevel; + } + // or if bitrate is not lower, continue to use loadLevel + return hls.loadLevel; } - removeLevel(levelIndex, urlId) { - const filterLevelAndGroupByIdIndex = (url, id) => id !== urlId; - const levels = this._levels.filter((level, index) => { - if (index !== levelIndex) { - return true; + getBwEstimate() { + return this.bwEstimator.canEstimate() ? this.bwEstimator.getEstimate() : this.hls.config.abrEwmaDefaultEstimate; + } + findBestLevel(currentBw, minAutoLevel, maxAutoLevel, bufferStarvationDelay, maxStarvationDelay, bwFactor, bwUpFactor) { + var _level$details; + const maxFetchDuration = bufferStarvationDelay + maxStarvationDelay; + const lastLoadedFragLevel = this.lastLoadedFragLevel; + const selectionBaseLevel = lastLoadedFragLevel === -1 ? this.hls.firstLevel : lastLoadedFragLevel; + const { + fragCurrent, + partCurrent + } = this; + const { + levels, + allAudioTracks, + loadLevel, + config + } = this.hls; + if (levels.length === 1) { + return 0; + } + const level = levels[selectionBaseLevel]; + const live = !!(level != null && (_level$details = level.details) != null && _level$details.live); + const firstSelection = loadLevel === -1 || lastLoadedFragLevel === -1; + let currentCodecSet; + let currentVideoRange = 'SDR'; + let currentFrameRate = (level == null ? void 0 : level.frameRate) || 0; + const { + audioPreference, + videoPreference + } = config; + const audioTracksByGroup = this.audioTracksByGroup || (this.audioTracksByGroup = getAudioTracksByGroup(allAudioTracks)); + if (firstSelection) { + if (this.firstSelection !== -1) { + return this.firstSelection; } - if (level.url.length > 1 && urlId !== undefined) { - level.url = level.url.filter(filterLevelAndGroupByIdIndex); - if (level.audioGroupIds) { - level.audioGroupIds = level.audioGroupIds.filter(filterLevelAndGroupByIdIndex); - } - if (level.textGroupIds) { - level.textGroupIds = level.textGroupIds.filter(filterLevelAndGroupByIdIndex); + const codecTiers = this.codecTiers || (this.codecTiers = getCodecTiers(levels, audioTracksByGroup, minAutoLevel, maxAutoLevel)); + const startTier = getStartCodecTier(codecTiers, currentVideoRange, currentBw, audioPreference, videoPreference); + const { + codecSet, + videoRanges, + minFramerate, + minBitrate, + preferHDR + } = startTier; + currentCodecSet = codecSet; + currentVideoRange = preferHDR ? videoRanges[videoRanges.length - 1] : videoRanges[0]; + currentFrameRate = minFramerate; + currentBw = Math.max(currentBw, minBitrate); + logger.log(`[abr] picked start tier ${JSON.stringify(startTier)}`); + } else { + currentCodecSet = level == null ? void 0 : level.codecSet; + currentVideoRange = level == null ? void 0 : level.videoRange; + } + const currentFragDuration = partCurrent ? partCurrent.duration : fragCurrent ? fragCurrent.duration : 0; + const ttfbEstimateSec = this.bwEstimator.getEstimateTTFB() / 1000; + const levelsSkipped = []; + for (let i = maxAutoLevel; i >= minAutoLevel; i--) { + var _levelInfo$supportedR, _levelInfo$supportedR2; + const levelInfo = levels[i]; + const upSwitch = i > selectionBaseLevel; + if (!levelInfo) { + continue; + } + if (config.useMediaCapabilities && !levelInfo.supportedResult && !levelInfo.supportedPromise) { + const mediaCapabilities = navigator.mediaCapabilities; + if (typeof (mediaCapabilities == null ? void 0 : mediaCapabilities.decodingInfo) === 'function' && requiresMediaCapabilitiesDecodingInfo(levelInfo, audioTracksByGroup, currentVideoRange, currentFrameRate, currentBw, audioPreference)) { + levelInfo.supportedPromise = getMediaDecodingInfoPromise(levelInfo, audioTracksByGroup, mediaCapabilities); + levelInfo.supportedPromise.then(decodingInfo => { + levelInfo.supportedResult = decodingInfo; + const levels = this.hls.levels; + const index = levels.indexOf(levelInfo); + if (decodingInfo.error) { + logger.warn(`[abr] MediaCapabilities decodingInfo error: "${decodingInfo.error}" for level ${index} ${JSON.stringify(decodingInfo)}`); + } else if (!decodingInfo.supported) { + logger.warn(`[abr] Unsupported MediaCapabilities decodingInfo result for level ${index} ${JSON.stringify(decodingInfo)}`); + if (index > -1 && levels.length > 1) { + logger.log(`[abr] Removing unsupported level ${index}`); + this.hls.removeLevel(index); + } + } + }); + } else { + levelInfo.supportedResult = SUPPORTED_INFO_DEFAULT; } - level.urlId = 0; - return true; } - if (this.steering) { - this.steering.removeLevel(level); + + // skip candidates which change codec-family or video-range, + // and which decrease or increase frame-rate for up and down-switch respectfully + if (currentCodecSet && levelInfo.codecSet !== currentCodecSet || currentVideoRange && levelInfo.videoRange !== currentVideoRange || upSwitch && currentFrameRate > levelInfo.frameRate || !upSwitch && currentFrameRate > 0 && currentFrameRate < levelInfo.frameRate || !((_levelInfo$supportedR = levelInfo.supportedResult) != null && (_levelInfo$supportedR2 = _levelInfo$supportedR.decodingInfoResults) != null && _levelInfo$supportedR2[0].smooth)) { + levelsSkipped.push(i); + continue; } - return false; - }); - this.hls.trigger(Events.LEVELS_UPDATED, { - levels - }); - } - onLevelsUpdated(event, { - levels - }) { - levels.forEach((level, index) => { - const { - details - } = level; - if (details != null && details.fragments) { - details.fragments.forEach(fragment => { - fragment.level = index; - }); + const levelDetails = levelInfo.details; + const avgDuration = (partCurrent ? levelDetails == null ? void 0 : levelDetails.partTarget : levelDetails == null ? void 0 : levelDetails.averagetargetduration) || currentFragDuration; + let adjustedbw; + // follow algorithm captured from stagefright : + // https://android.googlesource.com/platform/frameworks/av/+/master/media/libstagefright/httplive/LiveSession.cpp + // Pick the highest bandwidth stream below or equal to estimated bandwidth. + // consider only 80% of the available bandwidth, but if we are switching up, + // be even more conservative (70%) to avoid overestimating and immediately + // switching back. + if (!upSwitch) { + adjustedbw = bwFactor * currentBw; + } else { + adjustedbw = bwUpFactor * currentBw; } - }); - this._levels = levels; + + // Use average bitrate when starvation delay (buffer length) is gt or eq two segment durations and rebuffering is not expected (maxStarvationDelay > 0) + const bitrate = currentFragDuration && bufferStarvationDelay >= currentFragDuration * 2 && maxStarvationDelay === 0 ? levels[i].averageBitrate : levels[i].maxBitrate; + const fetchDuration = this.getTimeToLoadFrag(ttfbEstimateSec, adjustedbw, bitrate * avgDuration, levelDetails === undefined); + const canSwitchWithinTolerance = + // if adjusted bw is greater than level bitrate AND + adjustedbw >= bitrate && ( + // no level change, or new level has no error history + i === lastLoadedFragLevel || levelInfo.loadError === 0 && levelInfo.fragmentError === 0) && ( + // fragment fetchDuration unknown OR live stream OR fragment fetchDuration less than max allowed fetch duration, then this level matches + // we don't account for max Fetch Duration for live streams, this is to avoid switching down when near the edge of live sliding window ... + // special case to support startLevel = -1 (bitrateTest) on live streams : in that case we should not exit loop so that findBestLevel will return -1 + fetchDuration <= ttfbEstimateSec || !isFiniteNumber(fetchDuration) || live && !this.bitrateTestDelay || fetchDuration < maxFetchDuration); + if (canSwitchWithinTolerance) { + const forcedAutoLevel = this.forcedAutoLevel; + if (i !== loadLevel && (forcedAutoLevel === -1 || forcedAutoLevel !== loadLevel)) { + if (levelsSkipped.length) { + logger.trace(`[abr] Skipped level(s) ${levelsSkipped.join(',')} of ${maxAutoLevel} max with CODECS and VIDEO-RANGE:"${levels[levelsSkipped[0]].codecs}" ${levels[levelsSkipped[0]].videoRange}; not compatible with "${level.codecs}" ${currentVideoRange}`); + } + logger.info(`[abr] switch candidate:${selectionBaseLevel}->${i} adjustedbw(${Math.round(adjustedbw)})-bitrate=${Math.round(adjustedbw - bitrate)} ttfb:${ttfbEstimateSec.toFixed(1)} avgDuration:${avgDuration.toFixed(1)} maxFetchDuration:${maxFetchDuration.toFixed(1)} fetchDuration:${fetchDuration.toFixed(1)} firstSelection:${firstSelection} codecSet:${currentCodecSet} videoRange:${currentVideoRange} hls.loadLevel:${loadLevel}`); + } + if (firstSelection) { + this.firstSelection = i; + } + // as we are looping from highest to lowest, this will return the best achievable quality level + return i; + } + } + // not enough time budget even with quality level 0 ... rebuffering might happen + return -1; + } + set nextAutoLevel(nextLevel) { + const value = Math.max(this.hls.minAutoLevel, nextLevel); + if (this._nextAutoLevel != value) { + this.nextAutoLevelKey = ''; + this._nextAutoLevel = value; + } } } -function addGroupId(level, type, id) { - if (!id) { - return; + +/** + * @ignore + * Sub-class specialization of EventHandler base class. + * + * TaskLoop allows to schedule a task function being called (optionnaly repeatedly) on the main loop, + * scheduled asynchroneously, avoiding recursive calls in the same tick. + * + * The task itself is implemented in `doTick`. It can be requested and called for single execution + * using the `tick` method. + * + * It will be assured that the task execution method (`tick`) only gets called once per main loop "tick", + * no matter how often it gets requested for execution. Execution in further ticks will be scheduled accordingly. + * + * If further execution requests have already been scheduled on the next tick, it can be checked with `hasNextTick`, + * and cancelled with `clearNextTick`. + * + * The task can be scheduled as an interval repeatedly with a period as parameter (see `setInterval`, `clearInterval`). + * + * Sub-classes need to implement the `doTick` method which will effectively have the task execution routine. + * + * Further explanations: + * + * The baseclass has a `tick` method that will schedule the doTick call. It may be called synchroneously + * only for a stack-depth of one. On re-entrant calls, sub-sequent calls are scheduled for next main loop ticks. + * + * When the task execution (`tick` method) is called in re-entrant way this is detected and + * we are limiting the task execution per call stack to exactly one, but scheduling/post-poning further + * task processing on the next main loop iteration (also known as "next tick" in the Node/JS runtime lingo). + */ +class TaskLoop { + constructor() { + this._boundTick = void 0; + this._tickTimer = null; + this._tickInterval = null; + this._tickCallCount = 0; + this._boundTick = this.tick.bind(this); + } + destroy() { + this.onHandlerDestroying(); + this.onHandlerDestroyed(); + } + onHandlerDestroying() { + // clear all timers before unregistering from event bus + this.clearNextTick(); + this.clearInterval(); + } + onHandlerDestroyed() {} + hasInterval() { + return !!this._tickInterval; + } + hasNextTick() { + return !!this._tickTimer; } - if (type === 'audio') { - if (!level.audioGroupIds) { - level.audioGroupIds = []; + + /** + * @param millis - Interval time (ms) + * @eturns True when interval has been scheduled, false when already scheduled (no effect) + */ + setInterval(millis) { + if (!this._tickInterval) { + this._tickCallCount = 0; + this._tickInterval = self.setInterval(this._boundTick, millis); + return true; } - level.audioGroupIds[level.url.length - 1] = id; - } else if (type === 'text') { - if (!level.textGroupIds) { - level.textGroupIds = []; + return false; + } + + /** + * @returns True when interval was cleared, false when none was set (no effect) + */ + clearInterval() { + if (this._tickInterval) { + self.clearInterval(this._tickInterval); + this._tickInterval = null; + return true; } - level.textGroupIds[level.url.length - 1] = id; + return false; } -} -function assignTrackIdsByGroup(tracks) { - const groups = {}; - tracks.forEach(track => { - const groupId = track.groupId || ''; - track.id = groups[groupId] = groups[groupId] || 0; - groups[groupId]++; - }); + + /** + * @returns True when timeout was cleared, false when none was set (no effect) + */ + clearNextTick() { + if (this._tickTimer) { + self.clearTimeout(this._tickTimer); + this._tickTimer = null; + return true; + } + return false; + } + + /** + * Will call the subclass doTick implementation in this main loop tick + * or in the next one (via setTimeout(,0)) in case it has already been called + * in this tick (in case this is a re-entrant call). + */ + tick() { + this._tickCallCount++; + if (this._tickCallCount === 1) { + this.doTick(); + // re-entrant call to tick from previous doTick call stack + // -> schedule a call on the next main loop iteration to process this task processing request + if (this._tickCallCount > 1) { + // make sure only one timer exists at any time at max + this.tickImmediate(); + } + this._tickCallCount = 0; + } + } + tickImmediate() { + this.clearNextTick(); + this._tickTimer = self.setTimeout(this._boundTick, 0); + } + + /** + * For subclass to implement task logic + * @abstract + */ + doTick() {} } var FragmentState = { @@ -181787,13 +182893,17 @@ class FragmentTracker { }); break; } else if (startPTS < endTime && endPTS > startTime) { - buffered.partial = true; - // Check for intersection with buffer - // Get playable sections of the fragment - buffered.time.push({ - startPTS: Math.max(startPTS, timeRange.start(i)), - endPTS: Math.min(endPTS, timeRange.end(i)) - }); + const start = Math.max(startPTS, timeRange.start(i)); + const end = Math.min(endPTS, timeRange.end(i)); + if (end > start) { + buffered.partial = true; + // Check for intersection with buffer + // Get playable sections of the fragment + buffered.time.push({ + startPTS: start, + endPTS: end + }); + } } else if (endPTS <= startTime) { // No need to check the rest of the timeRange as it is in order break; @@ -181970,31 +183080,352 @@ function isPartial(fragmentEntity) { return fragmentEntity.buffered && (fragmentEntity.body.gap || ((_fragmentEntity$range = fragmentEntity.range.video) == null ? void 0 : _fragmentEntity$range.partial) || ((_fragmentEntity$range2 = fragmentEntity.range.audio) == null ? void 0 : _fragmentEntity$range2.partial) || ((_fragmentEntity$range3 = fragmentEntity.range.audiovideo) == null ? void 0 : _fragmentEntity$range3.partial)); } function getFragmentKey(fragment) { - return `${fragment.type}_${fragment.level}_${fragment.urlId}_${fragment.sn}`; + return `${fragment.type}_${fragment.level}_${fragment.sn}`; } -const MIN_CHUNK_SIZE = Math.pow(2, 17); // 128kb +/** + * Provides methods dealing with buffer length retrieval for example. + * + * In general, a helper around HTML5 MediaElement TimeRanges gathered from `buffered` property. + * + * Also @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/buffered + */ -class FragmentLoader { - constructor(config) { - this.config = void 0; - this.loader = null; - this.partLoadTimeout = -1; - this.config = config; - } - destroy() { - if (this.loader) { - this.loader.destroy(); - this.loader = null; - } - } - abort() { - if (this.loader) { - // Abort the loader for current fragment. Only one may load at any given time - this.loader.abort(); +const noopBuffered = { + length: 0, + start: () => 0, + end: () => 0 +}; +class BufferHelper { + /** + * Return true if `media`'s buffered include `position` + */ + static isBuffered(media, position) { + try { + if (media) { + const buffered = BufferHelper.getBuffered(media); + for (let i = 0; i < buffered.length; i++) { + if (position >= buffered.start(i) && position <= buffered.end(i)) { + return true; + } + } + } + } catch (error) { + // this is to catch + // InvalidStateError: Failed to read the 'buffered' property from 'SourceBuffer': + // This SourceBuffer has been removed from the parent media source } + return false; } - load(frag, onProgress) { + static bufferInfo(media, pos, maxHoleDuration) { + try { + if (media) { + const vbuffered = BufferHelper.getBuffered(media); + const buffered = []; + let i; + for (i = 0; i < vbuffered.length; i++) { + buffered.push({ + start: vbuffered.start(i), + end: vbuffered.end(i) + }); + } + return this.bufferedInfo(buffered, pos, maxHoleDuration); + } + } catch (error) { + // this is to catch + // InvalidStateError: Failed to read the 'buffered' property from 'SourceBuffer': + // This SourceBuffer has been removed from the parent media source + } + return { + len: 0, + start: pos, + end: pos, + nextStart: undefined + }; + } + static bufferedInfo(buffered, pos, maxHoleDuration) { + pos = Math.max(0, pos); + // sort on buffer.start/smaller end (IE does not always return sorted buffered range) + buffered.sort(function (a, b) { + const diff = a.start - b.start; + if (diff) { + return diff; + } else { + return b.end - a.end; + } + }); + let buffered2 = []; + if (maxHoleDuration) { + // there might be some small holes between buffer time range + // consider that holes smaller than maxHoleDuration are irrelevant and build another + // buffer time range representations that discards those holes + for (let i = 0; i < buffered.length; i++) { + const buf2len = buffered2.length; + if (buf2len) { + const buf2end = buffered2[buf2len - 1].end; + // if small hole (value between 0 or maxHoleDuration ) or overlapping (negative) + if (buffered[i].start - buf2end < maxHoleDuration) { + // merge overlapping time ranges + // update lastRange.end only if smaller than item.end + // e.g. [ 1, 15] with [ 2,8] => [ 1,15] (no need to modify lastRange.end) + // whereas [ 1, 8] with [ 2,15] => [ 1,15] ( lastRange should switch from [1,8] to [1,15]) + if (buffered[i].end > buf2end) { + buffered2[buf2len - 1].end = buffered[i].end; + } + } else { + // big hole + buffered2.push(buffered[i]); + } + } else { + // first value + buffered2.push(buffered[i]); + } + } + } else { + buffered2 = buffered; + } + let bufferLen = 0; + + // bufferStartNext can possibly be undefined based on the conditional logic below + let bufferStartNext; + + // bufferStart and bufferEnd are buffer boundaries around current video position + let bufferStart = pos; + let bufferEnd = pos; + for (let i = 0; i < buffered2.length; i++) { + const start = buffered2[i].start; + const end = buffered2[i].end; + // logger.log('buf start/end:' + buffered.start(i) + '/' + buffered.end(i)); + if (pos + maxHoleDuration >= start && pos < end) { + // play position is inside this buffer TimeRange, retrieve end of buffer position and buffer length + bufferStart = start; + bufferEnd = end; + bufferLen = bufferEnd - pos; + } else if (pos + maxHoleDuration < start) { + bufferStartNext = start; + break; + } + } + return { + len: bufferLen, + start: bufferStart || 0, + end: bufferEnd || 0, + nextStart: bufferStartNext + }; + } + + /** + * Safe method to get buffered property. + * SourceBuffer.buffered may throw if SourceBuffer is removed from it's MediaSource + */ + static getBuffered(media) { + try { + return media.buffered; + } catch (e) { + logger.log('failed to get media.buffered', e); + return noopBuffered; + } + } +} + +class ChunkMetadata { + constructor(level, sn, id, size = 0, part = -1, partial = false) { + this.level = void 0; + this.sn = void 0; + this.part = void 0; + this.id = void 0; + this.size = void 0; + this.partial = void 0; + this.transmuxing = getNewPerformanceTiming(); + this.buffering = { + audio: getNewPerformanceTiming(), + video: getNewPerformanceTiming(), + audiovideo: getNewPerformanceTiming() + }; + this.level = level; + this.sn = sn; + this.id = id; + this.size = size; + this.part = part; + this.partial = partial; + } +} +function getNewPerformanceTiming() { + return { + start: 0, + executeStart: 0, + executeEnd: 0, + end: 0 + }; +} + +function findFirstFragWithCC(fragments, cc) { + for (let i = 0, len = fragments.length; i < len; i++) { + var _fragments$i; + if (((_fragments$i = fragments[i]) == null ? void 0 : _fragments$i.cc) === cc) { + return fragments[i]; + } + } + return null; +} +function shouldAlignOnDiscontinuities(lastFrag, switchDetails, details) { + if (switchDetails) { + if (details.endCC > details.startCC || lastFrag && lastFrag.cc < details.startCC) { + return true; + } + } + return false; +} + +// Find the first frag in the previous level which matches the CC of the first frag of the new level +function findDiscontinuousReferenceFrag(prevDetails, curDetails) { + const prevFrags = prevDetails.fragments; + const curFrags = curDetails.fragments; + if (!curFrags.length || !prevFrags.length) { + logger.log('No fragments to align'); + return; + } + const prevStartFrag = findFirstFragWithCC(prevFrags, curFrags[0].cc); + if (!prevStartFrag || prevStartFrag && !prevStartFrag.startPTS) { + logger.log('No frag in previous level to align on'); + return; + } + return prevStartFrag; +} +function adjustFragmentStart(frag, sliding) { + if (frag) { + const start = frag.start + sliding; + frag.start = frag.startPTS = start; + frag.endPTS = start + frag.duration; + } +} +function adjustSlidingStart(sliding, details) { + // Update segments + const fragments = details.fragments; + for (let i = 0, len = fragments.length; i < len; i++) { + adjustFragmentStart(fragments[i], sliding); + } + // Update LL-HLS parts at the end of the playlist + if (details.fragmentHint) { + adjustFragmentStart(details.fragmentHint, sliding); + } + details.alignedSliding = true; +} + +/** + * Using the parameters of the last level, this function computes PTS' of the new fragments so that they form a + * contiguous stream with the last fragments. + * The PTS of a fragment lets Hls.js know where it fits into a stream - by knowing every PTS, we know which fragment to + * download at any given time. PTS is normally computed when the fragment is demuxed, so taking this step saves us time + * and an extra download. + * @param lastFrag + * @param lastLevel + * @param details + */ +function alignStream(lastFrag, switchDetails, details) { + if (!switchDetails) { + return; + } + alignDiscontinuities(lastFrag, details, switchDetails); + if (!details.alignedSliding && switchDetails) { + // If the PTS wasn't figured out via discontinuity sequence that means there was no CC increase within the level. + // Aligning via Program Date Time should therefore be reliable, since PDT should be the same within the same + // discontinuity sequence. + alignMediaPlaylistByPDT(details, switchDetails); + } + if (!details.alignedSliding && switchDetails && !details.skippedSegments) { + // Try to align on sn so that we pick a better start fragment. + // Do not perform this on playlists with delta updates as this is only to align levels on switch + // and adjustSliding only adjusts fragments after skippedSegments. + adjustSliding(switchDetails, details); + } +} + +/** + * Computes the PTS if a new level's fragments using the PTS of a fragment in the last level which shares the same + * discontinuity sequence. + * @param lastFrag - The last Fragment which shares the same discontinuity sequence + * @param lastLevel - The details of the last loaded level + * @param details - The details of the new level + */ +function alignDiscontinuities(lastFrag, details, switchDetails) { + if (shouldAlignOnDiscontinuities(lastFrag, switchDetails, details)) { + const referenceFrag = findDiscontinuousReferenceFrag(switchDetails, details); + if (referenceFrag && isFiniteNumber(referenceFrag.start)) { + logger.log(`Adjusting PTS using last level due to CC increase within current level ${details.url}`); + adjustSlidingStart(referenceFrag.start, details); + } + } +} + +/** + * Ensures appropriate time-alignment between renditions based on PDT. + * This function assumes the timelines represented in `refDetails` are accurate, including the PDTs + * for the last discontinuity sequence number shared by both playlists when present, + * and uses the "wallclock"/PDT timeline as a cross-reference to `details`, adjusting the presentation + * times/timelines of `details` accordingly. + * Given the asynchronous nature of fetches and initial loads of live `main` and audio/subtitle tracks, + * the primary purpose of this function is to ensure the "local timelines" of audio/subtitle tracks + * are aligned to the main/video timeline, using PDT as the cross-reference/"anchor" that should + * be consistent across playlists, per the HLS spec. + * @param details - The details of the rendition you'd like to time-align (e.g. an audio rendition). + * @param refDetails - The details of the reference rendition with start and PDT times for alignment. + */ +function alignMediaPlaylistByPDT(details, refDetails) { + if (!details.hasProgramDateTime || !refDetails.hasProgramDateTime) { + return; + } + const fragments = details.fragments; + const refFragments = refDetails.fragments; + if (!fragments.length || !refFragments.length) { + return; + } + + // Calculate a delta to apply to all fragments according to the delta in PDT times and start times + // of a fragment in the reference details, and a fragment in the target details of the same discontinuity. + // If a fragment of the same discontinuity was not found use the middle fragment of both. + let refFrag; + let frag; + const targetCC = Math.min(refDetails.endCC, details.endCC); + if (refDetails.startCC < targetCC && details.startCC < targetCC) { + refFrag = findFirstFragWithCC(refFragments, targetCC); + frag = findFirstFragWithCC(fragments, targetCC); + } + if (!refFrag || !frag) { + refFrag = refFragments[Math.floor(refFragments.length / 2)]; + frag = findFirstFragWithCC(fragments, refFrag.cc) || fragments[Math.floor(fragments.length / 2)]; + } + const refPDT = refFrag.programDateTime; + const targetPDT = frag.programDateTime; + if (!refPDT || !targetPDT) { + return; + } + const delta = (targetPDT - refPDT) / 1000 - (frag.start - refFrag.start); + adjustSlidingStart(delta, details); +} + +const MIN_CHUNK_SIZE = Math.pow(2, 17); // 128kb + +class FragmentLoader { + constructor(config) { + this.config = void 0; + this.loader = null; + this.partLoadTimeout = -1; + this.config = config; + } + destroy() { + if (this.loader) { + this.loader.destroy(); + this.loader = null; + } + } + abort() { + if (this.loader) { + // Abort the loader for current fragment. Only one may load at any given time + this.loader.abort(); + } + } + load(frag, onProgress) { const url = frag.url; if (!url) { return Promise.reject(new LoadError({ @@ -182284,707 +183715,6 @@ class LoadError extends Error { } } -class KeyLoader { - constructor(config) { - this.config = void 0; - this.keyUriToKeyInfo = {}; - this.emeController = null; - this.config = config; - } - abort(type) { - for (const uri in this.keyUriToKeyInfo) { - const loader = this.keyUriToKeyInfo[uri].loader; - if (loader) { - if (type && type !== loader.context.frag.type) { - return; - } - loader.abort(); - } - } - } - detach() { - for (const uri in this.keyUriToKeyInfo) { - const keyInfo = this.keyUriToKeyInfo[uri]; - // Remove cached EME keys on detach - if (keyInfo.mediaKeySessionContext || keyInfo.decryptdata.isCommonEncryption) { - delete this.keyUriToKeyInfo[uri]; - } - } - } - destroy() { - this.detach(); - for (const uri in this.keyUriToKeyInfo) { - const loader = this.keyUriToKeyInfo[uri].loader; - if (loader) { - loader.destroy(); - } - } - this.keyUriToKeyInfo = {}; - } - createKeyLoadError(frag, details = ErrorDetails.KEY_LOAD_ERROR, error, networkDetails, response) { - return new LoadError({ - type: ErrorTypes.NETWORK_ERROR, - details, - fatal: false, - frag, - response, - error, - networkDetails - }); - } - loadClear(loadingFrag, encryptedFragments) { - if (this.emeController && this.config.emeEnabled) { - // access key-system with nearest key on start (loaidng frag is unencrypted) - const { - sn, - cc - } = loadingFrag; - for (let i = 0; i < encryptedFragments.length; i++) { - const frag = encryptedFragments[i]; - if (cc <= frag.cc && (sn === 'initSegment' || frag.sn === 'initSegment' || sn < frag.sn)) { - this.emeController.selectKeySystemFormat(frag).then(keySystemFormat => { - frag.setKeyFormat(keySystemFormat); - }); - break; - } - } - } - } - load(frag) { - if (!frag.decryptdata && frag.encrypted && this.emeController) { - // Multiple keys, but none selected, resolve in eme-controller - return this.emeController.selectKeySystemFormat(frag).then(keySystemFormat => { - return this.loadInternal(frag, keySystemFormat); - }); - } - return this.loadInternal(frag); - } - loadInternal(frag, keySystemFormat) { - var _keyInfo, _keyInfo2; - if (keySystemFormat) { - frag.setKeyFormat(keySystemFormat); - } - const decryptdata = frag.decryptdata; - if (!decryptdata) { - const error = new Error(keySystemFormat ? `Expected frag.decryptdata to be defined after setting format ${keySystemFormat}` : 'Missing decryption data on fragment in onKeyLoading'); - return Promise.reject(this.createKeyLoadError(frag, ErrorDetails.KEY_LOAD_ERROR, error)); - } - const uri = decryptdata.uri; - if (!uri) { - return Promise.reject(this.createKeyLoadError(frag, ErrorDetails.KEY_LOAD_ERROR, new Error(`Invalid key URI: "${uri}"`))); - } - let keyInfo = this.keyUriToKeyInfo[uri]; - if ((_keyInfo = keyInfo) != null && _keyInfo.decryptdata.key) { - decryptdata.key = keyInfo.decryptdata.key; - return Promise.resolve({ - frag, - keyInfo - }); - } - // Return key load promise as long as it does not have a mediakey session with an unusable key status - if ((_keyInfo2 = keyInfo) != null && _keyInfo2.keyLoadPromise) { - var _keyInfo$mediaKeySess; - switch ((_keyInfo$mediaKeySess = keyInfo.mediaKeySessionContext) == null ? void 0 : _keyInfo$mediaKeySess.keyStatus) { - case undefined: - case 'status-pending': - case 'usable': - case 'usable-in-future': - return keyInfo.keyLoadPromise.then(keyLoadedData => { - // Return the correct fragment with updated decryptdata key and loaded keyInfo - decryptdata.key = keyLoadedData.keyInfo.decryptdata.key; - return { - frag, - keyInfo - }; - }); - } - // If we have a key session and status and it is not pending or usable, continue - // This will go back to the eme-controller for expired keys to get a new keyLoadPromise - } - - // Load the key or return the loading promise - keyInfo = this.keyUriToKeyInfo[uri] = { - decryptdata, - keyLoadPromise: null, - loader: null, - mediaKeySessionContext: null - }; - switch (decryptdata.method) { - case 'ISO-23001-7': - case 'SAMPLE-AES': - case 'SAMPLE-AES-CENC': - case 'SAMPLE-AES-CTR': - if (decryptdata.keyFormat === 'identity') { - // loadKeyHTTP handles http(s) and data URLs - return this.loadKeyHTTP(keyInfo, frag); - } - return this.loadKeyEME(keyInfo, frag); - case 'AES-128': - return this.loadKeyHTTP(keyInfo, frag); - default: - return Promise.reject(this.createKeyLoadError(frag, ErrorDetails.KEY_LOAD_ERROR, new Error(`Key supplied with unsupported METHOD: "${decryptdata.method}"`))); - } - } - loadKeyEME(keyInfo, frag) { - const keyLoadedData = { - frag, - keyInfo - }; - if (this.emeController && this.config.emeEnabled) { - const keySessionContextPromise = this.emeController.loadKey(keyLoadedData); - if (keySessionContextPromise) { - return (keyInfo.keyLoadPromise = keySessionContextPromise.then(keySessionContext => { - keyInfo.mediaKeySessionContext = keySessionContext; - return keyLoadedData; - })).catch(error => { - // Remove promise for license renewal or retry - keyInfo.keyLoadPromise = null; - throw error; - }); - } - } - return Promise.resolve(keyLoadedData); - } - loadKeyHTTP(keyInfo, frag) { - const config = this.config; - const Loader = config.loader; - const keyLoader = new Loader(config); - frag.keyLoader = keyInfo.loader = keyLoader; - return keyInfo.keyLoadPromise = new Promise((resolve, reject) => { - const loaderContext = { - keyInfo, - frag, - responseType: 'arraybuffer', - url: keyInfo.decryptdata.uri - }; - - // maxRetry is 0 so that instead of retrying the same key on the same variant multiple times, - // key-loader will trigger an error and rely on stream-controller to handle retry logic. - // this will also align retry logic with fragment-loader - const loadPolicy = config.keyLoadPolicy.default; - const loaderConfig = { - loadPolicy, - timeout: loadPolicy.maxLoadTimeMs, - maxRetry: 0, - retryDelay: 0, - maxRetryDelay: 0 - }; - const loaderCallbacks = { - onSuccess: (response, stats, context, networkDetails) => { - const { - frag, - keyInfo, - url: uri - } = context; - if (!frag.decryptdata || keyInfo !== this.keyUriToKeyInfo[uri]) { - return reject(this.createKeyLoadError(frag, ErrorDetails.KEY_LOAD_ERROR, new Error('after key load, decryptdata unset or changed'), networkDetails)); - } - keyInfo.decryptdata.key = frag.decryptdata.key = new Uint8Array(response.data); - - // detach fragment key loader on load success - frag.keyLoader = null; - keyInfo.loader = null; - resolve({ - frag, - keyInfo - }); - }, - onError: (response, context, networkDetails, stats) => { - this.resetLoader(context); - reject(this.createKeyLoadError(frag, ErrorDetails.KEY_LOAD_ERROR, new Error(`HTTP Error ${response.code} loading key ${response.text}`), networkDetails, _objectSpread2({ - url: loaderContext.url, - data: undefined - }, response))); - }, - onTimeout: (stats, context, networkDetails) => { - this.resetLoader(context); - reject(this.createKeyLoadError(frag, ErrorDetails.KEY_LOAD_TIMEOUT, new Error('key loading timed out'), networkDetails)); - }, - onAbort: (stats, context, networkDetails) => { - this.resetLoader(context); - reject(this.createKeyLoadError(frag, ErrorDetails.INTERNAL_ABORTED, new Error('key loading aborted'), networkDetails)); - } - }; - keyLoader.load(loaderContext, loaderConfig, loaderCallbacks); - }); - } - resetLoader(context) { - const { - frag, - keyInfo, - url: uri - } = context; - const loader = keyInfo.loader; - if (frag.keyLoader === loader) { - frag.keyLoader = null; - keyInfo.loader = null; - } - delete this.keyUriToKeyInfo[uri]; - if (loader) { - loader.destroy(); - } - } -} - -/** - * @ignore - * Sub-class specialization of EventHandler base class. - * - * TaskLoop allows to schedule a task function being called (optionnaly repeatedly) on the main loop, - * scheduled asynchroneously, avoiding recursive calls in the same tick. - * - * The task itself is implemented in `doTick`. It can be requested and called for single execution - * using the `tick` method. - * - * It will be assured that the task execution method (`tick`) only gets called once per main loop "tick", - * no matter how often it gets requested for execution. Execution in further ticks will be scheduled accordingly. - * - * If further execution requests have already been scheduled on the next tick, it can be checked with `hasNextTick`, - * and cancelled with `clearNextTick`. - * - * The task can be scheduled as an interval repeatedly with a period as parameter (see `setInterval`, `clearInterval`). - * - * Sub-classes need to implement the `doTick` method which will effectively have the task execution routine. - * - * Further explanations: - * - * The baseclass has a `tick` method that will schedule the doTick call. It may be called synchroneously - * only for a stack-depth of one. On re-entrant calls, sub-sequent calls are scheduled for next main loop ticks. - * - * When the task execution (`tick` method) is called in re-entrant way this is detected and - * we are limiting the task execution per call stack to exactly one, but scheduling/post-poning further - * task processing on the next main loop iteration (also known as "next tick" in the Node/JS runtime lingo). - */ -class TaskLoop { - constructor() { - this._boundTick = void 0; - this._tickTimer = null; - this._tickInterval = null; - this._tickCallCount = 0; - this._boundTick = this.tick.bind(this); - } - destroy() { - this.onHandlerDestroying(); - this.onHandlerDestroyed(); - } - onHandlerDestroying() { - // clear all timers before unregistering from event bus - this.clearNextTick(); - this.clearInterval(); - } - onHandlerDestroyed() {} - hasInterval() { - return !!this._tickInterval; - } - hasNextTick() { - return !!this._tickTimer; - } - - /** - * @param millis - Interval time (ms) - * @eturns True when interval has been scheduled, false when already scheduled (no effect) - */ - setInterval(millis) { - if (!this._tickInterval) { - this._tickCallCount = 0; - this._tickInterval = self.setInterval(this._boundTick, millis); - return true; - } - return false; - } - - /** - * @returns True when interval was cleared, false when none was set (no effect) - */ - clearInterval() { - if (this._tickInterval) { - self.clearInterval(this._tickInterval); - this._tickInterval = null; - return true; - } - return false; - } - - /** - * @returns True when timeout was cleared, false when none was set (no effect) - */ - clearNextTick() { - if (this._tickTimer) { - self.clearTimeout(this._tickTimer); - this._tickTimer = null; - return true; - } - return false; - } - - /** - * Will call the subclass doTick implementation in this main loop tick - * or in the next one (via setTimeout(,0)) in case it has already been called - * in this tick (in case this is a re-entrant call). - */ - tick() { - this._tickCallCount++; - if (this._tickCallCount === 1) { - this.doTick(); - // re-entrant call to tick from previous doTick call stack - // -> schedule a call on the next main loop iteration to process this task processing request - if (this._tickCallCount > 1) { - // make sure only one timer exists at any time at max - this.tickImmediate(); - } - this._tickCallCount = 0; - } - } - tickImmediate() { - this.clearNextTick(); - this._tickTimer = self.setTimeout(this._boundTick, 0); - } - - /** - * For subclass to implement task logic - * @abstract - */ - doTick() {} -} - -/** - * Provides methods dealing with buffer length retrieval for example. - * - * In general, a helper around HTML5 MediaElement TimeRanges gathered from `buffered` property. - * - * Also @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/buffered - */ - -const noopBuffered = { - length: 0, - start: () => 0, - end: () => 0 -}; -class BufferHelper { - /** - * Return true if `media`'s buffered include `position` - */ - static isBuffered(media, position) { - try { - if (media) { - const buffered = BufferHelper.getBuffered(media); - for (let i = 0; i < buffered.length; i++) { - if (position >= buffered.start(i) && position <= buffered.end(i)) { - return true; - } - } - } - } catch (error) { - // this is to catch - // InvalidStateError: Failed to read the 'buffered' property from 'SourceBuffer': - // This SourceBuffer has been removed from the parent media source - } - return false; - } - static bufferInfo(media, pos, maxHoleDuration) { - try { - if (media) { - const vbuffered = BufferHelper.getBuffered(media); - const buffered = []; - let i; - for (i = 0; i < vbuffered.length; i++) { - buffered.push({ - start: vbuffered.start(i), - end: vbuffered.end(i) - }); - } - return this.bufferedInfo(buffered, pos, maxHoleDuration); - } - } catch (error) { - // this is to catch - // InvalidStateError: Failed to read the 'buffered' property from 'SourceBuffer': - // This SourceBuffer has been removed from the parent media source - } - return { - len: 0, - start: pos, - end: pos, - nextStart: undefined - }; - } - static bufferedInfo(buffered, pos, maxHoleDuration) { - pos = Math.max(0, pos); - // sort on buffer.start/smaller end (IE does not always return sorted buffered range) - buffered.sort(function (a, b) { - const diff = a.start - b.start; - if (diff) { - return diff; - } else { - return b.end - a.end; - } - }); - let buffered2 = []; - if (maxHoleDuration) { - // there might be some small holes between buffer time range - // consider that holes smaller than maxHoleDuration are irrelevant and build another - // buffer time range representations that discards those holes - for (let i = 0; i < buffered.length; i++) { - const buf2len = buffered2.length; - if (buf2len) { - const buf2end = buffered2[buf2len - 1].end; - // if small hole (value between 0 or maxHoleDuration ) or overlapping (negative) - if (buffered[i].start - buf2end < maxHoleDuration) { - // merge overlapping time ranges - // update lastRange.end only if smaller than item.end - // e.g. [ 1, 15] with [ 2,8] => [ 1,15] (no need to modify lastRange.end) - // whereas [ 1, 8] with [ 2,15] => [ 1,15] ( lastRange should switch from [1,8] to [1,15]) - if (buffered[i].end > buf2end) { - buffered2[buf2len - 1].end = buffered[i].end; - } - } else { - // big hole - buffered2.push(buffered[i]); - } - } else { - // first value - buffered2.push(buffered[i]); - } - } - } else { - buffered2 = buffered; - } - let bufferLen = 0; - - // bufferStartNext can possibly be undefined based on the conditional logic below - let bufferStartNext; - - // bufferStart and bufferEnd are buffer boundaries around current video position - let bufferStart = pos; - let bufferEnd = pos; - for (let i = 0; i < buffered2.length; i++) { - const start = buffered2[i].start; - const end = buffered2[i].end; - // logger.log('buf start/end:' + buffered.start(i) + '/' + buffered.end(i)); - if (pos + maxHoleDuration >= start && pos < end) { - // play position is inside this buffer TimeRange, retrieve end of buffer position and buffer length - bufferStart = start; - bufferEnd = end; - bufferLen = bufferEnd - pos; - } else if (pos + maxHoleDuration < start) { - bufferStartNext = start; - break; - } - } - return { - len: bufferLen, - start: bufferStart || 0, - end: bufferEnd || 0, - nextStart: bufferStartNext - }; - } - - /** - * Safe method to get buffered property. - * SourceBuffer.buffered may throw if SourceBuffer is removed from it's MediaSource - */ - static getBuffered(media) { - try { - return media.buffered; - } catch (e) { - logger.log('failed to get media.buffered', e); - return noopBuffered; - } - } -} - -class ChunkMetadata { - constructor(level, sn, id, size = 0, part = -1, partial = false) { - this.level = void 0; - this.sn = void 0; - this.part = void 0; - this.id = void 0; - this.size = void 0; - this.partial = void 0; - this.transmuxing = getNewPerformanceTiming(); - this.buffering = { - audio: getNewPerformanceTiming(), - video: getNewPerformanceTiming(), - audiovideo: getNewPerformanceTiming() - }; - this.level = level; - this.sn = sn; - this.id = id; - this.size = size; - this.part = part; - this.partial = partial; - } -} -function getNewPerformanceTiming() { - return { - start: 0, - executeStart: 0, - executeEnd: 0, - end: 0 - }; -} - -function findFirstFragWithCC(fragments, cc) { - let firstFrag = null; - for (let i = 0, len = fragments.length; i < len; i++) { - const currentFrag = fragments[i]; - if (currentFrag && currentFrag.cc === cc) { - firstFrag = currentFrag; - break; - } - } - return firstFrag; -} -function shouldAlignOnDiscontinuities(lastFrag, lastLevel, details) { - if (lastLevel.details) { - if (details.endCC > details.startCC || lastFrag && lastFrag.cc < details.startCC) { - return true; - } - } - return false; -} - -// Find the first frag in the previous level which matches the CC of the first frag of the new level -function findDiscontinuousReferenceFrag(prevDetails, curDetails, referenceIndex = 0) { - const prevFrags = prevDetails.fragments; - const curFrags = curDetails.fragments; - if (!curFrags.length || !prevFrags.length) { - logger.log('No fragments to align'); - return; - } - const prevStartFrag = findFirstFragWithCC(prevFrags, curFrags[0].cc); - if (!prevStartFrag || prevStartFrag && !prevStartFrag.startPTS) { - logger.log('No frag in previous level to align on'); - return; - } - return prevStartFrag; -} -function adjustFragmentStart(frag, sliding) { - if (frag) { - const start = frag.start + sliding; - frag.start = frag.startPTS = start; - frag.endPTS = start + frag.duration; - } -} -function adjustSlidingStart(sliding, details) { - // Update segments - const fragments = details.fragments; - for (let i = 0, len = fragments.length; i < len; i++) { - adjustFragmentStart(fragments[i], sliding); - } - // Update LL-HLS parts at the end of the playlist - if (details.fragmentHint) { - adjustFragmentStart(details.fragmentHint, sliding); - } - details.alignedSliding = true; -} - -/** - * Using the parameters of the last level, this function computes PTS' of the new fragments so that they form a - * contiguous stream with the last fragments. - * The PTS of a fragment lets Hls.js know where it fits into a stream - by knowing every PTS, we know which fragment to - * download at any given time. PTS is normally computed when the fragment is demuxed, so taking this step saves us time - * and an extra download. - * @param lastFrag - * @param lastLevel - * @param details - */ -function alignStream(lastFrag, lastLevel, details) { - if (!lastLevel) { - return; - } - alignDiscontinuities(lastFrag, details, lastLevel); - if (!details.alignedSliding && lastLevel.details) { - // If the PTS wasn't figured out via discontinuity sequence that means there was no CC increase within the level. - // Aligning via Program Date Time should therefore be reliable, since PDT should be the same within the same - // discontinuity sequence. - alignPDT(details, lastLevel.details); - } - if (!details.alignedSliding && lastLevel.details && !details.skippedSegments) { - // Try to align on sn so that we pick a better start fragment. - // Do not perform this on playlists with delta updates as this is only to align levels on switch - // and adjustSliding only adjusts fragments after skippedSegments. - adjustSliding(lastLevel.details, details); - } -} - -/** - * Computes the PTS if a new level's fragments using the PTS of a fragment in the last level which shares the same - * discontinuity sequence. - * @param lastFrag - The last Fragment which shares the same discontinuity sequence - * @param lastLevel - The details of the last loaded level - * @param details - The details of the new level - */ -function alignDiscontinuities(lastFrag, details, lastLevel) { - if (shouldAlignOnDiscontinuities(lastFrag, lastLevel, details)) { - const referenceFrag = findDiscontinuousReferenceFrag(lastLevel.details, details); - if (referenceFrag && isFiniteNumber(referenceFrag.start)) { - logger.log(`Adjusting PTS using last level due to CC increase within current level ${details.url}`); - adjustSlidingStart(referenceFrag.start, details); - } - } -} - -/** - * Computes the PTS of a new level's fragments using the difference in Program Date Time from the last level. - * @param details - The details of the new level - * @param lastDetails - The details of the last loaded level - */ -function alignPDT(details, lastDetails) { - // This check protects the unsafe "!" usage below for null program date time access. - if (!lastDetails.fragments.length || !details.hasProgramDateTime || !lastDetails.hasProgramDateTime) { - return; - } - // if last level sliding is 1000 and its first frag PROGRAM-DATE-TIME is 2017-08-20 1:10:00 AM - // and if new details first frag PROGRAM DATE-TIME is 2017-08-20 1:10:08 AM - // then we can deduce that playlist B sliding is 1000+8 = 1008s - const lastPDT = lastDetails.fragments[0].programDateTime; // hasProgramDateTime check above makes this safe. - const newPDT = details.fragments[0].programDateTime; - // date diff is in ms. frag.start is in seconds - const sliding = (newPDT - lastPDT) / 1000 + lastDetails.fragments[0].start; - if (sliding && isFiniteNumber(sliding)) { - logger.log(`Adjusting PTS using programDateTime delta ${newPDT - lastPDT}ms, sliding:${sliding.toFixed(3)} ${details.url} `); - adjustSlidingStart(sliding, details); - } -} - -/** - * Ensures appropriate time-alignment between renditions based on PDT. Unlike `alignPDT`, which adjusts - * the timeline based on the delta between PDTs of the 0th fragment of two playlists/`LevelDetails`, - * this function assumes the timelines represented in `refDetails` are accurate, including the PDTs, - * and uses the "wallclock"/PDT timeline as a cross-reference to `details`, adjusting the presentation - * times/timelines of `details` accordingly. - * Given the asynchronous nature of fetches and initial loads of live `main` and audio/subtitle tracks, - * the primary purpose of this function is to ensure the "local timelines" of audio/subtitle tracks - * are aligned to the main/video timeline, using PDT as the cross-reference/"anchor" that should - * be consistent across playlists, per the HLS spec. - * @param details - The details of the rendition you'd like to time-align (e.g. an audio rendition). - * @param refDetails - The details of the reference rendition with start and PDT times for alignment. - */ -function alignMediaPlaylistByPDT(details, refDetails) { - if (!details.hasProgramDateTime || !refDetails.hasProgramDateTime) { - return; - } - const fragments = details.fragments; - const refFragments = refDetails.fragments; - if (!fragments.length || !refFragments.length) { - return; - } - - // Calculate a delta to apply to all fragments according to the delta in PDT times and start times - // of a fragment in the reference details, and a fragment in the target details of the same discontinuity. - // If a fragment of the same discontinuity was not found use the middle fragment of both. - const middleFrag = Math.round(refFragments.length / 2) - 1; - const refFrag = refFragments[middleFrag]; - const frag = findFirstFragWithCC(fragments, refFrag.cc) || fragments[Math.round(fragments.length / 2) - 1]; - const refPDT = refFrag.programDateTime; - const targetPDT = frag.programDateTime; - if (refPDT === null || targetPDT === null) { - return; - } - const delta = (targetPDT - refPDT) / 1000 - (frag.start - refFrag.start); - adjustSlidingStart(delta, details); -} - class AESCrypto { constructor(subtle, iv) { this.subtle = void 0; @@ -183536,8 +184266,8 @@ class BaseStreamController extends TaskLoop { } getLevelDetails() { if (this.levels && this.levelLastLoaded !== null) { - var _this$levels$this$lev; - return (_this$levels$this$lev = this.levels[this.levelLastLoaded]) == null ? void 0 : _this$levels$this$lev.details; + var _this$levelLastLoaded; + return (_this$levelLastLoaded = this.levelLastLoaded) == null ? void 0 : _this$levelLastLoaded.details; } } onMediaAttached(event, data) { @@ -183627,8 +184357,11 @@ class BaseStreamController extends TaskLoop { this.initPTS = []; } onHandlerDestroying() { + this.hls.off(Events.MANIFEST_LOADED, this.onManifestLoaded, this); this.stopLoad(); super.onHandlerDestroying(); + // @ts-ignore + this.hls = null; } onHandlerDestroyed() { this.state = State.STOPPED; @@ -183759,7 +184492,7 @@ class BaseStreamController extends TaskLoop { const decryptData = frag.decryptdata; // check to see if the payload needs to be decrypted - if (payload && payload.byteLength > 0 && decryptData && decryptData.key && decryptData.iv && decryptData.method === 'AES-128') { + if (payload && payload.byteLength > 0 && decryptData != null && decryptData.key && decryptData.iv && decryptData.method === 'AES-128') { const startTime = self.performance.now(); // decrypt init segment data return this.decrypter.decrypt(new Uint8Array(payload), decryptData.key.buffer, decryptData.iv.buffer).catch(err => { @@ -183783,36 +184516,10 @@ class BaseStreamController extends TaskLoop { } }); data.payload = decryptedData; - return data; + return this.completeInitSegmentLoad(data); }); } - return data; - }).then(data => { - const { - fragCurrent, - hls, - levels - } = this; - if (!levels) { - throw new Error('init load aborted, missing levels'); - } - const stats = frag.stats; - this.state = State.IDLE; - level.fragmentError = 0; - frag.data = new Uint8Array(data.payload); - stats.parsing.start = stats.buffering.start = self.performance.now(); - stats.parsing.end = stats.buffering.end = self.performance.now(); - - // Silence FRAG_BUFFERED event if fragCurrent is null - if (data.frag === fragCurrent) { - hls.trigger(Events.FRAG_BUFFERED, { - stats, - frag: fragCurrent, - part: null, - id: frag.type - }); - } - this.tick(); + return this.completeInitSegmentLoad(data); }).catch(reason => { if (this.state === State.STOPPED || this.state === State.ERROR) { return; @@ -183821,16 +184528,46 @@ class BaseStreamController extends TaskLoop { this.resetFragmentLoading(frag); }); } + completeInitSegmentLoad(data) { + const { + levels + } = this; + if (!levels) { + throw new Error('init load aborted, missing levels'); + } + const stats = data.frag.stats; + this.state = State.IDLE; + data.frag.data = new Uint8Array(data.payload); + stats.parsing.start = stats.buffering.start = self.performance.now(); + stats.parsing.end = stats.buffering.end = self.performance.now(); + this.tick(); + } fragContextChanged(frag) { const { fragCurrent } = this; - return !frag || !fragCurrent || frag.level !== fragCurrent.level || frag.sn !== fragCurrent.sn || frag.urlId !== fragCurrent.urlId; + return !frag || !fragCurrent || frag.sn !== fragCurrent.sn || frag.level !== fragCurrent.level; } fragBufferedComplete(frag, part) { var _frag$startPTS, _frag$endPTS, _this$fragCurrent, _this$fragPrevious; const media = this.mediaBuffer ? this.mediaBuffer : this.media; this.log(`Buffered ${frag.type} sn: ${frag.sn}${part ? ' part: ' + part.index : ''} of ${this.playlistType === PlaylistLevelType.MAIN ? 'level' : 'track'} ${frag.level} (frag:[${((_frag$startPTS = frag.startPTS) != null ? _frag$startPTS : NaN).toFixed(3)}-${((_frag$endPTS = frag.endPTS) != null ? _frag$endPTS : NaN).toFixed(3)}] > buffer:${media ? TimeRanges.toString(BufferHelper.getBuffered(media)) : '(detached)'})`); + if (frag.sn !== 'initSegment') { + var _this$levels; + if (frag.type !== PlaylistLevelType.SUBTITLE) { + const el = frag.elementaryStreams; + if (!Object.keys(el).some(type => !!el[type])) { + // empty segment + this.state = State.IDLE; + return; + } + } + const level = (_this$levels = this.levels) == null ? void 0 : _this$levels[frag.level]; + if (level != null && level.fragmentError) { + this.log(`Resetting level fragment error count of ${level.fragmentError} on frag buffered`); + level.fragmentError = 0; + } + } this.state = State.IDLE; if (!media) { return; @@ -184189,9 +184926,9 @@ class BaseStreamController extends TaskLoop { // In order to discover the range, we load the best matching fragment for that level and demux it. // Do not load using live logic if the starting frag is requested - we want to use getFragmentAtPosition() so that // we get the fragment matching that start time - if (!levelDetails.PTSKnown && !this.startFragRequested && this.startPosition === -1) { + if (!levelDetails.PTSKnown && !this.startFragRequested && this.startPosition === -1 || pos < start) { frag = this.getInitialLiveFragment(levelDetails, fragments); - this.startPosition = frag ? this.hls.liveSyncPosition || frag.start : pos; + this.startPosition = this.nextLoadPosition = frag ? this.hls.liveSyncPosition || frag.start : pos; } } else if (pos <= start) { // VoD playlist: if loadPosition before start of playlist, load first fragment @@ -184391,14 +185128,7 @@ class BaseStreamController extends TaskLoop { } } } - alignPlaylists(details, previousDetails) { - const { - levels, - levelLastLoaded, - fragPrevious - } = this; - const lastLevel = levelLastLoaded !== null ? levels[levelLastLoaded] : null; - + alignPlaylists(details, previousDetails, switchDetails) { // FIXME: If not for `shouldAlignOnDiscontinuities` requiring fragPrevious.cc, // this could all go in level-helper mergeDetails() const length = details.fragments.length; @@ -184410,7 +185140,10 @@ class BaseStreamController extends TaskLoop { const firstLevelLoad = !previousDetails; const aligned = details.alignedSliding && isFiniteNumber(slidingStart); if (firstLevelLoad || !aligned && !slidingStart) { - alignStream(fragPrevious, lastLevel, details); + const { + fragPrevious + } = this; + alignStream(fragPrevious, switchDetails, details); const alignedSlidingStart = details.fragments[0].start; this.log(`Live playlist sliding: ${alignedSlidingStart.toFixed(2)} start-sn: ${previousDetails ? previousDetails.startSN : 'na'}->${details.startSN} prev-sn: ${fragPrevious ? fragPrevious.sn : 'na'} fragments: ${length}`); return alignedSlidingStart; @@ -184505,8 +185238,7 @@ class BaseStreamController extends TaskLoop { retryConfig } = errorAction || {}; if (errorAction && action === NetworkErrorAction.RetryRequest && retryConfig) { - var _this$levelLastLoaded; - this.resetStartWhenNotLoaded((_this$levelLastLoaded = this.levelLastLoaded) != null ? _this$levelLastLoaded : frag.level); + this.resetStartWhenNotLoaded(this.levelLastLoaded); const delay = getRetryDelay(retryConfig, retryCount); this.warn(`Fragment ${frag.sn} of ${filterType} ${frag.level} errored with ${data.details}, retrying loading ${retryCount + 1}/${retryConfig.maxNumRetry} in ${delay}ms`); errorAction.resolved = true; @@ -184516,11 +185248,12 @@ class BaseStreamController extends TaskLoop { this.resetFragmentErrors(filterType); if (retryCount < retryConfig.maxNumRetry) { // Network retry is skipped when level switch is preferred - if (!gapTagEncountered) { + if (!gapTagEncountered && action !== NetworkErrorAction.RemoveAlternatePermanently) { errorAction.resolved = true; } } else { logger.warn(`${data.details} reached or exceeded max retry (${retryCount})`); + return; } } else if ((errorAction == null ? void 0 : errorAction.action) === NetworkErrorAction.SendAlternateToPenaltyBox) { this.state = State.WAITING_LEVEL; @@ -184594,7 +185327,7 @@ class BaseStreamController extends TaskLoop { // in that case, reset startFragRequested flag if (!this.loadedmetadata) { this.startFragRequested = false; - const details = this.levels ? this.levels[level].details : null; + const details = level ? level.details : null; if (details != null && details.live) { // Update the start position and return to IDLE to recover live start this.startPosition = -1; @@ -184606,10 +185339,9 @@ class BaseStreamController extends TaskLoop { } } resetWhenMissingContext(chunkMeta) { - var _this$levelLastLoaded2; this.warn(`The loading context changed while buffering fragment ${chunkMeta.sn} of level ${chunkMeta.level}. This chunk will not be buffered.`); this.removeUnbufferedFrags(); - this.resetStartWhenNotLoaded((_this$levelLastLoaded2 = this.levelLastLoaded) != null ? _this$levelLastLoaded2 : chunkMeta.level); + this.resetStartWhenNotLoaded(this.levelLastLoaded); this.resetLoadingState(); } removeUnbufferedFrags(start = 0) { @@ -184647,9 +185379,7 @@ class BaseStreamController extends TaskLoop { } return result; }, false); - if (parsed) { - level.fragmentError = 0; - } else if (((_this$transmuxer = this.transmuxer) == null ? void 0 : _this$transmuxer.error) === null) { + if (!parsed && ((_this$transmuxer = this.transmuxer) == null ? void 0 : _this$transmuxer.error) === null) { const error = new Error(`Found no media in fragment ${frag.sn} of level ${frag.level} resetting transmuxer to fallback to playlist timing`); if (level.fragmentError === 0) { // Mark and track the odd empty segment as a gap to avoid reloading @@ -184673,7 +185403,6 @@ class BaseStreamController extends TaskLoop { this.resetTransmuxer(); // For this error fallthrough. Marking parsed will allow advancing to next fragment. } - this.state = State.PARSED; this.hls.trigger(Events.FRAG_PARSED, { frag, @@ -184688,10 +185417,9 @@ class BaseStreamController extends TaskLoop { } recoverWorkerError(data) { if (data.event === 'demuxerWorker') { - var _ref, _this$levelLastLoaded3, _this$fragCurrent3; this.fragmentTracker.removeAllFragments(); this.resetTransmuxer(); - this.resetStartWhenNotLoaded((_ref = (_this$levelLastLoaded3 = this.levelLastLoaded) != null ? _this$levelLastLoaded3 : (_this$fragCurrent3 = this.fragCurrent) == null ? void 0 : _this$fragCurrent3.level) != null ? _ref : 0); + this.resetStartWhenNotLoaded(this.levelLastLoaded); this.resetLoadingState(); } } @@ -184707,34 +185435,45 @@ class BaseStreamController extends TaskLoop { } } -function getSourceBuffer() { - return self.SourceBuffer || self.WebKitSourceBuffer; -} - -/** - * @ignore - */ -function isSupported() { - const mediaSource = getMediaSource(); - if (!mediaSource) { - return false; +class ChunkCache { + constructor() { + this.chunks = []; + this.dataLength = 0; + } + push(chunk) { + this.chunks.push(chunk); + this.dataLength += chunk.length; + } + flush() { + const { + chunks, + dataLength + } = this; + let result; + if (!chunks.length) { + return new Uint8Array(0); + } else if (chunks.length === 1) { + result = chunks[0]; + } else { + result = concatUint8Arrays(chunks, dataLength); + } + this.reset(); + return result; + } + reset() { + this.chunks.length = 0; + this.dataLength = 0; } - const sourceBuffer = getSourceBuffer(); - const isTypeSupported = mediaSource && typeof mediaSource.isTypeSupported === 'function' && mediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"'); - - // if SourceBuffer is exposed ensure its API is valid - // Older browsers do not expose SourceBuffer globally so checking SourceBuffer.prototype is impossible - const sourceBufferValidAPI = !sourceBuffer || sourceBuffer.prototype && typeof sourceBuffer.prototype.appendBuffer === 'function' && typeof sourceBuffer.prototype.remove === 'function'; - return !!isTypeSupported && !!sourceBufferValidAPI; } - -/** - * @ignore - */ -function changeTypeSupported() { - var _sourceBuffer$prototy; - const sourceBuffer = getSourceBuffer(); - return typeof (sourceBuffer == null ? void 0 : (_sourceBuffer$prototy = sourceBuffer.prototype) == null ? void 0 : _sourceBuffer$prototy.changeType) === 'function'; +function concatUint8Arrays(chunks, dataLength) { + const result = new Uint8Array(dataLength); + let offset = 0; + for (let i = 0; i < chunks.length; i++) { + const chunk = chunks[i]; + result.set(chunk, offset); + offset += chunk.length; + } + return result; } // ensure the worker ends up in the bundle @@ -184932,11 +185671,13 @@ function getAudioConfig(observer, data, offset, audioCodec) { adtsObjectType = ((data[offset + 2] & 0xc0) >>> 6) + 1; const adtsSamplingIndex = (data[offset + 2] & 0x3c) >>> 2; if (adtsSamplingIndex > adtsSamplingRates.length - 1) { - observer.trigger(Events.ERROR, { + const error = new Error(`invalid ADTS sampling index:${adtsSamplingIndex}`); + observer.emit(Events.ERROR, Events.ERROR, { type: ErrorTypes.MEDIA_ERROR, details: ErrorDetails.FRAG_PARSING_ERROR, fatal: true, - reason: `invalid ADTS sampling index:${adtsSamplingIndex}` + error, + reason: error.message }); return; } @@ -185114,7 +185855,7 @@ function parseFrameHeader(data, offset) { } } } -function appendFrame$1(track, data, offset, pts, frameIndex) { +function appendFrame$2(track, data, offset, pts, frameIndex) { const frameDuration = getFrameDuration(track.samplerate); const stamp = pts + frameIndex * frameDuration; const header = parseFrameHeader(data, offset); @@ -185161,199 +185902,6 @@ function appendFrame$1(track, data, offset, pts, frameIndex) { }; } -/** - * AAC demuxer - */ -class AACDemuxer extends BaseAudioDemuxer { - constructor(observer, config) { - super(); - this.observer = void 0; - this.config = void 0; - this.observer = observer; - this.config = config; - } - resetInitSegment(initSegment, audioCodec, videoCodec, trackDuration) { - super.resetInitSegment(initSegment, audioCodec, videoCodec, trackDuration); - this._audioTrack = { - container: 'audio/adts', - type: 'audio', - id: 2, - pid: -1, - sequenceNumber: 0, - segmentCodec: 'aac', - samples: [], - manifestCodec: audioCodec, - duration: trackDuration, - inputTimeScale: 90000, - dropped: 0 - }; - } - - // Source for probe info - https://wiki.multimedia.cx/index.php?title=ADTS - static probe(data) { - if (!data) { - return false; - } - - // Check for the ADTS sync word - // Look for ADTS header | 1111 1111 | 1111 X00X | where X can be either 0 or 1 - // Layer bits (position 14 and 15) in header should be always 0 for ADTS - // More info https://wiki.multimedia.cx/index.php?title=ADTS - const id3Data = getID3Data(data, 0) || []; - let offset = id3Data.length; - for (let length = data.length; offset < length; offset++) { - if (probe$1(data, offset)) { - logger.log('ADTS sync word found !'); - return true; - } - } - return false; - } - canParse(data, offset) { - return canParse$1(data, offset); - } - appendFrame(track, data, offset) { - initTrackConfig(track, this.observer, data, offset, track.manifestCodec); - const frame = appendFrame$1(track, data, offset, this.basePTS, this.frameIndex); - if (frame && frame.missing === 0) { - return frame; - } - } -} - -const emsgSchemePattern = /\/emsg[-/]ID3/i; -class MP4Demuxer { - constructor(observer, config) { - this.remainderData = null; - this.timeOffset = 0; - this.config = void 0; - this.videoTrack = void 0; - this.audioTrack = void 0; - this.id3Track = void 0; - this.txtTrack = void 0; - this.config = config; - } - resetTimeStamp() {} - resetInitSegment(initSegment, audioCodec, videoCodec, trackDuration) { - const videoTrack = this.videoTrack = dummyTrack('video', 1); - const audioTrack = this.audioTrack = dummyTrack('audio', 1); - const captionTrack = this.txtTrack = dummyTrack('text', 1); - this.id3Track = dummyTrack('id3', 1); - this.timeOffset = 0; - if (!(initSegment != null && initSegment.byteLength)) { - return; - } - const initData = parseInitSegment(initSegment); - if (initData.video) { - const { - id, - timescale, - codec - } = initData.video; - videoTrack.id = id; - videoTrack.timescale = captionTrack.timescale = timescale; - videoTrack.codec = codec; - } - if (initData.audio) { - const { - id, - timescale, - codec - } = initData.audio; - audioTrack.id = id; - audioTrack.timescale = timescale; - audioTrack.codec = codec; - } - captionTrack.id = RemuxerTrackIdConfig.text; - videoTrack.sampleDuration = 0; - videoTrack.duration = audioTrack.duration = trackDuration; - } - resetContiguity() { - this.remainderData = null; - } - static probe(data) { - // ensure we find a moof box in the first 16 kB - data = data.length > 16384 ? data.subarray(0, 16384) : data; - return findBox(data, ['moof']).length > 0; - } - demux(data, timeOffset) { - this.timeOffset = timeOffset; - // Load all data into the avc track. The CMAF remuxer will look for the data in the samples object; the rest of the fields do not matter - let videoSamples = data; - const videoTrack = this.videoTrack; - const textTrack = this.txtTrack; - if (this.config.progressive) { - // Split the bytestream into two ranges: one encompassing all data up until the start of the last moof, and everything else. - // This is done to guarantee that we're sending valid data to MSE - when demuxing progressively, we have no guarantee - // that the fetch loader gives us flush moof+mdat pairs. If we push jagged data to MSE, it will throw an exception. - if (this.remainderData) { - videoSamples = appendUint8Array(this.remainderData, data); - } - const segmentedData = segmentValidRange(videoSamples); - this.remainderData = segmentedData.remainder; - videoTrack.samples = segmentedData.valid || new Uint8Array(); - } else { - videoTrack.samples = videoSamples; - } - const id3Track = this.extractID3Track(videoTrack, timeOffset); - textTrack.samples = parseSamples(timeOffset, videoTrack); - return { - videoTrack, - audioTrack: this.audioTrack, - id3Track, - textTrack: this.txtTrack - }; - } - flush() { - const timeOffset = this.timeOffset; - const videoTrack = this.videoTrack; - const textTrack = this.txtTrack; - videoTrack.samples = this.remainderData || new Uint8Array(); - this.remainderData = null; - const id3Track = this.extractID3Track(videoTrack, this.timeOffset); - textTrack.samples = parseSamples(timeOffset, videoTrack); - return { - videoTrack, - audioTrack: dummyTrack(), - id3Track, - textTrack: dummyTrack() - }; - } - extractID3Track(videoTrack, timeOffset) { - const id3Track = this.id3Track; - if (videoTrack.samples.length) { - const emsgs = findBox(videoTrack.samples, ['emsg']); - if (emsgs) { - emsgs.forEach(data => { - const emsgInfo = parseEmsg(data); - if (emsgSchemePattern.test(emsgInfo.schemeIdUri)) { - const pts = isFiniteNumber(emsgInfo.presentationTime) ? emsgInfo.presentationTime / emsgInfo.timeScale : timeOffset + emsgInfo.presentationTimeDelta / emsgInfo.timeScale; - let duration = emsgInfo.eventDuration === 0xffffffff ? Number.POSITIVE_INFINITY : emsgInfo.eventDuration / emsgInfo.timeScale; - // Safari takes anything <= 0.001 seconds and maps it to Infinity - if (duration <= 0.001) { - duration = Number.POSITIVE_INFINITY; - } - const payload = emsgInfo.payload; - id3Track.samples.push({ - data: payload, - len: payload.byteLength, - dts: pts, - pts: pts, - type: MetadataSchema.emsg, - duration: duration - }); - } - }); - } - } - return id3Track; - } - demuxSampleAes(data, keyData, timeOffset) { - return Promise.reject(new Error('The MP4 demuxer does not support SAMPLE-AES decryption')); - } - destroy() {} -} - /** * MPEG parser helper */ @@ -185398,7 +185946,6 @@ const SamplesCoefficients = [ // Layer2 12 // Layer1 ]]; - const BytesInSlot = [0, // Reserved 1, @@ -185407,8 +185954,7 @@ const BytesInSlot = [0, // Layer2 4 // Layer1 ]; - -function appendFrame(track, data, offset, pts, frameIndex) { +function appendFrame$1(track, data, offset, pts, frameIndex) { // Using http://www.datavoyage.com/mpgscript/mpeghdr.htm as a reference if (offset + 24 > data.length) { return; @@ -185499,6 +186045,388 @@ function probe(data, offset) { return false; } +/** + * AAC demuxer + */ +class AACDemuxer extends BaseAudioDemuxer { + constructor(observer, config) { + super(); + this.observer = void 0; + this.config = void 0; + this.observer = observer; + this.config = config; + } + resetInitSegment(initSegment, audioCodec, videoCodec, trackDuration) { + super.resetInitSegment(initSegment, audioCodec, videoCodec, trackDuration); + this._audioTrack = { + container: 'audio/adts', + type: 'audio', + id: 2, + pid: -1, + sequenceNumber: 0, + segmentCodec: 'aac', + samples: [], + manifestCodec: audioCodec, + duration: trackDuration, + inputTimeScale: 90000, + dropped: 0 + }; + } + + // Source for probe info - https://wiki.multimedia.cx/index.php?title=ADTS + static probe(data) { + if (!data) { + return false; + } + + // Check for the ADTS sync word + // Look for ADTS header | 1111 1111 | 1111 X00X | where X can be either 0 or 1 + // Layer bits (position 14 and 15) in header should be always 0 for ADTS + // More info https://wiki.multimedia.cx/index.php?title=ADTS + const id3Data = getID3Data(data, 0); + let offset = (id3Data == null ? void 0 : id3Data.length) || 0; + if (probe(data, offset)) { + return false; + } + for (let length = data.length; offset < length; offset++) { + if (probe$1(data, offset)) { + logger.log('ADTS sync word found !'); + return true; + } + } + return false; + } + canParse(data, offset) { + return canParse$1(data, offset); + } + appendFrame(track, data, offset) { + initTrackConfig(track, this.observer, data, offset, track.manifestCodec); + const frame = appendFrame$2(track, data, offset, this.basePTS, this.frameIndex); + if (frame && frame.missing === 0) { + return frame; + } + } +} + +const emsgSchemePattern = /\/emsg[-/]ID3/i; +class MP4Demuxer { + constructor(observer, config) { + this.remainderData = null; + this.timeOffset = 0; + this.config = void 0; + this.videoTrack = void 0; + this.audioTrack = void 0; + this.id3Track = void 0; + this.txtTrack = void 0; + this.config = config; + } + resetTimeStamp() {} + resetInitSegment(initSegment, audioCodec, videoCodec, trackDuration) { + const videoTrack = this.videoTrack = dummyTrack('video', 1); + const audioTrack = this.audioTrack = dummyTrack('audio', 1); + const captionTrack = this.txtTrack = dummyTrack('text', 1); + this.id3Track = dummyTrack('id3', 1); + this.timeOffset = 0; + if (!(initSegment != null && initSegment.byteLength)) { + return; + } + const initData = parseInitSegment(initSegment); + if (initData.video) { + const { + id, + timescale, + codec + } = initData.video; + videoTrack.id = id; + videoTrack.timescale = captionTrack.timescale = timescale; + videoTrack.codec = codec; + } + if (initData.audio) { + const { + id, + timescale, + codec + } = initData.audio; + audioTrack.id = id; + audioTrack.timescale = timescale; + audioTrack.codec = codec; + } + captionTrack.id = RemuxerTrackIdConfig.text; + videoTrack.sampleDuration = 0; + videoTrack.duration = audioTrack.duration = trackDuration; + } + resetContiguity() { + this.remainderData = null; + } + static probe(data) { + return hasMoofData(data); + } + demux(data, timeOffset) { + this.timeOffset = timeOffset; + // Load all data into the avc track. The CMAF remuxer will look for the data in the samples object; the rest of the fields do not matter + let videoSamples = data; + const videoTrack = this.videoTrack; + const textTrack = this.txtTrack; + if (this.config.progressive) { + // Split the bytestream into two ranges: one encompassing all data up until the start of the last moof, and everything else. + // This is done to guarantee that we're sending valid data to MSE - when demuxing progressively, we have no guarantee + // that the fetch loader gives us flush moof+mdat pairs. If we push jagged data to MSE, it will throw an exception. + if (this.remainderData) { + videoSamples = appendUint8Array(this.remainderData, data); + } + const segmentedData = segmentValidRange(videoSamples); + this.remainderData = segmentedData.remainder; + videoTrack.samples = segmentedData.valid || new Uint8Array(); + } else { + videoTrack.samples = videoSamples; + } + const id3Track = this.extractID3Track(videoTrack, timeOffset); + textTrack.samples = parseSamples(timeOffset, videoTrack); + return { + videoTrack, + audioTrack: this.audioTrack, + id3Track, + textTrack: this.txtTrack + }; + } + flush() { + const timeOffset = this.timeOffset; + const videoTrack = this.videoTrack; + const textTrack = this.txtTrack; + videoTrack.samples = this.remainderData || new Uint8Array(); + this.remainderData = null; + const id3Track = this.extractID3Track(videoTrack, this.timeOffset); + textTrack.samples = parseSamples(timeOffset, videoTrack); + return { + videoTrack, + audioTrack: dummyTrack(), + id3Track, + textTrack: dummyTrack() + }; + } + extractID3Track(videoTrack, timeOffset) { + const id3Track = this.id3Track; + if (videoTrack.samples.length) { + const emsgs = findBox(videoTrack.samples, ['emsg']); + if (emsgs) { + emsgs.forEach(data => { + const emsgInfo = parseEmsg(data); + if (emsgSchemePattern.test(emsgInfo.schemeIdUri)) { + const pts = isFiniteNumber(emsgInfo.presentationTime) ? emsgInfo.presentationTime / emsgInfo.timeScale : timeOffset + emsgInfo.presentationTimeDelta / emsgInfo.timeScale; + let duration = emsgInfo.eventDuration === 0xffffffff ? Number.POSITIVE_INFINITY : emsgInfo.eventDuration / emsgInfo.timeScale; + // Safari takes anything <= 0.001 seconds and maps it to Infinity + if (duration <= 0.001) { + duration = Number.POSITIVE_INFINITY; + } + const payload = emsgInfo.payload; + id3Track.samples.push({ + data: payload, + len: payload.byteLength, + dts: pts, + pts: pts, + type: MetadataSchema.emsg, + duration: duration + }); + } + }); + } + } + return id3Track; + } + demuxSampleAes(data, keyData, timeOffset) { + return Promise.reject(new Error('The MP4 demuxer does not support SAMPLE-AES decryption')); + } + destroy() {} +} + +const getAudioBSID = (data, offset) => { + // check the bsid to confirm ac-3 | ec-3 + let bsid = 0; + let numBits = 5; + offset += numBits; + const temp = new Uint32Array(1); // unsigned 32 bit for temporary storage + const mask = new Uint32Array(1); // unsigned 32 bit mask value + const byte = new Uint8Array(1); // unsigned 8 bit for temporary storage + while (numBits > 0) { + byte[0] = data[offset]; + // read remaining bits, upto 8 bits at a time + const bits = Math.min(numBits, 8); + const shift = 8 - bits; + mask[0] = 0xff000000 >>> 24 + shift << shift; + temp[0] = (byte[0] & mask[0]) >> shift; + bsid = !bsid ? temp[0] : bsid << bits | temp[0]; + offset += 1; + numBits -= bits; + } + return bsid; +}; + +class AC3Demuxer extends BaseAudioDemuxer { + constructor(observer) { + super(); + this.observer = void 0; + this.observer = observer; + } + resetInitSegment(initSegment, audioCodec, videoCodec, trackDuration) { + super.resetInitSegment(initSegment, audioCodec, videoCodec, trackDuration); + this._audioTrack = { + container: 'audio/ac-3', + type: 'audio', + id: 2, + pid: -1, + sequenceNumber: 0, + segmentCodec: 'ac3', + samples: [], + manifestCodec: audioCodec, + duration: trackDuration, + inputTimeScale: 90000, + dropped: 0 + }; + } + canParse(data, offset) { + return offset + 64 < data.length; + } + appendFrame(track, data, offset) { + const frameLength = appendFrame(track, data, offset, this.basePTS, this.frameIndex); + if (frameLength !== -1) { + const sample = track.samples[track.samples.length - 1]; + return { + sample, + length: frameLength, + missing: 0 + }; + } + } + static probe(data) { + if (!data) { + return false; + } + const id3Data = getID3Data(data, 0); + if (!id3Data) { + return false; + } + + // look for the ac-3 sync bytes + const offset = id3Data.length; + if (data[offset] === 0x0b && data[offset + 1] === 0x77 && getTimeStamp(id3Data) !== undefined && + // check the bsid to confirm ac-3 + getAudioBSID(data, offset) < 16) { + return true; + } + return false; + } +} +function appendFrame(track, data, start, pts, frameIndex) { + if (start + 8 > data.length) { + return -1; // not enough bytes left + } + if (data[start] !== 0x0b || data[start + 1] !== 0x77) { + return -1; // invalid magic + } + + // get sample rate + const samplingRateCode = data[start + 4] >> 6; + if (samplingRateCode >= 3) { + return -1; // invalid sampling rate + } + const samplingRateMap = [48000, 44100, 32000]; + const sampleRate = samplingRateMap[samplingRateCode]; + + // get frame size + const frameSizeCode = data[start + 4] & 0x3f; + const frameSizeMap = [64, 69, 96, 64, 70, 96, 80, 87, 120, 80, 88, 120, 96, 104, 144, 96, 105, 144, 112, 121, 168, 112, 122, 168, 128, 139, 192, 128, 140, 192, 160, 174, 240, 160, 175, 240, 192, 208, 288, 192, 209, 288, 224, 243, 336, 224, 244, 336, 256, 278, 384, 256, 279, 384, 320, 348, 480, 320, 349, 480, 384, 417, 576, 384, 418, 576, 448, 487, 672, 448, 488, 672, 512, 557, 768, 512, 558, 768, 640, 696, 960, 640, 697, 960, 768, 835, 1152, 768, 836, 1152, 896, 975, 1344, 896, 976, 1344, 1024, 1114, 1536, 1024, 1115, 1536, 1152, 1253, 1728, 1152, 1254, 1728, 1280, 1393, 1920, 1280, 1394, 1920]; + const frameLength = frameSizeMap[frameSizeCode * 3 + samplingRateCode] * 2; + if (start + frameLength > data.length) { + return -1; + } + + // get channel count + const channelMode = data[start + 6] >> 5; + let skipCount = 0; + if (channelMode === 2) { + skipCount += 2; + } else { + if (channelMode & 1 && channelMode !== 1) { + skipCount += 2; + } + if (channelMode & 4) { + skipCount += 2; + } + } + const lfeon = (data[start + 6] << 8 | data[start + 7]) >> 12 - skipCount & 1; + const channelsMap = [2, 1, 2, 3, 3, 4, 4, 5]; + const channelCount = channelsMap[channelMode] + lfeon; + + // build dac3 box + const bsid = data[start + 5] >> 3; + const bsmod = data[start + 5] & 7; + const config = new Uint8Array([samplingRateCode << 6 | bsid << 1 | bsmod >> 2, (bsmod & 3) << 6 | channelMode << 3 | lfeon << 2 | frameSizeCode >> 4, frameSizeCode << 4 & 0xe0]); + const frameDuration = 1536 / sampleRate * 90000; + const stamp = pts + frameIndex * frameDuration; + const unit = data.subarray(start, start + frameLength); + track.config = config; + track.channelCount = channelCount; + track.samplerate = sampleRate; + track.samples.push({ + unit, + pts: stamp + }); + return frameLength; +} + +class BaseVideoParser { + constructor() { + this.VideoSample = null; + } + createVideoSample(key, pts, dts, debug) { + return { + key, + frame: false, + pts, + dts, + units: [], + debug, + length: 0 + }; + } + getLastNalUnit(samples) { + var _VideoSample; + let VideoSample = this.VideoSample; + let lastUnit; + // try to fallback to previous sample if current one is empty + if (!VideoSample || VideoSample.units.length === 0) { + VideoSample = samples[samples.length - 1]; + } + if ((_VideoSample = VideoSample) != null && _VideoSample.units) { + const units = VideoSample.units; + lastUnit = units[units.length - 1]; + } + return lastUnit; + } + pushAccessUnit(VideoSample, videoTrack) { + if (VideoSample.units.length && VideoSample.frame) { + // if sample does not have PTS/DTS, patch with last sample PTS/DTS + if (VideoSample.pts === undefined) { + const samples = videoTrack.samples; + const nbSamples = samples.length; + if (nbSamples) { + const lastSample = samples[nbSamples - 1]; + VideoSample.pts = lastSample.pts; + VideoSample.dts = lastSample.dts; + } else { + // dropping samples, no timestamp found + videoTrack.dropped++; + return; + } + } + videoTrack.samples.push(VideoSample); + } + if (VideoSample.debug.length) { + logger.log(VideoSample.pts + '/' + VideoSample.dts + ':' + VideoSample.debug); + } + } +} + /** * Parser for exponential Golomb codes, a variable-bitwidth number encoding scheme used by h264. */ @@ -185728,7 +186656,6 @@ class ExpGolomb { skipEG(); } // offset_for_ref_frame[ i ] } - skipUEG(); // max_num_ref_frames skipBits(1); // gaps_in_frame_num_value_allowed_flag const picWidthInMbsMinus1 = readUEG(); @@ -185825,6 +186752,250 @@ class ExpGolomb { } } +class AvcVideoParser extends BaseVideoParser { + parseAVCPES(track, textTrack, pes, last, duration) { + const units = this.parseAVCNALu(track, pes.data); + let VideoSample = this.VideoSample; + let push; + let spsfound = false; + // free pes.data to save up some memory + pes.data = null; + + // if new NAL units found and last sample still there, let's push ... + // this helps parsing streams with missing AUD (only do this if AUD never found) + if (VideoSample && units.length && !track.audFound) { + this.pushAccessUnit(VideoSample, track); + VideoSample = this.VideoSample = this.createVideoSample(false, pes.pts, pes.dts, ''); + } + units.forEach(unit => { + var _VideoSample2; + switch (unit.type) { + // NDR + case 1: + { + let iskey = false; + push = true; + const data = unit.data; + // only check slice type to detect KF in case SPS found in same packet (any keyframe is preceded by SPS ...) + if (spsfound && data.length > 4) { + // retrieve slice type by parsing beginning of NAL unit (follow H264 spec, slice_header definition) to detect keyframe embedded in NDR + const sliceType = new ExpGolomb(data).readSliceType(); + // 2 : I slice, 4 : SI slice, 7 : I slice, 9: SI slice + // SI slice : A slice that is coded using intra prediction only and using quantisation of the prediction samples. + // An SI slice can be coded such that its decoded samples can be constructed identically to an SP slice. + // I slice: A slice that is not an SI slice that is decoded using intra prediction only. + // if (sliceType === 2 || sliceType === 7) { + if (sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9) { + iskey = true; + } + } + if (iskey) { + var _VideoSample; + // if we have non-keyframe data already, that cannot belong to the same frame as a keyframe, so force a push + if ((_VideoSample = VideoSample) != null && _VideoSample.frame && !VideoSample.key) { + this.pushAccessUnit(VideoSample, track); + VideoSample = this.VideoSample = null; + } + } + if (!VideoSample) { + VideoSample = this.VideoSample = this.createVideoSample(true, pes.pts, pes.dts, ''); + } + VideoSample.frame = true; + VideoSample.key = iskey; + break; + // IDR + } + case 5: + push = true; + // handle PES not starting with AUD + // if we have frame data already, that cannot belong to the same frame, so force a push + if ((_VideoSample2 = VideoSample) != null && _VideoSample2.frame && !VideoSample.key) { + this.pushAccessUnit(VideoSample, track); + VideoSample = this.VideoSample = null; + } + if (!VideoSample) { + VideoSample = this.VideoSample = this.createVideoSample(true, pes.pts, pes.dts, ''); + } + VideoSample.key = true; + VideoSample.frame = true; + break; + // SEI + case 6: + { + push = true; + parseSEIMessageFromNALu(unit.data, 1, pes.pts, textTrack.samples); + break; + // SPS + } + case 7: + { + var _track$pixelRatio, _track$pixelRatio2; + push = true; + spsfound = true; + const sps = unit.data; + const expGolombDecoder = new ExpGolomb(sps); + const config = expGolombDecoder.readSPS(); + if (!track.sps || track.width !== config.width || track.height !== config.height || ((_track$pixelRatio = track.pixelRatio) == null ? void 0 : _track$pixelRatio[0]) !== config.pixelRatio[0] || ((_track$pixelRatio2 = track.pixelRatio) == null ? void 0 : _track$pixelRatio2[1]) !== config.pixelRatio[1]) { + track.width = config.width; + track.height = config.height; + track.pixelRatio = config.pixelRatio; + track.sps = [sps]; + track.duration = duration; + const codecarray = sps.subarray(1, 4); + let codecstring = 'avc1.'; + for (let i = 0; i < 3; i++) { + let h = codecarray[i].toString(16); + if (h.length < 2) { + h = '0' + h; + } + codecstring += h; + } + track.codec = codecstring; + } + break; + } + // PPS + case 8: + push = true; + track.pps = [unit.data]; + break; + // AUD + case 9: + push = true; + track.audFound = true; + if (VideoSample) { + this.pushAccessUnit(VideoSample, track); + } + VideoSample = this.VideoSample = this.createVideoSample(false, pes.pts, pes.dts, ''); + break; + // Filler Data + case 12: + push = true; + break; + default: + push = false; + if (VideoSample) { + VideoSample.debug += 'unknown NAL ' + unit.type + ' '; + } + break; + } + if (VideoSample && push) { + const units = VideoSample.units; + units.push(unit); + } + }); + // if last PES packet, push samples + if (last && VideoSample) { + this.pushAccessUnit(VideoSample, track); + this.VideoSample = null; + } + } + parseAVCNALu(track, array) { + const len = array.byteLength; + let state = track.naluState || 0; + const lastState = state; + const units = []; + let i = 0; + let value; + let overflow; + let unitType; + let lastUnitStart = -1; + let lastUnitType = 0; + // logger.log('PES:' + Hex.hexDump(array)); + + if (state === -1) { + // special use case where we found 3 or 4-byte start codes exactly at the end of previous PES packet + lastUnitStart = 0; + // NALu type is value read from offset 0 + lastUnitType = array[0] & 0x1f; + state = 0; + i = 1; + } + while (i < len) { + value = array[i++]; + // optimization. state 0 and 1 are the predominant case. let's handle them outside of the switch/case + if (!state) { + state = value ? 0 : 1; + continue; + } + if (state === 1) { + state = value ? 0 : 2; + continue; + } + // here we have state either equal to 2 or 3 + if (!value) { + state = 3; + } else if (value === 1) { + overflow = i - state - 1; + if (lastUnitStart >= 0) { + const unit = { + data: array.subarray(lastUnitStart, overflow), + type: lastUnitType + }; + // logger.log('pushing NALU, type/size:' + unit.type + '/' + unit.data.byteLength); + units.push(unit); + } else { + // lastUnitStart is undefined => this is the first start code found in this PES packet + // first check if start code delimiter is overlapping between 2 PES packets, + // ie it started in last packet (lastState not zero) + // and ended at the beginning of this PES packet (i <= 4 - lastState) + const lastUnit = this.getLastNalUnit(track.samples); + if (lastUnit) { + if (lastState && i <= 4 - lastState) { + // start delimiter overlapping between PES packets + // strip start delimiter bytes from the end of last NAL unit + // check if lastUnit had a state different from zero + if (lastUnit.state) { + // strip last bytes + lastUnit.data = lastUnit.data.subarray(0, lastUnit.data.byteLength - lastState); + } + } + // If NAL units are not starting right at the beginning of the PES packet, push preceding data into previous NAL unit. + + if (overflow > 0) { + // logger.log('first NALU found with overflow:' + overflow); + lastUnit.data = appendUint8Array(lastUnit.data, array.subarray(0, overflow)); + lastUnit.state = 0; + } + } + } + // check if we can read unit type + if (i < len) { + unitType = array[i] & 0x1f; + // logger.log('find NALU @ offset:' + i + ',type:' + unitType); + lastUnitStart = i; + lastUnitType = unitType; + state = 0; + } else { + // not enough byte to read unit type. let's read it on next PES parsing + state = -1; + } + } else { + state = 0; + } + } + if (lastUnitStart >= 0 && state >= 0) { + const unit = { + data: array.subarray(lastUnitStart, len), + type: lastUnitType, + state: state + }; + units.push(unit); + // logger.log('pushing NALU, type/size/state:' + unit.type + '/' + unit.data.byteLength + '/' + state); + } + // no NALu found + if (units.length === 0) { + // append pes.data to previous NAL unit + const lastUnit = this.getLastNalUnit(track.samples); + if (lastUnit) { + lastUnit.data = appendUint8Array(lastUnit.data, array); + } + } + track.naluState = state; + return units; + } +} + /** * SAMPLE-AES decrypter */ @@ -185943,16 +187114,17 @@ class TSDemuxer { this.videoCodec = void 0; this._duration = 0; this._pmtId = -1; - this._avcTrack = void 0; + this._videoTrack = void 0; this._audioTrack = void 0; this._id3Track = void 0; this._txtTrack = void 0; this.aacOverFlow = null; - this.avcSample = null; this.remainderData = null; + this.videoParser = void 0; this.observer = observer; this.config = config; this.typeSupported = typeSupported; + this.videoParser = new AvcVideoParser(); } static probe(data) { const syncOffset = TSDemuxer.syncOffset(data); @@ -185963,7 +187135,7 @@ class TSDemuxer { } static syncOffset(data) { const length = data.length; - let scanwindow = Math.min(PACKET_LENGTH * 5, data.length - PACKET_LENGTH) + 1; + let scanwindow = Math.min(PACKET_LENGTH * 5, length - PACKET_LENGTH) + 1; let i = 0; while (i < scanwindow) { // a TS init segment should contain at least 2 TS packets: PAT and PMT, each starting with 0x47 @@ -185971,7 +187143,7 @@ class TSDemuxer { let packetStart = -1; let tsPackets = 0; for (let j = i; j < length; j += PACKET_LENGTH) { - if (data[j] === 0x47) { + if (data[j] === 0x47 && (length - j === PACKET_LENGTH || data[j + PACKET_LENGTH] === 0x47)) { tsPackets++; if (packetStart === -1) { packetStart = j; @@ -185988,7 +187160,7 @@ class TSDemuxer { return packetStart; } } else if (tsPackets) { - // Exit if sync word found, but does not contain contiguous packets (#5501) + // Exit if sync word found, but does not contain contiguous packets return -1; } else { break; @@ -186023,7 +187195,7 @@ class TSDemuxer { resetInitSegment(initSegment, audioCodec, videoCodec, trackDuration) { this.pmtParsed = false; this._pmtId = -1; - this._avcTrack = TSDemuxer.createTrack('video'); + this._videoTrack = TSDemuxer.createTrack('video'); this._audioTrack = TSDemuxer.createTrack('audio', trackDuration); this._id3Track = TSDemuxer.createTrack('id3'); this._txtTrack = TSDemuxer.createTrack('text'); @@ -186031,7 +187203,6 @@ class TSDemuxer { // flush any partial content this.aacOverFlow = null; - this.avcSample = null; this.remainderData = null; this.audioCodec = audioCodec; this.videoCodec = videoCodec; @@ -186041,20 +187212,19 @@ class TSDemuxer { resetContiguity() { const { _audioTrack, - _avcTrack, + _videoTrack, _id3Track } = this; if (_audioTrack) { _audioTrack.pesData = null; } - if (_avcTrack) { - _avcTrack.pesData = null; + if (_videoTrack) { + _videoTrack.pesData = null; } if (_id3Track) { _id3Track.pesData = null; } this.aacOverFlow = null; - this.avcSample = null; this.remainderData = null; } demux(data, timeOffset, isSampleAes = false, flush = false) { @@ -186062,14 +187232,14 @@ class TSDemuxer { this.sampleAes = null; } let pes; - const videoTrack = this._avcTrack; + const videoTrack = this._videoTrack; const audioTrack = this._audioTrack; const id3Track = this._id3Track; const textTrack = this._txtTrack; - let avcId = videoTrack.pid; - let avcData = videoTrack.pesData; - let audioId = audioTrack.pid; - let id3Id = id3Track.pid; + let videoPid = videoTrack.pid; + let videoData = videoTrack.pesData; + let audioPid = audioTrack.pid; + let id3Pid = id3Track.pid; let audioData = audioTrack.pesData; let id3Data = id3Track.pesData; let unknownPID = null; @@ -186116,22 +187286,22 @@ class TSDemuxer { offset = start + 4; } switch (pid) { - case avcId: + case videoPid: if (stt) { - if (avcData && (pes = parsePES(avcData))) { - this.parseAVCPES(videoTrack, textTrack, pes, false); + if (videoData && (pes = parsePES(videoData))) { + this.videoParser.parseAVCPES(videoTrack, textTrack, pes, false, this._duration); } - avcData = { + videoData = { data: [], size: 0 }; } - if (avcData) { - avcData.data.push(data.subarray(offset, start + PACKET_LENGTH)); - avcData.size += start + PACKET_LENGTH - offset; + if (videoData) { + videoData.data.push(data.subarray(offset, start + PACKET_LENGTH)); + videoData.size += start + PACKET_LENGTH - offset; } break; - case audioId: + case audioPid: if (stt) { if (audioData && (pes = parsePES(audioData))) { switch (audioTrack.segmentCodec) { @@ -186141,6 +187311,11 @@ class TSDemuxer { case 'mp3': this.parseMPEGPES(audioTrack, pes); break; + case 'ac3': + { + this.parseAC3PES(audioTrack, pes); + } + break; } } audioData = { @@ -186153,7 +187328,7 @@ class TSDemuxer { audioData.size += start + PACKET_LENGTH - offset; } break; - case id3Id: + case id3Pid: if (stt) { if (id3Data && (pes = parsePES(id3Data))) { this.parseID3PES(id3Track, pes); @@ -186188,18 +187363,19 @@ class TSDemuxer { // this could happen in case of transient missing audio samples for example // NOTE this is only the PID of the track as found in TS, // but we are not using this for MP4 track IDs. - avcId = parsedPIDs.avc; - if (avcId > 0) { - videoTrack.pid = avcId; + videoPid = parsedPIDs.videoPid; + if (videoPid > 0) { + videoTrack.pid = videoPid; + videoTrack.segmentCodec = parsedPIDs.segmentVideoCodec; } - audioId = parsedPIDs.audio; - if (audioId > 0) { - audioTrack.pid = audioId; - audioTrack.segmentCodec = parsedPIDs.segmentCodec; + audioPid = parsedPIDs.audioPid; + if (audioPid > 0) { + audioTrack.pid = audioPid; + audioTrack.segmentCodec = parsedPIDs.segmentAudioCodec; } - id3Id = parsedPIDs.id3; - if (id3Id > 0) { - id3Track.pid = id3Id; + id3Pid = parsedPIDs.id3Pid; + if (id3Pid > 0) { + id3Track.pid = id3Pid; } if (unknownPID !== null && !pmtParsed) { logger.warn(`MPEG-TS PMT found at ${start} after unknown PID '${unknownPID}'. Backtracking to sync byte @${syncOffset} to parse all TS packets.`); @@ -186231,7 +187407,7 @@ class TSDemuxer { reason: error.message }); } - videoTrack.pesData = avcData; + videoTrack.pesData = videoData; audioTrack.pesData = audioData; id3Track.pesData = id3Data; const demuxResult = { @@ -186255,7 +187431,7 @@ class TSDemuxer { result = this.demux(remainderData, -1, false, true); } else { result = { - videoTrack: this._avcTrack, + videoTrack: this._videoTrack, audioTrack: this._audioTrack, id3Track: this._id3Track, textTrack: this._txtTrack @@ -186274,17 +187450,17 @@ class TSDemuxer { id3Track, textTrack } = demuxResult; - const avcData = videoTrack.pesData; + const videoData = videoTrack.pesData; const audioData = audioTrack.pesData; const id3Data = id3Track.pesData; // try to parse last PES packets let pes; - if (avcData && (pes = parsePES(avcData))) { - this.parseAVCPES(videoTrack, textTrack, pes, true); + if (videoData && (pes = parsePES(videoData))) { + this.videoParser.parseAVCPES(videoTrack, textTrack, pes, true, this._duration); videoTrack.pesData = null; } else { // either avcData null or PES truncated, keep it for next frag parsing - videoTrack.pesData = avcData; + videoTrack.pesData = videoData; } if (audioData && (pes = parsePES(audioData))) { switch (audioTrack.segmentCodec) { @@ -186294,6 +187470,11 @@ class TSDemuxer { case 'mp3': this.parseMPEGPES(audioTrack, pes); break; + case 'ac3': + { + this.parseAC3PES(audioTrack, pes); + } + break; } audioTrack.pesData = null; } else { @@ -186343,267 +187524,6 @@ class TSDemuxer { destroy() { this._duration = 0; } - parseAVCPES(track, textTrack, pes, last) { - const units = this.parseAVCNALu(track, pes.data); - let avcSample = this.avcSample; - let push; - let spsfound = false; - // free pes.data to save up some memory - pes.data = null; - - // if new NAL units found and last sample still there, let's push ... - // this helps parsing streams with missing AUD (only do this if AUD never found) - if (avcSample && units.length && !track.audFound) { - pushAccessUnit(avcSample, track); - avcSample = this.avcSample = createAVCSample(false, pes.pts, pes.dts, ''); - } - units.forEach(unit => { - var _avcSample2; - switch (unit.type) { - // NDR - case 1: - { - let iskey = false; - push = true; - const data = unit.data; - // only check slice type to detect KF in case SPS found in same packet (any keyframe is preceded by SPS ...) - if (spsfound && data.length > 4) { - // retrieve slice type by parsing beginning of NAL unit (follow H264 spec, slice_header definition) to detect keyframe embedded in NDR - const sliceType = new ExpGolomb(data).readSliceType(); - // 2 : I slice, 4 : SI slice, 7 : I slice, 9: SI slice - // SI slice : A slice that is coded using intra prediction only and using quantisation of the prediction samples. - // An SI slice can be coded such that its decoded samples can be constructed identically to an SP slice. - // I slice: A slice that is not an SI slice that is decoded using intra prediction only. - // if (sliceType === 2 || sliceType === 7) { - if (sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9) { - iskey = true; - } - } - if (iskey) { - var _avcSample; - // if we have non-keyframe data already, that cannot belong to the same frame as a keyframe, so force a push - if ((_avcSample = avcSample) != null && _avcSample.frame && !avcSample.key) { - pushAccessUnit(avcSample, track); - avcSample = this.avcSample = null; - } - } - if (!avcSample) { - avcSample = this.avcSample = createAVCSample(true, pes.pts, pes.dts, ''); - } - avcSample.frame = true; - avcSample.key = iskey; - break; - // IDR - } - - case 5: - push = true; - // handle PES not starting with AUD - // if we have non-keyframe data already, that cannot belong to the same frame as a keyframe, so force a push - if ((_avcSample2 = avcSample) != null && _avcSample2.frame && !avcSample.key) { - pushAccessUnit(avcSample, track); - avcSample = this.avcSample = null; - } - if (!avcSample) { - avcSample = this.avcSample = createAVCSample(true, pes.pts, pes.dts, ''); - } - avcSample.key = true; - avcSample.frame = true; - break; - // SEI - case 6: - { - push = true; - parseSEIMessageFromNALu(unit.data, 1, pes.pts, textTrack.samples); - break; - // SPS - } - - case 7: - push = true; - spsfound = true; - if (!track.sps) { - const sps = unit.data; - const expGolombDecoder = new ExpGolomb(sps); - const config = expGolombDecoder.readSPS(); - track.width = config.width; - track.height = config.height; - track.pixelRatio = config.pixelRatio; - track.sps = [sps]; - track.duration = this._duration; - const codecarray = sps.subarray(1, 4); - let codecstring = 'avc1.'; - for (let i = 0; i < 3; i++) { - let h = codecarray[i].toString(16); - if (h.length < 2) { - h = '0' + h; - } - codecstring += h; - } - track.codec = codecstring; - } - break; - // PPS - case 8: - push = true; - if (!track.pps) { - track.pps = [unit.data]; - } - break; - // AUD - case 9: - push = false; - track.audFound = true; - if (avcSample) { - pushAccessUnit(avcSample, track); - } - avcSample = this.avcSample = createAVCSample(false, pes.pts, pes.dts, ''); - break; - // Filler Data - case 12: - push = true; - break; - default: - push = false; - if (avcSample) { - avcSample.debug += 'unknown NAL ' + unit.type + ' '; - } - break; - } - if (avcSample && push) { - const units = avcSample.units; - units.push(unit); - } - }); - // if last PES packet, push samples - if (last && avcSample) { - pushAccessUnit(avcSample, track); - this.avcSample = null; - } - } - getLastNalUnit(samples) { - var _avcSample3; - let avcSample = this.avcSample; - let lastUnit; - // try to fallback to previous sample if current one is empty - if (!avcSample || avcSample.units.length === 0) { - avcSample = samples[samples.length - 1]; - } - if ((_avcSample3 = avcSample) != null && _avcSample3.units) { - const units = avcSample.units; - lastUnit = units[units.length - 1]; - } - return lastUnit; - } - parseAVCNALu(track, array) { - const len = array.byteLength; - let state = track.naluState || 0; - const lastState = state; - const units = []; - let i = 0; - let value; - let overflow; - let unitType; - let lastUnitStart = -1; - let lastUnitType = 0; - // logger.log('PES:' + Hex.hexDump(array)); - - if (state === -1) { - // special use case where we found 3 or 4-byte start codes exactly at the end of previous PES packet - lastUnitStart = 0; - // NALu type is value read from offset 0 - lastUnitType = array[0] & 0x1f; - state = 0; - i = 1; - } - while (i < len) { - value = array[i++]; - // optimization. state 0 and 1 are the predominant case. let's handle them outside of the switch/case - if (!state) { - state = value ? 0 : 1; - continue; - } - if (state === 1) { - state = value ? 0 : 2; - continue; - } - // here we have state either equal to 2 or 3 - if (!value) { - state = 3; - } else if (value === 1) { - if (lastUnitStart >= 0) { - const unit = { - data: array.subarray(lastUnitStart, i - state - 1), - type: lastUnitType - }; - // logger.log('pushing NALU, type/size:' + unit.type + '/' + unit.data.byteLength); - units.push(unit); - } else { - // lastUnitStart is undefined => this is the first start code found in this PES packet - // first check if start code delimiter is overlapping between 2 PES packets, - // ie it started in last packet (lastState not zero) - // and ended at the beginning of this PES packet (i <= 4 - lastState) - const lastUnit = this.getLastNalUnit(track.samples); - if (lastUnit) { - if (lastState && i <= 4 - lastState) { - // start delimiter overlapping between PES packets - // strip start delimiter bytes from the end of last NAL unit - // check if lastUnit had a state different from zero - if (lastUnit.state) { - // strip last bytes - lastUnit.data = lastUnit.data.subarray(0, lastUnit.data.byteLength - lastState); - } - } - // If NAL units are not starting right at the beginning of the PES packet, push preceding data into previous NAL unit. - overflow = i - state - 1; - if (overflow > 0) { - // logger.log('first NALU found with overflow:' + overflow); - const tmp = new Uint8Array(lastUnit.data.byteLength + overflow); - tmp.set(lastUnit.data, 0); - tmp.set(array.subarray(0, overflow), lastUnit.data.byteLength); - lastUnit.data = tmp; - lastUnit.state = 0; - } - } - } - // check if we can read unit type - if (i < len) { - unitType = array[i] & 0x1f; - // logger.log('find NALU @ offset:' + i + ',type:' + unitType); - lastUnitStart = i; - lastUnitType = unitType; - state = 0; - } else { - // not enough byte to read unit type. let's read it on next PES parsing - state = -1; - } - } else { - state = 0; - } - } - if (lastUnitStart >= 0 && state >= 0) { - const unit = { - data: array.subarray(lastUnitStart, len), - type: lastUnitType, - state: state - }; - units.push(unit); - // logger.log('pushing NALU, type/size/state:' + unit.type + '/' + unit.data.byteLength + '/' + state); - } - // no NALu found - if (units.length === 0) { - // append pes.data to previous NAL unit - const lastUnit = this.getLastNalUnit(track.samples); - if (lastUnit) { - const tmp = new Uint8Array(lastUnit.data.byteLength + array.byteLength); - tmp.set(lastUnit.data, 0); - tmp.set(array, lastUnit.data.byteLength); - lastUnit.data = tmp; - } - } - track.naluState = state; - return units; - } parseAACPES(track, pes) { let startOffset = 0; const aacOverFlow = this.aacOverFlow; @@ -186614,10 +187534,7 @@ class TSDemuxer { const sampleLength = aacOverFlow.sample.unit.byteLength; // logger.log(`AAC: append overflowing ${sampleLength} bytes to beginning of new PES`); if (frameMissingBytes === -1) { - const tmp = new Uint8Array(sampleLength + data.byteLength); - tmp.set(aacOverFlow.sample.unit, 0); - tmp.set(data, sampleLength); - data = tmp; + data = appendUint8Array(aacOverFlow.sample.unit, data); } else { const frameOverflowBytes = sampleLength - frameMissingBytes; aacOverFlow.sample.unit.set(data.subarray(0, frameMissingBytes), frameOverflowBytes); @@ -186674,7 +187591,7 @@ class TSDemuxer { let frameIndex = 0; let frame; while (offset < len) { - frame = appendFrame$1(track, data, offset, pts, frameIndex); + frame = appendFrame$2(track, data, offset, pts, frameIndex); offset += frame.length; if (!frame.missing) { frameIndex++; @@ -186701,7 +187618,7 @@ class TSDemuxer { } while (offset < length) { if (isHeader(data, offset)) { - const frame = appendFrame(track, data, offset, pts, frameIndex); + const frame = appendFrame$1(track, data, offset, pts, frameIndex); if (frame) { offset += frame.length; frameIndex++; @@ -186715,29 +187632,35 @@ class TSDemuxer { } } } + parseAC3PES(track, pes) { + { + const data = pes.data; + const pts = pes.pts; + if (pts === undefined) { + logger.warn('[tsdemuxer]: AC3 PES unknown PTS'); + return; + } + const length = data.length; + let frameIndex = 0; + let offset = 0; + let parsed; + while (offset < length && (parsed = appendFrame(track, data, offset, pts, frameIndex++)) > 0) { + offset += parsed; + } + } + } parseID3PES(id3Track, pes) { if (pes.pts === undefined) { logger.warn('[tsdemuxer]: ID3 PES unknown PTS'); return; } const id3Sample = _extends({}, pes, { - type: this._avcTrack ? MetadataSchema.emsg : MetadataSchema.audioId3, + type: this._videoTrack ? MetadataSchema.emsg : MetadataSchema.audioId3, duration: Number.POSITIVE_INFINITY }); id3Track.samples.push(id3Sample); } } -function createAVCSample(key, pts, dts, debug) { - return { - key, - frame: false, - pts, - dts, - units: [], - debug, - length: 0 - }; -} function parsePID(data, offset) { // pid is a 13-bit field starting at the last bit of TS[1] return ((data[offset + 1] & 0x1f) << 8) + data[offset + 2]; @@ -186748,10 +187671,11 @@ function parsePAT(data, offset) { } function parsePMT(data, offset, typeSupported, isSampleAes) { const result = { - audio: -1, - avc: -1, - id3: -1, - segmentCodec: 'aac' + audioPid: -1, + videoPid: -1, + id3Pid: -1, + segmentVideoCodec: 'avc', + segmentAudioCodec: 'aac' }; const sectionLength = (data[offset + 1] & 0x0f) << 8 | data[offset + 2]; const tableEnd = offset + 3 + sectionLength - 4; @@ -186762,41 +187686,43 @@ function parsePMT(data, offset, typeSupported, isSampleAes) { offset += 12 + programInfoLength; while (offset < tableEnd) { const pid = parsePID(data, offset); + const esInfoLength = (data[offset + 3] & 0x0f) << 8 | data[offset + 4]; switch (data[offset]) { case 0xcf: // SAMPLE-AES AAC if (!isSampleAes) { - logger.log('ADTS AAC with AES-128-CBC frame encryption found in unencrypted stream'); + logEncryptedSamplesFoundInUnencryptedStream('ADTS AAC'); break; } /* falls through */ case 0x0f: // ISO/IEC 13818-7 ADTS AAC (MPEG-2 lower bit-rate audio) // logger.log('AAC PID:' + pid); - if (result.audio === -1) { - result.audio = pid; + if (result.audioPid === -1) { + result.audioPid = pid; } break; // Packetized metadata (ID3) case 0x15: // logger.log('ID3 PID:' + pid); - if (result.id3 === -1) { - result.id3 = pid; + if (result.id3Pid === -1) { + result.id3Pid = pid; } break; case 0xdb: // SAMPLE-AES AVC if (!isSampleAes) { - logger.log('H.264 with AES-128-CBC slice encryption found in unencrypted stream'); + logEncryptedSamplesFoundInUnencryptedStream('H.264'); break; } /* falls through */ case 0x1b: // ITU-T Rec. H.264 and ISO/IEC 14496-10 (lower bit-rate video) // logger.log('AVC PID:' + pid); - if (result.avc === -1) { - result.avc = pid; + if (result.videoPid === -1) { + result.videoPid = pid; + result.segmentVideoCodec = 'avc'; } break; @@ -186805,23 +187731,77 @@ function parsePMT(data, offset, typeSupported, isSampleAes) { case 0x03: case 0x04: // logger.log('MPEG PID:' + pid); - if (typeSupported.mpeg !== true && typeSupported.mp3 !== true) { + if (!typeSupported.mpeg && !typeSupported.mp3) { logger.log('MPEG audio found, not supported in this browser'); - } else if (result.audio === -1) { - result.audio = pid; - result.segmentCodec = 'mp3'; + } else if (result.audioPid === -1) { + result.audioPid = pid; + result.segmentAudioCodec = 'mp3'; } break; + case 0xc1: + // SAMPLE-AES AC3 + if (!isSampleAes) { + logEncryptedSamplesFoundInUnencryptedStream('AC-3'); + break; + } + /* falls through */ + case 0x81: + { + if (!typeSupported.ac3) { + logger.log('AC-3 audio found, not supported in this browser'); + } else if (result.audioPid === -1) { + result.audioPid = pid; + result.segmentAudioCodec = 'ac3'; + } + } + break; + case 0x06: + // stream_type 6 can mean a lot of different things in case of DVB. + // We need to look at the descriptors. Right now, we're only interested + // in AC-3 audio, so we do the descriptor parsing only when we don't have + // an audio PID yet. + if (result.audioPid === -1 && esInfoLength > 0) { + let parsePos = offset + 5; + let remaining = esInfoLength; + while (remaining > 2) { + const descriptorId = data[parsePos]; + switch (descriptorId) { + case 0x6a: + // DVB Descriptor for AC-3 + { + if (typeSupported.ac3 !== true) { + logger.log('AC-3 audio found, not supported in this browser for now'); + } else { + result.audioPid = pid; + result.segmentAudioCodec = 'ac3'; + } + } + break; + } + const descriptorLen = data[parsePos + 1] + 2; + parsePos += descriptorLen; + remaining -= descriptorLen; + } + } + break; + case 0xc2: // SAMPLE-AES EC3 + /* falls through */ + case 0x87: + logger.warn('Unsupported EC-3 in M2TS found'); + break; case 0x24: - logger.warn('Unsupported HEVC stream type found'); + logger.warn('Unsupported HEVC in M2TS found'); break; } // move to the next table entry // skip past the elementary stream descriptors, if present - offset += ((data[offset + 3] & 0x0f) << 8 | data[offset + 4]) + 5; + offset += esInfoLength + 5; } return result; } +function logEncryptedSamplesFoundInUnencryptedStream(type) { + logger.log(`${type} with AES-128-CBC encryption found in unencrypted stream`); +} function parsePES(stream) { let i = 0; let frag; @@ -186839,10 +187819,7 @@ function parsePES(stream) { // if first chunk of data is less than 19 bytes, let's merge it with following ones until we get 19 bytes // usually only one merge is needed (and this is rare ...) while (data[0].length < 19 && data.length > 1) { - const newData = new Uint8Array(data[0].length + data[1].length); - newData.set(data[0]); - newData.set(data[1], data[0].length); - data[0] = newData; + data[0] = appendUint8Array(data[0], data[1]); data.splice(1, 1); } // retrieve PTS/DTS from first fragment @@ -186927,28 +187904,6 @@ function parsePES(stream) { } return null; } -function pushAccessUnit(avcSample, avcTrack) { - if (avcSample.units.length && avcSample.frame) { - // if sample does not have PTS/DTS, patch with last sample PTS/DTS - if (avcSample.pts === undefined) { - const samples = avcTrack.samples; - const nbSamples = samples.length; - if (nbSamples) { - const lastSample = samples[nbSamples - 1]; - avcSample.pts = lastSample.pts; - avcSample.dts = lastSample.dts; - } else { - // dropping samples, no timestamp found - avcTrack.dropped++; - return; - } - } - avcTrack.samples.push(avcSample); - } - if (avcSample.debug.length) { - logger.log(avcSample.pts + '/' + avcSample.dts + ':' + avcSample.debug); - } -} /** * MP3 demuxer @@ -186979,8 +187934,15 @@ class MP3Demuxer extends BaseAudioDemuxer { // Look for MPEG header | 1111 1111 | 111X XYZX | where X can be either 0 or 1 and Y or Z should be 1 // Layer bits (position 14 and 15) in header should be always different from 0 (Layer I or Layer II or Layer III) // More info http://www.mp3-tech.org/programmer/frame_header.html - const id3Data = getID3Data(data, 0) || []; - let offset = id3Data.length; + const id3Data = getID3Data(data, 0); + let offset = (id3Data == null ? void 0 : id3Data.length) || 0; + + // Check for ac-3|ec-3 sync bytes and return false if present + if (id3Data && data[offset] === 0x0b && data[offset + 1] === 0x77 && getTimeStamp(id3Data) !== undefined && + // check the bsid to confirm ac-3 or ec-3 (not mp3) + getAudioBSID(data, offset) <= 16) { + return false; + } for (let length = data.length; offset < length; offset++) { if (probe(data, offset)) { logger.log('MPEG Audio sync word found !'); @@ -186996,7 +187958,7 @@ class MP3Demuxer extends BaseAudioDemuxer { if (this.basePTS === null) { return; } - return appendFrame(track, data, offset, this.basePTS, this.frameIndex); + return appendFrame$1(track, data, offset, this.basePTS, this.frameIndex); } } @@ -187066,6 +188028,8 @@ class MP4 { moov: [], mp4a: [], '.mp3': [], + dac3: [], + 'ac-3': [], mvex: [], mvhd: [], pasp: [], @@ -187108,7 +188072,6 @@ class MP4 { // reserved 0x56, 0x69, 0x64, 0x65, 0x6f, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x00 // name: 'VideoHandler' ]); - const audioHdlr = new Uint8Array([0x00, // version 0 0x00, 0x00, 0x00, @@ -187125,7 +188088,6 @@ class MP4 { // reserved 0x53, 0x6f, 0x75, 0x6e, 0x64, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x00 // name: 'SoundHandler' ]); - MP4.HDLR_TYPES = { video: videoHdlr, audio: audioHdlr @@ -187144,14 +188106,12 @@ class MP4 { // version 0 0x00, 0x00, 0x01 // entry_flags ]); - const stco = new Uint8Array([0x00, // version 0x00, 0x00, 0x00, // flags 0x00, 0x00, 0x00, 0x00 // entry_count ]); - MP4.STTS = MP4.STSC = MP4.STCO = stco; MP4.STSZ = new Uint8Array([0x00, // version @@ -187161,7 +188121,6 @@ class MP4 { // sample_size 0x00, 0x00, 0x00, 0x00 // sample_count ]); - MP4.VMHD = new Uint8Array([0x00, // version 0x00, 0x00, 0x01, @@ -187170,7 +188129,6 @@ class MP4 { // graphicsmode 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // opcolor ]); - MP4.SMHD = new Uint8Array([0x00, // version 0x00, 0x00, 0x00, @@ -187179,7 +188137,6 @@ class MP4 { // balance 0x00, 0x00 // reserved ]); - MP4.STSD = new Uint8Array([0x00, // version 0 0x00, 0x00, 0x00, @@ -187247,7 +188204,6 @@ class MP4 { sequenceNumber >> 24, sequenceNumber >> 16 & 0xff, sequenceNumber >> 8 & 0xff, sequenceNumber & 0xff // sequence_number ])); } - static minf(track) { if (track.type === 'audio') { return MP4.box(MP4.types.minf, MP4.box(MP4.types.smhd, MP4.SMHD), MP4.DINF, MP4.stbl(track)); @@ -187304,7 +188260,6 @@ class MP4 { // pre_defined 0xff, 0xff, 0xff, 0xff // next_track_ID ]); - return MP4.box(MP4.types.mvhd, bytes); } static sdtp(track) { @@ -187444,10 +188399,9 @@ class MP4 { 0x05 // descriptor_type ].concat([configlen]).concat(track.config).concat([0x06, 0x01, 0x02])); // GASpecificConfig)); // length + audio config descriptor } - - static mp4a(track) { + static audioStsd(track) { const samplerate = track.samplerate; - return MP4.box(MP4.types.mp4a, new Uint8Array([0x00, 0x00, 0x00, + return new Uint8Array([0x00, 0x00, 0x00, // reserved 0x00, 0x00, 0x00, // reserved @@ -187463,33 +188417,25 @@ class MP4 { // reserved2 samplerate >> 8 & 0xff, samplerate & 0xff, // - 0x00, 0x00]), MP4.box(MP4.types.esds, MP4.esds(track))); + 0x00, 0x00]); + } + static mp4a(track) { + return MP4.box(MP4.types.mp4a, MP4.audioStsd(track), MP4.box(MP4.types.esds, MP4.esds(track))); } static mp3(track) { - const samplerate = track.samplerate; - return MP4.box(MP4.types['.mp3'], new Uint8Array([0x00, 0x00, 0x00, - // reserved - 0x00, 0x00, 0x00, - // reserved - 0x00, 0x01, - // data_reference_index - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // reserved - 0x00, track.channelCount, - // channelcount - 0x00, 0x10, - // sampleSize:16bits - 0x00, 0x00, 0x00, 0x00, - // reserved2 - samplerate >> 8 & 0xff, samplerate & 0xff, - // - 0x00, 0x00])); + return MP4.box(MP4.types['.mp3'], MP4.audioStsd(track)); + } + static ac3(track) { + return MP4.box(MP4.types['ac-3'], MP4.audioStsd(track), MP4.box(MP4.types.dac3, track.config)); } static stsd(track) { if (track.type === 'audio') { if (track.segmentCodec === 'mp3' && track.codec === 'mp3') { return MP4.box(MP4.types.stsd, MP4.STSD, MP4.mp3(track)); } + if (track.segmentCodec === 'ac3') { + return MP4.box(MP4.types.stsd, MP4.STSD, MP4.ac3(track)); + } return MP4.box(MP4.types.stsd, MP4.STSD, MP4.mp4a(track)); } else { return MP4.box(MP4.types.stsd, MP4.STSD, MP4.avc1(track)); @@ -187531,7 +188477,6 @@ class MP4 { height >> 8 & 0xff, height & 0xff, 0x00, 0x00 // height ])); } - static traf(track, baseMediaDecodeTime) { const sampleDependencyTable = MP4.sdtp(track); const id = track.id; @@ -187586,7 +188531,6 @@ class MP4 { 0x00, 0x01, 0x00, 0x01 // default_sample_flags ])); } - static trun(track, offset) { const samples = track.samples || []; const len = samples.length; @@ -187629,9 +188573,7 @@ class MP4 { MP4.init(); } const movie = MP4.moov(tracks); - const result = new Uint8Array(MP4.FTYP.byteLength + movie.byteLength); - result.set(MP4.FTYP); - result.set(movie, MP4.FTYP.byteLength); + const result = appendUint8Array(MP4.FTYP, movie); return result; } } @@ -187665,6 +188607,7 @@ function toMpegTsClockFromTimescale(baseTime, srcScale = 1) { const MAX_SILENT_FRAME_DURATION = 10 * 1000; // 10 seconds const AAC_SAMPLES_PER_FRAME = 1024; const MPEG_AUDIO_SAMPLE_PER_FRAME = 1152; +const AC3_SAMPLES_PER_FRAME = 1536; let chromeVersion = null; let safariWebkitVersion = null; class MP4Remuxer { @@ -187680,6 +188623,7 @@ class MP4Remuxer { this.videoSampleDuration = null; this.isAudioContiguous = false; this.isVideoContiguous = false; + this.videoTrackConfig = void 0; this.observer = observer; this.config = config; this.typeSupported = typeSupported; @@ -187694,7 +188638,10 @@ class MP4Remuxer { safariWebkitVersion = result ? parseInt(result[1]) : 0; } } - destroy() {} + destroy() { + // @ts-ignore + this.config = this.videoTrackConfig = this._initPTS = this._initDTS = null; + } resetTimeStamp(defaultTimeStamp) { logger.log('[mp4-remuxer]: initPTS & initDTS reset'); this._initPTS = this._initDTS = defaultTimeStamp; @@ -187707,6 +188654,7 @@ class MP4Remuxer { resetInitSegment() { logger.log('[mp4-remuxer]: ISGenerated flag reset'); this.ISGenerated = false; + this.videoTrackConfig = undefined; } getVideoStartPts(videoSamples) { let rolloverDetected = false; @@ -187749,7 +188697,13 @@ class MP4Remuxer { const enoughVideoSamples = flush && length > 0 || length > 1; const canRemuxAvc = (!hasAudio || enoughAudioSamples) && (!hasVideo || enoughVideoSamples) || this.ISGenerated || flush; if (canRemuxAvc) { - if (!this.ISGenerated) { + if (this.ISGenerated) { + var _videoTrack$pixelRati, _config$pixelRatio, _videoTrack$pixelRati2, _config$pixelRatio2; + const config = this.videoTrackConfig; + if (config && (videoTrack.width !== config.width || videoTrack.height !== config.height || ((_videoTrack$pixelRati = videoTrack.pixelRatio) == null ? void 0 : _videoTrack$pixelRati[0]) !== ((_config$pixelRatio = config.pixelRatio) == null ? void 0 : _config$pixelRatio[0]) || ((_videoTrack$pixelRati2 = videoTrack.pixelRatio) == null ? void 0 : _videoTrack$pixelRati2[1]) !== ((_config$pixelRatio2 = config.pixelRatio) == null ? void 0 : _config$pixelRatio2[1]))) { + this.resetInitSegment(); + } + } else { initSegment = this.generateIS(audioTrack, videoTrack, timeOffset, accurateTimeOffset); } const isVideoContiguous = this.isVideoContiguous; @@ -187862,6 +188816,9 @@ class MP4Remuxer { audioTrack.codec = 'mp3'; } break; + case 'ac3': + audioTrack.codec = 'ac-3'; + break; } tracks.audio = { id: 'audio', @@ -187907,6 +188864,11 @@ class MP4Remuxer { computePTSDTS = false; } } + this.videoTrackConfig = { + width: videoTrack.width, + height: videoTrack.height, + pixelRatio: videoTrack.pixelRatio + }; } if (Object.keys(tracks).length) { this.ISGenerated = true; @@ -187948,8 +188910,13 @@ class MP4Remuxer { if (!contiguous || nextAvcDts === null) { const pts = timeOffset * timeScale; const cts = inputSamples[0].pts - normalizePts(inputSamples[0].dts, inputSamples[0].pts); - // if not contiguous, let's use target timeOffset - nextAvcDts = pts - cts; + if (chromeVersion && nextAvcDts !== null && Math.abs(pts - cts - nextAvcDts) < 15000) { + // treat as contigous to adjust samples that would otherwise produce video buffer gaps in Chrome + contiguous = true; + } else { + // if not contiguous, let's use target timeOffset + nextAvcDts = pts - cts; + } } // PTS is coded on 33bits, and can loop from -2^32 to 2^32 @@ -187990,22 +188957,33 @@ class MP4Remuxer { const foundOverlap = delta < -1; if (foundHole || foundOverlap) { if (foundHole) { - logger.warn(`AVC: ${toMsFromMpegTsClock(delta, true)} ms (${delta}dts) hole between fragments detected, filling it`); + logger.warn(`AVC: ${toMsFromMpegTsClock(delta, true)} ms (${delta}dts) hole between fragments detected at ${timeOffset.toFixed(3)}`); } else { - logger.warn(`AVC: ${toMsFromMpegTsClock(-delta, true)} ms (${delta}dts) overlapping between fragments detected`); + logger.warn(`AVC: ${toMsFromMpegTsClock(-delta, true)} ms (${delta}dts) overlapping between fragments detected at ${timeOffset.toFixed(3)}`); } - if (!foundOverlap || nextAvcDts >= inputSamples[0].pts) { + if (!foundOverlap || nextAvcDts >= inputSamples[0].pts || chromeVersion) { firstDTS = nextAvcDts; const firstPTS = inputSamples[0].pts - delta; - inputSamples[0].dts = firstDTS; - inputSamples[0].pts = firstPTS; - logger.log(`Video: First PTS/DTS adjusted: ${toMsFromMpegTsClock(firstPTS, true)}/${toMsFromMpegTsClock(firstDTS, true)}, delta: ${toMsFromMpegTsClock(delta, true)} ms`); + if (foundHole) { + inputSamples[0].dts = firstDTS; + inputSamples[0].pts = firstPTS; + } else { + for (let i = 0; i < inputSamples.length; i++) { + if (inputSamples[i].dts > firstPTS) { + break; + } + inputSamples[i].dts -= delta; + inputSamples[i].pts -= delta; + } + } + logger.log(`Video: Initial PTS/DTS adjusted: ${toMsFromMpegTsClock(firstPTS, true)}/${toMsFromMpegTsClock(firstDTS, true)}, delta: ${toMsFromMpegTsClock(delta, true)} ms`); } } } firstDTS = Math.max(0, firstDTS); let nbNalu = 0; let naluLen = 0; + let dtsStep = firstDTS; for (let i = 0; i < nbSamples; i++) { // compute total/avc sample length and nb of NAL units const sample = inputSamples[i]; @@ -188020,7 +188998,12 @@ class MP4Remuxer { sample.length = sampleLen; // ensure sample monotonic DTS - sample.dts = Math.max(sample.dts, firstDTS); + if (sample.dts < dtsStep) { + sample.dts = dtsStep; + dtsStep += averageSampleDuration / 4 | 0 || 1; + } else { + dtsStep = sample.dts; + } minPTS = Math.min(sample.pts, minPTS); maxPTS = Math.max(sample.pts, maxPTS); } @@ -188052,12 +189035,12 @@ class MP4Remuxer { let maxDtsDelta = Number.NEGATIVE_INFINITY; let maxPtsDelta = Number.NEGATIVE_INFINITY; for (let i = 0; i < nbSamples; i++) { - const avcSample = inputSamples[i]; - const avcSampleUnits = avcSample.units; + const VideoSample = inputSamples[i]; + const VideoSampleUnits = VideoSample.units; let mp4SampleLength = 0; // convert NALU bitstream to MP4 format (prepend NALU with size field) - for (let j = 0, nbUnits = avcSampleUnits.length; j < nbUnits; j++) { - const unit = avcSampleUnits[j]; + for (let j = 0, nbUnits = VideoSampleUnits.length; j < nbUnits; j++) { + const unit = VideoSampleUnits[j]; const unitData = unit.data; const unitDataLen = unit.data.byteLength; view.setUint32(offset, unitDataLen); @@ -188070,12 +189053,12 @@ class MP4Remuxer { // expected sample duration is the Decoding Timestamp diff of consecutive samples let ptsDelta; if (i < nbSamples - 1) { - mp4SampleDuration = inputSamples[i + 1].dts - avcSample.dts; - ptsDelta = inputSamples[i + 1].pts - avcSample.pts; + mp4SampleDuration = inputSamples[i + 1].dts - VideoSample.dts; + ptsDelta = inputSamples[i + 1].pts - VideoSample.pts; } else { const config = this.config; - const lastFrameDuration = i > 0 ? avcSample.dts - inputSamples[i - 1].dts : averageSampleDuration; - ptsDelta = i > 0 ? avcSample.pts - inputSamples[i - 1].pts : averageSampleDuration; + const lastFrameDuration = i > 0 ? VideoSample.dts - inputSamples[i - 1].dts : averageSampleDuration; + ptsDelta = i > 0 ? VideoSample.pts - inputSamples[i - 1].pts : averageSampleDuration; if (config.stretchShortVideoTrack && this.nextAudioPts !== null) { // In some cases, a segment's audio track duration may exceed the video track duration. // Since we've already remuxed audio, and we know how long the audio track is, we look to @@ -188083,7 +189066,7 @@ class MP4Remuxer { // If so, playback would potentially get stuck, so we artificially inflate // the duration of the last frame to minimize any potential gap between segments. const gapTolerance = Math.floor(config.maxBufferHole * timeScale); - const deltaToFrameEnd = (audioTrackLength ? minPTS + audioTrackLength * timeScale : this.nextAudioPts) - avcSample.pts; + const deltaToFrameEnd = (audioTrackLength ? minPTS + audioTrackLength * timeScale : this.nextAudioPts) - VideoSample.pts; if (deltaToFrameEnd > gapTolerance) { // We subtract lastFrameDuration from deltaToFrameEnd to try to prevent any video // frame overlap. maxBufferHole should be >> lastFrameDuration anyway. @@ -188101,12 +189084,12 @@ class MP4Remuxer { mp4SampleDuration = lastFrameDuration; } } - const compositionTimeOffset = Math.round(avcSample.pts - avcSample.dts); + const compositionTimeOffset = Math.round(VideoSample.pts - VideoSample.dts); minDtsDelta = Math.min(minDtsDelta, mp4SampleDuration); maxDtsDelta = Math.max(maxDtsDelta, mp4SampleDuration); minPtsDelta = Math.min(minPtsDelta, ptsDelta); maxPtsDelta = Math.max(maxPtsDelta, ptsDelta); - outputSamples.push(new Mp4Sample(avcSample.key, mp4SampleDuration, mp4SampleLength, compositionTimeOffset)); + outputSamples.push(new Mp4Sample(VideoSample.key, mp4SampleDuration, mp4SampleLength, compositionTimeOffset)); } if (outputSamples.length) { if (chromeVersion) { @@ -188164,11 +189147,21 @@ class MP4Remuxer { track.dropped = 0; return data; } + getSamplesPerFrame(track) { + switch (track.segmentCodec) { + case 'mp3': + return MPEG_AUDIO_SAMPLE_PER_FRAME; + case 'ac3': + return AC3_SAMPLES_PER_FRAME; + default: + return AAC_SAMPLES_PER_FRAME; + } + } remuxAudio(track, timeOffset, contiguous, accurateTimeOffset, videoTimeOffset) { const inputTimeScale = track.inputTimeScale; const mp4timeScale = track.samplerate ? track.samplerate : inputTimeScale; const scaleFactor = inputTimeScale / mp4timeScale; - const mp4SampleDuration = track.segmentCodec === 'aac' ? AAC_SAMPLES_PER_FRAME : MPEG_AUDIO_SAMPLE_PER_FRAME; + const mp4SampleDuration = this.getSamplesPerFrame(track); const inputSampleDuration = mp4SampleDuration * scaleFactor; const initPTS = this._initPTS; const rawMPEG = track.segmentCodec === 'mp3' && this.typeSupported.mpeg; @@ -188484,19 +189477,14 @@ class Mp4Sample { this.duration = duration; this.size = size; this.cts = cts; - this.flags = new Mp4SampleFlags(isKeyframe); - } -} -class Mp4SampleFlags { - constructor(isKeyframe) { - this.isLeading = 0; - this.isDependedOn = 0; - this.hasRedundancy = 0; - this.degradPrio = 0; - this.dependsOn = 1; - this.isNonSync = 1; - this.dependsOn = isKeyframe ? 2 : 1; - this.isNonSync = isKeyframe ? 0 : 1; + this.flags = { + isLeading: 0, + isDependedOn: 0, + hasRedundancy: 0, + degradPrio: 0, + dependsOn: isKeyframe ? 2 : 1, + isNonSync: isKeyframe ? 0 : 1 + }; } } @@ -188537,10 +189525,10 @@ class PassThroughRemuxer { const initData = this.initData = parseInitSegment(initSegment); // Get codec from initSegment or fallback to default - if (!audioCodec) { + if (initData.audio) { audioCodec = getParsedTrackCodec(initData.audio, ElementaryStreamTypes.AUDIO); } - if (!videoCodec) { + if (initData.video) { videoCodec = getParsedTrackCodec(initData.video, ElementaryStreamTypes.VIDEO); } const tracks = {}; @@ -188682,19 +189670,29 @@ function getParsedTrackCodec(track, type) { if (parsedCodec && parsedCodec.length > 4) { return parsedCodec; } - // Since mp4-tools cannot parse full codec string (see 'TODO: Parse codec details'... in mp4-tools) + if (type === ElementaryStreamTypes.AUDIO) { + if (parsedCodec === 'ec-3' || parsedCodec === 'ac-3' || parsedCodec === 'alac') { + return parsedCodec; + } + if (parsedCodec === 'fLaC' || parsedCodec === 'Opus') { + // Opting not to get `preferManagedMediaSource` from player config for isSupported() check for simplicity + const preferManagedMediaSource = false; + return getCodecCompatibleName(parsedCodec, preferManagedMediaSource); + } + const result = 'mp4a.40.5'; + logger.info(`Parsed audio codec "${parsedCodec}" or audio object type not handled. Using "${result}"`); + return result; + } // Provide defaults based on codec type // This allows for some playback of some fmp4 playlists without CODECS defined in manifest + logger.warn(`Unhandled video codec "${parsedCodec}"`); if (parsedCodec === 'hvc1' || parsedCodec === 'hev1') { return 'hvc1.1.6.L120.90'; } if (parsedCodec === 'av01') { return 'av01.0.04M.08'; } - if (parsedCodec === 'avc1' || type === ElementaryStreamTypes.VIDEO) { - return 'avc1.42e01e'; - } - return 'mp4a.40.5'; + return 'avc1.42e01e'; } let now; @@ -188703,7 +189701,7 @@ try { now = self.performance.now.bind(self.performance); } catch (err) { logger.debug('Unable to use Performance API on this environment'); - now = typeof self !== 'undefined' && self.Date.now; + now = optionalSelf == null ? void 0 : optionalSelf.Date.now; } const muxConfig = [{ demux: MP4Demuxer, @@ -188718,6 +189716,12 @@ const muxConfig = [{ demux: MP3Demuxer, remux: MP4Remuxer }]; +{ + muxConfig.splice(2, 0, { + demux: AC3Demuxer, + remux: MP4Remuxer + }); +} class Transmuxer { constructor(observer, typeSupported, config, vendor, id) { this.async = false; @@ -188987,7 +189991,8 @@ class Transmuxer { // probe for content type let mux; for (let i = 0, len = muxConfig.length; i < len; i++) { - if (muxConfig[i].demux.probe(data)) { + var _muxConfig$i$demux; + if ((_muxConfig$i$demux = muxConfig[i].demux) != null && _muxConfig$i$demux.probe(data)) { mux = muxConfig[i]; break; } @@ -189023,7 +190028,7 @@ class Transmuxer { } function getEncryptionType(data, decryptData) { let encryptionType = null; - if (data.byteLength > 0 && decryptData != null && decryptData.key != null && decryptData.iv !== null && decryptData.method != null) { + if (data.byteLength > 0 && (decryptData == null ? void 0 : decryptData.key) != null && decryptData.iv !== null && decryptData.method != null) { encryptionType = decryptData; } return encryptionType; @@ -189409,9 +190414,6 @@ var eventemitter3 = {exports: {}}; var eventemitter3Exports = eventemitter3.exports; var EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports); -const MediaSource$1 = getMediaSource() || { - isTypeSupported: () => false -}; class TransmuxerInterface { constructor(hls, id, onTransmuxComplete, onFlush) { this.error = null; @@ -189446,11 +190448,15 @@ class TransmuxerInterface { this.observer = new EventEmitter(); this.observer.on(Events.FRAG_DECRYPTED, forwardMessage); this.observer.on(Events.ERROR, forwardMessage); - const typeSupported = { - mp4: MediaSource$1.isTypeSupported('video/mp4'), - mpeg: MediaSource$1.isTypeSupported('audio/mpeg'), - mp3: MediaSource$1.isTypeSupported('audio/mp4; codecs="mp3"') + const MediaSource = getMediaSource(config.preferManagedMediaSource) || { + isTypeSupported: () => false }; + const m2tsTypeSupported = { + mpeg: MediaSource.isTypeSupported('audio/mpeg'), + mp3: MediaSource.isTypeSupported('audio/mp4; codecs="mp3"'), + ac3: MediaSource.isTypeSupported('audio/mp4; codecs="ac-3"') + }; + // navigator.vendor is not always available in Web Worker // refer to https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/navigator const vendor = navigator.vendor; @@ -189484,7 +190490,7 @@ class TransmuxerInterface { }; worker.postMessage({ cmd: 'init', - typeSupported: typeSupported, + typeSupported: m2tsTypeSupported, vendor: vendor, id: id, config: JSON.stringify(config) @@ -189493,12 +190499,12 @@ class TransmuxerInterface { logger.warn(`Error setting up "${id}" Web Worker, fallback to inline`, err); this.resetWorker(); this.error = null; - this.transmuxer = new Transmuxer(this.observer, typeSupported, config, vendor, id); + this.transmuxer = new Transmuxer(this.observer, m2tsTypeSupported, config, vendor, id); } return; } } - this.transmuxer = new Transmuxer(this.observer, typeSupported, config, vendor, id); + this.transmuxer = new Transmuxer(this.observer, m2tsTypeSupported, config, vendor, id); } resetWorker() { if (this.workerContext) { @@ -189709,347 +190715,55 @@ class TransmuxerInterface { } } -const STALL_MINIMUM_DURATION_MS = 250; -const MAX_START_GAP_JUMP = 2.0; -const SKIP_BUFFER_HOLE_STEP_SECONDS = 0.1; -const SKIP_BUFFER_RANGE_START = 0.05; -class GapController { - constructor(config, media, fragmentTracker, hls) { - this.config = void 0; - this.media = null; - this.fragmentTracker = void 0; - this.hls = void 0; - this.nudgeRetry = 0; - this.stallReported = false; - this.stalled = null; - this.moved = false; - this.seeking = false; - this.config = config; - this.media = media; - this.fragmentTracker = fragmentTracker; - this.hls = hls; - } - destroy() { - this.media = null; - // @ts-ignore - this.hls = this.fragmentTracker = null; - } - - /** - * Checks if the playhead is stuck within a gap, and if so, attempts to free it. - * A gap is an unbuffered range between two buffered ranges (or the start and the first buffered range). - * - * @param lastCurrentTime - Previously read playhead position - */ - poll(lastCurrentTime, activeFrag) { - const { - config, - media, - stalled - } = this; - if (media === null) { - return; - } - const { - currentTime, - seeking - } = media; - const seeked = this.seeking && !seeking; - const beginSeek = !this.seeking && seeking; - this.seeking = seeking; - - // The playhead is moving, no-op - if (currentTime !== lastCurrentTime) { - this.moved = true; - if (stalled !== null) { - // The playhead is now moving, but was previously stalled - if (this.stallReported) { - const _stalledDuration = self.performance.now() - stalled; - logger.warn(`playback not stuck anymore @${currentTime}, after ${Math.round(_stalledDuration)}ms`); - this.stallReported = false; - } - this.stalled = null; - this.nudgeRetry = 0; - } - return; - } - - // Clear stalled state when beginning or finishing seeking so that we don't report stalls coming out of a seek - if (beginSeek || seeked) { - this.stalled = null; - return; - } - - // The playhead should not be moving - if (media.paused && !seeking || media.ended || media.playbackRate === 0 || !BufferHelper.getBuffered(media).length) { - return; - } - const bufferInfo = BufferHelper.bufferInfo(media, currentTime, 0); - const isBuffered = bufferInfo.len > 0; - const nextStart = bufferInfo.nextStart || 0; - - // There is no playable buffer (seeked, waiting for buffer) - if (!isBuffered && !nextStart) { - return; - } - if (seeking) { - // Waiting for seeking in a buffered range to complete - const hasEnoughBuffer = bufferInfo.len > MAX_START_GAP_JUMP; - // Next buffered range is too far ahead to jump to while still seeking - const noBufferGap = !nextStart || activeFrag && activeFrag.start <= currentTime || nextStart - currentTime > MAX_START_GAP_JUMP && !this.fragmentTracker.getPartialFragment(currentTime); - if (hasEnoughBuffer || noBufferGap) { - return; - } - // Reset moved state when seeking to a point in or before a gap - this.moved = false; - } - - // Skip start gaps if we haven't played, but the last poll detected the start of a stall - // The addition poll gives the browser a chance to jump the gap for us - if (!this.moved && this.stalled !== null) { - var _level$details; - // Jump start gaps within jump threshold - const startJump = Math.max(nextStart, bufferInfo.start || 0) - currentTime; - - // When joining a live stream with audio tracks, account for live playlist window sliding by allowing - // a larger jump over start gaps caused by the audio-stream-controller buffering a start fragment - // that begins over 1 target duration after the video start position. - const level = this.hls.levels ? this.hls.levels[this.hls.currentLevel] : null; - const isLive = level == null ? void 0 : (_level$details = level.details) == null ? void 0 : _level$details.live; - const maxStartGapJump = isLive ? level.details.targetduration * 2 : MAX_START_GAP_JUMP; - const partialOrGap = this.fragmentTracker.getPartialFragment(currentTime); - if (startJump > 0 && (startJump <= maxStartGapJump || partialOrGap)) { - this._trySkipBufferHole(partialOrGap); - return; - } - } - - // Start tracking stall time - const tnow = self.performance.now(); - if (stalled === null) { - this.stalled = tnow; - return; - } - const stalledDuration = tnow - stalled; - if (!seeking && stalledDuration >= STALL_MINIMUM_DURATION_MS) { - // Report stalling after trying to fix - this._reportStall(bufferInfo); - if (!this.media) { - return; - } - } - const bufferedWithHoles = BufferHelper.bufferInfo(media, currentTime, config.maxBufferHole); - this._tryFixBufferStall(bufferedWithHoles, stalledDuration); - } - - /** - * Detects and attempts to fix known buffer stalling issues. - * @param bufferInfo - The properties of the current buffer. - * @param stalledDurationMs - The amount of time Hls.js has been stalling for. - * @private - */ - _tryFixBufferStall(bufferInfo, stalledDurationMs) { - const { - config, - fragmentTracker, - media - } = this; - if (media === null) { - return; - } - const currentTime = media.currentTime; - const partial = fragmentTracker.getPartialFragment(currentTime); - if (partial) { - // Try to skip over the buffer hole caused by a partial fragment - // This method isn't limited by the size of the gap between buffered ranges - const targetTime = this._trySkipBufferHole(partial); - // we return here in this case, meaning - // the branch below only executes when we haven't seeked to a new position - if (targetTime || !this.media) { - return; - } - } - - // if we haven't had to skip over a buffer hole of a partial fragment - // we may just have to "nudge" the playlist as the browser decoding/rendering engine - // needs to cross some sort of threshold covering all source-buffers content - // to start playing properly. - if ((bufferInfo.len > config.maxBufferHole || bufferInfo.nextStart && bufferInfo.nextStart - currentTime < config.maxBufferHole) && stalledDurationMs > config.highBufferWatchdogPeriod * 1000) { - logger.warn('Trying to nudge playhead over buffer-hole'); - // Try to nudge currentTime over a buffer hole if we've been stalling for the configured amount of seconds - // We only try to jump the hole if it's under the configured size - // Reset stalled so to rearm watchdog timer - this.stalled = null; - this._tryNudgeBuffer(); - } - } - - /** - * Triggers a BUFFER_STALLED_ERROR event, but only once per stall period. - * @param bufferLen - The playhead distance from the end of the current buffer segment. - * @private - */ - _reportStall(bufferInfo) { - const { - hls, - media, - stallReported - } = this; - if (!stallReported && media) { - // Report stalled error once - this.stallReported = true; - const error = new Error(`Playback stalling at @${media.currentTime} due to low buffer (${JSON.stringify(bufferInfo)})`); - logger.warn(error.message); - hls.trigger(Events.ERROR, { - type: ErrorTypes.MEDIA_ERROR, - details: ErrorDetails.BUFFER_STALLED_ERROR, - fatal: false, - error, - buffer: bufferInfo.len - }); - } +function subtitleOptionsIdentical(trackList1, trackList2) { + if (trackList1.length !== trackList2.length) { + return false; } - - /** - * Attempts to fix buffer stalls by jumping over known gaps caused by partial fragments - * @param partial - The partial fragment found at the current time (where playback is stalling). - * @private - */ - _trySkipBufferHole(partial) { - const { - config, - hls, - media - } = this; - if (media === null) { - return 0; - } - - // Check if currentTime is between unbuffered regions of partial fragments - const currentTime = media.currentTime; - const bufferInfo = BufferHelper.bufferInfo(media, currentTime, 0); - const startTime = currentTime < bufferInfo.start ? bufferInfo.start : bufferInfo.nextStart; - if (startTime) { - const bufferStarved = bufferInfo.len <= config.maxBufferHole; - const waiting = bufferInfo.len > 0 && bufferInfo.len < 1 && media.readyState < 3; - const gapLength = startTime - currentTime; - if (gapLength > 0 && (bufferStarved || waiting)) { - // Only allow large gaps to be skipped if it is a start gap, or all fragments in skip range are partial - if (gapLength > config.maxBufferHole) { - const { - fragmentTracker - } = this; - let startGap = false; - if (currentTime === 0) { - const startFrag = fragmentTracker.getAppendedFrag(0, PlaylistLevelType.MAIN); - if (startFrag && startTime < startFrag.end) { - startGap = true; - } - } - if (!startGap) { - const startProvisioned = partial || fragmentTracker.getAppendedFrag(currentTime, PlaylistLevelType.MAIN); - if (startProvisioned) { - let moreToLoad = false; - let pos = startProvisioned.end; - while (pos < startTime) { - const provisioned = fragmentTracker.getPartialFragment(pos); - if (provisioned) { - pos += provisioned.duration; - } else { - moreToLoad = true; - break; - } - } - if (moreToLoad) { - return 0; - } - } - } - } - const targetTime = Math.max(startTime + SKIP_BUFFER_RANGE_START, currentTime + SKIP_BUFFER_HOLE_STEP_SECONDS); - logger.warn(`skipping hole, adjusting currentTime from ${currentTime} to ${targetTime}`); - this.moved = true; - this.stalled = null; - media.currentTime = targetTime; - if (partial && !partial.gap) { - const error = new Error(`fragment loaded with buffer holes, seeking from ${currentTime} to ${targetTime}`); - hls.trigger(Events.ERROR, { - type: ErrorTypes.MEDIA_ERROR, - details: ErrorDetails.BUFFER_SEEK_OVER_HOLE, - fatal: false, - error, - reason: error.message, - frag: partial - }); - } - return targetTime; - } + for (let i = 0; i < trackList1.length; i++) { + if (!mediaAttributesIdentical(trackList1[i].attrs, trackList2[i].attrs)) { + return false; } - return 0; } - - /** - * Attempts to fix buffer stalls by advancing the mediaElement's current time by a small amount. - * @private - */ - _tryNudgeBuffer() { - const { - config, - hls, - media, - nudgeRetry - } = this; - if (media === null) { - return; - } - const currentTime = media.currentTime; - this.nudgeRetry++; - if (nudgeRetry < config.nudgeMaxRetry) { - const targetTime = currentTime + (nudgeRetry + 1) * config.nudgeOffset; - // playback stalled in buffered area ... let's nudge currentTime to try to overcome this - const error = new Error(`Nudging 'currentTime' from ${currentTime} to ${targetTime}`); - logger.warn(error.message); - media.currentTime = targetTime; - hls.trigger(Events.ERROR, { - type: ErrorTypes.MEDIA_ERROR, - details: ErrorDetails.BUFFER_NUDGE_ON_STALL, - error, - fatal: false - }); - } else { - const error = new Error(`Playhead still not moving while enough data buffered @${currentTime} after ${config.nudgeMaxRetry} nudges`); - logger.error(error.message); - hls.trigger(Events.ERROR, { - type: ErrorTypes.MEDIA_ERROR, - details: ErrorDetails.BUFFER_STALLED_ERROR, - error, - fatal: true - }); - } + return true; +} +function mediaAttributesIdentical(attrs1, attrs2, customAttributes) { + // Media options with the same rendition ID must be bit identical + const stableRenditionId = attrs1['STABLE-RENDITION-ID']; + if (stableRenditionId && !customAttributes) { + return stableRenditionId === attrs2['STABLE-RENDITION-ID']; } + // When rendition ID is not present, compare attributes + return !(customAttributes || ['LANGUAGE', 'NAME', 'CHARACTERISTICS', 'AUTOSELECT', 'DEFAULT', 'FORCED', 'ASSOC-LANGUAGE']).some(subtitleAttribute => attrs1[subtitleAttribute] !== attrs2[subtitleAttribute]); +} +function subtitleTrackMatchesTextTrack(subtitleTrack, textTrack) { + return textTrack.label.toLowerCase() === subtitleTrack.name.toLowerCase() && (!textTrack.language || textTrack.language.toLowerCase() === (subtitleTrack.lang || '').toLowerCase()); } const TICK_INTERVAL$2 = 100; // how often to tick in ms -class StreamController extends BaseStreamController { +class AudioStreamController extends BaseStreamController { constructor(hls, fragmentTracker, keyLoader) { - super(hls, fragmentTracker, keyLoader, '[stream-controller]', PlaylistLevelType.MAIN); - this.audioCodecSwap = false; - this.gapController = null; - this.level = -1; - this._forceStartLoad = false; - this.altAudio = false; - this.audioOnly = false; - this.fragPlaying = null; - this.onvplaying = null; - this.onvseeked = null; - this.fragLastKbps = 0; - this.couldBacktrack = false; - this.backtrackFragment = null; - this.audioCodecSwitch = false; + super(hls, fragmentTracker, keyLoader, '[audio-stream-controller]', PlaylistLevelType.AUDIO); this.videoBuffer = null; + this.videoTrackCC = -1; + this.waitingVideoCC = -1; + this.bufferedTrack = null; + this.switchingTrack = null; + this.trackId = -1; + this.waitingData = null; + this.mainDetails = null; + this.flushing = false; + this.bufferFlushed = false; + this.cachedTrackLoadedData = null; this._registerListeners(); } + onHandlerDestroying() { + this._unregisterListeners(); + super.onHandlerDestroying(); + this.mainDetails = null; + this.bufferedTrack = null; + this.switchingTrack = null; + } _registerListeners() { const { hls @@ -190057,16 +190771,16 @@ class StreamController extends BaseStreamController { hls.on(Events.MEDIA_ATTACHED, this.onMediaAttached, this); hls.on(Events.MEDIA_DETACHING, this.onMediaDetaching, this); hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this); - hls.on(Events.MANIFEST_PARSED, this.onManifestParsed, this); - hls.on(Events.LEVEL_LOADING, this.onLevelLoading, this); hls.on(Events.LEVEL_LOADED, this.onLevelLoaded, this); - hls.on(Events.FRAG_LOAD_EMERGENCY_ABORTED, this.onFragLoadEmergencyAborted, this); - hls.on(Events.ERROR, this.onError, this); + hls.on(Events.AUDIO_TRACKS_UPDATED, this.onAudioTracksUpdated, this); hls.on(Events.AUDIO_TRACK_SWITCHING, this.onAudioTrackSwitching, this); - hls.on(Events.AUDIO_TRACK_SWITCHED, this.onAudioTrackSwitched, this); + hls.on(Events.AUDIO_TRACK_LOADED, this.onAudioTrackLoaded, this); + hls.on(Events.ERROR, this.onError, this); + hls.on(Events.BUFFER_RESET, this.onBufferReset, this); hls.on(Events.BUFFER_CREATED, this.onBufferCreated, this); + hls.on(Events.BUFFER_FLUSHING, this.onBufferFlushing, this); hls.on(Events.BUFFER_FLUSHED, this.onBufferFlushed, this); - hls.on(Events.LEVELS_UPDATED, this.onLevelsUpdated, this); + hls.on(Events.INIT_PTS_FOUND, this.onInitPtsFound, this); hls.on(Events.FRAG_BUFFERED, this.onFragBuffered, this); } _unregisterListeners() { @@ -190076,477 +190790,382 @@ class StreamController extends BaseStreamController { hls.off(Events.MEDIA_ATTACHED, this.onMediaAttached, this); hls.off(Events.MEDIA_DETACHING, this.onMediaDetaching, this); hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this); - hls.off(Events.MANIFEST_PARSED, this.onManifestParsed, this); hls.off(Events.LEVEL_LOADED, this.onLevelLoaded, this); - hls.off(Events.FRAG_LOAD_EMERGENCY_ABORTED, this.onFragLoadEmergencyAborted, this); - hls.off(Events.ERROR, this.onError, this); + hls.off(Events.AUDIO_TRACKS_UPDATED, this.onAudioTracksUpdated, this); hls.off(Events.AUDIO_TRACK_SWITCHING, this.onAudioTrackSwitching, this); - hls.off(Events.AUDIO_TRACK_SWITCHED, this.onAudioTrackSwitched, this); + hls.off(Events.AUDIO_TRACK_LOADED, this.onAudioTrackLoaded, this); + hls.off(Events.ERROR, this.onError, this); + hls.off(Events.BUFFER_RESET, this.onBufferReset, this); hls.off(Events.BUFFER_CREATED, this.onBufferCreated, this); + hls.off(Events.BUFFER_FLUSHING, this.onBufferFlushing, this); hls.off(Events.BUFFER_FLUSHED, this.onBufferFlushed, this); - hls.off(Events.LEVELS_UPDATED, this.onLevelsUpdated, this); + hls.off(Events.INIT_PTS_FOUND, this.onInitPtsFound, this); hls.off(Events.FRAG_BUFFERED, this.onFragBuffered, this); } - onHandlerDestroying() { - this._unregisterListeners(); - this.onMediaDetaching(); + + // INIT_PTS_FOUND is triggered when the video track parsed in the stream-controller has a new PTS value + onInitPtsFound(event, { + frag, + id, + initPTS, + timescale + }) { + // Always update the new INIT PTS + // Can change due level switch + if (id === 'main') { + const cc = frag.cc; + this.initPTS[frag.cc] = { + baseTime: initPTS, + timescale + }; + this.log(`InitPTS for cc: ${cc} found from main: ${initPTS}`); + this.videoTrackCC = cc; + // If we are waiting, tick immediately to unblock audio fragment transmuxing + if (this.state === State.WAITING_INIT_PTS) { + this.tick(); + } + } } startLoad(startPosition) { - if (this.levels) { - const { - lastCurrentTime, - hls - } = this; - this.stopLoad(); - this.setInterval(TICK_INTERVAL$2); - this.level = -1; - if (!this.startFragRequested) { - // determine load level - let startLevel = hls.startLevel; - if (startLevel === -1) { - if (hls.config.testBandwidth && this.levels.length > 1) { - // -1 : guess start Level by doing a bitrate test by loading first fragment of lowest quality level - startLevel = 0; - this.bitrateTest = true; - } else { - startLevel = hls.nextAutoLevel; - } - } - // set new level to playlist loader : this will trigger start level load - // hls.nextLoadLevel remains until it is set to a new value or until a new frag is successfully loaded - this.level = hls.nextLoadLevel = startLevel; - this.loadedmetadata = false; - } - // if startPosition undefined but lastCurrentTime set, set startPosition to last currentTime - if (lastCurrentTime > 0 && startPosition === -1) { - this.log(`Override startPosition with lastCurrentTime @${lastCurrentTime.toFixed(3)}`); - startPosition = lastCurrentTime; - } + if (!this.levels) { + this.startPosition = startPosition; + this.state = State.STOPPED; + return; + } + const lastCurrentTime = this.lastCurrentTime; + this.stopLoad(); + this.setInterval(TICK_INTERVAL$2); + if (lastCurrentTime > 0 && startPosition === -1) { + this.log(`Override startPosition with lastCurrentTime @${lastCurrentTime.toFixed(3)}`); + startPosition = lastCurrentTime; this.state = State.IDLE; - this.nextLoadPosition = this.startPosition = this.lastCurrentTime = startPosition; - this.tick(); } else { - this._forceStartLoad = true; - this.state = State.STOPPED; + this.loadedmetadata = false; + this.state = State.WAITING_TRACK; } - } - stopLoad() { - this._forceStartLoad = false; - super.stopLoad(); + this.nextLoadPosition = this.startPosition = this.lastCurrentTime = startPosition; + this.tick(); } doTick() { switch (this.state) { - case State.WAITING_LEVEL: + case State.IDLE: + this.doTickIdle(); + break; + case State.WAITING_TRACK: { - var _levels$level; + var _levels$trackId; const { levels, - level + trackId } = this; - const details = levels == null ? void 0 : (_levels$level = levels[level]) == null ? void 0 : _levels$level.details; - if (details && (!details.live || this.levelLastLoaded === this.level)) { + const details = levels == null ? void 0 : (_levels$trackId = levels[trackId]) == null ? void 0 : _levels$trackId.details; + if (details) { if (this.waitForCdnTuneIn(details)) { break; } - this.state = State.IDLE; - break; - } else if (this.hls.nextLoadLevel !== this.level) { - this.state = State.IDLE; - break; + this.state = State.WAITING_INIT_PTS; } break; } case State.FRAG_LOADING_WAITING_RETRY: { var _this$media; - const now = self.performance.now(); + const now = performance.now(); const retryDate = this.retryDate; // if current time is gt than retryDate, or if media seeking let's switch to IDLE state to retry loading if (!retryDate || now >= retryDate || (_this$media = this.media) != null && _this$media.seeking) { - this.resetStartWhenNotLoaded(this.level); + const { + levels, + trackId + } = this; + this.log('RetryDate reached, switch back to IDLE state'); + this.resetStartWhenNotLoaded((levels == null ? void 0 : levels[trackId]) || null); + this.state = State.IDLE; + } + break; + } + case State.WAITING_INIT_PTS: + { + // Ensure we don't get stuck in the WAITING_INIT_PTS state if the waiting frag CC doesn't match any initPTS + const waitingData = this.waitingData; + if (waitingData) { + const { + frag, + part, + cache, + complete + } = waitingData; + if (this.initPTS[frag.cc] !== undefined) { + this.waitingData = null; + this.waitingVideoCC = -1; + this.state = State.FRAG_LOADING; + const payload = cache.flush(); + const data = { + frag, + part, + payload, + networkDetails: null + }; + this._handleFragmentLoadProgress(data); + if (complete) { + super._handleFragmentLoadComplete(data); + } + } else if (this.videoTrackCC !== this.waitingVideoCC) { + // Drop waiting fragment if videoTrackCC has changed since waitingFragment was set and initPTS was not found + this.log(`Waiting fragment cc (${frag.cc}) cancelled because video is at cc ${this.videoTrackCC}`); + this.clearWaitingFragment(); + } else { + // Drop waiting fragment if an earlier fragment is needed + const pos = this.getLoadPosition(); + const bufferInfo = BufferHelper.bufferInfo(this.mediaBuffer, pos, this.config.maxBufferHole); + const waitingFragmentAtPosition = fragmentWithinToleranceTest(bufferInfo.end, this.config.maxFragLookUpTolerance, frag); + if (waitingFragmentAtPosition < 0) { + this.log(`Waiting fragment cc (${frag.cc}) @ ${frag.start} cancelled because another fragment at ${bufferInfo.end} is needed`); + this.clearWaitingFragment(); + } + } + } else { this.state = State.IDLE; } } - break; - } - if (this.state === State.IDLE) { - this.doTickIdle(); } this.onTickEnd(); } + clearWaitingFragment() { + const waitingData = this.waitingData; + if (waitingData) { + this.fragmentTracker.removeFragment(waitingData.frag); + this.waitingData = null; + this.waitingVideoCC = -1; + this.state = State.IDLE; + } + } + resetLoadingState() { + this.clearWaitingFragment(); + super.resetLoadingState(); + } onTickEnd() { - super.onTickEnd(); - this.checkBuffer(); - this.checkFragmentChanged(); + const { + media + } = this; + if (!(media != null && media.readyState)) { + // Exit early if we don't have media or if the media hasn't buffered anything yet (readyState 0) + return; + } + this.lastCurrentTime = media.currentTime; } doTickIdle() { const { hls, - levelLastLoaded, levels, - media + media, + trackId } = this; - const { - config, - nextLoadLevel: level - } = hls; + const config = hls.config; - // if start level not parsed yet OR - // if video not attached AND start fragment already requested OR start frag prefetch not enabled - // exit loop, as we either need more info (level not parsed) or we need media to be attached to load new fragment - if (levelLastLoaded === null || !media && (this.startFragRequested || !config.startFragPrefetch)) { + // 1. if video not attached AND + // start fragment already requested OR start frag prefetch not enabled + // 2. if tracks or track not loaded and selected + // then exit loop + // => if media not attached but start frag prefetch is enabled and start frag not requested yet, we will not exit loop + if (!media && (this.startFragRequested || !config.startFragPrefetch) || !(levels != null && levels[trackId])) { return; } - - // If the "main" level is audio-only but we are loading an alternate track in the same group, do not load anything - if (this.altAudio && this.audioOnly) { + const levelInfo = levels[trackId]; + const trackDetails = levelInfo.details; + if (!trackDetails || trackDetails.live && this.levelLastLoaded !== levelInfo || this.waitForCdnTuneIn(trackDetails)) { + this.state = State.WAITING_TRACK; return; } - if (!(levels != null && levels[level])) { - return; + const bufferable = this.mediaBuffer ? this.mediaBuffer : this.media; + if (this.bufferFlushed && bufferable) { + this.bufferFlushed = false; + this.afterBufferFlushed(bufferable, ElementaryStreamTypes.AUDIO, PlaylistLevelType.AUDIO); } - const levelInfo = levels[level]; - - // if buffer length is less than maxBufLen try to load a new fragment - - const bufferInfo = this.getMainFwdBufferInfo(); + const bufferInfo = this.getFwdBufferInfo(bufferable, PlaylistLevelType.AUDIO); if (bufferInfo === null) { return; } - const lastDetails = this.getLevelDetails(); - if (lastDetails && this._streamEnded(bufferInfo, lastDetails)) { - const data = {}; - if (this.altAudio) { - data.type = 'video'; - } - this.hls.trigger(Events.BUFFER_EOS, data); + const { + bufferedTrack, + switchingTrack + } = this; + if (!switchingTrack && this._streamEnded(bufferInfo, trackDetails)) { + hls.trigger(Events.BUFFER_EOS, { + type: 'audio' + }); this.state = State.ENDED; return; } - - // set next load level : this will trigger a playlist load if needed - if (hls.loadLevel !== level && hls.manualLevel === -1) { - this.log(`Adapting to level ${level} from level ${this.level}`); - } - this.level = hls.nextLoadLevel = level; - const levelDetails = levelInfo.details; - // if level info not retrieved yet, switch state and wait for level retrieval - // if live playlist, ensure that new playlist has been refreshed to avoid loading/try to load - // a useless and outdated fragment (that might even introduce load error if it is already out of the live playlist) - if (!levelDetails || this.state === State.WAITING_LEVEL || levelDetails.live && this.levelLastLoaded !== level) { - this.level = level; - this.state = State.WAITING_LEVEL; - return; - } + const mainBufferInfo = this.getFwdBufferInfo(this.videoBuffer ? this.videoBuffer : this.media, PlaylistLevelType.MAIN); const bufferLen = bufferInfo.len; + const maxBufLen = this.getMaxBufferLength(mainBufferInfo == null ? void 0 : mainBufferInfo.len); + const fragments = trackDetails.fragments; + const start = fragments[0].start; + let targetBufferTime = this.flushing ? this.getLoadPosition() : bufferInfo.end; + if (switchingTrack && media) { + const pos = this.getLoadPosition(); + // STABLE + if (bufferedTrack && !mediaAttributesIdentical(switchingTrack.attrs, bufferedTrack.attrs)) { + targetBufferTime = pos; + } + // if currentTime (pos) is less than alt audio playlist start time, it means that alt audio is ahead of currentTime + if (trackDetails.PTSKnown && pos < start) { + // if everything is buffered from pos to start or if audio buffer upfront, let's seek to start + if (bufferInfo.end > start || bufferInfo.nextStart) { + this.log('Alt audio track ahead of main track, seek to start of alt audio track'); + media.currentTime = start + 0.05; + } + } + } - // compute max Buffer Length that we could get from this load level, based on level bitrate. don't buffer more than 60 MB and more than 30s - const maxBufLen = this.getMaxBufferLength(levelInfo.maxBitrate); - - // Stay idle if we are still with buffer margins - if (bufferLen >= maxBufLen) { + // if buffer length is less than maxBufLen, or near the end, find a fragment to load + if (bufferLen >= maxBufLen && !switchingTrack && targetBufferTime < fragments[fragments.length - 1].start) { return; } - if (this.backtrackFragment && this.backtrackFragment.start > bufferInfo.end) { - this.backtrackFragment = null; - } - const targetBufferTime = this.backtrackFragment ? this.backtrackFragment.start : bufferInfo.end; - let frag = this.getNextFragment(targetBufferTime, levelDetails); - // Avoid backtracking by loading an earlier segment in streams with segments that do not start with a key frame (flagged by `couldBacktrack`) - if (this.couldBacktrack && !this.fragPrevious && frag && frag.sn !== 'initSegment' && this.fragmentTracker.getState(frag) !== FragmentState.OK) { - var _this$backtrackFragme; - const backtrackSn = ((_this$backtrackFragme = this.backtrackFragment) != null ? _this$backtrackFragme : frag).sn; - const fragIdx = backtrackSn - levelDetails.startSN; - const backtrackFrag = levelDetails.fragments[fragIdx - 1]; - if (backtrackFrag && frag.cc === backtrackFrag.cc) { - frag = backtrackFrag; - this.fragmentTracker.removeFragment(backtrackFrag); - } - } else if (this.backtrackFragment && bufferInfo.len) { - this.backtrackFragment = null; - } + let frag = this.getNextFragment(targetBufferTime, trackDetails); + let atGap = false; // Avoid loop loading by using nextLoadPosition set for backtracking and skipping consecutive GAP tags if (frag && this.isLoopLoading(frag, targetBufferTime)) { - const gapStart = frag.gap; - if (!gapStart) { - // Cleanup the fragment tracker before trying to find the next unbuffered fragment - const type = this.audioOnly && !this.altAudio ? ElementaryStreamTypes.AUDIO : ElementaryStreamTypes.VIDEO; - const mediaBuffer = (type === ElementaryStreamTypes.VIDEO ? this.videoBuffer : this.mediaBuffer) || this.media; - if (mediaBuffer) { - this.afterBufferFlushed(mediaBuffer, type, PlaylistLevelType.MAIN); - } - } - frag = this.getNextFragmentLoopLoading(frag, levelDetails, bufferInfo, PlaylistLevelType.MAIN, maxBufLen); + atGap = !!frag.gap; + frag = this.getNextFragmentLoopLoading(frag, trackDetails, bufferInfo, PlaylistLevelType.MAIN, maxBufLen); } if (!frag) { + this.bufferFlushed = true; return; } - if (frag.initSegment && !frag.initSegment.data && !this.bitrateTest) { - frag = frag.initSegment; - } - this.loadFragment(frag, levelInfo, targetBufferTime); - } - loadFragment(frag, level, targetBufferTime) { - // Check if fragment is not loaded - const fragState = this.fragmentTracker.getState(frag); - this.fragCurrent = frag; - if (fragState === FragmentState.NOT_LOADED || fragState === FragmentState.PARTIAL) { - if (frag.sn === 'initSegment') { - this._loadInitSegment(frag, level); - } else if (this.bitrateTest) { - this.log(`Fragment ${frag.sn} of level ${frag.level} is being downloaded to test bitrate and will not be buffered`); - this._loadBitrateTestFrag(frag, level); - } else { - this.startFragRequested = true; - super.loadFragment(frag, level, targetBufferTime); - } - } else { - this.clearTrackerIfNeeded(frag); - } - } - getBufferedFrag(position) { - return this.fragmentTracker.getBufferedFrag(position, PlaylistLevelType.MAIN); - } - followingBufferedFrag(frag) { - if (frag) { - // try to get range of next fragment (500ms after this range) - return this.getBufferedFrag(frag.end + 0.5); - } - return null; - } - - /* - on immediate level switch : - - pause playback if playing - - cancel any pending load request - - and trigger a buffer flush - */ - immediateLevelSwitch() { - this.abortCurrentFrag(); - this.flushMainBuffer(0, Number.POSITIVE_INFINITY); - } - /** - * try to switch ASAP without breaking video playback: - * in order to ensure smooth but quick level switching, - * we need to find the next flushable buffer range - * we should take into account new segment fetch time - */ - nextLevelSwitch() { - const { - levels, - media - } = this; - // ensure that media is defined and that metadata are available (to retrieve currentTime) - if (media != null && media.readyState) { - let fetchdelay; - const fragPlayingCurrent = this.getAppendedFrag(media.currentTime); - if (fragPlayingCurrent && fragPlayingCurrent.start > 1) { - // flush buffer preceding current fragment (flush until current fragment start offset) - // minus 1s to avoid video freezing, that could happen if we flush keyframe of current video ... - this.flushMainBuffer(0, fragPlayingCurrent.start - 1); - } - const levelDetails = this.getLevelDetails(); - if (levelDetails != null && levelDetails.live) { - const bufferInfo = this.getMainFwdBufferInfo(); - // Do not flush in live stream with low buffer - if (!bufferInfo || bufferInfo.len < levelDetails.targetduration * 2) { - return; - } - } - if (!media.paused && levels) { - // add a safety delay of 1s - const nextLevelId = this.hls.nextLoadLevel; - const nextLevel = levels[nextLevelId]; - const fragLastKbps = this.fragLastKbps; - if (fragLastKbps && this.fragCurrent) { - fetchdelay = this.fragCurrent.duration * nextLevel.maxBitrate / (1000 * fragLastKbps) + 1; - } else { - fetchdelay = 0; - } - } else { - fetchdelay = 0; + // Buffer audio up to one target duration ahead of main buffer + const atBufferSyncLimit = mainBufferInfo && frag.start > mainBufferInfo.end + trackDetails.targetduration; + if (atBufferSyncLimit || + // Or wait for main buffer after buffing some audio + !(mainBufferInfo != null && mainBufferInfo.len) && bufferInfo.len) { + // Check fragment-tracker for main fragments since GAP segments do not show up in bufferInfo + const mainFrag = this.getAppendedFrag(frag.start, PlaylistLevelType.MAIN); + if (mainFrag === null) { + return; } - // this.log('fetchdelay:'+fetchdelay); - // find buffer range that will be reached once new fragment will be fetched - const bufferedFrag = this.getBufferedFrag(media.currentTime + fetchdelay); - if (bufferedFrag) { - // we can flush buffer range following this one without stalling playback - const nextBufferedFrag = this.followingBufferedFrag(bufferedFrag); - if (nextBufferedFrag) { - // if we are here, we can also cancel any loading/demuxing in progress, as they are useless - this.abortCurrentFrag(); - // start flush position is in next buffered frag. Leave some padding for non-independent segments and smoother playback. - const maxStart = nextBufferedFrag.maxStartPTS ? nextBufferedFrag.maxStartPTS : nextBufferedFrag.start; - const fragDuration = nextBufferedFrag.duration; - const startPts = Math.max(bufferedFrag.end, maxStart + Math.min(Math.max(fragDuration - this.config.maxFragLookUpTolerance, fragDuration * 0.5), fragDuration * 0.75)); - this.flushMainBuffer(startPts, Number.POSITIVE_INFINITY); - } + // Bridge gaps in main buffer + atGap || (atGap = !!mainFrag.gap || !!atBufferSyncLimit && mainBufferInfo.len === 0); + if (atBufferSyncLimit && !atGap || atGap && bufferInfo.nextStart && bufferInfo.nextStart < mainFrag.end) { + return; } } + this.loadFragment(frag, levelInfo, targetBufferTime); } - abortCurrentFrag() { - const fragCurrent = this.fragCurrent; - this.fragCurrent = null; - this.backtrackFragment = null; - if (fragCurrent) { - fragCurrent.abortRequests(); - this.fragmentTracker.removeFragment(fragCurrent); - } - switch (this.state) { - case State.KEY_LOADING: - case State.FRAG_LOADING: - case State.FRAG_LOADING_WAITING_RETRY: - case State.PARSING: - case State.PARSED: - this.state = State.IDLE; - break; + getMaxBufferLength(mainBufferLength) { + const maxConfigBuffer = super.getMaxBufferLength(); + if (!mainBufferLength) { + return maxConfigBuffer; } - this.nextLoadPosition = this.getLoadPosition(); + return Math.min(Math.max(maxConfigBuffer, mainBufferLength), this.config.maxMaxBufferLength); } - flushMainBuffer(startOffset, endOffset) { - super.flushMainBuffer(startOffset, endOffset, this.altAudio ? 'video' : null); + onMediaDetaching() { + this.videoBuffer = null; + this.bufferFlushed = this.flushing = false; + super.onMediaDetaching(); } - onMediaAttached(event, data) { - super.onMediaAttached(event, data); - const media = data.media; - this.onvplaying = this.onMediaPlaying.bind(this); - this.onvseeked = this.onMediaSeeked.bind(this); - media.addEventListener('playing', this.onvplaying); - media.addEventListener('seeked', this.onvseeked); - this.gapController = new GapController(this.config, media, this.fragmentTracker, this.hls); + onAudioTracksUpdated(event, { + audioTracks + }) { + // Reset tranxmuxer is essential for large context switches (Content Steering) + this.resetTransmuxer(); + this.levels = audioTracks.map(mediaPlaylist => new Level(mediaPlaylist)); } - onMediaDetaching() { + onAudioTrackSwitching(event, data) { + // if any URL found on new audio track, it is an alternate audio track + const altAudio = !!data.url; + this.trackId = data.id; const { - media + fragCurrent } = this; - if (media && this.onvplaying && this.onvseeked) { - media.removeEventListener('playing', this.onvplaying); - media.removeEventListener('seeked', this.onvseeked); - this.onvplaying = this.onvseeked = null; - this.videoBuffer = null; - } - this.fragPlaying = null; - if (this.gapController) { - this.gapController.destroy(); - this.gapController = null; + if (fragCurrent) { + fragCurrent.abortRequests(); + this.removeUnbufferedFrags(fragCurrent.start); } - super.onMediaDetaching(); - } - onMediaPlaying() { - // tick to speed up FRAG_CHANGED triggering - this.tick(); - } - onMediaSeeked() { - const media = this.media; - const currentTime = media ? media.currentTime : null; - if (isFiniteNumber(currentTime)) { - this.log(`Media seeked to ${currentTime.toFixed(3)}`); + this.resetLoadingState(); + // destroy useless transmuxer when switching audio to main + if (!altAudio) { + this.resetTransmuxer(); + } else { + // switching to audio track, start timer if not already started + this.setInterval(TICK_INTERVAL$2); } - // If seeked was issued before buffer was appended do not tick immediately - const bufferInfo = this.getMainFwdBufferInfo(); - if (bufferInfo === null || bufferInfo.len === 0) { - this.warn(`Main forward buffer length on "seeked" event ${bufferInfo ? bufferInfo.len : 'empty'})`); - return; + // should we switch tracks ? + if (altAudio) { + this.switchingTrack = data; + // main audio track are handled by stream-controller, just do something if switching to alt audio track + this.state = State.IDLE; + this.flushAudioIfNeeded(data); + } else { + this.switchingTrack = null; + this.bufferedTrack = data; + this.state = State.STOPPED; } - - // tick to speed up FRAG_CHANGED triggering this.tick(); } onManifestLoading() { - // reset buffer on manifest loading - this.log('Trigger BUFFER_RESET'); - this.hls.trigger(Events.BUFFER_RESET, undefined); this.fragmentTracker.removeAllFragments(); - this.couldBacktrack = false; this.startPosition = this.lastCurrentTime = 0; - this.levels = this.fragPlaying = this.backtrackFragment = null; - this.altAudio = this.audioOnly = false; + this.bufferFlushed = this.flushing = false; + this.levels = this.mainDetails = this.waitingData = this.bufferedTrack = this.cachedTrackLoadedData = this.switchingTrack = null; + this.startFragRequested = false; + this.trackId = this.videoTrackCC = this.waitingVideoCC = -1; } - onManifestParsed(event, data) { - let aac = false; - let heaac = false; - let codec; - data.levels.forEach(level => { - // detect if we have different kind of audio codecs used amongst playlists - codec = level.audioCodec; - if (codec) { - if (codec.indexOf('mp4a.40.2') !== -1) { - aac = true; - } - if (codec.indexOf('mp4a.40.5') !== -1) { - heaac = true; - } - } - }); - this.audioCodecSwitch = aac && heaac && !changeTypeSupported(); - if (this.audioCodecSwitch) { - this.log('Both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC'); + onLevelLoaded(event, data) { + this.mainDetails = data.details; + if (this.cachedTrackLoadedData !== null) { + this.hls.trigger(Events.AUDIO_TRACK_LOADED, this.cachedTrackLoadedData); + this.cachedTrackLoadedData = null; } - this.levels = data.levels; - this.startFragRequested = false; } - onLevelLoading(event, data) { - const { - levels - } = this; - if (!levels || this.state !== State.IDLE) { + onAudioTrackLoaded(event, data) { + var _track$details; + if (this.mainDetails == null) { + this.cachedTrackLoadedData = data; return; } - const level = levels[data.level]; - if (!level.details || level.details.live && this.levelLastLoaded !== data.level || this.waitForCdnTuneIn(level.details)) { - this.state = State.WAITING_LEVEL; - } - } - onLevelLoaded(event, data) { - var _curLevel$details; const { levels } = this; - const newLevelId = data.level; - const newDetails = data.details; - const duration = newDetails.totalduration; + const { + details: newDetails, + id: trackId + } = data; if (!levels) { - this.warn(`Levels were reset while loading level ${newLevelId}`); + this.warn(`Audio tracks were reset while loading level ${trackId}`); return; } - this.log(`Level ${newLevelId} loaded [${newDetails.startSN},${newDetails.endSN}]${newDetails.lastPartSn ? `[part-${newDetails.lastPartSn}-${newDetails.lastPartIndex}]` : ''}, cc [${newDetails.startCC}, ${newDetails.endCC}] duration:${duration}`); - const curLevel = levels[newLevelId]; - const fragCurrent = this.fragCurrent; - if (fragCurrent && (this.state === State.FRAG_LOADING || this.state === State.FRAG_LOADING_WAITING_RETRY)) { - if ((fragCurrent.level !== data.level || fragCurrent.urlId !== curLevel.urlId) && fragCurrent.loader) { - this.abortCurrentFrag(); - } - } + this.log(`Audio track ${trackId} loaded [${newDetails.startSN},${newDetails.endSN}]${newDetails.lastPartSn ? `[part-${newDetails.lastPartSn}-${newDetails.lastPartIndex}]` : ''},duration:${newDetails.totalduration}`); + const track = levels[trackId]; let sliding = 0; - if (newDetails.live || (_curLevel$details = curLevel.details) != null && _curLevel$details.live) { + if (newDetails.live || (_track$details = track.details) != null && _track$details.live) { this.checkLiveUpdate(newDetails); - if (newDetails.deltaUpdateFailed) { + const mainDetails = this.mainDetails; + if (newDetails.deltaUpdateFailed || !mainDetails) { return; } - sliding = this.alignPlaylists(newDetails, curLevel.details); + if (!track.details && newDetails.hasProgramDateTime && mainDetails.hasProgramDateTime) { + // Make sure our audio rendition is aligned with the "main" rendition, using + // pdt as our reference times. + alignMediaPlaylistByPDT(newDetails, mainDetails); + sliding = newDetails.fragments[0].start; + } else { + var _this$levelLastLoaded; + sliding = this.alignPlaylists(newDetails, track.details, (_this$levelLastLoaded = this.levelLastLoaded) == null ? void 0 : _this$levelLastLoaded.details); + } } - // override level info - curLevel.details = newDetails; - this.levelLastLoaded = newLevelId; - this.hls.trigger(Events.LEVEL_UPDATED, { - details: newDetails, - level: newLevelId - }); + track.details = newDetails; + this.levelLastLoaded = track; - // only switch back to IDLE state if we were waiting for level to start downloading a new fragment - if (this.state === State.WAITING_LEVEL) { - if (this.waitForCdnTuneIn(newDetails)) { - // Wait for Low-Latency CDN Tune-in - return; - } - this.state = State.IDLE; + // compute start position if we are aligned with the main playlist + if (!this.startFragRequested && (this.mainDetails || !newDetails.live)) { + this.setStartPosition(track.details, sliding); } - if (!this.startFragRequested) { - this.setStartPosition(newDetails, sliding); - } else if (newDetails.live) { - this.synchronizeToLiveEdge(newDetails); + // only switch back to IDLE state if we were waiting for track to start downloading a new fragment + if (this.state === State.WAITING_TRACK && !this.waitForCdnTuneIn(newDetails)) { + this.state = State.IDLE; } // trigger handler right now @@ -190560,114 +191179,78 @@ class StreamController extends BaseStreamController { payload } = data; const { + config, + trackId, levels } = this; if (!levels) { - this.warn(`Levels were reset while fragment load was in progress. Fragment ${frag.sn} of level ${frag.level} will not be buffered`); + this.warn(`Audio tracks were reset while fragment load was in progress. Fragment ${frag.sn} of level ${frag.level} will not be buffered`); return; } - const currentLevel = levels[frag.level]; - const details = currentLevel.details; + const track = levels[trackId]; + if (!track) { + this.warn('Audio track is undefined on fragment load progress'); + return; + } + const details = track.details; if (!details) { - this.warn(`Dropping fragment ${frag.sn} of level ${frag.level} after level details were reset`); - this.fragmentTracker.removeFragment(frag); + this.warn('Audio track details undefined on fragment load progress'); + this.removeUnbufferedFrags(frag.start); return; } - const videoCodec = currentLevel.videoCodec; - - // time Offset is accurate if level PTS is known, or if playlist is not sliding (not live) - const accurateTimeOffset = details.PTSKnown || !details.live; - const initSegmentData = (_frag$initSegment = frag.initSegment) == null ? void 0 : _frag$initSegment.data; - const audioCodec = this._getAudioCodec(currentLevel); + const audioCodec = config.defaultAudioCodec || track.audioCodec || 'mp4a.40.2'; + let transmuxer = this.transmuxer; + if (!transmuxer) { + transmuxer = this.transmuxer = new TransmuxerInterface(this.hls, PlaylistLevelType.AUDIO, this._handleTransmuxComplete.bind(this), this._handleTransmuxerFlush.bind(this)); + } - // transmux the MPEG-TS data to ISO-BMFF segments - // this.log(`Transmuxing ${frag.sn} of [${details.startSN} ,${details.endSN}],level ${frag.level}, cc ${frag.cc}`); - const transmuxer = this.transmuxer = this.transmuxer || new TransmuxerInterface(this.hls, PlaylistLevelType.MAIN, this._handleTransmuxComplete.bind(this), this._handleTransmuxerFlush.bind(this)); - const partIndex = part ? part.index : -1; - const partial = partIndex !== -1; - const chunkMeta = new ChunkMetadata(frag.level, frag.sn, frag.stats.chunkCount, payload.byteLength, partIndex, partial); + // Check if we have video initPTS + // If not we need to wait for it const initPTS = this.initPTS[frag.cc]; - transmuxer.push(payload, initSegmentData, audioCodec, videoCodec, frag, part, details.totalduration, accurateTimeOffset, chunkMeta, initPTS); - } - onAudioTrackSwitching(event, data) { - // if any URL found on new audio track, it is an alternate audio track - const fromAltAudio = this.altAudio; - const altAudio = !!data.url; - // if we switch on main audio, ensure that main fragment scheduling is synced with media.buffered - // don't do anything if we switch to alt audio: audio stream controller is handling it. - // we will just have to change buffer scheduling on audioTrackSwitched - if (!altAudio) { - if (this.mediaBuffer !== this.media) { - this.log('Switching on main audio, use media.buffered to schedule main fragment loading'); - this.mediaBuffer = this.media; - const fragCurrent = this.fragCurrent; - // we need to refill audio buffer from main: cancel any frag loading to speed up audio switch - if (fragCurrent) { - this.log('Switching to main audio track, cancel main fragment load'); - fragCurrent.abortRequests(); - this.fragmentTracker.removeFragment(fragCurrent); - } - // destroy transmuxer to force init segment generation (following audio switch) - this.resetTransmuxer(); - // switch to IDLE state to load new fragment - this.resetLoadingState(); - } else if (this.audioOnly) { - // Reset audio transmuxer so when switching back to main audio we're not still appending where we left off - this.resetTransmuxer(); - } - const hls = this.hls; - // If switching from alt to main audio, flush all audio and trigger track switched - if (fromAltAudio) { - hls.trigger(Events.BUFFER_FLUSHING, { - startOffset: 0, - endOffset: Number.POSITIVE_INFINITY, - type: null - }); - this.fragmentTracker.removeAllFragments(); - } - hls.trigger(Events.AUDIO_TRACK_SWITCHED, data); + const initSegmentData = (_frag$initSegment = frag.initSegment) == null ? void 0 : _frag$initSegment.data; + if (initPTS !== undefined) { + // this.log(`Transmuxing ${sn} of [${details.startSN} ,${details.endSN}],track ${trackId}`); + // time Offset is accurate if level PTS is known, or if playlist is not sliding (not live) + const accurateTimeOffset = false; // details.PTSKnown || !details.live; + const partIndex = part ? part.index : -1; + const partial = partIndex !== -1; + const chunkMeta = new ChunkMetadata(frag.level, frag.sn, frag.stats.chunkCount, payload.byteLength, partIndex, partial); + transmuxer.push(payload, initSegmentData, audioCodec, '', frag, part, details.totalduration, accurateTimeOffset, chunkMeta, initPTS); + } else { + this.log(`Unknown video PTS for cc ${frag.cc}, waiting for video PTS before demuxing audio frag ${frag.sn} of [${details.startSN} ,${details.endSN}],track ${trackId}`); + const { + cache + } = this.waitingData = this.waitingData || { + frag, + part, + cache: new ChunkCache(), + complete: false + }; + cache.push(new Uint8Array(payload)); + this.waitingVideoCC = this.videoTrackCC; + this.state = State.WAITING_INIT_PTS; } } - onAudioTrackSwitched(event, data) { - const trackId = data.id; - const altAudio = !!this.hls.audioTracks[trackId].url; - if (altAudio) { - const videoBuffer = this.videoBuffer; - // if we switched on alternate audio, ensure that main fragment scheduling is synced with video sourcebuffer buffered - if (videoBuffer && this.mediaBuffer !== videoBuffer) { - this.log('Switching on alternate audio, use video.buffered to schedule main fragment loading'); - this.mediaBuffer = videoBuffer; - } + _handleFragmentLoadComplete(fragLoadedData) { + if (this.waitingData) { + this.waitingData.complete = true; + return; } - this.altAudio = altAudio; - this.tick(); + super._handleFragmentLoadComplete(fragLoadedData); + } + onBufferReset( /* event: Events.BUFFER_RESET */ + ) { + // reset reference to sourcebuffers + this.mediaBuffer = this.videoBuffer = null; + this.loadedmetadata = false; } onBufferCreated(event, data) { - const tracks = data.tracks; - let mediaTrack; - let name; - let alternate = false; - for (const type in tracks) { - const track = tracks[type]; - if (track.id === 'main') { - name = type; - mediaTrack = track; - // keep video source buffer reference - if (type === 'video') { - const videoTrack = tracks[type]; - if (videoTrack) { - this.videoBuffer = videoTrack.buffer; - } - } - } else { - alternate = true; - } + const audioTrack = data.tracks.audio; + if (audioTrack) { + this.mediaBuffer = audioTrack.buffer || null; } - if (alternate && mediaTrack) { - this.log(`Alternate track found, use ${name}.buffered to schedule main fragment loading`); - this.mediaBuffer = mediaTrack.buffer; - } else { - this.mediaBuffer = this.media; + if (data.tracks.video) { + this.videoBuffer = data.tracks.video.buffer || null; } } onFragBuffered(event, data) { @@ -190675,22 +191258,32 @@ class StreamController extends BaseStreamController { frag, part } = data; - if (frag && frag.type !== PlaylistLevelType.MAIN) { + if (frag.type !== PlaylistLevelType.AUDIO) { + if (!this.loadedmetadata && frag.type === PlaylistLevelType.MAIN) { + const bufferable = this.videoBuffer || this.media; + if (bufferable) { + const bufferedTimeRanges = BufferHelper.getBuffered(bufferable); + if (bufferedTimeRanges.length) { + this.loadedmetadata = true; + } + } + } return; } if (this.fragContextChanged(frag)) { // If a level switch was requested while a fragment was buffering, it will emit the FRAG_BUFFERED event upon completion - // Avoid setting state back to IDLE, since that will interfere with a level switch - this.warn(`Fragment ${frag.sn}${part ? ' p: ' + part.index : ''} of level ${frag.level} finished buffering, but was aborted. state: ${this.state}`); - if (this.state === State.PARSED) { - this.state = State.IDLE; - } + // Avoid setting state back to IDLE or concluding the audio switch; otherwise, the switched-to track will not buffer + this.warn(`Fragment ${frag.sn}${part ? ' p: ' + part.index : ''} of level ${frag.level} finished buffering, but was aborted. state: ${this.state}, audioSwitch: ${this.switchingTrack ? this.switchingTrack.name : 'false'}`); return; } - const stats = part ? part.stats : frag.stats; - this.fragLastKbps = Math.round(8 * stats.total / (stats.buffering.end - stats.loading.first)); if (frag.sn !== 'initSegment') { this.fragPrevious = frag; + const track = this.switchingTrack; + if (track) { + this.bufferedTrack = track; + this.switchingTrack = null; + this.hls.trigger(Events.AUDIO_TRACK_SWITCHED, _objectSpread2({}, track)); + } } this.fragBufferedComplete(frag, part); } @@ -190708,22 +191301,28 @@ class StreamController extends BaseStreamController { case ErrorDetails.FRAG_LOAD_TIMEOUT: case ErrorDetails.KEY_LOAD_ERROR: case ErrorDetails.KEY_LOAD_TIMEOUT: - this.onFragmentOrKeyLoadError(PlaylistLevelType.MAIN, data); + this.onFragmentOrKeyLoadError(PlaylistLevelType.AUDIO, data); break; - case ErrorDetails.LEVEL_LOAD_ERROR: - case ErrorDetails.LEVEL_LOAD_TIMEOUT: + case ErrorDetails.AUDIO_TRACK_LOAD_ERROR: + case ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT: case ErrorDetails.LEVEL_PARSING_ERROR: - // in case of non fatal error while loading level, if level controller is not retrying to load level, switch back to IDLE - if (!data.levelRetry && this.state === State.WAITING_LEVEL && ((_data$context = data.context) == null ? void 0 : _data$context.type) === PlaylistContextType.LEVEL) { + // in case of non fatal error while loading track, if not retrying to load track, switch back to IDLE + if (!data.levelRetry && this.state === State.WAITING_TRACK && ((_data$context = data.context) == null ? void 0 : _data$context.type) === PlaylistContextType.AUDIO_TRACK) { this.state = State.IDLE; } break; + case ErrorDetails.BUFFER_APPEND_ERROR: case ErrorDetails.BUFFER_FULL_ERROR: - if (!data.parent || data.parent !== 'main') { + if (!data.parent || data.parent !== 'audio') { + return; + } + if (data.details === ErrorDetails.BUFFER_APPEND_ERROR) { + this.resetLoadingState(); return; } if (this.reduceLengthAndFlushBuffer(data)) { - this.flushMainBuffer(0, Number.POSITIVE_INFINITY); + this.bufferedTrack = null; + super.flushMainBuffer(0, Number.POSITIVE_INFINITY, 'audio'); } break; case ErrorDetails.INTERNAL_EXCEPTION: @@ -190731,115 +191330,32 @@ class StreamController extends BaseStreamController { break; } } - - // Checks the health of the buffer and attempts to resolve playback stalls. - checkBuffer() { - const { - media, - gapController - } = this; - if (!media || !gapController || !media.readyState) { - // Exit early if we don't have media or if the media hasn't buffered anything yet (readyState 0) - return; - } - if (this.loadedmetadata || !BufferHelper.getBuffered(media).length) { - // Resolve gaps using the main buffer, whose ranges are the intersections of the A/V sourcebuffers - const activeFrag = this.state !== State.IDLE ? this.fragCurrent : null; - gapController.poll(this.lastCurrentTime, activeFrag); - } - this.lastCurrentTime = media.currentTime; - } - onFragLoadEmergencyAborted() { - this.state = State.IDLE; - // if loadedmetadata is not set, it means that we are emergency switch down on first frag - // in that case, reset startFragRequested flag - if (!this.loadedmetadata) { - this.startFragRequested = false; - this.nextLoadPosition = this.startPosition; + onBufferFlushing(event, { + type + }) { + if (type !== ElementaryStreamTypes.VIDEO) { + this.flushing = true; } - this.tickImmediate(); } onBufferFlushed(event, { type }) { - if (type !== ElementaryStreamTypes.AUDIO || this.audioOnly && !this.altAudio) { - const mediaBuffer = (type === ElementaryStreamTypes.VIDEO ? this.videoBuffer : this.mediaBuffer) || this.media; - this.afterBufferFlushed(mediaBuffer, type, PlaylistLevelType.MAIN); - } - } - onLevelsUpdated(event, data) { - this.levels = data.levels; - } - swapAudioCodec() { - this.audioCodecSwap = !this.audioCodecSwap; - } - - /** - * Seeks to the set startPosition if not equal to the mediaElement's current time. - */ - seekToStartPos() { - const { - media - } = this; - if (!media) { - return; - } - const currentTime = media.currentTime; - let startPosition = this.startPosition; - // only adjust currentTime if different from startPosition or if startPosition not buffered - // at that stage, there should be only one buffered range, as we reach that code after first fragment has been buffered - if (startPosition >= 0 && currentTime < startPosition) { - if (media.seeking) { - this.log(`could not seek to ${startPosition}, already seeking at ${currentTime}`); - return; - } - const buffered = BufferHelper.getBuffered(media); - const bufferStart = buffered.length ? buffered.start(0) : 0; - const delta = bufferStart - startPosition; - if (delta > 0 && (delta < this.config.maxBufferHole || delta < this.config.maxFragLookUpTolerance)) { - this.log(`adjusting start position by ${delta} to match buffer start`); - startPosition += delta; - this.startPosition = startPosition; + if (type !== ElementaryStreamTypes.VIDEO) { + this.flushing = false; + this.bufferFlushed = true; + if (this.state === State.ENDED) { + this.state = State.IDLE; } - this.log(`seek to target start position ${startPosition} from current time ${currentTime}`); - media.currentTime = startPosition; - } - } - _getAudioCodec(currentLevel) { - let audioCodec = this.config.defaultAudioCodec || currentLevel.audioCodec; - if (this.audioCodecSwap && audioCodec) { - this.log('Swapping audio codec'); - if (audioCodec.indexOf('mp4a.40.5') !== -1) { - audioCodec = 'mp4a.40.2'; - } else { - audioCodec = 'mp4a.40.5'; + const mediaBuffer = this.mediaBuffer || this.media; + if (mediaBuffer) { + this.afterBufferFlushed(mediaBuffer, type, PlaylistLevelType.AUDIO); + this.tick(); } } - return audioCodec; - } - _loadBitrateTestFrag(frag, level) { - frag.bitrateTest = true; - this._doFragLoad(frag, level).then(data => { - const { - hls - } = this; - if (!data || this.fragContextChanged(frag)) { - return; - } - level.fragmentError = 0; - this.state = State.IDLE; - this.startFragRequested = false; - this.bitrateTest = false; - const stats = frag.stats; - // Bitrate tests fragments are neither parsed nor buffered - stats.parsing.start = stats.parsing.end = stats.buffering.start = stats.buffering.end = self.performance.now(); - hls.trigger(Events.FRAG_LOADED, data); - frag.bitrateTest = false; - }); } _handleTransmuxComplete(transmuxResult) { var _id3$samples; - const id = 'main'; + const id = 'audio'; const { hls } = this; @@ -190858,104 +191374,34 @@ class StreamController extends BaseStreamController { level } = context; const { - video, + details + } = level; + const { + audio, text, id3, initSegment } = remuxResult; - const { - details - } = level; - // The audio-stream-controller handles audio buffering if Hls.js is playing an alternate audio track - const audio = this.altAudio ? undefined : remuxResult.audio; // Check if the current fragment has been aborted. We check this by first seeing if we're still playing the current level. // If we are, subsequently check if the currently loading fragment (fragCurrent) has changed. - if (this.fragContextChanged(frag)) { + if (this.fragContextChanged(frag) || !details) { this.fragmentTracker.removeFragment(frag); return; } this.state = State.PARSING; - if (initSegment) { - if (initSegment != null && initSegment.tracks) { - const mapFragment = frag.initSegment || frag; - this._bufferInitSegment(level, initSegment.tracks, mapFragment, chunkMeta); - hls.trigger(Events.FRAG_PARSING_INIT_SEGMENT, { - frag: mapFragment, - id, - tracks: initSegment.tracks - }); - } - - // This would be nice if Number.isFinite acted as a typeguard, but it doesn't. See: https://github.com/Microsoft/TypeScript/issues/10038 - const initPTS = initSegment.initPTS; - const timescale = initSegment.timescale; - if (isFiniteNumber(initPTS)) { - this.initPTS[frag.cc] = { - baseTime: initPTS, - timescale - }; - hls.trigger(Events.INIT_PTS_FOUND, { - frag, - id, - initPTS, - timescale - }); - } + if (this.switchingTrack && audio) { + this.completeAudioSwitch(this.switchingTrack); } - - // Avoid buffering if backtracking this fragment - if (video && details && frag.sn !== 'initSegment') { - const prevFrag = details.fragments[frag.sn - 1 - details.startSN]; - const isFirstFragment = frag.sn === details.startSN; - const isFirstInDiscontinuity = !prevFrag || frag.cc > prevFrag.cc; - if (remuxResult.independent !== false) { - const { - startPTS, - endPTS, - startDTS, - endDTS - } = video; - if (part) { - part.elementaryStreams[video.type] = { - startPTS, - endPTS, - startDTS, - endDTS - }; - } else { - if (video.firstKeyFrame && video.independent && chunkMeta.id === 1 && !isFirstInDiscontinuity) { - this.couldBacktrack = true; - } - if (video.dropped && video.independent) { - // Backtrack if dropped frames create a gap after currentTime - - const bufferInfo = this.getMainFwdBufferInfo(); - const targetBufferTime = (bufferInfo ? bufferInfo.end : this.getLoadPosition()) + this.config.maxBufferHole; - const startTime = video.firstKeyFramePTS ? video.firstKeyFramePTS : startPTS; - if (!isFirstFragment && targetBufferTime < startTime - this.config.maxBufferHole && !isFirstInDiscontinuity) { - this.backtrack(frag); - return; - } else if (isFirstInDiscontinuity) { - // Mark segment with a gap to avoid loop loading - frag.gap = true; - } - // Set video stream start to fragment start so that truncated samples do not distort the timeline, and mark it partial - frag.setElementaryStreamInfo(video.type, frag.start, endPTS, frag.start, endDTS, true); - } - } - frag.setElementaryStreamInfo(video.type, startPTS, endPTS, startDTS, endDTS); - if (this.backtrackFragment) { - this.backtrackFragment = frag; - } - this.bufferFragmentData(video, frag, part, chunkMeta, isFirstFragment || isFirstInDiscontinuity); - } else if (isFirstFragment || isFirstInDiscontinuity) { - // Mark segment with a gap to avoid loop loading - frag.gap = true; - } else { - this.backtrack(frag); - return; - } + if (initSegment != null && initSegment.tracks) { + const mapFragment = frag.initSegment || frag; + this._bufferInitSegment(level, initSegment.tracks, mapFragment, chunkMeta); + hls.trigger(Events.FRAG_PARSING_INIT_SEGMENT, { + frag: mapFragment, + id, + tracks: initSegment.tracks + }); + // Only flush audio from old audio tracks when PTS is known on new audio track } if (audio) { const { @@ -190975,22 +191421,20 @@ class StreamController extends BaseStreamController { frag.setElementaryStreamInfo(ElementaryStreamTypes.AUDIO, startPTS, endPTS, startDTS, endDTS); this.bufferFragmentData(audio, frag, part, chunkMeta); } - if (details && id3 != null && (_id3$samples = id3.samples) != null && _id3$samples.length) { - const emittedID3 = { + if (id3 != null && (_id3$samples = id3.samples) != null && _id3$samples.length) { + const emittedID3 = _extends({ id, frag, - details, - samples: id3.samples - }; + details + }, id3); hls.trigger(Events.FRAG_PARSING_METADATA, emittedID3); } - if (details && text) { - const emittedText = { + if (text) { + const emittedText = _extends({ id, frag, - details, - samples: text.samples - }; + details + }, text); hls.trigger(Events.FRAG_PARSING_USERDATA, emittedText); } } @@ -190998,771 +191442,406 @@ class StreamController extends BaseStreamController { if (this.state !== State.PARSING) { return; } - this.audioOnly = !!tracks.audio && !tracks.video; - - // if audio track is expected to come from audio stream controller, discard any coming from main - if (this.altAudio && !this.audioOnly) { - delete tracks.audio; + // delete any video track found on audio transmuxer + if (tracks.video) { + delete tracks.video; } + // include levelCodec in audio and video tracks - const { - audio, - video, - audiovideo - } = tracks; - if (audio) { - let audioCodec = currentLevel.audioCodec; - const ua = navigator.userAgent.toLowerCase(); - if (this.audioCodecSwitch) { - if (audioCodec) { - if (audioCodec.indexOf('mp4a.40.5') !== -1) { - audioCodec = 'mp4a.40.2'; - } else { - audioCodec = 'mp4a.40.5'; - } - } - // In the case that AAC and HE-AAC audio codecs are signalled in manifest, - // force HE-AAC, as it seems that most browsers prefers it. - // don't force HE-AAC if mono stream, or in Firefox - if (audio.metadata.channelCount !== 1 && ua.indexOf('firefox') === -1) { - audioCodec = 'mp4a.40.5'; - } - } - // HE-AAC is broken on Android, always signal audio codec as AAC even if variant manifest states otherwise - if (ua.indexOf('android') !== -1 && audio.container !== 'audio/mpeg') { - // Exclude mpeg audio - audioCodec = 'mp4a.40.2'; - this.log(`Android: force audio codec to ${audioCodec}`); - } - if (currentLevel.audioCodec && currentLevel.audioCodec !== audioCodec) { - this.log(`Swapping manifest audio codec "${currentLevel.audioCodec}" for "${audioCodec}"`); - } - audio.levelCodec = audioCodec; - audio.id = 'main'; - this.log(`Init audio buffer, container:${audio.container}, codecs[selected/level/parsed]=[${audioCodec || ''}/${currentLevel.audioCodec || ''}/${audio.codec}]`); - } - if (video) { - video.levelCodec = currentLevel.videoCodec; - video.id = 'main'; - this.log(`Init video buffer, container:${video.container}, codecs[level/parsed]=[${currentLevel.videoCodec || ''}/${video.codec}]`); + const track = tracks.audio; + if (!track) { + return; } - if (audiovideo) { - this.log(`Init audiovideo buffer, container:${audiovideo.container}, codecs[level/parsed]=[${currentLevel.attrs.CODECS || ''}/${audiovideo.codec}]`); + track.id = 'audio'; + const variantAudioCodecs = currentLevel.audioCodec; + this.log(`Init audio buffer, container:${track.container}, codecs[level/parsed]=[${variantAudioCodecs}/${track.codec}]`); + // SourceBuffer will use track.levelCodec if defined + if (variantAudioCodecs && variantAudioCodecs.split(',').length === 1) { + track.levelCodec = variantAudioCodecs; } this.hls.trigger(Events.BUFFER_CODECS, tracks); - // loop through tracks that are going to be provided to bufferController - Object.keys(tracks).forEach(trackName => { - const track = tracks[trackName]; - const initSegment = track.initSegment; - if (initSegment != null && initSegment.byteLength) { - this.hls.trigger(Events.BUFFER_APPENDING, { - type: trackName, - data: initSegment, - frag, - part: null, - chunkMeta, - parent: frag.type - }); - } - }); + const initSegment = track.initSegment; + if (initSegment != null && initSegment.byteLength) { + const segment = { + type: 'audio', + frag, + part: null, + chunkMeta, + parent: frag.type, + data: initSegment + }; + this.hls.trigger(Events.BUFFER_APPENDING, segment); + } // trigger handler right now - this.tick(); - } - getMainFwdBufferInfo() { - return this.getFwdBufferInfo(this.mediaBuffer ? this.mediaBuffer : this.media, PlaylistLevelType.MAIN); - } - backtrack(frag) { - this.couldBacktrack = true; - // Causes findFragments to backtrack through fragments to find the keyframe - this.backtrackFragment = frag; - this.resetTransmuxer(); - this.flushBufferGap(frag); - this.fragmentTracker.removeFragment(frag); - this.fragPrevious = null; - this.nextLoadPosition = frag.start; - this.state = State.IDLE; + this.tickImmediate(); } - checkFragmentChanged() { - const video = this.media; - let fragPlayingCurrent = null; - if (video && video.readyState > 1 && video.seeking === false) { - const currentTime = video.currentTime; - /* if video element is in seeked state, currentTime can only increase. - (assuming that playback rate is positive ...) - As sometimes currentTime jumps back to zero after a - media decode error, check this, to avoid seeking back to - wrong position after a media decode error - */ + loadFragment(frag, track, targetBufferTime) { + // only load if fragment is not loaded or if in audio switch + const fragState = this.fragmentTracker.getState(frag); + this.fragCurrent = frag; - if (BufferHelper.isBuffered(video, currentTime)) { - fragPlayingCurrent = this.getAppendedFrag(currentTime); - } else if (BufferHelper.isBuffered(video, currentTime + 0.1)) { - /* ensure that FRAG_CHANGED event is triggered at startup, - when first video frame is displayed and playback is paused. - add a tolerance of 100ms, in case current position is not buffered, - check if current pos+100ms is buffered and use that buffer range - for FRAG_CHANGED event reporting */ - fragPlayingCurrent = this.getAppendedFrag(currentTime + 0.1); - } - if (fragPlayingCurrent) { - this.backtrackFragment = null; - const fragPlaying = this.fragPlaying; - const fragCurrentLevel = fragPlayingCurrent.level; - if (!fragPlaying || fragPlayingCurrent.sn !== fragPlaying.sn || fragPlaying.level !== fragCurrentLevel || fragPlayingCurrent.urlId !== fragPlaying.urlId) { - this.fragPlaying = fragPlayingCurrent; - this.hls.trigger(Events.FRAG_CHANGED, { - frag: fragPlayingCurrent - }); - if (!fragPlaying || fragPlaying.level !== fragCurrentLevel) { - this.hls.trigger(Events.LEVEL_SWITCHED, { - level: fragCurrentLevel - }); - } + // we force a frag loading in audio switch as fragment tracker might not have evicted previous frags in case of quick audio switch + if (this.switchingTrack || fragState === FragmentState.NOT_LOADED || fragState === FragmentState.PARTIAL) { + var _track$details2; + if (frag.sn === 'initSegment') { + this._loadInitSegment(frag, track); + } else if ((_track$details2 = track.details) != null && _track$details2.live && !this.initPTS[frag.cc]) { + this.log(`Waiting for video PTS in continuity counter ${frag.cc} of live stream before loading audio fragment ${frag.sn} of level ${this.trackId}`); + this.state = State.WAITING_INIT_PTS; + const mainDetails = this.mainDetails; + if (mainDetails && mainDetails.fragments[0].start !== track.details.fragments[0].start) { + alignMediaPlaylistByPDT(track.details, mainDetails); } + } else { + this.startFragRequested = true; + super.loadFragment(frag, track, targetBufferTime); } + } else { + this.clearTrackerIfNeeded(frag); } } - get nextLevel() { - const frag = this.nextBufferedFrag; - if (frag) { - return frag.level; - } - return -1; - } - get currentFrag() { - const media = this.media; - if (media) { - return this.fragPlaying || this.getAppendedFrag(media.currentTime); - } - return null; - } - get currentProgramDateTime() { - const media = this.media; - if (media) { - const currentTime = media.currentTime; - const frag = this.currentFrag; - if (frag && isFiniteNumber(currentTime) && isFiniteNumber(frag.programDateTime)) { - const epocMs = frag.programDateTime + (currentTime - frag.start) * 1000; - return new Date(epocMs); - } - } - return null; - } - get currentLevel() { - const frag = this.currentFrag; - if (frag) { - return frag.level; - } - return -1; - } - get nextBufferedFrag() { - const frag = this.currentFrag; - if (frag) { - return this.followingBufferedFrag(frag); - } - return null; - } - get forceStartLoad() { - return this._forceStartLoad; - } -} - -/* - * compute an Exponential Weighted moving average - * - https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average - * - heavily inspired from shaka-player - */ - -class EWMA { - // About half of the estimated value will be from the last |halfLife| samples by weight. - constructor(halfLife, estimate = 0, weight = 0) { - this.halfLife = void 0; - this.alpha_ = void 0; - this.estimate_ = void 0; - this.totalWeight_ = void 0; - this.halfLife = halfLife; - // Larger values of alpha expire historical data more slowly. - this.alpha_ = halfLife ? Math.exp(Math.log(0.5) / halfLife) : 0; - this.estimate_ = estimate; - this.totalWeight_ = weight; - } - sample(weight, value) { - const adjAlpha = Math.pow(this.alpha_, weight); - this.estimate_ = value * (1 - adjAlpha) + adjAlpha * this.estimate_; - this.totalWeight_ += weight; - } - getTotalWeight() { - return this.totalWeight_; - } - getEstimate() { - if (this.alpha_) { - const zeroFactor = 1 - Math.pow(this.alpha_, this.totalWeight_); - if (zeroFactor) { - return this.estimate_ / zeroFactor; - } - } - return this.estimate_; - } -} - -/* - * EWMA Bandwidth Estimator - * - heavily inspired from shaka-player - * Tracks bandwidth samples and estimates available bandwidth. - * Based on the minimum of two exponentially-weighted moving averages with - * different half-lives. - */ - -class EwmaBandWidthEstimator { - constructor(slow, fast, defaultEstimate, defaultTTFB = 100) { - this.defaultEstimate_ = void 0; - this.minWeight_ = void 0; - this.minDelayMs_ = void 0; - this.slow_ = void 0; - this.fast_ = void 0; - this.defaultTTFB_ = void 0; - this.ttfb_ = void 0; - this.defaultEstimate_ = defaultEstimate; - this.minWeight_ = 0.001; - this.minDelayMs_ = 50; - this.slow_ = new EWMA(slow); - this.fast_ = new EWMA(fast); - this.defaultTTFB_ = defaultTTFB; - this.ttfb_ = new EWMA(slow); - } - update(slow, fast) { + flushAudioIfNeeded(switchingTrack) { const { - slow_, - fast_, - ttfb_ + media, + bufferedTrack } = this; - if (slow_.halfLife !== slow) { - this.slow_ = new EWMA(slow, slow_.getEstimate(), slow_.getTotalWeight()); - } - if (fast_.halfLife !== fast) { - this.fast_ = new EWMA(fast, fast_.getEstimate(), fast_.getTotalWeight()); - } - if (ttfb_.halfLife !== slow) { - this.ttfb_ = new EWMA(slow, ttfb_.getEstimate(), ttfb_.getTotalWeight()); - } - } - sample(durationMs, numBytes) { - durationMs = Math.max(durationMs, this.minDelayMs_); - const numBits = 8 * numBytes; - // weight is duration in seconds - const durationS = durationMs / 1000; - // value is bandwidth in bits/s - const bandwidthInBps = numBits / durationS; - this.fast_.sample(durationS, bandwidthInBps); - this.slow_.sample(durationS, bandwidthInBps); - } - sampleTTFB(ttfb) { - // weight is frequency curve applied to TTFB in seconds - // (longer times have less weight with expected input under 1 second) - const seconds = ttfb / 1000; - const weight = Math.sqrt(2) * Math.exp(-Math.pow(seconds, 2) / 2); - this.ttfb_.sample(weight, Math.max(ttfb, 5)); - } - canEstimate() { - return this.fast_.getTotalWeight() >= this.minWeight_; - } - getEstimate() { - if (this.canEstimate()) { - // console.log('slow estimate:'+ Math.round(this.slow_.getEstimate())); - // console.log('fast estimate:'+ Math.round(this.fast_.getEstimate())); - // Take the minimum of these two estimates. This should have the effect of - // adapting down quickly, but up more slowly. - return Math.min(this.fast_.getEstimate(), this.slow_.getEstimate()); - } else { - return this.defaultEstimate_; + const bufferedAttributes = bufferedTrack == null ? void 0 : bufferedTrack.attrs; + const switchAttributes = switchingTrack.attrs; + if (media && bufferedAttributes && (bufferedAttributes.CHANNELS !== switchAttributes.CHANNELS || bufferedTrack.name !== switchingTrack.name || bufferedTrack.lang !== switchingTrack.lang)) { + this.log('Switching audio track : flushing all audio'); + super.flushMainBuffer(0, Number.POSITIVE_INFINITY, 'audio'); + this.bufferedTrack = null; } } - getEstimateTTFB() { - if (this.ttfb_.getTotalWeight() >= this.minWeight_) { - return this.ttfb_.getEstimate(); - } else { - return this.defaultTTFB_; - } + completeAudioSwitch(switchingTrack) { + const { + hls + } = this; + this.flushAudioIfNeeded(switchingTrack); + this.bufferedTrack = switchingTrack; + this.switchingTrack = null; + hls.trigger(Events.AUDIO_TRACK_SWITCHED, _objectSpread2({}, switchingTrack)); } - destroy() {} } -class AbrController { +class AudioTrackController extends BasePlaylistController { constructor(hls) { - this.hls = void 0; - this.lastLevelLoadSec = 0; - this.lastLoadedFragLevel = 0; - this._nextAutoLevel = -1; - this.timer = -1; - this.onCheck = this._abandonRulesCheck.bind(this); - this.fragCurrent = null; - this.partCurrent = null; - this.bitrateTestDelay = 0; - this.bwEstimator = void 0; - this.hls = hls; - const config = hls.config; - this.bwEstimator = new EwmaBandWidthEstimator(config.abrEwmaSlowVoD, config.abrEwmaFastVoD, config.abrEwmaDefaultEstimate); + super(hls, '[audio-track-controller]'); + this.tracks = []; + this.groupIds = null; + this.tracksInGroup = []; + this.trackId = -1; + this.currentTrack = null; + this.selectDefaultTrack = true; this.registerListeners(); } registerListeners() { const { hls } = this; - hls.on(Events.FRAG_LOADING, this.onFragLoading, this); - hls.on(Events.FRAG_LOADED, this.onFragLoaded, this); - hls.on(Events.FRAG_BUFFERED, this.onFragBuffered, this); + hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this); + hls.on(Events.MANIFEST_PARSED, this.onManifestParsed, this); + hls.on(Events.LEVEL_LOADING, this.onLevelLoading, this); hls.on(Events.LEVEL_SWITCHING, this.onLevelSwitching, this); - hls.on(Events.LEVEL_LOADED, this.onLevelLoaded, this); + hls.on(Events.AUDIO_TRACK_LOADED, this.onAudioTrackLoaded, this); + hls.on(Events.ERROR, this.onError, this); } unregisterListeners() { const { hls } = this; - hls.off(Events.FRAG_LOADING, this.onFragLoading, this); - hls.off(Events.FRAG_LOADED, this.onFragLoaded, this); - hls.off(Events.FRAG_BUFFERED, this.onFragBuffered, this); + hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this); + hls.off(Events.MANIFEST_PARSED, this.onManifestParsed, this); + hls.off(Events.LEVEL_LOADING, this.onLevelLoading, this); hls.off(Events.LEVEL_SWITCHING, this.onLevelSwitching, this); - hls.off(Events.LEVEL_LOADED, this.onLevelLoaded, this); + hls.off(Events.AUDIO_TRACK_LOADED, this.onAudioTrackLoaded, this); + hls.off(Events.ERROR, this.onError, this); } destroy() { this.unregisterListeners(); - this.clearTimer(); - // @ts-ignore - this.hls = this.onCheck = null; - this.fragCurrent = this.partCurrent = null; - } - onFragLoading(event, data) { - var _data$part; - const frag = data.frag; - if (this.ignoreFragment(frag)) { - return; - } - this.fragCurrent = frag; - this.partCurrent = (_data$part = data.part) != null ? _data$part : null; - this.clearTimer(); - this.timer = self.setInterval(this.onCheck, 100); - } - onLevelSwitching(event, data) { - this.clearTimer(); + this.tracks.length = 0; + this.tracksInGroup.length = 0; + this.currentTrack = null; + super.destroy(); } - getTimeToLoadFrag(timeToFirstByteSec, bandwidth, fragSizeBits, isSwitch) { - const fragLoadSec = timeToFirstByteSec + fragSizeBits / bandwidth; - const playlistLoadSec = isSwitch ? this.lastLevelLoadSec : 0; - return fragLoadSec + playlistLoadSec; + onManifestLoading() { + this.tracks = []; + this.tracksInGroup = []; + this.groupIds = null; + this.currentTrack = null; + this.trackId = -1; + this.selectDefaultTrack = true; } - onLevelLoaded(event, data) { - const config = this.hls.config; - const { - total, - bwEstimate - } = data.stats; - // Total is the bytelength and bwEstimate in bits/sec - if (isFiniteNumber(total) && isFiniteNumber(bwEstimate)) { - this.lastLevelLoadSec = 8 * total / bwEstimate; - } - if (data.details.live) { - this.bwEstimator.update(config.abrEwmaSlowLive, config.abrEwmaFastLive); - } else { - this.bwEstimator.update(config.abrEwmaSlowVoD, config.abrEwmaFastVoD); - } + onManifestParsed(event, data) { + this.tracks = data.audioTracks || []; } - - /* - This method monitors the download rate of the current fragment, and will downswitch if that fragment will not load - quickly enough to prevent underbuffering - */ - _abandonRulesCheck() { - const { - fragCurrent: frag, - partCurrent: part, - hls - } = this; + onAudioTrackLoaded(event, data) { const { - autoLevelEnabled, - media - } = hls; - if (!frag || !media) { - return; - } - const now = performance.now(); - const stats = part ? part.stats : frag.stats; - const duration = part ? part.duration : frag.duration; - const timeLoading = now - stats.loading.start; - // If frag loading is aborted, complete, or from lowest level, stop timer and return - if (stats.aborted || stats.loaded && stats.loaded === stats.total || frag.level === 0) { - this.clearTimer(); - // reset forced auto level value so that next level will be selected - this._nextAutoLevel = -1; + id, + groupId, + details + } = data; + const trackInActiveGroup = this.tracksInGroup[id]; + if (!trackInActiveGroup || trackInActiveGroup.groupId !== groupId) { + this.warn(`Audio track with id:${id} and group:${groupId} not found in active group ${trackInActiveGroup == null ? void 0 : trackInActiveGroup.groupId}`); return; } - - // This check only runs if we're in ABR mode and actually playing - if (!autoLevelEnabled || media.paused || !media.playbackRate || !media.readyState) { - return; + const curDetails = trackInActiveGroup.details; + trackInActiveGroup.details = data.details; + this.log(`Audio track ${id} "${trackInActiveGroup.name}" lang:${trackInActiveGroup.lang} group:${groupId} loaded [${details.startSN}-${details.endSN}]`); + if (id === this.trackId) { + this.playlistLoaded(id, data, curDetails); } - const bufferInfo = hls.mainForwardBufferInfo; - if (bufferInfo === null) { + } + onLevelLoading(event, data) { + this.switchLevel(data.level); + } + onLevelSwitching(event, data) { + this.switchLevel(data.level); + } + switchLevel(levelIndex) { + const levelInfo = this.hls.levels[levelIndex]; + if (!levelInfo) { return; } - const ttfbEstimate = this.bwEstimator.getEstimateTTFB(); - const playbackRate = Math.abs(media.playbackRate); - // To maintain stable adaptive playback, only begin monitoring frag loading after half or more of its playback duration has passed - if (timeLoading <= Math.max(ttfbEstimate, 1000 * (duration / (playbackRate * 2)))) { - return; + const audioGroups = levelInfo.audioGroups || null; + const currentGroups = this.groupIds; + let currentTrack = this.currentTrack; + if (!audioGroups || (currentGroups == null ? void 0 : currentGroups.length) !== (audioGroups == null ? void 0 : audioGroups.length) || audioGroups != null && audioGroups.some(groupId => (currentGroups == null ? void 0 : currentGroups.indexOf(groupId)) === -1)) { + this.groupIds = audioGroups; + this.trackId = -1; + this.currentTrack = null; + const audioTracks = this.tracks.filter(track => !audioGroups || audioGroups.indexOf(track.groupId) !== -1); + if (audioTracks.length) { + // Disable selectDefaultTrack if there are no default tracks + if (this.selectDefaultTrack && !audioTracks.some(track => track.default)) { + this.selectDefaultTrack = false; + } + // track.id should match hls.audioTracks index + audioTracks.forEach((track, i) => { + track.id = i; + }); + } else if (!currentTrack && !this.tracksInGroup.length) { + // Do not dispatch AUDIO_TRACKS_UPDATED when there were and are no tracks + return; + } + if (!currentTrack) { + currentTrack = this.setAudioOption(this.hls.config.audioPreference); + } + this.tracksInGroup = audioTracks; + let trackId = this.findTrackId(currentTrack); + if (trackId === -1 && currentTrack) { + trackId = this.findTrackId(null); + } + const audioTracksUpdated = { + audioTracks + }; + this.log(`Updating audio tracks, ${audioTracks.length} track(s) found in group(s): ${audioGroups == null ? void 0 : audioGroups.join(',')}`); + this.hls.trigger(Events.AUDIO_TRACKS_UPDATED, audioTracksUpdated); + const selectedTrackId = this.trackId; + if (trackId !== -1 && selectedTrackId === -1) { + this.setAudioTrack(trackId); + } else if (audioTracks.length && selectedTrackId === -1) { + var _this$groupIds; + const error = new Error(`No audio track selected for current audio group-ID(s): ${(_this$groupIds = this.groupIds) == null ? void 0 : _this$groupIds.join(',')} track count: ${audioTracks.length}`); + this.warn(error.message); + this.hls.trigger(Events.ERROR, { + type: ErrorTypes.MEDIA_ERROR, + details: ErrorDetails.AUDIO_TRACK_LOAD_ERROR, + fatal: true, + error + }); + } + } else if (this.shouldReloadPlaylist(currentTrack)) { + // Retry playlist loading if no playlist is or has been loaded yet + this.setAudioTrack(this.trackId); } - - // bufferStarvationDelay is an estimate of the amount time (in seconds) it will take to exhaust the buffer - const bufferStarvationDelay = bufferInfo.len / playbackRate; - // Only downswitch if less than 2 fragment lengths are buffered - if (bufferStarvationDelay >= 2 * duration / playbackRate) { + } + onError(event, data) { + if (data.fatal || !data.context) { return; } - const ttfb = stats.loading.first ? stats.loading.first - stats.loading.start : -1; - const loadedFirstByte = stats.loaded && ttfb > -1; - const bwEstimate = this.bwEstimator.getEstimate(); - const { - levels, - minAutoLevel - } = hls; - const level = levels[frag.level]; - const expectedLen = stats.total || Math.max(stats.loaded, Math.round(duration * level.maxBitrate / 8)); - let timeStreaming = timeLoading - ttfb; - if (timeStreaming < 1 && loadedFirstByte) { - timeStreaming = Math.min(timeLoading, stats.loaded * 8 / bwEstimate); - } - const loadRate = loadedFirstByte ? stats.loaded * 1000 / timeStreaming : 0; - // fragLoadDelay is an estimate of the time (in seconds) it will take to buffer the remainder of the fragment - const fragLoadedDelay = loadRate ? (expectedLen - stats.loaded) / loadRate : expectedLen * 8 / bwEstimate + ttfbEstimate / 1000; - // Only downswitch if the time to finish loading the current fragment is greater than the amount of buffer left - if (fragLoadedDelay <= bufferStarvationDelay) { - return; + if (data.context.type === PlaylistContextType.AUDIO_TRACK && data.context.id === this.trackId && (!this.groupIds || this.groupIds.indexOf(data.context.groupId) !== -1)) { + this.requestScheduled = -1; + this.checkRetry(data); } - const bwe = loadRate ? loadRate * 8 : bwEstimate; - let fragLevelNextLoadedDelay = Number.POSITIVE_INFINITY; - let nextLoadLevel; - // Iterate through lower level and try to find the largest one that avoids rebuffering - for (nextLoadLevel = frag.level - 1; nextLoadLevel > minAutoLevel; nextLoadLevel--) { - // compute time to load next fragment at lower level - // 8 = bits per byte (bps/Bps) - const levelNextBitrate = levels[nextLoadLevel].maxBitrate; - fragLevelNextLoadedDelay = this.getTimeToLoadFrag(ttfbEstimate / 1000, bwe, duration * levelNextBitrate, !levels[nextLoadLevel].details); - if (fragLevelNextLoadedDelay < bufferStarvationDelay) { - break; + } + get allAudioTracks() { + return this.tracks; + } + get audioTracks() { + return this.tracksInGroup; + } + get audioTrack() { + return this.trackId; + } + set audioTrack(newId) { + // If audio track is selected from API then don't choose from the manifest default track + this.selectDefaultTrack = false; + this.setAudioTrack(newId); + } + setAudioOption(audioOption) { + const hls = this.hls; + hls.config.audioPreference = audioOption; + if (audioOption) { + const allAudioTracks = this.allAudioTracks; + this.selectDefaultTrack = false; + if (allAudioTracks.length) { + // First see if current option matches (no switch op) + const currentTrack = this.currentTrack; + if (currentTrack && matchesOption(audioOption, currentTrack, audioMatchPredicate)) { + return currentTrack; + } + // Find option in available tracks (tracksInGroup) + const groupIndex = findMatchingOption(audioOption, this.tracksInGroup, audioMatchPredicate); + if (groupIndex > -1) { + const track = this.tracksInGroup[groupIndex]; + this.setAudioTrack(groupIndex); + return track; + } else if (currentTrack) { + // Find option in nearest level audio group + let searchIndex = hls.loadLevel; + if (searchIndex === -1) { + searchIndex = hls.firstAutoLevel; + } + const switchIndex = findClosestLevelWithAudioGroup(audioOption, hls.levels, allAudioTracks, searchIndex, audioMatchPredicate); + if (switchIndex === -1) { + // could not find matching variant + return null; + } + // and switch level to acheive the audio group switch + hls.nextLoadLevel = switchIndex; + } + if (audioOption.channels || audioOption.audioCodec) { + // Could not find a match with codec / channels predicate + // Find a match without channels or codec + const withoutCodecAndChannelsMatch = findMatchingOption(audioOption, allAudioTracks); + if (withoutCodecAndChannelsMatch > -1) { + return allAudioTracks[withoutCodecAndChannelsMatch]; + } + } } } - // Only emergency switch down if it takes less time to load a new fragment at lowest level instead of continuing - // to load the current one - if (fragLevelNextLoadedDelay >= fragLoadedDelay) { - return; - } + return null; + } + setAudioTrack(newId) { + const tracks = this.tracksInGroup; - // if estimated load time of new segment is completely unreasonable, ignore and do not emergency switch down - if (fragLevelNextLoadedDelay > duration * 10) { + // check if level idx is valid + if (newId < 0 || newId >= tracks.length) { + this.warn(`Invalid audio track id: ${newId}`); return; } - hls.nextLoadLevel = nextLoadLevel; - if (loadedFirstByte) { - // If there has been loading progress, sample bandwidth using loading time offset by minimum TTFB time - this.bwEstimator.sample(timeLoading - Math.min(ttfbEstimate, ttfb), stats.loaded); - } else { - // If there has been no loading progress, sample TTFB - this.bwEstimator.sampleTTFB(timeLoading); - } + + // stopping live reloading timer if any this.clearTimer(); - logger.warn(`[abr] Fragment ${frag.sn}${part ? ' part ' + part.index : ''} of level ${frag.level} is loading too slowly; - Time to underbuffer: ${bufferStarvationDelay.toFixed(3)} s - Estimated load time for current fragment: ${fragLoadedDelay.toFixed(3)} s - Estimated load time for down switch fragment: ${fragLevelNextLoadedDelay.toFixed(3)} s - TTFB estimate: ${ttfb} - Current BW estimate: ${isFiniteNumber(bwEstimate) ? (bwEstimate / 1024).toFixed(3) : 'Unknown'} Kb/s - New BW estimate: ${(this.bwEstimator.getEstimate() / 1024).toFixed(3)} Kb/s - Aborting and switching to level ${nextLoadLevel}`); - if (frag.loader) { - this.fragCurrent = this.partCurrent = null; - frag.abortRequests(); - } - hls.trigger(Events.FRAG_LOAD_EMERGENCY_ABORTED, { - frag, - part, - stats - }); - } - onFragLoaded(event, { - frag, - part - }) { - const stats = part ? part.stats : frag.stats; - if (frag.type === PlaylistLevelType.MAIN) { - this.bwEstimator.sampleTTFB(stats.loading.first - stats.loading.start); - } - if (this.ignoreFragment(frag)) { + this.selectDefaultTrack = false; + const lastTrack = this.currentTrack; + const track = tracks[newId]; + const trackLoaded = track.details && !track.details.live; + if (newId === this.trackId && track === lastTrack && trackLoaded) { return; } - // stop monitoring bw once frag loaded - this.clearTimer(); - // store level id after successful fragment load - this.lastLoadedFragLevel = frag.level; - // reset forced auto level value so that next level will be selected - this._nextAutoLevel = -1; - - // compute level average bitrate - if (this.hls.config.abrMaxWithRealBitrate) { - const duration = part ? part.duration : frag.duration; - const level = this.hls.levels[frag.level]; - const loadedBytes = (level.loaded ? level.loaded.bytes : 0) + stats.loaded; - const loadedDuration = (level.loaded ? level.loaded.duration : 0) + duration; - level.loaded = { - bytes: loadedBytes, - duration: loadedDuration - }; - level.realBitrate = Math.round(8 * loadedBytes / loadedDuration); - } - if (frag.bitrateTest) { - const fragBufferedData = { - stats, - frag, - part, - id: frag.type - }; - this.onFragBuffered(Events.FRAG_BUFFERED, fragBufferedData); - frag.bitrateTest = false; - } - } - onFragBuffered(event, data) { - const { - frag, - part - } = data; - const stats = part != null && part.stats.loaded ? part.stats : frag.stats; - if (stats.aborted) { + this.log(`Switching to audio-track ${newId} "${track.name}" lang:${track.lang} group:${track.groupId} channels:${track.channels}`); + this.trackId = newId; + this.currentTrack = track; + this.hls.trigger(Events.AUDIO_TRACK_SWITCHING, _objectSpread2({}, track)); + // Do not reload track unless live + if (trackLoaded) { return; } - if (this.ignoreFragment(frag)) { - return; + const hlsUrlParameters = this.switchParams(track.url, lastTrack == null ? void 0 : lastTrack.details); + this.loadPlaylist(hlsUrlParameters); + } + findTrackId(currentTrack) { + const audioTracks = this.tracksInGroup; + for (let i = 0; i < audioTracks.length; i++) { + const track = audioTracks[i]; + if (this.selectDefaultTrack && !track.default) { + continue; + } + if (!currentTrack || matchesOption(currentTrack, track, audioMatchPredicate)) { + return i; + } } - // Use the difference between parsing and request instead of buffering and request to compute fragLoadingProcessing; - // rationale is that buffer appending only happens once media is attached. This can happen when config.startFragPrefetch - // is used. If we used buffering in that case, our BW estimate sample will be very large. - const processingMs = stats.parsing.end - stats.loading.start - Math.min(stats.loading.first - stats.loading.start, this.bwEstimator.getEstimateTTFB()); - this.bwEstimator.sample(processingMs, stats.loaded); - stats.bwEstimate = this.bwEstimator.getEstimate(); - if (frag.bitrateTest) { - this.bitrateTestDelay = processingMs / 1000; - } else { - this.bitrateTestDelay = 0; + if (currentTrack) { + const { + name, + lang, + assocLang, + characteristics, + audioCodec, + channels + } = currentTrack; + for (let i = 0; i < audioTracks.length; i++) { + const track = audioTracks[i]; + if (matchesOption({ + name, + lang, + assocLang, + characteristics, + audioCodec, + channels + }, track, audioMatchPredicate)) { + return i; + } + } + for (let i = 0; i < audioTracks.length; i++) { + const track = audioTracks[i]; + if (mediaAttributesIdentical(currentTrack.attrs, track.attrs, ['LANGUAGE', 'ASSOC-LANGUAGE', 'CHARACTERISTICS'])) { + return i; + } + } + for (let i = 0; i < audioTracks.length; i++) { + const track = audioTracks[i]; + if (mediaAttributesIdentical(currentTrack.attrs, track.attrs, ['LANGUAGE'])) { + return i; + } + } } + return -1; } - ignoreFragment(frag) { - // Only count non-alt-audio frags which were actually buffered in our BW calculations - return frag.type !== PlaylistLevelType.MAIN || frag.sn === 'initSegment'; - } - clearTimer() { - self.clearInterval(this.timer); - } - - // return next auto level - get nextAutoLevel() { - const forcedAutoLevel = this._nextAutoLevel; - const bwEstimator = this.bwEstimator; - // in case next auto level has been forced, and bw not available or not reliable, return forced value - if (forcedAutoLevel !== -1 && !bwEstimator.canEstimate()) { - return forcedAutoLevel; - } - - // compute next level using ABR logic - let nextABRAutoLevel = this.getNextABRAutoLevel(); - // use forced auto level when ABR selected level has errored - if (forcedAutoLevel !== -1) { - const levels = this.hls.levels; - if (levels.length > Math.max(forcedAutoLevel, nextABRAutoLevel) && levels[forcedAutoLevel].loadError <= levels[nextABRAutoLevel].loadError) { - return forcedAutoLevel; - } - } - // if forced auto level has been defined, use it to cap ABR computed quality level - if (forcedAutoLevel !== -1) { - nextABRAutoLevel = Math.min(forcedAutoLevel, nextABRAutoLevel); - } - return nextABRAutoLevel; - } - getNextABRAutoLevel() { - const { - fragCurrent, - partCurrent, - hls - } = this; - const { - maxAutoLevel, - config, - minAutoLevel, - media - } = hls; - const currentFragDuration = partCurrent ? partCurrent.duration : fragCurrent ? fragCurrent.duration : 0; - - // playbackRate is the absolute value of the playback rate; if media.playbackRate is 0, we use 1 to load as - // if we're playing back at the normal rate. - const playbackRate = media && media.playbackRate !== 0 ? Math.abs(media.playbackRate) : 1.0; - const avgbw = this.bwEstimator ? this.bwEstimator.getEstimate() : config.abrEwmaDefaultEstimate; - // bufferStarvationDelay is the wall-clock time left until the playback buffer is exhausted. - const bufferInfo = hls.mainForwardBufferInfo; - const bufferStarvationDelay = (bufferInfo ? bufferInfo.len : 0) / playbackRate; - - // First, look to see if we can find a level matching with our avg bandwidth AND that could also guarantee no rebuffering at all - let bestLevel = this.findBestLevel(avgbw, minAutoLevel, maxAutoLevel, bufferStarvationDelay, config.abrBandWidthFactor, config.abrBandWidthUpFactor); - if (bestLevel >= 0) { - return bestLevel; - } - logger.trace(`[abr] ${bufferStarvationDelay ? 'rebuffering expected' : 'buffer is empty'}, finding optimal quality level`); - // not possible to get rid of rebuffering ... let's try to find level that will guarantee less than maxStarvationDelay of rebuffering - // if no matching level found, logic will return 0 - let maxStarvationDelay = currentFragDuration ? Math.min(currentFragDuration, config.maxStarvationDelay) : config.maxStarvationDelay; - let bwFactor = config.abrBandWidthFactor; - let bwUpFactor = config.abrBandWidthUpFactor; - if (!bufferStarvationDelay) { - // in case buffer is empty, let's check if previous fragment was loaded to perform a bitrate test - const bitrateTestDelay = this.bitrateTestDelay; - if (bitrateTestDelay) { - // if it is the case, then we need to adjust our max starvation delay using maxLoadingDelay config value - // max video loading delay used in automatic start level selection : - // in that mode ABR controller will ensure that video loading time (ie the time to fetch the first fragment at lowest quality level + - // the time to fetch the fragment at the appropriate quality level is less than ```maxLoadingDelay``` ) - // cap maxLoadingDelay and ensure it is not bigger 'than bitrate test' frag duration - const maxLoadingDelay = currentFragDuration ? Math.min(currentFragDuration, config.maxLoadingDelay) : config.maxLoadingDelay; - maxStarvationDelay = maxLoadingDelay - bitrateTestDelay; - logger.trace(`[abr] bitrate test took ${Math.round(1000 * bitrateTestDelay)}ms, set first fragment max fetchDuration to ${Math.round(1000 * maxStarvationDelay)} ms`); - // don't use conservative factor on bitrate test - bwFactor = bwUpFactor = 1; - } - } - bestLevel = this.findBestLevel(avgbw, minAutoLevel, maxAutoLevel, bufferStarvationDelay + maxStarvationDelay, bwFactor, bwUpFactor); - return Math.max(bestLevel, 0); - } - findBestLevel(currentBw, minAutoLevel, maxAutoLevel, maxFetchDuration, bwFactor, bwUpFactor) { - var _level$details; - const { - fragCurrent, - partCurrent, - lastLoadedFragLevel: currentLevel - } = this; - const { - levels - } = this.hls; - const level = levels[currentLevel]; - const live = !!(level != null && (_level$details = level.details) != null && _level$details.live); - const currentCodecSet = level == null ? void 0 : level.codecSet; - const currentFragDuration = partCurrent ? partCurrent.duration : fragCurrent ? fragCurrent.duration : 0; - const ttfbEstimateSec = this.bwEstimator.getEstimateTTFB() / 1000; - let levelSkippedMin = minAutoLevel; - let levelSkippedMax = -1; - for (let i = maxAutoLevel; i >= minAutoLevel; i--) { - const levelInfo = levels[i]; - if (!levelInfo || currentCodecSet && levelInfo.codecSet !== currentCodecSet) { - if (levelInfo) { - levelSkippedMin = Math.min(i, levelSkippedMin); - levelSkippedMax = Math.max(i, levelSkippedMax); + loadPlaylist(hlsUrlParameters) { + const audioTrack = this.currentTrack; + if (this.shouldLoadPlaylist(audioTrack) && audioTrack) { + super.loadPlaylist(); + const id = audioTrack.id; + const groupId = audioTrack.groupId; + let url = audioTrack.url; + if (hlsUrlParameters) { + try { + url = hlsUrlParameters.addDirectives(url); + } catch (error) { + this.warn(`Could not construct new URL with HLS Delivery Directives: ${error}`); } - continue; - } - if (levelSkippedMax !== -1) { - logger.trace(`[abr] Skipped level(s) ${levelSkippedMin}-${levelSkippedMax} with CODECS:"${levels[levelSkippedMax].attrs.CODECS}"; not compatible with "${level.attrs.CODECS}"`); - } - const levelDetails = levelInfo.details; - const avgDuration = (partCurrent ? levelDetails == null ? void 0 : levelDetails.partTarget : levelDetails == null ? void 0 : levelDetails.averagetargetduration) || currentFragDuration; - let adjustedbw; - // follow algorithm captured from stagefright : - // https://android.googlesource.com/platform/frameworks/av/+/master/media/libstagefright/httplive/LiveSession.cpp - // Pick the highest bandwidth stream below or equal to estimated bandwidth. - // consider only 80% of the available bandwidth, but if we are switching up, - // be even more conservative (70%) to avoid overestimating and immediately - // switching back. - if (i <= currentLevel) { - adjustedbw = bwFactor * currentBw; - } else { - adjustedbw = bwUpFactor * currentBw; - } - const bitrate = levels[i].maxBitrate; - const fetchDuration = this.getTimeToLoadFrag(ttfbEstimateSec, adjustedbw, bitrate * avgDuration, levelDetails === undefined); - logger.trace(`[abr] level:${i} adjustedbw-bitrate:${Math.round(adjustedbw - bitrate)} avgDuration:${avgDuration.toFixed(1)} maxFetchDuration:${maxFetchDuration.toFixed(1)} fetchDuration:${fetchDuration.toFixed(1)}`); - // if adjusted bw is greater than level bitrate AND - if (adjustedbw > bitrate && ( - // fragment fetchDuration unknown OR live stream OR fragment fetchDuration less than max allowed fetch duration, then this level matches - // we don't account for max Fetch Duration for live streams, this is to avoid switching down when near the edge of live sliding window ... - // special case to support startLevel = -1 (bitrateTest) on live streams : in that case we should not exit loop so that findBestLevel will return -1 - fetchDuration === 0 || !isFiniteNumber(fetchDuration) || live && !this.bitrateTestDelay || fetchDuration < maxFetchDuration)) { - // as we are looping from highest to lowest, this will return the best achievable quality level - return i; } + // track not retrieved yet, or live playlist we need to (re)load it + this.log(`loading audio-track playlist ${id} "${audioTrack.name}" lang:${audioTrack.lang} group:${groupId}`); + this.clearTimer(); + this.hls.trigger(Events.AUDIO_TRACK_LOADING, { + url, + id, + groupId, + deliveryDirectives: hlsUrlParameters || null + }); } - // not enough time budget even with quality level 0 ... rebuffering might happen - return -1; - } - set nextAutoLevel(nextLevel) { - this._nextAutoLevel = nextLevel; - } -} - -class ChunkCache { - constructor() { - this.chunks = []; - this.dataLength = 0; - } - push(chunk) { - this.chunks.push(chunk); - this.dataLength += chunk.length; - } - flush() { - const { - chunks, - dataLength - } = this; - let result; - if (!chunks.length) { - return new Uint8Array(0); - } else if (chunks.length === 1) { - result = chunks[0]; - } else { - result = concatUint8Arrays(chunks, dataLength); - } - this.reset(); - return result; - } - reset() { - this.chunks.length = 0; - this.dataLength = 0; - } -} -function concatUint8Arrays(chunks, dataLength) { - const result = new Uint8Array(dataLength); - let offset = 0; - for (let i = 0; i < chunks.length; i++) { - const chunk = chunks[i]; - result.set(chunk, offset); - offset += chunk.length; } - return result; } -const TICK_INTERVAL$1 = 100; // how often to tick in ms +const TICK_INTERVAL$1 = 500; // how often to tick in ms -class AudioStreamController extends BaseStreamController { +class SubtitleStreamController extends BaseStreamController { constructor(hls, fragmentTracker, keyLoader) { - super(hls, fragmentTracker, keyLoader, '[audio-stream-controller]', PlaylistLevelType.AUDIO); - this.videoBuffer = null; - this.videoTrackCC = -1; - this.waitingVideoCC = -1; - this.bufferedTrack = null; - this.switchingTrack = null; - this.trackId = -1; - this.waitingData = null; + super(hls, fragmentTracker, keyLoader, '[subtitle-stream-controller]', PlaylistLevelType.SUBTITLE); + this.currentTrackId = -1; + this.tracksBuffered = []; this.mainDetails = null; - this.bufferFlushed = false; - this.cachedTrackLoadedData = null; this._registerListeners(); } onHandlerDestroying() { this._unregisterListeners(); + super.onHandlerDestroying(); this.mainDetails = null; - this.bufferedTrack = null; - this.switchingTrack = null; } _registerListeners() { const { @@ -191772,14 +191851,12 @@ class AudioStreamController extends BaseStreamController { hls.on(Events.MEDIA_DETACHING, this.onMediaDetaching, this); hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this); hls.on(Events.LEVEL_LOADED, this.onLevelLoaded, this); - hls.on(Events.AUDIO_TRACKS_UPDATED, this.onAudioTracksUpdated, this); - hls.on(Events.AUDIO_TRACK_SWITCHING, this.onAudioTrackSwitching, this); - hls.on(Events.AUDIO_TRACK_LOADED, this.onAudioTrackLoaded, this); hls.on(Events.ERROR, this.onError, this); - hls.on(Events.BUFFER_RESET, this.onBufferReset, this); - hls.on(Events.BUFFER_CREATED, this.onBufferCreated, this); - hls.on(Events.BUFFER_FLUSHED, this.onBufferFlushed, this); - hls.on(Events.INIT_PTS_FOUND, this.onInitPtsFound, this); + hls.on(Events.SUBTITLE_TRACKS_UPDATED, this.onSubtitleTracksUpdated, this); + hls.on(Events.SUBTITLE_TRACK_SWITCH, this.onSubtitleTrackSwitch, this); + hls.on(Events.SUBTITLE_TRACK_LOADED, this.onSubtitleTrackLoaded, this); + hls.on(Events.SUBTITLE_FRAG_PROCESSED, this.onSubtitleFragProcessed, this); + hls.on(Events.BUFFER_FLUSHING, this.onBufferFlushing, this); hls.on(Events.FRAG_BUFFERED, this.onFragBuffered, this); } _unregisterListeners() { @@ -191790,335 +191867,162 @@ class AudioStreamController extends BaseStreamController { hls.off(Events.MEDIA_DETACHING, this.onMediaDetaching, this); hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this); hls.off(Events.LEVEL_LOADED, this.onLevelLoaded, this); - hls.off(Events.AUDIO_TRACKS_UPDATED, this.onAudioTracksUpdated, this); - hls.off(Events.AUDIO_TRACK_SWITCHING, this.onAudioTrackSwitching, this); - hls.off(Events.AUDIO_TRACK_LOADED, this.onAudioTrackLoaded, this); hls.off(Events.ERROR, this.onError, this); - hls.off(Events.BUFFER_RESET, this.onBufferReset, this); - hls.off(Events.BUFFER_CREATED, this.onBufferCreated, this); - hls.off(Events.BUFFER_FLUSHED, this.onBufferFlushed, this); - hls.off(Events.INIT_PTS_FOUND, this.onInitPtsFound, this); + hls.off(Events.SUBTITLE_TRACKS_UPDATED, this.onSubtitleTracksUpdated, this); + hls.off(Events.SUBTITLE_TRACK_SWITCH, this.onSubtitleTrackSwitch, this); + hls.off(Events.SUBTITLE_TRACK_LOADED, this.onSubtitleTrackLoaded, this); + hls.off(Events.SUBTITLE_FRAG_PROCESSED, this.onSubtitleFragProcessed, this); + hls.off(Events.BUFFER_FLUSHING, this.onBufferFlushing, this); hls.off(Events.FRAG_BUFFERED, this.onFragBuffered, this); } - - // INIT_PTS_FOUND is triggered when the video track parsed in the stream-controller has a new PTS value - onInitPtsFound(event, { - frag, - id, - initPTS, - timescale - }) { - // Always update the new INIT PTS - // Can change due level switch - if (id === 'main') { - const cc = frag.cc; - this.initPTS[frag.cc] = { - baseTime: initPTS, - timescale - }; - this.log(`InitPTS for cc: ${cc} found from main: ${initPTS}`); - this.videoTrackCC = cc; - // If we are waiting, tick immediately to unblock audio fragment transmuxing - if (this.state === State.WAITING_INIT_PTS) { - this.tick(); - } - } - } startLoad(startPosition) { - if (!this.levels) { - this.startPosition = startPosition; - this.state = State.STOPPED; - return; - } - const lastCurrentTime = this.lastCurrentTime; this.stopLoad(); + this.state = State.IDLE; this.setInterval(TICK_INTERVAL$1); - if (lastCurrentTime > 0 && startPosition === -1) { - this.log(`Override startPosition with lastCurrentTime @${lastCurrentTime.toFixed(3)}`); - startPosition = lastCurrentTime; - this.state = State.IDLE; - } else { - this.loadedmetadata = false; - this.state = State.WAITING_TRACK; - } this.nextLoadPosition = this.startPosition = this.lastCurrentTime = startPosition; this.tick(); } - doTick() { - switch (this.state) { - case State.IDLE: - this.doTickIdle(); - break; - case State.WAITING_TRACK: - { - var _levels$trackId; - const { - levels, - trackId - } = this; - const details = levels == null ? void 0 : (_levels$trackId = levels[trackId]) == null ? void 0 : _levels$trackId.details; - if (details) { - if (this.waitForCdnTuneIn(details)) { - break; - } - this.state = State.WAITING_INIT_PTS; - } - break; - } - case State.FRAG_LOADING_WAITING_RETRY: - { - var _this$media; - const now = performance.now(); - const retryDate = this.retryDate; - // if current time is gt than retryDate, or if media seeking let's switch to IDLE state to retry loading - if (!retryDate || now >= retryDate || (_this$media = this.media) != null && _this$media.seeking) { - this.log('RetryDate reached, switch back to IDLE state'); - this.resetStartWhenNotLoaded(this.trackId); - this.state = State.IDLE; - } - break; - } - case State.WAITING_INIT_PTS: - { - // Ensure we don't get stuck in the WAITING_INIT_PTS state if the waiting frag CC doesn't match any initPTS - const waitingData = this.waitingData; - if (waitingData) { - const { - frag, - part, - cache, - complete - } = waitingData; - if (this.initPTS[frag.cc] !== undefined) { - this.waitingData = null; - this.waitingVideoCC = -1; - this.state = State.FRAG_LOADING; - const payload = cache.flush(); - const data = { - frag, - part, - payload, - networkDetails: null - }; - this._handleFragmentLoadProgress(data); - if (complete) { - super._handleFragmentLoadComplete(data); - } - } else if (this.videoTrackCC !== this.waitingVideoCC) { - // Drop waiting fragment if videoTrackCC has changed since waitingFragment was set and initPTS was not found - this.log(`Waiting fragment cc (${frag.cc}) cancelled because video is at cc ${this.videoTrackCC}`); - this.clearWaitingFragment(); - } else { - // Drop waiting fragment if an earlier fragment is needed - const pos = this.getLoadPosition(); - const bufferInfo = BufferHelper.bufferInfo(this.mediaBuffer, pos, this.config.maxBufferHole); - const waitingFragmentAtPosition = fragmentWithinToleranceTest(bufferInfo.end, this.config.maxFragLookUpTolerance, frag); - if (waitingFragmentAtPosition < 0) { - this.log(`Waiting fragment cc (${frag.cc}) @ ${frag.start} cancelled because another fragment at ${bufferInfo.end} is needed`); - this.clearWaitingFragment(); - } - } - } else { - this.state = State.IDLE; - } - } - } - this.onTickEnd(); + onManifestLoading() { + this.mainDetails = null; + this.fragmentTracker.removeAllFragments(); } - clearWaitingFragment() { - const waitingData = this.waitingData; - if (waitingData) { - this.fragmentTracker.removeFragment(waitingData.frag); - this.waitingData = null; - this.waitingVideoCC = -1; - this.state = State.IDLE; - } + onMediaDetaching() { + this.tracksBuffered = []; + super.onMediaDetaching(); } - resetLoadingState() { - this.clearWaitingFragment(); - super.resetLoadingState(); + onLevelLoaded(event, data) { + this.mainDetails = data.details; } - onTickEnd() { + onSubtitleFragProcessed(event, data) { const { - media - } = this; - if (!(media != null && media.readyState)) { - // Exit early if we don't have media or if the media hasn't buffered anything yet (readyState 0) + frag, + success + } = data; + this.fragPrevious = frag; + this.state = State.IDLE; + if (!success) { return; } - this.lastCurrentTime = media.currentTime; - } - doTickIdle() { - const { - hls, - levels, - media, - trackId - } = this; - const config = hls.config; - if (!(levels != null && levels[trackId])) { + const buffered = this.tracksBuffered[this.currentTrackId]; + if (!buffered) { return; } - // if video not attached AND - // start fragment already requested OR start frag prefetch not enabled - // exit loop - // => if media not attached but start frag prefetch is enabled and start frag not requested yet, we will not exit loop - if (!media && (this.startFragRequested || !config.startFragPrefetch)) { - return; - } - const levelInfo = levels[trackId]; - const trackDetails = levelInfo.details; - if (!trackDetails || trackDetails.live && this.levelLastLoaded !== trackId || this.waitForCdnTuneIn(trackDetails)) { - this.state = State.WAITING_TRACK; - return; - } - const bufferable = this.mediaBuffer ? this.mediaBuffer : this.media; - if (this.bufferFlushed && bufferable) { - this.bufferFlushed = false; - this.afterBufferFlushed(bufferable, ElementaryStreamTypes.AUDIO, PlaylistLevelType.AUDIO); + // Create/update a buffered array matching the interface used by BufferHelper.bufferedInfo + // so we can re-use the logic used to detect how much has been buffered + let timeRange; + const fragStart = frag.start; + for (let i = 0; i < buffered.length; i++) { + if (fragStart >= buffered[i].start && fragStart <= buffered[i].end) { + timeRange = buffered[i]; + break; + } } - const bufferInfo = this.getFwdBufferInfo(bufferable, PlaylistLevelType.AUDIO); - if (bufferInfo === null) { - return; + const fragEnd = frag.start + frag.duration; + if (timeRange) { + timeRange.end = fragEnd; + } else { + timeRange = { + start: fragStart, + end: fragEnd + }; + buffered.push(timeRange); } + this.fragmentTracker.fragBuffered(frag); + this.fragBufferedComplete(frag, null); + } + onBufferFlushing(event, data) { const { - bufferedTrack, - switchingTrack - } = this; - if (!switchingTrack && this._streamEnded(bufferInfo, trackDetails)) { - hls.trigger(Events.BUFFER_EOS, { - type: 'audio' - }); - this.state = State.ENDED; - return; - } - const mainBufferInfo = this.getFwdBufferInfo(this.videoBuffer ? this.videoBuffer : this.media, PlaylistLevelType.MAIN); - const bufferLen = bufferInfo.len; - const maxBufLen = this.getMaxBufferLength(mainBufferInfo == null ? void 0 : mainBufferInfo.len); - - // if buffer length is less than maxBufLen try to load a new fragment - if (bufferLen >= maxBufLen && !switchingTrack) { - return; - } - const fragments = trackDetails.fragments; - const start = fragments[0].start; - let targetBufferTime = bufferInfo.end; - if (switchingTrack && media) { - const pos = this.getLoadPosition(); - if (bufferedTrack && switchingTrack.attrs !== bufferedTrack.attrs) { - targetBufferTime = pos; + startOffset, + endOffset + } = data; + if (startOffset === 0 && endOffset !== Number.POSITIVE_INFINITY) { + const endOffsetSubtitles = endOffset - 1; + if (endOffsetSubtitles <= 0) { + return; } - // if currentTime (pos) is less than alt audio playlist start time, it means that alt audio is ahead of currentTime - if (trackDetails.PTSKnown && pos < start) { - // if everything is buffered from pos to start or if audio buffer upfront, let's seek to start - if (bufferInfo.end > start || bufferInfo.nextStart) { - this.log('Alt audio track ahead of main track, seek to start of alt audio track'); - media.currentTime = start + 0.05; + data.endOffsetSubtitles = Math.max(0, endOffsetSubtitles); + this.tracksBuffered.forEach(buffered => { + for (let i = 0; i < buffered.length;) { + if (buffered[i].end <= endOffsetSubtitles) { + buffered.shift(); + continue; + } else if (buffered[i].start < endOffsetSubtitles) { + buffered[i].start = endOffsetSubtitles; + } else { + break; + } + i++; } - } - } - let frag = this.getNextFragment(targetBufferTime, trackDetails); - let atGap = false; - // Avoid loop loading by using nextLoadPosition set for backtracking and skipping consecutive GAP tags - if (frag && this.isLoopLoading(frag, targetBufferTime)) { - atGap = !!frag.gap; - frag = this.getNextFragmentLoopLoading(frag, trackDetails, bufferInfo, PlaylistLevelType.MAIN, maxBufLen); + }); + this.fragmentTracker.removeFragmentsInRange(startOffset, endOffsetSubtitles, PlaylistLevelType.SUBTITLE); } - if (!frag) { - this.bufferFlushed = true; - return; + } + onFragBuffered(event, data) { + if (!this.loadedmetadata && data.frag.type === PlaylistLevelType.MAIN) { + var _this$media; + if ((_this$media = this.media) != null && _this$media.buffered.length) { + this.loadedmetadata = true; + } } + } - // Buffer audio up to one target duration ahead of main buffer - const atBufferSyncLimit = mainBufferInfo && frag.start > mainBufferInfo.end + trackDetails.targetduration; - if (atBufferSyncLimit || - // Or wait for main buffer after buffing some audio - !(mainBufferInfo != null && mainBufferInfo.len) && bufferInfo.len) { - // Check fragment-tracker for main fragments since GAP segments do not show up in bufferInfo - const mainFrag = this.getAppendedFrag(frag.start, PlaylistLevelType.MAIN); - if (mainFrag === null) { - return; + // If something goes wrong, proceed to next frag, if we were processing one. + onError(event, data) { + const frag = data.frag; + if ((frag == null ? void 0 : frag.type) === PlaylistLevelType.SUBTITLE) { + if (this.fragCurrent) { + this.fragCurrent.abortRequests(); } - // Bridge gaps in main buffer - atGap || (atGap = !!mainFrag.gap || !!atBufferSyncLimit && mainBufferInfo.len === 0); - if (atBufferSyncLimit && !atGap || atGap && bufferInfo.nextStart && bufferInfo.nextStart < mainFrag.end) { - return; + if (this.state !== State.STOPPED) { + this.state = State.IDLE; } } - this.loadFragment(frag, levelInfo, targetBufferTime); - } - getMaxBufferLength(mainBufferLength) { - const maxConfigBuffer = super.getMaxBufferLength(); - if (!mainBufferLength) { - return maxConfigBuffer; - } - return Math.min(Math.max(maxConfigBuffer, mainBufferLength), this.config.maxMaxBufferLength); - } - onMediaDetaching() { - this.videoBuffer = null; - super.onMediaDetaching(); } - onAudioTracksUpdated(event, { - audioTracks + + // Got all new subtitle levels. + onSubtitleTracksUpdated(event, { + subtitleTracks }) { - this.resetTransmuxer(); - this.levels = audioTracks.map(mediaPlaylist => new Level(mediaPlaylist)); - } - onAudioTrackSwitching(event, data) { - // if any URL found on new audio track, it is an alternate audio track - const altAudio = !!data.url; - this.trackId = data.id; - const { - fragCurrent - } = this; - if (fragCurrent) { - fragCurrent.abortRequests(); - this.removeUnbufferedFrags(fragCurrent.start); + if (!this.levels || subtitleOptionsIdentical(this.levels, subtitleTracks)) { + this.levels = subtitleTracks.map(mediaPlaylist => new Level(mediaPlaylist)); + return; } - this.resetLoadingState(); - // destroy useless transmuxer when switching audio to main - if (!altAudio) { - this.resetTransmuxer(); - } else { - // switching to audio track, start timer if not already started - this.setInterval(TICK_INTERVAL$1); + this.tracksBuffered = []; + this.levels = subtitleTracks.map(mediaPlaylist => { + const level = new Level(mediaPlaylist); + this.tracksBuffered[level.id] = []; + return level; + }); + this.fragmentTracker.removeFragmentsInRange(0, Number.POSITIVE_INFINITY, PlaylistLevelType.SUBTITLE); + this.fragPrevious = null; + this.mediaBuffer = null; + } + onSubtitleTrackSwitch(event, data) { + var _this$levels; + this.currentTrackId = data.id; + if (!((_this$levels = this.levels) != null && _this$levels.length) || this.currentTrackId === -1) { + this.clearInterval(); + return; } - // should we switch tracks ? - if (altAudio) { - this.switchingTrack = data; - // main audio track are handled by stream-controller, just do something if switching to alt audio track - this.state = State.IDLE; + // Check if track has the necessary details to load fragments + const currentTrack = this.levels[this.currentTrackId]; + if (currentTrack != null && currentTrack.details) { + this.mediaBuffer = this.mediaBufferTimeRanges; } else { - this.switchingTrack = null; - this.bufferedTrack = data; - this.state = State.STOPPED; + this.mediaBuffer = null; } - this.tick(); - } - onManifestLoading() { - this.fragmentTracker.removeAllFragments(); - this.startPosition = this.lastCurrentTime = 0; - this.bufferFlushed = false; - this.levels = this.mainDetails = this.waitingData = this.bufferedTrack = this.cachedTrackLoadedData = this.switchingTrack = null; - this.startFragRequested = false; - this.trackId = this.videoTrackCC = this.waitingVideoCC = -1; - } - onLevelLoaded(event, data) { - this.mainDetails = data.details; - if (this.cachedTrackLoadedData !== null) { - this.hls.trigger(Events.AUDIO_TRACK_LOADED, this.cachedTrackLoadedData); - this.cachedTrackLoadedData = null; + if (currentTrack) { + this.setInterval(TICK_INTERVAL$1); } } - onAudioTrackLoaded(event, data) { + + // Got a new set of subtitle fragments. + onSubtitleTrackLoaded(event, data) { var _track$details; - if (this.mainDetails == null) { - this.cachedTrackLoadedData = data; - return; - } const { + currentTrackId, levels } = this; const { @@ -192126,416 +192030,322 @@ class AudioStreamController extends BaseStreamController { id: trackId } = data; if (!levels) { - this.warn(`Audio tracks were reset while loading level ${trackId}`); + this.warn(`Subtitle tracks were reset while loading level ${trackId}`); return; } - this.log(`Track ${trackId} loaded [${newDetails.startSN},${newDetails.endSN}]${newDetails.lastPartSn ? `[part-${newDetails.lastPartSn}-${newDetails.lastPartIndex}]` : ''},duration:${newDetails.totalduration}`); - const track = levels[trackId]; + const track = levels[currentTrackId]; + if (trackId >= levels.length || trackId !== currentTrackId || !track) { + return; + } + this.log(`Subtitle track ${trackId} loaded [${newDetails.startSN},${newDetails.endSN}]${newDetails.lastPartSn ? `[part-${newDetails.lastPartSn}-${newDetails.lastPartIndex}]` : ''},duration:${newDetails.totalduration}`); + this.mediaBuffer = this.mediaBufferTimeRanges; let sliding = 0; if (newDetails.live || (_track$details = track.details) != null && _track$details.live) { - this.checkLiveUpdate(newDetails); const mainDetails = this.mainDetails; if (newDetails.deltaUpdateFailed || !mainDetails) { return; } - if (!track.details && newDetails.hasProgramDateTime && mainDetails.hasProgramDateTime) { - // Make sure our audio rendition is aligned with the "main" rendition, using - // pdt as our reference times. - alignMediaPlaylistByPDT(newDetails, mainDetails); - sliding = newDetails.fragments[0].start; + const mainSlidingStartFragment = mainDetails.fragments[0]; + if (!track.details) { + if (newDetails.hasProgramDateTime && mainDetails.hasProgramDateTime) { + alignMediaPlaylistByPDT(newDetails, mainDetails); + sliding = newDetails.fragments[0].start; + } else if (mainSlidingStartFragment) { + // line up live playlist with main so that fragments in range are loaded + sliding = mainSlidingStartFragment.start; + addSliding(newDetails, sliding); + } } else { - sliding = this.alignPlaylists(newDetails, track.details); + var _this$levelLastLoaded; + sliding = this.alignPlaylists(newDetails, track.details, (_this$levelLastLoaded = this.levelLastLoaded) == null ? void 0 : _this$levelLastLoaded.details); + if (sliding === 0 && mainSlidingStartFragment) { + // realign with main when there is no overlap with last refresh + sliding = mainSlidingStartFragment.start; + addSliding(newDetails, sliding); + } } } track.details = newDetails; - this.levelLastLoaded = trackId; - - // compute start position if we are aligned with the main playlist + this.levelLastLoaded = track; if (!this.startFragRequested && (this.mainDetails || !newDetails.live)) { this.setStartPosition(track.details, sliding); } - // only switch back to IDLE state if we were waiting for track to start downloading a new fragment - if (this.state === State.WAITING_TRACK && !this.waitForCdnTuneIn(newDetails)) { - this.state = State.IDLE; - } // trigger handler right now this.tick(); + + // If playlist is misaligned because of bad PDT or drift, delete details to resync with main on reload + if (newDetails.live && !this.fragCurrent && this.media && this.state === State.IDLE) { + const foundFrag = findFragmentByPTS(null, newDetails.fragments, this.media.currentTime, 0); + if (!foundFrag) { + this.warn('Subtitle playlist not aligned with playback'); + track.details = undefined; + } + } } - _handleFragmentLoadProgress(data) { - var _frag$initSegment; + _handleFragmentLoadComplete(fragLoadedData) { const { frag, - part, payload - } = data; - const { - config, - trackId, - levels - } = this; - if (!levels) { - this.warn(`Audio tracks were reset while fragment load was in progress. Fragment ${frag.sn} of level ${frag.level} will not be buffered`); + } = fragLoadedData; + const decryptData = frag.decryptdata; + const hls = this.hls; + if (this.fragContextChanged(frag)) { return; } - const track = levels[trackId]; - if (!track) { - this.warn('Audio track is undefined on fragment load progress'); - return; + // check to see if the payload needs to be decrypted + if (payload && payload.byteLength > 0 && decryptData != null && decryptData.key && decryptData.iv && decryptData.method === 'AES-128') { + const startTime = performance.now(); + // decrypt the subtitles + this.decrypter.decrypt(new Uint8Array(payload), decryptData.key.buffer, decryptData.iv.buffer).catch(err => { + hls.trigger(Events.ERROR, { + type: ErrorTypes.MEDIA_ERROR, + details: ErrorDetails.FRAG_DECRYPT_ERROR, + fatal: false, + error: err, + reason: err.message, + frag + }); + throw err; + }).then(decryptedData => { + const endTime = performance.now(); + hls.trigger(Events.FRAG_DECRYPTED, { + frag, + payload: decryptedData, + stats: { + tstart: startTime, + tdecrypt: endTime + } + }); + }).catch(err => { + this.warn(`${err.name}: ${err.message}`); + this.state = State.IDLE; + }); } - const details = track.details; - if (!details) { - this.warn('Audio track details undefined on fragment load progress'); - this.removeUnbufferedFrags(frag.start); + } + doTick() { + if (!this.media) { + this.state = State.IDLE; return; } - const audioCodec = config.defaultAudioCodec || track.audioCodec || 'mp4a.40.2'; - let transmuxer = this.transmuxer; - if (!transmuxer) { - transmuxer = this.transmuxer = new TransmuxerInterface(this.hls, PlaylistLevelType.AUDIO, this._handleTransmuxComplete.bind(this), this._handleTransmuxerFlush.bind(this)); - } - - // Check if we have video initPTS - // If not we need to wait for it - const initPTS = this.initPTS[frag.cc]; - const initSegmentData = (_frag$initSegment = frag.initSegment) == null ? void 0 : _frag$initSegment.data; - if (initPTS !== undefined) { - // this.log(`Transmuxing ${sn} of [${details.startSN} ,${details.endSN}],track ${trackId}`); - // time Offset is accurate if level PTS is known, or if playlist is not sliding (not live) - const accurateTimeOffset = false; // details.PTSKnown || !details.live; - const partIndex = part ? part.index : -1; - const partial = partIndex !== -1; - const chunkMeta = new ChunkMetadata(frag.level, frag.sn, frag.stats.chunkCount, payload.byteLength, partIndex, partial); - transmuxer.push(payload, initSegmentData, audioCodec, '', frag, part, details.totalduration, accurateTimeOffset, chunkMeta, initPTS); - } else { - this.log(`Unknown video PTS for cc ${frag.cc}, waiting for video PTS before demuxing audio frag ${frag.sn} of [${details.startSN} ,${details.endSN}],track ${trackId}`); + if (this.state === State.IDLE) { const { - cache - } = this.waitingData = this.waitingData || { - frag, - part, - cache: new ChunkCache(), - complete: false - }; - cache.push(new Uint8Array(payload)); - this.waitingVideoCC = this.videoTrackCC; - this.state = State.WAITING_INIT_PTS; + currentTrackId, + levels + } = this; + const track = levels == null ? void 0 : levels[currentTrackId]; + if (!track || !levels.length || !track.details) { + return; + } + const { + config + } = this; + const currentTime = this.getLoadPosition(); + const bufferedInfo = BufferHelper.bufferedInfo(this.tracksBuffered[this.currentTrackId] || [], currentTime, config.maxBufferHole); + const { + end: targetBufferTime, + len: bufferLen + } = bufferedInfo; + const mainBufferInfo = this.getFwdBufferInfo(this.media, PlaylistLevelType.MAIN); + const trackDetails = track.details; + const maxBufLen = this.getMaxBufferLength(mainBufferInfo == null ? void 0 : mainBufferInfo.len) + trackDetails.levelTargetDuration; + if (bufferLen > maxBufLen) { + return; + } + const fragments = trackDetails.fragments; + const fragLen = fragments.length; + const end = trackDetails.edge; + let foundFrag = null; + const fragPrevious = this.fragPrevious; + if (targetBufferTime < end) { + const tolerance = config.maxFragLookUpTolerance; + const lookupTolerance = targetBufferTime > end - tolerance ? 0 : tolerance; + foundFrag = findFragmentByPTS(fragPrevious, fragments, Math.max(fragments[0].start, targetBufferTime), lookupTolerance); + if (!foundFrag && fragPrevious && fragPrevious.start < fragments[0].start) { + foundFrag = fragments[0]; + } + } else { + foundFrag = fragments[fragLen - 1]; + } + if (!foundFrag) { + return; + } + foundFrag = this.mapToInitFragWhenRequired(foundFrag); + if (foundFrag.sn !== 'initSegment') { + // Load earlier fragment in same discontinuity to make up for misaligned playlists and cues that extend beyond end of segment + const curSNIdx = foundFrag.sn - trackDetails.startSN; + const prevFrag = fragments[curSNIdx - 1]; + if (prevFrag && prevFrag.cc === foundFrag.cc && this.fragmentTracker.getState(prevFrag) === FragmentState.NOT_LOADED) { + foundFrag = prevFrag; + } + } + if (this.fragmentTracker.getState(foundFrag) === FragmentState.NOT_LOADED) { + // only load if fragment is not loaded + this.loadFragment(foundFrag, track, targetBufferTime); + } } } - _handleFragmentLoadComplete(fragLoadedData) { - if (this.waitingData) { - this.waitingData.complete = true; - return; + getMaxBufferLength(mainBufferLength) { + const maxConfigBuffer = super.getMaxBufferLength(); + if (!mainBufferLength) { + return maxConfigBuffer; } - super._handleFragmentLoadComplete(fragLoadedData); - } - onBufferReset( /* event: Events.BUFFER_RESET */ - ) { - // reset reference to sourcebuffers - this.mediaBuffer = this.videoBuffer = null; - this.loadedmetadata = false; + return Math.max(maxConfigBuffer, mainBufferLength); } - onBufferCreated(event, data) { - const audioTrack = data.tracks.audio; - if (audioTrack) { - this.mediaBuffer = audioTrack.buffer || null; - } - if (data.tracks.video) { - this.videoBuffer = data.tracks.video.buffer || null; + loadFragment(frag, level, targetBufferTime) { + this.fragCurrent = frag; + if (frag.sn === 'initSegment') { + this._loadInitSegment(frag, level); + } else { + this.startFragRequested = true; + super.loadFragment(frag, level, targetBufferTime); } } - onFragBuffered(event, data) { - const { - frag, - part - } = data; - if (frag.type !== PlaylistLevelType.AUDIO) { - if (!this.loadedmetadata && frag.type === PlaylistLevelType.MAIN) { - const bufferable = this.videoBuffer || this.media; - if (bufferable) { - const bufferedTimeRanges = BufferHelper.getBuffered(bufferable); - if (bufferedTimeRanges.length) { - this.loadedmetadata = true; - } - } + get mediaBufferTimeRanges() { + return new BufferableInstance(this.tracksBuffered[this.currentTrackId] || []); + } +} +class BufferableInstance { + constructor(timeranges) { + this.buffered = void 0; + const getRange = (name, index, length) => { + index = index >>> 0; + if (index > length - 1) { + throw new DOMException(`Failed to execute '${name}' on 'TimeRanges': The index provided (${index}) is greater than the maximum bound (${length})`); } - return; - } - if (this.fragContextChanged(frag)) { - // If a level switch was requested while a fragment was buffering, it will emit the FRAG_BUFFERED event upon completion - // Avoid setting state back to IDLE or concluding the audio switch; otherwise, the switched-to track will not buffer - this.warn(`Fragment ${frag.sn}${part ? ' p: ' + part.index : ''} of level ${frag.level} finished buffering, but was aborted. state: ${this.state}, audioSwitch: ${this.switchingTrack ? this.switchingTrack.name : 'false'}`); - return; - } - if (frag.sn !== 'initSegment') { - this.fragPrevious = frag; - const track = this.switchingTrack; - if (track) { - this.bufferedTrack = track; - this.switchingTrack = null; - this.hls.trigger(Events.AUDIO_TRACK_SWITCHED, _objectSpread2({}, track)); + return timeranges[index][name]; + }; + this.buffered = { + get length() { + return timeranges.length; + }, + end(index) { + return getRange('end', index, timeranges.length); + }, + start(index) { + return getRange('start', index, timeranges.length); } - } - this.fragBufferedComplete(frag, part); + }; } - onError(event, data) { - var _data$context; - if (data.fatal) { - this.state = State.ERROR; - return; - } - switch (data.details) { - case ErrorDetails.FRAG_GAP: - case ErrorDetails.FRAG_PARSING_ERROR: - case ErrorDetails.FRAG_DECRYPT_ERROR: - case ErrorDetails.FRAG_LOAD_ERROR: - case ErrorDetails.FRAG_LOAD_TIMEOUT: - case ErrorDetails.KEY_LOAD_ERROR: - case ErrorDetails.KEY_LOAD_TIMEOUT: - this.onFragmentOrKeyLoadError(PlaylistLevelType.AUDIO, data); - break; - case ErrorDetails.AUDIO_TRACK_LOAD_ERROR: - case ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT: - case ErrorDetails.LEVEL_PARSING_ERROR: - // in case of non fatal error while loading track, if not retrying to load track, switch back to IDLE - if (!data.levelRetry && this.state === State.WAITING_TRACK && ((_data$context = data.context) == null ? void 0 : _data$context.type) === PlaylistContextType.AUDIO_TRACK) { - this.state = State.IDLE; - } - break; - case ErrorDetails.BUFFER_FULL_ERROR: - if (!data.parent || data.parent !== 'audio') { - return; - } - if (this.reduceLengthAndFlushBuffer(data)) { - this.bufferedTrack = null; - super.flushMainBuffer(0, Number.POSITIVE_INFINITY, 'audio'); - } - break; - case ErrorDetails.INTERNAL_EXCEPTION: - this.recoverWorkerError(data); - break; - } +} + +class SubtitleTrackController extends BasePlaylistController { + constructor(hls) { + super(hls, '[subtitle-track-controller]'); + this.media = null; + this.tracks = []; + this.groupIds = null; + this.tracksInGroup = []; + this.trackId = -1; + this.currentTrack = null; + this.selectDefaultTrack = true; + this.queuedDefaultTrack = -1; + this.trackChangeListener = () => this.onTextTracksChanged(); + this.asyncPollTrackChange = () => this.pollTrackChange(0); + this.useTextTrackPolling = false; + this.subtitlePollingInterval = -1; + this._subtitleDisplay = true; + this.registerListeners(); } - onBufferFlushed(event, { - type - }) { - if (type === ElementaryStreamTypes.AUDIO) { - this.bufferFlushed = true; - if (this.state === State.ENDED) { - this.state = State.IDLE; - } + destroy() { + this.unregisterListeners(); + this.tracks.length = 0; + this.tracksInGroup.length = 0; + this.currentTrack = null; + this.trackChangeListener = this.asyncPollTrackChange = null; + super.destroy(); + } + get subtitleDisplay() { + return this._subtitleDisplay; + } + set subtitleDisplay(value) { + this._subtitleDisplay = value; + if (this.trackId > -1) { + this.toggleTrackModes(); } } - _handleTransmuxComplete(transmuxResult) { - var _id3$samples; - const id = 'audio'; + registerListeners() { const { hls } = this; + hls.on(Events.MEDIA_ATTACHED, this.onMediaAttached, this); + hls.on(Events.MEDIA_DETACHING, this.onMediaDetaching, this); + hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this); + hls.on(Events.MANIFEST_PARSED, this.onManifestParsed, this); + hls.on(Events.LEVEL_LOADING, this.onLevelLoading, this); + hls.on(Events.LEVEL_SWITCHING, this.onLevelSwitching, this); + hls.on(Events.SUBTITLE_TRACK_LOADED, this.onSubtitleTrackLoaded, this); + hls.on(Events.ERROR, this.onError, this); + } + unregisterListeners() { const { - remuxResult, - chunkMeta - } = transmuxResult; - const context = this.getCurrentContext(chunkMeta); - if (!context) { - this.resetWhenMissingContext(chunkMeta); + hls + } = this; + hls.off(Events.MEDIA_ATTACHED, this.onMediaAttached, this); + hls.off(Events.MEDIA_DETACHING, this.onMediaDetaching, this); + hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this); + hls.off(Events.MANIFEST_PARSED, this.onManifestParsed, this); + hls.off(Events.LEVEL_LOADING, this.onLevelLoading, this); + hls.off(Events.LEVEL_SWITCHING, this.onLevelSwitching, this); + hls.off(Events.SUBTITLE_TRACK_LOADED, this.onSubtitleTrackLoaded, this); + hls.off(Events.ERROR, this.onError, this); + } + + // Listen for subtitle track change, then extract the current track ID. + onMediaAttached(event, data) { + this.media = data.media; + if (!this.media) { return; } - const { - frag, - part, - level - } = context; - const { - details - } = level; - const { - audio, - text, - id3, - initSegment - } = remuxResult; - - // Check if the current fragment has been aborted. We check this by first seeing if we're still playing the current level. - // If we are, subsequently check if the currently loading fragment (fragCurrent) has changed. - if (this.fragContextChanged(frag) || !details) { - this.fragmentTracker.removeFragment(frag); + if (this.queuedDefaultTrack > -1) { + this.subtitleTrack = this.queuedDefaultTrack; + this.queuedDefaultTrack = -1; + } + this.useTextTrackPolling = !(this.media.textTracks && 'onchange' in this.media.textTracks); + if (this.useTextTrackPolling) { + this.pollTrackChange(500); + } else { + this.media.textTracks.addEventListener('change', this.asyncPollTrackChange); + } + } + pollTrackChange(timeout) { + self.clearInterval(this.subtitlePollingInterval); + this.subtitlePollingInterval = self.setInterval(this.trackChangeListener, timeout); + } + onMediaDetaching() { + if (!this.media) { return; } - this.state = State.PARSING; - if (this.switchingTrack && audio) { - this.completeAudioSwitch(this.switchingTrack); + self.clearInterval(this.subtitlePollingInterval); + if (!this.useTextTrackPolling) { + this.media.textTracks.removeEventListener('change', this.asyncPollTrackChange); } - if (initSegment != null && initSegment.tracks) { - const mapFragment = frag.initSegment || frag; - this._bufferInitSegment(initSegment.tracks, mapFragment, chunkMeta); - hls.trigger(Events.FRAG_PARSING_INIT_SEGMENT, { - frag: mapFragment, - id, - tracks: initSegment.tracks - }); - // Only flush audio from old audio tracks when PTS is known on new audio track + if (this.trackId > -1) { + this.queuedDefaultTrack = this.trackId; } - - if (audio) { - const { - startPTS, - endPTS, - startDTS, - endDTS - } = audio; - if (part) { - part.elementaryStreams[ElementaryStreamTypes.AUDIO] = { - startPTS, - endPTS, - startDTS, - endDTS - }; - } - frag.setElementaryStreamInfo(ElementaryStreamTypes.AUDIO, startPTS, endPTS, startDTS, endDTS); - this.bufferFragmentData(audio, frag, part, chunkMeta); - } - if (id3 != null && (_id3$samples = id3.samples) != null && _id3$samples.length) { - const emittedID3 = _extends({ - id, - frag, - details - }, id3); - hls.trigger(Events.FRAG_PARSING_METADATA, emittedID3); - } - if (text) { - const emittedText = _extends({ - id, - frag, - details - }, text); - hls.trigger(Events.FRAG_PARSING_USERDATA, emittedText); - } - } - _bufferInitSegment(tracks, frag, chunkMeta) { - if (this.state !== State.PARSING) { - return; - } - // delete any video track found on audio transmuxer - if (tracks.video) { - delete tracks.video; - } - - // include levelCodec in audio and video tracks - const track = tracks.audio; - if (!track) { - return; - } - track.levelCodec = track.codec; - track.id = 'audio'; - this.log(`Init audio buffer, container:${track.container}, codecs[parsed]=[${track.codec}]`); - this.hls.trigger(Events.BUFFER_CODECS, tracks); - const initSegment = track.initSegment; - if (initSegment != null && initSegment.byteLength) { - const segment = { - type: 'audio', - frag, - part: null, - chunkMeta, - parent: frag.type, - data: initSegment - }; - this.hls.trigger(Events.BUFFER_APPENDING, segment); - } - // trigger handler right now - this.tick(); - } - loadFragment(frag, track, targetBufferTime) { - // only load if fragment is not loaded or if in audio switch - const fragState = this.fragmentTracker.getState(frag); - this.fragCurrent = frag; - - // we force a frag loading in audio switch as fragment tracker might not have evicted previous frags in case of quick audio switch - if (this.switchingTrack || fragState === FragmentState.NOT_LOADED || fragState === FragmentState.PARTIAL) { - var _track$details2; - if (frag.sn === 'initSegment') { - this._loadInitSegment(frag, track); - } else if ((_track$details2 = track.details) != null && _track$details2.live && !this.initPTS[frag.cc]) { - this.log(`Waiting for video PTS in continuity counter ${frag.cc} of live stream before loading audio fragment ${frag.sn} of level ${this.trackId}`); - this.state = State.WAITING_INIT_PTS; - } else { - this.startFragRequested = true; - super.loadFragment(frag, track, targetBufferTime); - } - } else { - this.clearTrackerIfNeeded(frag); - } - } - completeAudioSwitch(switchingTrack) { - const { - hls, - media, - bufferedTrack - } = this; - const bufferedAttributes = bufferedTrack == null ? void 0 : bufferedTrack.attrs; - const switchAttributes = switchingTrack.attrs; - if (media && bufferedAttributes && (bufferedAttributes.CHANNELS !== switchAttributes.CHANNELS || bufferedAttributes.NAME !== switchAttributes.NAME || bufferedAttributes.LANGUAGE !== switchAttributes.LANGUAGE)) { - this.log('Switching audio track : flushing all audio'); - super.flushMainBuffer(0, Number.POSITIVE_INFINITY, 'audio'); - } - this.bufferedTrack = switchingTrack; - this.switchingTrack = null; - hls.trigger(Events.AUDIO_TRACK_SWITCHED, _objectSpread2({}, switchingTrack)); - } -} - -class AudioTrackController extends BasePlaylistController { - constructor(hls) { - super(hls, '[audio-track-controller]'); - this.tracks = []; - this.groupId = null; - this.tracksInGroup = []; - this.trackId = -1; - this.currentTrack = null; - this.selectDefaultTrack = true; - this.registerListeners(); - } - registerListeners() { - const { - hls - } = this; - hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this); - hls.on(Events.MANIFEST_PARSED, this.onManifestParsed, this); - hls.on(Events.LEVEL_LOADING, this.onLevelLoading, this); - hls.on(Events.LEVEL_SWITCHING, this.onLevelSwitching, this); - hls.on(Events.AUDIO_TRACK_LOADED, this.onAudioTrackLoaded, this); - hls.on(Events.ERROR, this.onError, this); - } - unregisterListeners() { - const { - hls - } = this; - hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this); - hls.off(Events.MANIFEST_PARSED, this.onManifestParsed, this); - hls.off(Events.LEVEL_LOADING, this.onLevelLoading, this); - hls.off(Events.LEVEL_SWITCHING, this.onLevelSwitching, this); - hls.off(Events.AUDIO_TRACK_LOADED, this.onAudioTrackLoaded, this); - hls.off(Events.ERROR, this.onError, this); - } - destroy() { - this.unregisterListeners(); - this.tracks.length = 0; - this.tracksInGroup.length = 0; - this.currentTrack = null; - super.destroy(); + const textTracks = filterSubtitleTracks(this.media.textTracks); + // Clear loaded cues on media detachment from tracks + textTracks.forEach(track => { + clearCurrentCues(track); + }); + // Disable all subtitle tracks before detachment so when reattached only tracks in that content are enabled. + this.subtitleTrack = -1; + this.media = null; } onManifestLoading() { this.tracks = []; - this.groupId = null; + this.groupIds = null; this.tracksInGroup = []; this.trackId = -1; this.currentTrack = null; this.selectDefaultTrack = true; } + + // Fired whenever a new manifest is loaded. onManifestParsed(event, data) { - this.tracks = data.audioTracks || []; + this.tracks = data.subtitleTracks; } - onAudioTrackLoaded(event, data) { + onSubtitleTrackLoaded(event, data) { const { id, groupId, @@ -192543,12 +192353,12 @@ class AudioTrackController extends BasePlaylistController { } = data; const trackInActiveGroup = this.tracksInGroup[id]; if (!trackInActiveGroup || trackInActiveGroup.groupId !== groupId) { - this.warn(`Track with id:${id} and group:${groupId} not found in active group ${trackInActiveGroup.groupId}`); + this.warn(`Subtitle track with id:${id} and group:${groupId} not found in active group ${trackInActiveGroup == null ? void 0 : trackInActiveGroup.groupId}`); return; } const curDetails = trackInActiveGroup.details; trackInActiveGroup.details = data.details; - this.log(`audio-track ${id} "${trackInActiveGroup.name}" lang:${trackInActiveGroup.lang} group:${groupId} loaded [${details.startSN}-${details.endSN}]`); + this.log(`Subtitle track ${id} "${trackInActiveGroup.name}" lang:${trackInActiveGroup.lang} group:${groupId} loaded [${details.startSN}-${details.endSN}]`); if (id === this.trackId) { this.playlistLoaded(id, data, curDetails); } @@ -192561,726 +192371,86 @@ class AudioTrackController extends BasePlaylistController { } switchLevel(levelIndex) { const levelInfo = this.hls.levels[levelIndex]; - if (!(levelInfo != null && levelInfo.audioGroupIds)) { - return; - } - const audioGroupId = levelInfo.audioGroupIds[levelInfo.urlId]; - if (this.groupId !== audioGroupId) { - this.groupId = audioGroupId || null; - const audioTracks = this.tracks.filter(track => !audioGroupId || track.groupId === audioGroupId); - - // Disable selectDefaultTrack if there are no default tracks - if (this.selectDefaultTrack && !audioTracks.some(track => track.default)) { - this.selectDefaultTrack = false; - } - this.tracksInGroup = audioTracks; - const audioTracksUpdated = { - audioTracks - }; - this.log(`Updating audio tracks, ${audioTracks.length} track(s) found in group:${audioGroupId}`); - this.hls.trigger(Events.AUDIO_TRACKS_UPDATED, audioTracksUpdated); - this.selectInitialTrack(); - } else if (this.shouldReloadPlaylist(this.currentTrack)) { - // Retry playlist loading if no playlist is or has been loaded yet - this.setAudioTrack(this.trackId); - } - } - onError(event, data) { - if (data.fatal || !data.context) { - return; - } - if (data.context.type === PlaylistContextType.AUDIO_TRACK && data.context.id === this.trackId && data.context.groupId === this.groupId) { - this.requestScheduled = -1; - this.checkRetry(data); - } - } - get audioTracks() { - return this.tracksInGroup; - } - get audioTrack() { - return this.trackId; - } - set audioTrack(newId) { - // If audio track is selected from API then don't choose from the manifest default track - this.selectDefaultTrack = false; - this.setAudioTrack(newId); - } - setAudioTrack(newId) { - const tracks = this.tracksInGroup; - - // check if level idx is valid - if (newId < 0 || newId >= tracks.length) { - this.warn('Invalid id passed to audio-track controller'); - return; - } - - // stopping live reloading timer if any - this.clearTimer(); - const lastTrack = this.currentTrack; - tracks[this.trackId]; - const track = tracks[newId]; - const { - groupId, - name - } = track; - this.log(`Switching to audio-track ${newId} "${name}" lang:${track.lang} group:${groupId}`); - this.trackId = newId; - this.currentTrack = track; - this.selectDefaultTrack = false; - this.hls.trigger(Events.AUDIO_TRACK_SWITCHING, _objectSpread2({}, track)); - // Do not reload track unless live - if (track.details && !track.details.live) { + if (!levelInfo) { return; } - const hlsUrlParameters = this.switchParams(track.url, lastTrack == null ? void 0 : lastTrack.details); - this.loadPlaylist(hlsUrlParameters); - } - selectInitialTrack() { - const audioTracks = this.tracksInGroup; - const trackId = this.findTrackId(this.currentTrack) | this.findTrackId(null); - if (trackId !== -1) { - this.setAudioTrack(trackId); - } else { - const error = new Error(`No track found for running audio group-ID: ${this.groupId} track count: ${audioTracks.length}`); - this.warn(error.message); - this.hls.trigger(Events.ERROR, { - type: ErrorTypes.MEDIA_ERROR, - details: ErrorDetails.AUDIO_TRACK_LOAD_ERROR, - fatal: true, - error - }); - } - } - findTrackId(currentTrack) { - const audioTracks = this.tracksInGroup; - for (let i = 0; i < audioTracks.length; i++) { - const track = audioTracks[i]; - if (!this.selectDefaultTrack || track.default) { - if (!currentTrack || currentTrack.attrs['STABLE-RENDITION-ID'] !== undefined && currentTrack.attrs['STABLE-RENDITION-ID'] === track.attrs['STABLE-RENDITION-ID']) { - return track.id; - } - if (currentTrack.name === track.name && currentTrack.lang === track.lang) { - return track.id; - } + const subtitleGroups = levelInfo.subtitleGroups || null; + const currentGroups = this.groupIds; + let currentTrack = this.currentTrack; + if (!subtitleGroups || (currentGroups == null ? void 0 : currentGroups.length) !== (subtitleGroups == null ? void 0 : subtitleGroups.length) || subtitleGroups != null && subtitleGroups.some(groupId => (currentGroups == null ? void 0 : currentGroups.indexOf(groupId)) === -1)) { + this.groupIds = subtitleGroups; + this.trackId = -1; + this.currentTrack = null; + const subtitleTracks = this.tracks.filter(track => !subtitleGroups || subtitleGroups.indexOf(track.groupId) !== -1); + if (subtitleTracks.length) { + // Disable selectDefaultTrack if there are no default or forced tracks + if (this.selectDefaultTrack && !subtitleTracks.some(track => track.default || track.forced || track.autoselect)) { + this.selectDefaultTrack = false; + } + // track.id should match hls.audioTracks index + subtitleTracks.forEach((track, i) => { + track.id = i; + }); + } else if (!currentTrack && !this.tracksInGroup.length) { + // Do not dispatch SUBTITLE_TRACKS_UPDATED when there were and are no tracks + return; } - } - return -1; - } - loadPlaylist(hlsUrlParameters) { - super.loadPlaylist(); - const audioTrack = this.tracksInGroup[this.trackId]; - if (this.shouldLoadPlaylist(audioTrack)) { - const id = audioTrack.id; - const groupId = audioTrack.groupId; - let url = audioTrack.url; - if (hlsUrlParameters) { - try { - url = hlsUrlParameters.addDirectives(url); - } catch (error) { - this.warn(`Could not construct new URL with HLS Delivery Directives: ${error}`); - } + if (!currentTrack) { + currentTrack = this.setSubtitleOption(this.hls.config.subtitlePreference); } - // track not retrieved yet, or live playlist we need to (re)load it - this.log(`loading audio-track playlist ${id} "${audioTrack.name}" lang:${audioTrack.lang} group:${groupId}`); - this.clearTimer(); - this.hls.trigger(Events.AUDIO_TRACK_LOADING, { - url, - id, - groupId, - deliveryDirectives: hlsUrlParameters || null - }); - } - } -} - -function subtitleOptionsIdentical(trackList1, trackList2) { - if (trackList1.length !== trackList2.length) { - return false; - } - for (let i = 0; i < trackList1.length; i++) { - if (!subtitleAttributesIdentical(trackList1[i].attrs, trackList2[i].attrs)) { - return false; - } - } - return true; -} -function subtitleAttributesIdentical(attrs1, attrs2) { - // Media options with the same rendition ID must be bit identical - const stableRenditionId = attrs1['STABLE-RENDITION-ID']; - if (stableRenditionId) { - return stableRenditionId === attrs2['STABLE-RENDITION-ID']; - } - // When rendition ID is not present, compare attributes - return !['LANGUAGE', 'NAME', 'CHARACTERISTICS', 'AUTOSELECT', 'DEFAULT', 'FORCED'].some(subtitleAttribute => attrs1[subtitleAttribute] !== attrs2[subtitleAttribute]); -} - -const TICK_INTERVAL = 500; // how often to tick in ms - -class SubtitleStreamController extends BaseStreamController { - constructor(hls, fragmentTracker, keyLoader) { - super(hls, fragmentTracker, keyLoader, '[subtitle-stream-controller]', PlaylistLevelType.SUBTITLE); - this.levels = []; - this.currentTrackId = -1; - this.tracksBuffered = []; - this.mainDetails = null; - this._registerListeners(); - } - onHandlerDestroying() { - this._unregisterListeners(); - this.mainDetails = null; - } - _registerListeners() { - const { - hls - } = this; - hls.on(Events.MEDIA_ATTACHED, this.onMediaAttached, this); - hls.on(Events.MEDIA_DETACHING, this.onMediaDetaching, this); - hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this); - hls.on(Events.LEVEL_LOADED, this.onLevelLoaded, this); - hls.on(Events.ERROR, this.onError, this); - hls.on(Events.SUBTITLE_TRACKS_UPDATED, this.onSubtitleTracksUpdated, this); - hls.on(Events.SUBTITLE_TRACK_SWITCH, this.onSubtitleTrackSwitch, this); - hls.on(Events.SUBTITLE_TRACK_LOADED, this.onSubtitleTrackLoaded, this); - hls.on(Events.SUBTITLE_FRAG_PROCESSED, this.onSubtitleFragProcessed, this); - hls.on(Events.BUFFER_FLUSHING, this.onBufferFlushing, this); - hls.on(Events.FRAG_BUFFERED, this.onFragBuffered, this); - } - _unregisterListeners() { - const { - hls - } = this; - hls.off(Events.MEDIA_ATTACHED, this.onMediaAttached, this); - hls.off(Events.MEDIA_DETACHING, this.onMediaDetaching, this); - hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this); - hls.off(Events.LEVEL_LOADED, this.onLevelLoaded, this); - hls.off(Events.ERROR, this.onError, this); - hls.off(Events.SUBTITLE_TRACKS_UPDATED, this.onSubtitleTracksUpdated, this); - hls.off(Events.SUBTITLE_TRACK_SWITCH, this.onSubtitleTrackSwitch, this); - hls.off(Events.SUBTITLE_TRACK_LOADED, this.onSubtitleTrackLoaded, this); - hls.off(Events.SUBTITLE_FRAG_PROCESSED, this.onSubtitleFragProcessed, this); - hls.off(Events.BUFFER_FLUSHING, this.onBufferFlushing, this); - hls.off(Events.FRAG_BUFFERED, this.onFragBuffered, this); - } - startLoad(startPosition) { - this.stopLoad(); - this.state = State.IDLE; - this.setInterval(TICK_INTERVAL); - this.nextLoadPosition = this.startPosition = this.lastCurrentTime = startPosition; - this.tick(); - } - onManifestLoading() { - this.mainDetails = null; - this.fragmentTracker.removeAllFragments(); - } - onMediaDetaching() { - this.tracksBuffered = []; - super.onMediaDetaching(); - } - onLevelLoaded(event, data) { - this.mainDetails = data.details; - } - onSubtitleFragProcessed(event, data) { - const { - frag, - success - } = data; - this.fragPrevious = frag; - this.state = State.IDLE; - if (!success) { - return; - } - const buffered = this.tracksBuffered[this.currentTrackId]; - if (!buffered) { - return; - } - - // Create/update a buffered array matching the interface used by BufferHelper.bufferedInfo - // so we can re-use the logic used to detect how much has been buffered - let timeRange; - const fragStart = frag.start; - for (let i = 0; i < buffered.length; i++) { - if (fragStart >= buffered[i].start && fragStart <= buffered[i].end) { - timeRange = buffered[i]; - break; + this.tracksInGroup = subtitleTracks; + let trackId = this.findTrackId(currentTrack); + if (trackId === -1 && currentTrack) { + trackId = this.findTrackId(null); } - } - const fragEnd = frag.start + frag.duration; - if (timeRange) { - timeRange.end = fragEnd; - } else { - timeRange = { - start: fragStart, - end: fragEnd + const subtitleTracksUpdated = { + subtitleTracks }; - buffered.push(timeRange); - } - this.fragmentTracker.fragBuffered(frag); - } - onBufferFlushing(event, data) { - const { - startOffset, - endOffset - } = data; - if (startOffset === 0 && endOffset !== Number.POSITIVE_INFINITY) { - const endOffsetSubtitles = endOffset - 1; - if (endOffsetSubtitles <= 0) { - return; - } - data.endOffsetSubtitles = Math.max(0, endOffsetSubtitles); - this.tracksBuffered.forEach(buffered => { - for (let i = 0; i < buffered.length;) { - if (buffered[i].end <= endOffsetSubtitles) { - buffered.shift(); - continue; - } else if (buffered[i].start < endOffsetSubtitles) { - buffered[i].start = endOffsetSubtitles; - } else { - break; - } - i++; - } - }); - this.fragmentTracker.removeFragmentsInRange(startOffset, endOffsetSubtitles, PlaylistLevelType.SUBTITLE); - } - } - onFragBuffered(event, data) { - if (!this.loadedmetadata && data.frag.type === PlaylistLevelType.MAIN) { - var _this$media; - if ((_this$media = this.media) != null && _this$media.buffered.length) { - this.loadedmetadata = true; + this.log(`Updating subtitle tracks, ${subtitleTracks.length} track(s) found in "${subtitleGroups == null ? void 0 : subtitleGroups.join(',')}" group-id`); + this.hls.trigger(Events.SUBTITLE_TRACKS_UPDATED, subtitleTracksUpdated); + if (trackId !== -1 && this.trackId === -1) { + this.setSubtitleTrack(trackId); } + } else if (this.shouldReloadPlaylist(currentTrack)) { + // Retry playlist loading if no playlist is or has been loaded yet + this.setSubtitleTrack(this.trackId); } } - - // If something goes wrong, proceed to next frag, if we were processing one. - onError(event, data) { - const frag = data.frag; - if ((frag == null ? void 0 : frag.type) === PlaylistLevelType.SUBTITLE) { - if (this.fragCurrent) { - this.fragCurrent.abortRequests(); + findTrackId(currentTrack) { + const tracks = this.tracksInGroup; + const selectDefault = this.selectDefaultTrack; + for (let i = 0; i < tracks.length; i++) { + const track = tracks[i]; + if (selectDefault && !track.default && !track.forced && !track.autoselect || !selectDefault && !currentTrack) { + continue; } - if (this.state !== State.STOPPED) { - this.state = State.IDLE; + if (!currentTrack || matchesOption(track, currentTrack)) { + return i; } } - } - - // Got all new subtitle levels. - onSubtitleTracksUpdated(event, { - subtitleTracks - }) { - if (subtitleOptionsIdentical(this.levels, subtitleTracks)) { - this.levels = subtitleTracks.map(mediaPlaylist => new Level(mediaPlaylist)); - return; - } - this.tracksBuffered = []; - this.levels = subtitleTracks.map(mediaPlaylist => { - const level = new Level(mediaPlaylist); - this.tracksBuffered[level.id] = []; - return level; - }); - this.fragmentTracker.removeFragmentsInRange(0, Number.POSITIVE_INFINITY, PlaylistLevelType.SUBTITLE); - this.fragPrevious = null; - this.mediaBuffer = null; - } - onSubtitleTrackSwitch(event, data) { - this.currentTrackId = data.id; - if (!this.levels.length || this.currentTrackId === -1) { - this.clearInterval(); - return; - } - - // Check if track has the necessary details to load fragments - const currentTrack = this.levels[this.currentTrackId]; - if (currentTrack != null && currentTrack.details) { - this.mediaBuffer = this.mediaBufferTimeRanges; - } else { - this.mediaBuffer = null; - } if (currentTrack) { - this.setInterval(TICK_INTERVAL); - } - } - - // Got a new set of subtitle fragments. - onSubtitleTrackLoaded(event, data) { - var _track$details; - const { - details: newDetails, - id: trackId - } = data; - const { - currentTrackId, - levels - } = this; - if (!levels.length) { - return; - } - const track = levels[currentTrackId]; - if (trackId >= levels.length || trackId !== currentTrackId || !track) { - return; - } - this.mediaBuffer = this.mediaBufferTimeRanges; - let sliding = 0; - if (newDetails.live || (_track$details = track.details) != null && _track$details.live) { - const mainDetails = this.mainDetails; - if (newDetails.deltaUpdateFailed || !mainDetails) { - return; - } - const mainSlidingStartFragment = mainDetails.fragments[0]; - if (!track.details) { - if (newDetails.hasProgramDateTime && mainDetails.hasProgramDateTime) { - alignMediaPlaylistByPDT(newDetails, mainDetails); - sliding = newDetails.fragments[0].start; - } else if (mainSlidingStartFragment) { - // line up live playlist with main so that fragments in range are loaded - sliding = mainSlidingStartFragment.start; - addSliding(newDetails, sliding); - } - } else { - sliding = this.alignPlaylists(newDetails, track.details); - if (sliding === 0 && mainSlidingStartFragment) { - // realign with main when there is no overlap with last refresh - sliding = mainSlidingStartFragment.start; - addSliding(newDetails, sliding); - } - } - } - track.details = newDetails; - this.levelLastLoaded = trackId; - if (!this.startFragRequested && (this.mainDetails || !newDetails.live)) { - this.setStartPosition(track.details, sliding); - } - - // trigger handler right now - this.tick(); - - // If playlist is misaligned because of bad PDT or drift, delete details to resync with main on reload - if (newDetails.live && !this.fragCurrent && this.media && this.state === State.IDLE) { - const foundFrag = findFragmentByPTS(null, newDetails.fragments, this.media.currentTime, 0); - if (!foundFrag) { - this.warn('Subtitle playlist not aligned with playback'); - track.details = undefined; - } - } - } - _handleFragmentLoadComplete(fragLoadedData) { - const { - frag, - payload - } = fragLoadedData; - const decryptData = frag.decryptdata; - const hls = this.hls; - if (this.fragContextChanged(frag)) { - return; - } - // check to see if the payload needs to be decrypted - if (payload && payload.byteLength > 0 && decryptData && decryptData.key && decryptData.iv && decryptData.method === 'AES-128') { - const startTime = performance.now(); - // decrypt the subtitles - this.decrypter.decrypt(new Uint8Array(payload), decryptData.key.buffer, decryptData.iv.buffer).catch(err => { - hls.trigger(Events.ERROR, { - type: ErrorTypes.MEDIA_ERROR, - details: ErrorDetails.FRAG_DECRYPT_ERROR, - fatal: false, - error: err, - reason: err.message, - frag - }); - throw err; - }).then(decryptedData => { - const endTime = performance.now(); - hls.trigger(Events.FRAG_DECRYPTED, { - frag, - payload: decryptedData, - stats: { - tstart: startTime, - tdecrypt: endTime - } - }); - }).catch(err => { - this.warn(`${err.name}: ${err.message}`); - this.state = State.IDLE; - }); - } - } - doTick() { - if (!this.media) { - this.state = State.IDLE; - return; - } - if (this.state === State.IDLE) { - const { - currentTrackId, - levels - } = this; - const track = levels[currentTrackId]; - if (!levels.length || !track || !track.details) { - return; - } - const { - config - } = this; - const currentTime = this.getLoadPosition(); - const bufferedInfo = BufferHelper.bufferedInfo(this.tracksBuffered[this.currentTrackId] || [], currentTime, config.maxBufferHole); - const { - end: targetBufferTime, - len: bufferLen - } = bufferedInfo; - const mainBufferInfo = this.getFwdBufferInfo(this.media, PlaylistLevelType.MAIN); - const trackDetails = track.details; - const maxBufLen = this.getMaxBufferLength(mainBufferInfo == null ? void 0 : mainBufferInfo.len) + trackDetails.levelTargetDuration; - if (bufferLen > maxBufLen) { - return; - } - const fragments = trackDetails.fragments; - const fragLen = fragments.length; - const end = trackDetails.edge; - let foundFrag = null; - const fragPrevious = this.fragPrevious; - if (targetBufferTime < end) { - const tolerance = config.maxFragLookUpTolerance; - const lookupTolerance = targetBufferTime > end - tolerance ? 0 : tolerance; - foundFrag = findFragmentByPTS(fragPrevious, fragments, Math.max(fragments[0].start, targetBufferTime), lookupTolerance); - if (!foundFrag && fragPrevious && fragPrevious.start < fragments[0].start) { - foundFrag = fragments[0]; + for (let i = 0; i < tracks.length; i++) { + const track = tracks[i]; + if (mediaAttributesIdentical(currentTrack.attrs, track.attrs, ['LANGUAGE', 'ASSOC-LANGUAGE', 'CHARACTERISTICS'])) { + return i; } - } else { - foundFrag = fragments[fragLen - 1]; - } - if (!foundFrag) { - return; } - foundFrag = this.mapToInitFragWhenRequired(foundFrag); - if (foundFrag.sn !== 'initSegment') { - // Load earlier fragment in same discontinuity to make up for misaligned playlists and cues that extend beyond end of segment - const curSNIdx = foundFrag.sn - trackDetails.startSN; - const prevFrag = fragments[curSNIdx - 1]; - if (prevFrag && prevFrag.cc === foundFrag.cc && this.fragmentTracker.getState(prevFrag) === FragmentState.NOT_LOADED) { - foundFrag = prevFrag; + for (let i = 0; i < tracks.length; i++) { + const track = tracks[i]; + if (mediaAttributesIdentical(currentTrack.attrs, track.attrs, ['LANGUAGE'])) { + return i; } } - if (this.fragmentTracker.getState(foundFrag) === FragmentState.NOT_LOADED) { - // only load if fragment is not loaded - this.loadFragment(foundFrag, track, targetBufferTime); - } - } - } - getMaxBufferLength(mainBufferLength) { - const maxConfigBuffer = super.getMaxBufferLength(); - if (!mainBufferLength) { - return maxConfigBuffer; - } - return Math.max(maxConfigBuffer, mainBufferLength); - } - loadFragment(frag, level, targetBufferTime) { - this.fragCurrent = frag; - if (frag.sn === 'initSegment') { - this._loadInitSegment(frag, level); - } else { - this.startFragRequested = true; - super.loadFragment(frag, level, targetBufferTime); - } - } - get mediaBufferTimeRanges() { - return new BufferableInstance(this.tracksBuffered[this.currentTrackId] || []); - } -} -class BufferableInstance { - constructor(timeranges) { - this.buffered = void 0; - const getRange = (name, index, length) => { - index = index >>> 0; - if (index > length - 1) { - throw new DOMException(`Failed to execute '${name}' on 'TimeRanges': The index provided (${index}) is greater than the maximum bound (${length})`); - } - return timeranges[index][name]; - }; - this.buffered = { - get length() { - return timeranges.length; - }, - end(index) { - return getRange('end', index, timeranges.length); - }, - start(index) { - return getRange('start', index, timeranges.length); - } - }; - } -} - -class SubtitleTrackController extends BasePlaylistController { - constructor(hls) { - super(hls, '[subtitle-track-controller]'); - this.media = null; - this.tracks = []; - this.groupId = null; - this.tracksInGroup = []; - this.trackId = -1; - this.selectDefaultTrack = true; - this.queuedDefaultTrack = -1; - this.trackChangeListener = () => this.onTextTracksChanged(); - this.asyncPollTrackChange = () => this.pollTrackChange(0); - this.useTextTrackPolling = false; - this.subtitlePollingInterval = -1; - this._subtitleDisplay = true; - this.registerListeners(); - } - destroy() { - this.unregisterListeners(); - this.tracks.length = 0; - this.tracksInGroup.length = 0; - this.trackChangeListener = this.asyncPollTrackChange = null; - super.destroy(); - } - get subtitleDisplay() { - return this._subtitleDisplay; - } - set subtitleDisplay(value) { - this._subtitleDisplay = value; - if (this.trackId > -1) { - this.toggleTrackModes(this.trackId); - } - } - registerListeners() { - const { - hls - } = this; - hls.on(Events.MEDIA_ATTACHED, this.onMediaAttached, this); - hls.on(Events.MEDIA_DETACHING, this.onMediaDetaching, this); - hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this); - hls.on(Events.MANIFEST_PARSED, this.onManifestParsed, this); - hls.on(Events.LEVEL_LOADING, this.onLevelLoading, this); - hls.on(Events.LEVEL_SWITCHING, this.onLevelSwitching, this); - hls.on(Events.SUBTITLE_TRACK_LOADED, this.onSubtitleTrackLoaded, this); - hls.on(Events.ERROR, this.onError, this); - } - unregisterListeners() { - const { - hls - } = this; - hls.off(Events.MEDIA_ATTACHED, this.onMediaAttached, this); - hls.off(Events.MEDIA_DETACHING, this.onMediaDetaching, this); - hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this); - hls.off(Events.MANIFEST_PARSED, this.onManifestParsed, this); - hls.off(Events.LEVEL_LOADING, this.onLevelLoading, this); - hls.off(Events.LEVEL_SWITCHING, this.onLevelSwitching, this); - hls.off(Events.SUBTITLE_TRACK_LOADED, this.onSubtitleTrackLoaded, this); - hls.off(Events.ERROR, this.onError, this); - } - - // Listen for subtitle track change, then extract the current track ID. - onMediaAttached(event, data) { - this.media = data.media; - if (!this.media) { - return; - } - if (this.queuedDefaultTrack > -1) { - this.subtitleTrack = this.queuedDefaultTrack; - this.queuedDefaultTrack = -1; - } - this.useTextTrackPolling = !(this.media.textTracks && 'onchange' in this.media.textTracks); - if (this.useTextTrackPolling) { - this.pollTrackChange(500); - } else { - this.media.textTracks.addEventListener('change', this.asyncPollTrackChange); - } - } - pollTrackChange(timeout) { - self.clearInterval(this.subtitlePollingInterval); - this.subtitlePollingInterval = self.setInterval(this.trackChangeListener, timeout); - } - onMediaDetaching() { - if (!this.media) { - return; - } - self.clearInterval(this.subtitlePollingInterval); - if (!this.useTextTrackPolling) { - this.media.textTracks.removeEventListener('change', this.asyncPollTrackChange); - } - if (this.trackId > -1) { - this.queuedDefaultTrack = this.trackId; - } - const textTracks = filterSubtitleTracks(this.media.textTracks); - // Clear loaded cues on media detachment from tracks - textTracks.forEach(track => { - clearCurrentCues(track); - }); - // Disable all subtitle tracks before detachment so when reattached only tracks in that content are enabled. - this.subtitleTrack = -1; - this.media = null; - } - onManifestLoading() { - this.tracks = []; - this.groupId = null; - this.tracksInGroup = []; - this.trackId = -1; - this.selectDefaultTrack = true; - } - - // Fired whenever a new manifest is loaded. - onManifestParsed(event, data) { - this.tracks = data.subtitleTracks; - } - onSubtitleTrackLoaded(event, data) { - const { - id, - details - } = data; - const { - trackId - } = this; - const currentTrack = this.tracksInGroup[trackId]; - if (!currentTrack) { - this.warn(`Invalid subtitle track id ${id}`); - return; - } - const curDetails = currentTrack.details; - currentTrack.details = data.details; - this.log(`subtitle track ${id} loaded [${details.startSN}-${details.endSN}]`); - if (id === this.trackId) { - this.playlistLoaded(id, data, curDetails); - } - } - onLevelLoading(event, data) { - this.switchLevel(data.level); - } - onLevelSwitching(event, data) { - this.switchLevel(data.level); - } - switchLevel(levelIndex) { - const levelInfo = this.hls.levels[levelIndex]; - if (!(levelInfo != null && levelInfo.textGroupIds)) { - return; - } - const textGroupId = levelInfo.textGroupIds[levelInfo.urlId]; - const lastTrack = this.tracksInGroup ? this.tracksInGroup[this.trackId] : undefined; - if (this.groupId !== textGroupId) { - const subtitleTracks = this.tracks.filter(track => !textGroupId || track.groupId === textGroupId); - this.tracksInGroup = subtitleTracks; - const initialTrackId = this.findTrackId(lastTrack == null ? void 0 : lastTrack.name) || this.findTrackId(); - this.groupId = textGroupId || null; - const subtitleTracksUpdated = { - subtitleTracks - }; - this.log(`Updating subtitle tracks, ${subtitleTracks.length} track(s) found in "${textGroupId}" group-id`); - this.hls.trigger(Events.SUBTITLE_TRACKS_UPDATED, subtitleTracksUpdated); - if (initialTrackId !== -1) { - this.setSubtitleTrack(initialTrackId, lastTrack); - } - } else if (this.shouldReloadPlaylist(lastTrack)) { - // Retry playlist loading if no playlist is or has been loaded yet - this.setSubtitleTrack(this.trackId, lastTrack); } + return -1; } - findTrackId(name) { - const textTracks = this.tracksInGroup; - for (let i = 0; i < textTracks.length; i++) { - const track = textTracks[i]; - if (!this.selectDefaultTrack || track.default) { - if (!name || name === track.name) { - return track.id; + findTrackForTextTrack(textTrack) { + if (textTrack) { + const tracks = this.tracksInGroup; + for (let i = 0; i < tracks.length; i++) { + const track = tracks[i]; + if (subtitleTrackMatchesTextTrack(track, textTrack)) { + return i; } } } @@ -193290,10 +192460,13 @@ class SubtitleTrackController extends BasePlaylistController { if (data.fatal || !data.context) { return; } - if (data.context.type === PlaylistContextType.SUBTITLE_TRACK && data.context.id === this.trackId && data.context.groupId === this.groupId) { + if (data.context.type === PlaylistContextType.SUBTITLE_TRACK && data.context.id === this.trackId && (!this.groupIds || this.groupIds.indexOf(data.context.groupId) !== -1)) { this.checkRetry(data); } } + get allSubtitleTracks() { + return this.tracks; + } /** get alternate subtitle tracks list from playlist **/ get subtitleTracks() { @@ -193306,13 +192479,44 @@ class SubtitleTrackController extends BasePlaylistController { } set subtitleTrack(newId) { this.selectDefaultTrack = false; - const lastTrack = this.tracksInGroup ? this.tracksInGroup[this.trackId] : undefined; - this.setSubtitleTrack(newId, lastTrack); + this.setSubtitleTrack(newId); + } + setSubtitleOption(subtitleOption) { + this.hls.config.subtitlePreference = subtitleOption; + if (subtitleOption) { + const allSubtitleTracks = this.allSubtitleTracks; + this.selectDefaultTrack = false; + if (allSubtitleTracks.length) { + // First see if current option matches (no switch op) + const currentTrack = this.currentTrack; + if (currentTrack && matchesOption(subtitleOption, currentTrack)) { + return currentTrack; + } + // Find option in current group + const groupIndex = findMatchingOption(subtitleOption, this.tracksInGroup); + if (groupIndex > -1) { + const track = this.tracksInGroup[groupIndex]; + this.setSubtitleTrack(groupIndex); + return track; + } else if (currentTrack) { + // If this is not the initial selection return null + // option should have matched one in active group + return null; + } else { + // Find the option in all tracks for initial selection + const allIndex = findMatchingOption(subtitleOption, allSubtitleTracks); + if (allIndex > -1) { + return allSubtitleTracks[allIndex]; + } + } + } + } + return null; } loadPlaylist(hlsUrlParameters) { super.loadPlaylist(); - const currentTrack = this.tracksInGroup[this.trackId]; - if (this.shouldLoadPlaylist(currentTrack)) { + const currentTrack = this.currentTrack; + if (this.shouldLoadPlaylist(currentTrack) && currentTrack) { const id = currentTrack.id; const groupId = currentTrack.groupId; let url = currentTrack.url; @@ -193338,29 +192542,32 @@ class SubtitleTrackController extends BasePlaylistController { * This operates on the DOM textTracks. * A value of -1 will disable all subtitle tracks. */ - toggleTrackModes(newId) { + toggleTrackModes() { const { - media, - trackId + media } = this; if (!media) { return; } const textTracks = filterSubtitleTracks(media.textTracks); - const groupTracks = textTracks.filter(track => track.groupId === this.groupId); - if (newId === -1) { - [].slice.call(textTracks).forEach(track => { - track.mode = 'disabled'; - }); - } else { - const oldTrack = groupTracks[trackId]; - if (oldTrack) { - oldTrack.mode = 'disabled'; + const currentTrack = this.currentTrack; + let nextTrack; + if (currentTrack) { + nextTrack = textTracks.filter(textTrack => subtitleTrackMatchesTextTrack(currentTrack, textTrack))[0]; + if (!nextTrack) { + this.warn(`Unable to find subtitle TextTrack with name "${currentTrack.name}" and language "${currentTrack.lang}"`); } } - const nextTrack = groupTracks[newId]; + [].slice.call(textTracks).forEach(track => { + if (track.mode !== 'disabled' && track !== nextTrack) { + track.mode = 'disabled'; + } + }); if (nextTrack) { - nextTrack.mode = this.subtitleDisplay ? 'showing' : 'hidden'; + const mode = this.subtitleDisplay ? 'showing' : 'hidden'; + if (nextTrack.mode !== mode) { + nextTrack.mode = mode; + } } } @@ -193368,8 +192575,7 @@ class SubtitleTrackController extends BasePlaylistController { * This method is responsible for validating the subtitle index and periodically reloading if live. * Dispatches the SUBTITLE_TRACK_SWITCH event, which instructs the subtitle-stream-controller to load the selected track. */ - setSubtitleTrack(newId, lastTrack) { - var _tracks$newId; + setSubtitleTrack(newId) { const tracks = this.tracksInGroup; // setting this.subtitleTrack will trigger internal logic @@ -193380,43 +192586,49 @@ class SubtitleTrackController extends BasePlaylistController { this.queuedDefaultTrack = newId; return; } - if (this.trackId !== newId) { - this.toggleTrackModes(newId); - } // exit if track id as already set or invalid - if (this.trackId === newId && (newId === -1 || (_tracks$newId = tracks[newId]) != null && _tracks$newId.details) || newId < -1 || newId >= tracks.length) { + if (newId < -1 || newId >= tracks.length) { + this.warn(`Invalid subtitle track id: ${newId}`); return; } // stopping live reloading timer if any this.clearTimer(); - const track = tracks[newId]; - this.log(`Switching to subtitle-track ${newId}` + (track ? ` "${track.name}" lang:${track.lang} group:${track.groupId}` : '')); + this.selectDefaultTrack = false; + const lastTrack = this.currentTrack; + const track = tracks[newId] || null; this.trackId = newId; - if (track) { - const { - id, - groupId = '', - name, - type, - url - } = track; - this.hls.trigger(Events.SUBTITLE_TRACK_SWITCH, { - id, - groupId, - name, - type, - url - }); - const hlsUrlParameters = this.switchParams(track.url, lastTrack == null ? void 0 : lastTrack.details); - this.loadPlaylist(hlsUrlParameters); - } else { + this.currentTrack = track; + this.toggleTrackModes(); + if (!track) { // switch to -1 this.hls.trigger(Events.SUBTITLE_TRACK_SWITCH, { id: newId }); + return; + } + const trackLoaded = track.details && !track.details.live; + if (newId === this.trackId && track === lastTrack && trackLoaded) { + return; } + this.log(`Switching to subtitle-track ${newId}` + (track ? ` "${track.name}" lang:${track.lang} group:${track.groupId}` : '')); + const { + id, + groupId = '', + name, + type, + url + } = track; + this.hls.trigger(Events.SUBTITLE_TRACK_SWITCH, { + id, + groupId, + name, + type, + url + }); + const hlsUrlParameters = this.switchParams(track.url, lastTrack == null ? void 0 : lastTrack.details); + this.loadPlaylist(hlsUrlParameters); } onTextTracksChanged() { if (!this.useTextTrackPolling) { @@ -193426,35 +192638,25 @@ class SubtitleTrackController extends BasePlaylistController { if (!this.media || !this.hls.config.renderTextTracksNatively) { return; } - let trackId = -1; + let textTrack = null; const tracks = filterSubtitleTracks(this.media.textTracks); - for (let id = 0; id < tracks.length; id++) { - if (tracks[id].mode === 'hidden') { + for (let i = 0; i < tracks.length; i++) { + if (tracks[i].mode === 'hidden') { // Do not break in case there is a following track with showing. - trackId = id; - } else if (tracks[id].mode === 'showing') { - trackId = id; + textTrack = tracks[i]; + } else if (tracks[i].mode === 'showing') { + textTrack = tracks[i]; break; } } - // Setting current subtitleTrack will invoke code. + // Find internal track index for TextTrack + const trackId = this.findTrackForTextTrack(textTrack); if (this.subtitleTrack !== trackId) { - this.subtitleTrack = trackId; + this.setSubtitleTrack(trackId); } } } -function filterSubtitleTracks(textTrackList) { - const tracks = []; - for (let i = 0; i < textTrackList.length; i++) { - const track = textTrackList[i]; - // Edge adds a track without a label; we don't want to use it - if ((track.kind === 'subtitles' || track.kind === 'captions') && track.label) { - tracks.push(textTrackList[i]); - } - } - return tracks; -} class BufferOperationQueue { constructor(sourceBufferReference) { @@ -193466,10 +192668,10 @@ class BufferOperationQueue { }; this.buffers = sourceBufferReference; } - append(operation, type) { + append(operation, type, pending) { const queue = this.queues[type]; queue.push(operation); - if (queue.length === 1 && this.buffers[type]) { + if (queue.length === 1 && !pending) { this.executeNext(type); } } @@ -193493,26 +192695,21 @@ class BufferOperationQueue { return promise; } executeNext(type) { - const { - buffers, - queues - } = this; - const sb = buffers[type]; - const queue = queues[type]; + const queue = this.queues[type]; if (queue.length) { const operation = queue[0]; try { // Operations are expected to result in an 'updateend' event being fired. If not, the queue will lock. Operations // which do not end with this event must call _onSBUpdateEnd manually operation.execute(); - } catch (e) { - logger.warn('[buffer-operation-queue]: Unhandled exception executing the current operation'); - operation.onError(e); + } catch (error) { + logger.warn(`[buffer-operation-queue]: Exception executing "${type}" SourceBuffer operation: ${error}`); + operation.onError(error); // Only shift the current operation off, otherwise the updateend handler will do this for us + const sb = this.buffers[type]; if (!(sb != null && sb.updating)) { - queue.shift(); - this.executeNext(type); + this.shiftAndExecuteNext(type); } } } @@ -193526,56 +192723,66 @@ class BufferOperationQueue { } } -const MediaSource = getMediaSource(); -const VIDEO_CODEC_PROFILE_REPACE = /([ha]vc.)(?:\.[^.,]+)+/; +const VIDEO_CODEC_PROFILE_REPLACE = /(avc[1234]|hvc1|hev1|dvh[1e]|vp09|av01)(?:\.[^.,]+)+/; class BufferController { - // The level details used to determine duration, target-duration and live - - // cache the self generated object url to detect hijack of video tag - - // A queue of buffer operations which require the SourceBuffer to not be updating upon execution - - // References to event listeners for each SourceBuffer, so that they can be referenced for event removal - - // The number of BUFFER_CODEC events received before any sourceBuffers are created - - // The total number of BUFFER_CODEC events received - - // A reference to the attached media element - - // A reference to the active media source - - // Last MP3 audio chunk appended - - // counters - constructor(hls) { + // The level details used to determine duration, target-duration and live this.details = null; + // cache the self generated object url to detect hijack of video tag this._objectUrl = null; + // A queue of buffer operations which require the SourceBuffer to not be updating upon execution this.operationQueue = void 0; + // References to event listeners for each SourceBuffer, so that they can be referenced for event removal this.listeners = void 0; this.hls = void 0; + // The number of BUFFER_CODEC events received before any sourceBuffers are created this.bufferCodecEventsExpected = 0; + // The total number of BUFFER_CODEC events received this._bufferCodecEventsTotal = 0; + // A reference to the attached media element this.media = null; + // A reference to the active media source this.mediaSource = null; + // Last MP3 audio chunk appended this.lastMpegAudioChunk = null; - this.appendError = 0; + this.appendSource = void 0; + // counters + this.appendErrors = { + audio: 0, + video: 0, + audiovideo: 0 + }; this.tracks = {}; this.pendingTracks = {}; this.sourceBuffer = void 0; + this.log = void 0; + this.warn = void 0; + this.error = void 0; + this._onEndStreaming = event => { + if (!this.hls) { + return; + } + this.hls.pauseBuffering(); + }; + this._onStartStreaming = event => { + if (!this.hls) { + return; + } + this.hls.resumeBuffering(); + }; // Keep as arrow functions so that we can directly reference these functions directly as event listeners this._onMediaSourceOpen = () => { const { media, mediaSource } = this; - logger.log('[buffer-controller]: Media source opened'); + this.log('Media source opened'); if (media) { media.removeEventListener('emptied', this._onMediaEmptied); this.updateMediaElementDuration(); this.hls.trigger(Events.MEDIA_ATTACHED, { - media + media, + mediaSource: mediaSource }); } if (mediaSource) { @@ -193585,21 +192792,26 @@ class BufferController { this.checkPendingTracks(); }; this._onMediaSourceClose = () => { - logger.log('[buffer-controller]: Media source closed'); + this.log('Media source closed'); }; this._onMediaSourceEnded = () => { - logger.log('[buffer-controller]: Media source ended'); + this.log('Media source ended'); }; this._onMediaEmptied = () => { const { - media, + mediaSrc, _objectUrl } = this; - if (media && media.src !== _objectUrl) { - logger.error(`Media element src was set while attaching MediaSource (${_objectUrl} > ${media.src})`); + if (mediaSrc !== _objectUrl) { + logger.error(`Media element src was set while attaching MediaSource (${_objectUrl} > ${mediaSrc})`); } }; this.hls = hls; + const logPrefix = '[buffer-controller]'; + this.appendSource = hls.config.preferManagedMediaSource; + this.log = logger.log.bind(logger, logPrefix); + this.warn = logger.warn.bind(logger, logPrefix); + this.error = logger.error.bind(logger, logPrefix); this._initSourceBuffer(); this.registerListeners(); } @@ -193610,6 +192822,8 @@ class BufferController { this.unregisterListeners(); this.details = null; this.lastMpegAudioChunk = null; + // @ts-ignore + this.hls = null; } registerListeners() { const { @@ -193653,6 +192867,11 @@ class BufferController { video: [], audiovideo: [] }; + this.appendErrors = { + audio: 0, + video: 0, + audiovideo: 0 + }; this.lastMpegAudioChunk = null; } onManifestLoading() { @@ -193669,20 +192888,40 @@ class BufferController { codecEvents = 1; } this.bufferCodecEventsExpected = this._bufferCodecEventsTotal = codecEvents; - logger.log(`${this.bufferCodecEventsExpected} bufferCodec event(s) expected`); + this.log(`${this.bufferCodecEventsExpected} bufferCodec event(s) expected`); } onMediaAttaching(event, data) { const media = this.media = data.media; + const MediaSource = getMediaSource(this.appendSource); if (media && MediaSource) { + var _ms$constructor; const ms = this.mediaSource = new MediaSource(); + this.log(`created media source: ${(_ms$constructor = ms.constructor) == null ? void 0 : _ms$constructor.name}`); // MediaSource listeners are arrow functions with a lexical scope, and do not need to be bound ms.addEventListener('sourceopen', this._onMediaSourceOpen); ms.addEventListener('sourceended', this._onMediaSourceEnded); ms.addEventListener('sourceclose', this._onMediaSourceClose); - // link video and media Source - media.src = self.URL.createObjectURL(ms); + ms.addEventListener('startstreaming', this._onStartStreaming); + ms.addEventListener('endstreaming', this._onEndStreaming); + // cache the locally generated object url - this._objectUrl = media.src; + const objectUrl = this._objectUrl = self.URL.createObjectURL(ms); + // link video and media Source + if (this.appendSource) { + try { + media.removeAttribute('src'); + // ManagedMediaSource will not open without disableRemotePlayback set to false or source alternatives + const MMS = self.ManagedMediaSource; + media.disableRemotePlayback = media.disableRemotePlayback || MMS && ms instanceof MMS; + removeSourceChildren(media); + addSource(media, objectUrl); + media.load(); + } catch (error) { + media.src = objectUrl; + } + } else { + media.src = objectUrl; + } media.addEventListener('emptied', this._onMediaEmptied); } } @@ -193693,7 +192932,7 @@ class BufferController { _objectUrl } = this; if (mediaSource) { - logger.log('[buffer-controller]: media source detaching'); + this.log('media source detaching'); if (mediaSource.readyState === 'open') { try { // endOfStream could trigger exception if any sourcebuffer is in updating state @@ -193702,7 +192941,7 @@ class BufferController { // let's just avoid this exception to propagate mediaSource.endOfStream(); } catch (err) { - logger.warn(`[buffer-controller]: onMediaDetaching: ${err.message} while calling endOfStream`); + this.warn(`onMediaDetaching: ${err.message} while calling endOfStream`); } } // Clean up the SourceBuffers by invoking onBufferReset @@ -193710,6 +192949,8 @@ class BufferController { mediaSource.removeEventListener('sourceopen', this._onMediaSourceOpen); mediaSource.removeEventListener('sourceended', this._onMediaSourceEnded); mediaSource.removeEventListener('sourceclose', this._onMediaSourceClose); + mediaSource.removeEventListener('startstreaming', this._onStartStreaming); + mediaSource.removeEventListener('endstreaming', this._onEndStreaming); // Detach properly the MediaSource from the HTMLMediaElement as // suggested in https://github.com/w3c/media-source/issues/53. @@ -193721,11 +192962,14 @@ class BufferController { // clean up video tag src only if it's our own url. some external libraries might // hijack the video tag and change its 'src' without destroying the Hls instance first - if (media.src === _objectUrl) { + if (this.mediaSrc === _objectUrl) { media.removeAttribute('src'); + if (this.appendSource) { + removeSourceChildren(media); + } media.load(); } else { - logger.warn('[buffer-controller]: media.src was changed by a third party - skip cleanup'); + this.warn('media|source.src was changed by a third party - skip cleanup'); } } this.mediaSource = null; @@ -193739,30 +192983,36 @@ class BufferController { } onBufferReset() { this.getSourceBufferTypes().forEach(type => { - const sb = this.sourceBuffer[type]; - try { - if (sb) { - this.removeBufferListeners(type); - if (this.mediaSource) { - this.mediaSource.removeSourceBuffer(sb); - } - // Synchronously remove the SB from the map before the next call in order to prevent an async function from - // accessing it - this.sourceBuffer[type] = undefined; - } - } catch (err) { - logger.warn(`[buffer-controller]: Failed to reset the ${type} buffer`, err); - } + this.resetBuffer(type); }); this._initSourceBuffer(); } + resetBuffer(type) { + const sb = this.sourceBuffer[type]; + try { + if (sb) { + var _this$mediaSource; + this.removeBufferListeners(type); + // Synchronously remove the SB from the map before the next call in order to prevent an async function from + // accessing it + this.sourceBuffer[type] = undefined; + if ((_this$mediaSource = this.mediaSource) != null && _this$mediaSource.sourceBuffers.length) { + this.mediaSource.removeSourceBuffer(sb); + } + } + } catch (err) { + this.warn(`onBufferReset ${type}`, err); + } + } onBufferCodecs(event, data) { const sourceBufferCount = this.getSourceBufferTypes().length; - Object.keys(data).forEach(trackName => { + const trackNames = Object.keys(data); + trackNames.forEach(trackName => { if (sourceBufferCount) { // check if SourceBuffer codec needs to change const track = this.tracks[trackName]; if (track && typeof track.buffer.changeType === 'function') { + var _trackCodec; const { id, codec, @@ -193770,12 +193020,17 @@ class BufferController { container, metadata } = data[trackName]; - const currentCodec = (track.levelCodec || track.codec).replace(VIDEO_CODEC_PROFILE_REPACE, '$1'); - const nextCodec = (levelCodec || codec).replace(VIDEO_CODEC_PROFILE_REPACE, '$1'); - if (currentCodec !== nextCodec) { - const mimeType = `${container};codecs=${levelCodec || codec}`; + const currentCodecFull = pickMostCompleteCodecName(track.codec, track.levelCodec); + const currentCodec = currentCodecFull == null ? void 0 : currentCodecFull.replace(VIDEO_CODEC_PROFILE_REPLACE, '$1'); + let trackCodec = pickMostCompleteCodecName(codec, levelCodec); + const nextCodec = (_trackCodec = trackCodec) == null ? void 0 : _trackCodec.replace(VIDEO_CODEC_PROFILE_REPLACE, '$1'); + if (trackCodec && currentCodec !== nextCodec) { + if (trackName.slice(0, 5) === 'audio') { + trackCodec = getCodecCompatibleName(trackCodec, this.hls.config.preferManagedMediaSource); + } + const mimeType = `${container};codecs=${trackCodec}`; this.appendChangeType(trackName, mimeType); - logger.log(`[buffer-controller]: switching codec ${currentCodec} to ${nextCodec}`); + this.log(`switching codec ${currentCodecFull} to ${trackCodec}`); this.tracks[trackName] = { buffer: track.buffer, codec, @@ -193796,7 +193051,11 @@ class BufferController { if (sourceBufferCount) { return; } - this.bufferCodecEventsExpected = Math.max(this.bufferCodecEventsExpected - 1, 0); + const bufferCodecEventsExpected = Math.max(this.bufferCodecEventsExpected - 1, 0); + if (this.bufferCodecEventsExpected !== bufferCodecEventsExpected) { + this.log(`${bufferCodecEventsExpected} bufferCodec event(s) expected ${trackNames.join(',')}`); + this.bufferCodecEventsExpected = bufferCodecEventsExpected; + } if (this.mediaSource && this.mediaSource.readyState === 'open') { this.checkPendingTracks(); } @@ -193809,18 +193068,18 @@ class BufferController { execute: () => { const sb = this.sourceBuffer[type]; if (sb) { - logger.log(`[buffer-controller]: changing ${type} sourceBuffer type to ${mimeType}`); + this.log(`changing ${type} sourceBuffer type to ${mimeType}`); sb.changeType(mimeType); } operationQueue.shiftAndExecuteNext(type); }, onStart: () => {}, onComplete: () => {}, - onError: e => { - logger.warn(`[buffer-controller]: Failed to change ${type} SourceBuffer type`, e); + onError: error => { + this.warn(`Failed to change ${type} SourceBuffer type`, error); } }; - operationQueue.append(operation, type); + operationQueue.append(operation, type, !!this.pendingTracks[type]); } onBufferAppending(event, eventData) { const { @@ -193867,7 +193126,7 @@ class BufferController { if (sb) { const delta = fragStart - sb.timestampOffset; if (Math.abs(delta) >= 0.1) { - logger.log(`[buffer-controller]: Updating audio SourceBuffer timestampOffset to ${fragStart} (delta: ${delta}) sn: ${frag.sn})`); + this.log(`Updating audio SourceBuffer timestampOffset to ${fragStart} (delta: ${delta}) sn: ${frag.sn})`); sb.timestampOffset = fragStart; } } @@ -193894,7 +193153,13 @@ class BufferController { for (const type in sourceBuffer) { timeRanges[type] = BufferHelper.getBuffered(sourceBuffer[type]); } - this.appendError = 0; + this.appendErrors[type] = 0; + if (type === 'audio' || type === 'video') { + this.appendErrors.audiovideo = 0; + } else { + this.appendErrors.audio = 0; + this.appendErrors.video = 0; + } this.hls.trigger(Events.BUFFER_APPENDED, { type, frag, @@ -193904,39 +193169,39 @@ class BufferController { timeRanges }); }, - onError: err => { + onError: error => { // in case any error occured while appending, put back segment in segments table - logger.error(`[buffer-controller]: Error encountered while trying to append to the ${type} SourceBuffer`, err); const event = { type: ErrorTypes.MEDIA_ERROR, parent: frag.type, details: ErrorDetails.BUFFER_APPEND_ERROR, + sourceBufferName: type, frag, part, chunkMeta, - error: err, - err, + error, + err: error, fatal: false }; - if (err.code === DOMException.QUOTA_EXCEEDED_ERR) { + if (error.code === DOMException.QUOTA_EXCEEDED_ERR) { // QuotaExceededError: http://www.w3.org/TR/html5/infrastructure.html#quotaexceedederror // let's stop appending any segments, and report BUFFER_FULL_ERROR error event.details = ErrorDetails.BUFFER_FULL_ERROR; } else { - this.appendError++; + const appendErrorCount = ++this.appendErrors[type]; event.details = ErrorDetails.BUFFER_APPEND_ERROR; /* with UHD content, we could get loop of quota exceeded error until browser is able to evict some data from sourcebuffer. Retrying can help recover. */ - if (this.appendError > hls.config.appendErrorMaxRetry) { - logger.error(`[buffer-controller]: Failed ${hls.config.appendErrorMaxRetry} times to append segment in sourceBuffer`); + this.warn(`Failed ${appendErrorCount}/${hls.config.appendErrorMaxRetry} times to append segment in "${type}" sourceBuffer`); + if (appendErrorCount >= hls.config.appendErrorMaxRetry) { event.fatal = true; } } hls.trigger(Events.ERROR, event); } }; - operationQueue.append(operation, type); + operationQueue.append(operation, type, !!this.pendingTracks[type]); } onBufferFlushing(event, data) { const { @@ -193953,8 +193218,8 @@ class BufferController { type }); }, - onError: e => { - logger.warn(`[buffer-controller]: Failed to remove from ${type} SourceBuffer`, e); + onError: error => { + this.warn(`Failed to remove from ${type} SourceBuffer`, error); } }); if (data.type) { @@ -193997,12 +193262,12 @@ class BufferController { }); }; if (buffersAppendedTo.length === 0) { - logger.warn(`Fragments must have at least one ElementaryStreamType set. type: ${frag.type} level: ${frag.level} sn: ${frag.sn}`); + this.warn(`Fragments must have at least one ElementaryStreamType set. type: ${frag.type} level: ${frag.level} sn: ${frag.sn}`); } this.blockBuffers(onUnblocked, buffersAppendedTo); } onFragChanged(event, data) { - this.flushBackBuffer(); + this.trimBuffers(); } // on BUFFER_EOS mark matching sourcebuffer(s) as ended and trigger checkEos() @@ -194014,13 +193279,13 @@ class BufferController { sb.ending = true; if (!sb.ended) { sb.ended = true; - logger.log(`[buffer-controller]: ${type} sourceBuffer now EOS`); + this.log(`${type} sourceBuffer now EOS`); } } return acc && !!(!sb || sb.ended); }, true); if (ended) { - logger.log(`[buffer-controller]: Queueing mediaSource.endOfStream()`); + this.log(`Queueing mediaSource.endOfStream()`); this.blockBuffers(() => { this.getSourceBufferTypes().forEach(type => { const sb = this.sourceBuffer[type]; @@ -194033,11 +193298,11 @@ class BufferController { } = this; if (!mediaSource || mediaSource.readyState !== 'open') { if (mediaSource) { - logger.info(`[buffer-controller]: Could not call mediaSource.endOfStream(). mediaSource.readyState: ${mediaSource.readyState}`); + this.log(`Could not call mediaSource.endOfStream(). mediaSource.readyState: ${mediaSource.readyState}`); } return; } - logger.log(`[buffer-controller]: Calling mediaSource.endOfStream()`); + this.log(`Calling mediaSource.endOfStream()`); // Allow this to throw and be caught by the enqueueing function mediaSource.endOfStream(); }); @@ -194056,12 +193321,11 @@ class BufferController { this.updateMediaElementDuration(); } } - flushBackBuffer() { + trimBuffers() { const { hls, details, - media, - sourceBuffer + media } = this; if (!media || details === null) { return; @@ -194070,36 +193334,50 @@ class BufferController { if (!sourceBufferTypes.length) { return; } + const config = hls.config; + const currentTime = media.currentTime; + const targetDuration = details.levelTargetDuration; // Support for deprecated liveBackBufferLength - const backBufferLength = details.live && hls.config.liveBackBufferLength !== null ? hls.config.liveBackBufferLength : hls.config.backBufferLength; - if (!isFiniteNumber(backBufferLength) || backBufferLength < 0) { - return; + const backBufferLength = details.live && config.liveBackBufferLength !== null ? config.liveBackBufferLength : config.backBufferLength; + if (isFiniteNumber(backBufferLength) && backBufferLength > 0) { + const maxBackBufferLength = Math.max(backBufferLength, targetDuration); + const targetBackBufferPosition = Math.floor(currentTime / targetDuration) * targetDuration - maxBackBufferLength; + this.flushBackBuffer(currentTime, targetDuration, targetBackBufferPosition); } - const currentTime = media.currentTime; - const targetDuration = details.levelTargetDuration; - const maxBackBufferLength = Math.max(backBufferLength, targetDuration); - const targetBackBufferPosition = Math.floor(currentTime / targetDuration) * targetDuration - maxBackBufferLength; + if (isFiniteNumber(config.frontBufferFlushThreshold) && config.frontBufferFlushThreshold > 0) { + const frontBufferLength = Math.max(config.maxBufferLength, config.frontBufferFlushThreshold); + const maxFrontBufferLength = Math.max(frontBufferLength, targetDuration); + const targetFrontBufferPosition = Math.floor(currentTime / targetDuration) * targetDuration + maxFrontBufferLength; + this.flushFrontBuffer(currentTime, targetDuration, targetFrontBufferPosition); + } + } + flushBackBuffer(currentTime, targetDuration, targetBackBufferPosition) { + const { + details, + sourceBuffer + } = this; + const sourceBufferTypes = this.getSourceBufferTypes(); sourceBufferTypes.forEach(type => { const sb = sourceBuffer[type]; if (sb) { const buffered = BufferHelper.getBuffered(sb); // when target buffer start exceeds actual buffer start if (buffered.length > 0 && targetBackBufferPosition > buffered.start(0)) { - hls.trigger(Events.BACK_BUFFER_REACHED, { + this.hls.trigger(Events.BACK_BUFFER_REACHED, { bufferEnd: targetBackBufferPosition }); // Support for deprecated event: - if (details.live) { - hls.trigger(Events.LIVE_BACK_BUFFER_REACHED, { + if (details != null && details.live) { + this.hls.trigger(Events.LIVE_BACK_BUFFER_REACHED, { bufferEnd: targetBackBufferPosition }); } else if (sb.ended && buffered.end(buffered.length - 1) - currentTime < targetDuration * 2) { - logger.info(`[buffer-controller]: Cannot flush ${type} back buffer while SourceBuffer is in ended state`); + this.log(`Cannot flush ${type} back buffer while SourceBuffer is in ended state`); return; } - hls.trigger(Events.BUFFER_FLUSHING, { + this.hls.trigger(Events.BUFFER_FLUSHING, { startOffset: 0, endOffset: targetBackBufferPosition, type @@ -194108,6 +193386,37 @@ class BufferController { } }); } + flushFrontBuffer(currentTime, targetDuration, targetFrontBufferPosition) { + const { + sourceBuffer + } = this; + const sourceBufferTypes = this.getSourceBufferTypes(); + sourceBufferTypes.forEach(type => { + const sb = sourceBuffer[type]; + if (sb) { + const buffered = BufferHelper.getBuffered(sb); + const numBufferedRanges = buffered.length; + // The buffer is either empty or contiguous + if (numBufferedRanges < 2) { + return; + } + const bufferStart = buffered.start(numBufferedRanges - 1); + const bufferEnd = buffered.end(numBufferedRanges - 1); + // No flush if we can tolerate the current buffer length or the current buffer range we would flush is contiguous with current position + if (targetFrontBufferPosition > bufferStart || currentTime >= bufferStart && currentTime <= bufferEnd) { + return; + } else if (sb.ended && currentTime - bufferEnd < 2 * targetDuration) { + this.log(`Cannot flush ${type} front buffer while SourceBuffer is in ended state`); + return; + } + this.hls.trigger(Events.BUFFER_FLUSHING, { + startOffset: bufferStart, + endOffset: Infinity, + type + }); + } + }); + } /** * Update Media Source duration to current level duration or override to Infinity if configuration parameter @@ -194129,7 +193438,6 @@ class BufferController { const msDuration = isFiniteNumber(mediaSource.duration) ? mediaSource.duration : 0; if (details.live && hls.config.liveDurationInfinity) { // Override duration to Infinity - logger.log('[buffer-controller]: Media Source duration is set to Infinity'); mediaSource.duration = Infinity; this.updateSeekableRange(details); } else if (levelDuration > msDuration && levelDuration > mediaDuration || !isFiniteNumber(mediaDuration)) { @@ -194137,7 +193445,7 @@ class BufferController { // not using mediaSource.duration as the browser may tweak this value // only update Media Source duration if its value increase, this is to avoid // flushing already buffered portion when switching between quality level - logger.log(`[buffer-controller]: Updating Media Source duration to ${levelDuration.toFixed(3)}`); + this.log(`Updating Media Source duration to ${levelDuration.toFixed(3)}`); mediaSource.duration = levelDuration; } } @@ -194148,6 +193456,7 @@ class BufferController { if (len && levelDetails.live && mediaSource != null && mediaSource.setLiveSeekableRange) { const start = Math.max(0, fragments[0].start); const end = Math.max(start, start + levelDetails.totalduration); + this.log(`Media Source duration is set to ${mediaSource.duration}. Setting seekable range to ${start}-${end}.`); mediaSource.setLiveSeekableRange(start, end); } } @@ -194163,7 +193472,7 @@ class BufferController { // data has been appended to existing ones. // 2 tracks is the max (one for audio, one for video). If we've reach this max go ahead and create the buffers. const pendingTracksCount = Object.keys(pendingTracks).length; - if (pendingTracksCount && !bufferCodecEventsExpected || pendingTracksCount === 2) { + if (pendingTracksCount && (!bufferCodecEventsExpected || pendingTracksCount === 2 || 'audiovideo' in pendingTracks)) { // ok, let's create them now ! this.createSourceBuffers(pendingTracks); this.pendingTracks = {}; @@ -194203,15 +193512,30 @@ class BufferController { throw Error(`source buffer exists for track ${trackName}, however track does not`); } // use levelCodec as first priority - const codec = track.levelCodec || track.codec; + let codec = track.levelCodec || track.codec; + if (codec) { + if (trackName.slice(0, 5) === 'audio') { + codec = getCodecCompatibleName(codec, this.hls.config.preferManagedMediaSource); + } + } const mimeType = `${track.container};codecs=${codec}`; - logger.log(`[buffer-controller]: creating sourceBuffer(${mimeType})`); + this.log(`creating sourceBuffer(${mimeType})`); try { const sb = sourceBuffer[trackName] = mediaSource.addSourceBuffer(mimeType); const sbName = trackName; this.addBufferListener(sbName, 'updatestart', this._onSBUpdateStart); this.addBufferListener(sbName, 'updateend', this._onSBUpdateEnd); this.addBufferListener(sbName, 'error', this._onSBUpdateError); + // ManagedSourceBuffer bufferedchange event + this.addBufferListener(sbName, 'bufferedchange', (type, event) => { + // If media was ejected check for a change. Added ranges are redundant with changes on 'updateend' event. + const removedRanges = event.removedRanges; + if (removedRanges != null && removedRanges.length) { + this.hls.trigger(Events.BUFFER_FLUSHED, { + type: trackName + }); + } + }); this.tracks[trackName] = { buffer: sb, codec: codec, @@ -194221,18 +193545,24 @@ class BufferController { id: track.id }; } catch (err) { - logger.error(`[buffer-controller]: error while trying to add sourceBuffer: ${err.message}`); + this.error(`error while trying to add sourceBuffer: ${err.message}`); this.hls.trigger(Events.ERROR, { type: ErrorTypes.MEDIA_ERROR, details: ErrorDetails.BUFFER_ADD_CODEC_ERROR, fatal: false, error: err, + sourceBufferName: trackName, mimeType: mimeType }); } } } } + get mediaSrc() { + var _this$media; + const media = ((_this$media = this.media) == null ? void 0 : _this$media.firstChild) || this.media; + return media == null ? void 0 : media.src; + } _onSBUpdateStart(type) { const { operationQueue @@ -194241,6 +193571,11 @@ class BufferController { operation.onStart(); } _onSBUpdateEnd(type) { + var _this$mediaSource2; + if (((_this$mediaSource2 = this.mediaSource) == null ? void 0 : _this$mediaSource2.readyState) === 'closed') { + this.resetBuffer(type); + return; + } const { operationQueue } = this; @@ -194249,20 +193584,22 @@ class BufferController { operationQueue.shiftAndExecuteNext(type); } _onSBUpdateError(type, event) { - const error = new Error(`${type} SourceBuffer error`); - logger.error(`[buffer-controller]: ${error}`, event); + var _this$mediaSource3; + const error = new Error(`${type} SourceBuffer error. MediaSource readyState: ${(_this$mediaSource3 = this.mediaSource) == null ? void 0 : _this$mediaSource3.readyState}`); + this.error(`${error}`, event); // according to http://www.w3.org/TR/media-source/#sourcebuffer-append-error // SourceBuffer errors are not necessarily fatal; if so, the HTMLMediaElement will fire an error event this.hls.trigger(Events.ERROR, { type: ErrorTypes.MEDIA_ERROR, details: ErrorDetails.BUFFER_APPENDING_ERROR, + sourceBufferName: type, error, fatal: false }); // updateend is always fired after error, so we'll allow that to shift the current operation off of the queue const operation = this.operationQueue.current(type); if (operation) { - operation.onError(event); + operation.onError(error); } } @@ -194276,7 +193613,7 @@ class BufferController { } = this; const sb = sourceBuffer[type]; if (!media || !mediaSource || !sb) { - logger.warn(`[buffer-controller]: Attempting to remove from the ${type} SourceBuffer, but it does not exist`); + this.warn(`Attempting to remove from the ${type} SourceBuffer, but it does not exist`); operationQueue.shiftAndExecuteNext(type); return; } @@ -194284,9 +193621,9 @@ class BufferController { const msDuration = isFiniteNumber(mediaSource.duration) ? mediaSource.duration : Infinity; const removeStart = Math.max(0, startOffset); const removeEnd = Math.min(endOffset, mediaDuration, msDuration); - if (removeEnd > removeStart && !sb.ending) { + if (removeEnd > removeStart && (!sb.ending || sb.ended)) { sb.ended = false; - logger.log(`[buffer-controller]: Removing [${removeStart},${removeEnd}] from the ${type} SourceBuffer`); + this.log(`Removing [${removeStart},${removeEnd}] from the ${type} SourceBuffer`); sb.remove(removeStart, removeEnd); } else { // Cycle the queue @@ -194296,14 +193633,11 @@ class BufferController { // This method must result in an updateend event; if append is not called, _onSBUpdateEnd must be called manually appendExecutor(data, type) { - const { - operationQueue, - sourceBuffer - } = this; - const sb = sourceBuffer[type]; + const sb = this.sourceBuffer[type]; if (!sb) { - logger.warn(`[buffer-controller]: Attempting to append to the ${type} SourceBuffer, but it does not exist`); - operationQueue.shiftAndExecuteNext(type); + if (!this.pendingTracks[type]) { + throw new Error(`Attempting to append to the ${type} SourceBuffer, but it does not exist`); + } return; } sb.ended = false; @@ -194315,7 +193649,7 @@ class BufferController { // upon completion, since we already do it here blockBuffers(onUnblocked, buffers = this.getSourceBufferTypes()) { if (!buffers.length) { - logger.log('[buffer-controller]: Blocking operation requested, but no SourceBuffers exist'); + this.log('Blocking operation requested, but no SourceBuffers exist'); Promise.resolve().then(onUnblocked); return; } @@ -194364,6 +193698,18 @@ class BufferController { }); } } +function removeSourceChildren(node) { + const sourceChildren = node.querySelectorAll('source'); + [].slice.call(sourceChildren).forEach(source => { + node.removeChild(source); + }); +} +function addSource(media, url) { + const source = self.document.createElement('source'); + source.type = 'video/mp4'; + source.src = url; + media.appendChild(source); +} /** * @@ -194667,17 +194013,12 @@ const numArrayToHexArray = function numArrayToHexArray(numArray) { return hexArray; }; class PenState { - constructor(foreground, underline, italics, background, flash) { - this.foreground = void 0; - this.underline = void 0; - this.italics = void 0; - this.background = void 0; - this.flash = void 0; - this.foreground = foreground || 'white'; - this.underline = underline || false; - this.italics = italics || false; - this.background = background || 'black'; - this.flash = flash || false; + constructor() { + this.foreground = 'white'; + this.underline = false; + this.italics = false; + this.background = 'black'; + this.flash = false; } reset() { this.foreground = 'white'; @@ -194718,11 +194059,9 @@ class PenState { * @constructor */ class StyledUnicodeChar { - constructor(uchar, foreground, underline, italics, background, flash) { - this.uchar = void 0; - this.penState = void 0; - this.uchar = uchar || ' '; // unicode character - this.penState = new PenState(foreground, underline, italics, background, flash); + constructor() { + this.uchar = ' '; + this.penState = new PenState(); } reset() { this.uchar = ' '; @@ -194753,28 +194092,23 @@ class StyledUnicodeChar { */ class Row { constructor(logger) { - this.chars = void 0; - this.pos = void 0; - this.currPenState = void 0; - this.cueStartTime = void 0; - this.logger = void 0; this.chars = []; + this.pos = 0; + this.currPenState = new PenState(); + this.cueStartTime = null; + this.logger = void 0; for (let i = 0; i < NR_COLS; i++) { this.chars.push(new StyledUnicodeChar()); } this.logger = logger; - this.pos = 0; - this.currPenState = new PenState(); } equals(other) { - let equal = true; for (let i = 0; i < NR_COLS; i++) { if (!this.chars[i].equals(other.chars[i])) { - equal = false; - break; + return false; } } - return equal; + return true; } copy(other) { for (let i = 0; i < NR_COLS; i++) { @@ -194884,21 +194218,15 @@ class Row { */ class CaptionScreen { constructor(logger) { - this.rows = void 0; - this.currRow = void 0; - this.nrRollUpRows = void 0; - this.lastOutputScreen = void 0; - this.logger = void 0; this.rows = []; - for (let i = 0; i < NR_ROWS; i++) { - this.rows.push(new Row(logger)); - } // Note that we use zero-based numbering (0-14) - - this.logger = logger; this.currRow = NR_ROWS - 1; this.nrRollUpRows = null; this.lastOutputScreen = null; - this.reset(); + this.logger = void 0; + for (let i = 0; i < NR_ROWS; i++) { + this.rows.push(new Row(logger)); + } + this.logger = logger; } reset() { for (let i = 0; i < NR_ROWS; i++) { @@ -194983,7 +194311,7 @@ class CaptionScreen { if (lastOutputScreen) { const prevLineTime = lastOutputScreen.rows[topRowIndex].cueStartTime; const time = this.logger.time; - if (prevLineTime && time !== null && prevLineTime < time) { + if (prevLineTime !== null && time !== null && prevLineTime < time) { for (let i = 0; i < this.nrRollUpRows; i++) { this.rows[newRow - this.nrRollUpRows + i + 1].copy(lastOutputScreen.rows[topRowIndex + i]); } @@ -195017,7 +194345,6 @@ class CaptionScreen { this.setPen(bkgData); this.insertChar(0x20); // Space } - setRollUpRows(nrRows) { this.nrRollUpRows = nrRows; } @@ -195026,7 +194353,6 @@ class CaptionScreen { this.logger.log(3, 'roll_up but nrRollUpRows not set yet'); return; // Not properly setup } - this.logger.log(1, () => this.getDisplayText()); const topRowIndex = this.currRow + 1 - this.nrRollUpRows; const topRow = this.rows.splice(topRowIndex, 1)[0]; @@ -195296,12 +194622,10 @@ class Cea608Parser { constructor(field, out1, out2) { this.channels = void 0; this.currentChannel = 0; - this.cmdHistory = void 0; + this.cmdHistory = createCmdHistory(); this.logger = void 0; - const logger = new CaptionsLogger(); + const logger = this.logger = new CaptionsLogger(); this.channels = [null, new Cea608Channel(field, out1, logger), new Cea608Channel(field + 1, out2, logger)]; - this.cmdHistory = createCmdHistory(); - this.logger = logger; } getHandler(channel) { return this.channels[channel].getHandler(); @@ -195460,7 +194784,6 @@ class Cea608Parser { setLastCmd(null, null, cmdHistory); return true; // Repeated commands are dropped (once) } - const chNr = a <= 0x17 ? 1 : 2; if (b >= 0x40 && b <= 0x5f) { row = chNr === 1 ? rowsLowCh1[a] : rowsLowCh2[a]; @@ -195667,7 +194990,7 @@ class OutputFilter { */ var VTTCue = (function () { - if (typeof self !== 'undefined' && self.VTTCue) { + if (optionalSelf != null && optionalSelf.VTTCue) { return self.VTTCue; } const AllowedDirections = ['', 'lr', 'rl']; @@ -196626,7 +195949,6 @@ function getTtmlStyles(region, style, styleElements) { // 'direction', // 'writingMode' ]; - const regionStyleName = region != null && region.hasAttribute('style') ? region.getAttribute('style') : null; if (regionStyleName && styleElements.hasOwnProperty(regionStyleName)) { regionStyle = styleElements[regionStyleName]; @@ -196701,9 +196023,14 @@ class TimelineController { this.nonNativeCaptionsTracks = {}; this.cea608Parser1 = void 0; this.cea608Parser2 = void 0; + this.lastCc = -1; + // Last video (CEA-608) fragment CC this.lastSn = -1; + // Last video (CEA-608) fragment MSN this.lastPartIndex = -1; + // Last video (CEA-608) fragment Part Index this.prevCC = -1; + // Last subtitle fragment CC this.vttCCs = newVTTCCs(); this.captionsProperties = void 0; this.hls = hls; @@ -196727,14 +196054,6 @@ class TimelineController { languageCode: this.config.captionsTextTrack4LanguageCode } }; - if (this.config.enableCEA708Captions) { - const channel1 = new OutputFilter(this, 'textTrack1'); - const channel2 = new OutputFilter(this, 'textTrack2'); - const channel3 = new OutputFilter(this, 'textTrack3'); - const channel4 = new OutputFilter(this, 'textTrack4'); - this.cea608Parser1 = new Cea608Parser(1, channel1, channel2); - this.cea608Parser2 = new Cea608Parser(3, channel3, channel4); - } hls.on(Events.MEDIA_ATTACHING, this.onMediaAttaching, this); hls.on(Events.MEDIA_DETACHING, this.onMediaDetaching, this); hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this); @@ -196765,7 +196084,18 @@ class TimelineController { hls.off(Events.SUBTITLE_TRACKS_CLEARED, this.onSubtitleTracksCleared, this); hls.off(Events.BUFFER_FLUSHING, this.onBufferFlushing, this); // @ts-ignore - this.hls = this.config = this.cea608Parser1 = this.cea608Parser2 = null; + this.hls = this.config = null; + this.cea608Parser1 = this.cea608Parser2 = undefined; + } + initCea608Parsers() { + if (this.config.enableCEA708Captions && (!this.cea608Parser1 || !this.cea608Parser2)) { + const channel1 = new OutputFilter(this, 'textTrack1'); + const channel2 = new OutputFilter(this, 'textTrack2'); + const channel3 = new OutputFilter(this, 'textTrack3'); + const channel4 = new OutputFilter(this, 'textTrack4'); + this.cea608Parser1 = new Cea608Parser(1, channel1, channel2); + this.cea608Parser2 = new Cea608Parser(3, channel3, channel4); + } } addCues(trackName, startTime, endTime, screen, cueRanges) { // skip cues which overlap more than 50% with previously parsed time ranges @@ -196824,14 +196154,18 @@ class TimelineController { }); } } - getExistingTrack(trackName) { + getExistingTrack(label, language) { const { media } = this; if (media) { for (let i = 0; i < media.textTracks.length; i++) { const textTrack = media.textTracks[i]; - if (textTrack[trackName]) { + if (canReuseVttTextTrack(textTrack, { + name: label, + lang: language, + attrs: {} + })) { return textTrack; } } @@ -196859,7 +196193,7 @@ class TimelineController { languageCode } = captionsProperties[trackName]; // Enable reuse of existing text track. - const existingTrack = this.getExistingTrack(trackName); + const existingTrack = this.getExistingTrack(label, languageCode); if (!existingTrack) { const textTrack = this.createTextTrack('captions', label, languageCode); if (textTrack) { @@ -196917,10 +196251,14 @@ class TimelineController { this.nonNativeCaptionsTracks = {}; } onManifestLoading() { - this.lastSn = -1; // Detect discontinuity in fragment parsing + // Detect discontinuity in video fragment (CEA-608) parsing + this.lastCc = -1; + this.lastSn = -1; this.lastPartIndex = -1; + // Detect discontinuity in subtitle manifests this.prevCC = -1; - this.vttCCs = newVTTCCs(); // Detect discontinuity in subtitle manifests + this.vttCCs = newVTTCCs(); + // Reset tracks this._cleanTracks(); this.tracks = []; this.captionsTracks = {}; @@ -196960,19 +196298,20 @@ class TimelineController { this.textTracks = []; this.tracks = tracks; if (this.config.renderTextTracksNatively) { - const inUseTracks = this.media ? this.media.textTracks : null; + const media = this.media; + const inUseTracks = media ? filterSubtitleTracks(media.textTracks) : null; this.tracks.forEach((track, index) => { + // Reuse tracks with the same label and lang, but do not reuse 608/708 tracks let textTrack; - if (inUseTracks && index < inUseTracks.length) { + if (inUseTracks) { let inUseTrack = null; for (let i = 0; i < inUseTracks.length; i++) { - if (canReuseVttTextTrack(inUseTracks[i], track)) { + if (inUseTracks[i] && canReuseVttTextTrack(inUseTracks[i], track)) { inUseTrack = inUseTracks[i]; + inUseTracks[i] = null; break; } } - - // Reuse tracks with the same label, but do not reuse 608/708 tracks if (inUseTrack) { textTrack = inUseTrack; } @@ -196980,17 +196319,23 @@ class TimelineController { if (textTrack) { clearCurrentCues(textTrack); } else { - const textTrackKind = this._captionsOrSubtitlesFromCharacteristics(track); + const textTrackKind = captionsOrSubtitlesFromCharacteristics(track); textTrack = this.createTextTrack(textTrackKind, track.name, track.lang); if (textTrack) { textTrack.mode = 'disabled'; } } if (textTrack) { - textTrack.groupId = track.groupId; this.textTracks.push(textTrack); } }); + // Warn when video element has captions or subtitle TextTracks carried over from another source + if (inUseTracks != null && inUseTracks.length) { + const unusedTextTracks = inUseTracks.filter(t => t !== null).map(t => t.label); + if (unusedTextTracks.length) { + logger.warn(`Media element contains unused subtitle tracks: ${unusedTextTracks.join(', ')}. Replace media element for each source to clear TextTracks and captions menu.`); + } + } } else if (this.tracks.length) { // Create a list of tracks for the provider to consume const tracksList = this.tracks.map(track => { @@ -197007,16 +196352,6 @@ class TimelineController { } } } - _captionsOrSubtitlesFromCharacteristics(track) { - if (track.attrs.CHARACTERISTICS) { - const transcribesSpokenDialog = /transcribes-spoken-dialog/gi.test(track.attrs.CHARACTERISTICS); - const describesMusicAndSound = /describes-music-and-sound/gi.test(track.attrs.CHARACTERISTICS); - if (transcribesSpokenDialog && describesMusicAndSound) { - return 'captions'; - } - } - return 'subtitles'; - } onManifestLoaded(event, data) { if (this.config.enableCEA708Captions && data.captions) { data.captions.forEach(captionsTrack => { @@ -197043,24 +196378,30 @@ class TimelineController { return level == null ? void 0 : level.attrs['CLOSED-CAPTIONS']; } onFragLoading(event, data) { + this.initCea608Parsers(); const { cea608Parser1, cea608Parser2, + lastCc, lastSn, lastPartIndex } = this; - if (!this.enabled || !(cea608Parser1 && cea608Parser2)) { + if (!this.enabled || !cea608Parser1 || !cea608Parser2) { return; } // if this frag isn't contiguous, clear the parser so cues with bad start/end times aren't added to the textTrack if (data.frag.type === PlaylistLevelType.MAIN) { var _data$part$index, _data$part; - const sn = data.frag.sn; + const { + cc, + sn + } = data.frag; const partIndex = (_data$part$index = data == null ? void 0 : (_data$part = data.part) == null ? void 0 : _data$part.index) != null ? _data$part$index : -1; - if (!(sn === lastSn + 1 || sn === lastSn && partIndex === lastPartIndex + 1)) { + if (!(sn === lastSn + 1 || sn === lastSn && partIndex === lastPartIndex + 1 || cc === lastCc)) { cea608Parser1.reset(); cea608Parser2.reset(); } + this.lastCc = cc; this.lastSn = sn; this.lastPartIndex = partIndex; } @@ -197215,11 +196556,12 @@ class TimelineController { this.captionsTracks = {}; } onFragParsingUserdata(event, data) { + this.initCea608Parsers(); const { cea608Parser1, cea608Parser2 } = this; - if (!this.enabled || !(cea608Parser1 && cea608Parser2)) { + if (!this.enabled || !cea608Parser1 || !cea608Parser2) { return; } const { @@ -197294,8 +196636,16 @@ class TimelineController { return actualCCBytes; } } +function captionsOrSubtitlesFromCharacteristics(track) { + if (track.characteristics) { + if (/transcribes-spoken-dialog/gi.test(track.characteristics) && /describes-music-and-sound/gi.test(track.characteristics)) { + return 'captions'; + } + } + return 'subtitles'; +} function canReuseVttTextTrack(inUseTrack, manifestTrack) { - return !!inUseTrack && inUseTrack.label === manifestTrack.name && !(inUseTrack.textTrack1 || inUseTrack.textTrack2); + return !!inUseTrack && inUseTrack.kind === captionsOrSubtitlesFromCharacteristics(manifestTrack) && subtitleTrackMatchesTextTrack(manifestTrack, inUseTrack); } function intersection(x1, x2, y1, y2) { return Math.min(x2, y2) - Math.max(x1, y1); @@ -197312,10 +196662,6 @@ function newVTTCCs() { }; } -/* - * cap stream level to media size dimension controller - */ - class CapLevelController { constructor(hls) { this.hls = void 0; @@ -197339,8 +196685,10 @@ class CapLevelController { this.streamController = streamController; } destroy() { - this.unregisterListener(); - if (this.hls.config.capLevelToPlayerSize) { + if (this.hls) { + this.unregisterListener(); + } + if (this.timer) { this.stopCapping(); } this.media = null; @@ -197355,6 +196703,7 @@ class CapLevelController { hls.on(Events.FPS_DROP_LEVEL_CAPPING, this.onFpsDropLevelCapping, this); hls.on(Events.MEDIA_ATTACHING, this.onMediaAttaching, this); hls.on(Events.MANIFEST_PARSED, this.onManifestParsed, this); + hls.on(Events.LEVELS_UPDATED, this.onLevelsUpdated, this); hls.on(Events.BUFFER_CODECS, this.onBufferCodecs, this); hls.on(Events.MEDIA_DETACHING, this.onMediaDetaching, this); } @@ -197365,6 +196714,7 @@ class CapLevelController { hls.off(Events.FPS_DROP_LEVEL_CAPPING, this.onFpsDropLevelCapping, this); hls.off(Events.MEDIA_ATTACHING, this.onMediaAttaching, this); hls.off(Events.MANIFEST_PARSED, this.onManifestParsed, this); + hls.off(Events.LEVELS_UPDATED, this.onLevelsUpdated, this); hls.off(Events.BUFFER_CODECS, this.onBufferCodecs, this); hls.off(Events.MEDIA_DETACHING, this.onMediaDetaching, this); } @@ -197382,6 +196732,9 @@ class CapLevelController { onMediaAttaching(event, data) { this.media = data.media instanceof HTMLVideoElement ? data.media : null; this.clientRect = null; + if (this.timer && this.hls.levels.length) { + this.detectPlayerSize(); + } } onManifestParsed(event, data) { const hls = this.hls; @@ -197392,6 +196745,11 @@ class CapLevelController { this.startCapping(); } } + onLevelsUpdated(event, data) { + if (this.timer && isFiniteNumber(this.autoLevelCapping)) { + this.detectPlayerSize(); + } + } // Only activate capping when playing a video stream; otherwise, multi-bitrate audio-only streams will be restricted // to the first level @@ -197406,11 +196764,19 @@ class CapLevelController { this.stopCapping(); } detectPlayerSize() { - if (this.media && this.mediaHeight > 0 && this.mediaWidth > 0) { + if (this.media) { + if (this.mediaHeight <= 0 || this.mediaWidth <= 0) { + this.clientRect = null; + return; + } const levels = this.hls.levels; if (levels.length) { const hls = this.hls; - hls.autoLevelCapping = this.getMaxLevel(levels.length - 1); + const maxLevel = this.getMaxLevel(levels.length - 1); + if (maxLevel !== this.autoLevelCapping) { + logger.log(`Setting autoLevelCapping to ${maxLevel}: ${levels[maxLevel].height}p@${levels[maxLevel].bitrate} for media ${this.mediaWidth}x${this.mediaHeight}`); + } + hls.autoLevelCapping = maxLevel; if (hls.autoLevelCapping > this.autoLevelCapping && this.streamController) { // if auto level capping has a higher value for the previous one, flush the buffer using nextLevelSwitch // usually happen when the user go to the fullscreen mode. @@ -197439,7 +196805,6 @@ class CapLevelController { return; } this.autoLevelCapping = Number.POSITIVE_INFINITY; - this.hls.firstLevel = this.getMaxLevel(this.firstLevel); self.clearInterval(this.timer); this.timer = self.setInterval(this.detectPlayerSize.bind(this), 1000); this.detectPlayerSize(); @@ -197516,9 +196881,11 @@ class CapLevelController { // If we run through the loop without breaking, the media's dimensions are greater than every level, so default to // the max level let maxLevelIndex = levels.length - 1; + // Prevent changes in aspect-ratio from causing capping to toggle back and forth + const squareSize = Math.max(width, height); for (let i = 0; i < levels.length; i += 1) { const level = levels[i]; - if ((level.width >= width || level.height >= height) && atGreatestBandwidth(level, levels[i + 1])) { + if ((level.width >= squareSize || level.height >= squareSize) && atGreatestBandwidth(level, levels[i + 1])) { maxLevelIndex = i; break; } @@ -197528,8 +196895,6 @@ class CapLevelController { } class FPSController { - // stream controller must be provided as a dependency! - constructor(hls) { this.hls = void 0; this.isVideoPlaybackQualityAvailable = false; @@ -197538,6 +196903,7 @@ class FPSController { this.lastTime = void 0; this.lastDroppedFrames = 0; this.lastDecodedFrames = 0; + // stream controller must be provided as a dependency! this.streamController = void 0; this.hls = hls; this.registerListeners(); @@ -198063,7 +197429,7 @@ class EMEController { const keyId = this.getKeyIdString(context.decryptdata); this.log(`Generating key-session request for "${reason}": ${keyId} (init data type: ${initDataType} length: ${initData ? initData.byteLength : null})`); const licenseStatus = new EventEmitter(); - context.mediaKeysSession.onmessage = event => { + const onmessage = context._onmessage = event => { const keySession = context.mediaKeysSession; if (!keySession) { licenseStatus.emit('error', new Error('invalid state')); @@ -198088,7 +197454,7 @@ class EMEController { this.warn(`unhandled media key message type "${messageType}"`); } }; - context.mediaKeysSession.onkeystatuseschange = event => { + const onkeystatuseschange = context._onkeystatuseschange = event => { const keySession = context.mediaKeysSession; if (!keySession) { licenseStatus.emit('error', new Error('invalid state')); @@ -198102,6 +197468,8 @@ class EMEController { this.renewKeySession(context); } }; + context.mediaKeysSession.addEventListener('message', onmessage); + context.mediaKeysSession.addEventListener('keystatuseschange', onkeystatuseschange); const keyUsablePromise = new Promise((resolve, reject) => { licenseStatus.on('error', reject); licenseStatus.on('keyStatus', keyStatus => { @@ -198159,7 +197527,7 @@ class EMEController { if (!url) { return Promise.resolve(); } - this.log(`Fetching serverCertificate for "${keySystem}"`); + this.log(`Fetching server certificate for "${keySystem}"`); return new Promise((resolve, reject) => { const loaderContext = { responseType: 'arraybuffer', @@ -198235,6 +197603,43 @@ class EMEController { }); }); } + unpackPlayReadyKeyMessage(xhr, licenseChallenge) { + // On Edge, the raw license message is UTF-16-encoded XML. We need + // to unpack the Challenge element (base64-encoded string containing the + // actual license request) and any HttpHeader elements (sent as request + // headers). + // For PlayReady CDMs, we need to dig the Challenge out of the XML. + const xmlString = String.fromCharCode.apply(null, new Uint16Array(licenseChallenge.buffer)); + if (!xmlString.includes('PlayReadyKeyMessage')) { + // This does not appear to be a wrapped message as on Edge. Some + // clients do not need this unwrapping, so we will assume this is one of + // them. Note that "xml" at this point probably looks like random + // garbage, since we interpreted UTF-8 as UTF-16. + xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-8'); + return licenseChallenge; + } + const keyMessageXml = new DOMParser().parseFromString(xmlString, 'application/xml'); + // Set request headers. + const headers = keyMessageXml.querySelectorAll('HttpHeader'); + if (headers.length > 0) { + let header; + for (let i = 0, len = headers.length; i < len; i++) { + var _header$querySelector, _header$querySelector2; + header = headers[i]; + const name = (_header$querySelector = header.querySelector('name')) == null ? void 0 : _header$querySelector.textContent; + const value = (_header$querySelector2 = header.querySelector('value')) == null ? void 0 : _header$querySelector2.textContent; + if (name && value) { + xhr.setRequestHeader(name, value); + } + } + } + const challengeElement = keyMessageXml.querySelector('Challenge'); + const challengeText = challengeElement == null ? void 0 : challengeElement.textContent; + if (!challengeText) { + throw new Error(`Cannot find in key message`); + } + return strToUtf8array(atob(challengeText)); + } setupLicenseXHR(xhr, url, keysListItem, licenseChallenge) { const licenseXhrSetup = this.config.licenseXhrSetup; if (!licenseXhrSetup) { @@ -198327,6 +197732,9 @@ class EMEController { xhr, licenseChallenge }) => { + if (keySessionContext.keySystem == KeySystems.PLAYREADY) { + licenseChallenge = this.unpackPlayReadyKeyMessage(xhr, licenseChallenge); + } xhr.send(licenseChallenge); }); }); @@ -198359,14 +197767,14 @@ class EMEController { // Close all sessions and remove media keys from the video element. const keySessionCount = mediaKeysList.length; EMEController.CDMCleanupPromise = Promise.all(mediaKeysList.map(mediaKeySessionContext => this.removeSession(mediaKeySessionContext)).concat(media == null ? void 0 : media.setMediaKeys(null).catch(error => { - this.log(`Could not clear media keys: ${error}. media.src: ${media == null ? void 0 : media.src}`); + this.log(`Could not clear media keys: ${error}`); }))).then(() => { if (keySessionCount) { this.log('finished closing key sessions and clearing media keys'); mediaKeysList.length = 0; } }).catch(error => { - this.log(`Could not close sessions and clear media keys: ${error}. media.src: ${media == null ? void 0 : media.src}`); + this.log(`Could not close sessions and clear media keys: ${error}`); }); } onManifestLoading() { @@ -198396,8 +197804,14 @@ class EMEController { } = mediaKeySessionContext; if (mediaKeysSession) { this.log(`Remove licenses and keys and close session ${mediaKeysSession.sessionId}`); - mediaKeysSession.onmessage = null; - mediaKeysSession.onkeystatuseschange = null; + if (mediaKeySessionContext._onmessage) { + mediaKeysSession.removeEventListener('message', mediaKeySessionContext._onmessage); + mediaKeySessionContext._onmessage = undefined; + } + if (mediaKeySessionContext._onkeystatuseschange) { + mediaKeysSession.removeEventListener('keystatuseschange', mediaKeySessionContext._onkeystatuseschange); + mediaKeySessionContext._onkeystatuseschange = undefined; + } if (licenseXhr && licenseXhr.readyState !== XMLHttpRequest.DONE) { licenseXhr.abort(); } @@ -198428,41 +197842,977 @@ class EMEKeyError extends Error { } /** - * CMCD spec version + * Common Media Object Type + * + * @group CMCD + * @group CMSD + * + * @beta + */ +var CmObjectType; +(function (CmObjectType) { + /** + * text file, such as a manifest or playlist + */ + CmObjectType["MANIFEST"] = "m"; + /** + * audio only + */ + CmObjectType["AUDIO"] = "a"; + /** + * video only + */ + CmObjectType["VIDEO"] = "v"; + /** + * muxed audio and video + */ + CmObjectType["MUXED"] = "av"; + /** + * init segment + */ + CmObjectType["INIT"] = "i"; + /** + * caption or subtitle + */ + CmObjectType["CAPTION"] = "c"; + /** + * ISOBMFF timed text track + */ + CmObjectType["TIMED_TEXT"] = "tt"; + /** + * cryptographic key, license or certificate. + */ + CmObjectType["KEY"] = "k"; + /** + * other + */ + CmObjectType["OTHER"] = "o"; +})(CmObjectType || (CmObjectType = {})); + +/** + * Common Media Streaming Format + * + * @group CMCD + * @group CMSD + * + * @beta + */ +var CmStreamingFormat; +(function (CmStreamingFormat) { + /** + * MPEG DASH + */ + CmStreamingFormat["DASH"] = "d"; + /** + * HTTP Live Streaming (HLS) + */ + CmStreamingFormat["HLS"] = "h"; + /** + * Smooth Streaming + */ + CmStreamingFormat["SMOOTH"] = "s"; + /** + * Other + */ + CmStreamingFormat["OTHER"] = "o"; +})(CmStreamingFormat || (CmStreamingFormat = {})); + +/** + * CMCD header fields. + * + * @group CMCD + * + * @beta + */ +var CmcdHeaderField; +(function (CmcdHeaderField) { + /** + * keys whose values vary with the object being requested. + */ + CmcdHeaderField["OBJECT"] = "CMCD-Object"; + /** + * keys whose values vary with each request. + */ + CmcdHeaderField["REQUEST"] = "CMCD-Request"; + /** + * keys whose values are expected to be invariant over the life of the session. + */ + CmcdHeaderField["SESSION"] = "CMCD-Session"; + /** + * keys whose values do not vary with every request or object. + */ + CmcdHeaderField["STATUS"] = "CMCD-Status"; +})(CmcdHeaderField || (CmcdHeaderField = {})); + +/** + * The map of CMCD header fields to official CMCD keys. + * + * @internal + * + * @group CMCD + */ +const CmcdHeaderMap = { + [CmcdHeaderField.OBJECT]: ['br', 'd', 'ot', 'tb'], + [CmcdHeaderField.REQUEST]: ['bl', 'dl', 'mtp', 'nor', 'nrr', 'su'], + [CmcdHeaderField.SESSION]: ['cid', 'pr', 'sf', 'sid', 'st', 'v'], + [CmcdHeaderField.STATUS]: ['bs', 'rtp'] +}; + +/** + * Structured Field Item + * + * @group Structured Field + * + * @beta + */ +class SfItem { + constructor(value, params) { + this.value = void 0; + this.params = void 0; + if (Array.isArray(value)) { + value = value.map(v => v instanceof SfItem ? v : new SfItem(v)); + } + this.value = value; + this.params = params; + } +} + +/** + * A class to represent structured field tokens when `Symbol` is not available. + * + * @group Structured Field + * + * @beta + */ +class SfToken { + constructor(description) { + this.description = void 0; + this.description = description; + } +} + +const DICT = 'Dict'; + +function format(value) { + if (Array.isArray(value)) { + return JSON.stringify(value); + } + if (value instanceof Map) { + return 'Map{}'; + } + if (value instanceof Set) { + return 'Set{}'; + } + if (typeof value === 'object') { + return JSON.stringify(value); + } + return String(value); +} +function throwError(action, src, type, cause) { + return new Error(`failed to ${action} "${format(src)}" as ${type}`, { + cause + }); +} + +const BARE_ITEM = 'Bare Item'; + +const BOOLEAN = 'Boolean'; + +const BYTES = 'Byte Sequence'; + +const DECIMAL = 'Decimal'; + +const INTEGER = 'Integer'; + +function isInvalidInt(value) { + return value < -999999999999999 || 999999999999999 < value; +} + +const STRING_REGEX = /[\x00-\x1f\x7f]+/; // eslint-disable-line no-control-regex + +const TOKEN = 'Token'; + +const KEY = 'Key'; + +function serializeError(src, type, cause) { + return throwError('serialize', src, type, cause); +} + +// 4.1.9. Serializing a Boolean +// +// Given a Boolean as input_boolean, return an ASCII string suitable for +// use in a HTTP field value. +// +// 1. If input_boolean is not a boolean, fail serialization. +// +// 2. Let output be an empty string. +// +// 3. Append "?" to output. +// +// 4. If input_boolean is true, append "1" to output. +// +// 5. If input_boolean is false, append "0" to output. +// +// 6. Return output. +function serializeBoolean(value) { + if (typeof value !== 'boolean') { + throw serializeError(value, BOOLEAN); + } + return value ? '?1' : '?0'; +} + +/** + * Encodes binary data to base64 + * + * @param binary - The binary data to encode + * @returns The base64 encoded string + * + * @group Utils + * + * @beta + */ +function base64encode(binary) { + return btoa(String.fromCharCode(...binary)); +} + +// 4.1.8. Serializing a Byte Sequence +// +// Given a Byte Sequence as input_bytes, return an ASCII string suitable +// for use in a HTTP field value. +// +// 1. If input_bytes is not a sequence of bytes, fail serialization. +// +// 2. Let output be an empty string. +// +// 3. Append ":" to output. +// +// 4. Append the result of base64-encoding input_bytes as per +// [RFC4648], Section 4, taking account of the requirements below. +// +// 5. Append ":" to output. +// +// 6. Return output. +// +// The encoded data is required to be padded with "=", as per [RFC4648], +// Section 3.2. +// +// Likewise, encoded data SHOULD have pad bits set to zero, as per +// [RFC4648], Section 3.5, unless it is not possible to do so due to +// implementation constraints. +function serializeByteSequence(value) { + if (ArrayBuffer.isView(value) === false) { + throw serializeError(value, BYTES); + } + return `:${base64encode(value)}:`; +} + +// 4.1.4. Serializing an Integer +// +// Given an Integer as input_integer, return an ASCII string suitable +// for use in a HTTP field value. +// +// 1. If input_integer is not an integer in the range of +// -999,999,999,999,999 to 999,999,999,999,999 inclusive, fail +// serialization. +// +// 2. Let output be an empty string. +// +// 3. If input_integer is less than (but not equal to) 0, append "-" to +// output. +// +// 4. Append input_integer's numeric value represented in base 10 using +// only decimal digits to output. +// +// 5. Return output. +function serializeInteger(value) { + if (isInvalidInt(value)) { + throw serializeError(value, INTEGER); + } + return value.toString(); +} + +// 4.1.10. Serializing a Date +// +// Given a Date as input_integer, return an ASCII string suitable for +// use in an HTTP field value. +// 1. Let output be "@". +// 2. Append to output the result of running Serializing an Integer +// with input_date (Section 4.1.4). +// 3. Return output. +function serializeDate(value) { + return `@${serializeInteger(value.getTime() / 1000)}`; +} + +/** + * This implements the rounding procedure described in step 2 of the "Serializing a Decimal" specification. + * This rounding style is known as "even rounding", "banker's rounding", or "commercial rounding". + * + * @param value - The value to round + * @param precision - The number of decimal places to round to + * @returns The rounded value + * + * @group Utils + * + * @beta + */ +function roundToEven(value, precision) { + if (value < 0) { + return -roundToEven(-value, precision); + } + const decimalShift = Math.pow(10, precision); + const isEquidistant = Math.abs(value * decimalShift % 1 - 0.5) < Number.EPSILON; + if (isEquidistant) { + // If the tail of the decimal place is 'equidistant' we round to the nearest even value + const flooredValue = Math.floor(value * decimalShift); + return (flooredValue % 2 === 0 ? flooredValue : flooredValue + 1) / decimalShift; + } else { + // Otherwise, proceed as normal + return Math.round(value * decimalShift) / decimalShift; + } +} + +// 4.1.5. Serializing a Decimal +// +// Given a decimal number as input_decimal, return an ASCII string +// suitable for use in a HTTP field value. +// +// 1. If input_decimal is not a decimal number, fail serialization. +// +// 2. If input_decimal has more than three significant digits to the +// right of the decimal point, round it to three decimal places, +// rounding the final digit to the nearest value, or to the even +// value if it is equidistant. +// +// 3. If input_decimal has more than 12 significant digits to the left +// of the decimal point after rounding, fail serialization. +// +// 4. Let output be an empty string. +// +// 5. If input_decimal is less than (but not equal to) 0, append "-" +// to output. +// +// 6. Append input_decimal's integer component represented in base 10 +// (using only decimal digits) to output; if it is zero, append +// "0". +// +// 7. Append "." to output. +// +// 8. If input_decimal's fractional component is zero, append "0" to +// output. +// +// 9. Otherwise, append the significant digits of input_decimal's +// fractional component represented in base 10 (using only decimal +// digits) to output. +// +// 10. Return output. +function serializeDecimal(value) { + const roundedValue = roundToEven(value, 3); // round to 3 decimal places + if (Math.floor(Math.abs(roundedValue)).toString().length > 12) { + throw serializeError(value, DECIMAL); + } + const stringValue = roundedValue.toString(); + return stringValue.includes('.') ? stringValue : `${stringValue}.0`; +} + +const STRING = 'String'; + +// 4.1.6. Serializing a String +// +// Given a String as input_string, return an ASCII string suitable for +// use in a HTTP field value. +// +// 1. Convert input_string into a sequence of ASCII characters; if +// conversion fails, fail serialization. +// +// 2. If input_string contains characters in the range %x00-1f or %x7f +// (i.e., not in VCHAR or SP), fail serialization. +// +// 3. Let output be the string DQUOTE. +// +// 4. For each character char in input_string: +// +// 1. If char is "\" or DQUOTE: +// +// 1. Append "\" to output. +// +// 2. Append char to output. +// +// 5. Append DQUOTE to output. +// +// 6. Return output. +function serializeString(value) { + if (STRING_REGEX.test(value)) { + throw serializeError(value, STRING); + } + return `"${value.replace(/\\/g, `\\\\`).replace(/"/g, `\\"`)}"`; +} + +function symbolToStr(symbol) { + return symbol.description || symbol.toString().slice(7, -1); +} + +function serializeToken(token) { + const value = symbolToStr(token); + if (/^([a-zA-Z*])([!#$%&'*+\-.^_`|~\w:/]*)$/.test(value) === false) { + throw serializeError(value, TOKEN); + } + return value; +} + +// 4.1.3.1. Serializing a Bare Item +// +// Given an Item as input_item, return an ASCII string suitable for use +// in a HTTP field value. +// +// 1. If input_item is an Integer, return the result of running +// Serializing an Integer (Section 4.1.4) with input_item. +// +// 2. If input_item is a Decimal, return the result of running +// Serializing a Decimal (Section 4.1.5) with input_item. +// +// 3. If input_item is a String, return the result of running +// Serializing a String (Section 4.1.6) with input_item. +// +// 4. If input_item is a Token, return the result of running +// Serializing a Token (Section 4.1.7) with input_item. +// +// 5. If input_item is a Boolean, return the result of running +// Serializing a Boolean (Section 4.1.9) with input_item. +// +// 6. If input_item is a Byte Sequence, return the result of running +// Serializing a Byte Sequence (Section 4.1.8) with input_item. +// +// 7. If input_item is a Date, return the result of running Serializing +// a Date (Section 4.1.10) with input_item. +// +// 8. Otherwise, fail serialization. +function serializeBareItem(value) { + switch (typeof value) { + case 'number': + if (!isFiniteNumber(value)) { + throw serializeError(value, BARE_ITEM); + } + if (Number.isInteger(value)) { + return serializeInteger(value); + } + return serializeDecimal(value); + case 'string': + return serializeString(value); + case 'symbol': + return serializeToken(value); + case 'boolean': + return serializeBoolean(value); + case 'object': + if (value instanceof Date) { + return serializeDate(value); + } + if (value instanceof Uint8Array) { + return serializeByteSequence(value); + } + if (value instanceof SfToken) { + return serializeToken(value); + } + default: + // fail + throw serializeError(value, BARE_ITEM); + } +} + +// 4.1.1.3. Serializing a Key +// +// Given a key as input_key, return an ASCII string suitable for use in +// a HTTP field value. +// +// 1. Convert input_key into a sequence of ASCII characters; if +// conversion fails, fail serialization. +// +// 2. If input_key contains characters not in lcalpha, DIGIT, "_", "-", +// ".", or "*" fail serialization. +// +// 3. If the first character of input_key is not lcalpha or "*", fail +// serialization. +// +// 4. Let output be an empty string. +// +// 5. Append input_key to output. +// +// 6. Return output. +function serializeKey(value) { + if (/^[a-z*][a-z0-9\-_.*]*$/.test(value) === false) { + throw serializeError(value, KEY); + } + return value; +} + +// 4.1.1.2. Serializing Parameters +// +// Given an ordered Dictionary as input_parameters (each member having a +// param_name and a param_value), return an ASCII string suitable for +// use in a HTTP field value. +// +// 1. Let output be an empty string. +// +// 2. For each param_name with a value of param_value in +// input_parameters: +// +// 1. Append ";" to output. +// +// 2. Append the result of running Serializing a Key +// (Section 4.1.1.3) with param_name to output. +// +// 3. If param_value is not Boolean true: +// +// 1. Append "=" to output. +// +// 2. Append the result of running Serializing a bare Item +// (Section 4.1.3.1) with param_value to output. +// +// 3. Return output. +function serializeParams(params) { + if (params == null) { + return ''; + } + return Object.entries(params).map(([key, value]) => { + if (value === true) { + return `;${serializeKey(key)}`; // omit true + } + return `;${serializeKey(key)}=${serializeBareItem(value)}`; + }).join(''); +} + +// 4.1.3. Serializing an Item +// +// Given an Item as bare_item and Parameters as item_parameters, return +// an ASCII string suitable for use in a HTTP field value. +// +// 1. Let output be an empty string. +// +// 2. Append the result of running Serializing a Bare Item +// Section 4.1.3.1 with bare_item to output. +// +// 3. Append the result of running Serializing Parameters +// Section 4.1.1.2 with item_parameters to output. +// +// 4. Return output. +function serializeItem(value) { + if (value instanceof SfItem) { + return `${serializeBareItem(value.value)}${serializeParams(value.params)}`; + } else { + return serializeBareItem(value); + } +} + +// 4.1.1.1. Serializing an Inner List +// +// Given an array of (member_value, parameters) tuples as inner_list, +// and parameters as list_parameters, return an ASCII string suitable +// for use in a HTTP field value. +// +// 1. Let output be the string "(". +// +// 2. For each (member_value, parameters) of inner_list: +// +// 1. Append the result of running Serializing an Item +// (Section 4.1.3) with (member_value, parameters) to output. +// +// 2. If more values remain in inner_list, append a single SP to +// output. +// +// 3. Append ")" to output. +// +// 4. Append the result of running Serializing Parameters +// (Section 4.1.1.2) with list_parameters to output. +// +// 5. Return output. +function serializeInnerList(value) { + return `(${value.value.map(serializeItem).join(' ')})${serializeParams(value.params)}`; +} + +// 4.1.2. Serializing a Dictionary +// +// Given an ordered Dictionary as input_dictionary (each member having a +// member_name and a tuple value of (member_value, parameters)), return +// an ASCII string suitable for use in a HTTP field value. +// +// 1. Let output be an empty string. +// +// 2. For each member_name with a value of (member_value, parameters) +// in input_dictionary: +// +// 1. Append the result of running Serializing a Key +// (Section 4.1.1.3) with member's member_name to output. +// +// 2. If member_value is Boolean true: +// +// 1. Append the result of running Serializing Parameters +// (Section 4.1.1.2) with parameters to output. +// +// 3. Otherwise: +// +// 1. Append "=" to output. +// +// 2. If member_value is an array, append the result of running +// Serializing an Inner List (Section 4.1.1.1) with +// (member_value, parameters) to output. +// +// 3. Otherwise, append the result of running Serializing an +// Item (Section 4.1.3) with (member_value, parameters) to +// output. +// +// 4. If more members remain in input_dictionary: +// +// 1. Append "," to output. +// +// 2. Append a single SP to output. +// +// 3. Return output. +function serializeDict(dict, options = { + whitespace: true +}) { + if (typeof dict !== 'object') { + throw serializeError(dict, DICT); + } + const entries = dict instanceof Map ? dict.entries() : Object.entries(dict); + const optionalWhiteSpace = options != null && options.whitespace ? ' ' : ''; + return Array.from(entries).map(([key, item]) => { + if (item instanceof SfItem === false) { + item = new SfItem(item); + } + let output = serializeKey(key); + if (item.value === true) { + output += serializeParams(item.params); + } else { + output += '='; + if (Array.isArray(item.value)) { + output += serializeInnerList(item); + } else { + output += serializeItem(item); + } + } + return output; + }).join(`,${optionalWhiteSpace}`); +} + +/** + * Encode an object into a structured field dictionary + * + * @param input - The structured field dictionary to encode + * @returns The structured field string + * + * @group Structured Field + * + * @beta */ -const CMCDVersion = 1; +function encodeSfDict(value, options) { + return serializeDict(value, options); +} /** - * CMCD Object Type + * Checks if the given key is a token field. + * + * @param key - The key to check. + * + * @returns `true` if the key is a token field. + * + * @internal + * + * @group CMCD */ -var CMCDObjectType = { - MANIFEST: "m", - AUDIO: "a", - VIDEO: "v", - MUXED: "av", - INIT: "i", - CAPTION: "c", - TIMED_TEXT: "tt", - KEY: "k", - OTHER: "o" +const isTokenField = key => key === 'ot' || key === 'sf' || key === 'st'; + +const isValid = value => { + if (typeof value === 'number') { + return isFiniteNumber(value); + } + return value != null && value !== '' && value !== false; }; /** - * CMCD Streaming Format + * Constructs a relative path from a URL. + * + * @param url - The destination URL + * @param base - The base URL + * @returns The relative path + * + * @group Utils + * + * @beta */ -const CMCDStreamingFormatHLS = 'h'; +function urlToRelativePath(url, base) { + const to = new URL(url); + const from = new URL(base); + if (to.origin !== from.origin) { + return url; + } + const toPath = to.pathname.split('/').slice(1); + const fromPath = from.pathname.split('/').slice(1, -1); + // remove common parents + while (toPath[0] === fromPath[0]) { + toPath.shift(); + fromPath.shift(); + } + // add back paths + while (fromPath.length) { + fromPath.shift(); + toPath.unshift('..'); + } + return toPath.join('/'); +} + +/** + * Generate a random v4 UUID + * + * @returns A random v4 UUID + * + * @group Utils + * + * @beta + */ +function uuid() { + try { + return crypto.randomUUID(); + } catch (error) { + try { + const url = URL.createObjectURL(new Blob()); + const uuid = url.toString(); + URL.revokeObjectURL(url); + return uuid.slice(uuid.lastIndexOf('/') + 1); + } catch (error) { + let dt = new Date().getTime(); + const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { + const r = (dt + Math.random() * 16) % 16 | 0; + dt = Math.floor(dt / 16); + return (c == 'x' ? r : r & 0x3 | 0x8).toString(16); + }); + return uuid; + } + } +} + +const toRounded = value => Math.round(value); +const toUrlSafe = (value, options) => { + if (options != null && options.baseUrl) { + value = urlToRelativePath(value, options.baseUrl); + } + return encodeURIComponent(value); +}; +const toHundred = value => toRounded(value / 100) * 100; +/** + * The default formatters for CMCD values. + * + * @group CMCD + * + * @beta + */ +const CmcdFormatters = { + /** + * Bitrate (kbps) rounded integer + */ + br: toRounded, + /** + * Duration (milliseconds) rounded integer + */ + d: toRounded, + /** + * Buffer Length (milliseconds) rounded nearest 100ms + */ + bl: toHundred, + /** + * Deadline (milliseconds) rounded nearest 100ms + */ + dl: toHundred, + /** + * Measured Throughput (kbps) rounded nearest 100kbps + */ + mtp: toHundred, + /** + * Next Object Request URL encoded + */ + nor: toUrlSafe, + /** + * Requested maximum throughput (kbps) rounded nearest 100kbps + */ + rtp: toHundred, + /** + * Top Bitrate (kbps) rounded integer + */ + tb: toRounded +}; + +/** + * Internal CMCD processing function. + * + * @param obj - The CMCD object to process. + * @param map - The mapping function to use. + * @param options - Options for encoding. + * + * @internal + * + * @group CMCD + */ +function processCmcd(obj, options) { + const results = {}; + if (obj == null || typeof obj !== 'object') { + return results; + } + const keys = Object.keys(obj).sort(); + const formatters = _extends({}, CmcdFormatters, options == null ? void 0 : options.formatters); + const filter = options == null ? void 0 : options.filter; + keys.forEach(key => { + if (filter != null && filter(key)) { + return; + } + let value = obj[key]; + const formatter = formatters[key]; + if (formatter) { + value = formatter(value, options); + } + // Version should only be reported if not equal to 1. + if (key === 'v' && value === 1) { + return; + } + // Playback rate should only be sent if not equal to 1. + if (key == 'pr' && value === 1) { + return; + } + // ignore invalid values + if (!isValid(value)) { + return; + } + if (isTokenField(key) && typeof value === 'string') { + value = new SfToken(value); + } + results[key] = value; + }); + return results; +} /** - * CMCD Streaming Type + * Encode a CMCD object to a string. + * + * @param cmcd - The CMCD object to encode. + * @param options - Options for encoding. + * + * @returns The encoded CMCD string. + * + * @group CMCD + * + * @beta */ +function encodeCmcd(cmcd, options = {}) { + if (!cmcd) { + return ''; + } + return encodeSfDict(processCmcd(cmcd, options), _extends({ + whitespace: false + }, options)); +} + +/** + * Convert a CMCD data object to request headers + * + * @param cmcd - The CMCD data object to convert. + * @param options - Options for encoding the CMCD object. + * + * @returns The CMCD header shards. + * + * @group CMCD + * + * @beta + */ +function toCmcdHeaders(cmcd, options = {}) { + if (!cmcd) { + return {}; + } + const entries = Object.entries(cmcd); + const headerMap = Object.entries(CmcdHeaderMap).concat(Object.entries((options == null ? void 0 : options.customHeaderMap) || {})); + const shards = entries.reduce((acc, entry) => { + var _headerMap$find, _acc$field; + const [key, value] = entry; + const field = ((_headerMap$find = headerMap.find(entry => entry[1].includes(key))) == null ? void 0 : _headerMap$find[0]) || CmcdHeaderField.REQUEST; + (_acc$field = acc[field]) != null ? _acc$field : acc[field] = {}; + acc[field][key] = value; + return acc; + }, {}); + return Object.entries(shards).reduce((acc, [field, value]) => { + acc[field] = encodeCmcd(value, options); + return acc; + }, {}); +} /** - * CMCD Headers + * Append CMCD query args to a header object. + * + * @param headers - The headers to append to. + * @param cmcd - The CMCD object to append. + * @param customHeaderMap - A map of custom CMCD keys to header fields. + * + * @returns The headers with the CMCD header shards appended. + * + * @group CMCD + * + * @beta */ +function appendCmcdHeaders(headers, cmcd, options) { + return _extends(headers, toCmcdHeaders(cmcd, options)); +} /** - * CMCD + * CMCD parameter name. + * + * @group CMCD + * + * @beta */ +const CMCD_PARAM = 'CMCD'; + +/** + * Convert a CMCD data object to a query arg. + * + * @param cmcd - The CMCD object to convert. + * @param options - Options for encoding the CMCD object. + * + * @returns The CMCD query arg. + * + * @group CMCD + * + * @beta + */ +function toCmcdQuery(cmcd, options = {}) { + if (!cmcd) { + return ''; + } + const params = encodeCmcd(cmcd, options); + return `${CMCD_PARAM}=${encodeURIComponent(params)}`; +} + +const REGEX = /CMCD=[^&#]+/; +/** + * Append CMCD query args to a URL. + * + * @param url - The URL to append to. + * @param cmcd - The CMCD object to append. + * @param options - Options for encoding the CMCD object. + * + * @returns The URL with the CMCD query args appended. + * + * @group CMCD + * + * @beta + */ +function appendCmcdQuery(url, cmcd, options) { + // TODO: Replace with URLSearchParams once we drop Safari < 10.1 & Chrome < 49 support. + // https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams + const query = toCmcdQuery(cmcd, options); + if (!query) { + return url; + } + if (REGEX.test(url)) { + return url.replace(REGEX, query); + } + const separator = url.includes('?') ? '&' : '?'; + return `${url}${separator}${query}`; +} /** * Controller to deal with Common Media Client Data (CMCD) @@ -198470,7 +198820,6 @@ const CMCDStreamingFormatHLS = 'h'; */ class CMCDController { // eslint-disable-line no-restricted-globals - // eslint-disable-line no-restricted-globals constructor(hls) { this.hls = void 0; @@ -198479,10 +198828,12 @@ class CMCDController { this.sid = void 0; this.cid = void 0; this.useHeaders = false; + this.includeKeys = void 0; this.initialized = false; this.starved = false; this.buffering = true; this.audioBuffer = void 0; + // eslint-disable-line no-restricted-globals this.videoBuffer = void 0; this.onWaiting = () => { if (this.initialized) { @@ -198502,7 +198853,7 @@ class CMCDController { this.applyPlaylistData = context => { try { this.apply(context, { - ot: CMCDObjectType.MANIFEST, + ot: CmObjectType.MANIFEST, su: !this.initialized }); } catch (error) { @@ -198521,7 +198872,7 @@ class CMCDController { d: fragment.duration * 1000, ot }; - if (ot === CMCDObjectType.VIDEO || ot === CMCDObjectType.AUDIO || ot == CMCDObjectType.MUXED) { + if (ot === CmObjectType.VIDEO || ot === CmObjectType.AUDIO || ot == CmObjectType.MUXED) { data.br = level.bitrate / 1000; data.tb = this.getTopBandwidth(ot) / 1000; data.bl = this.getBufferLength(ot); @@ -198539,9 +198890,10 @@ class CMCDController { if (cmcd != null) { config.pLoader = this.createPlaylistLoader(); config.fLoader = this.createFragmentLoader(); - this.sid = cmcd.sessionId || CMCDController.uuid(); + this.sid = cmcd.sessionId || uuid(); this.cid = cmcd.contentId; this.useHeaders = cmcd.useHeaders === true; + this.includeKeys = cmcd.includeKeys; this.registerListeners(); } } @@ -198590,8 +198942,8 @@ class CMCDController { createData() { var _this$media; return { - v: CMCDVersion, - sf: CMCDStreamingFormatHLS, + v: 1, + sf: CmStreamingFormat.HLS, sid: this.sid, cid: this.cid, pr: (_this$media = this.media) == null ? void 0 : _this$media.playbackRate, @@ -198605,7 +198957,7 @@ class CMCDController { apply(context, data = {}) { // apply baseline data _extends(data, this.createData()); - const isVideo = data.ot === CMCDObjectType.INIT || data.ot === CMCDObjectType.VIDEO || data.ot === CMCDObjectType.MUXED; + const isVideo = data.ot === CmObjectType.INIT || data.ot === CmObjectType.VIDEO || data.ot === CmObjectType.MUXED; if (this.starved && isVideo) { data.bs = true; data.su = true; @@ -198617,21 +198969,22 @@ class CMCDController { // TODO: Implement rtp, nrr, nor, dl + const { + includeKeys + } = this; + if (includeKeys) { + data = Object.keys(data).reduce((acc, key) => { + includeKeys.includes(key) && (acc[key] = data[key]); + return acc; + }, {}); + } if (this.useHeaders) { - const headers = CMCDController.toHeaders(data); - if (!Object.keys(headers).length) { - return; - } if (!context.headers) { context.headers = {}; } - _extends(context.headers, headers); + appendCmcdHeaders(context.headers, data); } else { - const query = CMCDController.toQuery(data); - if (!query) { - return; - } - context.url = CMCDController.appendQueryToUri(context.url, query); + context.url = appendCmcdQuery(context.url, data); } } /** @@ -198642,19 +198995,19 @@ class CMCDController { type } = fragment; if (type === 'subtitle') { - return CMCDObjectType.TIMED_TEXT; + return CmObjectType.TIMED_TEXT; } if (fragment.sn === 'initSegment') { - return CMCDObjectType.INIT; + return CmObjectType.INIT; } if (type === 'audio') { - return CMCDObjectType.AUDIO; + return CmObjectType.AUDIO; } if (type === 'main') { if (!this.hls.audioTracks.length) { - return CMCDObjectType.MUXED; + return CmObjectType.MUXED; } - return CMCDObjectType.VIDEO; + return CmObjectType.VIDEO; } return undefined; } @@ -198666,7 +199019,7 @@ class CMCDController { let bitrate = 0; let levels; const hls = this.hls; - if (type === CMCDObjectType.AUDIO) { + if (type === CmObjectType.AUDIO) { levels = hls.audioTracks; } else { const max = hls.maxAutoLevel; @@ -198686,7 +199039,7 @@ class CMCDController { */ getBufferLength(type) { const media = this.hls.media; - const buffer = type === CMCDObjectType.AUDIO ? this.audioBuffer : this.videoBuffer; + const buffer = type === CmObjectType.AUDIO ? this.audioBuffer : this.videoBuffer; if (!buffer || !media) { return NaN; } @@ -198759,145 +199112,6 @@ class CMCDController { } }; } - - /** - * Generate a random v4 UUI - * - * @returns {string} - */ - static uuid() { - const url = URL.createObjectURL(new Blob()); - const uuid = url.toString(); - URL.revokeObjectURL(url); - return uuid.slice(uuid.lastIndexOf('/') + 1); - } - - /** - * Serialize a CMCD data object according to the rules defined in the - * section 3.2 of - * [CTA-5004](https://cdn.cta.tech/cta/media/media/resources/standards/pdfs/cta-5004-final.pdf). - */ - static serialize(data) { - const results = []; - const isValid = value => !Number.isNaN(value) && value != null && value !== '' && value !== false; - const toRounded = value => Math.round(value); - const toHundred = value => toRounded(value / 100) * 100; - const toUrlSafe = value => encodeURIComponent(value); - const formatters = { - br: toRounded, - d: toRounded, - bl: toHundred, - dl: toHundred, - mtp: toHundred, - nor: toUrlSafe, - rtp: toHundred, - tb: toRounded - }; - const keys = Object.keys(data || {}).sort(); - for (const key of keys) { - let value = data[key]; - - // ignore invalid values - if (!isValid(value)) { - continue; - } - - // Version should only be reported if not equal to 1. - if (key === 'v' && value === 1) { - continue; - } - - // Playback rate should only be sent if not equal to 1. - if (key == 'pr' && value === 1) { - continue; - } - - // Certain values require special formatting - const formatter = formatters[key]; - if (formatter) { - value = formatter(value); - } - - // Serialize the key/value pair - const type = typeof value; - let result; - if (key === 'ot' || key === 'sf' || key === 'st') { - result = `${key}=${value}`; - } else if (type === 'boolean') { - result = key; - } else if (type === 'number') { - result = `${key}=${value}`; - } else { - result = `${key}=${JSON.stringify(value)}`; - } - results.push(result); - } - return results.join(','); - } - - /** - * Convert a CMCD data object to request headers according to the rules - * defined in the section 2.1 and 3.2 of - * [CTA-5004](https://cdn.cta.tech/cta/media/media/resources/standards/pdfs/cta-5004-final.pdf). - */ - static toHeaders(data) { - const keys = Object.keys(data); - const headers = {}; - const headerNames = ['Object', 'Request', 'Session', 'Status']; - const headerGroups = [{}, {}, {}, {}]; - const headerMap = { - br: 0, - d: 0, - ot: 0, - tb: 0, - bl: 1, - dl: 1, - mtp: 1, - nor: 1, - nrr: 1, - su: 1, - cid: 2, - pr: 2, - sf: 2, - sid: 2, - st: 2, - v: 2, - bs: 3, - rtp: 3 - }; - for (const key of keys) { - // Unmapped fields are mapped to the Request header - const index = headerMap[key] != null ? headerMap[key] : 1; - headerGroups[index][key] = data[key]; - } - for (let i = 0; i < headerGroups.length; i++) { - const value = CMCDController.serialize(headerGroups[i]); - if (value) { - headers[`CMCD-${headerNames[i]}`] = value; - } - } - return headers; - } - - /** - * Convert a CMCD data object to query args according to the rules - * defined in the section 2.2 and 3.2 of - * [CTA-5004](https://cdn.cta.tech/cta/media/media/resources/standards/pdfs/cta-5004-final.pdf). - */ - static toQuery(data) { - return `CMCD=${encodeURIComponent(CMCDController.serialize(data))}`; - } - - /** - * Append query args to a uri. - */ - static appendQueryToUri(uri, query) { - if (!query) { - return uri; - } - const separator = uri.includes('?') ? '&' : '?'; - return `${uri}${separator}${query}`; - } } const PATHWAY_PENALTY_DURATION_MS = 300000; @@ -198941,14 +199155,16 @@ class ContentSteeringController { } startLoad() { this.started = true; - self.clearTimeout(this.reloadTimer); + this.clearTimeout(); if (this.enabled && this.uri) { if (this.updated) { - const ttl = Math.max(this.timeToLoad * 1000 - (performance.now() - this.updated), 0); - this.scheduleRefresh(this.uri, ttl); - } else { - this.loadSteeringManifest(this.uri); + const ttl = this.timeToLoad * 1000 - (performance.now() - this.updated); + if (ttl > 0) { + this.scheduleRefresh(this.uri, ttl); + return; + } } + this.loadSteeringManifest(this.uri); } } stopLoad() { @@ -198957,7 +199173,13 @@ class ContentSteeringController { this.loader.destroy(); this.loader = null; } - self.clearTimeout(this.reloadTimer); + this.clearTimeout(); + } + clearTimeout() { + if (this.reloadTimer !== -1) { + self.clearTimeout(this.reloadTimer); + this.reloadTimer = -1; + } } destroy() { this.unregisterListeners(); @@ -199003,14 +199225,27 @@ class ContentSteeringController { errorAction } = data; if ((errorAction == null ? void 0 : errorAction.action) === NetworkErrorAction.SendAlternateToPenaltyBox && errorAction.flags === ErrorActionFlags.MoveAllAlternatesMatchingHost) { + const levels = this.levels; let pathwayPriority = this.pathwayPriority; - const pathwayId = this.pathwayId; - if (!this.penalizedPathways[pathwayId]) { - this.penalizedPathways[pathwayId] = performance.now(); + let errorPathway = this.pathwayId; + if (data.context) { + const { + groupId, + pathwayId, + type + } = data.context; + if (groupId && levels) { + errorPathway = this.getPathwayForGroupId(groupId, type, errorPathway); + } else if (pathwayId) { + errorPathway = pathwayId; + } + } + if (!(errorPathway in this.penalizedPathways)) { + this.penalizedPathways[errorPathway] = performance.now(); } - if (!pathwayPriority && this.levels) { + if (!pathwayPriority && levels) { // If PATHWAY-PRIORITY was not provided, list pathways for error handling - pathwayPriority = this.levels.reduce((pathways, level) => { + pathwayPriority = levels.reduce((pathways, level) => { if (pathways.indexOf(level.pathwayId) === -1) { pathways.push(level.pathwayId); } @@ -199019,7 +199254,10 @@ class ContentSteeringController { } if (pathwayPriority && pathwayPriority.length > 1) { this.updatePathwayPriority(pathwayPriority); - errorAction.resolved = this.pathwayId !== pathwayId; + errorAction.resolved = this.pathwayId !== errorPathway; + } + if (!errorAction.resolved) { + logger.warn(`Could not resolve ${data.details} ("${data.error.message}") with content-steering for Pathway: ${errorPathway} levels: ${levels ? levels.length : levels} priorities: ${JSON.stringify(pathwayPriority)} penalized: ${JSON.stringify(this.penalizedPathways)}`); } } } @@ -199059,7 +199297,7 @@ class ContentSteeringController { }); for (let i = 0; i < pathwayPriority.length; i++) { const pathwayId = pathwayPriority[i]; - if (penalizedPathways[pathwayId]) { + if (pathwayId in penalizedPathways) { continue; } if (pathwayId === this.pathwayId) { @@ -199071,6 +199309,7 @@ class ContentSteeringController { if (levels.length > 0) { this.log(`Setting Pathway to "${pathwayId}"`); this.pathwayId = pathwayId; + reassignFragmentLevelIndexes(levels); this.hls.trigger(Events.LEVELS_UPDATED, { levels }); @@ -199086,6 +199325,15 @@ class ContentSteeringController { } } } + getPathwayForGroupId(groupId, type, defaultPathway) { + const levels = this.getLevelsForPathway(defaultPathway).concat(this.levels || []); + for (let i = 0; i < levels.length; i++) { + if (type === PlaylistContextType.AUDIO_TRACK && levels[i].hasAudioGroup(groupId) || type === PlaylistContextType.SUBTITLE_TRACK && levels[i].hasSubtitleGroup(groupId)) { + return levels[i].pathwayId; + } + } + return defaultPathway; + } clonePathways(pathwayClones) { const levels = this.levels; if (!levels) { @@ -199103,9 +199351,6 @@ class ContentSteeringController { return; } const clonedVariants = this.getLevelsForPathway(baseId).map(baseLevel => { - const levelParsed = _extends({}, baseLevel); - levelParsed.details = undefined; - levelParsed.url = performUriReplacement(baseLevel.uri, baseLevel.attrs['STABLE-VARIANT-ID'], 'PER-VARIANT-URIS', uriReplacement); const attributes = new AttrList(baseLevel.attrs); attributes['PATHWAY-ID'] = cloneId; const clonedAudioGroupId = attributes.AUDIO && `${attributes.AUDIO}_clone_${cloneId}`; @@ -199118,10 +199363,27 @@ class ContentSteeringController { subtitleGroupCloneMap[attributes.SUBTITLES] = clonedSubtitleGroupId; attributes.SUBTITLES = clonedSubtitleGroupId; } - levelParsed.attrs = attributes; - const clonedLevel = new Level(levelParsed); - addGroupId(clonedLevel, 'audio', clonedAudioGroupId); - addGroupId(clonedLevel, 'text', clonedSubtitleGroupId); + const url = performUriReplacement(baseLevel.uri, attributes['STABLE-VARIANT-ID'], 'PER-VARIANT-URIS', uriReplacement); + const clonedLevel = new Level({ + attrs: attributes, + audioCodec: baseLevel.audioCodec, + bitrate: baseLevel.bitrate, + height: baseLevel.height, + name: baseLevel.name, + url, + videoCodec: baseLevel.videoCodec, + width: baseLevel.width + }); + if (baseLevel.audioGroups) { + for (let i = 1; i < baseLevel.audioGroups.length; i++) { + clonedLevel.addGroupId('audio', `${baseLevel.audioGroups[i]}_clone_${cloneId}`); + } + } + if (baseLevel.subtitleGroups) { + for (let i = 1; i < baseLevel.subtitleGroups.length; i++) { + clonedLevel.addGroupId('text', `${baseLevel.subtitleGroups[i]}_clone_${cloneId}`); + } + } return clonedLevel; }); levels.push(...clonedVariants); @@ -199190,6 +199452,11 @@ class ContentSteeringController { if (pathwayClones) { this.clonePathways(pathwayClones); } + const loadedSteeringData = { + steeringManifest: steeringData, + url: url.toString() + }; + this.hls.trigger(Events.STEERING_MANIFEST_LOADED, loadedSteeringData); if (pathwayPriority) { this.updatePathwayPriority(pathwayPriority); } @@ -199225,9 +199492,15 @@ class ContentSteeringController { this.loader.load(context, loaderConfig, callbacks); } scheduleRefresh(uri, ttlMs = this.timeToLoad * 1000) { - self.clearTimeout(this.reloadTimer); + this.clearTimeout(); this.reloadTimer = self.setTimeout(() => { - this.loadSteeringManifest(uri); + var _this$hls; + const media = (_this$hls = this.hls) == null ? void 0 : _this$hls.media; + if (media && !media.ended) { + this.loadSteeringManifest(uri); + return; + } + this.scheduleRefresh(uri, this.timeToLoad * 1000); }, ttlMs); } } @@ -199284,7 +199557,7 @@ class XhrLoader { this.retryDelay = void 0; this.config = null; this.callbacks = null; - this.context = void 0; + this.context = null; this.loader = null; this.stats = void 0; this.xhrSetup = config ? config.xhrSetup || null : null; @@ -199296,6 +199569,10 @@ class XhrLoader { this.abortInternal(); this.loader = null; this.config = null; + this.context = null; + this.xhrSetup = null; + // @ts-ignore + this.stats = null; } abortInternal() { const loader = this.loader; @@ -199332,7 +199609,7 @@ class XhrLoader { config, context } = this; - if (!config) { + if (!config || !context) { return; } const xhr = this.loader = new self.XMLHttpRequest(); @@ -199367,7 +199644,7 @@ class XhrLoader { if (!xhr.readyState) { xhr.open('GET', context.url, true); } - const headers = this.context.headers; + const headers = context.headers; const { maxTimeToFirstByteMs, maxLoadTimeMs @@ -199450,7 +199727,12 @@ class XhrLoader { const retryConfig = config.loadPolicy.errorRetry; const retryCount = stats.retry; // if max nb of retries reached or if http status between 400 and 499 (such error cannot be recovered, retrying is useless), return error - if (shouldRetry(retryConfig, retryCount, false, status)) { + const response = { + url: context.url, + data: undefined, + code: status + }; + if (shouldRetry(retryConfig, retryCount, false, response)) { this.retry(retryConfig); } else { logger.error(`${status} while loading ${context.url}`); @@ -199470,7 +199752,8 @@ class XhrLoader { if (shouldRetry(retryConfig, retryCount, true)) { this.retry(retryConfig); } else { - logger.warn(`timeout while loading ${this.context.url}`); + var _this$context; + logger.warn(`timeout while loading ${(_this$context = this.context) == null ? void 0 : _this$context.url}`); const callbacks = this.callbacks; if (callbacks) { this.abortInternal(); @@ -199485,7 +199768,7 @@ class XhrLoader { } = this; this.retryDelay = getRetryDelay(retryConfig, stats.retry); stats.retry++; - logger.warn(`${status ? 'HTTP Status ' + status : 'Timeout'} while loading ${context.url}, retrying ${stats.retry}/${retryConfig.maxNumRetry} in ${this.retryDelay}ms`); + logger.warn(`${status ? 'HTTP Status ' + status : 'Timeout'} while loading ${context == null ? void 0 : context.url}, retrying ${stats.retry}/${retryConfig.maxNumRetry} in ${this.retryDelay}ms`); // abort and reset internal state this.abortInternal(); this.loader = null; @@ -199534,10 +199817,10 @@ class FetchLoader { constructor(config /* HlsConfig */) { this.fetchSetup = void 0; this.requestTimeout = void 0; - this.request = void 0; - this.response = void 0; + this.request = null; + this.response = null; this.controller = void 0; - this.context = void 0; + this.context = null; this.config = null; this.callbacks = null; this.stats = void 0; @@ -199547,650 +199830,2942 @@ class FetchLoader { this.stats = new LoadStats(); } destroy() { - this.loader = this.callbacks = null; + this.loader = this.callbacks = this.context = this.config = this.request = null; this.abortInternal(); + this.response = null; + // @ts-ignore + this.fetchSetup = this.controller = this.stats = null; } abortInternal() { - const response = this.response; - if (!(response != null && response.ok)) { + if (this.controller && !this.stats.loading.end) { this.stats.aborted = true; this.controller.abort(); } } - abort() { - var _this$callbacks; - this.abortInternal(); - if ((_this$callbacks = this.callbacks) != null && _this$callbacks.onAbort) { - this.callbacks.onAbort(this.stats, this.context, this.response); + abort() { + var _this$callbacks; + this.abortInternal(); + if ((_this$callbacks = this.callbacks) != null && _this$callbacks.onAbort) { + this.callbacks.onAbort(this.stats, this.context, this.response); + } + } + load(context, config, callbacks) { + const stats = this.stats; + if (stats.loading.start) { + throw new Error('Loader can only be used once.'); + } + stats.loading.start = self.performance.now(); + const initParams = getRequestParameters(context, this.controller.signal); + const onProgress = callbacks.onProgress; + const isArrayBuffer = context.responseType === 'arraybuffer'; + const LENGTH = isArrayBuffer ? 'byteLength' : 'length'; + const { + maxTimeToFirstByteMs, + maxLoadTimeMs + } = config.loadPolicy; + this.context = context; + this.config = config; + this.callbacks = callbacks; + this.request = this.fetchSetup(context, initParams); + self.clearTimeout(this.requestTimeout); + config.timeout = maxTimeToFirstByteMs && isFiniteNumber(maxTimeToFirstByteMs) ? maxTimeToFirstByteMs : maxLoadTimeMs; + this.requestTimeout = self.setTimeout(() => { + this.abortInternal(); + callbacks.onTimeout(stats, context, this.response); + }, config.timeout); + self.fetch(this.request).then(response => { + this.response = this.loader = response; + const first = Math.max(self.performance.now(), stats.loading.start); + self.clearTimeout(this.requestTimeout); + config.timeout = maxLoadTimeMs; + this.requestTimeout = self.setTimeout(() => { + this.abortInternal(); + callbacks.onTimeout(stats, context, this.response); + }, maxLoadTimeMs - (first - stats.loading.start)); + if (!response.ok) { + const { + status, + statusText + } = response; + throw new FetchError(statusText || 'fetch, bad network response', status, response); + } + stats.loading.first = first; + stats.total = getContentLength(response.headers) || stats.total; + if (onProgress && isFiniteNumber(config.highWaterMark)) { + return this.loadProgressively(response, stats, context, config.highWaterMark, onProgress); + } + if (isArrayBuffer) { + return response.arrayBuffer(); + } + if (context.responseType === 'json') { + return response.json(); + } + return response.text(); + }).then(responseData => { + const response = this.response; + if (!response) { + throw new Error('loader destroyed'); + } + self.clearTimeout(this.requestTimeout); + stats.loading.end = Math.max(self.performance.now(), stats.loading.first); + const total = responseData[LENGTH]; + if (total) { + stats.loaded = stats.total = total; + } + const loaderResponse = { + url: response.url, + data: responseData, + code: response.status + }; + if (onProgress && !isFiniteNumber(config.highWaterMark)) { + onProgress(stats, context, responseData, response); + } + callbacks.onSuccess(loaderResponse, stats, context, response); + }).catch(error => { + self.clearTimeout(this.requestTimeout); + if (stats.aborted) { + return; + } + // CORS errors result in an undefined code. Set it to 0 here to align with XHR's behavior + // when destroying, 'error' itself can be undefined + const code = !error ? 0 : error.code || 0; + const text = !error ? null : error.message; + callbacks.onError({ + code, + text + }, context, error ? error.details : null, stats); + }); + } + getCacheAge() { + let result = null; + if (this.response) { + const ageHeader = this.response.headers.get('age'); + result = ageHeader ? parseFloat(ageHeader) : null; + } + return result; + } + getResponseHeader(name) { + return this.response ? this.response.headers.get(name) : null; + } + loadProgressively(response, stats, context, highWaterMark = 0, onProgress) { + const chunkCache = new ChunkCache(); + const reader = response.body.getReader(); + const pump = () => { + return reader.read().then(data => { + if (data.done) { + if (chunkCache.dataLength) { + onProgress(stats, context, chunkCache.flush(), response); + } + return Promise.resolve(new ArrayBuffer(0)); + } + const chunk = data.value; + const len = chunk.length; + stats.loaded += len; + if (len < highWaterMark || chunkCache.dataLength) { + // The current chunk is too small to to be emitted or the cache already has data + // Push it to the cache + chunkCache.push(chunk); + if (chunkCache.dataLength >= highWaterMark) { + // flush in order to join the typed arrays + onProgress(stats, context, chunkCache.flush(), response); + } + } else { + // If there's nothing cached already, and the chache is large enough + // just emit the progress event + onProgress(stats, context, chunk, response); + } + return pump(); + }).catch(() => { + /* aborted */ + return Promise.reject(); + }); + }; + return pump(); + } +} +function getRequestParameters(context, signal) { + const initParams = { + method: 'GET', + mode: 'cors', + credentials: 'same-origin', + signal, + headers: new self.Headers(_extends({}, context.headers)) + }; + if (context.rangeEnd) { + initParams.headers.set('Range', 'bytes=' + context.rangeStart + '-' + String(context.rangeEnd - 1)); + } + return initParams; +} +function getByteRangeLength(byteRangeHeader) { + const result = BYTERANGE.exec(byteRangeHeader); + if (result) { + return parseInt(result[2]) - parseInt(result[1]) + 1; + } +} +function getContentLength(headers) { + const contentRange = headers.get('Content-Range'); + if (contentRange) { + const byteRangeLength = getByteRangeLength(contentRange); + if (isFiniteNumber(byteRangeLength)) { + return byteRangeLength; + } + } + const contentLength = headers.get('Content-Length'); + if (contentLength) { + return parseInt(contentLength); + } +} +function getRequest(context, initParams) { + return new self.Request(context.url, initParams); +} +class FetchError extends Error { + constructor(message, code, details) { + super(message); + this.code = void 0; + this.details = void 0; + this.code = code; + this.details = details; + } +} + +const WHITESPACE_CHAR = /\s/; +const Cues = { + newCue(track, startTime, endTime, captionScreen) { + const result = []; + let row; + // the type data states this is VTTCue, but it can potentially be a TextTrackCue on old browsers + let cue; + let indenting; + let indent; + let text; + const Cue = self.VTTCue || self.TextTrackCue; + for (let r = 0; r < captionScreen.rows.length; r++) { + row = captionScreen.rows[r]; + indenting = true; + indent = 0; + text = ''; + if (!row.isEmpty()) { + var _track$cues; + for (let c = 0; c < row.chars.length; c++) { + if (WHITESPACE_CHAR.test(row.chars[c].uchar) && indenting) { + indent++; + } else { + text += row.chars[c].uchar; + indenting = false; + } + } + // To be used for cleaning-up orphaned roll-up captions + row.cueStartTime = startTime; + + // Give a slight bump to the endTime if it's equal to startTime to avoid a SyntaxError in IE + if (startTime === endTime) { + endTime += 0.0001; + } + if (indent >= 16) { + indent--; + } else { + indent++; + } + const cueText = fixLineBreaks(text.trim()); + const id = generateCueId(startTime, endTime, cueText); + + // If this cue already exists in the track do not push it + if (!(track != null && (_track$cues = track.cues) != null && _track$cues.getCueById(id))) { + cue = new Cue(startTime, endTime, cueText); + cue.id = id; + cue.line = r + 1; + cue.align = 'left'; + // Clamp the position between 10 and 80 percent (CEA-608 PAC indent code) + // https://dvcs.w3.org/hg/text-tracks/raw-file/default/608toVTT/608toVTT.html#positioning-in-cea-608 + // Firefox throws an exception and captions break with out of bounds 0-100 values + cue.position = 10 + Math.min(80, Math.floor(indent * 8 / 32) * 10); + result.push(cue); + } + } + } + if (track && result.length) { + // Sort bottom cues in reverse order so that they render in line order when overlapping in Chrome + result.sort((cueA, cueB) => { + if (cueA.line === 'auto' || cueB.line === 'auto') { + return 0; + } + if (cueA.line > 8 && cueB.line > 8) { + return cueB.line - cueA.line; + } + return cueA.line - cueB.line; + }); + result.forEach(cue => addCueToTrack(track, cue)); + } + return result; + } +}; + +/** + * @deprecated use fragLoadPolicy.default + */ + +/** + * @deprecated use manifestLoadPolicy.default and playlistLoadPolicy.default + */ + +const defaultLoadPolicy = { + maxTimeToFirstByteMs: 8000, + maxLoadTimeMs: 20000, + timeoutRetry: null, + errorRetry: null +}; + +/** + * @ignore + * If possible, keep hlsDefaultConfig shallow + * It is cloned whenever a new Hls instance is created, by keeping the config + * shallow the properties are cloned, and we don't end up manipulating the default + */ +const hlsDefaultConfig = _objectSpread2(_objectSpread2({ + autoStartLoad: true, + // used by stream-controller + startPosition: -1, + // used by stream-controller + defaultAudioCodec: undefined, + // used by stream-controller + debug: false, + // used by logger + capLevelOnFPSDrop: false, + // used by fps-controller + capLevelToPlayerSize: false, + // used by cap-level-controller + ignoreDevicePixelRatio: false, + // used by cap-level-controller + preferManagedMediaSource: true, + initialLiveManifestSize: 1, + // used by stream-controller + maxBufferLength: 30, + // used by stream-controller + backBufferLength: Infinity, + // used by buffer-controller + frontBufferFlushThreshold: Infinity, + maxBufferSize: 60 * 1000 * 1000, + // used by stream-controller + maxBufferHole: 0.1, + // used by stream-controller + highBufferWatchdogPeriod: 2, + // used by stream-controller + nudgeOffset: 0.1, + // used by stream-controller + nudgeMaxRetry: 3, + // used by stream-controller + maxFragLookUpTolerance: 0.25, + // used by stream-controller + liveSyncDurationCount: 3, + // used by latency-controller + liveMaxLatencyDurationCount: Infinity, + // used by latency-controller + liveSyncDuration: undefined, + // used by latency-controller + liveMaxLatencyDuration: undefined, + // used by latency-controller + maxLiveSyncPlaybackRate: 1, + // used by latency-controller + liveDurationInfinity: false, + // used by buffer-controller + /** + * @deprecated use backBufferLength + */ + liveBackBufferLength: null, + // used by buffer-controller + maxMaxBufferLength: 600, + // used by stream-controller + enableWorker: true, + // used by transmuxer + workerPath: null, + // used by transmuxer + enableSoftwareAES: true, + // used by decrypter + startLevel: undefined, + // used by level-controller + startFragPrefetch: false, + // used by stream-controller + fpsDroppedMonitoringPeriod: 5000, + // used by fps-controller + fpsDroppedMonitoringThreshold: 0.2, + // used by fps-controller + appendErrorMaxRetry: 3, + // used by buffer-controller + loader: XhrLoader, + // loader: FetchLoader, + fLoader: undefined, + // used by fragment-loader + pLoader: undefined, + // used by playlist-loader + xhrSetup: undefined, + // used by xhr-loader + licenseXhrSetup: undefined, + // used by eme-controller + licenseResponseCallback: undefined, + // used by eme-controller + abrController: AbrController, + bufferController: BufferController, + capLevelController: CapLevelController, + errorController: ErrorController, + fpsController: FPSController, + stretchShortVideoTrack: false, + // used by mp4-remuxer + maxAudioFramesDrift: 1, + // used by mp4-remuxer + forceKeyFrameOnDiscontinuity: true, + // used by ts-demuxer + abrEwmaFastLive: 3, + // used by abr-controller + abrEwmaSlowLive: 9, + // used by abr-controller + abrEwmaFastVoD: 3, + // used by abr-controller + abrEwmaSlowVoD: 9, + // used by abr-controller + abrEwmaDefaultEstimate: 5e5, + // 500 kbps // used by abr-controller + abrEwmaDefaultEstimateMax: 5e6, + // 5 mbps + abrBandWidthFactor: 0.95, + // used by abr-controller + abrBandWidthUpFactor: 0.7, + // used by abr-controller + abrMaxWithRealBitrate: false, + // used by abr-controller + maxStarvationDelay: 4, + // used by abr-controller + maxLoadingDelay: 4, + // used by abr-controller + minAutoBitrate: 0, + // used by hls + emeEnabled: false, + // used by eme-controller + widevineLicenseUrl: undefined, + // used by eme-controller + drmSystems: {}, + // used by eme-controller + drmSystemOptions: {}, + // used by eme-controller + requestMediaKeySystemAccessFunc: requestMediaKeySystemAccess , + // used by eme-controller + testBandwidth: true, + progressive: false, + lowLatencyMode: true, + cmcd: undefined, + enableDateRangeMetadataCues: true, + enableEmsgMetadataCues: true, + enableID3MetadataCues: true, + useMediaCapabilities: true, + certLoadPolicy: { + default: defaultLoadPolicy + }, + keyLoadPolicy: { + default: { + maxTimeToFirstByteMs: 8000, + maxLoadTimeMs: 20000, + timeoutRetry: { + maxNumRetry: 1, + retryDelayMs: 1000, + maxRetryDelayMs: 20000, + backoff: 'linear' + }, + errorRetry: { + maxNumRetry: 8, + retryDelayMs: 1000, + maxRetryDelayMs: 20000, + backoff: 'linear' + } + } + }, + manifestLoadPolicy: { + default: { + maxTimeToFirstByteMs: Infinity, + maxLoadTimeMs: 20000, + timeoutRetry: { + maxNumRetry: 2, + retryDelayMs: 0, + maxRetryDelayMs: 0 + }, + errorRetry: { + maxNumRetry: 1, + retryDelayMs: 1000, + maxRetryDelayMs: 8000 + } + } + }, + playlistLoadPolicy: { + default: { + maxTimeToFirstByteMs: 10000, + maxLoadTimeMs: 20000, + timeoutRetry: { + maxNumRetry: 2, + retryDelayMs: 0, + maxRetryDelayMs: 0 + }, + errorRetry: { + maxNumRetry: 2, + retryDelayMs: 1000, + maxRetryDelayMs: 8000 + } + } + }, + fragLoadPolicy: { + default: { + maxTimeToFirstByteMs: 10000, + maxLoadTimeMs: 120000, + timeoutRetry: { + maxNumRetry: 4, + retryDelayMs: 0, + maxRetryDelayMs: 0 + }, + errorRetry: { + maxNumRetry: 6, + retryDelayMs: 1000, + maxRetryDelayMs: 8000 + } + } + }, + steeringManifestLoadPolicy: { + default: { + maxTimeToFirstByteMs: 10000, + maxLoadTimeMs: 20000, + timeoutRetry: { + maxNumRetry: 2, + retryDelayMs: 0, + maxRetryDelayMs: 0 + }, + errorRetry: { + maxNumRetry: 1, + retryDelayMs: 1000, + maxRetryDelayMs: 8000 + } + } + }, + // These default settings are deprecated in favor of the above policies + // and are maintained for backwards compatibility + manifestLoadingTimeOut: 10000, + manifestLoadingMaxRetry: 1, + manifestLoadingRetryDelay: 1000, + manifestLoadingMaxRetryTimeout: 64000, + levelLoadingTimeOut: 10000, + levelLoadingMaxRetry: 4, + levelLoadingRetryDelay: 1000, + levelLoadingMaxRetryTimeout: 64000, + fragLoadingTimeOut: 20000, + fragLoadingMaxRetry: 6, + fragLoadingRetryDelay: 1000, + fragLoadingMaxRetryTimeout: 64000 +}, timelineConfig()), {}, { + subtitleStreamController: SubtitleStreamController , + subtitleTrackController: SubtitleTrackController , + timelineController: TimelineController , + audioStreamController: AudioStreamController , + audioTrackController: AudioTrackController , + emeController: EMEController , + cmcdController: CMCDController , + contentSteeringController: ContentSteeringController +}); +function timelineConfig() { + return { + cueHandler: Cues, + // used by timeline-controller + enableWebVTT: true, + // used by timeline-controller + enableIMSC1: true, + // used by timeline-controller + enableCEA708Captions: true, + // used by timeline-controller + captionsTextTrack1Label: 'English', + // used by timeline-controller + captionsTextTrack1LanguageCode: 'en', + // used by timeline-controller + captionsTextTrack2Label: 'Spanish', + // used by timeline-controller + captionsTextTrack2LanguageCode: 'es', + // used by timeline-controller + captionsTextTrack3Label: 'Unknown CC', + // used by timeline-controller + captionsTextTrack3LanguageCode: '', + // used by timeline-controller + captionsTextTrack4Label: 'Unknown CC', + // used by timeline-controller + captionsTextTrack4LanguageCode: '', + // used by timeline-controller + renderTextTracksNatively: true + }; +} + +/** + * @ignore + */ +function mergeConfig(defaultConfig, userConfig) { + if ((userConfig.liveSyncDurationCount || userConfig.liveMaxLatencyDurationCount) && (userConfig.liveSyncDuration || userConfig.liveMaxLatencyDuration)) { + throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration"); + } + if (userConfig.liveMaxLatencyDurationCount !== undefined && (userConfig.liveSyncDurationCount === undefined || userConfig.liveMaxLatencyDurationCount <= userConfig.liveSyncDurationCount)) { + throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be greater than "liveSyncDurationCount"'); + } + if (userConfig.liveMaxLatencyDuration !== undefined && (userConfig.liveSyncDuration === undefined || userConfig.liveMaxLatencyDuration <= userConfig.liveSyncDuration)) { + throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be greater than "liveSyncDuration"'); + } + const defaultsCopy = deepCpy(defaultConfig); + + // Backwards compatibility with deprecated config values + const deprecatedSettingTypes = ['manifest', 'level', 'frag']; + const deprecatedSettings = ['TimeOut', 'MaxRetry', 'RetryDelay', 'MaxRetryTimeout']; + deprecatedSettingTypes.forEach(type => { + const policyName = `${type === 'level' ? 'playlist' : type}LoadPolicy`; + const policyNotSet = userConfig[policyName] === undefined; + const report = []; + deprecatedSettings.forEach(setting => { + const deprecatedSetting = `${type}Loading${setting}`; + const value = userConfig[deprecatedSetting]; + if (value !== undefined && policyNotSet) { + report.push(deprecatedSetting); + const settings = defaultsCopy[policyName].default; + userConfig[policyName] = { + default: settings + }; + switch (setting) { + case 'TimeOut': + settings.maxLoadTimeMs = value; + settings.maxTimeToFirstByteMs = value; + break; + case 'MaxRetry': + settings.errorRetry.maxNumRetry = value; + settings.timeoutRetry.maxNumRetry = value; + break; + case 'RetryDelay': + settings.errorRetry.retryDelayMs = value; + settings.timeoutRetry.retryDelayMs = value; + break; + case 'MaxRetryTimeout': + settings.errorRetry.maxRetryDelayMs = value; + settings.timeoutRetry.maxRetryDelayMs = value; + break; + } + } + }); + if (report.length) { + logger.warn(`hls.js config: "${report.join('", "')}" setting(s) are deprecated, use "${policyName}": ${JSON.stringify(userConfig[policyName])}`); + } + }); + return _objectSpread2(_objectSpread2({}, defaultsCopy), userConfig); +} +function deepCpy(obj) { + if (obj && typeof obj === 'object') { + if (Array.isArray(obj)) { + return obj.map(deepCpy); + } + return Object.keys(obj).reduce((result, key) => { + result[key] = deepCpy(obj[key]); + return result; + }, {}); + } + return obj; +} + +/** + * @ignore + */ +function enableStreamingMode(config) { + const currentLoader = config.loader; + if (currentLoader !== FetchLoader && currentLoader !== XhrLoader) { + // If a developer has configured their own loader, respect that choice + logger.log('[config]: Custom loader detected, cannot enable progressive streaming'); + config.progressive = false; + } else { + const canStreamProgressively = fetchSupported(); + if (canStreamProgressively) { + config.loader = FetchLoader; + config.progressive = true; + config.enableSoftwareAES = true; + logger.log('[config]: Progressive streaming enabled, using FetchLoader'); + } + } +} + +let chromeOrFirefox; +class LevelController extends BasePlaylistController { + constructor(hls, contentSteeringController) { + super(hls, '[level-controller]'); + this._levels = []; + this._firstLevel = -1; + this._maxAutoLevel = -1; + this._startLevel = void 0; + this.currentLevel = null; + this.currentLevelIndex = -1; + this.manualLevelIndex = -1; + this.steering = void 0; + this.onParsedComplete = void 0; + this.steering = contentSteeringController; + this._registerListeners(); + } + _registerListeners() { + const { + hls + } = this; + hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this); + hls.on(Events.MANIFEST_LOADED, this.onManifestLoaded, this); + hls.on(Events.LEVEL_LOADED, this.onLevelLoaded, this); + hls.on(Events.LEVELS_UPDATED, this.onLevelsUpdated, this); + hls.on(Events.FRAG_BUFFERED, this.onFragBuffered, this); + hls.on(Events.ERROR, this.onError, this); + } + _unregisterListeners() { + const { + hls + } = this; + hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this); + hls.off(Events.MANIFEST_LOADED, this.onManifestLoaded, this); + hls.off(Events.LEVEL_LOADED, this.onLevelLoaded, this); + hls.off(Events.LEVELS_UPDATED, this.onLevelsUpdated, this); + hls.off(Events.FRAG_BUFFERED, this.onFragBuffered, this); + hls.off(Events.ERROR, this.onError, this); + } + destroy() { + this._unregisterListeners(); + this.steering = null; + this.resetLevels(); + super.destroy(); + } + stopLoad() { + const levels = this._levels; + + // clean up live level details to force reload them, and reset load errors + levels.forEach(level => { + level.loadError = 0; + level.fragmentError = 0; + }); + super.stopLoad(); + } + resetLevels() { + this._startLevel = undefined; + this.manualLevelIndex = -1; + this.currentLevelIndex = -1; + this.currentLevel = null; + this._levels = []; + this._maxAutoLevel = -1; + } + onManifestLoading(event, data) { + this.resetLevels(); + } + onManifestLoaded(event, data) { + const preferManagedMediaSource = this.hls.config.preferManagedMediaSource; + const levels = []; + const redundantSet = {}; + const generatePathwaySet = {}; + let resolutionFound = false; + let videoCodecFound = false; + let audioCodecFound = false; + data.levels.forEach(levelParsed => { + var _audioCodec, _videoCodec; + const attributes = levelParsed.attrs; + + // erase audio codec info if browser does not support mp4a.40.34. + // demuxer will autodetect codec and fallback to mpeg/audio + let { + audioCodec, + videoCodec + } = levelParsed; + if (((_audioCodec = audioCodec) == null ? void 0 : _audioCodec.indexOf('mp4a.40.34')) !== -1) { + chromeOrFirefox || (chromeOrFirefox = /chrome|firefox/i.test(navigator.userAgent)); + if (chromeOrFirefox) { + levelParsed.audioCodec = audioCodec = undefined; + } + } + if (audioCodec) { + levelParsed.audioCodec = audioCodec = getCodecCompatibleName(audioCodec, preferManagedMediaSource); + } + if (((_videoCodec = videoCodec) == null ? void 0 : _videoCodec.indexOf('avc1')) === 0) { + videoCodec = levelParsed.videoCodec = convertAVC1ToAVCOTI(videoCodec); + } + + // only keep levels with supported audio/video codecs + const { + width, + height, + unknownCodecs + } = levelParsed; + resolutionFound || (resolutionFound = !!(width && height)); + videoCodecFound || (videoCodecFound = !!videoCodec); + audioCodecFound || (audioCodecFound = !!audioCodec); + if (unknownCodecs != null && unknownCodecs.length || audioCodec && !areCodecsMediaSourceSupported(audioCodec, 'audio', preferManagedMediaSource) || videoCodec && !areCodecsMediaSourceSupported(videoCodec, 'video', preferManagedMediaSource)) { + return; + } + const { + CODECS, + 'FRAME-RATE': FRAMERATE, + 'HDCP-LEVEL': HDCP, + 'PATHWAY-ID': PATHWAY, + RESOLUTION, + 'VIDEO-RANGE': VIDEO_RANGE + } = attributes; + const contentSteeringPrefix = `${PATHWAY || '.'}-`; + const levelKey = `${contentSteeringPrefix}${levelParsed.bitrate}-${RESOLUTION}-${FRAMERATE}-${CODECS}-${VIDEO_RANGE}-${HDCP}`; + if (!redundantSet[levelKey]) { + const level = new Level(levelParsed); + redundantSet[levelKey] = level; + generatePathwaySet[levelKey] = 1; + levels.push(level); + } else if (redundantSet[levelKey].uri !== levelParsed.url && !levelParsed.attrs['PATHWAY-ID']) { + // Assign Pathway IDs to Redundant Streams (default Pathways is ".". Redundant Streams "..", "...", and so on.) + // Content Steering controller to handles Pathway fallback on error + const pathwayCount = generatePathwaySet[levelKey] += 1; + levelParsed.attrs['PATHWAY-ID'] = new Array(pathwayCount + 1).join('.'); + const level = new Level(levelParsed); + redundantSet[levelKey] = level; + levels.push(level); + } else { + redundantSet[levelKey].addGroupId('audio', attributes.AUDIO); + redundantSet[levelKey].addGroupId('text', attributes.SUBTITLES); + } + }); + this.filterAndSortMediaOptions(levels, data, resolutionFound, videoCodecFound, audioCodecFound); + } + filterAndSortMediaOptions(filteredLevels, data, resolutionFound, videoCodecFound, audioCodecFound) { + let audioTracks = []; + let subtitleTracks = []; + let levels = filteredLevels; + + // remove audio-only and invalid video-range levels if we also have levels with video codecs or RESOLUTION signalled + if ((resolutionFound || videoCodecFound) && audioCodecFound) { + levels = levels.filter(({ + videoCodec, + videoRange, + width, + height + }) => (!!videoCodec || !!(width && height)) && isVideoRange(videoRange)); + } + if (levels.length === 0) { + // Dispatch error after MANIFEST_LOADED is done propagating + Promise.resolve().then(() => { + if (this.hls) { + if (data.levels.length) { + this.warn(`One or more CODECS in variant not supported: ${JSON.stringify(data.levels[0].attrs)}`); + } + const error = new Error('no level with compatible codecs found in manifest'); + this.hls.trigger(Events.ERROR, { + type: ErrorTypes.MEDIA_ERROR, + details: ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR, + fatal: true, + url: data.url, + error, + reason: error.message + }); + } + }); + return; + } + if (data.audioTracks) { + const { + preferManagedMediaSource + } = this.hls.config; + audioTracks = data.audioTracks.filter(track => !track.audioCodec || areCodecsMediaSourceSupported(track.audioCodec, 'audio', preferManagedMediaSource)); + // Assign ids after filtering as array indices by group-id + assignTrackIdsByGroup(audioTracks); + } + if (data.subtitles) { + subtitleTracks = data.subtitles; + assignTrackIdsByGroup(subtitleTracks); + } + // start bitrate is the first bitrate of the manifest + const unsortedLevels = levels.slice(0); + // sort levels from lowest to highest + levels.sort((a, b) => { + if (a.attrs['HDCP-LEVEL'] !== b.attrs['HDCP-LEVEL']) { + return (a.attrs['HDCP-LEVEL'] || '') > (b.attrs['HDCP-LEVEL'] || '') ? 1 : -1; + } + // sort on height before bitrate for cap-level-controller + if (resolutionFound && a.height !== b.height) { + return a.height - b.height; + } + if (a.frameRate !== b.frameRate) { + return a.frameRate - b.frameRate; + } + if (a.videoRange !== b.videoRange) { + return VideoRangeValues.indexOf(a.videoRange) - VideoRangeValues.indexOf(b.videoRange); + } + if (a.videoCodec !== b.videoCodec) { + const valueA = videoCodecPreferenceValue(a.videoCodec); + const valueB = videoCodecPreferenceValue(b.videoCodec); + if (valueA !== valueB) { + return valueB - valueA; + } + } + if (a.uri === b.uri && a.codecSet !== b.codecSet) { + const valueA = codecsSetSelectionPreferenceValue(a.codecSet); + const valueB = codecsSetSelectionPreferenceValue(b.codecSet); + if (valueA !== valueB) { + return valueB - valueA; + } + } + if (a.bitrate !== b.bitrate) { + return a.bitrate - b.bitrate; + } + return 0; + }); + let firstLevelInPlaylist = unsortedLevels[0]; + if (this.steering) { + levels = this.steering.filterParsedLevels(levels); + if (levels.length !== unsortedLevels.length) { + for (let i = 0; i < unsortedLevels.length; i++) { + if (unsortedLevels[i].pathwayId === levels[0].pathwayId) { + firstLevelInPlaylist = unsortedLevels[i]; + break; + } + } + } + } + this._levels = levels; + + // find index of first level in sorted levels + for (let i = 0; i < levels.length; i++) { + if (levels[i] === firstLevelInPlaylist) { + var _this$hls$userConfig; + this._firstLevel = i; + const firstLevelBitrate = firstLevelInPlaylist.bitrate; + const bandwidthEstimate = this.hls.bandwidthEstimate; + this.log(`manifest loaded, ${levels.length} level(s) found, first bitrate: ${firstLevelBitrate}`); + // Update default bwe to first variant bitrate as long it has not been configured or set + if (((_this$hls$userConfig = this.hls.userConfig) == null ? void 0 : _this$hls$userConfig.abrEwmaDefaultEstimate) === undefined) { + const startingBwEstimate = Math.min(firstLevelBitrate, this.hls.config.abrEwmaDefaultEstimateMax); + if (startingBwEstimate > bandwidthEstimate && bandwidthEstimate === hlsDefaultConfig.abrEwmaDefaultEstimate) { + this.hls.bandwidthEstimate = startingBwEstimate; + } + } + break; + } + } + + // Audio is only alternate if manifest include a URI along with the audio group tag, + // and this is not an audio-only stream where levels contain audio-only + const audioOnly = audioCodecFound && !videoCodecFound; + const edata = { + levels, + audioTracks, + subtitleTracks, + sessionData: data.sessionData, + sessionKeys: data.sessionKeys, + firstLevel: this._firstLevel, + stats: data.stats, + audio: audioCodecFound, + video: videoCodecFound, + altAudio: !audioOnly && audioTracks.some(t => !!t.url) + }; + this.hls.trigger(Events.MANIFEST_PARSED, edata); + + // Initiate loading after all controllers have received MANIFEST_PARSED + if (this.hls.config.autoStartLoad || this.hls.forceStartLoad) { + this.hls.startLoad(this.hls.config.startPosition); + } + } + get levels() { + if (this._levels.length === 0) { + return null; + } + return this._levels; + } + get level() { + return this.currentLevelIndex; + } + set level(newLevel) { + const levels = this._levels; + if (levels.length === 0) { + return; + } + // check if level idx is valid + if (newLevel < 0 || newLevel >= levels.length) { + // invalid level id given, trigger error + const error = new Error('invalid level idx'); + const fatal = newLevel < 0; + this.hls.trigger(Events.ERROR, { + type: ErrorTypes.OTHER_ERROR, + details: ErrorDetails.LEVEL_SWITCH_ERROR, + level: newLevel, + fatal, + error, + reason: error.message + }); + if (fatal) { + return; + } + newLevel = Math.min(newLevel, levels.length - 1); + } + const lastLevelIndex = this.currentLevelIndex; + const lastLevel = this.currentLevel; + const lastPathwayId = lastLevel ? lastLevel.attrs['PATHWAY-ID'] : undefined; + const level = levels[newLevel]; + const pathwayId = level.attrs['PATHWAY-ID']; + this.currentLevelIndex = newLevel; + this.currentLevel = level; + if (lastLevelIndex === newLevel && level.details && lastLevel && lastPathwayId === pathwayId) { + return; + } + this.log(`Switching to level ${newLevel} (${level.height ? level.height + 'p ' : ''}${level.videoRange ? level.videoRange + ' ' : ''}${level.codecSet ? level.codecSet + ' ' : ''}@${level.bitrate})${pathwayId ? ' with Pathway ' + pathwayId : ''} from level ${lastLevelIndex}${lastPathwayId ? ' with Pathway ' + lastPathwayId : ''}`); + const levelSwitchingData = { + level: newLevel, + attrs: level.attrs, + details: level.details, + bitrate: level.bitrate, + averageBitrate: level.averageBitrate, + maxBitrate: level.maxBitrate, + realBitrate: level.realBitrate, + width: level.width, + height: level.height, + codecSet: level.codecSet, + audioCodec: level.audioCodec, + videoCodec: level.videoCodec, + audioGroups: level.audioGroups, + subtitleGroups: level.subtitleGroups, + loaded: level.loaded, + loadError: level.loadError, + fragmentError: level.fragmentError, + name: level.name, + id: level.id, + uri: level.uri, + url: level.url, + urlId: 0, + audioGroupIds: level.audioGroupIds, + textGroupIds: level.textGroupIds + }; + this.hls.trigger(Events.LEVEL_SWITCHING, levelSwitchingData); + // check if we need to load playlist for this level + const levelDetails = level.details; + if (!levelDetails || levelDetails.live) { + // level not retrieved yet, or live playlist we need to (re)load it + const hlsUrlParameters = this.switchParams(level.uri, lastLevel == null ? void 0 : lastLevel.details); + this.loadPlaylist(hlsUrlParameters); + } + } + get manualLevel() { + return this.manualLevelIndex; + } + set manualLevel(newLevel) { + this.manualLevelIndex = newLevel; + if (this._startLevel === undefined) { + this._startLevel = newLevel; + } + if (newLevel !== -1) { + this.level = newLevel; + } + } + get firstLevel() { + return this._firstLevel; + } + set firstLevel(newLevel) { + this._firstLevel = newLevel; + } + get startLevel() { + // Setting hls.startLevel (this._startLevel) overrides config.startLevel + if (this._startLevel === undefined) { + const configStartLevel = this.hls.config.startLevel; + if (configStartLevel !== undefined) { + return configStartLevel; + } + return this.hls.firstAutoLevel; + } + return this._startLevel; + } + set startLevel(newLevel) { + this._startLevel = newLevel; + } + onError(event, data) { + if (data.fatal || !data.context) { + return; + } + if (data.context.type === PlaylistContextType.LEVEL && data.context.level === this.level) { + this.checkRetry(data); + } + } + + // reset errors on the successful load of a fragment + onFragBuffered(event, { + frag + }) { + if (frag !== undefined && frag.type === PlaylistLevelType.MAIN) { + const el = frag.elementaryStreams; + if (!Object.keys(el).some(type => !!el[type])) { + return; + } + const level = this._levels[frag.level]; + if (level != null && level.loadError) { + this.log(`Resetting level error count of ${level.loadError} on frag buffered`); + level.loadError = 0; + } + } + } + onLevelLoaded(event, data) { + var _data$deliveryDirecti2; + const { + level, + details + } = data; + const curLevel = this._levels[level]; + if (!curLevel) { + var _data$deliveryDirecti; + this.warn(`Invalid level index ${level}`); + if ((_data$deliveryDirecti = data.deliveryDirectives) != null && _data$deliveryDirecti.skip) { + details.deltaUpdateFailed = true; + } + return; + } + + // only process level loaded events matching with expected level + if (level === this.currentLevelIndex) { + // reset level load error counter on successful level loaded only if there is no issues with fragments + if (curLevel.fragmentError === 0) { + curLevel.loadError = 0; + } + this.playlistLoaded(level, data, curLevel.details); + } else if ((_data$deliveryDirecti2 = data.deliveryDirectives) != null && _data$deliveryDirecti2.skip) { + // received a delta playlist update that cannot be merged + details.deltaUpdateFailed = true; + } + } + loadPlaylist(hlsUrlParameters) { + super.loadPlaylist(); + const currentLevelIndex = this.currentLevelIndex; + const currentLevel = this.currentLevel; + if (currentLevel && this.shouldLoadPlaylist(currentLevel)) { + let url = currentLevel.uri; + if (hlsUrlParameters) { + try { + url = hlsUrlParameters.addDirectives(url); + } catch (error) { + this.warn(`Could not construct new URL with HLS Delivery Directives: ${error}`); + } + } + const pathwayId = currentLevel.attrs['PATHWAY-ID']; + this.log(`Loading level index ${currentLevelIndex}${(hlsUrlParameters == null ? void 0 : hlsUrlParameters.msn) !== undefined ? ' at sn ' + hlsUrlParameters.msn + ' part ' + hlsUrlParameters.part : ''} with${pathwayId ? ' Pathway ' + pathwayId : ''} ${url}`); + + // console.log('Current audio track group ID:', this.hls.audioTracks[this.hls.audioTrack].groupId); + // console.log('New video quality level audio group id:', levelObject.attrs.AUDIO, level); + this.clearTimer(); + this.hls.trigger(Events.LEVEL_LOADING, { + url, + level: currentLevelIndex, + pathwayId: currentLevel.attrs['PATHWAY-ID'], + id: 0, + // Deprecated Level urlId + deliveryDirectives: hlsUrlParameters || null + }); + } + } + get nextLoadLevel() { + if (this.manualLevelIndex !== -1) { + return this.manualLevelIndex; + } else { + return this.hls.nextAutoLevel; + } + } + set nextLoadLevel(nextLevel) { + this.level = nextLevel; + if (this.manualLevelIndex === -1) { + this.hls.nextAutoLevel = nextLevel; + } + } + removeLevel(levelIndex) { + var _this$currentLevel; + const levels = this._levels.filter((level, index) => { + if (index !== levelIndex) { + return true; + } + if (this.steering) { + this.steering.removeLevel(level); + } + if (level === this.currentLevel) { + this.currentLevel = null; + this.currentLevelIndex = -1; + if (level.details) { + level.details.fragments.forEach(f => f.level = -1); + } + } + return false; + }); + reassignFragmentLevelIndexes(levels); + this._levels = levels; + if (this.currentLevelIndex > -1 && (_this$currentLevel = this.currentLevel) != null && _this$currentLevel.details) { + this.currentLevelIndex = this.currentLevel.details.fragments[0].level; + } + this.hls.trigger(Events.LEVELS_UPDATED, { + levels + }); + } + onLevelsUpdated(event, { + levels + }) { + this._levels = levels; + } + checkMaxAutoUpdated() { + const { + autoLevelCapping, + maxAutoLevel, + maxHdcpLevel + } = this.hls; + if (this._maxAutoLevel !== maxAutoLevel) { + this._maxAutoLevel = maxAutoLevel; + this.hls.trigger(Events.MAX_AUTO_LEVEL_UPDATED, { + autoLevelCapping, + levels: this.levels, + maxAutoLevel, + minAutoLevel: this.hls.minAutoLevel, + maxHdcpLevel + }); + } + } +} +function assignTrackIdsByGroup(tracks) { + const groups = {}; + tracks.forEach(track => { + const groupId = track.groupId || ''; + track.id = groups[groupId] = groups[groupId] || 0; + groups[groupId]++; + }); +} + +class KeyLoader { + constructor(config) { + this.config = void 0; + this.keyUriToKeyInfo = {}; + this.emeController = null; + this.config = config; + } + abort(type) { + for (const uri in this.keyUriToKeyInfo) { + const loader = this.keyUriToKeyInfo[uri].loader; + if (loader) { + var _loader$context; + if (type && type !== ((_loader$context = loader.context) == null ? void 0 : _loader$context.frag.type)) { + return; + } + loader.abort(); + } + } + } + detach() { + for (const uri in this.keyUriToKeyInfo) { + const keyInfo = this.keyUriToKeyInfo[uri]; + // Remove cached EME keys on detach + if (keyInfo.mediaKeySessionContext || keyInfo.decryptdata.isCommonEncryption) { + delete this.keyUriToKeyInfo[uri]; + } + } + } + destroy() { + this.detach(); + for (const uri in this.keyUriToKeyInfo) { + const loader = this.keyUriToKeyInfo[uri].loader; + if (loader) { + loader.destroy(); + } + } + this.keyUriToKeyInfo = {}; + } + createKeyLoadError(frag, details = ErrorDetails.KEY_LOAD_ERROR, error, networkDetails, response) { + return new LoadError({ + type: ErrorTypes.NETWORK_ERROR, + details, + fatal: false, + frag, + response, + error, + networkDetails + }); + } + loadClear(loadingFrag, encryptedFragments) { + if (this.emeController && this.config.emeEnabled) { + // access key-system with nearest key on start (loaidng frag is unencrypted) + const { + sn, + cc + } = loadingFrag; + for (let i = 0; i < encryptedFragments.length; i++) { + const frag = encryptedFragments[i]; + if (cc <= frag.cc && (sn === 'initSegment' || frag.sn === 'initSegment' || sn < frag.sn)) { + this.emeController.selectKeySystemFormat(frag).then(keySystemFormat => { + frag.setKeyFormat(keySystemFormat); + }); + break; + } + } + } + } + load(frag) { + if (!frag.decryptdata && frag.encrypted && this.emeController) { + // Multiple keys, but none selected, resolve in eme-controller + return this.emeController.selectKeySystemFormat(frag).then(keySystemFormat => { + return this.loadInternal(frag, keySystemFormat); + }); + } + return this.loadInternal(frag); + } + loadInternal(frag, keySystemFormat) { + var _keyInfo, _keyInfo2; + if (keySystemFormat) { + frag.setKeyFormat(keySystemFormat); + } + const decryptdata = frag.decryptdata; + if (!decryptdata) { + const error = new Error(keySystemFormat ? `Expected frag.decryptdata to be defined after setting format ${keySystemFormat}` : 'Missing decryption data on fragment in onKeyLoading'); + return Promise.reject(this.createKeyLoadError(frag, ErrorDetails.KEY_LOAD_ERROR, error)); + } + const uri = decryptdata.uri; + if (!uri) { + return Promise.reject(this.createKeyLoadError(frag, ErrorDetails.KEY_LOAD_ERROR, new Error(`Invalid key URI: "${uri}"`))); + } + let keyInfo = this.keyUriToKeyInfo[uri]; + if ((_keyInfo = keyInfo) != null && _keyInfo.decryptdata.key) { + decryptdata.key = keyInfo.decryptdata.key; + return Promise.resolve({ + frag, + keyInfo + }); + } + // Return key load promise as long as it does not have a mediakey session with an unusable key status + if ((_keyInfo2 = keyInfo) != null && _keyInfo2.keyLoadPromise) { + var _keyInfo$mediaKeySess; + switch ((_keyInfo$mediaKeySess = keyInfo.mediaKeySessionContext) == null ? void 0 : _keyInfo$mediaKeySess.keyStatus) { + case undefined: + case 'status-pending': + case 'usable': + case 'usable-in-future': + return keyInfo.keyLoadPromise.then(keyLoadedData => { + // Return the correct fragment with updated decryptdata key and loaded keyInfo + decryptdata.key = keyLoadedData.keyInfo.decryptdata.key; + return { + frag, + keyInfo + }; + }); + } + // If we have a key session and status and it is not pending or usable, continue + // This will go back to the eme-controller for expired keys to get a new keyLoadPromise + } + + // Load the key or return the loading promise + keyInfo = this.keyUriToKeyInfo[uri] = { + decryptdata, + keyLoadPromise: null, + loader: null, + mediaKeySessionContext: null + }; + switch (decryptdata.method) { + case 'ISO-23001-7': + case 'SAMPLE-AES': + case 'SAMPLE-AES-CENC': + case 'SAMPLE-AES-CTR': + if (decryptdata.keyFormat === 'identity') { + // loadKeyHTTP handles http(s) and data URLs + return this.loadKeyHTTP(keyInfo, frag); + } + return this.loadKeyEME(keyInfo, frag); + case 'AES-128': + return this.loadKeyHTTP(keyInfo, frag); + default: + return Promise.reject(this.createKeyLoadError(frag, ErrorDetails.KEY_LOAD_ERROR, new Error(`Key supplied with unsupported METHOD: "${decryptdata.method}"`))); + } + } + loadKeyEME(keyInfo, frag) { + const keyLoadedData = { + frag, + keyInfo + }; + if (this.emeController && this.config.emeEnabled) { + const keySessionContextPromise = this.emeController.loadKey(keyLoadedData); + if (keySessionContextPromise) { + return (keyInfo.keyLoadPromise = keySessionContextPromise.then(keySessionContext => { + keyInfo.mediaKeySessionContext = keySessionContext; + return keyLoadedData; + })).catch(error => { + // Remove promise for license renewal or retry + keyInfo.keyLoadPromise = null; + throw error; + }); + } + } + return Promise.resolve(keyLoadedData); + } + loadKeyHTTP(keyInfo, frag) { + const config = this.config; + const Loader = config.loader; + const keyLoader = new Loader(config); + frag.keyLoader = keyInfo.loader = keyLoader; + return keyInfo.keyLoadPromise = new Promise((resolve, reject) => { + const loaderContext = { + keyInfo, + frag, + responseType: 'arraybuffer', + url: keyInfo.decryptdata.uri + }; + + // maxRetry is 0 so that instead of retrying the same key on the same variant multiple times, + // key-loader will trigger an error and rely on stream-controller to handle retry logic. + // this will also align retry logic with fragment-loader + const loadPolicy = config.keyLoadPolicy.default; + const loaderConfig = { + loadPolicy, + timeout: loadPolicy.maxLoadTimeMs, + maxRetry: 0, + retryDelay: 0, + maxRetryDelay: 0 + }; + const loaderCallbacks = { + onSuccess: (response, stats, context, networkDetails) => { + const { + frag, + keyInfo, + url: uri + } = context; + if (!frag.decryptdata || keyInfo !== this.keyUriToKeyInfo[uri]) { + return reject(this.createKeyLoadError(frag, ErrorDetails.KEY_LOAD_ERROR, new Error('after key load, decryptdata unset or changed'), networkDetails)); + } + keyInfo.decryptdata.key = frag.decryptdata.key = new Uint8Array(response.data); + + // detach fragment key loader on load success + frag.keyLoader = null; + keyInfo.loader = null; + resolve({ + frag, + keyInfo + }); + }, + onError: (response, context, networkDetails, stats) => { + this.resetLoader(context); + reject(this.createKeyLoadError(frag, ErrorDetails.KEY_LOAD_ERROR, new Error(`HTTP Error ${response.code} loading key ${response.text}`), networkDetails, _objectSpread2({ + url: loaderContext.url, + data: undefined + }, response))); + }, + onTimeout: (stats, context, networkDetails) => { + this.resetLoader(context); + reject(this.createKeyLoadError(frag, ErrorDetails.KEY_LOAD_TIMEOUT, new Error('key loading timed out'), networkDetails)); + }, + onAbort: (stats, context, networkDetails) => { + this.resetLoader(context); + reject(this.createKeyLoadError(frag, ErrorDetails.INTERNAL_ABORTED, new Error('key loading aborted'), networkDetails)); + } + }; + keyLoader.load(loaderContext, loaderConfig, loaderCallbacks); + }); + } + resetLoader(context) { + const { + frag, + keyInfo, + url: uri + } = context; + const loader = keyInfo.loader; + if (frag.keyLoader === loader) { + frag.keyLoader = null; + keyInfo.loader = null; + } + delete this.keyUriToKeyInfo[uri]; + if (loader) { + loader.destroy(); + } + } +} + +function getSourceBuffer() { + return self.SourceBuffer || self.WebKitSourceBuffer; +} +function isMSESupported() { + const mediaSource = getMediaSource(); + if (!mediaSource) { + return false; + } + + // if SourceBuffer is exposed ensure its API is valid + // Older browsers do not expose SourceBuffer globally so checking SourceBuffer.prototype is impossible + const sourceBuffer = getSourceBuffer(); + return !sourceBuffer || sourceBuffer.prototype && typeof sourceBuffer.prototype.appendBuffer === 'function' && typeof sourceBuffer.prototype.remove === 'function'; +} +function isSupported() { + if (!isMSESupported()) { + return false; + } + const mediaSource = getMediaSource(); + return typeof (mediaSource == null ? void 0 : mediaSource.isTypeSupported) === 'function' && (['avc1.42E01E,mp4a.40.2', 'av01.0.01M.08', 'vp09.00.50.08'].some(codecsForVideoContainer => mediaSource.isTypeSupported(mimeTypeForCodec(codecsForVideoContainer, 'video'))) || ['mp4a.40.2', 'fLaC'].some(codecForAudioContainer => mediaSource.isTypeSupported(mimeTypeForCodec(codecForAudioContainer, 'audio')))); +} +function changeTypeSupported() { + var _sourceBuffer$prototy; + const sourceBuffer = getSourceBuffer(); + return typeof (sourceBuffer == null ? void 0 : (_sourceBuffer$prototy = sourceBuffer.prototype) == null ? void 0 : _sourceBuffer$prototy.changeType) === 'function'; +} + +const STALL_MINIMUM_DURATION_MS = 250; +const MAX_START_GAP_JUMP = 2.0; +const SKIP_BUFFER_HOLE_STEP_SECONDS = 0.1; +const SKIP_BUFFER_RANGE_START = 0.05; +class GapController { + constructor(config, media, fragmentTracker, hls) { + this.config = void 0; + this.media = null; + this.fragmentTracker = void 0; + this.hls = void 0; + this.nudgeRetry = 0; + this.stallReported = false; + this.stalled = null; + this.moved = false; + this.seeking = false; + this.config = config; + this.media = media; + this.fragmentTracker = fragmentTracker; + this.hls = hls; + } + destroy() { + this.media = null; + // @ts-ignore + this.hls = this.fragmentTracker = null; + } + + /** + * Checks if the playhead is stuck within a gap, and if so, attempts to free it. + * A gap is an unbuffered range between two buffered ranges (or the start and the first buffered range). + * + * @param lastCurrentTime - Previously read playhead position + */ + poll(lastCurrentTime, activeFrag) { + const { + config, + media, + stalled + } = this; + if (media === null) { + return; + } + const { + currentTime, + seeking + } = media; + const seeked = this.seeking && !seeking; + const beginSeek = !this.seeking && seeking; + this.seeking = seeking; + + // The playhead is moving, no-op + if (currentTime !== lastCurrentTime) { + this.moved = true; + if (!seeking) { + this.nudgeRetry = 0; + } + if (stalled !== null) { + // The playhead is now moving, but was previously stalled + if (this.stallReported) { + const _stalledDuration = self.performance.now() - stalled; + logger.warn(`playback not stuck anymore @${currentTime}, after ${Math.round(_stalledDuration)}ms`); + this.stallReported = false; + } + this.stalled = null; + } + return; + } + + // Clear stalled state when beginning or finishing seeking so that we don't report stalls coming out of a seek + if (beginSeek || seeked) { + this.stalled = null; + return; + } + + // The playhead should not be moving + if (media.paused && !seeking || media.ended || media.playbackRate === 0 || !BufferHelper.getBuffered(media).length) { + this.nudgeRetry = 0; + return; + } + const bufferInfo = BufferHelper.bufferInfo(media, currentTime, 0); + const nextStart = bufferInfo.nextStart || 0; + if (seeking) { + // Waiting for seeking in a buffered range to complete + const hasEnoughBuffer = bufferInfo.len > MAX_START_GAP_JUMP; + // Next buffered range is too far ahead to jump to while still seeking + const noBufferGap = !nextStart || activeFrag && activeFrag.start <= currentTime || nextStart - currentTime > MAX_START_GAP_JUMP && !this.fragmentTracker.getPartialFragment(currentTime); + if (hasEnoughBuffer || noBufferGap) { + return; + } + // Reset moved state when seeking to a point in or before a gap + this.moved = false; + } + + // Skip start gaps if we haven't played, but the last poll detected the start of a stall + // The addition poll gives the browser a chance to jump the gap for us + if (!this.moved && this.stalled !== null) { + var _level$details; + // There is no playable buffer (seeked, waiting for buffer) + const isBuffered = bufferInfo.len > 0; + if (!isBuffered && !nextStart) { + return; + } + // Jump start gaps within jump threshold + const startJump = Math.max(nextStart, bufferInfo.start || 0) - currentTime; + + // When joining a live stream with audio tracks, account for live playlist window sliding by allowing + // a larger jump over start gaps caused by the audio-stream-controller buffering a start fragment + // that begins over 1 target duration after the video start position. + const level = this.hls.levels ? this.hls.levels[this.hls.currentLevel] : null; + const isLive = level == null ? void 0 : (_level$details = level.details) == null ? void 0 : _level$details.live; + const maxStartGapJump = isLive ? level.details.targetduration * 2 : MAX_START_GAP_JUMP; + const partialOrGap = this.fragmentTracker.getPartialFragment(currentTime); + if (startJump > 0 && (startJump <= maxStartGapJump || partialOrGap)) { + if (!media.paused) { + this._trySkipBufferHole(partialOrGap); + } + return; + } + } + + // Start tracking stall time + const tnow = self.performance.now(); + if (stalled === null) { + this.stalled = tnow; + return; + } + const stalledDuration = tnow - stalled; + if (!seeking && stalledDuration >= STALL_MINIMUM_DURATION_MS) { + // Report stalling after trying to fix + this._reportStall(bufferInfo); + if (!this.media) { + return; + } + } + const bufferedWithHoles = BufferHelper.bufferInfo(media, currentTime, config.maxBufferHole); + this._tryFixBufferStall(bufferedWithHoles, stalledDuration); + } + + /** + * Detects and attempts to fix known buffer stalling issues. + * @param bufferInfo - The properties of the current buffer. + * @param stalledDurationMs - The amount of time Hls.js has been stalling for. + * @private + */ + _tryFixBufferStall(bufferInfo, stalledDurationMs) { + const { + config, + fragmentTracker, + media + } = this; + if (media === null) { + return; + } + const currentTime = media.currentTime; + const partial = fragmentTracker.getPartialFragment(currentTime); + if (partial) { + // Try to skip over the buffer hole caused by a partial fragment + // This method isn't limited by the size of the gap between buffered ranges + const targetTime = this._trySkipBufferHole(partial); + // we return here in this case, meaning + // the branch below only executes when we haven't seeked to a new position + if (targetTime || !this.media) { + return; + } + } + + // if we haven't had to skip over a buffer hole of a partial fragment + // we may just have to "nudge" the playlist as the browser decoding/rendering engine + // needs to cross some sort of threshold covering all source-buffers content + // to start playing properly. + if ((bufferInfo.len > config.maxBufferHole || bufferInfo.nextStart && bufferInfo.nextStart - currentTime < config.maxBufferHole) && stalledDurationMs > config.highBufferWatchdogPeriod * 1000) { + logger.warn('Trying to nudge playhead over buffer-hole'); + // Try to nudge currentTime over a buffer hole if we've been stalling for the configured amount of seconds + // We only try to jump the hole if it's under the configured size + // Reset stalled so to rearm watchdog timer + this.stalled = null; + this._tryNudgeBuffer(); + } + } + + /** + * Triggers a BUFFER_STALLED_ERROR event, but only once per stall period. + * @param bufferLen - The playhead distance from the end of the current buffer segment. + * @private + */ + _reportStall(bufferInfo) { + const { + hls, + media, + stallReported + } = this; + if (!stallReported && media) { + // Report stalled error once + this.stallReported = true; + const error = new Error(`Playback stalling at @${media.currentTime} due to low buffer (${JSON.stringify(bufferInfo)})`); + logger.warn(error.message); + hls.trigger(Events.ERROR, { + type: ErrorTypes.MEDIA_ERROR, + details: ErrorDetails.BUFFER_STALLED_ERROR, + fatal: false, + error, + buffer: bufferInfo.len + }); + } + } + + /** + * Attempts to fix buffer stalls by jumping over known gaps caused by partial fragments + * @param partial - The partial fragment found at the current time (where playback is stalling). + * @private + */ + _trySkipBufferHole(partial) { + const { + config, + hls, + media + } = this; + if (media === null) { + return 0; + } + + // Check if currentTime is between unbuffered regions of partial fragments + const currentTime = media.currentTime; + const bufferInfo = BufferHelper.bufferInfo(media, currentTime, 0); + const startTime = currentTime < bufferInfo.start ? bufferInfo.start : bufferInfo.nextStart; + if (startTime) { + const bufferStarved = bufferInfo.len <= config.maxBufferHole; + const waiting = bufferInfo.len > 0 && bufferInfo.len < 1 && media.readyState < 3; + const gapLength = startTime - currentTime; + if (gapLength > 0 && (bufferStarved || waiting)) { + // Only allow large gaps to be skipped if it is a start gap, or all fragments in skip range are partial + if (gapLength > config.maxBufferHole) { + const { + fragmentTracker + } = this; + let startGap = false; + if (currentTime === 0) { + const startFrag = fragmentTracker.getAppendedFrag(0, PlaylistLevelType.MAIN); + if (startFrag && startTime < startFrag.end) { + startGap = true; + } + } + if (!startGap) { + const startProvisioned = partial || fragmentTracker.getAppendedFrag(currentTime, PlaylistLevelType.MAIN); + if (startProvisioned) { + let moreToLoad = false; + let pos = startProvisioned.end; + while (pos < startTime) { + const provisioned = fragmentTracker.getPartialFragment(pos); + if (provisioned) { + pos += provisioned.duration; + } else { + moreToLoad = true; + break; + } + } + if (moreToLoad) { + return 0; + } + } + } + } + const targetTime = Math.max(startTime + SKIP_BUFFER_RANGE_START, currentTime + SKIP_BUFFER_HOLE_STEP_SECONDS); + logger.warn(`skipping hole, adjusting currentTime from ${currentTime} to ${targetTime}`); + this.moved = true; + this.stalled = null; + media.currentTime = targetTime; + if (partial && !partial.gap) { + const error = new Error(`fragment loaded with buffer holes, seeking from ${currentTime} to ${targetTime}`); + hls.trigger(Events.ERROR, { + type: ErrorTypes.MEDIA_ERROR, + details: ErrorDetails.BUFFER_SEEK_OVER_HOLE, + fatal: false, + error, + reason: error.message, + frag: partial + }); + } + return targetTime; + } + } + return 0; + } + + /** + * Attempts to fix buffer stalls by advancing the mediaElement's current time by a small amount. + * @private + */ + _tryNudgeBuffer() { + const { + config, + hls, + media, + nudgeRetry + } = this; + if (media === null) { + return; + } + const currentTime = media.currentTime; + this.nudgeRetry++; + if (nudgeRetry < config.nudgeMaxRetry) { + const targetTime = currentTime + (nudgeRetry + 1) * config.nudgeOffset; + // playback stalled in buffered area ... let's nudge currentTime to try to overcome this + const error = new Error(`Nudging 'currentTime' from ${currentTime} to ${targetTime}`); + logger.warn(error.message); + media.currentTime = targetTime; + hls.trigger(Events.ERROR, { + type: ErrorTypes.MEDIA_ERROR, + details: ErrorDetails.BUFFER_NUDGE_ON_STALL, + error, + fatal: false + }); + } else { + const error = new Error(`Playhead still not moving while enough data buffered @${currentTime} after ${config.nudgeMaxRetry} nudges`); + logger.error(error.message); + hls.trigger(Events.ERROR, { + type: ErrorTypes.MEDIA_ERROR, + details: ErrorDetails.BUFFER_STALLED_ERROR, + error, + fatal: true + }); + } + } +} + +const TICK_INTERVAL = 100; // how often to tick in ms + +class StreamController extends BaseStreamController { + constructor(hls, fragmentTracker, keyLoader) { + super(hls, fragmentTracker, keyLoader, '[stream-controller]', PlaylistLevelType.MAIN); + this.audioCodecSwap = false; + this.gapController = null; + this.level = -1; + this._forceStartLoad = false; + this.altAudio = false; + this.audioOnly = false; + this.fragPlaying = null; + this.onvplaying = null; + this.onvseeked = null; + this.fragLastKbps = 0; + this.couldBacktrack = false; + this.backtrackFragment = null; + this.audioCodecSwitch = false; + this.videoBuffer = null; + this._registerListeners(); + } + _registerListeners() { + const { + hls + } = this; + hls.on(Events.MEDIA_ATTACHED, this.onMediaAttached, this); + hls.on(Events.MEDIA_DETACHING, this.onMediaDetaching, this); + hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this); + hls.on(Events.MANIFEST_PARSED, this.onManifestParsed, this); + hls.on(Events.LEVEL_LOADING, this.onLevelLoading, this); + hls.on(Events.LEVEL_LOADED, this.onLevelLoaded, this); + hls.on(Events.FRAG_LOAD_EMERGENCY_ABORTED, this.onFragLoadEmergencyAborted, this); + hls.on(Events.ERROR, this.onError, this); + hls.on(Events.AUDIO_TRACK_SWITCHING, this.onAudioTrackSwitching, this); + hls.on(Events.AUDIO_TRACK_SWITCHED, this.onAudioTrackSwitched, this); + hls.on(Events.BUFFER_CREATED, this.onBufferCreated, this); + hls.on(Events.BUFFER_FLUSHED, this.onBufferFlushed, this); + hls.on(Events.LEVELS_UPDATED, this.onLevelsUpdated, this); + hls.on(Events.FRAG_BUFFERED, this.onFragBuffered, this); + } + _unregisterListeners() { + const { + hls + } = this; + hls.off(Events.MEDIA_ATTACHED, this.onMediaAttached, this); + hls.off(Events.MEDIA_DETACHING, this.onMediaDetaching, this); + hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this); + hls.off(Events.MANIFEST_PARSED, this.onManifestParsed, this); + hls.off(Events.LEVEL_LOADED, this.onLevelLoaded, this); + hls.off(Events.FRAG_LOAD_EMERGENCY_ABORTED, this.onFragLoadEmergencyAborted, this); + hls.off(Events.ERROR, this.onError, this); + hls.off(Events.AUDIO_TRACK_SWITCHING, this.onAudioTrackSwitching, this); + hls.off(Events.AUDIO_TRACK_SWITCHED, this.onAudioTrackSwitched, this); + hls.off(Events.BUFFER_CREATED, this.onBufferCreated, this); + hls.off(Events.BUFFER_FLUSHED, this.onBufferFlushed, this); + hls.off(Events.LEVELS_UPDATED, this.onLevelsUpdated, this); + hls.off(Events.FRAG_BUFFERED, this.onFragBuffered, this); + } + onHandlerDestroying() { + this._unregisterListeners(); + super.onHandlerDestroying(); + } + startLoad(startPosition) { + if (this.levels) { + const { + lastCurrentTime, + hls + } = this; + this.stopLoad(); + this.setInterval(TICK_INTERVAL); + this.level = -1; + if (!this.startFragRequested) { + // determine load level + let startLevel = hls.startLevel; + if (startLevel === -1) { + if (hls.config.testBandwidth && this.levels.length > 1) { + // -1 : guess start Level by doing a bitrate test by loading first fragment of lowest quality level + startLevel = 0; + this.bitrateTest = true; + } else { + startLevel = hls.firstAutoLevel; + } + } + // set new level to playlist loader : this will trigger start level load + // hls.nextLoadLevel remains until it is set to a new value or until a new frag is successfully loaded + this.level = hls.nextLoadLevel = startLevel; + this.loadedmetadata = false; + } + // if startPosition undefined but lastCurrentTime set, set startPosition to last currentTime + if (lastCurrentTime > 0 && startPosition === -1) { + this.log(`Override startPosition with lastCurrentTime @${lastCurrentTime.toFixed(3)}`); + startPosition = lastCurrentTime; + } + this.state = State.IDLE; + this.nextLoadPosition = this.startPosition = this.lastCurrentTime = startPosition; + this.tick(); + } else { + this._forceStartLoad = true; + this.state = State.STOPPED; + } + } + stopLoad() { + this._forceStartLoad = false; + super.stopLoad(); + } + doTick() { + switch (this.state) { + case State.WAITING_LEVEL: + { + const { + levels, + level + } = this; + const currentLevel = levels == null ? void 0 : levels[level]; + const details = currentLevel == null ? void 0 : currentLevel.details; + if (details && (!details.live || this.levelLastLoaded === currentLevel)) { + if (this.waitForCdnTuneIn(details)) { + break; + } + this.state = State.IDLE; + break; + } else if (this.hls.nextLoadLevel !== this.level) { + this.state = State.IDLE; + break; + } + break; + } + case State.FRAG_LOADING_WAITING_RETRY: + { + var _this$media; + const now = self.performance.now(); + const retryDate = this.retryDate; + // if current time is gt than retryDate, or if media seeking let's switch to IDLE state to retry loading + if (!retryDate || now >= retryDate || (_this$media = this.media) != null && _this$media.seeking) { + const { + levels, + level + } = this; + const currentLevel = levels == null ? void 0 : levels[level]; + this.resetStartWhenNotLoaded(currentLevel || null); + this.state = State.IDLE; + } + } + break; + } + if (this.state === State.IDLE) { + this.doTickIdle(); + } + this.onTickEnd(); + } + onTickEnd() { + super.onTickEnd(); + this.checkBuffer(); + this.checkFragmentChanged(); + } + doTickIdle() { + const { + hls, + levelLastLoaded, + levels, + media + } = this; + const { + config, + nextLoadLevel: level + } = hls; + + // if start level not parsed yet OR + // if video not attached AND start fragment already requested OR start frag prefetch not enabled + // exit loop, as we either need more info (level not parsed) or we need media to be attached to load new fragment + if (levelLastLoaded === null || !media && (this.startFragRequested || !config.startFragPrefetch)) { + return; + } + + // If the "main" level is audio-only but we are loading an alternate track in the same group, do not load anything + if (this.altAudio && this.audioOnly) { + return; + } + if (!(levels != null && levels[level])) { + return; + } + const levelInfo = levels[level]; + + // if buffer length is less than maxBufLen try to load a new fragment + + const bufferInfo = this.getMainFwdBufferInfo(); + if (bufferInfo === null) { + return; + } + const lastDetails = this.getLevelDetails(); + if (lastDetails && this._streamEnded(bufferInfo, lastDetails)) { + const data = {}; + if (this.altAudio) { + data.type = 'video'; + } + this.hls.trigger(Events.BUFFER_EOS, data); + this.state = State.ENDED; + return; + } + + // set next load level : this will trigger a playlist load if needed + if (hls.loadLevel !== level && hls.manualLevel === -1) { + this.log(`Adapting to level ${level} from level ${this.level}`); + } + this.level = hls.nextLoadLevel = level; + const levelDetails = levelInfo.details; + // if level info not retrieved yet, switch state and wait for level retrieval + // if live playlist, ensure that new playlist has been refreshed to avoid loading/try to load + // a useless and outdated fragment (that might even introduce load error if it is already out of the live playlist) + if (!levelDetails || this.state === State.WAITING_LEVEL || levelDetails.live && this.levelLastLoaded !== levelInfo) { + this.level = level; + this.state = State.WAITING_LEVEL; + return; + } + const bufferLen = bufferInfo.len; + + // compute max Buffer Length that we could get from this load level, based on level bitrate. don't buffer more than 60 MB and more than 30s + const maxBufLen = this.getMaxBufferLength(levelInfo.maxBitrate); + + // Stay idle if we are still with buffer margins + if (bufferLen >= maxBufLen) { + return; + } + if (this.backtrackFragment && this.backtrackFragment.start > bufferInfo.end) { + this.backtrackFragment = null; + } + const targetBufferTime = this.backtrackFragment ? this.backtrackFragment.start : bufferInfo.end; + let frag = this.getNextFragment(targetBufferTime, levelDetails); + // Avoid backtracking by loading an earlier segment in streams with segments that do not start with a key frame (flagged by `couldBacktrack`) + if (this.couldBacktrack && !this.fragPrevious && frag && frag.sn !== 'initSegment' && this.fragmentTracker.getState(frag) !== FragmentState.OK) { + var _this$backtrackFragme; + const backtrackSn = ((_this$backtrackFragme = this.backtrackFragment) != null ? _this$backtrackFragme : frag).sn; + const fragIdx = backtrackSn - levelDetails.startSN; + const backtrackFrag = levelDetails.fragments[fragIdx - 1]; + if (backtrackFrag && frag.cc === backtrackFrag.cc) { + frag = backtrackFrag; + this.fragmentTracker.removeFragment(backtrackFrag); + } + } else if (this.backtrackFragment && bufferInfo.len) { + this.backtrackFragment = null; + } + // Avoid loop loading by using nextLoadPosition set for backtracking and skipping consecutive GAP tags + if (frag && this.isLoopLoading(frag, targetBufferTime)) { + const gapStart = frag.gap; + if (!gapStart) { + // Cleanup the fragment tracker before trying to find the next unbuffered fragment + const type = this.audioOnly && !this.altAudio ? ElementaryStreamTypes.AUDIO : ElementaryStreamTypes.VIDEO; + const mediaBuffer = (type === ElementaryStreamTypes.VIDEO ? this.videoBuffer : this.mediaBuffer) || this.media; + if (mediaBuffer) { + this.afterBufferFlushed(mediaBuffer, type, PlaylistLevelType.MAIN); + } + } + frag = this.getNextFragmentLoopLoading(frag, levelDetails, bufferInfo, PlaylistLevelType.MAIN, maxBufLen); + } + if (!frag) { + return; + } + if (frag.initSegment && !frag.initSegment.data && !this.bitrateTest) { + frag = frag.initSegment; + } + this.loadFragment(frag, levelInfo, targetBufferTime); + } + loadFragment(frag, level, targetBufferTime) { + // Check if fragment is not loaded + const fragState = this.fragmentTracker.getState(frag); + this.fragCurrent = frag; + if (fragState === FragmentState.NOT_LOADED || fragState === FragmentState.PARTIAL) { + if (frag.sn === 'initSegment') { + this._loadInitSegment(frag, level); + } else if (this.bitrateTest) { + this.log(`Fragment ${frag.sn} of level ${frag.level} is being downloaded to test bitrate and will not be buffered`); + this._loadBitrateTestFrag(frag, level); + } else { + this.startFragRequested = true; + super.loadFragment(frag, level, targetBufferTime); + } + } else { + this.clearTrackerIfNeeded(frag); + } + } + getBufferedFrag(position) { + return this.fragmentTracker.getBufferedFrag(position, PlaylistLevelType.MAIN); + } + followingBufferedFrag(frag) { + if (frag) { + // try to get range of next fragment (500ms after this range) + return this.getBufferedFrag(frag.end + 0.5); + } + return null; + } + + /* + on immediate level switch : + - pause playback if playing + - cancel any pending load request + - and trigger a buffer flush + */ + immediateLevelSwitch() { + this.abortCurrentFrag(); + this.flushMainBuffer(0, Number.POSITIVE_INFINITY); + } + + /** + * try to switch ASAP without breaking video playback: + * in order to ensure smooth but quick level switching, + * we need to find the next flushable buffer range + * we should take into account new segment fetch time + */ + nextLevelSwitch() { + const { + levels, + media + } = this; + // ensure that media is defined and that metadata are available (to retrieve currentTime) + if (media != null && media.readyState) { + let fetchdelay; + const fragPlayingCurrent = this.getAppendedFrag(media.currentTime); + if (fragPlayingCurrent && fragPlayingCurrent.start > 1) { + // flush buffer preceding current fragment (flush until current fragment start offset) + // minus 1s to avoid video freezing, that could happen if we flush keyframe of current video ... + this.flushMainBuffer(0, fragPlayingCurrent.start - 1); + } + const levelDetails = this.getLevelDetails(); + if (levelDetails != null && levelDetails.live) { + const bufferInfo = this.getMainFwdBufferInfo(); + // Do not flush in live stream with low buffer + if (!bufferInfo || bufferInfo.len < levelDetails.targetduration * 2) { + return; + } + } + if (!media.paused && levels) { + // add a safety delay of 1s + const nextLevelId = this.hls.nextLoadLevel; + const nextLevel = levels[nextLevelId]; + const fragLastKbps = this.fragLastKbps; + if (fragLastKbps && this.fragCurrent) { + fetchdelay = this.fragCurrent.duration * nextLevel.maxBitrate / (1000 * fragLastKbps) + 1; + } else { + fetchdelay = 0; + } + } else { + fetchdelay = 0; + } + // this.log('fetchdelay:'+fetchdelay); + // find buffer range that will be reached once new fragment will be fetched + const bufferedFrag = this.getBufferedFrag(media.currentTime + fetchdelay); + if (bufferedFrag) { + // we can flush buffer range following this one without stalling playback + const nextBufferedFrag = this.followingBufferedFrag(bufferedFrag); + if (nextBufferedFrag) { + // if we are here, we can also cancel any loading/demuxing in progress, as they are useless + this.abortCurrentFrag(); + // start flush position is in next buffered frag. Leave some padding for non-independent segments and smoother playback. + const maxStart = nextBufferedFrag.maxStartPTS ? nextBufferedFrag.maxStartPTS : nextBufferedFrag.start; + const fragDuration = nextBufferedFrag.duration; + const startPts = Math.max(bufferedFrag.end, maxStart + Math.min(Math.max(fragDuration - this.config.maxFragLookUpTolerance, fragDuration * (this.couldBacktrack ? 0.5 : 0.125)), fragDuration * (this.couldBacktrack ? 0.75 : 0.25))); + this.flushMainBuffer(startPts, Number.POSITIVE_INFINITY); + } + } + } + } + abortCurrentFrag() { + const fragCurrent = this.fragCurrent; + this.fragCurrent = null; + this.backtrackFragment = null; + if (fragCurrent) { + fragCurrent.abortRequests(); + this.fragmentTracker.removeFragment(fragCurrent); + } + switch (this.state) { + case State.KEY_LOADING: + case State.FRAG_LOADING: + case State.FRAG_LOADING_WAITING_RETRY: + case State.PARSING: + case State.PARSED: + this.state = State.IDLE; + break; + } + this.nextLoadPosition = this.getLoadPosition(); + } + flushMainBuffer(startOffset, endOffset) { + super.flushMainBuffer(startOffset, endOffset, this.altAudio ? 'video' : null); + } + onMediaAttached(event, data) { + super.onMediaAttached(event, data); + const media = data.media; + this.onvplaying = this.onMediaPlaying.bind(this); + this.onvseeked = this.onMediaSeeked.bind(this); + media.addEventListener('playing', this.onvplaying); + media.addEventListener('seeked', this.onvseeked); + this.gapController = new GapController(this.config, media, this.fragmentTracker, this.hls); + } + onMediaDetaching() { + const { + media + } = this; + if (media && this.onvplaying && this.onvseeked) { + media.removeEventListener('playing', this.onvplaying); + media.removeEventListener('seeked', this.onvseeked); + this.onvplaying = this.onvseeked = null; + this.videoBuffer = null; + } + this.fragPlaying = null; + if (this.gapController) { + this.gapController.destroy(); + this.gapController = null; + } + super.onMediaDetaching(); + } + onMediaPlaying() { + // tick to speed up FRAG_CHANGED triggering + this.tick(); + } + onMediaSeeked() { + const media = this.media; + const currentTime = media ? media.currentTime : null; + if (isFiniteNumber(currentTime)) { + this.log(`Media seeked to ${currentTime.toFixed(3)}`); + } + + // If seeked was issued before buffer was appended do not tick immediately + const bufferInfo = this.getMainFwdBufferInfo(); + if (bufferInfo === null || bufferInfo.len === 0) { + this.warn(`Main forward buffer length on "seeked" event ${bufferInfo ? bufferInfo.len : 'empty'})`); + return; + } + + // tick to speed up FRAG_CHANGED triggering + this.tick(); + } + onManifestLoading() { + // reset buffer on manifest loading + this.log('Trigger BUFFER_RESET'); + this.hls.trigger(Events.BUFFER_RESET, undefined); + this.fragmentTracker.removeAllFragments(); + this.couldBacktrack = false; + this.startPosition = this.lastCurrentTime = this.fragLastKbps = 0; + this.levels = this.fragPlaying = this.backtrackFragment = this.levelLastLoaded = null; + this.altAudio = this.audioOnly = this.startFragRequested = false; + } + onManifestParsed(event, data) { + // detect if we have different kind of audio codecs used amongst playlists + let aac = false; + let heaac = false; + data.levels.forEach(level => { + const codec = level.audioCodec; + if (codec) { + aac = aac || codec.indexOf('mp4a.40.2') !== -1; + heaac = heaac || codec.indexOf('mp4a.40.5') !== -1; + } + }); + this.audioCodecSwitch = aac && heaac && !changeTypeSupported(); + if (this.audioCodecSwitch) { + this.log('Both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC'); + } + this.levels = data.levels; + this.startFragRequested = false; + } + onLevelLoading(event, data) { + const { + levels + } = this; + if (!levels || this.state !== State.IDLE) { + return; + } + const level = levels[data.level]; + if (!level.details || level.details.live && this.levelLastLoaded !== level || this.waitForCdnTuneIn(level.details)) { + this.state = State.WAITING_LEVEL; + } + } + onLevelLoaded(event, data) { + var _curLevel$details; + const { + levels + } = this; + const newLevelId = data.level; + const newDetails = data.details; + const duration = newDetails.totalduration; + if (!levels) { + this.warn(`Levels were reset while loading level ${newLevelId}`); + return; + } + this.log(`Level ${newLevelId} loaded [${newDetails.startSN},${newDetails.endSN}]${newDetails.lastPartSn ? `[part-${newDetails.lastPartSn}-${newDetails.lastPartIndex}]` : ''}, cc [${newDetails.startCC}, ${newDetails.endCC}] duration:${duration}`); + const curLevel = levels[newLevelId]; + const fragCurrent = this.fragCurrent; + if (fragCurrent && (this.state === State.FRAG_LOADING || this.state === State.FRAG_LOADING_WAITING_RETRY)) { + if (fragCurrent.level !== data.level && fragCurrent.loader) { + this.abortCurrentFrag(); + } + } + let sliding = 0; + if (newDetails.live || (_curLevel$details = curLevel.details) != null && _curLevel$details.live) { + var _this$levelLastLoaded; + this.checkLiveUpdate(newDetails); + if (newDetails.deltaUpdateFailed) { + return; + } + sliding = this.alignPlaylists(newDetails, curLevel.details, (_this$levelLastLoaded = this.levelLastLoaded) == null ? void 0 : _this$levelLastLoaded.details); + } + // override level info + curLevel.details = newDetails; + this.levelLastLoaded = curLevel; + this.hls.trigger(Events.LEVEL_UPDATED, { + details: newDetails, + level: newLevelId + }); + + // only switch back to IDLE state if we were waiting for level to start downloading a new fragment + if (this.state === State.WAITING_LEVEL) { + if (this.waitForCdnTuneIn(newDetails)) { + // Wait for Low-Latency CDN Tune-in + return; + } + this.state = State.IDLE; + } + if (!this.startFragRequested) { + this.setStartPosition(newDetails, sliding); + } else if (newDetails.live) { + this.synchronizeToLiveEdge(newDetails); + } + + // trigger handler right now + this.tick(); + } + _handleFragmentLoadProgress(data) { + var _frag$initSegment; + const { + frag, + part, + payload + } = data; + const { + levels + } = this; + if (!levels) { + this.warn(`Levels were reset while fragment load was in progress. Fragment ${frag.sn} of level ${frag.level} will not be buffered`); + return; + } + const currentLevel = levels[frag.level]; + const details = currentLevel.details; + if (!details) { + this.warn(`Dropping fragment ${frag.sn} of level ${frag.level} after level details were reset`); + this.fragmentTracker.removeFragment(frag); + return; + } + const videoCodec = currentLevel.videoCodec; + + // time Offset is accurate if level PTS is known, or if playlist is not sliding (not live) + const accurateTimeOffset = details.PTSKnown || !details.live; + const initSegmentData = (_frag$initSegment = frag.initSegment) == null ? void 0 : _frag$initSegment.data; + const audioCodec = this._getAudioCodec(currentLevel); + + // transmux the MPEG-TS data to ISO-BMFF segments + // this.log(`Transmuxing ${frag.sn} of [${details.startSN} ,${details.endSN}],level ${frag.level}, cc ${frag.cc}`); + const transmuxer = this.transmuxer = this.transmuxer || new TransmuxerInterface(this.hls, PlaylistLevelType.MAIN, this._handleTransmuxComplete.bind(this), this._handleTransmuxerFlush.bind(this)); + const partIndex = part ? part.index : -1; + const partial = partIndex !== -1; + const chunkMeta = new ChunkMetadata(frag.level, frag.sn, frag.stats.chunkCount, payload.byteLength, partIndex, partial); + const initPTS = this.initPTS[frag.cc]; + transmuxer.push(payload, initSegmentData, audioCodec, videoCodec, frag, part, details.totalduration, accurateTimeOffset, chunkMeta, initPTS); + } + onAudioTrackSwitching(event, data) { + // if any URL found on new audio track, it is an alternate audio track + const fromAltAudio = this.altAudio; + const altAudio = !!data.url; + // if we switch on main audio, ensure that main fragment scheduling is synced with media.buffered + // don't do anything if we switch to alt audio: audio stream controller is handling it. + // we will just have to change buffer scheduling on audioTrackSwitched + if (!altAudio) { + if (this.mediaBuffer !== this.media) { + this.log('Switching on main audio, use media.buffered to schedule main fragment loading'); + this.mediaBuffer = this.media; + const fragCurrent = this.fragCurrent; + // we need to refill audio buffer from main: cancel any frag loading to speed up audio switch + if (fragCurrent) { + this.log('Switching to main audio track, cancel main fragment load'); + fragCurrent.abortRequests(); + this.fragmentTracker.removeFragment(fragCurrent); + } + // destroy transmuxer to force init segment generation (following audio switch) + this.resetTransmuxer(); + // switch to IDLE state to load new fragment + this.resetLoadingState(); + } else if (this.audioOnly) { + // Reset audio transmuxer so when switching back to main audio we're not still appending where we left off + this.resetTransmuxer(); + } + const hls = this.hls; + // If switching from alt to main audio, flush all audio and trigger track switched + if (fromAltAudio) { + hls.trigger(Events.BUFFER_FLUSHING, { + startOffset: 0, + endOffset: Number.POSITIVE_INFINITY, + type: null + }); + this.fragmentTracker.removeAllFragments(); + } + hls.trigger(Events.AUDIO_TRACK_SWITCHED, data); + } + } + onAudioTrackSwitched(event, data) { + const trackId = data.id; + const altAudio = !!this.hls.audioTracks[trackId].url; + if (altAudio) { + const videoBuffer = this.videoBuffer; + // if we switched on alternate audio, ensure that main fragment scheduling is synced with video sourcebuffer buffered + if (videoBuffer && this.mediaBuffer !== videoBuffer) { + this.log('Switching on alternate audio, use video.buffered to schedule main fragment loading'); + this.mediaBuffer = videoBuffer; + } + } + this.altAudio = altAudio; + this.tick(); + } + onBufferCreated(event, data) { + const tracks = data.tracks; + let mediaTrack; + let name; + let alternate = false; + for (const type in tracks) { + const track = tracks[type]; + if (track.id === 'main') { + name = type; + mediaTrack = track; + // keep video source buffer reference + if (type === 'video') { + const videoTrack = tracks[type]; + if (videoTrack) { + this.videoBuffer = videoTrack.buffer; + } + } + } else { + alternate = true; + } + } + if (alternate && mediaTrack) { + this.log(`Alternate track found, use ${name}.buffered to schedule main fragment loading`); + this.mediaBuffer = mediaTrack.buffer; + } else { + this.mediaBuffer = this.media; + } + } + onFragBuffered(event, data) { + const { + frag, + part + } = data; + if (frag && frag.type !== PlaylistLevelType.MAIN) { + return; + } + if (this.fragContextChanged(frag)) { + // If a level switch was requested while a fragment was buffering, it will emit the FRAG_BUFFERED event upon completion + // Avoid setting state back to IDLE, since that will interfere with a level switch + this.warn(`Fragment ${frag.sn}${part ? ' p: ' + part.index : ''} of level ${frag.level} finished buffering, but was aborted. state: ${this.state}`); + if (this.state === State.PARSED) { + this.state = State.IDLE; + } + return; + } + const stats = part ? part.stats : frag.stats; + this.fragLastKbps = Math.round(8 * stats.total / (stats.buffering.end - stats.loading.first)); + if (frag.sn !== 'initSegment') { + this.fragPrevious = frag; + } + this.fragBufferedComplete(frag, part); + } + onError(event, data) { + var _data$context; + if (data.fatal) { + this.state = State.ERROR; + return; + } + switch (data.details) { + case ErrorDetails.FRAG_GAP: + case ErrorDetails.FRAG_PARSING_ERROR: + case ErrorDetails.FRAG_DECRYPT_ERROR: + case ErrorDetails.FRAG_LOAD_ERROR: + case ErrorDetails.FRAG_LOAD_TIMEOUT: + case ErrorDetails.KEY_LOAD_ERROR: + case ErrorDetails.KEY_LOAD_TIMEOUT: + this.onFragmentOrKeyLoadError(PlaylistLevelType.MAIN, data); + break; + case ErrorDetails.LEVEL_LOAD_ERROR: + case ErrorDetails.LEVEL_LOAD_TIMEOUT: + case ErrorDetails.LEVEL_PARSING_ERROR: + // in case of non fatal error while loading level, if level controller is not retrying to load level, switch back to IDLE + if (!data.levelRetry && this.state === State.WAITING_LEVEL && ((_data$context = data.context) == null ? void 0 : _data$context.type) === PlaylistContextType.LEVEL) { + this.state = State.IDLE; + } + break; + case ErrorDetails.BUFFER_APPEND_ERROR: + case ErrorDetails.BUFFER_FULL_ERROR: + if (!data.parent || data.parent !== 'main') { + return; + } + if (data.details === ErrorDetails.BUFFER_APPEND_ERROR) { + this.resetLoadingState(); + return; + } + if (this.reduceLengthAndFlushBuffer(data)) { + this.flushMainBuffer(0, Number.POSITIVE_INFINITY); + } + break; + case ErrorDetails.INTERNAL_EXCEPTION: + this.recoverWorkerError(data); + break; + } + } + + // Checks the health of the buffer and attempts to resolve playback stalls. + checkBuffer() { + const { + media, + gapController + } = this; + if (!media || !gapController || !media.readyState) { + // Exit early if we don't have media or if the media hasn't buffered anything yet (readyState 0) + return; + } + if (this.loadedmetadata || !BufferHelper.getBuffered(media).length) { + // Resolve gaps using the main buffer, whose ranges are the intersections of the A/V sourcebuffers + const activeFrag = this.state !== State.IDLE ? this.fragCurrent : null; + gapController.poll(this.lastCurrentTime, activeFrag); + } + this.lastCurrentTime = media.currentTime; + } + onFragLoadEmergencyAborted() { + this.state = State.IDLE; + // if loadedmetadata is not set, it means that we are emergency switch down on first frag + // in that case, reset startFragRequested flag + if (!this.loadedmetadata) { + this.startFragRequested = false; + this.nextLoadPosition = this.startPosition; + } + this.tickImmediate(); + } + onBufferFlushed(event, { + type + }) { + if (type !== ElementaryStreamTypes.AUDIO || this.audioOnly && !this.altAudio) { + const mediaBuffer = (type === ElementaryStreamTypes.VIDEO ? this.videoBuffer : this.mediaBuffer) || this.media; + this.afterBufferFlushed(mediaBuffer, type, PlaylistLevelType.MAIN); + this.tick(); + } + } + onLevelsUpdated(event, data) { + if (this.level > -1 && this.fragCurrent) { + this.level = this.fragCurrent.level; } + this.levels = data.levels; } - load(context, config, callbacks) { - const stats = this.stats; - if (stats.loading.start) { - throw new Error('Loader can only be used once.'); - } - stats.loading.start = self.performance.now(); - const initParams = getRequestParameters(context, this.controller.signal); - const onProgress = callbacks.onProgress; - const isArrayBuffer = context.responseType === 'arraybuffer'; - const LENGTH = isArrayBuffer ? 'byteLength' : 'length'; + swapAudioCodec() { + this.audioCodecSwap = !this.audioCodecSwap; + } + + /** + * Seeks to the set startPosition if not equal to the mediaElement's current time. + */ + seekToStartPos() { const { - maxTimeToFirstByteMs, - maxLoadTimeMs - } = config.loadPolicy; - this.context = context; - this.config = config; - this.callbacks = callbacks; - this.request = this.fetchSetup(context, initParams); - self.clearTimeout(this.requestTimeout); - config.timeout = maxTimeToFirstByteMs && isFiniteNumber(maxTimeToFirstByteMs) ? maxTimeToFirstByteMs : maxLoadTimeMs; - this.requestTimeout = self.setTimeout(() => { - this.abortInternal(); - callbacks.onTimeout(stats, context, this.response); - }, config.timeout); - self.fetch(this.request).then(response => { - this.response = this.loader = response; - const first = Math.max(self.performance.now(), stats.loading.start); - self.clearTimeout(this.requestTimeout); - config.timeout = maxLoadTimeMs; - this.requestTimeout = self.setTimeout(() => { - this.abortInternal(); - callbacks.onTimeout(stats, context, this.response); - }, maxLoadTimeMs - (first - stats.loading.start)); - if (!response.ok) { - const { - status, - statusText - } = response; - throw new FetchError(statusText || 'fetch, bad network response', status, response); - } - stats.loading.first = first; - stats.total = getContentLength(response.headers) || stats.total; - if (onProgress && isFiniteNumber(config.highWaterMark)) { - return this.loadProgressively(response, stats, context, config.highWaterMark, onProgress); + media + } = this; + if (!media) { + return; + } + const currentTime = media.currentTime; + let startPosition = this.startPosition; + // only adjust currentTime if different from startPosition or if startPosition not buffered + // at that stage, there should be only one buffered range, as we reach that code after first fragment has been buffered + if (startPosition >= 0 && currentTime < startPosition) { + if (media.seeking) { + this.log(`could not seek to ${startPosition}, already seeking at ${currentTime}`); + return; } - if (isArrayBuffer) { - return response.arrayBuffer(); + const buffered = BufferHelper.getBuffered(media); + const bufferStart = buffered.length ? buffered.start(0) : 0; + const delta = bufferStart - startPosition; + if (delta > 0 && (delta < this.config.maxBufferHole || delta < this.config.maxFragLookUpTolerance)) { + this.log(`adjusting start position by ${delta} to match buffer start`); + startPosition += delta; + this.startPosition = startPosition; } - if (context.responseType === 'json') { - return response.json(); + this.log(`seek to target start position ${startPosition} from current time ${currentTime}`); + media.currentTime = startPosition; + } + } + _getAudioCodec(currentLevel) { + let audioCodec = this.config.defaultAudioCodec || currentLevel.audioCodec; + if (this.audioCodecSwap && audioCodec) { + this.log('Swapping audio codec'); + if (audioCodec.indexOf('mp4a.40.5') !== -1) { + audioCodec = 'mp4a.40.2'; + } else { + audioCodec = 'mp4a.40.5'; } - return response.text(); - }).then(responseData => { + } + return audioCodec; + } + _loadBitrateTestFrag(frag, level) { + frag.bitrateTest = true; + this._doFragLoad(frag, level).then(data => { const { - response + hls } = this; - self.clearTimeout(this.requestTimeout); - stats.loading.end = Math.max(self.performance.now(), stats.loading.first); - const total = responseData[LENGTH]; - if (total) { - stats.loaded = stats.total = total; - } - const loaderResponse = { - url: response.url, - data: responseData, - code: response.status - }; - if (onProgress && !isFiniteNumber(config.highWaterMark)) { - onProgress(stats, context, responseData, response); - } - callbacks.onSuccess(loaderResponse, stats, context, response); - }).catch(error => { - self.clearTimeout(this.requestTimeout); - if (stats.aborted) { + if (!data || this.fragContextChanged(frag)) { return; } - // CORS errors result in an undefined code. Set it to 0 here to align with XHR's behavior - // when destroying, 'error' itself can be undefined - const code = !error ? 0 : error.code || 0; - const text = !error ? null : error.message; - callbacks.onError({ - code, - text - }, context, error ? error.details : null, stats); + level.fragmentError = 0; + this.state = State.IDLE; + this.startFragRequested = false; + this.bitrateTest = false; + const stats = frag.stats; + // Bitrate tests fragments are neither parsed nor buffered + stats.parsing.start = stats.parsing.end = stats.buffering.start = stats.buffering.end = self.performance.now(); + hls.trigger(Events.FRAG_LOADED, data); + frag.bitrateTest = false; }); } - getCacheAge() { - let result = null; - if (this.response) { - const ageHeader = this.response.headers.get('age'); - result = ageHeader ? parseFloat(ageHeader) : null; + _handleTransmuxComplete(transmuxResult) { + var _id3$samples; + const id = 'main'; + const { + hls + } = this; + const { + remuxResult, + chunkMeta + } = transmuxResult; + const context = this.getCurrentContext(chunkMeta); + if (!context) { + this.resetWhenMissingContext(chunkMeta); + return; } - return result; - } - getResponseHeader(name) { - return this.response ? this.response.headers.get(name) : null; - } - loadProgressively(response, stats, context, highWaterMark = 0, onProgress) { - const chunkCache = new ChunkCache(); - const reader = response.body.getReader(); - const pump = () => { - return reader.read().then(data => { - if (data.done) { - if (chunkCache.dataLength) { - onProgress(stats, context, chunkCache.flush(), response); - } - return Promise.resolve(new ArrayBuffer(0)); - } - const chunk = data.value; - const len = chunk.length; - stats.loaded += len; - if (len < highWaterMark || chunkCache.dataLength) { - // The current chunk is too small to to be emitted or the cache already has data - // Push it to the cache - chunkCache.push(chunk); - if (chunkCache.dataLength >= highWaterMark) { - // flush in order to join the typed arrays - onProgress(stats, context, chunkCache.flush(), response); - } - } else { - // If there's nothing cached already, and the chache is large enough - // just emit the progress event - onProgress(stats, context, chunk, response); - } - return pump(); - }).catch(() => { - /* aborted */ - return Promise.reject(); - }); - }; - return pump(); - } -} -function getRequestParameters(context, signal) { - const initParams = { - method: 'GET', - mode: 'cors', - credentials: 'same-origin', - signal, - headers: new self.Headers(_extends({}, context.headers)) - }; - if (context.rangeEnd) { - initParams.headers.set('Range', 'bytes=' + context.rangeStart + '-' + String(context.rangeEnd - 1)); - } - return initParams; -} -function getByteRangeLength(byteRangeHeader) { - const result = BYTERANGE.exec(byteRangeHeader); - if (result) { - return parseInt(result[2]) - parseInt(result[1]) + 1; - } -} -function getContentLength(headers) { - const contentRange = headers.get('Content-Range'); - if (contentRange) { - const byteRangeLength = getByteRangeLength(contentRange); - if (isFiniteNumber(byteRangeLength)) { - return byteRangeLength; + const { + frag, + part, + level + } = context; + const { + video, + text, + id3, + initSegment + } = remuxResult; + const { + details + } = level; + // The audio-stream-controller handles audio buffering if Hls.js is playing an alternate audio track + const audio = this.altAudio ? undefined : remuxResult.audio; + + // Check if the current fragment has been aborted. We check this by first seeing if we're still playing the current level. + // If we are, subsequently check if the currently loading fragment (fragCurrent) has changed. + if (this.fragContextChanged(frag)) { + this.fragmentTracker.removeFragment(frag); + return; } - } - const contentLength = headers.get('Content-Length'); - if (contentLength) { - return parseInt(contentLength); - } -} -function getRequest(context, initParams) { - return new self.Request(context.url, initParams); -} -class FetchError extends Error { - constructor(message, code, details) { - super(message); - this.code = void 0; - this.details = void 0; - this.code = code; - this.details = details; - } -} + this.state = State.PARSING; + if (initSegment) { + if (initSegment != null && initSegment.tracks) { + const mapFragment = frag.initSegment || frag; + this._bufferInitSegment(level, initSegment.tracks, mapFragment, chunkMeta); + hls.trigger(Events.FRAG_PARSING_INIT_SEGMENT, { + frag: mapFragment, + id, + tracks: initSegment.tracks + }); + } -const WHITESPACE_CHAR = /\s/; -const Cues = { - newCue(track, startTime, endTime, captionScreen) { - const result = []; - let row; - // the type data states this is VTTCue, but it can potentially be a TextTrackCue on old browsers - let cue; - let indenting; - let indent; - let text; - const Cue = self.VTTCue || self.TextTrackCue; - for (let r = 0; r < captionScreen.rows.length; r++) { - row = captionScreen.rows[r]; - indenting = true; - indent = 0; - text = ''; - if (!row.isEmpty()) { - var _track$cues; - for (let c = 0; c < row.chars.length; c++) { - if (WHITESPACE_CHAR.test(row.chars[c].uchar) && indenting) { - indent++; - } else { - text += row.chars[c].uchar; - indenting = false; - } - } - // To be used for cleaning-up orphaned roll-up captions - row.cueStartTime = startTime; + // This would be nice if Number.isFinite acted as a typeguard, but it doesn't. See: https://github.com/Microsoft/TypeScript/issues/10038 + const initPTS = initSegment.initPTS; + const timescale = initSegment.timescale; + if (isFiniteNumber(initPTS)) { + this.initPTS[frag.cc] = { + baseTime: initPTS, + timescale + }; + hls.trigger(Events.INIT_PTS_FOUND, { + frag, + id, + initPTS, + timescale + }); + } + } - // Give a slight bump to the endTime if it's equal to startTime to avoid a SyntaxError in IE - if (startTime === endTime) { - endTime += 0.0001; - } - if (indent >= 16) { - indent--; + // Avoid buffering if backtracking this fragment + if (video && details && frag.sn !== 'initSegment') { + const prevFrag = details.fragments[frag.sn - 1 - details.startSN]; + const isFirstFragment = frag.sn === details.startSN; + const isFirstInDiscontinuity = !prevFrag || frag.cc > prevFrag.cc; + if (remuxResult.independent !== false) { + const { + startPTS, + endPTS, + startDTS, + endDTS + } = video; + if (part) { + part.elementaryStreams[video.type] = { + startPTS, + endPTS, + startDTS, + endDTS + }; } else { - indent++; - } - const cueText = fixLineBreaks(text.trim()); - const id = generateCueId(startTime, endTime, cueText); + if (video.firstKeyFrame && video.independent && chunkMeta.id === 1 && !isFirstInDiscontinuity) { + this.couldBacktrack = true; + } + if (video.dropped && video.independent) { + // Backtrack if dropped frames create a gap after currentTime - // If this cue already exists in the track do not push it - if (!(track != null && (_track$cues = track.cues) != null && _track$cues.getCueById(id))) { - cue = new Cue(startTime, endTime, cueText); - cue.id = id; - cue.line = r + 1; - cue.align = 'left'; - // Clamp the position between 10 and 80 percent (CEA-608 PAC indent code) - // https://dvcs.w3.org/hg/text-tracks/raw-file/default/608toVTT/608toVTT.html#positioning-in-cea-608 - // Firefox throws an exception and captions break with out of bounds 0-100 values - cue.position = 10 + Math.min(80, Math.floor(indent * 8 / 32) * 10); - result.push(cue); + const bufferInfo = this.getMainFwdBufferInfo(); + const targetBufferTime = (bufferInfo ? bufferInfo.end : this.getLoadPosition()) + this.config.maxBufferHole; + const startTime = video.firstKeyFramePTS ? video.firstKeyFramePTS : startPTS; + if (!isFirstFragment && targetBufferTime < startTime - this.config.maxBufferHole && !isFirstInDiscontinuity) { + this.backtrack(frag); + return; + } else if (isFirstInDiscontinuity) { + // Mark segment with a gap to avoid loop loading + frag.gap = true; + } + // Set video stream start to fragment start so that truncated samples do not distort the timeline, and mark it partial + frag.setElementaryStreamInfo(video.type, frag.start, endPTS, frag.start, endDTS, true); + } else if (isFirstFragment && startPTS > MAX_START_GAP_JUMP) { + // Mark segment with a gap to skip large start gap + frag.gap = true; + } + } + frag.setElementaryStreamInfo(video.type, startPTS, endPTS, startDTS, endDTS); + if (this.backtrackFragment) { + this.backtrackFragment = frag; } + this.bufferFragmentData(video, frag, part, chunkMeta, isFirstFragment || isFirstInDiscontinuity); + } else if (isFirstFragment || isFirstInDiscontinuity) { + // Mark segment with a gap to avoid loop loading + frag.gap = true; + } else { + this.backtrack(frag); + return; } } - if (track && result.length) { - // Sort bottom cues in reverse order so that they render in line order when overlapping in Chrome - result.sort((cueA, cueB) => { - if (cueA.line === 'auto' || cueB.line === 'auto') { - return 0; - } - if (cueA.line > 8 && cueB.line > 8) { - return cueB.line - cueA.line; - } - return cueA.line - cueB.line; - }); - result.forEach(cue => addCueToTrack(track, cue)); + if (audio) { + const { + startPTS, + endPTS, + startDTS, + endDTS + } = audio; + if (part) { + part.elementaryStreams[ElementaryStreamTypes.AUDIO] = { + startPTS, + endPTS, + startDTS, + endDTS + }; + } + frag.setElementaryStreamInfo(ElementaryStreamTypes.AUDIO, startPTS, endPTS, startDTS, endDTS); + this.bufferFragmentData(audio, frag, part, chunkMeta); + } + if (details && id3 != null && (_id3$samples = id3.samples) != null && _id3$samples.length) { + const emittedID3 = { + id, + frag, + details, + samples: id3.samples + }; + hls.trigger(Events.FRAG_PARSING_METADATA, emittedID3); + } + if (details && text) { + const emittedText = { + id, + frag, + details, + samples: text.samples + }; + hls.trigger(Events.FRAG_PARSING_USERDATA, emittedText); } - return result; } -}; - -/** - * @deprecated use fragLoadPolicy.default - */ - -/** - * @deprecated use manifestLoadPolicy.default and playlistLoadPolicy.default - */ - -const defaultLoadPolicy = { - maxTimeToFirstByteMs: 8000, - maxLoadTimeMs: 20000, - timeoutRetry: null, - errorRetry: null -}; + _bufferInitSegment(currentLevel, tracks, frag, chunkMeta) { + if (this.state !== State.PARSING) { + return; + } + this.audioOnly = !!tracks.audio && !tracks.video; -/** - * @ignore - * If possible, keep hlsDefaultConfig shallow - * It is cloned whenever a new Hls instance is created, by keeping the config - * shallow the properties are cloned, and we don't end up manipulating the default - */ -const hlsDefaultConfig = _objectSpread2(_objectSpread2({ - autoStartLoad: true, - // used by stream-controller - startPosition: -1, - // used by stream-controller - defaultAudioCodec: undefined, - // used by stream-controller - debug: false, - // used by logger - capLevelOnFPSDrop: false, - // used by fps-controller - capLevelToPlayerSize: false, - // used by cap-level-controller - ignoreDevicePixelRatio: false, - // used by cap-level-controller - initialLiveManifestSize: 1, - // used by stream-controller - maxBufferLength: 30, - // used by stream-controller - backBufferLength: Infinity, - // used by buffer-controller - maxBufferSize: 60 * 1000 * 1000, - // used by stream-controller - maxBufferHole: 0.1, - // used by stream-controller - highBufferWatchdogPeriod: 2, - // used by stream-controller - nudgeOffset: 0.1, - // used by stream-controller - nudgeMaxRetry: 3, - // used by stream-controller - maxFragLookUpTolerance: 0.25, - // used by stream-controller - liveSyncDurationCount: 3, - // used by latency-controller - liveMaxLatencyDurationCount: Infinity, - // used by latency-controller - liveSyncDuration: undefined, - // used by latency-controller - liveMaxLatencyDuration: undefined, - // used by latency-controller - maxLiveSyncPlaybackRate: 1, - // used by latency-controller - liveDurationInfinity: false, - // used by buffer-controller - /** - * @deprecated use backBufferLength - */ - liveBackBufferLength: null, - // used by buffer-controller - maxMaxBufferLength: 600, - // used by stream-controller - enableWorker: true, - // used by transmuxer - workerPath: null, - // used by transmuxer - enableSoftwareAES: true, - // used by decrypter - startLevel: undefined, - // used by level-controller - startFragPrefetch: false, - // used by stream-controller - fpsDroppedMonitoringPeriod: 5000, - // used by fps-controller - fpsDroppedMonitoringThreshold: 0.2, - // used by fps-controller - appendErrorMaxRetry: 3, - // used by buffer-controller - loader: XhrLoader, - // loader: FetchLoader, - fLoader: undefined, - // used by fragment-loader - pLoader: undefined, - // used by playlist-loader - xhrSetup: undefined, - // used by xhr-loader - licenseXhrSetup: undefined, - // used by eme-controller - licenseResponseCallback: undefined, - // used by eme-controller - abrController: AbrController, - bufferController: BufferController, - capLevelController: CapLevelController, - errorController: ErrorController, - fpsController: FPSController, - stretchShortVideoTrack: false, - // used by mp4-remuxer - maxAudioFramesDrift: 1, - // used by mp4-remuxer - forceKeyFrameOnDiscontinuity: true, - // used by ts-demuxer - abrEwmaFastLive: 3, - // used by abr-controller - abrEwmaSlowLive: 9, - // used by abr-controller - abrEwmaFastVoD: 3, - // used by abr-controller - abrEwmaSlowVoD: 9, - // used by abr-controller - abrEwmaDefaultEstimate: 5e5, - // 500 kbps // used by abr-controller - abrBandWidthFactor: 0.95, - // used by abr-controller - abrBandWidthUpFactor: 0.7, - // used by abr-controller - abrMaxWithRealBitrate: false, - // used by abr-controller - maxStarvationDelay: 4, - // used by abr-controller - maxLoadingDelay: 4, - // used by abr-controller - minAutoBitrate: 0, - // used by hls - emeEnabled: false, - // used by eme-controller - widevineLicenseUrl: undefined, - // used by eme-controller - drmSystems: {}, - // used by eme-controller - drmSystemOptions: {}, - // used by eme-controller - requestMediaKeySystemAccessFunc: requestMediaKeySystemAccess , - // used by eme-controller - testBandwidth: true, - progressive: false, - lowLatencyMode: true, - cmcd: undefined, - enableDateRangeMetadataCues: true, - enableEmsgMetadataCues: true, - enableID3MetadataCues: true, - certLoadPolicy: { - default: defaultLoadPolicy - }, - keyLoadPolicy: { - default: { - maxTimeToFirstByteMs: 8000, - maxLoadTimeMs: 20000, - timeoutRetry: { - maxNumRetry: 1, - retryDelayMs: 1000, - maxRetryDelayMs: 20000, - backoff: 'linear' - }, - errorRetry: { - maxNumRetry: 8, - retryDelayMs: 1000, - maxRetryDelayMs: 20000, - backoff: 'linear' - } + // if audio track is expected to come from audio stream controller, discard any coming from main + if (this.altAudio && !this.audioOnly) { + delete tracks.audio; } - }, - manifestLoadPolicy: { - default: { - maxTimeToFirstByteMs: Infinity, - maxLoadTimeMs: 20000, - timeoutRetry: { - maxNumRetry: 2, - retryDelayMs: 0, - maxRetryDelayMs: 0 - }, - errorRetry: { - maxNumRetry: 1, - retryDelayMs: 1000, - maxRetryDelayMs: 8000 + // include levelCodec in audio and video tracks + const { + audio, + video, + audiovideo + } = tracks; + if (audio) { + let audioCodec = currentLevel.audioCodec; + const ua = navigator.userAgent.toLowerCase(); + if (this.audioCodecSwitch) { + if (audioCodec) { + if (audioCodec.indexOf('mp4a.40.5') !== -1) { + audioCodec = 'mp4a.40.2'; + } else { + audioCodec = 'mp4a.40.5'; + } + } + // In the case that AAC and HE-AAC audio codecs are signalled in manifest, + // force HE-AAC, as it seems that most browsers prefers it. + // don't force HE-AAC if mono stream, or in Firefox + if (audio.metadata.channelCount !== 1 && ua.indexOf('firefox') === -1) { + audioCodec = 'mp4a.40.5'; + } } - } - }, - playlistLoadPolicy: { - default: { - maxTimeToFirstByteMs: 10000, - maxLoadTimeMs: 20000, - timeoutRetry: { - maxNumRetry: 2, - retryDelayMs: 0, - maxRetryDelayMs: 0 - }, - errorRetry: { - maxNumRetry: 2, - retryDelayMs: 1000, - maxRetryDelayMs: 8000 + // HE-AAC is broken on Android, always signal audio codec as AAC even if variant manifest states otherwise + if (audioCodec && audioCodec.indexOf('mp4a.40.5') !== -1 && ua.indexOf('android') !== -1 && audio.container !== 'audio/mpeg') { + // Exclude mpeg audio + audioCodec = 'mp4a.40.2'; + this.log(`Android: force audio codec to ${audioCodec}`); } - } - }, - fragLoadPolicy: { - default: { - maxTimeToFirstByteMs: 10000, - maxLoadTimeMs: 120000, - timeoutRetry: { - maxNumRetry: 4, - retryDelayMs: 0, - maxRetryDelayMs: 0 - }, - errorRetry: { - maxNumRetry: 6, - retryDelayMs: 1000, - maxRetryDelayMs: 8000 + if (currentLevel.audioCodec && currentLevel.audioCodec !== audioCodec) { + this.log(`Swapping manifest audio codec "${currentLevel.audioCodec}" for "${audioCodec}"`); } + audio.levelCodec = audioCodec; + audio.id = 'main'; + this.log(`Init audio buffer, container:${audio.container}, codecs[selected/level/parsed]=[${audioCodec || ''}/${currentLevel.audioCodec || ''}/${audio.codec}]`); } - }, - steeringManifestLoadPolicy: { - default: { - maxTimeToFirstByteMs: 10000, - maxLoadTimeMs: 20000, - timeoutRetry: { - maxNumRetry: 2, - retryDelayMs: 0, - maxRetryDelayMs: 0 - }, - errorRetry: { - maxNumRetry: 1, - retryDelayMs: 1000, - maxRetryDelayMs: 8000 + if (video) { + video.levelCodec = currentLevel.videoCodec; + video.id = 'main'; + this.log(`Init video buffer, container:${video.container}, codecs[level/parsed]=[${currentLevel.videoCodec || ''}/${video.codec}]`); + } + if (audiovideo) { + this.log(`Init audiovideo buffer, container:${audiovideo.container}, codecs[level/parsed]=[${currentLevel.codecs}/${audiovideo.codec}]`); + } + this.hls.trigger(Events.BUFFER_CODECS, tracks); + // loop through tracks that are going to be provided to bufferController + Object.keys(tracks).forEach(trackName => { + const track = tracks[trackName]; + const initSegment = track.initSegment; + if (initSegment != null && initSegment.byteLength) { + this.hls.trigger(Events.BUFFER_APPENDING, { + type: trackName, + data: initSegment, + frag, + part: null, + chunkMeta, + parent: frag.type + }); } - } - }, - // These default settings are deprecated in favor of the above policies - // and are maintained for backwards compatibility - manifestLoadingTimeOut: 10000, - manifestLoadingMaxRetry: 1, - manifestLoadingRetryDelay: 1000, - manifestLoadingMaxRetryTimeout: 64000, - levelLoadingTimeOut: 10000, - levelLoadingMaxRetry: 4, - levelLoadingRetryDelay: 1000, - levelLoadingMaxRetryTimeout: 64000, - fragLoadingTimeOut: 20000, - fragLoadingMaxRetry: 6, - fragLoadingRetryDelay: 1000, - fragLoadingMaxRetryTimeout: 64000 -}, timelineConfig()), {}, { - subtitleStreamController: SubtitleStreamController , - subtitleTrackController: SubtitleTrackController , - timelineController: TimelineController , - audioStreamController: AudioStreamController , - audioTrackController: AudioTrackController , - emeController: EMEController , - cmcdController: CMCDController , - contentSteeringController: ContentSteeringController -}); -function timelineConfig() { - return { - cueHandler: Cues, - // used by timeline-controller - enableWebVTT: true, - // used by timeline-controller - enableIMSC1: true, - // used by timeline-controller - enableCEA708Captions: true, - // used by timeline-controller - captionsTextTrack1Label: 'English', - // used by timeline-controller - captionsTextTrack1LanguageCode: 'en', - // used by timeline-controller - captionsTextTrack2Label: 'Spanish', - // used by timeline-controller - captionsTextTrack2LanguageCode: 'es', - // used by timeline-controller - captionsTextTrack3Label: 'Unknown CC', - // used by timeline-controller - captionsTextTrack3LanguageCode: '', - // used by timeline-controller - captionsTextTrack4Label: 'Unknown CC', - // used by timeline-controller - captionsTextTrack4LanguageCode: '', - // used by timeline-controller - renderTextTracksNatively: true - }; -} - -/** - * @ignore - */ -function mergeConfig(defaultConfig, userConfig) { - if ((userConfig.liveSyncDurationCount || userConfig.liveMaxLatencyDurationCount) && (userConfig.liveSyncDuration || userConfig.liveMaxLatencyDuration)) { - throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration"); + }); + // trigger handler right now + this.tickImmediate(); } - if (userConfig.liveMaxLatencyDurationCount !== undefined && (userConfig.liveSyncDurationCount === undefined || userConfig.liveMaxLatencyDurationCount <= userConfig.liveSyncDurationCount)) { - throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be greater than "liveSyncDurationCount"'); + getMainFwdBufferInfo() { + return this.getFwdBufferInfo(this.mediaBuffer ? this.mediaBuffer : this.media, PlaylistLevelType.MAIN); } - if (userConfig.liveMaxLatencyDuration !== undefined && (userConfig.liveSyncDuration === undefined || userConfig.liveMaxLatencyDuration <= userConfig.liveSyncDuration)) { - throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be greater than "liveSyncDuration"'); + backtrack(frag) { + this.couldBacktrack = true; + // Causes findFragments to backtrack through fragments to find the keyframe + this.backtrackFragment = frag; + this.resetTransmuxer(); + this.flushBufferGap(frag); + this.fragmentTracker.removeFragment(frag); + this.fragPrevious = null; + this.nextLoadPosition = frag.start; + this.state = State.IDLE; } - const defaultsCopy = deepCpy(defaultConfig); + checkFragmentChanged() { + const video = this.media; + let fragPlayingCurrent = null; + if (video && video.readyState > 1 && video.seeking === false) { + const currentTime = video.currentTime; + /* if video element is in seeked state, currentTime can only increase. + (assuming that playback rate is positive ...) + As sometimes currentTime jumps back to zero after a + media decode error, check this, to avoid seeking back to + wrong position after a media decode error + */ - // Backwards compatibility with deprecated config values - const deprecatedSettingTypes = ['manifest', 'level', 'frag']; - const deprecatedSettings = ['TimeOut', 'MaxRetry', 'RetryDelay', 'MaxRetryTimeout']; - deprecatedSettingTypes.forEach(type => { - const policyName = `${type === 'level' ? 'playlist' : type}LoadPolicy`; - const policyNotSet = userConfig[policyName] === undefined; - const report = []; - deprecatedSettings.forEach(setting => { - const deprecatedSetting = `${type}Loading${setting}`; - const value = userConfig[deprecatedSetting]; - if (value !== undefined && policyNotSet) { - report.push(deprecatedSetting); - const settings = defaultsCopy[policyName].default; - userConfig[policyName] = { - default: settings - }; - switch (setting) { - case 'TimeOut': - settings.maxLoadTimeMs = value; - settings.maxTimeToFirstByteMs = value; - break; - case 'MaxRetry': - settings.errorRetry.maxNumRetry = value; - settings.timeoutRetry.maxNumRetry = value; - break; - case 'RetryDelay': - settings.errorRetry.retryDelayMs = value; - settings.timeoutRetry.retryDelayMs = value; - break; - case 'MaxRetryTimeout': - settings.errorRetry.maxRetryDelayMs = value; - settings.timeoutRetry.maxRetryDelayMs = value; - break; + if (BufferHelper.isBuffered(video, currentTime)) { + fragPlayingCurrent = this.getAppendedFrag(currentTime); + } else if (BufferHelper.isBuffered(video, currentTime + 0.1)) { + /* ensure that FRAG_CHANGED event is triggered at startup, + when first video frame is displayed and playback is paused. + add a tolerance of 100ms, in case current position is not buffered, + check if current pos+100ms is buffered and use that buffer range + for FRAG_CHANGED event reporting */ + fragPlayingCurrent = this.getAppendedFrag(currentTime + 0.1); + } + if (fragPlayingCurrent) { + this.backtrackFragment = null; + const fragPlaying = this.fragPlaying; + const fragCurrentLevel = fragPlayingCurrent.level; + if (!fragPlaying || fragPlayingCurrent.sn !== fragPlaying.sn || fragPlaying.level !== fragCurrentLevel) { + this.fragPlaying = fragPlayingCurrent; + this.hls.trigger(Events.FRAG_CHANGED, { + frag: fragPlayingCurrent + }); + if (!fragPlaying || fragPlaying.level !== fragCurrentLevel) { + this.hls.trigger(Events.LEVEL_SWITCHED, { + level: fragCurrentLevel + }); + } } } - }); - if (report.length) { - logger.warn(`hls.js config: "${report.join('", "')}" setting(s) are deprecated, use "${policyName}": ${JSON.stringify(userConfig[policyName])}`); } - }); - return _objectSpread2(_objectSpread2({}, defaultsCopy), userConfig); -} -function deepCpy(obj) { - if (obj && typeof obj === 'object') { - if (Array.isArray(obj)) { - return obj.map(deepCpy); + } + get nextLevel() { + const frag = this.nextBufferedFrag; + if (frag) { + return frag.level; } - return Object.keys(obj).reduce((result, key) => { - result[key] = deepCpy(obj[key]); - return result; - }, {}); + return -1; } - return obj; -} - -/** - * @ignore - */ -function enableStreamingMode(config) { - const currentLoader = config.loader; - if (currentLoader !== FetchLoader && currentLoader !== XhrLoader) { - // If a developer has configured their own loader, respect that choice - logger.log('[config]: Custom loader detected, cannot enable progressive streaming'); - config.progressive = false; - } else { - const canStreamProgressively = fetchSupported(); - if (canStreamProgressively) { - config.loader = FetchLoader; - config.progressive = true; - config.enableSoftwareAES = true; - logger.log('[config]: Progressive streaming enabled, using FetchLoader'); + get currentFrag() { + const media = this.media; + if (media) { + return this.fragPlaying || this.getAppendedFrag(media.currentTime); + } + return null; + } + get currentProgramDateTime() { + const media = this.media; + if (media) { + const currentTime = media.currentTime; + const frag = this.currentFrag; + if (frag && isFiniteNumber(currentTime) && isFiniteNumber(frag.programDateTime)) { + const epocMs = frag.programDateTime + (currentTime - frag.start) * 1000; + return new Date(epocMs); + } + } + return null; + } + get currentLevel() { + const frag = this.currentFrag; + if (frag) { + return frag.level; + } + return -1; + } + get nextBufferedFrag() { + const frag = this.currentFrag; + if (frag) { + return this.followingBufferedFrag(frag); } + return null; + } + get forceStartLoad() { + return this._forceStartLoad; } } @@ -200200,25 +202775,31 @@ function enableStreamingMode(config) { */ class Hls { /** - * The runtime configuration used by the player. At instantiation this is combination of `hls.userConfig` merged over `Hls.DefaultConfig`. + * Get the video-dev/hls.js package version. */ + static get version() { + return "1.5.0"; + } /** - * The configuration object provided on player instantiation. + * Check if the required MediaSource Extensions are available. */ + static isMSESupported() { + return isMSESupported(); + } /** - * Get the video-dev/hls.js package version. + * Check if MediaSource Extensions are available and isTypeSupported checks pass for any baseline codecs. */ - static get version() { - return "1.4.14"; + static isSupported() { + return isSupported(); } /** - * Check if the required MediaSource Extensions are available. + * Get the MediaSource global used for MSE playback (ManagedMediaSource, MediaSource, or WebKitMediaSource). */ - static isSupported() { - return isSupported(); + static getMediaSource() { + return getMediaSource(); } static get Events() { return Events; @@ -200252,12 +202833,19 @@ class Hls { * @param userConfig - Configuration options applied over `Hls.DefaultConfig` */ constructor(userConfig = {}) { + /** + * The runtime configuration used by the player. At instantiation this is combination of `hls.userConfig` merged over `Hls.DefaultConfig`. + */ this.config = void 0; + /** + * The configuration object provided on player instantiation. + */ this.userConfig = void 0; this.coreComponents = void 0; this.networkControllers = void 0; + this.started = false; this._emitter = new EventEmitter(); - this._autoLevelCapping = void 0; + this._autoLevelCapping = -1; this._maxHdcpLevel = null; this.abrController = void 0; this.bufferController = void 0; @@ -200271,10 +202859,10 @@ class Hls { this.cmcdController = void 0; this._media = null; this.url = null; + this.triggeringException = void 0; enableLogs(userConfig.debug || false, 'Hls instance'); const config = this.config = mergeConfig(Hls.DefaultConfig, userConfig); this.userConfig = userConfig; - this._autoLevelCapping = -1; if (config.progressive) { enableStreamingMode(config); } @@ -200374,15 +202962,21 @@ class Hls { } else { try { return this.emit(event, event, eventObject); - } catch (e) { - logger.error('An internal error happened while handling event ' + event + '. Error message: "' + e.message + '". Here is a stacktrace:', e); - this.trigger(Events.ERROR, { - type: ErrorTypes.OTHER_ERROR, - details: ErrorDetails.INTERNAL_EXCEPTION, - fatal: false, - event: event, - error: e - }); + } catch (error) { + logger.error('An internal error happened while handling event ' + event + '. Error message: "' + error.message + '". Here is a stacktrace:', error); + // Prevent recursion in error event handlers that throw #5497 + if (!this.triggeringException) { + this.triggeringException = true; + const fatal = event === Events.ERROR; + this.trigger(Events.ERROR, { + type: ErrorTypes.OTHER_ERROR, + details: ErrorDetails.INTERNAL_EXCEPTION, + fatal, + event, + error + }); + this.triggeringException = false; + } } } return false; @@ -200442,6 +203036,8 @@ class Hls { const loadingSource = this.url = urlToolkitExports.buildAbsoluteURL(self.location.href, url, { alwaysNormalize: true }); + this._autoLevelCapping = -1; + this._maxHdcpLevel = null; logger.log(`loadSource:${loadingSource}`); if (media && loadedSource && (loadedSource !== loadingSource || this.bufferController.hasSourceTypes())) { this.detachMedia(); @@ -200462,6 +203058,7 @@ class Hls { */ startLoad(startPosition = -1) { logger.log(`startLoad(${startPosition})`); + this.started = true; this.networkControllers.forEach(controller => { controller.startLoad(startPosition); }); @@ -200472,11 +203069,37 @@ class Hls { */ stopLoad() { logger.log('stopLoad'); + this.started = false; this.networkControllers.forEach(controller => { controller.stopLoad(); }); } + /** + * Resumes stream controller segment loading if previously started. + */ + resumeBuffering() { + if (this.started) { + this.networkControllers.forEach(controller => { + if ('fragmentLoader' in controller) { + controller.startLoad(-1); + } + }); + } + } + + /** + * Stops stream controller segment loading without changing 'started' state like stopLoad(). + * This allows for media buffering to be paused without interupting playlist loading. + */ + pauseBuffering() { + this.networkControllers.forEach(controller => { + if ('fragmentLoader' in controller) { + controller.stopLoad(); + } + }); + } + /** * Swap through possible audio codecs in the stream (for example to switch from stereo to 5.1) */ @@ -200499,12 +203122,12 @@ class Hls { this.attachMedia(media); } } - removeLevel(levelIndex, urlId = 0) { - this.levelController.removeLevel(levelIndex, urlId); + removeLevel(levelIndex) { + this.levelController.removeLevel(levelIndex); } /** - * @returns an array of levels (variants) sorted by HDCP-LEVEL, BANDWIDTH, SCORE, and RESOLUTION (height) + * @returns an array of levels (variants) sorted by HDCP-LEVEL, RESOLUTION (height), FRAME-RATE, CODECS, VIDEO-RANGE, and BANDWIDTH */ get levels() { const levels = this.levelController.levels; @@ -200523,8 +203146,7 @@ class Hls { */ set currentLevel(newLevel) { logger.log(`set currentLevel:${newLevel}`); - this.loadLevel = newLevel; - this.abrController.clearTimer(); + this.levelController.manualLevel = newLevel; this.streamController.immediateLevelSwitch(); } @@ -200597,13 +203219,17 @@ class Hls { } /** - * Return start level (level of first fragment that will be played back) - * if not overrided by user, first level appearing in manifest will be used as start level - * if -1 : automatic start level selection, playback will start from level matching download bandwidth - * (determined from download of first segment) + * Return the desired start level for the first fragment that will be loaded. + * The default value of -1 indicates automatic start level selection. + * Setting hls.nextAutoLevel without setting a startLevel will result in + * the nextAutoLevel value being used for one fragment load. */ get startLevel() { - return this.levelController.startLevel; + const startLevel = this.levelController.startLevel; + if (startLevel === -1 && this.abrController.forcedAutoLevel > -1) { + return this.abrController.forcedAutoLevel; + } + return startLevel; } /** @@ -200642,7 +203268,6 @@ class Hls { this.autoLevelCapping = -1; this.streamController.nextLevelSwitch(); // Now we're uncapped, get the next level asap. } - this.config.capLevelToPlayerSize = newCapLevelToPlayerSize; } } @@ -200666,6 +203291,9 @@ class Hls { } return bwEstimator.getEstimate(); } + set bandwidthEstimate(abrEwmaDefaultEstimate) { + this.abrController.resetEstimator(abrEwmaDefaultEstimate); + } /** * get time to first byte estimate @@ -200688,14 +203316,16 @@ class Hls { if (this._autoLevelCapping !== newLevel) { logger.log(`set autoLevelCapping:${newLevel}`); this._autoLevelCapping = newLevel; + this.levelController.checkMaxAutoUpdated(); } } get maxHdcpLevel() { return this._maxHdcpLevel; } set maxHdcpLevel(value) { - if (HdcpLevels.indexOf(value) > -1) { + if (isHdcpLevel(value) && this._maxHdcpLevel !== value) { this._maxHdcpLevel = value; + this.levelController.checkMaxAutoUpdated(); } } @@ -200743,7 +203373,7 @@ class Hls { maxHdcpLevel } = this; let maxAutoLevel; - if (autoLevelCapping === -1 && levels && levels.length) { + if (autoLevelCapping === -1 && levels != null && levels.length) { maxAutoLevel = levels.length - 1; } else { maxAutoLevel = autoLevelCapping; @@ -200758,13 +203388,15 @@ class Hls { } return maxAutoLevel; } + get firstAutoLevel() { + return this.abrController.firstAutoLevel; + } /** * next automatically selected quality level */ get nextAutoLevel() { - // ensure next auto level is between min and max auto level - return Math.min(Math.max(this.abrController.nextAutoLevel, this.minAutoLevel), this.maxAutoLevel); + return this.abrController.nextAutoLevel; } /** @@ -200775,7 +203407,7 @@ class Hls { * this value will be resetted to -1 by ABR controller. */ set nextAutoLevel(nextLevel) { - this.abrController.nextAutoLevel = Math.max(this.minAutoLevel, nextLevel); + this.abrController.nextAutoLevel = nextLevel; } /** @@ -200788,6 +203420,32 @@ class Hls { return this.streamController.getMainFwdBufferInfo(); } + /** + * Find and select the best matching audio track, making a level switch when a Group change is necessary. + * Updates `hls.config.audioPreference`. Returns the selected track, or null when no matching track is found. + */ + setAudioOption(audioOption) { + var _this$audioTrackContr; + return (_this$audioTrackContr = this.audioTrackController) == null ? void 0 : _this$audioTrackContr.setAudioOption(audioOption); + } + /** + * Find and select the best matching subtitle track, making a level switch when a Group change is necessary. + * Updates `hls.config.subtitlePreference`. Returns the selected track, or null when no matching track is found. + */ + setSubtitleOption(subtitleOption) { + var _this$subtitleTrackCo; + (_this$subtitleTrackCo = this.subtitleTrackController) == null ? void 0 : _this$subtitleTrackCo.setSubtitleOption(subtitleOption); + return null; + } + + /** + * Get the complete list of audio tracks across all media groups + */ + get allAudioTracks() { + const audioTrackController = this.audioTrackController; + return audioTrackController ? audioTrackController.allAudioTracks : []; + } + /** * Get the list of selectable audio tracks */ @@ -200814,6 +203472,14 @@ class Hls { } } + /** + * get the complete list of subtitle tracks across all media groups + */ + get allSubtitleTracks() { + const subtitleTrackController = this.subtitleTrackController; + return subtitleTrackController ? subtitleTrackController.allSubtitleTracks : []; + } + /** * get alternate subtitle tracks list from playlist */ @@ -201226,7 +203892,7 @@ function debounce (delay, callback, options) { /******/ // This function allow to reference async chunks /******/ __webpack_require__.u = function(chunkId) { /******/ // return url for filenames based on template -/******/ return "" + ({"292":"p__Classrooms__Lists__Exercise__Add__index","310":"p__User__Detail__ExperImentImg__Detail__index","556":"p__User__Detail__Order__pages__invoice__index","1482":"p__Classrooms__Lists__Graduation__Topics__Edit__index","1660":"p__User__QQLogin__index","1702":"p__Classrooms__New__index","2659":"p__User__Detail__UserPortrait__index","2819":"p__Classrooms__Lists__Template__detail__index","3317":"p__Classrooms__Lists__Graduation__Topics__Add__index","3391":"p__Classrooms__Lists__ProgramHomework__Detail__components__CodeReview__Detail__index","3451":"p__Classrooms__Lists__Statistics__StudentStatistics__Detail__index","3509":"p__HttpStatus__SixActivities","3585":"p__Classrooms__Lists__Statistics__StudentSituation__index","3951":"p__Classrooms__Lists__ProgramHomework__Detail__index","4736":"p__User__Detail__Projects__index","4766":"p__Administration__index","4884":"p__Shixuns__Detail__Repository__Commit__index","4973":"p__Engineering__Evaluate__List__index","5572":"p__Paths__HigherVocationalEducation__index","6127":"p__Classrooms__Lists__ProgramHomework__Ranking__index","6685":"p__Shixuns__Detail__RankingList__index","6758":"p__Classrooms__Lists__Attachment__index","6788":"p__Classrooms__Lists__ProgramHomework__index","7043":"p__User__Detail__Topics__Exercise__Edit__index","7852":"p__Classrooms__Lists__ShixunHomeworks__index","7884":"p__Shixuns__Exports__index","8787":"p__Competitions__Entered__index","8999":"p__Three__index","9416":"p__Graduations__Lists__Tasks__index","10195":"p__Classrooms__Lists__GroupHomework__Detail__index","10485":"p__Question__AddOrEdit__BatchAdd__index","10737":"p__Classrooms__Lists__CommonHomework__Detail__components__CodeReview__Detail__index","10799":"p__User__Detail__Topics__Poll__Detail__index","10921":"p__Classrooms__Lists__Exercise__CodeDetails__index","11070":"p__Innovation__PublicMirror__index","11253":"p__Graduations__Lists__Gradingsummary__index","11512":"p__Classrooms__Lists__Exercise__AnswerCheck__index","11520":"p__Engineering__Lists__StudentList__index","11545":"p__Paperlibrary__Random__ExchangeFromProblemSet__index","11581":"p__Problemset__Preview__index","12076":"p__User__Detail__Competitions__index","12102":"p__Classrooms__Lists__Board__Edit__index","12303":"p__Classrooms__Lists__CommonHomework__Comment__index","12412":"p__User__Detail__Videos__index","12476":"p__Colleges__index","12865":"p__Innovation__MyMirror__index","12884":"p__Classrooms__Lists__ProgramHomework__Comment__index","13006":"p__Engineering__index","13355":"p__Classrooms__Lists__Polls__index","13581":"p__Classrooms__Lists__ShixunHomeworks__Detail__index","14058":"p__Demo__index","14105":"p__Classrooms__Lists__Exercise__Answer__index","14227":"p__Paths__Overview__index","14514":"p__Account__Results__index","14599":"p__Problemset__index","14610":"p__User__Detail__LearningPath__index","14662":"p__Classrooms__Lists__GroupHomework__Review__index","14889":"p__Classrooms__Lists__Exercise__ImitateAnswer__index","15148":"p__Classrooms__Lists__Template__index","15186":"p__Classrooms__Overview__index","15319":"p__Classrooms__Lists__ProgramHomework__Detail__answer__Detail__index","15402":"p__User__Detail__Topics__Detail__index","16328":"p__Shixuns__Edit__body__Warehouse__index","16434":"p__User__Detail__Order__pages__records__index","16729":"p__Classrooms__Lists__GroupHomework__Edit__index","16845":"p__Shixuns__Detail__Settings__index","17482":"p__Classrooms__Lists__Exercise__Notice__index","17527":"p__MyProblem__RecordDetail__index","17622":"p__Classrooms__Lists__Polls__Detail__index","17806":"p__Classrooms__Lists__Statistics__StatisticsQuality__index","18241":"p__virtualSpaces__Lists__Plan__index","18302":"p__Classrooms__Lists__Board__index","18307":"p__User__Detail__Shixuns__index","19215":"p__Shixuns__Detail__ForkList__index","19360":"p__User__Detail__virtualSpaces__index","19519":"p__User__Detail__ClassManagement__Item__index","19715":"p__Classrooms__Lists__CommonHomework__Edit__index","19891":"p__User__Detail__Videos__Success__index","20026":"p__Classrooms__Lists__Graduation__Tasks__Edit__index","20576":"p__Account__Profile__Edit__index","20680":"p__Innovation__index","20700":"p__tasks__Jupyter__index","21265":"p__Classrooms__Lists__Announcement__index","21423":"p__Shixuns__Edit__body__Level__Challenges__EditPracticeAnswer__index","21578":"p__Classrooms__Lists__Graduation__Topics__Detail__index","21939":"p__User__Detail__Order__index","22254":"p__Shixuns__Detail__Discuss__index","22307":"p__Report__index","22707":"p__Innovation__MyDataSet__index","23332":"p__Paths__Detail__id","24504":"p__virtualSpaces__Lists__Survey__index","25022":"p__Graduations__Lists__Settings__index","25470":"p__Shixuns__Detail__Collaborators__index","25705":"p__virtualSpaces__Lists__Construction__index","25972":"layouts__user__index","26366":"p__Innovation__PublicProject__index","26685":"p__Classrooms__Index__index","26741":"p__Engineering__Norm__List__index","26883":"p__Competitions__Index__index","27178":"p__User__BindAccount__index","27182":"p__User__ResetPassword__index","27333":"p__User__WechatLogin__index","27395":"p__Classrooms__Lists__Statistics__StudentDetail__index","28072":"p__Classrooms__Lists__GroupHomework__SubmitWork__index","28237":"p__User__Detail__Order__pages__view__index","28435":"p__Classrooms__Lists__Attendance__index","28639":"p__Forums__Index__redirect","28723":"p__Classrooms__Lists__Polls__Edit__index","28782":"p__Shixuns__Index__index","28982":"p__Paths__New__index","29647":"p__Question__Index__index","30067":"p__Message__index","30264":"p__User__Detail__Order__pages__orderPay__index","30342":"p__Classrooms__Lists__ShixunHomeworks__Comment__index","31006":"p__RestFul__index","31211":"p__Classrooms__Lists__CommonHomework__EditWork__index","31427":"p__Classrooms__Lists__Statistics__index","31674":"p__Classrooms__ClassicCases__index","31962":"p__Classrooms__Lists__Engineering__index","33356":"p__Classrooms__Lists__Assistant__index","33747":"p__virtualSpaces__Lists__Homepage__index","33784":"p__Paperlibrary__Random__Detail__index","34093":"p__Classrooms__Lists__Attendance__Detail__index","34601":"p__Paths__Detail__Statistics__index","34741":"p__Problems__OjForm__NewEdit__index","34800":"p__Engineering__Lists__GraduatedMatrix__index","34994":"p__Problems__OjForm__index","35238":"p__virtualSpaces__Lists__Material__index","35729":"p__Help__Index","36029":"p__Administration__Student__index","36270":"p__MyProblem__index","36784":"p__Innovation__Edit__index","37062":"layouts__SimpleLayouts","37948":"p__User__Detail__ClassManagement__index","38143":"layouts__GraduationsDetail__index","38447":"p__virtualSpaces__Lists__Knowledge__index","38634":"p__Classrooms__Lists__CourseGroup__List__index","38797":"p__Competitions__Edit__index","39332":"p__Classrooms__Lists__Video__index","39391":"p__Engineering__Lists__CurseSetting__index","39404":"monaco-editor","39695":"p__Classrooms__Lists__Polls__Add__index","40559":"layouts__virtualDetail__index","41048":"p__Classrooms__Lists__ProgramHomework__Detail__Ranking__index","41657":"p__Shixuns__Edit__body__Level__Challenges__EditQuestion__index","41717":"layouts__index","41953":"p__Problemset__NewItem__index","42240":"p__User__Detail__Videos__Upload__index","43442":"p__Classrooms__Lists__Board__Add__index","43862":"p__HttpStatus__403","44216":"p__Classrooms__Lists__ProgramHomework__Detail__answer__Edit__index","44259":"p__User__Detail__Order__pages__result__index","44449":"p__Competitions__Exports__index","44565":"p__HttpStatus__500","45096":"p__Shixuns__Detail__AuditSituation__index","45179":"p__Administration__Student__Edit__index","45359":"p__Messages__Detail__index","45650":"p__Competitions__Update__index","45775":"p__Engineering__Lists__Document__index","45825":"p__Classrooms__Lists__Exercise__index","45992":"p__Classrooms__Lists__Exercise__ReviewGroup__index","46796":"p__virtualSpaces__Lists__Announcement__Detail__index","46963":"p__Classrooms__Lists__Engineering__Detail__index","47545":"p__Graduations__Lists__Archives__index","48077":"p__Classrooms__Lists__Students__index","48431":"p__Classrooms__Lists__Exercise__Export__index","48689":"p__Classrooms__Lists__Statistics__VideoStatistics__index","49205":"p__Shixuns__Edit__body__Level__Challenges__EditPracticeSetting__index","49366":"p__User__Login__index","49716":"p__Question__OjProblem__RecordDetail__index","49890":"p__Classrooms__Lists__CommonHomework__index","50869":"p__Guidance__index","51276":"p__MoopCases__Success__index","51461":"p__Graduations__Lists__Topics__index","51582":"p__Classrooms__Lists__GroupHomework__Add__index","51855":"p__MoopCases__InfoPanel__index","52338":"p__Classrooms__Lists__CommonHomework__Review__index","52404":"p__Classrooms__Lists__Template__teacher__index","52806":"p__User__Detail__Topics__Exercise__Detail__index","52829":"p__Messages__Private__index","52875":"p__Shixuns__Detail__id","53247":"p__Paperlibrary__See__index","53910":"p__HttpStatus__introduction","54056":"p__IntrainCourse__index","54164":"p__Classrooms__Lists__Exercise__Detail__index","54492":"p__Graduations__Lists__StudentSelection__index","54572":"p__Classrooms__Lists__ExportList__index","54770":"p__Classrooms__Lists__ProgramHomework__Detail__answer__index","54862":"p__Paperlibrary__index","55573":"p__Shixuns__Detail__Merge__index","55624":"p__Graduations__Lists__Index__index","56277":"p__Shixuns__Edit__index","57045":"p__Classrooms__Lists__CommonHomework__SubmitWork__index","57560":"p__Administration__College__index","57614":"p__Shixuns__Edit__body__Level__Challenges__RankingSetting__index","59133":"p__Shixuns__Detail__Challenges__index","59649":"p__Engineering__Lists__TrainingProgram__index","59788":"p__Account__Profile__index","60479":"p__Classrooms__Lists__GroupHomework__EditWork__index","60533":"p__Classrooms__Lists__Video__Statistics__Detail__index","60547":"p__Account__index","61043":"p__Classrooms__Lists__Graduation__Tasks__index","61713":"p__virtualSpaces__Lists__Settings__index","61727":"p__Classrooms__Lists__CourseGroup__NotList__index","61880":"p__User__Detail__Order__pages__apply__index","62300":"p__Api__index","62548":"p__Engineering__Norm__Detail__index","63157":"p__User__Detail__ExperImentImg__Add__index","64017":"p__Classrooms__Lists__PlaceholderPage__index","64144":"p__Problemset__Preview__New__index","64217":"p__Classrooms__Lists__Video__Statistics__index","64496":"p__HttpStatus__HpcCourse","64520":"p__Account__Secure__index","65111":"p__Terminal__index","65148":"p__Classrooms__Lists__Polls__Answer__index","65191":"p__User__Detail__Certificate__index","65549":"p__Shixuns__New__CreateImg__index","65816":"p__virtualSpaces__Lists__Announcement__index","66034":"p__HttpStatus__UserAgents","66063":"p__Graduations__Lists__Personmanage__index","66531":"p__HttpStatus__404","66583":"p__User__Detail__Classrooms__index","66651":"p__Engineering__Evaluate__Detail__index","67242":"p__Innovation__MyProject__index","67878":"p__Classrooms__Lists__LiveVideo__index","68014":"p__Classrooms__Lists__Teachers__index","68665":"p__Engineering__Lists__TrainingObjectives__index","68827":"p__Classrooms__Lists__OnlineLearning__index","68882":"p__Classrooms__Lists__Graduation__Tasks__Detail__index","69922":"p__Classrooms__Lists__Statistics__StudentVideo__index","69944":"p__Classrooms__Lists__Video__Statistics__StudentDetail__index","70928":"p__RestFul__Edit__index","71450":"p__Classrooms__Lists__ShixunHomeworks__Commitsummary__index","71783":"p__virtualSpaces__Lists__Experiment__index","72529":"p__User__Detail__id","72539":"p__Graduations__Review__index","72570":"p__Competitions__Detail__index","73183":"p__Engineering__Lists__GraduationIndex__index","73220":"p__Classrooms__Lists__Video__Upload__index","74264":"p__Forums__New__index","74795":"p__Classrooms__Lists__Graduation__Tasks__Add__index","75043":"p__User__Detail__Topics__Poll__Edit__index","75357":"p__Engineering__Lists__TrainingProgram__Edit__index","75786":"layouts__LoginAndRegister__index","75816":"p__Paperlibrary__Random__Edit__index","76904":"p__MoopCases__FormPanel__index","77460":"p__Question__OjProblem__index","77857":"p__Shixuns__Edit__body__Level__Challenges__NewQuestion__index","78085":"p__Classrooms__Lists__Exercise__Review__index","79489":"p__Engineering__Lists__CourseList__index","79590":"p__User__Detail__TeachGroup__index","79921":"p__Classrooms__ExamList__index","80508":"p__Forums__Detail__id","81148":"p__Shixuns__Detail__Repository__UploadFile__index","81799":"p__Competitions__Entered__Assembly__TeamDateil","82339":"p__virtualSpaces__Lists__Plan__Detail__index","82425":"p__Classrooms__Lists__Board__Detail__index","82443":"p__Graduations__Lists__StageModule__index","83141":"p__Innovation__Detail__index","83212":"p__MoopCases__index","83935":"p__Classrooms__Lists__GroupHomework__index","84546":"p__Engineering__Lists__TrainingProgram__Add__index","85048":"p__Classrooms__Lists__Graduation__Topics__index","85111":"p__User__Detail__Order__pages__orderInformation__index","85297":"p__Classrooms__Lists__Exercise__Detail__components__DuplicateChecking__CheckDetail__index","85888":"p__Classrooms__Lists__CommonHomework__Add__index","85891":"p__virtualSpaces__Lists__Resources__index","86052":"p__Paths__Index__index","86452":"p__Innovation__PublicDataSet__index","86541":"p__Shixuns__Detail__Dataset__index","86634":"p__Innovation__Tasks__index","86820":"p__User__Detail__Topics__Normal__index","86913":"p__Question__AddOrEdit__index","87058":"p__virtualSpaces__Lists__Survey__Detail__index","87260":"p__Account__Certification__index","87922":"p__Classrooms__Lists__CourseGroup__Detail__index","88155":"p__Shixuns__Overview__index","88517":"p__User__Detail__Topics__Group__index","88866":"p__index","89076":"p__Account__Binding__index","89677":"p__virtualSpaces__Lists__Announcement__AddAndEdit__index","89785":"p__Classrooms__Lists__Template__student__index","90109":"p__Classrooms__Lists__ShixunHomeworks__Detail__components__CodeReview__Detail__index","90265":"p__User__Detail__Topics__index","90337":"p__Paperlibrary__Random__PreviewEdit__index","91045":"p__virtualSpaces__Lists__Knowledge__AddAndEdit__index","91470":"p__User__Register__index","91831":"p__Graduations__Index__index","92045":"p__Engineering__Lists__TeacherList__index","92501":"p__Search__index","92603":"p__Classrooms__Lists__ProgramHomework__Detail__answer__Add__index","92823":"p__Engineering__Navigation__Home__index","92983":"p__Forums__Index__index","93260":"p__Paperlibrary__Add__index","93282":"layouts__ShixunDetail__index","93496":"p__User__Detail__OtherResources__index","93665":"p__tasks__index","93668":"p__Classrooms__Lists__CommonHomework__Detail__index","94078":"p__Messages__Tidings__index","94498":"p__Shixuns__Edit__body__Level__Challenges__NewPractice__index","94662":"p__User__Detail__Paths__index","94715":"p__virtualSpaces__Lists__Material__Detail__index","94849":"p__User__Detail__ExperImentImg__index","95125":"p__Classrooms__Lists__Exercise__DetailedAnalysis__index","95176":"p__User__Detail__Videos__Protocol__index","95335":"p__Engineering__Lists__CourseMatrix__index","96444":"p__Video__Detail__id","96882":"p__Classrooms__New__StartClass__index","97008":"p__Shixuns__New__index","97046":"p__Shixuns__Detail__Repository__AddFile__index","98062":"p__User__Detail__Topicbank__index","98398":"p__virtualSpaces__Lists__Resources__Detail__index","98688":"p__Shixuns__Detail__Repository__index","98885":"p__Classrooms__Lists__Statistics__StudentStatistics__index","99674":"p__Shixuns__New__ImagePreview__index"}[chunkId] || chunkId) + "." + {"92":"fba1ec42","127":"01b0e779","271":"0382915d","292":"2d97116f","310":"2b3692a8","556":"b5dc7627","1482":"711d2152","1653":"f778458b","1660":"13e763e4","1686":"df99c1fa","1702":"8e1ba196","2249":"90399667","2360":"2f3cadfa","2494":"5e069ec9","2595":"3c9ff6f5","2659":"694613c9","2805":"d6f0ae11","2819":"c2f7511d","2837":"b3a05bc1","3133":"6a9f7113","3317":"a8a2288f","3391":"e4cb0657","3451":"adbc2344","3471":"f3963651","3509":"3190935e","3585":"07020bd0","3885":"e66b03f8","3951":"7f31648a","4685":"21279a05","4736":"d2bf9775","4766":"b807262b","4884":"56a464cc","4973":"0ea90133","5112":"c1217071","5434":"361b868d","5572":"74405533","6127":"1f74646f","6216":"e580c712","6305":"45f1436e","6378":"27c8142f","6685":"868ec2d7","6758":"91193e92","6788":"b0048471","7043":"4805e542","7105":"83cfe42f","7356":"ff86e2ec","7852":"8a580825","7884":"96dccf69","8254":"02e1492b","8787":"682ed6ee","8999":"d7621b81","9042":"9ded77c2","9416":"2251081f","9485":"901f1fc5","9894":"f87c0ebb","9928":"5856e32a","9951":"295caf46","10195":"ba9090a4","10354":"5c063e6f","10375":"41e2eeb8","10485":"70485d0f","10635":"3efedcfa","10737":"fbbf4e72","10799":"91888727","10921":"d24dbf15","11070":"5f65f973","11253":"4a7033bb","11512":"feea018e","11520":"cdb956ef","11545":"dd5a721e","11561":"381d63a4","11581":"57c70a9f","11752":"9ed6c1fb","11833":"3e529ada","12076":"ef5927f1","12102":"bc50bd68","12303":"625f0fa2","12312":"6ebc949e","12386":"289c62c7","12412":"fbf9ba6e","12476":"ce382ef2","12865":"386d0cc0","12884":"f9e1cf5a","12911":"f94aa754","13006":"3a6bcfb0","13007":"2e9a9b22","13355":"ee6ebc58","13488":"ae031fd2","13581":"631fc79e","14000":"63f19e1a","14047":"4d6e5ffd","14058":"fad07263","14088":"c639825c","14105":"444f506a","14227":"c500e935","14333":"9e585c8f","14514":"de04ad78","14599":"f24fc396","14610":"6073b0a2","14642":"d8d9787e","14662":"5aef6830","14889":"309a4281","14993":"2d4d9856","15148":"fdb3720c","15186":"c162e773","15192":"1732d5a3","15250":"83dc2796","15290":"7b3f25d8","15319":"c6325383","15402":"b9156348","15569":"113c5038","15631":"d790a1bf","15845":"c8fe49ef","16328":"30b72346","16434":"20768b2f","16703":"f6abb1ba","16717":"9a38b45f","16729":"ab2132e1","16834":"817e62e4","16845":"9045ce5c","17142":"871bf314","17482":"b570ebd2","17527":"c5e9f883","17622":"9e5f637c","17806":"d2e3091a","18080":"6bcb1e13","18241":"88ffeaec","18302":"e3455b91","18307":"98cd8604","18350":"0ed0f7c3","18898":"25ad586a","18963":"33e3df18","19208":"85e01132","19215":"f83ac751","19360":"b1a651e5","19403":"3ab72a54","19519":"9ee4350a","19715":"1a494c1e","19842":"9eda460f","19891":"9cca4e6d","20026":"511bd98c","20062":"704c7129","20459":"c87122fd","20576":"c90e7824","20680":"a5a0ab60","20700":"c7ff0e17","20798":"d52f5213","20834":"26522551","21105":"7c0014aa","21265":"e4cc4af8","21423":"6c32cfc3","21560":"638caddd","21578":"744a5cfe","21939":"3c396a26","22254":"763a2dde","22307":"3afdc39f","22707":"c27a1cf9","23332":"1edc7e3c","23760":"f0904fce","24504":"e3601d8f","24628":"b863dad4","24665":"cea8e4ab","24797":"eb563316","25022":"d716ddc2","25105":"c2000cc7","25470":"79c0c778","25473":"8713b979","25490":"1a22a456","25576":"6afe7528","25705":"5ca9768e","25972":"eb375435","26126":"400f4fd5","26289":"8b16f4a4","26366":"014b0d8e","26588":"9c91bf02","26685":"3162df70","26741":"d3f81881","26883":"ca3f08b9","27178":"69a6a161","27182":"0cd11b7d","27315":"e89b908d","27333":"5c552215","27395":"31e7656a","27706":"c0d5e1ef","27739":"3bb25e43","27809":"3a2f492a","27829":"17300772","28009":"e42ab4ab","28072":"923996b4","28089":"aaa88c03","28161":"00a22aad","28163":"0081a56b","28237":"55256130","28435":"23d6a030","28561":"ec76d55e","28639":"2afb0fe5","28723":"e27ec039","28782":"1b125ca0","28920":"842a9870","28982":"cb00fe75","29190":"2e5cd7df","29414":"026ca7c3","29525":"e4f7063f","29535":"da216de7","29559":"cdc05f60","29647":"bc3193af","29895":"1fa85db5","29968":"5c930f27","30067":"0bea709f","30264":"172872b6","30335":"935fd8ca","30342":"1dcbb3d7","30441":"f8fc31e1","30741":"0afd7032","31006":"b1c43e5f","31087":"8aba01dd","31154":"abb4690e","31211":"f87b6d0f","31246":"ec10a487","31427":"8524b261","31674":"b1536dd2","31962":"7b54b573","32528":"96344ced","33056":"564080f7","33356":"2b31f149","33461":"d0c0c21b","33611":"c8d0abd6","33747":"92cc7764","33784":"b2904a2d","33805":"a93fd24f","34093":"665df972","34333":"513d6fbe","34495":"5be08a04","34601":"f4fd40cb","34668":"b7cfef49","34741":"d9388c2f","34790":"6eb90335","34800":"f1a5e866","34850":"daf624f2","34994":"bc821174","35060":"7530a2b3","35238":"f716152b","35354":"c0640e01","35416":"b4018e87","35729":"c514a24f","36029":"8d977ff9","36187":"d9cce9bb","36270":"006dfc85","36634":"03daa006","36784":"5f1bbaac","37062":"25c7d9be","37825":"5ef8076b","37885":"54433a82","37948":"942b4168","38143":"0a21df19","38177":"3dd2875c","38447":"2452b152","38634":"94ac1d57","38773":"b004873e","38797":"e8bd5cad","39252":"01ffe0b6","39299":"da682f81","39332":"6d1d5536","39391":"7e4bd5b8","39404":"22b5c59a","39695":"23adab3c","39787":"2d6930a2","39790":"f0e8ec83","39950":"57e939c0","40559":"d0441361","40847":"b71f3f54","41001":"da53c620","41048":"ef8d71fe","41657":"9a0711de","41717":"fa36080b","41811":"f1228622","41867":"53a6b604","41885":"5cf119f9","41921":"3d0081d2","41953":"fae4a1eb","42240":"c38013a4","42441":"9616313f","42917":"43e3ea7e","43110":"6abf25af","43428":"603ed3fd","43442":"8e8c6f69","43862":"1b7b3ff8","44147":"66791dd7","44216":"7d587b93","44259":"e0f8d927","44354":"4d10aca1","44360":"2fe17938","44425":"e6f53013","44449":"7632b1a0","44565":"ac4e1131","44613":"9bd3f6b0","45096":"2c158a99","45179":"e3abdd6b","45359":"78b949ac","45413":"ae45b3f8","45504":"7f6c0d59","45519":"a8174812","45582":"a829d032","45650":"61b83229","45775":"9b841426","45825":"103780cc","45909":"6a6c1f27","45992":"29806d58","46177":"0cb7db14","46372":"b81f2ce1","46573":"db7fbeee","46796":"688c18ae","46963":"8c8b0160","47256":"b1cde63d","47545":"3097a74d","47686":"f38a5fc1","47962":"9ee995b4","48077":"0423702a","48431":"6ef20ec6","48560":"54c406b5","48573":"3d9e4c7c","48689":"aca765d6","48691":"5775abd3","48776":"3ca5830e","48826":"17ad40dc","48913":"c45d4a20","49127":"f74d686d","49166":"20802f83","49205":"bc50bea1","49260":"d82ab47f","49366":"ee413809","49716":"e0656535","49890":"c4af4c2b","49906":"e25401e9","50251":"10ae186b","50812":"5d8b4e73","50869":"01508392","51144":"88d767c5","51276":"f9412058","51461":"37358c55","51582":"3bde123f","51646":"a1e61a3a","51855":"c53a1f8f","52312":"29d0251e","52338":"2039b97f","52404":"8b959a27","52409":"4a79ab63","52720":"a99b0bb3","52806":"1d28f1fa","52829":"3329615d","52875":"e05171ae","52987":"d784c083","53114":"685610c8","53247":"a1ae0a4a","53359":"e50240bc","53550":"d1343c48","53555":"40da94e6","53697":"344fc05c","53777":"630cd89c","53877":"c56d519b","53910":"b29f1429","53936":"0a44ec6e","54056":"3d06af4d","54164":"2d0aafb0","54393":"5c9f6f6c","54492":"1855c61b","54513":"f74dc486","54572":"18b6d1d7","54747":"e95d0294","54770":"3ac6c352","54862":"47e9c8bb","55127":"79f60e9a","55351":"b1b9a06c","55573":"9b121369","55624":"4b8a4858","55693":"4b714ff1","55950":"ca799b07","56021":"119eec61","56047":"b4b0d1c6","56156":"c61ad60b","56277":"6708e736","57045":"6df2b297","57365":"7e7804c5","57395":"1a8bd603","57560":"a014011c","57614":"ae1a8e98","57814":"fcc0b9c5","57889":"d093c543","58203":"045ac759","58271":"04f27f83","59133":"bf632bea","59649":"ea3d2935","59788":"00186671","59981":"8de9b01a","60479":"d5ab0727","60533":"4f3e3f86","60547":"c194da92","60590":"73a88b51","61043":"e4683c65","61713":"793864bf","61727":"9e46fc78","61761":"aae6d026","61880":"8d2ed650","61895":"534d8055","61952":"57a3c83e","62300":"082c4fab","62438":"40550107","62548":"e9b57ca3","62687":"8f8afe49","62778":"24586e4d","62945":"927b34c0","62979":"95ee6c8c","63157":"5a0d6fcc","63198":"f92793e1","63724":"0beb7987","63791":"18e115ca","64017":"0a564de0","64144":"11d544fe","64217":"328904a4","64447":"0244198b","64496":"161e856a","64520":"9ec0910e","64802":"1090d644","65111":"829d60e7","65148":"8cb95cf6","65191":"a3f6b239","65549":"5137a2cb","65816":"499002ca","65876":"a2754c64","66034":"04bc580a","66063":"edbe39df","66174":"53889c84","66302":"5397bd98","66381":"2783fbb7","66531":"5d0eb70a","66583":"a30fe47f","66651":"411c3d8f","67156":"918b4bca","67242":"aad92ca5","67468":"e4e958f2","67878":"c0c68428","68014":"fd74b4bb","68665":"79393a8a","68685":"2707d0be","68761":"fd19b2db","68827":"3db20491","68842":"19057860","68882":"8061833b","69242":"bff4b036","69922":"dafbcb04","69944":"e9153c8f","70130":"de78f0fd","70544":"05116266","70671":"749b4875","70928":"0fd06df7","70981":"157d0b6b","71126":"cd42e3cf","71448":"719d9d6e","71450":"23b3a8ab","71783":"cca11a1e","72011":"7efe6dda","72032":"d87e2e7b","72274":"4446bc88","72315":"d8d70ba7","72529":"4220d582","72539":"f0dd3506","72570":"0c217862","72605":"abd4c915","72773":"72493b4c","72969":"53256e8c","73168":"6c64659d","73183":"a656eb16","73220":"40bf0dde","73755":"7bd6b4f7","74014":"5339ac81","74264":"592b7741","74347":"a722ba6c","74675":"9e3112e8","74795":"8f033c4a","74997":"50a24f6b","75043":"8cb63c5b","75149":"2a800bb8","75321":"9b9a5dc1","75357":"6d5db9e9","75786":"db8f262f","75816":"7d72d6c5","75956":"d227f395","76904":"c8374112","76938":"a2709ddd","77084":"5fe882f0","77298":"4974ba9f","77350":"4a433c33","77437":"965aadda","77460":"c08c00e3","77772":"4f39a385","77857":"9f802652","77918":"bb41c9de","78085":"ef810c11","78241":"f698b2a3","78302":"2f657c59","78737":"fa31da0e","78782":"f9e80406","78859":"958de94c","78892":"ad739ccc","79439":"ec9ac461","79489":"cc71c18f","79590":"cd9f5dc8","79594":"e7b6ac37","79817":"69f42c89","79838":"c18a3f23","79921":"29dcac03","80399":"a890a6a9","80508":"15de3f87","80629":"ca49ee59","81057":"32ad27c1","81148":"664dc7f9","81326":"19829c36","81799":"bf73fa92","82080":"10f5c31e","82274":"f9b9c5c0","82339":"a7b0c187","82425":"20f23cf7","82443":"215042da","82890":"1b3ff4d6","83141":"81f04225","83212":"6092982a","83306":"917d504a","83935":"4429ad1f","83980":"05917be1","84546":"3f0a3b1d","84742":"6b5fed0b","85048":"d2fdedef","85081":"a73db95f","85111":"ffdb7e65","85297":"b9ce2001","85494":"da5840b1","85731":"49f28568","85764":"5c1c73b5","85794":"713c9192","85888":"0599e9f4","85891":"30bc0c2f","86045":"0a358cbb","86052":"d828e88f","86129":"801a9880","86452":"0bd1db6d","86541":"83216e40","86562":"4691cd5c","86634":"2aaf84e9","86774":"2db1d78d","86820":"55a5dabd","86913":"b0a045bc","86928":"8476f27f","87058":"b280c002","87260":"1195c883","87377":"70c5c54f","87557":"99277364","87922":"31f64ec6","87964":"83911fb5","88100":"0bd2630c","88155":"9f915cbd","88517":"1e95f5e7","88652":"b79a083e","88699":"0e126269","88816":"b48e55d9","88866":"33bc908f","89076":"5703f861","89360":"0c517cb7","89554":"3bd5f2ea","89597":"d1f2e594","89677":"fb15b8c6","89718":"c59ee184","89785":"f5dba329","90109":"107b6bbd","90265":"200b695e","90316":"c34a4fc4","90337":"6524bae4","91045":"a0ea1447","91274":"c142e23b","91375":"1d992b74","91462":"2cbc46cd","91470":"b8ee8755","91831":"8a7e2842","91834":"3905c46e","91857":"e34c7f99","92045":"afb668e4","92501":"1051e43b","92538":"a4db897b","92594":"0f02017f","92603":"7b1fffc0","92823":"eddfc70c","92983":"234bbb25","93260":"c0261dcd","93282":"52b61176","93496":"7bbc7570","93665":"e9d5ab5a","93668":"0aa1fd27","93948":"61d5b51a","94078":"1637d24d","94333":"3ec8aa1d","94439":"c3f3a54b","94498":"0cea6990","94662":"21ac244e","94715":"9103b8f4","94849":"8e3ff5e8","95125":"7711645f","95176":"07eeb5d7","95335":"d07e7932","95383":"f753ea65","95679":"33378d80","96232":"d49022e5","96444":"7406629c","96882":"763ad5aa","97008":"57ab8e72","97041":"9e9d8791","97046":"54a4bbdd","97120":"0eb88e7b","97591":"4868bb6b","97986":"e759afe2","98062":"2fdc4522","98228":"9183e003","98398":"a4373c63","98688":"7b46c48a","98885":"a2947fec","99104":"d4f63539","99313":"89e6d4a3","99674":"67f5c5de","99939":"68b2d9a0"}[chunkId] + ".async.js"; +/******/ return "" + ({"292":"p__Classrooms__Lists__Exercise__Add__index","310":"p__User__Detail__ExperImentImg__Detail__index","556":"p__User__Detail__Order__pages__invoice__index","1482":"p__Classrooms__Lists__Graduation__Topics__Edit__index","1660":"p__User__QQLogin__index","1702":"p__Classrooms__New__index","2659":"p__User__Detail__UserPortrait__index","2819":"p__Classrooms__Lists__Template__detail__index","3317":"p__Classrooms__Lists__Graduation__Topics__Add__index","3391":"p__Classrooms__Lists__ProgramHomework__Detail__components__CodeReview__Detail__index","3451":"p__Classrooms__Lists__Statistics__StudentStatistics__Detail__index","3509":"p__HttpStatus__SixActivities","3585":"p__Classrooms__Lists__Statistics__StudentSituation__index","3951":"p__Classrooms__Lists__ProgramHomework__Detail__index","4736":"p__User__Detail__Projects__index","4766":"p__Administration__index","4884":"p__Shixuns__Detail__Repository__Commit__index","4973":"p__Engineering__Evaluate__List__index","5572":"p__Paths__HigherVocationalEducation__index","6127":"p__Classrooms__Lists__ProgramHomework__Ranking__index","6685":"p__Shixuns__Detail__RankingList__index","6758":"p__Classrooms__Lists__Attachment__index","6788":"p__Classrooms__Lists__ProgramHomework__index","7043":"p__User__Detail__Topics__Exercise__Edit__index","7852":"p__Classrooms__Lists__ShixunHomeworks__index","7884":"p__Shixuns__Exports__index","8787":"p__Competitions__Entered__index","8999":"p__Three__index","9416":"p__Graduations__Lists__Tasks__index","10195":"p__Classrooms__Lists__GroupHomework__Detail__index","10485":"p__Question__AddOrEdit__BatchAdd__index","10737":"p__Classrooms__Lists__CommonHomework__Detail__components__CodeReview__Detail__index","10799":"p__User__Detail__Topics__Poll__Detail__index","10921":"p__Classrooms__Lists__Exercise__CodeDetails__index","11070":"p__Innovation__PublicMirror__index","11253":"p__Graduations__Lists__Gradingsummary__index","11512":"p__Classrooms__Lists__Exercise__AnswerCheck__index","11520":"p__Engineering__Lists__StudentList__index","11545":"p__Paperlibrary__Random__ExchangeFromProblemSet__index","11581":"p__Problemset__Preview__index","12076":"p__User__Detail__Competitions__index","12102":"p__Classrooms__Lists__Board__Edit__index","12303":"p__Classrooms__Lists__CommonHomework__Comment__index","12412":"p__User__Detail__Videos__index","12476":"p__Colleges__index","12865":"p__Innovation__MyMirror__index","12884":"p__Classrooms__Lists__ProgramHomework__Comment__index","13006":"p__Engineering__index","13355":"p__Classrooms__Lists__Polls__index","13581":"p__Classrooms__Lists__ShixunHomeworks__Detail__index","14058":"p__Demo__index","14105":"p__Classrooms__Lists__Exercise__Answer__index","14227":"p__Paths__Overview__index","14514":"p__Account__Results__index","14599":"p__Problemset__index","14610":"p__User__Detail__LearningPath__index","14662":"p__Classrooms__Lists__GroupHomework__Review__index","14889":"p__Classrooms__Lists__Exercise__ImitateAnswer__index","15148":"p__Classrooms__Lists__Template__index","15186":"p__Classrooms__Overview__index","15319":"p__Classrooms__Lists__ProgramHomework__Detail__answer__Detail__index","15402":"p__User__Detail__Topics__Detail__index","16328":"p__Shixuns__Edit__body__Warehouse__index","16434":"p__User__Detail__Order__pages__records__index","16729":"p__Classrooms__Lists__GroupHomework__Edit__index","16845":"p__Shixuns__Detail__Settings__index","17482":"p__Classrooms__Lists__Exercise__Notice__index","17527":"p__MyProblem__RecordDetail__index","17622":"p__Classrooms__Lists__Polls__Detail__index","17806":"p__Classrooms__Lists__Statistics__StatisticsQuality__index","18241":"p__virtualSpaces__Lists__Plan__index","18302":"p__Classrooms__Lists__Board__index","18307":"p__User__Detail__Shixuns__index","19215":"p__Shixuns__Detail__ForkList__index","19360":"p__User__Detail__virtualSpaces__index","19519":"p__User__Detail__ClassManagement__Item__index","19715":"p__Classrooms__Lists__CommonHomework__Edit__index","19891":"p__User__Detail__Videos__Success__index","20026":"p__Classrooms__Lists__Graduation__Tasks__Edit__index","20576":"p__Account__Profile__Edit__index","20680":"p__Innovation__index","20700":"p__tasks__Jupyter__index","21265":"p__Classrooms__Lists__Announcement__index","21423":"p__Shixuns__Edit__body__Level__Challenges__EditPracticeAnswer__index","21578":"p__Classrooms__Lists__Graduation__Topics__Detail__index","21939":"p__User__Detail__Order__index","22254":"p__Shixuns__Detail__Discuss__index","22307":"p__Report__index","22707":"p__Innovation__MyDataSet__index","23332":"p__Paths__Detail__id","24504":"p__virtualSpaces__Lists__Survey__index","25022":"p__Graduations__Lists__Settings__index","25470":"p__Shixuns__Detail__Collaborators__index","25705":"p__virtualSpaces__Lists__Construction__index","25972":"layouts__user__index","26366":"p__Innovation__PublicProject__index","26685":"p__Classrooms__Index__index","26741":"p__Engineering__Norm__List__index","26883":"p__Competitions__Index__index","27178":"p__User__BindAccount__index","27182":"p__User__ResetPassword__index","27333":"p__User__WechatLogin__index","27395":"p__Classrooms__Lists__Statistics__StudentDetail__index","28072":"p__Classrooms__Lists__GroupHomework__SubmitWork__index","28237":"p__User__Detail__Order__pages__view__index","28435":"p__Classrooms__Lists__Attendance__index","28639":"p__Forums__Index__redirect","28723":"p__Classrooms__Lists__Polls__Edit__index","28782":"p__Shixuns__Index__index","28982":"p__Paths__New__index","29647":"p__Question__Index__index","30067":"p__Message__index","30264":"p__User__Detail__Order__pages__orderPay__index","30342":"p__Classrooms__Lists__ShixunHomeworks__Comment__index","31006":"p__RestFul__index","31211":"p__Classrooms__Lists__CommonHomework__EditWork__index","31427":"p__Classrooms__Lists__Statistics__index","31674":"p__Classrooms__ClassicCases__index","31962":"p__Classrooms__Lists__Engineering__index","33356":"p__Classrooms__Lists__Assistant__index","33747":"p__virtualSpaces__Lists__Homepage__index","33784":"p__Paperlibrary__Random__Detail__index","34093":"p__Classrooms__Lists__Attendance__Detail__index","34601":"p__Paths__Detail__Statistics__index","34741":"p__Problems__OjForm__NewEdit__index","34800":"p__Engineering__Lists__GraduatedMatrix__index","34994":"p__Problems__OjForm__index","35238":"p__virtualSpaces__Lists__Material__index","35729":"p__Help__Index","36029":"p__Administration__Student__index","36270":"p__MyProblem__index","36784":"p__Innovation__Edit__index","37062":"layouts__SimpleLayouts","37948":"p__User__Detail__ClassManagement__index","38143":"layouts__GraduationsDetail__index","38447":"p__virtualSpaces__Lists__Knowledge__index","38634":"p__Classrooms__Lists__CourseGroup__List__index","38797":"p__Competitions__Edit__index","39332":"p__Classrooms__Lists__Video__index","39391":"p__Engineering__Lists__CurseSetting__index","39404":"monaco-editor","39695":"p__Classrooms__Lists__Polls__Add__index","40559":"layouts__virtualDetail__index","41048":"p__Classrooms__Lists__ProgramHomework__Detail__Ranking__index","41657":"p__Shixuns__Edit__body__Level__Challenges__EditQuestion__index","41717":"layouts__index","41953":"p__Problemset__NewItem__index","42240":"p__User__Detail__Videos__Upload__index","43442":"p__Classrooms__Lists__Board__Add__index","43862":"p__HttpStatus__403","44216":"p__Classrooms__Lists__ProgramHomework__Detail__answer__Edit__index","44259":"p__User__Detail__Order__pages__result__index","44449":"p__Competitions__Exports__index","44565":"p__HttpStatus__500","45096":"p__Shixuns__Detail__AuditSituation__index","45179":"p__Administration__Student__Edit__index","45359":"p__Messages__Detail__index","45650":"p__Competitions__Update__index","45775":"p__Engineering__Lists__Document__index","45825":"p__Classrooms__Lists__Exercise__index","45992":"p__Classrooms__Lists__Exercise__ReviewGroup__index","46796":"p__virtualSpaces__Lists__Announcement__Detail__index","46963":"p__Classrooms__Lists__Engineering__Detail__index","47545":"p__Graduations__Lists__Archives__index","48077":"p__Classrooms__Lists__Students__index","48431":"p__Classrooms__Lists__Exercise__Export__index","48689":"p__Classrooms__Lists__Statistics__VideoStatistics__index","49205":"p__Shixuns__Edit__body__Level__Challenges__EditPracticeSetting__index","49366":"p__User__Login__index","49716":"p__Question__OjProblem__RecordDetail__index","49890":"p__Classrooms__Lists__CommonHomework__index","50869":"p__Guidance__index","51276":"p__MoopCases__Success__index","51461":"p__Graduations__Lists__Topics__index","51582":"p__Classrooms__Lists__GroupHomework__Add__index","51855":"p__MoopCases__InfoPanel__index","52338":"p__Classrooms__Lists__CommonHomework__Review__index","52404":"p__Classrooms__Lists__Template__teacher__index","52806":"p__User__Detail__Topics__Exercise__Detail__index","52829":"p__Messages__Private__index","52875":"p__Shixuns__Detail__id","53247":"p__Paperlibrary__See__index","53910":"p__HttpStatus__introduction","54056":"p__IntrainCourse__index","54164":"p__Classrooms__Lists__Exercise__Detail__index","54492":"p__Graduations__Lists__StudentSelection__index","54572":"p__Classrooms__Lists__ExportList__index","54770":"p__Classrooms__Lists__ProgramHomework__Detail__answer__index","54862":"p__Paperlibrary__index","55573":"p__Shixuns__Detail__Merge__index","55624":"p__Graduations__Lists__Index__index","56277":"p__Shixuns__Edit__index","57045":"p__Classrooms__Lists__CommonHomework__SubmitWork__index","57560":"p__Administration__College__index","57614":"p__Shixuns__Edit__body__Level__Challenges__RankingSetting__index","59133":"p__Shixuns__Detail__Challenges__index","59649":"p__Engineering__Lists__TrainingProgram__index","59788":"p__Account__Profile__index","60479":"p__Classrooms__Lists__GroupHomework__EditWork__index","60533":"p__Classrooms__Lists__Video__Statistics__Detail__index","60547":"p__Account__index","61043":"p__Classrooms__Lists__Graduation__Tasks__index","61713":"p__virtualSpaces__Lists__Settings__index","61727":"p__Classrooms__Lists__CourseGroup__NotList__index","61880":"p__User__Detail__Order__pages__apply__index","62300":"p__Api__index","62548":"p__Engineering__Norm__Detail__index","63157":"p__User__Detail__ExperImentImg__Add__index","64017":"p__Classrooms__Lists__PlaceholderPage__index","64144":"p__Problemset__Preview__New__index","64217":"p__Classrooms__Lists__Video__Statistics__index","64496":"p__HttpStatus__HpcCourse","64520":"p__Account__Secure__index","65111":"p__Terminal__index","65148":"p__Classrooms__Lists__Polls__Answer__index","65191":"p__User__Detail__Certificate__index","65549":"p__Shixuns__New__CreateImg__index","65816":"p__virtualSpaces__Lists__Announcement__index","66034":"p__HttpStatus__UserAgents","66063":"p__Graduations__Lists__Personmanage__index","66531":"p__HttpStatus__404","66583":"p__User__Detail__Classrooms__index","66651":"p__Engineering__Evaluate__Detail__index","67242":"p__Innovation__MyProject__index","67878":"p__Classrooms__Lists__LiveVideo__index","68014":"p__Classrooms__Lists__Teachers__index","68665":"p__Engineering__Lists__TrainingObjectives__index","68827":"p__Classrooms__Lists__OnlineLearning__index","68882":"p__Classrooms__Lists__Graduation__Tasks__Detail__index","69922":"p__Classrooms__Lists__Statistics__StudentVideo__index","69944":"p__Classrooms__Lists__Video__Statistics__StudentDetail__index","70928":"p__RestFul__Edit__index","71450":"p__Classrooms__Lists__ShixunHomeworks__Commitsummary__index","71783":"p__virtualSpaces__Lists__Experiment__index","72529":"p__User__Detail__id","72539":"p__Graduations__Review__index","72570":"p__Competitions__Detail__index","73183":"p__Engineering__Lists__GraduationIndex__index","73220":"p__Classrooms__Lists__Video__Upload__index","74264":"p__Forums__New__index","74795":"p__Classrooms__Lists__Graduation__Tasks__Add__index","75043":"p__User__Detail__Topics__Poll__Edit__index","75357":"p__Engineering__Lists__TrainingProgram__Edit__index","75786":"layouts__LoginAndRegister__index","75816":"p__Paperlibrary__Random__Edit__index","76904":"p__MoopCases__FormPanel__index","77460":"p__Question__OjProblem__index","77857":"p__Shixuns__Edit__body__Level__Challenges__NewQuestion__index","78085":"p__Classrooms__Lists__Exercise__Review__index","79489":"p__Engineering__Lists__CourseList__index","79590":"p__User__Detail__TeachGroup__index","79921":"p__Classrooms__ExamList__index","80508":"p__Forums__Detail__id","81148":"p__Shixuns__Detail__Repository__UploadFile__index","81799":"p__Competitions__Entered__Assembly__TeamDateil","82339":"p__virtualSpaces__Lists__Plan__Detail__index","82425":"p__Classrooms__Lists__Board__Detail__index","82443":"p__Graduations__Lists__StageModule__index","83141":"p__Innovation__Detail__index","83212":"p__MoopCases__index","83935":"p__Classrooms__Lists__GroupHomework__index","84546":"p__Engineering__Lists__TrainingProgram__Add__index","85048":"p__Classrooms__Lists__Graduation__Topics__index","85111":"p__User__Detail__Order__pages__orderInformation__index","85297":"p__Classrooms__Lists__Exercise__Detail__components__DuplicateChecking__CheckDetail__index","85888":"p__Classrooms__Lists__CommonHomework__Add__index","85891":"p__virtualSpaces__Lists__Resources__index","86052":"p__Paths__Index__index","86452":"p__Innovation__PublicDataSet__index","86541":"p__Shixuns__Detail__Dataset__index","86634":"p__Innovation__Tasks__index","86820":"p__User__Detail__Topics__Normal__index","86913":"p__Question__AddOrEdit__index","87058":"p__virtualSpaces__Lists__Survey__Detail__index","87260":"p__Account__Certification__index","87922":"p__Classrooms__Lists__CourseGroup__Detail__index","88155":"p__Shixuns__Overview__index","88517":"p__User__Detail__Topics__Group__index","88866":"p__index","89076":"p__Account__Binding__index","89677":"p__virtualSpaces__Lists__Announcement__AddAndEdit__index","89785":"p__Classrooms__Lists__Template__student__index","90109":"p__Classrooms__Lists__ShixunHomeworks__Detail__components__CodeReview__Detail__index","90265":"p__User__Detail__Topics__index","90337":"p__Paperlibrary__Random__PreviewEdit__index","91045":"p__virtualSpaces__Lists__Knowledge__AddAndEdit__index","91470":"p__User__Register__index","91831":"p__Graduations__Index__index","92045":"p__Engineering__Lists__TeacherList__index","92501":"p__Search__index","92603":"p__Classrooms__Lists__ProgramHomework__Detail__answer__Add__index","92823":"p__Engineering__Navigation__Home__index","92983":"p__Forums__Index__index","93260":"p__Paperlibrary__Add__index","93282":"layouts__ShixunDetail__index","93496":"p__User__Detail__OtherResources__index","93665":"p__tasks__index","93668":"p__Classrooms__Lists__CommonHomework__Detail__index","94078":"p__Messages__Tidings__index","94498":"p__Shixuns__Edit__body__Level__Challenges__NewPractice__index","94662":"p__User__Detail__Paths__index","94715":"p__virtualSpaces__Lists__Material__Detail__index","94849":"p__User__Detail__ExperImentImg__index","95125":"p__Classrooms__Lists__Exercise__DetailedAnalysis__index","95176":"p__User__Detail__Videos__Protocol__index","95335":"p__Engineering__Lists__CourseMatrix__index","96444":"p__Video__Detail__id","96882":"p__Classrooms__New__StartClass__index","97008":"p__Shixuns__New__index","97046":"p__Shixuns__Detail__Repository__AddFile__index","98062":"p__User__Detail__Topicbank__index","98398":"p__virtualSpaces__Lists__Resources__Detail__index","98688":"p__Shixuns__Detail__Repository__index","98885":"p__Classrooms__Lists__Statistics__StudentStatistics__index","99674":"p__Shixuns__New__ImagePreview__index"}[chunkId] || chunkId) + "." + {"92":"fba1ec42","127":"01b0e779","271":"0382915d","292":"2d97116f","310":"2b3692a8","556":"b5dc7627","1482":"711d2152","1653":"f778458b","1660":"13e763e4","1686":"df99c1fa","1702":"8e1ba196","2249":"90399667","2360":"2f3cadfa","2494":"5e069ec9","2595":"3c9ff6f5","2659":"694613c9","2805":"d6f0ae11","2819":"c2f7511d","2837":"b3a05bc1","3133":"6a9f7113","3317":"a8a2288f","3391":"e4cb0657","3451":"adbc2344","3471":"f3963651","3509":"3190935e","3585":"07020bd0","3885":"e66b03f8","3951":"7f31648a","4685":"21279a05","4736":"d2bf9775","4766":"b807262b","4884":"56a464cc","4973":"0ea90133","5112":"c1217071","5434":"361b868d","5572":"74405533","6127":"1f74646f","6216":"e580c712","6305":"fa1934c4","6378":"27c8142f","6685":"868ec2d7","6758":"91193e92","6788":"b0048471","7043":"4805e542","7105":"83cfe42f","7356":"ff86e2ec","7852":"8a580825","7884":"96dccf69","8254":"02e1492b","8787":"682ed6ee","8999":"d7621b81","9042":"9ded77c2","9416":"2251081f","9485":"901f1fc5","9894":"f87c0ebb","9928":"5856e32a","9951":"295caf46","10195":"ba9090a4","10354":"5c063e6f","10375":"41e2eeb8","10485":"70485d0f","10635":"3efedcfa","10737":"fbbf4e72","10799":"91888727","10921":"d24dbf15","11070":"5f65f973","11253":"4a7033bb","11512":"feea018e","11520":"cdb956ef","11545":"dd5a721e","11561":"381d63a4","11581":"57c70a9f","11752":"9ed6c1fb","11833":"3e529ada","12076":"ef5927f1","12102":"bc50bd68","12303":"625f0fa2","12312":"6ebc949e","12386":"289c62c7","12412":"fbf9ba6e","12476":"ce382ef2","12865":"386d0cc0","12884":"f9e1cf5a","12911":"f94aa754","13006":"3a6bcfb0","13007":"2e9a9b22","13355":"ee6ebc58","13488":"ae031fd2","13581":"631fc79e","14000":"63f19e1a","14047":"4d6e5ffd","14058":"fad07263","14088":"c639825c","14105":"444f506a","14227":"c500e935","14333":"9e585c8f","14514":"de04ad78","14599":"f24fc396","14610":"6073b0a2","14642":"d8d9787e","14662":"5aef6830","14889":"309a4281","14993":"2d4d9856","15148":"fdb3720c","15186":"c162e773","15192":"1732d5a3","15250":"83dc2796","15290":"7b3f25d8","15319":"c6325383","15402":"b9156348","15569":"113c5038","15631":"d790a1bf","15845":"c8fe49ef","16328":"30b72346","16434":"20768b2f","16703":"f6abb1ba","16717":"9a38b45f","16729":"ab2132e1","16834":"817e62e4","16845":"9045ce5c","17142":"871bf314","17482":"b570ebd2","17527":"c5e9f883","17622":"9e5f637c","17806":"d2e3091a","18080":"6bcb1e13","18241":"88ffeaec","18302":"e3455b91","18307":"98cd8604","18350":"0ed0f7c3","18898":"25ad586a","18963":"33e3df18","19208":"85e01132","19215":"f83ac751","19360":"b1a651e5","19403":"3ab72a54","19519":"9ee4350a","19715":"1a494c1e","19842":"9eda460f","19891":"9cca4e6d","20026":"511bd98c","20062":"704c7129","20459":"c87122fd","20576":"c90e7824","20680":"a5a0ab60","20700":"c7ff0e17","20798":"d52f5213","20834":"26522551","21105":"7c0014aa","21265":"e4cc4af8","21423":"6c32cfc3","21560":"638caddd","21578":"744a5cfe","21939":"3c396a26","22254":"763a2dde","22307":"3afdc39f","22707":"c27a1cf9","23332":"1edc7e3c","23760":"f0904fce","24504":"e3601d8f","24628":"b863dad4","24665":"cea8e4ab","24797":"eb563316","25022":"d716ddc2","25105":"c2000cc7","25470":"79c0c778","25473":"8713b979","25490":"1a22a456","25576":"6afe7528","25705":"5ca9768e","25972":"eb375435","26126":"400f4fd5","26289":"8b16f4a4","26366":"014b0d8e","26588":"9c91bf02","26685":"3162df70","26741":"d3f81881","26883":"ca3f08b9","27178":"69a6a161","27182":"0cd11b7d","27315":"e89b908d","27333":"5c552215","27395":"31e7656a","27706":"c0d5e1ef","27739":"3bb25e43","27809":"3a2f492a","27829":"17300772","28009":"e42ab4ab","28072":"923996b4","28089":"aaa88c03","28161":"00a22aad","28163":"0081a56b","28237":"55256130","28435":"23d6a030","28561":"ec76d55e","28639":"2afb0fe5","28723":"e27ec039","28782":"1b125ca0","28920":"842a9870","28982":"cb00fe75","29190":"2e5cd7df","29414":"026ca7c3","29525":"e4f7063f","29535":"da216de7","29559":"cdc05f60","29647":"bc3193af","29895":"1fa85db5","29968":"5c930f27","30067":"0bea709f","30264":"172872b6","30335":"935fd8ca","30342":"1dcbb3d7","30441":"f8fc31e1","30741":"0afd7032","31006":"b1c43e5f","31087":"8aba01dd","31154":"abb4690e","31211":"f87b6d0f","31246":"ec10a487","31427":"8524b261","31674":"b1536dd2","31962":"7b54b573","32528":"96344ced","33056":"564080f7","33356":"2b31f149","33461":"d0c0c21b","33611":"c8d0abd6","33747":"92cc7764","33784":"b2904a2d","33805":"a93fd24f","34093":"665df972","34333":"513d6fbe","34495":"5be08a04","34601":"f4fd40cb","34668":"b7cfef49","34741":"d9388c2f","34790":"6eb90335","34800":"f1a5e866","34850":"daf624f2","34994":"bc821174","35060":"7530a2b3","35238":"f716152b","35354":"c0640e01","35416":"b4018e87","35729":"c514a24f","36029":"8d977ff9","36187":"d9cce9bb","36270":"006dfc85","36634":"03daa006","36784":"5f1bbaac","37062":"25c7d9be","37825":"5ef8076b","37885":"54433a82","37948":"942b4168","38143":"0a21df19","38177":"3dd2875c","38447":"2452b152","38634":"94ac1d57","38773":"b004873e","38797":"e8bd5cad","39252":"01ffe0b6","39299":"da682f81","39332":"6d1d5536","39391":"7e4bd5b8","39404":"22b5c59a","39695":"23adab3c","39787":"2d6930a2","39790":"f0e8ec83","39950":"57e939c0","40559":"d0441361","40847":"b71f3f54","41001":"da53c620","41048":"ef8d71fe","41657":"9a0711de","41717":"fa36080b","41811":"f1228622","41867":"53a6b604","41885":"5cf119f9","41921":"3d0081d2","41953":"fae4a1eb","42240":"c38013a4","42441":"9616313f","42917":"43e3ea7e","43110":"6abf25af","43428":"603ed3fd","43442":"8e8c6f69","43862":"1b7b3ff8","44147":"66791dd7","44216":"7d587b93","44259":"e0f8d927","44354":"4d10aca1","44360":"2fe17938","44425":"e6f53013","44449":"7632b1a0","44565":"ac4e1131","44613":"9bd3f6b0","45096":"2c158a99","45179":"e3abdd6b","45359":"78b949ac","45413":"ae45b3f8","45504":"7f6c0d59","45519":"a8174812","45582":"a829d032","45650":"61b83229","45775":"9b841426","45825":"103780cc","45909":"6a6c1f27","45992":"29806d58","46177":"0cb7db14","46372":"b81f2ce1","46573":"db7fbeee","46796":"688c18ae","46963":"8c8b0160","47256":"b1cde63d","47545":"3097a74d","47686":"f38a5fc1","47962":"9ee995b4","48077":"0423702a","48431":"6ef20ec6","48560":"54c406b5","48573":"3d9e4c7c","48689":"aca765d6","48691":"5775abd3","48776":"3ca5830e","48826":"17ad40dc","48913":"c45d4a20","49127":"f74d686d","49166":"20802f83","49205":"bc50bea1","49260":"d82ab47f","49366":"ee413809","49716":"e0656535","49890":"c4af4c2b","49906":"e25401e9","50251":"10ae186b","50812":"5d8b4e73","50869":"01508392","51144":"88d767c5","51276":"f9412058","51461":"37358c55","51582":"3bde123f","51646":"a1e61a3a","51855":"c53a1f8f","52312":"29d0251e","52338":"2039b97f","52404":"8b959a27","52409":"4a79ab63","52720":"a99b0bb3","52806":"1d28f1fa","52829":"3329615d","52875":"e05171ae","52987":"d784c083","53114":"685610c8","53247":"a1ae0a4a","53359":"e50240bc","53550":"d1343c48","53555":"40da94e6","53697":"344fc05c","53777":"630cd89c","53877":"c56d519b","53910":"b29f1429","53936":"0a44ec6e","54056":"3d06af4d","54164":"eff1dc90","54393":"5c9f6f6c","54492":"1855c61b","54513":"f74dc486","54572":"18b6d1d7","54747":"e95d0294","54770":"3ac6c352","54862":"47e9c8bb","55127":"79f60e9a","55351":"b1b9a06c","55573":"9b121369","55624":"4b8a4858","55693":"4b714ff1","55950":"ca799b07","56021":"119eec61","56047":"b4b0d1c6","56156":"c61ad60b","56277":"6708e736","57045":"6df2b297","57365":"7e7804c5","57395":"1a8bd603","57560":"a014011c","57614":"ae1a8e98","57814":"fcc0b9c5","57889":"d093c543","58203":"045ac759","58271":"04f27f83","59133":"bf632bea","59649":"ea3d2935","59788":"00186671","59981":"8de9b01a","60479":"d5ab0727","60533":"4f3e3f86","60547":"c194da92","60590":"73a88b51","61043":"e4683c65","61713":"793864bf","61727":"9e46fc78","61761":"aae6d026","61880":"8d2ed650","61895":"534d8055","61952":"57a3c83e","62300":"082c4fab","62438":"40550107","62548":"e9b57ca3","62687":"8f8afe49","62778":"24586e4d","62945":"927b34c0","62979":"95ee6c8c","63157":"5a0d6fcc","63198":"f92793e1","63724":"0beb7987","63791":"18e115ca","64017":"0a564de0","64144":"11d544fe","64217":"328904a4","64447":"0244198b","64496":"161e856a","64520":"9ec0910e","64802":"1090d644","65111":"829d60e7","65148":"8cb95cf6","65191":"a3f6b239","65549":"5137a2cb","65816":"499002ca","65876":"a2754c64","66034":"04bc580a","66063":"edbe39df","66174":"53889c84","66302":"5397bd98","66381":"2783fbb7","66531":"5d0eb70a","66583":"a30fe47f","66651":"411c3d8f","67156":"918b4bca","67242":"aad92ca5","67468":"e4e958f2","67878":"c0c68428","68014":"fd74b4bb","68665":"79393a8a","68685":"2707d0be","68761":"fd19b2db","68827":"3db20491","68842":"19057860","68882":"8061833b","69242":"bff4b036","69922":"dafbcb04","69944":"e9153c8f","70130":"de78f0fd","70544":"05116266","70671":"749b4875","70928":"0fd06df7","70981":"157d0b6b","71126":"cd42e3cf","71448":"719d9d6e","71450":"23b3a8ab","71783":"cca11a1e","72011":"7efe6dda","72032":"d87e2e7b","72274":"4446bc88","72315":"d8d70ba7","72529":"4220d582","72539":"f0dd3506","72570":"0c217862","72605":"abd4c915","72773":"72493b4c","72969":"53256e8c","73168":"6c64659d","73183":"a656eb16","73220":"40bf0dde","73755":"7bd6b4f7","74014":"5339ac81","74264":"592b7741","74347":"a722ba6c","74675":"9e3112e8","74795":"8f033c4a","74997":"50a24f6b","75043":"8cb63c5b","75149":"2a800bb8","75321":"9b9a5dc1","75357":"6d5db9e9","75786":"db8f262f","75816":"7d72d6c5","75956":"d227f395","76904":"c8374112","76938":"a2709ddd","77084":"5fe882f0","77298":"4974ba9f","77350":"4a433c33","77437":"965aadda","77460":"c08c00e3","77772":"4f39a385","77857":"9f802652","77918":"bb41c9de","78085":"ef810c11","78241":"f698b2a3","78302":"2f657c59","78737":"fa31da0e","78782":"f9e80406","78859":"958de94c","78892":"ad739ccc","79439":"ec9ac461","79489":"cc71c18f","79590":"cd9f5dc8","79594":"e7b6ac37","79817":"69f42c89","79838":"c18a3f23","79921":"29dcac03","80399":"a890a6a9","80508":"15de3f87","80629":"ca49ee59","81057":"32ad27c1","81148":"664dc7f9","81326":"19829c36","81799":"bf73fa92","82080":"10f5c31e","82274":"f9b9c5c0","82339":"a7b0c187","82425":"20f23cf7","82443":"215042da","82890":"1b3ff4d6","83141":"81f04225","83212":"6092982a","83306":"917d504a","83935":"4429ad1f","83980":"05917be1","84546":"3f0a3b1d","84742":"6b5fed0b","85048":"d2fdedef","85081":"a73db95f","85111":"ffdb7e65","85297":"b9ce2001","85494":"da5840b1","85731":"49f28568","85764":"5c1c73b5","85794":"713c9192","85888":"0599e9f4","85891":"30bc0c2f","86045":"0a358cbb","86052":"d828e88f","86129":"801a9880","86452":"0bd1db6d","86541":"83216e40","86562":"4691cd5c","86634":"2aaf84e9","86774":"2db1d78d","86820":"55a5dabd","86913":"b0a045bc","86928":"8476f27f","87058":"b280c002","87260":"1195c883","87377":"70c5c54f","87557":"99277364","87922":"31f64ec6","87964":"83911fb5","88100":"0bd2630c","88155":"9f915cbd","88517":"1e95f5e7","88652":"b79a083e","88699":"0e126269","88816":"b48e55d9","88866":"7ccfc406","89076":"5703f861","89360":"0c517cb7","89554":"3bd5f2ea","89597":"d1f2e594","89677":"fb15b8c6","89718":"c59ee184","89785":"f5dba329","90109":"107b6bbd","90265":"200b695e","90316":"c34a4fc4","90337":"6524bae4","91045":"a0ea1447","91274":"c142e23b","91375":"1d992b74","91462":"2cbc46cd","91470":"b8ee8755","91831":"8a7e2842","91834":"3905c46e","91857":"e34c7f99","92045":"afb668e4","92501":"1051e43b","92538":"a4db897b","92594":"0f02017f","92603":"7b1fffc0","92823":"eddfc70c","92983":"234bbb25","93260":"c0261dcd","93282":"52b61176","93496":"7bbc7570","93665":"e9d5ab5a","93668":"0aa1fd27","93948":"61d5b51a","94078":"1637d24d","94333":"3ec8aa1d","94439":"c3f3a54b","94498":"0cea6990","94662":"21ac244e","94715":"9103b8f4","94849":"8e3ff5e8","95125":"7711645f","95176":"07eeb5d7","95335":"d07e7932","95383":"f753ea65","95679":"33378d80","96232":"d49022e5","96444":"7406629c","96882":"763ad5aa","97008":"57ab8e72","97041":"9e9d8791","97046":"54a4bbdd","97120":"0eb88e7b","97591":"4868bb6b","97986":"e759afe2","98062":"2fdc4522","98228":"9183e003","98398":"a4373c63","98688":"7b46c48a","98885":"a2947fec","99104":"d4f63539","99313":"89e6d4a3","99674":"67f5c5de","99939":"68b2d9a0"}[chunkId] + ".async.js"; /******/ }; /******/ }(); /******/ @@ -201235,7 +203901,7 @@ function debounce (delay, callback, options) { /******/ // This function allow to reference async chunks /******/ __webpack_require__.miniCssF = function(chunkId) { /******/ // return url for filenames based on template -/******/ return "" + ({"292":"p__Classrooms__Lists__Exercise__Add__index","310":"p__User__Detail__ExperImentImg__Detail__index","556":"p__User__Detail__Order__pages__invoice__index","1482":"p__Classrooms__Lists__Graduation__Topics__Edit__index","1702":"p__Classrooms__New__index","2659":"p__User__Detail__UserPortrait__index","2819":"p__Classrooms__Lists__Template__detail__index","3317":"p__Classrooms__Lists__Graduation__Topics__Add__index","3391":"p__Classrooms__Lists__ProgramHomework__Detail__components__CodeReview__Detail__index","3451":"p__Classrooms__Lists__Statistics__StudentStatistics__Detail__index","3509":"p__HttpStatus__SixActivities","3585":"p__Classrooms__Lists__Statistics__StudentSituation__index","3951":"p__Classrooms__Lists__ProgramHomework__Detail__index","4736":"p__User__Detail__Projects__index","4766":"p__Administration__index","4884":"p__Shixuns__Detail__Repository__Commit__index","4973":"p__Engineering__Evaluate__List__index","5572":"p__Paths__HigherVocationalEducation__index","6127":"p__Classrooms__Lists__ProgramHomework__Ranking__index","6685":"p__Shixuns__Detail__RankingList__index","6758":"p__Classrooms__Lists__Attachment__index","6788":"p__Classrooms__Lists__ProgramHomework__index","7043":"p__User__Detail__Topics__Exercise__Edit__index","7852":"p__Classrooms__Lists__ShixunHomeworks__index","7884":"p__Shixuns__Exports__index","8787":"p__Competitions__Entered__index","8999":"p__Three__index","9416":"p__Graduations__Lists__Tasks__index","10195":"p__Classrooms__Lists__GroupHomework__Detail__index","10485":"p__Question__AddOrEdit__BatchAdd__index","10737":"p__Classrooms__Lists__CommonHomework__Detail__components__CodeReview__Detail__index","10799":"p__User__Detail__Topics__Poll__Detail__index","10921":"p__Classrooms__Lists__Exercise__CodeDetails__index","11070":"p__Innovation__PublicMirror__index","11253":"p__Graduations__Lists__Gradingsummary__index","11512":"p__Classrooms__Lists__Exercise__AnswerCheck__index","11520":"p__Engineering__Lists__StudentList__index","11545":"p__Paperlibrary__Random__ExchangeFromProblemSet__index","11581":"p__Problemset__Preview__index","12076":"p__User__Detail__Competitions__index","12102":"p__Classrooms__Lists__Board__Edit__index","12303":"p__Classrooms__Lists__CommonHomework__Comment__index","12412":"p__User__Detail__Videos__index","12476":"p__Colleges__index","12865":"p__Innovation__MyMirror__index","12884":"p__Classrooms__Lists__ProgramHomework__Comment__index","13006":"p__Engineering__index","13355":"p__Classrooms__Lists__Polls__index","13581":"p__Classrooms__Lists__ShixunHomeworks__Detail__index","14058":"p__Demo__index","14105":"p__Classrooms__Lists__Exercise__Answer__index","14227":"p__Paths__Overview__index","14514":"p__Account__Results__index","14599":"p__Problemset__index","14610":"p__User__Detail__LearningPath__index","14662":"p__Classrooms__Lists__GroupHomework__Review__index","14889":"p__Classrooms__Lists__Exercise__ImitateAnswer__index","15148":"p__Classrooms__Lists__Template__index","15186":"p__Classrooms__Overview__index","15319":"p__Classrooms__Lists__ProgramHomework__Detail__answer__Detail__index","15402":"p__User__Detail__Topics__Detail__index","16328":"p__Shixuns__Edit__body__Warehouse__index","16434":"p__User__Detail__Order__pages__records__index","16729":"p__Classrooms__Lists__GroupHomework__Edit__index","16845":"p__Shixuns__Detail__Settings__index","17482":"p__Classrooms__Lists__Exercise__Notice__index","17527":"p__MyProblem__RecordDetail__index","17622":"p__Classrooms__Lists__Polls__Detail__index","17806":"p__Classrooms__Lists__Statistics__StatisticsQuality__index","18241":"p__virtualSpaces__Lists__Plan__index","18302":"p__Classrooms__Lists__Board__index","18307":"p__User__Detail__Shixuns__index","19215":"p__Shixuns__Detail__ForkList__index","19360":"p__User__Detail__virtualSpaces__index","19519":"p__User__Detail__ClassManagement__Item__index","19715":"p__Classrooms__Lists__CommonHomework__Edit__index","19891":"p__User__Detail__Videos__Success__index","20026":"p__Classrooms__Lists__Graduation__Tasks__Edit__index","20576":"p__Account__Profile__Edit__index","20680":"p__Innovation__index","20700":"p__tasks__Jupyter__index","21265":"p__Classrooms__Lists__Announcement__index","21423":"p__Shixuns__Edit__body__Level__Challenges__EditPracticeAnswer__index","21578":"p__Classrooms__Lists__Graduation__Topics__Detail__index","21939":"p__User__Detail__Order__index","22254":"p__Shixuns__Detail__Discuss__index","22307":"p__Report__index","22707":"p__Innovation__MyDataSet__index","23332":"p__Paths__Detail__id","24504":"p__virtualSpaces__Lists__Survey__index","25022":"p__Graduations__Lists__Settings__index","25470":"p__Shixuns__Detail__Collaborators__index","25705":"p__virtualSpaces__Lists__Construction__index","25972":"layouts__user__index","26366":"p__Innovation__PublicProject__index","26685":"p__Classrooms__Index__index","26741":"p__Engineering__Norm__List__index","26883":"p__Competitions__Index__index","27178":"p__User__BindAccount__index","27182":"p__User__ResetPassword__index","27395":"p__Classrooms__Lists__Statistics__StudentDetail__index","28072":"p__Classrooms__Lists__GroupHomework__SubmitWork__index","28237":"p__User__Detail__Order__pages__view__index","28435":"p__Classrooms__Lists__Attendance__index","28723":"p__Classrooms__Lists__Polls__Edit__index","28782":"p__Shixuns__Index__index","28982":"p__Paths__New__index","29647":"p__Question__Index__index","30067":"p__Message__index","30264":"p__User__Detail__Order__pages__orderPay__index","30342":"p__Classrooms__Lists__ShixunHomeworks__Comment__index","31006":"p__RestFul__index","31211":"p__Classrooms__Lists__CommonHomework__EditWork__index","31427":"p__Classrooms__Lists__Statistics__index","31674":"p__Classrooms__ClassicCases__index","31962":"p__Classrooms__Lists__Engineering__index","33356":"p__Classrooms__Lists__Assistant__index","33747":"p__virtualSpaces__Lists__Homepage__index","33784":"p__Paperlibrary__Random__Detail__index","34093":"p__Classrooms__Lists__Attendance__Detail__index","34601":"p__Paths__Detail__Statistics__index","34741":"p__Problems__OjForm__NewEdit__index","34800":"p__Engineering__Lists__GraduatedMatrix__index","34994":"p__Problems__OjForm__index","35238":"p__virtualSpaces__Lists__Material__index","35729":"p__Help__Index","36029":"p__Administration__Student__index","36270":"p__MyProblem__index","36784":"p__Innovation__Edit__index","37062":"layouts__SimpleLayouts","37948":"p__User__Detail__ClassManagement__index","38143":"layouts__GraduationsDetail__index","38447":"p__virtualSpaces__Lists__Knowledge__index","38634":"p__Classrooms__Lists__CourseGroup__List__index","38797":"p__Competitions__Edit__index","39332":"p__Classrooms__Lists__Video__index","39391":"p__Engineering__Lists__CurseSetting__index","39404":"monaco-editor","39695":"p__Classrooms__Lists__Polls__Add__index","40559":"layouts__virtualDetail__index","41048":"p__Classrooms__Lists__ProgramHomework__Detail__Ranking__index","41657":"p__Shixuns__Edit__body__Level__Challenges__EditQuestion__index","41717":"layouts__index","41953":"p__Problemset__NewItem__index","42240":"p__User__Detail__Videos__Upload__index","43442":"p__Classrooms__Lists__Board__Add__index","44259":"p__User__Detail__Order__pages__result__index","44449":"p__Competitions__Exports__index","45096":"p__Shixuns__Detail__AuditSituation__index","45179":"p__Administration__Student__Edit__index","45359":"p__Messages__Detail__index","45650":"p__Competitions__Update__index","45775":"p__Engineering__Lists__Document__index","45825":"p__Classrooms__Lists__Exercise__index","45992":"p__Classrooms__Lists__Exercise__ReviewGroup__index","46796":"p__virtualSpaces__Lists__Announcement__Detail__index","46963":"p__Classrooms__Lists__Engineering__Detail__index","47545":"p__Graduations__Lists__Archives__index","48077":"p__Classrooms__Lists__Students__index","48431":"p__Classrooms__Lists__Exercise__Export__index","48689":"p__Classrooms__Lists__Statistics__VideoStatistics__index","49205":"p__Shixuns__Edit__body__Level__Challenges__EditPracticeSetting__index","49366":"p__User__Login__index","49716":"p__Question__OjProblem__RecordDetail__index","49890":"p__Classrooms__Lists__CommonHomework__index","50869":"p__Guidance__index","51276":"p__MoopCases__Success__index","51461":"p__Graduations__Lists__Topics__index","51582":"p__Classrooms__Lists__GroupHomework__Add__index","51855":"p__MoopCases__InfoPanel__index","52338":"p__Classrooms__Lists__CommonHomework__Review__index","52404":"p__Classrooms__Lists__Template__teacher__index","52806":"p__User__Detail__Topics__Exercise__Detail__index","52829":"p__Messages__Private__index","52875":"p__Shixuns__Detail__id","53247":"p__Paperlibrary__See__index","53910":"p__HttpStatus__introduction","54056":"p__IntrainCourse__index","54164":"p__Classrooms__Lists__Exercise__Detail__index","54492":"p__Graduations__Lists__StudentSelection__index","54572":"p__Classrooms__Lists__ExportList__index","54770":"p__Classrooms__Lists__ProgramHomework__Detail__answer__index","54862":"p__Paperlibrary__index","55573":"p__Shixuns__Detail__Merge__index","55624":"p__Graduations__Lists__Index__index","56277":"p__Shixuns__Edit__index","57045":"p__Classrooms__Lists__CommonHomework__SubmitWork__index","57560":"p__Administration__College__index","57614":"p__Shixuns__Edit__body__Level__Challenges__RankingSetting__index","59133":"p__Shixuns__Detail__Challenges__index","59649":"p__Engineering__Lists__TrainingProgram__index","59788":"p__Account__Profile__index","60479":"p__Classrooms__Lists__GroupHomework__EditWork__index","60533":"p__Classrooms__Lists__Video__Statistics__Detail__index","60547":"p__Account__index","61043":"p__Classrooms__Lists__Graduation__Tasks__index","61713":"p__virtualSpaces__Lists__Settings__index","61727":"p__Classrooms__Lists__CourseGroup__NotList__index","61880":"p__User__Detail__Order__pages__apply__index","62548":"p__Engineering__Norm__Detail__index","63157":"p__User__Detail__ExperImentImg__Add__index","64144":"p__Problemset__Preview__New__index","64217":"p__Classrooms__Lists__Video__Statistics__index","64496":"p__HttpStatus__HpcCourse","64520":"p__Account__Secure__index","65111":"p__Terminal__index","65148":"p__Classrooms__Lists__Polls__Answer__index","65191":"p__User__Detail__Certificate__index","65549":"p__Shixuns__New__CreateImg__index","65816":"p__virtualSpaces__Lists__Announcement__index","66063":"p__Graduations__Lists__Personmanage__index","66583":"p__User__Detail__Classrooms__index","66651":"p__Engineering__Evaluate__Detail__index","67242":"p__Innovation__MyProject__index","67878":"p__Classrooms__Lists__LiveVideo__index","68014":"p__Classrooms__Lists__Teachers__index","68665":"p__Engineering__Lists__TrainingObjectives__index","68827":"p__Classrooms__Lists__OnlineLearning__index","68882":"p__Classrooms__Lists__Graduation__Tasks__Detail__index","69922":"p__Classrooms__Lists__Statistics__StudentVideo__index","69944":"p__Classrooms__Lists__Video__Statistics__StudentDetail__index","71450":"p__Classrooms__Lists__ShixunHomeworks__Commitsummary__index","71783":"p__virtualSpaces__Lists__Experiment__index","72529":"p__User__Detail__id","72539":"p__Graduations__Review__index","72570":"p__Competitions__Detail__index","73183":"p__Engineering__Lists__GraduationIndex__index","73220":"p__Classrooms__Lists__Video__Upload__index","74264":"p__Forums__New__index","74795":"p__Classrooms__Lists__Graduation__Tasks__Add__index","75043":"p__User__Detail__Topics__Poll__Edit__index","75357":"p__Engineering__Lists__TrainingProgram__Edit__index","75786":"layouts__LoginAndRegister__index","75816":"p__Paperlibrary__Random__Edit__index","76904":"p__MoopCases__FormPanel__index","77460":"p__Question__OjProblem__index","77857":"p__Shixuns__Edit__body__Level__Challenges__NewQuestion__index","78085":"p__Classrooms__Lists__Exercise__Review__index","79489":"p__Engineering__Lists__CourseList__index","79590":"p__User__Detail__TeachGroup__index","79921":"p__Classrooms__ExamList__index","80508":"p__Forums__Detail__id","81148":"p__Shixuns__Detail__Repository__UploadFile__index","82339":"p__virtualSpaces__Lists__Plan__Detail__index","82425":"p__Classrooms__Lists__Board__Detail__index","82443":"p__Graduations__Lists__StageModule__index","83141":"p__Innovation__Detail__index","83212":"p__MoopCases__index","83935":"p__Classrooms__Lists__GroupHomework__index","84546":"p__Engineering__Lists__TrainingProgram__Add__index","85048":"p__Classrooms__Lists__Graduation__Topics__index","85111":"p__User__Detail__Order__pages__orderInformation__index","85297":"p__Classrooms__Lists__Exercise__Detail__components__DuplicateChecking__CheckDetail__index","85888":"p__Classrooms__Lists__CommonHomework__Add__index","85891":"p__virtualSpaces__Lists__Resources__index","86052":"p__Paths__Index__index","86452":"p__Innovation__PublicDataSet__index","86541":"p__Shixuns__Detail__Dataset__index","86634":"p__Innovation__Tasks__index","86820":"p__User__Detail__Topics__Normal__index","86913":"p__Question__AddOrEdit__index","87058":"p__virtualSpaces__Lists__Survey__Detail__index","87260":"p__Account__Certification__index","87922":"p__Classrooms__Lists__CourseGroup__Detail__index","88155":"p__Shixuns__Overview__index","88517":"p__User__Detail__Topics__Group__index","88866":"p__index","89076":"p__Account__Binding__index","89677":"p__virtualSpaces__Lists__Announcement__AddAndEdit__index","89785":"p__Classrooms__Lists__Template__student__index","90109":"p__Classrooms__Lists__ShixunHomeworks__Detail__components__CodeReview__Detail__index","90265":"p__User__Detail__Topics__index","90337":"p__Paperlibrary__Random__PreviewEdit__index","91045":"p__virtualSpaces__Lists__Knowledge__AddAndEdit__index","91470":"p__User__Register__index","91831":"p__Graduations__Index__index","92045":"p__Engineering__Lists__TeacherList__index","92501":"p__Search__index","92823":"p__Engineering__Navigation__Home__index","92983":"p__Forums__Index__index","93260":"p__Paperlibrary__Add__index","93282":"layouts__ShixunDetail__index","93496":"p__User__Detail__OtherResources__index","93665":"p__tasks__index","93668":"p__Classrooms__Lists__CommonHomework__Detail__index","94078":"p__Messages__Tidings__index","94498":"p__Shixuns__Edit__body__Level__Challenges__NewPractice__index","94662":"p__User__Detail__Paths__index","94715":"p__virtualSpaces__Lists__Material__Detail__index","94849":"p__User__Detail__ExperImentImg__index","95125":"p__Classrooms__Lists__Exercise__DetailedAnalysis__index","95176":"p__User__Detail__Videos__Protocol__index","95335":"p__Engineering__Lists__CourseMatrix__index","96444":"p__Video__Detail__id","96882":"p__Classrooms__New__StartClass__index","97008":"p__Shixuns__New__index","97046":"p__Shixuns__Detail__Repository__AddFile__index","98062":"p__User__Detail__Topicbank__index","98398":"p__virtualSpaces__Lists__Resources__Detail__index","98688":"p__Shixuns__Detail__Repository__index","98885":"p__Classrooms__Lists__Statistics__StudentStatistics__index","99674":"p__Shixuns__New__ImagePreview__index"}[chunkId] || chunkId) + "." + {"292":"5a996457","310":"75e03aa3","556":"4c72327f","1482":"b49d1920","1686":"38d20380","1702":"736b8dd2","2659":"495fc448","2819":"99f62cef","3317":"ab00d81a","3391":"4fc2dc91","3451":"a7a03e5e","3509":"695151b3","3585":"7739ff50","3951":"2e4eacc1","4736":"769fae07","4766":"8f02684a","4884":"187f5a31","4973":"5efc031d","5572":"947981c9","6127":"0bb73487","6685":"60feae92","6758":"b8452850","6788":"cf042b9c","7043":"2380a2f1","7852":"db2893c4","7884":"aa47f8d1","8254":"4fc94866","8787":"27ca9203","8999":"2f068ee7","9416":"9763e7b2","10195":"f767ea9a","10485":"844f9bdf","10737":"e6eba10a","10799":"10f1c1a2","10921":"d73ac794","11070":"13d6b839","11253":"98cd121d","11512":"e7d0ae09","11520":"f7f054ed","11545":"91fcf961","11581":"e5635afc","12076":"22474532","12102":"87ae64f5","12303":"0fb070d0","12412":"9be412e7","12476":"9578d472","12865":"5b0ba965","12884":"93370f0e","13006":"d8e2eaca","13355":"743212f5","13581":"16580e36","14058":"fb06de9f","14105":"93136efe","14227":"2c3d18bc","14333":"d3c9900c","14514":"73072130","14599":"eb7109b7","14610":"2fc74778","14662":"42472875","14889":"a4329cb3","15148":"f16b88c1","15186":"33abbf24","15319":"9cfada42","15402":"980bd3df","16328":"a39e46ca","16434":"2ba79912","16729":"29606af0","16845":"97c7ced4","17482":"da1374ca","17527":"4a714f2a","17622":"9e0b98db","17806":"8a5ecc39","18241":"c367596a","18302":"d6caf617","18307":"0acb79ce","19215":"9dcaaa5c","19360":"4762181c","19519":"3613caae","19715":"5e2a0b7d","19891":"1745f9dd","20026":"2185cbef","20576":"afc797fe","20680":"13d6b839","20700":"c66db1c2","21265":"72b968c9","21423":"925787ec","21578":"efd09cc7","21939":"3a68ced9","22254":"30e92a15","22307":"b773f7a8","22707":"84a6b292","23332":"0081f614","24504":"13261228","25022":"a9ae2ed6","25470":"1ac4cd7a","25705":"9933635f","25972":"873bd9da","26366":"99c0de22","26685":"f465f318","26741":"8aee11ea","26883":"8ee44eb8","27178":"1fbebe54","27182":"8f98a1dc","27395":"7566b46d","28072":"6f9a1b86","28237":"c822399b","28435":"1cce379e","28723":"fa461009","28782":"68dc8cc6","28982":"8685eafc","29647":"95cfdacc","30067":"a10e96f5","30264":"7282c74b","30342":"4c51e7fa","31006":"2ccf26c9","31211":"9ad23697","31427":"7094fb4c","31674":"5facd9be","31962":"1d3b5db1","33356":"2378f95d","33747":"5e1a83d5","33784":"e6a413b6","34093":"9df853be","34601":"ed5cc88a","34741":"2717bd09","34800":"1e4e1bd9","34994":"0804d8a9","35238":"a3ea44e7","35729":"ff3ae6ca","36029":"afaa7524","36270":"f6b2c0bb","36784":"b4cc7a25","37062":"b67eda31","37885":"3f7b8b76","37948":"f980807a","38143":"8586f1de","38447":"d4be38d0","38634":"89e1c326","38797":"1a4eb4e7","39332":"ffd783db","39391":"a7237b2e","39404":"87f370e9","39695":"210a4b44","40559":"126005df","41048":"74ed8829","41657":"b690c003","41717":"680001b6","41953":"e6b0db7c","42240":"022e1074","43442":"fae0ee56","44259":"6f6c3126","44449":"a56fbc59","45096":"3ad985cf","45179":"3ec536b4","45359":"aeff3aae","45650":"0971b6e0","45775":"bbb9e0c5","45825":"e2b24fdd","45992":"2e32d15a","46796":"bf51ab87","46963":"1d3b5db1","47545":"03f9142b","48077":"24763e54","48431":"bba27de7","48689":"29e9162c","49205":"e89d1991","49366":"e78af100","49716":"b9019790","49890":"14712f56","50869":"bcaacab4","51276":"9c9ce6c2","51461":"d328e0dd","51582":"9db8d1db","51855":"c7c8eefb","52338":"2997cbaf","52404":"83921ea5","52806":"a5762117","52829":"8c612d1a","52875":"1c141950","53247":"1410fac4","53910":"c7dced20","54056":"027dc8e7","54164":"06403803","54492":"08d22fd7","54572":"453b2bdf","54770":"9cfada42","54862":"30d6f055","55573":"1b353a6d","55624":"47b8c01f","56277":"b49bdd4d","57045":"7d21faab","57560":"d234a1ea","57614":"7ce5b918","59133":"72a2e444","59649":"70648c35","59788":"2a07eb0c","60479":"8d1ad677","60533":"93d13762","60547":"2897a6dd","61043":"f6c30b3d","61713":"364b90ff","61727":"7ace2d33","61880":"4714da08","62548":"68115e3c","63157":"d9dd657d","64144":"50d967c4","64217":"6e4f19a8","64496":"e0d8de8e","64520":"417c1bdc","65111":"87aedb27","65148":"a40e35ef","65191":"040ce748","65549":"dd8083ec","65816":"811668ae","66063":"e54eb446","66583":"d8cd8cbc","66651":"f6af1b73","67242":"025d14c7","67878":"8188125b","68014":"dc173275","68665":"74b138cf","68827":"2f83c579","68882":"dc18290e","69922":"910eb0cb","69944":"c0eee6f4","71450":"776e0758","71783":"faf07d3a","72529":"ad9dd215","72539":"585cc8e3","72570":"39586ff1","73183":"7d0e84a4","73220":"3d0c7bb5","74264":"42d78201","74795":"0a1864a7","75043":"02185c78","75357":"bc36dcec","75786":"dc6f7d4f","75816":"36096410","76904":"dc9336c8","77460":"8caf6e7f","77857":"6e825a97","78085":"99b63ff3","79489":"ed3cafc8","79590":"1483337d","79921":"a0bffefc","80508":"16f43f16","81148":"26aeb712","82339":"9d9d7b74","82425":"3e8daa20","82443":"05ad3522","83141":"51e8eca2","83212":"b2bbebb9","83935":"8a347d82","84546":"e9fe36cc","85048":"92c9616e","85111":"a4fec818","85297":"c18ccd20","85888":"2a2f42df","85891":"cdd0aaf4","86052":"240eb6a2","86452":"6342e243","86541":"6dc9335a","86634":"604be137","86820":"59cabb2e","86913":"e9424d99","87058":"549681af","87260":"219b54a4","87922":"fa3e5ef3","88155":"e80c98ba","88517":"10ae8d61","88866":"5328fdc3","89076":"ebf50422","89677":"9b44d2cd","89785":"83921ea5","90109":"e148913a","90265":"b7855242","90337":"d3caabd8","91045":"567f0fcd","91470":"8f98a1dc","91831":"d533be46","92045":"88bbc8ab","92501":"343dc994","92823":"9f57c07b","92983":"ea506616","93260":"59be2234","93282":"c8f15883","93496":"85f4504d","93665":"acfc6b8e","93668":"a5760178","94078":"d455483c","94498":"42ba2b23","94662":"62d70083","94715":"e0194d74","94849":"5fbef5ea","95125":"78253f56","95176":"17647050","95335":"485175e3","96444":"46614be0","96882":"f15aff03","97008":"23b22001","97046":"a18d9446","98062":"682f7e2e","98398":"b6e83c41","98688":"d407a4d8","98885":"7a7eff20","99674":"3fd3a712"}[chunkId] + ".chunk.css"; +/******/ return "" + ({"292":"p__Classrooms__Lists__Exercise__Add__index","310":"p__User__Detail__ExperImentImg__Detail__index","556":"p__User__Detail__Order__pages__invoice__index","1482":"p__Classrooms__Lists__Graduation__Topics__Edit__index","1702":"p__Classrooms__New__index","2659":"p__User__Detail__UserPortrait__index","2819":"p__Classrooms__Lists__Template__detail__index","3317":"p__Classrooms__Lists__Graduation__Topics__Add__index","3391":"p__Classrooms__Lists__ProgramHomework__Detail__components__CodeReview__Detail__index","3451":"p__Classrooms__Lists__Statistics__StudentStatistics__Detail__index","3509":"p__HttpStatus__SixActivities","3585":"p__Classrooms__Lists__Statistics__StudentSituation__index","3951":"p__Classrooms__Lists__ProgramHomework__Detail__index","4736":"p__User__Detail__Projects__index","4766":"p__Administration__index","4884":"p__Shixuns__Detail__Repository__Commit__index","4973":"p__Engineering__Evaluate__List__index","5572":"p__Paths__HigherVocationalEducation__index","6127":"p__Classrooms__Lists__ProgramHomework__Ranking__index","6685":"p__Shixuns__Detail__RankingList__index","6758":"p__Classrooms__Lists__Attachment__index","6788":"p__Classrooms__Lists__ProgramHomework__index","7043":"p__User__Detail__Topics__Exercise__Edit__index","7852":"p__Classrooms__Lists__ShixunHomeworks__index","7884":"p__Shixuns__Exports__index","8787":"p__Competitions__Entered__index","8999":"p__Three__index","9416":"p__Graduations__Lists__Tasks__index","10195":"p__Classrooms__Lists__GroupHomework__Detail__index","10485":"p__Question__AddOrEdit__BatchAdd__index","10737":"p__Classrooms__Lists__CommonHomework__Detail__components__CodeReview__Detail__index","10799":"p__User__Detail__Topics__Poll__Detail__index","10921":"p__Classrooms__Lists__Exercise__CodeDetails__index","11070":"p__Innovation__PublicMirror__index","11253":"p__Graduations__Lists__Gradingsummary__index","11512":"p__Classrooms__Lists__Exercise__AnswerCheck__index","11520":"p__Engineering__Lists__StudentList__index","11545":"p__Paperlibrary__Random__ExchangeFromProblemSet__index","11581":"p__Problemset__Preview__index","12076":"p__User__Detail__Competitions__index","12102":"p__Classrooms__Lists__Board__Edit__index","12303":"p__Classrooms__Lists__CommonHomework__Comment__index","12412":"p__User__Detail__Videos__index","12476":"p__Colleges__index","12865":"p__Innovation__MyMirror__index","12884":"p__Classrooms__Lists__ProgramHomework__Comment__index","13006":"p__Engineering__index","13355":"p__Classrooms__Lists__Polls__index","13581":"p__Classrooms__Lists__ShixunHomeworks__Detail__index","14058":"p__Demo__index","14105":"p__Classrooms__Lists__Exercise__Answer__index","14227":"p__Paths__Overview__index","14514":"p__Account__Results__index","14599":"p__Problemset__index","14610":"p__User__Detail__LearningPath__index","14662":"p__Classrooms__Lists__GroupHomework__Review__index","14889":"p__Classrooms__Lists__Exercise__ImitateAnswer__index","15148":"p__Classrooms__Lists__Template__index","15186":"p__Classrooms__Overview__index","15319":"p__Classrooms__Lists__ProgramHomework__Detail__answer__Detail__index","15402":"p__User__Detail__Topics__Detail__index","16328":"p__Shixuns__Edit__body__Warehouse__index","16434":"p__User__Detail__Order__pages__records__index","16729":"p__Classrooms__Lists__GroupHomework__Edit__index","16845":"p__Shixuns__Detail__Settings__index","17482":"p__Classrooms__Lists__Exercise__Notice__index","17527":"p__MyProblem__RecordDetail__index","17622":"p__Classrooms__Lists__Polls__Detail__index","17806":"p__Classrooms__Lists__Statistics__StatisticsQuality__index","18241":"p__virtualSpaces__Lists__Plan__index","18302":"p__Classrooms__Lists__Board__index","18307":"p__User__Detail__Shixuns__index","19215":"p__Shixuns__Detail__ForkList__index","19360":"p__User__Detail__virtualSpaces__index","19519":"p__User__Detail__ClassManagement__Item__index","19715":"p__Classrooms__Lists__CommonHomework__Edit__index","19891":"p__User__Detail__Videos__Success__index","20026":"p__Classrooms__Lists__Graduation__Tasks__Edit__index","20576":"p__Account__Profile__Edit__index","20680":"p__Innovation__index","20700":"p__tasks__Jupyter__index","21265":"p__Classrooms__Lists__Announcement__index","21423":"p__Shixuns__Edit__body__Level__Challenges__EditPracticeAnswer__index","21578":"p__Classrooms__Lists__Graduation__Topics__Detail__index","21939":"p__User__Detail__Order__index","22254":"p__Shixuns__Detail__Discuss__index","22307":"p__Report__index","22707":"p__Innovation__MyDataSet__index","23332":"p__Paths__Detail__id","24504":"p__virtualSpaces__Lists__Survey__index","25022":"p__Graduations__Lists__Settings__index","25470":"p__Shixuns__Detail__Collaborators__index","25705":"p__virtualSpaces__Lists__Construction__index","25972":"layouts__user__index","26366":"p__Innovation__PublicProject__index","26685":"p__Classrooms__Index__index","26741":"p__Engineering__Norm__List__index","26883":"p__Competitions__Index__index","27178":"p__User__BindAccount__index","27182":"p__User__ResetPassword__index","27395":"p__Classrooms__Lists__Statistics__StudentDetail__index","28072":"p__Classrooms__Lists__GroupHomework__SubmitWork__index","28237":"p__User__Detail__Order__pages__view__index","28435":"p__Classrooms__Lists__Attendance__index","28723":"p__Classrooms__Lists__Polls__Edit__index","28782":"p__Shixuns__Index__index","28982":"p__Paths__New__index","29647":"p__Question__Index__index","30067":"p__Message__index","30264":"p__User__Detail__Order__pages__orderPay__index","30342":"p__Classrooms__Lists__ShixunHomeworks__Comment__index","31006":"p__RestFul__index","31211":"p__Classrooms__Lists__CommonHomework__EditWork__index","31427":"p__Classrooms__Lists__Statistics__index","31674":"p__Classrooms__ClassicCases__index","31962":"p__Classrooms__Lists__Engineering__index","33356":"p__Classrooms__Lists__Assistant__index","33747":"p__virtualSpaces__Lists__Homepage__index","33784":"p__Paperlibrary__Random__Detail__index","34093":"p__Classrooms__Lists__Attendance__Detail__index","34601":"p__Paths__Detail__Statistics__index","34741":"p__Problems__OjForm__NewEdit__index","34800":"p__Engineering__Lists__GraduatedMatrix__index","34994":"p__Problems__OjForm__index","35238":"p__virtualSpaces__Lists__Material__index","35729":"p__Help__Index","36029":"p__Administration__Student__index","36270":"p__MyProblem__index","36784":"p__Innovation__Edit__index","37062":"layouts__SimpleLayouts","37948":"p__User__Detail__ClassManagement__index","38143":"layouts__GraduationsDetail__index","38447":"p__virtualSpaces__Lists__Knowledge__index","38634":"p__Classrooms__Lists__CourseGroup__List__index","38797":"p__Competitions__Edit__index","39332":"p__Classrooms__Lists__Video__index","39391":"p__Engineering__Lists__CurseSetting__index","39404":"monaco-editor","39695":"p__Classrooms__Lists__Polls__Add__index","40559":"layouts__virtualDetail__index","41048":"p__Classrooms__Lists__ProgramHomework__Detail__Ranking__index","41657":"p__Shixuns__Edit__body__Level__Challenges__EditQuestion__index","41717":"layouts__index","41953":"p__Problemset__NewItem__index","42240":"p__User__Detail__Videos__Upload__index","43442":"p__Classrooms__Lists__Board__Add__index","44259":"p__User__Detail__Order__pages__result__index","44449":"p__Competitions__Exports__index","45096":"p__Shixuns__Detail__AuditSituation__index","45179":"p__Administration__Student__Edit__index","45359":"p__Messages__Detail__index","45650":"p__Competitions__Update__index","45775":"p__Engineering__Lists__Document__index","45825":"p__Classrooms__Lists__Exercise__index","45992":"p__Classrooms__Lists__Exercise__ReviewGroup__index","46796":"p__virtualSpaces__Lists__Announcement__Detail__index","46963":"p__Classrooms__Lists__Engineering__Detail__index","47545":"p__Graduations__Lists__Archives__index","48077":"p__Classrooms__Lists__Students__index","48431":"p__Classrooms__Lists__Exercise__Export__index","48689":"p__Classrooms__Lists__Statistics__VideoStatistics__index","49205":"p__Shixuns__Edit__body__Level__Challenges__EditPracticeSetting__index","49366":"p__User__Login__index","49716":"p__Question__OjProblem__RecordDetail__index","49890":"p__Classrooms__Lists__CommonHomework__index","50869":"p__Guidance__index","51276":"p__MoopCases__Success__index","51461":"p__Graduations__Lists__Topics__index","51582":"p__Classrooms__Lists__GroupHomework__Add__index","51855":"p__MoopCases__InfoPanel__index","52338":"p__Classrooms__Lists__CommonHomework__Review__index","52404":"p__Classrooms__Lists__Template__teacher__index","52806":"p__User__Detail__Topics__Exercise__Detail__index","52829":"p__Messages__Private__index","52875":"p__Shixuns__Detail__id","53247":"p__Paperlibrary__See__index","53910":"p__HttpStatus__introduction","54056":"p__IntrainCourse__index","54164":"p__Classrooms__Lists__Exercise__Detail__index","54492":"p__Graduations__Lists__StudentSelection__index","54572":"p__Classrooms__Lists__ExportList__index","54770":"p__Classrooms__Lists__ProgramHomework__Detail__answer__index","54862":"p__Paperlibrary__index","55573":"p__Shixuns__Detail__Merge__index","55624":"p__Graduations__Lists__Index__index","56277":"p__Shixuns__Edit__index","57045":"p__Classrooms__Lists__CommonHomework__SubmitWork__index","57560":"p__Administration__College__index","57614":"p__Shixuns__Edit__body__Level__Challenges__RankingSetting__index","59133":"p__Shixuns__Detail__Challenges__index","59649":"p__Engineering__Lists__TrainingProgram__index","59788":"p__Account__Profile__index","60479":"p__Classrooms__Lists__GroupHomework__EditWork__index","60533":"p__Classrooms__Lists__Video__Statistics__Detail__index","60547":"p__Account__index","61043":"p__Classrooms__Lists__Graduation__Tasks__index","61713":"p__virtualSpaces__Lists__Settings__index","61727":"p__Classrooms__Lists__CourseGroup__NotList__index","61880":"p__User__Detail__Order__pages__apply__index","62548":"p__Engineering__Norm__Detail__index","63157":"p__User__Detail__ExperImentImg__Add__index","64144":"p__Problemset__Preview__New__index","64217":"p__Classrooms__Lists__Video__Statistics__index","64496":"p__HttpStatus__HpcCourse","64520":"p__Account__Secure__index","65111":"p__Terminal__index","65148":"p__Classrooms__Lists__Polls__Answer__index","65191":"p__User__Detail__Certificate__index","65549":"p__Shixuns__New__CreateImg__index","65816":"p__virtualSpaces__Lists__Announcement__index","66063":"p__Graduations__Lists__Personmanage__index","66583":"p__User__Detail__Classrooms__index","66651":"p__Engineering__Evaluate__Detail__index","67242":"p__Innovation__MyProject__index","67878":"p__Classrooms__Lists__LiveVideo__index","68014":"p__Classrooms__Lists__Teachers__index","68665":"p__Engineering__Lists__TrainingObjectives__index","68827":"p__Classrooms__Lists__OnlineLearning__index","68882":"p__Classrooms__Lists__Graduation__Tasks__Detail__index","69922":"p__Classrooms__Lists__Statistics__StudentVideo__index","69944":"p__Classrooms__Lists__Video__Statistics__StudentDetail__index","71450":"p__Classrooms__Lists__ShixunHomeworks__Commitsummary__index","71783":"p__virtualSpaces__Lists__Experiment__index","72529":"p__User__Detail__id","72539":"p__Graduations__Review__index","72570":"p__Competitions__Detail__index","73183":"p__Engineering__Lists__GraduationIndex__index","73220":"p__Classrooms__Lists__Video__Upload__index","74264":"p__Forums__New__index","74795":"p__Classrooms__Lists__Graduation__Tasks__Add__index","75043":"p__User__Detail__Topics__Poll__Edit__index","75357":"p__Engineering__Lists__TrainingProgram__Edit__index","75786":"layouts__LoginAndRegister__index","75816":"p__Paperlibrary__Random__Edit__index","76904":"p__MoopCases__FormPanel__index","77460":"p__Question__OjProblem__index","77857":"p__Shixuns__Edit__body__Level__Challenges__NewQuestion__index","78085":"p__Classrooms__Lists__Exercise__Review__index","79489":"p__Engineering__Lists__CourseList__index","79590":"p__User__Detail__TeachGroup__index","79921":"p__Classrooms__ExamList__index","80508":"p__Forums__Detail__id","81148":"p__Shixuns__Detail__Repository__UploadFile__index","82339":"p__virtualSpaces__Lists__Plan__Detail__index","82425":"p__Classrooms__Lists__Board__Detail__index","82443":"p__Graduations__Lists__StageModule__index","83141":"p__Innovation__Detail__index","83212":"p__MoopCases__index","83935":"p__Classrooms__Lists__GroupHomework__index","84546":"p__Engineering__Lists__TrainingProgram__Add__index","85048":"p__Classrooms__Lists__Graduation__Topics__index","85111":"p__User__Detail__Order__pages__orderInformation__index","85297":"p__Classrooms__Lists__Exercise__Detail__components__DuplicateChecking__CheckDetail__index","85888":"p__Classrooms__Lists__CommonHomework__Add__index","85891":"p__virtualSpaces__Lists__Resources__index","86052":"p__Paths__Index__index","86452":"p__Innovation__PublicDataSet__index","86541":"p__Shixuns__Detail__Dataset__index","86634":"p__Innovation__Tasks__index","86820":"p__User__Detail__Topics__Normal__index","86913":"p__Question__AddOrEdit__index","87058":"p__virtualSpaces__Lists__Survey__Detail__index","87260":"p__Account__Certification__index","87922":"p__Classrooms__Lists__CourseGroup__Detail__index","88155":"p__Shixuns__Overview__index","88517":"p__User__Detail__Topics__Group__index","88866":"p__index","89076":"p__Account__Binding__index","89677":"p__virtualSpaces__Lists__Announcement__AddAndEdit__index","89785":"p__Classrooms__Lists__Template__student__index","90109":"p__Classrooms__Lists__ShixunHomeworks__Detail__components__CodeReview__Detail__index","90265":"p__User__Detail__Topics__index","90337":"p__Paperlibrary__Random__PreviewEdit__index","91045":"p__virtualSpaces__Lists__Knowledge__AddAndEdit__index","91470":"p__User__Register__index","91831":"p__Graduations__Index__index","92045":"p__Engineering__Lists__TeacherList__index","92501":"p__Search__index","92823":"p__Engineering__Navigation__Home__index","92983":"p__Forums__Index__index","93260":"p__Paperlibrary__Add__index","93282":"layouts__ShixunDetail__index","93496":"p__User__Detail__OtherResources__index","93665":"p__tasks__index","93668":"p__Classrooms__Lists__CommonHomework__Detail__index","94078":"p__Messages__Tidings__index","94498":"p__Shixuns__Edit__body__Level__Challenges__NewPractice__index","94662":"p__User__Detail__Paths__index","94715":"p__virtualSpaces__Lists__Material__Detail__index","94849":"p__User__Detail__ExperImentImg__index","95125":"p__Classrooms__Lists__Exercise__DetailedAnalysis__index","95176":"p__User__Detail__Videos__Protocol__index","95335":"p__Engineering__Lists__CourseMatrix__index","96444":"p__Video__Detail__id","96882":"p__Classrooms__New__StartClass__index","97008":"p__Shixuns__New__index","97046":"p__Shixuns__Detail__Repository__AddFile__index","98062":"p__User__Detail__Topicbank__index","98398":"p__virtualSpaces__Lists__Resources__Detail__index","98688":"p__Shixuns__Detail__Repository__index","98885":"p__Classrooms__Lists__Statistics__StudentStatistics__index","99674":"p__Shixuns__New__ImagePreview__index"}[chunkId] || chunkId) + "." + {"292":"5a996457","310":"75e03aa3","556":"4c72327f","1482":"b49d1920","1686":"38d20380","1702":"736b8dd2","2659":"495fc448","2819":"99f62cef","3317":"ab00d81a","3391":"4fc2dc91","3451":"a7a03e5e","3509":"695151b3","3585":"7739ff50","3951":"2e4eacc1","4736":"769fae07","4766":"8f02684a","4884":"187f5a31","4973":"5efc031d","5572":"947981c9","6127":"0bb73487","6685":"60feae92","6758":"b8452850","6788":"cf042b9c","7043":"2380a2f1","7852":"db2893c4","7884":"aa47f8d1","8254":"4fc94866","8787":"27ca9203","8999":"2f068ee7","9416":"9763e7b2","10195":"f767ea9a","10485":"844f9bdf","10737":"e6eba10a","10799":"10f1c1a2","10921":"d73ac794","11070":"13d6b839","11253":"98cd121d","11512":"e7d0ae09","11520":"f7f054ed","11545":"91fcf961","11581":"e5635afc","12076":"22474532","12102":"87ae64f5","12303":"0fb070d0","12412":"9be412e7","12476":"9578d472","12865":"5b0ba965","12884":"93370f0e","13006":"d8e2eaca","13355":"743212f5","13581":"16580e36","14058":"fb06de9f","14105":"93136efe","14227":"2c3d18bc","14333":"d3c9900c","14514":"73072130","14599":"eb7109b7","14610":"2fc74778","14662":"42472875","14889":"a4329cb3","15148":"f16b88c1","15186":"33abbf24","15319":"9cfada42","15402":"980bd3df","16328":"a39e46ca","16434":"2ba79912","16729":"29606af0","16845":"97c7ced4","17482":"da1374ca","17527":"4a714f2a","17622":"9e0b98db","17806":"8a5ecc39","18241":"c367596a","18302":"d6caf617","18307":"0acb79ce","19215":"9dcaaa5c","19360":"4762181c","19519":"3613caae","19715":"5e2a0b7d","19891":"1745f9dd","20026":"2185cbef","20576":"afc797fe","20680":"13d6b839","20700":"c66db1c2","21265":"72b968c9","21423":"925787ec","21578":"efd09cc7","21939":"3a68ced9","22254":"30e92a15","22307":"b773f7a8","22707":"84a6b292","23332":"0081f614","24504":"13261228","25022":"a9ae2ed6","25470":"1ac4cd7a","25705":"9933635f","25972":"873bd9da","26366":"99c0de22","26685":"f465f318","26741":"8aee11ea","26883":"8ee44eb8","27178":"1fbebe54","27182":"8f98a1dc","27395":"7566b46d","28072":"6f9a1b86","28237":"c822399b","28435":"1cce379e","28723":"fa461009","28782":"68dc8cc6","28982":"8685eafc","29647":"95cfdacc","30067":"a10e96f5","30264":"7282c74b","30342":"4c51e7fa","31006":"2ccf26c9","31211":"9ad23697","31427":"7094fb4c","31674":"5facd9be","31962":"1d3b5db1","33356":"2378f95d","33747":"5e1a83d5","33784":"e6a413b6","34093":"9df853be","34601":"ed5cc88a","34741":"2717bd09","34800":"1e4e1bd9","34994":"0804d8a9","35238":"a3ea44e7","35729":"ff3ae6ca","36029":"afaa7524","36270":"f6b2c0bb","36784":"b4cc7a25","37062":"b67eda31","37885":"3f7b8b76","37948":"f980807a","38143":"8586f1de","38447":"d4be38d0","38634":"89e1c326","38797":"1a4eb4e7","39332":"ffd783db","39391":"a7237b2e","39404":"87f370e9","39695":"210a4b44","40559":"126005df","41048":"74ed8829","41657":"b690c003","41717":"680001b6","41953":"e6b0db7c","42240":"022e1074","43442":"fae0ee56","44259":"6f6c3126","44449":"a56fbc59","45096":"3ad985cf","45179":"3ec536b4","45359":"aeff3aae","45650":"0971b6e0","45775":"bbb9e0c5","45825":"e2b24fdd","45992":"2e32d15a","46796":"bf51ab87","46963":"1d3b5db1","47545":"03f9142b","48077":"24763e54","48431":"bba27de7","48689":"29e9162c","49205":"e89d1991","49366":"e78af100","49716":"b9019790","49890":"14712f56","50869":"bcaacab4","51276":"9c9ce6c2","51461":"d328e0dd","51582":"9db8d1db","51855":"c7c8eefb","52338":"2997cbaf","52404":"83921ea5","52806":"a5762117","52829":"8c612d1a","52875":"1c141950","53247":"1410fac4","53910":"c7dced20","54056":"027dc8e7","54164":"f7d9c0af","54492":"08d22fd7","54572":"453b2bdf","54770":"9cfada42","54862":"30d6f055","55573":"1b353a6d","55624":"47b8c01f","56277":"b49bdd4d","57045":"7d21faab","57560":"d234a1ea","57614":"7ce5b918","59133":"72a2e444","59649":"70648c35","59788":"2a07eb0c","60479":"8d1ad677","60533":"93d13762","60547":"2897a6dd","61043":"f6c30b3d","61713":"364b90ff","61727":"7ace2d33","61880":"4714da08","62548":"68115e3c","63157":"d9dd657d","64144":"50d967c4","64217":"6e4f19a8","64496":"e0d8de8e","64520":"417c1bdc","65111":"87aedb27","65148":"a40e35ef","65191":"040ce748","65549":"dd8083ec","65816":"811668ae","66063":"e54eb446","66583":"d8cd8cbc","66651":"f6af1b73","67242":"025d14c7","67878":"8188125b","68014":"dc173275","68665":"74b138cf","68827":"2f83c579","68882":"dc18290e","69922":"910eb0cb","69944":"c0eee6f4","71450":"776e0758","71783":"faf07d3a","72529":"ad9dd215","72539":"585cc8e3","72570":"39586ff1","73183":"7d0e84a4","73220":"3d0c7bb5","74264":"42d78201","74795":"0a1864a7","75043":"02185c78","75357":"bc36dcec","75786":"dc6f7d4f","75816":"36096410","76904":"dc9336c8","77460":"8caf6e7f","77857":"6e825a97","78085":"99b63ff3","79489":"ed3cafc8","79590":"1483337d","79921":"a0bffefc","80508":"16f43f16","81148":"26aeb712","82339":"9d9d7b74","82425":"3e8daa20","82443":"05ad3522","83141":"51e8eca2","83212":"b2bbebb9","83935":"8a347d82","84546":"e9fe36cc","85048":"92c9616e","85111":"a4fec818","85297":"c18ccd20","85888":"2a2f42df","85891":"cdd0aaf4","86052":"240eb6a2","86452":"6342e243","86541":"6dc9335a","86634":"604be137","86820":"59cabb2e","86913":"e9424d99","87058":"549681af","87260":"219b54a4","87922":"fa3e5ef3","88155":"e80c98ba","88517":"10ae8d61","88866":"5328fdc3","89076":"ebf50422","89677":"9b44d2cd","89785":"83921ea5","90109":"e148913a","90265":"b7855242","90337":"d3caabd8","91045":"567f0fcd","91470":"8f98a1dc","91831":"d533be46","92045":"88bbc8ab","92501":"343dc994","92823":"9f57c07b","92983":"ea506616","93260":"59be2234","93282":"c8f15883","93496":"85f4504d","93665":"acfc6b8e","93668":"a5760178","94078":"d455483c","94498":"42ba2b23","94662":"62d70083","94715":"e0194d74","94849":"5fbef5ea","95125":"78253f56","95176":"17647050","95335":"485175e3","96444":"46614be0","96882":"f15aff03","97008":"23b22001","97046":"a18d9446","98062":"682f7e2e","98398":"b6e83c41","98688":"d407a4d8","98885":"7a7eff20","99674":"3fd3a712"}[chunkId] + ".chunk.css"; /******/ }; /******/ }(); /******/