/* * CallingAPI.cpp * * Created on: 2021年12月10日 * Author: Admin */ #include "utilities.h" #include "utils/Log.h" #include "string.h" #include "sip_config.h" #include "storage/StoragePreferences.h" #include "sip_config.h" #include #include #include "base/strings.hpp" #include "base/base.hpp" #include "utilities.h" #include "base/time.hpp" #include "base/strings.hpp" #include "base/prefs.hpp" #include "base/json_object.h" #include "manager/ConfigManager.h" #include "security/SecurityManager.h" #include "zkaudio.h" #include "voip/telephone_audio_initializer.h" /** * 仅用于测试,默认不发送视频 */ void TelephoneAutoTransmitVideo(bool transmit); std::string GetDeviceUid(); static std::mutex telephone_mutex; static voip::Telephone* telephone = NULL; voip::Telephone* GetTelephone() { std::lock_guard lock(telephone_mutex); if (telephone != NULL) { return telephone; } voip::Configuration conf; #if 0 std::string password = StoragePreferences::getString(SIP_REG_PASSWORD, SIP_REG_PASSWORD_DEFAULT); conf.id_uri = "sip:RM-1-1-1-1-1-1@jhws.top;transport=tcp"; // conf.id_uri = "sip:RM-414-1-1-1-1-7@test.jhws.top"; conf.server_uri = "sip:test.jhws.top"; // conf.door_uri = "sip:OD-414-1-1-1-0-2@jhws.top"; conf.user_name = "RM-1-1-1-1-1-1"; conf.password = password; conf.port = 58583; #else std::string domain = StoragePreferences::getString(SIP_REG_DOMAIN, SIP_REG_DOMAIN_DEFAULT); std::string number = StoragePreferences::getString(SIP_REG_ACCOUNT, SIP_REG_ACCOUNT_DEFAULT); std::string password = StoragePreferences::getString(SIP_REG_PASSWORD, SIP_REG_PASSWORD_DEFAULT); int port = StoragePreferences::getInt(SIP_REG_PORT, SIP_REG_PORT_DEFAULT); // conf.id_uri = URI(number); conf.id_uri = URI(number, domain); conf.server_uri = base::format("sip:%s:%d", domain.c_str(), port); // conf.server_uri = "sip:new-sip.jhws.top:58583"; conf.user_name = number; conf.password = password; conf.enable_ice = StoragePreferences::getBool(SIP_ENABLE_ICE, false); std::string stun_server = base::trim(StoragePreferences::getString(SIP_STUN_TURN_SERVER, "")); conf.stun_server = stun_server; conf.turn_server = stun_server; // conf.user_agent = "JHCloud-linux-i1.1.0"; // conf.headers["SID"] = GetDeviceUid(); // conf.headers["CID"] = "jhylf14988-com.jhws"; // conf.headers["JWT"] = StoragePreferences::getString(SIP_JHWS_TOKEN, ""); // LOGD("deviceuid: %s", GetDeviceUid().c_str()); // LOGD("id_url: %s", conf.id_uri.c_str()); // LOGD("server_url: %s", conf.server_uri.c_str()); // LOGD("user_name: %s", conf.user_name.c_str()); // LOGD("password: %s", conf.password.c_str()); // LOGD("user_agent: %s", conf.user_agent.c_str()); #endif bool enable_video = StoragePreferences::getBool(SIP_ENABLE_VIDEO, false); conf.auto_transmit_video_to_remote = enable_video; //单实例 telephone = new voip::Telephone(conf); #if 0 //设置消回音、增益等参数 base::AcousticEchoCancellater::Configuration aec_conf; aec_conf.sample_rate = 8000; //固定8K aec_conf.nearend_channel = 1; aec_conf.farend_channel = 1; aec_conf.comfort_noise_enable = 0; base::AudioProcessChain::Configuration apc_conf; apc_conf.number_of_channels = 1; apc_conf.sample_rate = 8000; //固定8K apc_conf.anr.enable = 1; //降低噪音 // apc_conf.eq.enable = 1; apc_conf.agc.enable = 1; for (int i = 0; i < array_length(apc_conf.eq.gain_db); ++i) { //调节EQ,使发送给对方的声音音量更大 // apc_conf.eq.gain_db[i] = 10; } zk_audio_input_set_volume_native(0, 0); zk_audio_input_set_volume_native(1, 12); zk_audio_output_set_volume_native(15); // telephone->SetInputAecApcConfig(aec_conf, apc_conf); #endif #if 1 const int kSampleRate = 8000;//固定8K //设置消回音等参数 base::AcousticEchoCancellater::Configuration aec_conf; aec_conf.sample_rate = kSampleRate; //固定8K aec_conf.nearend_channel = 1; aec_conf.farend_channel = 1; { aec_conf.comfort_noise_enable = 0; unsigned int suppression_mode_intensity[7] = { 5, 5, 5, 5, 4, 4, 4 }; memcpy((void*)aec_conf.suppression_mode_intensity, (void*)suppression_mode_intensity, (int) sizeof(suppression_mode_intensity)); } //进一步处理录音数据 base::AudioProcessChain::Configuration apc_conf; apc_conf.number_of_channels = 1; apc_conf.sample_rate = kSampleRate; { apc_conf.anr.enable = 1; //降低噪音 for (int i = 0; i < array_length(apc_conf.anr.intensity); ++i) { apc_conf.anr.intensity[i] = 5; } } { apc_conf.eq.enable = 0;//增大音量 for(int i = 0; i < array_length(apc_conf.eq.gain_db); ++i) { apc_conf.eq.gain_db[i] = 8; } } { apc_conf.agc.enable = 0; short def_compression_ratio_input[7] = { -65, -55, -48, -25, -18, -12, 0 }; short def_compression_ratio_output[7] = { -65, -50, -30, -15, -8, -2, 0 }; memcpy(apc_conf.agc.compression_ratio_input, def_compression_ratio_input, (int) sizeof(def_compression_ratio_input)); memcpy(apc_conf.agc.compression_ratio_output, def_compression_ratio_output, (int) sizeof(def_compression_ratio_output)); } zk_audio_input_set_volume_native(0, 0); zk_audio_input_set_volume_native(1, 6); telephone->SetInputPcmGainSize(10.0); telephone->SetInputAecApcConfig(aec_conf, apc_conf); #else //也可以从配置文件中设置 Aec、 Apc、 输入输出音量 const std::string filename = CONFIGMANAGER->getResFilePath("telephone_audio_config.json"); TelephoneAudioInitializer::Setup(telephone, filename); #endif return telephone; } void ReleaseTelephone() { std::lock_guard lock(telephone_mutex); if (telephone != NULL) { deleteptr(&telephone); } } std::string GetDeviceUid() { unsigned char devID[16]; int ret = SECURITYMANAGER->getDevID(devID); if (ret <= 0) { return ""; } std::string str; for (int i = 0; i < ret; ++i) { str += base::format("%02X", devID[i]); } return str; }