mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Refactor code
This commit is contained in:
parent
23ddcbdaed
commit
e3d010113f
5 changed files with 47 additions and 25 deletions
|
@ -183,10 +183,6 @@ SrsRtpNackInfo::SrsRtpNackInfo()
|
||||||
req_nack_count_ = 0;
|
req_nack_count_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsRtpNackForReceiver::SeqComp::operator()(const uint16_t& pre_value, const uint16_t& value) const {
|
|
||||||
return srs_rtp_seq_distance(pre_value, value) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SrsRtpNackForReceiver::SrsRtpNackForReceiver(SrsRtpRingBuffer* rtp, size_t queue_size)
|
SrsRtpNackForReceiver::SrsRtpNackForReceiver(SrsRtpRingBuffer* rtp, size_t queue_size)
|
||||||
{
|
{
|
||||||
max_queue_size_ = queue_size;
|
max_queue_size_ = queue_size;
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include <srs_kernel_rtc_rtp.hpp>
|
||||||
|
|
||||||
class SrsRtpPacket2;
|
class SrsRtpPacket2;
|
||||||
class SrsRtpQueue;
|
class SrsRtpQueue;
|
||||||
class SrsRtpRingBuffer;
|
class SrsRtpRingBuffer;
|
||||||
|
@ -111,13 +113,9 @@ struct SrsRtpNackInfo
|
||||||
|
|
||||||
class SrsRtpNackForReceiver
|
class SrsRtpNackForReceiver
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
struct SeqComp {
|
|
||||||
bool operator()(const uint16_t& pre_value, const uint16_t& value) const;
|
|
||||||
};
|
|
||||||
private:
|
private:
|
||||||
// Nack queue, seq order, oldest to newest.
|
// Nack queue, seq order, oldest to newest.
|
||||||
std::map<uint16_t, SrsRtpNackInfo, SeqComp> queue_;
|
std::map<uint16_t, SrsRtpNackInfo, SrsSeqCompareLess> queue_;
|
||||||
// Max nack count.
|
// Max nack count.
|
||||||
size_t max_queue_size_;
|
size_t max_queue_size_;
|
||||||
SrsRtpRingBuffer* rtp_;
|
SrsRtpRingBuffer* rtp_;
|
||||||
|
|
|
@ -36,6 +36,11 @@ SrsRtcpCommon::~SrsRtcpCommon()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uint8_t SrsRtcpCommon::type() const
|
||||||
|
{
|
||||||
|
return header_.type;
|
||||||
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcpCommon::decode_header(SrsBuffer *buffer)
|
srs_error_t SrsRtcpCommon::decode_header(SrsBuffer *buffer)
|
||||||
{
|
{
|
||||||
buffer->read_bytes((char*)(&header_), sizeof(SrsRtcpHeader));
|
buffer->read_bytes((char*)(&header_), sizeof(SrsRtcpHeader));
|
||||||
|
@ -84,6 +89,11 @@ SrsRtcpApp::~SrsRtcpApp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uint8_t SrsRtcpApp::type() const
|
||||||
|
{
|
||||||
|
return SrsRtcpType_app;
|
||||||
|
}
|
||||||
|
|
||||||
const uint32_t SrsRtcpApp::get_ssrc() const
|
const uint32_t SrsRtcpApp::get_ssrc() const
|
||||||
{
|
{
|
||||||
return ssrc_;
|
return ssrc_;
|
||||||
|
@ -200,7 +210,16 @@ SrsRtcpSR::SrsRtcpSR()
|
||||||
|
|
||||||
SrsRtcpSR::~SrsRtcpSR()
|
SrsRtcpSR::~SrsRtcpSR()
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t SrsRtcpSR::get_rc() const
|
||||||
|
{
|
||||||
|
return header_.rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t SrsRtcpSR::type() const
|
||||||
|
{
|
||||||
|
return SrsRtcpType_sr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t SrsRtcpSR::get_sender_ssrc() const
|
const uint32_t SrsRtcpSR::get_sender_ssrc() const
|
||||||
|
@ -314,6 +333,11 @@ SrsRtcpRR::~SrsRtcpRR()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uint8_t SrsRtcpRR::type() const
|
||||||
|
{
|
||||||
|
return SrsRtcpType_rr;
|
||||||
|
}
|
||||||
|
|
||||||
const uint32_t SrsRtcpRR::get_rb_ssrc() const
|
const uint32_t SrsRtcpRR::get_rb_ssrc() const
|
||||||
{
|
{
|
||||||
return rb_.ssrc;
|
return rb_.ssrc;
|
||||||
|
|
|
@ -26,17 +26,19 @@
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <srs_kernel_buffer.hpp>
|
|
||||||
#include <srs_kernel_rtc_rtp.hpp>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include <srs_kernel_buffer.hpp>
|
||||||
|
#include <srs_kernel_rtc_rtp.hpp>
|
||||||
|
|
||||||
const int kRtcpPacketSize = 1500;
|
const int kRtcpPacketSize = 1500;
|
||||||
const uint8_t kRtcpVersion = 0x2;
|
const uint8_t kRtcpVersion = 0x2;
|
||||||
|
|
||||||
// RTCP Packet Types, @see http://www.networksorcery.com/enp/protocol/rtcp.htm
|
// RTCP Packet Types, @see http://www.networksorcery.com/enp/protocol/rtcp.htm
|
||||||
enum SrsRtcpType {
|
enum SrsRtcpType
|
||||||
|
{
|
||||||
SrsRtcpType_fir = 192,
|
SrsRtcpType_fir = 192,
|
||||||
SrsRtcpType_sr = 200,
|
SrsRtcpType_sr = 200,
|
||||||
SrsRtcpType_rr = 201,
|
SrsRtcpType_rr = 201,
|
||||||
|
@ -59,12 +61,6 @@ struct SrsRtcpHeader
|
||||||
uint16_t length:16;
|
uint16_t length:16;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SrsSeqCompareLess {
|
|
||||||
bool operator()(const uint16_t &lhs, const uint16_t &rhs) const {
|
|
||||||
return srs_seq_is_newer(rhs, lhs);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class SrsRtcpCommon: public ISrsCodec
|
class SrsRtcpCommon: public ISrsCodec
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
@ -78,7 +74,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
SrsRtcpCommon();
|
SrsRtcpCommon();
|
||||||
virtual ~SrsRtcpCommon();
|
virtual ~SrsRtcpCommon();
|
||||||
virtual const uint8_t type() const { return header_.type; }
|
virtual const uint8_t type() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// ISrsCodec
|
// ISrsCodec
|
||||||
|
@ -98,7 +94,7 @@ public:
|
||||||
SrsRtcpApp();
|
SrsRtcpApp();
|
||||||
virtual ~SrsRtcpApp();
|
virtual ~SrsRtcpApp();
|
||||||
|
|
||||||
virtual const uint8_t type() const { return SrsRtcpType_app; }
|
virtual const uint8_t type() const;
|
||||||
|
|
||||||
const uint32_t get_ssrc() const;
|
const uint32_t get_ssrc() const;
|
||||||
const uint8_t get_subtype() const;
|
const uint8_t get_subtype() const;
|
||||||
|
@ -116,7 +112,8 @@ public:
|
||||||
virtual srs_error_t encode(SrsBuffer *buffer);
|
virtual srs_error_t encode(SrsBuffer *buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct srs_rtcp_rb_t {
|
struct SrsRtcpRB
|
||||||
|
{
|
||||||
uint32_t ssrc;
|
uint32_t ssrc;
|
||||||
uint8_t fraction_lost;
|
uint8_t fraction_lost;
|
||||||
uint32_t lost_packets;
|
uint32_t lost_packets;
|
||||||
|
@ -138,9 +135,9 @@ public:
|
||||||
SrsRtcpSR();
|
SrsRtcpSR();
|
||||||
virtual ~SrsRtcpSR();
|
virtual ~SrsRtcpSR();
|
||||||
|
|
||||||
const uint8_t get_rc() const { return header_.rc; }
|
const uint8_t get_rc() const;
|
||||||
// overload SrsRtcpCommon
|
// overload SrsRtcpCommon
|
||||||
virtual const uint8_t type() const { return SrsRtcpType_sr; }
|
virtual const uint8_t type() const;
|
||||||
const uint32_t get_sender_ssrc() const;
|
const uint32_t get_sender_ssrc() const;
|
||||||
const uint64_t get_ntp() const;
|
const uint64_t get_ntp() const;
|
||||||
const uint32_t get_rtp_ts() const;
|
const uint32_t get_rtp_ts() const;
|
||||||
|
@ -164,13 +161,13 @@ class SrsRtcpRR : public SrsRtcpCommon
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
uint32_t sender_ssrc_;
|
uint32_t sender_ssrc_;
|
||||||
srs_rtcp_rb_t rb_;
|
SrsRtcpRB rb_;
|
||||||
public:
|
public:
|
||||||
SrsRtcpRR(uint32_t sender_ssrc = 0);
|
SrsRtcpRR(uint32_t sender_ssrc = 0);
|
||||||
virtual ~SrsRtcpRR();
|
virtual ~SrsRtcpRR();
|
||||||
|
|
||||||
// overload SrsRtcpCommon
|
// overload SrsRtcpCommon
|
||||||
virtual const uint8_t type() const { return SrsRtcpType_rr; }
|
virtual const uint8_t type() const;
|
||||||
|
|
||||||
const uint32_t get_rb_ssrc() const;
|
const uint32_t get_rb_ssrc() const;
|
||||||
const float get_lost_rate() const;
|
const float get_lost_rate() const;
|
||||||
|
|
|
@ -71,6 +71,13 @@ inline int16_t srs_rtp_seq_distance(const uint16_t& prev_value, const uint16_t&
|
||||||
return (int16_t)(value - prev_value);
|
return (int16_t)(value - prev_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For map to compare the sequence of RTP.
|
||||||
|
struct SrsSeqCompareLess {
|
||||||
|
bool operator()(const uint16_t& pre_value, const uint16_t& value) const {
|
||||||
|
return srs_rtp_seq_distance(pre_value, value) > 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
bool srs_seq_is_newer(uint16_t value, uint16_t pre_value);
|
bool srs_seq_is_newer(uint16_t value, uint16_t pre_value);
|
||||||
bool srs_seq_is_roolback(uint16_t value, uint16_t pre_value);
|
bool srs_seq_is_roolback(uint16_t value, uint16_t pre_value);
|
||||||
int32_t srs_seq_distance(uint16_t value, uint16_t pre_value);
|
int32_t srs_seq_distance(uint16_t value, uint16_t pre_value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue