| #include <vector> |
| 6 |
| 7 | #include "absl/types/variant.h" |
| 8 | #include "absl/types/optional.h" |
| 9 | #include "api/rtp_parameters.h" |
| 10 |
| 11 | namespace tgcalls { |
| 12 |
| 13 | namespace signaling { |
| 14 |
| 15 | struct DtlsFingerprint { |
| 16 | std::string hash; |
| 17 | std::string setup; |
| 18 | std::string fingerprint; |
| 19 | }; |
| 20 |
| 21 | struct ConnectionAddress { |
| 22 | std::string ip; |
| 23 | int port = 0; |
| 24 | }; |
| 25 |
| 26 | struct IceCandidate { |
| 27 | std::string sdpString; |
| 28 | }; |
| 29 |
| 30 | struct SsrcGroup { |
| 31 | std::vector<uint32_t> ssrcs; |
| 32 | std::string semantics; |
| 33 |
| 34 | bool operator==(SsrcGroup const &rhs) const { |
| 35 | if (ssrcs != rhs.ssrcs) { |
| 36 | return false; |
| 37 | } |
| 38 |
| 39 | if (semantics != rhs.semantics) { |
| 40 | return false; |
| 41 | } |
| 42 |
| 43 | return true; |
| 44 | } |
| 45 | }; |
| 46 |
| 47 | struct FeedbackType { |
| 48 | std::string type; |
| 49 | std::string subtype; |
| 50 |
| 51 | bool operator==(FeedbackType const &rhs) const { |
| 52 | if (type != rhs.type) { |
| 53 | return false; |
| 54 | } |
| 55 | if (subtype != rhs.subtype) { |
| 56 | return false; |
| 57 | } |
| 58 |
| 59 | return true; |
| 60 | } |
| 61 | }; |
| 62 |
| 63 | struct PayloadType { |
| 64 | uint32_t id = 0; |
| 65 | std::string name; |
| 66 | uint32_t clockrate = 0; |
| 67 | uint32_t channels = 0; |
| 68 | std::vector<FeedbackType> feedbackTypes; |
| 69 | std::vector<std::pair<std::string, std::string>> parameters; |
| 70 |
| 71 | bool operator==(PayloadType const &rhs) const { |
| 72 | if (id != rhs.id) { |
| 73 | return false; |
| 74 | } |
| 75 | if (name != rhs.name) { |
| 76 | return false; |
| 77 | } |
| 78 | if (clockrate != rhs.clockrate) { |
| 79 | return false; |
| 80 | } |
| 81 | if (channels != rhs.channels) { |
| 82 | return false; |
| 83 | } |
| 84 | if (feedbackTypes != rhs.feedbackTypes) { |
| 85 | return false; |
| 86 | } |
| 87 | if (parameters != rhs.parameters) { |
| 88 | return false; |
| 89 | } |
| 90 |
| 91 | return true; |
| 92 | } |
| 93 | }; |
| 94 |
| 95 | struct MediaContent { |
| 96 | enum class Type { |
| 97 | Audio, |
| 98 | Video |
| 99 | }; |
| 100 |
| 101 | Type type = Type::Audio; |
| 102 | uint32_t ssrc = 0; |
| 103 | std::vector<SsrcGroup> ssrcGroups; |
| 104 | std::vector<PayloadType> payloadTypes; |
| 105 | std::vector<webrtc::RtpExtension> rtpExtensions; |
| 106 |
| 107 | bool operator==(const MediaContent& rhs) const { |
| 108 | if (type != rhs.type) { |
| 109 | return false; |
| 110 | } |
| 111 | if (ssrc != rhs.ssrc) { |
| 112 | return false; |
| 113 | } |
| 114 | if (ssrcGroups != rhs.ssrcGroups) { |
| 115 | return false; |
| 116 | } |
| 117 |
| 118 | std::vector<PayloadType> sortedPayloadTypes = payloadTypes; |
| 119 | std::sort(sortedPayloadTypes.begin(), sortedPayloadTypes.end(), [](PayloadType const &lhs, PayloadType const &rhs) { |
| 120 | return lhs.id < rhs.id; |
| 121 | }); |
| 122 | std::vector<PayloadType> sortedRhsPayloadTypes = rhs.payloadTypes; |
| 123 | std::sort(sortedRhsPayloadTypes.begin(), sortedRhsPayloadTypes.end(), [](PayloadType const &lhs, PayloadType const &rhs) { |
| 124 | return lhs.id < rhs.id; |
| 125 | }); |
| 126 | if (sortedPayloadTypes != sortedRhsPayloadTypes) { |
| 127 | return false; |
| 128 | } |
| 129 |
| 130 | if (rtpExtensions != rhs.rtpExtensions) { |
| 131 | return false; |
| 132 | } |
| 133 |
| 134 | return true; |
| 135 | } |
| 136 | }; |
| 137 |
| 138 | struct InitialSetupMessage { |
| 139 | std::string ufrag; |
| 140 | std::string pwd; |
| 141 | bool supportsRenomination = false; |
| 142 | std::vector<DtlsFingerprint> fingerprints; |
| 143 | }; |
| 144 |
| 145 | struct NegotiateChannelsMessage { |
| 146 | uint32_t exchangeId = 0; |
| 147 | std::vector<MediaContent> contents; |
| 148 | }; |
| 149 |
| 150 | struct CandidatesMessage { |
| 151 | std::vector<IceCandidate> iceCandidates; |
| 152 | }; |
| 153 |
| 154 | struct MediaStateMessage { |
| 155 | enum class VideoState { |
| 156 | Inactive, |
| 157 | Suspended, |
| 158 | Active |
| 159 | }; |
| 160 |
| 161 | enum class VideoRotation { |
| 162 | Rotation0, |
| 163 | Rotation90, |
| 164 | Rotation180, |
| 165 | Rotation270 |
| 166 | }; |
| 167 |
| 168 | bool isMuted = false; |
| 169 | VideoState videoState = VideoState::Inactive; |
| 170 | VideoRotation videoRotation = VideoRotation::Rotation0; |
| 171 | VideoState screencastState = VideoState::Inactive; |
| 172 | bool isBatteryLow = false; |
| 173 |
| 174 | }; |
| 175 |
| 176 | struct Message { |
| 177 | absl::variant< |
| 178 | InitialSetupMessage, |
| 179 | NegotiateChannelsMessage, |
| 180 | CandidatesMessage, |
| 181 | MediaStateMessage> data; |
| 182 |
| 183 | std::vector<uint8_t> serialize() const; |
| 184 | static absl::optional<Message> parse(const std::vector<uint8_t> &data); |
| 185 | }; |
| 186 |
| 187 | }; |
| 188 |
| 189 | } // namespace tgcalls |
| 190 |
| 191 | #endif |
| 192 |