From 98b368cfbddd20b196d40a1e7182520abee07c0f Mon Sep 17 00:00:00 2001 From: Ali <> Date: Tue, 24 Dec 2019 22:40:50 +0400 Subject: [PATCH] Apply patch --- VoIPController.cpp | 22 +++++++++++++++++++++- VoIPController.h | 5 ++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/VoIPController.cpp b/VoIPController.cpp index d9297ce..3412e40 100755 --- a/VoIPController.cpp +++ b/VoIPController.cpp @@ -29,6 +29,11 @@ #include #include #include +#ifdef HAVE_CONFIG_H +#include +#else +#include "opus.h" +#endif inline int pad4(int x){ @@ -294,6 +299,12 @@ VoIPController::~VoIPController(){ tgvoipLogFile=NULL; fclose(log); } +#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO) + if (preprocDecoder) { + opus_decoder_destroy(preprocDecoder); + preprocDecoder=nullptr; + } +#endif } void VoIPController::Stop(){ @@ -841,9 +852,11 @@ void VoIPController::SetEchoCancellationStrength(int strength){ } #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO) -void VoIPController::SetAudioDataCallbacks(std::function input, std::function output){ +void VoIPController::SetAudioDataCallbacks(std::function input, std::function output, std::function preproc=nullptr){ audioInputDataCallback=input; audioOutputDataCallback=output; + audioPreprocDataCallback=preproc; + preprocDecoder=preprocDecoder ? preprocDecoder : opus_decoder_create(48000, 1, NULL); } #endif @@ -1153,6 +1166,13 @@ void VoIPController::HandleAudioInput(unsigned char *data, size_t len, unsigned } audioTimestampOut+=outgoingStreams[0]->frameDuration; + +#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO) + if (audioPreprocDataCallback && preprocDecoder) { + int size=opus_decode(preprocDecoder, data, len, preprocBuffer, 4096, 0); + audioPreprocDataCallback(preprocBuffer, size); + } +#endif } void VoIPController::InitializeAudio(){ diff --git a/VoIPController.h b/VoIPController.h index bb3c30d..9611ca6 100755 --- a/VoIPController.h +++ b/VoIPController.h @@ -402,7 +402,7 @@ namespace tgvoip{ void SetPersistentState(std::vector state); #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO) - void SetAudioDataCallbacks(std::function input, std::function output); + void SetAudioDataCallbacks(std::function input, std::function output, std::function preprocessed); #endif void SetVideoCodecSpecificData(const std::vector& data); @@ -749,6 +749,9 @@ namespace tgvoip{ #if defined(TGVOIP_USE_CALLBACK_AUDIO_IO) std::function audioInputDataCallback; std::function audioOutputDataCallback; + std::function audioPreprocDataCallback; + ::OpusDecoder* preprocDecoder=nullptr; + int16_t preprocBuffer[4096]; #endif #if defined(__APPLE__) && defined(TARGET_OS_OSX) bool macAudioDuckingEnabled=true;