| 6 | #include "media/base/media_engine.h" |
| 7 | #include "pc/media_session.h" |
| 8 | #include "pc/session_description.h" |
| 9 | #include "p2p/base/transport_description_factory.h" |
| 10 |
| 11 | #include "v2/Signaling.h" |
| 12 |
| 13 | namespace tgcalls { |
| 14 |
| 15 | class ContentNegotiationContext { |
| 16 | public: |
| 17 | struct NegotiationContents { |
| 18 | uint32_t exchangeId = 0; |
| 19 | std::vector<signaling::MediaContent> contents; |
| 20 | }; |
| 21 |
| 22 | struct PendingOutgoingOffer { |
| 23 | uint32_t exchangeId = 0; |
| 24 | }; |
| 25 |
| 26 | struct PendingOutgoingChannel { |
| 27 | cricket::MediaDescriptionOptions description; |
| 28 |
| 29 | uint32_t ssrc = 0; |
| 30 | std::vector<signaling::SsrcGroup> ssrcGroups; |
| 31 |
| 32 | PendingOutgoingChannel(cricket::MediaDescriptionOptions &&description_) : |
| 33 | description(std::move(description_)) { |
| 34 | } |
| 35 | }; |
| 36 |
| 37 | struct OutgoingChannel { |
| 38 | std::string id; |
| 39 | signaling::MediaContent content; |
| 40 |
| 41 | OutgoingChannel(std::string id_, signaling::MediaContent content_) : |
| 42 | id(id_), content(content_) { |
| 43 | } |
| 44 | }; |
| 45 |
| 46 | struct CoordinatedState { |
| 47 | std::vector<signaling::MediaContent> outgoingContents; |
| 48 | std::vector<signaling::MediaContent> incomingContents; |
| 49 | }; |
| 50 |
| 51 | public: |
| 52 | ContentNegotiationContext(const webrtc::FieldTrialsView &fieldTrials, bool isOutgoing, cricket::MediaEngineInterface *mediaEngine, rtc::UniqueRandomIdGenerator *uniqueRandomIdGenerator); |
| 53 | ~ContentNegotiationContext(); |
| 54 |
| 55 | void copyCodecsFromChannelManager(cricket::MediaEngineInterface *mediaEngine, bool randomize); |
| 56 |
| 57 | std::string addOutgoingChannel(signaling::MediaContent::Type mediaType); |
| 58 | void removeOutgoingChannel(std::string const &id); |
| 59 |
| 60 | std::unique_ptr<NegotiationContents> getPendingOffer(); |
| 61 | std::unique_ptr<NegotiationContents> setRemoteNegotiationContent(std::unique_ptr<NegotiationContents> &&remoteNegotiationContent); |
| 62 |
| 63 | std::unique_ptr<CoordinatedState> coordinatedState() const; |
| 64 | absl::optional<uint32_t> outgoingChannelSsrc(std::string const &id) const; |
| 65 |
| 66 | private: |
| 67 | std::string takeNextOutgoingChannelId(); |
| 68 | std::unique_ptr<cricket::SessionDescription> currentSessionDescriptionFromCoordinatedState(); |
| 69 |
| 70 | std::unique_ptr<NegotiationContents> getAnswer(std::unique_ptr<NegotiationContents> &&offer); |
| 71 | void setAnswer(std::unique_ptr<NegotiationContents> &&answer); |
| 72 |
| 73 | private: |
| 74 | bool _isOutgoing = false; |
| 75 | rtc::UniqueRandomIdGenerator *_uniqueRandomIdGenerator = nullptr; |
| 76 |
| 77 | std::unique_ptr<cricket::TransportDescriptionFactory> _transportDescriptionFactory; |
| 78 | std::unique_ptr<cricket::MediaSessionDescriptionFactory> _sessionDescriptionFactory; |
| 79 |
| 80 | std::vector<std::string> _channelIdOrder; |
| 81 |
| 82 | std::vector<webrtc::RtpHeaderExtensionCapability> _rtpAudioExtensions; |
| 83 | std::vector<webrtc::RtpHeaderExtensionCapability> _rtpVideoExtensions; |
| 84 |
| 85 | std::vector<PendingOutgoingChannel> _outgoingChannelDescriptions; |
| 86 | bool _needNegotiation = false; |
| 87 |
| 88 | std::vector<OutgoingChannel> _outgoingChannels; |
| 89 | std::vector<signaling::MediaContent> _incomingChannels; |
| 90 |
| 91 | std::unique_ptr<PendingOutgoingOffer> _pendingOutgoingOffer; |
| 92 |
| 93 | int _nextOutgoingChannelId = 0; |
| 94 |
| 95 | }; |
| 96 |
| 97 | } // namespace tgcalls |
| 98 |
| 99 | #endif |
| 100 |