123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- /**
- * 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 <iostream>
- #include <map>
- #include <optional>
- #include <vector>
- 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 { SendOnly, RecvOnly, SendRecv, Unknown };
- 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<string> fingerprint() const;
- std::optional<uint16_t> sctpPort() const;
- std::optional<size_t> 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<Candidate> extractCandidates();
- operator string() const;
- string generateSdp(string_view eol) const;
- string generateDataSdp(string_view eol) const;
- // Media (non-data)
- class Media {
- public:
- Media(string mline, Direction dir = Direction::Unknown, string mid = "media");
- string type() const { return mType; }
- string description() const { return mDescription; }
- string mid() const { return mMid; }
- void removeFormat(const string &fmt);
- Direction getDirection();
- void setDirection(Direction dir);
- void addVideoCodec(int payloadType, const string &codec);
- void addH264Codec(int payloadType);
- void addVP8Codec(int payloadType);
- void addVP9Codec(int payloadType);
- void setBitrate(int bitrate);
- int getBitrate() const;
- void parseSdpLine(string line);
- string generateSdp(string_view eol) const;
- private:
- string mType;
- string mDescription;
- string mMid;
- std::vector<string> mAttributes;
- std::vector<string> mAttributesl;
- int mBas = -1;
- struct RTPMap {
- RTPMap(const string &mLine);
- void removeFB(const string &string);
- void addFB(const string &string);
- int pt;
- string format;
- int clockRate;
- string encParams;
- std::vector<string> rtcpFbs;
- std::vector<string> fmtps;
- };
- Media::RTPMap &getFormat(int fmt);
- Media::RTPMap &getFormat(const string &fmt);
- std::map<int, RTPMap> mRtpMap;
- };
- class AudioMedia : public Media {
- public:
- AudioMedia(Direction dir, string mid = "audio");
- };
- class VideoMedia : public Media {
- public:
- VideoMedia(Direction dir, string mid = "video");
- };
- bool hasMedia() const;
- void addMedia(Media media);
- private:
- Type mType;
- Role mRole;
- string mSessionId;
- string mIceUfrag, mIcePwd;
- std::optional<string> mFingerprint;
- struct Data {
- string mid;
- std::optional<uint16_t> sctpPort;
- std::optional<size_t> maxMessageSize;
- };
- Data mData;
- std::map<int, Media> mMedia; // by m-line index
- // Candidates
- std::vector<Candidate> 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
|