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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "webrtc/base/location.h" | 26 #include "webrtc/base/location.h" |
27 #include "webrtc/base/logging.h" | 27 #include "webrtc/base/logging.h" |
28 #include "webrtc/base/optional.h" | 28 #include "webrtc/base/optional.h" |
29 #include "webrtc/base/task_queue.h" | 29 #include "webrtc/base/task_queue.h" |
30 #include "webrtc/base/thread_annotations.h" | 30 #include "webrtc/base/thread_annotations.h" |
31 #include "webrtc/base/thread_checker.h" | 31 #include "webrtc/base/thread_checker.h" |
32 #include "webrtc/base/trace_event.h" | 32 #include "webrtc/base/trace_event.h" |
33 #include "webrtc/call/bitrate_allocator.h" | 33 #include "webrtc/call/bitrate_allocator.h" |
34 #include "webrtc/call/call.h" | 34 #include "webrtc/call/call.h" |
35 #include "webrtc/call/flexfec_receive_stream_impl.h" | 35 #include "webrtc/call/flexfec_receive_stream_impl.h" |
| 36 #include "webrtc/call/rtp_transport_controller_receive.h" |
36 #include "webrtc/call/rtp_transport_controller_send.h" | 37 #include "webrtc/call/rtp_transport_controller_send.h" |
37 #include "webrtc/config.h" | 38 #include "webrtc/config.h" |
38 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 39 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
39 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 40 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
40 #include "webrtc/modules/congestion_controller/include/receive_side_congestion_c
ontroller.h" | 41 #include "webrtc/modules/congestion_controller/include/receive_side_congestion_c
ontroller.h" |
41 #include "webrtc/modules/pacing/paced_sender.h" | 42 #include "webrtc/modules/pacing/paced_sender.h" |
42 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" | 43 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
43 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 44 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
44 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 45 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
45 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" | 46 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 const uint8_t* packet, | 170 const uint8_t* packet, |
170 size_t length, | 171 size_t length, |
171 const PacketTime& packet_time); | 172 const PacketTime& packet_time); |
172 void ConfigureSync(const std::string& sync_group) | 173 void ConfigureSync(const std::string& sync_group) |
173 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); | 174 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
174 | 175 |
175 void NotifyBweOfReceivedPacket(const RtpPacketReceived& packet, | 176 void NotifyBweOfReceivedPacket(const RtpPacketReceived& packet, |
176 MediaType media_type) | 177 MediaType media_type) |
177 SHARED_LOCKS_REQUIRED(receive_crit_); | 178 SHARED_LOCKS_REQUIRED(receive_crit_); |
178 | 179 |
179 rtc::Optional<RtpPacketReceived> ParseRtpPacket(const uint8_t* packet, | |
180 size_t length, | |
181 const PacketTime& packet_time) | |
182 SHARED_LOCKS_REQUIRED(receive_crit_); | |
183 | |
184 void UpdateSendHistograms(int64_t first_sent_packet_ms) | 180 void UpdateSendHistograms(int64_t first_sent_packet_ms) |
185 EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); | 181 EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); |
186 void UpdateReceiveHistograms(); | 182 void UpdateReceiveHistograms(); |
187 void UpdateHistograms(); | 183 void UpdateHistograms(); |
188 void UpdateAggregateNetworkState(); | 184 void UpdateAggregateNetworkState(); |
189 | 185 |
190 Clock* const clock_; | 186 Clock* const clock_; |
191 | 187 |
192 const int num_cpu_cores_; | 188 const int num_cpu_cores_; |
193 const std::unique_ptr<ProcessThread> module_process_thread_; | 189 const std::unique_ptr<ProcessThread> module_process_thread_; |
194 const std::unique_ptr<ProcessThread> pacer_thread_; | 190 const std::unique_ptr<ProcessThread> pacer_thread_; |
195 const std::unique_ptr<CallStats> call_stats_; | 191 const std::unique_ptr<CallStats> call_stats_; |
196 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; | 192 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; |
197 Call::Config config_; | 193 Call::Config config_; |
198 rtc::ThreadChecker configuration_thread_checker_; | 194 rtc::ThreadChecker configuration_thread_checker_; |
199 | 195 |
200 NetworkState audio_network_state_; | 196 NetworkState audio_network_state_; |
201 NetworkState video_network_state_; | 197 NetworkState video_network_state_; |
202 | 198 |
203 std::unique_ptr<RWLockWrapper> receive_crit_; | 199 std::unique_ptr<RWLockWrapper> receive_crit_; |
204 // Audio, Video, and FlexFEC receive streams are owned by the client that | 200 // Audio, Video, and FlexFEC receive streams are owned by the client that |
205 // creates them. | 201 // creates them. |
| 202 // TODO(nisse): Try to eliminate these additional mappings. Two of |
| 203 // the users are DeliverRTCP and OnRecoveredPacket. |
206 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ | 204 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ |
207 GUARDED_BY(receive_crit_); | 205 GUARDED_BY(receive_crit_); |
208 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ | 206 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ |
209 GUARDED_BY(receive_crit_); | 207 GUARDED_BY(receive_crit_); |
210 std::set<VideoReceiveStream*> video_receive_streams_ | 208 std::set<VideoReceiveStream*> video_receive_streams_ |
211 GUARDED_BY(receive_crit_); | 209 GUARDED_BY(receive_crit_); |
212 // Each media stream could conceivably be protected by multiple FlexFEC | 210 |
213 // streams. | |
214 std::multimap<uint32_t, FlexfecReceiveStreamImpl*> | |
215 flexfec_receive_ssrcs_media_ GUARDED_BY(receive_crit_); | |
216 std::map<uint32_t, FlexfecReceiveStreamImpl*> | |
217 flexfec_receive_ssrcs_protection_ GUARDED_BY(receive_crit_); | |
218 std::set<FlexfecReceiveStreamImpl*> flexfec_receive_streams_ | |
219 GUARDED_BY(receive_crit_); | |
220 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ | 211 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ |
221 GUARDED_BY(receive_crit_); | 212 GUARDED_BY(receive_crit_); |
222 | 213 |
223 // This extra map is used for receive processing which is | |
224 // independent of media type. | |
225 | |
226 // TODO(nisse): In the RTP transport refactoring, we should have a | |
227 // single mapping from ssrc to a more abstract receive stream, with | |
228 // accessor methods for all configuration we need at this level. | |
229 struct ReceiveRtpConfig { | |
230 ReceiveRtpConfig() = default; // Needed by std::map | |
231 ReceiveRtpConfig(const std::vector<RtpExtension>& extensions, | |
232 bool use_send_side_bwe) | |
233 : extensions(extensions), use_send_side_bwe(use_send_side_bwe) {} | |
234 | |
235 // Registered RTP header extensions for each stream. Note that RTP header | |
236 // extensions are negotiated per track ("m= line") in the SDP, but we have | |
237 // no notion of tracks at the Call level. We therefore store the RTP header | |
238 // extensions per SSRC instead, which leads to some storage overhead. | |
239 RtpHeaderExtensionMap extensions; | |
240 // Set if both RTP extension the RTCP feedback message needed for | |
241 // send side BWE are negotiated. | |
242 bool use_send_side_bwe = false; | |
243 }; | |
244 std::map<uint32_t, ReceiveRtpConfig> receive_rtp_config_ | |
245 GUARDED_BY(receive_crit_); | |
246 | |
247 std::unique_ptr<RWLockWrapper> send_crit_; | 214 std::unique_ptr<RWLockWrapper> send_crit_; |
248 // Audio and Video send streams are owned by the client that creates them. | 215 // Audio and Video send streams are owned by the client that creates them. |
249 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_); | 216 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_); |
250 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); | 217 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); |
251 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); | 218 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); |
252 | 219 |
253 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; | 220 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; |
254 webrtc::RtcEventLog* event_log_; | 221 webrtc::RtcEventLog* event_log_; |
255 | 222 |
256 // The following members are only accessed (exclusively) from one thread and | 223 // The following members are only accessed (exclusively) from one thread and |
257 // from the destructor, and therefore doesn't need any explicit | 224 // from the destructor, and therefore doesn't need any explicit |
258 // synchronization. | 225 // synchronization. |
259 RateCounter received_bytes_per_second_counter_; | 226 RateCounter received_bytes_per_second_counter_; |
260 RateCounter received_audio_bytes_per_second_counter_; | 227 RateCounter received_audio_bytes_per_second_counter_; |
261 RateCounter received_video_bytes_per_second_counter_; | 228 RateCounter received_video_bytes_per_second_counter_; |
262 RateCounter received_rtcp_bytes_per_second_counter_; | 229 RateCounter received_rtcp_bytes_per_second_counter_; |
263 | 230 |
264 // TODO(holmer): Remove this lock once BitrateController no longer calls | 231 // TODO(holmer): Remove this lock once BitrateController no longer calls |
265 // OnNetworkChanged from multiple threads. | 232 // OnNetworkChanged from multiple threads. |
266 rtc::CriticalSection bitrate_crit_; | 233 rtc::CriticalSection bitrate_crit_; |
267 uint32_t min_allocated_send_bitrate_bps_ GUARDED_BY(&bitrate_crit_); | 234 uint32_t min_allocated_send_bitrate_bps_ GUARDED_BY(&bitrate_crit_); |
268 uint32_t configured_max_padding_bitrate_bps_ GUARDED_BY(&bitrate_crit_); | 235 uint32_t configured_max_padding_bitrate_bps_ GUARDED_BY(&bitrate_crit_); |
269 AvgCounter estimated_send_bitrate_kbps_counter_ GUARDED_BY(&bitrate_crit_); | 236 AvgCounter estimated_send_bitrate_kbps_counter_ GUARDED_BY(&bitrate_crit_); |
270 AvgCounter pacer_bitrate_kbps_counter_ GUARDED_BY(&bitrate_crit_); | 237 AvgCounter pacer_bitrate_kbps_counter_ GUARDED_BY(&bitrate_crit_); |
271 | 238 |
272 std::map<std::string, rtc::NetworkRoute> network_routes_; | 239 std::map<std::string, rtc::NetworkRoute> network_routes_; |
273 | 240 |
274 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; | 241 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; |
275 ReceiveSideCongestionController receive_side_cc_; | 242 ReceiveSideCongestionController receive_side_cc_; |
| 243 // TODO(nisse): Currently we always use separate demuxers. These |
| 244 // should be created and owned outside of Call, passing pointers |
| 245 // when Call is created. Then we should have two separate objects in |
| 246 // the unbundled case, and two pointers to the same object in the |
| 247 // bundled case. |
| 248 std::unique_ptr<RtpTransportControllerReceiveInterface> |
| 249 audio_rtp_transport_receive_ GUARDED_BY(receive_crit_); |
| 250 std::unique_ptr<RtpTransportControllerReceiveInterface> |
| 251 video_rtp_transport_receive_ GUARDED_BY(receive_crit_); |
276 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; | 252 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; |
277 const int64_t start_ms_; | 253 const int64_t start_ms_; |
278 // TODO(perkj): |worker_queue_| is supposed to replace | 254 // TODO(perkj): |worker_queue_| is supposed to replace |
279 // |module_process_thread_|. | 255 // |module_process_thread_|. |
280 // |worker_queue| is defined last to ensure all pending tasks are cancelled | 256 // |worker_queue| is defined last to ensure all pending tasks are cancelled |
281 // and deleted before any other members. | 257 // and deleted before any other members. |
282 rtc::TaskQueue worker_queue_; | 258 rtc::TaskQueue worker_queue_; |
283 | 259 |
284 RTC_DISALLOW_COPY_AND_ASSIGN(Call); | 260 RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
285 }; | 261 }; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 event_log_(config.event_log), | 298 event_log_(config.event_log), |
323 received_bytes_per_second_counter_(clock_, nullptr, true), | 299 received_bytes_per_second_counter_(clock_, nullptr, true), |
324 received_audio_bytes_per_second_counter_(clock_, nullptr, true), | 300 received_audio_bytes_per_second_counter_(clock_, nullptr, true), |
325 received_video_bytes_per_second_counter_(clock_, nullptr, true), | 301 received_video_bytes_per_second_counter_(clock_, nullptr, true), |
326 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), | 302 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), |
327 min_allocated_send_bitrate_bps_(0), | 303 min_allocated_send_bitrate_bps_(0), |
328 configured_max_padding_bitrate_bps_(0), | 304 configured_max_padding_bitrate_bps_(0), |
329 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), | 305 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), |
330 pacer_bitrate_kbps_counter_(clock_, nullptr, true), | 306 pacer_bitrate_kbps_counter_(clock_, nullptr, true), |
331 receive_side_cc_(clock_, transport_send->packet_router()), | 307 receive_side_cc_(clock_, transport_send->packet_router()), |
| 308 audio_rtp_transport_receive_( |
| 309 RtpTransportControllerReceiveInterface::Create( |
| 310 &receive_side_cc_, |
| 311 false /* enable_receive_side_bwe */)), |
| 312 video_rtp_transport_receive_( |
| 313 RtpTransportControllerReceiveInterface::Create( |
| 314 &receive_side_cc_, |
| 315 true /* enable_receive_side_bwe */)), |
332 video_send_delay_stats_(new SendDelayStats(clock_)), | 316 video_send_delay_stats_(new SendDelayStats(clock_)), |
333 start_ms_(clock_->TimeInMilliseconds()), | 317 start_ms_(clock_->TimeInMilliseconds()), |
334 worker_queue_("call_worker_queue") { | 318 worker_queue_("call_worker_queue") { |
335 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 319 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
336 RTC_DCHECK(config.event_log != nullptr); | 320 RTC_DCHECK(config.event_log != nullptr); |
337 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); | 321 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
338 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, | 322 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
339 config.bitrate_config.min_bitrate_bps); | 323 config.bitrate_config.min_bitrate_bps); |
340 if (config.bitrate_config.max_bitrate_bps != -1) { | 324 if (config.bitrate_config.max_bitrate_bps != -1) { |
341 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, | 325 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
(...skipping 22 matching lines...) Expand all Loading... |
364 | 348 |
365 pacer_thread_->Start(); | 349 pacer_thread_->Start(); |
366 } | 350 } |
367 | 351 |
368 Call::~Call() { | 352 Call::~Call() { |
369 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 353 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
370 | 354 |
371 RTC_CHECK(audio_send_ssrcs_.empty()); | 355 RTC_CHECK(audio_send_ssrcs_.empty()); |
372 RTC_CHECK(video_send_ssrcs_.empty()); | 356 RTC_CHECK(video_send_ssrcs_.empty()); |
373 RTC_CHECK(video_send_streams_.empty()); | 357 RTC_CHECK(video_send_streams_.empty()); |
374 RTC_CHECK(audio_receive_ssrcs_.empty()); | |
375 RTC_CHECK(video_receive_ssrcs_.empty()); | |
376 RTC_CHECK(video_receive_streams_.empty()); | |
377 | 358 |
378 pacer_thread_->Stop(); | 359 pacer_thread_->Stop(); |
379 pacer_thread_->DeRegisterModule(transport_send_->send_side_cc()->pacer()); | 360 pacer_thread_->DeRegisterModule(transport_send_->send_side_cc()->pacer()); |
380 pacer_thread_->DeRegisterModule( | 361 pacer_thread_->DeRegisterModule( |
381 receive_side_cc_.GetRemoteBitrateEstimator(true)); | 362 receive_side_cc_.GetRemoteBitrateEstimator(true)); |
382 module_process_thread_->DeRegisterModule(transport_send_->send_side_cc()); | 363 module_process_thread_->DeRegisterModule(transport_send_->send_side_cc()); |
383 module_process_thread_->DeRegisterModule(&receive_side_cc_); | 364 module_process_thread_->DeRegisterModule(&receive_side_cc_); |
384 module_process_thread_->DeRegisterModule(call_stats_.get()); | 365 module_process_thread_->DeRegisterModule(call_stats_.get()); |
385 module_process_thread_->Stop(); | 366 module_process_thread_->Stop(); |
386 call_stats_->DeregisterStatsObserver(&receive_side_cc_); | 367 call_stats_->DeregisterStatsObserver(&receive_side_cc_); |
387 call_stats_->DeregisterStatsObserver(transport_send_->send_side_cc()); | 368 call_stats_->DeregisterStatsObserver(transport_send_->send_side_cc()); |
388 | 369 |
389 int64_t first_sent_packet_ms = | 370 int64_t first_sent_packet_ms = |
390 transport_send_->send_side_cc()->GetFirstPacketTimeMs(); | 371 transport_send_->send_side_cc()->GetFirstPacketTimeMs(); |
391 // Only update histograms after process threads have been shut down, so that | 372 // Only update histograms after process threads have been shut down, so that |
392 // they won't try to concurrently update stats. | 373 // they won't try to concurrently update stats. |
393 { | 374 { |
394 rtc::CritScope lock(&bitrate_crit_); | 375 rtc::CritScope lock(&bitrate_crit_); |
395 UpdateSendHistograms(first_sent_packet_ms); | 376 UpdateSendHistograms(first_sent_packet_ms); |
396 } | 377 } |
397 UpdateReceiveHistograms(); | 378 UpdateReceiveHistograms(); |
398 UpdateHistograms(); | 379 UpdateHistograms(); |
399 | 380 |
400 Trace::ReturnTrace(); | 381 Trace::ReturnTrace(); |
401 } | 382 } |
402 | 383 |
403 rtc::Optional<RtpPacketReceived> Call::ParseRtpPacket( | |
404 const uint8_t* packet, | |
405 size_t length, | |
406 const PacketTime& packet_time) { | |
407 RtpPacketReceived parsed_packet; | |
408 if (!parsed_packet.Parse(packet, length)) | |
409 return rtc::Optional<RtpPacketReceived>(); | |
410 | |
411 auto it = receive_rtp_config_.find(parsed_packet.Ssrc()); | |
412 if (it != receive_rtp_config_.end()) | |
413 parsed_packet.IdentifyExtensions(it->second.extensions); | |
414 | |
415 int64_t arrival_time_ms; | |
416 if (packet_time.timestamp != -1) { | |
417 arrival_time_ms = (packet_time.timestamp + 500) / 1000; | |
418 } else { | |
419 arrival_time_ms = clock_->TimeInMilliseconds(); | |
420 } | |
421 parsed_packet.set_arrival_time_ms(arrival_time_ms); | |
422 | |
423 return rtc::Optional<RtpPacketReceived>(std::move(parsed_packet)); | |
424 } | |
425 | |
426 void Call::UpdateHistograms() { | 384 void Call::UpdateHistograms() { |
427 RTC_HISTOGRAM_COUNTS_100000( | 385 RTC_HISTOGRAM_COUNTS_100000( |
428 "WebRTC.Call.LifetimeInSeconds", | 386 "WebRTC.Call.LifetimeInSeconds", |
429 (clock_->TimeInMilliseconds() - start_ms_) / 1000); | 387 (clock_->TimeInMilliseconds() - start_ms_) / 1000); |
430 } | 388 } |
431 | 389 |
432 void Call::UpdateSendHistograms(int64_t first_sent_packet_ms) { | 390 void Call::UpdateSendHistograms(int64_t first_sent_packet_ms) { |
433 if (first_sent_packet_ms == -1) | 391 if (first_sent_packet_ms == -1) |
434 return; | 392 return; |
435 int64_t elapsed_sec = | 393 int64_t elapsed_sec = |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 } | 511 } |
554 | 512 |
555 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( | 513 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( |
556 const webrtc::AudioReceiveStream::Config& config) { | 514 const webrtc::AudioReceiveStream::Config& config) { |
557 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); | 515 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); |
558 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 516 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
559 event_log_->LogAudioReceiveStreamConfig(config); | 517 event_log_->LogAudioReceiveStreamConfig(config); |
560 AudioReceiveStream* receive_stream = | 518 AudioReceiveStream* receive_stream = |
561 new AudioReceiveStream(transport_send_->packet_router(), config, | 519 new AudioReceiveStream(transport_send_->packet_router(), config, |
562 config_.audio_state, event_log_); | 520 config_.audio_state, event_log_); |
| 521 RtpTransportControllerReceiveInterface::Config receive_config; |
| 522 receive_config.use_send_side_bwe = UseSendSideBwe(config); |
| 523 |
563 { | 524 { |
564 WriteLockScoped write_lock(*receive_crit_); | 525 WriteLockScoped write_lock(*receive_crit_); |
565 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == | 526 audio_rtp_transport_receive_->AddReceiver( |
566 audio_receive_ssrcs_.end()); | 527 config.rtp.remote_ssrc, receive_config, receive_stream); |
| 528 |
567 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | 529 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
568 receive_rtp_config_[config.rtp.remote_ssrc] = | |
569 ReceiveRtpConfig(config.rtp.extensions, UseSendSideBwe(config)); | |
570 | |
571 ConfigureSync(config.sync_group); | 530 ConfigureSync(config.sync_group); |
572 } | 531 } |
573 { | 532 { |
574 ReadLockScoped read_lock(*send_crit_); | 533 ReadLockScoped read_lock(*send_crit_); |
575 auto it = audio_send_ssrcs_.find(config.rtp.local_ssrc); | 534 auto it = audio_send_ssrcs_.find(config.rtp.local_ssrc); |
576 if (it != audio_send_ssrcs_.end()) { | 535 if (it != audio_send_ssrcs_.end()) { |
577 receive_stream->AssociateSendStream(it->second); | 536 receive_stream->AssociateSendStream(it->second); |
578 } | 537 } |
579 } | 538 } |
580 receive_stream->SignalNetworkState(audio_network_state_); | 539 receive_stream->SignalNetworkState(audio_network_state_); |
581 UpdateAggregateNetworkState(); | 540 UpdateAggregateNetworkState(); |
582 return receive_stream; | 541 return receive_stream; |
583 } | 542 } |
584 | 543 |
585 void Call::DestroyAudioReceiveStream( | 544 void Call::DestroyAudioReceiveStream( |
586 webrtc::AudioReceiveStream* receive_stream) { | 545 webrtc::AudioReceiveStream* receive_stream) { |
587 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); | 546 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); |
588 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 547 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
589 RTC_DCHECK(receive_stream != nullptr); | 548 RTC_DCHECK(receive_stream != nullptr); |
590 webrtc::internal::AudioReceiveStream* audio_receive_stream = | 549 webrtc::internal::AudioReceiveStream* audio_receive_stream = |
591 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); | 550 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); |
592 { | 551 { |
593 WriteLockScoped write_lock(*receive_crit_); | 552 WriteLockScoped write_lock(*receive_crit_); |
| 553 audio_rtp_transport_receive_->RemoveReceiver(audio_receive_stream); |
| 554 |
594 const AudioReceiveStream::Config& config = audio_receive_stream->config(); | 555 const AudioReceiveStream::Config& config = audio_receive_stream->config(); |
595 uint32_t ssrc = config.rtp.remote_ssrc; | 556 uint32_t ssrc = config.rtp.remote_ssrc; |
596 receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config)) | |
597 ->RemoveStream(ssrc); | |
598 size_t num_deleted = audio_receive_ssrcs_.erase(ssrc); | 557 size_t num_deleted = audio_receive_ssrcs_.erase(ssrc); |
599 RTC_DCHECK(num_deleted == 1); | 558 RTC_DCHECK(num_deleted == 1); |
600 const std::string& sync_group = audio_receive_stream->config().sync_group; | 559 const std::string& sync_group = audio_receive_stream->config().sync_group; |
601 const auto it = sync_stream_mapping_.find(sync_group); | 560 const auto it = sync_stream_mapping_.find(sync_group); |
602 if (it != sync_stream_mapping_.end() && | 561 if (it != sync_stream_mapping_.end() && |
603 it->second == audio_receive_stream) { | 562 it->second == audio_receive_stream) { |
604 sync_stream_mapping_.erase(it); | 563 sync_stream_mapping_.erase(it); |
605 ConfigureSync(sync_group); | 564 ConfigureSync(sync_group); |
606 } | 565 } |
607 receive_rtp_config_.erase(ssrc); | |
608 } | 566 } |
609 UpdateAggregateNetworkState(); | 567 UpdateAggregateNetworkState(); |
610 delete audio_receive_stream; | 568 delete audio_receive_stream; |
611 } | 569 } |
612 | 570 |
613 webrtc::VideoSendStream* Call::CreateVideoSendStream( | 571 webrtc::VideoSendStream* Call::CreateVideoSendStream( |
614 webrtc::VideoSendStream::Config config, | 572 webrtc::VideoSendStream::Config config, |
615 VideoEncoderConfig encoder_config) { | 573 VideoEncoderConfig encoder_config) { |
616 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); | 574 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
617 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 575 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 webrtc::VideoReceiveStream::Config configuration) { | 640 webrtc::VideoReceiveStream::Config configuration) { |
683 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); | 641 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); |
684 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 642 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
685 | 643 |
686 VideoReceiveStream* receive_stream = | 644 VideoReceiveStream* receive_stream = |
687 new VideoReceiveStream(num_cpu_cores_, transport_send_->packet_router(), | 645 new VideoReceiveStream(num_cpu_cores_, transport_send_->packet_router(), |
688 std::move(configuration), | 646 std::move(configuration), |
689 module_process_thread_.get(), call_stats_.get()); | 647 module_process_thread_.get(), call_stats_.get()); |
690 | 648 |
691 const webrtc::VideoReceiveStream::Config& config = receive_stream->config(); | 649 const webrtc::VideoReceiveStream::Config& config = receive_stream->config(); |
692 ReceiveRtpConfig receive_config(config.rtp.extensions, | 650 RtpTransportControllerReceiveInterface::Config receive_config; |
693 UseSendSideBwe(config)); | 651 receive_config.use_send_side_bwe = UseSendSideBwe(config); |
| 652 |
694 { | 653 { |
695 WriteLockScoped write_lock(*receive_crit_); | 654 WriteLockScoped write_lock(*receive_crit_); |
696 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == | 655 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
697 video_receive_ssrcs_.end()); | 656 video_receive_ssrcs_.end()); |
698 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | 657 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
| 658 video_rtp_transport_receive_->AddReceiver( |
| 659 config.rtp.remote_ssrc, receive_config, receive_stream); |
| 660 |
699 if (config.rtp.rtx_ssrc) { | 661 if (config.rtp.rtx_ssrc) { |
700 video_receive_ssrcs_[config.rtp.rtx_ssrc] = receive_stream; | 662 video_receive_ssrcs_[config.rtp.rtx_ssrc] = receive_stream; |
701 // We record identical config for the rtx stream as for the main | 663 // We record identical config for the rtx stream as for the main |
702 // stream. Since the transport_send_cc negotiation is per payload | 664 // stream. Since the transport_send_cc negotiation is per payload |
703 // type, we may get an incorrect value for the rtx stream, but | 665 // type, we may get an incorrect value for the rtx stream, but |
704 // that is unlikely to matter in practice. | 666 // that is unlikely to matter in practice. |
705 receive_rtp_config_[config.rtp.rtx_ssrc] = receive_config; | 667 video_rtp_transport_receive_->AddReceiver( |
| 668 config.rtp.rtx_ssrc, receive_config, receive_stream); |
706 } | 669 } |
707 receive_rtp_config_[config.rtp.remote_ssrc] = receive_config; | |
708 video_receive_streams_.insert(receive_stream); | 670 video_receive_streams_.insert(receive_stream); |
709 ConfigureSync(config.sync_group); | 671 ConfigureSync(config.sync_group); |
710 } | 672 } |
711 receive_stream->SignalNetworkState(video_network_state_); | 673 receive_stream->SignalNetworkState(video_network_state_); |
712 UpdateAggregateNetworkState(); | 674 UpdateAggregateNetworkState(); |
713 event_log_->LogVideoReceiveStreamConfig(config); | 675 event_log_->LogVideoReceiveStreamConfig(config); |
714 return receive_stream; | 676 return receive_stream; |
715 } | 677 } |
716 | 678 |
717 void Call::DestroyVideoReceiveStream( | 679 void Call::DestroyVideoReceiveStream( |
718 webrtc::VideoReceiveStream* receive_stream) { | 680 webrtc::VideoReceiveStream* receive_stream) { |
719 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); | 681 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); |
720 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 682 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
721 RTC_DCHECK(receive_stream != nullptr); | 683 RTC_DCHECK(receive_stream != nullptr); |
722 VideoReceiveStream* receive_stream_impl = nullptr; | 684 VideoReceiveStream* receive_stream_impl = nullptr; |
723 { | 685 { |
724 WriteLockScoped write_lock(*receive_crit_); | 686 WriteLockScoped write_lock(*receive_crit_); |
725 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a | 687 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a |
726 // separate SSRC there can be either one or two. | 688 // separate SSRC there can be either one or two. |
727 auto it = video_receive_ssrcs_.begin(); | 689 auto it = video_receive_ssrcs_.begin(); |
728 while (it != video_receive_ssrcs_.end()) { | 690 while (it != video_receive_ssrcs_.end()) { |
729 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { | 691 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { |
730 if (receive_stream_impl != nullptr) | 692 if (receive_stream_impl != nullptr) |
731 RTC_DCHECK(receive_stream_impl == it->second); | 693 RTC_DCHECK(receive_stream_impl == it->second); |
732 receive_stream_impl = it->second; | 694 receive_stream_impl = it->second; |
733 receive_rtp_config_.erase(it->first); | |
734 it = video_receive_ssrcs_.erase(it); | 695 it = video_receive_ssrcs_.erase(it); |
735 } else { | 696 } else { |
736 ++it; | 697 ++it; |
737 } | 698 } |
738 } | 699 } |
739 video_receive_streams_.erase(receive_stream_impl); | 700 video_receive_streams_.erase(receive_stream_impl); |
740 RTC_CHECK(receive_stream_impl != nullptr); | 701 RTC_CHECK(receive_stream_impl != nullptr); |
741 ConfigureSync(receive_stream_impl->config().sync_group); | 702 ConfigureSync(receive_stream_impl->config().sync_group); |
| 703 video_rtp_transport_receive_->RemoveReceiver(receive_stream_impl); |
742 } | 704 } |
743 const VideoReceiveStream::Config& config = receive_stream_impl->config(); | |
744 | |
745 receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config)) | |
746 ->RemoveStream(config.rtp.remote_ssrc); | |
747 | 705 |
748 UpdateAggregateNetworkState(); | 706 UpdateAggregateNetworkState(); |
749 delete receive_stream_impl; | 707 delete receive_stream_impl; |
750 } | 708 } |
751 | 709 |
752 FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( | 710 FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( |
753 const FlexfecReceiveStream::Config& config) { | 711 const FlexfecReceiveStream::Config& config) { |
754 TRACE_EVENT0("webrtc", "Call::CreateFlexfecReceiveStream"); | 712 TRACE_EVENT0("webrtc", "Call::CreateFlexfecReceiveStream"); |
755 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 713 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
756 | 714 |
757 RecoveredPacketReceiver* recovered_packet_receiver = this; | 715 RecoveredPacketReceiver* recovered_packet_receiver = this; |
758 FlexfecReceiveStreamImpl* receive_stream = new FlexfecReceiveStreamImpl( | 716 FlexfecReceiveStreamImpl* receive_stream = new FlexfecReceiveStreamImpl( |
759 config, recovered_packet_receiver, call_stats_->rtcp_rtt_stats(), | 717 config, recovered_packet_receiver, call_stats_->rtcp_rtt_stats(), |
760 module_process_thread_.get()); | 718 module_process_thread_.get()); |
761 | 719 |
| 720 RtpTransportControllerReceiveInterface::Config receive_config; |
| 721 receive_config.use_send_side_bwe = UseSendSideBwe(config); |
| 722 |
762 { | 723 { |
763 WriteLockScoped write_lock(*receive_crit_); | 724 WriteLockScoped write_lock(*receive_crit_); |
| 725 video_rtp_transport_receive_->AddReceiver(config.remote_ssrc, |
| 726 receive_config, receive_stream); |
764 | 727 |
765 RTC_DCHECK(flexfec_receive_streams_.find(receive_stream) == | 728 for (auto ssrc : config.protected_media_ssrcs) { |
766 flexfec_receive_streams_.end()); | 729 video_rtp_transport_receive_->AddSink(ssrc, receive_stream); |
767 flexfec_receive_streams_.insert(receive_stream); | 730 } |
768 | |
769 for (auto ssrc : config.protected_media_ssrcs) | |
770 flexfec_receive_ssrcs_media_.insert(std::make_pair(ssrc, receive_stream)); | |
771 | |
772 RTC_DCHECK(flexfec_receive_ssrcs_protection_.find(config.remote_ssrc) == | |
773 flexfec_receive_ssrcs_protection_.end()); | |
774 flexfec_receive_ssrcs_protection_[config.remote_ssrc] = receive_stream; | |
775 | |
776 RTC_DCHECK(receive_rtp_config_.find(config.remote_ssrc) == | |
777 receive_rtp_config_.end()); | |
778 receive_rtp_config_[config.remote_ssrc] = | |
779 ReceiveRtpConfig(config.rtp_header_extensions, UseSendSideBwe(config)); | |
780 } | 731 } |
781 | 732 |
782 // TODO(brandtr): Store config in RtcEventLog here. | 733 // TODO(brandtr): Store config in RtcEventLog here. |
783 | 734 |
784 return receive_stream; | 735 return receive_stream; |
785 } | 736 } |
786 | 737 |
787 void Call::DestroyFlexfecReceiveStream(FlexfecReceiveStream* receive_stream) { | 738 void Call::DestroyFlexfecReceiveStream(FlexfecReceiveStream* receive_stream) { |
788 TRACE_EVENT0("webrtc", "Call::DestroyFlexfecReceiveStream"); | 739 TRACE_EVENT0("webrtc", "Call::DestroyFlexfecReceiveStream"); |
789 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 740 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
790 | 741 |
791 RTC_DCHECK(receive_stream != nullptr); | 742 RTC_DCHECK(receive_stream != nullptr); |
792 // There exist no other derived classes of FlexfecReceiveStream, | 743 // There exist no other derived classes of FlexfecReceiveStream, |
793 // so this downcast is safe. | 744 // so this downcast is safe. |
794 FlexfecReceiveStreamImpl* receive_stream_impl = | 745 FlexfecReceiveStreamImpl* receive_stream_impl = |
795 static_cast<FlexfecReceiveStreamImpl*>(receive_stream); | 746 static_cast<FlexfecReceiveStreamImpl*>(receive_stream); |
796 { | 747 { |
797 WriteLockScoped write_lock(*receive_crit_); | 748 WriteLockScoped write_lock(*receive_crit_); |
798 | 749 video_rtp_transport_receive_->RemoveSink(receive_stream_impl); |
799 const FlexfecReceiveStream::Config& config = | 750 video_rtp_transport_receive_->RemoveReceiver(receive_stream_impl); |
800 receive_stream_impl->GetConfig(); | |
801 uint32_t ssrc = config.remote_ssrc; | |
802 receive_rtp_config_.erase(ssrc); | |
803 | |
804 // Remove all SSRCs pointing to the FlexfecReceiveStreamImpl to be | |
805 // destroyed. | |
806 auto prot_it = flexfec_receive_ssrcs_protection_.begin(); | |
807 while (prot_it != flexfec_receive_ssrcs_protection_.end()) { | |
808 if (prot_it->second == receive_stream_impl) | |
809 prot_it = flexfec_receive_ssrcs_protection_.erase(prot_it); | |
810 else | |
811 ++prot_it; | |
812 } | |
813 auto media_it = flexfec_receive_ssrcs_media_.begin(); | |
814 while (media_it != flexfec_receive_ssrcs_media_.end()) { | |
815 if (media_it->second == receive_stream_impl) | |
816 media_it = flexfec_receive_ssrcs_media_.erase(media_it); | |
817 else | |
818 ++media_it; | |
819 } | |
820 | |
821 receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config)) | |
822 ->RemoveStream(ssrc); | |
823 | |
824 flexfec_receive_streams_.erase(receive_stream_impl); | |
825 } | 751 } |
826 | 752 |
827 delete receive_stream_impl; | 753 delete receive_stream_impl; |
828 } | 754 } |
829 | 755 |
830 Call::Stats Call::GetStats() const { | 756 Call::Stats Call::GetStats() const { |
831 // TODO(solenberg): Some test cases in EndToEndTest use this from a different | 757 // TODO(solenberg): Some test cases in EndToEndTest use this from a different |
832 // thread. Re-enable once that is fixed. | 758 // thread. Re-enable once that is fixed. |
833 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 759 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
834 Stats stats; | 760 Stats stats; |
835 // Fetch available send/receive bitrates. | 761 // Fetch available send/receive bitrates. |
836 uint32_t send_bandwidth = 0; | 762 uint32_t send_bandwidth = 0; |
837 transport_send_->send_side_cc()->GetBitrateController()->AvailableBandwidth( | 763 transport_send_->send_side_cc()->GetBitrateController()->AvailableBandwidth( |
838 &send_bandwidth); | 764 &send_bandwidth); |
839 std::vector<unsigned int> ssrcs; | 765 std::vector<unsigned int> ssrcs; |
840 uint32_t recv_bandwidth = 0; | 766 uint32_t recv_bandwidth = 0; |
| 767 |
| 768 // TODO(nisse): Is this thread safe? Most access to |receive_side_cc_| is done |
| 769 // via |*_rtp_transport_receive_|, and protected by |receive_crit_|. |
841 receive_side_cc_.GetRemoteBitrateEstimator(false)->LatestEstimate( | 770 receive_side_cc_.GetRemoteBitrateEstimator(false)->LatestEstimate( |
842 &ssrcs, &recv_bandwidth); | 771 &ssrcs, &recv_bandwidth); |
| 772 |
843 stats.send_bandwidth_bps = send_bandwidth; | 773 stats.send_bandwidth_bps = send_bandwidth; |
844 stats.recv_bandwidth_bps = recv_bandwidth; | 774 stats.recv_bandwidth_bps = recv_bandwidth; |
845 stats.pacer_delay_ms = | 775 stats.pacer_delay_ms = |
846 transport_send_->send_side_cc()->GetPacerQueuingDelayMs(); | 776 transport_send_->send_side_cc()->GetPacerQueuingDelayMs(); |
847 stats.rtt_ms = call_stats_->rtcp_rtt_stats()->LastProcessedRtt(); | 777 stats.rtt_ms = call_stats_->rtcp_rtt_stats()->LastProcessedRtt(); |
848 { | 778 { |
849 rtc::CritScope cs(&bitrate_crit_); | 779 rtc::CritScope cs(&bitrate_crit_); |
850 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; | 780 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; |
851 } | 781 } |
852 return stats; | 782 return stats; |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 } | 1102 } |
1173 | 1103 |
1174 PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type, | 1104 PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type, |
1175 const uint8_t* packet, | 1105 const uint8_t* packet, |
1176 size_t length, | 1106 size_t length, |
1177 const PacketTime& packet_time) { | 1107 const PacketTime& packet_time) { |
1178 TRACE_EVENT0("webrtc", "Call::DeliverRtp"); | 1108 TRACE_EVENT0("webrtc", "Call::DeliverRtp"); |
1179 | 1109 |
1180 RTC_DCHECK(media_type == MediaType::AUDIO || media_type == MediaType::VIDEO); | 1110 RTC_DCHECK(media_type == MediaType::AUDIO || media_type == MediaType::VIDEO); |
1181 | 1111 |
| 1112 int64_t arrival_time_ms; |
| 1113 if (packet_time.timestamp != -1) { |
| 1114 arrival_time_ms = (packet_time.timestamp + 500) / 1000; |
| 1115 } else { |
| 1116 arrival_time_ms = clock_->TimeInMilliseconds(); |
| 1117 } |
| 1118 |
1182 ReadLockScoped read_lock(*receive_crit_); | 1119 ReadLockScoped read_lock(*receive_crit_); |
1183 // TODO(nisse): We should parse the RTP header only here, and pass | |
1184 // on parsed_packet to the receive streams. | |
1185 rtc::Optional<RtpPacketReceived> parsed_packet = | |
1186 ParseRtpPacket(packet, length, packet_time); | |
1187 | 1120 |
1188 if (!parsed_packet) | 1121 received_bytes_per_second_counter_.Add(static_cast<int>(length)); |
1189 return DELIVERY_PACKET_ERROR; | |
1190 | |
1191 NotifyBweOfReceivedPacket(*parsed_packet, media_type); | |
1192 | |
1193 uint32_t ssrc = parsed_packet->Ssrc(); | |
1194 | |
1195 if (media_type == MediaType::AUDIO) { | 1122 if (media_type == MediaType::AUDIO) { |
1196 auto it = audio_receive_ssrcs_.find(ssrc); | 1123 received_audio_bytes_per_second_counter_.Add(static_cast<int>(length)); |
1197 if (it != audio_receive_ssrcs_.end()) { | 1124 return audio_rtp_transport_receive_->OnRtpPacket( |
1198 received_bytes_per_second_counter_.Add(static_cast<int>(length)); | 1125 arrival_time_ms, rtc::ArrayView<const uint8_t>(packet, length)); |
1199 received_audio_bytes_per_second_counter_.Add(static_cast<int>(length)); | 1126 } else if (media_type == MediaType::VIDEO) { |
1200 it->second->OnRtpPacket(*parsed_packet); | 1127 received_video_bytes_per_second_counter_.Add(static_cast<int>(length)); |
1201 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); | 1128 return video_rtp_transport_receive_->OnRtpPacket( |
1202 return DELIVERY_OK; | 1129 arrival_time_ms, rtc::ArrayView<const uint8_t>(packet, length)); |
1203 } | |
1204 } | 1130 } |
1205 if (media_type == MediaType::VIDEO) { | 1131 RTC_NOTREACHED(); |
1206 auto it = video_receive_ssrcs_.find(ssrc); | 1132 return PacketReceiver::DELIVERY_PACKET_ERROR; |
1207 if (it != video_receive_ssrcs_.end()) { | |
1208 received_bytes_per_second_counter_.Add(static_cast<int>(length)); | |
1209 received_video_bytes_per_second_counter_.Add(static_cast<int>(length)); | |
1210 it->second->OnRtpPacket(*parsed_packet); | |
1211 | |
1212 // Deliver media packets to FlexFEC subsystem. | |
1213 auto it_bounds = flexfec_receive_ssrcs_media_.equal_range(ssrc); | |
1214 for (auto it = it_bounds.first; it != it_bounds.second; ++it) | |
1215 it->second->OnRtpPacket(*parsed_packet); | |
1216 | |
1217 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); | |
1218 return DELIVERY_OK; | |
1219 } | |
1220 } | |
1221 if (media_type == MediaType::VIDEO) { | |
1222 received_bytes_per_second_counter_.Add(static_cast<int>(length)); | |
1223 // TODO(brandtr): Update here when FlexFEC supports protecting audio. | |
1224 received_video_bytes_per_second_counter_.Add(static_cast<int>(length)); | |
1225 auto it = flexfec_receive_ssrcs_protection_.find(ssrc); | |
1226 if (it != flexfec_receive_ssrcs_protection_.end()) { | |
1227 it->second->OnRtpPacket(*parsed_packet); | |
1228 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); | |
1229 return DELIVERY_OK; | |
1230 } | |
1231 } | |
1232 return DELIVERY_UNKNOWN_SSRC; | |
1233 } | 1133 } |
1234 | 1134 |
1235 PacketReceiver::DeliveryStatus Call::DeliverPacket( | 1135 PacketReceiver::DeliveryStatus Call::DeliverPacket( |
1236 MediaType media_type, | 1136 MediaType media_type, |
1237 const uint8_t* packet, | 1137 const uint8_t* packet, |
1238 size_t length, | 1138 size_t length, |
1239 const PacketTime& packet_time) { | 1139 const PacketTime& packet_time) { |
1240 // TODO(solenberg): Tests call this function on a network thread, libjingle | 1140 // TODO(solenberg): Tests call this function on a network thread, libjingle |
1241 // calls on the worker thread. We should move towards always using a network | 1141 // calls on the worker thread. We should move towards always using a network |
1242 // thread. Then this check can be enabled. | 1142 // thread. Then this check can be enabled. |
1243 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); | 1143 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); |
1244 if (RtpHeaderParser::IsRtcp(packet, length)) | 1144 if (RtpHeaderParser::IsRtcp(packet, length)) |
1245 return DeliverRtcp(media_type, packet, length); | 1145 return DeliverRtcp(media_type, packet, length); |
1246 | 1146 |
1247 return DeliverRtp(media_type, packet, length, packet_time); | 1147 return DeliverRtp(media_type, packet, length, packet_time); |
1248 } | 1148 } |
1249 | 1149 |
1250 // TODO(brandtr): Update this member function when we support protecting | 1150 // TODO(brandtr): Update this member function when we support protecting |
1251 // audio packets with FlexFEC. | 1151 // audio packets with FlexFEC. |
| 1152 |
| 1153 // TODO(nisse): Add a recovered flag to RtpParsedPacket, if needed for stats, |
| 1154 // and demux recovered packets in the same way as ordinary packets. |
1252 bool Call::OnRecoveredPacket(const uint8_t* packet, size_t length) { | 1155 bool Call::OnRecoveredPacket(const uint8_t* packet, size_t length) { |
1253 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]); | 1156 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]); |
1254 ReadLockScoped read_lock(*receive_crit_); | 1157 ReadLockScoped read_lock(*receive_crit_); |
1255 auto it = video_receive_ssrcs_.find(ssrc); | 1158 auto it = video_receive_ssrcs_.find(ssrc); |
1256 if (it == video_receive_ssrcs_.end()) | 1159 if (it == video_receive_ssrcs_.end()) |
1257 return false; | 1160 return false; |
1258 return it->second->OnRecoveredPacket(packet, length); | 1161 return it->second->OnRecoveredPacket(packet, length); |
1259 } | 1162 } |
1260 | 1163 |
1261 void Call::NotifyBweOfReceivedPacket(const RtpPacketReceived& packet, | |
1262 MediaType media_type) { | |
1263 auto it = receive_rtp_config_.find(packet.Ssrc()); | |
1264 bool use_send_side_bwe = | |
1265 (it != receive_rtp_config_.end()) && it->second.use_send_side_bwe; | |
1266 | |
1267 RTPHeader header; | |
1268 packet.GetHeader(&header); | |
1269 | |
1270 if (!use_send_side_bwe && header.extension.hasTransportSequenceNumber) { | |
1271 // Inconsistent configuration of send side BWE. Do nothing. | |
1272 // TODO(nisse): Without this check, we may produce RTCP feedback | |
1273 // packets even when not negotiated. But it would be cleaner to | |
1274 // move the check down to RTCPSender::SendFeedbackPacket, which | |
1275 // would also help the PacketRouter to select an appropriate rtp | |
1276 // module in the case that some, but not all, have RTCP feedback | |
1277 // enabled. | |
1278 return; | |
1279 } | |
1280 // For audio, we only support send side BWE. | |
1281 if (media_type == MediaType::VIDEO || | |
1282 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { | |
1283 receive_side_cc_.OnReceivedPacket( | |
1284 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), | |
1285 header); | |
1286 } | |
1287 } | |
1288 | |
1289 } // namespace internal | 1164 } // namespace internal |
1290 | 1165 |
1291 } // namespace webrtc | 1166 } // namespace webrtc |
OLD | NEW |