Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <map> | 13 #include <map> |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <utility> | |
| 15 #include <vector> | 16 #include <vector> |
| 16 | 17 |
| 17 #include "webrtc/audio/audio_receive_stream.h" | 18 #include "webrtc/audio/audio_receive_stream.h" |
| 18 #include "webrtc/audio/audio_send_stream.h" | 19 #include "webrtc/audio/audio_send_stream.h" |
| 19 #include "webrtc/audio/audio_state.h" | 20 #include "webrtc/audio/audio_state.h" |
| 20 #include "webrtc/audio/scoped_voe_interface.h" | 21 #include "webrtc/audio/scoped_voe_interface.h" |
| 21 #include "webrtc/base/basictypes.h" | 22 #include "webrtc/base/basictypes.h" |
| 22 #include "webrtc/base/checks.h" | 23 #include "webrtc/base/checks.h" |
| 23 #include "webrtc/base/constructormagic.h" | 24 #include "webrtc/base/constructormagic.h" |
| 24 #include "webrtc/base/logging.h" | 25 #include "webrtc/base/logging.h" |
| 25 #include "webrtc/base/task_queue.h" | 26 #include "webrtc/base/task_queue.h" |
| 26 #include "webrtc/base/thread_annotations.h" | 27 #include "webrtc/base/thread_annotations.h" |
| 27 #include "webrtc/base/thread_checker.h" | 28 #include "webrtc/base/thread_checker.h" |
| 28 #include "webrtc/base/trace_event.h" | 29 #include "webrtc/base/trace_event.h" |
| 29 #include "webrtc/call.h" | 30 #include "webrtc/call.h" |
| 30 #include "webrtc/call/bitrate_allocator.h" | 31 #include "webrtc/call/bitrate_allocator.h" |
| 32 #include "webrtc/call/flexfec_receive_stream.h" | |
| 31 #include "webrtc/config.h" | 33 #include "webrtc/config.h" |
| 32 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 34 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
| 33 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 35 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 34 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 36 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
| 35 #include "webrtc/modules/pacing/paced_sender.h" | 37 #include "webrtc/modules/pacing/paced_sender.h" |
| 36 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" | 38 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
| 37 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 39 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
| 38 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 40 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 39 #include "webrtc/modules/utility/include/process_thread.h" | 41 #include "webrtc/modules/utility/include/process_thread.h" |
| 40 #include "webrtc/system_wrappers/include/clock.h" | 42 #include "webrtc/system_wrappers/include/clock.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 59 | 61 |
| 60 class Call : public webrtc::Call, | 62 class Call : public webrtc::Call, |
| 61 public PacketReceiver, | 63 public PacketReceiver, |
| 62 public RecoveredPacketReceiver, | 64 public RecoveredPacketReceiver, |
| 63 public CongestionController::Observer, | 65 public CongestionController::Observer, |
| 64 public BitrateAllocator::LimitObserver { | 66 public BitrateAllocator::LimitObserver { |
| 65 public: | 67 public: |
| 66 explicit Call(const Call::Config& config); | 68 explicit Call(const Call::Config& config); |
| 67 virtual ~Call(); | 69 virtual ~Call(); |
| 68 | 70 |
| 71 // Implements webrtc::Call. | |
| 69 PacketReceiver* Receiver() override; | 72 PacketReceiver* Receiver() override; |
| 70 | 73 |
| 71 webrtc::AudioSendStream* CreateAudioSendStream( | 74 webrtc::AudioSendStream* CreateAudioSendStream( |
| 72 const webrtc::AudioSendStream::Config& config) override; | 75 const webrtc::AudioSendStream::Config& config) override; |
| 73 void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override; | 76 void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override; |
| 74 | 77 |
| 75 webrtc::AudioReceiveStream* CreateAudioReceiveStream( | 78 webrtc::AudioReceiveStream* CreateAudioReceiveStream( |
| 76 const webrtc::AudioReceiveStream::Config& config) override; | 79 const webrtc::AudioReceiveStream::Config& config) override; |
| 77 void DestroyAudioReceiveStream( | 80 void DestroyAudioReceiveStream( |
| 78 webrtc::AudioReceiveStream* receive_stream) override; | 81 webrtc::AudioReceiveStream* receive_stream) override; |
| 79 | 82 |
| 80 webrtc::VideoSendStream* CreateVideoSendStream( | 83 webrtc::VideoSendStream* CreateVideoSendStream( |
| 81 webrtc::VideoSendStream::Config config, | 84 webrtc::VideoSendStream::Config config, |
| 82 VideoEncoderConfig encoder_config) override; | 85 VideoEncoderConfig encoder_config) override; |
| 83 void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) override; | 86 void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) override; |
| 84 | 87 |
| 85 webrtc::VideoReceiveStream* CreateVideoReceiveStream( | 88 webrtc::VideoReceiveStream* CreateVideoReceiveStream( |
| 86 webrtc::VideoReceiveStream::Config configuration) override; | 89 webrtc::VideoReceiveStream::Config configuration) override; |
| 87 void DestroyVideoReceiveStream( | 90 void DestroyVideoReceiveStream( |
| 88 webrtc::VideoReceiveStream* receive_stream) override; | 91 webrtc::VideoReceiveStream* receive_stream) override; |
| 89 | 92 |
| 93 webrtc::FlexfecReceiveStream* CreateFlexfecReceiveStream( | |
| 94 webrtc::FlexfecReceiveStream::Config configuration) override; | |
| 95 void DestroyFlexfecReceiveStream( | |
| 96 webrtc::FlexfecReceiveStream* receive_stream) override; | |
| 97 | |
| 90 Stats GetStats() const override; | 98 Stats GetStats() const override; |
| 91 | 99 |
| 100 // Implements PacketReceiver. | |
| 92 DeliveryStatus DeliverPacket(MediaType media_type, | 101 DeliveryStatus DeliverPacket(MediaType media_type, |
| 93 const uint8_t* packet, | 102 const uint8_t* packet, |
| 94 size_t length, | 103 size_t length, |
| 95 const PacketTime& packet_time) override; | 104 const PacketTime& packet_time) override; |
| 96 | 105 |
| 97 // Implements RecoveredPacketReceiver. | 106 // Implements RecoveredPacketReceiver. |
| 98 bool OnRecoveredPacket(const uint8_t* packet, size_t length) override; | 107 bool OnRecoveredPacket(const uint8_t* packet, size_t length) override; |
| 99 | 108 |
| 100 void SetBitrateConfig( | 109 void SetBitrateConfig( |
| 101 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; | 110 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 NetworkState video_network_state_; | 162 NetworkState video_network_state_; |
| 154 | 163 |
| 155 std::unique_ptr<RWLockWrapper> receive_crit_; | 164 std::unique_ptr<RWLockWrapper> receive_crit_; |
| 156 // Audio and Video receive streams are owned by the client that creates them. | 165 // Audio and Video receive streams are owned by the client that creates them. |
| 157 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ | 166 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ |
| 158 GUARDED_BY(receive_crit_); | 167 GUARDED_BY(receive_crit_); |
| 159 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ | 168 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ |
| 160 GUARDED_BY(receive_crit_); | 169 GUARDED_BY(receive_crit_); |
| 161 std::set<VideoReceiveStream*> video_receive_streams_ | 170 std::set<VideoReceiveStream*> video_receive_streams_ |
| 162 GUARDED_BY(receive_crit_); | 171 GUARDED_BY(receive_crit_); |
| 172 std::multimap<uint32_t, FlexfecReceiveStream*> flexfec_receive_ssrcs_media_ | |
| 173 GUARDED_BY(receive_crit_); | |
| 174 std::map<uint32_t, FlexfecReceiveStream*> flexfec_receive_ssrcs_protection_ | |
| 175 GUARDED_BY(receive_crit_); | |
| 176 std::set<FlexfecReceiveStream*> flexfec_receive_streams_ | |
| 177 GUARDED_BY(receive_crit_); | |
| 163 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ | 178 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ |
| 164 GUARDED_BY(receive_crit_); | 179 GUARDED_BY(receive_crit_); |
| 165 | 180 |
| 166 std::unique_ptr<RWLockWrapper> send_crit_; | 181 std::unique_ptr<RWLockWrapper> send_crit_; |
| 167 // Audio and Video send streams are owned by the client that creates them. | 182 // Audio and Video send streams are owned by the client that creates them. |
| 168 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_); | 183 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_); |
| 169 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); | 184 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); |
| 170 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); | 185 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); |
| 171 | 186 |
| 172 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; | 187 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 } | 586 } |
| 572 } | 587 } |
| 573 video_receive_streams_.erase(receive_stream_impl); | 588 video_receive_streams_.erase(receive_stream_impl); |
| 574 RTC_CHECK(receive_stream_impl != nullptr); | 589 RTC_CHECK(receive_stream_impl != nullptr); |
| 575 ConfigureSync(receive_stream_impl->config().sync_group); | 590 ConfigureSync(receive_stream_impl->config().sync_group); |
| 576 } | 591 } |
| 577 UpdateAggregateNetworkState(); | 592 UpdateAggregateNetworkState(); |
| 578 delete receive_stream_impl; | 593 delete receive_stream_impl; |
| 579 } | 594 } |
| 580 | 595 |
| 596 webrtc::FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( | |
| 597 webrtc::FlexfecReceiveStream::Config configuration) { | |
| 598 TRACE_EVENT0("webrtc", "Call::CreateFlexfecReceiveStream"); | |
| 599 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | |
| 600 FlexfecReceiveStream* receive_stream = | |
| 601 new FlexfecReceiveStream(std::move(configuration), this); | |
| 602 | |
| 603 const webrtc::FlexfecReceiveStream::Config& config = receive_stream->config(); | |
| 604 { | |
| 605 WriteLockScoped write_lock(*receive_crit_); | |
| 606 for (auto ssrc : config.protected_media_ssrcs) | |
| 607 flexfec_receive_ssrcs_media_.insert(std::make_pair(ssrc, receive_stream)); | |
| 608 RTC_DCHECK(flexfec_receive_ssrcs_protection_.find(config.flexfec_ssrc) == | |
| 609 flexfec_receive_ssrcs_protection_.end()); | |
| 610 flexfec_receive_ssrcs_protection_[config.flexfec_ssrc] = receive_stream; | |
| 611 flexfec_receive_streams_.insert(receive_stream); | |
| 612 } | |
| 613 // TODO(brandtr): Store config in RtcEventLog here. | |
| 614 return receive_stream; | |
| 615 } | |
| 616 | |
| 617 void Call::DestroyFlexfecReceiveStream( | |
| 618 webrtc::FlexfecReceiveStream* receive_stream) { | |
| 619 TRACE_EVENT0("webrtc", "Call::DestroyFlexfecReceiveStream"); | |
| 620 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | |
| 621 RTC_DCHECK(receive_stream != nullptr); | |
| 622 FlexfecReceiveStream* receive_stream_impl = nullptr; | |
| 623 { | |
| 624 WriteLockScoped write_lock(*receive_crit_); | |
| 625 // Remove all ssrcs pointing to a receive stream. | |
|
stefan-webrtc
2016/10/18 18:13:29
"...pointing to the FlexFec receive stream to be d
brandtr
2016/10/19 08:14:31
Yep, fixed.
| |
| 626 auto media_it = flexfec_receive_ssrcs_media_.begin(); | |
| 627 while (media_it != flexfec_receive_ssrcs_media_.end()) { | |
| 628 if (media_it->second == | |
| 629 static_cast<FlexfecReceiveStream*>(receive_stream)) { | |
| 630 if (receive_stream_impl != nullptr) | |
| 631 RTC_DCHECK(receive_stream_impl == media_it->second); | |
| 632 receive_stream_impl = media_it->second; | |
| 633 flexfec_receive_ssrcs_media_.erase(media_it++); | |
| 634 } else { | |
| 635 ++media_it; | |
| 636 } | |
| 637 } | |
| 638 auto prot_it = flexfec_receive_ssrcs_protection_.begin(); | |
| 639 while (prot_it != flexfec_receive_ssrcs_protection_.end()) { | |
| 640 if (prot_it->second == | |
| 641 static_cast<FlexfecReceiveStream*>(receive_stream)) { | |
| 642 if (receive_stream_impl != nullptr) | |
| 643 RTC_DCHECK(receive_stream_impl == prot_it->second); | |
| 644 receive_stream_impl = prot_it->second; | |
| 645 flexfec_receive_ssrcs_protection_.erase(prot_it++); | |
| 646 } else { | |
| 647 ++prot_it; | |
| 648 } | |
| 649 } | |
| 650 flexfec_receive_streams_.erase(receive_stream_impl); | |
|
stefan-webrtc
2016/10/18 18:13:29
If flexfec_receive_streams_ own the receive stream
brandtr
2016/10/19 08:14:31
Yes, but Call will not own the created FlexfecRece
| |
| 651 RTC_CHECK(receive_stream_impl != nullptr); | |
| 652 } | |
| 653 delete receive_stream_impl; | |
| 654 } | |
| 655 | |
| 581 Call::Stats Call::GetStats() const { | 656 Call::Stats Call::GetStats() const { |
| 582 // TODO(solenberg): Some test cases in EndToEndTest use this from a different | 657 // TODO(solenberg): Some test cases in EndToEndTest use this from a different |
| 583 // thread. Re-enable once that is fixed. | 658 // thread. Re-enable once that is fixed. |
| 584 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 659 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 585 Stats stats; | 660 Stats stats; |
| 586 // Fetch available send/receive bitrates. | 661 // Fetch available send/receive bitrates. |
| 587 uint32_t send_bandwidth = 0; | 662 uint32_t send_bandwidth = 0; |
| 588 congestion_controller_->GetBitrateController()->AvailableBandwidth( | 663 congestion_controller_->GetBitrateController()->AvailableBandwidth( |
| 589 &send_bandwidth); | 664 &send_bandwidth); |
| 590 std::vector<unsigned int> ssrcs; | 665 std::vector<unsigned int> ssrcs; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 916 } | 991 } |
| 917 } | 992 } |
| 918 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { | 993 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
| 919 auto it = video_receive_ssrcs_.find(ssrc); | 994 auto it = video_receive_ssrcs_.find(ssrc); |
| 920 if (it != video_receive_ssrcs_.end()) { | 995 if (it != video_receive_ssrcs_.end()) { |
| 921 received_bytes_per_second_counter_.Add(static_cast<int>(length)); | 996 received_bytes_per_second_counter_.Add(static_cast<int>(length)); |
| 922 received_video_bytes_per_second_counter_.Add(static_cast<int>(length)); | 997 received_video_bytes_per_second_counter_.Add(static_cast<int>(length)); |
| 923 auto status = it->second->DeliverRtp(packet, length, packet_time) | 998 auto status = it->second->DeliverRtp(packet, length, packet_time) |
| 924 ? DELIVERY_OK | 999 ? DELIVERY_OK |
| 925 : DELIVERY_PACKET_ERROR; | 1000 : DELIVERY_PACKET_ERROR; |
| 1001 auto flexfec_lower_it = flexfec_receive_ssrcs_media_.lower_bound(ssrc); | |
| 1002 auto flexfec_upper_it = flexfec_receive_ssrcs_media_.upper_bound(ssrc); | |
| 1003 while (flexfec_lower_it != flexfec_upper_it) { | |
| 1004 flexfec_lower_it->second->AddAndProcessReceivedPacket(packet, length); | |
| 1005 ++flexfec_lower_it; | |
| 1006 } | |
| 1007 if (status == DELIVERY_OK) | |
| 1008 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); | |
| 1009 return status; | |
| 1010 } | |
| 1011 } | |
| 1012 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { | |
| 1013 auto it = flexfec_receive_ssrcs_protection_.find(ssrc); | |
| 1014 if (it != flexfec_receive_ssrcs_protection_.end()) { | |
| 1015 auto status = it->second->AddAndProcessReceivedPacket(packet, length) | |
| 1016 ? DELIVERY_OK | |
| 1017 : DELIVERY_PACKET_ERROR; | |
| 926 if (status == DELIVERY_OK) | 1018 if (status == DELIVERY_OK) |
| 927 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); | 1019 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); |
| 928 return status; | 1020 return status; |
| 929 } | 1021 } |
| 930 } | 1022 } |
| 931 return DELIVERY_UNKNOWN_SSRC; | 1023 return DELIVERY_UNKNOWN_SSRC; |
| 932 } | 1024 } |
| 933 | 1025 |
| 934 PacketReceiver::DeliveryStatus Call::DeliverPacket( | 1026 PacketReceiver::DeliveryStatus Call::DeliverPacket( |
| 935 MediaType media_type, | 1027 MediaType media_type, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 952 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]); | 1044 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]); |
| 953 ReadLockScoped read_lock(*receive_crit_); | 1045 ReadLockScoped read_lock(*receive_crit_); |
| 954 auto it = video_receive_ssrcs_.find(ssrc); | 1046 auto it = video_receive_ssrcs_.find(ssrc); |
| 955 if (it != video_receive_ssrcs_.end()) | 1047 if (it != video_receive_ssrcs_.end()) |
| 956 return it->second->OnRecoveredPacket(packet, length); | 1048 return it->second->OnRecoveredPacket(packet, length); |
| 957 return false; | 1049 return false; |
| 958 } | 1050 } |
| 959 | 1051 |
| 960 } // namespace internal | 1052 } // namespace internal |
| 961 } // namespace webrtc | 1053 } // namespace webrtc |
| OLD | NEW |