description.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * Copyright (c) 2019 Paul-Louis Ageneau
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef RTC_DESCRIPTION_H
  19. #define RTC_DESCRIPTION_H
  20. #include "candidate.hpp"
  21. #include "include.hpp"
  22. #include <iostream>
  23. #include <map>
  24. #include <optional>
  25. #include <vector>
  26. namespace rtc {
  27. class Description {
  28. public:
  29. enum class Type { Unspec = 0, Offer = 1, Answer = 2 };
  30. enum class Role { ActPass = 0, Passive = 1, Active = 2 };
  31. Description(const string &sdp, const string &typeString = "");
  32. Description(const string &sdp, Type type);
  33. Description(const string &sdp, Type type, Role role);
  34. Type type() const;
  35. string typeString() const;
  36. Role role() const;
  37. string roleString() const;
  38. string dataMid() const;
  39. std::optional<string> fingerprint() const;
  40. std::optional<uint16_t> sctpPort() const;
  41. std::optional<size_t> maxMessageSize() const;
  42. bool ended() const;
  43. void hintType(Type type);
  44. void setDataMid(string mid);
  45. void setFingerprint(string fingerprint);
  46. void setSctpPort(uint16_t port);
  47. void setMaxMessageSize(size_t size);
  48. void addCandidate(Candidate candidate);
  49. void endCandidates();
  50. std::vector<Candidate> extractCandidates();
  51. bool hasMedia() const;
  52. void addMedia(const Description &source);
  53. operator string() const;
  54. string generateSdp(const string &eol) const;
  55. private:
  56. Type mType;
  57. Role mRole;
  58. string mSessionId;
  59. string mIceUfrag, mIcePwd;
  60. std::optional<string> mFingerprint;
  61. // Data
  62. struct Data {
  63. string mid;
  64. std::optional<uint16_t> sctpPort;
  65. std::optional<size_t> maxMessageSize;
  66. };
  67. Data mData;
  68. // Media (non-data)
  69. struct Media {
  70. Media(const string &mline);
  71. string type;
  72. string description;
  73. string mid;
  74. std::vector<string> attributes;
  75. };
  76. std::map<int, Media> mMedia; // by m-line index
  77. // Candidates
  78. std::vector<Candidate> mCandidates;
  79. bool mEnded = false;
  80. static Type stringToType(const string &typeString);
  81. static string typeToString(Type type);
  82. static string roleToString(Role role);
  83. };
  84. } // namespace rtc
  85. std::ostream &operator<<(std::ostream &out, const rtc::Description &description);
  86. #endif