Worker.js 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467
  1. class Workers {
  2. constructor(o, s) {
  3. (this.rtcp = o),
  4. (this.cacheSize = 0),
  5. (this.cacheBuffer = new Uint8Array(262144)),
  6. (this.cacheFrameCnt = 0),
  7. (this.startReceiveTime = 0),
  8. (this.cacheFrameComposes = new Array(0)),
  9. (this.cacheSizes = new Array(5).fill(0)),
  10. (this.cacheFrameCnts = new Array(5).fill(-1)),
  11. (this.cacheStartReceiveTimes = new Array(5).fill(0)),
  12. (this.cacheBuffers = [
  13. new Uint8Array(262144),
  14. new Uint8Array(262144),
  15. new Uint8Array(262144),
  16. new Uint8Array(262144),
  17. new Uint8Array(262144),
  18. ]),
  19. (this.panoCacheSize = 0),
  20. (this.panoCacheBuffer = new Uint8Array(2097152)),
  21. (this.cachePanoTileID = 0),
  22. (this.receivedMedia = 0),
  23. (this.receivedMedia_worker = 0),
  24. (this.receivedYUV = 0),
  25. (this.receivedEmit = 0),
  26. (this.returnFrames = 0),
  27. (this.lastReturnFrames = 0),
  28. (this.lastReceivedEmit = 0),
  29. (this.mediaBytesReceived = 0),
  30. (this.metaBytesReceived = 0),
  31. (this.noWasmBytesReceived = 0),
  32. (this.rtcBytesReceived = 0),
  33. (this.rtcMessageReceived = 0),
  34. (this.packetsDrop = 0),
  35. (this.framesAwait = 0),
  36. (this.sendOutBuffer = 0),
  37. (this.decodeTimePerFrame = 0),
  38. (this.decodeTimeMaxFrame = 0),
  39. (this.lastRenderTs = 0),
  40. (this.JankTimes = 0),
  41. (this.bigJankTimes = 0),
  42. (this.DecodeJankTimes = 0),
  43. (this.bigDecodeJankTimes = 0),
  44. (this.saveframe = !1),
  45. (this.SaveMediaStream = !1),
  46. (this.packetsLost = 0),
  47. (this.showAllReceivedMetadata = !1),
  48. (this.firstMediaArraval = 0),
  49. (this.firstMediaReceived = !1),
  50. (this.firstYUVDecoded = 0),
  51. (this.firstRender = 0),
  52. (this.firstYUVReceived = !1),
  53. (this.reconnectSignal = !1),
  54. (this.serverFrameSlow = 0),
  55. (this.serverFrameFast = 0),
  56. (this.clientFrameSlow = 0),
  57. (this.clientFrameFast = 0),
  58. (this.lastServerTS = 0),
  59. (this.lastClientTS = 0),
  60. (this.lastSeq = 0),
  61. (this.lastIsPureMeta = !1),
  62. (this.lastHBPacketTs = 0),
  63. (this.HBPacketInterval = 0),
  64. (this.lastHBPacketSrvSentTs = 0),
  65. (this.HBPacketIntervalSrvSent = 0),
  66. (this.cachedLength = 5),
  67. (this.cachedStreams = new Array(this.cachedLength)),
  68. (this.cachedMetas = new Array(this.cachedLength)),
  69. (this.cachedPtss = new Array(this.cachedLength)),
  70. (this.cachedRender = Array(this.cachedLength).fill(!1)),
  71. (this.cachedResolution = new Array(this.cachedLength)),
  72. (this.getPtr = 0),
  73. (this.setPtr = 0),
  74. (this.receiveIframes = 0),
  75. (this.decodeIframes = 0),
  76. (this.prevSenderTs = -1),
  77. (this.serverSendTimeArray = new CircularArray(120, !1, [])),
  78. (this.inPanoMode = !1),
  79. (this.PanoStatus = { x: 0, y: 0, z: 0, tiles: [] }),
  80. (this.DynamicPanoTest = !1),
  81. (this.PanoMask = new ArrayBuffer(8)),
  82. (this.PanoView = new DataView(this.PanoMask)),
  83. (this.userId_test = ""),
  84. (this.PendingMasks = []),
  85. (this.traceIdMap = new Map()),
  86. (this.responseTimeArray = []),
  87. (this.processTimeArray = []),
  88. (this.displayTimeArray = []),
  89. (this.overallTimeArray = []),
  90. (this.responseMiss = 0),
  91. (this.processMiss = 0),
  92. (this.displayMiss = 0),
  93. (this.joyStickTraceIdMap = new Map()),
  94. (this.joyStickResponseTimeArray = []),
  95. (this.joyStickProcessTimeArray = []),
  96. (this.joyStickDisplayTimeArray = []),
  97. (this.joyStickOverallTimeArray = []),
  98. (this.joyStickResponseMiss = 0),
  99. (this.joyStickProcessMiss = 0),
  100. (this.joyStickDisplayMiss = 0),
  101. (this.updateYUVCircular = new CircularArray(120, !1, [])),
  102. (this.updateDropFrame = 0),
  103. (this.metaParseAraay = []),
  104. (this.responseMoveMiss = 0),
  105. (this.processMoveMiss = 0),
  106. (this.displayMoveMiss = 0),
  107. (this.MovingTraceId = ""),
  108. (this.PendingMovingTraceId = ""),
  109. (this.inMovingMode = !1),
  110. (this.StartMovingTs = 0),
  111. (this.PendingStartMovingTs = 0),
  112. (this.moveEvent = ""),
  113. (this.MoveToFrameCnt = 0),
  114. (this.lastIsMoving = 0),
  115. (this.MoveResponseDelay = 0),
  116. (this.MoveProcessDelay = 0),
  117. (this.MoveDisplayDelay = 0),
  118. (this.lastMoveResponseTime = 0),
  119. (this.lastMoveProcessTime = 0),
  120. (this.lastMoveDisplayTime = 0),
  121. (this.moveResponseCircular = new CircularArray(120, !0, [
  122. STUCK_STAGE_GOOD,
  123. STUCK_STAGE_WELL,
  124. STUCK_STAGE_FAIR,
  125. STUCK_STAGE_BAD,
  126. ])),
  127. (this.moveProcessCircular = new CircularArray(120, !0, [
  128. STUCK_STAGE_GOOD,
  129. STUCK_STAGE_WELL,
  130. STUCK_STAGE_FAIR,
  131. STUCK_STAGE_BAD,
  132. ])),
  133. (this.moveDisplayCircular = new CircularArray(120, !0, [
  134. STUCK_STAGE_GOOD,
  135. STUCK_STAGE_WELL,
  136. STUCK_STAGE_FAIR,
  137. STUCK_STAGE_BAD,
  138. ])),
  139. (this.moveStartPts = -1),
  140. (this.frameServerCircular = new CircularArray(120, !1, [])),
  141. (this.srvMetaIntervalCircular = new CircularArray(120, !1, [])),
  142. (this.srvMediaIntervalCircular = new CircularArray(120, !1, [])),
  143. (this.srvHBMetaIntervalCircular = new CircularArray(120, !1, [])),
  144. (this.srvHBMetaIntervalSrvSentCircular = new CircularArray(120, !1, [])),
  145. (this.frameClientCircular = new CircularArray(120, !1, [])),
  146. (this.serverHBMax = 0),
  147. (this.serverHBAvg = 0),
  148. (this.unmarshalStreamExecutionArray = new SecondArray()),
  149. (this.receiveYUVExecutionArray = new SecondArray()),
  150. (this.postMessageWaitArray = new SecondArray()),
  151. (this.firstUpdateYUV = !0),
  152. (this.bypasserList = []),
  153. (this.functionMap = new Map()),
  154. (this.WASM_VERSION = "WASM-1.1"),
  155. (this.frameHistory = []),
  156. (this.getVersion = function () {
  157. return DECODER_VERSION;
  158. }),
  159. (this.downloadBlob = (c, _, b) => {
  160. const k = new Blob([c], { type: b }),
  161. j = window.URL.createObjectURL(k);
  162. this.downloadURL(j, _),
  163. setTimeout(function () {
  164. return window.URL.revokeObjectURL(j);
  165. }, 1e3);
  166. }),
  167. (this.downloadURL = function (c, _) {
  168. const b = document.createElement("a");
  169. (b.href = c),
  170. (b.download = _),
  171. document.body.appendChild(b),
  172. (b.style.display = "none"),
  173. b.click(),
  174. b.remove();
  175. }),
  176. (this.Stringify = function (c) {
  177. let _ = "";
  178. for (let k = 0; k < c.length / 8192; k++)
  179. _ += String.fromCharCode.apply(
  180. null,
  181. c.slice(k * 8192, (k + 1) * 8192)
  182. );
  183. return _;
  184. }),
  185. (this._rtcp = o);
  186. }
  187. registerLogger(o) {
  188. log$o = o;
  189. }
  190. registerFunction(o, s) {
  191. this.functionMap.set(o, s);
  192. }
  193. hasFrmCntInCache(o) {
  194. let s = -1;
  195. for (let c = 0; c < this.cacheFrameComposes.length; c++)
  196. this.cacheFrameComposes[c].frameCnt == o && (s = c);
  197. return s;
  198. }
  199. requestPanoramaTest(o, s, c, _, b) {
  200. const k = b,
  201. j = {
  202. action_type: 16,
  203. change_rotation_render_type_action: {
  204. render_type: 5,
  205. player: {
  206. position: { x: 0, y: 0, z: 0 },
  207. angle: { yaw: 0, pitch: 0, roll: 0 },
  208. },
  209. camera: {
  210. position: { x: o, y: s, z: c },
  211. angle: { yaw: 0, pitch: 0, roll: 0 },
  212. },
  213. client_pano_titles_bitmap: _,
  214. },
  215. trace_id: k,
  216. user_id: this.userId_test,
  217. packet_id: k,
  218. };
  219. log$o.debug("send data: ", j), this._rtcp.sendData(j);
  220. }
  221. onRotateInPanoMode(o) {
  222. const s = o.traceId,
  223. c = {};
  224. (c.width = 1280),
  225. (c.height = 720),
  226. (c.horz_fov = 92),
  227. (c.angle = { yaw: 100, pitch: 30 });
  228. const _ = new ArrayBuffer(8),
  229. b = new DataView(_);
  230. getTilesInView(c, _);
  231. const k = _.slice(0);
  232. this.PendingMasks.unshift({ buffer: k, angle: c.angle }),
  233. MaskSetToOne(18, this.PanoView),
  234. operateForDataView(b, this.PanoView, b, (j, $) => j ^ (j & $)),
  235. this.requestPanoramaTest(
  236. 0,
  237. 0,
  238. 0,
  239. [
  240. b.getUint8(0),
  241. b.getUint8(1),
  242. b.getUint8(2),
  243. b.getUint8(3),
  244. b.getUint8(4),
  245. b.getUint8(5),
  246. b.getUint8(6),
  247. b.getUint8(7),
  248. ],
  249. s
  250. );
  251. }
  252. processMetaWithTraceId(o) {
  253. for (const s of o.traceIds) {
  254. if (this.traceIdMap.has(s)) {
  255. const c = this.traceIdMap.get(s);
  256. c != null && ((c.receiveTime = Date.now()), (c.status = 1));
  257. }
  258. if (this.joyStickTraceIdMap.has(s)) {
  259. const c = this.joyStickTraceIdMap.get(s);
  260. c != null && ((c.receiveTime = Date.now()), (c.status = 1));
  261. }
  262. if (s == this.PendingMovingTraceId) {
  263. (this.inMovingMode = !0),
  264. (this.MovingTraceId = this.PendingMovingTraceId),
  265. (this.StartMovingTs = this.PendingStartMovingTs),
  266. (this.PendingMovingTraceId = ""),
  267. (this.PendingStartMovingTs = 0),
  268. log$o.info("MoveTo TraceId match", this.StartMovingTs, Date.now());
  269. const c = Date.now();
  270. (this.lastMoveResponseTime = c),
  271. (this.lastMoveProcessTime = c),
  272. (this.lastMoveDisplayTime = c),
  273. this.frameServerCircular.clear(),
  274. this.frameClientCircular.clear();
  275. }
  276. }
  277. }
  278. onTraceId(o, s = this) {
  279. const c = o.traceId,
  280. _ = o.timestamp,
  281. b = o.event;
  282. if (b === "Rotation") {
  283. const k = {
  284. traceId: c,
  285. pts: 0,
  286. startTime: _,
  287. receiveTime: 0,
  288. readyTime: 0,
  289. displayTime: 0,
  290. status: 0,
  291. };
  292. this.traceIdMap.set(c, k);
  293. const j = setTimeout(() => {
  294. if ((j && clearTimeout(j), this.traceIdMap.has(c))) {
  295. const $ = this.traceIdMap.get(c);
  296. switch ($ == null ? void 0 : $.status) {
  297. case 0: {
  298. this.responseMiss += 1;
  299. break;
  300. }
  301. case 1: {
  302. this.processMiss += 1;
  303. const _e = $.receiveTime - $.startTime;
  304. this.responseTimeArray.push(_e);
  305. break;
  306. }
  307. case 2: {
  308. this.displayMiss += 1;
  309. const _e = $.receiveTime - $.startTime,
  310. et = $.readyTime - $.receiveTime;
  311. this.responseTimeArray.push(_e), this.processTimeArray.push(et);
  312. break;
  313. }
  314. case 3:
  315. log$o.debug("status is 3");
  316. }
  317. }
  318. }, 1e3);
  319. } else if (b === "Joystick") {
  320. const k = {
  321. traceId: c,
  322. pts: 0,
  323. startTime: _,
  324. receiveTime: 0,
  325. readyTime: 0,
  326. displayTime: 0,
  327. status: 0,
  328. };
  329. this.joyStickTraceIdMap.set(c, k);
  330. const j = setTimeout(() => {
  331. if ((j && clearTimeout(j), this.joyStickTraceIdMap.has(c))) {
  332. const $ = this.joyStickTraceIdMap.get(c);
  333. switch ($ == null ? void 0 : $.status) {
  334. case 0: {
  335. this.joyStickResponseMiss += 1;
  336. break;
  337. }
  338. case 1: {
  339. this.joyStickProcessMiss += 1;
  340. const _e = $.receiveTime - $.startTime;
  341. this.joyStickResponseTimeArray.push(_e);
  342. break;
  343. }
  344. case 2: {
  345. this.joyStickDisplayMiss += 1;
  346. const _e = $.receiveTime - $.startTime,
  347. et = $.readyTime - $.receiveTime;
  348. this.joyStickResponseTimeArray.push(_e),
  349. this.joyStickProcessTimeArray.push(et);
  350. break;
  351. }
  352. case 3:
  353. log$o.debug("status is 3");
  354. }
  355. }
  356. }, 1e3);
  357. } else
  358. b === "MoveTo"
  359. ? (log$o.info("receive moveto traceId ", c, " at timestamp", _),
  360. (this.PendingMovingTraceId = c),
  361. (this.PendingStartMovingTs = _),
  362. (this.moveEvent = b),
  363. this.frameServerCircular.clear())
  364. : b === "GetOnAirship" || b === "GetOnVehicle"
  365. ? (log$o.info("receive airship traceId ", c, " at timestamp ", _),
  366. (this.PendingMovingTraceId = c),
  367. (this.PendingStartMovingTs = _),
  368. (this.moveEvent = b),
  369. this.frameServerCircular.clear())
  370. : (b === "GetOffAirship" || b === "GetOffVehicle") &&
  371. this.clearMoveArray();
  372. }
  373. executeFunction(o, s) {
  374. if (this.functionMap.has(o)) {
  375. const c = this.functionMap.get(o);
  376. c != null && c(s);
  377. }
  378. }
  379. UpdateStats(o) {
  380. var s;
  381. (s = this._rtcp.connection) == null ||
  382. s.getStats(null).then((c) => {
  383. c.forEach((_) => {
  384. _.type == "data-channel" &&
  385. ((this.rtcMessageReceived = _.messagesReceived - _.messagesSent),
  386. (this.rtcBytesReceived = _.bytesReceived));
  387. });
  388. }),
  389. (this.receivedMedia_worker = o.data.framesReceived),
  390. (this.receivedYUV = o.data.framesDecoded),
  391. (this.receivedEmit = o.data.framesRendered),
  392. (this.mediaBytesReceived = o.data.mediaBytesReceived),
  393. (this.metaBytesReceived = o.data.metaBytesReceived),
  394. (this.packetsLost = o.data.packetsLost),
  395. (this.packetsDrop = o.data.packetsDrop),
  396. (this.framesAwait = o.data.framesAwait),
  397. (this.decodeTimePerFrame = o.data.decodeTimePerFrame),
  398. (this.decodeTimeMaxFrame = o.data.decodeTimeMaxFrame),
  399. (this.returnFrames = o.data.framesReturned),
  400. (this.sendOutBuffer = o.data.sendOutBuffer),
  401. (this.DecodeJankTimes = o.data.JankTimes),
  402. (this.bigDecodeJankTimes = o.data.bigJankTimes),
  403. (this.receiveIframes = o.data.receivedIframe),
  404. (this.decodeIframes = o.data.decodedIframe);
  405. }
  406. ReceiveDecodeMessage(o) {
  407. var $;
  408. const s = Date.now(),
  409. c = s - o.data.postTs;
  410. if ((this.postMessageWaitArray.add(c), !this.firstYUVReceived)) {
  411. this.firstYUVDecoded = o.data.yuv_ts;
  412. const _e = this.firstYUVDecoded - this.rtcp.network.room._startTime;
  413. log$o.infoAndReportMeasurement({
  414. metric: "firstYUVDecodedAt",
  415. value: _e,
  416. group: "joinRoom",
  417. }),
  418. (this.firstRender = Date.now());
  419. const et = this.firstYUVDecoded - this.rtcp.network.room._startTime;
  420. log$o.infoAndReportMeasurement({
  421. metric: "firstRenderAt",
  422. value: et,
  423. group: "joinRoom",
  424. }),
  425. (this.firstYUVReceived = !0),
  426. (this.lastRenderTs = Date.now());
  427. }
  428. !this.cachedRender[this.setPtr] &&
  429. this.cachedMetas[this.setPtr] != null &&
  430. (this.cachedStreams[this.setPtr] != null &&
  431. this.cachedStreams[this.setPtr].byteLength != 0 &&
  432. (o.data.data == null
  433. ? (this.executeFunction("stream", {
  434. stream: this.cachedStreams[this.setPtr],
  435. width: this.cachedResolution[this.setPtr].width,
  436. height: this.cachedResolution[this.setPtr].height,
  437. pts: this.cachedPtss[this.setPtr],
  438. }),
  439. this.executeFunction("signal", {
  440. signal: this.cachedMetas[this.setPtr],
  441. pts: this.cachedPtss[this.setPtr],
  442. alreadyUpdateYUV: !0,
  443. }))
  444. : (this.updateDropFrame += 1),
  445. this.decoderWorker.postMessage(
  446. {
  447. t: 2,
  448. frameCnt: this.cachedPtss[this.setPtr],
  449. buffer: this.cachedStreams[this.setPtr],
  450. },
  451. [this.cachedStreams[this.setPtr].buffer]
  452. )),
  453. (this.getPtr = (this.getPtr + 1) % this.cachedLength));
  454. const _ = o.data.metadata;
  455. if (($ = _ == null ? void 0 : _.traceIds) != null && $.length)
  456. for (const _e of _.traceIds) {
  457. if (this.traceIdMap.has(_e)) {
  458. const et = this.traceIdMap.get(_e);
  459. et != null && ((et.readyTime = Date.now()), (et.status = 2));
  460. }
  461. if (this.joyStickTraceIdMap.has(_e)) {
  462. const et = this.joyStickTraceIdMap.get(_e);
  463. et != null && ((et.readyTime = Date.now()), (et.status = 2));
  464. }
  465. }
  466. if (
  467. (o.data.pts == this.moveStartPts &&
  468. (this.MoveProcessDelay = Date.now() - this.StartMovingTs),
  469. (this.userId_test = this.rtcp.network.room.userId),
  470. this.inMovingMode)
  471. ) {
  472. const _e = Date.now(),
  473. et = _e - this.lastMoveProcessTime;
  474. this.moveProcessCircular.add(et), (this.lastMoveProcessTime = _e);
  475. }
  476. const b = this.setPtr;
  477. (this.cachedStreams[b] = o.data.data),
  478. (this.cachedMetas[b] = o.data.metadata),
  479. (this.cachedPtss[b] = o.data.pts),
  480. (this.cachedRender[b] = !1),
  481. (this.cachedResolution[b] = {
  482. width: o.data.width,
  483. height: o.data.height,
  484. }),
  485. (this.setPtr = (this.setPtr + 1) % this.cachedLength);
  486. const j = Date.now() - s;
  487. this.receiveYUVExecutionArray.add(j);
  488. }
  489. SendCacheFrameInfo(o) {
  490. var tt, rt, it, nt, at, ot, st;
  491. const s = o.data.cachedKey,
  492. c = o.data.metadata,
  493. _ = s,
  494. b = c,
  495. k =
  496. (it =
  497. (rt =
  498. (tt = b.newUserStates) == null
  499. ? void 0
  500. : tt.find((lt) => lt.userId === this.rtcp.network.room.userId)) ==
  501. null
  502. ? void 0
  503. : rt.playerState) == null
  504. ? void 0
  505. : it.roomTypeId,
  506. j = this.rtcp.network.room.skinId,
  507. $ =
  508. (st =
  509. (ot =
  510. (at =
  511. (nt = b.newUserStates) == null
  512. ? void 0
  513. : nt.find(
  514. (lt) => lt.userId === this._rtcp.network.room.userId
  515. )) == null
  516. ? void 0
  517. : at.playerState) == null
  518. ? void 0
  519. : ot.player) == null
  520. ? void 0
  521. : st.position,
  522. _e = {
  523. MsgType: 1,
  524. FrameCacheMsg: { FrameIndex: _, RoomTypeId: k, SkinID: j, Position: $ },
  525. };
  526. let et = "";
  527. try {
  528. et = JSON.stringify(_e);
  529. } catch (lt) {
  530. log$o.error(lt);
  531. return;
  532. }
  533. }
  534. ReceivePanoramaDecodeMessage(o) {
  535. log$o.info("Receive Panorama Image in Workers.ts"),
  536. MaskSetToOne(o.data.tileId, this.PanoView);
  537. let s = 0,
  538. c;
  539. const _ = this.PendingMasks.length;
  540. for (s = 0; s < _; s++) {
  541. const b = this.PendingMasks[s].buffer,
  542. k = new DataView(b),
  543. j = new ArrayBuffer(8),
  544. $ = new DataView(j);
  545. if (
  546. (operateForDataView(this.PanoView, k, $, (_e, et) => et ^ (_e & et)),
  547. IsAll0($))
  548. ) {
  549. c = this.PendingMasks[s].angle;
  550. break;
  551. }
  552. }
  553. for (let b = s; b < _; b++) this.PendingMasks.pop();
  554. this.executeFunction("panorama", {
  555. data: o.data.data,
  556. metadata: o.data.metadata,
  557. tileId: o.data.tileId,
  558. finished: !0,
  559. matchAngle: c,
  560. });
  561. }
  562. enable_decoder_queue_logging() {
  563. this.decoderWorker.postMessage({ t: 100, status: !0 });
  564. }
  565. disable_decoder_queue_logging() {
  566. this.decoderWorker.postMessage({ t: 100, status: !1 });
  567. }
  568. async init(
  569. o = {
  570. width: 1280,
  571. height: 720,
  572. userID: "testUserId",
  573. pageSession: "pagesession1",
  574. serverSession: "serversession1",
  575. bypasserList: [],
  576. }
  577. ) {
  578. for (let c = 0; c < FRAME_COMPOSE_LENGTH; c++) {
  579. const _ = {
  580. buffer: new Uint8Array(262144),
  581. size: 0,
  582. startReceiveTime: 0,
  583. serverTime: 0,
  584. frameCnt: -1,
  585. };
  586. this.cacheFrameComposes.push(_);
  587. }
  588. console.log("decoder config is ", o),
  589. (this.bypasserList = o.bypasserList),
  590. (USER_ID = o.userID),
  591. (PAGE_SESSION = o.pageSession),
  592. (SERVER_SESSION = o.serverSession);
  593. const s = new Blob([decoder], { type: "application/javascript" });
  594. return (
  595. (this.decoderWorker = new Worker(URL.createObjectURL(s))),
  596. this.decoderWorker.postMessage({
  597. t: 9,
  598. url: WASM_URLS[WASM_Version],
  599. jitterLength: DECODER_PASSIVE_JITTER,
  600. }),
  601. this.decoderWorker.postMessage({ t: 1, config: o }),
  602. new Promise((c) => {
  603. this.decoderWorker.onmessage = (_) => {
  604. switch (_.data.t) {
  605. case 0:
  606. this.ReceiveDecodeMessage(_);
  607. break;
  608. case 1:
  609. this.UpdateStats(_);
  610. break;
  611. case 2:
  612. c();
  613. break;
  614. case 3:
  615. this.SendCacheFrameInfo(_);
  616. break;
  617. case 4: {
  618. const b = new Date().toISOString(),
  619. k =
  620. USER_ID +
  621. "-" +
  622. PAGE_SESSION +
  623. "-" +
  624. SERVER_SESSION +
  625. "-" +
  626. b +
  627. ".264";
  628. uploadStream(COS_PREFIX + k, _.data.fileObj);
  629. break;
  630. }
  631. case 5:
  632. this.executeFunction("signal", {
  633. signal: _.data.metadata,
  634. pts: -1,
  635. alreadyUpdateYUV: !1,
  636. });
  637. break;
  638. case 6:
  639. log$o.infoAndReportMeasurement(_.data.data),
  640. log$o.debug("WASM Ready Cost");
  641. break;
  642. case 7:
  643. this.ReceivePanoramaDecodeMessage(_);
  644. break;
  645. case 8: {
  646. const b = { MstType: 0 };
  647. let k = "";
  648. try {
  649. k = JSON.stringify(b);
  650. } catch ($) {
  651. log$o.error($);
  652. return;
  653. }
  654. const j = "wasm:" + k;
  655. this._rtcp.sendStringData(j);
  656. break;
  657. }
  658. case 9: {
  659. log$o.info(_.data.printMsg);
  660. break;
  661. }
  662. case 10: {
  663. log$o.error(_.data.printMsg),
  664. this.executeFunction("error", {
  665. code: _.data.code,
  666. message: _.data.printMsg,
  667. });
  668. break;
  669. }
  670. default:
  671. log$o.error("Receive unknown message event from decoder"),
  672. log$o.debug(_.data);
  673. break;
  674. }
  675. };
  676. })
  677. );
  678. }
  679. setPageSession(o) {
  680. PAGE_SESSION = o;
  681. }
  682. UpdateYUV() {
  683. var s, c;
  684. const o = this.getPtr;
  685. if (this.cachedMetas[o] != null && !this.cachedRender[o]) {
  686. const _ = Date.now();
  687. if (this.firstUpdateYUV) {
  688. const tt =
  689. ((s = this.cachedStreams[o]) == null ? void 0 : s.byteLength) || 0;
  690. log$o.infoAndReportMeasurement({
  691. metric: "firstUpdateStreamLength",
  692. value: tt,
  693. group: "joinRoom",
  694. }),
  695. (this.firstUpdateYUV = !1);
  696. }
  697. this.cachedStreams[o] != null &&
  698. this.executeFunction("stream", {
  699. stream: this.cachedStreams[o],
  700. width: this.cachedResolution[o].width,
  701. height: this.cachedResolution[o].height,
  702. pts: this.cachedPtss[o],
  703. });
  704. const b = Date.now();
  705. this.cachedStreams[o] != null &&
  706. this.decoderWorker.postMessage(
  707. { t: 2, frameCnt: this.cachedPtss[o], buffer: this.cachedStreams[o] },
  708. [this.cachedStreams[o].buffer]
  709. );
  710. const k = Date.now(),
  711. j = b - _,
  712. $ = k - b;
  713. (j > 33 || $ > 10) &&
  714. log$o.debug(
  715. "[wwwarning] updateYUV takes ",
  716. j,
  717. " ms, postMessage takes ",
  718. $,
  719. " ms for index ",
  720. this.cachedPtss[o]
  721. ),
  722. b - this.lastRenderTs > 84 && this.JankTimes++,
  723. b - this.lastRenderTs > 125 && this.bigJankTimes++,
  724. (this.lastRenderTs = b);
  725. const _e = b - _;
  726. this.updateYUVCircular.add(_e);
  727. const et = this.cachedMetas[o];
  728. if ((c = et == null ? void 0 : et.traceIds) != null && c.length)
  729. for (const tt of et.traceIds) {
  730. if (this.traceIdMap.has(tt)) {
  731. const rt = this.traceIdMap.get(tt);
  732. if (rt != null) {
  733. (rt.displayTime = Date.now()), (rt.status = 3);
  734. const it = rt.receiveTime - rt.startTime,
  735. nt = rt.readyTime - rt.receiveTime,
  736. at = rt.displayTime - rt.readyTime,
  737. ot = rt.displayTime - rt.startTime;
  738. this.responseTimeArray.push(it),
  739. this.processTimeArray.push(nt),
  740. this.displayTimeArray.push(at),
  741. this.overallTimeArray.push(ot),
  742. this.traceIdMap.delete(tt);
  743. }
  744. }
  745. if (this.joyStickTraceIdMap.has(tt)) {
  746. const rt = this.joyStickTraceIdMap.get(tt);
  747. if (rt != null) {
  748. (rt.displayTime = Date.now()), (rt.status = 3);
  749. const it = rt.receiveTime - rt.startTime,
  750. nt = rt.readyTime - rt.receiveTime,
  751. at = rt.displayTime - rt.readyTime,
  752. ot = rt.displayTime - rt.startTime;
  753. this.joyStickResponseTimeArray.push(it),
  754. this.joyStickProcessTimeArray.push(nt),
  755. this.joyStickDisplayTimeArray.push(at),
  756. this.joyStickOverallTimeArray.push(ot),
  757. this.joyStickTraceIdMap.delete(tt);
  758. }
  759. }
  760. }
  761. if (
  762. (this.cachedPtss[o] == this.moveStartPts &&
  763. (this.MoveDisplayDelay = Date.now() - this.StartMovingTs),
  764. this.inMovingMode)
  765. ) {
  766. const tt = Date.now(),
  767. rt = tt - this.lastMoveDisplayTime;
  768. this.moveDisplayCircular.add(rt), (this.lastMoveDisplayTime = tt);
  769. }
  770. this.executeFunction("signal", {
  771. signal: this.cachedMetas[o],
  772. pts: this.cachedPtss[o],
  773. alreadyUpdateYUV: !0,
  774. }),
  775. (this.cachedRender[o] = !0),
  776. (this.getPtr = (this.getPtr + 1) % this.cachedLength);
  777. }
  778. }
  779. unmarshalPano(o) {
  780. const s = new DataView(o),
  781. c = s.getUint32(0);
  782. if (c == 1723558763) return !0;
  783. if (c != 2296221069) return !1;
  784. console.log("Receive Pano Message"), s.getUint16(4);
  785. const _ = s.getUint16(6),
  786. b = s.getUint32(8),
  787. k = s.getUint32(12),
  788. j = s.getUint32(16),
  789. $ = s.getUint32(20),
  790. _e = o.byteLength - _;
  791. if (_e == k) {
  792. const et = new Uint8Array(o).subarray(_).slice(0, j),
  793. rt = {
  794. data: new Uint8Array(o).subarray(_).slice(j, k),
  795. mediaLen: k - j,
  796. metadata: et,
  797. metaLen: j,
  798. tileId: b,
  799. };
  800. this.decoderWorker.postMessage({ t: 8, data: rt });
  801. } else {
  802. const et = new Uint8Array(o, _, _e);
  803. if (this.cachePanoTileID == b) {
  804. if (
  805. (this.panoCacheBuffer.set(et, $),
  806. (this.panoCacheSize += _e),
  807. this.panoCacheSize === k)
  808. ) {
  809. const tt = new Uint8Array(this.panoCacheBuffer).slice(0, j),
  810. it = {
  811. data: new Uint8Array(this.panoCacheBuffer).slice(j, k),
  812. mediaLen: k - j,
  813. metadata: tt,
  814. metaLen: j,
  815. tileId: b,
  816. };
  817. this.decoderWorker.postMessage({ t: 8, data: it }),
  818. (this.panoCacheSize = 0);
  819. }
  820. } else
  821. this.panoCacheBuffer.set(et, $),
  822. (this.panoCacheSize = _e),
  823. (this.cachePanoTileID = b);
  824. }
  825. return !0;
  826. }
  827. clearMoveArray() {
  828. (this.MovingTraceId = ""),
  829. (this.inMovingMode = !1),
  830. (this.StartMovingTs = 0),
  831. (this.MoveToFrameCnt = 0),
  832. (this.MoveResponseDelay = 0),
  833. (this.MoveProcessDelay = 0),
  834. (this.MoveDisplayDelay = 0),
  835. (this.moveStartPts = -1),
  836. this.moveResponseCircular.clear(),
  837. this.moveProcessCircular.clear(),
  838. this.moveDisplayCircular.clear(),
  839. (this.moveEvent = "");
  840. }
  841. getIsMoving(o) {
  842. let s;
  843. if (typeof o.newUserStates != "undefined")
  844. for (let c = 0; c < o.newUserStates.length; c++) {
  845. const _ = o.newUserStates[c];
  846. if (_.userId == this.rtcp.network.room.userId) {
  847. s = _.renderInfo.isMoving;
  848. break;
  849. }
  850. }
  851. return s;
  852. }
  853. isHeartBeatPacket(o, s) {
  854. const c = new DataView(o);
  855. if (c.getUint32(0) == 2009889916) {
  856. if (s > 4) {
  857. const b = c.getUint32(4),
  858. k = Date.now(),
  859. j = { MsgType: 2, HBMsg: { SentTs: b, ClientTs: k } };
  860. let $ = "";
  861. try {
  862. $ = JSON.stringify(j);
  863. } catch (et) {
  864. log$o.error(et);
  865. return;
  866. }
  867. const _e = "wasm:" + $;
  868. this._rtcp.sendStringData(_e),
  869. s > 8 &&
  870. ((this.serverHBMax = c.getUint32(8)),
  871. (this.serverHBAvg = c.getUint32(12)));
  872. }
  873. return !0;
  874. } else return !1;
  875. }
  876. resetSendTimeDiff() {
  877. (this.prevSenderTs = 0), this.serverSendTimeArray.clear();
  878. }
  879. calcSendTimeDiff(o) {
  880. if (this.prevSenderTs == -1) {
  881. this.prevSenderTs = o;
  882. return;
  883. }
  884. const s = o - this.prevSenderTs;
  885. this.serverSendTimeArray.add(s), (this.prevSenderTs = o);
  886. }
  887. unmarshalStream(o) {
  888. var ft, pt, gt, _t, mt, At, vt, Et, bt, St;
  889. const s = Date.now(),
  890. c = new DataView(o);
  891. if (c.getUint32(0) != 1437227610) return !1;
  892. c.getUint16(4);
  893. const b = c.getUint16(6),
  894. k = c.getUint16(8),
  895. j = k,
  896. $ = c.getUint16(10);
  897. let _e = !1;
  898. $ == 1 && (_e = !0);
  899. const et = c.getUint32(12),
  900. tt = c.getUint32(16),
  901. rt = c.getUint32(20),
  902. it = c.getUint16(24),
  903. nt = c.getUint16(26),
  904. at = c.getUint32(28),
  905. ot = c.getUint32(b - 4),
  906. st = et + tt,
  907. lt = o.byteLength - b,
  908. ut = new Uint8Array(o, b, lt);
  909. this.calcSendTimeDiff(rt);
  910. let ct;
  911. if (this.inPanoMode && (tt > 0 || it))
  912. return (
  913. log$o.error(
  914. "Stream Protocal Violation: receive illegal stream in Pano mode"
  915. ),
  916. !0
  917. );
  918. if (lt === st) {
  919. this.receivedMedia++;
  920. const Pt = new Uint8Array(o).subarray(b);
  921. rt - this.lastServerTS > 60
  922. ? this.serverFrameSlow++
  923. : rt - this.lastServerTS < 16 && this.serverFrameFast++;
  924. const Ct = Date.now();
  925. Ct - this.lastClientTS > 60
  926. ? this.clientFrameSlow++
  927. : Ct - this.lastClientTS < 16 && this.clientFrameFast++;
  928. const xt = tt === 0,
  929. Mt = rt - this.lastServerTS;
  930. this.lastServerTS != 0 &&
  931. ((k + 65536 - this.lastSeq) % 65536 === 1 &&
  932. this.lastIsPureMeta == xt &&
  933. (xt
  934. ? this.srvMetaIntervalCircular.add(Mt)
  935. : this.srvMediaIntervalCircular.add(Mt)),
  936. this.frameServerCircular.add(Mt),
  937. this.frameClientCircular.add(Ct - this.lastClientTS)),
  938. (this.lastSeq = k),
  939. (this.lastIsPureMeta = xt),
  940. (this.lastServerTS = rt),
  941. (this.lastClientTS = Ct);
  942. const Tt = Pt.subarray(0, et),
  943. It = Date.now(),
  944. Ot = JSON.parse(this.Stringify(Tt)),
  945. Bt = Date.now();
  946. this.showAllReceivedMetadata && console.log(rt, Ct, Ot),
  947. this.metaParseAraay.push(Bt - It),
  948. (ft = Ot.traceIds) != null &&
  949. ft.length &&
  950. this.processMetaWithTraceId(Ot),
  951. tt != 0 &&
  952. this.moveStartPts == -1 &&
  953. this.inMovingMode &&
  954. (this.moveStartPts = k),
  955. this.moveStartPts == k &&
  956. ((this.MoveResponseDelay = Date.now() - this.StartMovingTs),
  957. console.log(
  958. "move response delay: ",
  959. k,
  960. this.moveStartPts,
  961. this.MoveResponseDelay
  962. ));
  963. const wt = this.getIsMoving(Ot);
  964. if (
  965. (this.inMovingMode &&
  966. wt == 0 &&
  967. this.lastIsMoving == 1 &&
  968. this.clearMoveArray(),
  969. typeof wt != "undefined" && (this.lastIsMoving = wt),
  970. this.inMovingMode)
  971. ) {
  972. const Rt = Date.now(),
  973. Ft = Rt - this.lastMoveResponseTime;
  974. this.moveResponseCircular.add(Ft), (this.lastMoveResponseTime = Rt);
  975. }
  976. (it || nt) &&
  977. (ct =
  978. (mt =
  979. (_t =
  980. (gt =
  981. (pt = Ot.newUserStates) == null
  982. ? void 0
  983. : pt.find(
  984. (Rt) => Rt.userId === this._rtcp.network.room.userId
  985. )) == null
  986. ? void 0
  987. : gt.playerState) == null
  988. ? void 0
  989. : _t.player) == null
  990. ? void 0
  991. : mt.position);
  992. const Dt = {
  993. t: 0,
  994. data: Pt,
  995. mediaLen: tt,
  996. metaLen: et,
  997. metadata: Ot,
  998. frameCnt: j,
  999. server_ts: rt,
  1000. isIDR: _e,
  1001. cacheRequest: nt,
  1002. cached: it,
  1003. cachedKey: at,
  1004. position: ct,
  1005. };
  1006. if (this.inPanoMode)
  1007. return (
  1008. this.executeFunction("signal", {
  1009. signal: Ot,
  1010. pts: -1,
  1011. alreadyUpdateYUV: !0,
  1012. }),
  1013. !0
  1014. );
  1015. if (
  1016. (this.decoderWorker.postMessage(Dt, [Pt.buffer]),
  1017. !this.firstMediaReceived)
  1018. ) {
  1019. this.firstMediaArraval = Date.now();
  1020. const Rt = this.firstMediaArraval - this.rtcp.network.room._startTime;
  1021. log$o.infoAndReportMeasurement({
  1022. metric: "firstMediaArravalAt",
  1023. value: Rt,
  1024. group: "joinRoom",
  1025. }),
  1026. (this.firstMediaReceived = !0);
  1027. }
  1028. } else {
  1029. const Pt = this.hasFrmCntInCache(j);
  1030. if (Pt != -1)
  1031. if (
  1032. (this.cacheFrameComposes[Pt].buffer.set(ut, ot),
  1033. (this.cacheFrameComposes[Pt].size += lt),
  1034. this.cacheFrameComposes[Pt].size === st)
  1035. ) {
  1036. const Ct = new Uint8Array(this.cacheFrameComposes[Pt].buffer).slice(
  1037. 0,
  1038. st
  1039. );
  1040. (this.cacheFrameComposes[Pt].frameCnt = -1),
  1041. (this.cacheFrameComposes[Pt].size = 0),
  1042. (this.cacheFrameComposes[Pt].startReceiveTime = 0),
  1043. (this.cacheFrameComposes[Pt].serverTime = 0),
  1044. this.receivedMedia++,
  1045. rt - this.lastServerTS > 60
  1046. ? this.serverFrameSlow++
  1047. : rt - this.lastServerTS < 16 && this.serverFrameFast++;
  1048. const xt = Date.now();
  1049. xt - this.lastClientTS > 60
  1050. ? this.clientFrameSlow++
  1051. : xt - this.lastClientTS < 16 && this.clientFrameFast++,
  1052. this.lastServerTS != 0 &&
  1053. (this.frameServerCircular.add(rt - this.lastServerTS),
  1054. this.frameClientCircular.add(xt - this.lastClientTS)),
  1055. (this.lastServerTS = rt),
  1056. (this.lastClientTS = xt);
  1057. const Mt = Ct.subarray(0, et),
  1058. Tt = Date.now(),
  1059. It = JSON.parse(this.Stringify(Mt)),
  1060. Ot = Date.now();
  1061. this.showAllReceivedMetadata && console.log(rt, xt, It),
  1062. this.metaParseAraay.push(Ot - Tt),
  1063. (At = It.traceIds) != null &&
  1064. At.length &&
  1065. this.processMetaWithTraceId(It),
  1066. tt != 0 &&
  1067. this.moveStartPts == -1 &&
  1068. this.inMovingMode &&
  1069. (this.moveStartPts = k),
  1070. this.moveStartPts == k &&
  1071. (this.MoveResponseDelay = Date.now() - this.StartMovingTs);
  1072. const Bt = this.getIsMoving(It);
  1073. if (
  1074. (this.inMovingMode &&
  1075. Bt == 0 &&
  1076. this.lastIsMoving == 1 &&
  1077. this.clearMoveArray(),
  1078. typeof Bt != "undefined" && (this.lastIsMoving = Bt),
  1079. this.inMovingMode)
  1080. ) {
  1081. const Dt = Date.now(),
  1082. Rt = Dt - this.lastMoveResponseTime;
  1083. this.moveResponseCircular.add(Rt), (this.lastMoveResponseTime = Dt);
  1084. }
  1085. (it || nt) &&
  1086. (ct =
  1087. (St =
  1088. (bt =
  1089. (Et =
  1090. (vt = It.newUserStates) == null
  1091. ? void 0
  1092. : vt.find(
  1093. (Dt) => Dt.userId === this._rtcp.network.room.userId
  1094. )) == null
  1095. ? void 0
  1096. : Et.playerState) == null
  1097. ? void 0
  1098. : bt.player) == null
  1099. ? void 0
  1100. : St.position);
  1101. const wt = {
  1102. t: 0,
  1103. data: Ct,
  1104. mediaLen: tt,
  1105. metaLen: et,
  1106. metadata: It,
  1107. frameCnt: j,
  1108. server_ts: rt,
  1109. isIDR: _e,
  1110. cacheRequest: nt,
  1111. cached: it,
  1112. cachedKey: at,
  1113. position: ct,
  1114. };
  1115. if (this.inPanoMode)
  1116. return (
  1117. this.executeFunction("signal", {
  1118. signal: It,
  1119. pts: -1,
  1120. alreadyUpdateYUV: !0,
  1121. }),
  1122. !0
  1123. );
  1124. if (
  1125. (this.decoderWorker.postMessage(wt, [Ct.buffer]),
  1126. !this.firstMediaReceived)
  1127. ) {
  1128. this.firstMediaArraval = Date.now();
  1129. const Dt =
  1130. this.firstMediaArraval - this.rtcp.network.room._startTime;
  1131. log$o.infoAndReportMeasurement({
  1132. metric: "firstMediaArravalAt",
  1133. value: Dt,
  1134. group: "joinRoom",
  1135. }),
  1136. (this.firstMediaReceived = !0);
  1137. }
  1138. } else
  1139. this.cacheFrameComposes[Pt].size > st &&
  1140. log$o.debug(
  1141. "I frame exceed, cache size is ",
  1142. this.cacheSize,
  1143. ", total size is ",
  1144. st
  1145. );
  1146. else if (Pt == -1) {
  1147. let Ct = this.hasFrmCntInCache(-1);
  1148. if (Ct == -1) {
  1149. let xt = Date.now() + 1e18,
  1150. Mt = -1;
  1151. for (let Tt = 0; Tt < this.cacheFrameComposes.length; Tt++)
  1152. this.cacheFrameComposes[Tt].serverTime < xt &&
  1153. ((xt = this.cacheFrameComposes[Tt].serverTime), (Mt = Tt));
  1154. Ct = Mt;
  1155. }
  1156. this.cacheFrameComposes[Ct].buffer.set(ut, ot),
  1157. (this.cacheFrameComposes[Ct].size = lt),
  1158. (this.cacheFrameComposes[Ct].frameCnt = j),
  1159. (this.cacheFrameComposes[Ct].startReceiveTime = Date.now()),
  1160. (this.cacheFrameComposes[Ct].serverTime = rt);
  1161. }
  1162. }
  1163. const dt = Date.now() - s;
  1164. return this.unmarshalStreamExecutionArray.add(dt), !0;
  1165. }
  1166. reset() {
  1167. log$o.debug("Worker reset is called"),
  1168. (this.cacheFrameCnt = 0),
  1169. (this.receivedMedia = 0),
  1170. (this.reconnectSignal = !0),
  1171. this.decoderWorker.postMessage({ t: 4 });
  1172. }
  1173. dataHandleOff(o) {
  1174. log$o.debug("hhh");
  1175. }
  1176. dataHandle(o) {
  1177. this.saveframe &&
  1178. (this.decoderWorker.postMessage({ t: 6 }), (this.saveframe = !1)),
  1179. this.SaveMediaStream &&
  1180. (this.decoderWorker.postMessage({ t: 7 }), (this.SaveMediaStream = !1));
  1181. const s = new Uint8Array(o);
  1182. if (s.length >= 4 && this.isHeartBeatPacket(s.buffer, s.length) == !0)
  1183. return;
  1184. if (s.length > 36 && this.unmarshalStream(s.buffer) == !0) {
  1185. this.reconnectSignal &&
  1186. (this.executeFunction("reconnectedFrame", {}),
  1187. (this.reconnectSignal = !1));
  1188. return;
  1189. }
  1190. if (s.length > 20 && this.unmarshalPano(s.buffer) == !0) return;
  1191. this.noWasmBytesReceived += o.byteLength;
  1192. const c = JSON.parse(this.Stringify(s));
  1193. this.executeFunction("signal", {
  1194. signal: c,
  1195. pts: -1,
  1196. alreadyUpdateYUV: !0,
  1197. });
  1198. }
  1199. changePanoMode(o) {
  1200. this.inPanoMode = o;
  1201. }
  1202. uploadDataToServer() {
  1203. this.DynamicPanoTest == !0 &&
  1204. (this.onRotateInPanoMode({
  1205. traceId: "b2e1a296-6438-4371-8a31-687beb724ebe",
  1206. }),
  1207. (this.DynamicPanoTest = !1));
  1208. function o(cr, ur) {
  1209. return ur == -1 && (ur = 0), cr + ur;
  1210. }
  1211. function s(cr, ur) {
  1212. return Math.max(cr, ur);
  1213. }
  1214. const c =
  1215. this.responseTimeArray.reduce(o, 0) / this.responseTimeArray.length ||
  1216. 0,
  1217. _ =
  1218. this.processTimeArray.reduce(o, 0) / this.processTimeArray.length || 0,
  1219. b =
  1220. this.displayTimeArray.reduce(o, 0) / this.displayTimeArray.length || 0,
  1221. k =
  1222. this.overallTimeArray.reduce(o, 0) / this.overallTimeArray.length || 0,
  1223. j = this.overallTimeArray.length;
  1224. (this.responseTimeArray = []),
  1225. (this.processTimeArray = []),
  1226. (this.displayTimeArray = []),
  1227. (this.overallTimeArray = []);
  1228. const $ =
  1229. this.joyStickResponseTimeArray.reduce(o, 0) /
  1230. this.joyStickResponseTimeArray.length || 0,
  1231. _e =
  1232. this.joyStickProcessTimeArray.reduce(o, 0) /
  1233. this.joyStickProcessTimeArray.length || 0,
  1234. et =
  1235. this.joyStickDisplayTimeArray.reduce(o, 0) /
  1236. this.joyStickDisplayTimeArray.length || 0,
  1237. tt =
  1238. this.joyStickOverallTimeArray.reduce(o, 0) /
  1239. this.joyStickOverallTimeArray.length || 0,
  1240. rt = this.joyStickResponseTimeArray.reduce(s, 0),
  1241. it = this.joyStickProcessTimeArray.reduce(s, 0),
  1242. nt = this.joyStickDisplayTimeArray.reduce(s, 0),
  1243. at = this.joyStickOverallTimeArray.reduce(s, 0);
  1244. (this.joyStickResponseTimeArray = []),
  1245. (this.joyStickProcessTimeArray = []),
  1246. (this.joyStickDisplayTimeArray = []),
  1247. (this.joyStickOverallTimeArray = []);
  1248. const ot = this.moveResponseCircular.getThreshPercent(),
  1249. st = ot[0],
  1250. lt = ot[1],
  1251. ut = ot[2],
  1252. ct = ot[3],
  1253. ht = ot[4],
  1254. dt = ht - ct,
  1255. ft = 1 - lt / ht || 0,
  1256. pt = [st, lt - st, ut - lt, ct - ut, dt],
  1257. gt = this.moveProcessCircular.getThreshPercent(),
  1258. _t = gt[0],
  1259. mt = gt[1],
  1260. At = gt[2],
  1261. vt = gt[3],
  1262. Et = gt[4],
  1263. bt = Et - vt,
  1264. St = 1 - mt / Et || 0,
  1265. Pt = [_t, mt - _t, At - mt, vt - At, bt],
  1266. Ct = this.moveDisplayCircular.getThreshPercent(),
  1267. xt = Ct[0],
  1268. Mt = Ct[1],
  1269. Tt = Ct[2],
  1270. It = Ct[3],
  1271. Ot = Ct[4],
  1272. Bt = Ot - It,
  1273. wt = 1 - Mt / Ot || 0,
  1274. Dt = [xt, Mt - xt, Tt - Mt, It - Tt, Bt],
  1275. Rt = xt,
  1276. Ft = Mt - xt,
  1277. Nt = Tt - Mt,
  1278. Lt = It - Tt,
  1279. Ut = Bt,
  1280. zt = this.moveResponseCircular.getAvg(),
  1281. Gt = this.moveProcessCircular.getAvg(),
  1282. Ht = this.moveDisplayCircular.getAvg(),
  1283. Vt = this.moveResponseCircular.getMax(),
  1284. Wt = this.moveProcessCircular.getMax(),
  1285. Xt = this.moveDisplayCircular.getMax(),
  1286. $t = this.moveResponseCircular.getStandardDeviation(),
  1287. jt = this.moveProcessCircular.getStandardDeviation(),
  1288. Yt = this.moveDisplayCircular.getStandardDeviation();
  1289. this.moveResponseCircular.getIncomingAvg(),
  1290. this.moveProcessCircular.getIncomingAvg(),
  1291. this.moveDisplayCircular.getIncomingAvg(),
  1292. this.moveResponseCircular.getIncomingMax(),
  1293. this.moveProcessCircular.getIncomingMax(),
  1294. this.moveDisplayCircular.getIncomingMax(),
  1295. this.moveResponseCircular.clearIncoming(),
  1296. this.moveProcessCircular.clearIncoming(),
  1297. this.moveDisplayCircular.clearIncoming();
  1298. const er = this.frameServerCircular.getAvg(),
  1299. rr = this.frameServerCircular.getMax();
  1300. this.frameClientCircular.getAvg(), this.frameClientCircular.getMax();
  1301. const ir =
  1302. this.metaParseAraay.reduce(o, 0) / this.metaParseAraay.length || 0,
  1303. tr = this.metaParseAraay.reduce(s, 0);
  1304. this.metaParseAraay = [];
  1305. const or = this.unmarshalStreamExecutionArray.getStat(),
  1306. Jt = this.receiveYUVExecutionArray.getStat(),
  1307. Zt = this.postMessageWaitArray.getStat().max,
  1308. lr = {
  1309. mediaBytesReceived: this.mediaBytesReceived,
  1310. metaBytesReceived: this.metaBytesReceived,
  1311. packetsLost: this.packetsLost,
  1312. timestamp: Date.now(),
  1313. frameHeight: 1280,
  1314. frameWidth: 720,
  1315. framesReceived: this.receivedMedia,
  1316. framesReceivedWorker: this.receivedMedia_worker,
  1317. framesDecoded: this.receivedYUV,
  1318. framesEmited: this.receivedEmit,
  1319. decodeTimePerFrame: this.decodeTimePerFrame,
  1320. decodeTimeMaxFrame: this.decodeTimeMaxFrame,
  1321. packetsDrop: this.packetsDrop,
  1322. framesAwait: this.framesAwait,
  1323. firstMediaArraval: this.firstMediaArraval,
  1324. firstYUVDecoded: this.firstYUVDecoded,
  1325. firstRender: this.firstRender,
  1326. returnFrames: this.returnFrames,
  1327. sendOutBuffer: this.sendOutBuffer,
  1328. maxGraphicTime: this.updateYUVCircular.getMax(),
  1329. averageGraphicTime: this.updateYUVCircular.getAvg(),
  1330. jankTimes: this.JankTimes,
  1331. bigJankTimes: this.bigJankTimes,
  1332. decodeJankTimes: this.DecodeJankTimes,
  1333. bigDecodeJankTimes: this.bigDecodeJankTimes,
  1334. serverFrameSlow: this.serverFrameSlow,
  1335. serverFrameFast: this.serverFrameFast,
  1336. clientFrameSlow: this.clientFrameSlow,
  1337. clientFrameFast: this.clientFrameFast,
  1338. rtcMessageReceived: this.rtcMessageReceived,
  1339. rtcBytesReceived: this.rtcBytesReceived - this.noWasmBytesReceived,
  1340. noWasmBytesReceived: this.noWasmBytesReceived,
  1341. receiveIframes: this.receiveIframes,
  1342. decodeIframes: this.decodeIframes,
  1343. avgResponseTime: c,
  1344. avgProcessTime: _,
  1345. avgDisplayTime: b,
  1346. avgOverallTime: k,
  1347. overallTimeCount: j,
  1348. responseMiss: this.responseMiss,
  1349. processMiss: this.processMiss,
  1350. displayMiss: this.displayMiss,
  1351. updateDropFrame: this.updateDropFrame,
  1352. moveEvent: this.moveEvent,
  1353. avgResponseMoveDiff: this.moveEvent == "MoveTo" ? zt : 0,
  1354. avgProcessMoveDiff: this.moveEvent == "MoveTo" ? Gt : 0,
  1355. avgDisplayMoveDiff: this.moveEvent == "MoveTo" ? Ht : 0,
  1356. maxResponseMoveDiff: this.moveEvent == "MoveTo" ? Vt : 0,
  1357. maxProcessMoveDiff: this.moveEvent == "MoveTo" ? Wt : 0,
  1358. maxDisplayMoveDiff: this.moveEvent == "MoveTo" ? Xt : 0,
  1359. moveResponseJank: this.moveEvent == "MoveTo" ? ft : 0,
  1360. moveProcessJank: this.moveEvent == "MoveTo" ? St : 0,
  1361. moveDisplayJank: this.moveEvent == "MoveTo" ? wt : 0,
  1362. moveResponseCounts:
  1363. this.moveEvent == "MoveTo" ? pt.toString() : "0,0,0,0,0",
  1364. moveProcessCounts:
  1365. this.moveEvent == "MoveTo" ? Pt.toString() : "0,0,0,0,0",
  1366. moveDisplayCounts:
  1367. this.moveEvent == "MoveTo" ? Dt.toString() : "0,0,0,0,0",
  1368. MoveDisplayCountGood: this.moveEvent == "MoveTo" ? Rt.toString() : "0",
  1369. MoveDisplayCountWell: this.moveEvent == "MoveTo" ? Ft.toString() : "0",
  1370. MoveDisplayCountFair: this.moveEvent == "MoveTo" ? Nt.toString() : "0",
  1371. MoveDisplayCountBad: this.moveEvent == "MoveTo" ? Lt.toString() : "0",
  1372. MoveDisplayCountRest: this.moveEvent == "MoveTo" ? Ut.toString() : "0",
  1373. moveResponseDelay:
  1374. this.moveEvent == "MoveTo" ? this.MoveResponseDelay : 0,
  1375. moveProcessDelay:
  1376. this.moveEvent == "MoveTo" ? this.MoveProcessDelay : 0,
  1377. moveDisplayDelay:
  1378. this.moveEvent == "MoveTo" ? this.MoveDisplayDelay : 0,
  1379. sdMoveResponseLongTime: $t,
  1380. sdMoveProcessLongTime: jt,
  1381. sdMoveDisplayLongTime: Yt,
  1382. avgResponseFlyDiff:
  1383. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1384. ? zt
  1385. : 0,
  1386. avgProcessFlyDiff:
  1387. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1388. ? Gt
  1389. : 0,
  1390. avgDisplayFlyDiff:
  1391. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1392. ? Ht
  1393. : 0,
  1394. maxResponseFlyDiff:
  1395. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1396. ? Vt
  1397. : 0,
  1398. maxProcessFlyDiff:
  1399. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1400. ? Wt
  1401. : 0,
  1402. maxDisplayFlyDiff:
  1403. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1404. ? Xt
  1405. : 0,
  1406. flyResponseJank:
  1407. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1408. ? ft
  1409. : 0,
  1410. flyProcessJank:
  1411. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1412. ? St
  1413. : 0,
  1414. flyDisplayJank:
  1415. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1416. ? wt
  1417. : 0,
  1418. flyResponseCounts:
  1419. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1420. ? pt.toString()
  1421. : "0,0,0,0,0",
  1422. flyProcessCounts:
  1423. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1424. ? Pt.toString()
  1425. : "0,0,0,0,0",
  1426. flyDisplayCounts:
  1427. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1428. ? Dt.toString()
  1429. : "0,0,0,0,0",
  1430. flyResponseDelay:
  1431. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1432. ? this.MoveResponseDelay
  1433. : 0,
  1434. flyProcessDelay:
  1435. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1436. ? this.MoveProcessDelay
  1437. : 0,
  1438. flyDisplayDelay:
  1439. this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship"
  1440. ? this.MoveDisplayDelay
  1441. : 0,
  1442. avgMetaParseTime: ir,
  1443. maxMetaParseTime: tr,
  1444. avgServerDiff: er,
  1445. maxServerDiff: rr,
  1446. unmarshalStreamStat: or,
  1447. receiveYUVStat: Jt,
  1448. maxPostMsgDiff: Zt,
  1449. serverHBMax: this.serverHBMax,
  1450. serverHBAvg: this.serverHBAvg,
  1451. streamType: WASM_Version,
  1452. avgJoyStickResponseTime: $,
  1453. avgJoyStickProcessTime: _e,
  1454. avgJoyStickDisplayTime: et,
  1455. avgJoyStickOverallTime: tt,
  1456. maxJoyStickResponseTime: rt,
  1457. maxJoyStickProcessTime: it,
  1458. maxJoyStickDisplayTime: nt,
  1459. maxJoyStickOverallTime: at,
  1460. };
  1461. return (
  1462. (this.lastReturnFrames = this.returnFrames),
  1463. (this.lastReceivedEmit = this.receivedEmit),
  1464. lr
  1465. );
  1466. }
  1467. }