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,137 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
package com.gravitycompile.gravixrtc.processing
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Pure decisions behind the microphone/route work of 0.4.15 (field report
|
|
7
|
+
* 2026-10-10, items 7b/7c/7d). Framework constants are literals so the JVM
|
|
8
|
+
* unit tests need no Android stubs (same reason as [CallServiceTypes]).
|
|
9
|
+
*/
|
|
10
|
+
internal object AudioRoutePolicy {
|
|
11
|
+
// route names shared with Dart (GravixAudioRoute)
|
|
12
|
+
const val SPEAKER = "speaker"
|
|
13
|
+
const val EARPIECE = "earpiece"
|
|
14
|
+
const val WIRED = "wiredHeadset"
|
|
15
|
+
const val BLUETOOTH = "bluetooth"
|
|
16
|
+
const val USB = "usb"
|
|
17
|
+
const val UNKNOWN = "unknown"
|
|
18
|
+
|
|
19
|
+
/** Dart's setEnableSpeakerphone(false): automatic, but earpiece over loudspeaker. */
|
|
20
|
+
const val SPEAKER_OFF = "speakerOff"
|
|
21
|
+
|
|
22
|
+
// AudioManager.MODE_*
|
|
23
|
+
const val MODE_NORMAL = 0
|
|
24
|
+
const val MODE_RINGTONE = 1
|
|
25
|
+
const val MODE_IN_CALL = 2
|
|
26
|
+
const val MODE_IN_COMMUNICATION = 3
|
|
27
|
+
const val MODE_CALL_SCREENING = 4
|
|
28
|
+
|
|
29
|
+
// AudioManager.AUDIOFOCUS_*
|
|
30
|
+
const val FOCUS_GAIN = 1
|
|
31
|
+
const val FOCUS_LOSS = -1
|
|
32
|
+
const val FOCUS_LOSS_TRANSIENT = -2
|
|
33
|
+
const val FOCUS_LOSS_TRANSIENT_CAN_DUCK = -3
|
|
34
|
+
|
|
35
|
+
/** AudioDeviceInfo.TYPE_* -> route name; null for inputs and internal devices. */
|
|
36
|
+
fun routeOfDeviceType(type: Int): String? = when (type) {
|
|
37
|
+
2, 24 -> SPEAKER // BUILTIN_SPEAKER, BUILTIN_SPEAKER_SAFE
|
|
38
|
+
1 -> EARPIECE // BUILTIN_EARPIECE
|
|
39
|
+
3, 4 -> WIRED // WIRED_HEADSET, WIRED_HEADPHONES
|
|
40
|
+
7, 8, 23, 26, 27, 30 -> BLUETOOTH // SCO, A2DP, HEARING_AID, BLE_HEADSET, BLE_SPEAKER, BLE_BROADCAST
|
|
41
|
+
11, 12, 22 -> USB // USB_DEVICE, USB_ACCESSORY, USB_HEADSET
|
|
42
|
+
5, 6, 9, 10, 13, 19, 29, 31 -> UNKNOWN // line, HDMI, dock, aux
|
|
43
|
+
else -> null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fun focusName(change: Int): String = when (change) {
|
|
47
|
+
FOCUS_GAIN, 2, 3, 4 -> "gain"
|
|
48
|
+
FOCUS_LOSS -> "loss"
|
|
49
|
+
FOCUS_LOSS_TRANSIENT -> "lossTransient"
|
|
50
|
+
FOCUS_LOSS_TRANSIENT_CAN_DUCK -> "lossTransientCanDuck"
|
|
51
|
+
else -> "unknown"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A cellular call holds the audio mode (RINGTONE is only ringing: the
|
|
56
|
+
* microphone is not taken yet).
|
|
57
|
+
*/
|
|
58
|
+
fun isPhoneCallMode(mode: Int): Boolean = mode == MODE_IN_CALL || mode == MODE_CALL_SCREENING
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The Bluetooth "chatroom" model (7b): the session mode to run in.
|
|
62
|
+
*
|
|
63
|
+
* Only a media-mode app (base MODE_NORMAL) is switched, only while the
|
|
64
|
+
* option is on, the local microphone is published and unmuted, and a
|
|
65
|
+
* Bluetooth headset with a microphone (HFP/SCO, a communication device) is
|
|
66
|
+
* connected. Everything else keeps the configured mode.
|
|
67
|
+
*/
|
|
68
|
+
fun chatroomMode(enabled: Boolean, micActive: Boolean, bluetoothHeadset: Boolean, baseMode: Int): Int =
|
|
69
|
+
if (enabled && micActive && bluetoothHeadset && baseMode == MODE_NORMAL) MODE_IN_COMMUNICATION else baseMode
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Preferred-route order for an explicit selection (7d), most wanted first.
|
|
73
|
+
* Null = no explicit selection (the speaker preference decides). A route that
|
|
74
|
+
* goes away falls to the next one, so a Bluetooth selection ends with the
|
|
75
|
+
* headset instead of sticking.
|
|
76
|
+
*/
|
|
77
|
+
fun explicitOrder(route: String?): List<String>? = when (route) {
|
|
78
|
+
null -> null
|
|
79
|
+
SPEAKER -> listOf(SPEAKER, BLUETOOTH, WIRED, EARPIECE)
|
|
80
|
+
EARPIECE -> listOf(EARPIECE, BLUETOOTH, WIRED, SPEAKER)
|
|
81
|
+
WIRED, USB -> listOf(WIRED, BLUETOOTH, SPEAKER, EARPIECE)
|
|
82
|
+
BLUETOOTH -> listOf(BLUETOOTH, WIRED, SPEAKER, EARPIECE)
|
|
83
|
+
SPEAKER_OFF -> listOf(BLUETOOTH, WIRED, EARPIECE, SPEAKER)
|
|
84
|
+
else -> null
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Whether a [route] selection counts as applied, given the route now in use
|
|
89
|
+
* ([current]) and whether the session routes at all ([routingHandled]: false
|
|
90
|
+
* in MODE_NORMAL, where Android routes media itself).
|
|
91
|
+
*/
|
|
92
|
+
fun selectionApplied(route: String?, current: String?, routingHandled: Boolean): Boolean {
|
|
93
|
+
if (route == null) return true
|
|
94
|
+
if (!routingHandled) {
|
|
95
|
+
// MODE_NORMAL: nothing is selected, but asking for the route media
|
|
96
|
+
// already plays on is a no-op success (device run D3, 2026-10-10);
|
|
97
|
+
// speakerphone off holds while a headset carries the media
|
|
98
|
+
return if (route == SPEAKER_OFF) current == BLUETOOTH || current == WIRED || current == USB else current == route
|
|
99
|
+
}
|
|
100
|
+
// speakerphone off holds only when the session is on a route other than
|
|
101
|
+
// the loudspeaker (2026-10-11, route API nit: it answered applied=true even
|
|
102
|
+
// when no earpiece or headset existed and the speaker stayed in use)
|
|
103
|
+
if (route == SPEAKER_OFF) return current != null && current != SPEAKER && current != UNKNOWN
|
|
104
|
+
val asked = if (route == USB) WIRED else route
|
|
105
|
+
return current == asked
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The current route to report: never one outside [available]. Phone run
|
|
110
|
+
* 2026-10-10 (Infinix, SpaceBuds): on a headset disconnect the media routing
|
|
111
|
+
* still answered "earpiece" for 0.9 s while only the speaker was available.
|
|
112
|
+
* An answer outside the list falls back to [fallback] (the output-device
|
|
113
|
+
* heuristic) when that is available, else the first available route; unknown
|
|
114
|
+
* stays unknown.
|
|
115
|
+
*/
|
|
116
|
+
fun consistentCurrent(current: String, available: List<String>, fallback: String): String = when {
|
|
117
|
+
current == UNKNOWN || current in available -> current
|
|
118
|
+
fallback in available -> fallback
|
|
119
|
+
else -> available.firstOrNull() ?: UNKNOWN
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Where media plays in MODE_NORMAL when the platform cannot say (below API
|
|
124
|
+
* 33): Android sends media to the most recently connected external output;
|
|
125
|
+
* this approximates it with a fixed priority over the connected outputs.
|
|
126
|
+
*/
|
|
127
|
+
fun mediaRouteOf(outputTypes: Collection<Int>): String {
|
|
128
|
+
val routes = outputTypes.mapNotNull(::routeOfDeviceType).toSet()
|
|
129
|
+
return when {
|
|
130
|
+
// A2DP (8) / LE (26, 27) carry media; an SCO-only (7) headset does not in MODE_NORMAL
|
|
131
|
+
outputTypes.any { it == 8 || it == 26 || it == 27 || it == 23 } -> BLUETOOTH
|
|
132
|
+
WIRED in routes -> WIRED
|
|
133
|
+
USB in routes -> USB
|
|
134
|
+
else -> SPEAKER
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GravixCaptureProcessing.kt
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Port of flutter_webrtc's AudioProcessingAdapter / AudioProcessingController
|
|
2
|
+
// (Copyright 2024 flutter-webrtc authors, MIT License).
|
|
3
|
+
// Modifications Copyright 2026 Gravity Compile. MIT License; see LICENSE.
|
|
4
|
+
|
|
5
|
+
package com.gravitycompile.gravixrtc.processing
|
|
6
|
+
|
|
7
|
+
import java.nio.ByteBuffer
|
|
8
|
+
import java.util.concurrent.CopyOnWriteArrayList
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The Gravix capture processing chain, the Flutter SDK's
|
|
12
|
+
* `AudioProcessingController.capturePostProcessing` slot.
|
|
13
|
+
*
|
|
14
|
+
* react-native-webrtc 155's WebRTC build has no capture post-processing slot,
|
|
15
|
+
* so [GxRecorderSeam] feeds this chain from the recorder: each 10 ms frame as
|
|
16
|
+
* int16-scale floats (one band), before WebRTC's own audio processing.
|
|
17
|
+
*
|
|
18
|
+
* [processors] are called in order on WebRTC's record thread (the Gravix chain
|
|
19
|
+
* is one processor: [GxNoiseProcessor], which runs NS -> voice effect -> post-
|
|
20
|
+
* effect room music). The list is copy-on-write: process() never locks, never
|
|
21
|
+
* allocates.
|
|
22
|
+
*/
|
|
23
|
+
object GravixCaptureProcessing {
|
|
24
|
+
interface Processor {
|
|
25
|
+
fun initialize(sampleRateHz: Int, numChannels: Int)
|
|
26
|
+
fun reset(newRate: Int)
|
|
27
|
+
fun process(numBands: Int, numFrames: Int, buffer: ByteBuffer)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private val processors = CopyOnWriteArrayList<Processor>()
|
|
31
|
+
|
|
32
|
+
@Volatile private var lastRate = 0
|
|
33
|
+
@Volatile private var lastChannels = 0
|
|
34
|
+
|
|
35
|
+
fun hasProcessors(): Boolean = processors.isNotEmpty()
|
|
36
|
+
|
|
37
|
+
/** Adds [p] once. A processor added after initialize() gets the last known format. */
|
|
38
|
+
@Synchronized
|
|
39
|
+
fun add(p: Processor): Boolean {
|
|
40
|
+
if (processors.contains(p)) return true
|
|
41
|
+
processors.add(p)
|
|
42
|
+
if (lastRate > 0) p.initialize(lastRate, lastChannels)
|
|
43
|
+
return true
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Synchronized
|
|
47
|
+
fun remove(p: Processor) {
|
|
48
|
+
processors.remove(p)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fun contains(p: Processor): Boolean = processors.contains(p)
|
|
52
|
+
|
|
53
|
+
fun initialize(sampleRateHz: Int, numChannels: Int) {
|
|
54
|
+
lastRate = sampleRateHz
|
|
55
|
+
lastChannels = numChannels
|
|
56
|
+
for (p in processors) p.initialize(sampleRateHz, numChannels)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fun reset(newRate: Int) {
|
|
60
|
+
lastRate = newRate
|
|
61
|
+
for (p in processors) p.reset(newRate)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fun process(numBands: Int, numFrames: Int, buffer: ByteBuffer) {
|
|
65
|
+
for (p in processors) p.process(numBands, numFrames, buffer)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
package com.gravitycompile.gravixrtc.processing
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import java.io.File
|
|
6
|
+
import java.io.RandomAccessFile
|
|
7
|
+
import java.nio.ByteBuffer
|
|
8
|
+
import java.nio.ByteOrder
|
|
9
|
+
import java.util.concurrent.ArrayBlockingQueue
|
|
10
|
+
import java.util.concurrent.TimeUnit
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Diagnostic (2026-10-22, the gift-echo measurements): records the capture the SFU
|
|
14
|
+
* receives, as two mono 16-bit WAVs per capture: `pre` = what reaches
|
|
15
|
+
* GxNoiseProcessor (after WebRTC's APM: AEC, high-pass; WebRTC NS is off while
|
|
16
|
+
* ours runs) and `post` = after Gravix NS / AGC (what is encoded).
|
|
17
|
+
*
|
|
18
|
+
* Off unless `adb shell setprop debug.gravix.capdump 1` before the capture
|
|
19
|
+
* starts. Files: <external files>/gxdump/cap-<time>-{pre,post}.wav. The audio
|
|
20
|
+
* thread only copies into a pooled array; a writer thread does the I/O.
|
|
21
|
+
*/
|
|
22
|
+
internal object GxCaptureDump {
|
|
23
|
+
private const val TAG = "GravixNS"
|
|
24
|
+
private const val MAX_FRAMES = 480
|
|
25
|
+
private const val MAX_SECONDS = 300
|
|
26
|
+
|
|
27
|
+
private class Block(val pre: FloatArray = FloatArray(MAX_FRAMES), val post: FloatArray = FloatArray(MAX_FRAMES)) {
|
|
28
|
+
var n = 0
|
|
29
|
+
var hasPost = false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private val pool = ArrayBlockingQueue<Block>(400)
|
|
33
|
+
private val queue = ArrayBlockingQueue<Block>(400)
|
|
34
|
+
@Volatile private var active = false
|
|
35
|
+
@Volatile private var pending: Block? = null
|
|
36
|
+
@Volatile private var dropped = 0
|
|
37
|
+
private var writer: Thread? = null
|
|
38
|
+
|
|
39
|
+
/** True when the property is set (checked at each capture start). */
|
|
40
|
+
fun enabled(): Boolean = try {
|
|
41
|
+
val c = Class.forName("android.os.SystemProperties")
|
|
42
|
+
(c.getMethod("get", String::class.java).invoke(null, "debug.gravix.capdump") as String) == "1"
|
|
43
|
+
} catch (t: Throwable) {
|
|
44
|
+
false
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Synchronized
|
|
48
|
+
fun start(ctx: Context?, rate: Int) {
|
|
49
|
+
if (active || ctx == null || rate <= 0 || !enabled()) return
|
|
50
|
+
val dir = File(ctx.getExternalFilesDir(null), "gxdump").apply { mkdirs() }
|
|
51
|
+
val stamp = java.text.SimpleDateFormat("HHmmss", java.util.Locale.US).format(java.util.Date())
|
|
52
|
+
val pre = File(dir, "cap-$stamp-pre.wav")
|
|
53
|
+
val post = File(dir, "cap-$stamp-post.wav")
|
|
54
|
+
if (pool.isEmpty()) repeat(400) { pool.offer(Block()) }
|
|
55
|
+
queue.clear()
|
|
56
|
+
dropped = 0
|
|
57
|
+
active = true
|
|
58
|
+
writer = Thread({ writeLoop(pre, post, rate) }, "GravixCapDump").apply { start() }
|
|
59
|
+
Log.i(TAG, "[GravixNS] capdump start rate=$rate pre=${pre.absolutePath}")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Audio thread, before NS. */
|
|
63
|
+
fun onPre(buffer: ByteBuffer, numFrames: Int) {
|
|
64
|
+
if (!active || numFrames > MAX_FRAMES) return
|
|
65
|
+
val b = pool.poll() ?: run { dropped++; return }
|
|
66
|
+
val f = buffer.duplicate().order(ByteOrder.nativeOrder())
|
|
67
|
+
for (i in 0 until numFrames) b.pre[i] = f.getFloat(i * 4)
|
|
68
|
+
b.n = numFrames
|
|
69
|
+
b.hasPost = false
|
|
70
|
+
pending = b
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Audio thread, after NS (or right after [onPre] when NS did not run). */
|
|
74
|
+
fun onPost(buffer: ByteBuffer, numFrames: Int, processed: Boolean) {
|
|
75
|
+
val b = pending ?: return
|
|
76
|
+
pending = null
|
|
77
|
+
if (processed) {
|
|
78
|
+
val f = buffer.duplicate().order(ByteOrder.nativeOrder())
|
|
79
|
+
for (i in 0 until numFrames) b.post[i] = f.getFloat(i * 4)
|
|
80
|
+
} else {
|
|
81
|
+
System.arraycopy(b.pre, 0, b.post, 0, numFrames)
|
|
82
|
+
}
|
|
83
|
+
b.hasPost = true
|
|
84
|
+
if (!queue.offer(b)) { dropped++; pool.offer(b) }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private fun writeLoop(pre: File, post: File, rate: Int) {
|
|
88
|
+
val maxSamples = rate.toLong() * MAX_SECONDS
|
|
89
|
+
var samples = 0L
|
|
90
|
+
try {
|
|
91
|
+
RandomAccessFile(pre, "rw").use { a ->
|
|
92
|
+
RandomAccessFile(post, "rw").use { b ->
|
|
93
|
+
a.setLength(0); b.setLength(0)
|
|
94
|
+
a.write(header(rate, 0)); b.write(header(rate, 0))
|
|
95
|
+
val bytes = ByteArray(MAX_FRAMES * 2)
|
|
96
|
+
while (active && samples < maxSamples) {
|
|
97
|
+
val blk = queue.poll(200, TimeUnit.MILLISECONDS) ?: continue
|
|
98
|
+
a.write(bytes, 0, pcm(blk.pre, blk.n, bytes))
|
|
99
|
+
b.write(bytes, 0, pcm(blk.post, blk.n, bytes))
|
|
100
|
+
samples += blk.n
|
|
101
|
+
pool.offer(blk)
|
|
102
|
+
if (samples % rate < blk.n) {
|
|
103
|
+
// keep the header valid while recording (the app may be killed)
|
|
104
|
+
patch(a, rate, samples); patch(b, rate, samples)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
patch(a, rate, samples); patch(b, rate, samples)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
Log.i(TAG, "[GravixNS] capdump end seconds=${samples / rate} dropped=$dropped")
|
|
111
|
+
} catch (t: Throwable) {
|
|
112
|
+
Log.w(TAG, "[GravixNS] capdump failed: $t")
|
|
113
|
+
} finally {
|
|
114
|
+
active = false
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private fun pcm(src: FloatArray, n: Int, out: ByteArray): Int {
|
|
119
|
+
for (i in 0 until n) {
|
|
120
|
+
val v = src[i].toInt().coerceIn(-32768, 32767)
|
|
121
|
+
out[2 * i] = (v and 0xff).toByte()
|
|
122
|
+
out[2 * i + 1] = ((v shr 8) and 0xff).toByte()
|
|
123
|
+
}
|
|
124
|
+
return n * 2
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private fun patch(f: RandomAccessFile, rate: Int, samples: Long) {
|
|
128
|
+
val pos = f.filePointer
|
|
129
|
+
f.seek(0)
|
|
130
|
+
f.write(header(rate, samples))
|
|
131
|
+
f.seek(pos)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private fun header(rate: Int, samples: Long): ByteArray {
|
|
135
|
+
val data = (samples * 2).toInt()
|
|
136
|
+
return ByteBuffer.allocate(44).order(ByteOrder.LITTLE_ENDIAN).apply {
|
|
137
|
+
put("RIFF".toByteArray()); putInt(36 + data); put("WAVE".toByteArray())
|
|
138
|
+
put("fmt ".toByteArray()); putInt(16); putShort(1); putShort(1); putInt(rate); putInt(rate * 2)
|
|
139
|
+
putShort(2); putShort(16)
|
|
140
|
+
put("data".toByteArray()); putInt(data)
|
|
141
|
+
}.array()
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
package com.gravitycompile.gravixrtc.processing
|
|
4
|
+
|
|
5
|
+
import android.media.AudioRecord
|
|
6
|
+
import android.media.MediaRecorder
|
|
7
|
+
import android.media.audiofx.AcousticEchoCanceler
|
|
8
|
+
import android.media.audiofx.AudioEffect
|
|
9
|
+
import android.media.audiofx.NoiseSuppressor
|
|
10
|
+
import android.os.Handler
|
|
11
|
+
import android.os.Looper
|
|
12
|
+
import android.util.Log
|
|
13
|
+
import org.webrtc.audio.JavaAudioDeviceModule
|
|
14
|
+
import java.util.concurrent.ExecutorService
|
|
15
|
+
import java.util.concurrent.RejectedExecutionException
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Applies the other-app capture action Dart decides (owner report 2026-10-10:
|
|
19
|
+
* YouTube / a game on the phone is heard by the room). Every action is undone
|
|
20
|
+
* by [OtherAppAudioPolicy.Action.NONE], which puts the capture back exactly as
|
|
21
|
+
* WebRTC built it.
|
|
22
|
+
*
|
|
23
|
+
* - PLATFORM_EFFECTS: android.media.audiofx AcousticEchoCanceler +
|
|
24
|
+
* NoiseSuppressor attached to WebRTC's running AudioRecord session. With the
|
|
25
|
+
* media profile (bypassVoiceProcessing) WebRTC never enables them itself:
|
|
26
|
+
* its builder says "no hardware AEC/NS", and `isAcousticEchoCancelerSupported`
|
|
27
|
+
* is a final field set from that. Whether the platform AEC hears other
|
|
28
|
+
* apps' output (its reference) is per phone: measured, not assumed.
|
|
29
|
+
* - VOICE_COMMUNICATION: the recorder re-opened with the VOICE_COMMUNICATION
|
|
30
|
+
* source (+ the effects above), the source a call app records from. The
|
|
31
|
+
* capture seam ([GxRecorderSeam]) owns the AudioRecord WebRTC reads, so the
|
|
32
|
+
* switch is a new AudioRecord on the new source, swapped in by the record
|
|
33
|
+
* thread between two reads. A refused open stays on the current source.
|
|
34
|
+
* - MUTE: the engine's microphone mute, combined with the user's own mute
|
|
35
|
+
* ([OtherAppAudioPolicy.engineMute]) so neither undoes the other.
|
|
36
|
+
* - singer mode ([setSingerSource], 2026-11-20): the recorder re-opened with
|
|
37
|
+
* the source singer mode asks for (MIC by default, see [GxSingerSource]),
|
|
38
|
+
* the same seam switch. It wins over the VOICE_COMMUNICATION and
|
|
39
|
+
* PLATFORM_EFFECTS actions (both would put the voice processing back that
|
|
40
|
+
* singer mode takes out); MUTE still applies. Off: back to the source the
|
|
41
|
+
* other-app action wants (the original one for NONE).
|
|
42
|
+
*
|
|
43
|
+
* All recorder work runs on [executor] (the plugin's audio device module
|
|
44
|
+
* thread), never on the main thread.
|
|
45
|
+
*/
|
|
46
|
+
internal class GxCaptureSwitcher(
|
|
47
|
+
private val adm: () -> JavaAudioDeviceModule?,
|
|
48
|
+
private val executor: () -> ExecutorService?,
|
|
49
|
+
) {
|
|
50
|
+
@Volatile
|
|
51
|
+
var userMuted = false
|
|
52
|
+
private set
|
|
53
|
+
|
|
54
|
+
@Volatile
|
|
55
|
+
private var autoMuted = false
|
|
56
|
+
|
|
57
|
+
@Volatile
|
|
58
|
+
private var action = OtherAppAudioPolicy.Action.NONE
|
|
59
|
+
|
|
60
|
+
/** The capture source singer mode wants (null: singer mode off / "keep"). */
|
|
61
|
+
@Volatile
|
|
62
|
+
private var singerSource: Int? = null
|
|
63
|
+
private var effectsSession = 0
|
|
64
|
+
private val main = Handler(Looper.getMainLooper())
|
|
65
|
+
private var aec: AcousticEchoCanceler? = null
|
|
66
|
+
private var ns: NoiseSuppressor? = null
|
|
67
|
+
|
|
68
|
+
private val muteLock = Any()
|
|
69
|
+
|
|
70
|
+
/** The user's engine mute (setMicrophoneMute); returns the applied mute. */
|
|
71
|
+
fun setUserMute(muted: Boolean): Boolean = synchronized(muteLock) {
|
|
72
|
+
userMuted = muted
|
|
73
|
+
val effective = OtherAppAudioPolicy.engineMute(userMuted, autoMuted)
|
|
74
|
+
GxRecorderSeam.applyEngineMute(effective)
|
|
75
|
+
effective
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// main thread (user) and the module thread (automatic) both write the one
|
|
79
|
+
// engine flag: under one lock, so the last write always reflects both
|
|
80
|
+
private fun setAutoMute(muted: Boolean) = synchronized(muteLock) {
|
|
81
|
+
if (autoMuted == muted) return@synchronized
|
|
82
|
+
autoMuted = muted
|
|
83
|
+
GxRecorderSeam.applyEngineMute(OtherAppAudioPolicy.engineMute(userMuted, autoMuted))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
fun apply(next: OtherAppAudioPolicy.Action) {
|
|
87
|
+
run { applyOnWorker(next, attempt = 0) }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Singer mode's capture source (null = singer mode off or "keep"). */
|
|
91
|
+
fun setSingerSource(source: Int?) {
|
|
92
|
+
// set here, applied on the module thread (idempotent: a later call, or
|
|
93
|
+
// the next other-app action, re-applies it if the executor was not up)
|
|
94
|
+
singerSource = source
|
|
95
|
+
Log.i(TAG, "singer capture source -> ${source ?: "off"}")
|
|
96
|
+
run { applyOnWorker(action, attempt = 0) }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Plugin detach: back to the original capture. */
|
|
100
|
+
fun reset() {
|
|
101
|
+
singerSource = null
|
|
102
|
+
run { applyOnWorker(OtherAppAudioPolicy.Action.NONE, attempt = 0) }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private fun run(block: () -> Unit) {
|
|
106
|
+
val ex = executor() ?: return
|
|
107
|
+
try {
|
|
108
|
+
ex.execute {
|
|
109
|
+
try {
|
|
110
|
+
block()
|
|
111
|
+
} catch (t: Throwable) {
|
|
112
|
+
Log.w(TAG, "capture action failed", t)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} catch (_: RejectedExecutionException) {
|
|
116
|
+
// plugin detaching
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private fun applyOnWorker(next: OtherAppAudioPolicy.Action, attempt: Int) {
|
|
121
|
+
val prev = action
|
|
122
|
+
action = next
|
|
123
|
+
Log.i(TAG, "capture action $prev -> $next")
|
|
124
|
+
val singer = singerSource
|
|
125
|
+
val wantSource = singer == null && next == OtherAppAudioPolicy.Action.VOICE_COMMUNICATION
|
|
126
|
+
val wantEffects = singer == null && (next == OtherAppAudioPolicy.Action.PLATFORM_EFFECTS || wantSource)
|
|
127
|
+
val wantMute = next == OtherAppAudioPolicy.Action.MUTE
|
|
128
|
+
|
|
129
|
+
setAutoMute(wantMute)
|
|
130
|
+
if (!wantEffects) releaseEffects()
|
|
131
|
+
val input = GxRecorderSeam.webRtcAudioRecord()
|
|
132
|
+
val target = singer ?: if (wantSource) MediaRecorder.AudioSource.VOICE_COMMUNICATION else null
|
|
133
|
+
if (target != GxRecorderSeam.currentSource() || target == null) {
|
|
134
|
+
// null = WebRTC's own source; the record thread swaps the recorder between two reads
|
|
135
|
+
if (wantEffects) releaseEffects()
|
|
136
|
+
GxRecorderSeam.requestSource(target)
|
|
137
|
+
Log.i(TAG, "capture source -> ${target ?: "original (${GxRecorderSeam.originalSource()})"}")
|
|
138
|
+
}
|
|
139
|
+
if (wantEffects && !attachEffects(input) && attempt < 5) {
|
|
140
|
+
// the recorder is not open yet (an unmute just started it): try again
|
|
141
|
+
// later without holding the audio device module thread
|
|
142
|
+
main.postDelayed({ run { if (action == next) applyOnWorker(next, attempt + 1) } }, 300)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ── platform effects ───────────────────────────────────────────────────
|
|
147
|
+
|
|
148
|
+
private fun recorder(input: Any): AudioRecord? = try {
|
|
149
|
+
input.javaClass.getDeclaredField("audioRecord").apply { isAccessible = true }.get(input) as? AudioRecord
|
|
150
|
+
} catch (_: Throwable) {
|
|
151
|
+
null
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** True when attached (or already attached) to the running recorder. */
|
|
155
|
+
private fun attachEffects(input: Any?): Boolean {
|
|
156
|
+
// a source switch the record thread has not made yet: attach after it (retried)
|
|
157
|
+
if (GxRecorderSeam.switchPending()) return false
|
|
158
|
+
val session = input?.let { recorder(it)?.audioSessionId } ?: 0
|
|
159
|
+
if (session <= 0) return false
|
|
160
|
+
if (session == effectsSession && (aec != null || ns != null)) return true
|
|
161
|
+
releaseEffects()
|
|
162
|
+
effectsSession = session
|
|
163
|
+
aec = if (AcousticEchoCanceler.isAvailable()) create { AcousticEchoCanceler.create(session) } else null
|
|
164
|
+
ns = if (NoiseSuppressor.isAvailable()) create { NoiseSuppressor.create(session) } else null
|
|
165
|
+
Log.i(TAG, "platform effects on session $session: aec=${describe(aec)} ns=${describe(ns)}")
|
|
166
|
+
return true
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private fun <T : AudioEffect> create(make: () -> T?): T? = try {
|
|
170
|
+
make()?.also { it.enabled = true }
|
|
171
|
+
} catch (t: Throwable) {
|
|
172
|
+
Log.w(TAG, "platform effect unavailable: $t")
|
|
173
|
+
null
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private fun describe(e: AudioEffect?): String =
|
|
177
|
+
if (e == null) "none" else try {
|
|
178
|
+
"${e.descriptor.name}/${e.descriptor.implementor} enabled=${e.enabled}"
|
|
179
|
+
} catch (_: Throwable) {
|
|
180
|
+
"attached"
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private fun releaseEffects() {
|
|
184
|
+
if (aec == null && ns == null) return
|
|
185
|
+
try { aec?.release() } catch (_: Throwable) {}
|
|
186
|
+
try { ns?.release() } catch (_: Throwable) {}
|
|
187
|
+
aec = null
|
|
188
|
+
ns = null
|
|
189
|
+
Log.i(TAG, "platform effects released (session $effectsSession)")
|
|
190
|
+
effectsSession = 0
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
companion object {
|
|
194
|
+
private const val TAG = "GxOtherAppAudio"
|
|
195
|
+
}
|
|
196
|
+
}
|