| #include "api/video_codecs/sdp_video_format.h" |
| 6 | #include "absl/types/variant.h" |
| 7 | #include "absl/types/optional.h" |
| 8 | #include "rtc_base/copy_on_write_buffer.h" |
| 9 | #include "rtc_base/byte_buffer.h" |
| 10 |
| 11 | #include <vector> |
| 12 |
| 13 | namespace tgcalls { |
| 14 |
| 15 | enum class VideoState; |
| 16 | enum class AudioState; |
| 17 |
| 18 | struct PeerIceParameters { |
| 19 | std::string ufrag; |
| 20 | std::string pwd; |
| 21 | bool supportsRenomination = false; |
| 22 |
| 23 | PeerIceParameters() = default; |
| 24 |
| 25 | PeerIceParameters(std::string ufrag_, std::string pwd_, bool supportsRenomination_) : |
| 26 | ufrag(ufrag_), |
| 27 | pwd(pwd_), |
| 28 | supportsRenomination(supportsRenomination_) { |
| 29 | } |
| 30 |
| 31 | }; |
| 32 |
| 33 | struct CandidatesListMessage { |
| 34 | static constexpr uint8_t kId = 1; |
| 35 | static constexpr bool kRequiresAck = true; |
| 36 |
| 37 | std::vector<cricket::Candidate> candidates; |
| 38 | PeerIceParameters iceParameters; |
| 39 | }; |
| 40 |
| 41 | struct VideoFormatsMessage { |
| 42 | static constexpr uint8_t kId = 2; |
| 43 | static constexpr bool kRequiresAck = true; |
| 44 |
| 45 | std::vector<webrtc::SdpVideoFormat> formats; |
| 46 | int encodersCount = 0; |
| 47 | }; |
| 48 |
| 49 | struct RequestVideoMessage { |
| 50 | static constexpr uint8_t kId = 3; |
| 51 | static constexpr bool kRequiresAck = true; |
| 52 | }; |
| 53 |
| 54 | struct RemoteMediaStateMessage { |
| 55 | static constexpr uint8_t kId = 4; |
| 56 | static constexpr bool kRequiresAck = true; |
| 57 |
| 58 | AudioState audio = AudioState(); |
| 59 | VideoState video = VideoState(); |
| 60 | }; |
| 61 |
| 62 | struct AudioDataMessage { |
| 63 | static constexpr uint8_t kId = 5; |
| 64 | static constexpr bool kRequiresAck = false; |
| 65 |
| 66 | rtc::CopyOnWriteBuffer data; |
| 67 | }; |
| 68 |
| 69 | struct VideoDataMessage { |
| 70 | static constexpr uint8_t kId = 6; |
| 71 | static constexpr bool kRequiresAck = false; |
| 72 |
| 73 | rtc::CopyOnWriteBuffer data; |
| 74 | }; |
| 75 |
| 76 | struct UnstructuredDataMessage { |
| 77 | static constexpr uint8_t kId = 7; |
| 78 | static constexpr bool kRequiresAck = true; |
| 79 |
| 80 | rtc::CopyOnWriteBuffer data; |
| 81 | }; |
| 82 |
| 83 | struct VideoParametersMessage { |
| 84 | static constexpr uint8_t kId = 8; |
| 85 | static constexpr bool kRequiresAck = true; |
| 86 |
| 87 | uint32_t aspectRatio; |
| 88 | }; |
| 89 |
| 90 | struct RemoteBatteryLevelIsLowMessage { |
| 91 | static constexpr uint8_t kId = 9; |
| 92 | static constexpr bool kRequiresAck = true; |
| 93 |
| 94 | bool batteryLow = false; |
| 95 | }; |
| 96 |
| 97 | struct RemoteNetworkStatusMessage { |
| 98 | static constexpr uint8_t kId = 10; |
| 99 | static constexpr bool kRequiresAck = true; |
| 100 |
| 101 | bool isLowCost = false; |
| 102 | bool isLowDataRequested = false; |
| 103 | }; |
| 104 |
| 105 | // To add a new message you should: |
| 106 | // 1. Add the message struct. |
| 107 | // 2. Add the message to the variant in Message struct. |
| 108 | // 3. Add Serialize/Deserialize methods in Message module. |
| 109 |
| 110 | struct Message { |
| 111 | absl::variant< |
| 112 | CandidatesListMessage, |
| 113 | VideoFormatsMessage, |
| 114 | RequestVideoMessage, |
| 115 | RemoteMediaStateMessage, |
| 116 | AudioDataMessage, |
| 117 | VideoDataMessage, |
| 118 | UnstructuredDataMessage, |
| 119 | VideoParametersMessage, |
| 120 | RemoteBatteryLevelIsLowMessage, |
| 121 | RemoteNetworkStatusMessage> data; |
| 122 | }; |
| 123 |
| 124 | rtc::CopyOnWriteBuffer SerializeMessageWithSeq( |
| 125 | const Message &message, |
| 126 | uint32_t seq, |
| 127 | bool singleMessagePacket); |
| 128 | absl::optional<Message> DeserializeMessage( |
| 129 | rtc::ByteBufferReader &reader, |
| 130 | bool singleMessagePacket); |
| 131 | absl::optional<rtc::CopyOnWriteBuffer> DeserializeRawMessage( |
| 132 | rtc::ByteBufferReader &reader, |
| 133 | bool singleMessagePacket); |
| 134 |
| 135 | struct DecryptedMessage { |
| 136 | Message message; |
| 137 | uint32_t counter = 0; |
| 138 | }; |
| 139 |
| 140 | struct DecryptedRawMessage { |
| 141 | rtc::CopyOnWriteBuffer message; |
| 142 | uint32_t counter = 0; |
| 143 | }; |
| 144 |
| 145 |
| 146 | } // namespace tgcalls |
| 147 |
| 148 | #endif |
| 149 |