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.
- package/CHANGELOG.md +134 -0
- package/LICENSE +20 -0
- package/LICENSES/Apache-2.0.txt +175 -0
- package/NOTICE +68 -0
- package/README.md +313 -2
- package/android/build.gradle +137 -0
- package/android/consumer-rules.pro +29 -0
- package/android/src/main/AndroidManifest.xml +9 -0
- package/android/src/main/cpp/CMakeLists.txt +48 -0
- package/android/src/main/cpp/gx_dfn_engine.c +332 -0
- package/android/src/main/cpp/gx_fx_jni.cpp +34 -0
- package/android/src/main/cpp/gx_ns_jni.c +162 -0
- package/android/src/main/cpp/third_party/onnxruntime/LICENSE +21 -0
- package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_c_api.h +9227 -0
- package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_ep_c_api.h +3315 -0
- package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_error_code.h +98 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioHooks.kt +144 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioModule.kt +105 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixNativeAudio.kt +310 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtc.kt +134 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcModule.kt +176 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcPackage.kt +39 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioDeviceKind.java +44 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioManagerUtils.kt +120 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioSwitchManager.java +270 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioType.kt +50 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicCaptureRouter.kt +375 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicDecoder.kt +339 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicInterruptionWatcher.kt +82 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMicRelease.kt +117 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixKernel.kt +191 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixerEngine.kt +617 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/AudioRoutePolicy.kt +137 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GravixCaptureProcessing.kt +67 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureDump.kt +143 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureSwitcher.kt +196 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNoiseProcessor.kt +795 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsLogic.kt +180 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsNative.kt +83 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsStudio.kt +372 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecordStartGuard.kt +76 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecorderSeam.kt +434 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxSingerSource.kt +37 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxVoiceFx.kt +160 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/OtherAppAudioPolicy.kt +143 -0
- package/android/src/main/java/org/webrtc/audio/WebRtcAudioTrackHelper.kt +43 -0
- package/docs/ANDROID_NATIVE_HOOKS.md +102 -0
- package/docs/FEATURE_MATRIX.md +192 -0
- package/docs/IOS_NATIVE_HOOKS.md +190 -0
- package/gravix-rtc-react-native.podspec +49 -0
- package/ios/GravixRtc.h +7 -0
- package/ios/GravixRtc.mm +273 -0
- package/ios/GravixRtcSetup.h +29 -0
- package/ios/GravixRtcSetup.m +52 -0
- package/ios/audio/GravixRtcIosAudio.m +157 -0
- package/ios/audio/GxAudioDevice.h +62 -0
- package/ios/audio/GxAudioDevice.m +857 -0
- package/ios/audio/GxAudioSetup.h +34 -0
- package/ios/audio/GxAudioSetup.m +70 -0
- package/ios/audio/GxCompat.swift +53 -0
- package/ios/audio/GxIosAudio.swift +99 -0
- package/ios/audio/GxMusicController.swift +150 -0
- package/ios/audio/GxMusicPost.swift +362 -0
- package/ios/audio/GxNoiseProcessor.swift +718 -0
- package/ios/audio/GxNsDfn3CoreML.swift +195 -0
- package/ios/audio/GxNsStudioEngine.swift +237 -0
- package/ios/audio/GxNsStudioPack.swift +212 -0
- package/ios/audio/GxVoiceFx.swift +161 -0
- package/ios/audio/gx_adm_state.h +153 -0
- package/ios/gxcore/apple/gx_music_post.c +312 -0
- package/ios/gxcore/apple/gx_pcm.c +30 -0
- package/ios/gxcore/apple/gxns_build.h +19 -0
- package/ios/gxcore/apple/gxns_ios.c +17 -0
- package/ios/gxcore/apple/include/gx_fx.h +3 -0
- package/ios/gxcore/apple/include/gx_music_post.h +88 -0
- package/ios/gxcore/apple/include/gx_ns.h +3 -0
- package/ios/gxcore/apple/include/gx_pcm.h +33 -0
- package/ios/gxcore/apple/include/gxns_ios.h +18 -0
- package/ios/gxcore/apple/include/module.modulemap +10 -0
- package/ios/gxcore/apple/shim/rnnoise.h +2 -0
- package/ios/gxcore/apple/shim/speex_resampler.h +2 -0
- package/ios/gxcore/apple/units/gx_fx_forward.cpp +3 -0
- package/ios/gxcore/apple/units/gx_ns.c +7 -0
- package/ios/gxcore/apple/units/gx_ns_timer.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_celt_lpc.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_denoise.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_kiss_fft.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_pitch.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_rnn.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_rnn_data.c +7 -0
- package/ios/gxcore/apple/units/speexdsp_resample.c +7 -0
- package/ios/resources/ns/DFN3-NOTICE.txt +10 -0
- package/ios/resources/ns/DeepFilterNet-LICENSE-APACHE +201 -0
- package/ios/resources/ns/DeepFilterNet-LICENSE-MIT +19 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/analytics/coremldata.bin +0 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/coremldata.bin +0 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/metadata.json +338 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/model.mil +927 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/weights/weight.bin +0 -0
- package/lib/module/android/bindings.js +49 -0
- package/lib/module/android/bindings.js.map +1 -0
- package/lib/module/android/index.js +13 -0
- package/lib/module/android/index.js.map +1 -0
- package/lib/module/android/micMute.js +341 -0
- package/lib/module/android/micMute.js.map +1 -0
- package/lib/module/android/nativeAudio.js +47 -0
- package/lib/module/android/nativeAudio.js.map +1 -0
- package/lib/module/android/noiseSuppression.js +170 -0
- package/lib/module/android/noiseSuppression.js.map +1 -0
- package/lib/module/android/roomMusic.js +142 -0
- package/lib/module/android/roomMusic.js.map +1 -0
- package/lib/module/android/singerMode.js +31 -0
- package/lib/module/android/singerMode.js.map +1 -0
- package/lib/module/android/voiceEffects.js +65 -0
- package/lib/module/android/voiceEffects.js.map +1 -0
- package/lib/module/audio/AudioManager.js +79 -0
- package/lib/module/audio/AudioManager.js.map +1 -0
- package/lib/module/audio/AudioSession.js +90 -0
- package/lib/module/audio/AudioSession.js.map +1 -0
- package/lib/module/audio/remoteVolume.js +54 -0
- package/lib/module/audio/remoteVolume.js.map +1 -0
- package/lib/module/components/VideoView.js +109 -0
- package/lib/module/components/VideoView.js.map +1 -0
- package/lib/module/features/audioScenario.js +53 -0
- package/lib/module/features/audioScenario.js.map +1 -0
- package/lib/module/features/beauty.js +828 -0
- package/lib/module/features/beauty.js.map +1 -0
- package/lib/module/features/micRelease.js +89 -0
- package/lib/module/features/micRelease.js.map +1 -0
- package/lib/module/features/noiseSuppression.js +213 -0
- package/lib/module/features/noiseSuppression.js.map +1 -0
- package/lib/module/features/roomMusic.js +90 -0
- package/lib/module/features/roomMusic.js.map +1 -0
- package/lib/module/features/roomMusicAndroid.js +294 -0
- package/lib/module/features/roomMusicAndroid.js.map +1 -0
- package/lib/module/features/roomMusicIos.js +250 -0
- package/lib/module/features/roomMusicIos.js.map +1 -0
- package/lib/module/features/roomMusicTypes.js +53 -0
- package/lib/module/features/roomMusicTypes.js.map +1 -0
- package/lib/module/features/screenShare.js +22 -0
- package/lib/module/features/screenShare.js.map +1 -0
- package/lib/module/features/singerMode.js +73 -0
- package/lib/module/features/singerMode.js.map +1 -0
- package/lib/module/features/voiceEffects.js +148 -0
- package/lib/module/features/voiceEffects.js.map +1 -0
- package/lib/module/hooks/context.js +34 -0
- package/lib/module/hooks/context.js.map +1 -0
- package/lib/module/hooks/hooks.js +145 -0
- package/lib/module/hooks/hooks.js.map +1 -0
- package/lib/module/hooks/types.js +4 -0
- package/lib/module/hooks/types.js.map +1 -0
- package/lib/module/hooks/useRoomEvents.js +30 -0
- package/lib/module/hooks/useRoomEvents.js.map +1 -0
- package/lib/module/index.js +43 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/ios/autoAttach.js +14 -0
- package/lib/module/ios/autoAttach.js.map +1 -0
- package/lib/module/ios/iosAudio.js +149 -0
- package/lib/module/ios/iosAudio.js.map +1 -0
- package/lib/module/join/appStateLifecycle.js +54 -0
- package/lib/module/join/appStateLifecycle.js.map +1 -0
- package/lib/module/micPolicy.js +249 -0
- package/lib/module/micPolicy.js.map +1 -0
- package/lib/module/native/NativeGravixAudio.js +18 -0
- package/lib/module/native/NativeGravixAudio.js.map +1 -0
- package/lib/module/native/NativeGravixRtc.js +13 -0
- package/lib/module/native/NativeGravixRtc.js.map +1 -0
- package/lib/module/native/module.js +23 -0
- package/lib/module/native/module.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/polyfills/DOMException.js +22 -0
- package/lib/module/polyfills/DOMException.js.map +1 -0
- package/lib/module/polyfills/early.js +18 -0
- package/lib/module/polyfills/early.js.map +1 -0
- package/lib/module/polyfills/event.js +71 -0
- package/lib/module/polyfills/event.js.map +1 -0
- package/lib/module/polyfills/sha256.js +92 -0
- package/lib/module/polyfills/sha256.js.map +1 -0
- package/lib/module/polyfills/subtleHmac.js +91 -0
- package/lib/module/polyfills/subtleHmac.js.map +1 -0
- package/lib/module/polyfills/textCoding.js +164 -0
- package/lib/module/polyfills/textCoding.js.map +1 -0
- package/lib/module/registerGlobals.js +135 -0
- package/lib/module/registerGlobals.js.map +1 -0
- package/lib/module/unsupported.js +90 -0
- package/lib/module/unsupported.js.map +1 -0
- package/lib/module/version.js +7 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/android/bindings.d.ts +14 -0
- package/lib/typescript/src/android/bindings.d.ts.map +1 -0
- package/lib/typescript/src/android/index.d.ts +9 -0
- package/lib/typescript/src/android/index.d.ts.map +1 -0
- package/lib/typescript/src/android/micMute.d.ts +124 -0
- package/lib/typescript/src/android/micMute.d.ts.map +1 -0
- package/lib/typescript/src/android/nativeAudio.d.ts +40 -0
- package/lib/typescript/src/android/nativeAudio.d.ts.map +1 -0
- package/lib/typescript/src/android/noiseSuppression.d.ts +48 -0
- package/lib/typescript/src/android/noiseSuppression.d.ts.map +1 -0
- package/lib/typescript/src/android/roomMusic.d.ts +80 -0
- package/lib/typescript/src/android/roomMusic.d.ts.map +1 -0
- package/lib/typescript/src/android/singerMode.d.ts +27 -0
- package/lib/typescript/src/android/singerMode.d.ts.map +1 -0
- package/lib/typescript/src/android/voiceEffects.d.ts +30 -0
- package/lib/typescript/src/android/voiceEffects.d.ts.map +1 -0
- package/lib/typescript/src/audio/AudioManager.d.ts +32 -0
- package/lib/typescript/src/audio/AudioManager.d.ts.map +1 -0
- package/lib/typescript/src/audio/AudioSession.d.ts +70 -0
- package/lib/typescript/src/audio/AudioSession.d.ts.map +1 -0
- package/lib/typescript/src/audio/remoteVolume.d.ts +8 -0
- package/lib/typescript/src/audio/remoteVolume.d.ts.map +1 -0
- package/lib/typescript/src/components/VideoView.d.ts +44 -0
- package/lib/typescript/src/components/VideoView.d.ts.map +1 -0
- package/lib/typescript/src/features/audioScenario.d.ts +24 -0
- package/lib/typescript/src/features/audioScenario.d.ts.map +1 -0
- package/lib/typescript/src/features/beauty.d.ts +377 -0
- package/lib/typescript/src/features/beauty.d.ts.map +1 -0
- package/lib/typescript/src/features/micRelease.d.ts +28 -0
- package/lib/typescript/src/features/micRelease.d.ts.map +1 -0
- package/lib/typescript/src/features/noiseSuppression.d.ts +64 -0
- package/lib/typescript/src/features/noiseSuppression.d.ts.map +1 -0
- package/lib/typescript/src/features/roomMusic.d.ts +41 -0
- package/lib/typescript/src/features/roomMusic.d.ts.map +1 -0
- package/lib/typescript/src/features/roomMusicAndroid.d.ts +60 -0
- package/lib/typescript/src/features/roomMusicAndroid.d.ts.map +1 -0
- package/lib/typescript/src/features/roomMusicIos.d.ts +56 -0
- package/lib/typescript/src/features/roomMusicIos.d.ts.map +1 -0
- package/lib/typescript/src/features/roomMusicTypes.d.ts +76 -0
- package/lib/typescript/src/features/roomMusicTypes.d.ts.map +1 -0
- package/lib/typescript/src/features/screenShare.d.ts +12 -0
- package/lib/typescript/src/features/screenShare.d.ts.map +1 -0
- package/lib/typescript/src/features/singerMode.d.ts +20 -0
- package/lib/typescript/src/features/singerMode.d.ts.map +1 -0
- package/lib/typescript/src/features/voiceEffects.d.ts +46 -0
- package/lib/typescript/src/features/voiceEffects.d.ts.map +1 -0
- package/lib/typescript/src/hooks/context.d.ts +12 -0
- package/lib/typescript/src/hooks/context.d.ts.map +1 -0
- package/lib/typescript/src/hooks/hooks.d.ts +54 -0
- package/lib/typescript/src/hooks/hooks.d.ts.map +1 -0
- package/lib/typescript/src/hooks/types.d.ts +8 -0
- package/lib/typescript/src/hooks/types.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRoomEvents.d.ts +13 -0
- package/lib/typescript/src/hooks/useRoomEvents.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +37 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/ios/autoAttach.d.ts +2 -0
- package/lib/typescript/src/ios/autoAttach.d.ts.map +1 -0
- package/lib/typescript/src/ios/iosAudio.d.ts +96 -0
- package/lib/typescript/src/ios/iosAudio.d.ts.map +1 -0
- package/lib/typescript/src/join/appStateLifecycle.d.ts +14 -0
- package/lib/typescript/src/join/appStateLifecycle.d.ts.map +1 -0
- package/lib/typescript/src/micPolicy.d.ts +104 -0
- package/lib/typescript/src/micPolicy.d.ts.map +1 -0
- package/lib/typescript/src/native/NativeGravixAudio.d.ts +21 -0
- package/lib/typescript/src/native/NativeGravixAudio.d.ts.map +1 -0
- package/lib/typescript/src/native/NativeGravixRtc.d.ts +31 -0
- package/lib/typescript/src/native/NativeGravixRtc.d.ts.map +1 -0
- package/lib/typescript/src/native/module.d.ts +7 -0
- package/lib/typescript/src/native/module.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/DOMException.d.ts +3 -0
- package/lib/typescript/src/polyfills/DOMException.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/early.d.ts +2 -0
- package/lib/typescript/src/polyfills/early.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/event.d.ts +2 -0
- package/lib/typescript/src/polyfills/event.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/sha256.d.ts +3 -0
- package/lib/typescript/src/polyfills/sha256.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/subtleHmac.d.ts +37 -0
- package/lib/typescript/src/polyfills/subtleHmac.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/textCoding.d.ts +36 -0
- package/lib/typescript/src/polyfills/textCoding.d.ts.map +1 -0
- package/lib/typescript/src/registerGlobals.d.ts +42 -0
- package/lib/typescript/src/registerGlobals.d.ts.map +1 -0
- package/lib/typescript/src/unsupported.d.ts +42 -0
- package/lib/typescript/src/unsupported.d.ts.map +1 -0
- package/lib/typescript/src/version.d.ts +3 -0
- package/lib/typescript/src/version.d.ts.map +1 -0
- package/metro/index.js +39 -0
- package/metro/noise-stub.js +10 -0
- package/native/gxfx/include/gx_fx.h +82 -0
- package/native/gxfx/src/gx_fx.cpp +527 -0
- package/native/gxfx/third_party/README.md +4 -0
- package/native/gxfx/third_party/signalsmith-linear/LICENSE.txt +21 -0
- package/native/gxfx/third_party/signalsmith-linear/approx.h +191 -0
- package/native/gxfx/third_party/signalsmith-linear/fft.h +1386 -0
- package/native/gxfx/third_party/signalsmith-linear/linear.h +1129 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/approx-cmsisdsp.h +40 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/basic-fill-warnings.h +61 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-accelerate.h +340 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-cmsisdsp.h +307 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-ipp.h +532 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-linear.h +213 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft-double.h +221 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft.h +221 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/linear-accelerate.h +593 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/linear-cmsisdsp.h +713 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd-dispatch.cpp +6 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd.h +818 -0
- package/native/gxfx/third_party/signalsmith-linear/stft.h +700 -0
- package/native/gxfx/third_party/signalsmith-stretch-LICENSE.txt +21 -0
- package/native/gxfx/third_party/signalsmith-stretch.h +1060 -0
- package/native/gxns/CMakeLists.txt +67 -0
- package/native/gxns/include/gx_ns.h +285 -0
- package/native/gxns/src/gx_ns.c +1518 -0
- package/native/gxns/src/gx_ns_timer.c +84 -0
- package/native/gxns/src/gx_ns_timer.h +29 -0
- package/native/gxns/third_party/VENDOR.md +43 -0
- package/native/gxns/third_party/rnnoise/AUTHORS +1 -0
- package/native/gxns/third_party/rnnoise/COPYING +31 -0
- package/native/gxns/third_party/rnnoise/include/rnnoise.h +117 -0
- package/native/gxns/third_party/rnnoise/src/_kiss_fft_guts.h +182 -0
- package/native/gxns/third_party/rnnoise/src/arch.h +261 -0
- package/native/gxns/third_party/rnnoise/src/celt_lpc.c +172 -0
- package/native/gxns/third_party/rnnoise/src/celt_lpc.h +45 -0
- package/native/gxns/third_party/rnnoise/src/common.h +48 -0
- package/native/gxns/third_party/rnnoise/src/denoise.c +664 -0
- package/native/gxns/third_party/rnnoise/src/kiss_fft.c +601 -0
- package/native/gxns/third_party/rnnoise/src/kiss_fft.h +203 -0
- package/native/gxns/third_party/rnnoise/src/opus_types.h +159 -0
- package/native/gxns/third_party/rnnoise/src/pitch.c +523 -0
- package/native/gxns/third_party/rnnoise/src/pitch.h +149 -0
- package/native/gxns/third_party/rnnoise/src/rnn.c +178 -0
- package/native/gxns/third_party/rnnoise/src/rnn.h +65 -0
- package/native/gxns/third_party/rnnoise/src/rnn_data.c +11051 -0
- package/native/gxns/third_party/rnnoise/src/rnn_data.h +34 -0
- package/native/gxns/third_party/rnnoise/src/tansig_table.h +45 -0
- package/native/gxns/third_party/speexdsp/AUTHORS +18 -0
- package/native/gxns/third_party/speexdsp/COPYING +35 -0
- package/native/gxns/third_party/speexdsp/arch.h +232 -0
- package/native/gxns/third_party/speexdsp/resample.c +1239 -0
- package/native/gxns/third_party/speexdsp/resample_neon.h +339 -0
- package/native/gxns/third_party/speexdsp/resample_sse.h +128 -0
- package/native/gxns/third_party/speexdsp/speex_resampler.h +343 -0
- package/package.json +186 -4
- package/src/android/bindings.ts +61 -0
- package/src/android/index.ts +10 -0
- package/src/android/micMute.ts +422 -0
- package/src/android/nativeAudio.ts +94 -0
- package/src/android/noiseSuppression.ts +209 -0
- package/src/android/roomMusic.ts +193 -0
- package/src/android/singerMode.ts +53 -0
- package/src/android/voiceEffects.ts +126 -0
- package/src/audio/AudioManager.ts +111 -0
- package/src/audio/AudioSession.ts +190 -0
- package/src/audio/remoteVolume.ts +58 -0
- package/src/components/VideoView.tsx +152 -0
- package/src/features/audioScenario.ts +58 -0
- package/src/features/beauty.ts +1057 -0
- package/src/features/micRelease.ts +108 -0
- package/src/features/noiseSuppression.ts +251 -0
- package/src/features/roomMusic.ts +106 -0
- package/src/features/roomMusicAndroid.ts +310 -0
- package/src/features/roomMusicIos.ts +300 -0
- package/src/features/roomMusicTypes.ts +97 -0
- package/src/features/screenShare.ts +19 -0
- package/src/features/singerMode.ts +70 -0
- package/src/features/voiceEffects.ts +245 -0
- package/src/hooks/context.tsx +38 -0
- package/src/hooks/hooks.ts +247 -0
- package/src/hooks/types.ts +10 -0
- package/src/hooks/useRoomEvents.ts +35 -0
- package/src/index.tsx +134 -0
- package/src/ios/autoAttach.ts +11 -0
- package/src/ios/iosAudio.ts +202 -0
- package/src/join/appStateLifecycle.ts +55 -0
- package/src/micPolicy.ts +312 -0
- package/src/native/NativeGravixAudio.ts +30 -0
- package/src/native/NativeGravixRtc.ts +38 -0
- package/src/native/module.ts +22 -0
- package/src/polyfills/DOMException.ts +20 -0
- package/src/polyfills/early.ts +16 -0
- package/src/polyfills/event.ts +88 -0
- package/src/polyfills/sha256.ts +112 -0
- package/src/polyfills/subtleHmac.ts +124 -0
- package/src/polyfills/textCoding.ts +197 -0
- package/src/registerGlobals.ts +201 -0
- package/src/unsupported.ts +139 -0
- package/src/version.ts +4 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
/** \addtogroup Global
|
|
7
|
+
* ONNX Runtime C API
|
|
8
|
+
* @{
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#ifdef __cplusplus
|
|
12
|
+
extern "C" {
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
/** \brief Error codes reported by ONNX Runtime.
|
|
16
|
+
*
|
|
17
|
+
* The error code associated with an ::OrtStatus.
|
|
18
|
+
*/
|
|
19
|
+
typedef enum OrtErrorCode {
|
|
20
|
+
/**
|
|
21
|
+
* Success. No error occurred.
|
|
22
|
+
*/
|
|
23
|
+
ORT_OK,
|
|
24
|
+
/**
|
|
25
|
+
* Generic failure that does not map to a more specific error code. Consult the error message for details.
|
|
26
|
+
*/
|
|
27
|
+
ORT_FAIL,
|
|
28
|
+
/**
|
|
29
|
+
* A caller-supplied argument was invalid (e.g. NULL pointer, out-of-range value, mismatched shape/rank, or bad
|
|
30
|
+
* configuration).
|
|
31
|
+
*/
|
|
32
|
+
ORT_INVALID_ARGUMENT,
|
|
33
|
+
/**
|
|
34
|
+
* A required file (such as a model file) does not exist.
|
|
35
|
+
*/
|
|
36
|
+
ORT_NO_SUCHFILE,
|
|
37
|
+
/**
|
|
38
|
+
* Legacy/unused but retained for ABI compatibility. Historically returned when a model could not be found by name in
|
|
39
|
+
* the ONNX Runtime Server (removed in 2022).
|
|
40
|
+
*/
|
|
41
|
+
ORT_NO_MODEL,
|
|
42
|
+
/**
|
|
43
|
+
* A hardware accelerator or backend engine reported a failure (e.g. a device crash or other device-level error).
|
|
44
|
+
*/
|
|
45
|
+
ORT_ENGINE_ERROR,
|
|
46
|
+
/**
|
|
47
|
+
* A generic runtime exception was caught. The error message is the primary source of detail.
|
|
48
|
+
*/
|
|
49
|
+
ORT_RUNTIME_EXCEPTION,
|
|
50
|
+
/**
|
|
51
|
+
* Protobuf parsing or serialization failed.
|
|
52
|
+
*/
|
|
53
|
+
ORT_INVALID_PROTOBUF,
|
|
54
|
+
/**
|
|
55
|
+
* Invalid session state for the requested operation. Despite the name, this code does not mean "success, model
|
|
56
|
+
* loaded"; it is returned when the session is in the wrong state for the requested call (e.g. a model is already
|
|
57
|
+
* loaded, the session is already initialized, or no model has been loaded yet). The name is historical and is
|
|
58
|
+
* retained for ABI compatibility; consult the error message for the specific condition.
|
|
59
|
+
*/
|
|
60
|
+
ORT_MODEL_LOADED,
|
|
61
|
+
/**
|
|
62
|
+
* The requested functionality is not implemented in this build.
|
|
63
|
+
*/
|
|
64
|
+
ORT_NOT_IMPLEMENTED,
|
|
65
|
+
/**
|
|
66
|
+
* The model graph is structurally invalid (e.g. recursive function definitions, invalid tensor dimensions, or
|
|
67
|
+
* malformed nodes).
|
|
68
|
+
*/
|
|
69
|
+
ORT_INVALID_GRAPH,
|
|
70
|
+
/**
|
|
71
|
+
* An execution provider reported a generic failure.
|
|
72
|
+
*/
|
|
73
|
+
ORT_EP_FAIL,
|
|
74
|
+
/**
|
|
75
|
+
* Model loading or session initialization was canceled at the caller's request.
|
|
76
|
+
*/
|
|
77
|
+
ORT_MODEL_LOAD_CANCELED,
|
|
78
|
+
/**
|
|
79
|
+
* The model requires compilation by an execution provider, but compilation was disabled via session options.
|
|
80
|
+
*/
|
|
81
|
+
ORT_MODEL_REQUIRES_COMPILATION,
|
|
82
|
+
/**
|
|
83
|
+
* A requested resource could not be found.
|
|
84
|
+
*/
|
|
85
|
+
ORT_NOT_FOUND,
|
|
86
|
+
/**
|
|
87
|
+
* The execution provider's hardware device has been reset.
|
|
88
|
+
*
|
|
89
|
+
* The caller should stop using the existing session (and release it) and create a new session.
|
|
90
|
+
*/
|
|
91
|
+
ORT_DEVICE_RESET,
|
|
92
|
+
} OrtErrorCode;
|
|
93
|
+
|
|
94
|
+
#ifdef __cplusplus
|
|
95
|
+
}
|
|
96
|
+
#endif
|
|
97
|
+
|
|
98
|
+
/// @}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
package com.gravitycompile.gravixrtc
|
|
4
|
+
|
|
5
|
+
import android.content.Context
|
|
6
|
+
import android.util.Log
|
|
7
|
+
import android.os.Build
|
|
8
|
+
import com.gravitycompile.gravixrtc.music.MusicMicRelease
|
|
9
|
+
import com.gravitycompile.gravixrtc.music.MusicMixerEngine
|
|
10
|
+
import com.gravitycompile.gravixrtc.processing.GxRecordStartGuard
|
|
11
|
+
import com.gravitycompile.gravixrtc.processing.GxRecorderSeam
|
|
12
|
+
import com.oney.WebRTCModule.WebRTCModuleOptions
|
|
13
|
+
import org.webrtc.audio.JavaAudioDeviceModule
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The Android audio hooks of the Gravix native features (voice effects, room
|
|
17
|
+
* music, noise suppression, mute that releases the mic), installed into
|
|
18
|
+
* react-native-webrtc by [GravixRtc.setup] BEFORE its WebRTCModule is created
|
|
19
|
+
* (it reads WebRTCModuleOptions once, in its constructor).
|
|
20
|
+
*
|
|
21
|
+
* Gravix builds the audio device module itself here:
|
|
22
|
+
* - the record-state callback attaches [GxRecorderSeam] at each recording
|
|
23
|
+
* start: room music, the capture chain (NS -> voice effect -> post-effect
|
|
24
|
+
* music), the recorder release and the capture source switch all run there
|
|
25
|
+
* (react-native-webrtc 155's WebRTC build has no buffer callback and no
|
|
26
|
+
* capture post-processing slot);
|
|
27
|
+
* - the microphone failure reporter is the recorder's error callback.
|
|
28
|
+
*
|
|
29
|
+
* Audio scenario (latched with the module, like Flutter's WebRTC.initialize):
|
|
30
|
+
* - [SCENARIO_STANDARD]: the module as GravixRtc.setup configures it;
|
|
31
|
+
* - [SCENARIO_CHAT_ROOM]: Agora ChatRoom parity (Flutter
|
|
32
|
+
* GravixAudioScenario.chatRoom): communication profile, platform AEC/NS,
|
|
33
|
+
* 16 kHz capture, 48 kHz playout.
|
|
34
|
+
*/
|
|
35
|
+
object GravixAudioHooks {
|
|
36
|
+
private const val TAG = "GravixRTC"
|
|
37
|
+
const val SCENARIO_STANDARD = "standard"
|
|
38
|
+
const val SCENARIO_CHAT_ROOM = "chatRoom"
|
|
39
|
+
|
|
40
|
+
@Volatile
|
|
41
|
+
var audioScenario: String = SCENARIO_STANDARD
|
|
42
|
+
private set
|
|
43
|
+
|
|
44
|
+
@Volatile
|
|
45
|
+
var appContext: Context? = null
|
|
46
|
+
private set
|
|
47
|
+
|
|
48
|
+
@Volatile private var installedAdm: JavaAudioDeviceModule? = null
|
|
49
|
+
|
|
50
|
+
/** Normalises a scenario name; unknown names are standard. */
|
|
51
|
+
@JvmStatic
|
|
52
|
+
fun scenarioOf(name: String?): String = if (name == SCENARIO_CHAT_ROOM) SCENARIO_CHAT_ROOM else SCENARIO_STANDARD
|
|
53
|
+
|
|
54
|
+
/** Builder settings for [scenario] and the mixer hook. Call before createAudioDeviceModule. */
|
|
55
|
+
@JvmStatic
|
|
56
|
+
fun configureBuilder(context: Context, builder: JavaAudioDeviceModule.Builder, scenario: String?): JavaAudioDeviceModule.Builder {
|
|
57
|
+
appContext = context.applicationContext
|
|
58
|
+
MusicMixerEngine.appContext = context.applicationContext
|
|
59
|
+
audioScenario = scenarioOf(scenario)
|
|
60
|
+
builder.setAudioRecordErrorCallback(GxRecordStartGuard.callback())
|
|
61
|
+
// flutter_webrtc builds its module with low-latency playout on O+ (Flutter SDK parity)
|
|
62
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) builder.setUseLowLatency(true)
|
|
63
|
+
// Recording start: the capture seam replaces WebRTC's AudioRecord (record thread, before its
|
|
64
|
+
// loop). Start / stop also run the release safety net (Flutter: handleStartLocalRecording ->
|
|
65
|
+
// restoreNow(orphanOnly)): an active release is JS's to give back (orphanOnly), and once the
|
|
66
|
+
// record thread ended a release is moot, so the next start opens the mic.
|
|
67
|
+
builder.setAudioRecordStateCallback(object : JavaAudioDeviceModule.AudioRecordStateCallback {
|
|
68
|
+
// both run on the record thread (org.jitsi:webrtc 155.0.1 WebRtcAudioRecord$AudioRecordThread)
|
|
69
|
+
override fun onWebRtcAudioRecordStart() {
|
|
70
|
+
safetyNet("record start", orphanOnly = true)
|
|
71
|
+
GxRecorderSeam.onRecordStart()
|
|
72
|
+
}
|
|
73
|
+
override fun onWebRtcAudioRecordStop() {
|
|
74
|
+
GxRecorderSeam.onRecordStop()
|
|
75
|
+
safetyNet("record stop", orphanOnly = false)
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
if (audioScenario == SCENARIO_CHAT_ROOM) {
|
|
79
|
+
builder.setUseHardwareAcousticEchoCanceler(true)
|
|
80
|
+
.setUseHardwareNoiseSuppressor(true)
|
|
81
|
+
.setInputSampleRate(16000)
|
|
82
|
+
.setOutputSampleRate(48000)
|
|
83
|
+
}
|
|
84
|
+
return builder
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private fun safetyNet(why: String, orphanOnly: Boolean) {
|
|
88
|
+
try {
|
|
89
|
+
MusicMicRelease.restoreNow(installedAdm, why, orphanOnly)
|
|
90
|
+
} catch (t: Throwable) {
|
|
91
|
+
Log.w(TAG, "[GravixAudio] recorder safety net failed ($why): $t")
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** After createAudioDeviceModule: the seam's module, and the platform noise suppressor on. */
|
|
96
|
+
@JvmStatic
|
|
97
|
+
fun onAdmCreated(adm: JavaAudioDeviceModule) {
|
|
98
|
+
installedAdm = adm
|
|
99
|
+
GxRecorderSeam.install(adm)
|
|
100
|
+
try {
|
|
101
|
+
if (JavaAudioDeviceModule.isBuiltInNoiseSuppressorSupported()) adm.setNoiseSuppressorEnabled(true)
|
|
102
|
+
} catch (t: Throwable) {
|
|
103
|
+
Log.w(TAG, "[GravixAudio] platform NS not enabled: $t")
|
|
104
|
+
}
|
|
105
|
+
Log.i(TAG, "[GravixAudio] hooks installed scenario=$audioScenario")
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A React Native reload rebuilds the module (GravixRtc.invalidate): no music session or
|
|
110
|
+
* released recorder survives into the new one.
|
|
111
|
+
*/
|
|
112
|
+
@JvmStatic
|
|
113
|
+
fun onReload() {
|
|
114
|
+
try {
|
|
115
|
+
MusicMixerEngine.stop()
|
|
116
|
+
} catch (t: Throwable) {
|
|
117
|
+
Log.w(TAG, "[GravixAudio] music stop on reload failed: $t")
|
|
118
|
+
}
|
|
119
|
+
MusicMicRelease.restoreNow(installedAdm, "reload")
|
|
120
|
+
MusicMixerEngine.captureMuted = false
|
|
121
|
+
GxRecorderSeam.reset()
|
|
122
|
+
installedAdm = null
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The audio device module the hooks were installed on (null before setup). */
|
|
126
|
+
@JvmStatic
|
|
127
|
+
fun audioDeviceModule(): JavaAudioDeviceModule? = installedAdm
|
|
128
|
+
|
|
129
|
+
/** Is our module still the one WebRTC will use (another library may replace it)? Seam state. */
|
|
130
|
+
@JvmStatic
|
|
131
|
+
fun installedState(): Map<String, Any?> {
|
|
132
|
+
val o = WebRTCModuleOptions.getInstance()
|
|
133
|
+
val adm = installedAdm
|
|
134
|
+
return mapOf(
|
|
135
|
+
"setup" to (adm != null),
|
|
136
|
+
"admInstalled" to (adm != null && o.audioDeviceModule === adm),
|
|
137
|
+
// the capture chain lives in our module's recorder seam: installed with the module
|
|
138
|
+
"processingInstalled" to (adm != null && o.audioDeviceModule === adm),
|
|
139
|
+
"processingCreated" to GxRecorderSeam.everAttached,
|
|
140
|
+
"seam" to GxRecorderSeam.state(),
|
|
141
|
+
"audioScenario" to audioScenario,
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
package com.gravitycompile.gravixrtc
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Arguments
|
|
6
|
+
import com.facebook.react.bridge.Promise
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.bridge.ReadableMap
|
|
9
|
+
import com.facebook.react.bridge.WritableMap
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* `GravixAudio` TurboModule (Android only): forwards to [GravixNativeAudio]
|
|
13
|
+
* (the Flutter SDK's method names and argument maps) and sends its events as
|
|
14
|
+
* the device event `GravixAudioEvent` = `{ name, payload }`.
|
|
15
|
+
*/
|
|
16
|
+
class GravixAudioModule(reactContext: ReactApplicationContext) : NativeGravixAudioSpec(reactContext) {
|
|
17
|
+
|
|
18
|
+
private val sink: (String, Map<String, Any?>?) -> Unit = { name, payload ->
|
|
19
|
+
val ctx = reactApplicationContext
|
|
20
|
+
if (ctx.hasActiveReactInstance()) {
|
|
21
|
+
val m = Arguments.createMap()
|
|
22
|
+
m.putString("name", name)
|
|
23
|
+
if (payload != null) m.putMap("payload", Arguments.makeNativeMap(normalize(payload))) else m.putNull("payload")
|
|
24
|
+
ctx.emitDeviceEvent(EVENT, m)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
init {
|
|
29
|
+
GravixNativeAudio.eventSink = sink
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
override fun getName(): String = NAME
|
|
33
|
+
|
|
34
|
+
override fun call(method: String, args: ReadableMap, promise: Promise) {
|
|
35
|
+
if (method == "setAudioProcessingOptions") return setAudioProcessingOptions(args.toHashMap(), promise)
|
|
36
|
+
GravixNativeAudio.call(
|
|
37
|
+
method,
|
|
38
|
+
args.toHashMap(),
|
|
39
|
+
{ value -> promise.resolve(wrap(value)) },
|
|
40
|
+
{ code, message -> promise.reject(code, message) },
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* WebRTC's own processing (AEC / NS / AGC / HPF) on a live local mic track (Flutter
|
|
46
|
+
* setAudioProcessingOptions). react-native-webrtc 155's WebRTC build (org.jitsi:webrtc
|
|
47
|
+
* 155.0.1) has no runtime per-track processing options: the call validates the track and
|
|
48
|
+
* answers `{result: false, code: "rejectedPlatformUnavailable"}`; WebRTC keeps the
|
|
49
|
+
* processing chosen when the track was captured. Callers treat it as best effort.
|
|
50
|
+
*/
|
|
51
|
+
private fun setAudioProcessingOptions(args: Map<String, Any?>, promise: Promise) {
|
|
52
|
+
args["trackId"] as? String ?: return promise.reject("INVALID_ARGUMENT", "trackId is required")
|
|
53
|
+
promise.resolve(
|
|
54
|
+
wrap(
|
|
55
|
+
mapOf(
|
|
56
|
+
"result" to false,
|
|
57
|
+
"code" to "rejectedPlatformUnavailable",
|
|
58
|
+
"message" to "runtime audio processing options are not available in this WebRTC build",
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
override fun addListener(eventName: String) = Unit
|
|
65
|
+
|
|
66
|
+
override fun removeListeners(count: Double) = Unit
|
|
67
|
+
|
|
68
|
+
override fun invalidate() {
|
|
69
|
+
// a reload may construct the new module before the old one is invalidated
|
|
70
|
+
if (GravixNativeAudio.eventSink === sink) GravixNativeAudio.eventSink = null
|
|
71
|
+
super.invalidate()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
companion object {
|
|
75
|
+
const val NAME = "GravixAudio"
|
|
76
|
+
const val EVENT = "GravixAudioEvent"
|
|
77
|
+
|
|
78
|
+
/** `{ value }`: a promise result must be a map for the generic spec. */
|
|
79
|
+
internal fun wrap(value: Any?): WritableMap {
|
|
80
|
+
val m = Arguments.createMap()
|
|
81
|
+
when (value) {
|
|
82
|
+
null, Unit -> m.putNull("value")
|
|
83
|
+
is Boolean -> m.putBoolean("value", value)
|
|
84
|
+
is Int -> m.putInt("value", value)
|
|
85
|
+
is Long -> m.putDouble("value", value.toDouble())
|
|
86
|
+
is Number -> m.putDouble("value", value.toDouble())
|
|
87
|
+
is String -> m.putString("value", value)
|
|
88
|
+
is Map<*, *> -> m.putMap("value", Arguments.makeNativeMap(normalize(value)))
|
|
89
|
+
else -> m.putString("value", value.toString())
|
|
90
|
+
}
|
|
91
|
+
return m
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** makeNativeMap takes String keys and JSON-able values; Longs become doubles. */
|
|
95
|
+
internal fun normalize(map: Map<*, *>): Map<String, Any?> = map.entries.associate { (k, v) ->
|
|
96
|
+
k.toString() to when (v) {
|
|
97
|
+
is Long -> v.toDouble()
|
|
98
|
+
is Float -> v.toDouble()
|
|
99
|
+
is Map<*, *> -> normalize(v)
|
|
100
|
+
is Unit -> null
|
|
101
|
+
else -> v
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
package com.gravitycompile.gravixrtc
|
|
4
|
+
|
|
5
|
+
import android.media.AudioManager
|
|
6
|
+
import android.os.Build
|
|
7
|
+
import android.os.Handler
|
|
8
|
+
import android.os.Looper
|
|
9
|
+
import android.util.Log
|
|
10
|
+
import com.gravitycompile.gravixrtc.music.MusicMicRelease
|
|
11
|
+
import com.gravitycompile.gravixrtc.music.MusicMixerEngine
|
|
12
|
+
import com.gravitycompile.gravixrtc.processing.GxCaptureSwitcher
|
|
13
|
+
import com.gravitycompile.gravixrtc.processing.GxNoiseProcessor
|
|
14
|
+
import com.gravitycompile.gravixrtc.processing.GxRecordStartGuard
|
|
15
|
+
import com.gravitycompile.gravixrtc.processing.GxRecorderSeam
|
|
16
|
+
import com.gravitycompile.gravixrtc.processing.GxSingerLevel
|
|
17
|
+
import com.gravitycompile.gravixrtc.processing.GxSingerSource
|
|
18
|
+
import com.gravitycompile.gravixrtc.processing.GxNsNative
|
|
19
|
+
import com.gravitycompile.gravixrtc.processing.GxVoiceFx
|
|
20
|
+
import com.gravitycompile.gravixrtc.processing.OtherAppAudioPolicy
|
|
21
|
+
import java.util.concurrent.Executors
|
|
22
|
+
import java.util.concurrent.RejectedExecutionException
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* One dispatcher for the Android-native audio features, platform-bridge
|
|
26
|
+
* agnostic: React Native calls [call] with the method name and a map (the
|
|
27
|
+
* Flutter SDK's MethodChannel method names and argument keys, so the native
|
|
28
|
+
* code and the JS side port 1:1), and gets a map / bool / null back.
|
|
29
|
+
*
|
|
30
|
+
* Methods (same names as Flutter's `gravix_client` / `.../music` channels):
|
|
31
|
+
* - capabilities
|
|
32
|
+
* - fxConfigure {effect}, fxStats, fxBenchmark {effect, rate, seconds}
|
|
33
|
+
* - nsConfigure {mode, engine, reason, agcOrder, musicBypass, autoMusic, ...},
|
|
34
|
+
* nsStats, nsGetState, nsDeviceFacts, nsBenchmark {budgetUs},
|
|
35
|
+
* nsSetSingerMode {on, source, level*}
|
|
36
|
+
* - setMicrophoneMute {mute}, setRecorderReleased {released, waitOpen, timeoutMs},
|
|
37
|
+
* recorderNativeState, recorderReleaseState, setOtherAppCaptureAction {action}
|
|
38
|
+
* - music.install, music.configure {holdOnMute, pauseOnInterruption},
|
|
39
|
+
* music.start {source, contentUri, loop, monitor, musicVolume, micVolume, ducking, duckLevel, holdOnMute, pauseOnInterruption},
|
|
40
|
+
* music.pause, music.resume, music.stop, music.seek {positionMs},
|
|
41
|
+
* music.setMusicVolume {volume}, music.setMicVolume {volume},
|
|
42
|
+
* music.setDucking {on, level}, music.setLoop {on}, music.isActive, music.getState
|
|
43
|
+
*
|
|
44
|
+
* Events ([eventSink]): onVoiceEffects, onNoiseSuppression, onMicrophoneFailure,
|
|
45
|
+
* music.onCompleted, music.onError {code, message}, music.onInterruption {active, reason, resumed}.
|
|
46
|
+
*
|
|
47
|
+
* Errors: [Failure] with the Flutter error codes (NOT_INSTALLED, CAPTURE_NOT_READY,
|
|
48
|
+
* OPEN_FAILED, MIXER_ERROR, UNKNOWN_METHOD, ...).
|
|
49
|
+
*/
|
|
50
|
+
object GravixNativeAudio {
|
|
51
|
+
private const val TAG = "GravixRTC"
|
|
52
|
+
|
|
53
|
+
class Failure(val code: String, message: String) : Exception(message)
|
|
54
|
+
|
|
55
|
+
/** (event name, payload) to JS. Called on any thread. */
|
|
56
|
+
@Volatile var eventSink: ((String, Map<String, Any?>?) -> Unit)? = null
|
|
57
|
+
|
|
58
|
+
private val main = Handler(Looper.getMainLooper())
|
|
59
|
+
private val admExecutor = Executors.newSingleThreadExecutor { r -> Thread(r, "GravixAdm").apply { isDaemon = true } }
|
|
60
|
+
private val micReleaseExecutor = Executors.newSingleThreadExecutor { r -> Thread(r, "GxMicRelease").apply { isDaemon = true } }
|
|
61
|
+
private val musicWorker = Executors.newSingleThreadExecutor { r -> Thread(r, "GxMusicControl").apply { isDaemon = true } }
|
|
62
|
+
|
|
63
|
+
private val captureSwitcher = GxCaptureSwitcher({ GravixAudioHooks.audioDeviceModule() }, { admExecutor })
|
|
64
|
+
|
|
65
|
+
init {
|
|
66
|
+
GxVoiceFx.eventSink = { m -> emit("onVoiceEffects", m) }
|
|
67
|
+
GxNoiseProcessor.eventSink = { m -> emit("onNoiseSuppression", m) }
|
|
68
|
+
GxRecordStartGuard.eventSink = { m -> emit("onMicrophoneFailure", m) }
|
|
69
|
+
MusicMixerEngine.listener = object : MusicMixerEngine.Listener {
|
|
70
|
+
override fun onCompleted() = emit("music.onCompleted", null)
|
|
71
|
+
override fun onError(code: String, message: String) = emit("music.onError", mapOf("code" to code, "message" to message))
|
|
72
|
+
override fun onInterruption(active: Boolean, reason: String, resumed: Boolean) =
|
|
73
|
+
emit("music.onInterruption", mapOf("active" to active, "reason" to reason, "resumed" to resumed))
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private fun emit(name: String, payload: Map<String, Any?>?) {
|
|
78
|
+
try {
|
|
79
|
+
eventSink?.invoke(name, payload)
|
|
80
|
+
} catch (t: Throwable) {
|
|
81
|
+
Log.w(TAG, "event $name not delivered: $t")
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Which native audio features run in this process: all of them once GravixRtc.setup
|
|
87
|
+
* built our audio device module (names = the JS `NATIVE_FEATURES` flags).
|
|
88
|
+
*/
|
|
89
|
+
fun featureFlags(): Map<String, Boolean> {
|
|
90
|
+
val ready = GravixAudioHooks.audioDeviceModule() != null
|
|
91
|
+
// the capture chain runs in our recorder seam (GxRecorderSeam), which our module's
|
|
92
|
+
// record-state callback attaches at each recording start; the engines need their library
|
|
93
|
+
// the capture chain runs in the seam: needs the Gravix ADM (attaches at the next recording
|
|
94
|
+
// start; GxRecorderSeam.everAttached / installedState report whether it did)
|
|
95
|
+
val processing = ready && GravixAudioHooks.installedState()["processingInstalled"] == true
|
|
96
|
+
return mapOf(
|
|
97
|
+
"voiceEffects" to (processing && GxVoiceFx.libraryLoaded),
|
|
98
|
+
"noiseSuppression" to (processing && GxNsNative.libraryLoaded),
|
|
99
|
+
"roomMusic" to ready,
|
|
100
|
+
"singerMode" to (processing && GxNsNative.libraryLoaded),
|
|
101
|
+
"muteReleasesMic" to ready,
|
|
102
|
+
"audioScenario" to ready,
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Diagnostics: hook state + feature flags. */
|
|
107
|
+
fun capabilities(): Map<String, Any?> = GravixAudioHooks.installedState() + featureFlags()
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Runs [method]. [done] gets the result (any thread), [fail] a code + message.
|
|
111
|
+
* Long work (benchmarks, music control, recorder release) runs off the caller's thread.
|
|
112
|
+
*/
|
|
113
|
+
@Suppress("UNCHECKED_CAST")
|
|
114
|
+
fun call(method: String, args: Map<String, Any?>, done: (Any?) -> Unit, fail: (String, String) -> Unit) {
|
|
115
|
+
try {
|
|
116
|
+
if (method.startsWith("music.")) {
|
|
117
|
+
musicWorker.execute {
|
|
118
|
+
try {
|
|
119
|
+
done(music(method.removePrefix("music."), args))
|
|
120
|
+
} catch (e: MusicMixerEngine.StartException) {
|
|
121
|
+
fail(e.code, e.message ?: e.code)
|
|
122
|
+
} catch (e: Failure) {
|
|
123
|
+
fail(e.code, e.message ?: e.code)
|
|
124
|
+
} catch (e: Throwable) {
|
|
125
|
+
Log.e(TAG, "$method failed", e)
|
|
126
|
+
fail("MIXER_ERROR", e.message ?: e.javaClass.simpleName)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
when (method) {
|
|
132
|
+
"capabilities" -> done(capabilities())
|
|
133
|
+
"fxConfigure" -> done(GxVoiceFx.configure(args))
|
|
134
|
+
"fxStats" -> done(GxVoiceFx.stats())
|
|
135
|
+
"fxBenchmark" -> GxVoiceFx.benchmark(args) { m -> done(m) }
|
|
136
|
+
"nsDeviceFacts" -> done(GxNoiseProcessor.deviceFacts(GravixAudioHooks.appContext))
|
|
137
|
+
"nsConfigure" -> done(GxNoiseProcessor.configure(GravixAudioHooks.appContext, args))
|
|
138
|
+
"nsBenchmark" -> GxNoiseProcessor.benchmark(GravixAudioHooks.appContext, (args["budgetUs"] as? Number)?.toInt() ?: 3000) { m -> done(m) }
|
|
139
|
+
"nsStats", "nsGetState" -> done(GxNoiseProcessor.stats())
|
|
140
|
+
"nsSetSingerMode" -> done(setSingerMode(args))
|
|
141
|
+
"setMicrophoneMute" -> done(setMicrophoneMute(args["mute"] as? Boolean ?: false))
|
|
142
|
+
"setRecorderReleased" -> setRecorderReleased(args, done)
|
|
143
|
+
"recorderNativeState" -> done(recorderNativeState())
|
|
144
|
+
"setCaptureClosed" -> done(setCaptureClosed(args["closed"] as? Boolean ?: false))
|
|
145
|
+
"recorderReleaseState" -> done(MusicMicRelease.state(GravixAudioHooks.audioDeviceModule()))
|
|
146
|
+
"setOtherAppCaptureAction" -> {
|
|
147
|
+
captureSwitcher.apply(OtherAppAudioPolicy.Action.parse(args["action"] as? String))
|
|
148
|
+
done(null)
|
|
149
|
+
}
|
|
150
|
+
else -> fail("UNKNOWN_METHOD", "unknown method $method")
|
|
151
|
+
}
|
|
152
|
+
} catch (e: Failure) {
|
|
153
|
+
fail(e.code, e.message ?: e.code)
|
|
154
|
+
} catch (e: RejectedExecutionException) {
|
|
155
|
+
fail("UNAVAILABLE", "worker unavailable")
|
|
156
|
+
} catch (e: Throwable) {
|
|
157
|
+
Log.e(TAG, "$method failed", e)
|
|
158
|
+
fail("NATIVE_ERROR", "${e.javaClass.simpleName}: ${e.message}")
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ---- singer mode (Flutter nsSetSingerMode) ----
|
|
163
|
+
|
|
164
|
+
private fun setSingerMode(args: Map<String, Any?>): Map<String, Any?> {
|
|
165
|
+
val on = args["on"] as? Boolean ?: false
|
|
166
|
+
val unprocessed = Build.VERSION.SDK_INT >= 24 && try {
|
|
167
|
+
(GravixAudioHooks.appContext?.getSystemService(android.content.Context.AUDIO_SERVICE) as? AudioManager)
|
|
168
|
+
?.getProperty(AudioManager.PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED) == "true"
|
|
169
|
+
} catch (_: Throwable) {
|
|
170
|
+
false
|
|
171
|
+
}
|
|
172
|
+
val source = if (on) GxSingerSource.resolve(args["source"] as? String, Build.VERSION.SDK_INT, unprocessed) else null
|
|
173
|
+
GxNoiseProcessor.setSingerMode(on, source, GxSingerLevel.of(args))
|
|
174
|
+
captureSwitcher.setSingerSource(source)
|
|
175
|
+
return mapOf("ok" to true, "sourceRequested" to source, "unprocessedSupported" to unprocessed)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ---- mute (Flutter handleSetMicrophoneMute / handleSetRecorderReleased) ----
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The module mute: PCM zeroed in the recorder, recorder left running. False when
|
|
182
|
+
* setup never ran (no module): the JS side then mutes the plain way.
|
|
183
|
+
*/
|
|
184
|
+
fun setMicrophoneMute(mute: Boolean): Boolean {
|
|
185
|
+
val adm = GravixAudioHooks.audioDeviceModule() ?: return false
|
|
186
|
+
// flag first on mute, last on unmute: no window where a held mixer runs
|
|
187
|
+
if (mute) MusicMixerEngine.captureMuted = true
|
|
188
|
+
// safety net (0.12.2): a released recorder never outlives the module mute
|
|
189
|
+
if (!mute) MusicMicRelease.restoreNow(adm, "module unmute")
|
|
190
|
+
captureSwitcher.setUserMute(mute)
|
|
191
|
+
if (!mute) MusicMixerEngine.captureMuted = false
|
|
192
|
+
return true
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private fun setRecorderReleased(args: Map<String, Any?>, done: (Any?) -> Unit) {
|
|
196
|
+
val adm = GravixAudioHooks.audioDeviceModule()
|
|
197
|
+
val released = args["released"] as? Boolean ?: false
|
|
198
|
+
val waitOpen = args["waitOpen"] as? Boolean ?: false
|
|
199
|
+
val timeoutMs = (args["timeoutMs"] as? Number)?.toLong() ?: 1500L
|
|
200
|
+
micReleaseExecutor.execute {
|
|
201
|
+
val ok = try {
|
|
202
|
+
if (released) MusicMicRelease.release(adm) else MusicMicRelease.restore(adm, waitOpen, timeoutMs)
|
|
203
|
+
} catch (t: Throwable) {
|
|
204
|
+
Log.w(TAG, "setRecorderReleased($released) failed", t)
|
|
205
|
+
false
|
|
206
|
+
}
|
|
207
|
+
done(ok)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Mute releases the mic (stock WebRTC keeps recording under a track mute): while
|
|
213
|
+
* [closed] the seam stops the hardware recorder and clocks silence, so the OS mic
|
|
214
|
+
* indicator goes off; false reopens it. False when the seam is not attached
|
|
215
|
+
* (no setup or no recording yet): the flag still applies at the next start.
|
|
216
|
+
*/
|
|
217
|
+
fun setCaptureClosed(closed: Boolean): Map<String, Any?> {
|
|
218
|
+
GxRecorderSeam.closedByMute = closed
|
|
219
|
+
return mapOf("ok" to (GxRecorderSeam.current != null), "closed" to closed)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* WebRTC's recorder state, read through the capture seam (org.jitsi:webrtc 155.0.1).
|
|
224
|
+
* `nativeStart` / `clientStart` = the record thread runs (stock WebRTC has no separate
|
|
225
|
+
* start flags); `recording` = the hardware recorder captures. Null without setup.
|
|
226
|
+
*/
|
|
227
|
+
fun recorderNativeState(): Map<String, Boolean>? {
|
|
228
|
+
if (GravixAudioHooks.audioDeviceModule() == null) return null
|
|
229
|
+
val thread = GxRecorderSeam.threadAlive()
|
|
230
|
+
return mapOf(
|
|
231
|
+
"nativeStart" to thread,
|
|
232
|
+
"clientStart" to thread,
|
|
233
|
+
"thread" to thread,
|
|
234
|
+
"recording" to GxRecorderSeam.recorderOpen(),
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ---- room music (Flutter MusicMixerPlugin), on the music worker ----
|
|
239
|
+
|
|
240
|
+
private fun num(args: Map<String, Any?>, key: String): Float? = (args[key] as? Number)?.toFloat()
|
|
241
|
+
|
|
242
|
+
private fun applyConfig(args: Map<String, Any?>) {
|
|
243
|
+
(args["holdOnMute"] as? Boolean)?.let { MusicMixerEngine.holdOnMute = it }
|
|
244
|
+
(args["pauseOnInterruption"] as? Boolean)?.let { MusicMixerEngine.pauseOnInterruption = it }
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private fun music(method: String, args: Map<String, Any?>): Any? {
|
|
248
|
+
val e = MusicMixerEngine
|
|
249
|
+
return when (method) {
|
|
250
|
+
// the mixer is the recorder's callback from GravixRtc.setup on: "installed" = setup ran
|
|
251
|
+
"install" -> GravixAudioHooks.audioDeviceModule() != null
|
|
252
|
+
"configure" -> { applyConfig(args); null }
|
|
253
|
+
"start" -> {
|
|
254
|
+
val source = args["source"] as? String ?: args["path"] as? String
|
|
255
|
+
if (source.isNullOrEmpty()) throw Failure("OPEN_FAILED", "no source")
|
|
256
|
+
if (GravixAudioHooks.audioDeviceModule() == null) {
|
|
257
|
+
throw Failure("NOT_INSTALLED", "GravixRtc.setup was not called in Application.onCreate")
|
|
258
|
+
}
|
|
259
|
+
applyConfig(args)
|
|
260
|
+
e.kernel.musicGain = num(args, "musicVolume") ?: num(args, "gain") ?: 1f
|
|
261
|
+
e.kernel.micGain = num(args, "micVolume") ?: 1f
|
|
262
|
+
(args["ducking"] as? Boolean)?.let { e.kernel.ducking = it }
|
|
263
|
+
num(args, "duckLevel")?.let { e.kernel.duckLevel = it }
|
|
264
|
+
val dur = e.start(
|
|
265
|
+
source,
|
|
266
|
+
args["contentUri"] as? Boolean ?: source.startsWith("content://"),
|
|
267
|
+
args["loop"] as? Boolean ?: false,
|
|
268
|
+
args["monitor"] as? Boolean ?: true,
|
|
269
|
+
)
|
|
270
|
+
mapOf("durationMs" to dur)
|
|
271
|
+
}
|
|
272
|
+
"pause" -> { e.pause(); null }
|
|
273
|
+
"resume" -> { e.resume(); null }
|
|
274
|
+
"stop" -> { e.stop(); null }
|
|
275
|
+
"seek", "seekTo" -> { e.seekTo((args["positionMs"] as? Number)?.toLong() ?: 0L); null }
|
|
276
|
+
"setMusicVolume", "setVolume" -> { e.kernel.musicGain = num(args, "volume") ?: num(args, "gain") ?: 1f; null }
|
|
277
|
+
"setMicVolume" -> { e.kernel.micGain = num(args, "volume") ?: 1f; null }
|
|
278
|
+
"setDucking" -> {
|
|
279
|
+
e.kernel.ducking = args["on"] as? Boolean ?: false
|
|
280
|
+
num(args, "level")?.let { e.kernel.duckLevel = it }
|
|
281
|
+
null
|
|
282
|
+
}
|
|
283
|
+
"setLoop" -> { e.setLoop(args["on"] as? Boolean ?: false); null }
|
|
284
|
+
"isActive" -> e.isActive()
|
|
285
|
+
"getState" -> mapOf(
|
|
286
|
+
"active" to e.isActive(),
|
|
287
|
+
"paused" to e.isPaused(),
|
|
288
|
+
"interrupted" to e.interruptedReason(),
|
|
289
|
+
"positionMs" to e.positionMs(),
|
|
290
|
+
"positionAgeUs" to e.positionAgeUs(),
|
|
291
|
+
"outputDelayMs" to e.outputDelayMs(),
|
|
292
|
+
"durationMs" to e.durationMs(),
|
|
293
|
+
"captureReady" to e.captureSeen,
|
|
294
|
+
"captureLive" to e.captureLive(),
|
|
295
|
+
"captureSampleRate" to e.captureSampleRate,
|
|
296
|
+
"captureChannels" to e.captureChannels,
|
|
297
|
+
"installed" to (GravixAudioHooks.audioDeviceModule() != null),
|
|
298
|
+
"mixRoute" to e.router.route.name.lowercase(),
|
|
299
|
+
"mixSwitches" to e.router.switches,
|
|
300
|
+
"mixDropped" to e.router.droppedTokens,
|
|
301
|
+
"mixCaptureGaps" to e.router.captureGaps,
|
|
302
|
+
"mixDelaySamples" to e.router.delaySamples,
|
|
303
|
+
"mixRetimes" to e.router.retimes,
|
|
304
|
+
"micReleased" to MusicMicRelease.released,
|
|
305
|
+
"silentFrames" to e.silentFrames,
|
|
306
|
+
)
|
|
307
|
+
else -> throw Failure("UNKNOWN_METHOD", "unknown method music.$method")
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|