/** * Copyright (c) 2019 Paul-Louis Ageneau * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef RTC_DESCRIPTION_H #define RTC_DESCRIPTION_H #include "candidate.hpp" #include "include.hpp" #include #include #include #include namespace rtc { class Description { public: enum class Type { Unspec = 0, Offer = 1, Answer = 2 }; enum class Role { ActPass = 0, Passive = 1, Active = 2 }; enum Direction { SEND_ONLY, RECV_ONLY, BOTH }; Description(const string &sdp, const string &typeString = ""); Description(const string &sdp, Type type); Description(const string &sdp, Type type, Role role); Type type() const; string typeString() const; Role role() const; string roleString() const; string dataMid() const; string bundleMid() const; std::optional fingerprint() const; std::optional sctpPort() const; std::optional maxMessageSize() const; bool ended() const; void hintType(Type type); void setDataMid(string mid); void setFingerprint(string fingerprint); void setSctpPort(uint16_t port); void setMaxMessageSize(size_t size); void addCandidate(Candidate candidate); void endCandidates(); std::vector extractCandidates(); bool hasMedia() const; void addMedia(const Description &source); operator string() const; string generateSdp(const string &eol) const; string generateDataSdp(const string &eol) const; // Data struct Data { string mid; std::optional sctpPort; std::optional maxMessageSize; }; // Media (non-data) struct Media { Media(const string &lines); string type; string description; string mid; std::vector attributes; std::vector attributesl; int bAS = -1; struct RTPMap { RTPMap(const string &mLine); int pt; string format; int clockRate; string encParams; std::vector rtcpFbs; std::vector fmtps; void removeFB(const char *string); }; std::unordered_map rtpMap; Media::RTPMap& getFormat(int fmt); Media::RTPMap& getFormat(const string& fmt); Direction getDirection() { for (auto attr : attributes) { if (attr == "sendrecv") return Direction::BOTH; if (attr == "recvonly") return Direction::RECV_ONLY; if (attr == "sendonly") return Direction::SEND_ONLY; } } void setDirection(Direction dir) { auto it = attributes.begin(); while (it != attributes.end()) { if (*it == "sendrecv" || *it == "sendonly" || *it == "recvonly") it = attributes.erase(it); else it++; } if (dir == Direction::BOTH) attributes.emplace(attributes.begin(), "sendrecv"); else if (dir == Direction::RECV_ONLY) attributes.emplace(attributes.begin(), "recvonly"); if (dir == Direction::SEND_ONLY) attributes.emplace(attributes.begin(), "sendonly"); } void removeFormat(const string &fmt); void addH264Codec(int pt); }; std::_Rb_tree_iterator> getMedia(int mLine); Media & addAudioMedia(); Media &addVideoMedia(bool direction); private: Type mType; Role mRole; string mSessionId; string mIceUfrag, mIcePwd; std::optional mFingerprint; Data mData; std::map mMedia; // by m-line index // Candidates std::vector mCandidates; bool mEnded = false; static Type stringToType(const string &typeString); static string typeToString(Type type); static string roleToString(Role role); }; } // namespace rtc std::ostream &operator<<(std::ostream &out, const rtc::Description &description); #endif