agora-electron-sdk 4.1.1-rc.1 → 4.2.0-dev.13

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 (358) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +143 -143
  3. package/gulpfile.js +5 -4
  4. package/js/AgoraSdk.js +62 -60
  5. package/js/Private/AgoraBase.js +4575 -3269
  6. package/js/Private/AgoraMediaBase.js +968 -564
  7. package/js/Private/AgoraMediaPlayerTypes.js +422 -310
  8. package/js/Private/IAgoraLog.js +86 -74
  9. package/js/Private/IAgoraMediaEngine.js +32 -32
  10. package/js/Private/IAgoraMediaPlayer.js +16 -16
  11. package/js/Private/IAgoraMediaPlayerSource.js +3 -3
  12. package/js/Private/IAgoraMediaRecorder.js +12 -12
  13. package/js/Private/IAgoraMediaStreamingSource.js +84 -0
  14. package/js/Private/IAgoraMusicContentCenter.js +239 -81
  15. package/js/Private/IAgoraRhythmPlayer.js +70 -62
  16. package/js/Private/IAgoraRtcEngine.js +1807 -948
  17. package/js/Private/IAgoraRtcEngineEx.js +26 -18
  18. package/js/Private/IAgoraSpatialAudio.js +74 -30
  19. package/js/Private/IAudioDeviceManager.js +20 -20
  20. package/js/Private/extension/AgoraBaseExtension.js +2 -2
  21. package/js/Private/extension/AgoraMediaBaseExtension.js +2 -2
  22. package/js/Private/extension/AgoraMediaPlayerTypesExtension.js +2 -2
  23. package/js/Private/extension/IAgoraLogExtension.js +2 -2
  24. package/js/Private/extension/IAgoraMediaEngineExtension.js +2 -2
  25. package/js/Private/extension/IAgoraMediaPlayerExtension.js +2 -2
  26. package/js/Private/extension/IAgoraMediaPlayerSourceExtension.js +2 -2
  27. package/js/Private/extension/IAgoraMediaRecorderExtension.js +2 -2
  28. package/js/Private/extension/IAgoraMusicContentCenterExtension.js +2 -2
  29. package/js/Private/extension/IAgoraRhythmPlayerExtension.js +2 -2
  30. package/js/Private/extension/IAgoraRtcEngineExExtension.js +2 -2
  31. package/js/Private/extension/IAgoraRtcEngineExtension.js +2 -2
  32. package/js/Private/extension/IAgoraSpatialAudioExtension.js +2 -2
  33. package/js/Private/extension/IAudioDeviceManagerExtension.js +2 -2
  34. package/js/Private/impl/AgoraBaseImpl.js +23 -23
  35. package/js/Private/impl/AgoraMediaBaseImpl.js +118 -138
  36. package/js/Private/impl/IAgoraMediaEngineImpl.js +287 -325
  37. package/js/Private/impl/IAgoraMediaPlayerImpl.js +932 -938
  38. package/js/Private/impl/IAgoraMediaPlayerSourceImpl.js +63 -63
  39. package/js/Private/impl/IAgoraMediaRecorderImpl.js +47 -67
  40. package/js/Private/impl/IAgoraMusicContentCenterImpl.js +353 -323
  41. package/js/Private/impl/IAgoraRtcEngineExImpl.js +945 -907
  42. package/js/Private/impl/IAgoraRtcEngineImpl.js +4742 -4702
  43. package/js/Private/impl/IAgoraSpatialAudioImpl.js +362 -362
  44. package/js/Private/impl/IAudioDeviceManagerImpl.js +375 -375
  45. package/js/Private/internal/AudioDeviceManagerInternal.js +44 -44
  46. package/js/Private/internal/IrisApiEngine.js +391 -382
  47. package/js/Private/internal/LocalSpatialAudioEngineInternal.js +46 -46
  48. package/js/Private/internal/MediaEngineInternal.js +119 -123
  49. package/js/Private/internal/MediaPlayerInternal.js +215 -213
  50. package/js/Private/internal/MediaRecorderInternal.js +82 -81
  51. package/js/Private/internal/MusicContentCenterInternal.js +128 -130
  52. package/js/Private/internal/RtcEngineExInternal.js +422 -363
  53. package/js/Private/internal/emitter/EventEmitter.js +111 -111
  54. package/js/Private/ti/AgoraBase-ti.js +40 -40
  55. package/js/Private/ti/AgoraMediaBase-ti.js +71 -73
  56. package/js/Private/ti/AgoraMediaPlayerTypes-ti.js +5 -5
  57. package/js/Private/ti/IAgoraLog-ti.js +5 -5
  58. package/js/Private/ti/IAgoraMediaEngine-ti.js +5 -5
  59. package/js/Private/ti/IAgoraMediaPlayer-ti.js +38 -42
  60. package/js/Private/ti/IAgoraMediaPlayerSource-ti.js +48 -48
  61. package/js/Private/ti/IAgoraMediaRecorder-ti.js +5 -5
  62. package/js/Private/ti/IAgoraMediaStreamingSource-ti.js +5 -0
  63. package/js/Private/ti/IAgoraMusicContentCenter-ti.js +41 -41
  64. package/js/Private/ti/IAgoraRhythmPlayer-ti.js +5 -5
  65. package/js/Private/ti/IAgoraRtcEngine-ti.js +139 -139
  66. package/js/Private/ti/IAgoraRtcEngineEx-ti.js +5 -5
  67. package/js/Private/ti/IAgoraSpatialAudio-ti.js +5 -5
  68. package/js/Private/ti/IAudioDeviceManager-ti.js +5 -5
  69. package/js/Renderer/AgoraView.js +128 -131
  70. package/js/Renderer/IRenderer.js +40 -48
  71. package/js/Renderer/IRendererManager.js +9 -0
  72. package/js/Renderer/RendererManager.js +479 -392
  73. package/js/Renderer/{GlRenderer → WebGLRenderer}/index.js +469 -473
  74. package/js/Renderer/{GlRenderer → WebGLRenderer}/webgl-utils.js +1337 -1337
  75. package/js/Renderer/YUVCanvasRenderer/index.js +195 -185
  76. package/js/Renderer/index.js +18 -0
  77. package/js/Types.js +17 -29
  78. package/js/Utils.js +168 -173
  79. package/package.json +61 -103
  80. package/scripts/bootstrap.js +1 -1
  81. package/scripts/build.js +1 -0
  82. package/scripts/buildJS.js +3 -3
  83. package/scripts/clean.js +2 -1
  84. package/scripts/downloadPrebuild.js +5 -5
  85. package/scripts/getConfig.js +3 -2
  86. package/scripts/synclib.js +8 -5
  87. package/scripts/util.js +3 -2
  88. package/scripts/zipBuild.js +2 -1
  89. package/ts/AgoraSdk.ts +9 -6
  90. package/ts/Private/AgoraBase.ts +278 -173
  91. package/ts/Private/AgoraMediaBase.ts +167 -100
  92. package/ts/Private/AgoraMediaPlayerTypes.ts +1 -1
  93. package/ts/Private/IAgoraMediaEngine.ts +43 -56
  94. package/ts/Private/IAgoraMediaPlayer.ts +90 -104
  95. package/ts/Private/IAgoraMediaPlayerSource.ts +3 -8
  96. package/ts/Private/IAgoraMediaRecorder.ts +8 -35
  97. package/ts/Private/IAgoraMediaStreamingSource.ts +80 -0
  98. package/ts/Private/IAgoraMusicContentCenter.ts +93 -12
  99. package/ts/Private/IAgoraRtcEngine.ts +807 -910
  100. package/ts/Private/IAgoraRtcEngineEx.ts +187 -191
  101. package/ts/Private/IAgoraSpatialAudio.ts +40 -22
  102. package/ts/Private/IAudioDeviceManager.ts +35 -13
  103. package/ts/Private/extension/IAgoraMediaEngineExtension.ts +1 -1
  104. package/ts/Private/extension/IAgoraMediaPlayerExtension.ts +4 -7
  105. package/ts/Private/extension/IAgoraMediaRecorderExtension.ts +6 -1
  106. package/ts/Private/extension/IAgoraMusicContentCenterExtension.ts +1 -1
  107. package/ts/Private/extension/IAgoraRtcEngineExtension.ts +4 -4
  108. package/ts/Private/impl/AgoraBaseImpl.ts +3 -3
  109. package/ts/Private/impl/AgoraMediaBaseImpl.ts +36 -42
  110. package/ts/Private/impl/IAgoraMediaEngineImpl.ts +79 -127
  111. package/ts/Private/impl/IAgoraMediaPlayerImpl.ts +106 -106
  112. package/ts/Private/impl/IAgoraMediaRecorderImpl.ts +13 -45
  113. package/ts/Private/impl/IAgoraMusicContentCenterImpl.ts +61 -16
  114. package/ts/Private/impl/IAgoraRtcEngineExImpl.ts +129 -59
  115. package/ts/Private/impl/IAgoraRtcEngineImpl.ts +490 -416
  116. package/ts/Private/impl/IAgoraSpatialAudioImpl.ts +5 -3
  117. package/ts/Private/impl/IAudioDeviceManagerImpl.ts +4 -2
  118. package/ts/Private/internal/AudioDeviceManagerInternal.ts +6 -5
  119. package/ts/Private/internal/IrisApiEngine.ts +41 -32
  120. package/ts/Private/internal/LocalSpatialAudioEngineInternal.ts +17 -13
  121. package/ts/Private/internal/MediaEngineInternal.ts +9 -11
  122. package/ts/Private/internal/MediaPlayerInternal.ts +42 -31
  123. package/ts/Private/internal/MediaRecorderInternal.ts +24 -22
  124. package/ts/Private/internal/MusicContentCenterInternal.ts +16 -18
  125. package/ts/Private/internal/RtcEngineExInternal.ts +189 -66
  126. package/ts/Private/ti/AgoraMediaBase-ti.ts +9 -10
  127. package/ts/Private/ti/IAgoraMediaPlayer-ti.ts +0 -5
  128. package/{js/Private/ti/AgoraMediaPlayerTypes-ti.d.ts → ts/Private/ti/IAgoraMediaStreamingSource-ti.ts} +11 -6
  129. package/ts/Private/ti/IAgoraMusicContentCenter-ti.ts +4 -4
  130. package/ts/Private/ti/IAgoraRtcEngine-ti.ts +4 -4
  131. package/ts/Renderer/AgoraView.ts +12 -7
  132. package/ts/Renderer/IRenderer.ts +11 -16
  133. package/ts/Renderer/IRendererManager.ts +35 -0
  134. package/ts/Renderer/RendererManager.ts +146 -82
  135. package/ts/Renderer/{GlRenderer → WebGLRenderer}/index.ts +36 -51
  136. package/ts/Renderer/YUVCanvasRenderer/index.ts +41 -25
  137. package/ts/Renderer/index.ts +2 -0
  138. package/ts/Types.ts +43 -23
  139. package/ts/Utils.ts +7 -12
  140. package/types/AgoraSdk.d.ts +38 -36
  141. package/types/AgoraSdk.d.ts.map +1 -0
  142. package/types/Private/AgoraBase.d.ts +4455 -4358
  143. package/types/Private/AgoraBase.d.ts.map +1 -0
  144. package/types/Private/AgoraMediaBase.d.ts +1125 -1070
  145. package/types/Private/AgoraMediaBase.d.ts.map +1 -0
  146. package/types/Private/AgoraMediaPlayerTypes.d.ts +409 -408
  147. package/types/Private/AgoraMediaPlayerTypes.d.ts.map +1 -0
  148. package/types/Private/IAgoraLog.d.ts +81 -80
  149. package/types/Private/IAgoraLog.d.ts.map +1 -0
  150. package/types/Private/IAgoraMediaEngine.d.ts +184 -193
  151. package/types/Private/IAgoraMediaEngine.d.ts.map +1 -0
  152. package/types/Private/IAgoraMediaPlayer.d.ts +533 -546
  153. package/types/Private/IAgoraMediaPlayer.d.ts.map +1 -0
  154. package/types/Private/IAgoraMediaPlayerSource.d.ts +83 -88
  155. package/types/Private/IAgoraMediaPlayerSource.d.ts.map +1 -0
  156. package/types/Private/IAgoraMediaRecorder.d.ts +29 -49
  157. package/types/Private/IAgoraMediaRecorder.d.ts.map +1 -0
  158. package/types/Private/IAgoraMediaStreamingSource.d.ts +42 -0
  159. package/types/Private/IAgoraMediaStreamingSource.d.ts.map +1 -0
  160. package/types/Private/IAgoraMusicContentCenter.d.ts +336 -255
  161. package/types/Private/IAgoraMusicContentCenter.d.ts.map +1 -0
  162. package/types/Private/IAgoraRhythmPlayer.d.ts +65 -64
  163. package/types/Private/IAgoraRhythmPlayer.d.ts.map +1 -0
  164. package/types/Private/IAgoraRtcEngine.d.ts +4948 -5058
  165. package/types/Private/IAgoraRtcEngine.d.ts.map +1 -0
  166. package/types/Private/IAgoraRtcEngineEx.d.ts +554 -570
  167. package/types/Private/IAgoraRtcEngineEx.d.ts.map +1 -0
  168. package/types/Private/IAgoraSpatialAudio.d.ts +266 -248
  169. package/types/Private/IAgoraSpatialAudio.d.ts.map +1 -0
  170. package/types/Private/IAudioDeviceManager.d.ts +255 -233
  171. package/types/Private/IAudioDeviceManager.d.ts.map +1 -0
  172. package/types/Private/extension/AgoraBaseExtension.d.ts +2 -1
  173. package/types/Private/extension/AgoraBaseExtension.d.ts.map +1 -0
  174. package/types/Private/extension/AgoraMediaBaseExtension.d.ts +2 -1
  175. package/types/Private/extension/AgoraMediaBaseExtension.d.ts.map +1 -0
  176. package/types/Private/extension/AgoraMediaPlayerTypesExtension.d.ts +2 -1
  177. package/types/Private/extension/AgoraMediaPlayerTypesExtension.d.ts.map +1 -0
  178. package/types/Private/extension/IAgoraLogExtension.d.ts +2 -1
  179. package/types/Private/extension/IAgoraLogExtension.d.ts.map +1 -0
  180. package/types/Private/extension/IAgoraMediaEngineExtension.d.ts +41 -40
  181. package/types/Private/extension/IAgoraMediaEngineExtension.d.ts.map +1 -0
  182. package/types/Private/extension/IAgoraMediaPlayerExtension.d.ts +47 -46
  183. package/types/Private/extension/IAgoraMediaPlayerExtension.d.ts.map +1 -0
  184. package/types/Private/extension/IAgoraMediaPlayerSourceExtension.d.ts +2 -1
  185. package/types/Private/extension/IAgoraMediaPlayerSourceExtension.d.ts.map +1 -0
  186. package/types/Private/extension/IAgoraMediaRecorderExtension.d.ts +45 -40
  187. package/types/Private/extension/IAgoraMediaRecorderExtension.d.ts.map +1 -0
  188. package/types/Private/extension/IAgoraMusicContentCenterExtension.d.ts +21 -20
  189. package/types/Private/extension/IAgoraMusicContentCenterExtension.d.ts.map +1 -0
  190. package/types/Private/extension/IAgoraRhythmPlayerExtension.d.ts +2 -1
  191. package/types/Private/extension/IAgoraRhythmPlayerExtension.d.ts.map +1 -0
  192. package/types/Private/extension/IAgoraRtcEngineExExtension.d.ts +2 -1
  193. package/types/Private/extension/IAgoraRtcEngineExExtension.d.ts.map +1 -0
  194. package/types/Private/extension/IAgoraRtcEngineExtension.d.ts +43 -42
  195. package/types/Private/extension/IAgoraRtcEngineExtension.d.ts.map +1 -0
  196. package/types/Private/extension/IAgoraSpatialAudioExtension.d.ts +2 -1
  197. package/types/Private/extension/IAgoraSpatialAudioExtension.d.ts.map +1 -0
  198. package/types/Private/extension/IAudioDeviceManagerExtension.d.ts +2 -1
  199. package/types/Private/extension/IAudioDeviceManagerExtension.d.ts.map +1 -0
  200. package/types/Private/impl/AgoraBaseImpl.d.ts +3 -2
  201. package/types/Private/impl/AgoraBaseImpl.d.ts.map +1 -0
  202. package/types/Private/impl/AgoraMediaBaseImpl.d.ts +9 -7
  203. package/types/Private/impl/AgoraMediaBaseImpl.d.ts.map +1 -0
  204. package/types/Private/impl/IAgoraMediaEngineImpl.d.ts +40 -43
  205. package/types/Private/impl/IAgoraMediaEngineImpl.d.ts.map +1 -0
  206. package/types/Private/impl/IAgoraMediaPlayerImpl.d.ts +141 -141
  207. package/types/Private/impl/IAgoraMediaPlayerImpl.d.ts.map +1 -0
  208. package/types/Private/impl/IAgoraMediaPlayerSourceImpl.d.ts +3 -2
  209. package/types/Private/impl/IAgoraMediaPlayerSourceImpl.d.ts.map +1 -0
  210. package/types/Private/impl/IAgoraMediaRecorderImpl.d.ts +11 -13
  211. package/types/Private/impl/IAgoraMediaRecorderImpl.d.ts.map +1 -0
  212. package/types/Private/impl/IAgoraMusicContentCenterImpl.d.ts +59 -51
  213. package/types/Private/impl/IAgoraMusicContentCenterImpl.d.ts.map +1 -0
  214. package/types/Private/impl/IAgoraRtcEngineExImpl.d.ts +106 -101
  215. package/types/Private/impl/IAgoraRtcEngineExImpl.d.ts.map +1 -0
  216. package/types/Private/impl/IAgoraRtcEngineImpl.d.ts +570 -566
  217. package/types/Private/impl/IAgoraRtcEngineImpl.d.ts.map +1 -0
  218. package/types/Private/impl/IAgoraSpatialAudioImpl.d.ts +49 -48
  219. package/types/Private/impl/IAgoraSpatialAudioImpl.d.ts.map +1 -0
  220. package/types/Private/impl/IAudioDeviceManagerImpl.d.ts +65 -64
  221. package/types/Private/impl/IAudioDeviceManagerImpl.d.ts.map +1 -0
  222. package/types/Private/internal/AudioDeviceManagerInternal.d.ts +9 -8
  223. package/types/Private/internal/AudioDeviceManagerInternal.d.ts.map +1 -0
  224. package/types/Private/internal/IrisApiEngine.d.ts +148 -146
  225. package/types/Private/internal/IrisApiEngine.d.ts.map +1 -0
  226. package/types/Private/internal/LocalSpatialAudioEngineInternal.d.ts +19 -18
  227. package/types/Private/internal/LocalSpatialAudioEngineInternal.d.ts.map +1 -0
  228. package/types/Private/internal/MediaEngineInternal.d.ts +22 -21
  229. package/types/Private/internal/MediaEngineInternal.d.ts.map +1 -0
  230. package/types/Private/internal/MediaPlayerInternal.d.ts +34 -33
  231. package/types/Private/internal/MediaPlayerInternal.d.ts.map +1 -0
  232. package/types/Private/internal/MediaRecorderInternal.d.ts +18 -15
  233. package/types/Private/internal/MediaRecorderInternal.d.ts.map +1 -0
  234. package/types/Private/internal/MusicContentCenterInternal.d.ts +40 -39
  235. package/types/Private/internal/MusicContentCenterInternal.d.ts.map +1 -0
  236. package/types/Private/internal/RtcEngineExInternal.d.ts +80 -73
  237. package/types/Private/internal/RtcEngineExInternal.d.ts.map +1 -0
  238. package/{js → types}/Private/internal/emitter/EventEmitter.d.ts +60 -59
  239. package/types/Private/internal/emitter/EventEmitter.d.ts.map +1 -0
  240. package/types/Private/ti/AgoraBase-ti.d.ts +8 -7
  241. package/types/Private/ti/AgoraBase-ti.d.ts.map +1 -0
  242. package/types/Private/ti/AgoraMediaBase-ti.d.ts +14 -12
  243. package/types/Private/ti/AgoraMediaBase-ti.d.ts.map +1 -0
  244. package/types/Private/ti/AgoraMediaPlayerTypes-ti.d.ts +7 -6
  245. package/types/Private/ti/AgoraMediaPlayerTypes-ti.d.ts.map +1 -0
  246. package/types/Private/ti/IAgoraLog-ti.d.ts +7 -6
  247. package/types/Private/ti/IAgoraLog-ti.d.ts.map +1 -0
  248. package/types/Private/ti/IAgoraMediaEngine-ti.d.ts +7 -6
  249. package/types/Private/ti/IAgoraMediaEngine-ti.d.ts.map +1 -0
  250. package/types/Private/ti/IAgoraMediaPlayer-ti.d.ts +8 -8
  251. package/types/Private/ti/IAgoraMediaPlayer-ti.d.ts.map +1 -0
  252. package/types/Private/ti/IAgoraMediaPlayerSource-ti.d.ts +8 -7
  253. package/types/Private/ti/IAgoraMediaPlayerSource-ti.d.ts.map +1 -0
  254. package/types/Private/ti/IAgoraMediaRecorder-ti.d.ts +7 -6
  255. package/types/Private/ti/IAgoraMediaRecorder-ti.d.ts.map +1 -0
  256. package/{js/Private/ti/IAgoraMediaRecorder-ti.d.ts → types/Private/ti/IAgoraMediaStreamingSource-ti.d.ts} +7 -6
  257. package/types/Private/ti/IAgoraMediaStreamingSource-ti.d.ts.map +1 -0
  258. package/types/Private/ti/IAgoraMusicContentCenter-ti.d.ts +8 -7
  259. package/types/Private/ti/IAgoraMusicContentCenter-ti.d.ts.map +1 -0
  260. package/types/Private/ti/IAgoraRhythmPlayer-ti.d.ts +7 -6
  261. package/types/Private/ti/IAgoraRhythmPlayer-ti.d.ts.map +1 -0
  262. package/types/Private/ti/IAgoraRtcEngine-ti.d.ts +10 -9
  263. package/types/Private/ti/IAgoraRtcEngine-ti.d.ts.map +1 -0
  264. package/types/Private/ti/IAgoraRtcEngineEx-ti.d.ts +7 -6
  265. package/types/Private/ti/IAgoraRtcEngineEx-ti.d.ts.map +1 -0
  266. package/types/Private/ti/IAgoraSpatialAudio-ti.d.ts +7 -6
  267. package/types/Private/ti/IAgoraSpatialAudio-ti.d.ts.map +1 -0
  268. package/types/Private/ti/IAudioDeviceManager-ti.d.ts +7 -6
  269. package/types/Private/ti/IAudioDeviceManager-ti.d.ts.map +1 -0
  270. package/types/Renderer/AgoraView.d.ts +70 -70
  271. package/types/Renderer/AgoraView.d.ts.map +1 -0
  272. package/types/Renderer/IRenderer.d.ts +22 -21
  273. package/types/Renderer/IRenderer.d.ts.map +1 -0
  274. package/types/Renderer/IRendererManager.d.ts +18 -0
  275. package/types/Renderer/IRendererManager.d.ts.map +1 -0
  276. package/types/Renderer/RendererManager.d.ts +154 -71
  277. package/types/Renderer/RendererManager.d.ts.map +1 -0
  278. package/types/Renderer/{GlRenderer → WebGLRenderer}/index.d.ts +49 -59
  279. package/types/Renderer/WebGLRenderer/index.d.ts.map +1 -0
  280. package/types/Renderer/WebGLRenderer/webgl-utils.d.ts +1 -0
  281. package/types/Renderer/WebGLRenderer/webgl-utils.d.ts.map +1 -0
  282. package/types/Renderer/YUVCanvasRenderer/index.d.ts +16 -16
  283. package/types/Renderer/YUVCanvasRenderer/index.d.ts.map +1 -0
  284. package/types/Renderer/index.d.ts +3 -0
  285. package/types/Renderer/index.d.ts.map +1 -0
  286. package/types/Types.d.ts +280 -260
  287. package/types/Types.d.ts.map +1 -0
  288. package/types/Utils.d.ts +59 -58
  289. package/types/Utils.d.ts.map +1 -0
  290. package/js/AgoraSdk.d.ts +0 -36
  291. package/js/Private/AgoraBase.d.ts +0 -4358
  292. package/js/Private/AgoraMediaBase.d.ts +0 -1070
  293. package/js/Private/AgoraMediaPlayerTypes.d.ts +0 -408
  294. package/js/Private/IAgoraLog.d.ts +0 -80
  295. package/js/Private/IAgoraMediaEngine.d.ts +0 -193
  296. package/js/Private/IAgoraMediaPlayer.d.ts +0 -546
  297. package/js/Private/IAgoraMediaPlayerSource.d.ts +0 -88
  298. package/js/Private/IAgoraMediaRecorder.d.ts +0 -49
  299. package/js/Private/IAgoraMusicContentCenter.d.ts +0 -255
  300. package/js/Private/IAgoraRhythmPlayer.d.ts +0 -64
  301. package/js/Private/IAgoraRtcEngine.d.ts +0 -5058
  302. package/js/Private/IAgoraRtcEngineEx.d.ts +0 -570
  303. package/js/Private/IAgoraSpatialAudio.d.ts +0 -248
  304. package/js/Private/IAudioDeviceManager.d.ts +0 -233
  305. package/js/Private/extension/AgoraBaseExtension.d.ts +0 -1
  306. package/js/Private/extension/AgoraMediaBaseExtension.d.ts +0 -1
  307. package/js/Private/extension/AgoraMediaPlayerTypesExtension.d.ts +0 -1
  308. package/js/Private/extension/IAgoraLogExtension.d.ts +0 -1
  309. package/js/Private/extension/IAgoraMediaEngineExtension.d.ts +0 -40
  310. package/js/Private/extension/IAgoraMediaPlayerExtension.d.ts +0 -46
  311. package/js/Private/extension/IAgoraMediaPlayerSourceExtension.d.ts +0 -1
  312. package/js/Private/extension/IAgoraMediaRecorderExtension.d.ts +0 -40
  313. package/js/Private/extension/IAgoraMusicContentCenterExtension.d.ts +0 -20
  314. package/js/Private/extension/IAgoraRhythmPlayerExtension.d.ts +0 -1
  315. package/js/Private/extension/IAgoraRtcEngineExExtension.d.ts +0 -1
  316. package/js/Private/extension/IAgoraRtcEngineExtension.d.ts +0 -42
  317. package/js/Private/extension/IAgoraSpatialAudioExtension.d.ts +0 -1
  318. package/js/Private/extension/IAudioDeviceManagerExtension.d.ts +0 -1
  319. package/js/Private/impl/AgoraBaseImpl.d.ts +0 -2
  320. package/js/Private/impl/AgoraMediaBaseImpl.d.ts +0 -7
  321. package/js/Private/impl/IAgoraMediaEngineImpl.d.ts +0 -43
  322. package/js/Private/impl/IAgoraMediaPlayerImpl.d.ts +0 -141
  323. package/js/Private/impl/IAgoraMediaPlayerSourceImpl.d.ts +0 -2
  324. package/js/Private/impl/IAgoraMediaRecorderImpl.d.ts +0 -13
  325. package/js/Private/impl/IAgoraMusicContentCenterImpl.d.ts +0 -51
  326. package/js/Private/impl/IAgoraRtcEngineExImpl.d.ts +0 -101
  327. package/js/Private/impl/IAgoraRtcEngineImpl.d.ts +0 -566
  328. package/js/Private/impl/IAgoraSpatialAudioImpl.d.ts +0 -48
  329. package/js/Private/impl/IAudioDeviceManagerImpl.d.ts +0 -64
  330. package/js/Private/internal/AudioDeviceManagerInternal.d.ts +0 -8
  331. package/js/Private/internal/IrisApiEngine.d.ts +0 -146
  332. package/js/Private/internal/LocalSpatialAudioEngineInternal.d.ts +0 -18
  333. package/js/Private/internal/MediaEngineInternal.d.ts +0 -21
  334. package/js/Private/internal/MediaPlayerInternal.d.ts +0 -33
  335. package/js/Private/internal/MediaRecorderInternal.d.ts +0 -15
  336. package/js/Private/internal/MusicContentCenterInternal.d.ts +0 -39
  337. package/js/Private/internal/RtcEngineExInternal.d.ts +0 -73
  338. package/js/Private/ti/AgoraBase-ti.d.ts +0 -7
  339. package/js/Private/ti/AgoraMediaBase-ti.d.ts +0 -12
  340. package/js/Private/ti/IAgoraLog-ti.d.ts +0 -6
  341. package/js/Private/ti/IAgoraMediaEngine-ti.d.ts +0 -6
  342. package/js/Private/ti/IAgoraMediaPlayer-ti.d.ts +0 -8
  343. package/js/Private/ti/IAgoraMediaPlayerSource-ti.d.ts +0 -7
  344. package/js/Private/ti/IAgoraMusicContentCenter-ti.d.ts +0 -7
  345. package/js/Private/ti/IAgoraRhythmPlayer-ti.d.ts +0 -6
  346. package/js/Private/ti/IAgoraRtcEngine-ti.d.ts +0 -9
  347. package/js/Private/ti/IAgoraRtcEngineEx-ti.d.ts +0 -6
  348. package/js/Private/ti/IAgoraSpatialAudio-ti.d.ts +0 -6
  349. package/js/Private/ti/IAudioDeviceManager-ti.d.ts +0 -6
  350. package/js/Renderer/AgoraView.d.ts +0 -70
  351. package/js/Renderer/GlRenderer/index.d.ts +0 -59
  352. package/js/Renderer/GlRenderer/webgl-utils.d.ts +0 -0
  353. package/js/Renderer/IRenderer.d.ts +0 -21
  354. package/js/Renderer/RendererManager.d.ts +0 -71
  355. package/js/Renderer/YUVCanvasRenderer/index.d.ts +0 -16
  356. package/js/Types.d.ts +0 -260
  357. package/js/Utils.d.ts +0 -58
  358. /package/ts/Renderer/{GlRenderer → WebGLRenderer}/webgl-utils.js +0 -0
@@ -1,473 +1,469 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GlRenderer = void 0;
4
- const createProgramFromSources = require('./webgl-utils').createProgramFromSources;
5
- const events_1 = require("events");
6
- const Utils_1 = require("../../Utils");
7
- const IRenderer_1 = require("../IRenderer");
8
- const vertexShaderSource = 'attribute vec2 a_position;' +
9
- 'attribute vec2 a_texCoord;' +
10
- 'uniform vec2 u_resolution;' +
11
- 'varying vec2 v_texCoord;' +
12
- 'void main() {' +
13
- 'vec2 zeroToOne = a_position / u_resolution;' +
14
- ' vec2 zeroToTwo = zeroToOne * 2.0;' +
15
- ' vec2 clipSpace = zeroToTwo - 1.0;' +
16
- ' gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);' +
17
- 'v_texCoord = a_texCoord;' +
18
- '}';
19
- const yuvShaderSource = 'precision mediump float;' +
20
- 'uniform sampler2D Ytex;' +
21
- 'uniform sampler2D Utex,Vtex;' +
22
- 'varying vec2 v_texCoord;' +
23
- 'void main(void) {' +
24
- ' float nx,ny,r,g,b,y,u,v;' +
25
- ' mediump vec4 txl,ux,vx;' +
26
- ' nx=v_texCoord[0];' +
27
- ' ny=v_texCoord[1];' +
28
- ' y=texture2D(Ytex,vec2(nx,ny)).r;' +
29
- ' u=texture2D(Utex,vec2(nx,ny)).r;' +
30
- ' v=texture2D(Vtex,vec2(nx,ny)).r;' +
31
- ' y=1.1643*(y-0.0625);' +
32
- ' u=u-0.5;' +
33
- ' v=v-0.5;' +
34
- ' r=y+1.5958*v;' +
35
- ' g=y-0.39173*u-0.81290*v;' +
36
- ' b=y+2.017*u;' +
37
- ' gl_FragColor=vec4(r,g,b,1.0);' +
38
- '}';
39
- class GlRenderer extends IRenderer_1.IRenderer {
40
- constructor(failCallback) {
41
- super();
42
- this.renderImageCount = 0;
43
- this.initWidth = 0;
44
- this.initHeight = 0;
45
- this.initRotation = 0;
46
- this.clientWidth = 0;
47
- this.clientHeight = 0;
48
- this.contentMode = 0;
49
- this.event = new events_1.EventEmitter();
50
- this.firstFrameRender = false;
51
- this.lastImageWidth = 0;
52
- this.lastImageHeight = 0;
53
- this.lastImageRotation = 0;
54
- this.videoBuffer = {};
55
- this.failInitRenderCB = failCallback;
56
- }
57
- bind(view) {
58
- super.bind(view);
59
- // this.initCanvas(
60
- // view,
61
- // view.clientWidth,
62
- // view.clientHeight,
63
- // this.initRotation,
64
- // console.warn
65
- // );
66
- // const ResizeObserver = window.ResizeObserver;
67
- // if (ResizeObserver) {
68
- // this.observer = new ResizeObserver(() => {
69
- // this.refreshCanvas && this.refreshCanvas();
70
- // });
71
- // this.observer.observe(view);
72
- // }
73
- }
74
- unbind() {
75
- // @ts-ignore
76
- this.observer && this.observer.unobserve && this.observer.disconnect();
77
- this.program = undefined;
78
- this.positionLocation = undefined;
79
- this.texCoordLocation = undefined;
80
- this.deleteTexture(this.yTexture);
81
- this.deleteTexture(this.uTexture);
82
- this.deleteTexture(this.vTexture);
83
- this.yTexture = undefined;
84
- this.uTexture = undefined;
85
- this.vTexture = undefined;
86
- this.deleteBuffer(this.texCoordBuffer);
87
- this.deleteBuffer(this.surfaceBuffer);
88
- this.texCoordBuffer = undefined;
89
- this.surfaceBuffer = undefined;
90
- this.gl = undefined;
91
- try {
92
- if (this.container &&
93
- this.canvas &&
94
- this.canvas.parentNode === this.container) {
95
- this.container.removeChild(this.canvas);
96
- }
97
- if (this.parentElement &&
98
- this.container &&
99
- this.container.parentNode === this.parentElement) {
100
- this.parentElement.removeChild(this.container);
101
- }
102
- }
103
- catch (e) {
104
- (0, Utils_1.logWarn)('webgl renderer unbind happen some error', e);
105
- }
106
- this.canvas = undefined;
107
- this.container = undefined;
108
- this.parentElement = undefined;
109
- }
110
- updateViewZoomLevel(rotation, width, height) {
111
- if (!this.parentElement || !this.canvas) {
112
- return;
113
- }
114
- this.clientWidth = this.parentElement.clientWidth;
115
- this.clientHeight = this.parentElement.clientHeight;
116
- try {
117
- if (this.contentMode === 0) {
118
- // Cover
119
- if (rotation === 0 || rotation === 180) {
120
- if (this.clientWidth / this.clientHeight > width / height) {
121
- // @ts-ignore
122
- this.canvas.style.zoom = this.clientWidth / width;
123
- }
124
- else {
125
- // @ts-ignore
126
- this.canvas.style.zoom = this.clientHeight / height;
127
- }
128
- }
129
- else {
130
- // 90, 270
131
- if (this.clientHeight / this.clientWidth > width / height) {
132
- // @ts-ignore
133
- this.canvas.style.zoom = this.clientHeight / width;
134
- }
135
- else {
136
- // @ts-ignore
137
- this.canvas.style.zoom = this.clientWidth / height;
138
- }
139
- }
140
- // Contain
141
- }
142
- else if (rotation === 0 || rotation === 180) {
143
- if (this.clientWidth / this.clientHeight > width / height) {
144
- // @ts-ignore
145
- this.canvas.style.zoom = this.clientHeight / height;
146
- }
147
- else {
148
- // @ts-ignore
149
- this.canvas.style.zoom = this.clientWidth / width;
150
- }
151
- }
152
- else {
153
- // 90, 270
154
- if (this.clientHeight / this.clientWidth > width / height) {
155
- // @ts-ignore
156
- this.canvas.style.zoom = this.clientWidth / height;
157
- }
158
- else {
159
- // @ts-ignore
160
- this.canvas.style.zoom = this.clientHeight / width;
161
- }
162
- }
163
- }
164
- catch (e) {
165
- (0, Utils_1.logError)('webgl updateViewZoomLevel', e);
166
- return false;
167
- }
168
- return true;
169
- }
170
- updateCanvas(rotation, width, height) {
171
- // if (this.canvasUpdated) {
172
- // return;
173
- // }
174
- if (width || height) {
175
- this.lastImageWidth = width;
176
- this.lastImageHeight = height;
177
- this.lastImageRotation = rotation;
178
- }
179
- else {
180
- width = this.lastImageWidth;
181
- height = this.lastImageHeight;
182
- rotation = this.lastImageRotation;
183
- }
184
- if (!this.updateViewZoomLevel(rotation, width, height)) {
185
- return;
186
- }
187
- let gl = this.gl;
188
- if (!gl) {
189
- return;
190
- }
191
- gl.bindBuffer(gl.ARRAY_BUFFER, this.surfaceBuffer);
192
- gl.enableVertexAttribArray(this.positionLocation);
193
- gl.vertexAttribPointer(this.positionLocation, 2, gl.FLOAT, false, 0, 0);
194
- // 4 vertex, 1(x1,y1), 2(x2,y1), 3(x2,y2), 4(x1,y2)
195
- // 0: 1,2,4/4,2,3
196
- // 90: 2,3,1/1,3,4
197
- // 180: 3,4,2/2,4,1
198
- // 270: 4,1,3/3,1,2
199
- const p1 = { x: 0, y: 0 };
200
- const p2 = { x: width, y: 0 };
201
- const p3 = { x: width, y: height };
202
- const p4 = { x: 0, y: height };
203
- let pp1 = p1, pp2 = p2, pp3 = p3, pp4 = p4;
204
- switch (rotation) {
205
- case 0:
206
- break;
207
- case 90:
208
- pp1 = p2;
209
- pp2 = p3;
210
- pp3 = p4;
211
- pp4 = p1;
212
- break;
213
- case 180:
214
- pp1 = p3;
215
- pp2 = p4;
216
- pp3 = p1;
217
- pp4 = p2;
218
- break;
219
- case 270:
220
- pp1 = p4;
221
- pp2 = p1;
222
- pp3 = p2;
223
- pp4 = p3;
224
- break;
225
- default:
226
- }
227
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
228
- pp1.x,
229
- pp1.y,
230
- pp2.x,
231
- pp2.y,
232
- pp4.x,
233
- pp4.y,
234
- pp4.x,
235
- pp4.y,
236
- pp2.x,
237
- pp2.y,
238
- pp3.x,
239
- pp3.y,
240
- ]), gl.STATIC_DRAW);
241
- const resolutionLocation = gl.getUniformLocation(this.program, 'u_resolution');
242
- gl.uniform2f(resolutionLocation, width, height);
243
- }
244
- drawFrame(videoFrame) {
245
- let error;
246
- try {
247
- this.renderImage({
248
- width: videoFrame.width,
249
- height: videoFrame.height,
250
- left: 0,
251
- top: 0,
252
- right: 0,
253
- bottom: 0,
254
- rotation: videoFrame.rotation || 0,
255
- yplane: videoFrame.yBuffer,
256
- uplane: videoFrame.uBuffer,
257
- vplane: videoFrame.vBuffer,
258
- });
259
- }
260
- catch (err) {
261
- error = err;
262
- }
263
- if (!this.gl || error) {
264
- this.failInitRenderCB &&
265
- this.failInitRenderCB({
266
- error: 'webgl lost or webgl initialize failed',
267
- });
268
- this.failInitRenderCB = null;
269
- return;
270
- }
271
- }
272
- refreshCanvas() {
273
- if (this.lastImageWidth) {
274
- this.updateViewZoomLevel(this.lastImageRotation, this.lastImageWidth, this.lastImageHeight);
275
- }
276
- }
277
- renderImage(image) {
278
- // Rotation, width, height, left, top, right, bottom, yplane, uplane, vplane
279
- if (image.width != this.initWidth ||
280
- image.height != this.initHeight ||
281
- image.rotation != this.initRotation) {
282
- const view = this.parentElement;
283
- this.unbind();
284
- this.initCanvas(view, image.width, image.height, image.rotation);
285
- const ResizeObserver = window.ResizeObserver;
286
- if (ResizeObserver) {
287
- this.observer = new ResizeObserver(() => {
288
- this.refreshCanvas && this.refreshCanvas();
289
- });
290
- this.observer.observe(view);
291
- }
292
- }
293
- let gl = this.gl;
294
- if (!gl) {
295
- return;
296
- }
297
- gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer);
298
- const xWidth = image.width + image.left + image.right;
299
- const xHeight = image.height + image.top + image.bottom;
300
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
301
- image.left / xWidth,
302
- image.bottom / xHeight,
303
- 1 - image.right / xWidth,
304
- image.bottom / xHeight,
305
- image.left / xWidth,
306
- 1 - image.top / xHeight,
307
- image.left / xWidth,
308
- 1 - image.top / xHeight,
309
- 1 - image.right / xWidth,
310
- image.bottom / xHeight,
311
- 1 - image.right / xWidth,
312
- 1 - image.top / xHeight,
313
- ]), gl.STATIC_DRAW);
314
- gl.enableVertexAttribArray(this.texCoordLocation);
315
- gl.vertexAttribPointer(this.texCoordLocation, 2, gl.FLOAT, false, 0, 0);
316
- this.uploadYuv(xWidth, xHeight, image.yplane, image.uplane, image.vplane);
317
- this.updateCanvas(image.rotation, image.width, image.height);
318
- gl.drawArrays(gl.TRIANGLES, 0, 6);
319
- this.renderImageCount += 1;
320
- if (!this.firstFrameRender) {
321
- this.firstFrameRender = true;
322
- this.event.emit('ready');
323
- }
324
- }
325
- uploadYuv(width, height, yplane, uplane, vplane) {
326
- let gl = this.gl;
327
- if (!gl || !this.yTexture || !this.uTexture || !this.vTexture) {
328
- return;
329
- }
330
- gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
331
- gl.activeTexture(gl.TEXTURE0);
332
- gl.bindTexture(gl.TEXTURE_2D, this.yTexture);
333
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, width, height, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, yplane);
334
- gl.activeTexture(gl.TEXTURE1);
335
- gl.bindTexture(gl.TEXTURE_2D, this.uTexture);
336
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, width / 2, height / 2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, uplane);
337
- gl.activeTexture(gl.TEXTURE2);
338
- gl.bindTexture(gl.TEXTURE_2D, this.vTexture);
339
- ('');
340
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, width / 2, height / 2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, vplane);
341
- }
342
- deleteBuffer(buffer) {
343
- if (buffer && this.gl) {
344
- this.gl.deleteBuffer(buffer);
345
- }
346
- }
347
- deleteTexture(texture) {
348
- if (texture && this.gl) {
349
- this.gl.deleteTexture(texture);
350
- }
351
- }
352
- initCanvas(view, width, height, rotation) {
353
- this.clientWidth = view.clientWidth;
354
- this.clientHeight = view.clientHeight;
355
- this.parentElement = view;
356
- this.container = document.createElement('div');
357
- this.container.style.width = '100%';
358
- this.container.style.height = '100%';
359
- this.container.style.display = 'flex';
360
- this.container.style.justifyContent = 'center';
361
- this.container.style.alignItems = 'center';
362
- this.container.style.overflow = 'hidden';
363
- this.parentElement.appendChild(this.container);
364
- this.canvas = document.createElement('canvas');
365
- if (rotation == 0 || rotation == 180) {
366
- this.canvas.width = width;
367
- this.canvas.height = height;
368
- }
369
- else {
370
- this.canvas.width = height;
371
- this.canvas.height = width;
372
- }
373
- this.initWidth = width;
374
- this.initHeight = height;
375
- this.initRotation = rotation;
376
- this.container.appendChild(this.canvas);
377
- try {
378
- // Try to grab the standard context. If it fails, fallback to experimental.
379
- this.gl = this.canvas.getContext('webgl2', {
380
- preserveDrawingBuffer: true,
381
- });
382
- // context list after toggle resolution on electron 12.0.6
383
- let handleContextLost = () => {
384
- try {
385
- this.gl = null;
386
- this.canvas &&
387
- this.canvas.removeEventListener('webglcontextlost', handleContextLost, false);
388
- }
389
- catch (error) {
390
- (0, Utils_1.logWarn)('webglcontextlost error', error);
391
- }
392
- finally {
393
- this.gl = undefined;
394
- this.failInitRenderCB &&
395
- this.failInitRenderCB({
396
- error: 'Browser not support! No WebGL detected.',
397
- });
398
- }
399
- };
400
- this.canvas.addEventListener('webglcontextlost', handleContextLost, false);
401
- }
402
- catch (e) {
403
- (0, Utils_1.logWarn)('webgl create happen some warming', this.gl, this.canvas);
404
- }
405
- if (!this.gl) {
406
- this.failInitRenderCB &&
407
- this.failInitRenderCB({
408
- error: 'Browser not support! No WebGL detected.',
409
- });
410
- return;
411
- }
412
- const gl = this.gl;
413
- // Set clear color to black, fully opaque
414
- gl.clearColor(0.0, 0.0, 0.0, 1.0);
415
- // Enable depth testing
416
- gl.enable(gl.DEPTH_TEST);
417
- // Near things obscure far things
418
- gl.depthFunc(gl.LEQUAL);
419
- // Clear the color as well as the depth buffer.
420
- gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
421
- // Setup GLSL program
422
- this.program = createProgramFromSources(gl, [
423
- vertexShaderSource,
424
- yuvShaderSource,
425
- ]);
426
- this.gl.useProgram(this.program);
427
- this.initTextures();
428
- }
429
- initTextures() {
430
- let gl = this.gl;
431
- if (!gl) {
432
- return;
433
- }
434
- let program = this.program;
435
- this.positionLocation = gl.getAttribLocation(program, 'a_position');
436
- this.texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
437
- this.surfaceBuffer = gl.createBuffer();
438
- this.texCoordBuffer = gl.createBuffer();
439
- // Create a texture.
440
- gl.activeTexture(gl.TEXTURE0);
441
- this.yTexture = gl.createTexture();
442
- gl.bindTexture(gl.TEXTURE_2D, this.yTexture);
443
- // Set the parameters so we can render any size image.
444
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
445
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
446
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
447
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
448
- gl.activeTexture(gl.TEXTURE1);
449
- this.uTexture = gl.createTexture();
450
- gl.bindTexture(gl.TEXTURE_2D, this.uTexture);
451
- // Set the parameters so we can render any size image.
452
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
453
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
454
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
455
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
456
- gl.activeTexture(gl.TEXTURE2);
457
- this.vTexture = gl.createTexture();
458
- gl.bindTexture(gl.TEXTURE_2D, this.vTexture);
459
- // Set the parameters so we can render any size image.
460
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
461
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
462
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
463
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
464
- const y = gl.getUniformLocation(program, 'Ytex');
465
- gl.uniform1i(y, 0); /* Bind Ytex to texture unit 0 */
466
- const u = gl.getUniformLocation(program, 'Utex');
467
- gl.uniform1i(u, 1); /* Bind Utex to texture unit 1 */
468
- const v = gl.getUniformLocation(program, 'Vtex');
469
- gl.uniform1i(v, 2); /* Bind Vtex to texture unit 2 */
470
- }
471
- }
472
- exports.GlRenderer = GlRenderer;
473
- exports.default = GlRenderer;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GlRenderer = void 0;
4
+ const events_1 = require("events");
5
+ const AgoraMediaBase_1 = require("../../Private/AgoraMediaBase");
6
+ const Utils_1 = require("../../Utils");
7
+ const IRenderer_1 = require("../IRenderer");
8
+ const createProgramFromSources = require('./webgl-utils').createProgramFromSources;
9
+ const vertexShaderSource = 'attribute vec2 a_position;' +
10
+ 'attribute vec2 a_texCoord;' +
11
+ 'uniform vec2 u_resolution;' +
12
+ 'varying vec2 v_texCoord;' +
13
+ 'void main() {' +
14
+ 'vec2 zeroToOne = a_position / u_resolution;' +
15
+ ' vec2 zeroToTwo = zeroToOne * 2.0;' +
16
+ ' vec2 clipSpace = zeroToTwo - 1.0;' +
17
+ ' gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);' +
18
+ 'v_texCoord = a_texCoord;' +
19
+ '}';
20
+ const yuvShaderSource = 'precision mediump float;' +
21
+ 'uniform sampler2D Ytex;' +
22
+ 'uniform sampler2D Utex;' +
23
+ 'uniform sampler2D Vtex;' +
24
+ 'varying vec2 v_texCoord;' +
25
+ 'void main(void) {' +
26
+ ' float nx,ny,r,g,b,y,u,v;' +
27
+ ' mediump vec4 txl,ux,vx;' +
28
+ ' nx=v_texCoord[0];' +
29
+ ' ny=v_texCoord[1];' +
30
+ ' y=texture2D(Ytex,vec2(nx,ny)).r;' +
31
+ ' u=texture2D(Utex,vec2(nx,ny)).r;' +
32
+ ' v=texture2D(Vtex,vec2(nx,ny)).r;' +
33
+ ' y=1.1643*(y-0.0625);' +
34
+ ' u=u-0.5;' +
35
+ ' v=v-0.5;' +
36
+ ' r=y+1.5958*v;' +
37
+ ' g=y-0.39173*u-0.81290*v;' +
38
+ ' b=y+2.017*u;' +
39
+ ' gl_FragColor=vec4(r,g,b,1.0);' +
40
+ '}';
41
+ class GlRenderer extends IRenderer_1.IRenderer {
42
+ gl;
43
+ handleContextLost;
44
+ program;
45
+ positionLocation;
46
+ texCoordLocation;
47
+ yTexture;
48
+ uTexture;
49
+ vTexture;
50
+ texCoordBuffer;
51
+ surfaceBuffer;
52
+ // @ts-ignore
53
+ parentElement;
54
+ container;
55
+ // @ts-ignore
56
+ canvas;
57
+ renderImageCount = 0;
58
+ initWidth = 0;
59
+ initHeight = 0;
60
+ initRotation = 0;
61
+ clientWidth = 0;
62
+ clientHeight = 0;
63
+ contentMode = 0;
64
+ event = new events_1.EventEmitter();
65
+ firstFrameRender = false;
66
+ lastImageWidth = 0;
67
+ lastImageHeight = 0;
68
+ lastImageRotation = 0;
69
+ videoBuffer = {};
70
+ observer;
71
+ failInitRenderCB;
72
+ constructor(failCallback) {
73
+ super();
74
+ this.failInitRenderCB = failCallback;
75
+ }
76
+ bind(view) {
77
+ super.bind(view);
78
+ }
79
+ unbind() {
80
+ this.observer?.unobserve && this.observer.disconnect();
81
+ this.program = undefined;
82
+ this.positionLocation = undefined;
83
+ this.texCoordLocation = undefined;
84
+ this.deleteTexture(this.yTexture);
85
+ this.deleteTexture(this.uTexture);
86
+ this.deleteTexture(this.vTexture);
87
+ this.yTexture = undefined;
88
+ this.uTexture = undefined;
89
+ this.vTexture = undefined;
90
+ this.deleteBuffer(this.texCoordBuffer);
91
+ this.deleteBuffer(this.surfaceBuffer);
92
+ this.texCoordBuffer = undefined;
93
+ this.surfaceBuffer = undefined;
94
+ this.gl = undefined;
95
+ try {
96
+ if (this.container &&
97
+ this.canvas &&
98
+ this.canvas.parentNode === this.container) {
99
+ this.container.removeChild(this.canvas);
100
+ }
101
+ if (this.parentElement &&
102
+ this.container &&
103
+ this.container.parentNode === this.parentElement) {
104
+ this.parentElement.removeChild(this.container);
105
+ }
106
+ }
107
+ catch (e) {
108
+ (0, Utils_1.logWarn)('webgl renderer unbind happen some error', e);
109
+ }
110
+ this.canvas = undefined;
111
+ this.container = undefined;
112
+ this.parentElement = undefined;
113
+ }
114
+ updateViewZoomLevel(rotation, width, height) {
115
+ if (!this.parentElement || !this.canvas) {
116
+ return;
117
+ }
118
+ this.clientWidth = this.parentElement.clientWidth;
119
+ this.clientHeight = this.parentElement.clientHeight;
120
+ try {
121
+ if (this.contentMode === AgoraMediaBase_1.RenderModeType.RenderModeHidden) {
122
+ // Cover
123
+ if (rotation === 0 || rotation === 180) {
124
+ if (this.clientWidth / this.clientHeight > width / height) {
125
+ this.canvas.style.transform = `scale(${this.clientWidth / width})`;
126
+ }
127
+ else {
128
+ this.canvas.style.transform = `scale(${this.clientHeight / height})`;
129
+ }
130
+ }
131
+ else {
132
+ // 90, 270
133
+ if (this.clientHeight / this.clientWidth > width / height) {
134
+ this.canvas.style.transform = `scale(${this.clientHeight / width})`;
135
+ }
136
+ else {
137
+ this.canvas.style.transform = `scale(${this.clientWidth / height})`;
138
+ }
139
+ }
140
+ // Contain
141
+ }
142
+ else if (rotation === 0 || rotation === 180) {
143
+ if (this.clientWidth / this.clientHeight > width / height) {
144
+ this.canvas.style.transform = `scale(${this.clientHeight / height})`;
145
+ }
146
+ else {
147
+ this.canvas.style.transform = `scale(${this.clientWidth / width})`;
148
+ }
149
+ }
150
+ else {
151
+ // 90, 270
152
+ if (this.clientHeight / this.clientWidth > width / height) {
153
+ this.canvas.style.transform = `scale(${this.clientWidth / height})`;
154
+ }
155
+ else {
156
+ this.canvas.style.transform = `scale(${this.clientHeight / width})`;
157
+ }
158
+ }
159
+ }
160
+ catch (e) {
161
+ (0, Utils_1.logError)('webgl updateViewZoomLevel', e);
162
+ return false;
163
+ }
164
+ return true;
165
+ }
166
+ updateCanvas(rotation, width, height) {
167
+ // if (this.canvasUpdated) {
168
+ // return;
169
+ // }
170
+ if (width || height) {
171
+ this.lastImageWidth = width;
172
+ this.lastImageHeight = height;
173
+ this.lastImageRotation = rotation;
174
+ }
175
+ else {
176
+ width = this.lastImageWidth;
177
+ height = this.lastImageHeight;
178
+ rotation = this.lastImageRotation;
179
+ }
180
+ if (!this.updateViewZoomLevel(rotation, width, height)) {
181
+ return;
182
+ }
183
+ let gl = this.gl;
184
+ if (!gl) {
185
+ return;
186
+ }
187
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.surfaceBuffer);
188
+ gl.enableVertexAttribArray(this.positionLocation);
189
+ gl.vertexAttribPointer(this.positionLocation, 2, gl.FLOAT, false, 0, 0);
190
+ // 4 vertex, 1(x1,y1), 2(x2,y1), 3(x2,y2), 4(x1,y2)
191
+ // 0: 1,2,4/4,2,3
192
+ // 90: 2,3,1/1,3,4
193
+ // 180: 3,4,2/2,4,1
194
+ // 270: 4,1,3/3,1,2
195
+ const p1 = { x: 0, y: 0 };
196
+ const p2 = { x: width, y: 0 };
197
+ const p3 = { x: width, y: height };
198
+ const p4 = { x: 0, y: height };
199
+ let pp1 = p1, pp2 = p2, pp3 = p3, pp4 = p4;
200
+ switch (rotation) {
201
+ case 0:
202
+ break;
203
+ case 90:
204
+ pp1 = p2;
205
+ pp2 = p3;
206
+ pp3 = p4;
207
+ pp4 = p1;
208
+ break;
209
+ case 180:
210
+ pp1 = p3;
211
+ pp2 = p4;
212
+ pp3 = p1;
213
+ pp4 = p2;
214
+ break;
215
+ case 270:
216
+ pp1 = p4;
217
+ pp2 = p1;
218
+ pp3 = p2;
219
+ pp4 = p3;
220
+ break;
221
+ default:
222
+ }
223
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
224
+ pp1.x,
225
+ pp1.y,
226
+ pp2.x,
227
+ pp2.y,
228
+ pp4.x,
229
+ pp4.y,
230
+ pp4.x,
231
+ pp4.y,
232
+ pp2.x,
233
+ pp2.y,
234
+ pp3.x,
235
+ pp3.y,
236
+ ]), gl.STATIC_DRAW);
237
+ const resolutionLocation = gl.getUniformLocation(this.program, 'u_resolution');
238
+ gl.uniform2f(resolutionLocation, width, height);
239
+ }
240
+ drawFrame(videoFrame) {
241
+ let error;
242
+ try {
243
+ this.renderImage({
244
+ width: videoFrame.width,
245
+ height: videoFrame.height,
246
+ left: 0,
247
+ top: 0,
248
+ right: videoFrame.yStride - videoFrame.width,
249
+ bottom: 0,
250
+ rotation: videoFrame.rotation || 0,
251
+ yplane: videoFrame.yBuffer,
252
+ uplane: videoFrame.uBuffer,
253
+ vplane: videoFrame.vBuffer,
254
+ });
255
+ }
256
+ catch (err) {
257
+ error = err;
258
+ }
259
+ if (!this.gl || error) {
260
+ this.failInitRenderCB &&
261
+ this.failInitRenderCB({
262
+ error: 'webgl lost or webgl initialize failed',
263
+ });
264
+ this.failInitRenderCB = null;
265
+ return;
266
+ }
267
+ }
268
+ refreshCanvas() {
269
+ if (this.lastImageWidth) {
270
+ this.updateViewZoomLevel(this.lastImageRotation, this.lastImageWidth, this.lastImageHeight);
271
+ }
272
+ }
273
+ renderImage(image) {
274
+ // Rotation, width, height, left, top, right, bottom, yplane, uplane, vplane
275
+ if (image.width != this.initWidth ||
276
+ image.height != this.initHeight ||
277
+ image.rotation != this.initRotation) {
278
+ const view = this.parentElement;
279
+ this.unbind();
280
+ this.initCanvas(view, image.width, image.height, image.rotation);
281
+ const ResizeObserver = window.ResizeObserver;
282
+ if (ResizeObserver) {
283
+ this.observer = new ResizeObserver(() => {
284
+ this.refreshCanvas && this.refreshCanvas();
285
+ });
286
+ this.observer.observe(view);
287
+ }
288
+ }
289
+ let gl = this.gl;
290
+ if (!gl) {
291
+ return;
292
+ }
293
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer);
294
+ const xWidth = image.width + image.left + image.right;
295
+ const xHeight = image.height + image.top + image.bottom;
296
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
297
+ image.left / xWidth,
298
+ image.bottom / xHeight,
299
+ 1 - image.right / xWidth,
300
+ image.bottom / xHeight,
301
+ image.left / xWidth,
302
+ 1 - image.top / xHeight,
303
+ image.left / xWidth,
304
+ 1 - image.top / xHeight,
305
+ 1 - image.right / xWidth,
306
+ image.bottom / xHeight,
307
+ 1 - image.right / xWidth,
308
+ 1 - image.top / xHeight,
309
+ ]), gl.STATIC_DRAW);
310
+ gl.enableVertexAttribArray(this.texCoordLocation);
311
+ gl.vertexAttribPointer(this.texCoordLocation, 2, gl.FLOAT, false, 0, 0);
312
+ this.uploadYuv(xWidth, xHeight, image.yplane, image.uplane, image.vplane);
313
+ this.updateCanvas(image.rotation, image.width, image.height);
314
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
315
+ this.renderImageCount += 1;
316
+ if (!this.firstFrameRender) {
317
+ this.firstFrameRender = true;
318
+ this.event.emit('ready');
319
+ }
320
+ }
321
+ uploadYuv(width, height, yplane, uplane, vplane) {
322
+ let gl = this.gl;
323
+ if (!gl || !this.yTexture || !this.uTexture || !this.vTexture) {
324
+ return;
325
+ }
326
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
327
+ gl.activeTexture(gl.TEXTURE0);
328
+ gl.bindTexture(gl.TEXTURE_2D, this.yTexture);
329
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, width, height, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, yplane);
330
+ gl.activeTexture(gl.TEXTURE1);
331
+ gl.bindTexture(gl.TEXTURE_2D, this.uTexture);
332
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, width / 2, height / 2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, uplane);
333
+ gl.activeTexture(gl.TEXTURE2);
334
+ gl.bindTexture(gl.TEXTURE_2D, this.vTexture);
335
+ ('');
336
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, width / 2, height / 2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, vplane);
337
+ }
338
+ deleteBuffer(buffer) {
339
+ if (buffer && this.gl) {
340
+ this.gl.deleteBuffer(buffer);
341
+ }
342
+ }
343
+ deleteTexture(texture) {
344
+ if (texture && this.gl) {
345
+ this.gl.deleteTexture(texture);
346
+ }
347
+ }
348
+ initCanvas(view, width, height, rotation) {
349
+ this.clientWidth = view.clientWidth;
350
+ this.clientHeight = view.clientHeight;
351
+ this.parentElement = view;
352
+ this.container = document.createElement('div');
353
+ this.container.style.width = '100%';
354
+ this.container.style.height = '100%';
355
+ this.container.style.display = 'flex';
356
+ this.container.style.justifyContent = 'center';
357
+ this.container.style.alignItems = 'center';
358
+ this.container.style.overflow = 'hidden';
359
+ this.parentElement.appendChild(this.container);
360
+ this.canvas = document.createElement('canvas');
361
+ if (rotation == 0 || rotation == 180) {
362
+ this.canvas.width = width;
363
+ this.canvas.height = height;
364
+ }
365
+ else {
366
+ this.canvas.width = height;
367
+ this.canvas.height = width;
368
+ }
369
+ this.initWidth = width;
370
+ this.initHeight = height;
371
+ this.initRotation = rotation;
372
+ this.container.appendChild(this.canvas);
373
+ try {
374
+ // Try to grab the standard context. If it fails, fallback to experimental.
375
+ this.gl = this.canvas.getContext('webgl2', {
376
+ preserveDrawingBuffer: true,
377
+ });
378
+ // context list after toggle resolution on electron 12.0.6
379
+ let handleContextLost = () => {
380
+ try {
381
+ this.gl = null;
382
+ this.canvas &&
383
+ this.canvas.removeEventListener('webglcontextlost', handleContextLost, false);
384
+ }
385
+ catch (error) {
386
+ (0, Utils_1.logWarn)('webglcontextlost error', error);
387
+ }
388
+ finally {
389
+ this.gl = undefined;
390
+ this.failInitRenderCB &&
391
+ this.failInitRenderCB({
392
+ error: 'Browser not support! No WebGL detected.',
393
+ });
394
+ }
395
+ };
396
+ this.canvas.addEventListener('webglcontextlost', handleContextLost, false);
397
+ }
398
+ catch (e) {
399
+ (0, Utils_1.logWarn)('webgl create happen some warming', this.gl, this.canvas);
400
+ }
401
+ if (!this.gl) {
402
+ this.failInitRenderCB &&
403
+ this.failInitRenderCB({
404
+ error: 'Browser not support! No WebGL detected.',
405
+ });
406
+ return;
407
+ }
408
+ const gl = this.gl;
409
+ // Set clear color to black, fully opaque
410
+ gl.clearColor(0.0, 0.0, 0.0, 1.0);
411
+ // Enable depth testing
412
+ gl.enable(gl.DEPTH_TEST);
413
+ // Near things obscure far things
414
+ gl.depthFunc(gl.LEQUAL);
415
+ // Clear the color as well as the depth buffer.
416
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
417
+ // Setup GLSL program
418
+ this.program = createProgramFromSources(gl, [
419
+ vertexShaderSource,
420
+ yuvShaderSource,
421
+ ]);
422
+ this.gl.useProgram(this.program);
423
+ this.initTextures();
424
+ }
425
+ initTextures() {
426
+ let gl = this.gl;
427
+ if (!gl) {
428
+ return;
429
+ }
430
+ let program = this.program;
431
+ this.positionLocation = gl.getAttribLocation(program, 'a_position');
432
+ this.texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
433
+ this.surfaceBuffer = gl.createBuffer();
434
+ this.texCoordBuffer = gl.createBuffer();
435
+ // Create a texture.
436
+ gl.activeTexture(gl.TEXTURE0);
437
+ this.yTexture = gl.createTexture();
438
+ gl.bindTexture(gl.TEXTURE_2D, this.yTexture);
439
+ // Set the parameters so we can render any size image.
440
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
441
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
442
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
443
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
444
+ gl.activeTexture(gl.TEXTURE1);
445
+ this.uTexture = gl.createTexture();
446
+ gl.bindTexture(gl.TEXTURE_2D, this.uTexture);
447
+ // Set the parameters so we can render any size image.
448
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
449
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
450
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
451
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
452
+ gl.activeTexture(gl.TEXTURE2);
453
+ this.vTexture = gl.createTexture();
454
+ gl.bindTexture(gl.TEXTURE_2D, this.vTexture);
455
+ // Set the parameters so we can render any size image.
456
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
457
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
458
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
459
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
460
+ const y = gl.getUniformLocation(program, 'Ytex');
461
+ gl.uniform1i(y, 0); /* Bind Ytex to texture unit 0 */
462
+ const u = gl.getUniformLocation(program, 'Utex');
463
+ gl.uniform1i(u, 1); /* Bind Utex to texture unit 1 */
464
+ const v = gl.getUniformLocation(program, 'Vtex');
465
+ gl.uniform1i(v, 2); /* Bind Vtex to texture unit 2 */
466
+ }
467
+ }
468
+ exports.GlRenderer = GlRenderer;
469
+ exports.default = GlRenderer;