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