├── .github └── workflows │ └── main.yml ├── CMakeLists.txt ├── COPYING ├── README.md ├── buildenv ├── Dockerfile.bionic ├── Dockerfile.centos7 ├── centos_entrypoint.sh ├── config_site.h ├── gen_db.desktop ├── icon.svg ├── prepare.sh ├── tdlib_header.patch ├── tdlib_threadname.patch └── tg2sip.desktop ├── include ├── INIReader.h └── boost │ └── sml.hpp ├── libtgvoip ├── .gitignore ├── Android.mk ├── BlockingQueue.cpp ├── BlockingQueue.h ├── Buffers.cpp ├── Buffers.h ├── CMakeLists.txt ├── CongestionControl.cpp ├── CongestionControl.h ├── EchoCanceller.cpp ├── EchoCanceller.h ├── Info.plist ├── JitterBuffer.cpp ├── JitterBuffer.h ├── Makefile.am ├── Makefile.in ├── MediaStreamItf.cpp ├── MediaStreamItf.h ├── MessageThread.cpp ├── MessageThread.h ├── NetworkSocket.cpp ├── NetworkSocket.h ├── OpusDecoder.cpp ├── OpusDecoder.h ├── OpusEncoder.cpp ├── OpusEncoder.h ├── PacketReassembler.cpp ├── PacketReassembler.h ├── PrivateDefines.h ├── UNLICENSE ├── VoIPController.cpp ├── VoIPController.h ├── VoIPGroupController.cpp ├── VoIPServerConfig.cpp ├── VoIPServerConfig.h ├── aclocal.m4 ├── audio │ ├── AudioIO.cpp │ ├── AudioIO.h │ ├── AudioIOCallback.cpp │ ├── AudioIOCallback.h │ ├── AudioInput.cpp │ ├── AudioInput.h │ ├── AudioOutput.cpp │ ├── AudioOutput.h │ ├── Resampler.cpp │ ├── Resampler.h │ ├── SoftwareAudioInput.cpp │ ├── SoftwareAudioInput.h │ ├── SoftwareAudioOutput.cpp │ └── SoftwareAudioOutput.h ├── client │ └── android │ │ ├── tg_voip_jni.cpp │ │ └── tg_voip_jni.h ├── compile ├── config.guess ├── config.h.in ├── config.sub ├── configure ├── configure.ac ├── depcomp ├── install-sh ├── json11.cpp ├── json11.hpp ├── libtgvoip.UWP.vcxproj ├── libtgvoip.UWP.vcxproj.filters ├── libtgvoip.WP81.vcxproj ├── libtgvoip.WP81.vcxproj.filters ├── libtgvoip.gyp ├── libtgvoip.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── libtgvoip_osx.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── logging.cpp ├── logging.h ├── ltmain.sh ├── missing ├── os │ ├── android │ │ ├── AudioInputAndroid.cpp │ │ ├── AudioInputAndroid.h │ │ ├── AudioInputOpenSLES.cpp │ │ ├── AudioInputOpenSLES.h │ │ ├── AudioOutputAndroid.cpp │ │ ├── AudioOutputAndroid.h │ │ ├── AudioOutputOpenSLES.cpp │ │ ├── AudioOutputOpenSLES.h │ │ ├── JNIUtilities.h │ │ ├── OpenSLEngineWrapper.cpp │ │ ├── OpenSLEngineWrapper.h │ │ ├── VideoRendererAndroid.cpp │ │ ├── VideoRendererAndroid.h │ │ ├── VideoSourceAndroid.cpp │ │ └── VideoSourceAndroid.h │ ├── darwin │ │ ├── AudioInputAudioUnit.cpp │ │ ├── AudioInputAudioUnit.h │ │ ├── AudioInputAudioUnitOSX.cpp │ │ ├── AudioInputAudioUnitOSX.h │ │ ├── AudioOutputAudioUnit.cpp │ │ ├── AudioOutputAudioUnit.h │ │ ├── AudioOutputAudioUnitOSX.cpp │ │ ├── AudioOutputAudioUnitOSX.h │ │ ├── AudioUnitIO.cpp │ │ ├── AudioUnitIO.h │ │ ├── DarwinSpecific.h │ │ ├── DarwinSpecific.mm │ │ ├── SetupLogging.h │ │ ├── TGLogWrapper.h │ │ └── TGLogWrapper.m │ ├── linux │ │ ├── AudioInputALSA.cpp │ │ ├── AudioInputALSA.h │ │ ├── AudioInputPulse.cpp │ │ ├── AudioInputPulse.h │ │ ├── AudioOutputALSA.cpp │ │ ├── AudioOutputALSA.h │ │ ├── AudioOutputPulse.cpp │ │ ├── AudioOutputPulse.h │ │ ├── AudioPulse.cpp │ │ ├── AudioPulse.h │ │ └── PulseFunctions.h │ ├── posix │ │ ├── NetworkSocketPosix.cpp │ │ └── NetworkSocketPosix.h │ └── windows │ │ ├── AudioInputWASAPI.cpp │ │ ├── AudioInputWASAPI.h │ │ ├── AudioInputWave.cpp │ │ ├── AudioInputWave.h │ │ ├── AudioOutputWASAPI.cpp │ │ ├── AudioOutputWASAPI.h │ │ ├── AudioOutputWave.cpp │ │ ├── AudioOutputWave.h │ │ ├── CXWrapper.cpp │ │ ├── CXWrapper.h │ │ ├── NetworkSocketWinsock.cpp │ │ ├── NetworkSocketWinsock.h │ │ ├── WindowsSandboxUtils.cpp │ │ ├── WindowsSandboxUtils.h │ │ ├── WindowsSpecific.cpp │ │ └── WindowsSpecific.h ├── tests │ ├── Info.plist │ ├── MockReflector.cpp │ ├── MockReflector.h │ └── libtgvoipTests.mm ├── threading.h ├── utils.h ├── video │ ├── VideoRenderer.cpp │ ├── VideoRenderer.h │ ├── VideoSource.cpp │ └── VideoSource.h └── webrtc_dsp │ ├── absl │ ├── algorithm │ │ └── algorithm.h │ ├── base │ │ ├── attributes.h │ │ ├── config.h │ │ ├── internal │ │ │ ├── atomic_hook.h │ │ │ ├── identity.h │ │ │ ├── inline_variable.h │ │ │ ├── invoke.h │ │ │ ├── raw_logging.cc │ │ │ ├── raw_logging.h │ │ │ ├── throw_delegate.cc │ │ │ └── throw_delegate.h │ │ ├── log_severity.h │ │ ├── macros.h │ │ ├── optimization.h │ │ ├── policy_checks.h │ │ └── port.h │ ├── container │ │ └── inlined_vector.h │ ├── memory │ │ └── memory.h │ ├── meta │ │ └── type_traits.h │ ├── strings │ │ ├── ascii.cc │ │ ├── ascii.h │ │ ├── internal │ │ │ ├── memutil.cc │ │ │ └── memutil.h │ │ ├── string_view.cc │ │ └── string_view.h │ ├── types │ │ ├── bad_optional_access.cc │ │ ├── bad_optional_access.h │ │ ├── optional.cc │ │ └── optional.h │ └── utility │ │ └── utility.h │ ├── api │ ├── array_view.h │ └── audio │ │ ├── audio_frame.cc │ │ ├── audio_frame.h │ │ ├── echo_canceller3_config.cc │ │ ├── echo_canceller3_config.h │ │ ├── echo_canceller3_factory.cc │ │ ├── echo_canceller3_factory.h │ │ └── echo_control.h │ ├── common_audio │ ├── audio_converter.cc │ ├── audio_converter.h │ ├── audio_util.cc │ ├── channel_buffer.cc │ ├── channel_buffer.h │ ├── fir_filter.h │ ├── fir_filter_c.cc │ ├── fir_filter_c.h │ ├── fir_filter_factory.cc │ ├── fir_filter_factory.h │ ├── fir_filter_neon.cc │ ├── fir_filter_neon.h │ ├── fir_filter_sse.cc │ ├── fir_filter_sse.h │ ├── include │ │ └── audio_util.h │ ├── mocks │ │ └── mock_smoothing_filter.h │ ├── real_fourier.cc │ ├── real_fourier.h │ ├── real_fourier_ooura.cc │ ├── real_fourier_ooura.h │ ├── resampler │ │ ├── include │ │ │ ├── push_resampler.h │ │ │ └── resampler.h │ │ ├── push_resampler.cc │ │ ├── push_sinc_resampler.cc │ │ ├── push_sinc_resampler.h │ │ ├── resampler.cc │ │ ├── sinc_resampler.cc │ │ ├── sinc_resampler.h │ │ ├── sinc_resampler_neon.cc │ │ ├── sinc_resampler_sse.cc │ │ ├── sinusoidal_linear_chirp_source.cc │ │ └── sinusoidal_linear_chirp_source.h │ ├── ring_buffer.c │ ├── ring_buffer.h │ ├── signal_processing │ │ ├── auto_corr_to_refl_coef.c │ │ ├── auto_correlation.c │ │ ├── complex_bit_reverse.c │ │ ├── complex_bit_reverse_arm.S │ │ ├── complex_fft.c │ │ ├── complex_fft_tables.h │ │ ├── copy_set_operations.c │ │ ├── cross_correlation.c │ │ ├── cross_correlation_neon.c │ │ ├── division_operations.c │ │ ├── dot_product_with_scale.cc │ │ ├── dot_product_with_scale.h │ │ ├── downsample_fast.c │ │ ├── downsample_fast_neon.c │ │ ├── energy.c │ │ ├── filter_ar.c │ │ ├── filter_ar_fast_q12.c │ │ ├── filter_ar_fast_q12_armv7.S │ │ ├── filter_ma_fast_q12.c │ │ ├── get_hanning_window.c │ │ ├── get_scaling_square.c │ │ ├── ilbc_specific_functions.c │ │ ├── include │ │ │ ├── real_fft.h │ │ │ ├── signal_processing_library.h │ │ │ ├── spl_inl.h │ │ │ └── spl_inl_armv7.h │ │ ├── levinson_durbin.c │ │ ├── lpc_to_refl_coef.c │ │ ├── min_max_operations.c │ │ ├── min_max_operations_neon.c │ │ ├── randomization_functions.c │ │ ├── real_fft.c │ │ ├── refl_coef_to_lpc.c │ │ ├── resample.c │ │ ├── resample_48khz.c │ │ ├── resample_by_2.c │ │ ├── resample_by_2_internal.c │ │ ├── resample_by_2_internal.h │ │ ├── resample_fractional.c │ │ ├── spl_init.c │ │ ├── spl_inl.c │ │ ├── spl_sqrt.c │ │ ├── splitting_filter1.c │ │ ├── sqrt_of_one_minus_x_squared.c │ │ └── vector_scaling_operations.c │ ├── smoothing_filter.cc │ ├── smoothing_filter.h │ ├── sparse_fir_filter.cc │ ├── sparse_fir_filter.h │ ├── third_party │ │ ├── fft4g │ │ │ ├── fft4g.c │ │ │ └── fft4g.h │ │ └── spl_sqrt_floor │ │ │ ├── spl_sqrt_floor.c │ │ │ ├── spl_sqrt_floor.h │ │ │ └── spl_sqrt_floor_arm.S │ ├── vad │ │ ├── include │ │ │ ├── vad.h │ │ │ └── webrtc_vad.h │ │ ├── vad.cc │ │ ├── vad_core.c │ │ ├── vad_core.h │ │ ├── vad_filterbank.c │ │ ├── vad_filterbank.h │ │ ├── vad_gmm.c │ │ ├── vad_gmm.h │ │ ├── vad_sp.c │ │ ├── vad_sp.h │ │ └── webrtc_vad.c │ ├── wav_file.cc │ ├── wav_file.h │ ├── wav_header.cc │ ├── wav_header.h │ ├── window_generator.cc │ └── window_generator.h │ ├── modules │ ├── audio_coding │ │ └── codecs │ │ │ └── isac │ │ │ ├── bandwidth_info.h │ │ │ └── main │ │ │ ├── include │ │ │ └── isac.h │ │ │ └── source │ │ │ ├── arith_routines.c │ │ │ ├── arith_routines.h │ │ │ ├── arith_routines_hist.c │ │ │ ├── arith_routines_logist.c │ │ │ ├── bandwidth_estimator.c │ │ │ ├── bandwidth_estimator.h │ │ │ ├── codec.h │ │ │ ├── crc.c │ │ │ ├── crc.h │ │ │ ├── decode.c │ │ │ ├── decode_bwe.c │ │ │ ├── encode.c │ │ │ ├── encode_lpc_swb.c │ │ │ ├── encode_lpc_swb.h │ │ │ ├── entropy_coding.c │ │ │ ├── entropy_coding.h │ │ │ ├── filter_functions.c │ │ │ ├── filter_functions.h │ │ │ ├── filterbanks.c │ │ │ ├── intialize.c │ │ │ ├── isac.c │ │ │ ├── isac_float_type.h │ │ │ ├── isac_vad.c │ │ │ ├── isac_vad.h │ │ │ ├── lattice.c │ │ │ ├── lpc_analysis.c │ │ │ ├── lpc_analysis.h │ │ │ ├── lpc_gain_swb_tables.c │ │ │ ├── lpc_gain_swb_tables.h │ │ │ ├── lpc_shape_swb12_tables.c │ │ │ ├── lpc_shape_swb12_tables.h │ │ │ ├── lpc_shape_swb16_tables.c │ │ │ ├── lpc_shape_swb16_tables.h │ │ │ ├── lpc_tables.c │ │ │ ├── lpc_tables.h │ │ │ ├── os_specific_inline.h │ │ │ ├── pitch_estimator.c │ │ │ ├── pitch_estimator.h │ │ │ ├── pitch_filter.c │ │ │ ├── pitch_filter.h │ │ │ ├── pitch_gain_tables.c │ │ │ ├── pitch_gain_tables.h │ │ │ ├── pitch_lag_tables.c │ │ │ ├── pitch_lag_tables.h │ │ │ ├── settings.h │ │ │ ├── spectrum_ar_model_tables.c │ │ │ ├── spectrum_ar_model_tables.h │ │ │ ├── structs.h │ │ │ └── transform.c │ ├── audio_processing │ │ ├── aec │ │ │ ├── aec_common.h │ │ │ ├── aec_core.cc │ │ │ ├── aec_core.h │ │ │ ├── aec_core_neon.cc │ │ │ ├── aec_core_optimized_methods.h │ │ │ ├── aec_core_sse2.cc │ │ │ ├── aec_resampler.cc │ │ │ ├── aec_resampler.h │ │ │ ├── echo_cancellation.cc │ │ │ └── echo_cancellation.h │ │ ├── aec3 │ │ │ ├── adaptive_fir_filter.cc │ │ │ ├── adaptive_fir_filter.h │ │ │ ├── aec3_common.cc │ │ │ ├── aec3_common.h │ │ │ ├── aec3_fft.cc │ │ │ ├── aec3_fft.h │ │ │ ├── aec_state.cc │ │ │ ├── aec_state.h │ │ │ ├── block_delay_buffer.cc │ │ │ ├── block_delay_buffer.h │ │ │ ├── block_framer.cc │ │ │ ├── block_framer.h │ │ │ ├── block_processor.cc │ │ │ ├── block_processor.h │ │ │ ├── block_processor2.cc │ │ │ ├── block_processor_metrics.cc │ │ │ ├── block_processor_metrics.h │ │ │ ├── cascaded_biquad_filter.cc │ │ │ ├── cascaded_biquad_filter.h │ │ │ ├── comfort_noise_generator.cc │ │ │ ├── comfort_noise_generator.h │ │ │ ├── decimator.cc │ │ │ ├── decimator.h │ │ │ ├── delay_estimate.h │ │ │ ├── downsampled_render_buffer.cc │ │ │ ├── downsampled_render_buffer.h │ │ │ ├── echo_audibility.cc │ │ │ ├── echo_audibility.h │ │ │ ├── echo_canceller3.cc │ │ │ ├── echo_canceller3.h │ │ │ ├── echo_path_delay_estimator.cc │ │ │ ├── echo_path_delay_estimator.h │ │ │ ├── echo_path_variability.cc │ │ │ ├── echo_path_variability.h │ │ │ ├── echo_remover.cc │ │ │ ├── echo_remover.h │ │ │ ├── echo_remover_metrics.cc │ │ │ ├── echo_remover_metrics.h │ │ │ ├── erl_estimator.cc │ │ │ ├── erl_estimator.h │ │ │ ├── erle_estimator.cc │ │ │ ├── erle_estimator.h │ │ │ ├── fft_buffer.cc │ │ │ ├── fft_buffer.h │ │ │ ├── fft_data.h │ │ │ ├── filter_analyzer.cc │ │ │ ├── filter_analyzer.h │ │ │ ├── frame_blocker.cc │ │ │ ├── frame_blocker.h │ │ │ ├── fullband_erle_estimator.cc │ │ │ ├── fullband_erle_estimator.h │ │ │ ├── main_filter_update_gain.cc │ │ │ ├── main_filter_update_gain.h │ │ │ ├── matched_filter.cc │ │ │ ├── matched_filter.h │ │ │ ├── matched_filter_lag_aggregator.cc │ │ │ ├── matched_filter_lag_aggregator.h │ │ │ ├── matrix_buffer.cc │ │ │ ├── matrix_buffer.h │ │ │ ├── moving_average.cc │ │ │ ├── moving_average.h │ │ │ ├── render_buffer.cc │ │ │ ├── render_buffer.h │ │ │ ├── render_delay_buffer.cc │ │ │ ├── render_delay_buffer.h │ │ │ ├── render_delay_buffer2.cc │ │ │ ├── render_delay_controller.cc │ │ │ ├── render_delay_controller.h │ │ │ ├── render_delay_controller2.cc │ │ │ ├── render_delay_controller_metrics.cc │ │ │ ├── render_delay_controller_metrics.h │ │ │ ├── render_reverb_model.cc │ │ │ ├── render_reverb_model.h │ │ │ ├── render_signal_analyzer.cc │ │ │ ├── render_signal_analyzer.h │ │ │ ├── residual_echo_estimator.cc │ │ │ ├── residual_echo_estimator.h │ │ │ ├── reverb_decay_estimator.cc │ │ │ ├── reverb_decay_estimator.h │ │ │ ├── reverb_frequency_response.cc │ │ │ ├── reverb_frequency_response.h │ │ │ ├── reverb_model.cc │ │ │ ├── reverb_model.h │ │ │ ├── reverb_model_estimator.cc │ │ │ ├── reverb_model_estimator.h │ │ │ ├── reverb_model_fallback.cc │ │ │ ├── reverb_model_fallback.h │ │ │ ├── shadow_filter_update_gain.cc │ │ │ ├── shadow_filter_update_gain.h │ │ │ ├── skew_estimator.cc │ │ │ ├── skew_estimator.h │ │ │ ├── stationarity_estimator.cc │ │ │ ├── stationarity_estimator.h │ │ │ ├── subband_erle_estimator.cc │ │ │ ├── subband_erle_estimator.h │ │ │ ├── subtractor.cc │ │ │ ├── subtractor.h │ │ │ ├── subtractor_output.cc │ │ │ ├── subtractor_output.h │ │ │ ├── subtractor_output_analyzer.cc │ │ │ ├── subtractor_output_analyzer.h │ │ │ ├── suppression_filter.cc │ │ │ ├── suppression_filter.h │ │ │ ├── suppression_gain.cc │ │ │ ├── suppression_gain.h │ │ │ ├── suppression_gain_limiter.cc │ │ │ ├── suppression_gain_limiter.h │ │ │ ├── vector_buffer.cc │ │ │ ├── vector_buffer.h │ │ │ └── vector_math.h │ │ ├── aecm │ │ │ ├── aecm_core.cc │ │ │ ├── aecm_core.h │ │ │ ├── aecm_core_c.cc │ │ │ ├── aecm_core_neon.cc │ │ │ ├── aecm_defines.h │ │ │ ├── echo_control_mobile.cc │ │ │ └── echo_control_mobile.h │ │ ├── agc │ │ │ ├── agc.cc │ │ │ ├── agc.h │ │ │ ├── agc_manager_direct.cc │ │ │ ├── agc_manager_direct.h │ │ │ ├── gain_map_internal.h │ │ │ ├── legacy │ │ │ │ ├── analog_agc.c │ │ │ │ ├── analog_agc.h │ │ │ │ ├── digital_agc.c │ │ │ │ ├── digital_agc.h │ │ │ │ └── gain_control.h │ │ │ ├── loudness_histogram.cc │ │ │ ├── loudness_histogram.h │ │ │ ├── mock_agc.h │ │ │ ├── utility.cc │ │ │ └── utility.h │ │ ├── agc2 │ │ │ ├── adaptive_agc.cc │ │ │ ├── adaptive_agc.h │ │ │ ├── adaptive_digital_gain_applier.cc │ │ │ ├── adaptive_digital_gain_applier.h │ │ │ ├── adaptive_mode_level_estimator.cc │ │ │ ├── adaptive_mode_level_estimator.h │ │ │ ├── adaptive_mode_level_estimator_agc.cc │ │ │ ├── adaptive_mode_level_estimator_agc.h │ │ │ ├── agc2_common.cc │ │ │ ├── agc2_common.h │ │ │ ├── agc2_testing_common.cc │ │ │ ├── agc2_testing_common.h │ │ │ ├── biquad_filter.cc │ │ │ ├── biquad_filter.h │ │ │ ├── compute_interpolated_gain_curve.cc │ │ │ ├── compute_interpolated_gain_curve.h │ │ │ ├── down_sampler.cc │ │ │ ├── down_sampler.h │ │ │ ├── fixed_digital_level_estimator.cc │ │ │ ├── fixed_digital_level_estimator.h │ │ │ ├── fixed_gain_controller.cc │ │ │ ├── fixed_gain_controller.h │ │ │ ├── gain_applier.cc │ │ │ ├── gain_applier.h │ │ │ ├── interpolated_gain_curve.cc │ │ │ ├── interpolated_gain_curve.h │ │ │ ├── limiter.cc │ │ │ ├── limiter.h │ │ │ ├── limiter_db_gain_curve.cc │ │ │ ├── limiter_db_gain_curve.h │ │ │ ├── noise_level_estimator.cc │ │ │ ├── noise_level_estimator.h │ │ │ ├── noise_spectrum_estimator.cc │ │ │ ├── noise_spectrum_estimator.h │ │ │ ├── rnn_vad │ │ │ │ ├── common.h │ │ │ │ ├── features_extraction.cc │ │ │ │ ├── features_extraction.h │ │ │ │ ├── fft_util.cc │ │ │ │ ├── fft_util.h │ │ │ │ ├── lp_residual.cc │ │ │ │ ├── lp_residual.h │ │ │ │ ├── pitch_info.h │ │ │ │ ├── pitch_search.cc │ │ │ │ ├── pitch_search.h │ │ │ │ ├── pitch_search_internal.cc │ │ │ │ ├── pitch_search_internal.h │ │ │ │ ├── ring_buffer.h │ │ │ │ ├── rnn.cc │ │ │ │ ├── rnn.h │ │ │ │ ├── sequence_buffer.h │ │ │ │ ├── spectral_features.cc │ │ │ │ ├── spectral_features.h │ │ │ │ ├── spectral_features_internal.cc │ │ │ │ ├── spectral_features_internal.h │ │ │ │ ├── symmetric_matrix_buffer.h │ │ │ │ └── test_utils.h │ │ │ ├── saturation_protector.cc │ │ │ ├── saturation_protector.h │ │ │ ├── signal_classifier.cc │ │ │ ├── signal_classifier.h │ │ │ ├── vad_with_level.cc │ │ │ ├── vad_with_level.h │ │ │ ├── vector_float_frame.cc │ │ │ └── vector_float_frame.h │ │ ├── audio_buffer.cc │ │ ├── audio_buffer.h │ │ ├── audio_generator │ │ │ ├── file_audio_generator.cc │ │ │ └── file_audio_generator.h │ │ ├── audio_processing_impl.cc │ │ ├── audio_processing_impl.h │ │ ├── common.h │ │ ├── echo_cancellation_impl.cc │ │ ├── echo_cancellation_impl.h │ │ ├── echo_control_mobile_impl.cc │ │ ├── echo_control_mobile_impl.h │ │ ├── echo_detector │ │ │ ├── circular_buffer.cc │ │ │ ├── circular_buffer.h │ │ │ ├── mean_variance_estimator.cc │ │ │ ├── mean_variance_estimator.h │ │ │ ├── moving_max.cc │ │ │ ├── moving_max.h │ │ │ ├── normalized_covariance_estimator.cc │ │ │ └── normalized_covariance_estimator.h │ │ ├── gain_control_for_experimental_agc.cc │ │ ├── gain_control_for_experimental_agc.h │ │ ├── gain_control_impl.cc │ │ ├── gain_control_impl.h │ │ ├── gain_controller2.cc │ │ ├── gain_controller2.h │ │ ├── include │ │ │ ├── aec_dump.cc │ │ │ ├── aec_dump.h │ │ │ ├── audio_frame_view.h │ │ │ ├── audio_generator.h │ │ │ ├── audio_generator_factory.cc │ │ │ ├── audio_generator_factory.h │ │ │ ├── audio_processing.cc │ │ │ ├── audio_processing.h │ │ │ ├── audio_processing_statistics.cc │ │ │ ├── audio_processing_statistics.h │ │ │ ├── config.cc │ │ │ ├── config.h │ │ │ ├── gain_control.h │ │ │ └── mock_audio_processing.h │ │ ├── level_estimator_impl.cc │ │ ├── level_estimator_impl.h │ │ ├── logging │ │ │ ├── apm_data_dumper.cc │ │ │ └── apm_data_dumper.h │ │ ├── low_cut_filter.cc │ │ ├── low_cut_filter.h │ │ ├── noise_suppression_impl.cc │ │ ├── noise_suppression_impl.h │ │ ├── ns │ │ │ ├── defines.h │ │ │ ├── noise_suppression.c │ │ │ ├── noise_suppression.h │ │ │ ├── noise_suppression_x.c │ │ │ ├── noise_suppression_x.h │ │ │ ├── ns_core.c │ │ │ ├── ns_core.h │ │ │ ├── nsx_core.c │ │ │ ├── nsx_core.h │ │ │ ├── nsx_core_c.c │ │ │ ├── nsx_core_neon.c │ │ │ ├── nsx_defines.h │ │ │ └── windows_private.h │ │ ├── render_queue_item_verifier.h │ │ ├── residual_echo_detector.cc │ │ ├── residual_echo_detector.h │ │ ├── rms_level.cc │ │ ├── rms_level.h │ │ ├── splitting_filter.cc │ │ ├── splitting_filter.h │ │ ├── three_band_filter_bank.cc │ │ ├── three_band_filter_bank.h │ │ ├── transient │ │ │ ├── common.h │ │ │ ├── daubechies_8_wavelet_coeffs.h │ │ │ ├── dyadic_decimator.h │ │ │ ├── moving_moments.cc │ │ │ ├── moving_moments.h │ │ │ ├── transient_detector.cc │ │ │ ├── transient_detector.h │ │ │ ├── transient_suppressor.cc │ │ │ ├── transient_suppressor.h │ │ │ ├── wpd_node.cc │ │ │ ├── wpd_node.h │ │ │ ├── wpd_tree.cc │ │ │ └── wpd_tree.h │ │ ├── typing_detection.cc │ │ ├── typing_detection.h │ │ ├── utility │ │ │ ├── block_mean_calculator.cc │ │ │ ├── block_mean_calculator.h │ │ │ ├── delay_estimator.cc │ │ │ ├── delay_estimator.h │ │ │ ├── delay_estimator_internal.h │ │ │ ├── delay_estimator_wrapper.cc │ │ │ ├── delay_estimator_wrapper.h │ │ │ ├── ooura_fft.cc │ │ │ ├── ooura_fft.h │ │ │ ├── ooura_fft_neon.cc │ │ │ ├── ooura_fft_sse2.cc │ │ │ ├── ooura_fft_tables_common.h │ │ │ └── ooura_fft_tables_neon_sse2.h │ │ ├── vad │ │ │ ├── common.h │ │ │ ├── gmm.cc │ │ │ ├── gmm.h │ │ │ ├── noise_gmm_tables.h │ │ │ ├── pitch_based_vad.cc │ │ │ ├── pitch_based_vad.h │ │ │ ├── pitch_internal.cc │ │ │ ├── pitch_internal.h │ │ │ ├── pole_zero_filter.cc │ │ │ ├── pole_zero_filter.h │ │ │ ├── standalone_vad.cc │ │ │ ├── standalone_vad.h │ │ │ ├── vad_audio_proc.cc │ │ │ ├── vad_audio_proc.h │ │ │ ├── vad_audio_proc_internal.h │ │ │ ├── vad_circular_buffer.cc │ │ │ ├── vad_circular_buffer.h │ │ │ ├── voice_activity_detector.cc │ │ │ ├── voice_activity_detector.h │ │ │ └── voice_gmm_tables.h │ │ ├── voice_detection_impl.cc │ │ └── voice_detection_impl.h │ └── third_party │ │ └── fft │ │ ├── fft.c │ │ └── fft.h │ ├── rtc_base │ ├── arraysize.h │ ├── atomicops.h │ ├── checks.cc │ ├── checks.h │ ├── compile_assert_c.h │ ├── constructormagic.h │ ├── criticalsection.cc │ ├── criticalsection.h │ ├── deprecation.h │ ├── event.cc │ ├── event.h │ ├── event_tracer.cc │ ├── event_tracer.h │ ├── function_view.h │ ├── gtest_prod_util.h │ ├── ignore_wundef.h │ ├── logging.h │ ├── logging_mac.h │ ├── logging_mac.mm │ ├── logging_webrtc.cc │ ├── memory │ │ ├── aligned_malloc.cc │ │ └── aligned_malloc.h │ ├── numerics │ │ ├── safe_compare.h │ │ ├── safe_conversions.h │ │ ├── safe_conversions_impl.h │ │ └── safe_minmax.h │ ├── platform_file.cc │ ├── platform_file.h │ ├── platform_thread.cc │ ├── platform_thread.h │ ├── platform_thread_types.cc │ ├── platform_thread_types.h │ ├── protobuf_utils.h │ ├── race_checker.cc │ ├── race_checker.h │ ├── refcount.h │ ├── refcountedobject.h │ ├── refcounter.h │ ├── sanitizer.h │ ├── scoped_ref_ptr.h │ ├── string_to_number.cc │ ├── string_to_number.h │ ├── stringencode.cc │ ├── stringencode.h │ ├── strings │ │ ├── string_builder.cc │ │ └── string_builder.h │ ├── stringutils.cc │ ├── stringutils.h │ ├── swap_queue.h │ ├── system │ │ ├── arch.h │ │ ├── asm_defines.h │ │ ├── ignore_warnings.h │ │ ├── inline.h │ │ ├── rtc_export.h │ │ └── unused.h │ ├── thread_annotations.h │ ├── thread_checker.h │ ├── thread_checker_impl.cc │ ├── thread_checker_impl.h │ ├── timeutils.cc │ ├── timeutils.h │ ├── trace_event.h │ └── type_traits.h │ ├── system_wrappers │ ├── include │ │ ├── asm_defines.h │ │ ├── compile_assert_c.h │ │ ├── cpu_features_wrapper.h │ │ ├── field_trial.h │ │ └── metrics.h │ └── source │ │ ├── cpu_features.cc │ │ ├── field_trial.cc │ │ └── metrics.cc │ ├── third_party │ └── rnnoise │ │ └── src │ │ ├── kiss_fft.cc │ │ ├── kiss_fft.h │ │ ├── rnn_activations.h │ │ ├── rnn_vad_weights.cc │ │ └── rnn_vad_weights.h │ └── typedefs.h ├── settings.ini └── tg2sip ├── gateway.cpp ├── gateway.h ├── gen_db.cpp ├── logging.cpp ├── logging.h ├── main.cpp ├── queue.h ├── settings.cpp ├── settings.h ├── sip.cpp ├── sip.h ├── tg.cpp ├── tg.h ├── utils.cpp └── utils.h /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9) 2 | project(tg2sip) 3 | 4 | set(CMAKE_CXX_STANDARD 17) 5 | 6 | add_subdirectory(libtgvoip) 7 | 8 | find_package(PkgConfig REQUIRED) 9 | find_package(Threads REQUIRED) 10 | find_package(Td 1.7.10 REQUIRED) 11 | find_package(spdlog 0.17 REQUIRED) 12 | pkg_check_modules(PJSIP libpjproject>=2.8 REQUIRED) 13 | pkg_check_modules(OPUS opus REQUIRED) 14 | 15 | add_executable(tg2sip 16 | tg2sip/main.cpp 17 | tg2sip/tg.cpp 18 | tg2sip/tg.h 19 | tg2sip/sip.cpp 20 | tg2sip/sip.h 21 | tg2sip/settings.cpp 22 | tg2sip/settings.h 23 | tg2sip/logging.cpp 24 | tg2sip/logging.h 25 | tg2sip/utils.cpp 26 | tg2sip/utils.h 27 | tg2sip/queue.h 28 | tg2sip/gateway.cpp 29 | tg2sip/gateway.h 30 | ) 31 | 32 | add_custom_command( 33 | TARGET tg2sip PRE_BUILD 34 | COMMAND ${CMAKE_COMMAND} -E copy 35 | ${CMAKE_SOURCE_DIR}/settings.ini 36 | $) 37 | 38 | target_include_directories(tg2sip PRIVATE 39 | ${PJSIP_INCLUDE_DIRS} 40 | ${PROJECT_SOURCE_DIR} 41 | ${OPUS_INCLUDE_DIRS} 42 | include) 43 | 44 | target_link_libraries(tg2sip PRIVATE 45 | ${PJSIP_LIBRARIES} 46 | ${OPUS_LIBRARIES} 47 | libtgvoip 48 | Threads::Threads 49 | Td::TdStatic) 50 | 51 | add_executable(gen_db 52 | tg2sip/gen_db.cpp 53 | tg2sip/settings.cpp 54 | tg2sip/settings.h) 55 | 56 | target_include_directories(gen_db PRIVATE 57 | include) 58 | 59 | target_link_libraries(gen_db PRIVATE 60 | Td::TdStatic) -------------------------------------------------------------------------------- /buildenv/Dockerfile.bionic: -------------------------------------------------------------------------------- 1 | FROM ubuntu:bionic 2 | 3 | RUN apt-get update \ 4 | && apt-get install -y --no-install-recommends \ 5 | build-essential git \ 6 | wget ca-certificates \ 7 | pkg-config libopus-dev libssl-dev \ 8 | zlib1g-dev gperf ccache \ 9 | && rm -rf /var/lib/apt/lists/* 10 | 11 | RUN wget https://cmake.org/files/v3.18/cmake-3.18.0-Linux-x86_64.sh \ 12 | && sh cmake-3.18.0-Linux-x86_64.sh --prefix=/usr --exclude-subdir 13 | 14 | COPY tdlib_header.patch / 15 | COPY tdlib_threadname.patch / 16 | 17 | # TDLib 1.7.10 18 | RUN git clone https://github.com/tdlib/td.git \ 19 | && cd td \ 20 | && git reset --hard a53cb30e99f937cfd64e0266fa558785a184a553 \ 21 | && git apply /tdlib_header.patch \ 22 | && git apply /tdlib_threadname.patch \ 23 | && mkdir build \ 24 | && cd build \ 25 | && cmake -DCMAKE_BUILD_TYPE=Release .. \ 26 | && cmake --build . --target install -j $(grep -c ^processor /proc/cpuinfo) \ 27 | && cd / \ 28 | && rm -rf td 29 | 30 | COPY config_site.h / 31 | 32 | RUN git clone https://github.com/pjsip/pjproject.git \ 33 | && cd pjproject \ 34 | && git reset --hard 2.9 \ 35 | && cp /config_site.h pjlib/include/pj \ 36 | && ./configure --disable-sound CFLAGS="-O3 -DNDEBUG" \ 37 | && make dep && make -j $(grep -c ^processor /proc/cpuinfo) && make install \ 38 | && cd / \ 39 | && rm -rf pjproject 40 | 41 | RUN git clone -n https://github.com/gabime/spdlog.git \ 42 | && cd spdlog \ 43 | && git checkout tags/v0.17.0 \ 44 | && mkdir build \ 45 | && cd build \ 46 | && cmake -DCMAKE_BUILD_TYPE=Release -DSPDLOG_BUILD_EXAMPLES=OFF -DSPDLOG_BUILD_TESTING=OFF .. \ 47 | && cmake --build . --target install -j $(grep -c ^processor /proc/cpuinfo) \ 48 | && cd / \ 49 | && rm -rf spdlog -------------------------------------------------------------------------------- /buildenv/centos_entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | source /opt/rh/devtoolset-7/enable 5 | 6 | exec "$@" -------------------------------------------------------------------------------- /buildenv/config_site.h: -------------------------------------------------------------------------------- 1 | #define PJMEDIA_CONF_USE_SWITCH_BOARD 1 2 | #define PJMEDIA_CONF_SWITCH_BOARD_BUF_SIZE 2000 3 | 4 | #define PJSUA_MAX_CALLS 128 5 | #define PJSUA_MAX_PLAYERS 256 6 | #define PJ_IOQUEUE_MAX_HANDLES 256 7 | 8 | #define PJMEDIA_CODEC_L16_HAS_48KHZ_MONO 1 -------------------------------------------------------------------------------- /buildenv/gen_db.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=gen_db 3 | Exec=gen_db 4 | Comment=TG2SIP DB generator 5 | Terminal=true 6 | Type=Application 7 | Icon=icon 8 | Categories=AudioVideo; -------------------------------------------------------------------------------- /buildenv/prepare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | DOCKER_IMAGE=infactum/tg2sip-builder 6 | 7 | for DOCKER_TAG in bionic centos7 8 | do 9 | docker build . -f Dockerfile."$DOCKER_TAG" -t "$DOCKER_IMAGE:$DOCKER_TAG" 10 | docker push "$DOCKER_IMAGE:$DOCKER_TAG" 11 | done 12 | -------------------------------------------------------------------------------- /buildenv/tdlib_header.patch: -------------------------------------------------------------------------------- 1 | diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp 2 | index 0cbcde9c..50e05ffa 100644 3 | --- a/td/telegram/Td.cpp 4 | +++ b/td/telegram/Td.cpp 5 | @@ -4419,10 +4419,10 @@ Status Td::set_parameters(td_api::object_ptr parameters 6 | if (options_.application_version.empty()) { 7 | return Status::Error(400, "Application version must be non-empty"); 8 | } 9 | - if (options_.api_id != 21724) { 10 | - options_.application_version += ", TDLib "; 11 | - options_.application_version += TDLIB_VERSION; 12 | - } 13 | + // if (options_.api_id != 21724) { 14 | + // options_.application_version += ", TDLib "; 15 | + // options_.application_version += TDLIB_VERSION; 16 | + // } 17 | options_.language_pack = string(); 18 | options_.language_code = string(); 19 | options_.parameters = string(); 20 | -------------------------------------------------------------------------------- /buildenv/tdlib_threadname.patch: -------------------------------------------------------------------------------- 1 | diff --git a/tdutils/td/utils/port/detail/ThreadStl.h b/tdutils/td/utils/port/detail/ThreadStl.h 2 | index ef6ff475..c0e18ee4 100644 3 | --- a/tdutils/td/utils/port/detail/ThreadStl.h 4 | +++ b/tdutils/td/utils/port/detail/ThreadStl.h 5 | @@ -41,6 +41,7 @@ class ThreadStl { 6 | invoke_tuple(std::move(args)); 7 | clear_thread_locals(); 8 | }); 9 | + pthread_setname_np(thread_.native_handle(), "tdlib"); 10 | } 11 | 12 | void join() { 13 | -------------------------------------------------------------------------------- /buildenv/tg2sip.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=tg2sip 3 | Exec=tg2sip 4 | Comment=TG2SIP Voice Gateway 5 | Terminal=true 6 | Type=Application 7 | Icon=icon 8 | Categories=AudioVideo; -------------------------------------------------------------------------------- /libtgvoip/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | bin 3 | .idea 4 | build 5 | */Debug/* 6 | */Release/* 7 | 8 | # Build results 9 | [Dd]ebug/ 10 | [Dd]ebugPublic/ 11 | [Rr]elease/ 12 | [Rr]eleases/ 13 | [Pp]review/ 14 | [Pp]roduction/ 15 | x64/ 16 | x86/ 17 | bld/ 18 | [Bb]in/ 19 | [Oo]bj/ 20 | DerivedData/ 21 | 22 | # Visual Studio 2015 cache/options directory 23 | .vs/ 24 | 25 | xcuserdata/ 26 | autom4te.cache/ -------------------------------------------------------------------------------- /libtgvoip/BlockingQueue.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #include "BlockingQueue.h" 8 | 9 | using namespace tgvoip; 10 | 11 | -------------------------------------------------------------------------------- /libtgvoip/CongestionControl.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_CONGESTIONCONTROL_H 8 | #define LIBTGVOIP_CONGESTIONCONTROL_H 9 | 10 | #include 11 | #include 12 | #include "threading.h" 13 | #include "Buffers.h" 14 | 15 | #define TGVOIP_CONCTL_ACT_INCREASE 1 16 | #define TGVOIP_CONCTL_ACT_DECREASE 2 17 | #define TGVOIP_CONCTL_ACT_NONE 0 18 | 19 | namespace tgvoip{ 20 | 21 | struct tgvoip_congestionctl_packet_t{ 22 | uint32_t seq; 23 | double sendTime; 24 | size_t size; 25 | }; 26 | typedef struct tgvoip_congestionctl_packet_t tgvoip_congestionctl_packet_t; 27 | 28 | class CongestionControl{ 29 | public: 30 | CongestionControl(); 31 | ~CongestionControl(); 32 | 33 | void PacketSent(uint32_t seq, size_t size); 34 | void PacketAcknowledged(uint32_t seq); 35 | 36 | double GetAverageRTT(); 37 | double GetMinimumRTT(); 38 | size_t GetInflightDataSize(); 39 | size_t GetCongestionWindow(); 40 | size_t GetAcknowledgedDataSize(); 41 | void Tick(); 42 | int GetBandwidthControlAction(); 43 | uint32_t GetSendLossCount(); 44 | 45 | private: 46 | HistoricBuffer rttHistory; 47 | HistoricBuffer inflightHistory; 48 | tgvoip_congestionctl_packet_t inflightPackets[100]; 49 | uint32_t lossCount; 50 | double tmpRtt; 51 | double lastActionTime; 52 | double lastActionRtt; 53 | double stateTransitionTime; 54 | int tmpRttCount; 55 | uint32_t lastSentSeq; 56 | uint32_t tickCount; 57 | size_t inflightDataSize; 58 | size_t cwnd; 59 | Mutex mutex; 60 | }; 61 | } 62 | 63 | #endif //LIBTGVOIP_CONGESTIONCONTROL_H 64 | -------------------------------------------------------------------------------- /libtgvoip/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /libtgvoip/MessageThread.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Grishka on 17.06.2018. 3 | // 4 | 5 | #ifndef LIBTGVOIP_MESSAGETHREAD_H 6 | #define LIBTGVOIP_MESSAGETHREAD_H 7 | 8 | #include "threading.h" 9 | #include "utils.h" 10 | #include 11 | #include 12 | 13 | namespace tgvoip{ 14 | class MessageThread : public Thread{ 15 | public: 16 | TGVOIP_DISALLOW_COPY_AND_ASSIGN(MessageThread); 17 | MessageThread(); 18 | virtual ~MessageThread(); 19 | uint32_t Post(std::function func, double delay=0, double interval=0); 20 | void Cancel(uint32_t id); 21 | void CancelSelf(); 22 | void Stop(); 23 | 24 | enum{ 25 | INVALID_ID=0 26 | }; 27 | private: 28 | struct Message{ 29 | uint32_t id; 30 | double deliverAt; 31 | double interval; 32 | std::function func; 33 | }; 34 | 35 | void Run(); 36 | void InsertMessageInternal(Message& m); 37 | 38 | bool running=true; 39 | std::vector queue; 40 | Mutex queueMutex; 41 | uint32_t lastMessageID=1; 42 | bool cancelCurrent=false; 43 | 44 | #ifdef _WIN32 45 | HANDLE event; 46 | #else 47 | pthread_cond_t cond; 48 | #endif 49 | }; 50 | } 51 | 52 | #endif //LIBTGVOIP_MESSAGETHREAD_H 53 | -------------------------------------------------------------------------------- /libtgvoip/PacketReassembler.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Grishka on 19.03.2018. 3 | // 4 | 5 | #ifndef TGVOIP_PACKETREASSEMBLER_H 6 | #define TGVOIP_PACKETREASSEMBLER_H 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "Buffers.h" 13 | 14 | namespace tgvoip { 15 | class PacketReassembler{ 16 | public: 17 | PacketReassembler(); 18 | virtual ~PacketReassembler(); 19 | 20 | void Reset(); 21 | void AddFragment(Buffer pkt, unsigned int fragmentIndex, unsigned int fragmentCount, uint32_t pts, bool keyframe); 22 | void SetCallback(std::function callback); 23 | 24 | private: 25 | uint32_t currentTimestamp; 26 | unsigned int currentPacketPartCount=0; 27 | std::array parts; 28 | std::function callback; 29 | bool currentIsKeyframe; 30 | unsigned int receivedPartCount=0; 31 | }; 32 | } 33 | 34 | #endif //TGVOIP_PACKETREASSEMBLER_H 35 | -------------------------------------------------------------------------------- /libtgvoip/UNLICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to -------------------------------------------------------------------------------- /libtgvoip/VoIPServerConfig.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef TGVOIP_VOIPSERVERCONFIG_H 8 | #define TGVOIP_VOIPSERVERCONFIG_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include "threading.h" 14 | #include "json11.hpp" 15 | 16 | namespace tgvoip{ 17 | 18 | class ServerConfig{ 19 | public: 20 | ServerConfig(); 21 | ~ServerConfig(); 22 | static ServerConfig* GetSharedInstance(); 23 | int32_t GetInt(std::string name, int32_t fallback); 24 | double GetDouble(std::string name, double fallback); 25 | std::string GetString(std::string name, std::string fallback); 26 | bool GetBoolean(std::string name, bool fallback); 27 | void Update(std::string jsonString); 28 | 29 | private: 30 | static ServerConfig* sharedInstance; 31 | bool ContainsKey(std::string key); 32 | json11::Json config; 33 | Mutex mutex; 34 | }; 35 | } 36 | 37 | #endif //TGVOIP_VOIPSERVERCONFIG_H 38 | -------------------------------------------------------------------------------- /libtgvoip/audio/AudioIO.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | 8 | #ifndef LIBTGVOIP_AUDIOIO_H 9 | #define LIBTGVOIP_AUDIOIO_H 10 | 11 | #include "AudioInput.h" 12 | #include "AudioOutput.h" 13 | #include "../utils.h" 14 | #include 15 | #include 16 | 17 | namespace tgvoip{ 18 | namespace audio { 19 | class AudioIO{ 20 | public: 21 | AudioIO(){}; 22 | virtual ~AudioIO(){}; 23 | TGVOIP_DISALLOW_COPY_AND_ASSIGN(AudioIO); 24 | static AudioIO* Create(std::string inputDevice, std::string outputDevice); 25 | virtual AudioInput* GetInput()=0; 26 | virtual AudioOutput* GetOutput()=0; 27 | bool Failed(); 28 | std::string GetErrorDescription(); 29 | protected: 30 | bool failed=false; 31 | std::string error; 32 | }; 33 | 34 | template class ContextlessAudioIO : public AudioIO{ 35 | public: 36 | ContextlessAudioIO(){ 37 | input=new I(); 38 | output=new O(); 39 | } 40 | 41 | ContextlessAudioIO(std::string inputDeviceID, std::string outputDeviceID){ 42 | input=new I(inputDeviceID); 43 | output=new O(outputDeviceID); 44 | } 45 | 46 | virtual ~ContextlessAudioIO(){ 47 | delete input; 48 | delete output; 49 | } 50 | 51 | virtual AudioInput* GetInput(){ 52 | return input; 53 | } 54 | 55 | virtual AudioOutput* GetOutput(){ 56 | return output; 57 | } 58 | private: 59 | I* input; 60 | O* output; 61 | }; 62 | } 63 | } 64 | 65 | #endif //LIBTGVOIP_AUDIOIO_H 66 | -------------------------------------------------------------------------------- /libtgvoip/audio/AudioInput.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOINPUT_H 8 | #define LIBTGVOIP_AUDIOINPUT_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include "../MediaStreamItf.h" 14 | 15 | namespace tgvoip{ 16 | 17 | class AudioInputDevice; 18 | class AudioOutputDevice; 19 | 20 | namespace audio{ 21 | class AudioInput : public MediaStreamItf{ 22 | public: 23 | AudioInput(); 24 | AudioInput(std::string deviceID); 25 | virtual ~AudioInput(); 26 | 27 | bool IsInitialized(); 28 | virtual std::string GetCurrentDevice(); 29 | virtual void SetCurrentDevice(std::string deviceID); 30 | //static AudioInput* Create(std::string deviceID, void* platformSpecific); 31 | static void EnumerateDevices(std::vector& devs); 32 | static int32_t GetEstimatedDelay(); 33 | 34 | protected: 35 | std::string currentDevice; 36 | bool failed; 37 | static int32_t estimatedDelay; 38 | }; 39 | }} 40 | 41 | #endif //LIBTGVOIP_AUDIOINPUT_H 42 | -------------------------------------------------------------------------------- /libtgvoip/audio/AudioOutput.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOOUTPUT_H 8 | #define LIBTGVOIP_AUDIOOUTPUT_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "../MediaStreamItf.h" 15 | 16 | namespace tgvoip{ 17 | 18 | class AudioInputDevice; 19 | class AudioOutputDevice; 20 | 21 | namespace audio{ 22 | class AudioOutput : public MediaStreamItf{ 23 | public: 24 | AudioOutput(); 25 | AudioOutput(std::string deviceID); 26 | virtual ~AudioOutput(); 27 | virtual bool IsPlaying()=0; 28 | static int32_t GetEstimatedDelay(); 29 | virtual std::string GetCurrentDevice(); 30 | virtual void SetCurrentDevice(std::string deviceID); 31 | //static std::unique_ptr Create(std::string deviceID, void* platformSpecific); 32 | static void EnumerateDevices(std::vector& devs); 33 | bool IsInitialized(); 34 | 35 | protected: 36 | std::string currentDevice; 37 | bool failed; 38 | static int32_t estimatedDelay; 39 | }; 40 | }} 41 | 42 | #endif //LIBTGVOIP_AUDIOOUTPUT_H 43 | -------------------------------------------------------------------------------- /libtgvoip/audio/Resampler.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Grishka on 01.04.17. 3 | // 4 | 5 | #ifndef LIBTGVOIP_RESAMPLER_H 6 | #define LIBTGVOIP_RESAMPLER_H 7 | 8 | #include 9 | #include 10 | 11 | namespace tgvoip{ namespace audio{ 12 | class Resampler{ 13 | public: 14 | static size_t Convert48To44(int16_t* from, int16_t* to, size_t fromLen, size_t toLen); 15 | static size_t Convert44To48(int16_t* from, int16_t* to, size_t fromLen, size_t toLen); 16 | static size_t Convert(int16_t* from, int16_t* to, size_t fromLen, size_t toLen, int num, int denom); 17 | static void Rescale60To80(int16_t* in, int16_t* out); 18 | static void Rescale60To40(int16_t* in, int16_t* out); 19 | }; 20 | }} 21 | 22 | #endif //LIBTGVOIP_RESAMPLER_H 23 | -------------------------------------------------------------------------------- /libtgvoip/audio/SoftwareAudioInput.h: -------------------------------------------------------------------------------- 1 | #ifndef TG2SIP_SOFTWAREAUDIOINPUT_H 2 | #define TG2SIP_SOFTWAREAUDIOINPUT_H 3 | 4 | #include 5 | #include "AudioInput.h" 6 | #include "../threading.h" 7 | 8 | namespace tgvoip { 9 | namespace audio { 10 | class SoftwareAudioInput : public AudioInput, public pj::AudioMedia { 11 | public: 12 | explicit SoftwareAudioInput(); 13 | 14 | virtual ~SoftwareAudioInput(); 15 | 16 | void Start() override; 17 | 18 | void Stop() override; 19 | 20 | private: 21 | static pj_status_t PutFrameCallback(pjmedia_port *port, pjmedia_frame *frame); 22 | 23 | static pj_status_t GetFrameCallback(pjmedia_port *port, pjmedia_frame *frame); 24 | 25 | bool isActive; 26 | 27 | pj_pool_t *pj_pool; 28 | pjmedia_port *media_port; 29 | }; 30 | } 31 | } 32 | 33 | #endif //TG2SIP_SOFTWAREAUDIOINPUT_H -------------------------------------------------------------------------------- /libtgvoip/audio/SoftwareAudioOutput.h: -------------------------------------------------------------------------------- 1 | #ifndef TG2SIP_SOFTWAREAUDIOOUTPUT_H 2 | #define TG2SIP_SOFTWAREAUDIOOUTPUT_H 3 | 4 | #include 5 | #include "AudioOutput.h" 6 | #include "../threading.h" 7 | 8 | namespace tgvoip { 9 | namespace audio { 10 | class SoftwareAudioOutput : public AudioOutput, public pj::AudioMedia { 11 | public: 12 | explicit SoftwareAudioOutput(); 13 | 14 | virtual ~SoftwareAudioOutput(); 15 | 16 | void Start() override; 17 | 18 | void Stop() override; 19 | 20 | virtual bool IsPlaying(); 21 | 22 | private: 23 | static pj_status_t PutFrameCallback(pjmedia_port *port, pjmedia_frame *frame); 24 | 25 | static pj_status_t GetFrameCallback(pjmedia_port *port, pjmedia_frame *frame); 26 | 27 | bool isActive; 28 | 29 | pj_pool_t *pj_pool; 30 | pjmedia_port *media_port; 31 | 32 | bool read_buffer{true}; 33 | unsigned char *buffer; 34 | }; 35 | } 36 | } 37 | 38 | #endif //TG2SIP_SOFTWAREAUDIOOUTPUT_H -------------------------------------------------------------------------------- /libtgvoip/client/android/tg_voip_jni.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Grishka on 14.08.2018. 3 | // 4 | 5 | #ifndef TELEGRAM_TG_VOIP_JNI_H 6 | #define TELEGRAM_TG_VOIP_JNI_H 7 | 8 | #include 9 | 10 | #ifdef __cplusplus 11 | extern "C"{ 12 | #endif 13 | void tgvoipRegisterNatives(JNIEnv* env); 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | 18 | #endif //TELEGRAM_TG_VOIP_JNI_H 19 | -------------------------------------------------------------------------------- /libtgvoip/libtgvoip.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /libtgvoip/libtgvoip_osx.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /libtgvoip/libtgvoip_osx.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /libtgvoip/os/android/AudioInputAndroid.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOINPUTANDROID_H 8 | #define LIBTGVOIP_AUDIOINPUTANDROID_H 9 | 10 | #include 11 | #include "../../audio/AudioInput.h" 12 | #include "../../threading.h" 13 | 14 | namespace tgvoip{ namespace audio{ 15 | class AudioInputAndroid : public AudioInput{ 16 | 17 | public: 18 | AudioInputAndroid(); 19 | virtual ~AudioInputAndroid(); 20 | virtual void Start(); 21 | virtual void Stop(); 22 | void HandleCallback(JNIEnv* env, jobject buffer); 23 | unsigned int GetEnabledEffects(); 24 | static jmethodID initMethod; 25 | static jmethodID releaseMethod; 26 | static jmethodID startMethod; 27 | static jmethodID stopMethod; 28 | static jmethodID getEnabledEffectsMaskMethod; 29 | static jclass jniClass; 30 | 31 | static constexpr unsigned int EFFECT_AEC=1; 32 | static constexpr unsigned int EFFECT_NS=2; 33 | 34 | private: 35 | jobject javaObject; 36 | bool running; 37 | Mutex mutex; 38 | unsigned int enabledEffects=0; 39 | 40 | }; 41 | }} 42 | 43 | #endif //LIBTGVOIP_AUDIOINPUTANDROID_H 44 | -------------------------------------------------------------------------------- /libtgvoip/os/android/AudioInputOpenSLES.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOINPUTOPENSLES_H 8 | #define LIBTGVOIP_AUDIOINPUTOPENSLES_H 9 | 10 | #include 11 | #include 12 | 13 | #include "../../audio/AudioInput.h" 14 | 15 | namespace tgvoip{ namespace audio{ 16 | class AudioInputOpenSLES : public AudioInput{ 17 | 18 | public: 19 | AudioInputOpenSLES(); 20 | virtual ~AudioInputOpenSLES(); 21 | virtual void Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels); 22 | virtual void Start(); 23 | virtual void Stop(); 24 | 25 | static unsigned int nativeBufferSize; 26 | 27 | private: 28 | static void BufferCallback(SLAndroidSimpleBufferQueueItf bq, void *context); 29 | void HandleSLCallback(); 30 | SLEngineItf slEngine; 31 | SLObjectItf slRecorderObj; 32 | SLRecordItf slRecorder; 33 | SLAndroidSimpleBufferQueueItf slBufferQueue; 34 | int16_t* buffer; 35 | int16_t* nativeBuffer; 36 | size_t positionInBuffer; 37 | }; 38 | }} 39 | 40 | #endif //LIBTGVOIP_AUDIOINPUTOPENSLES_H 41 | -------------------------------------------------------------------------------- /libtgvoip/os/android/AudioOutputAndroid.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOOUTPUTANDROID_H 8 | #define LIBTGVOIP_AUDIOOUTPUTANDROID_H 9 | 10 | #include 11 | #include "../../audio/AudioOutput.h" 12 | 13 | namespace tgvoip{ namespace audio{ 14 | class AudioOutputAndroid : public AudioOutput{ 15 | 16 | public: 17 | 18 | AudioOutputAndroid(); 19 | virtual ~AudioOutputAndroid(); 20 | virtual void Start(); 21 | virtual void Stop(); 22 | virtual bool IsPlaying() override; 23 | void HandleCallback(JNIEnv* env, jbyteArray buffer); 24 | static jmethodID initMethod; 25 | static jmethodID releaseMethod; 26 | static jmethodID startMethod; 27 | static jmethodID stopMethod; 28 | static jclass jniClass; 29 | 30 | private: 31 | jobject javaObject; 32 | bool running; 33 | 34 | }; 35 | }} 36 | 37 | #endif //LIBTGVOIP_AUDIOOUTPUTANDROID_H 38 | -------------------------------------------------------------------------------- /libtgvoip/os/android/AudioOutputOpenSLES.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOOUTPUTOPENSLES_H 8 | #define LIBTGVOIP_AUDIOOUTPUTOPENSLES_H 9 | 10 | #include 11 | #include 12 | 13 | #include "../../audio/AudioOutput.h" 14 | 15 | namespace tgvoip{ namespace audio{ 16 | class AudioOutputOpenSLES : public AudioOutput{ 17 | public: 18 | AudioOutputOpenSLES(); 19 | virtual ~AudioOutputOpenSLES(); 20 | virtual void Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels); 21 | virtual bool IsPhone(); 22 | virtual void EnableLoudspeaker(bool enabled); 23 | virtual void Start(); 24 | virtual void Stop(); 25 | virtual bool IsPlaying(); 26 | virtual float GetLevel(); 27 | 28 | static void SetNativeBufferSize(unsigned int size); 29 | static unsigned int nativeBufferSize; 30 | 31 | private: 32 | static void BufferCallback(SLAndroidSimpleBufferQueueItf bq, void *context); 33 | void HandleSLCallback(); 34 | SLEngineItf slEngine; 35 | SLObjectItf slPlayerObj; 36 | SLObjectItf slOutputMixObj; 37 | SLPlayItf slPlayer; 38 | SLAndroidSimpleBufferQueueItf slBufferQueue; 39 | int16_t* buffer; 40 | int16_t* nativeBuffer; 41 | bool stopped; 42 | unsigned char remainingData[10240]; 43 | size_t remainingDataSize; 44 | }; 45 | }} 46 | 47 | #endif //LIBTGVOIP_AUDIOOUTPUTANDROID_H 48 | -------------------------------------------------------------------------------- /libtgvoip/os/android/JNIUtilities.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Grishka on 15.08.2018. 3 | // 4 | 5 | #ifndef LIBTGVOIP_JNIUTILITIES_H 6 | #define LIBTGVOIP_JNIUTILITIES_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "../../Buffers.h" 13 | 14 | extern JavaVM* sharedJVM; 15 | 16 | namespace tgvoip{ 17 | namespace jni{ 18 | 19 | inline void DoWithJNI(std::function f){ 20 | JNIEnv *env=NULL; 21 | bool didAttach=false; 22 | sharedJVM->GetEnv((void **) &env, JNI_VERSION_1_6); 23 | if(!env){ 24 | sharedJVM->AttachCurrentThread(&env, NULL); 25 | didAttach=true; 26 | } 27 | 28 | f(env); 29 | 30 | if(didAttach){ 31 | sharedJVM->DetachCurrentThread(); 32 | } 33 | } 34 | 35 | inline void AttachAndCallVoidMethod(jmethodID method, jobject obj, ...){ 36 | if(!method || !obj) 37 | return; 38 | va_list va; 39 | va_start(va, obj); 40 | DoWithJNI([&va, method, obj](JNIEnv* env){ 41 | env->CallVoidMethodV(obj, method, va); 42 | }); 43 | va_end(va); 44 | } 45 | 46 | inline std::string JavaStringToStdString(JNIEnv* env, jstring jstr){ 47 | if(!jstr) 48 | return ""; 49 | const char* jchars=env->GetStringUTFChars(jstr, NULL); 50 | std::string str(jchars); 51 | env->ReleaseStringUTFChars(jstr, jchars); 52 | return str; 53 | } 54 | 55 | inline jbyteArray BufferToByteArray(JNIEnv* env, Buffer& buf){ 56 | jbyteArray arr=env->NewByteArray((jsize)buf.Length()); 57 | jbyte* elements=env->GetByteArrayElements(arr, NULL); 58 | memcpy(elements, *buf, buf.Length()); 59 | env->ReleaseByteArrayElements(arr, elements, 0); 60 | return arr; 61 | } 62 | 63 | } 64 | } 65 | 66 | #endif //LIBTGVOIP_JNIUTILITIES_H 67 | -------------------------------------------------------------------------------- /libtgvoip/os/android/OpenSLEngineWrapper.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #include 8 | #include "OpenSLEngineWrapper.h" 9 | #include "../../logging.h" 10 | 11 | #define CHECK_SL_ERROR(res, msg) if(res!=SL_RESULT_SUCCESS){ LOGE(msg); return NULL; } 12 | 13 | using namespace tgvoip; 14 | using namespace tgvoip::audio; 15 | 16 | 17 | SLObjectItf OpenSLEngineWrapper::sharedEngineObj=NULL; 18 | SLEngineItf OpenSLEngineWrapper::sharedEngine=NULL; 19 | int OpenSLEngineWrapper::count=0; 20 | 21 | void OpenSLEngineWrapper::DestroyEngine(){ 22 | count--; 23 | LOGI("release: engine instance count %d", count); 24 | if(count==0){ 25 | (*sharedEngineObj)->Destroy(sharedEngineObj); 26 | sharedEngineObj=NULL; 27 | sharedEngine=NULL; 28 | } 29 | LOGI("after release"); 30 | } 31 | 32 | SLEngineItf OpenSLEngineWrapper::CreateEngine(){ 33 | count++; 34 | if(sharedEngine) 35 | return sharedEngine; 36 | const SLInterfaceID pIDs[1] = {SL_IID_ENGINE}; 37 | const SLboolean pIDsRequired[1] = {SL_BOOLEAN_TRUE}; 38 | SLresult result = slCreateEngine(&sharedEngineObj, 0, NULL, 1, pIDs, pIDsRequired); 39 | CHECK_SL_ERROR(result, "Error creating engine"); 40 | 41 | result=(*sharedEngineObj)->Realize(sharedEngineObj, SL_BOOLEAN_FALSE); 42 | CHECK_SL_ERROR(result, "Error realizing engine"); 43 | 44 | result = (*sharedEngineObj)->GetInterface(sharedEngineObj, SL_IID_ENGINE, &sharedEngine); 45 | CHECK_SL_ERROR(result, "Error getting engine interface"); 46 | return sharedEngine; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /libtgvoip/os/android/OpenSLEngineWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_OPENSLENGINEWRAPPER_H 8 | #define LIBTGVOIP_OPENSLENGINEWRAPPER_H 9 | 10 | #include 11 | #include 12 | 13 | namespace tgvoip{ namespace audio{ 14 | class OpenSLEngineWrapper{ 15 | public: 16 | static SLEngineItf CreateEngine(); 17 | static void DestroyEngine(); 18 | 19 | private: 20 | static SLObjectItf sharedEngineObj; 21 | static SLEngineItf sharedEngine; 22 | static int count; 23 | }; 24 | }} 25 | 26 | #endif //LIBTGVOIP_OPENSLENGINEWRAPPER_H 27 | -------------------------------------------------------------------------------- /libtgvoip/os/android/VideoRendererAndroid.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Grishka on 12.08.2018. 3 | // 4 | 5 | #ifndef LIBTGVOIP_VIDEORENDERERANDROID_H 6 | #define LIBTGVOIP_VIDEORENDERERANDROID_H 7 | 8 | #include "../../video/VideoRenderer.h" 9 | #include "../../MessageThread.h" 10 | 11 | #include 12 | #include "../../BlockingQueue.h" 13 | 14 | namespace tgvoip{ 15 | namespace video{ 16 | class VideoRendererAndroid : public VideoRenderer{ 17 | public: 18 | VideoRendererAndroid(jobject jobj); 19 | virtual ~VideoRendererAndroid(); 20 | virtual void Reset(uint32_t codec, unsigned int width, unsigned int height, std::vector& csd) override; 21 | virtual void DecodeAndDisplay(Buffer frame, uint32_t pts) override; 22 | virtual void SetStreamEnabled(bool enabled) override; 23 | 24 | static jmethodID resetMethod; 25 | static jmethodID decodeAndDisplayMethod; 26 | static jmethodID setStreamEnabledMethod; 27 | static std::vector availableDecoders; 28 | static int maxResolution; 29 | private: 30 | void RunThread(); 31 | Thread* thread=NULL; 32 | bool running=true; 33 | BlockingQueue queue; 34 | std::vector csd; 35 | int width; 36 | int height; 37 | uint32_t codec; 38 | jobject jobj; 39 | }; 40 | } 41 | } 42 | 43 | #endif //LIBTGVOIP_VIDEORENDERERANDROID_H 44 | -------------------------------------------------------------------------------- /libtgvoip/os/android/VideoSourceAndroid.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Grishka on 12.08.2018. 3 | // 4 | 5 | #ifndef LIBTGVOIP_VIDEOSOURCEANDROID_H 6 | #define LIBTGVOIP_VIDEOSOURCEANDROID_H 7 | 8 | #include "../../video/VideoSource.h" 9 | #include "../../Buffers.h" 10 | #include 11 | #include 12 | 13 | namespace tgvoip{ 14 | namespace video{ 15 | class VideoSourceAndroid : public VideoSource{ 16 | public: 17 | VideoSourceAndroid(jobject jobj); 18 | virtual ~VideoSourceAndroid(); 19 | virtual void Start() override; 20 | virtual void Stop() override; 21 | virtual void Reset(uint32_t codec, int maxResolution) override; 22 | void SendFrame(Buffer frame, uint32_t flags); 23 | void SetStreamParameters(std::vector csd, unsigned int width, unsigned int height); 24 | virtual void RequestKeyFrame() override; 25 | 26 | static std::vector availableEncoders; 27 | private: 28 | jobject javaObject; 29 | jmethodID prepareEncoderMethod; 30 | jmethodID startMethod; 31 | jmethodID stopMethod; 32 | jmethodID requestKeyFrameMethod; 33 | }; 34 | } 35 | } 36 | 37 | 38 | #endif //LIBTGVOIP_VIDEOSOURCEANDROID_H 39 | -------------------------------------------------------------------------------- /libtgvoip/os/darwin/AudioInputAudioUnit.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOINPUTAUDIOUNIT_H 8 | #define LIBTGVOIP_AUDIOINPUTAUDIOUNIT_H 9 | 10 | #include 11 | #include "../../audio/AudioInput.h" 12 | #include "../../utils.h" 13 | 14 | namespace tgvoip{ namespace audio{ 15 | class AudioUnitIO; 16 | 17 | class AudioInputAudioUnit : public AudioInput{ 18 | 19 | public: 20 | TGVOIP_DISALLOW_COPY_AND_ASSIGN(AudioInputAudioUnit); 21 | AudioInputAudioUnit(std::string deviceID, AudioUnitIO* io); 22 | virtual ~AudioInputAudioUnit(); 23 | virtual void Start(); 24 | virtual void Stop(); 25 | void HandleBufferCallback(AudioBufferList* ioData); 26 | #if TARGET_OS_OSX 27 | virtual void SetCurrentDevice(std::string deviceID); 28 | #endif 29 | 30 | private: 31 | unsigned char remainingData[10240]; 32 | size_t remainingDataSize; 33 | bool isRecording; 34 | AudioUnitIO* io; 35 | }; 36 | }} 37 | 38 | #endif //LIBTGVOIP_AUDIOINPUTAUDIOUNIT_H 39 | -------------------------------------------------------------------------------- /libtgvoip/os/darwin/AudioInputAudioUnitOSX.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOINPUTAUDIOUNIT_OSX_H 8 | #define LIBTGVOIP_AUDIOINPUTAUDIOUNIT_OSX_H 9 | 10 | #include 11 | #import 12 | #import 13 | #include "../../audio/AudioInput.h" 14 | 15 | namespace tgvoip{ namespace audio{ 16 | class AudioInputAudioUnitLegacy : public AudioInput{ 17 | 18 | public: 19 | AudioInputAudioUnitLegacy(std::string deviceID); 20 | virtual ~AudioInputAudioUnitLegacy(); 21 | virtual void Start(); 22 | virtual void Stop(); 23 | void HandleBufferCallback(AudioBufferList* ioData); 24 | static void EnumerateDevices(std::vector& devs); 25 | virtual void SetCurrentDevice(std::string deviceID); 26 | 27 | private: 28 | static OSStatus BufferCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData); 29 | static OSStatus DefaultDeviceChangedCallback(AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses, void *inClientData); 30 | unsigned char remainingData[10240]; 31 | size_t remainingDataSize; 32 | bool isRecording; 33 | AudioUnit unit; 34 | AudioBufferList inBufferList; 35 | int hardwareSampleRate; 36 | }; 37 | }} 38 | 39 | #endif //LIBTGVOIP_AUDIOINPUTAUDIOUNIT_OSX_H 40 | -------------------------------------------------------------------------------- /libtgvoip/os/darwin/AudioOutputAudioUnit.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOOUTPUTAUDIOUNIT_H 8 | #define LIBTGVOIP_AUDIOOUTPUTAUDIOUNIT_H 9 | 10 | #include 11 | #include "../../audio/AudioOutput.h" 12 | #include "../../utils.h" 13 | 14 | namespace tgvoip{ namespace audio{ 15 | class AudioUnitIO; 16 | 17 | class AudioOutputAudioUnit : public AudioOutput{ 18 | public: 19 | TGVOIP_DISALLOW_COPY_AND_ASSIGN(AudioOutputAudioUnit); 20 | AudioOutputAudioUnit(std::string deviceID, AudioUnitIO* io); 21 | virtual ~AudioOutputAudioUnit(); 22 | virtual void Start(); 23 | virtual void Stop(); 24 | virtual bool IsPlaying(); 25 | void HandleBufferCallback(AudioBufferList* ioData); 26 | #if TARGET_OS_OSX 27 | virtual void SetCurrentDevice(std::string deviceID); 28 | #endif 29 | 30 | private: 31 | bool isPlaying; 32 | unsigned char remainingData[10240]; 33 | size_t remainingDataSize; 34 | AudioUnitIO* io; 35 | }; 36 | }} 37 | 38 | #endif //LIBTGVOIP_AUDIOOUTPUTAUDIOUNIT_H 39 | -------------------------------------------------------------------------------- /libtgvoip/os/darwin/AudioOutputAudioUnitOSX.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOOUTPUTAUDIOUNIT_OSX_H 8 | #define LIBTGVOIP_AUDIOOUTPUTAUDIOUNIT_OSX_H 9 | 10 | #include 11 | #import 12 | #import 13 | #include "../../audio/AudioOutput.h" 14 | 15 | namespace tgvoip{ namespace audio{ 16 | class AudioOutputAudioUnitLegacy : public AudioOutput{ 17 | 18 | public: 19 | AudioOutputAudioUnitLegacy(std::string deviceID); 20 | virtual ~AudioOutputAudioUnitLegacy(); 21 | virtual void Start(); 22 | virtual void Stop(); 23 | virtual bool IsPlaying(); 24 | void HandleBufferCallback(AudioBufferList* ioData); 25 | static void EnumerateDevices(std::vector& devs); 26 | virtual void SetCurrentDevice(std::string deviceID); 27 | 28 | private: 29 | static OSStatus BufferCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData); 30 | static OSStatus DefaultDeviceChangedCallback(AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses, void *inClientData); 31 | void SetPanRight(bool panRight); 32 | unsigned char remainingData[10240]; 33 | size_t remainingDataSize; 34 | bool isPlaying; 35 | AudioUnit unit; 36 | int hardwareSampleRate; 37 | bool isMacBookPro; 38 | AudioDeviceID sysDevID; 39 | }; 40 | }} 41 | 42 | #endif //LIBTGVOIP_AUDIOOUTPUTAUDIOUNIT_OSX_H 43 | -------------------------------------------------------------------------------- /libtgvoip/os/darwin/DarwinSpecific.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef TGVOIP_DARWINSPECIFIC_H 8 | #define TGVOIP_DARWINSPECIFIC_H 9 | 10 | #include 11 | 12 | namespace tgvoip { 13 | 14 | struct CellularCarrierInfo; 15 | 16 | class DarwinSpecific{ 17 | public: 18 | enum{ 19 | THREAD_PRIO_USER_INTERACTIVE, 20 | THREAD_PRIO_USER_INITIATED, 21 | THREAD_PRIO_UTILITY, 22 | THREAD_PRIO_BACKGROUND, 23 | THREAD_PRIO_DEFAULT 24 | }; 25 | static void GetSystemName(char* buf, size_t len); 26 | static void SetCurrentThreadPriority(int priority); 27 | static CellularCarrierInfo GetCarrierInfo(); 28 | static void ConfigureAudioSession(); 29 | }; 30 | } 31 | 32 | #endif //TGVOIP_DARWINSPECIFIC_H 33 | -------------------------------------------------------------------------------- /libtgvoip/os/darwin/SetupLogging.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | extern void (*TGVoipLoggingFunction)(NSString *); 4 | -------------------------------------------------------------------------------- /libtgvoip/os/darwin/TGLogWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef TGVOIP_TGLOGWRAPPER_H 8 | #define TGVOIP_TGLOGWRAPPER_H 9 | 10 | #if defined __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | void __tgvoip_call_tglog(const char* format, ...); 15 | 16 | #if defined __cplusplus 17 | }; 18 | #endif 19 | 20 | #endif //TGVOIP_TGLOGWRAPPER_H 21 | -------------------------------------------------------------------------------- /libtgvoip/os/darwin/TGLogWrapper.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | void (*TGVoipLoggingFunction)(NSString *) = NULL; 4 | 5 | void __tgvoip_call_tglog(const char* format, ...){ 6 | va_list args; 7 | va_start(args, format); 8 | NSString *string = [[NSString alloc] initWithFormat:[[NSString alloc]initWithUTF8String:format] arguments:args]; 9 | va_end(args); 10 | if (TGVoipLoggingFunction) { 11 | TGVoipLoggingFunction(string); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /libtgvoip/os/linux/AudioInputALSA.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOINPUTALSA_H 8 | #define LIBTGVOIP_AUDIOINPUTALSA_H 9 | 10 | #include "../../audio/AudioInput.h" 11 | #include "../../threading.h" 12 | #include 13 | 14 | namespace tgvoip{ 15 | namespace audio{ 16 | 17 | class AudioInputALSA : public AudioInput{ 18 | 19 | public: 20 | AudioInputALSA(std::string devID); 21 | virtual ~AudioInputALSA(); 22 | virtual void Start(); 23 | virtual void Stop(); 24 | virtual void SetCurrentDevice(std::string devID); 25 | static void EnumerateDevices(std::vector& devs); 26 | 27 | private: 28 | void RunThread(); 29 | 30 | int (*_snd_pcm_open)(snd_pcm_t** pcm, const char* name, snd_pcm_stream_t stream, int mode); 31 | int (*_snd_pcm_set_params)(snd_pcm_t* pcm, snd_pcm_format_t format, snd_pcm_access_t access, unsigned int channels, unsigned int rate, int soft_resample, unsigned int latency); 32 | int (*_snd_pcm_close)(snd_pcm_t* pcm); 33 | snd_pcm_sframes_t (*_snd_pcm_readi)(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size); 34 | int (*_snd_pcm_recover)(snd_pcm_t* pcm, int err, int silent); 35 | const char* (*_snd_strerror)(int errnum); 36 | void* lib; 37 | 38 | snd_pcm_t* handle; 39 | Thread* thread; 40 | bool isRecording; 41 | }; 42 | 43 | } 44 | } 45 | 46 | #endif //LIBTGVOIP_AUDIOINPUTALSA_H 47 | -------------------------------------------------------------------------------- /libtgvoip/os/linux/AudioInputPulse.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOINPUTPULSE_H 8 | #define LIBTGVOIP_AUDIOINPUTPULSE_H 9 | 10 | #include "../../audio/AudioInput.h" 11 | #include "../../threading.h" 12 | #include 13 | 14 | #define DECLARE_DL_FUNCTION(name) typeof(name)* _import_##name 15 | 16 | namespace tgvoip{ 17 | namespace audio{ 18 | 19 | class AudioInputPulse : public AudioInput{ 20 | public: 21 | AudioInputPulse(pa_context* context, pa_threaded_mainloop* mainloop, std::string devID); 22 | virtual ~AudioInputPulse(); 23 | virtual void Start(); 24 | virtual void Stop(); 25 | virtual bool IsRecording(); 26 | virtual void SetCurrentDevice(std::string devID); 27 | static bool EnumerateDevices(std::vector& devs); 28 | 29 | private: 30 | static void StreamStateCallback(pa_stream* s, void* arg); 31 | static void StreamReadCallback(pa_stream* stream, size_t requested_bytes, void* userdata); 32 | void StreamReadCallback(pa_stream* stream, size_t requestedBytes); 33 | pa_stream* CreateAndInitStream(); 34 | 35 | pa_threaded_mainloop* mainloop; 36 | pa_context* context; 37 | pa_stream* stream; 38 | 39 | bool isRecording; 40 | bool isConnected; 41 | bool didStart; 42 | bool isLocked; 43 | unsigned char remainingData[960*8*2]; 44 | size_t remainingDataSize; 45 | }; 46 | 47 | } 48 | } 49 | 50 | #undef DECLARE_DL_FUNCTION 51 | 52 | #endif //LIBTGVOIP_AUDIOINPUTPULSE_H 53 | -------------------------------------------------------------------------------- /libtgvoip/os/linux/AudioOutputALSA.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOOUTPUTALSA_H 8 | #define LIBTGVOIP_AUDIOOUTPUTALSA_H 9 | 10 | #include "../../audio/AudioOutput.h" 11 | #include "../../threading.h" 12 | #include 13 | 14 | namespace tgvoip{ 15 | namespace audio{ 16 | 17 | class AudioOutputALSA : public AudioOutput{ 18 | public: 19 | AudioOutputALSA(std::string devID); 20 | virtual ~AudioOutputALSA(); 21 | virtual void Start(); 22 | virtual void Stop(); 23 | virtual bool IsPlaying(); 24 | virtual void SetCurrentDevice(std::string devID); 25 | static void EnumerateDevices(std::vector& devs); 26 | 27 | private: 28 | void RunThread(); 29 | 30 | int (*_snd_pcm_open)(snd_pcm_t** pcm, const char* name, snd_pcm_stream_t stream, int mode); 31 | int (*_snd_pcm_set_params)(snd_pcm_t* pcm, snd_pcm_format_t format, snd_pcm_access_t access, unsigned int channels, unsigned int rate, int soft_resample, unsigned int latency); 32 | int (*_snd_pcm_close)(snd_pcm_t* pcm); 33 | snd_pcm_sframes_t (*_snd_pcm_writei)(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size); 34 | int (*_snd_pcm_recover)(snd_pcm_t* pcm, int err, int silent); 35 | const char* (*_snd_strerror)(int errnum); 36 | void* lib; 37 | 38 | snd_pcm_t* handle; 39 | Thread* thread; 40 | bool isPlaying; 41 | }; 42 | 43 | } 44 | } 45 | 46 | #endif //LIBTGVOIP_AUDIOOUTPUTALSA_H 47 | -------------------------------------------------------------------------------- /libtgvoip/os/linux/AudioOutputPulse.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOOUTPUTPULSE_H 8 | #define LIBTGVOIP_AUDIOOUTPUTPULSE_H 9 | 10 | #include "../../audio/AudioOutput.h" 11 | #include "../../threading.h" 12 | #include 13 | 14 | namespace tgvoip{ 15 | namespace audio{ 16 | 17 | class AudioOutputPulse : public AudioOutput{ 18 | public: 19 | AudioOutputPulse(pa_context* context, pa_threaded_mainloop* mainloop, std::string devID); 20 | virtual ~AudioOutputPulse(); 21 | virtual void Start(); 22 | virtual void Stop(); 23 | virtual bool IsPlaying(); 24 | virtual void SetCurrentDevice(std::string devID); 25 | static bool EnumerateDevices(std::vector& devs); 26 | 27 | private: 28 | static void StreamStateCallback(pa_stream* s, void* arg); 29 | static void StreamWriteCallback(pa_stream* stream, size_t requested_bytes, void* userdata); 30 | void StreamWriteCallback(pa_stream* stream, size_t requestedBytes); 31 | pa_stream* CreateAndInitStream(); 32 | 33 | pa_threaded_mainloop* mainloop; 34 | pa_context* context; 35 | pa_stream* stream; 36 | 37 | bool isPlaying; 38 | bool isConnected; 39 | bool didStart; 40 | bool isLocked; 41 | unsigned char remainingData[960*8*2]; 42 | size_t remainingDataSize; 43 | }; 44 | 45 | } 46 | } 47 | 48 | #endif //LIBTGVOIP_AUDIOOUTPUTPULSE_H 49 | -------------------------------------------------------------------------------- /libtgvoip/os/windows/AudioInputWave.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOINPUTWAVE_H 8 | #define LIBTGVOIP_AUDIOINPUTWAVE_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include "../../audio/AudioInput.h" 14 | 15 | namespace tgvoip{ 16 | namespace audio{ 17 | 18 | class AudioInputWave : public AudioInput{ 19 | 20 | public: 21 | AudioInputWave(std::string deviceID); 22 | virtual ~AudioInputWave(); 23 | virtual void Start(); 24 | virtual void Stop(); 25 | virtual void SetCurrentDevice(std::string deviceID); 26 | static void EnumerateDevices(std::vector& devs); 27 | 28 | private: 29 | static void CALLBACK WaveInProc(HWAVEIN hwi, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2); 30 | void OnData(WAVEHDR* hdr); 31 | HWAVEIN hWaveIn; 32 | WAVEFORMATEX format; 33 | WAVEHDR buffers[4]; 34 | bool isRecording; 35 | }; 36 | 37 | } 38 | } 39 | 40 | #endif //LIBTGVOIP_AUDIOINPUTWAVE_H 41 | -------------------------------------------------------------------------------- /libtgvoip/os/windows/AudioOutputWave.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_AUDIOOUTPUTWAVE_H 8 | #define LIBTGVOIP_AUDIOOUTPUTWAVE_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include "../../audio/AudioOutput.h" 14 | 15 | namespace tgvoip{ 16 | namespace audio{ 17 | 18 | class AudioOutputWave : public AudioOutput{ 19 | public: 20 | AudioOutputWave(std::string deviceID); 21 | virtual ~AudioOutputWave(); 22 | virtual void Start(); 23 | virtual void Stop(); 24 | virtual bool IsPlaying(); 25 | virtual void SetCurrentDevice(std::string deviceID); 26 | static void EnumerateDevices(std::vector& devs); 27 | 28 | private: 29 | HWAVEOUT hWaveOut; 30 | WAVEFORMATEX format; 31 | WAVEHDR buffers[4]; 32 | static void CALLBACK WaveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2); 33 | void OnBufferDone(WAVEHDR* hdr); 34 | bool isPlaying; 35 | }; 36 | 37 | } 38 | } 39 | 40 | #endif //LIBTGVOIP_AUDIOOUTPUTWAVE_H 41 | -------------------------------------------------------------------------------- /libtgvoip/os/windows/WindowsSandboxUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_WINDOWS_SANDBOX_UTILS 8 | #define LIBTGVOIP_WINDOWS_SANDBOX_UTILS 9 | 10 | #include 11 | #include 12 | #ifndef TGVOIP_WP_SILVERLIGHT 13 | #include 14 | #endif 15 | #include 16 | #include 17 | 18 | using namespace Microsoft::WRL; 19 | 20 | namespace tgvoip { 21 | 22 | #ifndef TGVOIP_WP_SILVERLIGHT 23 | class ActivationHandler : 24 | public RuntimeClass< RuntimeClassFlags< ClassicCom >, FtmBase, IActivateAudioInterfaceCompletionHandler > 25 | { 26 | public: 27 | STDMETHOD(ActivateCompleted)(IActivateAudioInterfaceAsyncOperation *operation); 28 | 29 | ActivationHandler(HANDLE _event); 30 | HANDLE event; 31 | IAudioClient2* client; 32 | HRESULT actResult; 33 | }; 34 | #endif 35 | 36 | class WindowsSandboxUtils { 37 | public: 38 | static IAudioClient2* ActivateAudioDevice(const wchar_t* devID, HRESULT* callResult, HRESULT* actResult); 39 | }; 40 | } 41 | 42 | #endif // LIBTGVOIP_WINDOWS_SANDBOX_UTILS 43 | -------------------------------------------------------------------------------- /libtgvoip/os/windows/WindowsSpecific.cpp: -------------------------------------------------------------------------------- 1 | #include "WindowsSpecific.h" 2 | 3 | using namespace tgvoip; 4 | 5 | std::string WindowsSpecific::GetErrorMessage(DWORD code){ 6 | char buf[1024]={0}; 7 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, code, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), buf, sizeof(buf), NULL); 8 | return std::string(buf); 9 | } -------------------------------------------------------------------------------- /libtgvoip/os/windows/WindowsSpecific.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBTGVOIP_WINDOWS_SPECIFIC_H 2 | #define LIBTGVOIP_WINDOWS_SPECIFIC_H 3 | 4 | #include 5 | #include 6 | 7 | namespace tgvoip{ 8 | 9 | class WindowsSpecific{ 10 | public: 11 | static std::string GetErrorMessage(DWORD code); 12 | }; 13 | 14 | } 15 | 16 | #endif // LIBTGVOIP_WINDOWS_SPECIFIC_H -------------------------------------------------------------------------------- /libtgvoip/tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /libtgvoip/tests/MockReflector.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | #ifndef TGVOIP_MOCK_REFLECTOR 7 | #define TGVOIP_MOCK_REFLECTOR 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace tgvoip{ 25 | namespace test{ 26 | class MockReflector{ 27 | public: 28 | MockReflector(std::string bindAddress, uint16_t bindPort); 29 | ~MockReflector(); 30 | void Start(); 31 | void Stop(); 32 | void SetDropAllPackets(bool drop); 33 | static std::array, 2> GeneratePeerTags(); 34 | 35 | private: 36 | void RunThread(); 37 | struct ClientPair{ 38 | sockaddr_in addr0={0}; 39 | sockaddr_in addr1={0}; 40 | }; 41 | std::unordered_map clients; // clients are identified by the first half of their peer_tag 42 | int sfd; 43 | pthread_t thread; 44 | bool running=false; 45 | bool dropAllPackets=false; 46 | }; 47 | } 48 | } 49 | 50 | #endif //TGVOIP_MOCK_REFLECTOR 51 | -------------------------------------------------------------------------------- /libtgvoip/utils.h: -------------------------------------------------------------------------------- 1 | // 2 | // libtgvoip is free and unencumbered public domain software. 3 | // For more information, see http://unlicense.org or the UNLICENSE file 4 | // you should have received with this source code distribution. 5 | // 6 | 7 | #ifndef LIBTGVOIP_UTILS_H 8 | #define LIBTGVOIP_UTILS_H 9 | 10 | #define TGVOIP_DISALLOW_COPY_AND_ASSIGN(TypeName) \ 11 | TypeName(const TypeName&) = delete; \ 12 | void operator=(const TypeName&) = delete 13 | 14 | #endif /* LIBTGVOIP_UTILS_H */ 15 | -------------------------------------------------------------------------------- /libtgvoip/video/VideoRenderer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Grishka on 10.08.2018. 3 | // 4 | 5 | #include "VideoRenderer.h" 6 | 7 | #ifdef __ANDROID__ 8 | #include "../os/android/VideoRendererAndroid.h" 9 | #endif 10 | 11 | std::vector tgvoip::video::VideoRenderer::GetAvailableDecoders(){ 12 | #ifdef __ANDROID__ 13 | return VideoRendererAndroid::availableDecoders; 14 | #endif 15 | return std::vector(); 16 | } 17 | 18 | int tgvoip::video::VideoRenderer::GetMaximumResolution(){ 19 | #ifdef __ANDROID__ 20 | return VideoRendererAndroid::maxResolution; 21 | #endif 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /libtgvoip/video/VideoRenderer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Grishka on 10.08.2018. 3 | // 4 | 5 | #ifndef LIBTGVOIP_VIDEORENDERER_H 6 | #define LIBTGVOIP_VIDEORENDERER_H 7 | 8 | #include 9 | #include "../Buffers.h" 10 | 11 | namespace tgvoip{ 12 | namespace video{ 13 | class VideoRenderer{ 14 | public: 15 | static std::vector GetAvailableDecoders(); 16 | virtual ~VideoRenderer(){}; 17 | virtual void Reset(uint32_t codec, unsigned int width, unsigned int height, std::vector& csd)=0; 18 | virtual void DecodeAndDisplay(Buffer frame, uint32_t pts)=0; 19 | virtual void SetStreamEnabled(bool enabled)=0; 20 | static int GetMaximumResolution(); 21 | }; 22 | } 23 | } 24 | 25 | #endif //LIBTGVOIP_VIDEORENDERER_H 26 | -------------------------------------------------------------------------------- /libtgvoip/video/VideoSource.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Grishka on 10.08.2018. 3 | // 4 | 5 | #include "VideoSource.h" 6 | 7 | #ifdef __ANDROID__ 8 | #include "../os/android/VideoSourceAndroid.h" 9 | #endif 10 | 11 | using namespace tgvoip; 12 | using namespace tgvoip::video; 13 | 14 | std::shared_ptr VideoSource::Create(){ 15 | #ifdef __ANDROID__ 16 | //return std::make_shared(); 17 | return nullptr; 18 | #endif 19 | return nullptr; 20 | } 21 | 22 | 23 | void VideoSource::SetCallback(std::function callback){ 24 | this->callback=callback; 25 | } 26 | 27 | bool VideoSource::Failed(){ 28 | return failed; 29 | } 30 | 31 | std::string VideoSource::GetErrorDescription(){ 32 | return error; 33 | } 34 | 35 | std::vector VideoSource::GetAvailableEncoders(){ 36 | #ifdef __ANDROID__ 37 | return VideoSourceAndroid::availableEncoders; 38 | #endif 39 | return std::vector(); 40 | } 41 | -------------------------------------------------------------------------------- /libtgvoip/video/VideoSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Grishka on 10.08.2018. 3 | // 4 | 5 | #ifndef LIBTGVOIP_VIDEOSOURCE_H 6 | #define LIBTGVOIP_VIDEOSOURCE_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "../Buffers.h" 13 | 14 | namespace tgvoip{ 15 | namespace video { 16 | class VideoSource{ 17 | public: 18 | virtual ~VideoSource(){}; 19 | static std::shared_ptr Create(); 20 | static std::vector GetAvailableEncoders(); 21 | void SetCallback(std::function callback); 22 | virtual void Start()=0; 23 | virtual void Stop()=0; 24 | virtual void Reset(uint32_t codec, int maxResolution)=0; 25 | virtual void RequestKeyFrame()=0; 26 | bool Failed(); 27 | std::string GetErrorDescription(); 28 | std::vector& GetCodecSpecificData(){ 29 | return csd; 30 | } 31 | unsigned int GetFrameWidth(){ 32 | return width; 33 | } 34 | unsigned int GetFrameHeight(){ 35 | return height; 36 | } 37 | 38 | protected: 39 | std::function callback; 40 | bool failed; 41 | std::string error; 42 | unsigned int width=0; 43 | unsigned int height=0; 44 | std::vector csd; 45 | }; 46 | } 47 | } 48 | 49 | #endif //LIBTGVOIP_VIDEOSOURCE_H 50 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/absl/base/internal/identity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Abseil Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef ABSL_BASE_INTERNAL_IDENTITY_H_ 17 | #define ABSL_BASE_INTERNAL_IDENTITY_H_ 18 | 19 | namespace absl { 20 | namespace internal { 21 | 22 | template 23 | struct identity { 24 | typedef T type; 25 | }; 26 | 27 | template 28 | using identity_t = typename identity::type; 29 | 30 | } // namespace internal 31 | } // namespace absl 32 | 33 | #endif // ABSL_BASE_INTERNAL_IDENTITY_H_ 34 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/absl/base/port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Abseil Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // This files is a forwarding header for other headers containing various 16 | // portability macros and functions. 17 | // This file is used for both C and C++! 18 | 19 | #ifndef ABSL_BASE_PORT_H_ 20 | #define ABSL_BASE_PORT_H_ 21 | 22 | #include "absl/base/attributes.h" 23 | #include "absl/base/config.h" 24 | #include "absl/base/optimization.h" 25 | 26 | #endif // ABSL_BASE_PORT_H_ 27 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/absl/types/bad_optional_access.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Abseil Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "absl/types/bad_optional_access.h" 16 | 17 | #ifndef ABSL_HAVE_STD_OPTIONAL 18 | 19 | #include 20 | 21 | #include "absl/base/config.h" 22 | #include "absl/base/internal/raw_logging.h" 23 | 24 | namespace absl { 25 | 26 | bad_optional_access::~bad_optional_access() = default; 27 | 28 | const char* bad_optional_access::what() const noexcept { 29 | return "optional has no value"; 30 | } 31 | 32 | namespace optional_internal { 33 | 34 | void throw_bad_optional_access() { 35 | #ifdef ABSL_HAVE_EXCEPTIONS 36 | throw bad_optional_access(); 37 | #else 38 | ABSL_RAW_LOG(FATAL, "Bad optional access"); 39 | abort(); 40 | #endif 41 | } 42 | 43 | } // namespace optional_internal 44 | } // namespace absl 45 | 46 | #endif // ABSL_HAVE_STD_OPTIONAL 47 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/absl/types/optional.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Abseil Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "absl/types/optional.h" 16 | 17 | #ifndef ABSL_HAVE_STD_OPTIONAL 18 | namespace absl { 19 | 20 | nullopt_t::init_t nullopt_t::init; 21 | extern const nullopt_t nullopt{nullopt_t::init}; 22 | 23 | } // namespace absl 24 | #endif // ABSL_HAVE_STD_OPTIONAL 25 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/api/audio/echo_canceller3_factory.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | #include "api/audio/echo_canceller3_factory.h" 11 | 12 | #include 13 | 14 | #include "absl/memory/memory.h" 15 | #include "modules/audio_processing/aec3/echo_canceller3.h" 16 | 17 | namespace webrtc { 18 | 19 | EchoCanceller3Factory::EchoCanceller3Factory() {} 20 | 21 | EchoCanceller3Factory::EchoCanceller3Factory(const EchoCanceller3Config& config) 22 | : config_(config) {} 23 | 24 | std::unique_ptr EchoCanceller3Factory::Create(int sample_rate_hz) { 25 | return absl::make_unique(config_, sample_rate_hz, true); 26 | } 27 | } // namespace webrtc 28 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/api/audio/echo_canceller3_factory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef API_AUDIO_ECHO_CANCELLER3_FACTORY_H_ 12 | #define API_AUDIO_ECHO_CANCELLER3_FACTORY_H_ 13 | 14 | #include 15 | 16 | #include "api/audio/echo_canceller3_config.h" 17 | #include "api/audio/echo_control.h" 18 | #include "rtc_base/system/rtc_export.h" 19 | 20 | namespace webrtc { 21 | 22 | class RTC_EXPORT EchoCanceller3Factory : public EchoControlFactory { 23 | public: 24 | // Factory producing EchoCanceller3 instances with the default configuration. 25 | EchoCanceller3Factory(); 26 | 27 | // Factory producing EchoCanceller3 instances with the specified 28 | // configuration. 29 | explicit EchoCanceller3Factory(const EchoCanceller3Config& config); 30 | 31 | // Creates an EchoCanceller3 running at the specified sampling rate. 32 | std::unique_ptr Create(int sample_rate_hz) override; 33 | 34 | private: 35 | const EchoCanceller3Config config_; 36 | }; 37 | } // namespace webrtc 38 | 39 | #endif // API_AUDIO_ECHO_CANCELLER3_FACTORY_H_ 40 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/fir_filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef COMMON_AUDIO_FIR_FILTER_H_ 12 | #define COMMON_AUDIO_FIR_FILTER_H_ 13 | 14 | #include 15 | 16 | namespace webrtc { 17 | 18 | // Finite Impulse Response filter using floating-point arithmetic. 19 | class FIRFilter { 20 | public: 21 | virtual ~FIRFilter() {} 22 | 23 | // Filters the |in| data supplied. 24 | // |out| must be previously allocated and it must be at least of |length|. 25 | virtual void Filter(const float* in, size_t length, float* out) = 0; 26 | }; 27 | 28 | } // namespace webrtc 29 | 30 | #endif // COMMON_AUDIO_FIR_FILTER_H_ 31 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/fir_filter_c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef COMMON_AUDIO_FIR_FILTER_C_H_ 12 | #define COMMON_AUDIO_FIR_FILTER_C_H_ 13 | 14 | #include 15 | #include 16 | 17 | #include "common_audio/fir_filter.h" 18 | 19 | namespace webrtc { 20 | 21 | class FIRFilterC : public FIRFilter { 22 | public: 23 | FIRFilterC(const float* coefficients, size_t coefficients_length); 24 | ~FIRFilterC() override; 25 | 26 | void Filter(const float* in, size_t length, float* out) override; 27 | 28 | private: 29 | size_t coefficients_length_; 30 | size_t state_length_; 31 | std::unique_ptr coefficients_; 32 | std::unique_ptr state_; 33 | }; 34 | 35 | } // namespace webrtc 36 | 37 | #endif // COMMON_AUDIO_FIR_FILTER_C_H_ 38 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/fir_filter_factory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef COMMON_AUDIO_FIR_FILTER_FACTORY_H_ 12 | #define COMMON_AUDIO_FIR_FILTER_FACTORY_H_ 13 | 14 | #include 15 | 16 | namespace webrtc { 17 | 18 | class FIRFilter; 19 | 20 | // Creates a filter with the given coefficients. All initial state values will 21 | // be zeros. 22 | // The length of the chunks fed to the filter should never be greater than 23 | // |max_input_length|. This is needed because, when vectorizing it is 24 | // necessary to concatenate the input after the state, and resizing this array 25 | // dynamically is expensive. 26 | FIRFilter* CreateFirFilter(const float* coefficients, 27 | size_t coefficients_length, 28 | size_t max_input_length); 29 | 30 | } // namespace webrtc 31 | 32 | #endif // COMMON_AUDIO_FIR_FILTER_FACTORY_H_ 33 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/fir_filter_neon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef COMMON_AUDIO_FIR_FILTER_NEON_H_ 12 | #define COMMON_AUDIO_FIR_FILTER_NEON_H_ 13 | 14 | #include 15 | 16 | #include "common_audio/fir_filter.h" 17 | #include "rtc_base/memory/aligned_malloc.h" 18 | 19 | namespace webrtc { 20 | 21 | class FIRFilterNEON : public FIRFilter { 22 | public: 23 | FIRFilterNEON(const float* coefficients, 24 | size_t coefficients_length, 25 | size_t max_input_length); 26 | ~FIRFilterNEON() override; 27 | 28 | void Filter(const float* in, size_t length, float* out) override; 29 | 30 | private: 31 | size_t coefficients_length_; 32 | size_t state_length_; 33 | std::unique_ptr coefficients_; 34 | std::unique_ptr state_; 35 | }; 36 | 37 | } // namespace webrtc 38 | 39 | #endif // COMMON_AUDIO_FIR_FILTER_NEON_H_ 40 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/fir_filter_sse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef COMMON_AUDIO_FIR_FILTER_SSE_H_ 12 | #define COMMON_AUDIO_FIR_FILTER_SSE_H_ 13 | 14 | #include 15 | #include 16 | 17 | #include "common_audio/fir_filter.h" 18 | #include "rtc_base/memory/aligned_malloc.h" 19 | 20 | namespace webrtc { 21 | 22 | class FIRFilterSSE2 : public FIRFilter { 23 | public: 24 | FIRFilterSSE2(const float* coefficients, 25 | size_t coefficients_length, 26 | size_t max_input_length); 27 | ~FIRFilterSSE2() override; 28 | 29 | void Filter(const float* in, size_t length, float* out) override; 30 | 31 | private: 32 | size_t coefficients_length_; 33 | size_t state_length_; 34 | std::unique_ptr coefficients_; 35 | std::unique_ptr state_; 36 | }; 37 | 38 | } // namespace webrtc 39 | 40 | #endif // COMMON_AUDIO_FIR_FILTER_SSE_H_ 41 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/mocks/mock_smoothing_filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef COMMON_AUDIO_MOCKS_MOCK_SMOOTHING_FILTER_H_ 12 | #define COMMON_AUDIO_MOCKS_MOCK_SMOOTHING_FILTER_H_ 13 | 14 | #include "common_audio/smoothing_filter.h" 15 | #include "test/gmock.h" 16 | 17 | namespace webrtc { 18 | 19 | class MockSmoothingFilter : public SmoothingFilter { 20 | public: 21 | MOCK_METHOD1(AddSample, void(float)); 22 | MOCK_METHOD0(GetAverage, absl::optional()); 23 | MOCK_METHOD1(SetTimeConstantMs, bool(int)); 24 | }; 25 | 26 | } // namespace webrtc 27 | 28 | #endif // COMMON_AUDIO_MOCKS_MOCK_SMOOTHING_FILTER_H_ 29 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/real_fourier_ooura.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef COMMON_AUDIO_REAL_FOURIER_OOURA_H_ 12 | #define COMMON_AUDIO_REAL_FOURIER_OOURA_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "common_audio/real_fourier.h" 19 | 20 | namespace webrtc { 21 | 22 | class RealFourierOoura : public RealFourier { 23 | public: 24 | explicit RealFourierOoura(int fft_order); 25 | ~RealFourierOoura() override; 26 | 27 | void Forward(const float* src, std::complex* dest) const override; 28 | void Inverse(const std::complex* src, float* dest) const override; 29 | 30 | int order() const override; 31 | 32 | private: 33 | const int order_; 34 | const size_t length_; 35 | const size_t complex_length_; 36 | // These are work arrays for Ooura. The names are based on the comments in 37 | // fft4g.c. 38 | const std::unique_ptr work_ip_; 39 | const std::unique_ptr work_w_; 40 | }; 41 | 42 | } // namespace webrtc 43 | 44 | #endif // COMMON_AUDIO_REAL_FOURIER_OOURA_H_ 45 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/signal_processing/cross_correlation.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "common_audio/signal_processing/include/signal_processing_library.h" 12 | 13 | /* C version of WebRtcSpl_CrossCorrelation() for generic platforms. */ 14 | void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation, 15 | const int16_t* seq1, 16 | const int16_t* seq2, 17 | size_t dim_seq, 18 | size_t dim_cross_correlation, 19 | int right_shifts, 20 | int step_seq2) { 21 | size_t i = 0, j = 0; 22 | 23 | for (i = 0; i < dim_cross_correlation; i++) { 24 | int32_t corr = 0; 25 | for (j = 0; j < dim_seq; j++) 26 | corr += (seq1[j] * seq2[j]) >> right_shifts; 27 | seq2 += step_seq2; 28 | *cross_correlation++ = corr; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/signal_processing/dot_product_with_scale.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "common_audio/signal_processing/dot_product_with_scale.h" 12 | 13 | #include "rtc_base/numerics/safe_conversions.h" 14 | 15 | int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1, 16 | const int16_t* vector2, 17 | size_t length, 18 | int scaling) { 19 | int64_t sum = 0; 20 | size_t i = 0; 21 | 22 | /* Unroll the loop to improve performance. */ 23 | for (i = 0; i + 3 < length; i += 4) { 24 | sum += (vector1[i + 0] * vector2[i + 0]) >> scaling; 25 | sum += (vector1[i + 1] * vector2[i + 1]) >> scaling; 26 | sum += (vector1[i + 2] * vector2[i + 2]) >> scaling; 27 | sum += (vector1[i + 3] * vector2[i + 3]) >> scaling; 28 | } 29 | for (; i < length; i++) { 30 | sum += (vector1[i] * vector2[i]) >> scaling; 31 | } 32 | 33 | return rtc::saturated_cast(sum); 34 | } 35 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/signal_processing/dot_product_with_scale.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef COMMON_AUDIO_SIGNAL_PROCESSING_DOT_PRODUCT_WITH_SCALE_H_ 12 | #define COMMON_AUDIO_SIGNAL_PROCESSING_DOT_PRODUCT_WITH_SCALE_H_ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | // Calculates the dot product between two (int16_t) vectors. 22 | // 23 | // Input: 24 | // - vector1 : Vector 1 25 | // - vector2 : Vector 2 26 | // - vector_length : Number of samples used in the dot product 27 | // - scaling : The number of right bit shifts to apply on each term 28 | // during calculation to avoid overflow, i.e., the 29 | // output will be in Q(-|scaling|) 30 | // 31 | // Return value : The dot product in Q(-scaling) 32 | int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1, 33 | const int16_t* vector2, 34 | size_t length, 35 | int scaling); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif // __cplusplus 40 | #endif // COMMON_AUDIO_SIGNAL_PROCESSING_DOT_PRODUCT_WITH_SCALE_H_ 41 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/signal_processing/energy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | 12 | /* 13 | * This file contains the function WebRtcSpl_Energy(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | int32_t WebRtcSpl_Energy(int16_t* vector, 21 | size_t vector_length, 22 | int* scale_factor) 23 | { 24 | int32_t en = 0; 25 | size_t i; 26 | int scaling = 27 | WebRtcSpl_GetScalingSquare(vector, vector_length, vector_length); 28 | size_t looptimes = vector_length; 29 | int16_t *vectorptr = vector; 30 | 31 | for (i = 0; i < looptimes; i++) 32 | { 33 | en += (*vectorptr * *vectorptr) >> scaling; 34 | vectorptr++; 35 | } 36 | *scale_factor = scaling; 37 | 38 | return en; 39 | } 40 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/signal_processing/get_scaling_square.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | 12 | /* 13 | * This file contains the function WebRtcSpl_GetScalingSquare(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector, 21 | size_t in_vector_length, 22 | size_t times) 23 | { 24 | int16_t nbits = WebRtcSpl_GetSizeInBits((uint32_t)times); 25 | size_t i; 26 | int16_t smax = -1; 27 | int16_t sabs; 28 | int16_t *sptr = in_vector; 29 | int16_t t; 30 | size_t looptimes = in_vector_length; 31 | 32 | for (i = looptimes; i > 0; i--) 33 | { 34 | sabs = (*sptr > 0 ? *sptr++ : -*sptr++); 35 | smax = (sabs > smax ? sabs : smax); 36 | } 37 | t = WebRtcSpl_NormW32(WEBRTC_SPL_MUL(smax, smax)); 38 | 39 | if (smax == 0) 40 | { 41 | return 0; // Since norm(0) returns 0 42 | } else 43 | { 44 | return (t > nbits) ? 0 : nbits - t; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/signal_processing/refl_coef_to_lpc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | 12 | /* 13 | * This file contains the function WebRtcSpl_ReflCoefToLpc(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | void WebRtcSpl_ReflCoefToLpc(const int16_t *k, int use_order, int16_t *a) 21 | { 22 | int16_t any[WEBRTC_SPL_MAX_LPC_ORDER + 1]; 23 | int16_t *aptr, *aptr2, *anyptr; 24 | const int16_t *kptr; 25 | int m, i; 26 | 27 | kptr = k; 28 | *a = 4096; // i.e., (Word16_MAX >> 3)+1. 29 | *any = *a; 30 | a[1] = *k >> 3; 31 | 32 | for (m = 1; m < use_order; m++) 33 | { 34 | kptr++; 35 | aptr = a; 36 | aptr++; 37 | aptr2 = &a[m]; 38 | anyptr = any; 39 | anyptr++; 40 | 41 | any[m + 1] = *kptr >> 3; 42 | for (i = 0; i < m; i++) 43 | { 44 | *anyptr = *aptr + (int16_t)((*aptr2 * *kptr) >> 15); 45 | anyptr++; 46 | aptr++; 47 | aptr2--; 48 | } 49 | 50 | aptr = a; 51 | anyptr = any; 52 | for (i = 0; i < (m + 2); i++) 53 | { 54 | *aptr = *anyptr; 55 | aptr++; 56 | anyptr++; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/signal_processing/spl_inl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include 12 | 13 | #include "common_audio/signal_processing/include/spl_inl.h" 14 | 15 | // Table used by WebRtcSpl_CountLeadingZeros32_NotBuiltin. For each uint32_t n 16 | // that's a sequence of 0 bits followed by a sequence of 1 bits, the entry at 17 | // index (n * 0x8c0b2891) >> 26 in this table gives the number of zero bits in 18 | // n. 19 | const int8_t kWebRtcSpl_CountLeadingZeros32_Table[64] = { 20 | 32, 8, 17, -1, -1, 14, -1, -1, -1, 20, -1, -1, -1, 28, -1, 18, 21 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 26, 25, 24, 22 | 4, 11, 23, 31, 3, 7, 10, 16, 22, 30, -1, -1, 2, 6, 13, 9, 23 | -1, 15, -1, 21, -1, 29, 19, -1, -1, -1, -1, -1, 1, 27, 5, 12, 24 | }; 25 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/signal_processing/sqrt_of_one_minus_x_squared.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | 12 | /* 13 | * This file contains the function WebRtcSpl_SqrtOfOneMinusXSquared(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | void WebRtcSpl_SqrtOfOneMinusXSquared(int16_t *xQ15, size_t vector_length, 21 | int16_t *yQ15) 22 | { 23 | int32_t sq; 24 | size_t m; 25 | int16_t tmp; 26 | 27 | for (m = 0; m < vector_length; m++) 28 | { 29 | tmp = xQ15[m]; 30 | sq = tmp * tmp; // x^2 in Q30 31 | sq = 1073741823 - sq; // 1-x^2, where 1 ~= 0.99999999906 is 1073741823 in Q30 32 | sq = WebRtcSpl_Sqrt(sq); // sqrt(1-x^2) in Q15 33 | yQ15[m] = (int16_t)sq; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/third_party/fft4g/fft4g.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the ../../../LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef COMMON_AUDIO_THIRD_PARTY_FFT4G_FFT4G_H_ 12 | #define COMMON_AUDIO_THIRD_PARTY_FFT4G_FFT4G_H_ 13 | 14 | #if defined(__cplusplus) 15 | extern "C" { 16 | #endif 17 | 18 | // Refer to fft4g.c for documentation. 19 | void WebRtc_rdft(size_t n, int isgn, float* a, size_t* ip, float* w); 20 | 21 | #if defined(__cplusplus) 22 | } 23 | #endif 24 | 25 | #endif /* COMMON_AUDIO_THIRD_PARTY_FFT4G_FFT4G_H_ */ 26 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/third_party/spl_sqrt_floor/spl_sqrt_floor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include 12 | 13 | // 14 | // WebRtcSpl_SqrtFloor(...) 15 | // 16 | // Returns the square root of the input value |value|. The precision of this 17 | // function is rounding down integer precision, i.e., sqrt(8) gives 2 as answer. 18 | // If |value| is a negative number then 0 is returned. 19 | // 20 | // Algorithm: 21 | // 22 | // An iterative 4 cylce/bit routine 23 | // 24 | // Input: 25 | // - value : Value to calculate sqrt of 26 | // 27 | // Return value : Result of the sqrt calculation 28 | // 29 | int32_t WebRtcSpl_SqrtFloor(int32_t value); 30 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/vad/include/vad.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef COMMON_AUDIO_VAD_INCLUDE_VAD_H_ 12 | #define COMMON_AUDIO_VAD_INCLUDE_VAD_H_ 13 | 14 | #include 15 | 16 | #include "common_audio/vad/include/webrtc_vad.h" 17 | #include "rtc_base/checks.h" 18 | 19 | namespace webrtc { 20 | 21 | class Vad { 22 | public: 23 | enum Aggressiveness { 24 | kVadNormal = 0, 25 | kVadLowBitrate = 1, 26 | kVadAggressive = 2, 27 | kVadVeryAggressive = 3 28 | }; 29 | 30 | enum Activity { kPassive = 0, kActive = 1, kError = -1 }; 31 | 32 | virtual ~Vad() = default; 33 | 34 | // Calculates a VAD decision for the given audio frame. Valid sample rates 35 | // are 8000, 16000, and 32000 Hz; the number of samples must be such that the 36 | // frame is 10, 20, or 30 ms long. 37 | virtual Activity VoiceActivity(const int16_t* audio, 38 | size_t num_samples, 39 | int sample_rate_hz) = 0; 40 | 41 | // Resets VAD state. 42 | virtual void Reset() = 0; 43 | }; 44 | 45 | // Returns a Vad instance that's implemented on top of WebRtcVad. 46 | std::unique_ptr CreateVad(Vad::Aggressiveness aggressiveness); 47 | 48 | } // namespace webrtc 49 | 50 | #endif // COMMON_AUDIO_VAD_INCLUDE_VAD_H_ 51 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/vad/vad_gmm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | // Gaussian probability calculations internally used in vad_core.c. 12 | 13 | #ifndef COMMON_AUDIO_VAD_VAD_GMM_H_ 14 | #define COMMON_AUDIO_VAD_VAD_GMM_H_ 15 | 16 | #include 17 | 18 | // Calculates the probability for |input|, given that |input| comes from a 19 | // normal distribution with mean and standard deviation (|mean|, |std|). 20 | // 21 | // Inputs: 22 | // - input : input sample in Q4. 23 | // - mean : mean input in the statistical model, Q7. 24 | // - std : standard deviation, Q7. 25 | // 26 | // Output: 27 | // 28 | // - delta : input used when updating the model, Q11. 29 | // |delta| = (|input| - |mean|) / |std|^2. 30 | // 31 | // Return: 32 | // (probability for |input|) = 33 | // 1 / |std| * exp(-(|input| - |mean|)^2 / (2 * |std|^2)); 34 | int32_t WebRtcVad_GaussianProbability(int16_t input, 35 | int16_t mean, 36 | int16_t std, 37 | int16_t* delta); 38 | 39 | #endif // COMMON_AUDIO_VAD_VAD_GMM_H_ 40 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/common_audio/window_generator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef COMMON_AUDIO_WINDOW_GENERATOR_H_ 12 | #define COMMON_AUDIO_WINDOW_GENERATOR_H_ 13 | 14 | #include 15 | 16 | #include "rtc_base/constructormagic.h" 17 | 18 | namespace webrtc { 19 | 20 | // Helper class with generators for various signal transform windows. 21 | class WindowGenerator { 22 | public: 23 | static void Hanning(int length, float* window); 24 | static void KaiserBesselDerived(float alpha, size_t length, float* window); 25 | 26 | private: 27 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WindowGenerator); 28 | }; 29 | 30 | } // namespace webrtc 31 | 32 | #endif // COMMON_AUDIO_WINDOW_GENERATOR_H_ 33 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_coding/codecs/isac/bandwidth_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_BANDWIDTH_INFO_H_ 12 | #define MODULES_AUDIO_CODING_CODECS_ISAC_BANDWIDTH_INFO_H_ 13 | 14 | #include 15 | 16 | typedef struct { 17 | int in_use; 18 | int32_t send_bw_avg; 19 | int32_t send_max_delay_avg; 20 | int16_t bottleneck_idx; 21 | int16_t jitter_info; 22 | } IsacBandwidthInfo; 23 | 24 | #endif // MODULES_AUDIO_CODING_CODECS_ISAC_BANDWIDTH_INFO_H_ 25 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_coding/codecs/isac/main/source/crc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | /* 12 | * crc.h 13 | * 14 | * Checksum functions 15 | * 16 | */ 17 | 18 | #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CRC_H_ 19 | #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CRC_H_ 20 | 21 | #include 22 | 23 | /**************************************************************************** 24 | * WebRtcIsac_GetCrc(...) 25 | * 26 | * This function returns a 32 bit CRC checksum of a bit stream 27 | * 28 | * Input: 29 | * - encoded : payload bit stream 30 | * - no_of_word8s : number of 8-bit words in the bit stream 31 | * 32 | * Output: 33 | * - crc : checksum 34 | * 35 | * Return value : 0 - Ok 36 | * -1 - Error 37 | */ 38 | 39 | int WebRtcIsac_GetCrc(const int16_t* encoded, int no_of_word8s, uint32_t* crc); 40 | 41 | #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CRC_H_ */ 42 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_coding/codecs/isac/main/source/filter_functions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_FILTER_FUNCTIONS_H_ 12 | #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_FILTER_FUNCTIONS_H_ 13 | 14 | #include "modules/audio_coding/codecs/isac/main/source/structs.h" 15 | 16 | void WebRtcIsac_AutoCorr(double* r, const double* x, size_t N, size_t order); 17 | 18 | void WebRtcIsac_WeightingFilter(const double* in, 19 | double* weiout, 20 | double* whiout, 21 | WeightFiltstr* wfdata); 22 | 23 | #endif // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_FILTER_FUNCTIONS_H_ 24 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_coding/codecs/isac/main/source/os_specific_inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_OS_SPECIFIC_INLINE_H_ 12 | #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_OS_SPECIFIC_INLINE_H_ 13 | 14 | #include 15 | 16 | #include "rtc_base/system/arch.h" 17 | 18 | #if defined(WEBRTC_POSIX) 19 | #define WebRtcIsac_lrint lrint 20 | #elif (defined(WEBRTC_ARCH_X86) && defined(WIN32)) 21 | static __inline long int WebRtcIsac_lrint(double x_dbl) { 22 | long int x_int; 23 | 24 | __asm { 25 | fld x_dbl 26 | fistp x_int 27 | } 28 | ; 29 | 30 | return x_int; 31 | } 32 | #else // Do a slow but correct implementation of lrint 33 | 34 | static __inline long int WebRtcIsac_lrint(double x_dbl) { 35 | long int x_int; 36 | x_int = (long int)floor(x_dbl + 0.499999999999); 37 | return x_int; 38 | } 39 | 40 | #endif 41 | 42 | #endif // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_OS_SPECIFIC_INLINE_H_ 43 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_coding/codecs/isac/main/source/pitch_estimator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | /* 12 | * pitch_estimator.h 13 | * 14 | * Pitch functions 15 | * 16 | */ 17 | 18 | #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_ESTIMATOR_H_ 19 | #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_ESTIMATOR_H_ 20 | 21 | #include 22 | 23 | #include "modules/audio_coding/codecs/isac/main/source/structs.h" 24 | 25 | void WebRtcIsac_PitchAnalysis( 26 | const double* in, /* PITCH_FRAME_LEN samples */ 27 | double* out, /* PITCH_FRAME_LEN+QLOOKAHEAD samples */ 28 | PitchAnalysisStruct* State, 29 | double* lags, 30 | double* gains); 31 | 32 | #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_ESTIMATOR_H_ */ 33 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec/aec_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC_AEC_COMMON_H_ 12 | #define MODULES_AUDIO_PROCESSING_AEC_AEC_COMMON_H_ 13 | 14 | #ifdef _MSC_VER /* visual c++ */ 15 | #define ALIGN16_BEG __declspec(align(16)) 16 | #define ALIGN16_END 17 | #else /* gcc or icc */ 18 | #define ALIGN16_BEG 19 | #define ALIGN16_END __attribute__((aligned(16))) 20 | #endif 21 | 22 | #ifdef __cplusplus 23 | namespace webrtc { 24 | #endif 25 | 26 | extern ALIGN16_BEG const float ALIGN16_END WebRtcAec_sqrtHanning[65]; 27 | extern ALIGN16_BEG const float ALIGN16_END WebRtcAec_weightCurve[65]; 28 | extern ALIGN16_BEG const float ALIGN16_END WebRtcAec_overDriveCurve[65]; 29 | extern const float WebRtcAec_kExtendedSmoothingCoefficients[2][2]; 30 | extern const float WebRtcAec_kNormalSmoothingCoefficients[2][2]; 31 | extern const float WebRtcAec_kMinFarendPSD; 32 | 33 | #ifdef __cplusplus 34 | } // namespace webrtc 35 | #endif 36 | 37 | #endif // MODULES_AUDIO_PROCESSING_AEC_AEC_COMMON_H_ 38 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec/aec_resampler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC_AEC_RESAMPLER_H_ 12 | #define MODULES_AUDIO_PROCESSING_AEC_AEC_RESAMPLER_H_ 13 | 14 | #include 15 | 16 | #include "modules/audio_processing/aec/aec_core.h" 17 | 18 | namespace webrtc { 19 | 20 | enum { kResamplingDelay = 1 }; 21 | enum { kResamplerBufferSize = FRAME_LEN * 4 }; 22 | 23 | // Unless otherwise specified, functions return 0 on success and -1 on error. 24 | void* WebRtcAec_CreateResampler(); // Returns NULL on error. 25 | int WebRtcAec_InitResampler(void* resampInst, int deviceSampleRateHz); 26 | void WebRtcAec_FreeResampler(void* resampInst); 27 | 28 | // Estimates skew from raw measurement. 29 | int WebRtcAec_GetSkew(void* resampInst, int rawSkew, float* skewEst); 30 | 31 | // Resamples input using linear interpolation. 32 | void WebRtcAec_ResampleLinear(void* resampInst, 33 | const float* inspeech, 34 | size_t size, 35 | float skew, 36 | float* outspeech, 37 | size_t* size_out); 38 | 39 | } // namespace webrtc 40 | 41 | #endif // MODULES_AUDIO_PROCESSING_AEC_AEC_RESAMPLER_H_ 42 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/block_delay_buffer.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | #include "modules/audio_processing/aec3/block_delay_buffer.h" 11 | 12 | #include "rtc_base/checks.h" 13 | 14 | namespace webrtc { 15 | 16 | BlockDelayBuffer::BlockDelayBuffer(size_t num_bands, 17 | size_t frame_length, 18 | size_t delay_samples) 19 | : frame_length_(frame_length), 20 | delay_(delay_samples), 21 | buf_(num_bands, std::vector(delay_, 0.f)) {} 22 | 23 | BlockDelayBuffer::~BlockDelayBuffer() = default; 24 | 25 | void BlockDelayBuffer::DelaySignal(AudioBuffer* frame) { 26 | RTC_DCHECK_EQ(1, frame->num_channels()); 27 | RTC_DCHECK_EQ(buf_.size(), frame->num_bands()); 28 | if (delay_ == 0) { 29 | return; 30 | } 31 | 32 | const size_t i_start = last_insert_; 33 | size_t i = 0; 34 | for (size_t j = 0; j < buf_.size(); ++j) { 35 | i = i_start; 36 | for (size_t k = 0; k < frame_length_; ++k) { 37 | const float tmp = buf_[j][i]; 38 | buf_[j][i] = frame->split_bands_f(0)[j][k]; 39 | frame->split_bands_f(0)[j][k] = tmp; 40 | i = i < buf_[0].size() - 1 ? i + 1 : 0; 41 | } 42 | } 43 | 44 | last_insert_ = i; 45 | } 46 | 47 | } // namespace webrtc 48 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/block_delay_buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_BLOCK_DELAY_BUFFER_H_ 12 | #define MODULES_AUDIO_PROCESSING_AEC3_BLOCK_DELAY_BUFFER_H_ 13 | 14 | #include 15 | #include 16 | 17 | #include "modules/audio_processing/audio_buffer.h" 18 | 19 | namespace webrtc { 20 | 21 | // Class for applying a fixed delay to the samples in a signal partitioned using 22 | // the audiobuffer band-splitting scheme. 23 | class BlockDelayBuffer { 24 | public: 25 | BlockDelayBuffer(size_t num_bands, size_t frame_length, size_t delay_samples); 26 | ~BlockDelayBuffer(); 27 | 28 | // Delays the samples by the specified delay. 29 | void DelaySignal(AudioBuffer* frame); 30 | 31 | private: 32 | const size_t frame_length_; 33 | const size_t delay_; 34 | std::vector> buf_; 35 | size_t last_insert_ = 0; 36 | }; 37 | } // namespace webrtc 38 | 39 | #endif // MODULES_AUDIO_PROCESSING_AEC3_BLOCK_DELAY_BUFFER_H_ 40 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/block_processor_metrics.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_BLOCK_PROCESSOR_METRICS_H_ 12 | #define MODULES_AUDIO_PROCESSING_AEC3_BLOCK_PROCESSOR_METRICS_H_ 13 | 14 | #include "rtc_base/constructormagic.h" 15 | 16 | namespace webrtc { 17 | 18 | // Handles the reporting of metrics for the block_processor. 19 | class BlockProcessorMetrics { 20 | public: 21 | BlockProcessorMetrics() = default; 22 | 23 | // Updates the metric with new capture data. 24 | void UpdateCapture(bool underrun); 25 | 26 | // Updates the metric with new render data. 27 | void UpdateRender(bool overrun); 28 | 29 | // Returns true if the metrics have just been reported, otherwise false. 30 | bool MetricsReported() { return metrics_reported_; } 31 | 32 | private: 33 | // Resets the metrics. 34 | void ResetMetrics(); 35 | 36 | int capture_block_counter_ = 0; 37 | bool metrics_reported_ = false; 38 | int render_buffer_underruns_ = 0; 39 | int render_buffer_overruns_ = 0; 40 | int buffer_render_calls_ = 0; 41 | 42 | RTC_DISALLOW_COPY_AND_ASSIGN(BlockProcessorMetrics); 43 | }; 44 | 45 | } // namespace webrtc 46 | 47 | #endif // MODULES_AUDIO_PROCESSING_AEC3_BLOCK_PROCESSOR_METRICS_H_ 48 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/decimator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_DECIMATOR_H_ 12 | #define MODULES_AUDIO_PROCESSING_AEC3_DECIMATOR_H_ 13 | 14 | #include 15 | 16 | #include "api/array_view.h" 17 | #include "modules/audio_processing/aec3/aec3_common.h" 18 | #include "modules/audio_processing/aec3/cascaded_biquad_filter.h" 19 | #include "rtc_base/constructormagic.h" 20 | 21 | namespace webrtc { 22 | 23 | // Provides functionality for decimating a signal. 24 | class Decimator { 25 | public: 26 | explicit Decimator(size_t down_sampling_factor); 27 | 28 | // Downsamples the signal. 29 | void Decimate(rtc::ArrayView in, rtc::ArrayView out); 30 | 31 | private: 32 | const size_t down_sampling_factor_; 33 | CascadedBiQuadFilter anti_aliasing_filter_; 34 | CascadedBiQuadFilter noise_reduction_filter_; 35 | 36 | RTC_DISALLOW_COPY_AND_ASSIGN(Decimator); 37 | }; 38 | } // namespace webrtc 39 | 40 | #endif // MODULES_AUDIO_PROCESSING_AEC3_DECIMATOR_H_ 41 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/delay_estimate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_DELAY_ESTIMATE_H_ 12 | #define MODULES_AUDIO_PROCESSING_AEC3_DELAY_ESTIMATE_H_ 13 | 14 | namespace webrtc { 15 | 16 | // Stores delay_estimates. 17 | struct DelayEstimate { 18 | enum class Quality { kCoarse, kRefined }; 19 | 20 | DelayEstimate(Quality quality, size_t delay) 21 | : quality(quality), delay(delay) {} 22 | 23 | Quality quality; 24 | size_t delay; 25 | size_t blocks_since_last_change = 0; 26 | size_t blocks_since_last_update = 0; 27 | }; 28 | 29 | } // namespace webrtc 30 | 31 | #endif // MODULES_AUDIO_PROCESSING_AEC3_DELAY_ESTIMATE_H_ 32 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/downsampled_render_buffer.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/aec3/downsampled_render_buffer.h" 12 | 13 | #include 14 | 15 | namespace webrtc { 16 | 17 | DownsampledRenderBuffer::DownsampledRenderBuffer(size_t downsampled_buffer_size) 18 | : size(static_cast(downsampled_buffer_size)), 19 | buffer(downsampled_buffer_size, 0.f) { 20 | std::fill(buffer.begin(), buffer.end(), 0.f); 21 | } 22 | 23 | DownsampledRenderBuffer::~DownsampledRenderBuffer() = default; 24 | 25 | } // namespace webrtc 26 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/echo_path_variability.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/aec3/echo_path_variability.h" 12 | 13 | namespace webrtc { 14 | 15 | EchoPathVariability::EchoPathVariability(bool gain_change, 16 | DelayAdjustment delay_change, 17 | bool clock_drift) 18 | : gain_change(gain_change), 19 | delay_change(delay_change), 20 | clock_drift(clock_drift) {} 21 | 22 | } // namespace webrtc 23 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/echo_path_variability.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_ECHO_PATH_VARIABILITY_H_ 12 | #define MODULES_AUDIO_PROCESSING_AEC3_ECHO_PATH_VARIABILITY_H_ 13 | 14 | namespace webrtc { 15 | 16 | struct EchoPathVariability { 17 | enum class DelayAdjustment { 18 | kNone, 19 | kBufferReadjustment, 20 | kBufferFlush, 21 | kDelayReset, 22 | kNewDetectedDelay 23 | }; 24 | 25 | EchoPathVariability(bool gain_change, 26 | DelayAdjustment delay_change, 27 | bool clock_drift); 28 | 29 | bool AudioPathChanged() const { 30 | return gain_change || delay_change != DelayAdjustment::kNone; 31 | } 32 | bool gain_change; 33 | DelayAdjustment delay_change; 34 | bool clock_drift; 35 | }; 36 | 37 | } // namespace webrtc 38 | 39 | #endif // MODULES_AUDIO_PROCESSING_AEC3_ECHO_PATH_VARIABILITY_H_ 40 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/fft_buffer.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/aec3/fft_buffer.h" 12 | 13 | namespace webrtc { 14 | 15 | FftBuffer::FftBuffer(size_t size) : size(static_cast(size)), buffer(size) { 16 | for (auto& b : buffer) { 17 | b.Clear(); 18 | } 19 | } 20 | 21 | FftBuffer::~FftBuffer() = default; 22 | 23 | } // namespace webrtc 24 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/matrix_buffer.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/aec3/matrix_buffer.h" 12 | 13 | #include 14 | 15 | namespace webrtc { 16 | 17 | MatrixBuffer::MatrixBuffer(size_t size, size_t height, size_t width) 18 | : size(static_cast(size)), 19 | buffer(size, 20 | std::vector>(height, 21 | std::vector(width, 0.f))) { 22 | for (auto& c : buffer) { 23 | for (auto& b : c) { 24 | std::fill(b.begin(), b.end(), 0.f); 25 | } 26 | } 27 | } 28 | 29 | MatrixBuffer::~MatrixBuffer() = default; 30 | 31 | } // namespace webrtc 32 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/moving_average.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_MOVING_AVERAGE_H_ 12 | #define MODULES_AUDIO_PROCESSING_AEC3_MOVING_AVERAGE_H_ 13 | 14 | #include 15 | #include 16 | 17 | #include "api/array_view.h" 18 | 19 | namespace webrtc { 20 | namespace aec3 { 21 | 22 | class MovingAverage { 23 | public: 24 | // Creates an instance of MovingAverage that accepts inputs of length num_elem 25 | // and averages over mem_len inputs. 26 | MovingAverage(size_t num_elem, size_t mem_len); 27 | ~MovingAverage(); 28 | 29 | // Computes the average of input and mem_len-1 previous inputs and stores the 30 | // result in output. 31 | void Average(rtc::ArrayView input, rtc::ArrayView output); 32 | 33 | private: 34 | const size_t num_elem_; 35 | const size_t mem_len_; 36 | const float scaling_; 37 | std::vector memory_; 38 | size_t mem_index_; 39 | }; 40 | 41 | } // namespace aec3 42 | } // namespace webrtc 43 | 44 | #endif // MODULES_AUDIO_PROCESSING_AEC3_MOVING_AVERAGE_H_ 45 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/render_reverb_model.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/aec3/render_reverb_model.h" 12 | 13 | #include 14 | 15 | #include "api/array_view.h" 16 | #include "rtc_base/checks.h" 17 | 18 | namespace webrtc { 19 | 20 | RenderReverbModel::RenderReverbModel() { 21 | Reset(); 22 | } 23 | 24 | RenderReverbModel::~RenderReverbModel() = default; 25 | 26 | void RenderReverbModel::Reset() { 27 | render_reverb_.Reset(); 28 | } 29 | 30 | void RenderReverbModel::Apply(const VectorBuffer& spectrum_buffer, 31 | int delay_blocks, 32 | float reverb_decay, 33 | rtc::ArrayView reverb_power_spectrum) { 34 | int idx_at_delay = 35 | spectrum_buffer.OffsetIndex(spectrum_buffer.read, delay_blocks); 36 | int idx_past = spectrum_buffer.IncIndex(idx_at_delay); 37 | const auto& X2 = spectrum_buffer.buffer[idx_at_delay]; 38 | RTC_DCHECK_EQ(X2.size(), reverb_power_spectrum.size()); 39 | std::copy(X2.begin(), X2.end(), reverb_power_spectrum.begin()); 40 | render_reverb_.AddReverbNoFreqShaping(spectrum_buffer.buffer[idx_past], 1.0f, 41 | reverb_decay, reverb_power_spectrum); 42 | } 43 | 44 | } // namespace webrtc 45 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/reverb_model_estimator.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/aec3/reverb_model_estimator.h" 12 | 13 | namespace webrtc { 14 | 15 | ReverbModelEstimator::ReverbModelEstimator(const EchoCanceller3Config& config) 16 | : reverb_decay_estimator_(config) {} 17 | 18 | ReverbModelEstimator::~ReverbModelEstimator() = default; 19 | 20 | void ReverbModelEstimator::Update( 21 | rtc::ArrayView impulse_response, 22 | const std::vector>& 23 | frequency_response, 24 | const absl::optional& linear_filter_quality, 25 | int filter_delay_blocks, 26 | bool usable_linear_estimate, 27 | bool stationary_block) { 28 | // Estimate the frequency response for the reverb. 29 | reverb_frequency_response_.Update(frequency_response, filter_delay_blocks, 30 | linear_filter_quality, stationary_block); 31 | 32 | // Estimate the reverb decay, 33 | reverb_decay_estimator_.Update(impulse_response, linear_filter_quality, 34 | filter_delay_blocks, usable_linear_estimate, 35 | stationary_block); 36 | } 37 | } // namespace webrtc 38 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/skew_estimator.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | #include "modules/audio_processing/aec3/skew_estimator.h" 11 | 12 | #include 13 | 14 | namespace webrtc { 15 | 16 | SkewEstimator::SkewEstimator(size_t skew_history_size_log2) 17 | : skew_history_size_log2_(static_cast(skew_history_size_log2)), 18 | skew_history_(1ULL << skew_history_size_log2_, 0) {} 19 | 20 | SkewEstimator::~SkewEstimator() = default; 21 | 22 | void SkewEstimator::Reset() { 23 | skew_ = 0; 24 | skew_sum_ = 0; 25 | next_index_ = 0; 26 | sufficient_skew_stored_ = false; 27 | std::fill(skew_history_.begin(), skew_history_.end(), 0); 28 | } 29 | 30 | absl::optional SkewEstimator::GetSkewFromCapture() { 31 | --skew_; 32 | 33 | skew_sum_ += skew_ - skew_history_[next_index_]; 34 | skew_history_[next_index_] = skew_; 35 | if (++next_index_ == skew_history_.size()) { 36 | next_index_ = 0; 37 | sufficient_skew_stored_ = true; 38 | } 39 | 40 | const int bias = static_cast(skew_history_.size()) >> 1; 41 | const int average = (skew_sum_ + bias) >> skew_history_size_log2_; 42 | return sufficient_skew_stored_ ? absl::optional(average) : absl::nullopt; 43 | } 44 | 45 | } // namespace webrtc 46 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/skew_estimator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_SKEW_ESTIMATOR_H_ 12 | #define MODULES_AUDIO_PROCESSING_AEC3_SKEW_ESTIMATOR_H_ 13 | 14 | #include 15 | #include 16 | 17 | #include "absl/types/optional.h" 18 | #include "rtc_base/constructormagic.h" 19 | 20 | namespace webrtc { 21 | 22 | // Estimator of API call skew between render and capture. 23 | class SkewEstimator { 24 | public: 25 | explicit SkewEstimator(size_t skew_history_size_log2); 26 | ~SkewEstimator(); 27 | 28 | // Resets the estimation. 29 | void Reset(); 30 | 31 | // Updates the skew data for a render call. 32 | void LogRenderCall() { ++skew_; } 33 | 34 | // Updates and computes the skew at a capture call. Returns an optional which 35 | // is non-null if a reliable skew has been found. 36 | absl::optional GetSkewFromCapture(); 37 | 38 | private: 39 | const int skew_history_size_log2_; 40 | std::vector skew_history_; 41 | int skew_ = 0; 42 | int skew_sum_ = 0; 43 | size_t next_index_ = 0; 44 | bool sufficient_skew_stored_ = false; 45 | 46 | RTC_DISALLOW_COPY_AND_ASSIGN(SkewEstimator); 47 | }; 48 | 49 | } // namespace webrtc 50 | 51 | #endif // MODULES_AUDIO_PROCESSING_AEC3_SKEW_ESTIMATOR_H_ 52 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/subtractor_output.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_OUTPUT_H_ 12 | #define MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_OUTPUT_H_ 13 | 14 | #include 15 | 16 | #include "api/array_view.h" 17 | #include "modules/audio_processing/aec3/aec3_common.h" 18 | #include "modules/audio_processing/aec3/fft_data.h" 19 | 20 | namespace webrtc { 21 | 22 | // Stores the values being returned from the echo subtractor. 23 | struct SubtractorOutput { 24 | SubtractorOutput(); 25 | ~SubtractorOutput(); 26 | 27 | std::array s_main; 28 | std::array s_shadow; 29 | std::array e_main; 30 | std::array e_shadow; 31 | FftData E_main; 32 | std::array E2_main; 33 | std::array E2_shadow; 34 | float s2_main = 0.f; 35 | float s2_shadow = 0.f; 36 | float e2_main = 0.f; 37 | float e2_shadow = 0.f; 38 | float y2 = 0.f; 39 | float s_main_max_abs = 0.f; 40 | float s_shadow_max_abs = 0.f; 41 | 42 | // Reset the struct content. 43 | void Reset(); 44 | 45 | // Updates the powers of the signals. 46 | void ComputeMetrics(rtc::ArrayView y); 47 | }; 48 | 49 | } // namespace webrtc 50 | 51 | #endif // MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_OUTPUT_H_ 52 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/subtractor_output_analyzer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_OUTPUT_ANALYZER_H_ 12 | #define MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_OUTPUT_ANALYZER_H_ 13 | 14 | #include "modules/audio_processing/aec3/subtractor_output.h" 15 | 16 | namespace webrtc { 17 | 18 | // Class for analyzing the properties subtractor output 19 | class SubtractorOutputAnalyzer { 20 | public: 21 | SubtractorOutputAnalyzer(); 22 | ~SubtractorOutputAnalyzer() = default; 23 | 24 | // Analyses the subtractor output. 25 | void Update(const SubtractorOutput& subtractor_output); 26 | 27 | bool ConvergedFilter() const { 28 | return main_filter_converged_ || shadow_filter_converged_; 29 | } 30 | 31 | bool DivergedFilter() const { return filter_diverged_; } 32 | 33 | // Handle echo path change. 34 | void HandleEchoPathChange(); 35 | 36 | private: 37 | const bool strict_divergence_check_; 38 | bool shadow_filter_converged_ = false; 39 | bool main_filter_converged_ = false; 40 | bool filter_diverged_ = false; 41 | }; 42 | 43 | } // namespace webrtc 44 | 45 | #endif // MODULES_AUDIO_PROCESSING_AEC3_SUBTRACTOR_OUTPUT_ANALYZER_H_ 46 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/aec3/vector_buffer.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/aec3/vector_buffer.h" 12 | 13 | #include 14 | 15 | namespace webrtc { 16 | 17 | VectorBuffer::VectorBuffer(size_t size, size_t height) 18 | : size(static_cast(size)), 19 | buffer(size, std::vector(height, 0.f)) { 20 | for (auto& c : buffer) { 21 | std::fill(c.begin(), c.end(), 0.f); 22 | } 23 | } 24 | 25 | VectorBuffer::~VectorBuffer() = default; 26 | 27 | } // namespace webrtc 28 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc/mock_agc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AGC_MOCK_AGC_H_ 12 | #define MODULES_AUDIO_PROCESSING_AGC_MOCK_AGC_H_ 13 | 14 | #include "modules/audio_processing/agc/agc.h" 15 | 16 | #include "test/gmock.h" 17 | 18 | namespace webrtc { 19 | 20 | class MockAgc : public Agc { 21 | public: 22 | virtual ~MockAgc() {} 23 | MOCK_METHOD2(AnalyzePreproc, float(const int16_t* audio, size_t length)); 24 | MOCK_METHOD3(Process, 25 | void(const int16_t* audio, size_t length, int sample_rate_hz)); 26 | MOCK_METHOD1(GetRmsErrorDb, bool(int* error)); 27 | MOCK_METHOD0(Reset, void()); 28 | MOCK_METHOD1(set_target_level_dbfs, int(int level)); 29 | MOCK_CONST_METHOD0(target_level_dbfs, int()); 30 | MOCK_METHOD1(EnableStandaloneVad, void(bool enable)); 31 | MOCK_CONST_METHOD0(standalone_vad_enabled, bool()); 32 | }; 33 | 34 | } // namespace webrtc 35 | 36 | #endif // MODULES_AUDIO_PROCESSING_AGC_MOCK_AGC_H_ 37 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc/utility.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/agc/utility.h" 12 | 13 | #include 14 | 15 | static const double kLog10 = 2.30258509299; 16 | static const double kLinear2DbScale = 20.0 / kLog10; 17 | static const double kLinear2LoudnessScale = 13.4 / kLog10; 18 | 19 | double Loudness2Db(double loudness) { 20 | return loudness * kLinear2DbScale / kLinear2LoudnessScale; 21 | } 22 | 23 | double Linear2Loudness(double rms) { 24 | if (rms == 0) 25 | return -15; 26 | return kLinear2LoudnessScale * log(rms); 27 | } 28 | 29 | double Db2Loudness(double db) { 30 | return db * kLinear2LoudnessScale / kLinear2DbScale; 31 | } 32 | 33 | double Dbfs2Loudness(double dbfs) { 34 | return Db2Loudness(90 + dbfs); 35 | } 36 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc/utility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AGC_UTILITY_H_ 12 | #define MODULES_AUDIO_PROCESSING_AGC_UTILITY_H_ 13 | 14 | // TODO(turajs): Add description of function. 15 | double Loudness2Db(double loudness); 16 | 17 | double Linear2Loudness(double rms); 18 | 19 | double Db2Loudness(double db); 20 | 21 | double Dbfs2Loudness(double dbfs); 22 | 23 | #endif // MODULES_AUDIO_PROCESSING_AGC_UTILITY_H_ 24 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc2/adaptive_agc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_AGC_H_ 12 | #define MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_AGC_H_ 13 | 14 | #include "modules/audio_processing/agc2/adaptive_digital_gain_applier.h" 15 | #include "modules/audio_processing/agc2/adaptive_mode_level_estimator.h" 16 | #include "modules/audio_processing/agc2/noise_level_estimator.h" 17 | #include "modules/audio_processing/agc2/vad_with_level.h" 18 | #include "modules/audio_processing/include/audio_frame_view.h" 19 | #include "modules/audio_processing/include/audio_processing.h" 20 | 21 | namespace webrtc { 22 | class ApmDataDumper; 23 | 24 | class AdaptiveAgc { 25 | public: 26 | explicit AdaptiveAgc(ApmDataDumper* apm_data_dumper); 27 | AdaptiveAgc(ApmDataDumper* apm_data_dumper, 28 | const AudioProcessing::Config::GainController2& config); 29 | ~AdaptiveAgc(); 30 | 31 | void Process(AudioFrameView float_frame, float last_audio_level); 32 | void Reset(); 33 | 34 | private: 35 | AdaptiveModeLevelEstimator speech_level_estimator_; 36 | VadWithLevel vad_; 37 | AdaptiveDigitalGainApplier gain_applier_; 38 | ApmDataDumper* const apm_data_dumper_; 39 | NoiseLevelEstimator noise_level_estimator_; 40 | }; 41 | 42 | } // namespace webrtc 43 | 44 | #endif // MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_AGC_H_ 45 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc2/agc2_testing_common.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/agc2/agc2_testing_common.h" 12 | 13 | #include "rtc_base/checks.h" 14 | 15 | namespace webrtc { 16 | 17 | namespace test { 18 | 19 | std::vector LinSpace(const double l, 20 | const double r, 21 | size_t num_points) { 22 | RTC_CHECK(num_points >= 2); 23 | std::vector points(num_points); 24 | const double step = (r - l) / (num_points - 1.0); 25 | points[0] = l; 26 | for (size_t i = 1; i < num_points - 1; i++) { 27 | points[i] = static_cast(l) + i * step; 28 | } 29 | points[num_points - 1] = r; 30 | return points; 31 | } 32 | } // namespace test 33 | } // namespace webrtc 34 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc2/biquad_filter.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/agc2/biquad_filter.h" 12 | 13 | #include 14 | 15 | namespace webrtc { 16 | 17 | // Transposed direct form I implementation of a bi-quad filter applied to an 18 | // input signal |x| to produce an output signal |y|. 19 | void BiQuadFilter::Process(rtc::ArrayView x, 20 | rtc::ArrayView y) { 21 | for (size_t k = 0; k < x.size(); ++k) { 22 | // Use temporary variable for x[k] to allow in-place function call 23 | // (that x and y refer to the same array). 24 | const float tmp = x[k]; 25 | y[k] = coefficients_.b[0] * tmp + coefficients_.b[1] * biquad_state_.b[0] + 26 | coefficients_.b[2] * biquad_state_.b[1] - 27 | coefficients_.a[0] * biquad_state_.a[0] - 28 | coefficients_.a[1] * biquad_state_.a[1]; 29 | biquad_state_.b[1] = biquad_state_.b[0]; 30 | biquad_state_.b[0] = tmp; 31 | biquad_state_.a[1] = biquad_state_.a[0]; 32 | biquad_state_.a[0] = y[k]; 33 | } 34 | } 35 | 36 | } // namespace webrtc 37 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc2/down_sampler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AGC2_DOWN_SAMPLER_H_ 12 | #define MODULES_AUDIO_PROCESSING_AGC2_DOWN_SAMPLER_H_ 13 | 14 | #include "api/array_view.h" 15 | #include "modules/audio_processing/agc2/biquad_filter.h" 16 | #include "rtc_base/constructormagic.h" 17 | 18 | namespace webrtc { 19 | 20 | class ApmDataDumper; 21 | 22 | class DownSampler { 23 | public: 24 | explicit DownSampler(ApmDataDumper* data_dumper); 25 | void Initialize(int sample_rate_hz); 26 | 27 | void DownSample(rtc::ArrayView in, rtc::ArrayView out); 28 | 29 | private: 30 | ApmDataDumper* data_dumper_; 31 | int sample_rate_hz_; 32 | int down_sampling_factor_; 33 | BiQuadFilter low_pass_filter_; 34 | 35 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DownSampler); 36 | }; 37 | 38 | } // namespace webrtc 39 | 40 | #endif // MODULES_AUDIO_PROCESSING_AGC2_DOWN_SAMPLER_H_ 41 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc2/fixed_gain_controller.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | #ifndef MODULES_AUDIO_PROCESSING_AGC2_FIXED_GAIN_CONTROLLER_H_ 11 | #define MODULES_AUDIO_PROCESSING_AGC2_FIXED_GAIN_CONTROLLER_H_ 12 | #include "modules/audio_processing/agc2/limiter.h" 13 | #include "modules/audio_processing/include/audio_frame_view.h" 14 | namespace webrtc { 15 | class ApmDataDumper; 16 | class FixedGainController { 17 | public: 18 | explicit FixedGainController(ApmDataDumper* apm_data_dumper); 19 | FixedGainController(ApmDataDumper* apm_data_dumper, 20 | std::string histogram_name_prefix); 21 | void Process(AudioFrameView signal); 22 | // Gain and sample rate may be changed at any time (but not 23 | // concurrently with any other method call). 24 | void SetGain(float gain_to_apply_db); 25 | void SetSampleRate(size_t sample_rate_hz); 26 | float LastAudioLevel() const; 27 | private: 28 | float gain_to_apply_ = 1.f; 29 | ApmDataDumper* apm_data_dumper_ = nullptr; 30 | Limiter limiter_; 31 | }; 32 | } // namespace webrtc 33 | #endif // MODULES_AUDIO_PROCESSING_AGC2_FIXED_GAIN_CONTROLLER_H_ -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc2/gain_applier.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AGC2_GAIN_APPLIER_H_ 12 | #define MODULES_AUDIO_PROCESSING_AGC2_GAIN_APPLIER_H_ 13 | 14 | #include 15 | 16 | #include "modules/audio_processing/include/audio_frame_view.h" 17 | 18 | namespace webrtc { 19 | class GainApplier { 20 | public: 21 | GainApplier(bool hard_clip_samples, float initial_gain_factor); 22 | 23 | void ApplyGain(AudioFrameView signal); 24 | void SetGainFactor(float gain_factor); 25 | float GetGainFactor() const { return current_gain_factor_; }; 26 | 27 | private: 28 | void Initialize(size_t samples_per_channel); 29 | 30 | // Whether to clip samples after gain is applied. If 'true', result 31 | // will fit in FloatS16 range. 32 | const bool hard_clip_samples_; 33 | float last_gain_factor_; 34 | 35 | // If this value is not equal to 'last_gain_factor', gain will be 36 | // ramped from 'last_gain_factor_' to this value during the next 37 | // 'ApplyGain'. 38 | float current_gain_factor_; 39 | int samples_per_channel_ = -1; 40 | float inverse_samples_per_channel_ = -1.f; 41 | }; 42 | } // namespace webrtc 43 | 44 | #endif // MODULES_AUDIO_PROCESSING_AGC2_GAIN_APPLIER_H_ 45 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc2/noise_level_estimator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AGC2_NOISE_LEVEL_ESTIMATOR_H_ 12 | #define MODULES_AUDIO_PROCESSING_AGC2_NOISE_LEVEL_ESTIMATOR_H_ 13 | 14 | #include "modules/audio_processing/agc2/signal_classifier.h" 15 | #include "modules/audio_processing/include/audio_frame_view.h" 16 | #include "rtc_base/constructormagic.h" 17 | 18 | namespace webrtc { 19 | class ApmDataDumper; 20 | 21 | class NoiseLevelEstimator { 22 | public: 23 | NoiseLevelEstimator(ApmDataDumper* data_dumper); 24 | ~NoiseLevelEstimator(); 25 | // Returns the estimated noise level in dBFS. 26 | float Analyze(const AudioFrameView& frame); 27 | 28 | private: 29 | void Initialize(int sample_rate_hz); 30 | 31 | int sample_rate_hz_; 32 | float min_noise_energy_; 33 | bool first_update_; 34 | float noise_energy_; 35 | int noise_energy_hold_counter_; 36 | SignalClassifier signal_classifier_; 37 | 38 | RTC_DISALLOW_COPY_AND_ASSIGN(NoiseLevelEstimator); 39 | }; 40 | 41 | } // namespace webrtc 42 | 43 | #endif // MODULES_AUDIO_PROCESSING_AGC2_NOISE_LEVEL_ESTIMATOR_H_ 44 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc2/noise_spectrum_estimator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AGC2_NOISE_SPECTRUM_ESTIMATOR_H_ 12 | #define MODULES_AUDIO_PROCESSING_AGC2_NOISE_SPECTRUM_ESTIMATOR_H_ 13 | 14 | #include "api/array_view.h" 15 | #include "rtc_base/constructormagic.h" 16 | 17 | namespace webrtc { 18 | 19 | class ApmDataDumper; 20 | 21 | class NoiseSpectrumEstimator { 22 | public: 23 | explicit NoiseSpectrumEstimator(ApmDataDumper* data_dumper); 24 | void Initialize(); 25 | void Update(rtc::ArrayView spectrum, bool first_update); 26 | 27 | rtc::ArrayView GetNoiseSpectrum() const { 28 | return rtc::ArrayView(noise_spectrum_); 29 | } 30 | 31 | private: 32 | ApmDataDumper* data_dumper_; 33 | float noise_spectrum_[65]; 34 | 35 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(NoiseSpectrumEstimator); 36 | }; 37 | 38 | } // namespace webrtc 39 | 40 | #endif // MODULES_AUDIO_PROCESSING_AGC2_NOISE_SPECTRUM_ESTIMATOR_H_ 41 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc2/rnn_vad/lp_residual.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_LP_RESIDUAL_H_ 12 | #define MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_LP_RESIDUAL_H_ 13 | 14 | #include 15 | 16 | #include "api/array_view.h" 17 | 18 | namespace webrtc { 19 | namespace rnn_vad { 20 | 21 | // LPC inverse filter length. 22 | constexpr size_t kNumLpcCoefficients = 5; 23 | 24 | // Given a frame |x|, computes a post-processed version of LPC coefficients 25 | // tailored for pitch estimation. 26 | void ComputeAndPostProcessLpcCoefficients( 27 | rtc::ArrayView x, 28 | rtc::ArrayView lpc_coeffs); 29 | 30 | // Computes the LP residual for the input frame |x| and the LPC coefficients 31 | // |lpc_coeffs|. |y| and |x| can point to the same array for in-place 32 | // computation. 33 | void ComputeLpResidual( 34 | rtc::ArrayView lpc_coeffs, 35 | rtc::ArrayView x, 36 | rtc::ArrayView y); 37 | 38 | } // namespace rnn_vad 39 | } // namespace webrtc 40 | 41 | #endif // MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_LP_RESIDUAL_H_ 42 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc2/rnn_vad/pitch_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_PITCH_INFO_H_ 12 | #define MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_PITCH_INFO_H_ 13 | 14 | namespace webrtc { 15 | namespace rnn_vad { 16 | 17 | // Stores pitch period and gain information. The pitch gain measures the 18 | // strength of the pitch (the higher, the stronger). 19 | struct PitchInfo { 20 | PitchInfo() : period(0), gain(0.f) {} 21 | PitchInfo(size_t p, float g) : period(p), gain(g) {} 22 | size_t period; 23 | float gain; 24 | }; 25 | 26 | } // namespace rnn_vad 27 | } // namespace webrtc 28 | 29 | #endif // MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_PITCH_INFO_H_ 30 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc2/vector_float_frame.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/agc2/vector_float_frame.h" 12 | 13 | namespace webrtc { 14 | 15 | namespace { 16 | 17 | std::vector ConstructChannelPointers( 18 | std::vector>* x) { 19 | std::vector channel_ptrs; 20 | for (auto& v : *x) { 21 | channel_ptrs.push_back(v.data()); 22 | } 23 | return channel_ptrs; 24 | } 25 | } // namespace 26 | 27 | VectorFloatFrame::VectorFloatFrame(int num_channels, 28 | int samples_per_channel, 29 | float start_value) 30 | : channels_(num_channels, 31 | std::vector(samples_per_channel, start_value)), 32 | channel_ptrs_(ConstructChannelPointers(&channels_)), 33 | float_frame_view_(channel_ptrs_.data(), 34 | channels_.size(), 35 | samples_per_channel) {} 36 | 37 | VectorFloatFrame::~VectorFloatFrame() = default; 38 | 39 | } // namespace webrtc 40 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/agc2/vector_float_frame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_AGC2_VECTOR_FLOAT_FRAME_H_ 12 | #define MODULES_AUDIO_PROCESSING_AGC2_VECTOR_FLOAT_FRAME_H_ 13 | 14 | #include 15 | 16 | #include "modules/audio_processing/include/audio_frame_view.h" 17 | 18 | namespace webrtc { 19 | 20 | // A construct consisting of a multi-channel audio frame, and a FloatFrame view 21 | // of it. 22 | class VectorFloatFrame { 23 | public: 24 | VectorFloatFrame(int num_channels, 25 | int samples_per_channel, 26 | float start_value); 27 | const AudioFrameView& float_frame_view() { return float_frame_view_; } 28 | AudioFrameView float_frame_view() const { 29 | return float_frame_view_; 30 | } 31 | 32 | ~VectorFloatFrame(); 33 | 34 | private: 35 | std::vector> channels_; 36 | std::vector channel_ptrs_; 37 | AudioFrameView float_frame_view_; 38 | }; 39 | 40 | } // namespace webrtc 41 | 42 | #endif // MODULES_AUDIO_PROCESSING_AGC2_VECTOR_FLOAT_FRAME_H_ 43 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/audio_generator/file_audio_generator.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/audio_generator/file_audio_generator.h" 12 | 13 | namespace webrtc { 14 | 15 | FileAudioGenerator::FileAudioGenerator( 16 | std::unique_ptr input_audio_file) { 17 | // TODO(bugs.webrtc.org/8882) Stub. 18 | // Read audio from file into internal buffer. 19 | } 20 | 21 | FileAudioGenerator::~FileAudioGenerator() = default; 22 | 23 | void FileAudioGenerator::FillFrame(AudioFrameView audio) { 24 | // TODO(bugs.webrtc.org/8882) Stub. 25 | // Fill |audio| from internal buffer. 26 | } 27 | 28 | size_t FileAudioGenerator::NumChannels() { 29 | return num_channels_; 30 | } 31 | 32 | size_t FileAudioGenerator::SampleRateHz() { 33 | return sample_rate_hz_; 34 | } 35 | 36 | } // namespace webrtc 37 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_COMMON_H_ 12 | #define MODULES_AUDIO_PROCESSING_COMMON_H_ 13 | 14 | #include "modules/audio_processing/include/audio_processing.h" 15 | #include "rtc_base/checks.h" 16 | 17 | namespace webrtc { 18 | 19 | static inline size_t ChannelsFromLayout(AudioProcessing::ChannelLayout layout) { 20 | switch (layout) { 21 | case AudioProcessing::kMono: 22 | case AudioProcessing::kMonoAndKeyboard: 23 | return 1; 24 | case AudioProcessing::kStereo: 25 | case AudioProcessing::kStereoAndKeyboard: 26 | return 2; 27 | } 28 | RTC_NOTREACHED(); 29 | return 0; 30 | } 31 | 32 | } // namespace webrtc 33 | 34 | #endif // MODULES_AUDIO_PROCESSING_COMMON_H_ 35 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/echo_detector/circular_buffer.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/echo_detector/circular_buffer.h" 12 | 13 | #include 14 | 15 | #include "rtc_base/checks.h" 16 | 17 | namespace webrtc { 18 | 19 | CircularBuffer::CircularBuffer(size_t size) : buffer_(size) {} 20 | CircularBuffer::~CircularBuffer() = default; 21 | 22 | void CircularBuffer::Push(float value) { 23 | buffer_[next_insertion_index_] = value; 24 | ++next_insertion_index_; 25 | next_insertion_index_ %= buffer_.size(); 26 | RTC_DCHECK_LT(next_insertion_index_, buffer_.size()); 27 | nr_elements_in_buffer_ = std::min(nr_elements_in_buffer_ + 1, buffer_.size()); 28 | RTC_DCHECK_LE(nr_elements_in_buffer_, buffer_.size()); 29 | } 30 | 31 | absl::optional CircularBuffer::Pop() { 32 | if (nr_elements_in_buffer_ == 0) { 33 | return absl::nullopt; 34 | } 35 | const size_t index = 36 | (buffer_.size() + next_insertion_index_ - nr_elements_in_buffer_) % 37 | buffer_.size(); 38 | RTC_DCHECK_LT(index, buffer_.size()); 39 | --nr_elements_in_buffer_; 40 | return buffer_[index]; 41 | } 42 | 43 | void CircularBuffer::Clear() { 44 | std::fill(buffer_.begin(), buffer_.end(), 0.f); 45 | next_insertion_index_ = 0; 46 | nr_elements_in_buffer_ = 0; 47 | } 48 | 49 | } // namespace webrtc 50 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/echo_detector/circular_buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_CIRCULAR_BUFFER_H_ 12 | #define MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_CIRCULAR_BUFFER_H_ 13 | 14 | #include 15 | #include 16 | 17 | #include "absl/types/optional.h" 18 | 19 | namespace webrtc { 20 | 21 | // Ring buffer containing floating point values. 22 | struct CircularBuffer { 23 | public: 24 | explicit CircularBuffer(size_t size); 25 | ~CircularBuffer(); 26 | 27 | void Push(float value); 28 | absl::optional Pop(); 29 | size_t Size() const { return nr_elements_in_buffer_; } 30 | // This function fills the buffer with zeros, but does not change its size. 31 | void Clear(); 32 | 33 | private: 34 | std::vector buffer_; 35 | size_t next_insertion_index_ = 0; 36 | // This is the number of elements that have been pushed into the circular 37 | // buffer, not the allocated buffer size. 38 | size_t nr_elements_in_buffer_ = 0; 39 | }; 40 | 41 | } // namespace webrtc 42 | 43 | #endif // MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_CIRCULAR_BUFFER_H_ 44 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/echo_detector/mean_variance_estimator.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/echo_detector/mean_variance_estimator.h" 12 | 13 | #include 14 | 15 | #include "rtc_base/checks.h" 16 | 17 | namespace webrtc { 18 | namespace { 19 | 20 | // Parameter controlling the adaptation speed. 21 | constexpr float kAlpha = 0.001f; 22 | 23 | } // namespace 24 | 25 | void MeanVarianceEstimator::Update(float value) { 26 | mean_ = (1.f - kAlpha) * mean_ + kAlpha * value; 27 | variance_ = 28 | (1.f - kAlpha) * variance_ + kAlpha * (value - mean_) * (value - mean_); 29 | RTC_DCHECK(isfinite(mean_)); 30 | RTC_DCHECK(isfinite(variance_)); 31 | } 32 | 33 | float MeanVarianceEstimator::std_deviation() const { 34 | RTC_DCHECK_GE(variance_, 0.f); 35 | return sqrtf(variance_); 36 | } 37 | 38 | float MeanVarianceEstimator::mean() const { 39 | return mean_; 40 | } 41 | 42 | void MeanVarianceEstimator::Clear() { 43 | mean_ = 0.f; 44 | variance_ = 0.f; 45 | } 46 | 47 | } // namespace webrtc 48 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/echo_detector/mean_variance_estimator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_MEAN_VARIANCE_ESTIMATOR_H_ 12 | #define MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_MEAN_VARIANCE_ESTIMATOR_H_ 13 | 14 | namespace webrtc { 15 | 16 | // This class iteratively estimates the mean and variance of a signal. 17 | class MeanVarianceEstimator { 18 | public: 19 | void Update(float value); 20 | float std_deviation() const; 21 | float mean() const; 22 | void Clear(); 23 | 24 | private: 25 | // Estimate of the expected value of the input values. 26 | float mean_ = 0.f; 27 | // Estimate of the variance of the input values. 28 | float variance_ = 0.f; 29 | }; 30 | 31 | } // namespace webrtc 32 | 33 | #endif // MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_MEAN_VARIANCE_ESTIMATOR_H_ 34 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/echo_detector/moving_max.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/echo_detector/moving_max.h" 12 | 13 | #include "rtc_base/checks.h" 14 | 15 | namespace webrtc { 16 | namespace { 17 | 18 | // Parameter for controlling how fast the estimated maximum decays after the 19 | // previous maximum is no longer valid. With a value of 0.99, the maximum will 20 | // decay to 1% of its former value after 460 updates. 21 | constexpr float kDecayFactor = 0.99f; 22 | 23 | } // namespace 24 | 25 | MovingMax::MovingMax(size_t window_size) : window_size_(window_size) { 26 | RTC_DCHECK_GT(window_size, 0); 27 | } 28 | 29 | MovingMax::~MovingMax() {} 30 | 31 | void MovingMax::Update(float value) { 32 | if (counter_ >= window_size_ - 1) { 33 | max_value_ *= kDecayFactor; 34 | } else { 35 | ++counter_; 36 | } 37 | if (value > max_value_) { 38 | max_value_ = value; 39 | counter_ = 0; 40 | } 41 | } 42 | 43 | float MovingMax::max() const { 44 | return max_value_; 45 | } 46 | 47 | void MovingMax::Clear() { 48 | max_value_ = 0.f; 49 | counter_ = 0; 50 | } 51 | 52 | } // namespace webrtc 53 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/echo_detector/moving_max.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_MOVING_MAX_H_ 12 | #define MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_MOVING_MAX_H_ 13 | 14 | #include 15 | 16 | namespace webrtc { 17 | 18 | class MovingMax { 19 | public: 20 | explicit MovingMax(size_t window_size); 21 | ~MovingMax(); 22 | 23 | void Update(float value); 24 | float max() const; 25 | // Reset all of the state in this class. 26 | void Clear(); 27 | 28 | private: 29 | float max_value_ = 0.f; 30 | size_t counter_ = 0; 31 | size_t window_size_ = 1; 32 | }; 33 | 34 | } // namespace webrtc 35 | 36 | #endif // MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_MOVING_MAX_H_ 37 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/echo_detector/normalized_covariance_estimator.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/echo_detector/normalized_covariance_estimator.h" 12 | 13 | #include 14 | 15 | #include "rtc_base/checks.h" 16 | 17 | namespace webrtc { 18 | namespace { 19 | 20 | // Parameter controlling the adaptation speed. 21 | constexpr float kAlpha = 0.001f; 22 | 23 | } // namespace 24 | 25 | void NormalizedCovarianceEstimator::Update(float x, 26 | float x_mean, 27 | float x_sigma, 28 | float y, 29 | float y_mean, 30 | float y_sigma) { 31 | covariance_ = 32 | (1.f - kAlpha) * covariance_ + kAlpha * (x - x_mean) * (y - y_mean); 33 | normalized_cross_correlation_ = covariance_ / (x_sigma * y_sigma + .0001f); 34 | RTC_DCHECK(isfinite(covariance_)); 35 | RTC_DCHECK(isfinite(normalized_cross_correlation_)); 36 | } 37 | 38 | void NormalizedCovarianceEstimator::Clear() { 39 | covariance_ = 0.f; 40 | normalized_cross_correlation_ = 0.f; 41 | } 42 | 43 | } // namespace webrtc 44 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/echo_detector/normalized_covariance_estimator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_NORMALIZED_COVARIANCE_ESTIMATOR_H_ 12 | #define MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_NORMALIZED_COVARIANCE_ESTIMATOR_H_ 13 | 14 | namespace webrtc { 15 | 16 | // This class iteratively estimates the normalized covariance between two 17 | // signals. 18 | class NormalizedCovarianceEstimator { 19 | public: 20 | void Update(float x, 21 | float x_mean, 22 | float x_var, 23 | float y, 24 | float y_mean, 25 | float y_var); 26 | // This function returns an estimate of the Pearson product-moment correlation 27 | // coefficient of the two signals. 28 | float normalized_cross_correlation() const { 29 | return normalized_cross_correlation_; 30 | } 31 | float covariance() const { return covariance_; } 32 | // This function resets the estimated values to zero. 33 | void Clear(); 34 | 35 | private: 36 | float normalized_cross_correlation_ = 0.f; 37 | // Estimate of the covariance value. 38 | float covariance_ = 0.f; 39 | }; 40 | 41 | } // namespace webrtc 42 | 43 | #endif // MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_NORMALIZED_COVARIANCE_ESTIMATOR_H_ 44 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/include/audio_generator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_GENERATOR_H_ 12 | #define MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_GENERATOR_H_ 13 | 14 | #include "modules/audio_processing/include/audio_frame_view.h" 15 | 16 | namespace webrtc { 17 | // This class is used as input sink for the APM, for diagnostic purposes. 18 | // Generates an infinite audio signal, [-1, 1] floating point values, in frames 19 | // of fixed channel count and sample rate. 20 | class AudioGenerator { 21 | public: 22 | virtual ~AudioGenerator() {} 23 | 24 | // Fill |audio| with the next samples of the audio signal. 25 | virtual void FillFrame(AudioFrameView audio) = 0; 26 | 27 | // Return the number of channels output by the AudioGenerator. 28 | virtual size_t NumChannels() = 0; 29 | 30 | // Return the sample rate output by the AudioGenerator. 31 | virtual size_t SampleRateHz() = 0; 32 | }; 33 | 34 | } // namespace webrtc 35 | 36 | #endif // MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_GENERATOR_H_ 37 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/include/audio_generator_factory.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/include/audio_generator_factory.h" 12 | 13 | #include "absl/memory/memory.h" 14 | #include "common_audio/wav_file.h" 15 | #include "modules/audio_processing/audio_generator/file_audio_generator.h" 16 | 17 | namespace webrtc { 18 | 19 | std::unique_ptr AudioGeneratorFactory::Create( 20 | const std::string& file_name) { 21 | std::unique_ptr input_audio_file(new WavReader(file_name)); 22 | return absl::make_unique(std::move(input_audio_file)); 23 | } 24 | 25 | } // namespace webrtc 26 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/include/audio_generator_factory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_GENERATOR_FACTORY_H_ 12 | #define MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_GENERATOR_FACTORY_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "modules/audio_processing/include/audio_generator.h" 19 | 20 | namespace webrtc { 21 | 22 | class AudioGeneratorFactory { 23 | public: 24 | // Creates an AudioGenerator that reads the playout audio from a given 16-bit 25 | // int-encoded WAV file. 26 | static std::unique_ptr Create(const std::string& file_name); 27 | }; 28 | 29 | } // namespace webrtc 30 | 31 | #endif // MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_GENERATOR_FACTORY_H_ 32 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/include/audio_processing.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/include/audio_processing.h" 12 | 13 | namespace webrtc { 14 | 15 | void CustomProcessing::SetRuntimeSetting( 16 | AudioProcessing::RuntimeSetting setting) {} 17 | 18 | } // namespace webrtc 19 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/include/audio_processing_statistics.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/include/audio_processing_statistics.h" 12 | 13 | namespace webrtc { 14 | 15 | AudioProcessingStats::AudioProcessingStats() = default; 16 | 17 | AudioProcessingStats::AudioProcessingStats(const AudioProcessingStats& other) = 18 | default; 19 | 20 | AudioProcessingStats::~AudioProcessingStats() = default; 21 | 22 | } // namespace webrtc 23 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/include/config.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/include/config.h" 12 | 13 | namespace webrtc { 14 | 15 | Config::Config() {} 16 | 17 | Config::~Config() { 18 | for (OptionMap::iterator it = options_.begin(); it != options_.end(); ++it) { 19 | delete it->second; 20 | } 21 | } 22 | 23 | } // namespace webrtc 24 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/level_estimator_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_IMPL_H_ 12 | #define MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_IMPL_H_ 13 | 14 | #include 15 | 16 | #include "modules/audio_processing/include/audio_processing.h" 17 | #include "rtc_base/constructormagic.h" 18 | #include "rtc_base/criticalsection.h" 19 | 20 | namespace webrtc { 21 | 22 | class AudioBuffer; 23 | class RmsLevel; 24 | 25 | class LevelEstimatorImpl : public LevelEstimator { 26 | public: 27 | explicit LevelEstimatorImpl(rtc::CriticalSection* crit); 28 | ~LevelEstimatorImpl() override; 29 | 30 | // TODO(peah): Fold into ctor, once public API is removed. 31 | void Initialize(); 32 | void ProcessStream(AudioBuffer* audio); 33 | 34 | // LevelEstimator implementation. 35 | int Enable(bool enable) override; 36 | bool is_enabled() const override; 37 | int RMS() override; 38 | 39 | private: 40 | rtc::CriticalSection* const crit_ = nullptr; 41 | bool enabled_ RTC_GUARDED_BY(crit_) = false; 42 | std::unique_ptr rms_ RTC_GUARDED_BY(crit_); 43 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(LevelEstimatorImpl); 44 | }; 45 | } // namespace webrtc 46 | 47 | #endif // MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_IMPL_H_ 48 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/low_cut_filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_LOW_CUT_FILTER_H_ 12 | #define MODULES_AUDIO_PROCESSING_LOW_CUT_FILTER_H_ 13 | 14 | #include 15 | #include 16 | 17 | #include "rtc_base/constructormagic.h" 18 | 19 | namespace webrtc { 20 | 21 | class AudioBuffer; 22 | 23 | class LowCutFilter { 24 | public: 25 | LowCutFilter(size_t channels, int sample_rate_hz); 26 | ~LowCutFilter(); 27 | void Process(AudioBuffer* audio); 28 | 29 | private: 30 | class BiquadFilter; 31 | std::vector> filters_; 32 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(LowCutFilter); 33 | }; 34 | } // namespace webrtc 35 | 36 | #endif // MODULES_AUDIO_PROCESSING_LOW_CUT_FILTER_H_ 37 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/render_queue_item_verifier.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_RENDER_QUEUE_ITEM_VERIFIER_H_ 12 | #define MODULES_AUDIO_PROCESSING_RENDER_QUEUE_ITEM_VERIFIER_H_ 13 | 14 | #include 15 | 16 | namespace webrtc { 17 | 18 | // Functor to use when supplying a verifier function for the queue item 19 | // verifcation. 20 | template 21 | class RenderQueueItemVerifier { 22 | public: 23 | explicit RenderQueueItemVerifier(size_t minimum_capacity) 24 | : minimum_capacity_(minimum_capacity) {} 25 | 26 | bool operator()(const std::vector& v) const { 27 | return v.capacity() >= minimum_capacity_; 28 | } 29 | 30 | private: 31 | size_t minimum_capacity_; 32 | }; 33 | 34 | } // namespace webrtc 35 | 36 | #endif // MODULES_AUDIO_PROCESSING_RENDER_QUEUE_ITEM_VERIFIER_H__ 37 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/transient/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_COMMON_H_ 12 | #define MODULES_AUDIO_PROCESSING_TRANSIENT_COMMON_H_ 13 | namespace webrtc { 14 | namespace ts { 15 | 16 | static const float kPi = 3.14159265358979323846f; 17 | static const int kChunkSizeMs = 10; 18 | enum { 19 | kSampleRate8kHz = 8000, 20 | kSampleRate16kHz = 16000, 21 | kSampleRate32kHz = 32000, 22 | kSampleRate48kHz = 48000 23 | }; 24 | 25 | } // namespace ts 26 | } // namespace webrtc 27 | #endif // MODULES_AUDIO_PROCESSING_TRANSIENT_COMMON_H_ 28 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/transient/moving_moments.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/transient/moving_moments.h" 12 | 13 | #include 14 | 15 | #include "rtc_base/checks.h" 16 | 17 | namespace webrtc { 18 | 19 | MovingMoments::MovingMoments(size_t length) 20 | : length_(length), queue_(), sum_(0.0), sum_of_squares_(0.0) { 21 | RTC_DCHECK_GT(length, 0); 22 | for (size_t i = 0; i < length; ++i) { 23 | queue_.push(0.0); 24 | } 25 | } 26 | 27 | MovingMoments::~MovingMoments() {} 28 | 29 | void MovingMoments::CalculateMoments(const float* in, 30 | size_t in_length, 31 | float* first, 32 | float* second) { 33 | RTC_DCHECK(in); 34 | RTC_DCHECK_GT(in_length, 0); 35 | RTC_DCHECK(first); 36 | RTC_DCHECK(second); 37 | 38 | for (size_t i = 0; i < in_length; ++i) { 39 | const float old_value = queue_.front(); 40 | queue_.pop(); 41 | queue_.push(in[i]); 42 | 43 | sum_ += in[i] - old_value; 44 | sum_of_squares_ += in[i] * in[i] - old_value * old_value; 45 | first[i] = sum_ / length_; 46 | second[i] = std::max(0.f, sum_of_squares_ / length_); 47 | } 48 | } 49 | 50 | } // namespace webrtc 51 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/transient/wpd_node.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_WPD_NODE_H_ 12 | #define MODULES_AUDIO_PROCESSING_TRANSIENT_WPD_NODE_H_ 13 | 14 | #include 15 | 16 | namespace webrtc { 17 | 18 | class FIRFilter; 19 | 20 | // A single node of a Wavelet Packet Decomposition (WPD) tree. 21 | class WPDNode { 22 | public: 23 | // Creates a WPDNode. The data vector will contain zeros. The filter will have 24 | // the coefficients provided. 25 | WPDNode(size_t length, const float* coefficients, size_t coefficients_length); 26 | ~WPDNode(); 27 | 28 | // Updates the node data. |parent_data| / 2 must be equals to |length_|. 29 | // Returns 0 if correct, and -1 otherwise. 30 | int Update(const float* parent_data, size_t parent_data_length); 31 | 32 | const float* data() const { return data_.get(); } 33 | // Returns 0 if correct, and -1 otherwise. 34 | int set_data(const float* new_data, size_t length); 35 | size_t length() const { return length_; } 36 | 37 | private: 38 | std::unique_ptr data_; 39 | size_t length_; 40 | std::unique_ptr filter_; 41 | }; 42 | 43 | } // namespace webrtc 44 | 45 | #endif // MODULES_AUDIO_PROCESSING_TRANSIENT_WPD_NODE_H_ 46 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/utility/block_mean_calculator.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The WebRTC Project Authors. All rights reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "modules/audio_processing/utility/block_mean_calculator.h" 12 | 13 | #include "rtc_base/checks.h" 14 | 15 | namespace webrtc { 16 | 17 | BlockMeanCalculator::BlockMeanCalculator(size_t block_length) 18 | : block_length_(block_length), count_(0), sum_(0.0), mean_(0.0) { 19 | RTC_DCHECK(block_length_ != 0); 20 | } 21 | 22 | void BlockMeanCalculator::Reset() { 23 | Clear(); 24 | mean_ = 0.0; 25 | } 26 | 27 | void BlockMeanCalculator::AddValue(float value) { 28 | sum_ += value; 29 | ++count_; 30 | if (count_ == block_length_) { 31 | mean_ = sum_ / block_length_; 32 | Clear(); 33 | } 34 | } 35 | 36 | bool BlockMeanCalculator::EndOfBlock() const { 37 | return count_ == 0; 38 | } 39 | 40 | float BlockMeanCalculator::GetLatestMean() const { 41 | return mean_; 42 | } 43 | 44 | // Flush all samples added. 45 | void BlockMeanCalculator::Clear() { 46 | count_ = 0; 47 | sum_ = 0.0; 48 | } 49 | 50 | } // namespace webrtc 51 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/utility/block_mean_calculator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The WebRTC Project Authors. All rights reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_UTILITY_BLOCK_MEAN_CALCULATOR_H_ 12 | #define MODULES_AUDIO_PROCESSING_UTILITY_BLOCK_MEAN_CALCULATOR_H_ 13 | 14 | #include 15 | 16 | #include "rtc_base/constructormagic.h" 17 | 18 | namespace webrtc { 19 | 20 | // BlockMeanCalculator calculates the mean of a block of values. Values are 21 | // added one after another, and the mean is updated at the end of every block. 22 | class BlockMeanCalculator { 23 | public: 24 | explicit BlockMeanCalculator(size_t block_length); 25 | 26 | // Reset. 27 | void Reset(); 28 | 29 | // Add one value to the sequence. 30 | void AddValue(float value); 31 | 32 | // Return whether the latest added value was at the end of a block. 33 | bool EndOfBlock() const; 34 | 35 | // Return the latest mean. 36 | float GetLatestMean() const; 37 | 38 | private: 39 | // Clear all values added. 40 | void Clear(); 41 | 42 | const size_t block_length_; 43 | size_t count_; 44 | float sum_; 45 | float mean_; 46 | 47 | RTC_DISALLOW_COPY_AND_ASSIGN(BlockMeanCalculator); 48 | }; 49 | 50 | } // namespace webrtc 51 | 52 | #endif // MODULES_AUDIO_PROCESSING_UTILITY_BLOCK_MEAN_CALCULATOR_H_ 53 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/utility/delay_estimator_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | // Header file including the delay estimator handle used for testing. 12 | 13 | #ifndef MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_INTERNAL_H_ 14 | #define MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_INTERNAL_H_ 15 | 16 | #include "modules/audio_processing/utility/delay_estimator.h" 17 | 18 | typedef union { 19 | float float_; 20 | int32_t int32_; 21 | } SpectrumType; 22 | 23 | typedef struct { 24 | // Pointers to mean values of spectrum. 25 | SpectrumType* mean_far_spectrum; 26 | // |mean_far_spectrum| initialization indicator. 27 | int far_spectrum_initialized; 28 | 29 | int spectrum_size; 30 | 31 | // Far-end part of binary spectrum based delay estimation. 32 | BinaryDelayEstimatorFarend* binary_farend; 33 | } DelayEstimatorFarend; 34 | 35 | typedef struct { 36 | // Pointers to mean values of spectrum. 37 | SpectrumType* mean_near_spectrum; 38 | // |mean_near_spectrum| initialization indicator. 39 | int near_spectrum_initialized; 40 | 41 | int spectrum_size; 42 | 43 | // Binary spectrum based delay estimator 44 | BinaryDelayEstimator* binary_handle; 45 | } DelayEstimator; 46 | 47 | #endif // MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_INTERNAL_H_ 48 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/vad/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_VAD_COMMON_H_ 12 | #define MODULES_AUDIO_PROCESSING_VAD_COMMON_H_ 13 | 14 | #include 15 | 16 | static const int kSampleRateHz = 16000; 17 | static const size_t kLength10Ms = kSampleRateHz / 100; 18 | static const size_t kMaxNumFrames = 4; 19 | 20 | struct AudioFeatures { 21 | double log_pitch_gain[kMaxNumFrames]; 22 | double pitch_lag_hz[kMaxNumFrames]; 23 | double spectral_peak[kMaxNumFrames]; 24 | double rms[kMaxNumFrames]; 25 | size_t num_frames; 26 | bool silence; 27 | }; 28 | 29 | #endif // MODULES_AUDIO_PROCESSING_VAD_COMMON_H_ 30 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/modules/audio_processing/vad/pitch_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef MODULES_AUDIO_PROCESSING_VAD_PITCH_INTERNAL_H_ 12 | #define MODULES_AUDIO_PROCESSING_VAD_PITCH_INTERNAL_H_ 13 | 14 | // TODO(turajs): Write a description of this function. Also be consistent with 15 | // usage of |sampling_rate_hz| vs |kSamplingFreqHz|. 16 | void GetSubframesPitchParameters(int sampling_rate_hz, 17 | double* gains, 18 | double* lags, 19 | int num_in_frames, 20 | int num_out_frames, 21 | double* log_old_gain, 22 | double* old_lag, 23 | double* log_pitch_gain, 24 | double* pitch_lag_hz); 25 | 26 | #endif // MODULES_AUDIO_PROCESSING_VAD_PITCH_INTERNAL_H_ 27 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/arraysize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef RTC_BASE_ARRAYSIZE_H_ 12 | #define RTC_BASE_ARRAYSIZE_H_ 13 | 14 | #include 15 | 16 | // This file defines the arraysize() macro and is derived from Chromium's 17 | // base/macros.h. 18 | 19 | // The arraysize(arr) macro returns the # of elements in an array arr. 20 | // The expression is a compile-time constant, and therefore can be 21 | // used in defining new arrays, for example. If you use arraysize on 22 | // a pointer by mistake, you will get a compile-time error. 23 | 24 | // This template function declaration is used in defining arraysize. 25 | // Note that the function doesn't need an implementation, as we only 26 | // use its type. 27 | template 28 | char (&ArraySizeHelper(T (&array)[N]))[N]; 29 | 30 | #define arraysize(array) (sizeof(ArraySizeHelper(array))) 31 | 32 | #endif // RTC_BASE_ARRAYSIZE_H_ 33 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/compile_assert_c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef RTC_BASE_COMPILE_ASSERT_C_H_ 12 | #define RTC_BASE_COMPILE_ASSERT_C_H_ 13 | 14 | // Use this macro to verify at compile time that certain restrictions are met. 15 | // The argument is the boolean expression to evaluate. 16 | // Example: 17 | // RTC_COMPILE_ASSERT(sizeof(foo) < 128); 18 | // Note: In C++, use static_assert instead! 19 | #define RTC_COMPILE_ASSERT(expression) \ 20 | switch (0) { \ 21 | case 0: \ 22 | case expression:; \ 23 | } 24 | 25 | #endif // RTC_BASE_COMPILE_ASSERT_C_H_ 26 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/constructormagic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef RTC_BASE_CONSTRUCTORMAGIC_H_ 12 | #define RTC_BASE_CONSTRUCTORMAGIC_H_ 13 | 14 | // Put this in the declarations for a class to be unassignable. 15 | #define RTC_DISALLOW_ASSIGN(TypeName) \ 16 | TypeName& operator=(const TypeName&) = delete 17 | 18 | // A macro to disallow the copy constructor and operator= functions. This should 19 | // be used in the declarations for a class. 20 | #define RTC_DISALLOW_COPY_AND_ASSIGN(TypeName) \ 21 | TypeName(const TypeName&) = delete; \ 22 | RTC_DISALLOW_ASSIGN(TypeName) 23 | 24 | // A macro to disallow all the implicit constructors, namely the default 25 | // constructor, copy constructor and operator= functions. 26 | // 27 | // This should be used in the declarations for a class that wants to prevent 28 | // anyone from instantiating it. This is especially useful for classes 29 | // containing only static methods. 30 | #define RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ 31 | TypeName() = delete; \ 32 | RTC_DISALLOW_COPY_AND_ASSIGN(TypeName) 33 | 34 | #endif // RTC_BASE_CONSTRUCTORMAGIC_H_ 35 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/gtest_prod_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef RTC_BASE_GTEST_PROD_UTIL_H_ 12 | #define RTC_BASE_GTEST_PROD_UTIL_H_ 13 | 14 | // Define our own version of FRIEND_TEST here rather than including 15 | // gtest_prod.h to avoid depending on any part of GTest in production code. 16 | #define FRIEND_TEST_WEBRTC(test_case_name, test_name) \ 17 | friend class test_case_name##_##test_name##_Test 18 | 19 | // This file is a plain copy of Chromium's base/gtest_prod_util.h. 20 | // 21 | // This is a wrapper for gtest's FRIEND_TEST macro that friends 22 | // test with all possible prefixes. This is very helpful when changing the test 23 | // prefix, because the friend declarations don't need to be updated. 24 | // 25 | // Example usage: 26 | // 27 | // class MyClass { 28 | // private: 29 | // void MyMethod(); 30 | // FRIEND_TEST_ALL_PREFIXES(MyClassTest, MyMethod); 31 | // }; 32 | #define FRIEND_TEST_ALL_PREFIXES(test_case_name, test_name) \ 33 | FRIEND_TEST_WEBRTC(test_case_name, test_name); \ 34 | FRIEND_TEST_WEBRTC(test_case_name, DISABLED_##test_name); \ 35 | FRIEND_TEST_WEBRTC(test_case_name, FLAKY_##test_name); \ 36 | FRIEND_TEST_WEBRTC(test_case_name, FAILS_##test_name) 37 | 38 | #endif // RTC_BASE_GTEST_PROD_UTIL_H_ 39 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/ignore_wundef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef RTC_BASE_IGNORE_WUNDEF_H_ 12 | #define RTC_BASE_IGNORE_WUNDEF_H_ 13 | 14 | // If a header file uses #if on possibly undefined macros (and it's for some 15 | // reason not possible to just fix the header file), include it like this: 16 | // 17 | // RTC_PUSH_IGNORING_WUNDEF() 18 | // #include "misbehaving_header.h" 19 | // RTC_POP_IGNORING_WUNDEF() 20 | // 21 | // This will cause the compiler to not emit -Wundef warnings for that file. 22 | 23 | #ifdef __clang__ 24 | #define RTC_PUSH_IGNORING_WUNDEF() \ 25 | _Pragma("clang diagnostic push") \ 26 | _Pragma("clang diagnostic ignored \"-Wundef\"") 27 | #define RTC_POP_IGNORING_WUNDEF() _Pragma("clang diagnostic pop") 28 | #else 29 | #define RTC_PUSH_IGNORING_WUNDEF() 30 | #define RTC_POP_IGNORING_WUNDEF() 31 | #endif // __clang__ 32 | 33 | #endif // RTC_BASE_IGNORE_WUNDEF_H_ 34 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/logging_mac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The WebRTC Project Authors. All rights reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | #ifndef RTC_BASE_LOGGING_MAC_H_ 11 | #define RTC_BASE_LOGGING_MAC_H_ 12 | 13 | #if !defined(WEBRTC_MAC) || defined(WEBRTC_IOS) 14 | #error "Only include this header in macOS builds" 15 | #endif 16 | 17 | #include 18 | 19 | #include 20 | 21 | namespace rtc { 22 | 23 | // Returns a UTF8 description from an OS X Status error. 24 | std::string DescriptionFromOSStatus(OSStatus err); 25 | 26 | } // namespace rtc 27 | 28 | #endif // RTC_BASE_LOGGING_MAC_H_ 29 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/logging_mac.mm: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The WebRTC Project Authors. All rights reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include "rtc_base/logging_mac.h" 12 | 13 | #import 14 | 15 | namespace rtc { 16 | std::string DescriptionFromOSStatus(OSStatus err) { 17 | NSError* error = 18 | [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil]; 19 | return error.description.UTF8String; 20 | } 21 | 22 | } // namespace rtc 23 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/protobuf_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #include 12 | 13 | #ifndef RTC_BASE_PROTOBUF_UTILS_H_ 14 | #define RTC_BASE_PROTOBUF_UTILS_H_ 15 | 16 | namespace webrtc { 17 | 18 | using ProtoString = std::string; 19 | 20 | } // namespace webrtc 21 | 22 | #if WEBRTC_ENABLE_PROTOBUF 23 | 24 | #include "third_party/protobuf/src/google/protobuf/message_lite.h" 25 | #include "third_party/protobuf/src/google/protobuf/repeated_field.h" 26 | 27 | namespace webrtc { 28 | 29 | using google::protobuf::MessageLite; 30 | using google::protobuf::RepeatedPtrField; 31 | 32 | } // namespace webrtc 33 | 34 | #endif // WEBRTC_ENABLE_PROTOBUF 35 | 36 | #endif // RTC_BASE_PROTOBUF_UTILS_H_ 37 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/system/ignore_warnings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef RTC_BASE_SYSTEM_IGNORE_WARNINGS_H_ 12 | #define RTC_BASE_SYSTEM_IGNORE_WARNINGS_H_ 13 | 14 | #ifdef __clang__ 15 | #define RTC_PUSH_IGNORING_WFRAME_LARGER_THAN() \ 16 | _Pragma("clang diagnostic push") \ 17 | _Pragma("clang diagnostic ignored \"-Wframe-larger-than=\"") 18 | #define RTC_POP_IGNORING_WFRAME_LARGER_THAN() _Pragma("clang diagnostic pop") 19 | #elif __GNUC__ 20 | #define RTC_PUSH_IGNORING_WFRAME_LARGER_THAN() \ 21 | _Pragma("GCC diagnostic push") \ 22 | _Pragma("GCC diagnostic ignored \"-Wframe-larger-than=\"") 23 | #define RTC_POP_IGNORING_WFRAME_LARGER_THAN() _Pragma("GCC diagnostic pop") 24 | #else 25 | #define RTC_PUSH_IGNORING_WFRAME_LARGER_THAN() 26 | #define RTC_POP_IGNORING_WFRAME_LARGER_THAN() 27 | #endif 28 | 29 | #endif // RTC_BASE_SYSTEM_IGNORE_WARNINGS_H_ 30 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/system/inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef RTC_BASE_SYSTEM_INLINE_H_ 12 | #define RTC_BASE_SYSTEM_INLINE_H_ 13 | 14 | #if defined(_MSC_VER) 15 | 16 | #define RTC_FORCE_INLINE __forceinline 17 | #define RTC_NO_INLINE __declspec(noinline) 18 | 19 | #elif defined(__GNUC__) 20 | 21 | #define RTC_FORCE_INLINE __attribute__((__always_inline__)) 22 | #define RTC_NO_INLINE __attribute__((__noinline__)) 23 | 24 | #else 25 | 26 | #define RTC_FORCE_INLINE 27 | #define RTC_NO_INLINE 28 | 29 | #endif 30 | 31 | #endif // RTC_BASE_SYSTEM_INLINE_H_ 32 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/system/rtc_export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef RTC_BASE_SYSTEM_RTC_EXPORT_H_ 12 | #define RTC_BASE_SYSTEM_RTC_EXPORT_H_ 13 | 14 | // RTC_EXPORT is used to mark symbols as exported or imported when WebRTC is 15 | // built or used as a shared library. 16 | // When WebRTC is built as a static library the RTC_EXPORT macro expands to 17 | // nothing. 18 | 19 | #ifdef WEBRTC_ENABLE_SYMBOL_EXPORT 20 | 21 | #ifdef WEBRTC_WIN 22 | 23 | #ifdef WEBRTC_LIBRARY_IMPL 24 | #define RTC_EXPORT __declspec(dllexport) 25 | #else 26 | #define RTC_EXPORT __declspec(dllimport) 27 | #endif 28 | 29 | #else // WEBRTC_WIN 30 | 31 | #if __has_attribute(visibility) && defined(WEBRTC_LIBRARY_IMPL) 32 | #define RTC_EXPORT __attribute__((visibility("default"))) 33 | #endif 34 | 35 | #endif // WEBRTC_WIN 36 | 37 | #endif // WEBRTC_ENABLE_SYMBOL_EXPORT 38 | 39 | #ifndef RTC_EXPORT 40 | #define RTC_EXPORT 41 | #endif 42 | 43 | #endif // RTC_BASE_SYSTEM_RTC_EXPORT_H_ 44 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/system/unused.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef RTC_BASE_SYSTEM_UNUSED_H_ 12 | #define RTC_BASE_SYSTEM_UNUSED_H_ 13 | 14 | // Annotate a function indicating the caller must examine the return value. 15 | // Use like: 16 | // int foo() RTC_WARN_UNUSED_RESULT; 17 | // To explicitly ignore a result, cast to void. 18 | // TODO(kwiberg): Remove when we can use [[nodiscard]] from C++17. 19 | #if defined(__clang__) 20 | #define RTC_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) 21 | #elif defined(__GNUC__) 22 | // gcc has a __warn_unused_result__ attribute, but you can't quiet it by 23 | // casting to void, so we don't use it. 24 | #define RTC_WARN_UNUSED_RESULT 25 | #else 26 | #define RTC_WARN_UNUSED_RESULT 27 | #endif 28 | 29 | // Prevent the compiler from warning about an unused variable. For example: 30 | // int result = DoSomething(); 31 | // assert(result == 17); 32 | // RTC_UNUSED(result); 33 | // Note: In most cases it is better to remove the unused variable rather than 34 | // suppressing the compiler warning. 35 | #ifndef RTC_UNUSED 36 | #define RTC_UNUSED(x) static_cast(x) 37 | #endif // RTC_UNUSED 38 | 39 | #endif // RTC_BASE_SYSTEM_UNUSED_H_ 40 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/thread_checker_impl.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | // Borrowed from Chromium's src/base/threading/thread_checker_impl.cc. 12 | 13 | #include "rtc_base/thread_checker_impl.h" 14 | 15 | namespace rtc { 16 | 17 | ThreadCheckerImpl::ThreadCheckerImpl() : valid_thread_(CurrentThreadRef()) {} 18 | 19 | ThreadCheckerImpl::~ThreadCheckerImpl() {} 20 | 21 | bool ThreadCheckerImpl::CalledOnValidThread() const { 22 | const PlatformThreadRef current_thread = CurrentThreadRef(); 23 | CritScope scoped_lock(&lock_); 24 | if (!valid_thread_) // Set if previously detached. 25 | valid_thread_ = current_thread; 26 | return IsThreadRefEqual(valid_thread_, current_thread); 27 | } 28 | 29 | void ThreadCheckerImpl::DetachFromThread() { 30 | CritScope scoped_lock(&lock_); 31 | valid_thread_ = 0; 32 | } 33 | 34 | } // namespace rtc 35 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/rtc_base/thread_checker_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | // Borrowed from Chromium's src/base/threading/thread_checker_impl.h. 12 | 13 | #ifndef RTC_BASE_THREAD_CHECKER_IMPL_H_ 14 | #define RTC_BASE_THREAD_CHECKER_IMPL_H_ 15 | 16 | #include "rtc_base/criticalsection.h" 17 | #include "rtc_base/platform_thread_types.h" 18 | 19 | namespace rtc { 20 | 21 | // Real implementation of ThreadChecker, for use in debug mode, or 22 | // for temporary use in release mode (e.g. to RTC_CHECK on a threading issue 23 | // seen only in the wild). 24 | // 25 | // Note: You should almost always use the ThreadChecker class to get the 26 | // right version for your build configuration. 27 | class ThreadCheckerImpl { 28 | public: 29 | ThreadCheckerImpl(); 30 | ~ThreadCheckerImpl(); 31 | 32 | bool CalledOnValidThread() const; 33 | 34 | // Changes the thread that is checked for in CalledOnValidThread. This may 35 | // be useful when an object may be created on one thread and then used 36 | // exclusively on another thread. 37 | void DetachFromThread(); 38 | 39 | private: 40 | CriticalSection lock_; 41 | // This is mutable so that CalledOnValidThread can set it. 42 | // It's guarded by |lock_|. 43 | mutable PlatformThreadRef valid_thread_; 44 | }; 45 | 46 | } // namespace rtc 47 | 48 | #endif // RTC_BASE_THREAD_CHECKER_IMPL_H_ 49 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/system_wrappers/include/compile_assert_c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_COMPILE_ASSERT_H_ 12 | #define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_COMPILE_ASSERT_H_ 13 | 14 | // Use this macro to verify at compile time that certain restrictions are met. 15 | // The argument is the boolean expression to evaluate. 16 | // Example: 17 | // COMPILE_ASSERT(sizeof(foo) < 128); 18 | // Note: In C++, use static_assert instead! 19 | #define COMPILE_ASSERT(expression) switch (0) {case 0: case expression:;} 20 | 21 | #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_COMPILE_ASSERT_H_ 22 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/system_wrappers/include/cpu_features_wrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 | * 4 | * Use of this source code is governed by a BSD-style license 5 | * that can be found in the LICENSE file in the root of the source 6 | * tree. An additional intellectual property rights grant can be found 7 | * in the file PATENTS. All contributing project authors may 8 | * be found in the AUTHORS file in the root of the source tree. 9 | */ 10 | 11 | #ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_ 12 | #define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_ 13 | 14 | #if defined(__cplusplus) || defined(c_plusplus) 15 | extern "C" { 16 | #endif 17 | 18 | #include "typedefs.h" 19 | 20 | // List of features in x86. 21 | typedef enum { 22 | kSSE2, 23 | kSSE3 24 | } CPUFeature; 25 | 26 | // List of features in ARM. 27 | enum { 28 | kCPUFeatureARMv7 = (1 << 0), 29 | kCPUFeatureVFPv3 = (1 << 1), 30 | kCPUFeatureNEON = (1 << 2), 31 | kCPUFeatureLDREXSTREX = (1 << 3) 32 | }; 33 | 34 | typedef int (*WebRtc_CPUInfo)(CPUFeature feature); 35 | 36 | // Returns true if the CPU supports the feature. 37 | extern WebRtc_CPUInfo WebRtc_GetCPUInfo; 38 | 39 | // No CPU feature is available => straight C path. 40 | extern WebRtc_CPUInfo WebRtc_GetCPUInfoNoASM; 41 | 42 | // Return the features in an ARM device. 43 | // It detects the features in the hardware platform, and returns supported 44 | // values in the above enum definition as a bitmask. 45 | extern uint64_t WebRtc_GetCPUFeaturesARM(void); 46 | 47 | #if defined(__cplusplus) || defined(c_plusplus) 48 | } // extern "C" 49 | #endif 50 | 51 | #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_ 52 | -------------------------------------------------------------------------------- /libtgvoip/webrtc_dsp/third_party/rnnoise/src/rnn_vad_weights.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_RNNOISE_SRC_RNN_VAD_WEIGHTS_H_ 2 | #define THIRD_PARTY_RNNOISE_SRC_RNN_VAD_WEIGHTS_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace rnnoise { 8 | 9 | // Weights scaling factor. 10 | const float kWeightsScale = 1.f / 256.f; 11 | 12 | // Input layer (dense). 13 | const size_t kInputLayerInputSize = 42; 14 | const size_t kInputLayerOutputSize = 24; 15 | const size_t kInputLayerWeights = kInputLayerInputSize * kInputLayerOutputSize; 16 | extern const int8_t kInputDenseWeights[kInputLayerWeights]; 17 | extern const int8_t kInputDenseBias[kInputLayerOutputSize]; 18 | 19 | // Hidden layer (GRU). 20 | const size_t kHiddenLayerOutputSize = 24; 21 | const size_t kHiddenLayerWeights = 22 | 3 * kInputLayerOutputSize * kHiddenLayerOutputSize; 23 | const size_t kHiddenLayerBiases = 3 * kHiddenLayerOutputSize; 24 | extern const int8_t kHiddenGruWeights[kHiddenLayerWeights]; 25 | extern const int8_t kHiddenGruRecurrentWeights[kHiddenLayerWeights]; 26 | extern const int8_t kHiddenGruBias[kHiddenLayerBiases]; 27 | 28 | // Output layer (dense). 29 | const size_t kOutputLayerOutputSize = 1; 30 | const size_t kOutputLayerWeights = 31 | kHiddenLayerOutputSize * kOutputLayerOutputSize; 32 | extern const int8_t kOutputDenseWeights[kOutputLayerWeights]; 33 | extern const int8_t kOutputDenseBias[kOutputLayerOutputSize]; 34 | 35 | } // namespace rnnoise 36 | 37 | #endif // THIRD_PARTY_RNNOISE_SRC_RNN_VAD_WEIGHTS_H_ 38 | -------------------------------------------------------------------------------- /tg2sip/logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017-2018 infactum (infactum@gmail.com) 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; If not, see . 16 | */ 17 | 18 | #ifndef TG2SIP_LOGGING_H 19 | #define TG2SIP_LOGGING_H 20 | 21 | #include 22 | #include 23 | #include "settings.h" 24 | 25 | #ifndef DISABLE_DEBUG_ 26 | #define STRINGIZE_(x) #x 27 | #define STRINGIZE(x) STRINGIZE_(x) 28 | #define TRACE(logger, ...) logger->trace("" __FILE__ ":" STRINGIZE(__LINE__)" " __VA_ARGS__) 29 | #define DEBUG(logger, ...) logger->debug(__VA_ARGS__) 30 | #else 31 | #define TRACE(logger, ...) (void)0 32 | #define DEBUG(logger, ...) (void)0 33 | #endif 34 | 35 | void init_logging(Settings &settings); 36 | 37 | #endif //TG2SIP_LOGGING_H 38 | -------------------------------------------------------------------------------- /tg2sip/utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017-2018 infactum (infactum@gmail.com) 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; If not, see . 16 | */ 17 | 18 | #include 19 | #include "utils.h" 20 | 21 | bool is_digits(const std::string &str) { return std::all_of(str.begin(), str.end(), ::isdigit); }; -------------------------------------------------------------------------------- /tg2sip/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017-2018 infactum (infactum@gmail.com) 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; If not, see . 16 | */ 17 | 18 | #ifndef TG2SIP_UTILS_H 19 | #define TG2SIP_UTILS_H 20 | 21 | #include 22 | 23 | bool is_digits(const std::string &str); 24 | 25 | template 26 | std::unique_ptr move_unique_ptr_as(std::unique_ptr &from) { 27 | return std::unique_ptr(static_cast(from.release())); 28 | } 29 | 30 | #endif //TG2SIP_UTILS_H 31 | --------------------------------------------------------------------------------