forked from langhuihui/jessibuca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
276 lines (234 loc) · 6.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// 播放协议
export const PLAYER_PLAY_PROTOCOL = {
websocket: 0,
fetch: 1
}
export const DEMUX_TYPE = {
flv: 'flv',
m7s: 'm7s'
}
// default player options
export const DEFAULT_PLAYER_OPTIONS = {
videoBuffer: 1000, //1000ms == 1 second
isResize: true,
isFullResize: false, //
isFlv: false,
debug: false,
hotKey: false, // 快捷键
loadingTimeout: 10, // loading timeout
heartTimeout: 10, // heart timeout
timeout: 10, // second
supportDblclickFullscreen: false,
showBandwidth: false, //
keepScreenOn: false,
isNotMute: false,
hasAudio: true,
hasVideo: true,
operateBtns: {
fullscreen: false,
screenshot: false,
play: false,
audio: false,
record: false,
},
controlAutoHide: false,
hasControl: false,
loadingText: '',
background: '',
decoder: 'decoder.js',
url: '',//
rotate: 0,
// text: '',
forceNoOffscreen: true, // 默认是不采用
hiddenAutoPause: false,
protocol: PLAYER_PLAY_PROTOCOL.fetch,
demuxType: DEMUX_TYPE.flv, //
useWCS: false, //
useMSE: false, //
useOffscreen: false, //
autoWasm: false, // 自动降级到 wasm 模式
heartTimeoutReplay: false,// 心跳超时之后自动再播放。
wasmDecodeErrorReplay: false, // 解码失败重新播放。
openWebglAlignment: false,// https://github.com/langhuihui/jessibuca/issues/152
}
export const WORKER_CMD_TYPE = {
init: 'init',
initVideo: 'initVideo',
render: 'render',
playAudio: 'playAudio',
initAudio: 'initAudio',
kBps: 'kBps',
decode: 'decode',
audioCode: 'audioCode',
videoCode: 'videoCode',
wasmError: 'wasmError'
}
export const WASM_ERROR = {
invalidNalUnitSize: 'Invalid NAL unit size',
// errorSplittingTheInputIntoNALUnits: 'Error splitting the input into NAL units'
}
export const MEDIA_TYPE = {
audio: 1,
video: 2
}
export const FLV_MEDIA_TYPE = {
audio: 8,
video: 9
}
export const WORKER_SEND_TYPE = {
init: 'init',
decode: 'decode',
audioDecode: 'audioDecode',
videoDecode: 'videoDecode',
close: 'close',
updateConfig: 'updateConfig'
}
//
export const EVENTS = {
fullscreen: 'fullscreen$2',
webFullscreen: 'webFullscreen',
decoderWorkerInit: 'decoderWorkerInit',
play: 'play',
playing: 'playing',
pause: 'pause',
mute: 'mute',
load: 'load',
loading: 'loading',
videoInfo: 'videoInfo',
timeUpdate: 'timeUpdate',
audioInfo: "audioInfo",
log: 'log',
error: "error",
kBps: 'kBps',
timeout: 'timeout',
delayTimeout: 'delayTimeout',
loadingTimeout: 'loadingTimeout',
stats: 'stats',
performance: "performance",
record: 'record',
recording: 'recording',
recordingTimestamp: 'recordingTimestamp',
recordStart: 'recordStart',
recordEnd: 'recordEnd',
recordCreateError: 'recordCreateError',
buffer: 'buffer',
videoFrame: 'videoFrame',
start: 'start',
metadata: 'metadata',
resize: 'resize',
streamEnd: 'streamEnd',
streamSuccess: 'streamSuccess',
streamMessage: 'streamMessage',
streamError: 'streamError',
volumechange: 'volumechange',
destroy: 'destroy',
mseSourceOpen: 'mseSourceOpen',
mseSourceClose: 'mseSourceClose',
mseSourceBufferError: 'mseSourceBufferError',
mseSourceBufferBusy: 'mseSourceBufferBusy',
videoWaiting: 'videoWaiting',
videoTimeUpdate: 'videoTimeUpdate',
videoSyncAudio: 'videoSyncAudio',
playToRenderTimes: 'playToRenderTimes'
}
export const JESSIBUCA_EVENTS = {
load: EVENTS.load,
timeUpdate: EVENTS.timeUpdate,
videoInfo: EVENTS.videoInfo,
audioInfo: EVENTS.audioInfo,
error: EVENTS.error,
kBps: EVENTS.kBps,
log: EVENTS.log,
start: EVENTS.start,
timeout: EVENTS.timeout,
loadingTimeout: EVENTS.loadingTimeout,
delayTimeout: EVENTS.delayTimeout,
fullscreen: 'fullscreen',
play: EVENTS.play,
pause: EVENTS.pause,
mute: EVENTS.mute,
stats: EVENTS.stats,
performance: EVENTS.performance,
recordingTimestamp: EVENTS.recordingTimestamp,
recordStart: EVENTS.recordStart,
recordEnd: EVENTS.recordEnd,
playToRenderTimes: EVENTS.playToRenderTimes
}
export const EVENTS_ERROR = {
playError: 'playIsNotPauseOrUrlIsNull',
fetchError: "fetchError",
websocketError: 'websocketError',
webcodecsH265NotSupport: 'webcodecsH265NotSupport',
mediaSourceH265NotSupport: 'mediaSourceH265NotSupport',
wasmDecodeError: 'wasmDecodeError'
}
export const WEBSOCKET_STATUS = {
notConnect: 'notConnect',
open: 'open',
close: 'close',
error: 'error'
}
export const BUFFER_STATUS = {
empty: 'empty',
buffering: 'buffering',
full: 'full'
}
export const SCREENSHOT_TYPE = {
download: 'download',
base64: 'base64',
blob: 'blob'
}
export const VIDEO_ENC_TYPE = {
7: 'H264(AVC)', //
12: 'H265(HEVC)' //
}
export const VIDEO_ENC_CODE = {
h264: 7,
h265: 12
}
export const AUDIO_ENC_TYPE = {
10: 'AAC',
7: 'ALAW',
8: 'MULAW'
}
export const H265_NAL_TYPE = {
vps: 32,
sps: 33,
pps: 34
}
export const CONTROL_HEIGHT = 38
export const SCALE_MODE_TYPE = {
full: 0, // 视频画面完全填充canvas区域,画面会被拉伸
auto: 1, // 视频画面做等比缩放后,高或宽对齐canvas区域,画面不被拉伸,但有黑边
fullAuto: 2 // 视频画面做等比缩放后,完全填充canvas区域,画面不被拉伸,没有黑边,但画面显示不全
}
export const FILE_SUFFIX = {
mp4: 'mp4',
webm: 'webm'
};
export const CANVAS_RENDER_TYPE = {
webcodecs: 'webcodecs',
webgl: 'webgl',
offscreen: 'offscreen'
}
export const ENCODED_VIDEO_TYPE = {
key: 'key',
delta: 'delta'
}
export const MP4_CODECS = {
avc: 'video/mp4; codecs="avc1.64002A"',
hev: 'video/mp4; codecs="hev1.1.6.L123.b0"',
}
export const MEDIA_SOURCE_STATE = {
ended: 'ended',
open: 'open',
closed: 'closed'
}
// frag duration
export const FRAG_DURATION = Math.ceil(1000 / 25)
export const AUDIO_SYNC_VIDEO_DIFF = 1000;
export const HOT_KEY = {
esc: 27, //
arrowUp: 38, //
arrowDown: 40, //
}