| 6 | namespace tgvoip |
| 7 | { |
| 8 |
| 9 | class VoIPGroupController : public VoIPController |
| 10 | { |
| 11 | public: |
| 12 | VoIPGroupController(std::int32_t m_timeDifference); |
| 13 | ~VoIPGroupController() override; |
| 14 | void SetGroupCallInfo(std::uint8_t* m_encryptionKey, std::uint8_t* reflectorGroupTag, std::uint8_t* m_reflectorSelfTag, |
| 15 | std::uint8_t* m_reflectorSelfSecret, std::uint8_t* m_reflectorSelfTagHash, std::int32_t selfUserID, |
| 16 | const NetworkAddress& reflectorAddress, const NetworkAddress& reflectorAddressV6, std::uint16_t reflectorPort); |
| 17 | void AddGroupCallParticipant(std::int32_t userID, std::uint8_t* memberTagHash, std::uint8_t* serializedStreams, std::size_t streamsLength); |
| 18 | void RemoveGroupCallParticipant(std::int32_t userID); |
| 19 | float GetParticipantAudioLevel(std::int32_t userID); |
| 20 | void SetMicMute(bool mute) override; |
| 21 | void SetParticipantVolume(std::int32_t userID, float volume); |
| 22 | void SetParticipantStreams(std::int32_t userID, std::uint8_t* serializedStreams, std::size_t length); |
| 23 | static std::size_t GetInitialStreams(std::uint8_t* buf, std::size_t size); |
| 24 |
| 25 | struct Callbacks : public VoIPController::Callbacks |
| 26 | { |
| 27 | void (*updateStreams)(VoIPGroupController*, std::uint8_t*, std::size_t); |
| 28 | void (*participantAudioStateChanged)(VoIPGroupController*, std::int32_t, bool); |
| 29 | }; |
| 30 | void SetCallbacks(Callbacks m_callbacks); |
| 31 | std::string GetDebugString() override; |
| 32 | void SetNetworkType(NetType type) override; |
| 33 |
| 34 | protected: |
| 35 | void ProcessIncomingPacket(NetworkPacket& packet, Endpoint& srcEndpoint) override; |
| 36 | void SendInit() override; |
| 37 | void SendUdpPing(Endpoint& endpoint) override; |
| 38 | void SendRelayPings() override; |
| 39 | void SendPacket(std::uint8_t* data, std::size_t len, Endpoint& ep, PendingOutgoingPacket& srcPacket) override; |
| 40 | void WritePacketHeader(std::uint32_t seq, BufferOutputStream* s, PktType type, |
| 41 | std::uint32_t length, PacketSender* source) override; |
| 42 | void OnAudioOutputReady() override; |
| 43 |
| 44 | private: |
| 45 | struct GroupCallParticipant |
| 46 | { |
| 47 | std::vector<std::shared_ptr<Stream>> streams; |
| 48 | AudioLevelMeter* levelMeter; |
| 49 | std::int32_t userID; |
| 50 | std::uint8_t memberTagHash[32]; |
| 51 | }; |
| 52 |
| 53 | struct PacketIdMapping |
| 54 | { |
| 55 | double ackTime; |
| 56 | std::uint32_t seq; |
| 57 | std::uint16_t id; |
| 58 | }; |
| 59 |
| 60 | std::vector<std::shared_ptr<Stream>> DeserializeStreams(BufferInputStream& in); |
| 61 | std::vector<PacketIdMapping> m_recentSentPackets; |
| 62 | std::vector<GroupCallParticipant> m_participants; |
| 63 |
| 64 | Callbacks m_groupCallbacks; |
| 65 | AudioMixer* m_audioMixer; |
| 66 | Endpoint m_groupReflector; |
| 67 |
| 68 | Mutex m_sentPacketsMutex; |
| 69 | Mutex m_participantsMutex; |
| 70 |
| 71 | std::int32_t m_timeDifference; |
| 72 | std::int32_t m_userSelfID; |
| 73 |
| 74 | AudioLevelMeter m_selfLevelMeter; |
| 75 |
| 76 | std::uint8_t m_reflectorSelfTag[16]; |
| 77 | std::uint8_t m_reflectorSelfSecret[16]; |
| 78 | std::uint8_t m_reflectorSelfTagHash[32]; |
| 79 |
| 80 | std::int32_t GetCurrentUnixtime(); |
| 81 | void SendRecentPacketsRequest(); |
| 82 | void SendSpecialReflectorRequest(std::uint8_t* data, std::size_t len); |
| 83 | void SerializeAndUpdateOutgoingStreams(); |
| 84 | }; |
| 85 |
| 86 | } // namespace tgvoip |
| 87 |
| 88 | #endif // VOIPGROUPCONTROLLER_H |
| 89 |