| #include <vector> |
| 6 | #include <string> |
| 7 | #include <memory> |
| 8 | #include <map> |
| 9 | #include <optional> |
| 10 |
| 11 | #include "../Instance.h" |
| 12 |
| 13 | #include "../StaticThreads.h" |
| 14 | #include "GroupJoinPayload.h" |
| 15 |
| 16 | namespace webrtc { |
| 17 | class AudioDeviceModule; |
| 18 | class TaskQueueFactory; |
| 19 | class VideoTrackSourceInterface; |
| 20 | } |
| 21 |
| 22 | namespace webrtc { |
| 23 | template <class T> |
| 24 | class scoped_refptr; |
| 25 | } |
| 26 |
| 27 | namespace tgcalls { |
| 28 |
| 29 | class LogSinkImpl; |
| 30 | class GroupInstanceManager; |
| 31 | class WrappedAudioDeviceModule; |
| 32 | struct AudioFrame; |
| 33 |
| 34 | struct GroupConfig { |
| 35 | bool need_log{true}; |
| 36 | FilePath logPath; |
| 37 | }; |
| 38 |
| 39 | struct GroupLevelValue { |
| 40 | float level = 0.; |
| 41 | bool voice = false; |
| 42 | bool isMuted = false; |
| 43 | }; |
| 44 |
| 45 | struct GroupLevelUpdate { |
| 46 | uint32_t ssrc = 0; |
| 47 | GroupLevelValue value; |
| 48 | }; |
| 49 |
| 50 | struct GroupLevelsUpdate { |
| 51 | std::vector<GroupLevelUpdate> updates; |
| 52 | }; |
| 53 |
| 54 | struct GroupActivityUpdate { |
| 55 | uint32_t ssrc = 0; |
| 56 | }; |
| 57 |
| 58 | struct GroupActivitiesUpdate { |
| 59 | std::vector<GroupActivityUpdate> updates; |
| 60 | }; |
| 61 |
| 62 |
| 63 | class BroadcastPartTask { |
| 64 | public: |
| 65 | virtual ~BroadcastPartTask() = default; |
| 66 |
| 67 | virtual void cancel() = 0; |
| 68 | }; |
| 69 |
| 70 | struct BroadcastPart { |
| 71 | struct VideoParams { |
| 72 | }; |
| 73 |
| 74 | enum class Status { |
| 75 | Success, |
| 76 | NotReady, |
| 77 | ResyncNeeded |
| 78 | }; |
| 79 |
| 80 | int64_t timestampMilliseconds = 0; |
| 81 | double responseTimestamp = 0; |
| 82 | Status status = Status::NotReady; |
| 83 | std::vector<uint8_t> data; |
| 84 | }; |
| 85 |
| 86 | enum class GroupConnectionMode { |
| 87 | GroupConnectionModeNone, |
| 88 | GroupConnectionModeRtc, |
| 89 | GroupConnectionModeBroadcast |
| 90 | }; |
| 91 |
| 92 | struct GroupNetworkState { |
| 93 | bool isConnected = false; |
| 94 | bool isTransitioningFromBroadcastToRtc = false; |
| 95 | }; |
| 96 |
| 97 | enum class VideoContentType { |
| 98 | None, |
| 99 | Screencast, |
| 100 | Generic |
| 101 | }; |
| 102 |
| 103 | enum class VideoCodecName { |
| 104 | VP8, |
| 105 | VP9, |
| 106 | H264 |
| 107 | }; |
| 108 |
| 109 | class RequestMediaChannelDescriptionTask { |
| 110 | public: |
| 111 | virtual ~RequestMediaChannelDescriptionTask() = default; |
| 112 |
| 113 | virtual void cancel() = 0; |
| 114 | }; |
| 115 |
| 116 | struct MediaChannelDescription { |
| 117 | enum class Type { |
| 118 | Audio, |
| 119 | Video |
| 120 | }; |
| 121 |
| 122 | Type type = Type::Audio; |
| 123 | uint32_t audioSsrc = 0; |
| 124 | int64_t userId = 0; |
| 125 | std::string videoInformation; |
| 126 | }; |
| 127 |
| 128 | struct MediaSsrcGroup { |
| 129 | std::string semantics; |
| 130 | std::vector<uint32_t> ssrcs; |
| 131 | }; |
| 132 |
| 133 | struct VideoChannelDescription { |
| 134 | enum class Quality { |
| 135 | Thumbnail, |
| 136 | Medium, |
| 137 | Full |
| 138 | }; |
| 139 | uint32_t audioSsrc = 0; |
| 140 | int64_t userId = 0; |
| 141 | std::string endpointId; |
| 142 | std::vector<MediaSsrcGroup> ssrcGroups; |
| 143 | Quality minQuality = Quality::Thumbnail; |
| 144 | Quality maxQuality = Quality::Thumbnail; |
| 145 | }; |
| 146 |
| 147 | struct GroupInstanceStats { |
| 148 | struct IncomingVideoStats { |
| 149 | int receivingQuality = 0; |
| 150 | int availableQuality = 0; |
| 151 | }; |
| 152 |
| 153 | std::vector<std::pair<std::string, IncomingVideoStats>> incomingVideoStats; |
| 154 | }; |
| 155 |
| 156 | struct GroupInstanceDescriptor { |
| 157 | std::shared_ptr<Threads> threads; |
| 158 | GroupConfig config; |
| 159 | std::string statsLogPath; |
| 160 | std::function<void(GroupNetworkState)> networkStateUpdated; |
| 161 | std::function<void(int)> signalBarsUpdated; |
| 162 | std::function<void(GroupLevelsUpdate const &)> audioLevelsUpdated; |
| 163 | std::function<void(uint32_t, const AudioFrame &)> onAudioFrame; |
| 164 | std::function<void(GroupActivitiesUpdate const &)> ssrcActivityUpdated; |
| 165 | std::string initialInputDeviceId; |
| 166 | std::string initialOutputDeviceId; |
| 167 | bool useDummyChannel{true}; |
| 168 | bool disableIncomingChannels{false}; |
| 169 | std::function<webrtc::scoped_refptr<webrtc::AudioDeviceModule>(webrtc::TaskQueueFactory*)> createAudioDeviceModule; |
| 170 | std::function<webrtc::scoped_refptr<WrappedAudioDeviceModule>(webrtc::TaskQueueFactory*)> createWrappedAudioDeviceModule; |
| 171 | std::shared_ptr<VideoCaptureInterface> videoCapture; // deprecated |
| 172 | std::function<webrtc::scoped_refptr<webrtc::VideoTrackSourceInterface>()> getVideoSource; |
| 173 | std::function<std::shared_ptr<BroadcastPartTask>(std::function<void(int64_t)>)> requestCurrentTime; |
| 174 | std::function<std::shared_ptr<BroadcastPartTask>(std::shared_ptr<PlatformContext>, int64_t, int64_t, std::function<void(BroadcastPart &&)>)> requestAudioBroadcastPart; |
| 175 | std::function<std::shared_ptr<BroadcastPartTask>(std::shared_ptr<PlatformContext>, int64_t, int64_t, int32_t, VideoChannelDescription::Quality, std::function<void(BroadcastPart &&)>)> requestVideoBroadcastPart; |
| 176 | int outgoingAudioBitrateKbit{32}; |
| 177 | bool disableOutgoingAudioProcessing{false}; |
| 178 | bool disableAudioInput{false}; |
| 179 | bool ios_enableSystemMute{false}; |
| 180 | VideoContentType videoContentType{VideoContentType::None}; |
| 181 | bool initialEnableNoiseSuppression{false}; |
| 182 | std::vector<VideoCodecName> videoCodecPreferences; |
| 183 | std::function<std::shared_ptr<RequestMediaChannelDescriptionTask>(std::vector<uint32_t> const &, std::function<void(std::vector<MediaChannelDescription> &&)>)> requestMediaChannelDescriptions; |
| 184 | int minOutgoingVideoBitrateKbit{100}; |
| 185 | std::function<void(bool)> onMutedSpeechActivityDetected; |
| 186 | std::function<std::vector<uint8_t>(std::vector<uint8_t> const &, int64_t, bool, int32_t)> e2eEncryptDecrypt; |
| 187 | bool isConference{false}; |
| 188 |
| 189 | std::shared_ptr<PlatformContext> platformContext; |
| 190 | }; |
| 191 |
| 192 | template <typename T> |
| 193 | class ThreadLocalObject; |
| 194 |
| 195 | class GroupInstanceInterface { |
| 196 | protected: |
| 197 | GroupInstanceInterface() = default; |
| 198 |
| 199 | public: |
| 200 | virtual ~GroupInstanceInterface() = default; |
| 201 |
| 202 | virtual void stop(std::function<void()> completion) = 0; |
| 203 |
| 204 | virtual void setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled, bool isUnifiedBroadcast) = 0; |
| 205 |
| 206 | virtual void emitJoinPayload(std::function<void(GroupJoinPayload const &)> completion) = 0; |
| 207 | virtual void setJoinResponsePayload(std::string const &payload) = 0; |
| 208 | virtual void removeSsrcs(std::vector<uint32_t> ssrcs) = 0; |
| 209 | virtual void removeIncomingVideoSource(uint32_t ssrc) = 0; |
| 210 |
| 211 | virtual void setIsMuted(bool isMuted) = 0; |
| 212 | virtual void setIsNoiseSuppressionEnabled(bool isNoiseSuppressionEnabled) = 0; |
| 213 | virtual void setVideoCapture(std::shared_ptr<VideoCaptureInterface> videoCapture) = 0; |
| 214 | virtual void setVideoSource(std::function<webrtc::scoped_refptr<webrtc::VideoTrackSourceInterface>()> getVideoSource) = 0; |
| 215 | virtual void setAudioOutputDevice(std::string id) = 0; |
| 216 | virtual void setAudioInputDevice(std::string id) = 0; |
| 217 | virtual void addExternalAudioSamples(std::vector<uint8_t> &&samples) = 0; |
| 218 |
| 219 | virtual void addOutgoingVideoOutput(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) = 0; |
| 220 | virtual void addIncomingVideoOutput(std::string const &endpointId, std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) = 0; |
| 221 |
| 222 | virtual void setVolume(uint32_t ssrc, double volume) = 0; |
| 223 | virtual void setRequestedVideoChannels(std::vector<VideoChannelDescription> &&requestedVideoChannels) = 0; |
| 224 |
| 225 | virtual void getStats(std::function<void(GroupInstanceStats)> completion) = 0; |
| 226 | virtual void internal_addCustomNetworkEvent(bool isRemoteConnected) = 0; |
| 227 |
| 228 | struct AudioDevice { |
| 229 | enum class Type {Input, Output}; |
| 230 | std::string name; |
| 231 | std::string guid; |
| 232 | }; |
| 233 | static std::vector<GroupInstanceInterface::AudioDevice> getAudioDevices(AudioDevice::Type type); |
| 234 | }; |
| 235 |
| 236 | } // namespace tgcalls |
| 237 |
| 238 | #endif |
| 239 |