Nagram/TMessagesProj/jni/voip/tgcalls/InstanceImpl.cpp

203 lines
5.3 KiB
C++
Raw Normal View History

2020-08-14 16:58:22 +00:00
#include "InstanceImpl.h"
#include "LogSinkImpl.h"
#include "Manager.h"
#include "MediaManager.h"
#include "VideoCaptureInterfaceImpl.h"
#include "VideoCapturerInterface.h"
namespace tgcalls {
2023-02-18 21:24:25 +00:00
2020-08-14 16:58:22 +00:00
namespace {
rtc::Thread *makeManagerThread() {
static std::unique_ptr<rtc::Thread> value = rtc::Thread::Create();
value->SetName("WebRTC-Manager", nullptr);
value->Start();
return value.get();
}
rtc::Thread *getManagerThread() {
static rtc::Thread *value = makeManagerThread();
return value;
}
} // namespace
InstanceImpl::InstanceImpl(Descriptor &&descriptor)
2020-12-23 07:48:30 +00:00
: _logSink(std::make_unique<LogSinkImpl>(descriptor.config.logPath)) {
2020-08-14 16:58:22 +00:00
rtc::LogMessage::LogToDebug(rtc::LS_INFO);
rtc::LogMessage::SetLogToStderr(false);
rtc::LogMessage::AddLogToStream(_logSink.get(), rtc::LS_INFO);
2020-12-23 07:48:30 +00:00
2020-08-15 21:06:36 +00:00
auto networkType = descriptor.initialNetworkType;
2020-08-14 16:58:22 +00:00
_manager.reset(new ThreadLocalObject<Manager>(getManagerThread(), [descriptor = std::move(descriptor)]() mutable {
return new Manager(getManagerThread(), std::move(descriptor));
}));
2023-02-18 21:24:25 +00:00
_manager->perform([](Manager *manager) {
2020-08-14 16:58:22 +00:00
manager->start();
});
2020-12-23 07:48:30 +00:00
2020-08-15 21:06:36 +00:00
setNetworkType(networkType);
2020-08-14 16:58:22 +00:00
}
InstanceImpl::~InstanceImpl() {
rtc::LogMessage::RemoveLogToStream(_logSink.get());
}
void InstanceImpl::receiveSignalingData(const std::vector<uint8_t> &data) {
2023-02-18 21:24:25 +00:00
_manager->perform([data](Manager *manager) {
2020-08-14 16:58:22 +00:00
manager->receiveSignalingData(data);
});
};
void InstanceImpl::setVideoCapture(std::shared_ptr<VideoCaptureInterface> videoCapture) {
2023-02-18 21:24:25 +00:00
_manager->perform([videoCapture](Manager *manager) {
2020-08-14 16:58:22 +00:00
manager->setVideoCapture(videoCapture);
});
}
2021-08-31 19:06:39 +00:00
void InstanceImpl::sendVideoDeviceUpdated() {
2023-02-18 21:24:25 +00:00
_manager->perform([](Manager *manager) {
2021-08-31 19:06:39 +00:00
manager->sendVideoDeviceUpdated();
});
}
2020-10-01 01:59:32 +00:00
void InstanceImpl::setRequestedVideoAspect(float aspect) {
2023-02-18 21:24:25 +00:00
_manager->perform([aspect](Manager *manager) {
2020-10-01 01:59:32 +00:00
manager->setRequestedVideoAspect(aspect);
});
}
2020-08-14 16:58:22 +00:00
void InstanceImpl::setNetworkType(NetworkType networkType) {
2020-08-15 21:06:36 +00:00
bool isLowCostNetwork = false;
switch (networkType) {
case NetworkType::WiFi:
case NetworkType::Ethernet:
isLowCostNetwork = true;
break;
default:
break;
}
2020-12-23 07:48:30 +00:00
2023-02-18 21:24:25 +00:00
_manager->perform([isLowCostNetwork](Manager *manager) {
2020-08-15 21:06:36 +00:00
manager->setIsLocalNetworkLowCost(isLowCostNetwork);
});
2020-08-14 16:58:22 +00:00
}
void InstanceImpl::setMuteMicrophone(bool muteMicrophone) {
2023-02-18 21:24:25 +00:00
_manager->perform([muteMicrophone](Manager *manager) {
2020-08-14 16:58:22 +00:00
manager->setMuteOutgoingAudio(muteMicrophone);
});
}
2023-10-28 20:52:06 +00:00
void InstanceImpl::setIncomingVideoOutput(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) {
2023-02-18 21:24:25 +00:00
_manager->perform([sink](Manager *manager) {
2020-08-14 16:58:22 +00:00
manager->setIncomingVideoOutput(sink);
});
}
void InstanceImpl::setAudioOutputGainControlEnabled(bool enabled) {
}
void InstanceImpl::setEchoCancellationStrength(int strength) {
}
void InstanceImpl::setAudioInputDevice(std::string id) {
2023-02-18 21:24:25 +00:00
_manager->perform([id](Manager *manager) {
2020-10-01 01:59:32 +00:00
manager->setAudioInputDevice(id);
});
2020-08-14 16:58:22 +00:00
}
void InstanceImpl::setAudioOutputDevice(std::string id) {
2023-02-18 21:24:25 +00:00
_manager->perform([id](Manager *manager) {
2020-10-01 01:59:32 +00:00
manager->setAudioOutputDevice(id);
});
2020-08-14 16:58:22 +00:00
}
void InstanceImpl::setInputVolume(float level) {
2023-02-18 21:24:25 +00:00
_manager->perform([level](Manager *manager) {
2020-10-01 01:59:32 +00:00
manager->setInputVolume(level);
});
2020-08-14 16:58:22 +00:00
}
void InstanceImpl::setOutputVolume(float level) {
2023-02-18 21:24:25 +00:00
_manager->perform([level](Manager *manager) {
2020-10-01 01:59:32 +00:00
manager->setOutputVolume(level);
});
2020-08-14 16:58:22 +00:00
}
void InstanceImpl::setAudioOutputDuckingEnabled(bool enabled) {
// TODO: not implemented
}
2021-07-30 14:49:55 +00:00
void InstanceImpl::addExternalAudioSamples(std::vector<uint8_t> &&samples) {
2023-02-18 21:24:25 +00:00
_manager->perform([samples = std::move(samples)](Manager *manager) mutable {
2021-07-30 14:49:55 +00:00
manager->addExternalAudioSamples(std::move(samples));
});
}
2020-08-14 16:58:22 +00:00
void InstanceImpl::setIsLowBatteryLevel(bool isLowBatteryLevel) {
2023-02-18 21:24:25 +00:00
_manager->perform([isLowBatteryLevel](Manager *manager) {
2020-08-14 16:58:22 +00:00
manager->setIsLowBatteryLevel(isLowBatteryLevel);
});
}
std::string InstanceImpl::getLastError() {
return ""; // TODO: not implemented
}
std::string InstanceImpl::getDebugInfo() {
return ""; // TODO: not implemented
}
int64_t InstanceImpl::getPreferredRelayId() {
return 0; // we don't have endpoint ids
}
TrafficStats InstanceImpl::getTrafficStats() {
return TrafficStats{}; // TODO: not implemented
}
PersistentState InstanceImpl::getPersistentState() {
return PersistentState{}; // we dont't have such information
}
2020-08-15 21:06:36 +00:00
void InstanceImpl::stop(std::function<void(FinalState)> completion) {
2023-10-28 20:52:06 +00:00
RTC_LOG(LS_INFO) << "Stopping InstanceImpl";
2020-08-15 21:06:36 +00:00
std::string debugLog = _logSink->result();
2020-12-23 07:48:30 +00:00
2023-02-18 21:24:25 +00:00
_manager->perform([completion, debugLog = std::move(debugLog)](Manager *manager) {
2020-10-01 01:59:32 +00:00
manager->getNetworkStats([completion, debugLog = std::move(debugLog)](TrafficStats stats, CallStats callStats) {
2020-08-15 21:06:36 +00:00
FinalState finalState;
finalState.debugLog = debugLog;
finalState.isRatingSuggested = false;
finalState.trafficStats = stats;
2020-10-01 01:59:32 +00:00
finalState.callStats = callStats;
2020-12-23 07:48:30 +00:00
2020-08-15 21:06:36 +00:00
completion(finalState);
});
});
2020-08-14 16:58:22 +00:00
}
int InstanceImpl::GetConnectionMaxLayer() {
2021-06-25 00:43:10 +00:00
return 92;
2020-08-14 16:58:22 +00:00
}
2020-08-15 21:06:36 +00:00
std::vector<std::string> InstanceImpl::GetVersions() {
std::vector<std::string> result;
result.push_back("2.7.7");
2023-02-18 21:24:25 +00:00
result.push_back("5.0.0");
2020-08-15 21:06:36 +00:00
return result;
2020-08-14 16:58:22 +00:00
}
template <>
bool Register<InstanceImpl>() {
return Meta::RegisterOne<InstanceImpl>();
}
} // namespace tgcalls