2020-08-14 16:58:22 +00:00
|
|
|
#ifndef TGCALLS_MANAGER_H
|
|
|
|
#define TGCALLS_MANAGER_H
|
|
|
|
|
|
|
|
#include "ThreadLocalObject.h"
|
|
|
|
#include "EncryptedConnection.h"
|
|
|
|
#include "NetworkManager.h"
|
|
|
|
#include "MediaManager.h"
|
|
|
|
#include "Instance.h"
|
2020-10-01 01:59:32 +00:00
|
|
|
#include "Stats.h"
|
2020-08-14 16:58:22 +00:00
|
|
|
|
|
|
|
namespace tgcalls {
|
|
|
|
|
|
|
|
class Manager final : public std::enable_shared_from_this<Manager> {
|
2020-10-01 01:59:32 +00:00
|
|
|
private:
|
|
|
|
struct ResolvedNetworkStatus {
|
|
|
|
bool isLowCost = false;
|
|
|
|
bool isLowDataRequested = false;
|
|
|
|
|
2022-03-11 16:49:54 +00:00
|
|
|
bool operator==(const ResolvedNetworkStatus &rhs) const;
|
|
|
|
bool operator!=(const ResolvedNetworkStatus &rhs) const;
|
2020-10-01 01:59:32 +00:00
|
|
|
};
|
|
|
|
|
2020-08-14 16:58:22 +00:00
|
|
|
public:
|
|
|
|
static rtc::Thread *getMediaThread();
|
|
|
|
|
|
|
|
Manager(rtc::Thread *thread, Descriptor &&descriptor);
|
|
|
|
~Manager();
|
|
|
|
|
|
|
|
void start();
|
|
|
|
void receiveSignalingData(const std::vector<uint8_t> &data);
|
|
|
|
void setVideoCapture(std::shared_ptr<VideoCaptureInterface> videoCapture);
|
2021-08-31 19:06:39 +00:00
|
|
|
void sendVideoDeviceUpdated();
|
2020-10-01 01:59:32 +00:00
|
|
|
void setRequestedVideoAspect(float aspect);
|
2020-08-14 16:58:22 +00:00
|
|
|
void setMuteOutgoingAudio(bool mute);
|
2022-03-11 16:49:54 +00:00
|
|
|
void setIncomingVideoOutput(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink);
|
2020-08-14 16:58:22 +00:00
|
|
|
void setIsLowBatteryLevel(bool isLowBatteryLevel);
|
2020-08-15 21:06:36 +00:00
|
|
|
void setIsLocalNetworkLowCost(bool isLocalNetworkLowCost);
|
2020-10-01 01:59:32 +00:00
|
|
|
void getNetworkStats(std::function<void(TrafficStats, CallStats)> completion);
|
|
|
|
|
|
|
|
|
|
|
|
void setAudioInputDevice(std::string id);
|
|
|
|
void setAudioOutputDevice(std::string id);
|
|
|
|
void setInputVolume(float level);
|
|
|
|
void setOutputVolume(float level);
|
|
|
|
|
2021-07-30 14:49:55 +00:00
|
|
|
void addExternalAudioSamples(std::vector<uint8_t> &&samples);
|
|
|
|
|
2020-08-14 16:58:22 +00:00
|
|
|
private:
|
|
|
|
void sendSignalingAsync(int delayMs, int cause);
|
|
|
|
void receiveMessage(DecryptedMessage &&message);
|
2020-10-01 01:59:32 +00:00
|
|
|
void updateCurrentResolvedNetworkStatus();
|
2020-08-15 21:06:36 +00:00
|
|
|
void sendInitialSignalingMessages();
|
2020-08-14 16:58:22 +00:00
|
|
|
|
|
|
|
rtc::Thread *_thread;
|
|
|
|
EncryptionKey _encryptionKey;
|
|
|
|
EncryptedConnection _signaling;
|
|
|
|
bool _enableP2P = false;
|
2020-10-01 01:59:32 +00:00
|
|
|
bool _enableTCP = false;
|
|
|
|
bool _enableStunMarking = false;
|
2020-08-15 21:06:36 +00:00
|
|
|
ProtocolVersion _protocolVersion = ProtocolVersion::V0;
|
2020-10-01 01:59:32 +00:00
|
|
|
FilePath _statsLogPath;
|
2020-08-14 16:58:22 +00:00
|
|
|
std::vector<RtcServer> _rtcServers;
|
2020-12-23 07:48:30 +00:00
|
|
|
std::unique_ptr<Proxy> _proxy;
|
2020-10-01 01:59:32 +00:00
|
|
|
MediaDevicesConfig _mediaDevicesConfig;
|
2020-08-14 16:58:22 +00:00
|
|
|
std::shared_ptr<VideoCaptureInterface> _videoCapture;
|
|
|
|
std::function<void(State)> _stateUpdated;
|
|
|
|
std::function<void(AudioState, VideoState)> _remoteMediaStateUpdated;
|
|
|
|
std::function<void(bool)> _remoteBatteryLevelIsLowUpdated;
|
|
|
|
std::function<void(float)> _remotePrefferedAspectRatioUpdated;
|
|
|
|
std::function<void(const std::vector<uint8_t> &)> _signalingDataEmitted;
|
|
|
|
std::function<void(int)> _signalBarsUpdated;
|
2020-12-23 07:48:30 +00:00
|
|
|
std::function<void(float)> _audioLevelUpdated;
|
2021-03-19 10:25:58 +00:00
|
|
|
std::function<rtc::scoped_refptr<webrtc::AudioDeviceModule>(webrtc::TaskQueueFactory*)> _createAudioDeviceModule;
|
2020-08-14 16:58:22 +00:00
|
|
|
std::function<uint32_t(const Message &)> _sendSignalingMessage;
|
|
|
|
std::function<void(Message&&)> _sendTransportMessage;
|
|
|
|
std::unique_ptr<ThreadLocalObject<NetworkManager>> _networkManager;
|
|
|
|
std::unique_ptr<ThreadLocalObject<MediaManager>> _mediaManager;
|
|
|
|
State _state = State::Reconnecting;
|
|
|
|
bool _didConnectOnce = false;
|
|
|
|
bool _enableHighBitrateVideo = false;
|
2020-10-01 01:59:32 +00:00
|
|
|
DataSaving _dataSaving = DataSaving::Never;
|
2020-08-15 21:06:36 +00:00
|
|
|
std::vector<std::string> _preferredCodecs;
|
|
|
|
bool _localNetworkIsLowCost = false;
|
|
|
|
bool _remoteNetworkIsLowCost = false;
|
2020-10-01 01:59:32 +00:00
|
|
|
bool _remoteIsLowDataRequested = false;
|
|
|
|
absl::optional<ResolvedNetworkStatus> _currentResolvedLocalNetworkStatus;
|
|
|
|
absl::optional<ResolvedNetworkStatus> _currentResolvedNetworkStatus;
|
2020-08-14 16:58:22 +00:00
|
|
|
|
2020-08-21 23:59:49 +00:00
|
|
|
std::shared_ptr<PlatformContext> _platformContext;
|
|
|
|
|
2020-08-14 16:58:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace tgcalls
|
|
|
|
|
|
|
|
#endif
|