Skip to content

Commit

Permalink
Improved CXWrapper adding various methods
Browse files Browse the repository at this point in the history
  • Loading branch information
FrayxRulez committed Mar 12, 2019
1 parent 07df8c9 commit e5900e6
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 28 deletions.
24 changes: 18 additions & 6 deletions os/windows/AudioInputWASAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,27 @@ void AudioInputWASAPI::ActuallySetCurrentDevice(std::string deviceID){
res=device->Activate(__uuidof(IAudioClient), CLSCTX_INPROC_SERVER, NULL, (void**)&audioClient);
CHECK_RES(res, "device->Activate");
#else
Platform::String^ defaultDevID=Windows::Media::Devices::MediaDevice::GetDefaultAudioCaptureId(Windows::Media::Devices::AudioDeviceRole::Communications);
if(defaultDevID == nullptr){
LOGE("Didn't find capture device; failing");
failed=true;
return;
std::wstring devID;

if (deviceID=="default"){
Platform::String^ defaultDevID=Windows::Media::Devices::MediaDevice::GetDefaultAudioCaptureId(Windows::Media::Devices::AudioDeviceRole::Communications);
if(defaultDevID==nullptr){
LOGE("Didn't find capture device; failing");
failed=true;
return;
}else{
isDefaultDevice=true;
devID=defaultDevID->Data();
}
}else{
int wchars_num=MultiByteToWideChar(CP_UTF8, 0, deviceID.c_str(), -1, NULL, 0);
wchar_t* wstr=new wchar_t[wchars_num];
MultiByteToWideChar(CP_UTF8, 0, deviceID.c_str(), -1, wstr, wchars_num);
devID=wstr;
}

HRESULT res1, res2;
IAudioClient2* audioClient2=WindowsSandboxUtils::ActivateAudioDevice(defaultDevID->Data(), &res1, &res2);
IAudioClient2* audioClient2=WindowsSandboxUtils::ActivateAudioDevice(devID.c_str(), &res1, &res2);
CHECK_RES(res1, "activate1");
CHECK_RES(res2, "activate2");

Expand Down
24 changes: 18 additions & 6 deletions os/windows/AudioOutputWASAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,27 @@ void AudioOutputWASAPI::ActuallySetCurrentDevice(std::string deviceID){
res=device->Activate(__uuidof(IAudioClient), CLSCTX_INPROC_SERVER, NULL, (void**)&audioClient);
CHECK_RES(res, "device->Activate");
#else
Platform::String^ defaultDevID=Windows::Media::Devices::MediaDevice::GetDefaultAudioRenderId(Windows::Media::Devices::AudioDeviceRole::Communications);
if(defaultDevID==nullptr){
LOGE("Didn't find playback device; failing");
failed=true;
return;
std::wstring devID;

if (deviceID=="default"){
Platform::String^ defaultDevID=Windows::Media::Devices::MediaDevice::GetDefaultAudioRenderId(Windows::Media::Devices::AudioDeviceRole::Communications);
if(defaultDevID==nullptr){
LOGE("Didn't find playback device; failing");
failed=true;
return;
}else{
isDefaultDevice=true;
devID=defaultDevID->Data();
}
}else{
int wchars_num=MultiByteToWideChar(CP_UTF8, 0, deviceID.c_str(), -1, NULL, 0);
wchar_t* wstr=new wchar_t[wchars_num];
MultiByteToWideChar(CP_UTF8, 0, deviceID.c_str(), -1, wstr, wchars_num);
devID=wstr;
}

HRESULT res1, res2;
IAudioClient2* audioClient2=WindowsSandboxUtils::ActivateAudioDevice(defaultDevID->Data(), &res1, &res2);
IAudioClient2* audioClient2=WindowsSandboxUtils::ActivateAudioDevice(devID.c_str(), &res1, &res2);
CHECK_RES(res1, "activate1");
CHECK_RES(res2, "activate2");

Expand Down
47 changes: 33 additions & 14 deletions os/windows/CXWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int64 VoIPControllerWrapper::GetPreferredRelayID(){
}

int32_t VoIPControllerWrapper::GetConnectionMaxLayer(){
return controller->GetConnectionMaxLayer();
return tgvoip::VoIPController::GetConnectionMaxLayer();
}

void VoIPControllerWrapper::SetEncryptionKey(const Platform::Array<uint8>^ key, bool isOutgoing){
Expand Down Expand Up @@ -174,22 +174,33 @@ void VoIPControllerWrapper::OnSignalBarsChangedInternal(int count){
SignalBarsChanged(this, count);
}

void VoIPControllerWrapper::SetConfig(double initTimeout, double recvTimeout, DataSavingMode dataSavingMode, bool enableAEC, bool enableNS, bool enableAGC, Platform::String^ logFilePath, Platform::String^ statsDumpFilePath){
void VoIPControllerWrapper::SetConfig(VoIPConfig^ wrapper){
VoIPController::Config config{0};
config.initTimeout=initTimeout;
config.recvTimeout=recvTimeout;
config.dataSaving=(int)dataSavingMode;
config.enableAEC=enableAEC;
config.enableAGC=enableAGC;
config.enableNS=enableNS;
if(logFilePath!=nullptr&&!logFilePath->IsEmpty()){
config.logFilePath = wstring(logFilePath->Data());
//WideCharToMultiByte(CP_UTF8, 0, logFilePath->Data(), -1, config.logFilePath, sizeof(config.logFilePath), NULL, NULL);
config.initTimeout=wrapper->initTimeout;
config.recvTimeout=wrapper->recvTimeout;
config.dataSaving=(int)wrapper->dataSaving;
config.logFilePath;
config.statsDumpFilePath;

config.enableAEC=wrapper->enableAEC;
config.enableNS=wrapper->enableNS;
config.enableAGC=wrapper->enableAGC;

config.enableCallUpgrade=wrapper->enableCallUpgrade;

config.logPacketStats=wrapper->logPacketStats;
config.enableVolumeControl=wrapper->enableVolumeControl;

config.enableVideoSend=wrapper->enableVideoSend;
config.enableVideoReceive=wrapper->enableVideoReceive;

if(wrapper->logFilePath!=nullptr&&!wrapper->logFilePath->IsEmpty()){
config.logFilePath = wstring(wrapper->logFilePath->Data());
}
if (statsDumpFilePath != nullptr&&!statsDumpFilePath->IsEmpty()){
config.statsDumpFilePath = wstring(statsDumpFilePath->Data());
//WideCharToMultiByte(CP_UTF8, 0, statsDumpFilePath->Data(), -1, config.statsDumpFilePath, sizeof(config.statsDumpFilePath), NULL, NULL);
if (wrapper->statsDumpFilePath != nullptr&&!wrapper->statsDumpFilePath->IsEmpty()){
config.statsDumpFilePath = wstring(wrapper->statsDumpFilePath->Data());
}

controller->SetConfig(config);
}

Expand All @@ -209,6 +220,14 @@ void VoIPControllerWrapper::SetAudioOutputGainControlEnabled(bool enabled){
controller->SetAudioOutputGainControlEnabled(enabled);
}

void VoIPControllerWrapper::SetInputVolume(float level){
controller->SetInputVolume(level);
}

void VoIPControllerWrapper::SetOutputVolume(float level){
controller->SetOutputVolume(level);
}

void VoIPControllerWrapper::UpdateServerConfig(Platform::String^ json){
std::string config=ToUtf8(json->Data(), json->Length());
ServerConfig::GetSharedInstance()->Update(config);
Expand Down
72 changes: 70 additions & 2 deletions os/windows/CXWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,23 @@
#include "../../VoIPController.h"
#include "../../VoIPServerConfig.h"

using namespace Platform;

#define STACK_ARRAY(TYPE, LEN) \
static_cast<TYPE*>(::alloca((LEN) * sizeof(TYPE)))

inline std::wstring ToUtf16(const char* utf8, size_t len) {
int len16 = ::MultiByteToWideChar(CP_UTF8, 0, utf8, static_cast<int>(len),
nullptr, 0);
wchar_t* ws = STACK_ARRAY(wchar_t, len16);
::MultiByteToWideChar(CP_UTF8, 0, utf8, static_cast<int>(len), ws, len16);
return std::wstring(ws, len16);
}

inline std::wstring ToUtf16(const std::string& str) {
return ToUtf16(str.data(), str.length());
}

inline std::string ToUtf8(const wchar_t* wide, size_t len) {
int len8 = ::WideCharToMultiByte(CP_UTF8, 0, wide, static_cast<int>(len),
nullptr, 0, nullptr, nullptr);
Expand Down Expand Up @@ -46,6 +60,34 @@ namespace libtgvoip{
property uint64_t bytesRecvdMobile;
};

public ref class VoIPConfig sealed{
public:
VoIPConfig(){
logPacketStats=false;
enableVolumeControl=false;
enableVideoSend=false;
enableVideoReceive=false;
}

property double initTimeout;
property double recvTimeout;
property DataSavingMode dataSaving;
property String^ logFilePath;
property String^ statsDumpFilePath;

property bool enableAEC;
property bool enableNS;
property bool enableAGC;

property bool enableCallUpgrade;

property bool logPacketStats;
property bool enableVolumeControl;

property bool enableVideoSend;
property bool enableVideoReceive;
};

public enum class CallState : int{
WaitInit=1,
WaitInitAck,
Expand Down Expand Up @@ -102,19 +144,45 @@ namespace libtgvoip{
void SetNetworkType(NetworkType type);
void SetMicMute(bool mute);
void SetEncryptionKey(const Platform::Array<uint8>^ key, bool isOutgoing);
void SetConfig(double initTimeout, double recvTimeout, DataSavingMode dataSavingMode, bool enableAEC, bool enableNS, bool enableAGC, Platform::String^ logFilePath, Platform::String^ statsDumpFilePath);
void SetConfig(VoIPConfig^ config);
void SetProxy(ProxyProtocol protocol, Platform::String^ address, uint16_t port, Platform::String^ username, Platform::String^ password);
int GetSignalBarsCount();
CallState GetConnectionState();
TrafficStats^ GetStats();
int32_t GetConnectionMaxLayer();
Platform::String^ GetDebugString();
Platform::String^ GetDebugLog();
Error GetLastError();
static Platform::String^ GetVersion();
int64 GetPreferredRelayID();
void SetAudioOutputGainControlEnabled(bool enabled);

void SetInputVolume(float level);
void SetOutputVolume(float level);

property String^ CurrentAudioInput
{
String^ get()
{
return ref new String(ToUtf16(controller->GetCurrentAudioInputID()).data());
}
void set(String^ value)
{
controller->SetCurrentAudioInput(ToUtf8(value->Data()));
}
}

property String^ CurrentAudioOutput
{
String^ get()
{
return ref new String(ToUtf16(controller->GetCurrentAudioOutputID()).data());
}
void set(String^ value)
{
controller->SetCurrentAudioOutput(ToUtf8(value->Data()));
}
}

static int32_t GetConnectionMaxLayer();
static void UpdateServerConfig(Platform::String^ json);
static void SwitchSpeaker(bool external);
Expand Down

0 comments on commit e5900e6

Please sign in to comment.