Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: webrtc/call/call.cc

Issue 2669463006: Move RemoteBitrateEstimator::RemoveStream calls from receive streams to Call. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/audio/audio_receive_stream_unittest.cc ('k') | webrtc/video/rtp_stream_receiver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "webrtc/video/send_delay_stats.h" 53 #include "webrtc/video/send_delay_stats.h"
54 #include "webrtc/video/stats_counter.h" 54 #include "webrtc/video/stats_counter.h"
55 #include "webrtc/video/video_receive_stream.h" 55 #include "webrtc/video/video_receive_stream.h"
56 #include "webrtc/video/video_send_stream.h" 56 #include "webrtc/video/video_send_stream.h"
57 #include "webrtc/video/vie_remb.h" 57 #include "webrtc/video/vie_remb.h"
58 58
59 namespace webrtc { 59 namespace webrtc {
60 60
61 const int Call::Config::kDefaultStartBitrateBps = 300000; 61 const int Call::Config::kDefaultStartBitrateBps = 300000;
62 62
63 namespace {
64
65 // TODO(nisse): This really begs for a shared context struct.
66 bool UseSendSideBwe(const std::vector<RtpExtension>& extensions,
67 bool transport_cc) {
68 if (!transport_cc)
69 return false;
70 for (const auto& extension : extensions) {
71 if (extension.uri == RtpExtension::kTransportSequenceNumberUri)
72 return true;
73 }
74 return false;
75 }
76
77 bool UseSendSideBwe(const VideoReceiveStream::Config& config) {
stefan-webrtc 2017/02/02 10:42:52 Maybe use a template instead?
brandtr_google 2017/02/02 10:45:14 Doesn't work with the FlexfecReceiveStream::Config
stefan-webrtc 2017/02/02 10:47:21 ah, i see
78 return UseSendSideBwe(config.rtp.extensions, config.rtp.transport_cc);
79 }
80
81 bool UseSendSideBwe(const AudioReceiveStream::Config& config) {
82 return UseSendSideBwe(config.rtp.extensions, config.rtp.transport_cc);
83 }
84
85 bool UseSendSideBwe(const FlexfecReceiveStream::Config& config) {
86 return UseSendSideBwe(config.rtp_header_extensions, config.transport_cc);
87 }
88
89 } // namespace
90
63 namespace internal { 91 namespace internal {
64 92
65 class Call : public webrtc::Call, 93 class Call : public webrtc::Call,
66 public PacketReceiver, 94 public PacketReceiver,
67 public RecoveredPacketReceiver, 95 public RecoveredPacketReceiver,
68 public CongestionController::Observer, 96 public CongestionController::Observer,
69 public BitrateAllocator::LimitObserver { 97 public BitrateAllocator::LimitObserver {
70 public: 98 public:
71 explicit Call(const Call::Config& config); 99 explicit Call(const Call::Config& config);
72 virtual ~Call(); 100 virtual ~Call();
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 219
192 // This extra map is used for receive processing which is 220 // This extra map is used for receive processing which is
193 // independent of media type. 221 // independent of media type.
194 222
195 // TODO(nisse): In the RTP transport refactoring, we should have a 223 // TODO(nisse): In the RTP transport refactoring, we should have a
196 // single mapping from ssrc to a more abstract receive stream, with 224 // single mapping from ssrc to a more abstract receive stream, with
197 // accessor methods for all configuration we need at this level. 225 // accessor methods for all configuration we need at this level.
198 struct ReceiveRtpConfig { 226 struct ReceiveRtpConfig {
199 ReceiveRtpConfig() = default; // Needed by std::map 227 ReceiveRtpConfig() = default; // Needed by std::map
200 ReceiveRtpConfig(const std::vector<RtpExtension>& extensions, 228 ReceiveRtpConfig(const std::vector<RtpExtension>& extensions,
201 bool transport_cc) 229 bool use_send_side_bwe)
202 : extensions(extensions), transport_cc(transport_cc) {} 230 : extensions(extensions), use_send_side_bwe(use_send_side_bwe) {}
203 231
204 // Registered RTP header extensions for each stream. Note that RTP header 232 // Registered RTP header extensions for each stream. Note that RTP header
205 // extensions are negotiated per track ("m= line") in the SDP, but we have 233 // extensions are negotiated per track ("m= line") in the SDP, but we have
206 // no notion of tracks at the Call level. We therefore store the RTP header 234 // no notion of tracks at the Call level. We therefore store the RTP header
207 // extensions per SSRC instead, which leads to some storage overhead. 235 // extensions per SSRC instead, which leads to some storage overhead.
208 RtpHeaderExtensionMap extensions; 236 RtpHeaderExtensionMap extensions;
209 // Set if the RTCP feedback message needed for send side BWE was negotiated. 237 // Set if both RTP extension the RTCP feedback message needed for
210 bool transport_cc; 238 // send side BWE are negotiated.
239 bool use_send_side_bwe;
211 }; 240 };
212 std::map<uint32_t, ReceiveRtpConfig> receive_rtp_config_ 241 std::map<uint32_t, ReceiveRtpConfig> receive_rtp_config_
213 GUARDED_BY(receive_crit_); 242 GUARDED_BY(receive_crit_);
214 243
215 std::unique_ptr<RWLockWrapper> send_crit_; 244 std::unique_ptr<RWLockWrapper> send_crit_;
216 // Audio and Video send streams are owned by the client that creates them. 245 // Audio and Video send streams are owned by the client that creates them.
217 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_); 246 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_);
218 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); 247 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_);
219 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); 248 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_);
220 249
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 UpdateAggregateNetworkState(); 546 UpdateAggregateNetworkState();
518 delete audio_send_stream; 547 delete audio_send_stream;
519 } 548 }
520 549
521 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( 550 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream(
522 const webrtc::AudioReceiveStream::Config& config) { 551 const webrtc::AudioReceiveStream::Config& config) {
523 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); 552 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream");
524 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 553 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
525 event_log_->LogAudioReceiveStreamConfig(config); 554 event_log_->LogAudioReceiveStreamConfig(config);
526 AudioReceiveStream* receive_stream = new AudioReceiveStream( 555 AudioReceiveStream* receive_stream = new AudioReceiveStream(
527 &packet_router_, 556 &packet_router_, config,
528 congestion_controller_->GetRemoteBitrateEstimator(true), config,
529 config_.audio_state, event_log_); 557 config_.audio_state, event_log_);
530 { 558 {
531 WriteLockScoped write_lock(*receive_crit_); 559 WriteLockScoped write_lock(*receive_crit_);
532 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == 560 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) ==
533 audio_receive_ssrcs_.end()); 561 audio_receive_ssrcs_.end());
534 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; 562 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream;
535 receive_rtp_config_[config.rtp.remote_ssrc] = 563 receive_rtp_config_[config.rtp.remote_ssrc] =
536 ReceiveRtpConfig(config.rtp.extensions, config.rtp.transport_cc); 564 ReceiveRtpConfig(config.rtp.extensions, UseSendSideBwe(config));
537 565
538 ConfigureSync(config.sync_group); 566 ConfigureSync(config.sync_group);
539 } 567 }
540 { 568 {
541 ReadLockScoped read_lock(*send_crit_); 569 ReadLockScoped read_lock(*send_crit_);
542 auto it = audio_send_ssrcs_.find(config.rtp.local_ssrc); 570 auto it = audio_send_ssrcs_.find(config.rtp.local_ssrc);
543 if (it != audio_send_ssrcs_.end()) { 571 if (it != audio_send_ssrcs_.end()) {
544 receive_stream->AssociateSendStream(it->second); 572 receive_stream->AssociateSendStream(it->second);
545 } 573 }
546 } 574 }
547 receive_stream->SignalNetworkState(audio_network_state_); 575 receive_stream->SignalNetworkState(audio_network_state_);
548 UpdateAggregateNetworkState(); 576 UpdateAggregateNetworkState();
549 return receive_stream; 577 return receive_stream;
550 } 578 }
551 579
552 void Call::DestroyAudioReceiveStream( 580 void Call::DestroyAudioReceiveStream(
553 webrtc::AudioReceiveStream* receive_stream) { 581 webrtc::AudioReceiveStream* receive_stream) {
554 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); 582 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream");
555 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 583 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
556 RTC_DCHECK(receive_stream != nullptr); 584 RTC_DCHECK(receive_stream != nullptr);
557 webrtc::internal::AudioReceiveStream* audio_receive_stream = 585 webrtc::internal::AudioReceiveStream* audio_receive_stream =
558 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); 586 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream);
559 { 587 {
560 WriteLockScoped write_lock(*receive_crit_); 588 WriteLockScoped write_lock(*receive_crit_);
561 uint32_t ssrc = audio_receive_stream->config().rtp.remote_ssrc; 589 const AudioReceiveStream::Config& config = audio_receive_stream->config();
562 590 uint32_t ssrc = config.rtp.remote_ssrc;
591 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config))
592 ->RemoveStream(ssrc);
563 size_t num_deleted = audio_receive_ssrcs_.erase(ssrc); 593 size_t num_deleted = audio_receive_ssrcs_.erase(ssrc);
564 RTC_DCHECK(num_deleted == 1); 594 RTC_DCHECK(num_deleted == 1);
565 const std::string& sync_group = audio_receive_stream->config().sync_group; 595 const std::string& sync_group = audio_receive_stream->config().sync_group;
566 const auto it = sync_stream_mapping_.find(sync_group); 596 const auto it = sync_stream_mapping_.find(sync_group);
567 if (it != sync_stream_mapping_.end() && 597 if (it != sync_stream_mapping_.end() &&
568 it->second == audio_receive_stream) { 598 it->second == audio_receive_stream) {
569 sync_stream_mapping_.erase(it); 599 sync_stream_mapping_.erase(it);
570 ConfigureSync(sync_group); 600 ConfigureSync(sync_group);
571 } 601 }
572 receive_rtp_config_.erase(ssrc); 602 receive_rtp_config_.erase(ssrc);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 680 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
651 681
652 bool protected_by_flexfec = false; 682 bool protected_by_flexfec = false;
653 { 683 {
654 ReadLockScoped read_lock(*receive_crit_); 684 ReadLockScoped read_lock(*receive_crit_);
655 protected_by_flexfec = 685 protected_by_flexfec =
656 flexfec_receive_ssrcs_media_.find(configuration.rtp.remote_ssrc) != 686 flexfec_receive_ssrcs_media_.find(configuration.rtp.remote_ssrc) !=
657 flexfec_receive_ssrcs_media_.end(); 687 flexfec_receive_ssrcs_media_.end();
658 } 688 }
659 VideoReceiveStream* receive_stream = new VideoReceiveStream( 689 VideoReceiveStream* receive_stream = new VideoReceiveStream(
660 num_cpu_cores_, protected_by_flexfec, congestion_controller_.get(), 690 num_cpu_cores_, protected_by_flexfec,
661 &packet_router_, std::move(configuration), module_process_thread_.get(), 691 &packet_router_, std::move(configuration), module_process_thread_.get(),
662 call_stats_.get(), &remb_); 692 call_stats_.get(), &remb_);
663 693
664 const webrtc::VideoReceiveStream::Config& config = receive_stream->config(); 694 const webrtc::VideoReceiveStream::Config& config = receive_stream->config();
665 ReceiveRtpConfig receive_config(config.rtp.extensions, 695 ReceiveRtpConfig receive_config(config.rtp.extensions,
666 config.rtp.transport_cc); 696 UseSendSideBwe(config));
667 { 697 {
668 WriteLockScoped write_lock(*receive_crit_); 698 WriteLockScoped write_lock(*receive_crit_);
669 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == 699 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) ==
670 video_receive_ssrcs_.end()); 700 video_receive_ssrcs_.end());
671 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; 701 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream;
672 if (config.rtp.rtx_ssrc) { 702 if (config.rtp.rtx_ssrc) {
673 video_receive_ssrcs_[config.rtp.rtx_ssrc] = receive_stream; 703 video_receive_ssrcs_[config.rtp.rtx_ssrc] = receive_stream;
674 // We record identical config for the rtx stream as for the main 704 // We record identical config for the rtx stream as for the main
675 // stream. Since the transport_cc negotiation is per payload 705 // stream. Since the transport_cc negotiation is per payload
676 // type, we may get an incorrect value for the rtx stream, but 706 // type, we may get an incorrect value for the rtx stream, but
(...skipping 29 matching lines...) Expand all
706 receive_rtp_config_.erase(it->first); 736 receive_rtp_config_.erase(it->first);
707 it = video_receive_ssrcs_.erase(it); 737 it = video_receive_ssrcs_.erase(it);
708 } else { 738 } else {
709 ++it; 739 ++it;
710 } 740 }
711 } 741 }
712 video_receive_streams_.erase(receive_stream_impl); 742 video_receive_streams_.erase(receive_stream_impl);
713 RTC_CHECK(receive_stream_impl != nullptr); 743 RTC_CHECK(receive_stream_impl != nullptr);
714 ConfigureSync(receive_stream_impl->config().sync_group); 744 ConfigureSync(receive_stream_impl->config().sync_group);
715 } 745 }
746 const VideoReceiveStream::Config& config = receive_stream_impl->config();
747
748 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config))
749 ->RemoveStream(config.rtp.remote_ssrc);
750
716 UpdateAggregateNetworkState(); 751 UpdateAggregateNetworkState();
717 delete receive_stream_impl; 752 delete receive_stream_impl;
718 } 753 }
719 754
720 FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( 755 FlexfecReceiveStream* Call::CreateFlexfecReceiveStream(
721 const FlexfecReceiveStream::Config& config) { 756 const FlexfecReceiveStream::Config& config) {
722 TRACE_EVENT0("webrtc", "Call::CreateFlexfecReceiveStream"); 757 TRACE_EVENT0("webrtc", "Call::CreateFlexfecReceiveStream");
723 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 758 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
724 759
725 RecoveredPacketReceiver* recovered_packet_receiver = this; 760 RecoveredPacketReceiver* recovered_packet_receiver = this;
(...skipping 11 matching lines...) Expand all
737 for (auto ssrc : config.protected_media_ssrcs) 772 for (auto ssrc : config.protected_media_ssrcs)
738 flexfec_receive_ssrcs_media_.insert(std::make_pair(ssrc, receive_stream)); 773 flexfec_receive_ssrcs_media_.insert(std::make_pair(ssrc, receive_stream));
739 774
740 RTC_DCHECK(flexfec_receive_ssrcs_protection_.find(config.remote_ssrc) == 775 RTC_DCHECK(flexfec_receive_ssrcs_protection_.find(config.remote_ssrc) ==
741 flexfec_receive_ssrcs_protection_.end()); 776 flexfec_receive_ssrcs_protection_.end());
742 flexfec_receive_ssrcs_protection_[config.remote_ssrc] = receive_stream; 777 flexfec_receive_ssrcs_protection_[config.remote_ssrc] = receive_stream;
743 778
744 RTC_DCHECK(receive_rtp_config_.find(config.remote_ssrc) == 779 RTC_DCHECK(receive_rtp_config_.find(config.remote_ssrc) ==
745 receive_rtp_config_.end()); 780 receive_rtp_config_.end());
746 receive_rtp_config_[config.remote_ssrc] = 781 receive_rtp_config_[config.remote_ssrc] =
747 ReceiveRtpConfig(config.rtp_header_extensions, config.transport_cc); 782 ReceiveRtpConfig(config.rtp_header_extensions, UseSendSideBwe(config));
748 } 783 }
749 784
750 // TODO(brandtr): Store config in RtcEventLog here. 785 // TODO(brandtr): Store config in RtcEventLog here.
751 786
752 return receive_stream; 787 return receive_stream;
753 } 788 }
754 789
755 void Call::DestroyFlexfecReceiveStream(FlexfecReceiveStream* receive_stream) { 790 void Call::DestroyFlexfecReceiveStream(FlexfecReceiveStream* receive_stream) {
756 TRACE_EVENT0("webrtc", "Call::DestroyFlexfecReceiveStream"); 791 TRACE_EVENT0("webrtc", "Call::DestroyFlexfecReceiveStream");
757 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 792 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]); 1260 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]);
1226 ReadLockScoped read_lock(*receive_crit_); 1261 ReadLockScoped read_lock(*receive_crit_);
1227 auto it = video_receive_ssrcs_.find(ssrc); 1262 auto it = video_receive_ssrcs_.find(ssrc);
1228 if (it == video_receive_ssrcs_.end()) 1263 if (it == video_receive_ssrcs_.end())
1229 return false; 1264 return false;
1230 return it->second->OnRecoveredPacket(packet, length); 1265 return it->second->OnRecoveredPacket(packet, length);
1231 } 1266 }
1232 1267
1233 void Call::NotifyBweOfReceivedPacket(const RtpPacketReceived& packet) { 1268 void Call::NotifyBweOfReceivedPacket(const RtpPacketReceived& packet) {
1234 auto it = receive_rtp_config_.find(packet.Ssrc()); 1269 auto it = receive_rtp_config_.find(packet.Ssrc());
1235 bool transport_cc = 1270 bool use_send_side_bwe =
1236 (it != receive_rtp_config_.end()) && it->second.transport_cc; 1271 (it != receive_rtp_config_.end()) && it->second.use_send_side_bwe;
1237 1272
1238 RTPHeader header; 1273 RTPHeader header;
1239 packet.GetHeader(&header); 1274 packet.GetHeader(&header);
1240 1275
1241 // transport_cc represents the negotiation of the RTCP feedback 1276 // This can fail in two ways: Either send side BWE was negotiated (both RTP
1242 // message used for send side BWE. If it was negotiated but the 1277 // extension and RTCP feedback), but the received RTP packets don't carry any
1243 // corresponding RTP header extension is not present, or vice versa, 1278 // transport sequence number. Or the transport sequence number extension was
1244 // bandwidth estimation is not correctly configured. 1279 // negotiated and is in use, but RTCP feed wasn't negotiated, so we can't send
1245 if (transport_cc != header.extension.hasTransportSequenceNumber) { 1280 // any feedback. In the latter case, it might be desirable to fall back to
1281 // receive side bandwidth estimation, but to do that, we would need to tell
1282 // the congestion controller to ignore the transport sequence number.
1283 if (use_send_side_bwe != header.extension.hasTransportSequenceNumber) {
stefan-webrtc 2017/02/02 10:42:52 I'm not entirely sure it's worth logging when this
nisse-webrtc 2017/02/02 11:56:00 In this case I think use_send_side_bwe will be fal
stefan-webrtc 2017/02/02 12:27:37 But as I see it use_send_side_bwe can be true if e
1246 LOG(LS_ERROR) << "Inconsistent configuration of send side BWE."; 1284 LOG(LS_ERROR) << "Inconsistent configuration of send side BWE.";
1247 return; 1285 return;
1248 } 1286 }
1249 congestion_controller_->OnReceivedPacket(packet.arrival_time_ms(), 1287 congestion_controller_->OnReceivedPacket(packet.arrival_time_ms(),
1250 packet.payload_size(), header); 1288 packet.payload_size(), header);
1251 } 1289 }
1252 1290
1253 } // namespace internal 1291 } // namespace internal
1254 } // namespace webrtc 1292 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/audio/audio_receive_stream_unittest.cc ('k') | webrtc/video/rtp_stream_receiver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698