mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Refine cid for PLI
This commit is contained in:
parent
a0dedba2ab
commit
579f7a8a5b
4 changed files with 41 additions and 32 deletions
|
@ -295,9 +295,9 @@ SrsRtcPlayStreamStatistic::~SrsRtcPlayStreamStatistic()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcPlayStream::SrsRtcPlayStream(SrsRtcConnection* s, SrsContextId parent_cid)
|
SrsRtcPlayStream::SrsRtcPlayStream(SrsRtcConnection* s, const SrsContextId& cid)
|
||||||
{
|
{
|
||||||
_parent_cid = parent_cid;
|
cid_ = cid;
|
||||||
trd = new SrsDummyCoroutine();
|
trd = new SrsDummyCoroutine();
|
||||||
|
|
||||||
req_ = NULL;
|
req_ = NULL;
|
||||||
|
@ -394,9 +394,9 @@ srs_error_t SrsRtcPlayStream::on_reload_vhost_realtime(string vhost)
|
||||||
return on_reload_vhost_play(vhost);
|
return on_reload_vhost_play(vhost);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsContextId SrsRtcPlayStream::cid()
|
const SrsContextId& SrsRtcPlayStream::context_id()
|
||||||
{
|
{
|
||||||
return trd->cid();
|
return cid_;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcPlayStream::start()
|
srs_error_t SrsRtcPlayStream::start()
|
||||||
|
@ -411,7 +411,7 @@ srs_error_t SrsRtcPlayStream::start()
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_freep(trd);
|
srs_freep(trd);
|
||||||
trd = new SrsSTCoroutine("rtc_sender", this, _parent_cid);
|
trd = new SrsSTCoroutine("rtc_sender", this, cid_);
|
||||||
|
|
||||||
if ((err = trd->start()) != srs_success) {
|
if ((err = trd->start()) != srs_success) {
|
||||||
return srs_error_wrap(err, "rtc_sender");
|
return srs_error_wrap(err, "rtc_sender");
|
||||||
|
@ -804,11 +804,11 @@ uint32_t SrsRtcPlayStream::get_video_publish_ssrc(uint32_t play_ssrc)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcPublishStream::SrsRtcPublishStream(SrsRtcConnection* session, SrsContextId parent_cid)
|
SrsRtcPublishStream::SrsRtcPublishStream(SrsRtcConnection* session, const SrsContextId& cid)
|
||||||
{
|
{
|
||||||
timer_ = new SrsHourGlass(this, 200 * SRS_UTIME_MILLISECONDS);
|
timer_ = new SrsHourGlass(this, 200 * SRS_UTIME_MILLISECONDS);
|
||||||
|
|
||||||
parent_cid_ = parent_cid;
|
cid_ = cid;
|
||||||
is_started = false;
|
is_started = false;
|
||||||
session_ = session;
|
session_ = session;
|
||||||
request_keyframe_ = false;
|
request_keyframe_ = false;
|
||||||
|
@ -948,6 +948,11 @@ void SrsRtcPublishStream::set_all_tracks_status(bool status)
|
||||||
srs_trace("RTC: Init tracks %s ok", merged_log.str().c_str());
|
srs_trace("RTC: Init tracks %s ok", merged_log.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SrsContextId& SrsRtcPublishStream::context_id()
|
||||||
|
{
|
||||||
|
return cid_;
|
||||||
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcPublishStream::send_rtcp_rr()
|
srs_error_t SrsRtcPublishStream::send_rtcp_rr()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
@ -1274,10 +1279,10 @@ void SrsRtcPublishStream::request_keyframe(uint32_t ssrc)
|
||||||
{
|
{
|
||||||
uint32_t nn = 0;
|
uint32_t nn = 0;
|
||||||
if (pli_epp->can_print(ssrc, &nn)) {
|
if (pli_epp->can_print(ssrc, &nn)) {
|
||||||
SrsContextId scid = _srs_context->get_id();
|
// The player(subscriber) cid, which requires PLI.
|
||||||
SrsContextId pcid = session_->context_id();
|
const SrsContextId& sub_cid = _srs_context->get_id();
|
||||||
srs_trace("RTC: Request PLI ssrc=%u, play=[%d][%s], publish=[%d][%s], count=%u/%u", ssrc, ::getpid(), scid.c_str(),
|
srs_trace("RTC: Need PLI ssrc=%u, play=[%s], publish=[%s], count=%u/%u", ssrc, sub_cid.c_str(),
|
||||||
::getpid(), pcid.c_str(), nn, pli_epp->nn_count);
|
cid_.c_str(), nn, pli_epp->nn_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcVideoRecvTrack* video_track = get_video_track(ssrc);
|
SrsRtcVideoRecvTrack* video_track = get_video_track(ssrc);
|
||||||
|
@ -1440,10 +1445,10 @@ ISrsRtcConnectionHijacker::~ISrsRtcConnectionHijacker()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcConnection::SrsRtcConnection(SrsRtcServer* s, SrsContextId context_id)
|
SrsRtcConnection::SrsRtcConnection(SrsRtcServer* s, const SrsContextId& cid)
|
||||||
{
|
{
|
||||||
req = NULL;
|
req = NULL;
|
||||||
cid = context_id;
|
cid_ = cid;
|
||||||
stat_ = new SrsRtcConnectionStatistic();
|
stat_ = new SrsRtcConnectionStatistic();
|
||||||
timer_ = new SrsHourGlass(this, 1000 * SRS_UTIME_MILLISECONDS);
|
timer_ = new SrsHourGlass(this, 1000 * SRS_UTIME_MILLISECONDS);
|
||||||
hijacker_ = NULL;
|
hijacker_ = NULL;
|
||||||
|
@ -1548,12 +1553,12 @@ vector<SrsUdpMuxSocket*> SrsRtcConnection::peer_addresses()
|
||||||
|
|
||||||
void SrsRtcConnection::switch_to_context()
|
void SrsRtcConnection::switch_to_context()
|
||||||
{
|
{
|
||||||
_srs_context->set_id(cid);
|
_srs_context->set_id(cid_);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsContextId SrsRtcConnection::context_id()
|
const SrsContextId& SrsRtcConnection::context_id()
|
||||||
{
|
{
|
||||||
return cid;
|
return cid_;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcConnection::add_publisher(SrsRequest* req, const SrsSdp& remote_sdp, SrsSdp& local_sdp)
|
srs_error_t SrsRtcConnection::add_publisher(SrsRequest* req, const SrsSdp& remote_sdp, SrsSdp& local_sdp)
|
||||||
|
@ -2202,7 +2207,7 @@ srs_error_t SrsRtcConnection::send_rtcp_xr_rrtr(uint32_t ssrc)
|
||||||
return sendonly_skt->sendto(protected_buf, nb_protected_buf, 0);
|
return sendonly_skt->sendto(protected_buf, nb_protected_buf, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcConnection::send_rtcp_fb_pli(uint32_t ssrc)
|
srs_error_t SrsRtcConnection::send_rtcp_fb_pli(uint32_t ssrc, const SrsContextId& cid_of_subscriber)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
@ -2216,7 +2221,8 @@ srs_error_t SrsRtcConnection::send_rtcp_fb_pli(uint32_t ssrc)
|
||||||
|
|
||||||
uint32_t nn = 0;
|
uint32_t nn = 0;
|
||||||
if (pli_epp->can_print(ssrc, &nn)) {
|
if (pli_epp->can_print(ssrc, &nn)) {
|
||||||
srs_trace("RTC: Request PLI ssrc=%u, count=%u/%u, bytes=%uB", ssrc, nn, pli_epp->nn_count, stream.pos());
|
srs_trace("RTC: Request PLI ssrc=%u, play=[%s], count=%u/%u, bytes=%uB", ssrc, cid_of_subscriber.c_str(),
|
||||||
|
nn, pli_epp->nn_count, stream.pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_srs_blackhole->blackhole) {
|
if (_srs_blackhole->blackhole) {
|
||||||
|
|
|
@ -211,7 +211,7 @@ public:
|
||||||
class SrsRtcPlayStream : virtual public ISrsCoroutineHandler, virtual public ISrsReloadHandler, virtual public ISrsHourGlass
|
class SrsRtcPlayStream : virtual public ISrsCoroutineHandler, virtual public ISrsReloadHandler, virtual public ISrsHourGlass
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SrsContextId _parent_cid;
|
SrsContextId cid_;
|
||||||
SrsCoroutine* trd;
|
SrsCoroutine* trd;
|
||||||
SrsRtcConnection* session_;
|
SrsRtcConnection* session_;
|
||||||
private:
|
private:
|
||||||
|
@ -235,7 +235,7 @@ private:
|
||||||
// The statistic for consumer to send packets to player.
|
// The statistic for consumer to send packets to player.
|
||||||
SrsRtcPlayStreamStatistic info;
|
SrsRtcPlayStreamStatistic info;
|
||||||
public:
|
public:
|
||||||
SrsRtcPlayStream(SrsRtcConnection* s, SrsContextId parent_cid);
|
SrsRtcPlayStream(SrsRtcConnection* s, const SrsContextId& cid);
|
||||||
virtual ~SrsRtcPlayStream();
|
virtual ~SrsRtcPlayStream();
|
||||||
public:
|
public:
|
||||||
srs_error_t initialize(SrsRequest* request, std::map<uint32_t, SrsRtcTrackDescription*> sub_relations);
|
srs_error_t initialize(SrsRequest* request, std::map<uint32_t, SrsRtcTrackDescription*> sub_relations);
|
||||||
|
@ -243,8 +243,7 @@ public:
|
||||||
public:
|
public:
|
||||||
virtual srs_error_t on_reload_vhost_play(std::string vhost);
|
virtual srs_error_t on_reload_vhost_play(std::string vhost);
|
||||||
virtual srs_error_t on_reload_vhost_realtime(std::string vhost);
|
virtual srs_error_t on_reload_vhost_realtime(std::string vhost);
|
||||||
public:
|
virtual const SrsContextId& context_id();
|
||||||
virtual SrsContextId cid();
|
|
||||||
public:
|
public:
|
||||||
virtual srs_error_t start();
|
virtual srs_error_t start();
|
||||||
virtual void stop();
|
virtual void stop();
|
||||||
|
@ -273,7 +272,7 @@ private:
|
||||||
class SrsRtcPublishStream : virtual public ISrsHourGlass, virtual public ISrsRtpPacketDecodeHandler, virtual public ISrsRtcPublishStream
|
class SrsRtcPublishStream : virtual public ISrsHourGlass, virtual public ISrsRtpPacketDecodeHandler, virtual public ISrsRtcPublishStream
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SrsContextId parent_cid_;
|
SrsContextId cid_;
|
||||||
SrsHourGlass* timer_;
|
SrsHourGlass* timer_;
|
||||||
uint64_t nn_audio_frames;
|
uint64_t nn_audio_frames;
|
||||||
private:
|
private:
|
||||||
|
@ -300,13 +299,14 @@ private:
|
||||||
SrsRtpExtensionTypes extension_types_;
|
SrsRtpExtensionTypes extension_types_;
|
||||||
bool is_started;
|
bool is_started;
|
||||||
public:
|
public:
|
||||||
SrsRtcPublishStream(SrsRtcConnection* session, SrsContextId parent_cid);
|
SrsRtcPublishStream(SrsRtcConnection* session, const SrsContextId& cid);
|
||||||
virtual ~SrsRtcPublishStream();
|
virtual ~SrsRtcPublishStream();
|
||||||
public:
|
public:
|
||||||
srs_error_t initialize(SrsRequest* req, SrsRtcStreamDescription* stream_desc);
|
srs_error_t initialize(SrsRequest* req, SrsRtcStreamDescription* stream_desc);
|
||||||
srs_error_t start();
|
srs_error_t start();
|
||||||
// Directly set the status of track, generally for init to set the default value.
|
// Directly set the status of track, generally for init to set the default value.
|
||||||
void set_all_tracks_status(bool status);
|
void set_all_tracks_status(bool status);
|
||||||
|
virtual const SrsContextId& context_id();
|
||||||
private:
|
private:
|
||||||
srs_error_t send_rtcp_rr();
|
srs_error_t send_rtcp_rr();
|
||||||
srs_error_t send_rtcp_xr_rrtr();
|
srs_error_t send_rtcp_xr_rrtr();
|
||||||
|
@ -408,7 +408,7 @@ private:
|
||||||
srs_utime_t last_stun_time;
|
srs_utime_t last_stun_time;
|
||||||
private:
|
private:
|
||||||
// For each RTC session, we use a specified cid for debugging logs.
|
// For each RTC session, we use a specified cid for debugging logs.
|
||||||
SrsContextId cid;
|
SrsContextId cid_;
|
||||||
// TODO: FIXME: Rename to req_.
|
// TODO: FIXME: Rename to req_.
|
||||||
SrsRequest* req;
|
SrsRequest* req;
|
||||||
SrsSdp remote_sdp;
|
SrsSdp remote_sdp;
|
||||||
|
@ -423,7 +423,7 @@ private:
|
||||||
// Pithy print for PLI request.
|
// Pithy print for PLI request.
|
||||||
SrsErrorPithyPrint* pli_epp;
|
SrsErrorPithyPrint* pli_epp;
|
||||||
public:
|
public:
|
||||||
SrsRtcConnection(SrsRtcServer* s, SrsContextId context_id);
|
SrsRtcConnection(SrsRtcServer* s, const SrsContextId& cid);
|
||||||
virtual ~SrsRtcConnection();
|
virtual ~SrsRtcConnection();
|
||||||
public:
|
public:
|
||||||
// TODO: FIXME: save only connection info.
|
// TODO: FIXME: save only connection info.
|
||||||
|
@ -440,7 +440,7 @@ public:
|
||||||
std::vector<SrsUdpMuxSocket*> peer_addresses();
|
std::vector<SrsUdpMuxSocket*> peer_addresses();
|
||||||
public:
|
public:
|
||||||
void switch_to_context();
|
void switch_to_context();
|
||||||
SrsContextId context_id();
|
const SrsContextId& context_id();
|
||||||
public:
|
public:
|
||||||
srs_error_t add_publisher(SrsRequest* request, const SrsSdp& remote_sdp, SrsSdp& local_sdp);
|
srs_error_t add_publisher(SrsRequest* request, const SrsSdp& remote_sdp, SrsSdp& local_sdp);
|
||||||
srs_error_t add_player(SrsRequest* request, const SrsSdp& remote_sdp, SrsSdp& local_sdp);
|
srs_error_t add_player(SrsRequest* request, const SrsSdp& remote_sdp, SrsSdp& local_sdp);
|
||||||
|
@ -477,7 +477,7 @@ public:
|
||||||
void check_send_nacks(SrsRtpNackForReceiver* nack, uint32_t ssrc, uint32_t& sent_nacks);
|
void check_send_nacks(SrsRtpNackForReceiver* nack, uint32_t ssrc, uint32_t& sent_nacks);
|
||||||
srs_error_t send_rtcp_rr(uint32_t ssrc, SrsRtpRingBuffer* rtp_queue, const uint64_t& last_send_systime, const SrsNtp& last_send_ntp);
|
srs_error_t send_rtcp_rr(uint32_t ssrc, SrsRtpRingBuffer* rtp_queue, const uint64_t& last_send_systime, const SrsNtp& last_send_ntp);
|
||||||
srs_error_t send_rtcp_xr_rrtr(uint32_t ssrc);
|
srs_error_t send_rtcp_xr_rrtr(uint32_t ssrc);
|
||||||
srs_error_t send_rtcp_fb_pli(uint32_t ssrc);
|
srs_error_t send_rtcp_fb_pli(uint32_t ssrc, const SrsContextId& cid_of_subscriber);
|
||||||
public:
|
public:
|
||||||
// Simulate the NACK to drop nn packets.
|
// Simulate the NACK to drop nn packets.
|
||||||
void simulate_nack_drop(int nn);
|
void simulate_nack_drop(int nn);
|
||||||
|
|
|
@ -1700,10 +1700,10 @@ srs_error_t SrsRtcRecvTrack::on_nack(SrsRtpPacket2* pkt)
|
||||||
// insert check nack list
|
// insert check nack list
|
||||||
uint16_t nack_first = 0, nack_last = 0;
|
uint16_t nack_first = 0, nack_last = 0;
|
||||||
if (!rtp_queue_->update(seq, nack_first, nack_last)) {
|
if (!rtp_queue_->update(seq, nack_first, nack_last)) {
|
||||||
srs_warn("too old seq %u, range [%u, %u]", seq, rtp_queue_->begin, rtp_queue_->end);
|
srs_warn("NACK: too old seq %u, range [%u, %u]", seq, rtp_queue_->begin, rtp_queue_->end);
|
||||||
}
|
}
|
||||||
if (srs_rtp_seq_distance(nack_first, nack_last) > 0) {
|
if (srs_rtp_seq_distance(nack_first, nack_last) > 0) {
|
||||||
srs_trace("update seq=%u, nack range [%u, %u]", seq, nack_first, nack_last);
|
srs_trace("NACK: update seq=%u, nack range [%u, %u]", seq, nack_first, nack_last);
|
||||||
nack_receiver_->insert(nack_first, nack_last);
|
nack_receiver_->insert(nack_first, nack_last);
|
||||||
nack_receiver_->check_queue_size();
|
nack_receiver_->check_queue_size();
|
||||||
}
|
}
|
||||||
|
@ -1783,7 +1783,7 @@ srs_error_t SrsRtcVideoRecvTrack::on_rtp(SrsRtcStream* source, SrsRtpPacket2* pk
|
||||||
// TODO: FIXME: add coroutine to request key frame.
|
// TODO: FIXME: add coroutine to request key frame.
|
||||||
request_key_frame_ = false;
|
request_key_frame_ = false;
|
||||||
|
|
||||||
if ((err = session_->send_rtcp_fb_pli(track_desc_->ssrc_)) != srs_success) {
|
if ((err = session_->send_rtcp_fb_pli(track_desc_->ssrc_, cid_of_subscriber_)) != srs_success) {
|
||||||
srs_warn("PLI err %s", srs_error_desc(err).c_str());
|
srs_warn("PLI err %s", srs_error_desc(err).c_str());
|
||||||
srs_freep(err);
|
srs_freep(err);
|
||||||
}
|
}
|
||||||
|
@ -1799,6 +1799,7 @@ srs_error_t SrsRtcVideoRecvTrack::on_rtp(SrsRtcStream* source, SrsRtpPacket2* pk
|
||||||
|
|
||||||
void SrsRtcVideoRecvTrack::request_keyframe()
|
void SrsRtcVideoRecvTrack::request_keyframe()
|
||||||
{
|
{
|
||||||
|
cid_of_subscriber_ = _srs_context->get_id();
|
||||||
request_key_frame_ = true;
|
request_key_frame_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1848,7 +1849,7 @@ SrsRtpPacket2* SrsRtcSendTrack::fetch_rtp_packet(uint16_t seq)
|
||||||
// Ignore if sequence not match.
|
// Ignore if sequence not match.
|
||||||
uint32_t nn = 0;
|
uint32_t nn = 0;
|
||||||
if (nack_epp->can_print(pkt->header.get_ssrc(), &nn)) {
|
if (nack_epp->can_print(pkt->header.get_ssrc(), &nn)) {
|
||||||
srs_trace("RTC NACK miss seq=%u, require_seq=%u, ssrc=%u, ts=%u, count=%u/%u, %d bytes", seq, pkt->header.get_sequence(),
|
srs_trace("RTC: NACK miss seq=%u, require_seq=%u, ssrc=%u, ts=%u, count=%u/%u, %d bytes", seq, pkt->header.get_sequence(),
|
||||||
pkt->header.get_ssrc(), pkt->header.get_timestamp(), nn, nack_epp->nn_count, pkt->nb_bytes());
|
pkt->header.get_ssrc(), pkt->header.get_timestamp(), nn, nack_epp->nn_count, pkt->nb_bytes());
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -516,6 +516,8 @@ class SrsRtcVideoRecvTrack : public SrsRtcRecvTrack
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool request_key_frame_;
|
bool request_key_frame_;
|
||||||
|
// The player(subscriber) cid, which requires PLI.
|
||||||
|
SrsContextId cid_of_subscriber_;
|
||||||
public:
|
public:
|
||||||
SrsRtcVideoRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescription* stream_descs);
|
SrsRtcVideoRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescription* stream_descs);
|
||||||
virtual ~SrsRtcVideoRecvTrack();
|
virtual ~SrsRtcVideoRecvTrack();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue