1
0
Fork 0
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:
winlin 2020-05-19 17:49:34 +08:00
parent 23ddcbdaed
commit e3d010113f
5 changed files with 47 additions and 25 deletions

View file

@ -183,10 +183,6 @@ SrsRtpNackInfo::SrsRtpNackInfo()
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)
{
max_queue_size_ = queue_size;

View file

@ -30,6 +30,8 @@
#include <vector>
#include <map>
#include <srs_kernel_rtc_rtp.hpp>
class SrsRtpPacket2;
class SrsRtpQueue;
class SrsRtpRingBuffer;
@ -111,13 +113,9 @@ struct SrsRtpNackInfo
class SrsRtpNackForReceiver
{
private:
struct SeqComp {
bool operator()(const uint16_t& pre_value, const uint16_t& value) const;
};
private:
// Nack queue, seq order, oldest to newest.
std::map<uint16_t, SrsRtpNackInfo, SeqComp> queue_;
std::map<uint16_t, SrsRtpNackInfo, SrsSeqCompareLess> queue_;
// Max nack count.
size_t max_queue_size_;
SrsRtpRingBuffer* rtp_;

View file

@ -36,6 +36,11 @@ SrsRtcpCommon::~SrsRtcpCommon()
{
}
const uint8_t SrsRtcpCommon::type() const
{
return header_.type;
}
srs_error_t SrsRtcpCommon::decode_header(SrsBuffer *buffer)
{
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
{
return ssrc_;
@ -200,7 +210,16 @@ 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
@ -314,6 +333,11 @@ SrsRtcpRR::~SrsRtcpRR()
{
}
const uint8_t SrsRtcpRR::type() const
{
return SrsRtcpType_rr;
}
const uint32_t SrsRtcpRR::get_rb_ssrc() const
{
return rb_.ssrc;

View file

@ -26,17 +26,19 @@
#include <srs_core.hpp>
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_rtc_rtp.hpp>
#include <vector>
#include <set>
#include <map>
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_rtc_rtp.hpp>
const int kRtcpPacketSize = 1500;
const uint8_t kRtcpVersion = 0x2;
// RTCP Packet Types, @see http://www.networksorcery.com/enp/protocol/rtcp.htm
enum SrsRtcpType {
enum SrsRtcpType
{
SrsRtcpType_fir = 192,
SrsRtcpType_sr = 200,
SrsRtcpType_rr = 201,
@ -59,12 +61,6 @@ struct SrsRtcpHeader
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
{
protected:
@ -78,7 +74,7 @@ protected:
public:
SrsRtcpCommon();
virtual ~SrsRtcpCommon();
virtual const uint8_t type() const { return header_.type; }
virtual const uint8_t type() const;
public:
// ISrsCodec
@ -98,7 +94,7 @@ public:
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 uint8_t get_subtype() const;
@ -116,7 +112,8 @@ public:
virtual srs_error_t encode(SrsBuffer *buffer);
};
struct srs_rtcp_rb_t {
struct SrsRtcpRB
{
uint32_t ssrc;
uint8_t fraction_lost;
uint32_t lost_packets;
@ -138,9 +135,9 @@ public:
SrsRtcpSR();
virtual ~SrsRtcpSR();
const uint8_t get_rc() const { return header_.rc; }
const uint8_t get_rc() const;
// 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 uint64_t get_ntp() const;
const uint32_t get_rtp_ts() const;
@ -164,13 +161,13 @@ class SrsRtcpRR : public SrsRtcpCommon
{
private:
uint32_t sender_ssrc_;
srs_rtcp_rb_t rb_;
SrsRtcpRB rb_;
public:
SrsRtcpRR(uint32_t sender_ssrc = 0);
virtual ~SrsRtcpRR();
// 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 float get_lost_rate() const;

View file

@ -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);
}
// 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_roolback(uint16_t value, uint16_t pre_value);
int32_t srs_seq_distance(uint16_t value, uint16_t pre_value);