123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630 |
- #ifndef PC_SESSION_DESCRIPTION_H_
- #define PC_SESSION_DESCRIPTION_H_
- #include <stddef.h>
- #include <stdint.h>
- #include <iosfwd>
- #include <memory>
- #include <string>
- #include <utility>
- #include <vector>
- #include "absl/memory/memory.h"
- #include "api/crypto_params.h"
- #include "api/media_types.h"
- #include "api/rtp_parameters.h"
- #include "api/rtp_transceiver_interface.h"
- #include "media/base/media_channel.h"
- #include "media/base/stream_params.h"
- #include "p2p/base/transport_description.h"
- #include "p2p/base/transport_info.h"
- #include "pc/media_protocol_names.h"
- #include "pc/simulcast_description.h"
- #include "rtc_base/deprecation.h"
- #include "rtc_base/socket_address.h"
- #include "rtc_base/system/rtc_export.h"
- namespace cricket {
- typedef std::vector<AudioCodec> AudioCodecs;
- typedef std::vector<VideoCodec> VideoCodecs;
- typedef std::vector<RtpDataCodec> RtpDataCodecs;
- typedef std::vector<CryptoParams> CryptoParamsVec;
- typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
- extern const char kMediaProtocolAvpf[];
- extern const char kMediaProtocolSavpf[];
- extern const char kMediaProtocolDtlsSavpf[];
- const int kAutoBandwidth = -1;
- class AudioContentDescription;
- class VideoContentDescription;
- class RtpDataContentDescription;
- class SctpDataContentDescription;
- class MediaContentDescription {
- public:
- MediaContentDescription() = default;
- virtual ~MediaContentDescription() = default;
- virtual MediaType type() const = 0;
-
-
- virtual AudioContentDescription* as_audio() { return nullptr; }
- virtual const AudioContentDescription* as_audio() const { return nullptr; }
-
-
- virtual VideoContentDescription* as_video() { return nullptr; }
- virtual const VideoContentDescription* as_video() const { return nullptr; }
- virtual RtpDataContentDescription* as_rtp_data() { return nullptr; }
- virtual const RtpDataContentDescription* as_rtp_data() const {
- return nullptr;
- }
- virtual SctpDataContentDescription* as_sctp() { return nullptr; }
- virtual const SctpDataContentDescription* as_sctp() const { return nullptr; }
- virtual bool has_codecs() const = 0;
-
-
-
-
- std::unique_ptr<MediaContentDescription> Clone() const {
- return absl::WrapUnique(CloneInternal());
- }
-
-
- virtual std::string protocol() const { return protocol_; }
- virtual void set_protocol(const std::string& protocol) {
- protocol_ = protocol;
- }
- virtual webrtc::RtpTransceiverDirection direction() const {
- return direction_;
- }
- virtual void set_direction(webrtc::RtpTransceiverDirection direction) {
- direction_ = direction;
- }
- virtual bool rtcp_mux() const { return rtcp_mux_; }
- virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
- virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
- virtual void set_rtcp_reduced_size(bool reduced_size) {
- rtcp_reduced_size_ = reduced_size;
- }
-
-
- virtual bool remote_estimate() const { return remote_estimate_; }
- virtual void set_remote_estimate(bool remote_estimate) {
- remote_estimate_ = remote_estimate;
- }
- virtual int bandwidth() const { return bandwidth_; }
- virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
- virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
- virtual void AddCrypto(const CryptoParams& params) {
- cryptos_.push_back(params);
- }
- virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
- cryptos_ = cryptos;
- }
- virtual const RtpHeaderExtensions& rtp_header_extensions() const {
- return rtp_header_extensions_;
- }
- virtual void set_rtp_header_extensions(
- const RtpHeaderExtensions& extensions) {
- rtp_header_extensions_ = extensions;
- rtp_header_extensions_set_ = true;
- }
- virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
- rtp_header_extensions_.push_back(ext);
- rtp_header_extensions_set_ = true;
- }
- virtual void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
- webrtc::RtpExtension webrtc_extension;
- webrtc_extension.uri = ext.uri;
- webrtc_extension.id = ext.id;
- rtp_header_extensions_.push_back(webrtc_extension);
- rtp_header_extensions_set_ = true;
- }
- virtual void ClearRtpHeaderExtensions() {
- rtp_header_extensions_.clear();
- rtp_header_extensions_set_ = true;
- }
-
-
-
-
-
- virtual bool rtp_header_extensions_set() const {
- return rtp_header_extensions_set_;
- }
- virtual const StreamParamsVec& streams() const { return send_streams_; }
-
-
- virtual StreamParamsVec& mutable_streams() { return send_streams_; }
- virtual void AddStream(const StreamParams& stream) {
- send_streams_.push_back(stream);
- }
-
- void AddLegacyStream(uint32_t ssrc) {
- AddStream(StreamParams::CreateLegacy(ssrc));
- }
- void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
- StreamParams sp = StreamParams::CreateLegacy(ssrc);
- sp.AddFidSsrc(ssrc, fid_ssrc);
- AddStream(sp);
- }
-
- virtual void SetCnameIfEmpty(const std::string& cname) {
- for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
- it != send_streams_.end(); ++it) {
- if (it->cname.empty())
- it->cname = cname;
- }
- }
- virtual uint32_t first_ssrc() const {
- if (send_streams_.empty()) {
- return 0;
- }
- return send_streams_[0].first_ssrc();
- }
- virtual bool has_ssrcs() const {
- if (send_streams_.empty()) {
- return false;
- }
- return send_streams_[0].has_ssrcs();
- }
- virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
- virtual bool conference_mode() const { return conference_mode_; }
-
-
-
- virtual void set_connection_address(const rtc::SocketAddress& address) {
- connection_address_ = address;
- }
- virtual const rtc::SocketAddress& connection_address() const {
- return connection_address_;
- }
-
-
- enum ExtmapAllowMixed { kNo, kSession, kMedia };
- virtual void set_extmap_allow_mixed_enum(
- ExtmapAllowMixed new_extmap_allow_mixed) {
- if (new_extmap_allow_mixed == kMedia &&
- extmap_allow_mixed_enum_ == kSession) {
-
- return;
- }
- extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
- }
- virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
- return extmap_allow_mixed_enum_;
- }
- virtual bool extmap_allow_mixed() const {
- return extmap_allow_mixed_enum_ != kNo;
- }
-
- virtual bool HasSimulcast() const { return !simulcast_.empty(); }
- virtual SimulcastDescription& simulcast_description() { return simulcast_; }
- virtual const SimulcastDescription& simulcast_description() const {
- return simulcast_;
- }
- virtual void set_simulcast_description(
- const SimulcastDescription& simulcast) {
- simulcast_ = simulcast;
- }
- virtual const std::vector<RidDescription>& receive_rids() const {
- return receive_rids_;
- }
- virtual void set_receive_rids(const std::vector<RidDescription>& rids) {
- receive_rids_ = rids;
- }
- virtual const absl::optional<std::string>& alt_protocol() const {
- return alt_protocol_;
- }
- virtual void set_alt_protocol(const absl::optional<std::string>& protocol) {
- alt_protocol_ = protocol;
- }
- protected:
- bool rtcp_mux_ = false;
- bool rtcp_reduced_size_ = false;
- bool remote_estimate_ = false;
- int bandwidth_ = kAutoBandwidth;
- std::string protocol_;
- std::vector<CryptoParams> cryptos_;
- std::vector<webrtc::RtpExtension> rtp_header_extensions_;
- bool rtp_header_extensions_set_ = false;
- StreamParamsVec send_streams_;
- bool conference_mode_ = false;
- webrtc::RtpTransceiverDirection direction_ =
- webrtc::RtpTransceiverDirection::kSendRecv;
- rtc::SocketAddress connection_address_;
-
-
-
- ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
- SimulcastDescription simulcast_;
- std::vector<RidDescription> receive_rids_;
- absl::optional<std::string> alt_protocol_;
- private:
-
-
-
- virtual MediaContentDescription* CloneInternal() const = 0;
- };
- template <class C>
- class MediaContentDescriptionImpl : public MediaContentDescription {
- public:
- void set_protocol(const std::string& protocol) override {
- RTC_DCHECK(IsRtpProtocol(protocol));
- protocol_ = protocol;
- }
- typedef C CodecType;
-
- virtual const std::vector<C>& codecs() const { return codecs_; }
- virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
- bool has_codecs() const override { return !codecs_.empty(); }
- virtual bool HasCodec(int id) {
- bool found = false;
- for (typename std::vector<C>::iterator iter = codecs_.begin();
- iter != codecs_.end(); ++iter) {
- if (iter->id == id) {
- found = true;
- break;
- }
- }
- return found;
- }
- virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
- virtual void AddOrReplaceCodec(const C& codec) {
- for (typename std::vector<C>::iterator iter = codecs_.begin();
- iter != codecs_.end(); ++iter) {
- if (iter->id == codec.id) {
- *iter = codec;
- return;
- }
- }
- AddCodec(codec);
- }
- virtual void AddCodecs(const std::vector<C>& codecs) {
- typename std::vector<C>::const_iterator codec;
- for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
- AddCodec(*codec);
- }
- }
- private:
- std::vector<C> codecs_;
- };
- class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
- public:
- AudioContentDescription() {}
- virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
- virtual AudioContentDescription* as_audio() { return this; }
- virtual const AudioContentDescription* as_audio() const { return this; }
- private:
- virtual AudioContentDescription* CloneInternal() const {
- return new AudioContentDescription(*this);
- }
- };
- class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
- public:
- virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
- virtual VideoContentDescription* as_video() { return this; }
- virtual const VideoContentDescription* as_video() const { return this; }
- private:
- virtual VideoContentDescription* CloneInternal() const {
- return new VideoContentDescription(*this);
- }
- };
- class RtpDataContentDescription
- : public MediaContentDescriptionImpl<RtpDataCodec> {
- public:
- RtpDataContentDescription() {}
- MediaType type() const override { return MEDIA_TYPE_DATA; }
- RtpDataContentDescription* as_rtp_data() override { return this; }
- const RtpDataContentDescription* as_rtp_data() const override { return this; }
- private:
- RtpDataContentDescription* CloneInternal() const override {
- return new RtpDataContentDescription(*this);
- }
- };
- class SctpDataContentDescription : public MediaContentDescription {
- public:
- SctpDataContentDescription() {}
- SctpDataContentDescription(const SctpDataContentDescription& o)
- : MediaContentDescription(o),
- use_sctpmap_(o.use_sctpmap_),
- port_(o.port_),
- max_message_size_(o.max_message_size_) {}
- MediaType type() const override { return MEDIA_TYPE_DATA; }
- SctpDataContentDescription* as_sctp() override { return this; }
- const SctpDataContentDescription* as_sctp() const override { return this; }
- bool has_codecs() const override { return false; }
- void set_protocol(const std::string& protocol) override {
- RTC_DCHECK(IsSctpProtocol(protocol));
- protocol_ = protocol;
- }
- bool use_sctpmap() const { return use_sctpmap_; }
- void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
- int port() const { return port_; }
- void set_port(int port) { port_ = port; }
- int max_message_size() const { return max_message_size_; }
- void set_max_message_size(int max_message_size) {
- max_message_size_ = max_message_size;
- }
- private:
- SctpDataContentDescription* CloneInternal() const override {
- return new SctpDataContentDescription(*this);
- }
- bool use_sctpmap_ = true;
-
- int port_ = 5000;
-
- int max_message_size_ = 64 * 1024;
- };
- enum class MediaProtocolType {
- kRtp,
-
- kSctp
-
- };
- class RTC_EXPORT ContentInfo {
- public:
- explicit ContentInfo(MediaProtocolType type) : type(type) {}
- ~ContentInfo();
-
- ContentInfo(const ContentInfo& o);
- ContentInfo& operator=(const ContentInfo& o);
- ContentInfo(ContentInfo&& o) = default;
- ContentInfo& operator=(ContentInfo&& o) = default;
-
- std::string mid() const { return name; }
- void set_mid(const std::string& mid) { this->name = mid; }
-
- MediaContentDescription* media_description();
- const MediaContentDescription* media_description() const;
- void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
- description_ = std::move(desc);
- }
-
- std::string name;
- MediaProtocolType type;
- bool rejected = false;
- bool bundle_only = false;
- private:
- friend class SessionDescription;
- std::unique_ptr<MediaContentDescription> description_;
- };
- typedef std::vector<std::string> ContentNames;
- class ContentGroup {
- public:
- explicit ContentGroup(const std::string& semantics);
- ContentGroup(const ContentGroup&);
- ContentGroup(ContentGroup&&);
- ContentGroup& operator=(const ContentGroup&);
- ContentGroup& operator=(ContentGroup&&);
- ~ContentGroup();
- const std::string& semantics() const { return semantics_; }
- const ContentNames& content_names() const { return content_names_; }
- const std::string* FirstContentName() const;
- bool HasContentName(const std::string& content_name) const;
- void AddContentName(const std::string& content_name);
- bool RemoveContentName(const std::string& content_name);
- private:
- std::string semantics_;
- ContentNames content_names_;
- };
- typedef std::vector<ContentInfo> ContentInfos;
- typedef std::vector<ContentGroup> ContentGroups;
- const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
- const std::string& name);
- const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
- const std::string& type);
- enum MsidSignaling {
-
- kMsidSignalingMediaSection = 0x1,
-
- kMsidSignalingSsrcAttribute = 0x2
- };
- class SessionDescription {
- public:
- SessionDescription();
- ~SessionDescription();
- std::unique_ptr<SessionDescription> Clone() const;
-
- const ContentInfos& contents() const { return contents_; }
- ContentInfos& contents() { return contents_; }
- const ContentInfo* GetContentByName(const std::string& name) const;
- ContentInfo* GetContentByName(const std::string& name);
- const MediaContentDescription* GetContentDescriptionByName(
- const std::string& name) const;
- MediaContentDescription* GetContentDescriptionByName(const std::string& name);
- const ContentInfo* FirstContentByType(MediaProtocolType type) const;
- const ContentInfo* FirstContent() const;
-
-
- void AddContent(const std::string& name,
- MediaProtocolType type,
- std::unique_ptr<MediaContentDescription> description);
- void AddContent(const std::string& name,
- MediaProtocolType type,
- bool rejected,
- std::unique_ptr<MediaContentDescription> description);
- void AddContent(const std::string& name,
- MediaProtocolType type,
- bool rejected,
- bool bundle_only,
- std::unique_ptr<MediaContentDescription> description);
- void AddContent(ContentInfo&& content);
- bool RemoveContentByName(const std::string& name);
-
- const TransportInfos& transport_infos() const { return transport_infos_; }
- TransportInfos& transport_infos() { return transport_infos_; }
- const TransportInfo* GetTransportInfoByName(const std::string& name) const;
- TransportInfo* GetTransportInfoByName(const std::string& name);
- const TransportDescription* GetTransportDescriptionByName(
- const std::string& name) const {
- const TransportInfo* tinfo = GetTransportInfoByName(name);
- return tinfo ? &tinfo->description : NULL;
- }
-
- void set_transport_infos(const TransportInfos& transport_infos) {
- transport_infos_ = transport_infos;
- }
-
- void AddTransportInfo(const TransportInfo& transport_info);
- bool RemoveTransportInfoByName(const std::string& name);
-
- const ContentGroups& groups() const { return content_groups_; }
- const ContentGroup* GetGroupByName(const std::string& name) const;
- bool HasGroup(const std::string& name) const;
-
- void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
-
- void RemoveGroupByName(const std::string& name);
-
- void set_msid_supported(bool supported) { msid_supported_ = supported; }
- bool msid_supported() const { return msid_supported_; }
-
-
- void set_msid_signaling(int msid_signaling) {
- msid_signaling_ = msid_signaling;
- }
- int msid_signaling() const { return msid_signaling_; }
-
-
- void set_extmap_allow_mixed(bool supported) {
- extmap_allow_mixed_ = supported;
- MediaContentDescription::ExtmapAllowMixed media_level_setting =
- supported ? MediaContentDescription::kSession
- : MediaContentDescription::kNo;
- for (auto& content : contents_) {
-
- if (supported || content.media_description()->extmap_allow_mixed_enum() !=
- MediaContentDescription::kMedia) {
- content.media_description()->set_extmap_allow_mixed_enum(
- media_level_setting);
- }
- }
- }
- bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
- private:
- SessionDescription(const SessionDescription&);
- ContentInfos contents_;
- TransportInfos transport_infos_;
- ContentGroups content_groups_;
- bool msid_supported_ = true;
-
-
- int msid_signaling_ = kMsidSignalingSsrcAttribute;
-
-
-
-
-
- bool extmap_allow_mixed_ = false;
- };
- enum ContentSource { CS_LOCAL, CS_REMOTE };
- }
- #endif
|