pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 11 | #include <string.h> |
| 12 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 13 | #include <map> |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 14 | #include <memory> |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Peter Boström | 5c389d3 | 2015-09-25 13:58:30 +0200 | [diff] [blame] | 17 | #include "webrtc/audio/audio_receive_stream.h" |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 18 | #include "webrtc/audio/audio_send_stream.h" |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 19 | #include "webrtc/audio/audio_state.h" |
| 20 | #include "webrtc/audio/scoped_voe_interface.h" |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 21 | #include "webrtc/base/checks.h" |
Peter Boström | 7c704b8 | 2015-12-04 16:13:05 +0100 | [diff] [blame] | 22 | #include "webrtc/base/logging.h" |
pbos@webrtc.org | 38344ed | 2014-09-24 06:05:00 +0000 | [diff] [blame] | 23 | #include "webrtc/base/thread_annotations.h" |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 24 | #include "webrtc/base/thread_checker.h" |
tommi | e4f9650 | 2015-10-20 23:00:48 -0700 | [diff] [blame] | 25 | #include "webrtc/base/trace_event.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 26 | #include "webrtc/call.h" |
mflodman | 0e7e259 | 2015-11-12 21:02:42 -0800 | [diff] [blame] | 27 | #include "webrtc/call/bitrate_allocator.h" |
Peter Boström | 5c389d3 | 2015-09-25 13:58:30 +0200 | [diff] [blame] | 28 | #include "webrtc/call/rtc_event_log.h" |
pbos@webrtc.org | c49d5b7 | 2013-12-05 12:11:47 +0000 | [diff] [blame] | 29 | #include "webrtc/config.h" |
mflodman | 0e7e259 | 2015-11-12 21:02:42 -0800 | [diff] [blame] | 30 | #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
Stefan Holmer | 80e1207 | 2016-02-23 13:30:42 +0100 | [diff] [blame] | 31 | #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
Henrik Kjellander | 0b9e29c | 2015-11-16 11:12:24 +0100 | [diff] [blame] | 32 | #include "webrtc/modules/pacing/paced_sender.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 33 | #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
sprang@webrtc.org | 2a6558c | 2015-01-28 12:37:36 +0000 | [diff] [blame] | 34 | #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 35 | #include "webrtc/modules/utility/include/process_thread.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 36 | #include "webrtc/system_wrappers/include/cpu_info.h" |
| 37 | #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 38 | #include "webrtc/system_wrappers/include/metrics.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 39 | #include "webrtc/system_wrappers/include/rw_lock_wrapper.h" |
| 40 | #include "webrtc/system_wrappers/include/trace.h" |
Peter Boström | 7623ce4 | 2015-12-09 12:13:30 +0100 | [diff] [blame] | 41 | #include "webrtc/video/call_stats.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 42 | #include "webrtc/video/video_receive_stream.h" |
| 43 | #include "webrtc/video/video_send_stream.h" |
Stefan Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 44 | #include "webrtc/video/vie_remb.h" |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 45 | #include "webrtc/voice_engine/include/voe_codec.h" |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 46 | |
| 47 | namespace webrtc { |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 48 | |
pbos@webrtc.org | a73a678 | 2014-10-14 11:52:10 +0000 | [diff] [blame] | 49 | const int Call::Config::kDefaultStartBitrateBps = 300000; |
| 50 | |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 51 | namespace internal { |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 52 | |
mflodman | 0e7e259 | 2015-11-12 21:02:42 -0800 | [diff] [blame] | 53 | class Call : public webrtc::Call, public PacketReceiver, |
| 54 | public BitrateObserver { |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 55 | public: |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 56 | explicit Call(const Call::Config& config); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 57 | virtual ~Call(); |
| 58 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 59 | PacketReceiver* Receiver() override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 60 | |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 61 | webrtc::AudioSendStream* CreateAudioSendStream( |
| 62 | const webrtc::AudioSendStream::Config& config) override; |
| 63 | void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override; |
| 64 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 65 | webrtc::AudioReceiveStream* CreateAudioReceiveStream( |
| 66 | const webrtc::AudioReceiveStream::Config& config) override; |
| 67 | void DestroyAudioReceiveStream( |
| 68 | webrtc::AudioReceiveStream* receive_stream) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 69 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 70 | webrtc::VideoSendStream* CreateVideoSendStream( |
| 71 | const webrtc::VideoSendStream::Config& config, |
| 72 | const VideoEncoderConfig& encoder_config) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 73 | void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 74 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 75 | webrtc::VideoReceiveStream* CreateVideoReceiveStream( |
| 76 | const webrtc::VideoReceiveStream::Config& config) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 77 | void DestroyVideoReceiveStream( |
| 78 | webrtc::VideoReceiveStream* receive_stream) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 79 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 80 | Stats GetStats() const override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 81 | |
stefan | 68786d2 | 2015-09-08 05:36:15 -0700 | [diff] [blame] | 82 | DeliveryStatus DeliverPacket(MediaType media_type, |
| 83 | const uint8_t* packet, |
| 84 | size_t length, |
| 85 | const PacketTime& packet_time) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 86 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 87 | void SetBitrateConfig( |
| 88 | const webrtc::Call::Config::BitrateConfig& bitrate_config) override; |
| 89 | void SignalNetworkState(NetworkState state) override; |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 90 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 91 | void OnSentPacket(const rtc::SentPacket& sent_packet) override; |
| 92 | |
mflodman | 0e7e259 | 2015-11-12 21:02:42 -0800 | [diff] [blame] | 93 | // Implements BitrateObserver. |
| 94 | void OnNetworkChanged(uint32_t bitrate_bps, uint8_t fraction_loss, |
| 95 | int64_t rtt_ms) override; |
| 96 | |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 97 | private: |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 98 | DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, |
| 99 | size_t length); |
stefan | 68786d2 | 2015-09-08 05:36:15 -0700 | [diff] [blame] | 100 | DeliveryStatus DeliverRtp(MediaType media_type, |
| 101 | const uint8_t* packet, |
| 102 | size_t length, |
| 103 | const PacketTime& packet_time); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 104 | |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 105 | void ConfigureSync(const std::string& sync_group) |
| 106 | EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
| 107 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 108 | VoiceEngine* voice_engine() { |
| 109 | internal::AudioState* audio_state = |
| 110 | static_cast<internal::AudioState*>(config_.audio_state.get()); |
| 111 | if (audio_state) |
| 112 | return audio_state->voice_engine(); |
| 113 | else |
| 114 | return nullptr; |
| 115 | } |
| 116 | |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 117 | void UpdateSendHistograms() EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 118 | void UpdateReceiveHistograms(); |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 119 | |
Peter Boström | d3c9447 | 2015-12-09 11:20:58 +0100 | [diff] [blame] | 120 | Clock* const clock_; |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 121 | |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 122 | const int num_cpu_cores_; |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 123 | const std::unique_ptr<ProcessThread> module_process_thread_; |
| 124 | const std::unique_ptr<ProcessThread> pacer_thread_; |
| 125 | const std::unique_ptr<CallStats> call_stats_; |
| 126 | const std::unique_ptr<BitrateAllocator> bitrate_allocator_; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 127 | Call::Config config_; |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 128 | rtc::ThreadChecker configuration_thread_checker_; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 129 | |
Fredrik Solenberg | ea07373 | 2015-12-01 11:26:34 +0100 | [diff] [blame] | 130 | bool network_enabled_; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 131 | |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 132 | std::unique_ptr<RWLockWrapper> receive_crit_; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 133 | // Audio and Video receive streams are owned by the client that creates them. |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 134 | std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 135 | GUARDED_BY(receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 136 | std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ |
| 137 | GUARDED_BY(receive_crit_); |
| 138 | std::set<VideoReceiveStream*> video_receive_streams_ |
| 139 | GUARDED_BY(receive_crit_); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 140 | std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ |
| 141 | GUARDED_BY(receive_crit_); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 142 | |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 143 | std::unique_ptr<RWLockWrapper> send_crit_; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 144 | // Audio and Video send streams are owned by the client that creates them. |
| 145 | std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 146 | std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); |
| 147 | std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 148 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 149 | VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 150 | |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 151 | RtcEventLog* event_log_ = nullptr; |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 152 | |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 153 | // The following members are only accessed (exclusively) from one thread and |
| 154 | // from the destructor, and therefore doesn't need any explicit |
| 155 | // synchronization. |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 156 | int64_t received_video_bytes_; |
| 157 | int64_t received_audio_bytes_; |
| 158 | int64_t received_rtcp_bytes_; |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 159 | int64_t first_rtp_packet_received_ms_; |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 160 | int64_t last_rtp_packet_received_ms_; |
| 161 | int64_t first_packet_sent_ms_; |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 162 | |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 163 | // TODO(holmer): Remove this lock once BitrateController no longer calls |
| 164 | // OnNetworkChanged from multiple threads. |
| 165 | rtc::CriticalSection bitrate_crit_; |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 166 | int64_t estimated_send_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_); |
| 167 | int64_t pacer_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_); |
| 168 | int64_t num_bitrate_updates_ GUARDED_BY(&bitrate_crit_); |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 169 | |
Stefan Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 170 | VieRemb remb_; |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 171 | const std::unique_ptr<CongestionController> congestion_controller_; |
mflodman | 0e7e259 | 2015-11-12 21:02:42 -0800 | [diff] [blame] | 172 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 173 | RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 174 | }; |
pbos@webrtc.org | c49d5b7 | 2013-12-05 12:11:47 +0000 | [diff] [blame] | 175 | } // namespace internal |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 176 | |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 177 | Call* Call::Create(const Call::Config& config) { |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 178 | return new internal::Call(config); |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 179 | } |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 180 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 181 | namespace internal { |
| 182 | |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 183 | Call::Call(const Call::Config& config) |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 184 | : clock_(Clock::GetRealTimeClock()), |
| 185 | num_cpu_cores_(CpuInfo::DetectNumberOfCores()), |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 186 | module_process_thread_( |
| 187 | rtc::ScopedToUnique(ProcessThread::Create("ModuleProcessThread"))), |
| 188 | pacer_thread_(rtc::ScopedToUnique(ProcessThread::Create("PacerThread"))), |
Peter Boström | d3c9447 | 2015-12-09 11:20:58 +0100 | [diff] [blame] | 189 | call_stats_(new CallStats(clock_)), |
mflodman | 0e7e259 | 2015-11-12 21:02:42 -0800 | [diff] [blame] | 190 | bitrate_allocator_(new BitrateAllocator()), |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 191 | config_(config), |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 192 | network_enabled_(true), |
| 193 | receive_crit_(RWLockWrapper::CreateRWLock()), |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 194 | send_crit_(RWLockWrapper::CreateRWLock()), |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 195 | received_video_bytes_(0), |
| 196 | received_audio_bytes_(0), |
| 197 | received_rtcp_bytes_(0), |
mflodman | 0e7e259 | 2015-11-12 21:02:42 -0800 | [diff] [blame] | 198 | first_rtp_packet_received_ms_(-1), |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 199 | last_rtp_packet_received_ms_(-1), |
| 200 | first_packet_sent_ms_(-1), |
| 201 | estimated_send_bitrate_sum_kbits_(0), |
| 202 | pacer_bitrate_sum_kbits_(0), |
| 203 | num_bitrate_updates_(0), |
Stefan Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 204 | remb_(clock_), |
Stefan Holmer | 789ba92 | 2016-02-17 15:52:17 +0100 | [diff] [blame] | 205 | congestion_controller_(new CongestionController(clock_, this, &remb_)) { |
solenberg | 56a34df | 2015-11-12 08:24:41 -0800 | [diff] [blame] | 206 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 207 | RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
| 208 | RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
| 209 | config.bitrate_config.min_bitrate_bps); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 210 | if (config.bitrate_config.max_bitrate_bps != -1) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 211 | RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
| 212 | config.bitrate_config.start_bitrate_bps); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 213 | } |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 214 | if (config.audio_state.get()) { |
| 215 | ScopedVoEInterface<VoECodec> voe_codec(voice_engine()); |
| 216 | event_log_ = voe_codec->GetEventLog(); |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 217 | } |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 218 | |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 219 | Trace::CreateTrace(); |
Stefan Holmer | 789ba92 | 2016-02-17 15:52:17 +0100 | [diff] [blame] | 220 | call_stats_->RegisterStatsObserver(congestion_controller_.get()); |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 221 | |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 222 | congestion_controller_->SetBweBitrates( |
| 223 | config_.bitrate_config.min_bitrate_bps, |
| 224 | config_.bitrate_config.start_bitrate_bps, |
| 225 | config_.bitrate_config.max_bitrate_bps); |
terelius | 006d93d | 2015-11-05 12:02:15 -0800 | [diff] [blame] | 226 | congestion_controller_->GetBitrateController()->SetEventLog(event_log_); |
Stefan Holmer | c379fcb | 2016-02-24 16:02:55 +0100 | [diff] [blame] | 227 | |
| 228 | module_process_thread_->Start(); |
| 229 | module_process_thread_->RegisterModule(call_stats_.get()); |
| 230 | module_process_thread_->RegisterModule(congestion_controller_.get()); |
| 231 | pacer_thread_->RegisterModule(congestion_controller_->pacer()); |
| 232 | pacer_thread_->RegisterModule( |
| 233 | congestion_controller_->GetRemoteBitrateEstimator(true)); |
| 234 | pacer_thread_->Start(); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 235 | } |
| 236 | |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 237 | Call::~Call() { |
Stefan Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 238 | RTC_DCHECK(!remb_.InUse()); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 239 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 240 | UpdateSendHistograms(); |
| 241 | UpdateReceiveHistograms(); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 242 | RTC_CHECK(audio_send_ssrcs_.empty()); |
| 243 | RTC_CHECK(video_send_ssrcs_.empty()); |
| 244 | RTC_CHECK(video_send_streams_.empty()); |
| 245 | RTC_CHECK(audio_receive_ssrcs_.empty()); |
| 246 | RTC_CHECK(video_receive_ssrcs_.empty()); |
| 247 | RTC_CHECK(video_receive_streams_.empty()); |
pbos@webrtc.org | 9e4e524 | 2015-02-12 10:48:23 +0000 | [diff] [blame] | 248 | |
Stefan Holmer | c379fcb | 2016-02-24 16:02:55 +0100 | [diff] [blame] | 249 | pacer_thread_->Stop(); |
| 250 | pacer_thread_->DeRegisterModule(congestion_controller_->pacer()); |
| 251 | pacer_thread_->DeRegisterModule( |
| 252 | congestion_controller_->GetRemoteBitrateEstimator(true)); |
Stefan Holmer | 789ba92 | 2016-02-17 15:52:17 +0100 | [diff] [blame] | 253 | module_process_thread_->DeRegisterModule(congestion_controller_.get()); |
mflodman | e378702 | 2015-10-21 13:24:28 +0200 | [diff] [blame] | 254 | module_process_thread_->DeRegisterModule(call_stats_.get()); |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 255 | module_process_thread_->Stop(); |
Stefan Holmer | c379fcb | 2016-02-24 16:02:55 +0100 | [diff] [blame] | 256 | call_stats_->DeregisterStatsObserver(congestion_controller_.get()); |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 257 | Trace::ReturnTrace(); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 258 | } |
| 259 | |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 260 | void Call::UpdateSendHistograms() { |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 261 | if (num_bitrate_updates_ == 0 || first_packet_sent_ms_ == -1) |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 262 | return; |
| 263 | int64_t elapsed_sec = |
| 264 | (clock_->TimeInMilliseconds() - first_packet_sent_ms_) / 1000; |
| 265 | if (elapsed_sec < metrics::kMinRunTimeInSeconds) |
| 266 | return; |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 267 | int send_bitrate_kbps = |
| 268 | estimated_send_bitrate_sum_kbits_ / num_bitrate_updates_; |
| 269 | int pacer_bitrate_kbps = pacer_bitrate_sum_kbits_ / num_bitrate_updates_; |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 270 | if (send_bitrate_kbps > 0) { |
asapersson | 28ba927 | 2016-01-25 05:58:23 -0800 | [diff] [blame] | 271 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.EstimatedSendBitrateInKbps", |
| 272 | send_bitrate_kbps); |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 273 | } |
| 274 | if (pacer_bitrate_kbps > 0) { |
asapersson | 28ba927 | 2016-01-25 05:58:23 -0800 | [diff] [blame] | 275 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.PacerBitrateInKbps", |
| 276 | pacer_bitrate_kbps); |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
| 280 | void Call::UpdateReceiveHistograms() { |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 281 | if (first_rtp_packet_received_ms_ == -1) |
| 282 | return; |
| 283 | int64_t elapsed_sec = |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 284 | (last_rtp_packet_received_ms_ - first_rtp_packet_received_ms_) / 1000; |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 285 | if (elapsed_sec < metrics::kMinRunTimeInSeconds) |
| 286 | return; |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 287 | int audio_bitrate_kbps = received_audio_bytes_ * 8 / elapsed_sec / 1000; |
| 288 | int video_bitrate_kbps = received_video_bytes_ * 8 / elapsed_sec / 1000; |
| 289 | int rtcp_bitrate_bps = received_rtcp_bytes_ * 8 / elapsed_sec; |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 290 | if (video_bitrate_kbps > 0) { |
asapersson | 28ba927 | 2016-01-25 05:58:23 -0800 | [diff] [blame] | 291 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.VideoBitrateReceivedInKbps", |
| 292 | video_bitrate_kbps); |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 293 | } |
| 294 | if (audio_bitrate_kbps > 0) { |
asapersson | 28ba927 | 2016-01-25 05:58:23 -0800 | [diff] [blame] | 295 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.AudioBitrateReceivedInKbps", |
| 296 | audio_bitrate_kbps); |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 297 | } |
| 298 | if (rtcp_bitrate_bps > 0) { |
asapersson | 28ba927 | 2016-01-25 05:58:23 -0800 | [diff] [blame] | 299 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.RtcpBitrateReceivedInBps", |
| 300 | rtcp_bitrate_bps); |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 301 | } |
asapersson | 28ba927 | 2016-01-25 05:58:23 -0800 | [diff] [blame] | 302 | RTC_HISTOGRAM_COUNTS_100000( |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 303 | "WebRTC.Call.BitrateReceivedInKbps", |
| 304 | audio_bitrate_kbps + video_bitrate_kbps + rtcp_bitrate_bps / 1000); |
| 305 | } |
| 306 | |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 307 | PacketReceiver* Call::Receiver() { |
| 308 | // TODO(solenberg): Some test cases in EndToEndTest use this from a different |
| 309 | // thread. Re-enable once that is fixed. |
| 310 | // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 311 | return this; |
| 312 | } |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 313 | |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 314 | webrtc::AudioSendStream* Call::CreateAudioSendStream( |
| 315 | const webrtc::AudioSendStream::Config& config) { |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 316 | TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 317 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 318 | AudioSendStream* send_stream = new AudioSendStream( |
| 319 | config, config_.audio_state, congestion_controller_.get()); |
mflodman | 717432f | 2015-10-26 16:34:46 +0100 | [diff] [blame] | 320 | if (!network_enabled_) |
| 321 | send_stream->SignalNetworkState(kNetworkDown); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 322 | { |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 323 | WriteLockScoped write_lock(*send_crit_); |
| 324 | RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == |
| 325 | audio_send_ssrcs_.end()); |
| 326 | audio_send_ssrcs_[config.rtp.ssrc] = send_stream; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 327 | } |
| 328 | return send_stream; |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 332 | TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 333 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 334 | RTC_DCHECK(send_stream != nullptr); |
| 335 | |
| 336 | send_stream->Stop(); |
| 337 | |
| 338 | webrtc::internal::AudioSendStream* audio_send_stream = |
| 339 | static_cast<webrtc::internal::AudioSendStream*>(send_stream); |
| 340 | { |
| 341 | WriteLockScoped write_lock(*send_crit_); |
| 342 | size_t num_deleted = audio_send_ssrcs_.erase( |
| 343 | audio_send_stream->config().rtp.ssrc); |
| 344 | RTC_DCHECK(num_deleted == 1); |
| 345 | } |
| 346 | delete audio_send_stream; |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 347 | } |
| 348 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 349 | webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( |
| 350 | const webrtc::AudioReceiveStream::Config& config) { |
| 351 | TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 352 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 353 | AudioReceiveStream* receive_stream = new AudioReceiveStream( |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 354 | congestion_controller_.get(), config, config_.audio_state); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 355 | { |
| 356 | WriteLockScoped write_lock(*receive_crit_); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 357 | RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| 358 | audio_receive_ssrcs_.end()); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 359 | audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 360 | ConfigureSync(config.sync_group); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 361 | } |
| 362 | return receive_stream; |
| 363 | } |
| 364 | |
| 365 | void Call::DestroyAudioReceiveStream( |
| 366 | webrtc::AudioReceiveStream* receive_stream) { |
| 367 | TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 368 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 369 | RTC_DCHECK(receive_stream != nullptr); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 370 | webrtc::internal::AudioReceiveStream* audio_receive_stream = |
| 371 | static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 372 | { |
| 373 | WriteLockScoped write_lock(*receive_crit_); |
| 374 | size_t num_deleted = audio_receive_ssrcs_.erase( |
| 375 | audio_receive_stream->config().rtp.remote_ssrc); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 376 | RTC_DCHECK(num_deleted == 1); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 377 | const std::string& sync_group = audio_receive_stream->config().sync_group; |
| 378 | const auto it = sync_stream_mapping_.find(sync_group); |
| 379 | if (it != sync_stream_mapping_.end() && |
| 380 | it->second == audio_receive_stream) { |
| 381 | sync_stream_mapping_.erase(it); |
| 382 | ConfigureSync(sync_group); |
| 383 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 384 | } |
| 385 | delete audio_receive_stream; |
| 386 | } |
| 387 | |
| 388 | webrtc::VideoSendStream* Call::CreateVideoSendStream( |
| 389 | const webrtc::VideoSendStream::Config& config, |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 390 | const VideoEncoderConfig& encoder_config) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 391 | TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 392 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
pbos@webrtc.org | 1819fd7 | 2013-06-10 13:48:26 +0000 | [diff] [blame] | 393 | |
mflodman@webrtc.org | eb16b81 | 2014-06-16 08:57:39 +0000 | [diff] [blame] | 394 | // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if |
| 395 | // the call has already started. |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 396 | VideoSendStream* send_stream = new VideoSendStream( |
| 397 | num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), |
mflodman | 86aabb2 | 2016-03-11 15:44:32 +0100 | [diff] [blame] | 398 | congestion_controller_.get(), bitrate_allocator_.get(), &remb_, config, |
mflodman | 0e7e259 | 2015-11-12 21:02:42 -0800 | [diff] [blame] | 399 | encoder_config, suspended_video_send_ssrcs_); |
pbos@webrtc.org | 1819fd7 | 2013-06-10 13:48:26 +0000 | [diff] [blame] | 400 | |
mflodman | 717432f | 2015-10-26 16:34:46 +0100 | [diff] [blame] | 401 | if (!network_enabled_) |
| 402 | send_stream->SignalNetworkState(kNetworkDown); |
| 403 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 404 | WriteLockScoped write_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 405 | for (uint32_t ssrc : config.rtp.ssrcs) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 406 | RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 407 | video_send_ssrcs_[ssrc] = send_stream; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 408 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 409 | video_send_streams_.insert(send_stream); |
| 410 | |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 411 | if (event_log_) |
| 412 | event_log_->LogVideoSendStreamConfig(config); |
| 413 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 414 | return send_stream; |
| 415 | } |
| 416 | |
pbos@webrtc.org | 2c46f8d | 2013-11-21 13:49:43 +0000 | [diff] [blame] | 417 | void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 418 | TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream"); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 419 | RTC_DCHECK(send_stream != nullptr); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 420 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 421 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 422 | send_stream->Stop(); |
| 423 | |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 424 | VideoSendStream* send_stream_impl = nullptr; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 425 | { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 426 | WriteLockScoped write_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 427 | auto it = video_send_ssrcs_.begin(); |
| 428 | while (it != video_send_ssrcs_.end()) { |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 429 | if (it->second == static_cast<VideoSendStream*>(send_stream)) { |
| 430 | send_stream_impl = it->second; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 431 | video_send_ssrcs_.erase(it++); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 432 | } else { |
| 433 | ++it; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 434 | } |
| 435 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 436 | video_send_streams_.erase(send_stream_impl); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 437 | } |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 438 | RTC_CHECK(send_stream_impl != nullptr); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 439 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 440 | VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates(); |
| 441 | |
| 442 | for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin(); |
| 443 | it != rtp_state.end(); |
| 444 | ++it) { |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 445 | suspended_video_send_ssrcs_[it->first] = it->second; |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 446 | } |
| 447 | |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 448 | delete send_stream_impl; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 451 | webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( |
| 452 | const webrtc::VideoReceiveStream::Config& config) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 453 | TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 454 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
Peter Boström | c4188fd | 2015-04-24 15:16:03 +0200 | [diff] [blame] | 455 | VideoReceiveStream* receive_stream = new VideoReceiveStream( |
Stefan Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 456 | num_cpu_cores_, congestion_controller_.get(), config, voice_engine(), |
| 457 | module_process_thread_.get(), call_stats_.get(), &remb_); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 458 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 459 | WriteLockScoped write_lock(*receive_crit_); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 460 | RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| 461 | video_receive_ssrcs_.end()); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 462 | video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 463 | // TODO(pbos): Configure different RTX payloads per receive payload. |
| 464 | VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = |
| 465 | config.rtp.rtx.begin(); |
| 466 | if (it != config.rtp.rtx.end()) |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 467 | video_receive_ssrcs_[it->second.ssrc] = receive_stream; |
| 468 | video_receive_streams_.insert(receive_stream); |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 469 | |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 470 | ConfigureSync(config.sync_group); |
| 471 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 472 | if (!network_enabled_) |
| 473 | receive_stream->SignalNetworkState(kNetworkDown); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 474 | |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 475 | if (event_log_) |
| 476 | event_log_->LogVideoReceiveStreamConfig(config); |
| 477 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 478 | return receive_stream; |
| 479 | } |
| 480 | |
pbos@webrtc.org | 2c46f8d | 2013-11-21 13:49:43 +0000 | [diff] [blame] | 481 | void Call::DestroyVideoReceiveStream( |
| 482 | webrtc::VideoReceiveStream* receive_stream) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 483 | TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 484 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 485 | RTC_DCHECK(receive_stream != nullptr); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 486 | VideoReceiveStream* receive_stream_impl = nullptr; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 487 | { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 488 | WriteLockScoped write_lock(*receive_crit_); |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 489 | // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a |
| 490 | // separate SSRC there can be either one or two. |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 491 | auto it = video_receive_ssrcs_.begin(); |
| 492 | while (it != video_receive_ssrcs_.end()) { |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 493 | if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 494 | if (receive_stream_impl != nullptr) |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 495 | RTC_DCHECK(receive_stream_impl == it->second); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 496 | receive_stream_impl = it->second; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 497 | video_receive_ssrcs_.erase(it++); |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 498 | } else { |
| 499 | ++it; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 500 | } |
| 501 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 502 | video_receive_streams_.erase(receive_stream_impl); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 503 | RTC_CHECK(receive_stream_impl != nullptr); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 504 | ConfigureSync(receive_stream_impl->config().sync_group); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 505 | } |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 506 | delete receive_stream_impl; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 507 | } |
| 508 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 509 | Call::Stats Call::GetStats() const { |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 510 | // TODO(solenberg): Some test cases in EndToEndTest use this from a different |
| 511 | // thread. Re-enable once that is fixed. |
| 512 | // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 513 | Stats stats; |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 514 | // Fetch available send/receive bitrates. |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 515 | uint32_t send_bandwidth = 0; |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 516 | congestion_controller_->GetBitrateController()->AvailableBandwidth( |
| 517 | &send_bandwidth); |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 518 | std::vector<unsigned int> ssrcs; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 519 | uint32_t recv_bandwidth = 0; |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 520 | congestion_controller_->GetRemoteBitrateEstimator(false)->LatestEstimate( |
mflodman | a20de20 | 2015-10-18 22:08:19 -0700 | [diff] [blame] | 521 | &ssrcs, &recv_bandwidth); |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 522 | stats.send_bandwidth_bps = send_bandwidth; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 523 | stats.recv_bandwidth_bps = recv_bandwidth; |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 524 | stats.pacer_delay_ms = congestion_controller_->GetPacerQueuingDelayMs(); |
sprang | e2d83d6 | 2016-02-19 09:03:26 -0800 | [diff] [blame] | 525 | stats.rtt_ms = call_stats_->rtcp_rtt_stats()->LastProcessedRtt(); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 526 | return stats; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 527 | } |
| 528 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 529 | void Call::SetBitrateConfig( |
| 530 | const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 531 | TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 532 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 533 | RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 534 | if (bitrate_config.max_bitrate_bps != -1) |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 535 | RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 536 | if (config_.bitrate_config.min_bitrate_bps == |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 537 | bitrate_config.min_bitrate_bps && |
| 538 | (bitrate_config.start_bitrate_bps <= 0 || |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 539 | config_.bitrate_config.start_bitrate_bps == |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 540 | bitrate_config.start_bitrate_bps) && |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 541 | config_.bitrate_config.max_bitrate_bps == |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 542 | bitrate_config.max_bitrate_bps) { |
| 543 | // Nothing new to set, early abort to avoid encoder reconfigurations. |
| 544 | return; |
| 545 | } |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 546 | config_.bitrate_config = bitrate_config; |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 547 | congestion_controller_->SetBweBitrates(bitrate_config.min_bitrate_bps, |
| 548 | bitrate_config.start_bitrate_bps, |
| 549 | bitrate_config.max_bitrate_bps); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 550 | } |
| 551 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 552 | void Call::SignalNetworkState(NetworkState state) { |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 553 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 554 | network_enabled_ = state == kNetworkUp; |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 555 | congestion_controller_->SignalNetworkState(state); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 556 | { |
| 557 | ReadLockScoped write_lock(*send_crit_); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 558 | for (auto& kv : audio_send_ssrcs_) { |
| 559 | kv.second->SignalNetworkState(state); |
| 560 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 561 | for (auto& kv : video_send_ssrcs_) { |
| 562 | kv.second->SignalNetworkState(state); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | { |
| 566 | ReadLockScoped write_lock(*receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 567 | for (auto& kv : video_receive_ssrcs_) { |
| 568 | kv.second->SignalNetworkState(state); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | } |
| 572 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 573 | void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 574 | if (first_packet_sent_ms_ == -1) |
| 575 | first_packet_sent_ms_ = clock_->TimeInMilliseconds(); |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 576 | congestion_controller_->OnSentPacket(sent_packet); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 577 | } |
| 578 | |
mflodman | 0e7e259 | 2015-11-12 21:02:42 -0800 | [diff] [blame] | 579 | void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, |
| 580 | int64_t rtt_ms) { |
| 581 | uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged( |
| 582 | target_bitrate_bps, fraction_loss, rtt_ms); |
| 583 | |
| 584 | int pad_up_to_bitrate_bps = 0; |
| 585 | { |
| 586 | ReadLockScoped read_lock(*send_crit_); |
| 587 | // No need to update as long as we're not sending. |
| 588 | if (video_send_streams_.empty()) |
| 589 | return; |
| 590 | |
| 591 | for (VideoSendStream* stream : video_send_streams_) |
| 592 | pad_up_to_bitrate_bps += stream->GetPaddingNeededBps(); |
| 593 | } |
| 594 | // Allocated bitrate might be higher than bitrate estimate if enforcing min |
| 595 | // bitrate, or lower if estimate is higher than the sum of max bitrates, so |
| 596 | // set the pacer bitrate to the maximum of the two. |
| 597 | uint32_t pacer_bitrate_bps = |
| 598 | std::max(target_bitrate_bps, allocated_bitrate_bps); |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 599 | { |
| 600 | rtc::CritScope lock(&bitrate_crit_); |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 601 | // We only update these stats if we have send streams, and assume that |
| 602 | // OnNetworkChanged is called roughly with a fixed frequency. |
| 603 | estimated_send_bitrate_sum_kbits_ += target_bitrate_bps / 1000; |
| 604 | pacer_bitrate_sum_kbits_ += pacer_bitrate_bps / 1000; |
| 605 | ++num_bitrate_updates_; |
stefan | 18adf0a | 2015-11-17 06:24:56 -0800 | [diff] [blame] | 606 | } |
mflodman | 0e7e259 | 2015-11-12 21:02:42 -0800 | [diff] [blame] | 607 | congestion_controller_->UpdatePacerBitrate( |
| 608 | target_bitrate_bps / 1000, |
| 609 | PacedSender::kDefaultPaceMultiplier * pacer_bitrate_bps / 1000, |
| 610 | pad_up_to_bitrate_bps / 1000); |
| 611 | } |
| 612 | |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 613 | void Call::ConfigureSync(const std::string& sync_group) { |
| 614 | // Set sync only if there was no previous one. |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 615 | if (voice_engine() == nullptr || sync_group.empty()) |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 616 | return; |
| 617 | |
| 618 | AudioReceiveStream* sync_audio_stream = nullptr; |
| 619 | // Find existing audio stream. |
| 620 | const auto it = sync_stream_mapping_.find(sync_group); |
| 621 | if (it != sync_stream_mapping_.end()) { |
| 622 | sync_audio_stream = it->second; |
| 623 | } else { |
| 624 | // No configured audio stream, see if we can find one. |
| 625 | for (const auto& kv : audio_receive_ssrcs_) { |
| 626 | if (kv.second->config().sync_group == sync_group) { |
| 627 | if (sync_audio_stream != nullptr) { |
| 628 | LOG(LS_WARNING) << "Attempting to sync more than one audio stream " |
| 629 | "within the same sync group. This is not " |
| 630 | "supported in the current implementation."; |
| 631 | break; |
| 632 | } |
| 633 | sync_audio_stream = kv.second; |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | if (sync_audio_stream) |
| 638 | sync_stream_mapping_[sync_group] = sync_audio_stream; |
| 639 | size_t num_synced_streams = 0; |
| 640 | for (VideoReceiveStream* video_stream : video_receive_streams_) { |
| 641 | if (video_stream->config().sync_group != sync_group) |
| 642 | continue; |
| 643 | ++num_synced_streams; |
| 644 | if (num_synced_streams > 1) { |
| 645 | // TODO(pbos): Support synchronizing more than one A/V pair. |
| 646 | // https://code.google.com/p/webrtc/issues/detail?id=4762 |
| 647 | LOG(LS_WARNING) << "Attempting to sync more than one audio/video pair " |
| 648 | "within the same sync group. This is not supported in " |
| 649 | "the current implementation."; |
| 650 | } |
| 651 | // Only sync the first A/V pair within this sync group. |
| 652 | if (sync_audio_stream != nullptr && num_synced_streams == 1) { |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 653 | video_stream->SetSyncChannel(voice_engine(), |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 654 | sync_audio_stream->config().voe_channel_id); |
| 655 | } else { |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 656 | video_stream->SetSyncChannel(voice_engine(), -1); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | } |
| 660 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 661 | PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type, |
| 662 | const uint8_t* packet, |
| 663 | size_t length) { |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 664 | TRACE_EVENT0("webrtc", "Call::DeliverRtcp"); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 665 | // TODO(pbos): Figure out what channel needs it actually. |
| 666 | // Do NOT broadcast! Also make sure it's a valid packet. |
pbos@webrtc.org | caba2d2 | 2014-05-14 13:57:12 +0000 | [diff] [blame] | 667 | // Return DELIVERY_UNKNOWN_SSRC if it can be determined that |
| 668 | // there's no receiver of the packet. |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 669 | received_rtcp_bytes_ += length; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 670 | bool rtcp_delivered = false; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 671 | if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 672 | ReadLockScoped read_lock(*receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 673 | for (VideoReceiveStream* stream : video_receive_streams_) { |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 674 | if (stream->DeliverRtcp(packet, length)) { |
pbos@webrtc.org | 4052370 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 675 | rtcp_delivered = true; |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 676 | if (event_log_) |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 677 | event_log_->LogRtcpPacket(kIncomingPacket, media_type, packet, |
| 678 | length); |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 679 | } |
pbos@webrtc.org | bbb07e6 | 2013-08-05 12:01:36 +0000 | [diff] [blame] | 680 | } |
| 681 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 682 | if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 683 | ReadLockScoped read_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 684 | for (VideoSendStream* stream : video_send_streams_) { |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 685 | if (stream->DeliverRtcp(packet, length)) { |
pbos@webrtc.org | 4052370 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 686 | rtcp_delivered = true; |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 687 | if (event_log_) |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 688 | event_log_->LogRtcpPacket(kIncomingPacket, media_type, packet, |
| 689 | length); |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 690 | } |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 691 | } |
| 692 | } |
pbos@webrtc.org | caba2d2 | 2014-05-14 13:57:12 +0000 | [diff] [blame] | 693 | return rtcp_delivered ? DELIVERY_OK : DELIVERY_PACKET_ERROR; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 696 | PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type, |
| 697 | const uint8_t* packet, |
stefan | 68786d2 | 2015-09-08 05:36:15 -0700 | [diff] [blame] | 698 | size_t length, |
| 699 | const PacketTime& packet_time) { |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 700 | TRACE_EVENT0("webrtc", "Call::DeliverRtp"); |
pbos@webrtc.org | af38f4e | 2014-07-08 07:38:12 +0000 | [diff] [blame] | 701 | // Minimum RTP header size. |
| 702 | if (length < 12) |
| 703 | return DELIVERY_PACKET_ERROR; |
| 704 | |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 705 | last_rtp_packet_received_ms_ = clock_->TimeInMilliseconds(); |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 706 | if (first_rtp_packet_received_ms_ == -1) |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 707 | first_rtp_packet_received_ms_ = last_rtp_packet_received_ms_; |
pbos@webrtc.org | af38f4e | 2014-07-08 07:38:12 +0000 | [diff] [blame] | 708 | |
stefan | 91d9260 | 2015-11-11 10:13:02 -0800 | [diff] [blame] | 709 | uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 710 | ReadLockScoped read_lock(*receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 711 | if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) { |
| 712 | auto it = audio_receive_ssrcs_.find(ssrc); |
| 713 | if (it != audio_receive_ssrcs_.end()) { |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 714 | received_audio_bytes_ += length; |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 715 | auto status = it->second->DeliverRtp(packet, length, packet_time) |
| 716 | ? DELIVERY_OK |
| 717 | : DELIVERY_PACKET_ERROR; |
| 718 | if (status == DELIVERY_OK && event_log_) |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 719 | event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 720 | return status; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
| 724 | auto it = video_receive_ssrcs_.find(ssrc); |
| 725 | if (it != video_receive_ssrcs_.end()) { |
Stefan Holmer | 226befe | 2015-11-26 15:36:48 +0100 | [diff] [blame] | 726 | received_video_bytes_ += length; |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 727 | auto status = it->second->DeliverRtp(packet, length, packet_time) |
| 728 | ? DELIVERY_OK |
| 729 | : DELIVERY_PACKET_ERROR; |
| 730 | if (status == DELIVERY_OK && event_log_) |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 731 | event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 732 | return status; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | return DELIVERY_UNKNOWN_SSRC; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 736 | } |
| 737 | |
stefan | 68786d2 | 2015-09-08 05:36:15 -0700 | [diff] [blame] | 738 | PacketReceiver::DeliveryStatus Call::DeliverPacket( |
| 739 | MediaType media_type, |
| 740 | const uint8_t* packet, |
| 741 | size_t length, |
| 742 | const PacketTime& packet_time) { |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 743 | // TODO(solenberg): Tests call this function on a network thread, libjingle |
| 744 | // calls on the worker thread. We should move towards always using a network |
| 745 | // thread. Then this check can be enabled. |
| 746 | // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 747 | if (RtpHeaderParser::IsRtcp(packet, length)) |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 748 | return DeliverRtcp(media_type, packet, length); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 749 | |
stefan | 68786d2 | 2015-09-08 05:36:15 -0700 | [diff] [blame] | 750 | return DeliverRtp(media_type, packet, length, packet_time); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | } // namespace internal |
| 754 | } // namespace webrtc |