1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

RTC: Refine play stream find track. 4.0.102

This commit is contained in:
winlin 2021-05-07 10:50:51 +08:00
parent b823dcdfd7
commit 4527a91545
4 changed files with 62 additions and 31 deletions

View file

@ -176,6 +176,7 @@ The ports used by SRS:
## V4 changes
* v4.0, 2021-05-07, RTC: Refine play stream find track. 4.0.102
* v4.0, 2021-05-07, RTC: Refine FastTimer to fixed interval. 4.0.101
* v4.0, 2021-05-06, RTC: Fix config bug for nack and twcc. 4.0.99
* v4.0, 2021-05-04, Add video room demo. 4.0.98

View file

@ -382,6 +382,9 @@ SrsRtcPlayStream::SrsRtcPlayStream(SrsRtcConnection* s, const SrsContextId& cid)
_srs_config->subscribe(this);
nack_epp = new SrsErrorPithyPrint();
pli_worker_ = new SrsRtcPLIWorker(this);
cache_ssrc0_ = cache_ssrc1_ = cache_ssrc2_ = 0;
cache_track0_ = cache_track1_ = cache_track2_ = NULL;
}
SrsRtcPlayStream::~SrsRtcPlayStream()
@ -624,45 +627,63 @@ srs_error_t SrsRtcPlayStream::send_packet(SrsRtpPacket2*& pkt)
{
srs_error_t err = srs_success;
// TODO: FIXME: Maybe refine for performance issue.
if (!audio_tracks_.count(pkt->header.get_ssrc()) && !video_tracks_.count(pkt->header.get_ssrc())) {
srs_warn("RTC: Drop for ssrc %u not found", pkt->header.get_ssrc());
uint32_t ssrc = pkt->header.get_ssrc();
// Try to find track from cache.
SrsRtcSendTrack* track = NULL;
if (cache_ssrc0_ == ssrc) {
track = cache_track0_;
} else if (cache_ssrc1_ == ssrc) {
track = cache_track1_;
} else if (cache_ssrc2_ == ssrc) {
track = cache_track2_;
}
// Find by original tracks and build fast cache.
if (!track) {
if (pkt->is_audio()) {
map<uint32_t, SrsRtcAudioSendTrack*>::iterator it = audio_tracks_.find(ssrc);
if (it != audio_tracks_.end()) {
track = it->second;
}
} else {
map<uint32_t, SrsRtcVideoSendTrack*>::iterator it = video_tracks_.find(ssrc);
if (it != video_tracks_.end()) {
track = it->second;
}
}
if (track && !cache_ssrc2_) {
if (!cache_ssrc0_) {
cache_ssrc0_ = ssrc;
cache_track0_ = track;
} else if (!cache_ssrc1_) {
cache_ssrc1_ = ssrc;
cache_track1_ = track;
} else if (!cache_ssrc2_) {
cache_ssrc2_ = ssrc;
cache_track2_ = track;
}
}
}
// Ignore if no track found.
if (!track) {
srs_warn("RTC: Drop for ssrc %u not found", ssrc);
return err;
}
// For audio, we transcoded AAC to opus in extra payloads.
SrsRtcAudioSendTrack* audio_track = NULL;
SrsRtcVideoSendTrack* video_track = NULL;
if (pkt->is_audio()) {
// TODO: FIXME: Any simple solution?
audio_track = audio_tracks_[pkt->header.get_ssrc()];
if ((err = audio_track->on_rtp(pkt)) != srs_success) {
return srs_error_wrap(err, "audio track, SSRC=%u, SEQ=%u", pkt->header.get_ssrc(), pkt->header.get_sequence());
}
// TODO: FIXME: Padding audio to the max payload in RTP packets.
} else {
// TODO: FIXME: Any simple solution?
video_track = video_tracks_[pkt->header.get_ssrc()];
if ((err = video_track->on_rtp(pkt)) != srs_success) {
return srs_error_wrap(err, "video track, SSRC=%u, SEQ=%u", pkt->header.get_ssrc(), pkt->header.get_sequence());
}
// Consume packet by track.
if ((err = track->on_rtp(pkt)) != srs_success) {
return srs_error_wrap(err, "audio track, SSRC=%u, SEQ=%u", ssrc, pkt->header.get_sequence());
}
// For NACK to handle packet.
// @remark Note that the pkt might be set to NULL.
if (nack_enabled_) {
if (audio_track) {
if ((err = audio_track->on_nack(&pkt)) != srs_success) {
if ((err = track->on_nack(&pkt)) != srs_success) {
return srs_error_wrap(err, "on nack");
}
} else if (video_track) {
if ((err = video_track->on_nack(&pkt)) != srs_success) {
return srs_error_wrap(err, "on nack");
}
}
}
return err;

View file

@ -65,6 +65,7 @@ class SrsErrorPithyPrint;
class SrsPithyPrint;
class SrsStatistic;
class SrsRtcUserConfig;
class SrsRtcSendTrack;
const uint8_t kSR = 200;
const uint8_t kRR = 201;
@ -228,6 +229,14 @@ private:
std::map<uint32_t, SrsRtcVideoSendTrack*> video_tracks_;
// The pithy print for special stage.
SrsErrorPithyPrint* nack_epp;
private:
// Fast cache for tracks.
uint32_t cache_ssrc0_;
uint32_t cache_ssrc1_;
uint32_t cache_ssrc2_;
SrsRtcSendTrack* cache_track0_;
SrsRtcSendTrack* cache_track1_;
SrsRtcSendTrack* cache_track2_;
private:
// For merged-write messages.
int mw_msgs;

View file

@ -26,6 +26,6 @@
#define VERSION_MAJOR 4
#define VERSION_MINOR 0
#define VERSION_REVISION 101
#define VERSION_REVISION 102
#endif