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

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

Issue 2388303009: Integrate FlexfecReceiveStream with Call. (Closed)
Patch Set: Rebase. Created 4 years, 2 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/call.h ('k') | webrtc/call/call_unittest.cc » ('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
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
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 const std::unique_ptr<ProcessThread> pacer_thread_; 155 const std::unique_ptr<ProcessThread> pacer_thread_;
147 const std::unique_ptr<CallStats> call_stats_; 156 const std::unique_ptr<CallStats> call_stats_;
148 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; 157 const std::unique_ptr<BitrateAllocator> bitrate_allocator_;
149 Call::Config config_; 158 Call::Config config_;
150 rtc::ThreadChecker configuration_thread_checker_; 159 rtc::ThreadChecker configuration_thread_checker_;
151 160
152 NetworkState audio_network_state_; 161 NetworkState audio_network_state_;
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, Video, and FlexFEC receive streams are owned by the client that
166 // creates them.
157 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ 167 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_
158 GUARDED_BY(receive_crit_); 168 GUARDED_BY(receive_crit_);
159 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ 169 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_
160 GUARDED_BY(receive_crit_); 170 GUARDED_BY(receive_crit_);
161 std::set<VideoReceiveStream*> video_receive_streams_ 171 std::set<VideoReceiveStream*> video_receive_streams_
162 GUARDED_BY(receive_crit_); 172 GUARDED_BY(receive_crit_);
173 // Each media stream could conceivably be protected by multiple FlexFEC
174 // streams.
175 std::multimap<uint32_t, FlexfecReceiveStream*> flexfec_receive_ssrcs_media_
176 GUARDED_BY(receive_crit_);
177 std::map<uint32_t, FlexfecReceiveStream*> flexfec_receive_ssrcs_protection_
178 GUARDED_BY(receive_crit_);
179 std::set<FlexfecReceiveStream*> flexfec_receive_streams_
180 GUARDED_BY(receive_crit_);
163 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ 181 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_
164 GUARDED_BY(receive_crit_); 182 GUARDED_BY(receive_crit_);
165 183
166 std::unique_ptr<RWLockWrapper> send_crit_; 184 std::unique_ptr<RWLockWrapper> send_crit_;
167 // Audio and Video send streams are owned by the client that creates them. 185 // 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_); 186 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_); 187 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_);
170 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); 188 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_);
171 189
172 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; 190 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_;
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 } 589 }
572 } 590 }
573 video_receive_streams_.erase(receive_stream_impl); 591 video_receive_streams_.erase(receive_stream_impl);
574 RTC_CHECK(receive_stream_impl != nullptr); 592 RTC_CHECK(receive_stream_impl != nullptr);
575 ConfigureSync(receive_stream_impl->config().sync_group); 593 ConfigureSync(receive_stream_impl->config().sync_group);
576 } 594 }
577 UpdateAggregateNetworkState(); 595 UpdateAggregateNetworkState();
578 delete receive_stream_impl; 596 delete receive_stream_impl;
579 } 597 }
580 598
599 webrtc::FlexfecReceiveStream* Call::CreateFlexfecReceiveStream(
600 webrtc::FlexfecReceiveStream::Config configuration) {
601 TRACE_EVENT0("webrtc", "Call::CreateFlexfecReceiveStream");
602 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
603 FlexfecReceiveStream* receive_stream =
604 new FlexfecReceiveStream(std::move(configuration), this);
605
606 const webrtc::FlexfecReceiveStream::Config& config = receive_stream->config();
607 {
608 WriteLockScoped write_lock(*receive_crit_);
609 for (auto ssrc : config.protected_media_ssrcs)
610 flexfec_receive_ssrcs_media_.insert(std::make_pair(ssrc, receive_stream));
611 RTC_DCHECK(flexfec_receive_ssrcs_protection_.find(config.flexfec_ssrc) ==
612 flexfec_receive_ssrcs_protection_.end());
613 flexfec_receive_ssrcs_protection_[config.flexfec_ssrc] = receive_stream;
614 flexfec_receive_streams_.insert(receive_stream);
615 }
616 // TODO(brandtr): Store config in RtcEventLog here.
617 return receive_stream;
618 }
619
620 void Call::DestroyFlexfecReceiveStream(
621 webrtc::FlexfecReceiveStream* receive_stream) {
622 TRACE_EVENT0("webrtc", "Call::DestroyFlexfecReceiveStream");
623 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
624 RTC_DCHECK(receive_stream != nullptr);
625 // There exist no other derived classes of webrtc::FlexfecReceiveStream,
626 // so this downcast is safe.
627 FlexfecReceiveStream* receive_stream_impl =
628 static_cast<FlexfecReceiveStream*>(receive_stream);
629 {
630 WriteLockScoped write_lock(*receive_crit_);
631 // Remove all SSRCs pointing to the FlexfecReceiveStream to be destroyed.
632 auto media_it = flexfec_receive_ssrcs_media_.begin();
633 while (media_it != flexfec_receive_ssrcs_media_.end()) {
634 if (media_it->second == receive_stream_impl)
635 media_it = flexfec_receive_ssrcs_media_.erase(media_it);
636 else
637 ++media_it;
638 }
639 auto prot_it = flexfec_receive_ssrcs_protection_.begin();
640 while (prot_it != flexfec_receive_ssrcs_protection_.end()) {
641 if (prot_it->second == receive_stream_impl)
stefan-webrtc 2016/10/20 16:23:26 {}, here and above
brandtr 2016/10/21 08:40:26 While I personally like the braces for single-line
stefan-webrtc 2016/10/21 11:07:35 My impression has always been that an if-else is a
brandtr 2016/10/21 12:18:39 Seems fairly common with if/else without braces: h
642 prot_it = flexfec_receive_ssrcs_protection_.erase(prot_it);
643 else
644 ++prot_it;
645 }
646 flexfec_receive_streams_.erase(receive_stream_impl);
647 }
648 delete receive_stream_impl;
649 }
650
581 Call::Stats Call::GetStats() const { 651 Call::Stats Call::GetStats() const {
582 // TODO(solenberg): Some test cases in EndToEndTest use this from a different 652 // TODO(solenberg): Some test cases in EndToEndTest use this from a different
583 // thread. Re-enable once that is fixed. 653 // thread. Re-enable once that is fixed.
584 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 654 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
585 Stats stats; 655 Stats stats;
586 // Fetch available send/receive bitrates. 656 // Fetch available send/receive bitrates.
587 uint32_t send_bandwidth = 0; 657 uint32_t send_bandwidth = 0;
588 congestion_controller_->GetBitrateController()->AvailableBandwidth( 658 congestion_controller_->GetBitrateController()->AvailableBandwidth(
589 &send_bandwidth); 659 &send_bandwidth);
590 std::vector<unsigned int> ssrcs; 660 std::vector<unsigned int> ssrcs;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 } 986 }
917 } 987 }
918 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { 988 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) {
919 auto it = video_receive_ssrcs_.find(ssrc); 989 auto it = video_receive_ssrcs_.find(ssrc);
920 if (it != video_receive_ssrcs_.end()) { 990 if (it != video_receive_ssrcs_.end()) {
921 received_bytes_per_second_counter_.Add(static_cast<int>(length)); 991 received_bytes_per_second_counter_.Add(static_cast<int>(length));
922 received_video_bytes_per_second_counter_.Add(static_cast<int>(length)); 992 received_video_bytes_per_second_counter_.Add(static_cast<int>(length));
923 auto status = it->second->DeliverRtp(packet, length, packet_time) 993 auto status = it->second->DeliverRtp(packet, length, packet_time)
924 ? DELIVERY_OK 994 ? DELIVERY_OK
925 : DELIVERY_PACKET_ERROR; 995 : DELIVERY_PACKET_ERROR;
996 // Deliver media packets to FlexFEC subsystem.
997 auto it_bounds = flexfec_receive_ssrcs_media_.equal_range(ssrc);
998 for (auto it = it_bounds.first; it != it_bounds.second; ++it)
999 it->second->AddAndProcessReceivedPacket(packet, length);
1000 if (status == DELIVERY_OK)
1001 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length);
1002 return status;
1003 }
1004 }
1005 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) {
1006 auto it = flexfec_receive_ssrcs_protection_.find(ssrc);
1007 if (it != flexfec_receive_ssrcs_protection_.end()) {
1008 auto status = it->second->AddAndProcessReceivedPacket(packet, length)
1009 ? DELIVERY_OK
1010 : DELIVERY_PACKET_ERROR;
926 if (status == DELIVERY_OK) 1011 if (status == DELIVERY_OK)
927 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); 1012 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length);
928 return status; 1013 return status;
929 } 1014 }
930 } 1015 }
931 return DELIVERY_UNKNOWN_SSRC; 1016 return DELIVERY_UNKNOWN_SSRC;
932 } 1017 }
933 1018
934 PacketReceiver::DeliveryStatus Call::DeliverPacket( 1019 PacketReceiver::DeliveryStatus Call::DeliverPacket(
935 MediaType media_type, 1020 MediaType media_type,
(...skipping 16 matching lines...) Expand all
952 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]); 1037 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]);
953 ReadLockScoped read_lock(*receive_crit_); 1038 ReadLockScoped read_lock(*receive_crit_);
954 auto it = video_receive_ssrcs_.find(ssrc); 1039 auto it = video_receive_ssrcs_.find(ssrc);
955 if (it == video_receive_ssrcs_.end()) 1040 if (it == video_receive_ssrcs_.end())
956 return false; 1041 return false;
957 return it->second->OnRecoveredPacket(packet, length); 1042 return it->second->OnRecoveredPacket(packet, length);
958 } 1043 }
959 1044
960 } // namespace internal 1045 } // namespace internal
961 } // namespace webrtc 1046 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/call.h ('k') | webrtc/call/call_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698