Skip to content

Commit

Permalink
Fix crash when process rtcp feedback message. v5.0.159, v6.0.52 (ossr…
Browse files Browse the repository at this point in the history
…s#3591)

---------

Co-authored-by: johzzy <hellojinqiang@gmail.com>
  • Loading branch information
xiaozhihong and johzzy committed Jun 25, 2023
1 parent d221286 commit e561c62
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 63 deletions.
10 changes: 5 additions & 5 deletions trunk/src/app/srs_app_rtc_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ srs_error_t SrsRtcPlayStream::on_rtcp(SrsRtcpCommon* rtcp)
SrsRtcpNack* nack = dynamic_cast<SrsRtcpNack*>(rtcp);
return on_rtcp_nack(nack);
} else if(SrsRtcpType_psfb == rtcp->type()) {
SrsRtcpPsfbCommon* psfb = dynamic_cast<SrsRtcpPsfbCommon*>(rtcp);
SrsRtcpFbCommon* psfb = dynamic_cast<SrsRtcpFbCommon*>(rtcp);
return on_rtcp_ps_feedback(psfb);
} else if(SrsRtcpType_xr == rtcp->type()) {
SrsRtcpXr* xr = dynamic_cast<SrsRtcpXr*>(rtcp);
Expand Down Expand Up @@ -1545,7 +1545,7 @@ srs_error_t SrsRtcPlayStream::on_rtcp_nack(SrsRtcpNack* rtcp)
return err;
}

srs_error_t SrsRtcPlayStream::on_rtcp_ps_feedback(SrsRtcpPsfbCommon* rtcp)
srs_error_t SrsRtcPlayStream::on_rtcp_ps_feedback(SrsRtcpFbCommon* rtcp)
{
srs_error_t err = srs_success;

Expand Down Expand Up @@ -3292,7 +3292,7 @@ srs_error_t SrsRtcConnection::dispatch_rtcp(SrsRtcpCommon* rtcp)

// For REMB packet.
if (SrsRtcpType_psfb == rtcp->type()) {
SrsRtcpPsfbCommon* psfb = dynamic_cast<SrsRtcpPsfbCommon*>(rtcp);
SrsRtcpFbCommon* psfb = dynamic_cast<SrsRtcpFbCommon*>(rtcp);
if (kAfbMessageType == psfb->get_rc()) {
return on_rtcp_feedback_remb(psfb);
}
Expand All @@ -3314,7 +3314,7 @@ srs_error_t SrsRtcConnection::dispatch_rtcp(SrsRtcpCommon* rtcp)
SrsRtcpRR* rr = dynamic_cast<SrsRtcpRR*>(rtcp);
required_player_ssrc = rr->get_rb_ssrc();
} else if(SrsRtcpType_psfb == rtcp->type()) {
SrsRtcpPsfbCommon* psfb = dynamic_cast<SrsRtcpPsfbCommon*>(rtcp);
SrsRtcpFbCommon* psfb = dynamic_cast<SrsRtcpFbCommon*>(rtcp);
required_player_ssrc = psfb->get_media_ssrc();
}

Expand Down Expand Up @@ -3419,7 +3419,7 @@ void CreateHeader(
constexpr uint32_t kUniqueIdentifier = 0x52454D42; // 'R' 'E' 'M' 'B'.


srs_error_t SrsRtcConnection::on_rtcp_feedback_remb(SrsRtcpPsfbCommon *rtcp)
srs_error_t SrsRtcConnection::on_rtcp_feedback_remb(SrsRtcpFbCommon *rtcp)
{
// Receiver Estimated Max Bitrate (REMB) (draft-alvestrand-rmcat-remb).
//
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_rtc_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class SrsRtcPlayStream : public ISrsCoroutineHandler, public ISrsReloadHandler
private:
srs_error_t on_rtcp_xr(SrsRtcpXr* rtcp);
srs_error_t on_rtcp_nack(SrsRtcpNack* rtcp);
srs_error_t on_rtcp_ps_feedback(SrsRtcpPsfbCommon* rtcp);
srs_error_t on_rtcp_ps_feedback(SrsRtcpFbCommon* rtcp);
srs_error_t on_rtcp_rr(SrsRtcpRR* rtcp);
uint32_t get_video_publish_ssrc(uint32_t play_ssrc);
// Interface ISrsRtcPLIWorkerHandler
Expand Down Expand Up @@ -587,7 +587,7 @@ class SrsRtcConnection : public ISrsResource, public ISrsDisposingHandler, publi
srs_error_t dispatch_rtcp(SrsRtcpCommon* rtcp);
public:
srs_error_t on_rtcp_feedback_twcc(char* buf, int nb_buf);
srs_error_t on_rtcp_feedback_remb(SrsRtcpPsfbCommon *rtcp);
srs_error_t on_rtcp_feedback_remb(SrsRtcpFbCommon *rtcp);
public:
void set_hijacker(ISrsRtcConnectionHijacker* h);
public:
Expand Down
36 changes: 10 additions & 26 deletions trunk/src/kernel/srs_kernel_rtc_rtcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,6 @@ void SrsRtcpTWCC::clear()
next_base_sn_ = 0;
}

uint32_t SrsRtcpTWCC::get_media_ssrc() const
{
return media_ssrc_;
}
uint16_t SrsRtcpTWCC::get_base_sn() const
{
return base_sn_;
Expand All @@ -746,10 +742,6 @@ vector<uint16_t> SrsRtcpTWCC::get_recv_deltas() const
return pkt_deltas_;
}

void SrsRtcpTWCC::set_media_ssrc(uint32_t ssrc)
{
media_ssrc_ = ssrc;
}
void SrsRtcpTWCC::set_base_sn(uint16_t sn)
{
base_sn_ = sn;
Expand Down Expand Up @@ -1217,11 +1209,6 @@ SrsRtcpNack::~SrsRtcpNack()
{
}

uint32_t SrsRtcpNack::get_media_ssrc() const
{
return media_ssrc_;
}

vector<uint16_t> SrsRtcpNack::get_lost_sns() const
{
vector<uint16_t> sn;
Expand All @@ -1236,11 +1223,6 @@ bool SrsRtcpNack::empty()
return lost_sns_.empty();
}

void SrsRtcpNack::set_media_ssrc(uint32_t ssrc)
{
media_ssrc_ = ssrc;
}

void SrsRtcpNack::add_lost_sn(uint16_t sn)
{
lost_sns_.insert(sn);
Expand Down Expand Up @@ -1377,7 +1359,7 @@ srs_error_t SrsRtcpNack::encode(SrsBuffer *buffer)
return err;
}

SrsRtcpPsfbCommon::SrsRtcpPsfbCommon()
SrsRtcpFbCommon::SrsRtcpFbCommon()
{
header_.padding = 0;
header_.type = SrsRtcpType_psfb;
Expand All @@ -1386,22 +1368,22 @@ SrsRtcpPsfbCommon::SrsRtcpPsfbCommon()
//ssrc_ = sender_ssrc;
}

SrsRtcpPsfbCommon::~SrsRtcpPsfbCommon()
SrsRtcpFbCommon::~SrsRtcpFbCommon()
{

}

uint32_t SrsRtcpPsfbCommon::get_media_ssrc() const
uint32_t SrsRtcpFbCommon::get_media_ssrc() const
{
return media_ssrc_;
}

void SrsRtcpPsfbCommon::set_media_ssrc(uint32_t ssrc)
void SrsRtcpFbCommon::set_media_ssrc(uint32_t ssrc)
{
media_ssrc_ = ssrc;
}

srs_error_t SrsRtcpPsfbCommon::decode(SrsBuffer *buffer)
srs_error_t SrsRtcpFbCommon::decode(SrsBuffer *buffer)
{
/*
@doc: https://tools.ietf.org/html/rfc4585#section-6.1
Expand Down Expand Up @@ -1432,12 +1414,12 @@ srs_error_t SrsRtcpPsfbCommon::decode(SrsBuffer *buffer)
return err;
}

uint64_t SrsRtcpPsfbCommon::nb_bytes()
uint64_t SrsRtcpFbCommon::nb_bytes()
{
return kRtcpPacketSize;
}

srs_error_t SrsRtcpPsfbCommon::encode(SrsBuffer *buffer)
srs_error_t SrsRtcpFbCommon::encode(SrsBuffer *buffer)
{
return srs_error_new(ERROR_RTC_RTCP, "not support");
}
Expand Down Expand Up @@ -1767,6 +1749,8 @@ srs_error_t SrsRtcpCompound::decode(SrsBuffer *buffer)
// 1-Nack
// 15-TransportFeedback
srs_warn("rtcp_block.fmt=%d, 3-Tmmbr,4-Tmmbn,5-RapidResyncRequest", (int)header->rc);
// common fb
rtcp = new SrsRtcpFbCommon();
}
} else if(header->type == SrsRtcpType_psfb) {
if(1 == header->rc) {
Expand All @@ -1780,7 +1764,7 @@ srs_error_t SrsRtcpCompound::decode(SrsBuffer *buffer)
rtcp = new SrsRtcpRpsi();
} else {
// common psfb
rtcp = new SrsRtcpPsfbCommon();
rtcp = new SrsRtcpFbCommon();
}
} else if(header->type == SrsRtcpType_xr) {
rtcp = new SrsRtcpXr();
Expand Down
58 changes: 28 additions & 30 deletions trunk/src/kernel/srs_kernel_rtc_rtcp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,28 @@ class SrsRtcpRR : public SrsRtcpCommon

};

// @doc: https://tools.ietf.org/html/rfc4585#section-6.1
// As RFC 4585 says, all FB messages MUST use a common packet format,
// inlucde Transport layer FB message and Payload-specific FB message.
class SrsRtcpFbCommon : public SrsRtcpCommon
{
protected:
uint32_t media_ssrc_;
public:
SrsRtcpFbCommon();
virtual ~SrsRtcpFbCommon();

uint32_t get_media_ssrc() const;
void set_media_ssrc(uint32_t ssrc);

// interface ISrsCodec
public:
virtual srs_error_t decode(SrsBuffer *buffer);
virtual uint64_t nb_bytes();
virtual srs_error_t encode(SrsBuffer *buffer);
};


// The Message format of TWCC, @see https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01#section-3.1
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
Expand Down Expand Up @@ -247,10 +269,9 @@ class SrsRtcpRR : public SrsRtcpCommon
#define kTwccFbLargeRecvDeltaBytes 2
#define kTwccFbMaxBitElements kTwccFbOneBitElements

class SrsRtcpTWCC : public SrsRtcpCommon
class SrsRtcpTWCC : public SrsRtcpFbCommon
{
private:
uint32_t media_ssrc_;
uint16_t base_sn_;
int32_t reference_time_;
uint8_t fb_pkt_count_;
Expand Down Expand Up @@ -286,14 +307,12 @@ class SrsRtcpTWCC : public SrsRtcpCommon
SrsRtcpTWCC(uint32_t sender_ssrc = 0);
virtual ~SrsRtcpTWCC();

uint32_t get_media_ssrc() const;
uint16_t get_base_sn() const;
uint32_t get_reference_time() const;
uint8_t get_feedback_count() const;
std::vector<uint16_t> get_packet_chucks() const;
std::vector<uint16_t> get_recv_deltas() const;

void set_media_ssrc(uint32_t ssrc);
void set_base_sn(uint16_t sn);
void set_reference_time(uint32_t time);
void set_feedback_count(uint8_t count);
Expand All @@ -312,7 +331,7 @@ class SrsRtcpTWCC : public SrsRtcpCommon
srs_error_t do_encode(SrsBuffer *buffer);
};

class SrsRtcpNack : public SrsRtcpCommon
class SrsRtcpNack : public SrsRtcpFbCommon
{
private:
struct SrsPidBlp {
Expand All @@ -321,17 +340,14 @@ class SrsRtcpNack : public SrsRtcpCommon
bool in_use;
};

uint32_t media_ssrc_;
std::set<uint16_t, SrsSeqCompareLess> lost_sns_;
public:
SrsRtcpNack(uint32_t sender_ssrc = 0);
virtual ~SrsRtcpNack();

uint32_t get_media_ssrc() const;
std::vector<uint16_t> get_lost_sns() const;
bool empty();

void set_media_ssrc(uint32_t ssrc);
void add_lost_sn(uint16_t sn);
// interface ISrsCodec
public:
Expand All @@ -340,25 +356,7 @@ class SrsRtcpNack : public SrsRtcpCommon
virtual srs_error_t encode(SrsBuffer *buffer);
};

class SrsRtcpPsfbCommon : public SrsRtcpCommon
{
protected:
uint32_t media_ssrc_;
public:
SrsRtcpPsfbCommon();
virtual ~SrsRtcpPsfbCommon();

uint32_t get_media_ssrc() const;
void set_media_ssrc(uint32_t ssrc);

// interface ISrsCodec
public:
virtual srs_error_t decode(SrsBuffer *buffer);
virtual uint64_t nb_bytes();
virtual srs_error_t encode(SrsBuffer *buffer);
};

class SrsRtcpPli : public SrsRtcpPsfbCommon
class SrsRtcpPli : public SrsRtcpFbCommon
{
public:
SrsRtcpPli(uint32_t sender_ssrc = 0);
Expand All @@ -371,7 +369,7 @@ class SrsRtcpPli : public SrsRtcpPsfbCommon
virtual srs_error_t encode(SrsBuffer *buffer);
};

class SrsRtcpSli : public SrsRtcpPsfbCommon
class SrsRtcpSli : public SrsRtcpFbCommon
{
private:
uint16_t first_;
Expand All @@ -388,7 +386,7 @@ class SrsRtcpSli : public SrsRtcpPsfbCommon
virtual srs_error_t encode(SrsBuffer *buffer);
};

class SrsRtcpRpsi : public SrsRtcpPsfbCommon
class SrsRtcpRpsi : public SrsRtcpFbCommon
{
private:
uint8_t pb_;
Expand All @@ -407,7 +405,7 @@ class SrsRtcpRpsi : public SrsRtcpPsfbCommon
virtual srs_error_t encode(SrsBuffer *buffer);
};

class SrsRtcpXr : public SrsRtcpCommon
class SrsRtcpXr : public SrsRtcpFbCommon
{
public:
SrsRtcpXr (uint32_t ssrc = 0);
Expand Down

0 comments on commit e561c62

Please sign in to comment.