mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-07 12:18:12 +08:00
整理命名空间 (#1409)
* feat: remove using namespace mediakit in header files. (cherry picked from commit d44aeb339a8a0e1f0455be82b21fe4b1b536299f) * feat: remove using namespace mediakit in FFmpegSource.h * feat: remove using namespace mediakit in RtpExt.h * feat: remove using namespace mediakit in header files. * feat: remove using namespace std in header files. * feat: remove using namespace std in header files when zltoolkit remove std in header * 补充命名空间 * 整理命名空间 * 整理命名空间2 * 修复macos ci * 修复编译问题 * 修复编译问题2 * 修复编译问题3 Co-authored-by: Johnny <hellojinqiang@gmail.com> Co-authored-by: Xiaofeng Wang <wasphin@gmail.com>
This commit is contained in:
@@ -30,6 +30,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#include <cstring> // std::memcpy(), std::strcmp()
|
||||
#include "Util/util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define LOG_OPENSSL_ERROR(desc) \
|
||||
do \
|
||||
{ \
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
|
||||
#include "Nack.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
using namespace mediakit;
|
||||
|
||||
static constexpr uint32_t kMaxNackMS = 10 * 1000;
|
||||
|
||||
void NackList::push_back(RtpPacket::Ptr rtp) {
|
||||
|
||||
@@ -14,30 +14,29 @@
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Rtcp/RtcpFCI.h"
|
||||
|
||||
using namespace mediakit;
|
||||
|
||||
class NackList {
|
||||
public:
|
||||
NackList() = default;
|
||||
~NackList() = default;
|
||||
|
||||
void push_back(RtpPacket::Ptr rtp);
|
||||
void for_each_nack(const FCI_NACK &nack, const function<void(const RtpPacket::Ptr &rtp)> &cb);
|
||||
void push_back(mediakit::RtpPacket::Ptr rtp);
|
||||
void for_each_nack(const mediakit::FCI_NACK &nack, const std::function<void(const mediakit::RtpPacket::Ptr &rtp)> &cb);
|
||||
|
||||
private:
|
||||
void pop_front();
|
||||
uint32_t get_cache_ms();
|
||||
RtpPacket::Ptr *get_rtp(uint16_t seq);
|
||||
mediakit::RtpPacket::Ptr *get_rtp(uint16_t seq);
|
||||
|
||||
private:
|
||||
deque<uint16_t> _nack_cache_seq;
|
||||
unordered_map<uint16_t, RtpPacket::Ptr> _nack_cache_pkt;
|
||||
std::deque<uint16_t> _nack_cache_seq;
|
||||
std::unordered_map<uint16_t, mediakit::RtpPacket::Ptr> _nack_cache_pkt;
|
||||
};
|
||||
|
||||
class NackContext {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<NackContext>;
|
||||
using onNack = function<void(const FCI_NACK &nack)>;
|
||||
using onNack = std::function<void(const mediakit::FCI_NACK &nack)>;
|
||||
//最大保留的rtp丢包状态个数
|
||||
static constexpr auto kNackMaxSize = 1024;
|
||||
//rtp丢包状态最长保留时间
|
||||
@@ -56,14 +55,14 @@ public:
|
||||
|
||||
private:
|
||||
void eraseFrontSeq();
|
||||
void doNack(const FCI_NACK &nack, bool record_nack);
|
||||
void recordNack(const FCI_NACK &nack);
|
||||
void doNack(const mediakit::FCI_NACK &nack, bool record_nack);
|
||||
void recordNack(const mediakit::FCI_NACK &nack);
|
||||
void onRtx(uint16_t seq);
|
||||
|
||||
private:
|
||||
int _rtt = 50;
|
||||
onNack _cb;
|
||||
set<uint16_t> _seq;
|
||||
std::set<uint16_t> _seq;
|
||||
uint16_t _last_max_seq = 0;
|
||||
|
||||
struct NackStatus{
|
||||
@@ -71,7 +70,7 @@ private:
|
||||
uint64_t update_stamp;
|
||||
int nack_count = 0;
|
||||
};
|
||||
map<uint16_t/*seq*/, NackStatus > _nack_send_status;
|
||||
std::map<uint16_t/*seq*/, NackStatus > _nack_send_status;
|
||||
};
|
||||
|
||||
#endif //ZLMEDIAKIT_NACK_H
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
#pragma pack(push, 1)
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
using namespace mediakit;
|
||||
|
||||
//https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
|
||||
//https://tools.ietf.org/html/rfc5285
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
#include "Common/macros.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace mediakit;
|
||||
|
||||
#define RTP_EXT_MAP(XX) \
|
||||
XX(ssrc_audio_level, "urn:ietf:params:rtp-hdrext:ssrc-audio-level") \
|
||||
@@ -51,25 +49,25 @@ class RtcMedia;
|
||||
class RtpExt {
|
||||
public:
|
||||
template<typename Type>
|
||||
friend void appendExt(map<uint8_t, RtpExt> &ret, uint8_t *ptr, const uint8_t *end);
|
||||
friend void appendExt(std::map<uint8_t, RtpExt> &ret, uint8_t *ptr, const uint8_t *end);
|
||||
friend class RtpExtContext;
|
||||
~RtpExt() = default;
|
||||
|
||||
static map<uint8_t/*id*/, RtpExt/*data*/> getExtValue(const RtpHeader *header);
|
||||
static RtpExtType getExtType(const string &url);
|
||||
static const string& getExtUrl(RtpExtType type);
|
||||
static std::map<uint8_t/*id*/, RtpExt/*data*/> getExtValue(const mediakit::RtpHeader *header);
|
||||
static RtpExtType getExtType(const std::string &url);
|
||||
static const std::string& getExtUrl(RtpExtType type);
|
||||
static const char *getExtName(RtpExtType type);
|
||||
|
||||
void setType(RtpExtType type);
|
||||
RtpExtType getType() const;
|
||||
string dumpString() const;
|
||||
std::string dumpString() const;
|
||||
|
||||
uint8_t getAudioLevel(bool *vad) const;
|
||||
uint32_t getAbsSendTime() const;
|
||||
uint16_t getTransportCCSeq() const;
|
||||
string getSdesMid() const;
|
||||
string getRtpStreamId() const;
|
||||
string getRepairedRtpStreamId() const;
|
||||
std::string getSdesMid() const;
|
||||
std::string getRtpStreamId() const;
|
||||
std::string getRepairedRtpStreamId() const;
|
||||
|
||||
void getVideoTiming(uint8_t &flags,
|
||||
uint16_t &encode_start,
|
||||
@@ -116,27 +114,27 @@ class RtcMedia;
|
||||
class RtpExtContext {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<RtpExtContext>;
|
||||
using OnGetRtp = function<void(uint8_t pt, uint32_t ssrc, const string &rid)>;
|
||||
using OnGetRtp = std::function<void(uint8_t pt, uint32_t ssrc, const std::string &rid)>;
|
||||
|
||||
RtpExtContext(const RtcMedia &media);
|
||||
~RtpExtContext() = default;
|
||||
|
||||
void setOnGetRtp(OnGetRtp cb);
|
||||
string getRid(uint32_t ssrc) const;
|
||||
void setRid(uint32_t ssrc, const string &rid);
|
||||
RtpExt changeRtpExtId(const RtpHeader *header, bool is_recv, string *rid_ptr = nullptr, RtpExtType type = RtpExtType::padding);
|
||||
std::string getRid(uint32_t ssrc) const;
|
||||
void setRid(uint32_t ssrc, const std::string &rid);
|
||||
RtpExt changeRtpExtId(const mediakit::RtpHeader *header, bool is_recv, std::string *rid_ptr = nullptr, RtpExtType type = RtpExtType::padding);
|
||||
|
||||
private:
|
||||
void onGetRtp(uint8_t pt, uint32_t ssrc, const string &rid);
|
||||
void onGetRtp(uint8_t pt, uint32_t ssrc, const std::string &rid);
|
||||
|
||||
private:
|
||||
OnGetRtp _cb;
|
||||
//发送rtp时需要修改rtp ext id
|
||||
map<RtpExtType, uint8_t> _rtp_ext_type_to_id;
|
||||
std::map<RtpExtType, uint8_t> _rtp_ext_type_to_id;
|
||||
//接收rtp时需要修改rtp ext id
|
||||
unordered_map<uint8_t, RtpExtType> _rtp_ext_id_to_type;
|
||||
std::unordered_map<uint8_t, RtpExtType> _rtp_ext_id_to_type;
|
||||
//ssrc --> rid
|
||||
unordered_map<uint32_t/*simulcast ssrc*/, string/*rid*/> _ssrc_to_rid;
|
||||
std::unordered_map<uint32_t/*simulcast ssrc*/, std::string/*rid*/> _ssrc_to_rid;
|
||||
};
|
||||
|
||||
#endif //ZLMEDIAKIT_RTPEXT_H
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
#include "Sdp.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include <cinttypes>
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
using namespace mediakit;
|
||||
|
||||
namespace RTC {
|
||||
|
||||
328
webrtc/Sdp.h
328
webrtc/Sdp.h
@@ -17,8 +17,6 @@
|
||||
#include "assert.h"
|
||||
#include "Extension/Frame.h"
|
||||
#include "Common/Parser.h"
|
||||
using namespace std;
|
||||
using namespace mediakit;
|
||||
|
||||
//https://datatracker.ietf.org/doc/rfc4566/?include_text=1
|
||||
//https://blog.csdn.net/aggresss/article/details/109850434
|
||||
@@ -81,19 +79,19 @@ enum class SdpType {
|
||||
answer
|
||||
};
|
||||
|
||||
DtlsRole getDtlsRole(const string &str);
|
||||
DtlsRole getDtlsRole(const std::string &str);
|
||||
const char* getDtlsRoleString(DtlsRole role);
|
||||
RtpDirection getRtpDirection(const string &str);
|
||||
RtpDirection getRtpDirection(const std::string &str);
|
||||
const char* getRtpDirectionString(RtpDirection val);
|
||||
|
||||
class SdpItem {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<SdpItem>;
|
||||
virtual ~SdpItem() = default;
|
||||
virtual void parse(const string &str) {
|
||||
virtual void parse(const std::string &str) {
|
||||
value = str;
|
||||
}
|
||||
virtual string toString() const {
|
||||
virtual std::string toString() const {
|
||||
return value;
|
||||
}
|
||||
virtual const char* getKey() const = 0;
|
||||
@@ -103,23 +101,23 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
mutable string value;
|
||||
mutable std::string value;
|
||||
};
|
||||
|
||||
template <char KEY>
|
||||
class SdpString : public SdpItem{
|
||||
public:
|
||||
SdpString() = default;
|
||||
SdpString(string val) {value = std::move(val);}
|
||||
SdpString(std::string val) {value = std::move(val);}
|
||||
// *=*
|
||||
const char* getKey() const override { static string key(1, KEY); return key.data();}
|
||||
const char* getKey() const override { static std::string key(1, KEY); return key.data();}
|
||||
};
|
||||
|
||||
class SdpCommon : public SdpItem {
|
||||
public:
|
||||
string key;
|
||||
SdpCommon(string key) { this->key = std::move(key); }
|
||||
SdpCommon(string key, string val) {
|
||||
std::string key;
|
||||
SdpCommon(std::string key) { this->key = std::move(key); }
|
||||
SdpCommon(std::string key, std::string val) {
|
||||
this->key = std::move(key);
|
||||
this->value = std::move(val);
|
||||
}
|
||||
@@ -133,8 +131,8 @@ public:
|
||||
// t=<start-time> <stop-time>
|
||||
uint64_t start {0};
|
||||
uint64_t stop {0};
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "t";}
|
||||
};
|
||||
|
||||
@@ -143,14 +141,14 @@ public:
|
||||
// 5.2. Origin ("o=")
|
||||
// o=jdoe 2890844526 2890842807 IN IP4 10.47.16.5
|
||||
// o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
|
||||
string username {"-"};
|
||||
string session_id;
|
||||
string session_version;
|
||||
string nettype {"IN"};
|
||||
string addrtype {"IP4"};
|
||||
string address {"0.0.0.0"};
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
std::string username {"-"};
|
||||
std::string session_id;
|
||||
std::string session_version;
|
||||
std::string nettype {"IN"};
|
||||
std::string addrtype {"IP4"};
|
||||
std::string address {"0.0.0.0"};
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "o";}
|
||||
bool empty() const {
|
||||
return username.empty() || session_id.empty() || session_version.empty()
|
||||
@@ -163,11 +161,11 @@ public:
|
||||
// 5.7. Connection Data ("c=")
|
||||
// c=IN IP4 224.2.17.12/127
|
||||
// c=<nettype> <addrtype> <connection-address>
|
||||
string nettype {"IN"};
|
||||
string addrtype {"IP4"};
|
||||
string address {"0.0.0.0"};
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
std::string nettype {"IN"};
|
||||
std::string addrtype {"IP4"};
|
||||
std::string address {"0.0.0.0"};
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "c";}
|
||||
bool empty() const {return address.empty();}
|
||||
};
|
||||
@@ -178,11 +176,11 @@ public:
|
||||
//b=<bwtype>:<bandwidth>
|
||||
|
||||
//AS、CT
|
||||
string bwtype {"AS"};
|
||||
std::string bwtype {"AS"};
|
||||
uint32_t bandwidth {0};
|
||||
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "b";}
|
||||
bool empty() const {return bandwidth == 0;}
|
||||
};
|
||||
@@ -191,17 +189,17 @@ class SdpMedia : public SdpItem {
|
||||
public:
|
||||
// 5.14. Media Descriptions ("m=")
|
||||
// m=<media> <port> <proto> <fmt> ...
|
||||
TrackType type;
|
||||
mediakit::TrackType type;
|
||||
uint16_t port;
|
||||
//RTP/AVP:应用场景为视频/音频的 RTP 协议。参考 RFC 3551
|
||||
//RTP/SAVP:应用场景为视频/音频的 SRTP 协议。参考 RFC 3711
|
||||
//RTP/AVPF: 应用场景为视频/音频的 RTP 协议,支持 RTCP-based Feedback。参考 RFC 4585
|
||||
//RTP/SAVPF: 应用场景为视频/音频的 SRTP 协议,支持 RTCP-based Feedback。参考 RFC 5124
|
||||
string proto;
|
||||
vector<uint32_t> fmts;
|
||||
std::string proto;
|
||||
std::vector<uint32_t> fmts;
|
||||
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "m";}
|
||||
};
|
||||
|
||||
@@ -212,8 +210,8 @@ public:
|
||||
//a=<attribute>
|
||||
//a=<attribute>:<value>
|
||||
SdpItem::Ptr detail;
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "a";}
|
||||
};
|
||||
|
||||
@@ -223,10 +221,10 @@ public:
|
||||
// BUNDLE group is included at the session-level.
|
||||
//a=group:LS session level attribute MUST be included wth the 'mid'
|
||||
// identifiers that are part of the same lip sync group.
|
||||
string type {"BUNDLE"};
|
||||
vector<string> mids;
|
||||
void parse(const string &str) override ;
|
||||
string toString() const override ;
|
||||
std::string type {"BUNDLE"};
|
||||
std::vector<std::string> mids;
|
||||
void parse(const std::string &str) override ;
|
||||
std::string toString() const override ;
|
||||
const char* getKey() const override { return "group";}
|
||||
};
|
||||
|
||||
@@ -252,10 +250,10 @@ public:
|
||||
// "Semantics for the "ssrc-group" SDP Attribute" and "Semantics for the
|
||||
// "group" SDP Attribute".
|
||||
//a=msid-semantic: WMS 616cfbb1-33a3-4d8c-8275-a199d6005549
|
||||
string msid{"WMS"};
|
||||
string token;
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
std::string msid{"WMS"};
|
||||
std::string token;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "msid-semantic";}
|
||||
bool empty() const {
|
||||
return msid.empty();
|
||||
@@ -266,11 +264,11 @@ class SdpAttrRtcp : public SdpItem {
|
||||
public:
|
||||
// a=rtcp:9 IN IP4 0.0.0.0
|
||||
uint16_t port{0};
|
||||
string nettype {"IN"};
|
||||
string addrtype {"IP4"};
|
||||
string address {"0.0.0.0"};
|
||||
void parse(const string &str) override;;
|
||||
string toString() const override;
|
||||
std::string nettype {"IN"};
|
||||
std::string addrtype {"IP4"};
|
||||
std::string address {"0.0.0.0"};
|
||||
void parse(const std::string &str) override;;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "rtcp";}
|
||||
bool empty() const {
|
||||
return address.empty() || !port;
|
||||
@@ -280,7 +278,7 @@ public:
|
||||
class SdpAttrIceUfrag : public SdpItem {
|
||||
public:
|
||||
SdpAttrIceUfrag() = default;
|
||||
SdpAttrIceUfrag(string str) {value = std::move(str);}
|
||||
SdpAttrIceUfrag(std::string str) {value = std::move(str);}
|
||||
//a=ice-ufrag:sXJ3
|
||||
const char* getKey() const override { return "ice-ufrag";}
|
||||
};
|
||||
@@ -288,7 +286,7 @@ public:
|
||||
class SdpAttrIcePwd : public SdpItem {
|
||||
public:
|
||||
SdpAttrIcePwd() = default;
|
||||
SdpAttrIcePwd(string str) {value = std::move(str);}
|
||||
SdpAttrIcePwd(std::string str) {value = std::move(str);}
|
||||
//a=ice-pwd:yEclOTrLg1gEubBFefOqtmyV
|
||||
const char* getKey() const override { return "ice-pwd";}
|
||||
};
|
||||
@@ -298,18 +296,18 @@ public:
|
||||
//a=ice-options:trickle
|
||||
bool trickle{false};
|
||||
bool renomination{false};
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "ice-options";}
|
||||
};
|
||||
|
||||
class SdpAttrFingerprint : public SdpItem {
|
||||
public:
|
||||
//a=fingerprint:sha-256 22:14:B5:AF:66:12:C7:C7:8D:EF:4B:DE:40:25:ED:5D:8F:17:54:DD:88:33:C0:13:2E:FD:1A:FA:7E:7A:1B:79
|
||||
string algorithm;
|
||||
string hash;
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
std::string algorithm;
|
||||
std::string hash;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "fingerprint";}
|
||||
bool empty() const { return algorithm.empty() || hash.empty(); }
|
||||
};
|
||||
@@ -320,15 +318,15 @@ public:
|
||||
SdpAttrSetup() = default;
|
||||
SdpAttrSetup(DtlsRole r) { role = r; }
|
||||
DtlsRole role{DtlsRole::actpass};
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "setup";}
|
||||
};
|
||||
|
||||
class SdpAttrMid : public SdpItem {
|
||||
public:
|
||||
SdpAttrMid() = default;
|
||||
SdpAttrMid(string val) { value = std::move(val); }
|
||||
SdpAttrMid(std::string val) { value = std::move(val); }
|
||||
//a=mid:audio
|
||||
const char* getKey() const override { return "mid";}
|
||||
};
|
||||
@@ -339,9 +337,9 @@ public:
|
||||
//a=extmap:1[/sendonly] urn:ietf:params:rtp-hdrext:ssrc-audio-level
|
||||
uint8_t id;
|
||||
RtpDirection direction{RtpDirection::invalid};
|
||||
string ext;
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
std::string ext;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "extmap";}
|
||||
};
|
||||
|
||||
@@ -349,11 +347,11 @@ class SdpAttrRtpMap : public SdpItem {
|
||||
public:
|
||||
//a=rtpmap:111 opus/48000/2
|
||||
uint8_t pt;
|
||||
string codec;
|
||||
std::string codec;
|
||||
uint32_t sample_rate;
|
||||
uint32_t channel {0};
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "rtpmap";}
|
||||
};
|
||||
|
||||
@@ -366,9 +364,9 @@ public:
|
||||
//a=rtcp-fb:120 goog-remb 支持 REMB (Receiver Estimated Maximum Bitrate) 。
|
||||
//a=rtcp-fb:120 transport-cc 支持 TCC (Transport Congest Control) 。
|
||||
uint8_t pt;
|
||||
string rtcp_type;
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
std::string rtcp_type;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "rtcp-fb";}
|
||||
};
|
||||
|
||||
@@ -376,9 +374,9 @@ class SdpAttrFmtp : public SdpItem {
|
||||
public:
|
||||
//fmtp:96 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f
|
||||
uint8_t pt;
|
||||
map<string/*key*/, string/*value*/, StrCaseCompare> fmtp;
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
std::map<std::string/*key*/, std::string/*value*/, mediakit::StrCaseCompare> fmtp;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "fmtp";}
|
||||
};
|
||||
|
||||
@@ -399,10 +397,10 @@ public:
|
||||
//a=ssrc:3245185839 cname:Cx4i/VTR51etgjT7
|
||||
|
||||
uint32_t ssrc;
|
||||
string attribute;
|
||||
string attribute_value;
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
std::string attribute;
|
||||
std::string attribute_value;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "ssrc";}
|
||||
};
|
||||
|
||||
@@ -413,13 +411,13 @@ public:
|
||||
// FID (Flow Identification) 最初用在 FEC 的关联中,WebRTC 中通常用于关联一组常规 RTP stream 和 重传 RTP stream 。
|
||||
//a=ssrc-group:SIM 360918977 360918978 360918980
|
||||
// 在 Chrome 独有的 SDP munging 风格的 simulcast 中使用,将三组编码质量由低到高的 MediaStreamTrack 关联在一起。
|
||||
string type{"FID"};
|
||||
vector<uint32_t> ssrcs;
|
||||
std::string type{"FID"};
|
||||
std::vector<uint32_t> ssrcs;
|
||||
|
||||
bool isFID() const { return type == "FID"; }
|
||||
bool isSIM() const { return type == "SIM"; }
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "ssrc-group";}
|
||||
};
|
||||
|
||||
@@ -429,10 +427,10 @@ public:
|
||||
//a=sctpmap:5000 webrtc-datachannel 1024
|
||||
//a=sctpmap: sctpmap-number media-subtypes [streams]
|
||||
uint16_t port;
|
||||
string subtypes;
|
||||
std::string subtypes;
|
||||
uint32_t streams;
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "sctpmap";}
|
||||
};
|
||||
|
||||
@@ -443,18 +441,18 @@ public:
|
||||
//15.1. "candidate" Attribute
|
||||
//a=candidate:4 1 udp 2 192.168.1.7 58107 typ host
|
||||
//a=candidate:<foundation> <component-id> <transport> <priority> <address> <port> typ <cand-type>
|
||||
string foundation;
|
||||
std::string foundation;
|
||||
//传输媒体的类型,1代表RTP;2代表 RTCP。
|
||||
uint32_t component;
|
||||
string transport {"udp"};
|
||||
std::string transport {"udp"};
|
||||
uint32_t priority;
|
||||
string address;
|
||||
std::string address;
|
||||
uint16_t port;
|
||||
string type;
|
||||
vector<std::pair<string, string> > arr;
|
||||
std::string type;
|
||||
std::vector<std::pair<std::string, std::string> > arr;
|
||||
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "candidate";}
|
||||
};
|
||||
|
||||
@@ -473,56 +471,56 @@ public:
|
||||
//https://www.meetecho.com/blog/simulcast-janus-ssrc/
|
||||
//https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-14
|
||||
const char* getKey() const override { return "simulcast";}
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
bool empty() const { return rids.empty(); }
|
||||
string direction;
|
||||
vector<string> rids;
|
||||
std::string direction;
|
||||
std::vector<std::string> rids;
|
||||
};
|
||||
|
||||
class SdpAttrRid : public SdpItem{
|
||||
public:
|
||||
void parse(const string &str) override;
|
||||
string toString() const override;
|
||||
void parse(const std::string &str) override;
|
||||
std::string toString() const override;
|
||||
const char* getKey() const override { return "rid";}
|
||||
string direction;
|
||||
string rid;
|
||||
std::string direction;
|
||||
std::string rid;
|
||||
};
|
||||
|
||||
class RtcSdpBase {
|
||||
public:
|
||||
vector<SdpItem::Ptr> items;
|
||||
std::vector<SdpItem::Ptr> items;
|
||||
|
||||
public:
|
||||
virtual ~RtcSdpBase() = default;
|
||||
virtual string toString() const;
|
||||
virtual std::string toString() const;
|
||||
|
||||
int getVersion() const;
|
||||
SdpOrigin getOrigin() const;
|
||||
string getSessionName() const;
|
||||
string getSessionInfo() const;
|
||||
std::string getSessionName() const;
|
||||
std::string getSessionInfo() const;
|
||||
SdpTime getSessionTime() const;
|
||||
SdpConnection getConnection() const;
|
||||
SdpBandwidth getBandwidth() const;
|
||||
|
||||
string getUri() const;
|
||||
string getEmail() const;
|
||||
string getPhone() const;
|
||||
string getTimeZone() const;
|
||||
string getEncryptKey() const;
|
||||
string getRepeatTimes() const;
|
||||
std::string getUri() const;
|
||||
std::string getEmail() const;
|
||||
std::string getPhone() const;
|
||||
std::string getTimeZone() const;
|
||||
std::string getEncryptKey() const;
|
||||
std::string getRepeatTimes() const;
|
||||
RtpDirection getDirection() const;
|
||||
|
||||
template<typename cls>
|
||||
cls getItemClass(char key, const char *attr_key = nullptr) const{
|
||||
auto item = dynamic_pointer_cast<cls>(getItem(key, attr_key));
|
||||
auto item = std::dynamic_pointer_cast<cls>(getItem(key, attr_key));
|
||||
if (!item) {
|
||||
return cls();
|
||||
}
|
||||
return *item;
|
||||
}
|
||||
|
||||
string getStringItem(char key, const char *attr_key = nullptr) const{
|
||||
std::string getStringItem(char key, const char *attr_key = nullptr) const{
|
||||
auto item = getItem(key, attr_key);
|
||||
if (!item) {
|
||||
return "";
|
||||
@@ -533,20 +531,20 @@ public:
|
||||
SdpItem::Ptr getItem(char key, const char *attr_key = nullptr) const;
|
||||
|
||||
template<typename cls>
|
||||
vector<cls> getAllItem(char key_c, const char *attr_key = nullptr) const {
|
||||
vector<cls> ret;
|
||||
std::vector<cls> getAllItem(char key_c, const char *attr_key = nullptr) const {
|
||||
std::vector<cls> ret;
|
||||
for (auto item : items) {
|
||||
string key(1, key_c);
|
||||
std::string key(1, key_c);
|
||||
if (strcasecmp(item->getKey(), key.data()) == 0) {
|
||||
if (!attr_key) {
|
||||
auto c = dynamic_pointer_cast<cls>(item);
|
||||
auto c = std::dynamic_pointer_cast<cls>(item);
|
||||
if (c) {
|
||||
ret.emplace_back(*c);
|
||||
}
|
||||
} else {
|
||||
auto attr = dynamic_pointer_cast<SdpAttr>(item);
|
||||
auto attr = std::dynamic_pointer_cast<SdpAttr>(item);
|
||||
if (attr && !strcasecmp(attr->detail->getKey(), attr_key)) {
|
||||
auto c = dynamic_pointer_cast<cls>(attr->detail);
|
||||
auto c = std::dynamic_pointer_cast<cls>(attr->detail);
|
||||
if (c) {
|
||||
ret.emplace_back(*c);
|
||||
}
|
||||
@@ -562,9 +560,9 @@ class RtcSessionSdp : public RtcSdpBase{
|
||||
public:
|
||||
using Ptr = std::shared_ptr<RtcSessionSdp>;
|
||||
|
||||
vector<RtcSdpBase> medias;
|
||||
void parse(const string &str);
|
||||
string toString() const override;
|
||||
std::vector<RtcSdpBase> medias;
|
||||
void parse(const std::string &str);
|
||||
std::string toString() const override;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
@@ -574,10 +572,10 @@ class RtcSSRC{
|
||||
public:
|
||||
uint32_t ssrc {0};
|
||||
uint32_t rtx_ssrc {0};
|
||||
string cname;
|
||||
string msid;
|
||||
string mslabel;
|
||||
string label;
|
||||
std::string cname;
|
||||
std::string msid;
|
||||
std::string mslabel;
|
||||
std::string label;
|
||||
|
||||
bool empty() const {return ssrc == 0 && cname.empty();}
|
||||
};
|
||||
@@ -585,36 +583,36 @@ public:
|
||||
//rtc传输编码方案
|
||||
class RtcCodecPlan{
|
||||
public:
|
||||
using Ptr = shared_ptr<RtcCodecPlan>;
|
||||
using Ptr = std::shared_ptr<RtcCodecPlan>;
|
||||
uint8_t pt;
|
||||
string codec;
|
||||
std::string codec;
|
||||
uint32_t sample_rate;
|
||||
//音频时有效
|
||||
uint32_t channel = 0;
|
||||
//rtcp反馈
|
||||
set<string> rtcp_fb;
|
||||
map<string/*key*/, string/*value*/, StrCaseCompare> fmtp;
|
||||
std::set<std::string> rtcp_fb;
|
||||
std::map<std::string/*key*/, std::string/*value*/, mediakit::StrCaseCompare> fmtp;
|
||||
|
||||
string getFmtp(const char *key) const;
|
||||
std::string getFmtp(const char *key) const;
|
||||
};
|
||||
|
||||
//rtc 媒体描述
|
||||
class RtcMedia{
|
||||
public:
|
||||
TrackType type{TrackType::TrackInvalid};
|
||||
string mid;
|
||||
mediakit::TrackType type{mediakit::TrackType::TrackInvalid};
|
||||
std::string mid;
|
||||
uint16_t port{0};
|
||||
SdpConnection addr;
|
||||
string proto;
|
||||
std::string proto;
|
||||
RtpDirection direction{RtpDirection::invalid};
|
||||
vector<RtcCodecPlan> plan;
|
||||
std::vector<RtcCodecPlan> plan;
|
||||
|
||||
//////// rtp ////////
|
||||
vector<RtcSSRC> rtp_rtx_ssrc;
|
||||
std::vector<RtcSSRC> rtp_rtx_ssrc;
|
||||
|
||||
//////// simulcast ////////
|
||||
vector<RtcSSRC> rtp_ssrc_sim;
|
||||
vector<string> rtp_rids;
|
||||
std::vector<RtcSSRC> rtp_ssrc_sim;
|
||||
std::vector<std::string> rtp_rids;
|
||||
|
||||
//////// rtcp ////////
|
||||
bool rtcp_mux{false};
|
||||
@@ -625,8 +623,8 @@ public:
|
||||
bool ice_trickle{false};
|
||||
bool ice_lite{false};
|
||||
bool ice_renomination{false};
|
||||
string ice_ufrag;
|
||||
string ice_pwd;
|
||||
std::string ice_ufrag;
|
||||
std::string ice_pwd;
|
||||
std::vector<SdpAttrCandidate> candidate;
|
||||
|
||||
//////// dtls ////////
|
||||
@@ -634,7 +632,7 @@ public:
|
||||
SdpAttrFingerprint fingerprint;
|
||||
|
||||
//////// extmap ////////
|
||||
vector<SdpAttrExtmap> extmap;
|
||||
std::vector<SdpAttrExtmap> extmap;
|
||||
|
||||
//////// sctp ////////////
|
||||
SdpAttrSctpMap sctpmap;
|
||||
@@ -655,21 +653,21 @@ public:
|
||||
|
||||
uint32_t version;
|
||||
SdpOrigin origin;
|
||||
string session_name;
|
||||
string session_info;
|
||||
std::string session_name;
|
||||
std::string session_info;
|
||||
SdpTime time;
|
||||
SdpConnection connection;
|
||||
SdpBandwidth bandwidth;
|
||||
SdpAttrMsidSemantic msid_semantic;
|
||||
vector<RtcMedia> media;
|
||||
std::vector<RtcMedia> media;
|
||||
SdpAttrGroup group;
|
||||
|
||||
void loadFrom(const string &sdp);
|
||||
void loadFrom(const std::string &sdp);
|
||||
void checkValid() const;
|
||||
string toString() const;
|
||||
string toRtspSdp() const;
|
||||
const RtcMedia *getMedia(TrackType type) const;
|
||||
bool supportRtcpFb(const string &name, TrackType type = TrackType::TrackVideo) const;
|
||||
std::string toString() const;
|
||||
std::string toRtspSdp() const;
|
||||
const RtcMedia *getMedia(mediakit::TrackType type) const;
|
||||
bool supportRtcpFb(const std::string &name, mediakit::TrackType type = mediakit::TrackType::TrackVideo) const;
|
||||
bool supportSimulcast() const;
|
||||
|
||||
private:
|
||||
@@ -690,18 +688,18 @@ public:
|
||||
bool ice_lite;
|
||||
bool ice_trickle;
|
||||
bool ice_renomination;
|
||||
string ice_ufrag;
|
||||
string ice_pwd;
|
||||
std::string ice_ufrag;
|
||||
std::string ice_pwd;
|
||||
|
||||
RtpDirection direction{RtpDirection::invalid};
|
||||
SdpAttrFingerprint fingerprint;
|
||||
|
||||
set<string> rtcp_fb;
|
||||
map<RtpExtType, RtpDirection> extmap;
|
||||
vector<CodecId> preferred_codec;
|
||||
vector<SdpAttrCandidate> candidate;
|
||||
std::set<std::string> rtcp_fb;
|
||||
std::map<RtpExtType, RtpDirection> extmap;
|
||||
std::vector<mediakit::CodecId> preferred_codec;
|
||||
std::vector<SdpAttrCandidate> candidate;
|
||||
|
||||
void setDefaultSetting(TrackType type);
|
||||
void setDefaultSetting(mediakit::TrackType type);
|
||||
void enableTWCC(bool enable = true);
|
||||
void enableREMB(bool enable = true);
|
||||
};
|
||||
@@ -710,20 +708,20 @@ public:
|
||||
RtcTrackConfigure audio;
|
||||
RtcTrackConfigure application;
|
||||
|
||||
void setDefaultSetting(string ice_ufrag, string ice_pwd, RtpDirection direction, const SdpAttrFingerprint &fingerprint);
|
||||
void addCandidate(const SdpAttrCandidate &candidate, TrackType type = TrackInvalid);
|
||||
void setDefaultSetting(std::string ice_ufrag, std::string ice_pwd, RtpDirection direction, const SdpAttrFingerprint &fingerprint);
|
||||
void addCandidate(const SdpAttrCandidate &candidate, mediakit::TrackType type = mediakit::TrackInvalid);
|
||||
|
||||
shared_ptr<RtcSession> createAnswer(const RtcSession &offer);
|
||||
std::shared_ptr<RtcSession> createAnswer(const RtcSession &offer);
|
||||
|
||||
void setPlayRtspInfo(const string &sdp);
|
||||
void setPlayRtspInfo(const std::string &sdp);
|
||||
|
||||
void enableTWCC(bool enable = true, TrackType type = TrackInvalid);
|
||||
void enableREMB(bool enable = true, TrackType type = TrackInvalid);
|
||||
void enableTWCC(bool enable = true, mediakit::TrackType type = mediakit::TrackInvalid);
|
||||
void enableREMB(bool enable = true, mediakit::TrackType type = mediakit::TrackInvalid);
|
||||
|
||||
private:
|
||||
void matchMedia(const shared_ptr<RtcSession> &ret, TrackType type, const vector<RtcMedia> &medias, const RtcTrackConfigure &configure);
|
||||
bool onCheckCodecProfile(const RtcCodecPlan &plan, CodecId codec);
|
||||
void onSelectPlan(RtcCodecPlan &plan, CodecId codec);
|
||||
void matchMedia(const std::shared_ptr<RtcSession> &ret, mediakit::TrackType type, const std::vector<RtcMedia> &medias, const RtcTrackConfigure &configure);
|
||||
bool onCheckCodecProfile(const RtcCodecPlan &plan, mediakit::CodecId codec);
|
||||
void onSelectPlan(RtcCodecPlan &plan, mediakit::CodecId codec);
|
||||
|
||||
private:
|
||||
RtcCodecPlan::Ptr _rtsp_video_plan;
|
||||
@@ -732,8 +730,8 @@ private:
|
||||
|
||||
class SdpConst {
|
||||
public:
|
||||
static string const kTWCCRtcpFb;
|
||||
static string const kRembRtcpFb;
|
||||
static std::string const kTWCCRtcpFb;
|
||||
static std::string const kRembRtcpFb;
|
||||
|
||||
private:
|
||||
SdpConst() = delete;
|
||||
|
||||
@@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#include "logger.h"
|
||||
#include "Util/util.h"
|
||||
#include "Util/logger.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
namespace RTC
|
||||
|
||||
@@ -15,11 +15,10 @@
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include "Util/TimeTicker.h"
|
||||
using namespace toolkit;
|
||||
|
||||
class TwccContext {
|
||||
public:
|
||||
using onSendTwccCB = function<void(uint32_t ssrc, string fci)>;
|
||||
using onSendTwccCB = std::function<void(uint32_t ssrc, std::string fci)>;
|
||||
//每个twcc rtcp包最多表明的rtp ext seq增量
|
||||
static constexpr size_t kMaxSeqSize = 20;
|
||||
//每个twcc rtcp包发送的最大时间间隔,单位毫秒
|
||||
|
||||
@@ -26,7 +26,7 @@ protected:
|
||||
void onRtp(const char *buf, size_t len, uint64_t stamp_ms) override;
|
||||
void onRtcp(const char *buf, size_t len) override;
|
||||
|
||||
void onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Ptr rtp) override {};
|
||||
void onRecvRtp(MediaTrack &track, const std::string &rid, mediakit::RtpPacket::Ptr rtp) override {};
|
||||
void onBeforeEncryptRtp(const char *buf, int &len, void *ctx) override {};
|
||||
void onBeforeEncryptRtcp(const char *buf, int &len, void *ctx) override {};
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
#include "WebRtcPlayer.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace mediakit;
|
||||
|
||||
WebRtcPlayer::Ptr WebRtcPlayer::create(const EventPoller::Ptr &poller,
|
||||
const RtspMediaSource::Ptr &src,
|
||||
const MediaInfo &info) {
|
||||
|
||||
@@ -17,25 +17,25 @@ class WebRtcPlayer : public WebRtcTransportImp {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<WebRtcPlayer>;
|
||||
~WebRtcPlayer() override = default;
|
||||
static Ptr create(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info);
|
||||
static Ptr create(const EventPoller::Ptr &poller, const mediakit::RtspMediaSource::Ptr &src, const mediakit::MediaInfo &info);
|
||||
|
||||
protected:
|
||||
///////WebRtcTransportImp override///////
|
||||
void onStartWebRTC() override;
|
||||
void onDestory() override;
|
||||
void onRtcConfigure(RtcConfigure &configure) const override;
|
||||
void onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Ptr rtp) override {};
|
||||
void onRecvRtp(MediaTrack &track, const std::string &rid, mediakit::RtpPacket::Ptr rtp) override {};
|
||||
|
||||
private:
|
||||
WebRtcPlayer(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info);
|
||||
WebRtcPlayer(const EventPoller::Ptr &poller, const mediakit::RtspMediaSource::Ptr &src, const mediakit::MediaInfo &info);
|
||||
|
||||
private:
|
||||
//媒体相关元数据
|
||||
MediaInfo _media_info;
|
||||
mediakit::MediaInfo _media_info;
|
||||
//播放的rtsp源
|
||||
RtspMediaSource::Ptr _play_src;
|
||||
mediakit::RtspMediaSource::Ptr _play_src;
|
||||
//播放rtsp源的reader对象
|
||||
RtspMediaSource::RingType::RingReader::Ptr _reader;
|
||||
mediakit::RtspMediaSource::RingType::RingReader::Ptr _reader;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
#include "WebRtcPusher.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace mediakit;
|
||||
|
||||
WebRtcPusher::Ptr WebRtcPusher::create(const EventPoller::Ptr &poller,
|
||||
const RtspMediaSource::Ptr &src,
|
||||
const std::shared_ptr<void> &ownership,
|
||||
|
||||
@@ -13,48 +13,48 @@
|
||||
|
||||
#include "WebRtcTransport.h"
|
||||
|
||||
class WebRtcPusher : public WebRtcTransportImp, public MediaSourceEvent {
|
||||
class WebRtcPusher : public WebRtcTransportImp, public mediakit::MediaSourceEvent {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<WebRtcPusher>;
|
||||
~WebRtcPusher() override = default;
|
||||
static Ptr create(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src,
|
||||
const std::shared_ptr<void> &ownership, const MediaInfo &info);
|
||||
static Ptr create(const EventPoller::Ptr &poller, const mediakit::RtspMediaSource::Ptr &src,
|
||||
const std::shared_ptr<void> &ownership, const mediakit::MediaInfo &info);
|
||||
|
||||
protected:
|
||||
///////WebRtcTransportImp override///////
|
||||
void onStartWebRTC() override;
|
||||
void onDestory() override;
|
||||
void onRtcConfigure(RtcConfigure &configure) const override;
|
||||
void onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Ptr rtp) override;
|
||||
void onRecvRtp(MediaTrack &track, const std::string &rid, mediakit::RtpPacket::Ptr rtp) override;
|
||||
|
||||
protected:
|
||||
///////MediaSourceEvent override///////
|
||||
// 关闭
|
||||
bool close(MediaSource &sender, bool force) override;
|
||||
bool close(mediakit::MediaSource &sender, bool force) override;
|
||||
// 播放总人数
|
||||
int totalReaderCount(MediaSource &sender) override;
|
||||
int totalReaderCount(mediakit::MediaSource &sender) override;
|
||||
// 获取媒体源类型
|
||||
MediaOriginType getOriginType(MediaSource &sender) const override;
|
||||
mediakit::MediaOriginType getOriginType(mediakit::MediaSource &sender) const override;
|
||||
// 获取媒体源url或者文件路径
|
||||
string getOriginUrl(MediaSource &sender) const override;
|
||||
std::string getOriginUrl(mediakit::MediaSource &sender) const override;
|
||||
// 获取媒体源客户端相关信息
|
||||
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
|
||||
std::shared_ptr<SockInfo> getOriginSock(mediakit::MediaSource &sender) const override;
|
||||
|
||||
private:
|
||||
WebRtcPusher(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src,
|
||||
const std::shared_ptr<void> &ownership, const MediaInfo &info);
|
||||
WebRtcPusher(const EventPoller::Ptr &poller, const mediakit::RtspMediaSource::Ptr &src,
|
||||
const std::shared_ptr<void> &ownership, const mediakit::MediaInfo &info);
|
||||
|
||||
private:
|
||||
bool _simulcast = false;
|
||||
//媒体相关元数据
|
||||
MediaInfo _media_info;
|
||||
mediakit::MediaInfo _media_info;
|
||||
//推流的rtsp源
|
||||
RtspMediaSource::Ptr _push_src;
|
||||
mediakit::RtspMediaSource::Ptr _push_src;
|
||||
//推流所有权
|
||||
std::shared_ptr<void> _push_src_ownership;
|
||||
//推流的rtsp源,支持simulcast
|
||||
unordered_map<string/*rid*/, RtspMediaSource::Ptr> _push_src_sim;
|
||||
unordered_map<string/*rid*/, std::shared_ptr<void> > _push_src_sim_ownership;
|
||||
std::unordered_map<std::string/*rid*/, mediakit::RtspMediaSource::Ptr> _push_src_sim;
|
||||
std::unordered_map<std::string/*rid*/, std::shared_ptr<void> > _push_src_sim_ownership;
|
||||
};
|
||||
|
||||
#endif //ZLMEDIAKIT_WEBRTCPUSHER_H
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
#include "WebRtcSession.h"
|
||||
#include "Util/util.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace mediakit;
|
||||
|
||||
static string getUserName(const Buffer::Ptr &buffer) {
|
||||
auto buf = buffer->data();
|
||||
auto len = buffer->size();
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
#include "IceServer.hpp"
|
||||
#include "WebRtcTransport.h"
|
||||
|
||||
using namespace toolkit;
|
||||
|
||||
class WebRtcSession : public UdpSession {
|
||||
public:
|
||||
WebRtcSession(const Socket::Ptr &sock);
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
#define RTP_MSLABEL "zlmediakit-mslabel"
|
||||
#define RTP_MSID RTP_MSLABEL " " RTP_LABEL
|
||||
|
||||
using namespace std;
|
||||
using namespace mediakit;
|
||||
|
||||
//RTC配置项目
|
||||
namespace RTC {
|
||||
#define RTC_FIELD "rtc."
|
||||
@@ -564,7 +567,7 @@ private:
|
||||
NackContext _nack_ctx;
|
||||
RtcpContextForRecv _rtcp_context;
|
||||
EventPoller::Ptr _poller;
|
||||
DelayTask::Ptr _delay_task;
|
||||
EventPoller::DelayTask::Ptr _delay_task;
|
||||
function<void(const FCI_NACK &nack)> _on_nack;
|
||||
};
|
||||
|
||||
|
||||
@@ -26,32 +26,29 @@
|
||||
#include "Network/Session.h"
|
||||
#include "TwccContext.h"
|
||||
|
||||
using namespace toolkit;
|
||||
using namespace mediakit;
|
||||
|
||||
//RTC配置项目
|
||||
namespace RTC {
|
||||
extern const string kPort;
|
||||
extern const string kTimeOutSec;
|
||||
extern const std::string kPort;
|
||||
extern const std::string kTimeOutSec;
|
||||
}//namespace RTC
|
||||
|
||||
class WebRtcInterface {
|
||||
public:
|
||||
WebRtcInterface() = default;
|
||||
virtual ~WebRtcInterface() = default;
|
||||
virtual string getAnswerSdp(const string &offer) = 0;
|
||||
virtual const string &getIdentifier() const = 0;
|
||||
virtual std::string getAnswerSdp(const std::string &offer) = 0;
|
||||
virtual const std::string &getIdentifier() const = 0;
|
||||
};
|
||||
|
||||
class WebRtcException : public WebRtcInterface {
|
||||
public:
|
||||
WebRtcException(const SockException &ex) : _ex(ex) {};
|
||||
~WebRtcException() override = default;
|
||||
string getAnswerSdp(const string &offer) override {
|
||||
std::string getAnswerSdp(const std::string &offer) override {
|
||||
throw _ex;
|
||||
}
|
||||
const string &getIdentifier() const override {
|
||||
static string s_null;
|
||||
const std::string &getIdentifier() const override {
|
||||
static std::string s_null;
|
||||
return s_null;
|
||||
}
|
||||
|
||||
@@ -80,12 +77,12 @@ public:
|
||||
* @param offer offer sdp
|
||||
* @return answer sdp
|
||||
*/
|
||||
string getAnswerSdp(const string &offer) override;
|
||||
std::string getAnswerSdp(const std::string &offer) override;
|
||||
|
||||
/**
|
||||
* 获取对象唯一id
|
||||
*/
|
||||
const string& getIdentifier() const override;
|
||||
const std::string& getIdentifier() const override;
|
||||
|
||||
/**
|
||||
* socket收到udp数据
|
||||
@@ -157,7 +154,7 @@ protected:
|
||||
RtcSession::Ptr _answer_sdp;
|
||||
|
||||
private:
|
||||
string _identifier;
|
||||
std::string _identifier;
|
||||
EventPoller::Ptr _poller;
|
||||
std::shared_ptr<RTC::IceServer> _ice_server;
|
||||
std::shared_ptr<RTC::DtlsTransport> _dtls_transport;
|
||||
@@ -183,10 +180,10 @@ public:
|
||||
|
||||
//for send rtp
|
||||
NackList nack_list;
|
||||
RtcpContext::Ptr rtcp_context_send;
|
||||
mediakit::RtcpContext::Ptr rtcp_context_send;
|
||||
|
||||
//for recv rtp
|
||||
unordered_map<string/*rid*/, std::shared_ptr<RtpChannel> > rtp_channel;
|
||||
std::unordered_map<std::string/*rid*/, std::shared_ptr<RtpChannel> > rtp_channel;
|
||||
std::shared_ptr<RtpChannel> getRtpChannel(uint32_t ssrc) const;
|
||||
};
|
||||
|
||||
@@ -194,13 +191,13 @@ struct WrappedMediaTrack {
|
||||
MediaTrack::Ptr track;
|
||||
explicit WrappedMediaTrack(MediaTrack::Ptr ptr): track(ptr) {}
|
||||
virtual ~WrappedMediaTrack() {}
|
||||
virtual void inputRtp(const char *buf, size_t len, uint64_t stamp_ms, RtpHeader *rtp) = 0;
|
||||
virtual void inputRtp(const char *buf, size_t len, uint64_t stamp_ms, mediakit::RtpHeader *rtp) = 0;
|
||||
};
|
||||
|
||||
struct WrappedRtxTrack: public WrappedMediaTrack {
|
||||
explicit WrappedRtxTrack(MediaTrack::Ptr ptr)
|
||||
: WrappedMediaTrack(std::move(ptr)) {}
|
||||
void inputRtp(const char *buf, size_t len, uint64_t stamp_ms, RtpHeader *rtp) override;
|
||||
void inputRtp(const char *buf, size_t len, uint64_t stamp_ms, mediakit::RtpHeader *rtp) override;
|
||||
};
|
||||
|
||||
class WebRtcTransportImp;
|
||||
@@ -212,7 +209,7 @@ struct WrappedRtpTrack : public WrappedMediaTrack {
|
||||
, _transport(t) {}
|
||||
TwccContext& _twcc_ctx;
|
||||
WebRtcTransportImp& _transport;
|
||||
void inputRtp(const char *buf, size_t len, uint64_t stamp_ms, RtpHeader *rtp) override;
|
||||
void inputRtp(const char *buf, size_t len, uint64_t stamp_ms, mediakit::RtpHeader *rtp) override;
|
||||
};
|
||||
|
||||
class WebRtcTransportImp : public WebRtcTransport {
|
||||
@@ -226,9 +223,9 @@ public:
|
||||
uint64_t getDuration() const;
|
||||
bool canSendRtp() const;
|
||||
bool canRecvRtp() const;
|
||||
void onSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool rtx = false);
|
||||
void onSendRtp(const mediakit::RtpPacket::Ptr &rtp, bool flush, bool rtx = false);
|
||||
|
||||
void createRtpChannel(const string &rid, uint32_t ssrc, MediaTrack &track);
|
||||
void createRtpChannel(const std::string &rid, uint32_t ssrc, MediaTrack &track);
|
||||
|
||||
protected:
|
||||
WebRtcTransportImp(const EventPoller::Ptr &poller);
|
||||
@@ -244,14 +241,14 @@ protected:
|
||||
void onCreate() override;
|
||||
void onDestory() override;
|
||||
void onShutdown(const SockException &ex) override;
|
||||
virtual void onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Ptr rtp) = 0;
|
||||
virtual void onRecvRtp(MediaTrack &track, const std::string &rid, mediakit::RtpPacket::Ptr rtp) = 0;
|
||||
void updateTicker();
|
||||
|
||||
private:
|
||||
SdpAttrCandidate::Ptr getIceCandidate() const;
|
||||
void onSortedRtp(MediaTrack &track, const string &rid, RtpPacket::Ptr rtp);
|
||||
void onSendNack(MediaTrack &track, const FCI_NACK &nack, uint32_t ssrc);
|
||||
void onSendTwcc(uint32_t ssrc, const string &twcc_fci);
|
||||
void onSortedRtp(MediaTrack &track, const std::string &rid, mediakit::RtpPacket::Ptr rtp);
|
||||
void onSendNack(MediaTrack &track, const mediakit::FCI_NACK &nack, uint32_t ssrc);
|
||||
void onSendTwcc(uint32_t ssrc, const std::string &twcc_fci);
|
||||
|
||||
void registerSelf();
|
||||
void unregisterSelf();
|
||||
@@ -273,31 +270,31 @@ private:
|
||||
//当前选中的udp链接
|
||||
Session::Ptr _selected_session;
|
||||
//链接迁移前后使用过的udp链接
|
||||
unordered_map<Session *, weak_ptr<Session> > _history_sessions;
|
||||
std::unordered_map<Session *, std::weak_ptr<Session> > _history_sessions;
|
||||
//twcc rtcp发送上下文对象
|
||||
TwccContext _twcc_ctx;
|
||||
//根据发送rtp的track类型获取相关信息
|
||||
MediaTrack::Ptr _type_to_track[2];
|
||||
//根据rtcp的ssrc获取相关信息,收发rtp和rtx的ssrc都会记录
|
||||
unordered_map<uint32_t/*ssrc*/, MediaTrack::Ptr> _ssrc_to_track;
|
||||
std::unordered_map<uint32_t/*ssrc*/, MediaTrack::Ptr> _ssrc_to_track;
|
||||
//根据接收rtp的pt获取相关信息
|
||||
unordered_map<uint8_t/*pt*/, std::unique_ptr<WrappedMediaTrack>> _pt_to_track;
|
||||
std::unordered_map<uint8_t/*pt*/, std::unique_ptr<WrappedMediaTrack>> _pt_to_track;
|
||||
};
|
||||
|
||||
class WebRtcTransportManager {
|
||||
public:
|
||||
friend class WebRtcTransportImp;
|
||||
static WebRtcTransportManager &Instance();
|
||||
WebRtcTransportImp::Ptr getItem(const string &key);
|
||||
WebRtcTransportImp::Ptr getItem(const std::string &key);
|
||||
|
||||
private:
|
||||
WebRtcTransportManager() = default;
|
||||
void addItem(const string &key, const WebRtcTransportImp::Ptr &ptr);
|
||||
void removeItem(const string &key);
|
||||
void addItem(const std::string &key, const WebRtcTransportImp::Ptr &ptr);
|
||||
void removeItem(const std::string &key);
|
||||
|
||||
private:
|
||||
mutable mutex _mtx;
|
||||
unordered_map<string, weak_ptr<WebRtcTransportImp> > _map;
|
||||
mutable std::mutex _mtx;
|
||||
std::unordered_map<std::string, std::weak_ptr<WebRtcTransportImp> > _map;
|
||||
};
|
||||
|
||||
class WebRtcArgs {
|
||||
@@ -305,23 +302,23 @@ public:
|
||||
WebRtcArgs() = default;
|
||||
virtual ~WebRtcArgs() = default;
|
||||
|
||||
virtual variant operator[](const string &key) const = 0;
|
||||
virtual variant operator[](const std::string &key) const = 0;
|
||||
};
|
||||
|
||||
class WebRtcPluginManager {
|
||||
public:
|
||||
using onCreateRtc = function<void(const WebRtcInterface &rtc)>;
|
||||
using Plugin = function<void(Session &sender, const string &offer, const WebRtcArgs &args, const onCreateRtc &cb)>;
|
||||
using onCreateRtc = std::function<void(const WebRtcInterface &rtc)>;
|
||||
using Plugin = std::function<void(Session &sender, const std::string &offer, const WebRtcArgs &args, const onCreateRtc &cb)>;
|
||||
|
||||
static WebRtcPluginManager &Instance();
|
||||
|
||||
void registerPlugin(const string &type, Plugin cb);
|
||||
void getAnswerSdp(Session &sender, const string &type, const string &offer, const WebRtcArgs &args, const onCreateRtc &cb);
|
||||
void registerPlugin(const std::string &type, Plugin cb);
|
||||
void getAnswerSdp(Session &sender, const std::string &type, const std::string &offer, const WebRtcArgs &args, const onCreateRtc &cb);
|
||||
|
||||
private:
|
||||
WebRtcPluginManager() = default;
|
||||
|
||||
private:
|
||||
mutable mutex _mtx_creator;
|
||||
unordered_map<string, Plugin> _map_creator;
|
||||
mutable std::mutex _mtx_creator;
|
||||
std::unordered_map<std::string, Plugin> _map_creator;
|
||||
};
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include "Util/logger.h"
|
||||
using namespace toolkit;
|
||||
|
||||
#define MS_TRACE()
|
||||
#define MS_ERROR PrintE
|
||||
|
||||
Reference in New Issue
Block a user