11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
24PROMEKI_NAMESPACE_BEGIN
46class SdpMediaDescription {
49 SdpMediaDescription() =
default;
52 const String &mediaType()
const {
return _mediaType; }
55 void setMediaType(
const String &type) { _mediaType = type; }
58 uint16_t port()
const {
return _port; }
61 void setPort(uint16_t port) { _port = port; }
64 const String &protocol()
const {
return _protocol; }
67 void setProtocol(
const String &proto) { _protocol = proto; }
70 const List<uint8_t> &payloadTypes()
const {
return _payloadTypes; }
73 void addPayloadType(uint8_t pt) { _payloadTypes.pushToBack(pt); }
76 using Attribute = Pair<String, String>;
79 using AttributeList = ::promeki::List<Attribute>;
82 String attribute(
const String &name)
const {
83 for (
size_t i = 0; i < _attributes.size(); i++) {
84 if (_attributes[i].first() == name)
return _attributes[i].second();
96 void setAttribute(
const String &name,
const String &value) {
97 for (
size_t i = 0; i < _attributes.size(); i++) {
98 if (_attributes[i].first() == name) {
99 _attributes[i].setSecond(value);
103 _attributes.pushToBack(Attribute(name, value));
107 const AttributeList &attributes()
const {
return _attributes; }
114 const String &connectionAddress()
const {
return _connectionAddress; }
117 void setConnectionAddress(
const String &addr) { _connectionAddress = addr; }
128 uint8_t payloadType = 0;
130 uint32_t clockRate = 0;
131 unsigned int channels = 1;
142 RtpMap rtpMap()
const;
145 using FmtpParameters = ::promeki::Map<String, String>;
156 FmtpParameters fmtpParameters()
const;
159 bool operator==(
const SdpMediaDescription &other)
const {
160 return _mediaType == other._mediaType && _port == other._port && _protocol == other._protocol &&
161 _payloadTypes == other._payloadTypes && _attributes == other._attributes &&
162 _connectionAddress == other._connectionAddress;
166 bool operator!=(
const SdpMediaDescription &other)
const {
return !(*
this == other); }
172 List<uint8_t> _payloadTypes;
173 AttributeList _attributes;
174 String _connectionAddress;
204 PROMEKI_SHARED_FINAL(SdpSession)
206 PROMEKI_DATATYPE(SdpSession, DataTypeSdpSession, 1)
209 Error writeToStream(DataStream &s) const;
211 template <uint32_t V> static Result<SdpSession> readFromStream(DataStream &s);
214 using Ptr = SharedPtr<SdpSession>;
217 using List = ::promeki::List<SdpSession>;
220 using PtrList = ::promeki::List<SdpSession::Ptr>;
223 using MediaDescriptionList = ::promeki::List<SdpMediaDescription>;
231 static Result<SdpSession> fromString(const String &sdp);
246 static Result<SdpSession> fromFile(const String &path);
249 SdpSession() = default;
252 const String &sessionName()
const {
return _sessionName; }
255 void setSessionName(
const String &name) { _sessionName = name; }
258 const String &originUsername()
const {
return _originUsername; }
261 uint64_t sessionId()
const {
return _sessionId; }
264 uint64_t sessionVersion()
const {
return _sessionVersion; }
275 void setOrigin(
const String &username, uint64_t sessionId, uint64_t sessionVersion,
276 const String &netType =
"IN",
const String &addrType =
"IP4",
277 const String &address =
"0.0.0.0");
280 const String &originNetType()
const {
return _originNetType; }
283 const String &originAddrType()
const {
return _originAddrType; }
286 const String &originAddress()
const {
return _originAddress; }
289 const String &connectionAddress()
const {
return _connectionAddress; }
292 void setConnectionAddress(
const String &address) { _connectionAddress = address; }
295 const MediaDescriptionList &mediaDescriptions()
const {
return _mediaDescriptions; }
298 void addMediaDescription(
const SdpMediaDescription &md) { _mediaDescriptions.pushToBack(md); }
304 String toString()
const;
317 Error toFile(
const String &path)
const;
320 bool operator==(
const SdpSession &other)
const {
321 return _sessionName == other._sessionName && _originUsername == other._originUsername &&
322 _sessionId == other._sessionId && _sessionVersion == other._sessionVersion &&
323 _originNetType == other._originNetType && _originAddrType == other._originAddrType &&
324 _originAddress == other._originAddress &&
325 _connectionAddress == other._connectionAddress &&
326 _mediaDescriptions == other._mediaDescriptions;
330 bool operator!=(
const SdpSession &other)
const {
return !(*
this == other); }
334 String _originUsername =
"-";
335 uint64_t _sessionId = 0;
336 uint64_t _sessionVersion = 0;
337 String _originNetType =
"IN";
338 String _originAddrType =
"IP4";
339 String _originAddress =
"0.0.0.0";
340 String _connectionAddress;
341 MediaDescriptionList _mediaDescriptions;
346PROMEKI_FORMAT_VIA_TOSTRING(promeki::SdpSession);