Index: webrtc/api/rtpsender.cc |
diff --git a/webrtc/api/rtpsender.cc b/webrtc/api/rtpsender.cc |
index 58cb18c6cd2734e5bc37df470c5a3ba121abd401..360b6868fd377b99e1f64fdeb21bead5d7b490df 100644 |
--- a/webrtc/api/rtpsender.cc |
+++ b/webrtc/api/rtpsender.cc |
@@ -122,6 +122,9 @@ bool AudioRtpSender::SetTrack(MediaStreamTrackInterface* track) { |
// Attach to new track. |
bool prev_can_send_track = can_send_track(); |
+ // Keep a reference to the old track to keep it alive until we call |
+ // SetAudioSend. |
+ rtc::scoped_refptr<AudioTrackInterface> old_track = track_; |
track_ = audio_track; |
if (track_) { |
cached_track_enabled_ = track_->enabled(); |
@@ -276,6 +279,9 @@ bool VideoRtpSender::SetTrack(MediaStreamTrackInterface* track) { |
// Attach to new track. |
bool prev_can_send_track = can_send_track(); |
+ // Keep a reference to the old track to keep it alive until we call |
+ // SetSource. |
+ rtc::scoped_refptr<VideoTrackInterface> old_track = track_; |
track_ = video_track; |
if (track_) { |
cached_track_enabled_ = track_->enabled(); |