ezuikit-js 7.6.5 → 7.6.7

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