RTC: Ignore NACK when disable for player.

pull/2252/head
winlin 4 years ago
parent 4e474a24ce
commit 712dc7225a

@ -432,11 +432,13 @@ srs_error_t SrsRtcPlayStream::initialize(SrsRequest* req, std::map<uint32_t, Srs
std::map<uint32_t, SrsRtcTrackDescription*>::iterator it = sub_relations.begin();
while (it != sub_relations.end()) {
if (it->second->type_ == "audio") {
audio_tracks_.insert(make_pair(it->first, new SrsRtcAudioSendTrack(session_, it->second)));
SrsRtcAudioSendTrack* track = new SrsRtcAudioSendTrack(session_, it->second);
audio_tracks_.insert(make_pair(it->first, track));
}
if (it->second->type_ == "video") {
video_tracks_.insert(make_pair(it->first, new SrsRtcVideoSendTrack(session_, it->second)));
SrsRtcVideoSendTrack* track = new SrsRtcVideoSendTrack(session_, it->second);
video_tracks_.insert(make_pair(it->first, track));
}
++it;
}
@ -446,6 +448,18 @@ srs_error_t SrsRtcPlayStream::initialize(SrsRequest* req, std::map<uint32_t, Srs
nack_enabled_ = _srs_config->get_rtc_nack_enabled(req->vhost);
srs_trace("RTC player nack=%d", nack_enabled_);
// Apply configs for all tracks.
for (map<uint32_t, SrsRtcAudioSendTrack*>::iterator it = audio_tracks_.begin(); it != audio_tracks_.end(); ++it) {
SrsRtcAudioSendTrack* track = it->second;
track->set_nack_enabled(nack_enabled_);
}
for (map<uint32_t, SrsRtcVideoSendTrack*>::iterator it = video_tracks_.begin(); it != video_tracks_.end(); ++it) {
SrsRtcVideoSendTrack* track = it->second;
track->set_nack_enabled(nack_enabled_);
}
// Update stat for session.
session_->stat_->nn_subscribers++;
return err;
@ -910,6 +924,16 @@ srs_error_t SrsRtcPublishStream::initialize(SrsRequest* r, SrsRtcStreamDescripti
srs_trace("RTC publisher nack=%d, pt-drop=%u, twcc=%u/%d", nack_enabled_, pt_to_drop_, twcc_enabled_, twcc_id);
for (vector<SrsRtcAudioRecvTrack*>::iterator it = audio_tracks_.begin(); it != audio_tracks_.end(); ++it) {
SrsRtcAudioRecvTrack* track = *it;
track->set_nack_enabled(nack_enabled_);
}
for (vector<SrsRtcVideoRecvTrack*>::iterator it = video_tracks_.begin(); it != video_tracks_.end(); ++it) {
SrsRtcVideoRecvTrack* track = *it;
track->set_nack_enabled(nack_enabled_);
}
// Update stat for session.
session_->stat_->nn_publishers++;
// Setup the publish stream in source to enable PLI as such.
@ -1164,12 +1188,12 @@ srs_error_t SrsRtcPublishStream::do_on_rtp_plaintext(SrsRtpPacket2* pkt, SrsBuff
SrsRtcVideoRecvTrack* video_track = get_video_track(ssrc);
if (audio_track) {
pkt->frame_type = SrsFrameTypeAudio;
if ((err = audio_track->on_rtp(source, pkt, nack_enabled_)) != srs_success) {
if ((err = audio_track->on_rtp(source, pkt)) != srs_success) {
return srs_error_wrap(err, "on audio");
}
} else if (video_track) {
pkt->frame_type = SrsFrameTypeVideo;
if ((err = video_track->on_rtp(source, pkt, nack_enabled_)) != srs_success) {
if ((err = video_track->on_rtp(source, pkt)) != srs_success) {
return srs_error_wrap(err, "on video");
}
} else {

@ -1729,6 +1729,7 @@ SrsRtcRecvTrack::SrsRtcRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescripti
session_ = session;
track_desc_ = track_desc->copy();
statistic_ = new SrsRtcTrackStatistic();
nack_enabled_ = false;
if (is_audio) {
rtp_queue_ = new SrsRtpRingBuffer(100);
@ -1749,6 +1750,11 @@ SrsRtcRecvTrack::~SrsRtcRecvTrack()
srs_freep(statistic_);
}
void SrsRtcRecvTrack::set_nack_enabled(bool v)
{
nack_enabled_ = v;
}
bool SrsRtcRecvTrack::has_ssrc(uint32_t ssrc)
{
return track_desc_->has_ssrc(ssrc);
@ -1872,7 +1878,7 @@ void SrsRtcAudioRecvTrack::on_before_decode_payload(SrsRtpPacket2* pkt, SrsBuffe
*ppt = SrsRtpPacketPayloadTypeRaw;
}
srs_error_t SrsRtcAudioRecvTrack::on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt, bool nack_enabled)
srs_error_t SrsRtcAudioRecvTrack::on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt)
{
srs_error_t err = srs_success;
@ -1888,7 +1894,7 @@ srs_error_t SrsRtcAudioRecvTrack::on_rtp(SrsRtcStream* source, SrsRtpPacket2* pk
}
// For NACK to handle packet.
if (nack_enabled && (err = on_nack(pkt)) != srs_success) {
if (nack_enabled_ && (err = on_nack(pkt)) != srs_success) {
return srs_error_wrap(err, "on nack");
}
@ -1938,7 +1944,7 @@ void SrsRtcVideoRecvTrack::on_before_decode_payload(SrsRtpPacket2* pkt, SrsBuffe
}
}
srs_error_t SrsRtcVideoRecvTrack::on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt, bool nack_enabled)
srs_error_t SrsRtcVideoRecvTrack::on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt)
{
srs_error_t err = srs_success;
@ -1956,7 +1962,7 @@ srs_error_t SrsRtcVideoRecvTrack::on_rtp(SrsRtcStream* source, SrsRtpPacket2* pk
}
// For NACK to handle packet.
if (nack_enabled && (err = on_nack(pkt)) != srs_success) {
if ((err = on_nack(pkt)) != srs_success) {
return srs_error_wrap(err, "on nack");
}
@ -1990,6 +1996,7 @@ SrsRtcSendTrack::SrsRtcSendTrack(SrsRtcConnection* session, SrsRtcTrackDescripti
session_ = session;
track_desc_ = track_desc->copy();
statistic_ = new SrsRtcTrackStatistic();
nack_enabled_ = false;
if (is_audio) {
rtp_queue_ = new SrsRtpRingBuffer(100);
@ -2008,6 +2015,11 @@ SrsRtcSendTrack::~SrsRtcSendTrack()
srs_freep(nack_epp);
}
void SrsRtcSendTrack::set_nack_enabled(bool v)
{
nack_enabled_ = v;
}
bool SrsRtcSendTrack::has_ssrc(uint32_t ssrc)
{
return track_desc_->has_ssrc(ssrc);
@ -2119,7 +2131,7 @@ srs_error_t SrsRtcAudioSendTrack::on_rtp(SrsRtpPacket2* pkt)
}
// Put rtp packet to NACK/ARQ queue
if (true) {
if (nack_enabled_) {
SrsRtpPacket2* nack = pkt->copy();
rtp_queue_->set(nack->header.get_sequence(), nack);
}
@ -2179,7 +2191,7 @@ srs_error_t SrsRtcVideoSendTrack::on_rtp(SrsRtpPacket2* pkt)
}
// Put rtp packet to NACK/ARQ queue
if (true) {
if (nack_enabled_) {
SrsRtpPacket2* nack = pkt->copy();
rtp_queue_->set(nack->header.get_sequence(), nack);
}

@ -510,6 +510,9 @@ public:
class SrsRtcRecvTrack
{
protected:
// Whether enabled nack.
bool nack_enabled_;
SrsRtcTrackDescription* track_desc_;
SrsRtcTrackStatistic* statistic_;
@ -524,6 +527,7 @@ public:
SrsRtcRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescription* stream_descs, bool is_audio);
virtual ~SrsRtcRecvTrack();
public:
void set_nack_enabled(bool v);
bool has_ssrc(uint32_t ssrc);
uint32_t get_ssrc();
void update_rtt(int rtt);
@ -536,7 +540,7 @@ public:
protected:
srs_error_t on_nack(SrsRtpPacket2* pkt);
public:
virtual srs_error_t on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt, bool nack_enabled) = 0;
virtual srs_error_t on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt) = 0;
virtual srs_error_t check_send_nacks() = 0;
protected:
virtual srs_error_t do_check_send_nacks(uint32_t& timeout_nacks);
@ -550,7 +554,7 @@ public:
public:
virtual void on_before_decode_payload(SrsRtpPacket2* pkt, SrsBuffer* buf, ISrsRtpPayloader** ppayload, SrsRtpPacketPayloadType* ppt);
public:
virtual srs_error_t on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt, bool nack_enabled);
virtual srs_error_t on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt);
virtual srs_error_t check_send_nacks();
};
@ -562,7 +566,7 @@ public:
public:
virtual void on_before_decode_payload(SrsRtpPacket2* pkt, SrsBuffer* buf, ISrsRtpPayloader** ppayload, SrsRtpPacketPayloadType* ppt);
public:
virtual srs_error_t on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt, bool nack_enabled);
virtual srs_error_t on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt);
virtual srs_error_t check_send_nacks();
};
@ -577,6 +581,8 @@ protected:
SrsRtcConnection* session_;
// NACK ARQ ring buffer.
SrsRtpRingBuffer* rtp_queue_;
// Whether enabled nack.
bool nack_enabled_;
private:
// The pithy print for special stage.
SrsErrorPithyPrint* nack_epp;
@ -584,6 +590,7 @@ public:
SrsRtcSendTrack(SrsRtcConnection* session, SrsRtcTrackDescription* track_desc, bool is_audio);
virtual ~SrsRtcSendTrack();
public:
void set_nack_enabled(bool v);
bool has_ssrc(uint32_t ssrc);
SrsRtpPacket2* fetch_rtp_packet(uint16_t seq);
bool set_track_status(bool active);

Loading…
Cancel
Save