gravix-rtc-react-native 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (378) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/LICENSE +20 -0
  3. package/LICENSES/Apache-2.0.txt +175 -0
  4. package/NOTICE +68 -0
  5. package/README.md +313 -2
  6. package/android/build.gradle +137 -0
  7. package/android/consumer-rules.pro +29 -0
  8. package/android/src/main/AndroidManifest.xml +9 -0
  9. package/android/src/main/cpp/CMakeLists.txt +48 -0
  10. package/android/src/main/cpp/gx_dfn_engine.c +332 -0
  11. package/android/src/main/cpp/gx_fx_jni.cpp +34 -0
  12. package/android/src/main/cpp/gx_ns_jni.c +162 -0
  13. package/android/src/main/cpp/third_party/onnxruntime/LICENSE +21 -0
  14. package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_c_api.h +9227 -0
  15. package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_ep_c_api.h +3315 -0
  16. package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_error_code.h +98 -0
  17. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioHooks.kt +144 -0
  18. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioModule.kt +105 -0
  19. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixNativeAudio.kt +310 -0
  20. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtc.kt +134 -0
  21. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcModule.kt +176 -0
  22. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcPackage.kt +39 -0
  23. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioDeviceKind.java +44 -0
  24. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioManagerUtils.kt +120 -0
  25. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioSwitchManager.java +270 -0
  26. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioType.kt +50 -0
  27. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicCaptureRouter.kt +375 -0
  28. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicDecoder.kt +339 -0
  29. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicInterruptionWatcher.kt +82 -0
  30. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMicRelease.kt +117 -0
  31. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixKernel.kt +191 -0
  32. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixerEngine.kt +617 -0
  33. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/AudioRoutePolicy.kt +137 -0
  34. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GravixCaptureProcessing.kt +67 -0
  35. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureDump.kt +143 -0
  36. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureSwitcher.kt +196 -0
  37. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNoiseProcessor.kt +795 -0
  38. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsLogic.kt +180 -0
  39. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsNative.kt +83 -0
  40. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsStudio.kt +372 -0
  41. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecordStartGuard.kt +76 -0
  42. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecorderSeam.kt +434 -0
  43. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxSingerSource.kt +37 -0
  44. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxVoiceFx.kt +160 -0
  45. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/OtherAppAudioPolicy.kt +143 -0
  46. package/android/src/main/java/org/webrtc/audio/WebRtcAudioTrackHelper.kt +43 -0
  47. package/docs/ANDROID_NATIVE_HOOKS.md +102 -0
  48. package/docs/FEATURE_MATRIX.md +192 -0
  49. package/docs/IOS_NATIVE_HOOKS.md +190 -0
  50. package/gravix-rtc-react-native.podspec +49 -0
  51. package/ios/GravixRtc.h +7 -0
  52. package/ios/GravixRtc.mm +273 -0
  53. package/ios/GravixRtcSetup.h +29 -0
  54. package/ios/GravixRtcSetup.m +52 -0
  55. package/ios/audio/GravixRtcIosAudio.m +157 -0
  56. package/ios/audio/GxAudioDevice.h +62 -0
  57. package/ios/audio/GxAudioDevice.m +857 -0
  58. package/ios/audio/GxAudioSetup.h +34 -0
  59. package/ios/audio/GxAudioSetup.m +70 -0
  60. package/ios/audio/GxCompat.swift +53 -0
  61. package/ios/audio/GxIosAudio.swift +99 -0
  62. package/ios/audio/GxMusicController.swift +150 -0
  63. package/ios/audio/GxMusicPost.swift +362 -0
  64. package/ios/audio/GxNoiseProcessor.swift +718 -0
  65. package/ios/audio/GxNsDfn3CoreML.swift +195 -0
  66. package/ios/audio/GxNsStudioEngine.swift +237 -0
  67. package/ios/audio/GxNsStudioPack.swift +212 -0
  68. package/ios/audio/GxVoiceFx.swift +161 -0
  69. package/ios/audio/gx_adm_state.h +153 -0
  70. package/ios/gxcore/apple/gx_music_post.c +312 -0
  71. package/ios/gxcore/apple/gx_pcm.c +30 -0
  72. package/ios/gxcore/apple/gxns_build.h +19 -0
  73. package/ios/gxcore/apple/gxns_ios.c +17 -0
  74. package/ios/gxcore/apple/include/gx_fx.h +3 -0
  75. package/ios/gxcore/apple/include/gx_music_post.h +88 -0
  76. package/ios/gxcore/apple/include/gx_ns.h +3 -0
  77. package/ios/gxcore/apple/include/gx_pcm.h +33 -0
  78. package/ios/gxcore/apple/include/gxns_ios.h +18 -0
  79. package/ios/gxcore/apple/include/module.modulemap +10 -0
  80. package/ios/gxcore/apple/shim/rnnoise.h +2 -0
  81. package/ios/gxcore/apple/shim/speex_resampler.h +2 -0
  82. package/ios/gxcore/apple/units/gx_fx_forward.cpp +3 -0
  83. package/ios/gxcore/apple/units/gx_ns.c +7 -0
  84. package/ios/gxcore/apple/units/gx_ns_timer.c +7 -0
  85. package/ios/gxcore/apple/units/rnnoise_celt_lpc.c +7 -0
  86. package/ios/gxcore/apple/units/rnnoise_denoise.c +7 -0
  87. package/ios/gxcore/apple/units/rnnoise_kiss_fft.c +7 -0
  88. package/ios/gxcore/apple/units/rnnoise_pitch.c +7 -0
  89. package/ios/gxcore/apple/units/rnnoise_rnn.c +7 -0
  90. package/ios/gxcore/apple/units/rnnoise_rnn_data.c +7 -0
  91. package/ios/gxcore/apple/units/speexdsp_resample.c +7 -0
  92. package/ios/resources/ns/DFN3-NOTICE.txt +10 -0
  93. package/ios/resources/ns/DeepFilterNet-LICENSE-APACHE +201 -0
  94. package/ios/resources/ns/DeepFilterNet-LICENSE-MIT +19 -0
  95. package/ios/resources/ns/gxns_dfn3.mlmodelc/analytics/coremldata.bin +0 -0
  96. package/ios/resources/ns/gxns_dfn3.mlmodelc/coremldata.bin +0 -0
  97. package/ios/resources/ns/gxns_dfn3.mlmodelc/metadata.json +338 -0
  98. package/ios/resources/ns/gxns_dfn3.mlmodelc/model.mil +927 -0
  99. package/ios/resources/ns/gxns_dfn3.mlmodelc/weights/weight.bin +0 -0
  100. package/lib/module/android/bindings.js +49 -0
  101. package/lib/module/android/bindings.js.map +1 -0
  102. package/lib/module/android/index.js +13 -0
  103. package/lib/module/android/index.js.map +1 -0
  104. package/lib/module/android/micMute.js +341 -0
  105. package/lib/module/android/micMute.js.map +1 -0
  106. package/lib/module/android/nativeAudio.js +47 -0
  107. package/lib/module/android/nativeAudio.js.map +1 -0
  108. package/lib/module/android/noiseSuppression.js +170 -0
  109. package/lib/module/android/noiseSuppression.js.map +1 -0
  110. package/lib/module/android/roomMusic.js +142 -0
  111. package/lib/module/android/roomMusic.js.map +1 -0
  112. package/lib/module/android/singerMode.js +31 -0
  113. package/lib/module/android/singerMode.js.map +1 -0
  114. package/lib/module/android/voiceEffects.js +65 -0
  115. package/lib/module/android/voiceEffects.js.map +1 -0
  116. package/lib/module/audio/AudioManager.js +79 -0
  117. package/lib/module/audio/AudioManager.js.map +1 -0
  118. package/lib/module/audio/AudioSession.js +90 -0
  119. package/lib/module/audio/AudioSession.js.map +1 -0
  120. package/lib/module/audio/remoteVolume.js +54 -0
  121. package/lib/module/audio/remoteVolume.js.map +1 -0
  122. package/lib/module/components/VideoView.js +109 -0
  123. package/lib/module/components/VideoView.js.map +1 -0
  124. package/lib/module/features/audioScenario.js +53 -0
  125. package/lib/module/features/audioScenario.js.map +1 -0
  126. package/lib/module/features/beauty.js +828 -0
  127. package/lib/module/features/beauty.js.map +1 -0
  128. package/lib/module/features/micRelease.js +89 -0
  129. package/lib/module/features/micRelease.js.map +1 -0
  130. package/lib/module/features/noiseSuppression.js +213 -0
  131. package/lib/module/features/noiseSuppression.js.map +1 -0
  132. package/lib/module/features/roomMusic.js +90 -0
  133. package/lib/module/features/roomMusic.js.map +1 -0
  134. package/lib/module/features/roomMusicAndroid.js +294 -0
  135. package/lib/module/features/roomMusicAndroid.js.map +1 -0
  136. package/lib/module/features/roomMusicIos.js +250 -0
  137. package/lib/module/features/roomMusicIos.js.map +1 -0
  138. package/lib/module/features/roomMusicTypes.js +53 -0
  139. package/lib/module/features/roomMusicTypes.js.map +1 -0
  140. package/lib/module/features/screenShare.js +22 -0
  141. package/lib/module/features/screenShare.js.map +1 -0
  142. package/lib/module/features/singerMode.js +73 -0
  143. package/lib/module/features/singerMode.js.map +1 -0
  144. package/lib/module/features/voiceEffects.js +148 -0
  145. package/lib/module/features/voiceEffects.js.map +1 -0
  146. package/lib/module/hooks/context.js +34 -0
  147. package/lib/module/hooks/context.js.map +1 -0
  148. package/lib/module/hooks/hooks.js +145 -0
  149. package/lib/module/hooks/hooks.js.map +1 -0
  150. package/lib/module/hooks/types.js +4 -0
  151. package/lib/module/hooks/types.js.map +1 -0
  152. package/lib/module/hooks/useRoomEvents.js +30 -0
  153. package/lib/module/hooks/useRoomEvents.js.map +1 -0
  154. package/lib/module/index.js +43 -0
  155. package/lib/module/index.js.map +1 -0
  156. package/lib/module/ios/autoAttach.js +14 -0
  157. package/lib/module/ios/autoAttach.js.map +1 -0
  158. package/lib/module/ios/iosAudio.js +149 -0
  159. package/lib/module/ios/iosAudio.js.map +1 -0
  160. package/lib/module/join/appStateLifecycle.js +54 -0
  161. package/lib/module/join/appStateLifecycle.js.map +1 -0
  162. package/lib/module/micPolicy.js +249 -0
  163. package/lib/module/micPolicy.js.map +1 -0
  164. package/lib/module/native/NativeGravixAudio.js +18 -0
  165. package/lib/module/native/NativeGravixAudio.js.map +1 -0
  166. package/lib/module/native/NativeGravixRtc.js +13 -0
  167. package/lib/module/native/NativeGravixRtc.js.map +1 -0
  168. package/lib/module/native/module.js +23 -0
  169. package/lib/module/native/module.js.map +1 -0
  170. package/lib/module/package.json +1 -0
  171. package/lib/module/polyfills/DOMException.js +22 -0
  172. package/lib/module/polyfills/DOMException.js.map +1 -0
  173. package/lib/module/polyfills/early.js +18 -0
  174. package/lib/module/polyfills/early.js.map +1 -0
  175. package/lib/module/polyfills/event.js +71 -0
  176. package/lib/module/polyfills/event.js.map +1 -0
  177. package/lib/module/polyfills/sha256.js +92 -0
  178. package/lib/module/polyfills/sha256.js.map +1 -0
  179. package/lib/module/polyfills/subtleHmac.js +91 -0
  180. package/lib/module/polyfills/subtleHmac.js.map +1 -0
  181. package/lib/module/polyfills/textCoding.js +164 -0
  182. package/lib/module/polyfills/textCoding.js.map +1 -0
  183. package/lib/module/registerGlobals.js +135 -0
  184. package/lib/module/registerGlobals.js.map +1 -0
  185. package/lib/module/unsupported.js +90 -0
  186. package/lib/module/unsupported.js.map +1 -0
  187. package/lib/module/version.js +7 -0
  188. package/lib/module/version.js.map +1 -0
  189. package/lib/typescript/package.json +1 -0
  190. package/lib/typescript/src/android/bindings.d.ts +14 -0
  191. package/lib/typescript/src/android/bindings.d.ts.map +1 -0
  192. package/lib/typescript/src/android/index.d.ts +9 -0
  193. package/lib/typescript/src/android/index.d.ts.map +1 -0
  194. package/lib/typescript/src/android/micMute.d.ts +124 -0
  195. package/lib/typescript/src/android/micMute.d.ts.map +1 -0
  196. package/lib/typescript/src/android/nativeAudio.d.ts +40 -0
  197. package/lib/typescript/src/android/nativeAudio.d.ts.map +1 -0
  198. package/lib/typescript/src/android/noiseSuppression.d.ts +48 -0
  199. package/lib/typescript/src/android/noiseSuppression.d.ts.map +1 -0
  200. package/lib/typescript/src/android/roomMusic.d.ts +80 -0
  201. package/lib/typescript/src/android/roomMusic.d.ts.map +1 -0
  202. package/lib/typescript/src/android/singerMode.d.ts +27 -0
  203. package/lib/typescript/src/android/singerMode.d.ts.map +1 -0
  204. package/lib/typescript/src/android/voiceEffects.d.ts +30 -0
  205. package/lib/typescript/src/android/voiceEffects.d.ts.map +1 -0
  206. package/lib/typescript/src/audio/AudioManager.d.ts +32 -0
  207. package/lib/typescript/src/audio/AudioManager.d.ts.map +1 -0
  208. package/lib/typescript/src/audio/AudioSession.d.ts +70 -0
  209. package/lib/typescript/src/audio/AudioSession.d.ts.map +1 -0
  210. package/lib/typescript/src/audio/remoteVolume.d.ts +8 -0
  211. package/lib/typescript/src/audio/remoteVolume.d.ts.map +1 -0
  212. package/lib/typescript/src/components/VideoView.d.ts +44 -0
  213. package/lib/typescript/src/components/VideoView.d.ts.map +1 -0
  214. package/lib/typescript/src/features/audioScenario.d.ts +24 -0
  215. package/lib/typescript/src/features/audioScenario.d.ts.map +1 -0
  216. package/lib/typescript/src/features/beauty.d.ts +377 -0
  217. package/lib/typescript/src/features/beauty.d.ts.map +1 -0
  218. package/lib/typescript/src/features/micRelease.d.ts +28 -0
  219. package/lib/typescript/src/features/micRelease.d.ts.map +1 -0
  220. package/lib/typescript/src/features/noiseSuppression.d.ts +64 -0
  221. package/lib/typescript/src/features/noiseSuppression.d.ts.map +1 -0
  222. package/lib/typescript/src/features/roomMusic.d.ts +41 -0
  223. package/lib/typescript/src/features/roomMusic.d.ts.map +1 -0
  224. package/lib/typescript/src/features/roomMusicAndroid.d.ts +60 -0
  225. package/lib/typescript/src/features/roomMusicAndroid.d.ts.map +1 -0
  226. package/lib/typescript/src/features/roomMusicIos.d.ts +56 -0
  227. package/lib/typescript/src/features/roomMusicIos.d.ts.map +1 -0
  228. package/lib/typescript/src/features/roomMusicTypes.d.ts +76 -0
  229. package/lib/typescript/src/features/roomMusicTypes.d.ts.map +1 -0
  230. package/lib/typescript/src/features/screenShare.d.ts +12 -0
  231. package/lib/typescript/src/features/screenShare.d.ts.map +1 -0
  232. package/lib/typescript/src/features/singerMode.d.ts +20 -0
  233. package/lib/typescript/src/features/singerMode.d.ts.map +1 -0
  234. package/lib/typescript/src/features/voiceEffects.d.ts +46 -0
  235. package/lib/typescript/src/features/voiceEffects.d.ts.map +1 -0
  236. package/lib/typescript/src/hooks/context.d.ts +12 -0
  237. package/lib/typescript/src/hooks/context.d.ts.map +1 -0
  238. package/lib/typescript/src/hooks/hooks.d.ts +54 -0
  239. package/lib/typescript/src/hooks/hooks.d.ts.map +1 -0
  240. package/lib/typescript/src/hooks/types.d.ts +8 -0
  241. package/lib/typescript/src/hooks/types.d.ts.map +1 -0
  242. package/lib/typescript/src/hooks/useRoomEvents.d.ts +13 -0
  243. package/lib/typescript/src/hooks/useRoomEvents.d.ts.map +1 -0
  244. package/lib/typescript/src/index.d.ts +37 -0
  245. package/lib/typescript/src/index.d.ts.map +1 -0
  246. package/lib/typescript/src/ios/autoAttach.d.ts +2 -0
  247. package/lib/typescript/src/ios/autoAttach.d.ts.map +1 -0
  248. package/lib/typescript/src/ios/iosAudio.d.ts +96 -0
  249. package/lib/typescript/src/ios/iosAudio.d.ts.map +1 -0
  250. package/lib/typescript/src/join/appStateLifecycle.d.ts +14 -0
  251. package/lib/typescript/src/join/appStateLifecycle.d.ts.map +1 -0
  252. package/lib/typescript/src/micPolicy.d.ts +104 -0
  253. package/lib/typescript/src/micPolicy.d.ts.map +1 -0
  254. package/lib/typescript/src/native/NativeGravixAudio.d.ts +21 -0
  255. package/lib/typescript/src/native/NativeGravixAudio.d.ts.map +1 -0
  256. package/lib/typescript/src/native/NativeGravixRtc.d.ts +31 -0
  257. package/lib/typescript/src/native/NativeGravixRtc.d.ts.map +1 -0
  258. package/lib/typescript/src/native/module.d.ts +7 -0
  259. package/lib/typescript/src/native/module.d.ts.map +1 -0
  260. package/lib/typescript/src/polyfills/DOMException.d.ts +3 -0
  261. package/lib/typescript/src/polyfills/DOMException.d.ts.map +1 -0
  262. package/lib/typescript/src/polyfills/early.d.ts +2 -0
  263. package/lib/typescript/src/polyfills/early.d.ts.map +1 -0
  264. package/lib/typescript/src/polyfills/event.d.ts +2 -0
  265. package/lib/typescript/src/polyfills/event.d.ts.map +1 -0
  266. package/lib/typescript/src/polyfills/sha256.d.ts +3 -0
  267. package/lib/typescript/src/polyfills/sha256.d.ts.map +1 -0
  268. package/lib/typescript/src/polyfills/subtleHmac.d.ts +37 -0
  269. package/lib/typescript/src/polyfills/subtleHmac.d.ts.map +1 -0
  270. package/lib/typescript/src/polyfills/textCoding.d.ts +36 -0
  271. package/lib/typescript/src/polyfills/textCoding.d.ts.map +1 -0
  272. package/lib/typescript/src/registerGlobals.d.ts +42 -0
  273. package/lib/typescript/src/registerGlobals.d.ts.map +1 -0
  274. package/lib/typescript/src/unsupported.d.ts +42 -0
  275. package/lib/typescript/src/unsupported.d.ts.map +1 -0
  276. package/lib/typescript/src/version.d.ts +3 -0
  277. package/lib/typescript/src/version.d.ts.map +1 -0
  278. package/metro/index.js +39 -0
  279. package/metro/noise-stub.js +10 -0
  280. package/native/gxfx/include/gx_fx.h +82 -0
  281. package/native/gxfx/src/gx_fx.cpp +527 -0
  282. package/native/gxfx/third_party/README.md +4 -0
  283. package/native/gxfx/third_party/signalsmith-linear/LICENSE.txt +21 -0
  284. package/native/gxfx/third_party/signalsmith-linear/approx.h +191 -0
  285. package/native/gxfx/third_party/signalsmith-linear/fft.h +1386 -0
  286. package/native/gxfx/third_party/signalsmith-linear/linear.h +1129 -0
  287. package/native/gxfx/third_party/signalsmith-linear/platform/approx-cmsisdsp.h +40 -0
  288. package/native/gxfx/third_party/signalsmith-linear/platform/basic-fill-warnings.h +61 -0
  289. package/native/gxfx/third_party/signalsmith-linear/platform/fft-accelerate.h +340 -0
  290. package/native/gxfx/third_party/signalsmith-linear/platform/fft-cmsisdsp.h +307 -0
  291. package/native/gxfx/third_party/signalsmith-linear/platform/fft-ipp.h +532 -0
  292. package/native/gxfx/third_party/signalsmith-linear/platform/fft-linear.h +213 -0
  293. package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft-double.h +221 -0
  294. package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft.h +221 -0
  295. package/native/gxfx/third_party/signalsmith-linear/platform/linear-accelerate.h +593 -0
  296. package/native/gxfx/third_party/signalsmith-linear/platform/linear-cmsisdsp.h +713 -0
  297. package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd-dispatch.cpp +6 -0
  298. package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd.h +818 -0
  299. package/native/gxfx/third_party/signalsmith-linear/stft.h +700 -0
  300. package/native/gxfx/third_party/signalsmith-stretch-LICENSE.txt +21 -0
  301. package/native/gxfx/third_party/signalsmith-stretch.h +1060 -0
  302. package/native/gxns/CMakeLists.txt +67 -0
  303. package/native/gxns/include/gx_ns.h +285 -0
  304. package/native/gxns/src/gx_ns.c +1518 -0
  305. package/native/gxns/src/gx_ns_timer.c +84 -0
  306. package/native/gxns/src/gx_ns_timer.h +29 -0
  307. package/native/gxns/third_party/VENDOR.md +43 -0
  308. package/native/gxns/third_party/rnnoise/AUTHORS +1 -0
  309. package/native/gxns/third_party/rnnoise/COPYING +31 -0
  310. package/native/gxns/third_party/rnnoise/include/rnnoise.h +117 -0
  311. package/native/gxns/third_party/rnnoise/src/_kiss_fft_guts.h +182 -0
  312. package/native/gxns/third_party/rnnoise/src/arch.h +261 -0
  313. package/native/gxns/third_party/rnnoise/src/celt_lpc.c +172 -0
  314. package/native/gxns/third_party/rnnoise/src/celt_lpc.h +45 -0
  315. package/native/gxns/third_party/rnnoise/src/common.h +48 -0
  316. package/native/gxns/third_party/rnnoise/src/denoise.c +664 -0
  317. package/native/gxns/third_party/rnnoise/src/kiss_fft.c +601 -0
  318. package/native/gxns/third_party/rnnoise/src/kiss_fft.h +203 -0
  319. package/native/gxns/third_party/rnnoise/src/opus_types.h +159 -0
  320. package/native/gxns/third_party/rnnoise/src/pitch.c +523 -0
  321. package/native/gxns/third_party/rnnoise/src/pitch.h +149 -0
  322. package/native/gxns/third_party/rnnoise/src/rnn.c +178 -0
  323. package/native/gxns/third_party/rnnoise/src/rnn.h +65 -0
  324. package/native/gxns/third_party/rnnoise/src/rnn_data.c +11051 -0
  325. package/native/gxns/third_party/rnnoise/src/rnn_data.h +34 -0
  326. package/native/gxns/third_party/rnnoise/src/tansig_table.h +45 -0
  327. package/native/gxns/third_party/speexdsp/AUTHORS +18 -0
  328. package/native/gxns/third_party/speexdsp/COPYING +35 -0
  329. package/native/gxns/third_party/speexdsp/arch.h +232 -0
  330. package/native/gxns/third_party/speexdsp/resample.c +1239 -0
  331. package/native/gxns/third_party/speexdsp/resample_neon.h +339 -0
  332. package/native/gxns/third_party/speexdsp/resample_sse.h +128 -0
  333. package/native/gxns/third_party/speexdsp/speex_resampler.h +343 -0
  334. package/package.json +186 -4
  335. package/src/android/bindings.ts +61 -0
  336. package/src/android/index.ts +10 -0
  337. package/src/android/micMute.ts +422 -0
  338. package/src/android/nativeAudio.ts +94 -0
  339. package/src/android/noiseSuppression.ts +209 -0
  340. package/src/android/roomMusic.ts +193 -0
  341. package/src/android/singerMode.ts +53 -0
  342. package/src/android/voiceEffects.ts +126 -0
  343. package/src/audio/AudioManager.ts +111 -0
  344. package/src/audio/AudioSession.ts +190 -0
  345. package/src/audio/remoteVolume.ts +58 -0
  346. package/src/components/VideoView.tsx +152 -0
  347. package/src/features/audioScenario.ts +58 -0
  348. package/src/features/beauty.ts +1057 -0
  349. package/src/features/micRelease.ts +108 -0
  350. package/src/features/noiseSuppression.ts +251 -0
  351. package/src/features/roomMusic.ts +106 -0
  352. package/src/features/roomMusicAndroid.ts +310 -0
  353. package/src/features/roomMusicIos.ts +300 -0
  354. package/src/features/roomMusicTypes.ts +97 -0
  355. package/src/features/screenShare.ts +19 -0
  356. package/src/features/singerMode.ts +70 -0
  357. package/src/features/voiceEffects.ts +245 -0
  358. package/src/hooks/context.tsx +38 -0
  359. package/src/hooks/hooks.ts +247 -0
  360. package/src/hooks/types.ts +10 -0
  361. package/src/hooks/useRoomEvents.ts +35 -0
  362. package/src/index.tsx +134 -0
  363. package/src/ios/autoAttach.ts +11 -0
  364. package/src/ios/iosAudio.ts +202 -0
  365. package/src/join/appStateLifecycle.ts +55 -0
  366. package/src/micPolicy.ts +312 -0
  367. package/src/native/NativeGravixAudio.ts +30 -0
  368. package/src/native/NativeGravixRtc.ts +38 -0
  369. package/src/native/module.ts +22 -0
  370. package/src/polyfills/DOMException.ts +20 -0
  371. package/src/polyfills/early.ts +16 -0
  372. package/src/polyfills/event.ts +88 -0
  373. package/src/polyfills/sha256.ts +112 -0
  374. package/src/polyfills/subtleHmac.ts +124 -0
  375. package/src/polyfills/textCoding.ts +197 -0
  376. package/src/registerGlobals.ts +201 -0
  377. package/src/unsupported.ts +139 -0
  378. package/src/version.ts +4 -0
@@ -0,0 +1,339 @@
1
+ package com.gravitycompile.gravixrtc.music
2
+
3
+ import android.content.Context
4
+ import android.media.AudioFormat
5
+ import android.media.MediaCodec
6
+ import android.media.MediaExtractor
7
+ import android.media.MediaFormat
8
+ import android.net.Uri
9
+ import android.util.Log
10
+ import java.util.concurrent.atomic.AtomicLong
11
+
12
+ /**
13
+ * Decodes a local audio file or an Android `content://` URI (mp3/aac/m4a/ogg/
14
+ * flac/wav: anything the device's MediaCodec handles) to 16-bit PCM,
15
+ * resampled/remixed to the WebRTC capture format, and feeds a [PcmRingBuffer].
16
+ *
17
+ * [prepare] opens the source, selects the audio track and creates + starts the
18
+ * codec SYNCHRONOUSLY, so a missing file, an unreadable URI, a file with no
19
+ * audio track or a codec the device cannot decode is reported to the caller
20
+ * (start() fails with OPEN_FAILED) instead of being discovered silently on the
21
+ * decode thread (the pre-0.4.10 SDK engine returned success for all of those).
22
+ *
23
+ * The ring buffer's blocking write paces this thread: decode runs ~2 s ahead of
24
+ * playback and then sleeps, so pause simply stops consumption.
25
+ *
26
+ * SEEK: [requestSeek] is safe from any thread. It clears the ring (which also
27
+ * unblocks a decoder stuck in ring.write), and the decode loop applies the seek
28
+ * at the next iteration: codec flush + extractor.seekTo + resampler reset + a
29
+ * second ring.clear to drop any stale chunk written in between. [onSeekApplied]
30
+ * fires with the actual landed presentation time so the engine can rebase its
31
+ * position counter.
32
+ *
33
+ * LOOP: with [loop] on, end of stream rewinds to 0 WITHOUT clearing the ring, so
34
+ * the tail of the track and its head join seamlessly.
35
+ */
36
+ class MusicDecoder(
37
+ private val context: Context?,
38
+ private val source: String,
39
+ private val isContentUri: Boolean,
40
+ private val dstRate: Int,
41
+ private val dstChannels: Int,
42
+ private val ring: PcmRingBuffer,
43
+ ) : Thread("GxMusicDecoder") {
44
+
45
+ @Volatile var finished = false; private set
46
+ @Volatile var failed: String? = null; private set
47
+ @Volatile var durationUs: Long = -1; private set
48
+ @Volatile var loop = false
49
+ @Volatile private var stopped = false
50
+
51
+ /** Invoked on the decoder thread right after a seek lands (actual µs). */
52
+ @Volatile var onSeekApplied: ((Long) -> Unit)? = null
53
+ /** Invoked on the decoder thread when decoding fails mid-track. */
54
+ @Volatile var onFailed: ((String) -> Unit)? = null
55
+ /** Invoked on the decoder thread each time a loop rewinds to 0. */
56
+ @Volatile var onLooped: (() -> Unit)? = null
57
+
58
+ private val pendingSeekUs = AtomicLong(-1)
59
+
60
+ private var extractor: MediaExtractor? = null
61
+ private var codec: MediaCodec? = null
62
+ private var isRawPcm = false
63
+ private var prepared = false
64
+
65
+ // linear-resampler state
66
+ private var srcRate = dstRate
67
+ private var srcChannels = dstChannels
68
+ private var pos = 0.0
69
+ private var hasPrev = false
70
+ private val lastFrame = ShortArray(8)
71
+ private var out = ShortArray(0)
72
+
73
+ /**
74
+ * Opens the source and the codec. Returns null on success, else a reason.
75
+ * Must be called (once) before [start].
76
+ */
77
+ fun prepare(): String? {
78
+ var ex: MediaExtractor? = null
79
+ try {
80
+ ex = MediaExtractor()
81
+ if (isContentUri) {
82
+ val ctx = context ?: return "no Android context for a content URI"
83
+ ex.setDataSource(ctx, Uri.parse(source), null)
84
+ } else {
85
+ ex.setDataSource(source)
86
+ }
87
+ var trackIndex = -1
88
+ var format: MediaFormat? = null
89
+ for (i in 0 until ex.trackCount) {
90
+ val f = ex.getTrackFormat(i)
91
+ val m = f.getString(MediaFormat.KEY_MIME) ?: continue
92
+ if (m.startsWith("audio/")) { trackIndex = i; format = f; break }
93
+ }
94
+ if (trackIndex < 0 || format == null) {
95
+ runCatching { ex.release() }
96
+ return "no audio track in the source"
97
+ }
98
+ ex.selectTrack(trackIndex)
99
+ val mime = format.getString(MediaFormat.KEY_MIME)!!
100
+ srcRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE)
101
+ srcChannels = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT).coerceIn(1, 8)
102
+ if (format.containsKey(MediaFormat.KEY_DURATION)) {
103
+ durationUs = format.getLong(MediaFormat.KEY_DURATION)
104
+ }
105
+ isRawPcm = mime == MediaFormat.MIMETYPE_AUDIO_RAW
106
+ if (!isRawPcm) {
107
+ // createDecoderByType/configure/start are where an unsupported
108
+ // codec actually fails, so they belong here.
109
+ val c = MediaCodec.createDecoderByType(mime)
110
+ try {
111
+ c.configure(format, null, null, 0)
112
+ c.start()
113
+ } catch (e: Exception) {
114
+ runCatching { c.release() }
115
+ throw e
116
+ }
117
+ codec = c
118
+ }
119
+ extractor = ex
120
+ prepared = true
121
+ return null
122
+ } catch (e: Exception) {
123
+ runCatching { ex?.release() }
124
+ Log.w(TAG, "prepare failed: $e")
125
+ return e.message ?: e.javaClass.simpleName
126
+ }
127
+ }
128
+
129
+ fun shutdown() {
130
+ stopped = true
131
+ ring.close()
132
+ interrupt()
133
+ // A thread that was never started never runs its finally block.
134
+ if (state == State.NEW) releaseCodec()
135
+ }
136
+
137
+ /** Thread-safe. Position in microseconds; clamped to >= 0. */
138
+ fun requestSeek(positionUs: Long) {
139
+ pendingSeekUs.set(positionUs.coerceAtLeast(0))
140
+ // Frees space + wakes a blocked write() so the loop reaches the seek
141
+ // check promptly instead of waiting for playback to drain.
142
+ ring.clear()
143
+ }
144
+
145
+ override fun run() {
146
+ try {
147
+ check(prepared) { "prepare() first" }
148
+ val ex = extractor!!
149
+ val c = codec
150
+ if (isRawPcm || c == null) pumpRaw(ex) else pumpCodec(ex, c)
151
+ } catch (e: Exception) {
152
+ if (!stopped) {
153
+ Log.e(TAG, "decode failed: $e")
154
+ failed = e.message ?: e.javaClass.simpleName
155
+ onFailed?.invoke(failed!!)
156
+ }
157
+ } finally {
158
+ finished = true
159
+ releaseCodec()
160
+ }
161
+ }
162
+
163
+ @Synchronized
164
+ private fun releaseCodec() {
165
+ val c = codec
166
+ codec = null
167
+ if (c != null) runCatching { c.stop() }.also { runCatching { c.release() } }
168
+ val ex = extractor
169
+ extractor = null
170
+ if (ex != null) runCatching { ex.release() }
171
+ }
172
+
173
+ /** Applies a pending seek, if any. Returns true when a seek happened. */
174
+ private fun maybeSeek(extractor: MediaExtractor, codec: MediaCodec?): Boolean {
175
+ val us = pendingSeekUs.getAndSet(-1)
176
+ if (us < 0) return false
177
+ runCatching { codec?.flush() }
178
+ extractor.seekTo(us, MediaExtractor.SEEK_TO_PREVIOUS_SYNC)
179
+ // Drop anything decoded before the seek that slipped into the ring
180
+ // between requestSeek()'s clear and now.
181
+ ring.clear()
182
+ pos = 0.0
183
+ hasPrev = false
184
+ val actual = extractor.sampleTime.let { if (it >= 0) it else us }
185
+ onSeekApplied?.invoke(actual)
186
+ return true
187
+ }
188
+
189
+ /** Rewinds for [loop] without touching the ring (seamless). */
190
+ private fun rewind(extractor: MediaExtractor, codec: MediaCodec?) {
191
+ runCatching { codec?.flush() }
192
+ extractor.seekTo(0, MediaExtractor.SEEK_TO_PREVIOUS_SYNC)
193
+ onLooped?.invoke()
194
+ }
195
+
196
+ private fun pumpCodec(extractor: MediaExtractor, codec: MediaCodec) {
197
+ val info = MediaCodec.BufferInfo()
198
+ var inputDone = false
199
+ var pcm = ShortArray(0)
200
+ while (!stopped) {
201
+ if (maybeSeek(extractor, codec)) inputDone = false
202
+
203
+ if (!inputDone) {
204
+ val inIdx = codec.dequeueInputBuffer(10_000)
205
+ if (inIdx >= 0) {
206
+ val inBuf = codec.getInputBuffer(inIdx)!!
207
+ val size = extractor.readSampleData(inBuf, 0)
208
+ if (size < 0) {
209
+ codec.queueInputBuffer(inIdx, 0, 0, 0,
210
+ MediaCodec.BUFFER_FLAG_END_OF_STREAM)
211
+ inputDone = true
212
+ } else {
213
+ codec.queueInputBuffer(inIdx, 0, size, extractor.sampleTime, 0)
214
+ extractor.advance()
215
+ }
216
+ }
217
+ }
218
+ when (val outIdx = codec.dequeueOutputBuffer(info, 10_000)) {
219
+ MediaCodec.INFO_OUTPUT_FORMAT_CHANGED -> {
220
+ // decoders may output a different rate/layout than the
221
+ // container declares (e.g. HE-AAC): trust this format
222
+ val f = codec.outputFormat
223
+ srcRate = f.getInteger(MediaFormat.KEY_SAMPLE_RATE)
224
+ srcChannels = f.getInteger(MediaFormat.KEY_CHANNEL_COUNT).coerceIn(1, 8)
225
+ if (f.containsKey(MediaFormat.KEY_PCM_ENCODING) &&
226
+ f.getInteger(MediaFormat.KEY_PCM_ENCODING) != AudioFormat.ENCODING_PCM_16BIT) {
227
+ Log.w(TAG, "non-16bit PCM output; audio may be wrong")
228
+ }
229
+ }
230
+ MediaCodec.INFO_TRY_AGAIN_LATER -> { /* loop */ }
231
+ else -> if (outIdx >= 0) {
232
+ val outBuf = codec.getOutputBuffer(outIdx)!!
233
+ if (info.size > 0) {
234
+ outBuf.position(info.offset)
235
+ outBuf.limit(info.offset + info.size)
236
+ val n = info.size / 2
237
+ if (pcm.size < n) pcm = ShortArray(n)
238
+ outBuf.order(java.nio.ByteOrder.nativeOrder())
239
+ .asShortBuffer().get(pcm, 0, n)
240
+ feed(pcm, n)
241
+ }
242
+ codec.releaseOutputBuffer(outIdx, false)
243
+ if (info.flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM != 0) {
244
+ // A seek can race EOS: if one is pending, honor it
245
+ // instead of ending the track.
246
+ if (pendingSeekUs.get() >= 0 && maybeSeek(extractor, codec)) {
247
+ inputDone = false
248
+ continue
249
+ }
250
+ if (loop && !stopped) {
251
+ rewind(extractor, codec)
252
+ inputDone = false
253
+ continue
254
+ }
255
+ return
256
+ }
257
+ }
258
+ }
259
+ }
260
+ }
261
+
262
+ private fun pumpRaw(extractor: MediaExtractor) {
263
+ val buf = java.nio.ByteBuffer.allocate(64 * 1024)
264
+ var pcm = ShortArray(0)
265
+ while (!stopped) {
266
+ maybeSeek(extractor, null)
267
+ buf.clear()
268
+ val size = extractor.readSampleData(buf, 0)
269
+ if (size < 0) {
270
+ if (pendingSeekUs.get() >= 0) continue // seek raced EOS
271
+ if (loop && !stopped) { rewind(extractor, null); continue }
272
+ return
273
+ }
274
+ val n = size / 2
275
+ if (pcm.size < n) pcm = ShortArray(n)
276
+ buf.limit(size)
277
+ buf.order(java.nio.ByteOrder.nativeOrder()).asShortBuffer().get(pcm, 0, n)
278
+ feed(pcm, n)
279
+ extractor.advance()
280
+ }
281
+ }
282
+
283
+ /** Downmix/upmix to dstChannels, linear-resample to dstRate, push to ring. */
284
+ private fun feed(pcm: ShortArray, len: Int) {
285
+ val srcFrames = len / srcChannels
286
+ if (srcFrames == 0) return
287
+
288
+ if (srcChannels == dstChannels && srcRate == dstRate) {
289
+ ring.write(pcm, 0, srcFrames * srcChannels)
290
+ return
291
+ }
292
+ // channel conversion: average to mono, copy to every destination channel
293
+ val mono = ShortArray(srcFrames * dstChannels)
294
+ for (f in 0 until srcFrames) {
295
+ var acc = 0
296
+ for (c in 0 until srcChannels) acc += pcm[f * srcChannels + c]
297
+ val sample = (acc / srcChannels).toShort()
298
+ for (c in 0 until dstChannels) mono[f * dstChannels + c] = sample
299
+ }
300
+
301
+ if (srcRate == dstRate) { ring.write(mono, 0, mono.size); return }
302
+
303
+ // linear resample over [prevFrame, mono...] so chunks join seamlessly
304
+ val prevFrames = if (hasPrev) 1 else 0
305
+ val totalFrames = srcFrames + prevFrames
306
+ fun sampleAt(idx: Int, c: Int): Double =
307
+ if (idx < prevFrames) lastFrame[c].toDouble()
308
+ else mono[(idx - prevFrames) * dstChannels + c].toDouble()
309
+
310
+ val step = srcRate.toDouble() / dstRate
311
+ val maxOut = ((totalFrames / step) + 2).toInt() * dstChannels
312
+ if (out.size < maxOut) out = ShortArray(maxOut)
313
+ var outFrames = 0
314
+ while (pos < totalFrames - 1) {
315
+ val i = pos.toInt()
316
+ val frac = pos - i
317
+ for (c in 0 until dstChannels) {
318
+ val a = sampleAt(i, c)
319
+ val b = sampleAt(i + 1, c)
320
+ out[outFrames * dstChannels + c] = (a + (b - a) * frac).toInt()
321
+ .coerceIn(-32768, 32767).toShort()
322
+ }
323
+ outFrames++
324
+ pos += step
325
+ }
326
+ // re-base pos against the new carried frame (= last frame of chunk)
327
+ pos -= (totalFrames - 1)
328
+ if (pos < 0) pos = 0.0
329
+ for (c in 0 until dstChannels) {
330
+ lastFrame[c] = mono[(srcFrames - 1) * dstChannels + c]
331
+ }
332
+ hasPrev = true
333
+ ring.write(out, 0, outFrames * dstChannels)
334
+ }
335
+
336
+ private companion object {
337
+ const val TAG = "GxMusicDecoder"
338
+ }
339
+ }
@@ -0,0 +1,82 @@
1
+ package com.gravitycompile.gravixrtc.music
2
+
3
+ import android.content.Context
4
+ import android.media.AudioManager
5
+ import android.os.Build
6
+ import android.os.Handler
7
+ import android.os.Looper
8
+ import android.util.Log
9
+
10
+ /**
11
+ * Reports a phone call (cellular or another app's call) while room music plays,
12
+ * without READ_PHONE_STATE: the audio mode turns RINGTONE / IN_CALL /
13
+ * CALL_SCREENING / CALL_REDIRECT. MODE_IN_COMMUNICATION is not a call signal
14
+ * (the room itself runs in it).
15
+ *
16
+ * Android 12+: AudioManager.addOnModeChangedListener. Older: a 500 ms poll of
17
+ * AudioManager.mode on the main looper, only while music is active.
18
+ */
19
+ class MusicInterruptionWatcher(
20
+ context: Context,
21
+ private val onCallChanged: (inCall: Boolean) -> Unit,
22
+ ) {
23
+ private val am = context.applicationContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
24
+ private val main = Handler(Looper.getMainLooper())
25
+ private var inCall = false
26
+ private var running = false
27
+ private var modeListener: Any? = null
28
+
29
+ private val poll = object : Runnable {
30
+ override fun run() {
31
+ if (!running) return
32
+ onMode(am.mode)
33
+ main.postDelayed(this, 500)
34
+ }
35
+ }
36
+
37
+ fun start() {
38
+ if (running) return
39
+ running = true
40
+ inCall = isCallMode(am.mode)
41
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
42
+ try {
43
+ val l = AudioManager.OnModeChangedListener { mode -> onMode(mode) }
44
+ am.addOnModeChangedListener({ r -> main.post(r) }, l)
45
+ modeListener = l
46
+ return
47
+ } catch (e: Throwable) {
48
+ Log.w(TAG, "mode listener unavailable, polling: $e")
49
+ }
50
+ }
51
+ main.postDelayed(poll, 500)
52
+ }
53
+
54
+ fun stop() {
55
+ running = false
56
+ main.removeCallbacks(poll)
57
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
58
+ (modeListener as? AudioManager.OnModeChangedListener)?.let {
59
+ runCatching { am.removeOnModeChangedListener(it) }
60
+ }
61
+ }
62
+ modeListener = null
63
+ }
64
+
65
+ private fun onMode(mode: Int) {
66
+ if (!running) return
67
+ val call = isCallMode(mode)
68
+ if (call == inCall) return
69
+ inCall = call
70
+ onCallChanged(call)
71
+ }
72
+
73
+ companion object {
74
+ private const val TAG = "GxMusicInterrupt"
75
+
76
+ fun isCallMode(mode: Int): Boolean =
77
+ mode == AudioManager.MODE_RINGTONE ||
78
+ mode == AudioManager.MODE_IN_CALL ||
79
+ mode == 4 /* MODE_CALL_SCREENING (API 30) */ ||
80
+ mode == 5 /* MODE_CALL_REDIRECT (API 33) */
81
+ }
82
+ }
@@ -0,0 +1,117 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ package com.gravitycompile.gravixrtc.music
4
+
5
+ import android.os.SystemClock
6
+ import android.util.Log
7
+ import com.gravitycompile.gravixrtc.processing.GxRecorderSeam
8
+ import org.webrtc.audio.JavaAudioDeviceModule
9
+
10
+ /**
11
+ * Room music under a mute with the HARDWARE microphone closed (owner decision 2026-11-28,
12
+ * doc/internal/MUSIC_WHILE_MIC_RELEASED.md).
13
+ *
14
+ * On react-native-webrtc 155's WebRTC build the release runs in the capture seam
15
+ * ([GxRecorderSeam]): while [GxRecorderSeam.released] its AudioRecord.read() stops the
16
+ * hardware recorder (the OS mic indicator goes off) and delivers silence, which
17
+ * [MusicMixerEngine] mixes the music into and clocks to real time (bytesRead = 0). On a
18
+ * restore the next read() restarts the recorder; a refused restart is reported
19
+ * ([GxRecorderSeam.reopenFailed]) and silence keeps the record thread alive.
20
+ *
21
+ * The voice mute ([MusicMixerEngine.captureMuted]) is required BEFORE a release and stays on
22
+ * for the whole release.
23
+ */
24
+ internal object MusicMicRelease {
25
+ private const val TAG = "GxMicRelease"
26
+
27
+ /** The recorder is released by us (the record thread delivers silence + music). */
28
+ val released: Boolean
29
+ get() = GxRecorderSeam.released
30
+
31
+ @Volatile private var releasedAtMs = 0L
32
+
33
+ /**
34
+ * Releases the hardware recorder. Refused (false, nothing changed) unless the capture seam is
35
+ * attached to the running recorder, a music session runs without holdOnMute, and the voice
36
+ * mute is on.
37
+ */
38
+ @Synchronized
39
+ fun release(adm: JavaAudioDeviceModule?): Boolean {
40
+ if (adm == null) return refuse("no audio device module")
41
+ if (!MusicMixerEngine.captureMuted) return refuse("the module mute is off")
42
+ if (MusicMixerEngine.holdOnMute) return refuse("holdOnMute")
43
+ if (!MusicMixerEngine.isActive()) return refuse("no music session")
44
+ if (GxRecorderSeam.current == null) return refuse("the capture seam is not attached to the recorder")
45
+ GxRecorderSeam.released = true
46
+ releasedAtMs = SystemClock.elapsedRealtime()
47
+ Log.i(TAG, "recorder released: the record thread delivers silence + music")
48
+ return true
49
+ }
50
+
51
+ /**
52
+ * Gives the recorder back. [waitOpen] (unmute): waits up to [timeoutMs] for the record thread
53
+ * to have the recorder RECORDING again; false when it failed (no microphone; the seam keeps
54
+ * retrying). Otherwise (music ended while muted, core mute, teardown): clears the flag at once
55
+ * and returns true. Stock WebRTC never stops its record thread on a track mute, so there is
56
+ * nothing to wait for; a mute that should keep the mic closed is [GxRecorderSeam.closedByMute]
57
+ * (the room mic policy sets it on the core mute). Runs off the main thread (it sleeps).
58
+ */
59
+ fun restore(adm: JavaAudioDeviceModule?, waitOpen: Boolean, timeoutMs: Long): Boolean {
60
+ val heldMs = if (releasedAtMs > 0) SystemClock.elapsedRealtime() - releasedAtMs else -1
61
+ GxRecorderSeam.released = false
62
+ if (adm == null) return true
63
+ if (!waitOpen) {
64
+ Log.i(TAG, "recorder flag restored (released for $heldMs ms, closedByMute=${GxRecorderSeam.closedByMute})")
65
+ return true
66
+ }
67
+ val t0 = SystemClock.elapsedRealtime()
68
+ val deadline = t0 + timeoutMs
69
+ while (SystemClock.elapsedRealtime() < deadline) {
70
+ if (!GxRecorderSeam.threadAlive()) {
71
+ Log.i(TAG, "recorder restored: no record thread (the next start opens the mic)")
72
+ return true
73
+ }
74
+ if (GxRecorderSeam.closedByMute) {
75
+ Log.i(TAG, "recorder restored to the mute release (the mic stays closed while muted)")
76
+ return true
77
+ }
78
+ if (GxRecorderSeam.recorderOpen()) {
79
+ Log.i(TAG, "recorder reopened in ${SystemClock.elapsedRealtime() - t0} ms (released for $heldMs ms)")
80
+ return true
81
+ }
82
+ // a fresh failure only: wait at least one retry period of the seam before giving up
83
+ if (GxRecorderSeam.reopenFailed && SystemClock.elapsedRealtime() - t0 > 600) {
84
+ Log.e(TAG, "recorder reopen FAILED (no microphone; the seam keeps retrying)")
85
+ return false
86
+ }
87
+ SystemClock.sleep(5)
88
+ }
89
+ Log.e(TAG, "recorder reopen timed out after $timeoutMs ms")
90
+ return false
91
+ }
92
+
93
+ /**
94
+ * Safety net (module unmute, reload): the release never outlives its owner. No wait.
95
+ * [orphanOnly] (capture start) keeps an active release: it is JS's to give back, in its order.
96
+ */
97
+ @Suppress("UNUSED_PARAMETER")
98
+ fun restoreNow(adm: JavaAudioDeviceModule?, why: String, orphanOnly: Boolean = false) {
99
+ if (orphanOnly || !released) return
100
+ GxRecorderSeam.released = false
101
+ Log.w(TAG, "recorder release cleared by the safety net ($why)")
102
+ }
103
+
104
+ fun state(adm: JavaAudioDeviceModule?): Map<String, Any?> = mapOf(
105
+ "released" to released,
106
+ "recorderOpen" to (adm != null && GxRecorderSeam.recorderOpen()),
107
+ // webrtc-sdk's flag name, kept for the JS diagnostics: false while the seam holds the mic closed
108
+ "useAudioRecord" to !(GxRecorderSeam.released || GxRecorderSeam.closedByMute),
109
+ "silentFrames" to MusicMixerEngine.silentFrames,
110
+ "seam" to GxRecorderSeam.state(),
111
+ )
112
+
113
+ private fun refuse(why: String): Boolean {
114
+ Log.w(TAG, "recorder release refused: $why")
115
+ return false
116
+ }
117
+ }