@@ -392,8 +392,6 @@ SrsRtcPlayStream::SrsRtcPlayStream(SrsRtcConnection* s, const SrsContextId& cid)
392
392
393
393
SrsRtcPlayStream::~SrsRtcPlayStream ()
394
394
{
395
- _srs_hybrid->timer1s ()->unsubscribe (this );
396
-
397
395
// TODO: FIXME: Should not do callback in de-constructor?
398
396
if (_srs_rtc_hijacker) {
399
397
_srs_rtc_hijacker->on_stop_play (session_, this , req_);
@@ -534,10 +532,6 @@ srs_error_t SrsRtcPlayStream::start()
534
532
return srs_error_wrap (err, " rtc_sender" );
535
533
}
536
534
537
- // The timer for play, process TWCC in the future.
538
- // @see SrsRtcPlayStream::on_timer()
539
- _srs_hybrid->timer1s ()->subscribe (this );
540
-
541
535
if ((err = pli_worker_->start ()) != srs_success) {
542
536
return srs_error_wrap (err, " start pli worker" );
543
537
}
@@ -722,17 +716,6 @@ void SrsRtcPlayStream::set_all_tracks_status(bool status)
722
716
srs_trace (" RTC: Init tracks %s ok" , merged_log.str ().c_str ());
723
717
}
724
718
725
- srs_error_t SrsRtcPlayStream::on_timer (srs_utime_t interval)
726
- {
727
- srs_error_t err = srs_success;
728
-
729
- if (!is_started) {
730
- return err;
731
- }
732
-
733
- return err;
734
- }
735
-
736
719
srs_error_t SrsRtcPlayStream::on_rtcp (SrsRtcpCommon* rtcp)
737
720
{
738
721
if (SrsRtcpType_rr == rtcp->type ()) {
@@ -893,6 +876,85 @@ srs_error_t SrsRtcPlayStream::do_request_keyframe(uint32_t ssrc, SrsContextId ci
893
876
return err;
894
877
}
895
878
879
+ SrsRtcPublishRtcpTimer::SrsRtcPublishRtcpTimer (SrsRtcPublishStream* p) : p_(p)
880
+ {
881
+ _srs_hybrid->timer1s ()->subscribe (this );
882
+ }
883
+
884
+ SrsRtcPublishRtcpTimer::~SrsRtcPublishRtcpTimer ()
885
+ {
886
+ _srs_hybrid->timer1s ()->unsubscribe (this );
887
+ }
888
+
889
+ srs_error_t SrsRtcPublishRtcpTimer::on_timer (srs_utime_t interval)
890
+ {
891
+ srs_error_t err = srs_success;
892
+
893
+ ++_srs_pps_pub->sugar ;
894
+
895
+ if (!p_->is_started ) {
896
+ return err;
897
+ }
898
+
899
+ // For RR and RRTR.
900
+ ++_srs_pps_rr->sugar ;
901
+
902
+ if ((err = p_->send_rtcp_rr ()) != srs_success) {
903
+ srs_warn (" RR err %s" , srs_error_desc (err).c_str ());
904
+ srs_freep (err);
905
+ }
906
+
907
+ if ((err = p_->send_rtcp_xr_rrtr ()) != srs_success) {
908
+ srs_warn (" XR err %s" , srs_error_desc (err).c_str ());
909
+ srs_freep (err);
910
+ }
911
+
912
+ return err;
913
+ }
914
+
915
+ SrsRtcPublishTwccTimer::SrsRtcPublishTwccTimer (SrsRtcPublishStream* p) : p_(p)
916
+ {
917
+ _srs_hybrid->timer100ms ()->subscribe (this );
918
+ }
919
+
920
+ SrsRtcPublishTwccTimer::~SrsRtcPublishTwccTimer ()
921
+ {
922
+ _srs_hybrid->timer100ms ()->unsubscribe (this );
923
+ }
924
+
925
+ srs_error_t SrsRtcPublishTwccTimer::on_timer (srs_utime_t interval)
926
+ {
927
+ srs_error_t err = srs_success;
928
+
929
+ ++_srs_pps_pub->sugar ;
930
+
931
+ if (!p_->is_started ) {
932
+ return err;
933
+ }
934
+
935
+ // For TWCC feedback.
936
+ if (!p_->twcc_enabled_ ) {
937
+ return err;
938
+ }
939
+
940
+ ++_srs_pps_twcc->sugar ;
941
+
942
+ // If circuit-breaker is dropping packet, disable TWCC.
943
+ if (_srs_circuit_breaker->hybrid_critical_water_level ()) {
944
+ ++_srs_pps_snack4->sugar ;
945
+ return err;
946
+ }
947
+
948
+ // We should not depends on the received packet,
949
+ // instead we should send feedback every Nms.
950
+ if ((err = p_->send_periodic_twcc ()) != srs_success) {
951
+ srs_warn (" TWCC err %s" , srs_error_desc (err).c_str ());
952
+ srs_freep (err);
953
+ }
954
+
955
+ return err;
956
+ }
957
+
896
958
SrsRtcPublishStream::SrsRtcPublishStream (SrsRtcConnection* session, const SrsContextId& cid)
897
959
{
898
960
cid_ = cid;
@@ -916,11 +978,15 @@ SrsRtcPublishStream::SrsRtcPublishStream(SrsRtcConnection* session, const SrsCon
916
978
917
979
pli_worker_ = new SrsRtcPLIWorker (this );
918
980
last_time_send_twcc_ = 0 ;
981
+
982
+ timer_rtcp_ = new SrsRtcPublishRtcpTimer (this );
983
+ timer_twcc_ = new SrsRtcPublishTwccTimer (this );
919
984
}
920
985
921
986
SrsRtcPublishStream::~SrsRtcPublishStream ()
922
987
{
923
- _srs_hybrid->timer100ms ()->unsubscribe (this );
988
+ srs_freep (timer_rtcp_);
989
+ srs_freep (timer_twcc_);
924
990
925
991
// TODO: FIXME: Should remove and delete source.
926
992
if (source) {
@@ -1056,10 +1122,6 @@ srs_error_t SrsRtcPublishStream::start()
1056
1122
return err;
1057
1123
}
1058
1124
1059
- // For publisher timer, such as TWCC and RR.
1060
- // @see SrsRtcPublishStream::on_timer()
1061
- _srs_hybrid->timer100ms ()->subscribe (this );
1062
-
1063
1125
if ((err = source->on_publish ()) != srs_success) {
1064
1126
return srs_error_wrap (err, " on publish" );
1065
1127
}
@@ -1529,52 +1591,6 @@ srs_error_t SrsRtcPublishStream::do_request_keyframe(uint32_t ssrc, SrsContextId
1529
1591
return err;
1530
1592
}
1531
1593
1532
- srs_error_t SrsRtcPublishStream::on_timer (srs_utime_t interval)
1533
- {
1534
- srs_error_t err = srs_success;
1535
-
1536
- ++_srs_pps_pub->sugar ;
1537
-
1538
- if (!is_started) {
1539
- return err;
1540
- }
1541
-
1542
- // For RR and RRTR.
1543
- if (true ) {
1544
- ++_srs_pps_rr->sugar ;
1545
-
1546
- if ((err = send_rtcp_rr ()) != srs_success) {
1547
- srs_warn (" RR err %s" , srs_error_desc (err).c_str ());
1548
- srs_freep (err);
1549
- }
1550
-
1551
- if ((err = send_rtcp_xr_rrtr ()) != srs_success) {
1552
- srs_warn (" XR err %s" , srs_error_desc (err).c_str ());
1553
- srs_freep (err);
1554
- }
1555
- }
1556
-
1557
- // For TWCC feedback.
1558
- if (twcc_enabled_) {
1559
- ++_srs_pps_twcc->sugar ;
1560
-
1561
- // If circuit-breaker is dropping packet, disable TWCC.
1562
- if (_srs_circuit_breaker->hybrid_critical_water_level ()) {
1563
- ++_srs_pps_snack4->sugar ;
1564
- return err;
1565
- }
1566
-
1567
- // We should not depends on the received packet,
1568
- // instead we should send feedback every Nms.
1569
- if ((err = send_periodic_twcc ()) != srs_success) {
1570
- srs_warn (" TWCC err %s" , srs_error_desc (err).c_str ());
1571
- srs_freep (err);
1572
- }
1573
- }
1574
-
1575
- return err;
1576
- }
1577
-
1578
1594
void SrsRtcPublishStream::simulate_nack_drop (int nn)
1579
1595
{
1580
1596
nn_simulate_nack_drop = nn;
@@ -1692,6 +1708,45 @@ ISrsRtcConnectionHijacker::~ISrsRtcConnectionHijacker()
1692
1708
{
1693
1709
}
1694
1710
1711
+ SrsRtcConnectionNackTimer::SrsRtcConnectionNackTimer (SrsRtcConnection* p) : p_(p)
1712
+ {
1713
+ _srs_hybrid->timer20ms ()->subscribe (this );
1714
+ }
1715
+
1716
+ SrsRtcConnectionNackTimer::~SrsRtcConnectionNackTimer ()
1717
+ {
1718
+ _srs_hybrid->timer20ms ()->unsubscribe (this );
1719
+ }
1720
+
1721
+ srs_error_t SrsRtcConnectionNackTimer::on_timer (srs_utime_t interval)
1722
+ {
1723
+ srs_error_t err = srs_success;
1724
+
1725
+ if (!p_->nack_enabled_ ) {
1726
+ return err;
1727
+ }
1728
+
1729
+ ++_srs_pps_conn->sugar ;
1730
+
1731
+ // If circuit-breaker is enabled, disable nack.
1732
+ if (_srs_circuit_breaker->hybrid_critical_water_level ()) {
1733
+ ++_srs_pps_snack4->sugar ;
1734
+ return err;
1735
+ }
1736
+
1737
+ std::map<std::string, SrsRtcPublishStream*>::iterator it;
1738
+ for (it = p_->publishers_ .begin (); it != p_->publishers_ .end (); it++) {
1739
+ SrsRtcPublishStream* publisher = it->second ;
1740
+
1741
+ if ((err = publisher->check_send_nacks ()) != srs_success) {
1742
+ srs_warn (" ignore nack err %s" , srs_error_desc (err).c_str ());
1743
+ srs_freep (err);
1744
+ }
1745
+ }
1746
+
1747
+ return err;
1748
+ }
1749
+
1695
1750
SrsRtcConnection::SrsRtcConnection (SrsRtcServer* s, const SrsContextId& cid)
1696
1751
{
1697
1752
req = NULL ;
@@ -1719,16 +1774,17 @@ SrsRtcConnection::SrsRtcConnection(SrsRtcServer* s, const SrsContextId& cid)
1719
1774
pli_epp = new SrsErrorPithyPrint ();
1720
1775
1721
1776
nack_enabled_ = false ;
1777
+ timer_nack_ = new SrsRtcConnectionNackTimer (this );
1722
1778
1723
1779
_srs_rtc_manager->subscribe (this );
1724
1780
}
1725
1781
1726
1782
SrsRtcConnection::~SrsRtcConnection ()
1727
1783
{
1728
- _srs_hybrid->timer20ms ()->unsubscribe (this );
1729
-
1730
1784
_srs_rtc_manager->unsubscribe (this );
1731
1785
1786
+ srs_freep (timer_nack_);
1787
+
1732
1788
// Cleanup publishers.
1733
1789
for (map<string, SrsRtcPublishStream*>::iterator it = publishers_.begin (); it != publishers_.end (); ++it) {
1734
1790
SrsRtcPublishStream* publisher = it->second ;
@@ -1972,10 +2028,6 @@ srs_error_t SrsRtcConnection::initialize(SrsRequest* r, bool dtls, bool srtp, st
1972
2028
return srs_error_wrap (err, " init" );
1973
2029
}
1974
2030
1975
- // The RTC connection start a timer, handle nacks.
1976
- // @see SrsRtcConnection::on_timer()
1977
- _srs_hybrid->timer20ms ()->subscribe (this );
1978
-
1979
2031
// TODO: FIXME: Support reload.
1980
2032
session_timeout = _srs_config->get_rtc_stun_timeout (req->vhost );
1981
2033
last_stun_time = srs_get_system_time ();
@@ -2351,35 +2403,6 @@ void SrsRtcConnection::update_sendonly_socket(SrsUdpMuxSocket* skt)
2351
2403
sendonly_skt = addr_cache;
2352
2404
}
2353
2405
2354
- srs_error_t SrsRtcConnection::on_timer (srs_utime_t interval)
2355
- {
2356
- srs_error_t err = srs_success;
2357
-
2358
- if (!nack_enabled_) {
2359
- return err;
2360
- }
2361
-
2362
- ++_srs_pps_conn->sugar ;
2363
-
2364
- // If circuit-breaker is enabled, disable nack.
2365
- if (_srs_circuit_breaker->hybrid_critical_water_level ()) {
2366
- ++_srs_pps_snack4->sugar ;
2367
- return err;
2368
- }
2369
-
2370
- std::map<std::string, SrsRtcPublishStream*>::iterator it;
2371
- for (it = publishers_.begin (); it != publishers_.end (); it++) {
2372
- SrsRtcPublishStream* publisher = it->second ;
2373
-
2374
- if ((err = publisher->check_send_nacks ()) != srs_success) {
2375
- srs_warn (" ignore nack err %s" , srs_error_desc (err).c_str ());
2376
- srs_freep (err);
2377
- }
2378
- }
2379
-
2380
- return err;
2381
- }
2382
-
2383
2406
srs_error_t SrsRtcConnection::send_rtcp (char *data, int nb_data)
2384
2407
{
2385
2408
srs_error_t err = srs_success;
0 commit comments