From da6663b530f9969ed7ea00efbbff4bf36388bac8 Mon Sep 17 00:00:00 2001 From: xiaozhihong Date: Wed, 16 Jun 2021 20:00:58 +0800 Subject: [PATCH] Check audio/video track when rtc stream updated --- trunk/src/app/srs_app_rtc_conn.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp index 0d1ef72f76..952be23d89 100644 --- a/trunk/src/app/srs_app_rtc_conn.cpp +++ b/trunk/src/app/srs_app_rtc_conn.cpp @@ -455,22 +455,26 @@ void SrsRtcPlayStream::on_stream_change(SrsRtcSourceDescription* desc) // Refresh the relation for audio. // TODO: FIMXE: Match by label? if (desc && desc->audio_track_desc_ && audio_tracks_.size() == 1) { - uint32_t ssrc = desc->audio_track_desc_->ssrc_; - SrsRtcAudioSendTrack* track = audio_tracks_.begin()->second; + if (! audio_tracks_.empty()) { + uint32_t ssrc = desc->audio_track_desc_->ssrc_; + SrsRtcAudioSendTrack* track = audio_tracks_.begin()->second; - audio_tracks_.clear(); - audio_tracks_.insert(make_pair(ssrc, track)); + audio_tracks_.clear(); + audio_tracks_.insert(make_pair(ssrc, track)); + } } // Refresh the relation for video. // TODO: FIMXE: Match by label? if (desc && desc->video_track_descs_.size() == 1) { - SrsRtcTrackDescription* vdesc = desc->video_track_descs_.at(0); - uint32_t ssrc = vdesc->ssrc_; - SrsRtcVideoSendTrack* track = video_tracks_.begin()->second; + if (! video_tracks_.empty()) { + SrsRtcTrackDescription* vdesc = desc->video_track_descs_.at(0); + uint32_t ssrc = vdesc->ssrc_; + SrsRtcVideoSendTrack* track = video_tracks_.begin()->second; - video_tracks_.clear(); - video_tracks_.insert(make_pair(ssrc, track)); + video_tracks_.clear(); + video_tracks_.insert(make_pair(ssrc, track)); + } } }