@video-supply/dahua-player 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +1 -0
  3. package/README.md +192 -0
  4. package/README.zh-CN.md +202 -0
  5. package/dist/bin/copy-assets.cjs +51 -0
  6. package/dist/bin/copy-assets.cjs.map +1 -0
  7. package/dist/index.cjs +1447 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.d.cts +157 -0
  10. package/dist/index.d.ts +157 -0
  11. package/dist/index.js +1418 -0
  12. package/dist/index.js.map +1 -0
  13. package/package.json +55 -0
  14. package/wsplayer-gov/Version.xml +4 -0
  15. package/wsplayer-gov/WSPlayer/PlaySDKInterface.js +1 -0
  16. package/wsplayer-gov/WSPlayer/WSPlayer.js +1 -0
  17. package/wsplayer-gov/WSPlayer/audioTalkWorker.js +1 -0
  18. package/wsplayer-gov/WSPlayer/commonThread/libH264Enc.js +21 -0
  19. package/wsplayer-gov/WSPlayer/commonThread/libH264Enc.wasm +0 -0
  20. package/wsplayer-gov/WSPlayer/commonThread/libIVSDrawer.js +21 -0
  21. package/wsplayer-gov/WSPlayer/commonThread/libIVSDrawer.wasm +0 -0
  22. package/wsplayer-gov/WSPlayer/commonThread/libRenderEngine.js +21 -0
  23. package/wsplayer-gov/WSPlayer/commonThread/libRenderEngine.wasm +0 -0
  24. package/wsplayer-gov/WSPlayer/commonThread/libmavasp_litepacket.data +50 -0
  25. package/wsplayer-gov/WSPlayer/commonThread/libmavasp_litepacket.js +21 -0
  26. package/wsplayer-gov/WSPlayer/commonThread/libmavasp_litepacket.wasm +0 -0
  27. package/wsplayer-gov/WSPlayer/icon/RecordHover.svg +13 -0
  28. package/wsplayer-gov/WSPlayer/icon/RecordNormal.svg +13 -0
  29. package/wsplayer-gov/WSPlayer/icon/Recording.svg +15 -0
  30. package/wsplayer-gov/WSPlayer/icon/arrow-b.svg +9 -0
  31. package/wsplayer-gov/WSPlayer/icon/arrow-l.svg +9 -0
  32. package/wsplayer-gov/WSPlayer/icon/arrow-lb.svg +10 -0
  33. package/wsplayer-gov/WSPlayer/icon/arrow-lt.svg +10 -0
  34. package/wsplayer-gov/WSPlayer/icon/arrow-r.svg +9 -0
  35. package/wsplayer-gov/WSPlayer/icon/arrow-rb.svg +10 -0
  36. package/wsplayer-gov/WSPlayer/icon/arrow-rt.svg +10 -0
  37. package/wsplayer-gov/WSPlayer/icon/arrow-t.svg +9 -0
  38. package/wsplayer-gov/WSPlayer/icon/close-all-hover.svg +18 -0
  39. package/wsplayer-gov/WSPlayer/icon/close-all.svg +18 -0
  40. package/wsplayer-gov/WSPlayer/icon/close.svg +16 -0
  41. package/wsplayer-gov/WSPlayer/icon/close_hover.svg +16 -0
  42. package/wsplayer-gov/WSPlayer/icon/default.png +0 -0
  43. package/wsplayer-gov/WSPlayer/icon/draw-triangle_off.svg +14 -0
  44. package/wsplayer-gov/WSPlayer/icon/draw-triangle_off_hover.svg +14 -0
  45. package/wsplayer-gov/WSPlayer/icon/draw-triangle_on.svg +15 -0
  46. package/wsplayer-gov/WSPlayer/icon/draw-triangle_on_hover.svg +15 -0
  47. package/wsplayer-gov/WSPlayer/icon/fullscreen-hover.svg +13 -0
  48. package/wsplayer-gov/WSPlayer/icon/fullscreen.svg +13 -0
  49. package/wsplayer-gov/WSPlayer/icon/more.svg +13 -0
  50. package/wsplayer-gov/WSPlayer/icon/play-h.png +0 -0
  51. package/wsplayer-gov/WSPlayer/icon/play-n.png +0 -0
  52. package/wsplayer-gov/WSPlayer/icon/play-p.png +0 -0
  53. package/wsplayer-gov/WSPlayer/icon/ptz-icon1.svg +4 -0
  54. package/wsplayer-gov/WSPlayer/icon/ptz-icon2.svg +13 -0
  55. package/wsplayer-gov/WSPlayer/icon/ptz-icon3.svg +10 -0
  56. package/wsplayer-gov/WSPlayer/icon/ptz-icon4.svg +10 -0
  57. package/wsplayer-gov/WSPlayer/icon/ptz-icon5.svg +12 -0
  58. package/wsplayer-gov/WSPlayer/icon/ptz-icon6.svg +14 -0
  59. package/wsplayer-gov/WSPlayer/icon/ptz-select-hover.svg +3 -0
  60. package/wsplayer-gov/WSPlayer/icon/ptz-select.svg +3 -0
  61. package/wsplayer-gov/WSPlayer/icon/record_pause.svg +5 -0
  62. package/wsplayer-gov/WSPlayer/icon/record_play.svg +5 -0
  63. package/wsplayer-gov/WSPlayer/icon/screen_1.svg +11 -0
  64. package/wsplayer-gov/WSPlayer/icon/screen_16.svg +18 -0
  65. package/wsplayer-gov/WSPlayer/icon/screen_16_hover.svg +18 -0
  66. package/wsplayer-gov/WSPlayer/icon/screen_1_hover.svg +11 -0
  67. package/wsplayer-gov/WSPlayer/icon/screen_2.svg +18 -0
  68. package/wsplayer-gov/WSPlayer/icon/screen_25.svg +19 -0
  69. package/wsplayer-gov/WSPlayer/icon/screen_25_hover.svg +19 -0
  70. package/wsplayer-gov/WSPlayer/icon/screen_2_hover.svg +18 -0
  71. package/wsplayer-gov/WSPlayer/icon/screen_3.svg +13 -0
  72. package/wsplayer-gov/WSPlayer/icon/screen_3_hover.svg +13 -0
  73. package/wsplayer-gov/WSPlayer/icon/screen_4.svg +12 -0
  74. package/wsplayer-gov/WSPlayer/icon/screen_4_hover.svg +12 -0
  75. package/wsplayer-gov/WSPlayer/icon/screen_6.svg +16 -0
  76. package/wsplayer-gov/WSPlayer/icon/screen_6_hover.svg +16 -0
  77. package/wsplayer-gov/WSPlayer/icon/screen_8.svg +18 -0
  78. package/wsplayer-gov/WSPlayer/icon/screen_8_hover.svg +18 -0
  79. package/wsplayer-gov/WSPlayer/icon/screen_9.svg +17 -0
  80. package/wsplayer-gov/WSPlayer/icon/screen_9_hover.svg +17 -0
  81. package/wsplayer-gov/WSPlayer/icon/screen_custom_division.svg +9 -0
  82. package/wsplayer-gov/WSPlayer/icon/screen_custom_division_hover.svg +9 -0
  83. package/wsplayer-gov/WSPlayer/icon/screen_custom_division_merge.svg +3 -0
  84. package/wsplayer-gov/WSPlayer/icon/screen_custom_division_split.svg +6 -0
  85. package/wsplayer-gov/WSPlayer/icon/screen_more.svg +15 -0
  86. package/wsplayer-gov/WSPlayer/icon/snapshot.svg +38 -0
  87. package/wsplayer-gov/WSPlayer/icon/snapshot_hover.svg +38 -0
  88. package/wsplayer-gov/WSPlayer/icon/speed_left.svg +15 -0
  89. package/wsplayer-gov/WSPlayer/icon/speed_right.svg +15 -0
  90. package/wsplayer-gov/WSPlayer/icon/spread.png +0 -0
  91. package/wsplayer-gov/WSPlayer/icon/talk-off-hover.svg +11 -0
  92. package/wsplayer-gov/WSPlayer/icon/talk-off.svg +11 -0
  93. package/wsplayer-gov/WSPlayer/icon/talk-on.svg +9 -0
  94. package/wsplayer-gov/WSPlayer/icon/voice-have.svg +43 -0
  95. package/wsplayer-gov/WSPlayer/icon/voice-have_hover.svg +43 -0
  96. package/wsplayer-gov/WSPlayer/icon/voice-null.svg +38 -0
  97. package/wsplayer-gov/WSPlayer/icon/voice-null_hover.svg +38 -0
  98. package/wsplayer-gov/WSPlayer/icon/ws-ctrl-ellipsis-hover.svg +14 -0
  99. package/wsplayer-gov/WSPlayer/icon/ws-ctrl-ellipsis.svg +14 -0
  100. package/wsplayer-gov/WSPlayer/locale/lang/en_US.js +123 -0
  101. package/wsplayer-gov/WSPlayer/locale/lang/zh_CN.js +124 -0
  102. package/wsplayer-gov/WSPlayer/locale/localProvider.js +7 -0
  103. package/wsplayer-gov/WSPlayer/locale/locale.js +34 -0
  104. package/wsplayer-gov/WSPlayer/multiThread/libStreamClient.js +21 -0
  105. package/wsplayer-gov/WSPlayer/multiThread/libStreamClient.wasm +0 -0
  106. package/wsplayer-gov/WSPlayer/multiThread/libStreamClient.worker.js +1 -0
  107. package/wsplayer-gov/WSPlayer/multiThread/libplay.data +0 -0
  108. package/wsplayer-gov/WSPlayer/multiThread/libplay.js +1 -0
  109. package/wsplayer-gov/WSPlayer/multiThread/libplay.wasm +0 -0
  110. package/wsplayer-gov/WSPlayer/multiThread/libplay.worker.js +1 -0
  111. package/wsplayer-gov/WSPlayer/player.css +1098 -0
  112. package/wsplayer-gov/WSPlayer/singleThread/VideoDecodeWorker.js +1245 -0
  113. package/wsplayer-gov/WSPlayer/singleThread/libStreamClient.js +21 -0
  114. package/wsplayer-gov/WSPlayer/singleThread/libStreamClient.wasm +0 -0
  115. package/wsplayer-gov/WSPlayer/singleThread/libplay.data +0 -0
  116. package/wsplayer-gov/WSPlayer/singleThread/libplay.js +1 -0
  117. package/wsplayer-gov/WSPlayer/singleThread/libplay.wasm +0 -0
  118. package/wsplayer-gov/WSPlayer/window.division.css +80 -0
  119. package/wsplayer-gov/wsplayer.min.js +6 -0
@@ -0,0 +1,1245 @@
1
+ let SDKModule;
2
+
3
+ const VIDEO_FRAME_SUB_TYPE_I = 0; //I帧
4
+ const VIDEO_FRAME_SUB_TYPE_P = 1; //P帧
5
+ const VIDEO_FRAME_SUB_TYPE_B = 2; //B帧
6
+ const VIDEO_FRAME_SUB_TYPE_SMART_I = 18; //智能I帧
7
+ const VIDEO_FRAME_SUB_TYPE_SMART_P = 19; //智能P帧
8
+ const VIDEO_FRAME_SUB_TYPE_SMART_I_NORENDER = 20; //智能I帧,但不显示
9
+
10
+ const ENCODE_TYPE_VIDEO_HI_H264 = 2; //海思H.264编码格式
11
+ const ENCODE_TYPE_VIDEO_MY_H264 = 4; //公司H.264编码格式
12
+ const ENCODE_TYPE_VIDEO_STD_H264 = 8; //标准H.264编码格式
13
+ const ENCODE_TYPE_VIDEO_H265 = 12; //H.265编码格式
14
+
15
+ const DATA_RECORD_MP4 = 5; //录制MP4格式
16
+
17
+ const SP_STREAM_TYPE_DHSTD = 8; //dav编码格式
18
+ const STREAM_TYPE_SVC = 13; //H.264 SVC编码格式
19
+ const SP_STREAM_TYPE_FLV = 18; //flv编码格式
20
+
21
+ const ENCRYPT_UNKOWN = 0; //未知加密类型
22
+ const ENCRYPT_AES = 1; //AES加密类型,16进制数组格式
23
+ const ENCRYPT_AES256 = 2; //AES256加密类型,16进制数组格式
24
+ const ENCRYPT_AES_STRING_FORMAT = 3; //AES加密类型,字符串格式
25
+
26
+ const CACHE_MODE_OFF = 0; //关闭实时流自适应缓冲模式
27
+ const ADAPTIVE_CACHE = 1; //自适应缓冲
28
+ const REALTIME_FIRST = 2; //实时优先
29
+ const FLUENCY_FIRST = 3; //流畅优先
30
+ const FRAME_SCENE_POINTS_INFOR_SIZE = 144; // 景物点信息单组信息长度
31
+ /* IVS类型 */
32
+ var IVS_TYPE =
33
+ {
34
+ IVSINFOTYPE_PRESETPOS : 1,
35
+ IVSINFOTYPE_MOTINTRKS : 2,
36
+ IVSINFOTYPE_MOTINTRKS_EX : 3,
37
+ IVSINFOTYPE_LIGHT : 4, // 光照
38
+ IVSINFOTYPE_RAWDATA : 5, // jason数据
39
+ IVSINFOTYPE_TRACK : 6, // 智能分析信息
40
+ IVSINFOTYPE_TRACK_EX_B0 : 7, // 智能结构化数据信息
41
+ IVSINFOTYPE_MOTIONFRAME : 9,
42
+ IVSINFOTYPE_VIDEO_CONCENTRATION : 10,
43
+ IVSINFOTYPE_OVERLAY_PIC : 11, // 叠加图片帧
44
+ IVSINFOTYPE_OSD_INFO : 12, // OSD辅助帧
45
+ IVSINFOTYPE_GPS_INFO : 13, // GPS辅助帧
46
+ IVSINFOTYPE_TAGGING_INFO : 14, // 景物点信息标注帧,辅助帧(0x13)
47
+ IVSINFOTYPE_TRACK_A1 : 15, // NVR浓缩信息轨迹点
48
+ IVSINFOTYPE_DATA_WITH_LARGE_AMOUNT : 16,
49
+ IVSINFOTYPE_TRACK_A1_EX : 17, // NVR浓缩信息轨迹点(扩展)
50
+ IVSINFOTYPE_DATA_WITH_WATER_LEVEL_MONITOR : 18, //水位检测水位尺信息帧(0x17)
51
+ IVSINFOTYPE_INTELFLOW : 19, // 智能客流量
52
+ IVSINFOTYPE_DATA_WITH_SOUND_DECIBEL : 20, //声音警报分贝值信息帧(0x18)
53
+ IVSINFOTYPE_DATA_WITH_SMART_MOTION : 21, //智能动检信息帧(0x19)
54
+ IVSINFOTYPE_DHOP_SMART : 22, //开放平台智能帧(0x14)
55
+ IVSINFOTYPE_TRAFFIC_LIGHT : 23, //交通信号灯(红绿灯)辅助帧(0x1D)
56
+ IVSINFOTYPE_PTZ_LOCATION : 24, //云台位置帧(0x21)
57
+ };
58
+
59
+ var DRAW_TYPE =
60
+ {
61
+ DRAW_JSON : 0,
62
+ DRAW_TRACK : 1,
63
+ DRAW_ALARM : 2,
64
+ DRAW_RULE : 3,
65
+ DRAW_MOVE_CHECK : 7,
66
+ DRAW_TEST : 9,
67
+ DRAW_WEB_RULE : 11,
68
+ DRAW_WEB_ALARM : 12,
69
+ DRAW_FLOW_INFO : 13,
70
+ DRAW_TRACKEX2 : 14,
71
+ DRAW_WUXI235_TRACKEX2 : 15,
72
+ DRAW_TRACKEXA1 : 16,
73
+ DRAW_TRACKEX2_TYPE_HUMAN : 17,
74
+ DRAW_TRACKEX2_TYPE_VEHICLE : 18,
75
+ DRAW_TRACKEX2_TYPE_NONMOTOR : 19,
76
+ DRAW_TRACKEX2_TYPE_SHOPPRESENCE : 20,
77
+ DRAW_TRACKEX2_TYPE_FLOWBUSINESS : 21,
78
+ DRAW_INTELFLOW : 22,
79
+ DRAW_SMARTMOTION : 23,
80
+ DRAW_DHOPSMART : 24,
81
+ DRAW_DATA_WITH_LARGE_AMOUNT : 25,//大数据量帧
82
+ DRAW_TRACKEX2_TYPE_BAG : 26,
83
+ DRAW_RULE_HIGHWAY_LANES : 27, //高速车道线
84
+ DRAW_WATER_LEVEL_MONITOR : 28, //水位尺
85
+ DRAW_END : 29
86
+ };
87
+
88
+ //DHOP元素类型
89
+ var IVS_DHOP_ElEMENT_TYPE =
90
+ {
91
+ EM_DHOP_CIRCLE : 1,
92
+ EM_DHOP_BrokenLine : 2,
93
+ EM_DHOP_POLYGON : 3,
94
+ EM_DHOP_TEXT : 4
95
+ };
96
+
97
+ importScripts('libplay.js');
98
+
99
+ addEventListener('message', receiveMessage, false);
100
+
101
+ Module.onRuntimeInitialized = function(){
102
+ m_bLoadSuccess = true;
103
+ var msgType = 'LoadSuccess';
104
+ sendMessage(m_nPlayPort, msgType, null);
105
+ }
106
+
107
+ var m_bPlayback = 0;
108
+ var m_bSupportH264MSE = false;
109
+ var m_bSupportH265MSE = false;
110
+ var m_nCanvasWidth = 1920;
111
+ var m_nCanvasHeight = 1080;
112
+ var m_nPlayPort = 0;
113
+
114
+ var jsInputData = null;
115
+ var jsInputDataAry = null;
116
+
117
+ var jsFrameBuf = null;
118
+ var jsFrameInfo = null;
119
+ let dataView = null;
120
+
121
+ var jsBuf = null;
122
+ var jsFrameBodyData = null;
123
+
124
+ var jsBufY = null;
125
+ var jsBufU = null;
126
+ var jsBufV = null;
127
+ var jsYuvDataY = null;
128
+ var jsYuvDataU = null;
129
+ var jsYuvDataV = null;
130
+
131
+ var jsRecordFrameBuf = null;
132
+ var jsRecordFrameInfo = null;
133
+ var dataViewRecord = null;
134
+
135
+ let ivsBuf = null;
136
+ let ivsDataArray = null;
137
+ let ivsDataView = null;
138
+
139
+ var m_nWidth = 0;
140
+ var m_nHeight = 0;
141
+ var m_nPreWidth = 0;
142
+ var m_nPreHeight = 0;
143
+
144
+ var m_bSmartEncode = 0;
145
+ var m_nVideoEncodeType = 0;
146
+
147
+ var m_bLoadSuccess = false;
148
+
149
+ var m_bDecryptionResult = false;
150
+
151
+ var m_nTotalStreamLength = 0;
152
+
153
+ function receiveMessage(event)
154
+ {
155
+ if (!m_bLoadSuccess)
156
+ {
157
+ return;
158
+ }
159
+ var message = event.data;
160
+ switch (message.nType)
161
+ {
162
+ //初始化
163
+ case 'Init':
164
+ m_bPlayback = message.option.bPlayback;
165
+ m_bSupportH264MSE = message.option.bSupportH264MSE;
166
+ m_bSupportH265MSE = message.option.bSupportH265MSE;
167
+ m_nCanvasWidth = message.option.nCanvasWidth;
168
+ m_nCanvasHeight = message.option.nCanvasHeight;
169
+ Init();
170
+ break;
171
+ //送流
172
+ case 'InputData':
173
+ InputData(message.pData);
174
+ break;
175
+ //打开智能绘制
176
+ case 'OpenIVSDraw':
177
+ OpenIVSDraw();
178
+ break;
179
+ //关闭智能绘制
180
+ case 'CloseIVSDraw':
181
+ CloseIVSDraw();
182
+ break;
183
+ //开始码流录制
184
+ case 'StartRecord':
185
+ StartRecord(message.nRecordType);
186
+ break;
187
+ //停止码流录制
188
+ case 'StopRecord':
189
+ StopRecord();
190
+ break;
191
+ //设置播放速度
192
+ case 'SetPlaySpeed':
193
+ SetPlaySpeed(message.nSpeed);
194
+ break;
195
+ //设置OSD叠加
196
+ case 'SetYUVOSDInfoEx':
197
+ SetYUVOSDInfoEx(message.OSDInfo);
198
+ break;
199
+ case 'GetOriginalKeyCallBack':
200
+ GetOriginalKey(message.playToken, message.playTokenKey, message.deviceID);
201
+ break;
202
+ case 'SetWebSecurityKey':
203
+ SetWebSecurityKey(message.nDecryptType, message.nFrameType, message.strKey, message.stStreamInfo);
204
+ break;
205
+ //设置解密秘钥
206
+ case 'SetSecurityKey':
207
+ SetSecurityKey(message.nEncryptType, message.szKey, message.nKeyLen, message.szKeyId, message.nKeyIdLen);
208
+ break;
209
+ //设置是否支持硬解码标记
210
+ case 'SetSupportWebMSE':
211
+ m_bSupportH264MSE = message.bSupportH264MSE;
212
+ m_bSupportH265MSE = message.bSupportH265MSE;
213
+ SetSupportWebMSE(m_bSupportH264MSE, m_bSupportH265MSE);
214
+ //暂停播放
215
+ case 'Pause':
216
+ Pause(message.bPause);
217
+ break;
218
+ //抓图
219
+ case 'CatchPic':
220
+ CatchPic();
221
+ break;
222
+ //停止播放
223
+ case 'Stop':
224
+ Stop();
225
+ break;
226
+ case 'setPrintLogLevel':
227
+ SetPrintLogLevel(message.nLogLevel);
228
+ break;
229
+ default:
230
+ break;
231
+ }
232
+ }
233
+
234
+ function Init()
235
+ {
236
+ //获取PlaySDK空闲端口号
237
+ var jsPort = Module._malloc(1);
238
+ var jsPortAry = new Uint8Array(Module.HEAPU8.buffer, jsPort, 1);
239
+ Module._PLAY_GetFreePort(jsPortAry.byteOffset);
240
+ m_nPlayPort = jsPortAry[0];
241
+ jsPortAry = null;
242
+ Module._free(jsPort);
243
+
244
+ //设置播放窗口宽高属性
245
+ Module._PLAY_ViewResolutionChanged(m_nPlayPort, m_nCanvasWidth, m_nCanvasHeight, 0);
246
+
247
+ //设置实时流模式
248
+ var nRet = Module._PLAY_SetStreamOpenMode(m_nPlayPort, m_bPlayback);
249
+ nRet = Module._PLAY_OpenStream(m_nPlayPort, 0, 0, 10*1024*1024);
250
+
251
+ nRet = Module._PLAY_SetSupportWebMSE(m_nPlayPort, m_bSupportH264MSE, m_bSupportH265MSE);
252
+
253
+ nRet = Module._PLAY_Play(m_nPlayPort, 1);
254
+ if (nRet)
255
+ {
256
+ //向C++层申请一块wasm内存,用于接收码流
257
+ jsInputData = Module._malloc(5*1024*1024);
258
+ jsInputDataAry = new Uint8Array(Module.HEAPU8.buffer, jsInputData, 5*1024*1024);
259
+
260
+ var msgType = 'InitSuccess';
261
+ sendMessage(m_nPlayPort, msgType, null);
262
+ }
263
+ }
264
+
265
+ function InputData(data)
266
+ {
267
+ m_nTotalStreamLength += data.length;
268
+
269
+ if(jsInputDataAry)
270
+ {
271
+ jsInputDataAry.set(data);
272
+ var nRet = Module._PLAY_InputData(m_nPlayPort, jsInputDataAry.byteOffset, data.length);
273
+ var i = 0;
274
+ }
275
+ }
276
+
277
+ function OpenIVSDraw()
278
+ {
279
+ Module._PLAY_RenderPrivateData(m_nPlayPort, 1, 0);
280
+ }
281
+
282
+ function CloseIVSDraw()
283
+ {
284
+ Module._PLAY_RenderPrivateData(m_nPlayPort, 0, 0);
285
+ }
286
+
287
+ function StartRecord(nRecordType)
288
+ {
289
+ Module._PLAY_StartDataRecord(m_nPlayPort, 0, nRecordType);
290
+ }
291
+
292
+ function StopRecord()
293
+ {
294
+ Module._PLAY_StopDataRecord(m_nPlayPort);
295
+ }
296
+
297
+ function SetPlaySpeed(nSpeed)
298
+ {
299
+ Module._PLAY_SetPlaySpeed(m_nPlayPort, nSpeed);
300
+ }
301
+
302
+ function SetYUVOSDInfoEx(OSDInfo)
303
+ {
304
+ if (0 == m_nCanvasWidth || 0 == m_nCanvasHeight)
305
+ {
306
+ return;
307
+ }
308
+
309
+ let nOsdCount = OSDInfo.osdCount;
310
+ let nStuOsdInfoSize = 18376;//单个YUV_OSD_INFO_EX结构体18376字节
311
+ const OsdDataInfoPtr = Module._malloc(nStuOsdInfoSize);
312
+ let arrayFormat = new Uint8Array(Module.HEAPU8.buffer);
313
+ for (let i = 0; i < nStuOsdInfoSize; i ++)
314
+ {
315
+ arrayFormat[OsdDataInfoPtr + i] = 0;
316
+ }
317
+
318
+ Module.HEAPU8[OsdDataInfoPtr + 0] = 1;//是否是私有字体
319
+ let strFontPath = "Font.bin";
320
+ let nSequence = 0;
321
+ strFontPath.split('').forEach((char, nIndex) =>
322
+ {
323
+ let nValue = char.charCodeAt(0);
324
+ arrayFormat[OsdDataInfoPtr + nSequence + 1] = nValue;
325
+ nSequence++;
326
+ });
327
+
328
+ Module.HEAP32[OsdDataInfoPtr/4 + 65] = nOsdCount;
329
+ for (let i = 0; i < nOsdCount; i ++)
330
+ {
331
+ let nPointX = OSDInfo.osdList[i].pointX / m_nCanvasWidth * m_nWidth;
332
+ let nPointY = OSDInfo.osdList[i].pointY / m_nCanvasHeight * m_nHeight;
333
+
334
+ Module.HEAP32[OsdDataInfoPtr/4 + 66 + 564/4 * i] = nPointX;// 旋转点像素x位置
335
+ Module.HEAP32[OsdDataInfoPtr/4 + 67 + 564/4 * i] = nPointY;// 旋转点像素y位置
336
+ Module.HEAP32[OsdDataInfoPtr/4 + 68 + 564/4 * i] = OSDInfo.osdList[i].colorR;// osd叠加颜色r,范围0-255
337
+ Module.HEAP32[OsdDataInfoPtr/4 + 69 + 564/4 * i] = OSDInfo.osdList[i].colorG;// osd叠加颜色g,范围0-255
338
+ Module.HEAP32[OsdDataInfoPtr/4 + 70 + 564/4 * i] = OSDInfo.osdList[i].colorB;// osd叠加颜色b,范围0-255
339
+ Module.HEAP32[OsdDataInfoPtr/4 + 71 + 564/4 * i] = OSDInfo.osdList[i].colorA;// osd叠加透明度,范围0-255
340
+
341
+ nSequence = 0;
342
+ //JS默认采用UTF-16编码,需要先转为UTF-8编码
343
+ let UTF8Array = UTF16ToUTF8(OSDInfo.osdList[i].strOsdData);
344
+ for(let j = 0; j < UTF8Array.length; j++)
345
+ {
346
+ arrayFormat[(OsdDataInfoPtr + nSequence + 288 + 564 * i) >> 0] = UTF8Array[j];// osd数据,使用utf-8编码
347
+ nSequence++;
348
+ }
349
+
350
+ Module.HEAP32[OsdDataInfoPtr/4 + 200 + 564/4 * i] = OSDInfo.osdList[i].fontX;// 字体宽度, 使用私有字体时无效
351
+ Module.HEAP32[OsdDataInfoPtr/4 + 201 + 564/4 * i] = OSDInfo.osdList[i].fontY;// 字体高度, 最大512
352
+ Module.HEAP32[OsdDataInfoPtr/4 + 202 + 564/4 * i] = OSDInfo.osdList[i].rotateAngle;// 旋转角度,范围0-359度
353
+ Module.HEAPU8[OsdDataInfoPtr + 812 + 564 * i] = OSDInfo.osdList[i].coordinate8192;// 8192坐标系, 0表示像素坐标x,y基于码流分辨率, 1表示基于8192坐标系
354
+ }
355
+ Module._PLAY_SetYUVOSDInfoEx(m_nPlayPort, OsdDataInfoPtr);
356
+
357
+ Module._free(OsdDataInfoPtr);
358
+ }
359
+
360
+ function GetOriginalKey(playToken, playTokenKey, deviceID)
361
+ {
362
+ var arrPlayToken = Module.intArrayFromString(playToken).concat(0);//add '\0'
363
+ var playTokenPtr = Module._malloc(arrPlayToken.length);//采用声明的c函数 _malloc
364
+ Module.HEAPU8.set(arrPlayToken, playTokenPtr);//复制字符串内容
365
+
366
+ var arrPlayTokenKey = Module.intArrayFromString(playTokenKey).concat(0);
367
+ var playTokenKeyPtr = Module._malloc(arrPlayTokenKey.length);
368
+ Module.HEAPU8.set(arrPlayTokenKey, playTokenKeyPtr);
369
+
370
+ var arrDeviceID = Module.intArrayFromString(deviceID).concat(0);
371
+ var deviceIDPtr = Module._malloc(arrDeviceID.length);
372
+ Module.HEAPU8.set(arrDeviceID, deviceIDPtr);
373
+
374
+ var outKeyPtr = Module._malloc(256);
375
+ var outKeyLengthPtr = Module._malloc(4);
376
+
377
+ var nRet = Module._PLAY_GetOriginalKey(m_nPlayPort, playTokenPtr, playTokenKeyPtr, deviceIDPtr, outKeyPtr, outKeyLengthPtr);
378
+
379
+ var outKeyLength = Module.HEAP32[outKeyLengthPtr >>2];
380
+ var outKeyTmp = "";
381
+
382
+ if ((1 == nRet) && (outKeyLength <= 256))
383
+ {
384
+ var jsKeyBuf = new ArrayBuffer(outKeyLength);
385
+ var jsKeyData = new Uint8Array(jsKeyBuf);
386
+ jsKeyData.set(Module.HEAPU8.subarray(outKeyPtr, outKeyPtr + outKeyLength));
387
+ outKeyTmp = ArrayBufferToString(jsKeyBuf);
388
+ }
389
+
390
+ Module._free(playTokenPtr);//释放内存
391
+ Module._free(playTokenKeyPtr);
392
+ Module._free(deviceIDPtr);
393
+ Module._free(outKeyPtr);
394
+ Module._free(outKeyLengthPtr);
395
+
396
+ var outKeyParam =
397
+ {
398
+ nRet: nRet,
399
+ outKey: outKeyTmp,
400
+ };
401
+
402
+ var msgType = 'GetOriginalKeyCallBack';
403
+ var msgData =
404
+ {
405
+ nRet: nRet,
406
+ outKey: outKeyTmp,
407
+ }
408
+
409
+ sendMessage(m_nPlayPort, msgType, msgData);
410
+ }
411
+
412
+ function SetWebSecurityKey(nDecryptType, nFrameType, strKey, stStreamInfo)
413
+ {
414
+ var arrStrKey = Module.intArrayFromString(strKey).concat(0);
415
+ var strKeyPtr = Module._malloc(arrStrKey.length);
416
+ Module.HEAPU8.set(arrStrKey, strKeyPtr);
417
+
418
+ var arrSdpInfo = Module.intArrayFromString(stStreamInfo.sdpInfo).concat(0);
419
+ var sdpInfoPtr = Module._malloc(arrSdpInfo.length);
420
+ Module.HEAPU8.set(arrSdpInfo, sdpInfoPtr);
421
+
422
+ var arrUserName = Module.intArrayFromString(stStreamInfo.strUserName).concat(0);
423
+ var userNamePtr = Module._malloc(arrUserName.length);
424
+ Module.HEAPU8.set(arrUserName, userNamePtr);
425
+
426
+ var arrPassWord = Module.intArrayFromString(stStreamInfo.strPassWord).concat(0);
427
+ var passWordPtr = Module._malloc(arrPassWord.length);
428
+ Module.HEAPU8.set(arrPassWord, passWordPtr);
429
+
430
+ const stStreamInfoPtr = Module._malloc(16);//4:uint32的字节大小
431
+ Module.HEAP32[stStreamInfoPtr/4 + 0] = sdpInfoPtr;
432
+ Module.HEAP32[stStreamInfoPtr/4 + 1] = userNamePtr;
433
+ Module.HEAP32[stStreamInfoPtr/4 + 2] = passWordPtr;
434
+ Module.HEAP32[stStreamInfoPtr/4 + 3] = stStreamInfo.nSsrc;
435
+
436
+ Module._PLAY_SetWebSecurityKey(m_nPlayPort, nDecryptType, nFrameType, strKeyPtr, stStreamInfoPtr);
437
+
438
+ Module._free(strKeyPtr);//释放内存
439
+ Module._free(sdpInfoPtr);
440
+ Module._free(userNamePtr);
441
+ Module._free(passWordPtr);
442
+ Module._free(stStreamInfoPtr);
443
+ }
444
+
445
+ function SetSecurityKey(nEncryptType, szKey, nKeyLen, szKeyId, nKeyIdLen)
446
+ {
447
+ var nRet = 1;
448
+
449
+ var strKey = Module._malloc(49);
450
+ var arrayKey = new Uint8Array(Module.HEAPU8.buffer);
451
+ var nSequence = 0;
452
+
453
+ if (ENCRYPT_AES == nEncryptType)
454
+ {
455
+ //逐字节的形式去内存中设置值,直接修改wasm内存数据
456
+ szKey.forEach((value, nIndex) => {
457
+ arrayKey[(strKey + nSequence) >> 0] = value;
458
+ nSequence++;
459
+ });
460
+ }
461
+ else if(ENCRYPT_AES256 == nEncryptType)
462
+ {
463
+ var szKeyIdTmp = new Uint8Array(16); ;
464
+
465
+ //协议规定ENCRYPT_AES256对应的枚举值为1
466
+ arrayKey[(strKey + nSequence) >> 0] = 1;
467
+ nSequence++;
468
+ if (0 == nKeyIdLen)
469
+ {
470
+ for(var i = 0; i < 16; i++)
471
+ {
472
+ szKeyIdTmp[i] = 0x00;
473
+ }
474
+ nKeyIdLen = 16;
475
+ szKeyId = szKeyIdTmp;
476
+ }
477
+
478
+ //拼接上key ID,逐字节的形式去内存中设置值,直接修改wasm内存数据
479
+ szKeyId.forEach((value, nIndex) => {
480
+ arrayKey[(strKey + nSequence) >> 0] = value;
481
+ nSequence++;
482
+ });
483
+
484
+ //拼接上key,逐字节的形式去内存中设置值,直接修改wasm内存数据
485
+ szKey.forEach((value, nIndex) => {
486
+ arrayKey[strKey + nSequence] = value;
487
+ nSequence++;
488
+ });
489
+
490
+ nKeyLen = 1 + nKeyLen + nKeyIdLen;
491
+ szKeyIdTmp = null;
492
+ }
493
+ else if(ENCRYPT_AES_STRING_FORMAT == nEncryptType)
494
+ {
495
+ szKey.split('').forEach((char, nIndex) => {
496
+ arrayKey[(strKey + nSequence) >> 0] = char.charCodeAt(0);
497
+ nSequence++;
498
+ });
499
+ }
500
+ nRet = Module._PLAY_SetSecurityKey(m_nPlayPort, strKey, nKeyLen);
501
+
502
+ Module._free(strKey);
503
+
504
+ return nRet;
505
+ }
506
+
507
+ function SetSupportWebMSE(bSupportH264MSE, bSupportH265MSE)
508
+ {
509
+ Module._PLAY_SetSupportWebMSE(m_nPlayPort, bSupportH264MSE, bSupportH265MSE);
510
+ }
511
+
512
+ function Pause(bPause)
513
+ {
514
+ Module._PLAY_Pause(m_nPlayPort, bPause);
515
+ }
516
+
517
+ function CatchPic()
518
+ {
519
+ var nSize = m_nWidth * m_nHeight * 3/2;
520
+ var pJpegBuf = Module._malloc(nSize);
521
+ var pJpegBufArr = new Uint8Array(Module.HEAPU8.buffer, pJpegBuf, nSize);
522
+
523
+ var pJpegSize = Module._malloc(4);
524
+ var pJpegSizeArr = new Uint8Array(Module.HEAPU8.buffer, pJpegSize, 4);
525
+
526
+ //获取当前图像编码后的jpeg图片数据
527
+ Module._PLAY_GetPicJPEG(m_nPlayPort, pJpegBufArr.byteOffset, nSize, pJpegSizeArr.byteOffset, 100);
528
+
529
+ //C++内存数据拷贝至JS内存
530
+ var nDataSize = (pJpegSizeArr[3] << 24) + (pJpegSizeArr[2] << 16) + (pJpegSizeArr[1] << 8) + pJpegSizeArr[0];
531
+ var pOutJpegBuf = new ArrayBuffer(nDataSize);
532
+ var pOutJpegBufArr = new Uint8Array(pOutJpegBuf);
533
+ pOutJpegBufArr.set(Module.HEAPU8.subarray(pJpegBufArr.byteOffset, pJpegBufArr.byteOffset + nDataSize));
534
+
535
+ var msgType = 'CatchPicCallBack';
536
+ var msgData =
537
+ {
538
+ buffer: pOutJpegBufArr
539
+ }
540
+ sendMessage(m_nPlayPort, msgType, msgData);
541
+
542
+ Module._free(pJpegBuf);
543
+ Module._free(pJpegSize);
544
+ pJpegBufArr = null;
545
+ pJpegSizeArr = null;
546
+ pOutJpegBuf= null;
547
+ pOutJpegBufArr = null;
548
+
549
+ }
550
+
551
+ function Stop()
552
+ {
553
+ var nRet = Module._PLAY_Stop(m_nPlayPort);
554
+ if (0 == nRet)
555
+ {
556
+ return;
557
+ }
558
+ nRet = Module._PLAY_CloseStream(m_nPlayPort);
559
+
560
+ jsInputDataAry = null;
561
+ Module._free(jsInputData);
562
+
563
+ jsFrameBuf = null;
564
+ jsFrameInfo = null;
565
+ dataView = null;
566
+
567
+ jsBufY = null;
568
+ jsBufU = null;
569
+ jsBufV = null;
570
+ jsYuvDataY = null;
571
+ jsYuvDataU = null;
572
+ jsYuvDataV = null;
573
+
574
+ jsRecordFrameBuf = null;
575
+ jsRecordFrameInfo = null;
576
+ dataViewRecord = null;
577
+
578
+ m_nTotalStreamLength = 0;
579
+ }
580
+
581
+ function SetPrintLogLevel(nLogLevel)
582
+ {
583
+ Module._PLAY_SetPrintLogLevel(nLogLevel);
584
+ }
585
+
586
+ function cPlusVisibleDecCallBack(nPort, pBufY, pBufU, pBufV, nSize, pFrameInfo)
587
+ {
588
+ var stuFrameInfo = {};
589
+
590
+ stuFrameInfo.nTotalStreamLength = m_nTotalStreamLength;
591
+
592
+ if(!jsFrameInfo)
593
+ {
594
+ jsFrameBuf = new ArrayBuffer(292);//通过二进制对象分配一块连续内存
595
+ jsFrameInfo = new Uint8Array(jsFrameBuf);//二进制对象绑定到视图,通过视图对内存进行读写操作
596
+ dataView = new DataView(jsFrameBuf);
597
+ }
598
+ jsFrameInfo.set(Module.HEAPU8.subarray(pFrameInfo, pFrameInfo + 292));//c中的内存拷贝到刚分配的js内存中
599
+ //帧类型
600
+ stuFrameInfo.nFrameType = dataView.getInt32(0, true);
601
+ //帧序号
602
+ stuFrameInfo.nFrameID = dataView.getInt32(4, true);
603
+ //帧子类型
604
+ stuFrameInfo.nFrameSubType = dataView.getInt32(56, true);
605
+
606
+ //帧时间
607
+ stuFrameInfo.nYear = dataView.getUint16(40, true);
608
+ stuFrameInfo.nMonth = dataView.getUint16(42, true);
609
+ stuFrameInfo.nDay = dataView.getUint16(46, true);
610
+ stuFrameInfo.nHour = dataView.getUint16(48, true);
611
+ stuFrameInfo.nMinute = dataView.getUint16(50, true);
612
+ stuFrameInfo.nSecond = dataView.getUint16(52, true);
613
+
614
+ var msgData = {};
615
+ //视频
616
+ if (1 == stuFrameInfo.nFrameType)
617
+ {
618
+ //剩余缓冲数据量
619
+ stuFrameInfo.nRemainData = dataView.getInt32(36, true);
620
+ //抽帧标记
621
+ stuFrameInfo.bThrowFrame = dataView.getUint8(120, true);
622
+ if (0 == stuFrameInfo.bThrowFrame)
623
+ {
624
+ //编码类型
625
+ stuFrameInfo.nEncodeType = dataView.getInt32(108, true);
626
+ //码流类型
627
+ stuFrameInfo.nStreamType = dataView.getInt32(112, true);
628
+ //时间戳
629
+ stuFrameInfo.nTimeStamp = dataView.getUint32(8, true);
630
+ //图像宽度
631
+ stuFrameInfo.nWidth = dataView.getInt32(12, true);
632
+ m_nWidth = stuFrameInfo.nWidth;
633
+ //图像高度
634
+ stuFrameInfo.nHeight = dataView.getInt32(16, true);
635
+ m_nHeight = stuFrameInfo.nHeight;
636
+ //视频帧率
637
+ stuFrameInfo.nFrameRate = dataView.getInt32(20, true);
638
+ //图像跨距
639
+ stuFrameInfo.nStride = dataView.getInt32(116, true);
640
+ //vui句法中视频三原色
641
+ stuFrameInfo.nColorPrimaries = dataView.getUint8(124, true);
642
+ //vui句法中视频信号转换函数
643
+ stuFrameInfo.nColorTransfer = dataView.getUint8(125, true);
644
+ //vui中视频颜色空间
645
+ stuFrameInfo.nColorSpace = dataView.getUint8(126, true);
646
+ //颜色范围 0:yuv范围16-235,对应 TV; 1:yuv范围0-255, 对应 PC
647
+ stuFrameInfo.bColorFull = dataView.getUint8(127, true);
648
+
649
+ if ((ENCODE_TYPE_VIDEO_HI_H264 == stuFrameInfo.nEncodeType) || (ENCODE_TYPE_VIDEO_MY_H264 == stuFrameInfo.nEncodeType) || (ENCODE_TYPE_VIDEO_STD_H264 == stuFrameInfo.nEncodeType))
650
+ {
651
+ //H.264编码类型
652
+ m_nVideoEncodeType = 1;
653
+ }
654
+ else if(12 == stuFrameInfo.nEncodeType)
655
+ {
656
+ //H.265编码类型
657
+ m_nVideoEncodeType = 2;
658
+ }
659
+
660
+ //智能I/P帧
661
+ if ((VIDEO_FRAME_SUB_TYPE_SMART_I == stuFrameInfo.nFrameSubType)
662
+ || (VIDEO_FRAME_SUB_TYPE_SMART_P == stuFrameInfo.nFrameSubType)
663
+ || (VIDEO_FRAME_SUB_TYPE_SMART_I_NORENDER == stuFrameInfo.nFrameSubType))
664
+ {
665
+ //Smart H.264或者Smart H.265
666
+ m_bSmartEncode = 1;
667
+ }
668
+ else if(0 == stuFrameInfo.nFrameSubType)
669
+ {
670
+ m_bSmartEncode = 0;
671
+ }
672
+
673
+ //非Smart H.264/H.265码流,若浏览器支持MSE硬解码则采用硬解码
674
+ //SVC码流不支持硬解码
675
+ if ((((1 == m_nVideoEncodeType) && (true == m_bSupportH264MSE))
676
+ || ((2 == m_nVideoEncodeType) && (true == m_bSupportH265MSE)))
677
+ && !m_bSmartEncode
678
+ && (STREAM_TYPE_SVC != stuFrameInfo.nStreamType))
679
+ {
680
+ //读取码流裸数据
681
+ jsBuf = new ArrayBuffer(nSize);//通过二进制对象分配一块连续内存
682
+ jsFrameBodyData = new Uint8Array(jsBuf);//二进制对象绑定到视图,通过视图对内存进行读写操作
683
+ jsFrameBodyData.set(Module.HEAPU8.subarray(pBufY, pBufY + nSize));//c中的内存拷贝到刚分配的js内存中
684
+
685
+ msgData =
686
+ {
687
+ pBufY: jsFrameBodyData,
688
+ pBufU: null,
689
+ pBufV: null,
690
+ nSize: nSize,
691
+ stuFrameInfo: stuFrameInfo,
692
+ }
693
+ }
694
+ else
695
+ {
696
+ if((0 == pBufY) || (0 == pBufU) || (0 == pBufV))
697
+ {
698
+ return;
699
+ }
700
+
701
+ if (m_nWidth != m_nPreWidth || m_nHeight != m_nPreHeight)
702
+ {
703
+ m_nPreWidth = m_nWidth;
704
+ m_nPreHeight = m_nHeight;
705
+
706
+ jsBufY = null;
707
+ jsBufU = null;
708
+ jsBufV = null;
709
+ jsYuvDataY = null;
710
+ jsYuvDataU = null;
711
+ jsYuvDataV = null;
712
+
713
+ jsBufY = new ArrayBuffer(m_nWidth * m_nHeight);//通过二进制对象分配一块连续内存
714
+ jsYuvDataY = new Uint8Array(jsBufY);//二进制对象绑定到视图,通过视图对内存进行读写操作
715
+
716
+ jsBufU = new ArrayBuffer(m_nWidth * m_nHeight / 4);
717
+ jsYuvDataU = new Uint8Array(jsBufU);
718
+
719
+ jsBufV = new ArrayBuffer(m_nWidth * m_nHeight / 4);
720
+ jsYuvDataV = new Uint8Array(jsBufV);
721
+ }
722
+
723
+ var h = 0;
724
+ //将C++层YUV解码数据Y分量数据拷贝至JS层内存中
725
+ for(h = 0; h < stuFrameInfo.nHeight; h++)
726
+ {
727
+ jsYuvDataY.set(Module.HEAPU8.subarray((pBufY + h * stuFrameInfo.nStride), (pBufY + h * stuFrameInfo.nStride) + stuFrameInfo.nWidth), h * stuFrameInfo.nWidth);//c中的内存拷贝到刚分配的js内存中
728
+ }
729
+ //将C++层YUV解码数据U分量数据拷贝至JS层内存中
730
+ for(h = 0; h < stuFrameInfo.nHeight / 2; h++)
731
+ {
732
+ jsYuvDataU.set(Module.HEAPU8.subarray((pBufU + h * stuFrameInfo.nStride/2), (pBufU + h * stuFrameInfo.nStride/2) + stuFrameInfo.nWidth/2), h * stuFrameInfo.nWidth/2);//c中的内存拷贝到刚分配的js内存中
733
+ }
734
+ //将C++层YUV解码数据V分量数据拷贝至JS层内存中
735
+ for(h = 0; h < stuFrameInfo.nHeight / 2; h++)
736
+ {
737
+ jsYuvDataV.set(Module.HEAPU8.subarray((pBufV + h * stuFrameInfo.nStride/2), (pBufV + h * stuFrameInfo.nStride/2) + stuFrameInfo.nWidth/2), h * stuFrameInfo.nWidth/2);//c中的内存拷贝到刚分配的js内存中
738
+ }
739
+
740
+ msgData =
741
+ {
742
+ pBufY: jsYuvDataY,
743
+ pBufU: jsYuvDataU,
744
+ pBufV: jsYuvDataV,
745
+ nSize: nSize,
746
+ stuFrameInfo: stuFrameInfo,
747
+ }
748
+ }
749
+ }
750
+ else
751
+ {
752
+ msgData =
753
+ {
754
+ pBufY: null,
755
+ pBufU: null,
756
+ pBufV: null,
757
+ nSize: 0,
758
+ stuFrameInfo: stuFrameInfo,
759
+ }
760
+ }
761
+ }
762
+ else if(2 == stuFrameInfo.nFrameType)//音频帧
763
+ {
764
+ //总通道数
765
+ stuFrameInfo.nTotalChannel = dataView.getInt32(68, true);
766
+ //当前通道
767
+ stuFrameInfo.nCurChannel = dataView.getInt32(72, true);
768
+ //暂不支持双通道音频播放
769
+ if (stuFrameInfo.nCurChannel > 0)
770
+ {
771
+ return;
772
+ }
773
+ //采样位数
774
+ stuFrameInfo.nBits = dataView.getInt32(28, true);
775
+ //采样率
776
+ stuFrameInfo.nSamples = dataView.getInt32(32, true);
777
+ //声道数
778
+ stuFrameInfo.nAudioChnNum = dataView.getInt32(24, true);
779
+
780
+ var AudioBuf = new ArrayBuffer(nSize);
781
+ var UI8AudioData = new Uint8Array(AudioBuf);
782
+ //将C++层解码后的pcm音频数据拷贝至JS层内存
783
+ UI8AudioData.set(Module.HEAPU8.subarray(pBufY, pBufY + nSize));
784
+
785
+ msgData =
786
+ {
787
+ pBufY: UI8AudioData,
788
+ pBufU: null,
789
+ pBufV: null,
790
+ nSize: nSize,
791
+ stuFrameInfo: stuFrameInfo,
792
+ }
793
+ }
794
+
795
+ var msgType = 'VisibleDecCallBack';
796
+
797
+ sendMessage(nPort, msgType, msgData);
798
+
799
+ jsBuf = null;
800
+ jsFrameBodyData = null;
801
+ }
802
+
803
+ /*
804
+ * C++层AES解密回调。
805
+ *
806
+ * @param[in] nPort 端口号
807
+ * @param[in] nFrameID 视频帧序号
808
+ * @param[in] bSuccess 是否解密成功
809
+ */
810
+ function cDigitalSignCallBack(nPort, nFrameID, bSuccess)
811
+ {
812
+ m_bDecryptionResult = bSuccess;
813
+ var msgType = 'DecryptionResultCallBack';
814
+ var msgData =
815
+ {
816
+ bSuccess: bSuccess
817
+ }
818
+
819
+ sendMessage(nPort, msgType, msgData);
820
+ }
821
+
822
+ /*
823
+ * C++层码流录制回调,回调至JS层进行数据存储
824
+ *
825
+ * @param[in] nPort 端口号
826
+ * @param[in] pData 码流数据
827
+ * @param[in] nDataLen 数据长度
828
+ * @param[in] nOffset 偏移量
829
+ * @param[in] pFrameInfo 码流信息
830
+ */
831
+ function cRecordDataCallBack(nPort, pData, nDataLen, nOffset, pFrameInfo)
832
+ {
833
+ var stuFrameInfo = {};
834
+ if (!jsRecordFrameInfo)
835
+ {
836
+ jsRecordFrameBuf = new ArrayBuffer(292); //通过二进制对象分配一块连续内存
837
+ jsRecordFrameInfo = new Uint8Array(jsRecordFrameBuf); //二进制对象绑定到视图,通过视图对内存进行读写操作
838
+ dataViewRecord = new DataView(jsRecordFrameBuf);
839
+ }
840
+ jsRecordFrameInfo.set(Module.HEAPU8.subarray(pFrameInfo, pFrameInfo + 292)); //c中的内存拷贝到刚分配的js内存中
841
+
842
+ //帧类型
843
+ stuFrameInfo.nFrameType = dataViewRecord.getInt32(0, true);
844
+ //帧序号
845
+ stuFrameInfo.nFrameID = dataViewRecord.getInt32(4, true);
846
+ //帧子类型
847
+ stuFrameInfo.nFrameSubType = dataViewRecord.getInt32(56, true);
848
+
849
+ //视频帧
850
+ if (1 == stuFrameInfo.nFrameType)
851
+ {
852
+ //编码类型
853
+ stuFrameInfo.nEncodeType = dataViewRecord.getInt32(68, true);
854
+ //码流类型
855
+ stuFrameInfo.nStreamType = dataViewRecord.getInt32(72, true);
856
+
857
+ //时间戳
858
+ stuFrameInfo.nTimeStamp = dataViewRecord.getUint32(8, true);
859
+ //帧时间
860
+ stuFrameInfo.nYear = dataViewRecord.getUint16(40, true);
861
+ stuFrameInfo.nMonth = dataViewRecord.getUint16(42, true);
862
+ stuFrameInfo.nDay = dataViewRecord.getUint16(46, true);
863
+ stuFrameInfo.nHour = dataViewRecord.getUint16(48, true);
864
+ stuFrameInfo.nMinute = dataViewRecord.getUint16(50, true);
865
+ stuFrameInfo.nSecond = dataViewRecord.getUint16(52, true);
866
+ }
867
+
868
+ var bufRecord = new ArrayBuffer(nDataLen);
869
+ var arrayRecord = new Uint8Array(bufRecord);
870
+ arrayRecord.set(Module.HEAPU8.subarray(pData, pData + nDataLen));
871
+
872
+ var msgType = 'RecordDataCallBack';
873
+ var msgData =
874
+ {
875
+ pRecordData: arrayRecord,
876
+ nLen: nDataLen,
877
+ Offset: nOffset,
878
+ stuFrameInfo: stuFrameInfo,
879
+ }
880
+ sendMessage(nPort, msgType, msgData);
881
+
882
+ bufRecord = null;
883
+ arrayRecord = null;
884
+ }
885
+
886
+ function cIVSDrawDataCallBack(nPort, pBuf, nType, nLen, nReallen)
887
+ {
888
+ //帧序号为-1时不绘制
889
+ if(-1 == nReallen)
890
+ {
891
+ return;
892
+ }
893
+
894
+ var pParseredBuf = null;
895
+
896
+ ivsBuf = new ArrayBuffer(nLen);//通过二进制对象分配一块连续内存
897
+ ivsDataArray = new Uint8Array(ivsBuf);//二进制对象绑定到视图,通过视图对内存进行读写操作
898
+ ivsDataArray.set(Module.HEAPU8.subarray(pBuf, pBuf + nLen));
899
+ ivsDataView = new DataView(ivsDataArray.buffer);
900
+
901
+ if (IVS_TYPE.IVSINFOTYPE_INTELFLOW == nType)
902
+ {//智能客流量
903
+ var stuIntelflowInfo = {};
904
+ stuIntelflowInfo.NumberStat = ivsDataView.getUint16(0, true);//大类业务方案
905
+ stuIntelflowInfo.nIntelFlowPlanNum = ivsDataView.getUint16(2, true);//智能客流规则数量(最大不会超过32个)
906
+
907
+ var pIntelFlowPlan = ivsDataView.getUint32(4, true);
908
+ let IntelFlowPlanBuf = new ArrayBuffer(12);
909
+ let IntelFlowPlanArray = new Uint8Array(IntelFlowPlanBuf);
910
+ let IntelFlowPlanView = new DataView(IntelFlowPlanBuf);
911
+
912
+ stuIntelflowInfo.pIntelFlowPlan = new Array(stuIntelflowInfo.nIntelFlowPlanNum);
913
+ for (let i = 0; i < stuIntelflowInfo.nIntelFlowPlanNum; i++)
914
+ {
915
+ IntelFlowPlanArray.set(Module.HEAPU8.subarray(pIntelFlowPlan + i * 12, pIntelFlowPlan + i * 12 + 12));
916
+ //解析智能客流规则
917
+ stuIntelflowInfo.pIntelFlowPlan[i] = {};
918
+ stuIntelflowInfo.pIntelFlowPlan[i].PlanId = IntelFlowPlanView.getUint16(0, true);//规则ID
919
+ stuIntelflowInfo.pIntelFlowPlan[i].RuleType = IntelFlowPlanView.getUint16(2, true);//规则类型
920
+ stuIntelflowInfo.pIntelFlowPlan[i].RegionNum = IntelFlowPlanView.getUint16(8, true);//区域数目
921
+ var pRegion = IntelFlowPlanView.getUint32(4, true);
922
+ let RegionBuf = new ArrayBuffer(12);
923
+ let RegionArray = new Uint8Array(RegionBuf);
924
+ let RegionView = new DataView(RegionBuf);
925
+
926
+ stuIntelflowInfo.pIntelFlowPlan[i].pRegion = new Array(stuIntelflowInfo.pIntelFlowPlan[i].RegionNum);
927
+ for (let j = 0; j < stuIntelflowInfo.pIntelFlowPlan[i].RegionNum; j++)
928
+ {
929
+ RegionArray.set(Module.HEAPU8.subarray(pRegion + j * 12, pRegion + j * 12 + 12));
930
+
931
+ stuIntelflowInfo.pIntelFlowPlan[i].pRegion[j] = {};
932
+ stuIntelflowInfo.pIntelFlowPlan[i].pRegion[j].RegionId = RegionView.getUint16(0, true);//区域ID
933
+ stuIntelflowInfo.pIntelFlowPlan[i].pRegion[j].State = RegionView.getUint16(2, true);//状态:离开or进入
934
+ stuIntelflowInfo.pIntelFlowPlan[i].pRegion[j].PeopleNum = RegionView.getUint32(4, true);//人数
935
+ }
936
+ }
937
+
938
+ pParseredBuf = stuIntelflowInfo;
939
+ }
940
+ else if (IVS_TYPE.IVSINFOTYPE_DHOP_SMART == nType)
941
+ {//DHOP开放平台智能帧
942
+ var stuObjDHOP = {};
943
+ stuObjDHOP.nId = ivsDataView.getUint32(0, true);//对象ID
944
+ stuObjDHOP.wCustom = ivsDataView.getUint16(4, true);//自定义值
945
+ stuObjDHOP.chState = ivsDataView.getUint8(6, true);//对象状态
946
+ stuObjDHOP.chCount = ivsDataView.getUint8(7, true);//元素个数
947
+
948
+ //解析DHOP元素
949
+ var pElement = ivsDataView.getUint32(8, true);
950
+ let elementBuf = new ArrayBuffer(12);
951
+ let elementDataArray = new Uint8Array(elementBuf);
952
+ let elementDataView = new DataView(elementBuf);
953
+
954
+ stuObjDHOP.pElement = new Array(stuObjDHOP.chCount);
955
+ for (var i = 0; i < stuObjDHOP.chCount; i++)
956
+ {
957
+ elementDataArray.set(Module.HEAPU8.subarray(pElement + i * 12, pElement + i * 12 + 12));
958
+ //解析DHOP元素类型
959
+ stuObjDHOP.pElement[i] = {};
960
+ stuObjDHOP.pElement[i].nStructType = elementDataView.getUint32(0, true);
961
+ stuObjDHOP.pElement[i].nStructLength = elementDataView.getUint32(4, true);
962
+ var pStruct = elementDataView.getUint32(8, true);
963
+
964
+ let structBuf = new ArrayBuffer(stuObjDHOP.pElement[i].nStructLength);
965
+ let structArray = new Uint8Array(structBuf);
966
+ let structDataView = new DataView(structBuf);
967
+ structArray.set(Module.HEAPU8.subarray(pStruct, pStruct + stuObjDHOP.pElement[i].nStructLength));
968
+
969
+ stuObjDHOP.pElement[i].pStruct = {};
970
+ if (IVS_DHOP_ElEMENT_TYPE.EM_DHOP_CIRCLE == stuObjDHOP.pElement[i].nStructType)
971
+ {
972
+ stuObjDHOP.pElement[i].pStruct.chType = structDataView.getUint8(0, true);//子类型0x3
973
+ stuObjDHOP.pElement[i].pStruct.chWidth = structDataView.getUint8(1, true);//线宽,单位px
974
+ stuObjDHOP.pElement[i].pStruct.chStyle = structDataView.getUint8(2, true);//样式
975
+
976
+ stuObjDHOP.pElement[i].pStruct.wRadius = structDataView.getUint16(4, true);//半径
977
+ stuObjDHOP.pElement[i].pStruct.positionCircle = {};//圆心坐标
978
+ stuObjDHOP.pElement[i].pStruct.positionCircle.x = structDataView.getUint16(8, true);
979
+ stuObjDHOP.pElement[i].pStruct.positionCircle.y = structDataView.getUint16(10, true);
980
+
981
+ stuObjDHOP.pElement[i].pStruct.chLineA = structDataView.getUint8(12, true);//边框线条颜色(ARGB)
982
+ stuObjDHOP.pElement[i].pStruct.chLineR = structDataView.getUint8(13, true);
983
+ stuObjDHOP.pElement[i].pStruct.chLineG = structDataView.getUint8(14, true);
984
+ stuObjDHOP.pElement[i].pStruct.chLineB = structDataView.getUint8(15, true);
985
+ stuObjDHOP.pElement[i].pStruct.chRegA = structDataView.getUint8(16, true);//区域填充颜色(ARGB)
986
+ stuObjDHOP.pElement[i].pStruct.chRegR = structDataView.getUint8(17, true);
987
+ stuObjDHOP.pElement[i].pStruct.chRegG = structDataView.getUint8(18, true);
988
+ stuObjDHOP.pElement[i].pStruct.chRegB = structDataView.getUint8(19, true);
989
+
990
+ }
991
+ else if(IVS_DHOP_ElEMENT_TYPE.EM_DHOP_BrokenLine == stuObjDHOP.pElement[i].nStructType)
992
+ {
993
+ stuObjDHOP.pElement[i].pStruct.chType = structDataView.getUint8(0, true);//子类型0x2
994
+ stuObjDHOP.pElement[i].pStruct.chCount = structDataView.getUint8(1, true);//端点个数
995
+ stuObjDHOP.pElement[i].pStruct.chWidth = structDataView.getUint8(2, true);//线宽,单位px
996
+ stuObjDHOP.pElement[i].pStruct.chStyle = structDataView.getUint8(3, true);//样式
997
+ stuObjDHOP.pElement[i].pStruct.chLineA = structDataView.getUint8(4, true);//边框线条颜色(ARGB)
998
+ stuObjDHOP.pElement[i].pStruct.chLineR = structDataView.getUint8(5, true);
999
+ stuObjDHOP.pElement[i].pStruct.chLineG = structDataView.getUint8(6, true);
1000
+ stuObjDHOP.pElement[i].pStruct.chLineB = structDataView.getUint8(7, true);
1001
+ //端点坐标
1002
+ var pPoints = null;
1003
+ let pointsBuf = null;
1004
+ let pointsDataArray = null;
1005
+ let pointsDataView = null;
1006
+
1007
+ if (stuObjDHOP.pElement[i].pStruct.chCount > 0)
1008
+ {
1009
+ stuObjDHOP.pElement[i].pStruct.pPoints = new Array(stuObjDHOP.pElement[i].pStruct.chCount);
1010
+ pPoints = structDataView.getUint32(8, true);
1011
+ pointsBuf = new ArrayBuffer(4);
1012
+ pointsDataArray = new Uint8Array(pointsBuf);
1013
+ pointsDataView = new DataView(pointsBuf);
1014
+ }
1015
+
1016
+ for(var j = 0; j < stuObjDHOP.pElement[i].pStruct.chCount; j++)
1017
+ {
1018
+ pointsDataArray.set(Module.HEAPU8.subarray(pPoints + j*4, pPoints + j*4 + 4));
1019
+ stuObjDHOP.pElement[i].pStruct.pPoints[j] = {};
1020
+ stuObjDHOP.pElement[i].pStruct.pPoints[j].x = pointsDataView.getUint16(0, true);
1021
+ stuObjDHOP.pElement[i].pStruct.pPoints[j].y = pointsDataView.getUint16(2, true);
1022
+ }
1023
+ }
1024
+ else if(IVS_DHOP_ElEMENT_TYPE.EM_DHOP_POLYGON == stuObjDHOP.pElement[i].nStructType)
1025
+ {
1026
+ stuObjDHOP.pElement[i].pStruct.chType = structDataView.getUint8(0, true);//子类型0x3
1027
+ stuObjDHOP.pElement[i].pStruct.chCount = structDataView.getUint8(1, true);//端点个数
1028
+ stuObjDHOP.pElement[i].pStruct.chWidth = structDataView.getUint8(2, true);//线宽,单位px
1029
+ stuObjDHOP.pElement[i].pStruct.chStyle = structDataView.getUint8(3, true);//样式
1030
+ stuObjDHOP.pElement[i].pStruct.chLineA = structDataView.getUint8(4, true);//边框线条颜色(ARGB)
1031
+ stuObjDHOP.pElement[i].pStruct.chLineR = structDataView.getUint8(5, true);
1032
+ stuObjDHOP.pElement[i].pStruct.chLineG = structDataView.getUint8(6, true);
1033
+ stuObjDHOP.pElement[i].pStruct.chLineB = structDataView.getUint8(7, true);
1034
+ stuObjDHOP.pElement[i].pStruct.chRegA = structDataView.getUint8(8, true);//区域填充颜色(ARGB)
1035
+ stuObjDHOP.pElement[i].pStruct.chRegR = structDataView.getUint8(9, true);
1036
+ stuObjDHOP.pElement[i].pStruct.chRegG = structDataView.getUint8(10, true);
1037
+ stuObjDHOP.pElement[i].pStruct.chRegB = structDataView.getUint8(11, true);
1038
+ //端点坐标
1039
+ var pPoints = null;
1040
+ let pointsBuf = null;
1041
+ let pointsDataArray = null;
1042
+ let pointsDataView = null;
1043
+
1044
+ if (stuObjDHOP.pElement[i].pStruct.chCount > 0)
1045
+ {
1046
+ stuObjDHOP.pElement[i].pStruct.pPoints = new Array(stuObjDHOP.pElement[i].pStruct.chCount);
1047
+ pPoints = structDataView.getUint32(12, true);
1048
+ pointsBuf = new ArrayBuffer(4);
1049
+ pointsDataArray = new Uint8Array(pointsBuf);
1050
+ pointsDataView = new DataView(pointsBuf);
1051
+ }
1052
+
1053
+ for(var j = 0; j < stuObjDHOP.pElement[i].pStruct.chCount; j++)
1054
+ {
1055
+ pointsDataArray.set(Module.HEAPU8.subarray(pPoints + j*4, pPoints + j*4 + 4));
1056
+ stuObjDHOP.pElement[i].pStruct.pPoints[j] = {};
1057
+ stuObjDHOP.pElement[i].pStruct.pPoints[j].x = pointsDataView.getUint16(0, true);
1058
+ stuObjDHOP.pElement[i].pStruct.pPoints[j].y = pointsDataView.getUint16(2, true);
1059
+ }
1060
+ }
1061
+ else if(IVS_DHOP_ElEMENT_TYPE.EM_DHOP_TEXT == stuObjDHOP.pElement[i].nStructType)
1062
+ {
1063
+ stuObjDHOP.pElement[i].pStruct.chType = structDataView.getUint8(0, true);//子类型0x4
1064
+ stuObjDHOP.pElement[i].pStruct.chCharset = structDataView.getUint8(1, true);//编码方式
1065
+ stuObjDHOP.pElement[i].pStruct.stringPos = {};//字符坐标
1066
+ stuObjDHOP.pElement[i].pStruct.stringPos.x = structDataView.getUint16(4, true);
1067
+ stuObjDHOP.pElement[i].pStruct.stringPos.y = structDataView.getUint16(6, true);
1068
+ stuObjDHOP.pElement[i].pStruct.chLineA = structDataView.getUint8(8, true);//字体颜色(ARGB)
1069
+ stuObjDHOP.pElement[i].pStruct.chLineR = structDataView.getUint8(9, true);
1070
+ stuObjDHOP.pElement[i].pStruct.chLineG = structDataView.getUint8(10, true);
1071
+ stuObjDHOP.pElement[i].pStruct.chLineB = structDataView.getUint8(11, true);
1072
+ stuObjDHOP.pElement[i].pStruct.chFontSize = structDataView.getUint8(12, true);//字体大小,单位px
1073
+ stuObjDHOP.pElement[i].pStruct.chFontAlign = structDataView.getUint8(13, true);//对齐方式
1074
+ stuObjDHOP.pElement[i].pStruct.wTxtLen = structDataView.getUint16(14, true);//字符长度
1075
+
1076
+ var pString = structDataView.getUint32(16, true);
1077
+ var stringBuf = new ArrayBuffer(stuObjDHOP.pElement[i].pStruct.wTxtLen);
1078
+ var stringDataArray = new Uint8Array(stringBuf);
1079
+ var stringDataView = new DataView(stringBuf);
1080
+ stringDataArray.set(Module.HEAPU8.subarray(pString, pString + stuObjDHOP.pElement[i].pStruct.wTxtLen));
1081
+ stuObjDHOP.pElement[i].pStruct.stringDataArray = stringDataArray;
1082
+ }
1083
+ }
1084
+
1085
+ //解析DHOP信息内容
1086
+ stuObjDHOP.nInfoLen = ivsDataView.getUint16(12, true);//信息长度
1087
+ if (stuObjDHOP.nInfoLen > 0)
1088
+ {
1089
+ var pInfo = ivsDataView.getUint32(16, true);
1090
+ let infoBuf = new ArrayBuffer(nInfoLen);
1091
+ let infoDataArray = new Uint8Array(infoBuf);
1092
+ infoDataArray.set(Module.HEAPU8.subarray(pInfo, pInfo + nInfoLen));
1093
+ stuObjDHOP.pInfo = infoDataArray;
1094
+ }
1095
+
1096
+ pParseredBuf = stuObjDHOP;
1097
+ }
1098
+ else if (IVS_TYPE.IVSINFOTYPE_TAGGING_INFO == nType)//景物点信息标注帧
1099
+ {
1100
+ let dataView = new DataView(ivsBuf);
1101
+
1102
+ let tagInfoNum = nLen/FRAME_SCENE_POINTS_INFOR_SIZE;
1103
+
1104
+ let tagInfos = [];
1105
+ for (let tagInfoIndex = 0; tagInfoIndex < tagInfoNum; tagInfoIndex++)
1106
+ {
1107
+ var tagInfo = {};
1108
+ let Stride = FRAME_SCENE_POINTS_INFOR_SIZE * tagInfoIndex;
1109
+ //编号
1110
+ tagInfo.nIndex = dataView.getInt32(Stride + 0, true);
1111
+ //景物点x坐标
1112
+ tagInfo.xPoint = dataView.getUint16(Stride + 4, true);
1113
+ //景物点y坐标
1114
+ tagInfo.yPoint = dataView.getUint16(Stride + 6, true);
1115
+
1116
+ //一级名称
1117
+ var jsNameBuf = new ArrayBuffer(64);
1118
+ jsNameBuf = ivsBuf.slice(Stride + 8);
1119
+ tagInfo.strName = ArrayBufferToStringAutoClip(jsNameBuf);
1120
+
1121
+ //使能标记
1122
+ tagInfo.enable = dataView.getInt8(Stride + 72, true);
1123
+ //标签类型
1124
+ tagInfo.titleType = dataView.getInt8(Stride + 73, true);
1125
+ //标签属性
1126
+ tagInfo.titleAttribute = dataView.getInt8(Stride + 74, true);
1127
+ tagInfo.sharpType = dataView.getInt8(Stride + 75, true);
1128
+ tagInfo.polygonNum = dataView.getInt8(Stride + 76, true);
1129
+ tagInfo.polygon = [];
1130
+ //与上一个中间空了三字节
1131
+ for(let i = 0;i< tagInfo.polygonNum*2;i+=2)
1132
+ {
1133
+ tagInfo.polygon[i] ={x: dataView.getInt8(Stride + 79 + 2*i, true),
1134
+ y: dataView.getInt8(Stride + 79 + 2*(i+1), true)};
1135
+ }
1136
+
1137
+ tagInfos[tagInfoIndex] = tagInfo;
1138
+ jsNameBuf = null;
1139
+ }
1140
+
1141
+ var msgType = 'ARTagInfoCallback';
1142
+ var msgData =
1143
+ {
1144
+ tagInfo: tagInfos,
1145
+ }
1146
+
1147
+ sendMessage(nPort, msgType, msgData);
1148
+
1149
+ pParseredBuf = ivsDataArray;
1150
+ dataView = null;
1151
+ }
1152
+ else
1153
+ {
1154
+ pParseredBuf = ivsDataArray;
1155
+ }
1156
+
1157
+ var msgType = 'IVSDataCallBack';
1158
+ var msgData =
1159
+ {
1160
+ pBuf: pParseredBuf,
1161
+ nType: nType,
1162
+ nLen: nLen,
1163
+ nReallen: nReallen,
1164
+ }
1165
+
1166
+ sendMessage(nPort, msgType, msgData);
1167
+ }
1168
+
1169
+ function sendMessage(nPort, msgType, msgData)
1170
+ {
1171
+ var event =
1172
+ {
1173
+ nPort: nPort,
1174
+ msgType: msgType,
1175
+ msgData: msgData,
1176
+ };
1177
+
1178
+ postMessage(event);
1179
+ }
1180
+
1181
+ function ArrayBufferToString(buffer, encoding = 'utf-8')
1182
+ {
1183
+ const decoder = new TextDecoder(encoding);
1184
+ return decoder.decode(buffer);
1185
+ }
1186
+
1187
+ function ArrayBufferToStringAutoClip(buffer, encoding = 'utf-8')
1188
+ {
1189
+ const decoder = new TextDecoder(encoding);
1190
+ const uint8Array = new Uint8Array(buffer);
1191
+
1192
+ let i = 0;
1193
+
1194
+ while (i < uint8Array.length) {
1195
+ if (uint8Array[i] === 0) {
1196
+ break;
1197
+ }
1198
+ i++;
1199
+ }
1200
+
1201
+ return decoder.decode(buffer.slice(0,i));
1202
+ }
1203
+
1204
+ function UTF16ToUTF8(UTF16Str)
1205
+ {
1206
+ var UTF8Arr = [];
1207
+ var byteSize = 0;
1208
+ for (var i = 0; i < UTF16Str.length; i++)
1209
+ {
1210
+ //获取字符Unicode码值
1211
+ var code = UTF16Str.charCodeAt(i);
1212
+
1213
+ //如果码值是1个字节的范围,则直接写入
1214
+ if (code >= 0x00 && code <= 0x7f)
1215
+ {
1216
+ byteSize += 1;
1217
+ UTF8Arr.push(code);
1218
+
1219
+ //如果码值是2个字节以上的范围,则按规则进行填充补码转换
1220
+ }
1221
+ else if (code >= 0x80 && code <= 0x7ff)
1222
+ {
1223
+ byteSize += 2;
1224
+ UTF8Arr.push((192 | (31 & (code >> 6))));
1225
+ UTF8Arr.push((128 | (63 & code)))
1226
+ }
1227
+ else if ((code >= 0x800 && code <= 0xd7ff) || (code >= 0xe000 && code <= 0xffff))
1228
+ {
1229
+ byteSize += 3;
1230
+ UTF8Arr.push((224 | (15 & (code >> 12))));
1231
+ UTF8Arr.push((128 | (63 & (code >> 6))));
1232
+ UTF8Arr.push((128 | (63 & code)))
1233
+ }
1234
+ else if(code >= 0x10000 && code <= 0x10ffff)
1235
+ {
1236
+ byteSize += 4;
1237
+ UTF8Arr.push((240 | (7 & (code >> 18))));
1238
+ UTF8Arr.push((128 | (63 & (code >> 12))));
1239
+ UTF8Arr.push((128 | (63 & (code >> 6))));
1240
+ UTF8Arr.push((128 | (63 & code)))
1241
+ }
1242
+ }
1243
+
1244
+ return UTF8Arr
1245
+ }