1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 11:51:57 +00:00

RTC: Support disable the NACK no-copy, enable copy by default

This commit is contained in:
winlin 2021-02-28 18:51:27 +08:00
parent 50860325dd
commit f63441413d
7 changed files with 81 additions and 8 deletions

View file

@ -578,6 +578,9 @@ vhost rtc.vhost.srs.com {
# Whether support NACK. # Whether support NACK.
# default: on # default: on
enabled on; enabled on;
# Whether directly use the packet, avoid copy.
# default: off
no_copy off;
} }
# For TWCC. # For TWCC.
twcc { twcc {

View file

@ -5249,6 +5249,28 @@ bool SrsConfig::get_rtc_nack_enabled(string vhost)
return SRS_CONF_PERFER_TRUE(conf->arg0()); return SRS_CONF_PERFER_TRUE(conf->arg0());
} }
bool SrsConfig::get_rtc_nack_no_copy(string vhost)
{
static bool DEFAULT = false;
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("nack");
if (!conf) {
return DEFAULT;
}
conf = conf->get("no_copy");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
bool SrsConfig::get_rtc_twcc_enabled(string vhost) bool SrsConfig::get_rtc_twcc_enabled(string vhost)
{ {
static bool DEFAULT = true; static bool DEFAULT = true;

View file

@ -563,6 +563,7 @@ public:
std::string get_rtc_dtls_version(std::string vhost); std::string get_rtc_dtls_version(std::string vhost);
int get_rtc_drop_for_pt(std::string vhost); int get_rtc_drop_for_pt(std::string vhost);
bool get_rtc_nack_enabled(std::string vhost); bool get_rtc_nack_enabled(std::string vhost);
bool get_rtc_nack_no_copy(std::string vhost);
bool get_rtc_twcc_enabled(std::string vhost); bool get_rtc_twcc_enabled(std::string vhost);
// vhost specified section // vhost specified section

View file

@ -381,6 +381,7 @@ SrsRtcPlayStream::SrsRtcPlayStream(SrsRtcConnection* s, const SrsContextId& cid)
realtime = true; realtime = true;
nack_enabled_ = false; nack_enabled_ = false;
nack_no_copy_ = false;
_srs_config->subscribe(this); _srs_config->subscribe(this);
timer_ = new SrsHourGlass("play", this, 1000 * SRS_UTIME_MILLISECONDS); timer_ = new SrsHourGlass("play", this, 1000 * SRS_UTIME_MILLISECONDS);
@ -446,7 +447,19 @@ srs_error_t SrsRtcPlayStream::initialize(SrsRequest* req, std::map<uint32_t, Srs
// TODO: FIXME: Support reload. // TODO: FIXME: Support reload.
nack_enabled_ = _srs_config->get_rtc_nack_enabled(req->vhost); nack_enabled_ = _srs_config->get_rtc_nack_enabled(req->vhost);
srs_trace("RTC player nack=%d", nack_enabled_); nack_no_copy_ = _srs_config->get_rtc_nack_no_copy(req->vhost);
srs_trace("RTC player nack=%d, nnc=%d", nack_enabled_, nack_no_copy_);
// Setup tracks.
for (map<uint32_t, SrsRtcAudioSendTrack*>::iterator it = audio_tracks_.begin(); it != audio_tracks_.end(); ++it) {
SrsRtcAudioSendTrack* track = it->second;
track->set_nack_no_copy(nack_no_copy_);
}
for (map<uint32_t, SrsRtcVideoSendTrack*>::iterator it = video_tracks_.begin(); it != video_tracks_.end(); ++it) {
SrsRtcVideoSendTrack* track = it->second;
track->set_nack_no_copy(nack_no_copy_);
}
// Update stat for session. // Update stat for session.
session_->stat_->nn_subscribers++; session_->stat_->nn_subscribers++;
@ -849,6 +862,7 @@ SrsRtcPublishStream::SrsRtcPublishStream(SrsRtcConnection* session, const SrsCon
source = NULL; source = NULL;
nn_simulate_nack_drop = 0; nn_simulate_nack_drop = 0;
nack_enabled_ = false; nack_enabled_ = false;
nack_no_copy_ = false;
pt_to_drop_ = 0; pt_to_drop_ = 0;
nn_audio_frames = 0; nn_audio_frames = 0;
@ -923,10 +937,22 @@ srs_error_t SrsRtcPublishStream::initialize(SrsRequest* r, SrsRtcStreamDescripti
} }
nack_enabled_ = _srs_config->get_rtc_nack_enabled(req->vhost); nack_enabled_ = _srs_config->get_rtc_nack_enabled(req->vhost);
nack_no_copy_ = _srs_config->get_rtc_nack_no_copy(req->vhost);
pt_to_drop_ = (uint16_t)_srs_config->get_rtc_drop_for_pt(req->vhost); pt_to_drop_ = (uint16_t)_srs_config->get_rtc_drop_for_pt(req->vhost);
twcc_enabled_ = _srs_config->get_rtc_twcc_enabled(req->vhost); twcc_enabled_ = _srs_config->get_rtc_twcc_enabled(req->vhost);
srs_trace("RTC publisher nack=%d, pt-drop=%u, twcc=%u/%d", nack_enabled_, pt_to_drop_, twcc_enabled_, twcc_id); srs_trace("RTC publisher nack=%d, nnc=%d, pt-drop=%u, twcc=%u/%d", nack_enabled_, nack_no_copy_, pt_to_drop_, twcc_enabled_, twcc_id);
// Setup tracks.
for (int i = 0; i < (int)audio_tracks_.size(); i++) {
SrsRtcAudioRecvTrack* track = audio_tracks_.at(i);
track->set_nack_no_copy(nack_no_copy_);
}
for (int i = 0; i < (int)video_tracks_.size(); i++) {
SrsRtcVideoRecvTrack* track = video_tracks_.at(i);
track->set_nack_no_copy(nack_no_copy_);
}
// Update stat for session. // Update stat for session.
session_->stat_->nn_publishers++; session_->stat_->nn_publishers++;

View file

@ -233,6 +233,7 @@ private:
bool realtime; bool realtime;
// Whether enabled nack. // Whether enabled nack.
bool nack_enabled_; bool nack_enabled_;
bool nack_no_copy_;
private: private:
// Whether palyer started. // Whether palyer started.
bool is_started; bool is_started;
@ -287,6 +288,7 @@ private:
uint16_t pt_to_drop_; uint16_t pt_to_drop_;
// Whether enabled nack. // Whether enabled nack.
bool nack_enabled_; bool nack_enabled_;
bool nack_no_copy_;
bool twcc_enabled_; bool twcc_enabled_;
private: private:
bool request_keyframe_; bool request_keyframe_;

View file

@ -1729,6 +1729,7 @@ SrsRtcRecvTrack::SrsRtcRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescripti
session_ = session; session_ = session;
track_desc_ = track_desc->copy(); track_desc_ = track_desc->copy();
statistic_ = new SrsRtcTrackStatistic(); statistic_ = new SrsRtcTrackStatistic();
nack_no_copy_ = false;
if (is_audio) { if (is_audio) {
rtp_queue_ = new SrsRtpRingBuffer(100); rtp_queue_ = new SrsRtpRingBuffer(100);
@ -1838,8 +1839,12 @@ srs_error_t SrsRtcRecvTrack::on_nack(SrsRtpPacket2** ppkt)
// insert into video_queue and audio_queue // insert into video_queue and audio_queue
// We directly use the pkt, never copy it, so we should set the pkt to NULL. // We directly use the pkt, never copy it, so we should set the pkt to NULL.
rtp_queue_->set(seq, pkt); if (nack_no_copy_) {
*ppkt = NULL; rtp_queue_->set(seq, pkt);
*ppkt = NULL;
} else {
rtp_queue_->set(seq, pkt->copy());
}
return err; return err;
} }
@ -1983,6 +1988,7 @@ SrsRtcSendTrack::SrsRtcSendTrack(SrsRtcConnection* session, SrsRtcTrackDescripti
session_ = session; session_ = session;
track_desc_ = track_desc->copy(); track_desc_ = track_desc->copy();
statistic_ = new SrsRtcTrackStatistic(); statistic_ = new SrsRtcTrackStatistic();
nack_no_copy_ = false;
if (is_audio) { if (is_audio) {
rtp_queue_ = new SrsRtpRingBuffer(100); rtp_queue_ = new SrsRtpRingBuffer(100);
@ -2058,8 +2064,12 @@ srs_error_t SrsRtcSendTrack::on_nack(SrsRtpPacket2** ppkt)
// insert into video_queue and audio_queue // insert into video_queue and audio_queue
// We directly use the pkt, never copy it, so we should set the pkt to NULL. // We directly use the pkt, never copy it, so we should set the pkt to NULL.
rtp_queue_->set(seq, pkt); if (nack_no_copy_) {
*ppkt = NULL; rtp_queue_->set(seq, pkt);
*ppkt = NULL;
} else {
rtp_queue_->set(seq, pkt->copy());
}
return err; return err;
} }

View file

@ -512,11 +512,14 @@ class SrsRtcRecvTrack
protected: protected:
SrsRtcTrackDescription* track_desc_; SrsRtcTrackDescription* track_desc_;
SrsRtcTrackStatistic* statistic_; SrsRtcTrackStatistic* statistic_;
protected:
SrsRtcConnection* session_; SrsRtcConnection* session_;
SrsRtpRingBuffer* rtp_queue_; SrsRtpRingBuffer* rtp_queue_;
SrsRtpNackForReceiver* nack_receiver_; SrsRtpNackForReceiver* nack_receiver_;
private:
// By config, whether no copy.
bool nack_no_copy_;
protected:
// send report ntp and received time. // send report ntp and received time.
SrsNtp last_sender_report_ntp; SrsNtp last_sender_report_ntp;
uint64_t last_sender_report_sys_time; uint64_t last_sender_report_sys_time;
@ -524,6 +527,8 @@ public:
SrsRtcRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescription* stream_descs, bool is_audio); SrsRtcRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescription* stream_descs, bool is_audio);
virtual ~SrsRtcRecvTrack(); virtual ~SrsRtcRecvTrack();
public: public:
// SrsRtcSendTrack::set_nack_no_copy
void set_nack_no_copy(bool v) { nack_no_copy_ = v; }
bool has_ssrc(uint32_t ssrc); bool has_ssrc(uint32_t ssrc);
uint32_t get_ssrc(); uint32_t get_ssrc();
void update_rtt(int rtt); void update_rtt(int rtt);
@ -580,12 +585,16 @@ protected:
// NACK ARQ ring buffer. // NACK ARQ ring buffer.
SrsRtpRingBuffer* rtp_queue_; SrsRtpRingBuffer* rtp_queue_;
private: private:
// By config, whether no copy.
bool nack_no_copy_;
// The pithy print for special stage. // The pithy print for special stage.
SrsErrorPithyPrint* nack_epp; SrsErrorPithyPrint* nack_epp;
public: public:
SrsRtcSendTrack(SrsRtcConnection* session, SrsRtcTrackDescription* track_desc, bool is_audio); SrsRtcSendTrack(SrsRtcConnection* session, SrsRtcTrackDescription* track_desc, bool is_audio);
virtual ~SrsRtcSendTrack(); virtual ~SrsRtcSendTrack();
public: public:
// SrsRtcSendTrack::set_nack_no_copy
void set_nack_no_copy(bool v) { nack_no_copy_ = v; }
bool has_ssrc(uint32_t ssrc); bool has_ssrc(uint32_t ssrc);
SrsRtpPacket2* fetch_rtp_packet(uint16_t seq); SrsRtpPacket2* fetch_rtp_packet(uint16_t seq);
bool set_track_status(bool active); bool set_track_status(bool active);