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