utilities.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * CallingAPI.cpp
  3. *
  4. * Created on: 2021年12月10日
  5. * Author: Admin
  6. */
  7. #include "utilities.h"
  8. #include "utils/Log.h"
  9. #include "string.h"
  10. #include "sip_config.h"
  11. #include "storage/StoragePreferences.h"
  12. #include "sip_config.h"
  13. #include <entry/EasyUIContext.h>
  14. #include <mutex>
  15. #include "base/strings.hpp"
  16. #include "base/base.hpp"
  17. #include "utilities.h"
  18. #include "base/time.hpp"
  19. #include "base/strings.hpp"
  20. #include "base/prefs.hpp"
  21. #include "base/json_object.h"
  22. #include "edge/ip_table.h"
  23. #include "core/jhws.h"
  24. #include "security/SecurityManager.h"
  25. #include "zkaudio.h"
  26. /**
  27. * 仅用于测试,默认不发送视频
  28. */
  29. void TelephoneAutoTransmitVideo(bool transmit);
  30. std::string GetDeviceUid();
  31. static std::mutex telephone_mutex;
  32. static voip::Telephone* telephone = NULL;
  33. voip::Telephone* GetTelephone() {
  34. std::lock_guard<std::mutex> lock(telephone_mutex);
  35. if (telephone != NULL) {
  36. return telephone;
  37. }
  38. voip::Configuration conf;
  39. #if 0
  40. std::string password = StoragePreferences::getString(SIP_REG_PASSWORD,
  41. SIP_REG_PASSWORD_DEFAULT);
  42. conf.id_uri = "sip:RM-1-1-1-1-1-1@jhws.top;transport=tcp";
  43. // conf.id_uri = "sip:RM-414-1-1-1-1-7@test.jhws.top";
  44. conf.server_uri = "sip:test.jhws.top";
  45. // conf.door_uri = "sip:OD-414-1-1-1-0-2@jhws.top";
  46. conf.user_name = "RM-1-1-1-1-1-1";
  47. conf.password = password;
  48. conf.port = 58583;
  49. #else
  50. std::string domain = StoragePreferences::getString(SIP_REG_DOMAIN,
  51. SIP_REG_DOMAIN_DEFAULT);
  52. std::string number = StoragePreferences::getString(SIP_REG_ACCOUNT,
  53. SIP_REG_ACCOUNT_DEFAULT);
  54. std::string password = StoragePreferences::getString(SIP_REG_PASSWORD,
  55. SIP_REG_PASSWORD_DEFAULT);
  56. int port = StoragePreferences::getInt(SIP_REG_PORT, SIP_REG_PORT_DEFAULT);
  57. // conf.id_uri = URI(number);
  58. conf.id_uri = URI(number, domain);
  59. conf.server_uri = base::format("sip:%s:%d", domain.c_str(), port);
  60. // conf.server_uri = "sip:new-sip.jhws.top:58583";
  61. conf.user_name = number;
  62. conf.password = password;
  63. conf.enable_ice = StoragePreferences::getBool(SIP_ENABLE_ICE, false);
  64. std::string stun_server =
  65. base::trim(StoragePreferences::getString(SIP_STUN_TURN_SERVER, ""));
  66. conf.stun_server = stun_server;
  67. conf.turn_server = stun_server;
  68. // conf.user_agent = "JHCloud-linux-i1.1.0";
  69. // conf.headers["SID"] = GetDeviceUid();
  70. // conf.headers["CID"] = "jhylf14988-com.jhws";
  71. // conf.headers["JWT"] = StoragePreferences::getString(SIP_JHWS_TOKEN, "");
  72. // LOGD("deviceuid: %s", GetDeviceUid().c_str());
  73. LOGD("id_url: %s", conf.id_uri.c_str());
  74. LOGD("server_url: %s", conf.server_uri.c_str());
  75. LOGD("user_name: %s", conf.user_name.c_str());
  76. LOGD("password: %s", conf.password.c_str());
  77. LOGD("user_agent: %s", conf.user_agent.c_str());
  78. #endif
  79. bool enable_video = StoragePreferences::getBool(SIP_ENABLE_VIDEO, true);
  80. conf.auto_transmit_video_to_remote = enable_video;
  81. telephone = new voip::Telephone(conf);
  82. //设置消回音、增益等参数
  83. base::AcousticEchoCancellater::Configuration aec_conf;
  84. aec_conf.sample_rate = 8000; //固定8K
  85. aec_conf.nearend_channel = 1;
  86. aec_conf.farend_channel = 1;
  87. aec_conf.comfort_noise_enable = 0;
  88. base::AudioProcessChain::Configuration apc_conf;
  89. apc_conf.number_of_channels = 1;
  90. apc_conf.sample_rate = 8000; //固定8K
  91. apc_conf.anr.enable = 1; //降低噪音
  92. // apc_conf.eq.enable = 1;
  93. apc_conf.agc.enable = 1;
  94. for (int i = 0; i < array_length(apc_conf.eq.gain_db); ++i) {
  95. //调节EQ,使发送给对方的声音音量更大
  96. // apc_conf.eq.gain_db[i] = 10;
  97. }
  98. zk_audio_input_set_volume_native(0, 0);
  99. zk_audio_input_set_volume_native(1, 12);
  100. zk_audio_output_set_volume_native(15);
  101. // telephone->SetInputAecApcConfig(aec_conf, apc_conf);
  102. return telephone;
  103. }
  104. void ReleaseTelephone() {
  105. std::lock_guard<std::mutex> lock(telephone_mutex);
  106. if (telephone != NULL) {
  107. deleteptr(&telephone);
  108. }
  109. }
  110. std::string GetVersion(){
  111. return "1.0.0";
  112. }
  113. int GetVersionNo() {
  114. return 3;
  115. }
  116. std::string GetDeviceUid() {
  117. unsigned char devID[16];
  118. int ret = SECURITYMANAGER->getDevID(devID);
  119. if (ret <= 0) {
  120. return "";
  121. }
  122. std::string str;
  123. for (int i = 0; i < ret; ++i) {
  124. str += base::format("%02X", devID[i]);
  125. }
  126. return str;
  127. }