| 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/congestion_controller/include/send_side_congestion_cont
roller.h" | 42 #include "webrtc/modules/congestion_controller/include/send_side_congestion_cont
roller.h" |
| 42 #include "webrtc/modules/pacing/paced_sender.h" | 43 #include "webrtc/modules/pacing/paced_sender.h" |
| 43 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" | 44 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
| 44 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 45 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
| 45 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 46 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 const uint8_t* packet, | 205 const uint8_t* packet, |
| 205 size_t length, | 206 size_t length, |
| 206 const PacketTime& packet_time); | 207 const PacketTime& packet_time); |
| 207 void ConfigureSync(const std::string& sync_group) | 208 void ConfigureSync(const std::string& sync_group) |
| 208 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); | 209 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
| 209 | 210 |
| 210 void NotifyBweOfReceivedPacket(const RtpPacketReceived& packet, | 211 void NotifyBweOfReceivedPacket(const RtpPacketReceived& packet, |
| 211 MediaType media_type) | 212 MediaType media_type) |
| 212 SHARED_LOCKS_REQUIRED(receive_crit_); | 213 SHARED_LOCKS_REQUIRED(receive_crit_); |
| 213 | 214 |
| 214 rtc::Optional<RtpPacketReceived> ParseRtpPacket(const uint8_t* packet, | |
| 215 size_t length, | |
| 216 const PacketTime& packet_time) | |
| 217 SHARED_LOCKS_REQUIRED(receive_crit_); | |
| 218 | |
| 219 void UpdateSendHistograms() EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); | 215 void UpdateSendHistograms() EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); |
| 220 void UpdateReceiveHistograms(); | 216 void UpdateReceiveHistograms(); |
| 221 void UpdateHistograms(); | 217 void UpdateHistograms(); |
| 222 void UpdateAggregateNetworkState(); | 218 void UpdateAggregateNetworkState(); |
| 223 | 219 |
| 224 Clock* const clock_; | 220 Clock* const clock_; |
| 225 | 221 |
| 226 const int num_cpu_cores_; | 222 const int num_cpu_cores_; |
| 227 const std::unique_ptr<ProcessThread> module_process_thread_; | 223 const std::unique_ptr<ProcessThread> module_process_thread_; |
| 228 const std::unique_ptr<ProcessThread> pacer_thread_; | 224 const std::unique_ptr<ProcessThread> pacer_thread_; |
| 229 const std::unique_ptr<CallStats> call_stats_; | 225 const std::unique_ptr<CallStats> call_stats_; |
| 230 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; | 226 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; |
| 231 Call::Config config_; | 227 Call::Config config_; |
| 232 rtc::ThreadChecker configuration_thread_checker_; | 228 rtc::ThreadChecker configuration_thread_checker_; |
| 233 | 229 |
| 234 NetworkState audio_network_state_; | 230 NetworkState audio_network_state_; |
| 235 NetworkState video_network_state_; | 231 NetworkState video_network_state_; |
| 236 | 232 |
| 237 std::unique_ptr<RWLockWrapper> receive_crit_; | 233 std::unique_ptr<RWLockWrapper> receive_crit_; |
| 238 // Audio, Video, and FlexFEC receive streams are owned by the client that | 234 // Audio, Video, and FlexFEC receive streams are owned by the client that |
| 239 // creates them. | 235 // creates them. |
| 236 // TODO(nisse): Try to eliminate these additional mappings. Two of |
| 237 // the users are DeliverRTCP and OnRecoveredPacket. |
| 240 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ | 238 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ |
| 241 GUARDED_BY(receive_crit_); | 239 GUARDED_BY(receive_crit_); |
| 242 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ | 240 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ |
| 243 GUARDED_BY(receive_crit_); | 241 GUARDED_BY(receive_crit_); |
| 244 std::set<VideoReceiveStream*> video_receive_streams_ | 242 std::set<VideoReceiveStream*> video_receive_streams_ |
| 245 GUARDED_BY(receive_crit_); | 243 GUARDED_BY(receive_crit_); |
| 246 // Each media stream could conceivably be protected by multiple FlexFEC | 244 |
| 247 // streams. | |
| 248 std::multimap<uint32_t, FlexfecReceiveStreamImpl*> | |
| 249 flexfec_receive_ssrcs_media_ GUARDED_BY(receive_crit_); | |
| 250 std::map<uint32_t, FlexfecReceiveStreamImpl*> | |
| 251 flexfec_receive_ssrcs_protection_ GUARDED_BY(receive_crit_); | |
| 252 std::set<FlexfecReceiveStreamImpl*> flexfec_receive_streams_ | |
| 253 GUARDED_BY(receive_crit_); | |
| 254 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ | 245 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ |
| 255 GUARDED_BY(receive_crit_); | 246 GUARDED_BY(receive_crit_); |
| 256 | 247 |
| 257 // This extra map is used for receive processing which is | |
| 258 // independent of media type. | |
| 259 | |
| 260 // TODO(nisse): In the RTP transport refactoring, we should have a | |
| 261 // single mapping from ssrc to a more abstract receive stream, with | |
| 262 // accessor methods for all configuration we need at this level. | |
| 263 struct ReceiveRtpConfig { | |
| 264 ReceiveRtpConfig() = default; // Needed by std::map | |
| 265 ReceiveRtpConfig(const std::vector<RtpExtension>& extensions, | |
| 266 bool use_send_side_bwe) | |
| 267 : extensions(extensions), use_send_side_bwe(use_send_side_bwe) {} | |
| 268 | |
| 269 // Registered RTP header extensions for each stream. Note that RTP header | |
| 270 // extensions are negotiated per track ("m= line") in the SDP, but we have | |
| 271 // no notion of tracks at the Call level. We therefore store the RTP header | |
| 272 // extensions per SSRC instead, which leads to some storage overhead. | |
| 273 RtpHeaderExtensionMap extensions; | |
| 274 // Set if both RTP extension the RTCP feedback message needed for | |
| 275 // send side BWE are negotiated. | |
| 276 bool use_send_side_bwe = false; | |
| 277 }; | |
| 278 std::map<uint32_t, ReceiveRtpConfig> receive_rtp_config_ | |
| 279 GUARDED_BY(receive_crit_); | |
| 280 | |
| 281 std::unique_ptr<RWLockWrapper> send_crit_; | 248 std::unique_ptr<RWLockWrapper> send_crit_; |
| 282 // Audio and Video send streams are owned by the client that creates them. | 249 // Audio and Video send streams are owned by the client that creates them. |
| 283 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_); | 250 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_); |
| 284 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); | 251 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); |
| 285 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); | 252 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); |
| 286 | 253 |
| 287 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; | 254 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; |
| 288 webrtc::RtcEventLog* event_log_; | 255 webrtc::RtcEventLog* event_log_; |
| 289 | 256 |
| 290 // The following members are only accessed (exclusively) from one thread and | 257 // The following members are only accessed (exclusively) from one thread and |
| (...skipping 10 matching lines...) Expand all Loading... |
| 301 rtc::CriticalSection bitrate_crit_; | 268 rtc::CriticalSection bitrate_crit_; |
| 302 uint32_t min_allocated_send_bitrate_bps_ GUARDED_BY(&bitrate_crit_); | 269 uint32_t min_allocated_send_bitrate_bps_ GUARDED_BY(&bitrate_crit_); |
| 303 uint32_t configured_max_padding_bitrate_bps_ GUARDED_BY(&bitrate_crit_); | 270 uint32_t configured_max_padding_bitrate_bps_ GUARDED_BY(&bitrate_crit_); |
| 304 AvgCounter estimated_send_bitrate_kbps_counter_ GUARDED_BY(&bitrate_crit_); | 271 AvgCounter estimated_send_bitrate_kbps_counter_ GUARDED_BY(&bitrate_crit_); |
| 305 AvgCounter pacer_bitrate_kbps_counter_ GUARDED_BY(&bitrate_crit_); | 272 AvgCounter pacer_bitrate_kbps_counter_ GUARDED_BY(&bitrate_crit_); |
| 306 | 273 |
| 307 std::map<std::string, rtc::NetworkRoute> network_routes_; | 274 std::map<std::string, rtc::NetworkRoute> network_routes_; |
| 308 | 275 |
| 309 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; | 276 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; |
| 310 ReceiveSideCongestionController receive_side_cc_; | 277 ReceiveSideCongestionController receive_side_cc_; |
| 278 // TODO(nisse): Currently we always use separate demuxers. These |
| 279 // should be created and owned outside of Call, passing pointers |
| 280 // when Call is created. Then we should have two separate objects in |
| 281 // the unbundled case, and two pointers to the same object in the |
| 282 // bundled case. |
| 283 std::unique_ptr<RtpTransportControllerReceiveInterface> |
| 284 rtp_transport_receive_audio_ GUARDED_BY(receive_crit_); |
| 285 std::unique_ptr<RtpTransportControllerReceiveInterface> |
| 286 rtp_transport_receive_video_ GUARDED_BY(receive_crit_); |
| 311 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; | 287 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; |
| 312 const int64_t start_ms_; | 288 const int64_t start_ms_; |
| 313 // TODO(perkj): |worker_queue_| is supposed to replace | 289 // TODO(perkj): |worker_queue_| is supposed to replace |
| 314 // |module_process_thread_|. | 290 // |module_process_thread_|. |
| 315 // |worker_queue| is defined last to ensure all pending tasks are cancelled | 291 // |worker_queue| is defined last to ensure all pending tasks are cancelled |
| 316 // and deleted before any other members. | 292 // and deleted before any other members. |
| 317 rtc::TaskQueue worker_queue_; | 293 rtc::TaskQueue worker_queue_; |
| 318 | 294 |
| 319 RTC_DISALLOW_COPY_AND_ASSIGN(Call); | 295 RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
| 320 }; | 296 }; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 first_packet_sent_ms_(-1), | 334 first_packet_sent_ms_(-1), |
| 359 received_bytes_per_second_counter_(clock_, nullptr, true), | 335 received_bytes_per_second_counter_(clock_, nullptr, true), |
| 360 received_audio_bytes_per_second_counter_(clock_, nullptr, true), | 336 received_audio_bytes_per_second_counter_(clock_, nullptr, true), |
| 361 received_video_bytes_per_second_counter_(clock_, nullptr, true), | 337 received_video_bytes_per_second_counter_(clock_, nullptr, true), |
| 362 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), | 338 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), |
| 363 min_allocated_send_bitrate_bps_(0), | 339 min_allocated_send_bitrate_bps_(0), |
| 364 configured_max_padding_bitrate_bps_(0), | 340 configured_max_padding_bitrate_bps_(0), |
| 365 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), | 341 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), |
| 366 pacer_bitrate_kbps_counter_(clock_, nullptr, true), | 342 pacer_bitrate_kbps_counter_(clock_, nullptr, true), |
| 367 receive_side_cc_(clock_, transport_send->packet_router()), | 343 receive_side_cc_(clock_, transport_send->packet_router()), |
| 344 rtp_transport_receive_audio_( |
| 345 RtpTransportControllerReceiveInterface::Create( |
| 346 &receive_side_cc_, |
| 347 false /* enable_receive_side_bwe */)), |
| 348 rtp_transport_receive_video_( |
| 349 RtpTransportControllerReceiveInterface::Create( |
| 350 &receive_side_cc_, |
| 351 true /* enable_receive_side_bwe */)), |
| 368 video_send_delay_stats_(new SendDelayStats(clock_)), | 352 video_send_delay_stats_(new SendDelayStats(clock_)), |
| 369 start_ms_(clock_->TimeInMilliseconds()), | 353 start_ms_(clock_->TimeInMilliseconds()), |
| 370 worker_queue_("call_worker_queue") { | 354 worker_queue_("call_worker_queue") { |
| 371 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 355 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 372 RTC_DCHECK(config.event_log != nullptr); | 356 RTC_DCHECK(config.event_log != nullptr); |
| 373 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); | 357 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
| 374 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, | 358 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
| 375 config.bitrate_config.min_bitrate_bps); | 359 config.bitrate_config.min_bitrate_bps); |
| 376 if (config.bitrate_config.max_bitrate_bps != -1) { | 360 if (config.bitrate_config.max_bitrate_bps != -1) { |
| 377 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, | 361 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 400 | 384 |
| 401 pacer_thread_->Start(); | 385 pacer_thread_->Start(); |
| 402 } | 386 } |
| 403 | 387 |
| 404 Call::~Call() { | 388 Call::~Call() { |
| 405 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 389 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 406 | 390 |
| 407 RTC_CHECK(audio_send_ssrcs_.empty()); | 391 RTC_CHECK(audio_send_ssrcs_.empty()); |
| 408 RTC_CHECK(video_send_ssrcs_.empty()); | 392 RTC_CHECK(video_send_ssrcs_.empty()); |
| 409 RTC_CHECK(video_send_streams_.empty()); | 393 RTC_CHECK(video_send_streams_.empty()); |
| 410 RTC_CHECK(audio_receive_ssrcs_.empty()); | |
| 411 RTC_CHECK(video_receive_ssrcs_.empty()); | |
| 412 RTC_CHECK(video_receive_streams_.empty()); | |
| 413 | 394 |
| 414 pacer_thread_->Stop(); | 395 pacer_thread_->Stop(); |
| 415 pacer_thread_->DeRegisterModule(transport_send_->send_side_cc()->pacer()); | 396 pacer_thread_->DeRegisterModule(transport_send_->send_side_cc()->pacer()); |
| 416 pacer_thread_->DeRegisterModule( | 397 pacer_thread_->DeRegisterModule( |
| 417 receive_side_cc_.GetRemoteBitrateEstimator(true)); | 398 receive_side_cc_.GetRemoteBitrateEstimator(true)); |
| 418 module_process_thread_->DeRegisterModule(transport_send_->send_side_cc()); | 399 module_process_thread_->DeRegisterModule(transport_send_->send_side_cc()); |
| 419 module_process_thread_->DeRegisterModule(&receive_side_cc_); | 400 module_process_thread_->DeRegisterModule(&receive_side_cc_); |
| 420 module_process_thread_->DeRegisterModule(call_stats_.get()); | 401 module_process_thread_->DeRegisterModule(call_stats_.get()); |
| 421 module_process_thread_->Stop(); | 402 module_process_thread_->Stop(); |
| 422 call_stats_->DeregisterStatsObserver(&receive_side_cc_); | 403 call_stats_->DeregisterStatsObserver(&receive_side_cc_); |
| 423 call_stats_->DeregisterStatsObserver(transport_send_->send_side_cc()); | 404 call_stats_->DeregisterStatsObserver(transport_send_->send_side_cc()); |
| 424 | 405 |
| 425 // Only update histograms after process threads have been shut down, so that | 406 // Only update histograms after process threads have been shut down, so that |
| 426 // they won't try to concurrently update stats. | 407 // they won't try to concurrently update stats. |
| 427 { | 408 { |
| 428 rtc::CritScope lock(&bitrate_crit_); | 409 rtc::CritScope lock(&bitrate_crit_); |
| 429 UpdateSendHistograms(); | 410 UpdateSendHistograms(); |
| 430 } | 411 } |
| 431 UpdateReceiveHistograms(); | 412 UpdateReceiveHistograms(); |
| 432 UpdateHistograms(); | 413 UpdateHistograms(); |
| 433 | 414 |
| 434 Trace::ReturnTrace(); | 415 Trace::ReturnTrace(); |
| 435 } | 416 } |
| 436 | 417 |
| 437 rtc::Optional<RtpPacketReceived> Call::ParseRtpPacket( | |
| 438 const uint8_t* packet, | |
| 439 size_t length, | |
| 440 const PacketTime& packet_time) { | |
| 441 RtpPacketReceived parsed_packet; | |
| 442 if (!parsed_packet.Parse(packet, length)) | |
| 443 return rtc::Optional<RtpPacketReceived>(); | |
| 444 | |
| 445 auto it = receive_rtp_config_.find(parsed_packet.Ssrc()); | |
| 446 if (it != receive_rtp_config_.end()) | |
| 447 parsed_packet.IdentifyExtensions(it->second.extensions); | |
| 448 | |
| 449 int64_t arrival_time_ms; | |
| 450 if (packet_time.timestamp != -1) { | |
| 451 arrival_time_ms = (packet_time.timestamp + 500) / 1000; | |
| 452 } else { | |
| 453 arrival_time_ms = clock_->TimeInMilliseconds(); | |
| 454 } | |
| 455 parsed_packet.set_arrival_time_ms(arrival_time_ms); | |
| 456 | |
| 457 return rtc::Optional<RtpPacketReceived>(std::move(parsed_packet)); | |
| 458 } | |
| 459 | |
| 460 void Call::UpdateHistograms() { | 418 void Call::UpdateHistograms() { |
| 461 RTC_HISTOGRAM_COUNTS_100000( | 419 RTC_HISTOGRAM_COUNTS_100000( |
| 462 "WebRTC.Call.LifetimeInSeconds", | 420 "WebRTC.Call.LifetimeInSeconds", |
| 463 (clock_->TimeInMilliseconds() - start_ms_) / 1000); | 421 (clock_->TimeInMilliseconds() - start_ms_) / 1000); |
| 464 } | 422 } |
| 465 | 423 |
| 466 void Call::UpdateSendHistograms() { | 424 void Call::UpdateSendHistograms() { |
| 467 if (first_packet_sent_ms_ == -1) | 425 if (first_packet_sent_ms_ == -1) |
| 468 return; | 426 return; |
| 469 int64_t elapsed_sec = | 427 int64_t elapsed_sec = |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 } | 545 } |
| 588 | 546 |
| 589 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( | 547 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( |
| 590 const webrtc::AudioReceiveStream::Config& config) { | 548 const webrtc::AudioReceiveStream::Config& config) { |
| 591 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); | 549 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); |
| 592 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 550 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 593 event_log_->LogAudioReceiveStreamConfig(config); | 551 event_log_->LogAudioReceiveStreamConfig(config); |
| 594 AudioReceiveStream* receive_stream = | 552 AudioReceiveStream* receive_stream = |
| 595 new AudioReceiveStream(transport_send_->packet_router(), config, | 553 new AudioReceiveStream(transport_send_->packet_router(), config, |
| 596 config_.audio_state, event_log_); | 554 config_.audio_state, event_log_); |
| 555 RtpTransportControllerReceiveInterface::Config receive_config; |
| 556 receive_config.use_send_side_bwe = UseSendSideBwe(config); |
| 557 |
| 597 { | 558 { |
| 598 WriteLockScoped write_lock(*receive_crit_); | 559 WriteLockScoped write_lock(*receive_crit_); |
| 599 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == | 560 rtp_transport_receive_audio_->AddReceiver( |
| 600 audio_receive_ssrcs_.end()); | 561 config.rtp.remote_ssrc, receive_config, receive_stream); |
| 562 |
| 601 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | 563 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
| 602 receive_rtp_config_[config.rtp.remote_ssrc] = | |
| 603 ReceiveRtpConfig(config.rtp.extensions, UseSendSideBwe(config)); | |
| 604 | |
| 605 ConfigureSync(config.sync_group); | 564 ConfigureSync(config.sync_group); |
| 606 } | 565 } |
| 607 { | 566 { |
| 608 ReadLockScoped read_lock(*send_crit_); | 567 ReadLockScoped read_lock(*send_crit_); |
| 609 auto it = audio_send_ssrcs_.find(config.rtp.local_ssrc); | 568 auto it = audio_send_ssrcs_.find(config.rtp.local_ssrc); |
| 610 if (it != audio_send_ssrcs_.end()) { | 569 if (it != audio_send_ssrcs_.end()) { |
| 611 receive_stream->AssociateSendStream(it->second); | 570 receive_stream->AssociateSendStream(it->second); |
| 612 } | 571 } |
| 613 } | 572 } |
| 614 receive_stream->SignalNetworkState(audio_network_state_); | 573 receive_stream->SignalNetworkState(audio_network_state_); |
| 615 UpdateAggregateNetworkState(); | 574 UpdateAggregateNetworkState(); |
| 616 return receive_stream; | 575 return receive_stream; |
| 617 } | 576 } |
| 618 | 577 |
| 619 void Call::DestroyAudioReceiveStream( | 578 void Call::DestroyAudioReceiveStream( |
| 620 webrtc::AudioReceiveStream* receive_stream) { | 579 webrtc::AudioReceiveStream* receive_stream) { |
| 621 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); | 580 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); |
| 622 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 581 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 623 RTC_DCHECK(receive_stream != nullptr); | 582 RTC_DCHECK(receive_stream != nullptr); |
| 624 webrtc::internal::AudioReceiveStream* audio_receive_stream = | 583 webrtc::internal::AudioReceiveStream* audio_receive_stream = |
| 625 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); | 584 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); |
| 626 { | 585 { |
| 627 WriteLockScoped write_lock(*receive_crit_); | 586 WriteLockScoped write_lock(*receive_crit_); |
| 587 rtp_transport_receive_audio_->RemoveReceiver(audio_receive_stream); |
| 588 |
| 628 const AudioReceiveStream::Config& config = audio_receive_stream->config(); | 589 const AudioReceiveStream::Config& config = audio_receive_stream->config(); |
| 629 uint32_t ssrc = config.rtp.remote_ssrc; | 590 uint32_t ssrc = config.rtp.remote_ssrc; |
| 630 receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config)) | |
| 631 ->RemoveStream(ssrc); | |
| 632 size_t num_deleted = audio_receive_ssrcs_.erase(ssrc); | 591 size_t num_deleted = audio_receive_ssrcs_.erase(ssrc); |
| 633 RTC_DCHECK(num_deleted == 1); | 592 RTC_DCHECK(num_deleted == 1); |
| 634 const std::string& sync_group = audio_receive_stream->config().sync_group; | 593 const std::string& sync_group = audio_receive_stream->config().sync_group; |
| 635 const auto it = sync_stream_mapping_.find(sync_group); | 594 const auto it = sync_stream_mapping_.find(sync_group); |
| 636 if (it != sync_stream_mapping_.end() && | 595 if (it != sync_stream_mapping_.end() && |
| 637 it->second == audio_receive_stream) { | 596 it->second == audio_receive_stream) { |
| 638 sync_stream_mapping_.erase(it); | 597 sync_stream_mapping_.erase(it); |
| 639 ConfigureSync(sync_group); | 598 ConfigureSync(sync_group); |
| 640 } | 599 } |
| 641 receive_rtp_config_.erase(ssrc); | |
| 642 } | 600 } |
| 643 UpdateAggregateNetworkState(); | 601 UpdateAggregateNetworkState(); |
| 644 delete audio_receive_stream; | 602 delete audio_receive_stream; |
| 645 } | 603 } |
| 646 | 604 |
| 647 webrtc::VideoSendStream* Call::CreateVideoSendStream( | 605 webrtc::VideoSendStream* Call::CreateVideoSendStream( |
| 648 webrtc::VideoSendStream::Config config, | 606 webrtc::VideoSendStream::Config config, |
| 649 VideoEncoderConfig encoder_config) { | 607 VideoEncoderConfig encoder_config) { |
| 650 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); | 608 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
| 651 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 609 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 webrtc::VideoReceiveStream::Config configuration) { | 674 webrtc::VideoReceiveStream::Config configuration) { |
| 717 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); | 675 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); |
| 718 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 676 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 719 | 677 |
| 720 VideoReceiveStream* receive_stream = | 678 VideoReceiveStream* receive_stream = |
| 721 new VideoReceiveStream(num_cpu_cores_, transport_send_->packet_router(), | 679 new VideoReceiveStream(num_cpu_cores_, transport_send_->packet_router(), |
| 722 std::move(configuration), | 680 std::move(configuration), |
| 723 module_process_thread_.get(), call_stats_.get()); | 681 module_process_thread_.get(), call_stats_.get()); |
| 724 | 682 |
| 725 const webrtc::VideoReceiveStream::Config& config = receive_stream->config(); | 683 const webrtc::VideoReceiveStream::Config& config = receive_stream->config(); |
| 726 ReceiveRtpConfig receive_config(config.rtp.extensions, | 684 RtpTransportControllerReceiveInterface::Config receive_config; |
| 727 UseSendSideBwe(config)); | 685 receive_config.use_send_side_bwe = UseSendSideBwe(config); |
| 686 |
| 728 { | 687 { |
| 729 WriteLockScoped write_lock(*receive_crit_); | 688 WriteLockScoped write_lock(*receive_crit_); |
| 730 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == | 689 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| 731 video_receive_ssrcs_.end()); | 690 video_receive_ssrcs_.end()); |
| 732 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | 691 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
| 692 rtp_transport_receive_video_->AddReceiver( |
| 693 config.rtp.remote_ssrc, receive_config, receive_stream); |
| 694 |
| 733 if (config.rtp.rtx_ssrc) { | 695 if (config.rtp.rtx_ssrc) { |
| 734 video_receive_ssrcs_[config.rtp.rtx_ssrc] = receive_stream; | 696 video_receive_ssrcs_[config.rtp.rtx_ssrc] = receive_stream; |
| 735 // We record identical config for the rtx stream as for the main | 697 // We record identical config for the rtx stream as for the main |
| 736 // stream. Since the transport_send_cc negotiation is per payload | 698 // stream. Since the transport_send_cc negotiation is per payload |
| 737 // type, we may get an incorrect value for the rtx stream, but | 699 // type, we may get an incorrect value for the rtx stream, but |
| 738 // that is unlikely to matter in practice. | 700 // that is unlikely to matter in practice. |
| 739 receive_rtp_config_[config.rtp.rtx_ssrc] = receive_config; | 701 rtp_transport_receive_video_->AddReceiver( |
| 702 config.rtp.rtx_ssrc, receive_config, receive_stream); |
| 740 } | 703 } |
| 741 receive_rtp_config_[config.rtp.remote_ssrc] = receive_config; | |
| 742 video_receive_streams_.insert(receive_stream); | 704 video_receive_streams_.insert(receive_stream); |
| 743 ConfigureSync(config.sync_group); | 705 ConfigureSync(config.sync_group); |
| 744 } | 706 } |
| 745 receive_stream->SignalNetworkState(video_network_state_); | 707 receive_stream->SignalNetworkState(video_network_state_); |
| 746 UpdateAggregateNetworkState(); | 708 UpdateAggregateNetworkState(); |
| 747 event_log_->LogVideoReceiveStreamConfig(config); | 709 event_log_->LogVideoReceiveStreamConfig(config); |
| 748 return receive_stream; | 710 return receive_stream; |
| 749 } | 711 } |
| 750 | 712 |
| 751 void Call::DestroyVideoReceiveStream( | 713 void Call::DestroyVideoReceiveStream( |
| 752 webrtc::VideoReceiveStream* receive_stream) { | 714 webrtc::VideoReceiveStream* receive_stream) { |
| 753 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); | 715 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); |
| 754 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 716 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 755 RTC_DCHECK(receive_stream != nullptr); | 717 RTC_DCHECK(receive_stream != nullptr); |
| 756 VideoReceiveStream* receive_stream_impl = nullptr; | 718 VideoReceiveStream* receive_stream_impl = nullptr; |
| 757 { | 719 { |
| 758 WriteLockScoped write_lock(*receive_crit_); | 720 WriteLockScoped write_lock(*receive_crit_); |
| 759 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a | 721 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a |
| 760 // separate SSRC there can be either one or two. | 722 // separate SSRC there can be either one or two. |
| 761 auto it = video_receive_ssrcs_.begin(); | 723 auto it = video_receive_ssrcs_.begin(); |
| 762 while (it != video_receive_ssrcs_.end()) { | 724 while (it != video_receive_ssrcs_.end()) { |
| 763 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { | 725 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { |
| 764 if (receive_stream_impl != nullptr) | 726 if (receive_stream_impl != nullptr) |
| 765 RTC_DCHECK(receive_stream_impl == it->second); | 727 RTC_DCHECK(receive_stream_impl == it->second); |
| 766 receive_stream_impl = it->second; | 728 receive_stream_impl = it->second; |
| 767 receive_rtp_config_.erase(it->first); | |
| 768 it = video_receive_ssrcs_.erase(it); | 729 it = video_receive_ssrcs_.erase(it); |
| 769 } else { | 730 } else { |
| 770 ++it; | 731 ++it; |
| 771 } | 732 } |
| 772 } | 733 } |
| 773 video_receive_streams_.erase(receive_stream_impl); | 734 video_receive_streams_.erase(receive_stream_impl); |
| 774 RTC_CHECK(receive_stream_impl != nullptr); | 735 RTC_CHECK(receive_stream_impl != nullptr); |
| 775 ConfigureSync(receive_stream_impl->config().sync_group); | 736 ConfigureSync(receive_stream_impl->config().sync_group); |
| 737 rtp_transport_receive_video_->RemoveReceiver(receive_stream_impl); |
| 776 } | 738 } |
| 777 const VideoReceiveStream::Config& config = receive_stream_impl->config(); | |
| 778 | |
| 779 receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config)) | |
| 780 ->RemoveStream(config.rtp.remote_ssrc); | |
| 781 | 739 |
| 782 UpdateAggregateNetworkState(); | 740 UpdateAggregateNetworkState(); |
| 783 delete receive_stream_impl; | 741 delete receive_stream_impl; |
| 784 } | 742 } |
| 785 | 743 |
| 786 FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( | 744 FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( |
| 787 const FlexfecReceiveStream::Config& config) { | 745 const FlexfecReceiveStream::Config& config) { |
| 788 TRACE_EVENT0("webrtc", "Call::CreateFlexfecReceiveStream"); | 746 TRACE_EVENT0("webrtc", "Call::CreateFlexfecReceiveStream"); |
| 789 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 747 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 790 | 748 |
| 791 RecoveredPacketReceiver* recovered_packet_receiver = this; | 749 RecoveredPacketReceiver* recovered_packet_receiver = this; |
| 792 FlexfecReceiveStreamImpl* receive_stream = new FlexfecReceiveStreamImpl( | 750 FlexfecReceiveStreamImpl* receive_stream = new FlexfecReceiveStreamImpl( |
| 793 config, recovered_packet_receiver, call_stats_->rtcp_rtt_stats(), | 751 config, recovered_packet_receiver, call_stats_->rtcp_rtt_stats(), |
| 794 module_process_thread_.get()); | 752 module_process_thread_.get()); |
| 795 | 753 |
| 754 RtpTransportControllerReceiveInterface::Config receive_config; |
| 755 receive_config.use_send_side_bwe = UseSendSideBwe(config); |
| 756 |
| 796 { | 757 { |
| 797 WriteLockScoped write_lock(*receive_crit_); | 758 WriteLockScoped write_lock(*receive_crit_); |
| 759 rtp_transport_receive_video_->AddReceiver(config.remote_ssrc, |
| 760 receive_config, receive_stream); |
| 798 | 761 |
| 799 RTC_DCHECK(flexfec_receive_streams_.find(receive_stream) == | 762 for (auto ssrc : config.protected_media_ssrcs) { |
| 800 flexfec_receive_streams_.end()); | 763 rtp_transport_receive_video_->AddSink(ssrc, receive_stream); |
| 801 flexfec_receive_streams_.insert(receive_stream); | 764 } |
| 802 | |
| 803 for (auto ssrc : config.protected_media_ssrcs) | |
| 804 flexfec_receive_ssrcs_media_.insert(std::make_pair(ssrc, receive_stream)); | |
| 805 | |
| 806 RTC_DCHECK(flexfec_receive_ssrcs_protection_.find(config.remote_ssrc) == | |
| 807 flexfec_receive_ssrcs_protection_.end()); | |
| 808 flexfec_receive_ssrcs_protection_[config.remote_ssrc] = receive_stream; | |
| 809 | |
| 810 RTC_DCHECK(receive_rtp_config_.find(config.remote_ssrc) == | |
| 811 receive_rtp_config_.end()); | |
| 812 receive_rtp_config_[config.remote_ssrc] = | |
| 813 ReceiveRtpConfig(config.rtp_header_extensions, UseSendSideBwe(config)); | |
| 814 } | 765 } |
| 815 | 766 |
| 816 // TODO(brandtr): Store config in RtcEventLog here. | 767 // TODO(brandtr): Store config in RtcEventLog here. |
| 817 | 768 |
| 818 return receive_stream; | 769 return receive_stream; |
| 819 } | 770 } |
| 820 | 771 |
| 821 void Call::DestroyFlexfecReceiveStream(FlexfecReceiveStream* receive_stream) { | 772 void Call::DestroyFlexfecReceiveStream(FlexfecReceiveStream* receive_stream) { |
| 822 TRACE_EVENT0("webrtc", "Call::DestroyFlexfecReceiveStream"); | 773 TRACE_EVENT0("webrtc", "Call::DestroyFlexfecReceiveStream"); |
| 823 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 774 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 824 | 775 |
| 825 RTC_DCHECK(receive_stream != nullptr); | 776 RTC_DCHECK(receive_stream != nullptr); |
| 826 // There exist no other derived classes of FlexfecReceiveStream, | 777 // There exist no other derived classes of FlexfecReceiveStream, |
| 827 // so this downcast is safe. | 778 // so this downcast is safe. |
| 828 FlexfecReceiveStreamImpl* receive_stream_impl = | 779 FlexfecReceiveStreamImpl* receive_stream_impl = |
| 829 static_cast<FlexfecReceiveStreamImpl*>(receive_stream); | 780 static_cast<FlexfecReceiveStreamImpl*>(receive_stream); |
| 830 { | 781 { |
| 831 WriteLockScoped write_lock(*receive_crit_); | 782 WriteLockScoped write_lock(*receive_crit_); |
| 832 | 783 rtp_transport_receive_video_->RemoveSink(receive_stream_impl); |
| 833 const FlexfecReceiveStream::Config& config = | 784 rtp_transport_receive_video_->RemoveReceiver(receive_stream_impl); |
| 834 receive_stream_impl->GetConfig(); | |
| 835 uint32_t ssrc = config.remote_ssrc; | |
| 836 receive_rtp_config_.erase(ssrc); | |
| 837 | |
| 838 // Remove all SSRCs pointing to the FlexfecReceiveStreamImpl to be | |
| 839 // destroyed. | |
| 840 auto prot_it = flexfec_receive_ssrcs_protection_.begin(); | |
| 841 while (prot_it != flexfec_receive_ssrcs_protection_.end()) { | |
| 842 if (prot_it->second == receive_stream_impl) | |
| 843 prot_it = flexfec_receive_ssrcs_protection_.erase(prot_it); | |
| 844 else | |
| 845 ++prot_it; | |
| 846 } | |
| 847 auto media_it = flexfec_receive_ssrcs_media_.begin(); | |
| 848 while (media_it != flexfec_receive_ssrcs_media_.end()) { | |
| 849 if (media_it->second == receive_stream_impl) | |
| 850 media_it = flexfec_receive_ssrcs_media_.erase(media_it); | |
| 851 else | |
| 852 ++media_it; | |
| 853 } | |
| 854 | |
| 855 receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config)) | |
| 856 ->RemoveStream(ssrc); | |
| 857 | |
| 858 flexfec_receive_streams_.erase(receive_stream_impl); | |
| 859 } | 785 } |
| 860 | 786 |
| 861 delete receive_stream_impl; | 787 delete receive_stream_impl; |
| 862 } | 788 } |
| 863 | 789 |
| 864 Call::Stats Call::GetStats() const { | 790 Call::Stats Call::GetStats() const { |
| 865 // TODO(solenberg): Some test cases in EndToEndTest use this from a different | 791 // TODO(solenberg): Some test cases in EndToEndTest use this from a different |
| 866 // thread. Re-enable once that is fixed. | 792 // thread. Re-enable once that is fixed. |
| 867 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 793 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 868 Stats stats; | 794 Stats stats; |
| 869 // Fetch available send/receive bitrates. | 795 // Fetch available send/receive bitrates. |
| 870 uint32_t send_bandwidth = 0; | 796 uint32_t send_bandwidth = 0; |
| 871 transport_send_->send_side_cc()->GetBitrateController()->AvailableBandwidth( | 797 transport_send_->send_side_cc()->GetBitrateController()->AvailableBandwidth( |
| 872 &send_bandwidth); | 798 &send_bandwidth); |
| 873 std::vector<unsigned int> ssrcs; | 799 std::vector<unsigned int> ssrcs; |
| 874 uint32_t recv_bandwidth = 0; | 800 uint32_t recv_bandwidth = 0; |
| 801 |
| 802 // TODO(nisse): Is this thread safe? Most access to |receive_side_cc_| is done |
| 803 // via |rtp_transport_receive_|, and protected by |receive_crit_|. |
| 875 receive_side_cc_.GetRemoteBitrateEstimator(false)->LatestEstimate( | 804 receive_side_cc_.GetRemoteBitrateEstimator(false)->LatestEstimate( |
| 876 &ssrcs, &recv_bandwidth); | 805 &ssrcs, &recv_bandwidth); |
| 806 |
| 877 stats.send_bandwidth_bps = send_bandwidth; | 807 stats.send_bandwidth_bps = send_bandwidth; |
| 878 stats.recv_bandwidth_bps = recv_bandwidth; | 808 stats.recv_bandwidth_bps = recv_bandwidth; |
| 879 stats.pacer_delay_ms = | 809 stats.pacer_delay_ms = |
| 880 transport_send_->send_side_cc()->GetPacerQueuingDelayMs(); | 810 transport_send_->send_side_cc()->GetPacerQueuingDelayMs(); |
| 881 stats.rtt_ms = call_stats_->rtcp_rtt_stats()->LastProcessedRtt(); | 811 stats.rtt_ms = call_stats_->rtcp_rtt_stats()->LastProcessedRtt(); |
| 882 { | 812 { |
| 883 rtc::CritScope cs(&bitrate_crit_); | 813 rtc::CritScope cs(&bitrate_crit_); |
| 884 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; | 814 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; |
| 885 } | 815 } |
| 886 return stats; | 816 return stats; |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 } | 1138 } |
| 1209 | 1139 |
| 1210 PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type, | 1140 PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type, |
| 1211 const uint8_t* packet, | 1141 const uint8_t* packet, |
| 1212 size_t length, | 1142 size_t length, |
| 1213 const PacketTime& packet_time) { | 1143 const PacketTime& packet_time) { |
| 1214 TRACE_EVENT0("webrtc", "Call::DeliverRtp"); | 1144 TRACE_EVENT0("webrtc", "Call::DeliverRtp"); |
| 1215 | 1145 |
| 1216 RTC_DCHECK(media_type == MediaType::AUDIO || media_type == MediaType::VIDEO); | 1146 RTC_DCHECK(media_type == MediaType::AUDIO || media_type == MediaType::VIDEO); |
| 1217 | 1147 |
| 1148 int64_t arrival_time_ms; |
| 1149 if (packet_time.timestamp != -1) { |
| 1150 arrival_time_ms = (packet_time.timestamp + 500) / 1000; |
| 1151 } else { |
| 1152 arrival_time_ms = clock_->TimeInMilliseconds(); |
| 1153 } |
| 1154 |
| 1218 ReadLockScoped read_lock(*receive_crit_); | 1155 ReadLockScoped read_lock(*receive_crit_); |
| 1219 // TODO(nisse): We should parse the RTP header only here, and pass | |
| 1220 // on parsed_packet to the receive streams. | |
| 1221 rtc::Optional<RtpPacketReceived> parsed_packet = | |
| 1222 ParseRtpPacket(packet, length, packet_time); | |
| 1223 | 1156 |
| 1224 if (!parsed_packet) | 1157 received_bytes_per_second_counter_.Add(static_cast<int>(length)); |
| 1225 return DELIVERY_PACKET_ERROR; | |
| 1226 | |
| 1227 NotifyBweOfReceivedPacket(*parsed_packet, media_type); | |
| 1228 | |
| 1229 uint32_t ssrc = parsed_packet->Ssrc(); | |
| 1230 | |
| 1231 if (media_type == MediaType::AUDIO) { | 1158 if (media_type == MediaType::AUDIO) { |
| 1232 auto it = audio_receive_ssrcs_.find(ssrc); | 1159 received_audio_bytes_per_second_counter_.Add(static_cast<int>(length)); |
| 1233 if (it != audio_receive_ssrcs_.end()) { | 1160 return rtp_transport_receive_audio_->OnRtpPacket( |
| 1234 received_bytes_per_second_counter_.Add(static_cast<int>(length)); | 1161 arrival_time_ms, rtc::ArrayView<const uint8_t>(packet, length)); |
| 1235 received_audio_bytes_per_second_counter_.Add(static_cast<int>(length)); | 1162 } else if (media_type == MediaType::VIDEO) { |
| 1236 it->second->OnRtpPacket(*parsed_packet); | 1163 received_video_bytes_per_second_counter_.Add(static_cast<int>(length)); |
| 1237 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); | 1164 return rtp_transport_receive_video_->OnRtpPacket( |
| 1238 return DELIVERY_OK; | 1165 arrival_time_ms, rtc::ArrayView<const uint8_t>(packet, length)); |
| 1239 } | |
| 1240 } | 1166 } |
| 1241 if (media_type == MediaType::VIDEO) { | 1167 RTC_NOTREACHED(); |
| 1242 auto it = video_receive_ssrcs_.find(ssrc); | 1168 return PacketReceiver::DELIVERY_PACKET_ERROR; |
| 1243 if (it != video_receive_ssrcs_.end()) { | |
| 1244 received_bytes_per_second_counter_.Add(static_cast<int>(length)); | |
| 1245 received_video_bytes_per_second_counter_.Add(static_cast<int>(length)); | |
| 1246 it->second->OnRtpPacket(*parsed_packet); | |
| 1247 | |
| 1248 // Deliver media packets to FlexFEC subsystem. | |
| 1249 auto it_bounds = flexfec_receive_ssrcs_media_.equal_range(ssrc); | |
| 1250 for (auto it = it_bounds.first; it != it_bounds.second; ++it) | |
| 1251 it->second->OnRtpPacket(*parsed_packet); | |
| 1252 | |
| 1253 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); | |
| 1254 return DELIVERY_OK; | |
| 1255 } | |
| 1256 } | |
| 1257 if (media_type == MediaType::VIDEO) { | |
| 1258 received_bytes_per_second_counter_.Add(static_cast<int>(length)); | |
| 1259 // TODO(brandtr): Update here when FlexFEC supports protecting audio. | |
| 1260 received_video_bytes_per_second_counter_.Add(static_cast<int>(length)); | |
| 1261 auto it = flexfec_receive_ssrcs_protection_.find(ssrc); | |
| 1262 if (it != flexfec_receive_ssrcs_protection_.end()) { | |
| 1263 it->second->OnRtpPacket(*parsed_packet); | |
| 1264 event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); | |
| 1265 return DELIVERY_OK; | |
| 1266 } | |
| 1267 } | |
| 1268 return DELIVERY_UNKNOWN_SSRC; | |
| 1269 } | 1169 } |
| 1270 | 1170 |
| 1271 PacketReceiver::DeliveryStatus Call::DeliverPacket( | 1171 PacketReceiver::DeliveryStatus Call::DeliverPacket( |
| 1272 MediaType media_type, | 1172 MediaType media_type, |
| 1273 const uint8_t* packet, | 1173 const uint8_t* packet, |
| 1274 size_t length, | 1174 size_t length, |
| 1275 const PacketTime& packet_time) { | 1175 const PacketTime& packet_time) { |
| 1276 // TODO(solenberg): Tests call this function on a network thread, libjingle | 1176 // TODO(solenberg): Tests call this function on a network thread, libjingle |
| 1277 // calls on the worker thread. We should move towards always using a network | 1177 // calls on the worker thread. We should move towards always using a network |
| 1278 // thread. Then this check can be enabled. | 1178 // thread. Then this check can be enabled. |
| 1279 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); | 1179 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); |
| 1280 if (RtpHeaderParser::IsRtcp(packet, length)) | 1180 if (RtpHeaderParser::IsRtcp(packet, length)) |
| 1281 return DeliverRtcp(media_type, packet, length); | 1181 return DeliverRtcp(media_type, packet, length); |
| 1282 | 1182 |
| 1283 return DeliverRtp(media_type, packet, length, packet_time); | 1183 return DeliverRtp(media_type, packet, length, packet_time); |
| 1284 } | 1184 } |
| 1285 | 1185 |
| 1286 // TODO(brandtr): Update this member function when we support protecting | 1186 // TODO(brandtr): Update this member function when we support protecting |
| 1287 // audio packets with FlexFEC. | 1187 // audio packets with FlexFEC. |
| 1188 |
| 1189 // TODO(nisse): Add a recovered flag to RtpParsedPacket, if needed for stats, |
| 1190 // and demux recovered packets in the same way as ordinary packets. |
| 1288 bool Call::OnRecoveredPacket(const uint8_t* packet, size_t length) { | 1191 bool Call::OnRecoveredPacket(const uint8_t* packet, size_t length) { |
| 1289 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]); | 1192 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]); |
| 1290 ReadLockScoped read_lock(*receive_crit_); | 1193 ReadLockScoped read_lock(*receive_crit_); |
| 1291 auto it = video_receive_ssrcs_.find(ssrc); | 1194 auto it = video_receive_ssrcs_.find(ssrc); |
| 1292 if (it == video_receive_ssrcs_.end()) | 1195 if (it == video_receive_ssrcs_.end()) |
| 1293 return false; | 1196 return false; |
| 1294 return it->second->OnRecoveredPacket(packet, length); | 1197 return it->second->OnRecoveredPacket(packet, length); |
| 1295 } | 1198 } |
| 1296 | 1199 |
| 1297 void Call::NotifyBweOfReceivedPacket(const RtpPacketReceived& packet, | |
| 1298 MediaType media_type) { | |
| 1299 auto it = receive_rtp_config_.find(packet.Ssrc()); | |
| 1300 bool use_send_side_bwe = | |
| 1301 (it != receive_rtp_config_.end()) && it->second.use_send_side_bwe; | |
| 1302 | |
| 1303 RTPHeader header; | |
| 1304 packet.GetHeader(&header); | |
| 1305 | |
| 1306 if (!use_send_side_bwe && header.extension.hasTransportSequenceNumber) { | |
| 1307 // Inconsistent configuration of send side BWE. Do nothing. | |
| 1308 // TODO(nisse): Without this check, we may produce RTCP feedback | |
| 1309 // packets even when not negotiated. But it would be cleaner to | |
| 1310 // move the check down to RTCPSender::SendFeedbackPacket, which | |
| 1311 // would also help the PacketRouter to select an appropriate rtp | |
| 1312 // module in the case that some, but not all, have RTCP feedback | |
| 1313 // enabled. | |
| 1314 return; | |
| 1315 } | |
| 1316 // For audio, we only support send side BWE. | |
| 1317 if (media_type == MediaType::VIDEO || | |
| 1318 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { | |
| 1319 receive_side_cc_.OnReceivedPacket( | |
| 1320 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), | |
| 1321 header); | |
| 1322 } | |
| 1323 } | |
| 1324 | |
| 1325 } // namespace internal | 1200 } // namespace internal |
| 1326 | 1201 |
| 1327 } // namespace webrtc | 1202 } // namespace webrtc |
| OLD | NEW |