| #include "MediaManager.h" |
| 6 | #include "VideoCaptureInterfaceImpl.h" |
| 7 | #include "VideoCapturerInterface.h" |
| 8 |
| 9 | namespace tgcalls { |
| 10 | namespace { |
| 11 |
| 12 | rtc::Thread *makeManagerThread() { |
| 13 | static std::unique_ptr<rtc::Thread> value = rtc::Thread::Create(); |
| 14 | value->SetName("WebRTC-Manager", nullptr); |
| 15 | value->Start(); |
| 16 | return value.get(); |
| 17 | } |
| 18 |
| 19 |
| 20 | rtc::Thread *getManagerThread() { |
| 21 | static rtc::Thread *value = makeManagerThread(); |
| 22 | return value; |
| 23 | } |
| 24 |
| 25 | } // namespace |
| 26 |
| 27 | InstanceImpl::InstanceImpl(Descriptor &&descriptor) |
| 28 | : _logSink(std::make_unique<LogSinkImpl>(descriptor.config)) { |
| 29 | rtc::LogMessage::LogToDebug(rtc::LS_INFO); |
| 30 | rtc::LogMessage::SetLogToStderr(false); |
| 31 | rtc::LogMessage::AddLogToStream(_logSink.get(), rtc::LS_INFO); |
| 32 |
| 33 | auto networkType = descriptor.initialNetworkType; |
| 34 |
| 35 | _manager.reset(new ThreadLocalObject<Manager>(getManagerThread(), [descriptor = std::move(descriptor)]() mutable { |
| 36 | return new Manager(getManagerThread(), std::move(descriptor)); |
| 37 | })); |
| 38 | _manager->perform(RTC_FROM_HERE, [](Manager *manager) { |
| 39 | manager->start(); |
| 40 | }); |
| 41 |
| 42 | setNetworkType(networkType); |
| 43 | } |
| 44 |
| 45 | InstanceImpl::~InstanceImpl() { |
| 46 | rtc::LogMessage::RemoveLogToStream(_logSink.get()); |
| 47 | } |
| 48 |
| 49 | void InstanceImpl::receiveSignalingData(const std::vector<uint8_t> &data) { |
| 50 | _manager->perform(RTC_FROM_HERE, [data](Manager *manager) { |
| 51 | manager->receiveSignalingData(data); |
| 52 | }); |
| 53 | }; |
| 54 |
| 55 | void InstanceImpl::setVideoCapture(std::shared_ptr<VideoCaptureInterface> videoCapture) { |
| 56 | _manager->perform(RTC_FROM_HERE, [videoCapture](Manager *manager) { |
| 57 | manager->setVideoCapture(videoCapture); |
| 58 | }); |
| 59 | } |
| 60 |
| 61 | void InstanceImpl::setNetworkType(NetworkType networkType) { |
| 62 | bool isLowCostNetwork = false; |
| 63 | switch (networkType) { |
| 64 | case NetworkType::WiFi: |
| 65 | case NetworkType::Ethernet: |
| 66 | isLowCostNetwork = true; |
| 67 | break; |
| 68 | default: |
| 69 | break; |
| 70 | } |
| 71 |
| 72 | _manager->perform(RTC_FROM_HERE, [isLowCostNetwork](Manager *manager) { |
| 73 | manager->setIsLocalNetworkLowCost(isLowCostNetwork); |
| 74 | }); |
| 75 | } |
| 76 |
| 77 | void InstanceImpl::setMuteMicrophone(bool muteMicrophone) { |
| 78 | _manager->perform(RTC_FROM_HERE, [muteMicrophone](Manager *manager) { |
| 79 | manager->setMuteOutgoingAudio(muteMicrophone); |
| 80 | }); |
| 81 | } |
| 82 |
| 83 | void InstanceImpl::setIncomingVideoOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) { |
| 84 | _manager->perform(RTC_FROM_HERE, [sink](Manager *manager) { |
| 85 | manager->setIncomingVideoOutput(sink); |
| 86 | }); |
| 87 | } |
| 88 |
| 89 | void InstanceImpl::setAudioOutputGainControlEnabled(bool enabled) { |
| 90 | } |
| 91 |
| 92 | void InstanceImpl::setEchoCancellationStrength(int strength) { |
| 93 | } |
| 94 |
| 95 | void InstanceImpl::setAudioInputDevice(std::string id) { |
| 96 | // TODO: not implemented |
| 97 | } |
| 98 |
| 99 | void InstanceImpl::setAudioOutputDevice(std::string id) { |
| 100 | // TODO: not implemented |
| 101 | } |
| 102 |
| 103 | void InstanceImpl::setInputVolume(float level) { |
| 104 | // TODO: not implemented |
| 105 | } |
| 106 |
| 107 | void InstanceImpl::setOutputVolume(float level) { |
| 108 | // TODO: not implemented |
| 109 | } |
| 110 |
| 111 | void InstanceImpl::setAudioOutputDuckingEnabled(bool enabled) { |
| 112 | // TODO: not implemented |
| 113 | } |
| 114 |
| 115 | void InstanceImpl::setIsLowBatteryLevel(bool isLowBatteryLevel) { |
| 116 | _manager->perform(RTC_FROM_HERE, [isLowBatteryLevel](Manager *manager) { |
| 117 | manager->setIsLowBatteryLevel(isLowBatteryLevel); |
| 118 | }); |
| 119 | } |
| 120 |
| 121 | std::string InstanceImpl::getLastError() { |
| 122 | return ""; // TODO: not implemented |
| 123 | } |
| 124 |
| 125 | std::string InstanceImpl::getDebugInfo() { |
| 126 | return ""; // TODO: not implemented |
| 127 | } |
| 128 |
| 129 | int64_t InstanceImpl::getPreferredRelayId() { |
| 130 | return 0; // we don't have endpoint ids |
| 131 | } |
| 132 |
| 133 | TrafficStats InstanceImpl::getTrafficStats() { |
| 134 | return TrafficStats{}; // TODO: not implemented |
| 135 | } |
| 136 |
| 137 | PersistentState InstanceImpl::getPersistentState() { |
| 138 | return PersistentState{}; // we dont't have such information |
| 139 | } |
| 140 |
| 141 | void InstanceImpl::stop(std::function<void(FinalState)> completion) { |
| 142 | std::string debugLog = _logSink->result(); |
| 143 |
| 144 | _manager->perform(RTC_FROM_HERE, [completion, debugLog = std::move(debugLog)](Manager *manager) { |
| 145 | manager->getNetworkStats([completion, debugLog = std::move(debugLog)](TrafficStats stats) { |
| 146 | FinalState finalState; |
| 147 | finalState.debugLog = debugLog; |
| 148 | finalState.isRatingSuggested = false; |
| 149 | finalState.trafficStats = stats; |
| 150 |
| 151 | completion(finalState); |
| 152 | }); |
| 153 | }); |
| 154 | } |
| 155 |
| 156 | /*void InstanceImpl::controllerStateCallback(Controller::State state) { |
| 157 | if (onStateUpdated_) { |
| 158 | const auto mappedState = [&] { |
| 159 | switch (state) { |
| 160 | case Controller::State::WaitInit: |
| 161 | return State::WaitInit; |
| 162 | case Controller::State::WaitInitAck: |
| 163 | return State::WaitInitAck; |
| 164 | case Controller::State::Established: |
| 165 | return State::Estabilished; |
| 166 | case Controller::State::Failed: |
| 167 | return State::Failed; |
| 168 | case Controller::State::Reconnecting: |
| 169 | return State::Reconnecting; |
| 170 | default: |
| 171 | return State::Estabilished; |
| 172 | } |
| 173 | }(); |
| 174 |
| 175 | onStateUpdated_(mappedState); |
| 176 | } |
| 177 | }*/ |
| 178 |
| 179 | int InstanceImpl::GetConnectionMaxLayer() { |
| 180 | return 92; // TODO: retrieve from LayerBase |
| 181 | } |
| 182 |
| 183 | std::vector<std::string> InstanceImpl::GetVersions() { |
| 184 | std::vector<std::string> result; |
| 185 | result.push_back("2.7.7"); |
| 186 | result.push_back("3.0.0"); |
| 187 | return result; |
| 188 | } |
| 189 |
| 190 | template <> |
| 191 | bool Register<InstanceImpl>() { |
| 192 | return Meta::RegisterOne<InstanceImpl>(); |
| 193 | } |
| 194 |
| 195 | } // namespace tgcalls |
| 196 |