Skip to content

Commit 3b90ae6

Browse files
committed
Fix crash when process rtcp feedback message
1 parent 7f997b3 commit 3b90ae6

File tree

4 files changed

+46
-63
lines changed

4 files changed

+46
-63
lines changed

trunk/src/app/srs_app_rtc_conn.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ srs_error_t SrsRtcPlayStream::on_rtcp(SrsRtcpCommon* rtcp)
786786
SrsRtcpNack* nack = dynamic_cast<SrsRtcpNack*>(rtcp);
787787
return on_rtcp_nack(nack);
788788
} else if(SrsRtcpType_psfb == rtcp->type()) {
789-
SrsRtcpPsfbCommon* psfb = dynamic_cast<SrsRtcpPsfbCommon*>(rtcp);
789+
SrsRtcpFbCommon* psfb = dynamic_cast<SrsRtcpFbCommon*>(rtcp);
790790
return on_rtcp_ps_feedback(psfb);
791791
} else if(SrsRtcpType_xr == rtcp->type()) {
792792
SrsRtcpXr* xr = dynamic_cast<SrsRtcpXr*>(rtcp);
@@ -866,7 +866,7 @@ srs_error_t SrsRtcPlayStream::on_rtcp_nack(SrsRtcpNack* rtcp)
866866
return err;
867867
}
868868

869-
srs_error_t SrsRtcPlayStream::on_rtcp_ps_feedback(SrsRtcpPsfbCommon* rtcp)
869+
srs_error_t SrsRtcPlayStream::on_rtcp_ps_feedback(SrsRtcpFbCommon* rtcp)
870870
{
871871
srs_error_t err = srs_success;
872872

@@ -2064,7 +2064,7 @@ srs_error_t SrsRtcConnection::dispatch_rtcp(SrsRtcpCommon* rtcp)
20642064

20652065
// For REMB packet.
20662066
if (SrsRtcpType_psfb == rtcp->type()) {
2067-
SrsRtcpPsfbCommon* psfb = dynamic_cast<SrsRtcpPsfbCommon*>(rtcp);
2067+
SrsRtcpFbCommon* psfb = dynamic_cast<SrsRtcpFbCommon*>(rtcp);
20682068
if (15 == psfb->get_rc()) {
20692069
return on_rtcp_feedback_remb(psfb);
20702070
}
@@ -2092,7 +2092,7 @@ srs_error_t SrsRtcConnection::dispatch_rtcp(SrsRtcpCommon* rtcp)
20922092
required_player_ssrc = nack->get_media_ssrc();
20932093
}
20942094
} else if(SrsRtcpType_psfb == rtcp->type()) {
2095-
SrsRtcpPsfbCommon* psfb = dynamic_cast<SrsRtcpPsfbCommon*>(rtcp);
2095+
SrsRtcpFbCommon* psfb = dynamic_cast<SrsRtcpFbCommon*>(rtcp);
20962096
required_player_ssrc = psfb->get_media_ssrc();
20972097
}
20982098

@@ -2141,7 +2141,7 @@ srs_error_t SrsRtcConnection::on_rtcp_feedback_twcc(char* data, int nb_data)
21412141
return srs_success;
21422142
}
21432143

2144-
srs_error_t SrsRtcConnection::on_rtcp_feedback_remb(SrsRtcpPsfbCommon *rtcp)
2144+
srs_error_t SrsRtcConnection::on_rtcp_feedback_remb(SrsRtcpFbCommon *rtcp)
21452145
{
21462146
//ignore REMB
21472147
return srs_success;

trunk/src/app/srs_app_rtc_conn.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class SrsRtcPlayStream : public ISrsCoroutineHandler, public ISrsReloadHandler
269269
private:
270270
srs_error_t on_rtcp_xr(SrsRtcpXr* rtcp);
271271
srs_error_t on_rtcp_nack(SrsRtcpNack* rtcp);
272-
srs_error_t on_rtcp_ps_feedback(SrsRtcpPsfbCommon* rtcp);
272+
srs_error_t on_rtcp_ps_feedback(SrsRtcpFbCommon* rtcp);
273273
srs_error_t on_rtcp_rr(SrsRtcpRR* rtcp);
274274
uint32_t get_video_publish_ssrc(uint32_t play_ssrc);
275275
// Interface ISrsRtcPLIWorkerHandler
@@ -513,7 +513,7 @@ class SrsRtcConnection : public ISrsResource, public ISrsDisposingHandler, publi
513513
srs_error_t dispatch_rtcp(SrsRtcpCommon* rtcp);
514514
public:
515515
srs_error_t on_rtcp_feedback_twcc(char* buf, int nb_buf);
516-
srs_error_t on_rtcp_feedback_remb(SrsRtcpPsfbCommon *rtcp);
516+
srs_error_t on_rtcp_feedback_remb(SrsRtcpFbCommon *rtcp);
517517
public:
518518
srs_error_t on_dtls_handshake_done();
519519
srs_error_t on_dtls_alert(std::string type, std::string desc);

trunk/src/kernel/srs_kernel_rtc_rtcp.cpp

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -717,10 +717,6 @@ void SrsRtcpTWCC::clear()
717717
next_base_sn_ = 0;
718718
}
719719

720-
uint32_t SrsRtcpTWCC::get_media_ssrc() const
721-
{
722-
return media_ssrc_;
723-
}
724720
uint16_t SrsRtcpTWCC::get_base_sn() const
725721
{
726722
return base_sn_;
@@ -746,10 +742,6 @@ vector<uint16_t> SrsRtcpTWCC::get_recv_deltas() const
746742
return pkt_deltas_;
747743
}
748744

749-
void SrsRtcpTWCC::set_media_ssrc(uint32_t ssrc)
750-
{
751-
media_ssrc_ = ssrc;
752-
}
753745
void SrsRtcpTWCC::set_base_sn(uint16_t sn)
754746
{
755747
base_sn_ = sn;
@@ -1217,11 +1209,6 @@ SrsRtcpNack::~SrsRtcpNack()
12171209
{
12181210
}
12191211

1220-
uint32_t SrsRtcpNack::get_media_ssrc() const
1221-
{
1222-
return media_ssrc_;
1223-
}
1224-
12251212
vector<uint16_t> SrsRtcpNack::get_lost_sns() const
12261213
{
12271214
vector<uint16_t> sn;
@@ -1236,11 +1223,6 @@ bool SrsRtcpNack::empty()
12361223
return lost_sns_.empty();
12371224
}
12381225

1239-
void SrsRtcpNack::set_media_ssrc(uint32_t ssrc)
1240-
{
1241-
media_ssrc_ = ssrc;
1242-
}
1243-
12441226
void SrsRtcpNack::add_lost_sn(uint16_t sn)
12451227
{
12461228
lost_sns_.insert(sn);
@@ -1377,7 +1359,7 @@ srs_error_t SrsRtcpNack::encode(SrsBuffer *buffer)
13771359
return err;
13781360
}
13791361

1380-
SrsRtcpPsfbCommon::SrsRtcpPsfbCommon()
1362+
SrsRtcpFbCommon::SrsRtcpFbCommon()
13811363
{
13821364
header_.padding = 0;
13831365
header_.type = SrsRtcpType_psfb;
@@ -1386,22 +1368,22 @@ SrsRtcpPsfbCommon::SrsRtcpPsfbCommon()
13861368
//ssrc_ = sender_ssrc;
13871369
}
13881370

1389-
SrsRtcpPsfbCommon::~SrsRtcpPsfbCommon()
1371+
SrsRtcpFbCommon::~SrsRtcpFbCommon()
13901372
{
13911373

13921374
}
13931375

1394-
uint32_t SrsRtcpPsfbCommon::get_media_ssrc() const
1376+
uint32_t SrsRtcpFbCommon::get_media_ssrc() const
13951377
{
13961378
return media_ssrc_;
13971379
}
13981380

1399-
void SrsRtcpPsfbCommon::set_media_ssrc(uint32_t ssrc)
1381+
void SrsRtcpFbCommon::set_media_ssrc(uint32_t ssrc)
14001382
{
14011383
media_ssrc_ = ssrc;
14021384
}
14031385

1404-
srs_error_t SrsRtcpPsfbCommon::decode(SrsBuffer *buffer)
1386+
srs_error_t SrsRtcpFbCommon::decode(SrsBuffer *buffer)
14051387
{
14061388
/*
14071389
@doc: https://tools.ietf.org/html/rfc4585#section-6.1
@@ -1432,12 +1414,12 @@ srs_error_t SrsRtcpPsfbCommon::decode(SrsBuffer *buffer)
14321414
return err;
14331415
}
14341416

1435-
uint64_t SrsRtcpPsfbCommon::nb_bytes()
1417+
uint64_t SrsRtcpFbCommon::nb_bytes()
14361418
{
14371419
return kRtcpPacketSize;
14381420
}
14391421

1440-
srs_error_t SrsRtcpPsfbCommon::encode(SrsBuffer *buffer)
1422+
srs_error_t SrsRtcpFbCommon::encode(SrsBuffer *buffer)
14411423
{
14421424
return srs_error_new(ERROR_RTC_RTCP, "not support");
14431425
}
@@ -1762,6 +1744,9 @@ srs_error_t SrsRtcpCompound::decode(SrsBuffer *buffer)
17621744
} else if (15 == header->rc) {
17631745
//twcc
17641746
rtcp = new SrsRtcpTWCC();
1747+
} else {
1748+
// common fb
1749+
rtcp = new SrsRtcpFbCommon();
17651750
}
17661751
} else if(header->type == SrsRtcpType_psfb) {
17671752
if(1 == header->rc) {
@@ -1775,7 +1760,7 @@ srs_error_t SrsRtcpCompound::decode(SrsBuffer *buffer)
17751760
rtcp = new SrsRtcpRpsi();
17761761
} else {
17771762
// common psfb
1778-
rtcp = new SrsRtcpPsfbCommon();
1763+
rtcp = new SrsRtcpFbCommon();
17791764
}
17801765
} else if(header->type == SrsRtcpType_xr) {
17811766
rtcp = new SrsRtcpXr();

trunk/src/kernel/srs_kernel_rtc_rtcp.hpp

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,28 @@ class SrsRtcpRR : public SrsRtcpCommon
206206

207207
};
208208

209+
// @doc: https://tools.ietf.org/html/rfc4585#section-6.1
210+
// As RFC 4585 says, all FB messages MUST use a common packet format,
211+
// inlucde Transport layer FB message and Payload-specific FB message.
212+
class SrsRtcpFbCommon : public SrsRtcpCommon
213+
{
214+
protected:
215+
uint32_t media_ssrc_;
216+
public:
217+
SrsRtcpFbCommon();
218+
virtual ~SrsRtcpFbCommon();
219+
220+
uint32_t get_media_ssrc() const;
221+
void set_media_ssrc(uint32_t ssrc);
222+
223+
// interface ISrsCodec
224+
public:
225+
virtual srs_error_t decode(SrsBuffer *buffer);
226+
virtual uint64_t nb_bytes();
227+
virtual srs_error_t encode(SrsBuffer *buffer);
228+
};
229+
230+
209231
// The Message format of TWCC, @see https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01#section-3.1
210232
// 0 1 2 3
211233
// 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
@@ -247,10 +269,9 @@ class SrsRtcpRR : public SrsRtcpCommon
247269
#define kTwccFbLargeRecvDeltaBytes 2
248270
#define kTwccFbMaxBitElements kTwccFbOneBitElements
249271

250-
class SrsRtcpTWCC : public SrsRtcpCommon
272+
class SrsRtcpTWCC : public SrsRtcpFbCommon
251273
{
252274
private:
253-
uint32_t media_ssrc_;
254275
uint16_t base_sn_;
255276
int32_t reference_time_;
256277
uint8_t fb_pkt_count_;
@@ -286,14 +307,12 @@ class SrsRtcpTWCC : public SrsRtcpCommon
286307
SrsRtcpTWCC(uint32_t sender_ssrc = 0);
287308
virtual ~SrsRtcpTWCC();
288309

289-
uint32_t get_media_ssrc() const;
290310
uint16_t get_base_sn() const;
291311
uint32_t get_reference_time() const;
292312
uint8_t get_feedback_count() const;
293313
std::vector<uint16_t> get_packet_chucks() const;
294314
std::vector<uint16_t> get_recv_deltas() const;
295315

296-
void set_media_ssrc(uint32_t ssrc);
297316
void set_base_sn(uint16_t sn);
298317
void set_reference_time(uint32_t time);
299318
void set_feedback_count(uint8_t count);
@@ -312,7 +331,7 @@ class SrsRtcpTWCC : public SrsRtcpCommon
312331
srs_error_t do_encode(SrsBuffer *buffer);
313332
};
314333

315-
class SrsRtcpNack : public SrsRtcpCommon
334+
class SrsRtcpNack : public SrsRtcpFbCommon
316335
{
317336
private:
318337
struct SrsPidBlp {
@@ -321,17 +340,14 @@ class SrsRtcpNack : public SrsRtcpCommon
321340
bool in_use;
322341
};
323342

324-
uint32_t media_ssrc_;
325343
std::set<uint16_t, SrsSeqCompareLess> lost_sns_;
326344
public:
327345
SrsRtcpNack(uint32_t sender_ssrc = 0);
328346
virtual ~SrsRtcpNack();
329347

330-
uint32_t get_media_ssrc() const;
331348
std::vector<uint16_t> get_lost_sns() const;
332349
bool empty();
333350

334-
void set_media_ssrc(uint32_t ssrc);
335351
void add_lost_sn(uint16_t sn);
336352
// interface ISrsCodec
337353
public:
@@ -340,25 +356,7 @@ class SrsRtcpNack : public SrsRtcpCommon
340356
virtual srs_error_t encode(SrsBuffer *buffer);
341357
};
342358

343-
class SrsRtcpPsfbCommon : public SrsRtcpCommon
344-
{
345-
protected:
346-
uint32_t media_ssrc_;
347-
public:
348-
SrsRtcpPsfbCommon();
349-
virtual ~SrsRtcpPsfbCommon();
350-
351-
uint32_t get_media_ssrc() const;
352-
void set_media_ssrc(uint32_t ssrc);
353-
354-
// interface ISrsCodec
355-
public:
356-
virtual srs_error_t decode(SrsBuffer *buffer);
357-
virtual uint64_t nb_bytes();
358-
virtual srs_error_t encode(SrsBuffer *buffer);
359-
};
360-
361-
class SrsRtcpPli : public SrsRtcpPsfbCommon
359+
class SrsRtcpPli : public SrsRtcpFbCommon
362360
{
363361
public:
364362
SrsRtcpPli(uint32_t sender_ssrc = 0);
@@ -371,7 +369,7 @@ class SrsRtcpPli : public SrsRtcpPsfbCommon
371369
virtual srs_error_t encode(SrsBuffer *buffer);
372370
};
373371

374-
class SrsRtcpSli : public SrsRtcpPsfbCommon
372+
class SrsRtcpSli : public SrsRtcpFbCommon
375373
{
376374
private:
377375
uint16_t first_;
@@ -388,7 +386,7 @@ class SrsRtcpSli : public SrsRtcpPsfbCommon
388386
virtual srs_error_t encode(SrsBuffer *buffer);
389387
};
390388

391-
class SrsRtcpRpsi : public SrsRtcpPsfbCommon
389+
class SrsRtcpRpsi : public SrsRtcpFbCommon
392390
{
393391
private:
394392
uint8_t pb_;
@@ -407,7 +405,7 @@ class SrsRtcpRpsi : public SrsRtcpPsfbCommon
407405
virtual srs_error_t encode(SrsBuffer *buffer);
408406
};
409407

410-
class SrsRtcpXr : public SrsRtcpCommon
408+
class SrsRtcpXr : public SrsRtcpFbCommon
411409
{
412410
public:
413411
SrsRtcpXr (uint32_t ssrc = 0);

0 commit comments

Comments
 (0)