mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
format code use clang-format
This commit is contained in:
parent
602b475a3c
commit
cffc0743d7
@ -8,11 +8,11 @@
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
#include "Rtcp.h"
|
||||
#include "Util/logger.h"
|
||||
#include "RtcpFCI.h"
|
||||
#include "Util/logger.h"
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
@ -21,37 +21,49 @@ namespace mediakit {
|
||||
|
||||
const char *rtcpTypeToStr(RtcpType type) {
|
||||
switch (type) {
|
||||
#define SWITCH_CASE(key, value) case RtcpType::key : return #value "(" #key ")";
|
||||
#define SWITCH_CASE(key, value) \
|
||||
case RtcpType::key: \
|
||||
return #value "(" #key ")";
|
||||
RTCP_PT_MAP(SWITCH_CASE)
|
||||
#undef SWITCH_CASE
|
||||
default: return "unknown rtcp pt";
|
||||
default:
|
||||
return "unknown rtcp pt";
|
||||
}
|
||||
}
|
||||
|
||||
const char *sdesTypeToStr(SdesType type) {
|
||||
switch (type) {
|
||||
#define SWITCH_CASE(key, value) case SdesType::key : return #value "(" #key ")";
|
||||
#define SWITCH_CASE(key, value) \
|
||||
case SdesType::key: \
|
||||
return #value "(" #key ")";
|
||||
SDES_TYPE_MAP(SWITCH_CASE)
|
||||
#undef SWITCH_CASE
|
||||
default: return "unknown source description type";
|
||||
default:
|
||||
return "unknown source description type";
|
||||
}
|
||||
}
|
||||
|
||||
const char *psfbTypeToStr(PSFBType type) {
|
||||
switch (type) {
|
||||
#define SWITCH_CASE(key, value) case PSFBType::key : return #value "(" #key ")";
|
||||
#define SWITCH_CASE(key, value) \
|
||||
case PSFBType::key: \
|
||||
return #value "(" #key ")";
|
||||
PSFB_TYPE_MAP(SWITCH_CASE)
|
||||
#undef SWITCH_CASE
|
||||
default: return "unknown payload-specific fb message fmt type";
|
||||
default:
|
||||
return "unknown payload-specific fb message fmt type";
|
||||
}
|
||||
}
|
||||
|
||||
const char *rtpfbTypeToStr(RTPFBType type) {
|
||||
switch (type) {
|
||||
#define SWITCH_CASE(key, value) case RTPFBType::key : return #value "(" #key ")";
|
||||
#define SWITCH_CASE(key, value) \
|
||||
case RTPFBType::key: \
|
||||
return #value "(" #key ")";
|
||||
RTPFB_TYPE_MAP(SWITCH_CASE)
|
||||
#undef SWITCH_CASE
|
||||
default: return "unknown transport layer feedback messages fmt type";
|
||||
default:
|
||||
return "unknown transport layer feedback messages fmt type";
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,7 +152,8 @@ string RtcpHeader::dumpString() const {
|
||||
return rtcp->dumpString();
|
||||
}
|
||||
|
||||
default: return StrPrinter << dumpHeader() << hexdump((char *)this + sizeof(*this), getSize() - sizeof(*this));
|
||||
default:
|
||||
return StrPrinter << dumpHeader() << hexdump((char *)this + sizeof(*this), getSize() - sizeof(*this));
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,7 +220,8 @@ void RtcpHeader::net2Host(size_t len) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: throw std::runtime_error(StrPrinter << "未处理的rtcp包:" << rtcpTypeToStr((RtcpType) this->pt));
|
||||
default:
|
||||
throw std::runtime_error(StrPrinter << "未处理的rtcp包:" << rtcpTypeToStr((RtcpType)this->pt));
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,19 +251,13 @@ vector<RtcpHeader *> RtcpHeader::loadFromBytes(char *data, size_t len) {
|
||||
|
||||
class BufferRtcp : public Buffer {
|
||||
public:
|
||||
BufferRtcp(std::shared_ptr<RtcpHeader> rtcp) {
|
||||
_rtcp = std::move(rtcp);
|
||||
}
|
||||
BufferRtcp(std::shared_ptr<RtcpHeader> rtcp) { _rtcp = std::move(rtcp); }
|
||||
|
||||
~BufferRtcp() override {}
|
||||
|
||||
char *data() const override {
|
||||
return (char *) _rtcp.get();
|
||||
}
|
||||
char *data() const override { return (char *)_rtcp.get(); }
|
||||
|
||||
size_t size() const override {
|
||||
return _rtcp->getSize();
|
||||
}
|
||||
size_t size() const override { return _rtcp->getSize(); }
|
||||
|
||||
private:
|
||||
std::shared_ptr<RtcpHeader> _rtcp;
|
||||
@ -267,9 +275,7 @@ std::shared_ptr<RtcpSR> RtcpSR::create(size_t item_count) {
|
||||
auto ptr = (RtcpSR *)new char[bytes];
|
||||
setupHeader(ptr, RtcpType::RTCP_SR, item_count, bytes);
|
||||
setupPadding(ptr, bytes - real_size);
|
||||
return std::shared_ptr<RtcpSR>(ptr, [](RtcpSR *ptr) {
|
||||
delete[] (char *) ptr;
|
||||
});
|
||||
return std::shared_ptr<RtcpSR>(ptr, [](RtcpSR *ptr) { delete[] (char *)ptr; });
|
||||
}
|
||||
|
||||
string RtcpSR::getNtpStamp() const {
|
||||
@ -324,13 +330,15 @@ string RtcpSR::dumpString() const {
|
||||
|
||||
#define CHECK_MIN_SIZE(size, kMinSize) \
|
||||
if (size < kMinSize) { \
|
||||
throw std::out_of_range(StrPrinter << rtcpTypeToStr((RtcpType)pt) << " 长度不足:" << size << " < " << kMinSize); \
|
||||
throw std::out_of_range( \
|
||||
StrPrinter << rtcpTypeToStr((RtcpType)pt) << " 长度不足:" << size << " < " << kMinSize); \
|
||||
}
|
||||
|
||||
#define CHECK_REPORT_COUNT(item_count) \
|
||||
/*修正个数,防止getItemList时内存越界*/ \
|
||||
if (report_count != item_count) { \
|
||||
WarnL << rtcpTypeToStr((RtcpType)pt) << " report_count 字段不正确,已修正为:" << (int)report_count << " -> " << item_count; \
|
||||
WarnL << rtcpTypeToStr((RtcpType)pt) << " report_count 字段不正确,已修正为:" << (int)report_count << " -> " \
|
||||
<< item_count; \
|
||||
report_count = item_count; \
|
||||
}
|
||||
|
||||
@ -398,9 +406,7 @@ std::shared_ptr<RtcpRR> RtcpRR::create(size_t item_count) {
|
||||
auto ptr = (RtcpRR *)new char[bytes];
|
||||
setupHeader(ptr, RtcpType::RTCP_RR, item_count, bytes);
|
||||
setupPadding(ptr, bytes - real_size);
|
||||
return std::shared_ptr<RtcpRR>(ptr, [](RtcpRR *ptr) {
|
||||
delete[] (char *) ptr;
|
||||
});
|
||||
return std::shared_ptr<RtcpRR>(ptr, [](RtcpRR *ptr) { delete[] (char *)ptr; });
|
||||
}
|
||||
|
||||
string RtcpRR::dumpString() const {
|
||||
@ -486,9 +492,7 @@ std::shared_ptr<RtcpSdes> RtcpSdes::create(const std::vector<string> &item_text)
|
||||
|
||||
setupHeader(ptr, RtcpType::RTCP_SDES, item_text.size(), bytes);
|
||||
setupPadding(ptr, bytes - real_size);
|
||||
return std::shared_ptr<RtcpSdes>(ptr, [](RtcpSdes *ptr) {
|
||||
delete[] (char *) ptr;
|
||||
});
|
||||
return std::shared_ptr<RtcpSdes>(ptr, [](RtcpSdes *ptr) { delete[] (char *)ptr; });
|
||||
}
|
||||
|
||||
string RtcpSdes::dumpString() const {
|
||||
@ -540,9 +544,7 @@ std::shared_ptr<RtcpFB> RtcpFB::create_l(RtcpType type, int fmt, const void *fci
|
||||
}
|
||||
setupHeader(ptr, type, fmt, bytes);
|
||||
setupPadding(ptr, bytes - real_size);
|
||||
return std::shared_ptr<RtcpFB>((RtcpFB *) ptr, [](RtcpFB *ptr) {
|
||||
delete[] (char *) ptr;
|
||||
});
|
||||
return std::shared_ptr<RtcpFB>((RtcpFB *)ptr, [](RtcpFB *ptr) { delete[] (char *)ptr; });
|
||||
}
|
||||
|
||||
std::shared_ptr<RtcpFB> RtcpFB::create(PSFBType fmt, const void *fci, size_t fci_len) {
|
||||
@ -619,7 +621,9 @@ string RtcpFB::dumpString() const {
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: /*不可达*/ assert(0); break;
|
||||
default: /*不可达*/
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
return std::move(printer);
|
||||
}
|
||||
@ -652,9 +656,7 @@ std::shared_ptr<RtcpBye> RtcpBye::create(const std::vector<uint32_t> &ssrcs, con
|
||||
memcpy(reason_len_ptr + 1, reason.data(), *reason_len_ptr);
|
||||
}
|
||||
|
||||
return std::shared_ptr<RtcpBye>(ptr, [](RtcpBye *ptr) {
|
||||
delete[] (char *) ptr;
|
||||
});
|
||||
return std::shared_ptr<RtcpBye>(ptr, [](RtcpBye *ptr) { delete[] (char *)ptr; });
|
||||
}
|
||||
|
||||
vector<uint32_t *> RtcpBye::getSSRC() {
|
||||
@ -720,7 +722,9 @@ void RtcpXRRRTR::net2Host(size_t size) {
|
||||
static const size_t kMinSize = sizeof(RtcpHeader);
|
||||
CHECK_MIN_SIZE(size, kMinSize);
|
||||
if (size != sizeof(RtcpXRRRTR)) {
|
||||
throw std::invalid_argument(StrPrinter << "rtcp xr Receiver Reference Time Report Block must is " << sizeof(RtcpXRRRTR)<<" actual size "<<size);
|
||||
throw std::invalid_argument(
|
||||
StrPrinter << "rtcp xr Receiver Reference Time Report Block must is " << sizeof(RtcpXRRRTR)
|
||||
<< " actual size " << size);
|
||||
}
|
||||
ssrc = ntohl(ssrc);
|
||||
block_length = ntohs(block_length);
|
||||
@ -728,7 +732,6 @@ void RtcpXRRRTR::net2Host(size_t size) {
|
||||
ntplsw = ntohl(ntplsw);
|
||||
}
|
||||
|
||||
|
||||
string RtcpXRDLRRReportItem::dumpString() const {
|
||||
_StrPrinter printer;
|
||||
|
||||
@ -754,7 +757,6 @@ std::vector<RtcpXRDLRRReportItem*> RtcpXRDLRR::getItemList(){
|
||||
++ptr;
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
string RtcpXRDLRR::dumpString() const {
|
||||
_StrPrinter printer;
|
||||
@ -792,9 +794,7 @@ std::shared_ptr<RtcpXRDLRR> RtcpXRDLRR::create(size_t item_count){
|
||||
auto ptr = (RtcpXRDLRR *)new char[bytes];
|
||||
setupHeader(ptr, RtcpType::RTCP_XR, 0, bytes);
|
||||
setupPadding(ptr, bytes - real_size);
|
||||
return std::shared_ptr<RtcpXRDLRR>(ptr, [](RtcpXRDLRR *ptr) {
|
||||
delete[] (char *) ptr;
|
||||
});
|
||||
return std::shared_ptr<RtcpXRDLRR>(ptr, [](RtcpXRDLRR *ptr) { delete[] (char *)ptr; });
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -11,11 +11,11 @@
|
||||
#ifndef ZLMEDIAKIT_RTCP_H
|
||||
#define ZLMEDIAKIT_RTCP_H
|
||||
|
||||
#include "Common/macros.h"
|
||||
#include "Network/Buffer.h"
|
||||
#include "Util/util.h"
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include "Util/util.h"
|
||||
#include "Network/Buffer.h"
|
||||
#include "Common/macros.h"
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@ -222,7 +222,6 @@ public:
|
||||
void setSize(size_t size);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* 打印字段详情
|
||||
* 使用net2Host转换成主机字节序后才可使用此函数
|
||||
@ -712,8 +711,7 @@ private:
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
||||
*/
|
||||
class RtcpXRRRTR : public RtcpHeader
|
||||
{
|
||||
class RtcpXRRRTR : public RtcpHeader {
|
||||
public:
|
||||
friend class RtcpHeader;
|
||||
uint32_t ssrc;
|
||||
@ -726,6 +724,7 @@ public:
|
||||
uint32_t ntpmsw;
|
||||
// ntp timestamp LSW(in picosecond)
|
||||
uint32_t ntplsw;
|
||||
|
||||
private:
|
||||
/**
|
||||
* 打印字段详情
|
||||
@ -759,13 +758,13 @@ private:
|
||||
: ... : 2
|
||||
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|
||||
*/
|
||||
class RtcpXRDLRRReportItem
|
||||
{
|
||||
class RtcpXRDLRRReportItem {
|
||||
public:
|
||||
friend class RtcpXRDLRR;
|
||||
uint32_t ssrc;
|
||||
uint32_t lrr;
|
||||
uint32_t dlrr;
|
||||
|
||||
private:
|
||||
/**
|
||||
* 打印字段详情
|
||||
@ -780,10 +779,7 @@ private:
|
||||
void net2Host();
|
||||
} PACKED;
|
||||
|
||||
|
||||
|
||||
class RtcpXRDLRR : public RtcpHeader
|
||||
{
|
||||
class RtcpXRDLRR : public RtcpHeader {
|
||||
public:
|
||||
friend class RtcpHeader;
|
||||
uint32_t ssrc;
|
||||
@ -820,7 +816,6 @@ private:
|
||||
|
||||
} PACKED;
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
#pragma pack(pop)
|
||||
#endif // defined(_WIN32)
|
||||
|
@ -14,7 +14,8 @@ using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
void RtcpContext::onRtp(uint16_t /*seq*/, uint32_t stamp, uint64_t ntp_stamp_ms, uint32_t /*sample_rate*/, size_t bytes) {
|
||||
void RtcpContext::onRtp(
|
||||
uint16_t /*seq*/, uint32_t stamp, uint64_t ntp_stamp_ms, uint32_t /*sample_rate*/, size_t bytes) {
|
||||
++_packets;
|
||||
_bytes += bytes;
|
||||
_last_rtp_stamp = stamp;
|
||||
@ -79,7 +80,8 @@ void RtcpContextForSend::onRtcp(RtcpHeader *rtcp) {
|
||||
case RtcpType::RTCP_XR: {
|
||||
auto rtcp_xr = (RtcpXRRRTR *)rtcp;
|
||||
if (rtcp_xr->bt == 4) {
|
||||
_xr_xrrtr_recv_last_rr[rtcp_xr->ssrc] = ((rtcp_xr->ntpmsw & 0xFFFF) << 16) | ((rtcp_xr->ntplsw >> 16) & 0xFFFF);
|
||||
_xr_xrrtr_recv_last_rr[rtcp_xr->ssrc]
|
||||
= ((rtcp_xr->ntpmsw & 0xFFFF) << 16) | ((rtcp_xr->ntplsw >> 16) & 0xFFFF);
|
||||
_xr_rrtr_recv_sys_stamp[rtcp_xr->ssrc] = getCurrentMillisecond();
|
||||
} else if (rtcp_xr->bt == 5) {
|
||||
TraceL << "for sender not recive dlrr";
|
||||
@ -88,7 +90,8 @@ void RtcpContextForSend::onRtcp(RtcpHeader *rtcp) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,13 +152,15 @@ toolkit::Buffer::Ptr RtcpContextForSend::createRtcpXRDLRR(uint32_t rtcp_ssrc, ui
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RtcpContextForRecv::onRtp(uint16_t seq, uint32_t stamp, uint64_t ntp_stamp_ms, uint32_t sample_rate, size_t bytes) {
|
||||
void RtcpContextForRecv::onRtp(
|
||||
uint16_t seq, uint32_t stamp, uint64_t ntp_stamp_ms, uint32_t sample_rate, size_t bytes) {
|
||||
{
|
||||
// 接收者才做复杂的统计运算
|
||||
auto sys_stamp = getCurrentMillisecond();
|
||||
if (_last_rtp_sys_stamp) {
|
||||
// 计算时间戳抖动值
|
||||
double diff = double((int64_t(sys_stamp) - int64_t(_last_rtp_sys_stamp)) * (sample_rate / double(1000.0))
|
||||
double diff = double(
|
||||
(int64_t(sys_stamp) - int64_t(_last_rtp_sys_stamp)) * (sample_rate / double(1000.0))
|
||||
- (int64_t(stamp) - int64_t(_last_rtp_stamp)));
|
||||
if (diff < 0) {
|
||||
diff = -diff;
|
||||
@ -206,7 +211,8 @@ void RtcpContextForRecv::onRtcp(RtcpHeader *rtcp) {
|
||||
_last_sr_ntp_sys = getCurrentMillisecond();
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,9 @@
|
||||
#ifndef ZLMEDIAKIT_RTCPCONTEXT_H
|
||||
#define ZLMEDIAKIT_RTCPCONTEXT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "Rtcp.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@ -55,7 +55,6 @@ public:
|
||||
*/
|
||||
virtual toolkit::Buffer::Ptr createRtcpSR(uint32_t rtcp_ssrc);
|
||||
|
||||
|
||||
/**
|
||||
* @brief 创建xr的dlrr包,用于接收者估算rtt
|
||||
*
|
||||
|
@ -465,9 +465,11 @@ FCI_TWCC::TwccPacketStatus FCI_TWCC::getPacketChunkList(size_t total_size) const
|
||||
string FCI_TWCC::dumpString(size_t total_size) const {
|
||||
_StrPrinter printer;
|
||||
auto map = getPacketChunkList(total_size);
|
||||
printer << "twcc fci, base_seq:" << getBaseSeq() << ", pkt_status_count:" << getPacketCount() << ", ref time:" << getReferenceTime() << ", fb count:" << (int)fb_pkt_count << "\n";
|
||||
printer << "twcc fci, base_seq:" << getBaseSeq() << ", pkt_status_count:" << getPacketCount()
|
||||
<< ", ref time:" << getReferenceTime() << ", fb count:" << (int)fb_pkt_count << "\n";
|
||||
for (auto &pr : map) {
|
||||
printer << "rtp seq:" << pr.first <<", packet status:" << (int)(pr.second.first) << ", delta:" << pr.second.second << "\n";
|
||||
printer << "rtp seq:" << pr.first << ", packet status:" << (int)(pr.second.first)
|
||||
<< ", delta:" << pr.second.second << "\n";
|
||||
}
|
||||
return std::move(printer);
|
||||
}
|
||||
@ -476,10 +478,14 @@ static void appendDeltaString(string &delta_str, FCI_TWCC::TwccPacketStatus &sta
|
||||
for (auto it = status.begin(); it != status.end() && count--;) {
|
||||
switch (it->second.first) {
|
||||
// large delta模式先写高字节,再写低字节
|
||||
case SymbolStatus::large_delta: delta_str.push_back((it->second.second >> 8) & 0xFF);
|
||||
case SymbolStatus::large_delta:
|
||||
delta_str.push_back((it->second.second >> 8) & 0xFF);
|
||||
// small delta模式只写低字节
|
||||
case SymbolStatus::small_delta: delta_str.push_back(it->second.second & 0xFF); break;
|
||||
default: break;
|
||||
case SymbolStatus::small_delta:
|
||||
delta_str.push_back(it->second.second & 0xFF);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// 移除已经处理过的数据
|
||||
it = status.erase(it);
|
||||
|
@ -11,8 +11,8 @@
|
||||
#ifndef ZLMEDIAKIT_RTCPFCI_H
|
||||
#define ZLMEDIAKIT_RTCPFCI_H
|
||||
|
||||
#include "Rtcp.h"
|
||||
#include "Common/config.h"
|
||||
#include "Rtcp.h"
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@ -354,7 +354,8 @@ enum class SymbolStatus : uint8_t{
|
||||
class FCI_TWCC {
|
||||
public:
|
||||
static size_t constexpr kSize = 8;
|
||||
using TwccPacketStatus = std::map<uint16_t/*rtp ext seq*/, std::pair<SymbolStatus, int16_t/*recv delta,单位为250us*/> >;
|
||||
using TwccPacketStatus
|
||||
= std::map<uint16_t /*rtp ext seq*/, std::pair<SymbolStatus, int16_t /*recv delta,单位为250us*/>>;
|
||||
void check(size_t size);
|
||||
std::string dumpString(size_t total_size) const;
|
||||
uint16_t getBaseSeq() const;
|
||||
|
@ -9,11 +9,11 @@
|
||||
*/
|
||||
|
||||
#include "WebRtcTransport.h"
|
||||
#include <iostream>
|
||||
#include "RtpExt.h"
|
||||
#include "Rtcp/Rtcp.h"
|
||||
#include "Rtcp/RtcpFCI.h"
|
||||
#include "RtpExt.h"
|
||||
#include "Rtsp/RtpReceiver.h"
|
||||
#include <iostream>
|
||||
|
||||
#define RTP_SSRC_OFFSET 1
|
||||
#define RTX_SSRC_OFFSET 2
|
||||
@ -92,7 +92,8 @@ const string &WebRtcTransport::getIdentifier() const {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void WebRtcTransport::OnIceServerSendStunPacket(const RTC::IceServer *iceServer, const RTC::StunPacket *packet, RTC::TransportTuple *tuple) {
|
||||
void WebRtcTransport::OnIceServerSendStunPacket(
|
||||
const RTC::IceServer *iceServer, const RTC::StunPacket *packet, RTC::TransportTuple *tuple) {
|
||||
sendSockData((char *)packet->GetData(), packet->GetSize(), tuple);
|
||||
}
|
||||
|
||||
@ -120,16 +121,13 @@ void WebRtcTransport::OnIceServerDisconnected(const RTC::IceServer *iceServer) {
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void WebRtcTransport::OnDtlsTransportConnected(
|
||||
const RTC::DtlsTransport *dtlsTransport,
|
||||
RTC::SrtpSession::CryptoSuite srtpCryptoSuite,
|
||||
uint8_t *srtpLocalKey,
|
||||
size_t srtpLocalKeyLen,
|
||||
uint8_t *srtpRemoteKey,
|
||||
size_t srtpRemoteKeyLen,
|
||||
std::string &remoteCert) {
|
||||
const RTC::DtlsTransport *dtlsTransport, RTC::SrtpSession::CryptoSuite srtpCryptoSuite, uint8_t *srtpLocalKey,
|
||||
size_t srtpLocalKeyLen, uint8_t *srtpRemoteKey, size_t srtpRemoteKeyLen, std::string &remoteCert) {
|
||||
InfoL;
|
||||
_srtp_session_send = std::make_shared<RTC::SrtpSession>(RTC::SrtpSession::Type::OUTBOUND, srtpCryptoSuite, srtpLocalKey, srtpLocalKeyLen);
|
||||
_srtp_session_recv = std::make_shared<RTC::SrtpSession>(RTC::SrtpSession::Type::INBOUND, srtpCryptoSuite, srtpRemoteKey, srtpRemoteKeyLen);
|
||||
_srtp_session_send = std::make_shared<RTC::SrtpSession>(
|
||||
RTC::SrtpSession::Type::OUTBOUND, srtpCryptoSuite, srtpLocalKey, srtpLocalKeyLen);
|
||||
_srtp_session_recv = std::make_shared<RTC::SrtpSession>(
|
||||
RTC::SrtpSession::Type::INBOUND, srtpCryptoSuite, srtpRemoteKey, srtpRemoteKeyLen);
|
||||
#ifdef ENABLE_SCTP
|
||||
_sctp = std::make_shared<RTC::SctpAssociationImp>(getPoller(), this, 128, 128, 262144, true);
|
||||
_sctp->TransportConnected();
|
||||
@ -137,7 +135,8 @@ void WebRtcTransport::OnDtlsTransportConnected(
|
||||
onStartWebRTC();
|
||||
}
|
||||
|
||||
void WebRtcTransport::OnDtlsTransportSendData(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) {
|
||||
void WebRtcTransport::OnDtlsTransportSendData(
|
||||
const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) {
|
||||
sendSockData((char *)data, len, nullptr);
|
||||
}
|
||||
|
||||
@ -155,7 +154,8 @@ void WebRtcTransport::OnDtlsTransportClosed(const RTC::DtlsTransport *dtlsTransp
|
||||
onShutdown(SockException(Err_shutdown, "dtls close notify received"));
|
||||
}
|
||||
|
||||
void WebRtcTransport::OnDtlsTransportApplicationDataReceived(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) {
|
||||
void WebRtcTransport::OnDtlsTransportApplicationDataReceived(
|
||||
const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) {
|
||||
#ifdef ENABLE_SCTP
|
||||
_sctp->ProcessSctpData(data, len);
|
||||
#else
|
||||
@ -181,12 +181,13 @@ void WebRtcTransport::OnSctpAssociationClosed(RTC::SctpAssociation* sctpAssociat
|
||||
InfoL << getIdentifier();
|
||||
}
|
||||
|
||||
void WebRtcTransport::OnSctpAssociationSendData(RTC::SctpAssociation* sctpAssociation, const uint8_t* data, size_t len) {
|
||||
void WebRtcTransport::OnSctpAssociationSendData(
|
||||
RTC::SctpAssociation *sctpAssociation, const uint8_t *data, size_t len) {
|
||||
_dtls_transport->SendApplicationData(data, len);
|
||||
}
|
||||
|
||||
void WebRtcTransport::OnSctpAssociationMessageReceived(RTC::SctpAssociation *sctpAssociation, uint16_t streamId,
|
||||
uint32_t ppid, const uint8_t *msg, size_t len) {
|
||||
void WebRtcTransport::OnSctpAssociationMessageReceived(
|
||||
RTC::SctpAssociation *sctpAssociation, uint16_t streamId, uint32_t ppid, const uint8_t *msg, size_t len) {
|
||||
InfoL << getIdentifier() << " " << streamId << " " << ppid << " " << len << " " << string((char *)msg, len);
|
||||
RTC::SctpStreamParameters params;
|
||||
params.streamId = streamId;
|
||||
@ -234,7 +235,8 @@ string getFingerprint(const string &algorithm_str, const std::shared_ptr<RTC::Dt
|
||||
void WebRtcTransport::setRemoteDtlsFingerprint(const RtcSession &remote) {
|
||||
// 设置远端dtls签名
|
||||
RTC::DtlsTransport::Fingerprint remote_fingerprint;
|
||||
remote_fingerprint.algorithm = RTC::DtlsTransport::GetFingerprintAlgorithm(_offer_sdp->media[0].fingerprint.algorithm);
|
||||
remote_fingerprint.algorithm
|
||||
= RTC::DtlsTransport::GetFingerprintAlgorithm(_offer_sdp->media[0].fingerprint.algorithm);
|
||||
remote_fingerprint.value = _offer_sdp->media[0].fingerprint.hash;
|
||||
_dtls_transport->SetRemoteFingerprint(remote_fingerprint);
|
||||
}
|
||||
@ -259,8 +261,8 @@ std::string WebRtcTransport::getAnswerSdp(const string &offer){
|
||||
fingerprint.algorithm = _offer_sdp->media[0].fingerprint.algorithm;
|
||||
fingerprint.hash = getFingerprint(fingerprint.algorithm, _dtls_transport);
|
||||
RtcConfigure configure;
|
||||
configure.setDefaultSetting(_ice_server->GetUsernameFragment(), _ice_server->GetPassword(),
|
||||
RtpDirection::sendrecv, fingerprint);
|
||||
configure.setDefaultSetting(
|
||||
_ice_server->GetUsernameFragment(), _ice_server->GetPassword(), RtpDirection::sendrecv, fingerprint);
|
||||
onRtcConfigure(configure);
|
||||
|
||||
//// 生成answer sdp ////
|
||||
@ -364,7 +366,9 @@ void WebRtcTransportImp::onCreate(){
|
||||
|
||||
weak_ptr<WebRtcTransportImp> weak_self = static_pointer_cast<WebRtcTransportImp>(shared_from_this());
|
||||
GET_CONFIG(float, timeoutSec, RTC::kTimeOutSec);
|
||||
_timer = std::make_shared<Timer>(timeoutSec / 2, [weak_self]() {
|
||||
_timer = std::make_shared<Timer>(
|
||||
timeoutSec / 2,
|
||||
[weak_self]() {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
return false;
|
||||
@ -373,14 +377,14 @@ void WebRtcTransportImp::onCreate(){
|
||||
strong_self->onShutdown(SockException(Err_timeout, "接受rtp和rtcp超时"));
|
||||
}
|
||||
return true;
|
||||
}, getPoller());
|
||||
},
|
||||
getPoller());
|
||||
|
||||
_twcc_ctx.setOnSendTwccCB([this](uint32_t ssrc, string fci) {
|
||||
onSendTwcc(ssrc, fci);
|
||||
});
|
||||
_twcc_ctx.setOnSendTwccCB([this](uint32_t ssrc, string fci) { onSendTwcc(ssrc, fci); });
|
||||
}
|
||||
|
||||
WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller) : WebRtcTransport(poller) {
|
||||
WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller)
|
||||
: WebRtcTransport(poller) {
|
||||
InfoL << getIdentifier();
|
||||
}
|
||||
|
||||
@ -455,7 +459,8 @@ void WebRtcTransportImp::onStartWebRTC() {
|
||||
_ssrc_to_track[track->offer_ssrc_rtx] = track;
|
||||
|
||||
// rtp pt --> MediaTrack
|
||||
_pt_to_track.emplace(track->plan_rtp->pt, std::unique_ptr<WrappedMediaTrack>(new WrappedRtpTrack(track, _twcc_ctx, *this)));
|
||||
_pt_to_track.emplace(
|
||||
track->plan_rtp->pt, std::unique_ptr<WrappedMediaTrack>(new WrappedRtpTrack(track, _twcc_ctx, *this)));
|
||||
if (track->plan_rtx) {
|
||||
// rtx pt --> MediaTrack
|
||||
_pt_to_track.emplace(track->plan_rtx->pt, std::unique_ptr<WrappedMediaTrack>(new WrappedRtxTrack(track)));
|
||||
@ -546,14 +551,19 @@ void WebRtcTransportImp::onCheckAnswer(RtcSession &sdp) {
|
||||
|
||||
void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp) {
|
||||
switch (type) {
|
||||
case SdpType::answer: onCheckAnswer(sdp); break;
|
||||
case SdpType::offer: break;
|
||||
default: /*不可达*/ assert(0); break;
|
||||
case SdpType::answer:
|
||||
onCheckAnswer(sdp);
|
||||
break;
|
||||
case SdpType::offer:
|
||||
break;
|
||||
default: /*不可达*/
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SdpAttrCandidate::Ptr makeIceCandidate(std::string ip, uint16_t port,
|
||||
uint32_t priority = 100, std::string proto = "udp") {
|
||||
SdpAttrCandidate::Ptr
|
||||
makeIceCandidate(std::string ip, uint16_t port, uint32_t priority = 100, std::string proto = "udp") {
|
||||
auto candidate = std::make_shared<SdpAttrCandidate>();
|
||||
// rtp端口
|
||||
candidate->component = 1;
|
||||
@ -593,19 +603,18 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
class RtpChannel : public RtpTrackImp, public std::enable_shared_from_this<RtpChannel> {
|
||||
class RtpChannel
|
||||
: public RtpTrackImp
|
||||
, public std::enable_shared_from_this<RtpChannel> {
|
||||
public:
|
||||
RtpChannel(EventPoller::Ptr poller, RtpTrackImp::OnSorted cb, function<void(const FCI_NACK &nack)> on_nack) {
|
||||
_poller = std::move(poller);
|
||||
_on_nack = std::move(on_nack);
|
||||
setOnSorted(std::move(cb));
|
||||
|
||||
_nack_ctx.setOnNack([this](const FCI_NACK &nack) {
|
||||
onNack(nack);
|
||||
});
|
||||
_nack_ctx.setOnNack([this](const FCI_NACK &nack) { onNack(nack); });
|
||||
}
|
||||
|
||||
~RtpChannel() override = default;
|
||||
@ -770,7 +779,8 @@ void WebRtcTransportImp::onRtcp(const char *buf, size_t len) {
|
||||
});
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -791,7 +801,8 @@ void WebRtcTransportImp::onRtcp(const char *buf, size_t len) {
|
||||
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -802,9 +813,9 @@ void WebRtcTransportImp::createRtpChannel(const string &rid, uint32_t ssrc, Medi
|
||||
// rid --> RtpReceiverImp
|
||||
auto &ref = track.rtp_channel[rid];
|
||||
weak_ptr<WebRtcTransportImp> weak_self = dynamic_pointer_cast<WebRtcTransportImp>(shared_from_this());
|
||||
ref = std::make_shared<RtpChannel>(getPoller(), [&track, this, rid](RtpPacket::Ptr rtp) mutable {
|
||||
onSortedRtp(track, rid, std::move(rtp));
|
||||
}, [&track, weak_self, ssrc](const FCI_NACK &nack) mutable {
|
||||
ref = std::make_shared<RtpChannel>(
|
||||
getPoller(), [&track, this, rid](RtpPacket::Ptr rtp) mutable { onSortedRtp(track, rid, std::move(rtp)); },
|
||||
[&track, weak_self, ssrc](const FCI_NACK &nack) mutable {
|
||||
// nack发送可能由定时器异步触发
|
||||
auto strong_self = weak_self.lock();
|
||||
if (strong_self) {
|
||||
@ -868,7 +879,8 @@ void WrappedRtxTrack::inputRtp(const char *buf, size_t len, uint64_t stamp_ms, R
|
||||
auto &ref = track->rtp_channel[rid];
|
||||
if (!ref) {
|
||||
// 再接收到对应的rtp前,丢弃rtx包
|
||||
WarnL << "unknown rtx rtp, rid:" << rid << ", ssrc:" << ntohl(rtp->ssrc) << ", codec:" << track->plan_rtp->codec << ", seq:" << ntohs(rtp->seq);
|
||||
WarnL << "unknown rtx rtp, rid:" << rid << ", ssrc:" << ntohl(rtp->ssrc) << ", codec:" << track->plan_rtp->codec
|
||||
<< ", seq:" << ntohs(rtp->seq);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -935,7 +947,9 @@ void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool r
|
||||
}
|
||||
if (!rtx) {
|
||||
// 统计rtp发送情况,好做sr汇报
|
||||
track->rtcp_context_send->onRtp(rtp->getSeq(), rtp->getStamp(), rtp->ntp_stamp, rtp->sample_rate, rtp->size() - RtpPacket::kRtpTcpHeaderSize);
|
||||
track->rtcp_context_send->onRtp(
|
||||
rtp->getSeq(), rtp->getStamp(), rtp->ntp_stamp, rtp->sample_rate,
|
||||
rtp->size() - RtpPacket::kRtpTcpHeaderSize);
|
||||
track->nack_list.pushBack(rtp);
|
||||
#if 0
|
||||
//此处模拟发送丢包
|
||||
@ -1005,8 +1019,9 @@ void WebRtcTransportImp::onShutdown(const SockException &ex){
|
||||
void WebRtcTransportImp::setSession(Session::Ptr session) {
|
||||
_history_sessions.emplace(session.get(), session);
|
||||
if (_selected_session) {
|
||||
InfoL << "rtc network changed: " << _selected_session->get_peer_ip() << ":" << _selected_session->get_peer_port()
|
||||
<< " -> " << session->get_peer_ip() << ":" << session->get_peer_port() << ", id:" << getIdentifier();
|
||||
InfoL << "rtc network changed: " << _selected_session->get_peer_ip() << ":"
|
||||
<< _selected_session->get_peer_port() << " -> " << session->get_peer_ip() << ":"
|
||||
<< session->get_peer_port() << ", id:" << getIdentifier();
|
||||
}
|
||||
_selected_session = std::move(session);
|
||||
unrefSelf();
|
||||
@ -1079,8 +1094,8 @@ void WebRtcPluginManager::registerPlugin(const string &type, Plugin cb) {
|
||||
_map_creator[type] = std::move(cb);
|
||||
}
|
||||
|
||||
void WebRtcPluginManager::getAnswerSdp(Session &sender, const string &type, const string &offer, const WebRtcArgs &args,
|
||||
const onCreateRtc &cb) {
|
||||
void WebRtcPluginManager::getAnswerSdp(
|
||||
Session &sender, const string &type, const string &offer, const WebRtcArgs &args, const onCreateRtc &cb) {
|
||||
lock_guard<mutex> lck(_mtx_creator);
|
||||
auto it = _map_creator.find(type);
|
||||
if (it == _map_creator.end()) {
|
||||
@ -1090,17 +1105,20 @@ void WebRtcPluginManager::getAnswerSdp(Session &sender, const string &type, cons
|
||||
it->second(sender, offer, args, cb);
|
||||
}
|
||||
|
||||
#include "WebRtcEchoTest.h"
|
||||
#include "WebRtcPlayer.h"
|
||||
#include "WebRtcPusher.h"
|
||||
#include "WebRtcEchoTest.h"
|
||||
|
||||
void echo_plugin(Session &sender, const string &offer, const WebRtcArgs &args, const WebRtcPluginManager::onCreateRtc &cb) {
|
||||
void echo_plugin(
|
||||
Session &sender, const string &offer, const WebRtcArgs &args, const WebRtcPluginManager::onCreateRtc &cb) {
|
||||
cb(*WebRtcEchoTest::create(EventPollerPool::Instance().getPoller()));
|
||||
}
|
||||
|
||||
void push_plugin(Session &sender, const string &offer_sdp, const WebRtcArgs &args, const WebRtcPluginManager::onCreateRtc &cb) {
|
||||
void push_plugin(
|
||||
Session &sender, const string &offer_sdp, const WebRtcArgs &args, const WebRtcPluginManager::onCreateRtc &cb) {
|
||||
MediaInfo info(args["url"]);
|
||||
Broadcast::PublishAuthInvoker invoker = [cb, offer_sdp, info](const string &err, const ProtocolOption &option) mutable {
|
||||
Broadcast::PublishAuthInvoker invoker = [cb, offer_sdp,
|
||||
info](const string &err, const ProtocolOption &option) mutable {
|
||||
if (!err.empty()) {
|
||||
cb(WebRtcException(SockException(Err_other, err)));
|
||||
return;
|
||||
@ -1139,20 +1157,23 @@ void push_plugin(Session &sender, const string &offer_sdp, const WebRtcArgs &arg
|
||||
push_src_ownership = push_src->getOwnership();
|
||||
push_src->setProtocolOption(option);
|
||||
}
|
||||
auto rtc = WebRtcPusher::create(EventPollerPool::Instance().getPoller(), push_src, push_src_ownership, info, option);
|
||||
auto rtc
|
||||
= WebRtcPusher::create(EventPollerPool::Instance().getPoller(), push_src, push_src_ownership, info, option);
|
||||
push_src->setListener(rtc);
|
||||
cb(*rtc);
|
||||
};
|
||||
|
||||
// rtsp推流需要鉴权
|
||||
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPublish, MediaOriginType::rtc_push, info, invoker, static_cast<SockInfo &>(sender));
|
||||
auto flag = NoticeCenter::Instance().emitEvent(
|
||||
Broadcast::kBroadcastMediaPublish, MediaOriginType::rtc_push, info, invoker, static_cast<SockInfo &>(sender));
|
||||
if (!flag) {
|
||||
// 该事件无人监听,默认不鉴权
|
||||
invoker("", ProtocolOption());
|
||||
}
|
||||
}
|
||||
|
||||
void play_plugin(Session &sender, const string &offer_sdp, const WebRtcArgs &args, const WebRtcPluginManager::onCreateRtc &cb) {
|
||||
void play_plugin(
|
||||
Session &sender, const string &offer_sdp, const WebRtcArgs &args, const WebRtcPluginManager::onCreateRtc &cb) {
|
||||
MediaInfo info(args["url"]);
|
||||
auto session_ptr = sender.shared_from_this();
|
||||
Broadcast::AuthInvoker invoker = [cb, offer_sdp, info, session_ptr](const string &err) mutable {
|
||||
@ -1177,7 +1198,8 @@ void play_plugin(Session &sender, const string &offer_sdp, const WebRtcArgs &arg
|
||||
};
|
||||
|
||||
// 广播通用播放url鉴权事件
|
||||
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed, info, invoker, static_cast<SockInfo &>(sender));
|
||||
auto flag = NoticeCenter::Instance().emitEvent(
|
||||
Broadcast::kBroadcastMediaPlayed, info, invoker, static_cast<SockInfo &>(sender));
|
||||
if (!flag) {
|
||||
// 该事件无人监听,默认不鉴权
|
||||
invoker("");
|
||||
|
Loading…
Reference in New Issue
Block a user