ezuikit-js 7.7.6 → 7.7.8

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 (61) hide show
  1. package/CHANGELOG.md +33 -71
  2. package/ezuikit.js +1 -1
  3. package/package.json +1 -2
  4. package/ezuikit_static/v65/v1/css/component.css +0 -1257
  5. package/ezuikit_static/v65/v1/css/inspectTheme.css +0 -354
  6. package/ezuikit_static/v65/v1/css/theme.css +0 -104
  7. package/ezuikit_static/v65/v1/imgs/bg.png +0 -0
  8. package/ezuikit_static/v65/v1/imgs/bg.svg +0 -33
  9. package/ezuikit_static/v65/v1/imgs/empty.png +0 -0
  10. package/ezuikit_static/v65/v1/imgs/end.png +0 -0
  11. package/ezuikit_static/v65/v1/imgs/fallback.svg +0 -52
  12. package/ezuikit_static/v65/v1/imgs/start.png +0 -0
  13. package/ezuikit_static/v65/v1/js/AudioRenderer.js +0 -225
  14. package/ezuikit_static/v65/v1/js/SuperRender_10.js +0 -397
  15. package/ezuikit_static/v65/v1/js/SystemTransform.js +0 -22
  16. package/ezuikit_static/v65/v1/js/SystemTransform.js.mem +0 -0
  17. package/ezuikit_static/v65/v1/js/jsPluginV1-1.0.0.min.js +0 -12
  18. package/ezuikit_static/v65/v1/js/playctrl/AudioRenderer.js +0 -250
  19. package/ezuikit_static/v65/v1/js/playctrl/DecodeWorker.js +0 -616
  20. package/ezuikit_static/v65/v1/js/playctrl/DecodeWorkerString.js +0 -623
  21. package/ezuikit_static/v65/v1/js/playctrl/Decoder.js +0 -1
  22. package/ezuikit_static/v65/v1/js/playctrl/JSPlaySDKInterface.js +0 -2146
  23. package/ezuikit_static/v65/v1/js/playctrl/SuperRender_10.js +0 -486
  24. package/ezuikit_static/v65/v1/js/playctrl/SuperRender_20.js +0 -1
  25. package/ezuikit_static/v65/v1/js/transform/SystemTransform.js +0 -22
  26. package/ezuikit_static/v65/v1/js/transform/SystemTransform.js.mem +0 -0
  27. package/ezuikit_static/v65/v1/js/transform/systemTransform-worker.min.js +0 -1
  28. package/ezuikit_static/v65/v1/js/tts-v4.js +0 -346
  29. package/ezuikit_static/v65/v1/rec/datepicker.js +0 -1522
  30. package/ezuikit_static/v65/v1/rec/datepicker.min.css +0 -36
  31. package/ezuikit_static/v65/v1/rec/datepicker.zh-CN.js +0 -19
  32. package/ezuikit_static/v65/v1/rec/jquery.min.js +0 -2
  33. package/ezuikit_static/v65/v1/speed/speed.css +0 -145
  34. package/ezuikit_static/v65/v1/talk/adapeter.js +0 -5497
  35. package/ezuikit_static/v65/v1/talk/janus.js +0 -3507
  36. package/ezuikit_static/v65/v1/talk/tts-v4.js +0 -346
  37. package/ezuikit_static/v65/v3/css/component.css +0 -1257
  38. package/ezuikit_static/v65/v3/css/inspectTheme.css +0 -354
  39. package/ezuikit_static/v65/v3/css/theme.css +0 -105
  40. package/ezuikit_static/v65/v3/imgs/bg.png +0 -0
  41. package/ezuikit_static/v65/v3/imgs/bg.svg +0 -33
  42. package/ezuikit_static/v65/v3/imgs/empty.png +0 -0
  43. package/ezuikit_static/v65/v3/imgs/end.png +0 -0
  44. package/ezuikit_static/v65/v3/imgs/fallback.svg +0 -52
  45. package/ezuikit_static/v65/v3/imgs/start.png +0 -0
  46. package/ezuikit_static/v65/v3/js/PlayCtrlWasm/hasWorker/Decoder.js +0 -21
  47. package/ezuikit_static/v65/v3/js/PlayCtrlWasm/hasWorker/Decoder.wasm +0 -0
  48. package/ezuikit_static/v65/v3/js/PlayCtrlWasm/hasWorker/Decoder.worker.js +0 -1
  49. package/ezuikit_static/v65/v3/js/PlayCtrlWasm/noWorker/Decoder.js +0 -21
  50. package/ezuikit_static/v65/v3/js/PlayCtrlWasm/noWorker/Decoder.wasm +0 -0
  51. package/ezuikit_static/v65/v3/js/PlayCtrlWasm/noWorker/Decoder.worker.js +0 -1
  52. package/ezuikit_static/v65/v3/js/jsPluginV3-1.0.0.min.js +0 -16907
  53. package/ezuikit_static/v65/v3/js/wasmplayer.min.js +0 -1
  54. package/ezuikit_static/v65/v3/rec/datepicker.js +0 -1522
  55. package/ezuikit_static/v65/v3/rec/datepicker.min.css +0 -36
  56. package/ezuikit_static/v65/v3/rec/datepicker.zh-CN.js +0 -19
  57. package/ezuikit_static/v65/v3/rec/jquery.min.js +0 -2
  58. package/ezuikit_static/v65/v3/speed/speed.css +0 -145
  59. package/ezuikit_static/v65/v3/talk/adapeter.js +0 -5497
  60. package/ezuikit_static/v65/v3/talk/janus.js +0 -3507
  61. package/ezuikit_static/v65/v3/talk/tts-v4.js +0 -343
@@ -1,2146 +0,0 @@
1
- /* eslint-disable indent */
2
- /* eslint-disable valid-jsdoc */
3
- /**
4
- * Created by wangweijie5 on 2016/12/2.
5
- */
6
- import DecodeWorkerString from "./DecodeWorkerString";
7
- /**
8
- * Created by wangweijie5 on 2016/12/2.
9
- */
10
-
11
- // 错误码
12
- const PLAYM4_PARA_OVER = 0; // 参数错误
13
- const PLAYM4_OK = 1; //正确
14
- const PLAYM4_ORDER_ERROR = 2; // 调用接口顺序错误
15
- const PLAYM4_TIMER_ERROR = 3; // 创建多媒体时钟错误
16
- const PLAYM4_DEC_VIDEO_ERROR = 4; // 视频设备错误
17
- const PLAYM4_DEC_AUDIO_ERROR = 5; // 音频设备错误
18
- const PLAYM4_ALLOC_MEMORY_ERROR = 6; // 申请内存失败
19
- const PLAYM4_OPEN_FILE_ERROR = 7; // 打开文件失败
20
- const PLAYM4_BUF_OVER = 11; // 缓存溢出
21
- const PLAYM4_SYS_NOT_SUPPORT = 16; // 不支持
22
- const PLAYM4_NEED_MORE_DATA = 31; // 需要更多数据才能解析
23
- const PLAYM4_NEED_NEET_LOOP = 35; //丢帧需要下个循环
24
- const PLAYM4_BUF_WILL_OVER = 36; //C层缓存即将满,需触发解I帧
25
-
26
- const PLAYM4_NOT_KEYFRAME = 48; // 非关键帧
27
- const PLAYM4_WORKER_ERROR = 60; // WORKER错误
28
- const PLAYM4_CREATE_RENDERER_ERROR = 61; // 创建渲染句柄失败
29
- const PLAYM4_LOAD_UNFINISHED = 62; // js文件未加载完成
30
- const PLAYM4_GET_VOLUME_ERROR = 63; // 获取音频音量失败
31
-
32
- const PLAYM4_ITYPE_DECODE_ERROR = 100; //定位后送进来的第一帧I帧解码失败
33
- const PLAYM4_FIRST_FRAME_NOT_ICURRENT = 101; //定位后送进来的第一帧不是定位帧所在的I帧(Ni>Mp)
34
-
35
- // 加密类型
36
- const SECRET_NONE = 0; // 不加密
37
- const SECRET_AES = 1; // AES 加密
38
-
39
- // 流模式
40
- const STREAM_REALTIME = 0; // 实时流
41
- const STREAM_FILE = 1; // 文件流
42
-
43
- // 解码类型
44
- const DECODE_ALL = 0; // 全解
45
- const DECODE_VIDEO_KEYFRAME = 1; // 只解关键帧
46
-
47
- // 缓存帧数
48
- const BUFFER_MAXNUM_ONEBYONE = 15; // 帧进上限缓存数
49
- const BUFFER_MINNUM_ONEBYONE = 8; // 帧进下限缓存数
50
- const BUFFER_NUM_NORMAL = 1; // 正常缓存数
51
- const BUFFER_NUM_AUDIO = 50; // 音频存储25帧播放一次
52
- const BUFFER_MAXNUM_YUV = 5; // YUV最大缓存帧数
53
- const YUV_SKIP_NUM = 2; // YUV跳帧间隔
54
-
55
- // const BUFFER_NODE_NUM = 20; // 输入缓存节点数
56
- // const BUFFER_MAX_SIZE = 800*1024; // 最大缓存
57
- const BUFFER_MAX_SIZE = 5 * 1024 * 1024; // 最大缓存
58
- const BUFFER_MIN_SIZE = 100;//最小缓存
59
- const BUFFER_INPUT_SIZE = 1024 * 20; // 一次送入数据大小
60
- // const BUFFER_FAST_INPUT_SIZE = 10000; // 快放一次送入数据大小
61
-
62
- const WRITE_AUD_ENCODE_NUM = 200; //一次写编码音频帧总帧数
63
- const WRITE_AUD_PCM_NUM = 100; //一次写PCM数据
64
- const WRITE_VID_YUV_NUM = 20; //一次写YUV数据
65
- const WRITE_VID_RAW_NUM = 100;//一次写裸数据
66
- // 电子放大区域
67
- const WRITE_RTP_NUM = 200; //写RTP数据
68
-
69
- //解码回调帧信息
70
- var DECODE_INFO_YUV = {
71
- "width": 0,
72
- "height": 0,
73
- "frameNum": 0,
74
- "yuvData": null
75
- };
76
- //显示回调帧信息
77
- var DISPLAY_INFO_YUV = {
78
- "width": 0,
79
- "height": 0,
80
- "frameNum": 0,
81
- "yuvData": null
82
- };
83
-
84
- //音频PCM回调信息
85
- var DECODE_INFO_PCM = {
86
- "sampleRate": 0,
87
- "channel": 0,
88
- "bitsPerSample": 0,
89
- "length": 0,
90
- "pcmData": null
91
- };
92
-
93
- // xx.js加载标识
94
- var bAudioRenderLoad = false;
95
- var bSuperRenderLoad = false;
96
-
97
- // 回调函数参数对象
98
- var CALLBACK_PARAMETER = {
99
- "id": null,
100
- "cmd": null,
101
- "data": null,
102
- "errorCode": 0,
103
- "status": null
104
- };
105
-
106
- //定义类 JSPlayCtrl
107
- export class JSPlayCtrl {
108
- constructor(path, callBack, winId, staticPath) {
109
-
110
- // 路径
111
- if (path != null && path !== undefined && typeof (path) === "string") {
112
- this.szBasePath = path;
113
- } else {
114
- return PLAYM4_PARA_OVER;
115
- }
116
-
117
- // 加载回调
118
- if (callBack && typeof (callBack) === "function") {
119
- this.fnCallBack = callBack;
120
- } else {
121
- return PLAYM4_PARA_OVER;
122
- }
123
-
124
- if (typeof staticPath === 'string') {
125
- this.staticPath = staticPath
126
- }
127
-
128
- // 解码 Worker
129
- this.decodeWorker = null;
130
-
131
- // 开启流类型
132
- this.streamOpenMode = null;
133
- this.bOpenStream = false;
134
-
135
-
136
- // 音频渲染
137
- this.audioRenderer = null;
138
- this.aAudioBuffer = [];
139
- this.iAudioBufferSize = 0;
140
- this.Volume = 0;
141
-
142
- // 视频渲染库
143
- this.oSuperRender = null;
144
- this.aVideoFrameBuffer = []; //YUV数据
145
- this.YUVBufferSize = BUFFER_NUM_NORMAL;
146
- this.szOSDTime = null;
147
-
148
- //打印日志
149
- //JS层log打印开关
150
- this.bJSPrintLog = false;
151
-
152
- //下载YUV数据
153
- this.bWriteYUVData = false;
154
- this.iYUV10size = 0;//YUV帧数
155
- this.aVideoYUVBuffer = [];
156
-
157
- //下载PCM数据
158
- this.bWritePCMData = false;
159
- this.iAudioBuffer500Size = 0;
160
- this.aAudioPCMBuffer = [];
161
-
162
- //下载裸数据
163
- this.bWriteRawData = false;
164
- this.iRawDataSize = 0;
165
- this.aRawDataBuffer = [];
166
-
167
- //下载RTP数据
168
- this.bWriteRTPData = true;
169
- this.iRTPDataSize = 0;
170
- this.aRTPDataBuffer = [];
171
- this.downloadRTP = false;
172
- this.rtpNum = 0;
173
-
174
- // 播放音视频标识
175
- this.bPlaySound = false;
176
- this.bPlay = false;
177
- this.bPause = false;
178
- this.bOnebyOne = false;
179
- this.bPlayRateChange = false;
180
- // this.bAudioTypeSupport = true;
181
- this.audioNum = 0;
182
- this.videoNum = 0;
183
-
184
- //帧进步长
185
- this.FrameForwardLen = 1;
186
-
187
- //纯音频播放标识
188
- this.bOnlyPlaySound = false;
189
-
190
- //是否使用裁剪宽高标识
191
- this.bVideoCropInfo = false;
192
-
193
- // 回调函数
194
- this.dataCallBackFun = null; // 截图回调函数
195
- this.YUVBufSizeCBFun = null; // YUV缓存大小回调函数
196
- this.DecCallBackFun = null;//解码回调函数
197
- this.DisplayCallBackFun = null; //显示回调函数
198
- this.PCMCallBackFun = null;//PCM数据回调
199
- this.DecInfoYUV = DECODE_INFO_YUV; //解码回调数据
200
- this.DisplayInfoYUV = DISPLAY_INFO_YUV; //显示回调数据
201
- this.DecInfoPCM = DECODE_INFO_PCM;//音频PCM回调数据
202
-
203
-
204
- // 图像宽高
205
- this.nWidth = 0;
206
- this.nHeight = 0;
207
-
208
- //图像的裁剪信息
209
- this.nSPSCropLeft = 0;
210
- this.nSPSCropRight = 0;
211
- this.nSPSCropTop = 0;
212
- this.nSPSCropBottom = 0;
213
-
214
- // 画布ID
215
- this.sCanvasId = null;
216
-
217
- // 显示图像数据缓存
218
- this.aDisplayBuf = null;
219
-
220
- // 页面是否激活
221
- this.bVisibility = true;
222
-
223
- // 解码类型
224
- this.nDecFrameType = DECODE_ALL;
225
-
226
- //实时信息回调
227
- this.runtimeInfoCBFun = null;
228
-
229
- // 电子放大
230
- this.iCanvasWidth = 0; // canvas宽
231
- this.iCanvasHeight = 0; // canvas高
232
- this.iZoomNum = 0; // 放大次数
233
- this.iRatio_x = 1; // X方向比率
234
- this.iRatio_y = 1; // Y方向比率
235
- this.stDisplayRect = {
236
- "top": 0,
237
- "left": 0,
238
- "right": 0,
239
- "bottom": 0
240
- }; // 上一次电子放大区域
241
- this.bDisRect = false;
242
- this.stYUVRect = {
243
- "top": 0,
244
- "left": 0,
245
- "right": 0,
246
- "bottom": 0
247
- }; // 映射到YUV上区域
248
-
249
- this.aInputDataLens = []; // 送入缓存数据长度列表
250
- /***********性能不足解决方案************/
251
- this.aInputDataBuffer = []; // 送入数据的缓存
252
- this.bIsGetYUV = false; // 获取YUV数据
253
- this.bIsFirstFrame = true; // 第一帧数据
254
- this.iInputMaxBufSize = BUFFER_MAX_SIZE; // 输入最大缓存大小
255
- this.bIsInput = false; // 输入数据
256
- this.bIsInputBufOver = false; // 输入缓存溢出
257
- this.bIsInputBufWillOver = false;//C层缓存将要溢出
258
- this.iInputDataLen = BUFFER_INPUT_SIZE; // 输入数据长度
259
-
260
- var that = this; // 保存this, 在onmessage回调中使用
261
- this.errorCode = PLAYM4_OK;
262
- this.loopNum = 0;
263
-
264
- // 回调设置
265
- this.setCallBack = function (that, cmd, data, errorCode, status) {
266
- // 回调函数参数
267
- var callBackParameter = CALLBACK_PARAMETER;
268
-
269
- callBackParameter.id = winId;
270
- callBackParameter.cmd = cmd;
271
- callBackParameter.data = data;
272
- callBackParameter.errorCode = errorCode;
273
- callBackParameter.status = status;
274
-
275
- that.fnCallBack(callBackParameter);
276
- };
277
-
278
- // 加载音频渲染js文件
279
- if (!bAudioRenderLoad) {
280
- bAudioRenderLoad = true;
281
- // var script_audio = document.createElement("script");
282
- // script_audio.type = "text/javascript";
283
- // script_audio.src = that.szBasePath + "AudioRenderer.js";
284
- // var head_audio = document.getElementsByTagName('head')[0];
285
- // head_audio.appendChild(script_audio);
286
- // script_audio.onload = script_audio.onreadystatechange = function () {
287
- // if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') {
288
- // if (this.bJSPrintLog) {
289
- // console.log(">>>JS AudioRenderer.js load finish!");
290
- // }
291
- // }
292
- // };
293
- }
294
-
295
- // 加载视频渲染js文件
296
- if (!bSuperRenderLoad) {
297
- bSuperRenderLoad = true;
298
- // var script_vedio = document.createElement("script");
299
- // script_vedio.type = "text/javascript";
300
- // script_vedio.src = that.szBasePath + "SuperRender_10.js";
301
- // var head_vedio = document.getElementsByTagName('head')[0];
302
- // head_vedio.appendChild(script_vedio);
303
- // script_vedio.onload = script_vedio.onreadystatechange = function () {
304
- // if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') {
305
- // if (this.bJSPrintLog) {
306
- // console.log(">>>JS SuperRender_10.js load finish!");
307
- // }
308
- // }
309
- // };
310
-
311
- }
312
-
313
- this.convertErrorCode = function (nErrorCode) {
314
- switch (nErrorCode) {
315
- case 1:
316
- return PLAYM4_OK;
317
-
318
- case 98:
319
- return PLAYM4_PARA_OVER;
320
-
321
- default:
322
- return nErrorCode;
323
- }
324
- };
325
-
326
- // ArrayBuffer复制
327
- this.arrayBufferCopy = function (srcArrayBuf) {
328
- var length = srcArrayBuf.byteLength;
329
- var destBuf = new Uint8Array(length);
330
- var srcBuf = new Uint8Array(srcArrayBuf);
331
-
332
- var i = 0;
333
- for (i = 0; i < length; i++) {
334
- destBuf[i] = srcBuf[i];
335
- }
336
-
337
- return destBuf;
338
- };
339
-
340
- // 送入数据
341
- this.inputDataFun = function () {
342
- var aReadBuf;
343
- var aSendBuf;
344
- var iSize = 0;
345
- that.bIsGetYUV = false;
346
- // 如果解析解码缓存溢出,则停止送入数据,直到缓存空闲后继续送入
347
- if (that.bIsInputBufOver || that.bIsInputBufWillOver) {
348
- aReadBuf = new Uint8Array(1);
349
- aSendBuf = new Uint8Array(aReadBuf);
350
- var message = { 'command': "InputData", 'data': aSendBuf.buffer, 'dataSize': 0 };
351
- that.decodeWorker.postMessage(message, [message.data]);
352
- } else {
353
- if ((that.bPlay && (!that.bPause || that.bOnebyOne)) || this.bOnlyPlaySound) {
354
- //播放或单帧前进时,往worker送流
355
- while (that.aInputDataLens.length > 0) {
356
- iSize += that.aInputDataLens.shift();
357
- if (iSize > that.iInputDataLen) {
358
- break;
359
- }
360
- }
361
- aReadBuf = that.aInputDataBuffer.splice(0, iSize);
362
- aSendBuf = new Uint8Array(aReadBuf);
363
- var message = { 'command': "InputData", 'data': aSendBuf.buffer, 'dataSize': iSize };
364
- that.decodeWorker.postMessage(message, [message.data]);
365
- }
366
- }
367
- aReadBuf = null;
368
- aSendBuf = null;
369
- };
370
-
371
- this.getPic = function (callBack, command) {
372
- if (this.decodeWorker == null || this.oSuperRender == null) {
373
- return PLAYM4_ORDER_ERROR;
374
- }
375
-
376
- if (!this.bPlay) {
377
- return PLAYM4_ORDER_ERROR;
378
- }
379
-
380
- if (callBack && typeof (callBack) === "function") {
381
- this.dataCallBackFun = callBack;
382
- } else {
383
- return PLAYM4_PARA_OVER;
384
- }
385
-
386
- // 映射到原图位置信息
387
- if (0 === this.iZoomNum) {
388
- this.stYUVRect.left = 0;
389
- this.stYUVRect.top = 0;
390
- this.stYUVRect.right = 0;
391
- this.stYUVRect.bottom = 0;
392
- } else {
393
- if (0 === this.iCanvasWidth || 0 === this.iCanvasHeight) {
394
- this.stYUVRect.left = 0;
395
- this.stYUVRect.top = 0;
396
- this.stYUVRect.right = 0;
397
- this.stYUVRect.bottom = 0;
398
- } else {
399
- var ratio_x = this.nWidth / this.iCanvasWidth;
400
- var ratio_y = this.nHeight / this.iCanvasHeight;
401
- this.stYUVRect.left = Math.round(this.stDisplayRect.left * ratio_x);
402
- this.stYUVRect.top = Math.round(this.stDisplayRect.top * ratio_y);
403
- this.stYUVRect.right = Math.round(this.stDisplayRect.right * ratio_x);
404
- this.stYUVRect.bottom = Math.round(this.stDisplayRect.bottom * ratio_y);
405
- }
406
-
407
- // 宽高必须大于32
408
- if ((this.stYUVRect.right - this.stYUVRect.left) < 32 || (this.stYUVRect.bottom - this.stYUVRect.top) < 32) {
409
- return PLAYM4_PARA_OVER;
410
- }
411
- }
412
-
413
- // 数据转换
414
- if (this.aDisplayBuf == null) {
415
- return PLAYM4_ORDER_ERROR;
416
- }
417
- var buf = this.arrayBufferCopy(this.aDisplayBuf);
418
-
419
- // 往 Worker 送数据
420
- var message = {
421
- 'command': command, 'data': buf.buffer, 'width': this.nWidth, 'height': this.nHeight,
422
- 'rect': this.stYUVRect
423
- };
424
- this.decodeWorker.postMessage(message, [message.data]);
425
-
426
- return PLAYM4_OK;
427
- };
428
-
429
- this.createWorker = function (self) {
430
- // 加载Worker
431
- if (window.Worker) { // 判断浏览器是否支持 Worker
432
- if (this.decodeWorker == null) {
433
- // 创建解码 Worker
434
- // this.decodeWorker = new Worker(that.szBasePath + "DecodeWorker.js");
435
- const workBlob = new Blob([DecodeWorkerString(this.staticPath)]);
436
- const url = URL.createObjectURL(workBlob);
437
- this.decodeWorker = new Worker(url);
438
-
439
- if (self.bJSPrintLog) {
440
- console.log(">>>JSPlayV1.1 createWorker success!");
441
- }
442
- if (this.decodeWorker == null) {
443
- return PLAYM4_WORKER_ERROR;
444
- }
445
- }
446
-
447
- // 接收 message
448
- this.decodeWorker.onmessage = function (evt) {
449
- var typeName = null;
450
- var eventData = evt.data;
451
- switch (eventData.function) {
452
- case "printLog":
453
- console.log("print JSPlayerSDK log failed");
454
- break;
455
-
456
- case "loaded":
457
- typeName = "loaded";
458
-
459
- self.setCallBack(self, "loaded", 0, 0, true);
460
- break;
461
-
462
- case "SetStreamOpenMode":
463
- typeName = "SetStreamOpenMode";
464
- break;
465
-
466
- case "OpenStream":
467
- typeName = "OpenStream";
468
- if (1 === eventData.errorCode) {
469
- that.bOpenStream = true;
470
- return;
471
- }
472
- break;
473
-
474
- case "InputData":
475
- typeName = "InputData";
476
-
477
- // 解析解码缓存溢出
478
- if (eventData.errorCode === PLAYM4_BUF_OVER) {
479
- that.bIsInputBufOver = true;
480
- console.log("yff inputBuffer over set key frame \n");
481
- if (that.nDecFrameType != DECODE_VIDEO_KEYFRAME) {
482
- that.PlayM4_SetDecodeFrameType(DECODE_VIDEO_KEYFRAME);//本地流功能测试,很容易送流过快,导致触发解I帧
483
- }
484
- //that.inputDataFun();
485
- }
486
- if (eventData.errorCode === PLAYM4_BUF_WILL_OVER) {
487
- that.bIsInputBufWillOver = true;
488
- //console.log("C buffer will over, C sourceRemain:"+eventData.sourceRemain);
489
-
490
- //that.inputDataFun();
491
- }
492
-
493
- // 解析解码缓存空闲(inputdata接口不会返回need more data)
494
- if (eventData.errorCode === PLAYM4_NEED_MORE_DATA) {
495
- //console.log(">>>JS inputdata need more data \n");
496
- that.bIsInputBufOver = false;
497
- that.bIsInputBufWillOver = false;
498
- if (that.aInputDataLens.length > 0 && that.bIsInput) {
499
- that.inputDataFun();
500
- that.bIsInput = false;
501
- } else {
502
- that.bIsGetYUV = true;
503
- }
504
- //console.log(">>> js inputdata need more data,aInputDataLens.length:"+that.aInputDataLens.length+" bIsGetYUV:"+that.bIsGetYUV+",bIsInput:"+that.bIsInput)
505
- }
506
- break;
507
-
508
- case "GetFrameData":
509
- typeName = "GetFrameData";
510
-
511
- if (!that.bOnlyPlaySound) {
512
- if (eventData.data != null && eventData.frameInfo != null) {
513
- // 获取图像宽高
514
- var width = eventData.frameInfo.width;
515
- var height = eventData.frameInfo.height;
516
- }
517
-
518
- if (!that.bPlay) {
519
- return;
520
- }
521
- that.errorCode = eventData.errorCode;
522
- //送数据策略,连续送5次后中断
523
- if (!that.bIsFirstFrame && (eventData.errorCode === PLAYM4_NEED_MORE_DATA || eventData.errorCode === PLAYM4_NEED_NEET_LOOP)) {
524
- if (eventData.errorCode === PLAYM4_NEED_MORE_DATA) {
525
- that.bIsInputBufOver = false;
526
- that.bIsInputBufWillOver = false;
527
- }
528
- //送数据策略
529
- if (that.loopNum > 5) {
530
- that.bIsGetYUV = true;
531
- that.loopNum = 0;
532
- } else {
533
- //setTimeout(that.inputDataFun(), 5);
534
- that.inputDataFun();
535
- that.loopNum++;//连续送数据计数
536
- }
537
- //console.log("loopNum:"+that.loopNum);
538
- break;
539
- } else if (that.bIsInputBufOver || that.bIsInputBufWillOver) {
540
- // 解析缓存溢出
541
- that.inputDataFun();
542
- } else {
543
- if (eventData.type === "videoType") {
544
- if (that.aInputDataLens.length > 0 && that.bIsInput) {
545
- that.inputDataFun();
546
- that.bIsInput = false;
547
- } else {
548
- that.bIsGetYUV = true;
549
- }
550
-
551
- that.bIsFirstFrame = false;
552
- }
553
- }
554
-
555
- }
556
-
557
- // web页面激活时才缓存音视频数据
558
- if (that.bVisibility) {
559
- if (PLAYM4_OK === eventData.errorCode) {
560
- switch (eventData.type) {
561
- case "videoType":
562
- if (eventData.data == null || eventData.frameInfo == null) {
563
- return PLAYM4_PARA_OVER;
564
- }
565
- //显示回调
566
- if (that.DecCallBackFun != null) {
567
- that.DecInfoYUV.height = eventData.frameInfo.height;
568
- that.DecInfoYUV.width = eventData.frameInfo.width;
569
- that.DecInfoYUV.frameNum = eventData.frameInfo.frameNum;
570
- that.DecInfoYUV.yuvData = new Uint8Array(eventData.data);
571
- that.DecCallBackFun(that.DecInfoYUV)
572
- }
573
- that.bIsFirstFrame = false;
574
-
575
- //处理视频数据
576
- self.nWidth = eventData.frameInfo.width;
577
- self.nHeight = eventData.frameInfo.height;
578
- self.nSPSCropLeft = eventData.frameInfo.cropLeft;
579
- self.nSPSCropRight = eventData.frameInfo.cropRight;
580
- self.nSPSCropTop = eventData.frameInfo.cropTop;
581
- self.nSPSCropBottom = eventData.frameInfo.cropBottom;
582
-
583
- var oVideoFrameInfo = new Object();
584
- oVideoFrameInfo.data = eventData.data;
585
- oVideoFrameInfo.osdTime = eventData.osd;
586
- oVideoFrameInfo.nWidth = eventData.frameInfo.width;
587
- oVideoFrameInfo.nHeight = eventData.frameInfo.height;
588
- oVideoFrameInfo.frameNum = eventData.frameInfo.frameNum;
589
- oVideoFrameInfo.timeStamp = eventData.frameInfo.timeStamp;
590
-
591
- //打印10帧YUV视频
592
- if (self.bWriteYUVData) {
593
- var bufferPackage = new Uint8Array(eventData.data);
594
- var iIndexBuffer = self.aVideoYUVBuffer.length;
595
- for (var i = 0, iLen = bufferPackage.length; i < iLen; i++) {
596
- self.aVideoYUVBuffer[iIndexBuffer + i] = bufferPackage[i];
597
- }
598
- self.iYUV10size++;
599
- bufferPackage = null;
600
- }
601
- if (self.bWriteYUVData && self.iYUV10size >= WRITE_VID_YUV_NUM) {
602
- var YUVbuffer = new Uint8Array(self.aVideoYUVBuffer);
603
- self.downloadFile(YUVbuffer, "videoYUV.data");
604
- self.aVideoYUVBuffer.splice(0, self.aVideoYUVBuffer.length);//清空PCM缓存
605
- self.bWriteYUVData = false;
606
- self.iYUV10size = 0;
607
- YUVbuffer = null;
608
- }
609
- /*******打印结束*****/
610
- self.aVideoFrameBuffer.push(oVideoFrameInfo);
611
- oVideoFrameInfo = null;
612
-
613
- // 如果YUV缓存大于阈值时进行抽帧显示,防止内存快速增长导致浏览器崩溃
614
- var iYUVNum = self.aVideoFrameBuffer.length;
615
- if (iYUVNum > BUFFER_MAXNUM_YUV) {
616
- // 非单帧模式下进行该处理
617
- // YUV缓存超过BUFFER_MAXNUM_YUV个节点后隔YUV_SKIP_NUM个帧播一帧
618
- if (!self.bOnebyOne) {
619
- self.aVideoFrameBuffer.splice(0, YUV_SKIP_NUM);
620
- }
621
- }
622
- // 单帧
623
- if (self.bOnebyOne) {
624
- // 缓存满,通知上层停止送流
625
- if (self.aVideoFrameBuffer.length >= BUFFER_MAXNUM_ONEBYONE) {
626
- self.setCallBack(self, "OnebyOne", 0, 0, false);
627
-
628
- // 下次直接从缓存读取数据
629
- self.bIsFirstFrame = true;
630
- break;
631
- }
632
- }
633
- break;
634
-
635
- case "audioType":
636
- if ((self.bPlaySound && !self.bPlayRateChange) || that.bOnlyPlaySound) {
637
- //音频PCM回调
638
- if (that.PCMCallBackFun != null) {
639
- that.DecInfoPCM.sampleRate = eventData.frameInfo.samplesPerSec;
640
- that.DecInfoPCM.channel = eventData.frameInfo.channels;
641
- that.DecInfoPCM.bitsPerSample = eventData.frameInfo.bitsPerSample;
642
- that.DecInfoPCM.pcmData = new Uint8Array(eventData.data);
643
- that.DecInfoPCM.length = that.DecInfoPCM.pcmData.length;
644
- that.PCMCallBackFun(that.DecInfoPCM)
645
- }
646
-
647
- //处理音频数据
648
- var bufferPackage = new Uint8Array(eventData.data);
649
- var iIndexBuffer = self.aAudioBuffer.length;
650
- for (var i = 0, iLen = bufferPackage.length; i < iLen; i++) {
651
- self.aAudioBuffer[iIndexBuffer + i] = bufferPackage[i];
652
- }
653
- self.iAudioBufferSize++;
654
- bufferPackage = null;
655
-
656
- //打印10帧PCM音频
657
- if (self.bWritePCMData) {
658
- var bufferPackage = new Uint8Array(eventData.data);
659
- var iIndexBuffer = self.aAudioPCMBuffer.length;
660
- for (var i = 0, iLen = bufferPackage.length; i < iLen; i++) {
661
- self.aAudioPCMBuffer[iIndexBuffer + i] = bufferPackage[i];
662
- }
663
- console.log("audio_type num:" + self.iAudioBuffer500Size + ", len:" + bufferPackage.length);
664
- self.iAudioBuffer500Size++;
665
- bufferPackage = null;
666
- }
667
-
668
- if (self.bWritePCMData && self.iAudioBuffer500Size >= WRITE_AUD_PCM_NUM) {
669
- var PCMbuffer = new Uint8Array(self.aAudioPCMBuffer);
670
- self.downloadFile(PCMbuffer, "audioPCM.data");
671
- self.aAudioPCMBuffer.splice(0, self.aAudioPCMBuffer.length);//清空PCM缓存
672
- self.bWritePCMData = false;
673
- self.iAudioBuffer500Size = 0;
674
- PCMbuffer = null;
675
- }
676
- /********打印结束*****/
677
-
678
- // 储存25帧播放一次
679
- if (self.iAudioBufferSize >= BUFFER_NUM_AUDIO) {
680
- // 播放
681
- self.audioRenderer.Play(self.aAudioBuffer, self.aAudioBuffer.length, eventData.frameInfo);
682
- self.aAudioBuffer.splice(0, self.aAudioBuffer.length);
683
- self.aAudioBuffer.length = 0;
684
- self.iAudioBufferSize = 0;
685
- }
686
- }
687
- break;
688
-
689
- case "privateType":
690
- break;
691
-
692
- default:
693
- break;
694
- }
695
- }
696
-
697
- }
698
- break;
699
- case "GetRawData":
700
- typeName = "GetRawData";
701
- /********打印10帧裸数据*****/
702
- if (self.bWriteRawData) {
703
- var bufferRawPackage = new Uint8Array(eventData.data);
704
- var iIndexRawBuffer = self.aRawDataBuffer.length;
705
- for (var i = 0, iLen = bufferRawPackage.length; i < iLen; i++) {
706
- self.aRawDataBuffer[iIndexRawBuffer + i] = bufferRawPackage[i];
707
- }
708
- self.iRawDataSize++;
709
- bufferRawPackage = null;
710
- }
711
-
712
- if (self.bWriteRawData && self.iRawDataSize >= WRITE_VID_RAW_NUM) {
713
- var RAWbuffer = new Uint8Array(self.aRawDataBuffer);
714
- self.downloadFile(RAWbuffer, "rawBuffer.data");
715
- self.aRawDataBuffer.splice(0, self.aRawDataBuffer.length);//清空PCM缓存
716
- self.bWriteRawData = false;
717
- self.iRawDataSize = 0;
718
- RAWbuffer = null;
719
- }
720
- /********打印结束*****/
721
- break;
722
-
723
- case "PlaySound":
724
- typeName = "PlaySound";
725
- break;
726
-
727
- case "GetJPEG":
728
- typeName = "GetJPEG";
729
-
730
- if (eventData.errorCode !== PLAYM4_OK) {
731
- console.log("GetJPEG ErrorParam");
732
- return;
733
- }
734
- // 获取图像宽高
735
- var pJpegData = eventData.data;
736
-
737
- self.dataCallBackFun(pJpegData);
738
- break;
739
-
740
- case "GetBMP":
741
- typeName = "GetBMP";
742
-
743
- if (eventData.errorCode !== PLAYM4_OK) {
744
- console.log("GetBMP ErrorParam");
745
- return;
746
- }
747
- // 获取图像宽高
748
- var pBmpData = eventData.data;
749
-
750
- self.dataCallBackFun(pBmpData);
751
- break;
752
- case "RunTimeInfoCallBack":
753
- typeName = "RunTimeInfoCallBack";
754
- let runTimeModule = eventData.nRunTimeModule;
755
- let strVersion = eventData.nStrVersion;
756
- let frameTimeStamp = eventData.nFrameTimeStamp;
757
- let frameNum = eventData.nFrameNum;
758
- let errorCode = eventData.nErrorCode;
759
- if (self.runtimeInfoCBFun != null) {
760
- self.runtimeInfoCBFun(runTimeModule, strVersion, frameTimeStamp, frameNum, errorCode);
761
- }
762
- default:
763
- break;
764
- }
765
- //如果返回错误码该如何处理
766
-
767
- // 回调方式返回错误码
768
- if ("GetFrameData" !== typeName && "loaded" != typeName) {
769
- self.setCallBack(self, typeName, 0, self.convertErrorCode(eventData.errorCode), true);
770
- } else {
771
-
772
- if (PLAYM4_SYS_NOT_SUPPORT === eventData.errorCode || PLAYM4_FIRST_FRAME_NOT_ICURRENT === eventData.errorCode || PLAYM4_ITYPE_DECODE_ERROR === eventData.errorCode || PLAYM4_NOT_KEYFRAME === eventData.errorCode) {
773
- self.setCallBack(self, typeName, 0, self.convertErrorCode(eventData.errorCode), true);
774
- }
775
- }
776
- };
777
- }
778
- };
779
-
780
- this.createWorker(that);
781
-
782
- // 视频渲染
783
- this.draw = function () {
784
- if (that.bPlay) {
785
- if (!that.bPause || that.bOnebyOne) {
786
- // that.bPause:true 暂停
787
- requestAnimationFrame(that.draw);
788
-
789
- var iYUVNum = that.aVideoFrameBuffer.length;
790
- if (that.YUVBufSizeCBFun != null) {
791
- that.YUVBufSizeCBFun(iYUVNum);
792
- }
793
- if (that.bOnebyOne) {
794
- // 缓存不够,通知上层开始送流
795
- if (iYUVNum <= BUFFER_MINNUM_ONEBYONE) {
796
- that.setCallBack(that, "OnebyOne", 0, PLAYM4_NEED_MORE_DATA, true);
797
- }
798
- if (iYUVNum <= that.FrameForwardLen + 1) {
799
- that.setCallBack(that, "OnebyOne", 0, PLAYM4_NEED_MORE_DATA, true);
800
- return;
801
- } else {
802
- var frameForwardLen = that.FrameForwardLen;
803
- while (frameForwardLen > 1) {
804
- var framevuffer = that.aVideoFrameBuffer.shift();
805
- frameForwardLen--;
806
- }
807
- }
808
- that.bOnebyOne = false;
809
- }
810
-
811
- if (iYUVNum > 0) {
812
- var oVideoFrameInfo = that.aVideoFrameBuffer.shift();
813
-
814
- that.aDisplayBuf = oVideoFrameInfo.data;
815
- var displayBuf = new Uint8Array(that.aDisplayBuf);
816
- if (that.bVideoCropInfo) {
817
- that.oSuperRender.SR_DisplayFrameData(oVideoFrameInfo.nWidth, oVideoFrameInfo.nHeight, displayBuf, oVideoFrameInfo.nWidth - that.nSPSCropLeft - that.nSPSCropRight, oVideoFrameInfo.nHeight - that.nSPSCropTop - that.nSPSCropBottom);
818
- }
819
- else {
820
- that.oSuperRender.SR_DisplayFrameData(oVideoFrameInfo.nWidth, oVideoFrameInfo.nHeight, displayBuf, oVideoFrameInfo.nWidth, oVideoFrameInfo.nHeight);
821
- }
822
- if (that.DisplayCallBackFun != null) {
823
- that.DisplayInfoYUV.height = oVideoFrameInfo.nHeight;
824
- that.DisplayInfoYUV.width = oVideoFrameInfo.nWidth;
825
- that.DisplayInfoYUV.frameNum = oVideoFrameInfo.frameNum;
826
- that.DisplayInfoYUV.yuvData = new Uint8Array(displayBuf);
827
- that.DisplayCallBackFun(that.DisplayInfoYUV)
828
- }
829
-
830
- displayBuf = null;
831
- // 当前OSD时间
832
- that.szOSDTime = oVideoFrameInfo.osdTime;
833
- oVideoFrameInfo = null;
834
- } else {
835
- that.setCallBack(that, "Play", 0, PLAYM4_NEED_MORE_DATA, true);
836
- }
837
- }
838
- } else {
839
- if (!that.bPlay) {
840
- // 停止播放清空视频帧和音频帧数据缓存
841
- that.aVideoFrameBuffer.splice(0, that.aVideoFrameBuffer.length);
842
- that.aAudioBuffer.splice(0, that.aAudioBuffer.length);
843
- }
844
- }
845
- };
846
- }
847
-
848
- /**
849
- * @synopsis 根据帧号进行精确定位
850
- * @param nFrameNum [IN] 定位帧号
851
- * @param playType [IN] 定位后是否继续播放。true为继续播放,false为暂停播放
852
- */
853
- PlayM4_SetCurrentFrameNum(nFrameNum, playType) {
854
- return PLAYM4_SYS_NOT_SUPPORT;
855
- }
856
-
857
- /**
858
- * @synopsis 播放库打印日志开关
859
- * @param downloadFlag [IN] true为打开日志,false为关闭日志
860
- * @returns 返回错误码
861
- */
862
- PlayM4_OpenPlayerSDKPrintLog(downloadFlag) {
863
- if (downloadFlag === true) {
864
- this.bJSPrintLog = true;
865
- this.decodeWorker.postMessage({ 'command': "printLog", 'data': downloadFlag });
866
- } else {
867
- this.bJSPrintLog = false;
868
- this.decodeWorker.postMessage({ 'command': "printLog", 'data': downloadFlag });
869
- }
870
- return PLAYM4_OK;
871
-
872
- }
873
-
874
- /**
875
- * @synopsis 下载YUV数据开关
876
- */
877
- PlayM4_DownloadYUVdata() {
878
- this.bWriteYUVData = true;
879
- return PLAYM4_OK;
880
- }
881
-
882
- /**
883
- * @synopsis 下载PCM数据开关
884
- */
885
- PlayM4_DownloadPCMdata() {
886
- this.bWritePCMData = true;
887
- return PLAYM4_OK;
888
- }
889
-
890
- /**
891
- * @synopsis 设置解码回调
892
- * @param DecCBFun [IN] 解码回调函数
893
- * @returns 返回错误码
894
- */
895
- PlayM4_SetDecCallBack(DecCBFun) {
896
- if (DecCBFun && typeof (DecCBFun) === "function") {
897
- this.DecCallBackFun = DecCBFun;
898
- return PLAYM4_OK;
899
- } else {
900
- return PLAYM4_PARA_OVER;
901
- }
902
- }
903
-
904
- /**
905
- * @synopsis 设置显示回调
906
- * @param DecCBFun [IN] 显示回调函数
907
- * @returns 返回错误码
908
- */
909
- PlayM4_SetDisplayCallBack(DisplayCBFun) {
910
- if (DisplayCBFun && typeof (DisplayCBFun) === "function") {
911
- this.DisplayCallBackFun = DisplayCBFun;
912
- return PLAYM4_OK;
913
- } else {
914
- return PLAYM4_PARA_OVER;
915
- }
916
- }
917
-
918
- /**
919
- * @synopsis 设置音频PCM数据回调
920
- * @param DecCBFun [IN] 音频回调函数
921
- * @returns 返回错误码
922
- */
923
- PlayM4_SetPCMCallBack(PCMCBFun) {
924
- if (PCMCBFun && typeof (PCMCBFun) === "function") {
925
- this.PCMCallBackFun = PCMCBFun;
926
- return PLAYM4_OK;
927
- } else {
928
- return PLAYM4_PARA_OVER;
929
- }
930
- }
931
-
932
- /**
933
- * @synopsis 设置开启流播放模式
934
- *
935
- * @param nMode [IN] 打开方式
936
- *
937
- * @returns 状态码
938
- */
939
- PlayM4_SetStreamOpenMode(nMode) {
940
- if (nMode == null || nMode === undefined) {
941
- return PLAYM4_PARA_OVER;
942
- }
943
-
944
- if (nMode !== STREAM_REALTIME && nMode !== STREAM_FILE) {
945
- return PLAYM4_PARA_OVER;
946
- }
947
-
948
- this.streamOpenMode = nMode;
949
-
950
- return PLAYM4_OK;
951
- }
952
- PlayM4_DownloadRTPData(downloadFlag) {
953
- this.downloadRTP = downloadFlag;
954
- }
955
-
956
- PlayM4_SetVideoCropInfo(nFlag) {
957
- if (nFlag == null || nFlag === undefined) {
958
- return PLAYM4_PARA_OVER;
959
- }
960
-
961
- if (typeof (nFlag) !== "boolean") {
962
- return PLAYM4_PARA_OVER;
963
- }
964
-
965
- this.bVideoCropInfo = nFlag;
966
-
967
- return PLAYM4_OK;
968
- }
969
- /**
970
- * @synopsis 实时流、回放流时字节头开流
971
- *
972
- * @param pFileHeadBuf 文件头缓存数据
973
- * @param nSize 文件头缓存大小
974
- * @param nBufPoolSize 流缓存大小
975
- *
976
- * @returns 状态码
977
- */
978
- PlayM4_OpenStream(pFileHeadBuf, nSize, nBufPoolSize) {
979
- if (this.bJSPrintLog) {
980
- console.log(">>>JS PlayM4_OpenStream nSysTime:" + (new Date().getMonth() + 1) + "-" + new Date().getDate() + " " + new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds() + "." + new Date().getMilliseconds());
981
- }
982
- if (this.decodeWorker == null) {
983
- return PLAYM4_ORDER_ERROR;
984
- }
985
-
986
- if (this.downloadRTP) {
987
- var apRTPHeadData = new Uint8Array(pFileHeadBuf.buffer);
988
- this.DownloadRTPData(apRTPHeadData);
989
- console.log("write 40 hik head");
990
- }
991
-
992
- if (pFileHeadBuf == null || nSize <= 0 || nBufPoolSize <= 0) {
993
- return PLAYM4_PARA_OVER;
994
- }
995
-
996
- // 单帧后恢复回放,清除状态值
997
- this.bPlay = false;
998
- this.bPause = false;
999
- this.bOnebyOne = false;
1000
- this.bIsFirstFrame = true;
1001
- this.bIsGetYUV = false;
1002
- this.bIsInput = false;
1003
-
1004
- // 往 Worker 送数据
1005
- this.decodeWorker.postMessage({ 'command': "SetStreamOpenMode", 'data': this.streamOpenMode });
1006
- // 往 Worker 送数据
1007
- this.decodeWorker.postMessage({
1008
- 'command': "OpenStream",
1009
- 'data': pFileHeadBuf,
1010
- 'dataSize': nSize,
1011
- 'bufPoolSize': nBufPoolSize
1012
- });
1013
-
1014
- this.bOpenStream = true;
1015
- return PLAYM4_OK;
1016
- }
1017
-
1018
-
1019
- /**
1020
- * @synopsis 关闭流
1021
- *
1022
- * @returns 状态码
1023
- */
1024
- PlayM4_CloseStream() {
1025
- if (this.decodeWorker === null || this.bOpenStream === false) {
1026
- return PLAYM4_ORDER_ERROR;
1027
- }
1028
-
1029
- this.bOnlyPlaySound = false;
1030
-
1031
- this.PlayM4_Stop();
1032
-
1033
- // 往 Worker 送数据
1034
- this.decodeWorker.postMessage({ 'command': "CloseStream" });
1035
-
1036
- if (this.oSuperRender !== null) {
1037
- // 释放渲染资源
1038
- this.oSuperRender.SR_Destroy();
1039
- this.oSuperRender = null;
1040
- }
1041
-
1042
- if (this.audioRenderer !== null) {
1043
- // 释放渲染资源
1044
- this.audioRenderer.Stop();
1045
- this.audioRenderer = null;
1046
- }
1047
-
1048
- // 清空缓存
1049
- this.aAudioBuffer.splice(0, this.aAudioBuffer.length);
1050
- this.aVideoFrameBuffer.splice(0, this.aVideoFrameBuffer.length);
1051
- this.aInputDataBuffer.splice(0, this.aInputDataBuffer.length);
1052
- this.aInputDataLens.splice(0, this.aInputDataLens.length);
1053
- this.aVideoYUVBuffer.splice(0, this.aVideoYUVBuffer.length);
1054
- this.aAudioPCMBuffer.splice(0, this.aAudioPCMBuffer.length);
1055
- this.aRawDataBuffer.splice(0, this.aRawDataBuffer.length);
1056
-
1057
- this.bOpenStream = false;
1058
- this.iAudioBufferSize = 0;
1059
- this.szOSDTime = null;
1060
-
1061
- return PLAYM4_OK;
1062
- }
1063
-
1064
- /**
1065
- * @synopsis 销毁,关闭worker
1066
- *
1067
- * @returns 状态码
1068
- */
1069
- PlayM4_Destroy() {
1070
- if (this.decodeWorker === null) {
1071
- return PLAYM4_OK;
1072
- }
1073
-
1074
- this.PlayM4_CloseStream();
1075
-
1076
-
1077
- this.decodeWorker.terminate(); // 停止 Worker 工作
1078
- this.decodeWorker = null;
1079
- return PLAYM4_OK;
1080
- }
1081
-
1082
- /**
1083
- * @synopsis 实时流、回放流送数据
1084
- *
1085
- * @param dataBuf [IN] 输入数据缓存
1086
- * @param nSize [IN] 输入数据大小
1087
- *
1088
- * @returns 状态码
1089
- */
1090
- PlayM4_InputData(dataBuf, nSize) {
1091
- //if (this.decodeWorker === null || this.bOpenStream === false) {
1092
- // return PLAYM4_ORDER_ERROR;
1093
- // }
1094
- //console.log(">>>JSPlaySDKInterface.js PlayM4_InputData nSize:"+nSize+",bIsGetYUV:"+this.bIsGetYUV+",bIsInput:"+this.bIsInput);
1095
- var iInputBufLen = this.aInputDataBuffer.length;
1096
-
1097
- // 结束送流标识位[0x01, 0x02, 0x03, 0x04]
1098
- if (nSize === 4) {
1099
- var aBuf = new Uint8Array(dataBuf.buffer);
1100
- if (aBuf[0] === 0x01 && aBuf[1] === 0x02 && aBuf[2] === 0x03 && aBuf[3] === 0x04) {
1101
- if (this.bIsFirstFrame) {
1102
- // 直接往 Worker 送数据
1103
- this.inputDataFun();
1104
- } else {
1105
- if (this.bIsGetYUV) {
1106
- this.inputDataFun();
1107
- } else {
1108
- this.bIsInput = true;
1109
- }
1110
- }
1111
-
1112
- aBuf = null;
1113
- return PLAYM4_OK;
1114
- }
1115
- }
1116
- // 超出设置的缓存阈值,返回错误码(缓存溢出)
1117
- if (iInputBufLen + nSize > this.iInputMaxBufSize) {
1118
- console.log("input over");
1119
- //this.inputDataFun();
1120
- if (this.bIsGetYUV) {
1121
- this.inputDataFun();
1122
- } else {
1123
- this.bIsInput = true;
1124
- }
1125
- return PLAYM4_BUF_OVER;
1126
- }
1127
-
1128
- // 写入缓存,添加4字节头
1129
- var tempBuf = null;
1130
- var iDataLen = nSize;
1131
- switch (this.streamOpenMode) {
1132
- case STREAM_FILE:
1133
- tempBuf = new Uint8Array(dataBuf.buffer);
1134
- if (this.downloadRTP) {
1135
- this.DownloadRTPData(tempBuf);
1136
- this.rtpNum++;
1137
- console.log("STREAM_FILE psNUm:" + this.rtpNum);
1138
- }
1139
- this.aInputDataLens.push(nSize);
1140
- break;
1141
-
1142
- case STREAM_REALTIME:
1143
- // 加4字节长度信息
1144
- iDataLen = nSize + 4;
1145
- var a32 = new Uint32Array([nSize]);
1146
- var a8 = new Uint8Array(a32.buffer);
1147
- tempBuf = new Uint8Array(iDataLen);
1148
- tempBuf.set(a8, 0);
1149
- tempBuf.set(dataBuf, 4);
1150
- if (this.downloadRTP) {
1151
- this.DownloadRTPData(tempBuf);
1152
- this.rtpNum++;
1153
- console.log("STREAM_REALTIME rtpNUm:" + this.rtpNum);
1154
- }
1155
- a32 = null;
1156
- a8 = null;
1157
-
1158
- this.aInputDataLens.push(nSize + 4);
1159
- break;
1160
-
1161
- default:
1162
- return PLAYM4_SYS_NOT_SUPPORT;
1163
- }
1164
-
1165
- for (var i = 0; i < iDataLen; i++) {
1166
- this.aInputDataBuffer[iInputBufLen + i] = tempBuf[i];
1167
- }
1168
- if ((!this.bPlay && !this.bOnlyPlaySound) || this.decodeWorker === null || this.bOpenStream === false) {
1169
- return PLAYM4_OK;
1170
- }
1171
- tempBuf = null;
1172
- if (this.bOnlyPlaySound) {
1173
- //直接送音频帧,一个RTP包一个音频帧
1174
- this.inputDataFun();
1175
- } else {
1176
-
1177
- if (this.bIsFirstFrame) {
1178
- // 首帧直接往 Worker 送数据
1179
- this.inputDataFun();
1180
- } else {
1181
- if (this.bIsGetYUV) {
1182
- this.inputDataFun();
1183
- } else {
1184
- this.bIsInput = true;
1185
- }
1186
- }
1187
- }
1188
- return PLAYM4_OK;
1189
- }
1190
-
1191
- DownloadRTPData(rtpData) {
1192
- if (this.bWriteRTPData) {
1193
-
1194
- var bufferPackage = new Uint8Array(rtpData);
1195
- var iIndexBuffer = this.aRTPDataBuffer.length;
1196
- for (var i = 0, iLen = bufferPackage.length; i < iLen; i++) {
1197
- this.aRTPDataBuffer[iIndexBuffer + i] = bufferPackage[i];
1198
- }
1199
- this.iRTPDataSize++;
1200
- bufferPackage = null;
1201
- }
1202
- if (this.bWriteRTPData && this.iRTPDataSize >= WRITE_RTP_NUM) {
1203
- console.log("download" + WRITE_RTP_NUM + "RTPdata");
1204
- var RTPbuffer = new Uint8Array(this.aRTPDataBuffer);
1205
- this.downloadFile(RTPbuffer, "RTP.data");
1206
- this.aRTPDataBuffer.splice(0, this.aRTPDataBuffer.length);//清空YUV缓存
1207
- //this.bWriteRTPData = false; 应注释,修复再次调用无法下载数据的问题
1208
- this.iRTPDataSize = 0;
1209
- this.rtpNum = 0;
1210
- this.downloadRTP = false;
1211
- RTPbuffer = null;
1212
- }
1213
- }
1214
- /**
1215
- * @synopsis 开启播放
1216
- *
1217
- * @param canvasID [IN] 窗口id
1218
- *
1219
- * @returns 状态码
1220
- */
1221
- PlayM4_Play(canvasID) {
1222
-
1223
- if (this.decodeWorker === null) {
1224
- return PLAYM4_ORDER_ERROR;
1225
- }
1226
- //canvasID传入为null,则表示只送入纯音频js播放库进行播放
1227
- if (this.bJSPrintLog) {
1228
- console.log(">>>JS PlayM4_Play canvasID: " + canvasID);
1229
- }
1230
- if (canvasID === null) {
1231
- //console.log(">>>>>>>>> PlayM4_Play 2-1 nSysTime:" + (new Date().getMonth()+1) + "-" + new Date().getDate() + " " + new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds() + "." + new Date().getMilliseconds());
1232
- this.bOnlyPlaySound = true;
1233
- //console.log("fzj---------------------------------true");
1234
- // 往 Worker 送数据
1235
- this.decodeWorker.postMessage({
1236
- 'command': "OnlyPlaySound"
1237
- });
1238
- this.sCanvasId = null;
1239
- } else {
1240
- if (typeof (canvasID) !== "string") {
1241
- return PLAYM4_PARA_OVER;
1242
- }
1243
-
1244
- if (this.bOnebyOne) {
1245
- this.bPlayRateChange = false;
1246
- this.bOnebyOne = false;
1247
- this.bPause = false;
1248
- this.draw();
1249
- }
1250
-
1251
- if (this.bPlay) {
1252
- return PLAYM4_OK;
1253
- }
1254
-
1255
- // 创建视频渲染句柄
1256
- if (this.oSuperRender == null) {
1257
- this.oSuperRender = new SuperRender(canvasID, this.szBasePath);
1258
- if (this.oSuperRender == null) {
1259
- return PLAYM4_CREATE_RENDERER_ERROR;
1260
- }
1261
- }
1262
-
1263
- this.sCanvasId = canvasID;
1264
-
1265
- // 初始化
1266
- this.bPlay = true;
1267
- this.bPause = false;
1268
- this.bOnebyOne = false;
1269
-
1270
- // 关闭声音
1271
- // this.bPlaySound = false;
1272
- this.bPlayRateChange = false;
1273
- this.bOnlyPlaySound = false;
1274
- this.draw();
1275
- //console.log(">>>>>>>>> PlayM4_Play 2-2 nSysTime:" + (new Date().getMonth()+1) + "-" + new Date().getDate() + " " + new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds() + "." + new Date().getMilliseconds());
1276
- }
1277
-
1278
- // 创建音频渲染句柄
1279
- if (this.audioRenderer == null) {
1280
- this.audioRenderer = new AudioRenderer();
1281
- if (this.audioRenderer == null) {
1282
- return PLAYM4_CREATE_RENDERER_ERROR;
1283
- }
1284
- }
1285
- this.decodeWorker.postMessage({
1286
- 'command': "Play"
1287
- });
1288
- //console.log(">>>>>>>>> PlayM4_Play 3 nSysTime:" + (new Date().getMonth()+1) + "-" + new Date().getDate() + " " + new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds() + "." + new Date().getMilliseconds());
1289
- return PLAYM4_OK;
1290
- }
1291
-
1292
- /**
1293
- * @synopsis 停止播放
1294
- *
1295
- * @returns 状态码
1296
- */
1297
- PlayM4_Stop() {
1298
- if (this.decodeWorker == null || this.oSuperRender == null) {
1299
- return PLAYM4_ORDER_ERROR;
1300
- }
1301
-
1302
- if (!this.bPlay) {
1303
- return PLAYM4_ORDER_ERROR;
1304
- }
1305
-
1306
- // 关闭声音
1307
- if (this.bPlaySound) {
1308
- this.PlayM4_StopSound();
1309
- this.bPlaySound = true;
1310
- }
1311
-
1312
- this.bPlay = false;
1313
- this.bOnebyOne = false;
1314
- this.bPause = false;
1315
-
1316
- // 关闭电子放大
1317
- this.oSuperRender.SR_SetDisplayRect(null);
1318
- this.iZoomNum = 0;
1319
- this.bDisRect = false;
1320
-
1321
- // 画布置黑
1322
- // if (this.bVideoCropInfo) {
1323
- // this.oSuperRender.SR_DisplayFrameData(this.nWidth, this.nHeight, null, this.nWidth - this.nSPSCropLeft - this.nSPSCropRight, this.nHeight - this.nSPSCropTop - this.nSPSCropBottom);
1324
- // }
1325
- // else {
1326
- // this.oSuperRender.SR_DisplayFrameData(this.nWidth, this.nHeight, null, this.nWidth, this.nHeight);
1327
- // }
1328
- // let oldCanvas = document.getElementById(this.sCanvasId);
1329
- // if (oldCanvas) {
1330
- // this.clonedCanvas = oldCanvas.cloneNode(true); // 克隆节点
1331
- // this.clonedCanvasParentNode = oldCanvas.parentNode;
1332
- // oldCanvas.parentNode.removeChild(oldCanvas);
1333
- // this.clonedCanvasParentNode.replaceChild(this.clonedCanvas, oldCanvas);
1334
- // }
1335
- return PLAYM4_OK;
1336
- }
1337
-
1338
- /**
1339
- * @synopsis 播放速率
1340
- *
1341
- * @param nPlayRate [IN] 倍率
1342
- *
1343
- * @returns 状态码
1344
- */
1345
- PlayM4_PlayRate(nPlayRate) {
1346
- if (this.decodeWorker == null) {
1347
- return PLAYM4_ORDER_ERROR;
1348
- }
1349
-
1350
- if (nPlayRate === 1) {
1351
- this.bPlayRateChange = false;
1352
- } else {
1353
- this.bPlayRateChange = true;
1354
- }
1355
-
1356
- if (nPlayRate < 1) {
1357
- nPlayRate = 1;
1358
- }
1359
- this.iInputDataLen = nPlayRate * BUFFER_INPUT_SIZE;
1360
- this.decodeWorker.postMessage({
1361
- 'command': "PlayRate",
1362
- 'playRate': nPlayRate
1363
- });
1364
-
1365
- return PLAYM4_OK;
1366
- }
1367
-
1368
- /**
1369
- * @synopsis 暂停播放
1370
- *
1371
- * @param pause [IN] 暂停/恢复标识
1372
- *
1373
- * @returns 状态码
1374
- */
1375
- PlayM4_Pause(pause) {
1376
- if (this.decodeWorker == null || this.oSuperRender == null) {
1377
- return PLAYM4_ORDER_ERROR;
1378
- }
1379
-
1380
- if (!this.bPlay) {
1381
- return PLAYM4_ORDER_ERROR;
1382
- }
1383
-
1384
- if (this.bOnebyOne) {
1385
- return PLAYM4_ORDER_ERROR;
1386
- }
1387
-
1388
- if (this.bPause == pause) {
1389
- return PLAYM4_ORDER_ERROR;
1390
- }
1391
-
1392
- if (typeof (pause) !== "boolean") {
1393
- return PLAYM4_PARA_OVER;
1394
- }
1395
-
1396
- this.bPause = pause;
1397
- // this.bOnebyOne = false;
1398
- // 下次直接从缓存读取数据
1399
- this.bIsFirstFrame = true;
1400
- if (pause) {
1401
- if (this.bPlaySound) {
1402
- this.PlayM4_StopSound();
1403
- this.bPlaySound = true;
1404
- }
1405
- } else {
1406
- if (this.bPlaySound) {
1407
- this.PlayM4_PlaySound();
1408
- }
1409
-
1410
- this.draw();
1411
- }
1412
- return PLAYM4_OK;
1413
- }
1414
-
1415
- /**
1416
- * @synopsis 帧进
1417
- *
1418
- * @returns 状态码
1419
- */
1420
- PlayM4_OneByOne(stepLength) {
1421
- if (this.decodeWorker == null || this.oSuperRender == null) {
1422
- return PLAYM4_ORDER_ERROR;
1423
- }
1424
-
1425
- if (!this.bPlay) {
1426
- return PLAYM4_ORDER_ERROR;
1427
- }
1428
- if (stepLength > 10 || stepLength <= 0) {
1429
- return PLAYM4_PARA_OVER;
1430
- }
1431
- if (!stepLength) {
1432
- stepLength = 1;
1433
- }
1434
- this.iInputDataLen = BUFFER_INPUT_SIZE;
1435
- this.FrameForwardLen = stepLength;
1436
- this.bPause = true;
1437
- this.bOnebyOne = true;
1438
- //this.bPlaySound = false; // 单帧模式下关闭声音
1439
- //this.bPlayRateChange = true;
1440
- this.bIsFirstFrame = true;
1441
- this.draw();
1442
- return PLAYM4_OK;
1443
- }
1444
-
1445
- /**
1446
- * @synopsis 开启声音
1447
- *
1448
- * @param iWndNum [IN] 窗口号
1449
- *
1450
- * @returns 状态码
1451
- */
1452
- PlayM4_PlaySound(iWndNum) {
1453
- if (this.decodeWorker === null || this.bOpenStream === false) {
1454
- return PLAYM4_ORDER_ERROR;
1455
- }
1456
-
1457
- // // 判断音频格式是否支持,如果不支持返回状态码
1458
- // if (!this.bAudioTypeSupport) {
1459
- // return PLAYM4_SYS_NOT_SUPPORT;
1460
- // }
1461
-
1462
- // 最大支持16路
1463
- if (iWndNum < 0 || iWndNum > 16) {
1464
- return PLAYM4_PARA_OVER;
1465
- }
1466
-
1467
- // 创建音频渲染句柄
1468
- if (this.audioRenderer == null) {
1469
- this.audioRenderer = new AudioRenderer();
1470
- if (this.audioRenderer == null) {
1471
- return PLAYM4_CREATE_RENDERER_ERROR;
1472
- }
1473
- }
1474
- // 往 Worker 送数据
1475
- this.decodeWorker.postMessage({
1476
- 'command': "PlaySound"
1477
- });
1478
- // 设置当前窗口号
1479
- this.audioRenderer.SetWndNum(iWndNum);
1480
- if (this.Volume !== 0) {
1481
- this.audioRenderer.SetVolume(this.Volume);
1482
- }
1483
- this.audioRenderer.oAudioContext.resume();
1484
- this.bPlaySound = true;
1485
- return PLAYM4_OK;
1486
- }
1487
-
1488
- /**
1489
- * @synopsis 关闭声音
1490
- *
1491
- * @returns
1492
- */
1493
- PlayM4_StopSound() {
1494
- if (this.decodeWorker == null || this.audioRenderer == null) {
1495
- return PLAYM4_ORDER_ERROR;
1496
- }
1497
-
1498
- if (!this.bPlaySound) {
1499
- return PLAYM4_ORDER_ERROR;
1500
- }
1501
- this.decodeWorker.postMessage({
1502
- 'command': "StopSound"
1503
- });
1504
- this.bPlaySound = false;
1505
- return PLAYM4_OK;
1506
- }
1507
-
1508
- /**
1509
- * @synopsis 设置解码后缓存
1510
- *
1511
- * @param nNum [IN] 显示缓存节点数
1512
- *
1513
- * @returns 状态码
1514
- */
1515
- PlayM4_SetDisplayBuf(nNum) {
1516
- if (this.decodeWorker == null) {
1517
- return PLAYM4_ORDER_ERROR;
1518
- }
1519
-
1520
- if (nNum <= 0) {
1521
- return PLAYM4_PARA_OVER;
1522
- }
1523
-
1524
- this.YUVBufferSize = nNum;
1525
- return PLAYM4_OK;
1526
- }
1527
-
1528
- /**
1529
- * @synopsis 设置解密秘钥
1530
- *
1531
- * @param nKeyType [IN] 密钥类型
1532
- * @param pSecretKey [IN] 密钥缓存
1533
- * @param nKeyLen [IN] 密钥缓存大小
1534
- *
1535
- * @returns 状态码
1536
- */
1537
- PlayM4_SetSecretKey(nKeyType, pSecretKey, nKeyLen) {
1538
- if (this.decodeWorker == null || this.bOpenStream === false) {
1539
- return PLAYM4_ORDER_ERROR;
1540
- }
1541
-
1542
- if (pSecretKey == null) {
1543
- return PLAYM4_PARA_OVER;
1544
- }
1545
-
1546
- if (SECRET_AES === nKeyType) {
1547
- if (128 === nKeyLen) {
1548
- if (pSecretKey == null || pSecretKey === undefined) {
1549
- return PLAYM4_PARA_OVER;
1550
- }
1551
- } else {
1552
- return PLAYM4_PARA_OVER;
1553
- }
1554
- } else if (SECRET_NONE === nKeyType) {
1555
- } else {
1556
- return PLAYM4_PARA_OVER;
1557
- }
1558
-
1559
- // 往 Worker 送数据
1560
- this.decodeWorker.postMessage({
1561
- 'command': "SetSecretKey",
1562
- 'data': pSecretKey,
1563
- 'nKeyType': nKeyType,
1564
- 'nKeyLen': nKeyLen
1565
- });
1566
-
1567
- return PLAYM4_OK;
1568
- }
1569
-
1570
- /**
1571
- * @synopsis 设置要解码的帧类型.默认正常解码,当前只支持全解和只解码I帧
1572
- *
1573
- * @param nFrameType [IN] 帧类型
1574
- *
1575
- * @returns 状态码
1576
- */
1577
- PlayM4_SetDecodeFrameType(nFrameType) {
1578
- console.log("PlayM4_SetDecodeFrameType nFrameType:" + nFrameType);
1579
- if (this.decodeWorker == null || this.oSuperRender == null) {
1580
- return PLAYM4_ORDER_ERROR;
1581
- }
1582
-
1583
- if (nFrameType !== DECODE_ALL && nFrameType !== DECODE_VIDEO_KEYFRAME) {
1584
- return PLAYM4_PARA_OVER;
1585
- }
1586
-
1587
- if (this.bJSPrintLog) {
1588
- console.log(">>>JS PlayM4_SetDecodeFrameType :" + nFrameType);
1589
- }
1590
-
1591
- this.nDecFrameType = nFrameType;
1592
- // 往 Worker 送数据
1593
- this.decodeWorker.postMessage({ 'command': "SetDecodeFrameType", 'data': nFrameType });
1594
-
1595
- return PLAYM4_OK;
1596
- }
1597
-
1598
- /**
1599
- * @synopsis 设置跳I帧间隔(调用前需要设置 setDecodeFrameType(1)只解关键帧,否则返回错误码 2)
1600
- *
1601
- * @param nInterval [IN] 跳I帧间隔
1602
- *
1603
- * @returns 状态码
1604
- */
1605
- PlayM4_SetIFrameDecInterval(nInterval) {
1606
- if (this.nDecFrameType !== DECODE_VIDEO_KEYFRAME) {
1607
- return PLAYM4_ORDER_ERROR;
1608
- }
1609
-
1610
- if (nInterval < 0) {
1611
- return PLAYM4_PARA_OVER;
1612
- }
1613
-
1614
- // 往 Worker 送数据
1615
- this.decodeWorker.postMessage({ 'command': "SetIFrameDecInterval", 'data': nInterval });
1616
-
1617
- return PLAYM4_OK;
1618
- }
1619
- /**
1620
- * @synopsis 设置丢帧模式
1621
- *
1622
- * @param nInterval [IN] 丢帧模式
1623
- *
1624
- * @returns 状态码
1625
- */
1626
- PlayM4_SetLostFrameMode(nLostMode) {
1627
-
1628
- if (nLostMode < 0 || nLostMode > 1) {
1629
- return PLAYM4_PARA_OVER;
1630
- }
1631
-
1632
- // 往 Worker 送数据
1633
- this.decodeWorker.postMessage({ 'command': "SetLostFrameMode", 'data': nLostMode });
1634
-
1635
- return PLAYM4_OK;
1636
- }
1637
- /**
1638
- * @synopsis 电子放大
1639
- *
1640
- * @param diplayRect [IN] 显示区域
1641
- * @param bEnable [IN] 是否显示
1642
- *
1643
- * @returns 状态码
1644
- */
1645
- PlayM4_SetDisplayRegion(diplayRect, bEnable) {
1646
-
1647
- if (this.decodeWorker === null || this.bPlay === false || this.oSuperRender === null) {
1648
- return PLAYM4_ORDER_ERROR;
1649
- }
1650
-
1651
- if (this.canvasId === null) {
1652
- return PLAYM4_ORDER_ERROR;
1653
- }
1654
-
1655
- if (bEnable === true) {
1656
- if (diplayRect === null || diplayRect === undefined) {
1657
- return PLAYM4_PARA_OVER;
1658
- }
1659
-
1660
- // 判断放大区域参数
1661
- if (typeof diplayRect.left === "number" &&
1662
- typeof diplayRect.top === "number" &&
1663
- typeof diplayRect.right === "number" &&
1664
- typeof diplayRect.bottom === "number") {
1665
-
1666
- if (diplayRect.right < 0 ||
1667
- diplayRect.left < 0 ||
1668
- diplayRect.top < 0 ||
1669
- diplayRect.bottom < 0) {
1670
- return PLAYM4_PARA_OVER;
1671
- }
1672
-
1673
- var iLeft = diplayRect.left;
1674
- var iRight = diplayRect.right;
1675
- var iTop = diplayRect.top;
1676
- var iBottom = diplayRect.bottom;
1677
-
1678
- // 获取画布大小
1679
- var oRect = document.getElementById(this.sCanvasId).getBoundingClientRect();
1680
- this.iCanvasWidth = oRect.width;
1681
- this.iCanvasHeight = oRect.height;
1682
-
1683
- /*区域宽高必须不小于16且不大于图像宽高*/
1684
- /*modify.2018.7.6经过测试区域宽高可以大于分辨率*/
1685
- if (iRight - iLeft < 16 || iBottom - iTop < 16 ||
1686
- iRight - iLeft > this.iCanvasWidth || iBottom - iTop > this.iCanvasHeight) {
1687
- return PLAYM4_PARA_OVER;
1688
- }
1689
-
1690
- // 获取画布大小
1691
- /*var oRect = document.getElementById(this.sCanvasId).getBoundingClientRect();
1692
- this.iCanvasWidth = oRect.width;
1693
- this.iCanvasHeight = oRect.height;*/
1694
-
1695
- if (this.iZoomNum !== 0) {
1696
- iLeft = Math.round(iLeft / this.iRatio_x) + this.stDisplayRect.left;
1697
- iTop = Math.round(iTop / this.iRatio_y) + this.stDisplayRect.top;
1698
- iRight = Math.round(iRight / this.iRatio_x) + this.stDisplayRect.left;
1699
- iBottom = Math.round(iBottom / this.iRatio_y) + this.stDisplayRect.top;
1700
- }
1701
-
1702
- // 电子放大
1703
- this.stDisplayRect = {
1704
- "top": iTop,
1705
- "left": iLeft,
1706
- "right": iRight,
1707
- "bottom": iBottom
1708
- };
1709
-
1710
- // 开启电子放大
1711
- this.oSuperRender.SR_SetDisplayRect(this.stDisplayRect);
1712
- this.bDisRect = true;
1713
-
1714
- // 电子放大选择区域大小
1715
- var nCropWidth = iRight - iLeft;
1716
- var nCropHeight = iBottom - iTop;
1717
-
1718
- // 计算放大比率
1719
- this.iRatio_x = this.iCanvasWidth / nCropWidth;
1720
- this.iRatio_y = this.iCanvasHeight / nCropHeight;
1721
-
1722
- // this.iZoomNum++;
1723
- } else {
1724
- return PLAYM4_PARA_OVER;
1725
- }
1726
- } else {
1727
- // 关闭电子放大
1728
- this.oSuperRender.SR_SetDisplayRect(null);
1729
- this.iZoomNum = 0;
1730
- this.bDisRect = false;
1731
- }
1732
-
1733
- // 如果暂停、单帧、快慢放情况,电子放大后需要刷新一帧
1734
- if (this.bPause || this.bOnebyOne || this.bPlayRateChange) {
1735
- if (this.bVideoCropInfo) {
1736
- this.oSuperRender.SR_DisplayFrameData(this.nWidth, this.nHeight,
1737
- (new Uint8Array(this.aDisplayBuf)), this.nWidth - this.nSPSCropLeft - this.nSPSCropRight, this.nHeight - this.nSPSCropTop - this.nSPSCropBottom);
1738
- }
1739
- else {
1740
- this.oSuperRender.SR_DisplayFrameData(this.nWidth, this.nHeight, (new Uint8Array(this.aDisplayBuf)), this.nWidth, this.nHeight);
1741
- }
1742
- }
1743
-
1744
- return PLAYM4_OK;
1745
- }
1746
-
1747
- /**
1748
- * @synopsis 抓取BMP图
1749
- *
1750
- * @param callBack [IN] 数据回调函数
1751
- *
1752
- * @returns 状态码
1753
- */
1754
- PlayM4_GetBMP(callBack) {
1755
- return this.getPic(callBack, "GetBMP");
1756
- }
1757
-
1758
- /**
1759
- * @synopsis 抓取JPEG图
1760
- *
1761
- * @param callBack [IN] 数据回调函数
1762
- *
1763
- * @returns 状态码
1764
- */
1765
- PlayM4_GetJPEG(callBack) {
1766
- return this.getPic(callBack, "GetJPEG");
1767
- }
1768
-
1769
- /**
1770
- * @synopsis 设置音量
1771
- *
1772
- * @param volume [IN] 音量
1773
- *
1774
- * @returns 状态码
1775
- */
1776
- PlayM4_SetVolume(volume) {
1777
- if (this.decodeWorker == null) {
1778
- return PLAYM4_ORDER_ERROR;
1779
- }
1780
-
1781
- if (this.audioRenderer == null) {
1782
- return PLAYM4_ORDER_ERROR;
1783
- }
1784
-
1785
- //增加volume === ""兼容框内容什么都不填的情况
1786
- if (volume < 0 || volume > 100 || volume === "") {
1787
- return PLAYM4_PARA_OVER;
1788
- }
1789
- //保存音量
1790
- this.Volume = volume;
1791
-
1792
- this.audioRenderer.SetVolume(volume);
1793
-
1794
- return PLAYM4_OK;
1795
- }
1796
-
1797
- /**
1798
- * @synopsis 获取音量
1799
- *
1800
- * @param callBack [IN] 音量回调函数
1801
- *
1802
- * @returns 状态码
1803
- */
1804
- PlayM4_GetVolume(callBack) {
1805
- if (this.decodeWorker == null) {
1806
- return PLAYM4_ORDER_ERROR;
1807
- }
1808
-
1809
- if (this.audioRenderer == null) {
1810
- return PLAYM4_ORDER_ERROR;
1811
- }
1812
-
1813
- if (callBack && typeof (callBack) === "function") {
1814
- var volume = this.audioRenderer.GetVolume();
1815
- if (volume === null) {
1816
- return PLAYM4_GET_VOLUME_ERROR;
1817
- } else {
1818
- //修改逻辑解决设置获取音量不一致的问题
1819
- callBack(volume);
1820
-
1821
- return PLAYM4_OK;
1822
- }
1823
- } else {
1824
- return PLAYM4_PARA_OVER;
1825
- }
1826
- }
1827
-
1828
- /**
1829
- * @synopsis 获取OSD时间信息
1830
- *
1831
- * @param callBack [IN] 获取OSD时间信息回调函数
1832
- *
1833
- * @returns 状态码
1834
- */
1835
- PlayM4_GetOSDTime(callBack) {
1836
- if (this.decodeWorker == null) {
1837
- return PLAYM4_ORDER_ERROR;
1838
- }
1839
-
1840
- if (!this.bPlay) {
1841
- return PLAYM4_ORDER_ERROR;
1842
- }
1843
-
1844
- if (callBack && typeof (callBack) === "function") {
1845
- callBack(this.szOSDTime);
1846
-
1847
- return PLAYM4_OK;
1848
- } else {
1849
- return PLAYM4_PARA_OVER;
1850
- }
1851
- }
1852
-
1853
- /**
1854
- * @synopsis 当前页面状态
1855
- *
1856
- * @param visibility [IN] 页面状态
1857
- *
1858
- * @returns 状态码
1859
- */
1860
- PlayM4_IsVisible(visibility) {
1861
- this.bVisibility = visibility;
1862
-
1863
- return PLAYM4_OK;
1864
- }
1865
-
1866
- /**
1867
- * @synopsis 获取SDK版本信息
1868
- *
1869
- * @returns 状态码
1870
- */
1871
- PlayM4_GetSdkVersion() {
1872
- return "07040005";
1873
- }
1874
-
1875
- /**
1876
- * @synopsis 获取build日期
1877
- *
1878
- * @returns 状态码
1879
- */
1880
- PlayM4_GetBuildDate() {
1881
- return "20230303";
1882
- }
1883
-
1884
- /**
1885
- * @synopsis 获取输入缓存大小
1886
- *
1887
- * @returns 返回输入缓存大小
1888
- */
1889
- PlayM4_GetInputBufSize() {
1890
- return this.aInputDataBuffer.length;
1891
- }
1892
-
1893
- /**
1894
- * @synopsis 设置输入缓存大小
1895
- *
1896
- * @returns 设置输入缓存大小
1897
- */
1898
- PlayM4_SetInputBufSize(iInputBufSize) {
1899
- if (iInputBufSize > 0) {
1900
- this.iInputMaxBufSize = iInputBufSize;
1901
- console.log(">>JSBufferSize SetInputBufSize:" + this.iInputMaxBufSize);
1902
- return PLAYM4_OK;
1903
- } else {
1904
- return PLAYM4_PARA_OVER;
1905
- }
1906
- }
1907
-
1908
- /**
1909
- * @synopsis 获取YUV缓存大小
1910
- *
1911
- * @returns 返回YUV缓存大小
1912
- */
1913
- PlayM4_GetYUVBufSize() {
1914
- return this.aVideoFrameBuffer.length;
1915
- }
1916
-
1917
- /**
1918
- * @synopsis 获取一帧图像分辨率
1919
- *
1920
- * @param callBack [IN] 获取一帧图像分辨率回调函数
1921
- *
1922
- * @returns 状态码
1923
- */
1924
- PlayM4_GetFrameResolution(callBack) {
1925
- if (this.decodeWorker == null) {
1926
- return PLAYM4_ORDER_ERROR;
1927
- }
1928
-
1929
- if (callBack && typeof (callBack) === "function") {
1930
- callBack(this.nWidth, this.nHeight);
1931
-
1932
- return PLAYM4_OK;
1933
- } else {
1934
- return PLAYM4_PARA_OVER;
1935
- }
1936
- }
1937
-
1938
-
1939
- /**
1940
- * @synopsis 获取YUV缓存大小
1941
- *
1942
- * @returns 返回YUV缓存大小
1943
- */
1944
- PlayM4_RegisterYUVBufSizeCB(callback) {
1945
- if (callback && typeof (callback) === "function") {
1946
- this.YUVBufSizeCBFun = callback;
1947
- return PLAYM4_OK;
1948
- } else {
1949
- return PLAYM4_PARA_OVER;
1950
- }
1951
- }
1952
-
1953
- /**
1954
- * @synopsis 注销YUV缓存大小回调
1955
- *
1956
- * @returns
1957
- */
1958
- PlayM4_UnRegisterYUVBufSizeCB() {
1959
- if (this.YUVBufSizeCBFun != null) {
1960
- this.YUVBufSizeCBFun = null;
1961
- }
1962
-
1963
- return PLAYM4_OK;
1964
- }
1965
-
1966
- /**
1967
- * @synopsis 画布置透明
1968
- *
1969
- * @returns 状态码
1970
- */
1971
- PlayM4_ClearCanvas() {
1972
- if (this.oSuperRender == null) {
1973
- return PLAYM4_ORDER_ERROR;
1974
- }
1975
-
1976
- // 画布置黑
1977
- if (this.bVideoCropInfo) {
1978
- this.oSuperRender.SR_DisplayFrameData(this.nWidth, this.nHeight, null, this.nWidth - this.nSPSCropLeft - this.nSPSCropRight, this.nHeight - this.nSPSCropTop - this.nSPSCropBottom);
1979
- }
1980
- else {
1981
- this.oSuperRender.SR_DisplayFrameData(this.nWidth, this.nHeight, null, this.nWidth, this.nHeight);
1982
- }
1983
-
1984
- return PLAYM4_OK;
1985
- }
1986
-
1987
- /**
1988
- * @synopsis 释放输入码流缓存
1989
- *
1990
- * @returns 状态码
1991
- */
1992
- PlayM4_ReleaseInputBuffer() {
1993
- if (this.aInputDataBuffer === null) {
1994
- return PLAYM4_ORDER_ERROR;
1995
- }
1996
-
1997
- // 释放缓存
1998
- this.aInputDataBuffer.splice(0, this.aInputDataBuffer.length);
1999
- this.aInputDataLens.splice(0, this.aInputDataLens.length);
2000
-
2001
- return PLAYM4_OK;
2002
- }
2003
-
2004
- /**
2005
- * @synopsis 获取解码帧类型
2006
- *
2007
- * @returns 返回解码帧类型
2008
- */
2009
- PlayM4_GetDecodeFrameType() {
2010
- return this.nDecFrameType;
2011
- }
2012
-
2013
- /**
2014
- * @synopsis 设置实时信息回调
2015
- *
2016
- * @returns 状态码
2017
- */
2018
- PlayM4_SetRunTimeInfoCallBackEx(moduleType, callBack) {
2019
- this.runtimeInfoCBFun = callBack;
2020
- // 往 Worker 送数据
2021
- this.decodeWorker.postMessage({
2022
- 'command': "SetRunTimeInfoCB",
2023
- 'nModuleType': moduleType,
2024
- });
2025
- return PLAYM4_OK;
2026
- }
2027
-
2028
- /**
2029
- * @synopsis 设置编码层断帧
2030
- *
2031
- * @returns 错误码
2032
- */
2033
- PlayM4_SetDemuxModel(nIdemuxType, bTrue) {
2034
- // 往 Worker 送数据
2035
- this.decodeWorker.postMessage({
2036
- 'command': "SetDemuxModel",
2037
- 'nIdemuxType': nIdemuxType,
2038
- 'bTrue': bTrue
2039
- });
2040
- return PLAYM4_OK;
2041
- }
2042
-
2043
- /**
2044
- * @synopsis 设置跳过错误数据
2045
- *
2046
- * @returns 错误码
2047
- */
2048
- PlayM4_SkipErrorData(bSkip) {
2049
- // 往 Worker 送数据
2050
- this.decodeWorker.postMessage({
2051
- 'command': "SkipErrorData",
2052
- 'bSkip': bSkip
2053
- });
2054
- return PLAYM4_OK;
2055
- }
2056
-
2057
- /**
2058
- * @synopsis 设置解码差错隐藏等级
2059
- *
2060
- * @returns 错误码
2061
- */
2062
- PlayM4_SetDecodeERC(nLevel) {
2063
- // 往 Worker 送数据
2064
- this.decodeWorker.postMessage({
2065
- 'command': "SetDecodeERC",
2066
- 'nLevel': nLevel
2067
- });
2068
- return PLAYM4_OK;
2069
- }
2070
-
2071
- /**
2072
- * @synopsis 设置降噪等级
2073
- *
2074
- * @returns 错误码
2075
- */
2076
- PlayM4_SetANRParam(nEnable, nANRLevel) {
2077
- // 往 Worker 送数据
2078
- this.decodeWorker.postMessage({
2079
- 'command': "SetANRParam",
2080
- 'nEnable': nEnable,
2081
- 'nANRLevel': nANRLevel,
2082
- });
2083
- return PLAYM4_OK;
2084
- }
2085
- /**
2086
- * @synopsis 设置重采样
2087
- *
2088
- * @returns 错误码
2089
- */
2090
- PlayM4_SetResampleValue(nEnable, resampleValue) {
2091
- // 往 Worker 送数据
2092
- this.decodeWorker.postMessage({
2093
- 'command': "SetResampleValue",
2094
- 'nEnable': nEnable,
2095
- 'resampleValue': resampleValue,
2096
- });
2097
- return PLAYM4_OK;
2098
- }
2099
- PlayM4_SetGlobalBaseTime(year, month, day, hour, min, sec, ms) {
2100
- // 往 Worker 送数据
2101
- if (year < 2000 || year > 3000) {
2102
- return PLAYM4_SYS_NOT_SUPPORT;
2103
- }
2104
-
2105
- if (month < 1 || month > 12) {
2106
- return PLAYM4_SYS_NOT_SUPPORT;
2107
- }
2108
-
2109
- if (year < 0 || month < 0 || day < 0 || hour < 0 || min < 0 || sec < 0 || ms < 0) {
2110
- return PLAYM4_SYS_NOT_SUPPORT;
2111
- }
2112
-
2113
- this.decodeWorker.postMessage({
2114
- 'command': "SetGlobalBaseTime",
2115
- 'year': year,
2116
- 'month': month,
2117
- 'day': day,
2118
- 'hour': hour,
2119
- 'min': min,
2120
- 'sec': sec,
2121
- 'ms': ms,
2122
- });
2123
- return PLAYM4_OK;
2124
- }
2125
- /**
2126
- * @synopsis 下载文件
2127
- *
2128
- * @param {object} oData 数据 File对象或者Blob对象或者ArrayBuffer对象
2129
- * @param {string} szName 下载文件名
2130
- * @returns {none} 无返回
2131
- */
2132
- downloadFile(oData, szName) {
2133
- let oBlob = oData;
2134
- if (!(oData instanceof Blob || oData instanceof File)) {
2135
- oBlob = new Blob([oData]);
2136
- }
2137
- var szFileUrl = window.URL.createObjectURL(oBlob);
2138
- var oLink = window.document.createElement("a");
2139
- oLink.href = szFileUrl;
2140
- oLink.download = szName;
2141
-
2142
- var oClick = document.createEvent("MouseEvents");
2143
- oClick.initEvent("click", true, true);
2144
- oLink.dispatchEvent(oClick);
2145
- }
2146
- }