2021-05-31 05:42:20 +00:00
|
|
|
//
|
2021-07-08 06:30:47 +00:00
|
|
|
// Copyright (c) 2013-2021 The SRS Authors
|
2021-05-31 05:42:20 +00:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
2020-03-30 07:16:29 +00:00
|
|
|
|
2020-05-11 04:07:55 +00:00
|
|
|
#ifndef SRS_APP_RTC_SDP_HPP
|
|
|
|
#define SRS_APP_RTC_SDP_HPP
|
2020-03-30 07:16:29 +00:00
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
#include <srs_kernel_utility.hpp>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2020-05-19 10:12:58 +00:00
|
|
|
#include <map>
|
|
|
|
const std::string kTWCCExt = "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01";
|
2020-03-30 07:16:29 +00:00
|
|
|
|
2020-07-15 05:11:35 +00:00
|
|
|
// TDOO: FIXME: Rename it, and add utest.
|
|
|
|
extern std::vector<std::string> split_str(const std::string& str, const std::string& delim);
|
|
|
|
|
2021-03-08 04:39:25 +00:00
|
|
|
class SrsSessionConfig
|
2020-06-27 03:13:53 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string dtls_role;
|
|
|
|
std::string dtls_version;
|
|
|
|
};
|
|
|
|
|
2020-03-30 07:16:29 +00:00
|
|
|
class SrsSessionInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsSessionInfo();
|
2020-03-30 13:21:31 +00:00
|
|
|
virtual ~SrsSessionInfo();
|
2020-03-30 07:16:29 +00:00
|
|
|
|
|
|
|
srs_error_t parse_attribute(const std::string& attribute, const std::string& value);
|
|
|
|
srs_error_t encode(std::ostringstream& os);
|
|
|
|
|
2021-08-14 06:45:12 +00:00
|
|
|
bool operator==(const SrsSessionInfo& rhs);
|
|
|
|
// user-defined copy assignment (copy-and-swap idiom)
|
|
|
|
SrsSessionInfo& operator=(SrsSessionInfo other);
|
2020-03-30 07:16:29 +00:00
|
|
|
public:
|
|
|
|
std::string ice_ufrag_;
|
|
|
|
std::string ice_pwd_;
|
|
|
|
std::string ice_options_;
|
|
|
|
std::string fingerprint_algo_;
|
|
|
|
std::string fingerprint_;
|
|
|
|
std::string setup_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SrsSSRCInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsSSRCInfo();
|
2020-07-15 05:11:35 +00:00
|
|
|
SrsSSRCInfo(uint32_t ssrc, std::string cname, std::string stream_id, std::string track_id);
|
2020-03-30 07:16:29 +00:00
|
|
|
virtual ~SrsSSRCInfo();
|
|
|
|
public:
|
|
|
|
srs_error_t encode(std::ostringstream& os);
|
|
|
|
public:
|
|
|
|
uint32_t ssrc_;
|
|
|
|
std::string cname_;
|
2021-06-21 23:49:48 +00:00
|
|
|
// See https://webrtchacks.com/sdp-anatomy/
|
|
|
|
// a=ssrc:2231627014 msid:lgsCFqt9kN2fVKw5wg3NKqGdATQoltEwOdMS daed9400-d0dd-4db3-b949-422499e96e2d
|
|
|
|
// a=ssrc:2231627014 msid:{msid_} {msid_tracker_}
|
2020-03-30 07:16:29 +00:00
|
|
|
std::string msid_;
|
|
|
|
std::string msid_tracker_;
|
|
|
|
std::string mslabel_;
|
|
|
|
std::string label_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SrsSSRCGroup
|
|
|
|
{
|
2020-06-27 09:06:33 +00:00
|
|
|
public:
|
|
|
|
SrsSSRCGroup();
|
|
|
|
SrsSSRCGroup(const std::string& usage, const std::vector<uint32_t>& ssrcs);
|
|
|
|
virtual ~SrsSSRCGroup();
|
|
|
|
public:
|
|
|
|
srs_error_t encode(std::ostringstream& os);
|
|
|
|
public:
|
|
|
|
// e.g FIX, FEC, SIM.
|
|
|
|
std::string semantic_;
|
|
|
|
// SSRCs of this type.
|
|
|
|
std::vector<uint32_t> ssrcs_;
|
2020-03-30 07:16:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct H264SpecificParam
|
|
|
|
{
|
2020-04-08 15:24:59 +00:00
|
|
|
std::string profile_level_id;
|
|
|
|
std::string packetization_mode;
|
|
|
|
std::string level_asymmerty_allow;
|
2020-03-30 07:16:29 +00:00
|
|
|
};
|
|
|
|
|
2020-05-17 11:40:45 +00:00
|
|
|
extern srs_error_t srs_parse_h264_fmtp(const std::string& fmtp, H264SpecificParam& h264_param);
|
2020-03-30 07:16:29 +00:00
|
|
|
|
|
|
|
class SrsMediaPayloadType
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsMediaPayloadType(int payload_type);
|
2020-03-30 13:21:31 +00:00
|
|
|
virtual ~SrsMediaPayloadType();
|
2020-03-30 07:16:29 +00:00
|
|
|
|
|
|
|
srs_error_t encode(std::ostringstream& os);
|
|
|
|
public:
|
|
|
|
int payload_type_;
|
|
|
|
|
|
|
|
std::string encoding_name_;
|
|
|
|
int clock_rate_;
|
|
|
|
std::string encoding_param_;
|
|
|
|
|
|
|
|
std::vector<std::string> rtcp_fb_;
|
|
|
|
std::string format_specific_param_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SrsCandidate
|
|
|
|
{
|
|
|
|
std::string ip_;
|
|
|
|
int port_;
|
|
|
|
std::string type_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SrsMediaDesc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsMediaDesc(const std::string& type);
|
2020-03-30 13:21:31 +00:00
|
|
|
virtual ~SrsMediaDesc();
|
2020-03-30 07:16:29 +00:00
|
|
|
public:
|
|
|
|
srs_error_t parse_line(const std::string& line);
|
|
|
|
srs_error_t encode(std::ostringstream& os);
|
|
|
|
SrsMediaPayloadType* find_media_with_payload_type(int payload_type);
|
|
|
|
std::vector<SrsMediaPayloadType> find_media_with_encoding_name(const std::string& encoding_name) const;
|
2020-05-19 10:12:58 +00:00
|
|
|
const std::map<int, std::string>& get_extmaps() const { return extmaps_; }
|
2020-09-15 04:31:36 +00:00
|
|
|
srs_error_t update_msid(std::string id);
|
2020-03-30 07:16:29 +00:00
|
|
|
|
|
|
|
bool is_audio() const { return type_ == "audio"; }
|
|
|
|
bool is_video() const { return type_ == "video"; }
|
|
|
|
private:
|
|
|
|
srs_error_t parse_attribute(const std::string& content);
|
|
|
|
srs_error_t parse_attr_rtpmap(const std::string& value);
|
2020-04-01 06:38:00 +00:00
|
|
|
srs_error_t parse_attr_rtcp(const std::string& value);
|
2020-03-30 07:16:29 +00:00
|
|
|
srs_error_t parse_attr_rtcp_fb(const std::string& value);
|
|
|
|
srs_error_t parse_attr_fmtp(const std::string& value);
|
|
|
|
srs_error_t parse_attr_mid(const std::string& value);
|
|
|
|
srs_error_t parse_attr_msid(const std::string& value);
|
|
|
|
srs_error_t parse_attr_ssrc(const std::string& value);
|
|
|
|
srs_error_t parse_attr_ssrc_group(const std::string& value);
|
2020-05-19 10:12:58 +00:00
|
|
|
srs_error_t parse_attr_extmap(const std::string& value);
|
2020-03-30 07:16:29 +00:00
|
|
|
private:
|
|
|
|
SrsSSRCInfo& fetch_or_create_ssrc_info(uint32_t ssrc);
|
|
|
|
|
|
|
|
public:
|
|
|
|
SrsSessionInfo session_info_;
|
|
|
|
std::string type_;
|
|
|
|
int port_;
|
|
|
|
|
|
|
|
bool rtcp_mux_;
|
2020-04-01 06:38:00 +00:00
|
|
|
bool rtcp_rsize_;
|
2020-03-30 07:16:29 +00:00
|
|
|
|
|
|
|
bool sendonly_;
|
|
|
|
bool recvonly_;
|
|
|
|
bool sendrecv_;
|
|
|
|
bool inactive_;
|
|
|
|
|
|
|
|
std::string mid_;
|
|
|
|
std::string msid_;
|
|
|
|
std::string msid_tracker_;
|
|
|
|
std::string protos_;
|
|
|
|
std::vector<SrsMediaPayloadType> payload_types_;
|
|
|
|
|
|
|
|
std::vector<SrsCandidate> candidates_;
|
|
|
|
std::vector<SrsSSRCGroup> ssrc_groups_;
|
|
|
|
std::vector<SrsSSRCInfo> ssrc_infos_;
|
2020-05-19 10:12:58 +00:00
|
|
|
std::map<int, std::string> extmaps_;
|
2020-03-30 07:16:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SrsSdp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsSdp();
|
2020-03-30 13:21:31 +00:00
|
|
|
virtual ~SrsSdp();
|
2020-03-30 07:16:29 +00:00
|
|
|
public:
|
|
|
|
srs_error_t parse(const std::string& sdp_str);
|
|
|
|
srs_error_t encode(std::ostringstream& os);
|
|
|
|
public:
|
2020-09-16 11:41:34 +00:00
|
|
|
std::vector<SrsMediaDesc*> find_media_descs(const std::string& type);
|
2020-03-30 07:16:29 +00:00
|
|
|
public:
|
|
|
|
void set_ice_ufrag(const std::string& ufrag);
|
|
|
|
void set_ice_pwd(const std::string& pwd);
|
2020-07-15 05:11:35 +00:00
|
|
|
void set_dtls_role(const std::string& dtls_role);
|
2020-03-30 07:16:29 +00:00
|
|
|
void set_fingerprint_algo(const std::string& algo);
|
|
|
|
void set_fingerprint(const std::string& fingerprint);
|
|
|
|
void add_candidate(const std::string& ip, const int& port, const std::string& type);
|
|
|
|
|
|
|
|
std::string get_ice_ufrag() const;
|
|
|
|
std::string get_ice_pwd() const;
|
2020-07-15 05:11:35 +00:00
|
|
|
std::string get_dtls_role() const;
|
2020-03-30 07:16:29 +00:00
|
|
|
private:
|
|
|
|
srs_error_t parse_line(const std::string& line);
|
|
|
|
private:
|
|
|
|
srs_error_t parse_origin(const std::string& content);
|
|
|
|
srs_error_t parse_version(const std::string& content);
|
|
|
|
srs_error_t parse_session_name(const std::string& content);
|
|
|
|
srs_error_t parse_timing(const std::string& content);
|
|
|
|
srs_error_t parse_attribute(const std::string& content);
|
|
|
|
srs_error_t parse_media_description(const std::string& content);
|
|
|
|
srs_error_t parse_attr_group(const std::string& content);
|
|
|
|
private:
|
|
|
|
bool in_media_session_;
|
|
|
|
public:
|
|
|
|
// version
|
|
|
|
std::string version_;
|
|
|
|
|
|
|
|
// origin
|
|
|
|
std::string username_;
|
|
|
|
std::string session_id_;
|
|
|
|
std::string session_version_;
|
|
|
|
std::string nettype_;
|
|
|
|
std::string addrtype_;
|
|
|
|
std::string unicast_address_;
|
|
|
|
|
|
|
|
// session_name
|
|
|
|
std::string session_name_;
|
|
|
|
|
|
|
|
// timing
|
|
|
|
int64_t start_time_;
|
|
|
|
int64_t end_time_;
|
|
|
|
|
|
|
|
SrsSessionInfo session_info_;
|
2020-06-27 03:13:53 +00:00
|
|
|
SrsSessionConfig session_config_;
|
2021-03-08 04:39:25 +00:00
|
|
|
SrsSessionConfig session_negotiate_;
|
2020-03-30 07:16:29 +00:00
|
|
|
|
|
|
|
std::vector<std::string> groups_;
|
|
|
|
std::string group_policy_;
|
|
|
|
|
|
|
|
std::string msid_semantic_;
|
|
|
|
std::vector<std::string> msids_;
|
|
|
|
|
|
|
|
// m-line, media sessions
|
|
|
|
std::vector<SrsMediaDesc> media_descs_;
|
2020-08-21 10:08:54 +00:00
|
|
|
|
|
|
|
bool is_unified() const;
|
2020-09-15 04:31:36 +00:00
|
|
|
// TODO: FIXME: will be fixed when use single pc.
|
|
|
|
srs_error_t update_msid(std::string id);
|
2020-03-30 07:16:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|