| 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 #include "webrtc/video/video_send_stream.h" | 10 #include "webrtc/video/video_send_stream.h" |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <cmath> | 13 #include <cmath> |
| 14 #include <sstream> | 14 #include <sstream> |
| 15 #include <string> | 15 #include <string> |
| 16 #include <utility> | 16 #include <utility> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
| 20 #include "webrtc/base/file.h" | 20 #include "webrtc/base/file.h" |
| 21 #include "webrtc/base/location.h" | 21 #include "webrtc/base/location.h" |
| 22 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
| 23 #include "webrtc/base/trace_event.h" | 23 #include "webrtc/base/trace_event.h" |
| 24 #include "webrtc/base/weak_ptr.h" | 24 #include "webrtc/base/weak_ptr.h" |
| 25 #include "webrtc/call/rtp_transport_controller_send_interface.h" | 25 #include "webrtc/call/rtp_transport_controller_send_interface.h" |
| 26 #include "webrtc/common_types.h" | 26 #include "webrtc/common_types.h" |
| 27 #include "webrtc/common_video/include/video_bitrate_allocator.h" | 27 #include "webrtc/common_video/include/video_bitrate_allocator.h" |
| 28 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 28 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 29 #include "webrtc/modules/congestion_controller/include/send_side_congestion_cont
roller.h" | 29 #include "webrtc/modules/congestion_controller/include/send_side_congestion_cont
roller.h" |
| 30 #include "webrtc/modules/pacing/alr_detector.h" |
| 30 #include "webrtc/modules/pacing/packet_router.h" | 31 #include "webrtc/modules/pacing/packet_router.h" |
| 31 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 32 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 32 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" | 33 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" |
| 33 #include "webrtc/modules/utility/include/process_thread.h" | 34 #include "webrtc/modules/utility/include/process_thread.h" |
| 34 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 35 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
| 35 #include "webrtc/system_wrappers/include/field_trial.h" | 36 #include "webrtc/system_wrappers/include/field_trial.h" |
| 36 #include "webrtc/video/call_stats.h" | 37 #include "webrtc/video/call_stats.h" |
| 37 #include "webrtc/video/payload_router.h" | 38 #include "webrtc/video/payload_router.h" |
| 38 #include "webrtc/video_send_stream.h" | 39 #include "webrtc/video_send_stream.h" |
| 39 | 40 |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 VideoSendStreamImpl(SendStatisticsProxy* stats_proxy, | 339 VideoSendStreamImpl(SendStatisticsProxy* stats_proxy, |
| 339 rtc::TaskQueue* worker_queue, | 340 rtc::TaskQueue* worker_queue, |
| 340 CallStats* call_stats, | 341 CallStats* call_stats, |
| 341 RtpTransportControllerSendInterface* transport, | 342 RtpTransportControllerSendInterface* transport, |
| 342 BitrateAllocator* bitrate_allocator, | 343 BitrateAllocator* bitrate_allocator, |
| 343 SendDelayStats* send_delay_stats, | 344 SendDelayStats* send_delay_stats, |
| 344 ViEEncoder* vie_encoder, | 345 ViEEncoder* vie_encoder, |
| 345 RtcEventLog* event_log, | 346 RtcEventLog* event_log, |
| 346 const VideoSendStream::Config* config, | 347 const VideoSendStream::Config* config, |
| 347 int initial_encoder_max_bitrate, | 348 int initial_encoder_max_bitrate, |
| 348 std::map<uint32_t, RtpState> suspended_ssrcs); | 349 std::map<uint32_t, RtpState> suspended_ssrcs, |
| 350 VideoEncoderConfig::ContentType content_type); |
| 349 ~VideoSendStreamImpl() override; | 351 ~VideoSendStreamImpl() override; |
| 350 | 352 |
| 351 // RegisterProcessThread register |module_process_thread| with those objects | 353 // RegisterProcessThread register |module_process_thread| with those objects |
| 352 // that use it. Registration has to happen on the thread were | 354 // that use it. Registration has to happen on the thread were |
| 353 // |module_process_thread| was created (libjingle's worker thread). | 355 // |module_process_thread| was created (libjingle's worker thread). |
| 354 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue, | 356 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue, |
| 355 // maybe |worker_queue|. | 357 // maybe |worker_queue|. |
| 356 void RegisterProcessThread(ProcessThread* module_process_thread); | 358 void RegisterProcessThread(ProcessThread* module_process_thread); |
| 357 void DeRegisterProcessThread(); | 359 void DeRegisterProcessThread(); |
| 358 | 360 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 SendStatisticsProxy* stats_proxy, | 470 SendStatisticsProxy* stats_proxy, |
| 469 ViEEncoder* vie_encoder, | 471 ViEEncoder* vie_encoder, |
| 470 ProcessThread* module_process_thread, | 472 ProcessThread* module_process_thread, |
| 471 CallStats* call_stats, | 473 CallStats* call_stats, |
| 472 RtpTransportControllerSendInterface* transport, | 474 RtpTransportControllerSendInterface* transport, |
| 473 BitrateAllocator* bitrate_allocator, | 475 BitrateAllocator* bitrate_allocator, |
| 474 SendDelayStats* send_delay_stats, | 476 SendDelayStats* send_delay_stats, |
| 475 RtcEventLog* event_log, | 477 RtcEventLog* event_log, |
| 476 const VideoSendStream::Config* config, | 478 const VideoSendStream::Config* config, |
| 477 int initial_encoder_max_bitrate, | 479 int initial_encoder_max_bitrate, |
| 478 const std::map<uint32_t, RtpState>& suspended_ssrcs) | 480 const std::map<uint32_t, RtpState>& suspended_ssrcs, |
| 481 VideoEncoderConfig::ContentType content_type) |
| 479 : send_stream_(send_stream), | 482 : send_stream_(send_stream), |
| 480 done_event_(done_event), | 483 done_event_(done_event), |
| 481 stats_proxy_(stats_proxy), | 484 stats_proxy_(stats_proxy), |
| 482 vie_encoder_(vie_encoder), | 485 vie_encoder_(vie_encoder), |
| 483 call_stats_(call_stats), | 486 call_stats_(call_stats), |
| 484 transport_(transport), | 487 transport_(transport), |
| 485 bitrate_allocator_(bitrate_allocator), | 488 bitrate_allocator_(bitrate_allocator), |
| 486 send_delay_stats_(send_delay_stats), | 489 send_delay_stats_(send_delay_stats), |
| 487 event_log_(event_log), | 490 event_log_(event_log), |
| 488 config_(config), | 491 config_(config), |
| 489 initial_encoder_max_bitrate_(initial_encoder_max_bitrate), | 492 initial_encoder_max_bitrate_(initial_encoder_max_bitrate), |
| 490 suspended_ssrcs_(suspended_ssrcs) {} | 493 suspended_ssrcs_(suspended_ssrcs), |
| 494 content_type_(content_type) {} |
| 491 | 495 |
| 492 ~ConstructionTask() override { done_event_->Set(); } | 496 ~ConstructionTask() override { done_event_->Set(); } |
| 493 | 497 |
| 494 private: | 498 private: |
| 495 bool Run() override { | 499 bool Run() override { |
| 496 send_stream_->reset(new VideoSendStreamImpl( | 500 send_stream_->reset(new VideoSendStreamImpl( |
| 497 stats_proxy_, rtc::TaskQueue::Current(), call_stats_, transport_, | 501 stats_proxy_, rtc::TaskQueue::Current(), call_stats_, transport_, |
| 498 bitrate_allocator_, send_delay_stats_, vie_encoder_, event_log_, | 502 bitrate_allocator_, send_delay_stats_, vie_encoder_, event_log_, |
| 499 config_, initial_encoder_max_bitrate_, std::move(suspended_ssrcs_))); | 503 config_, initial_encoder_max_bitrate_, std::move(suspended_ssrcs_), |
| 504 content_type_)); |
| 500 return true; | 505 return true; |
| 501 } | 506 } |
| 502 | 507 |
| 503 std::unique_ptr<VideoSendStreamImpl>* const send_stream_; | 508 std::unique_ptr<VideoSendStreamImpl>* const send_stream_; |
| 504 rtc::Event* const done_event_; | 509 rtc::Event* const done_event_; |
| 505 SendStatisticsProxy* const stats_proxy_; | 510 SendStatisticsProxy* const stats_proxy_; |
| 506 ViEEncoder* const vie_encoder_; | 511 ViEEncoder* const vie_encoder_; |
| 507 CallStats* const call_stats_; | 512 CallStats* const call_stats_; |
| 508 RtpTransportControllerSendInterface* const transport_; | 513 RtpTransportControllerSendInterface* const transport_; |
| 509 BitrateAllocator* const bitrate_allocator_; | 514 BitrateAllocator* const bitrate_allocator_; |
| 510 SendDelayStats* const send_delay_stats_; | 515 SendDelayStats* const send_delay_stats_; |
| 511 RtcEventLog* const event_log_; | 516 RtcEventLog* const event_log_; |
| 512 const VideoSendStream::Config* config_; | 517 const VideoSendStream::Config* config_; |
| 513 int initial_encoder_max_bitrate_; | 518 int initial_encoder_max_bitrate_; |
| 514 std::map<uint32_t, RtpState> suspended_ssrcs_; | 519 std::map<uint32_t, RtpState> suspended_ssrcs_; |
| 520 const VideoEncoderConfig::ContentType content_type_; |
| 515 }; | 521 }; |
| 516 | 522 |
| 517 class VideoSendStream::DestructAndGetRtpStateTask : public rtc::QueuedTask { | 523 class VideoSendStream::DestructAndGetRtpStateTask : public rtc::QueuedTask { |
| 518 public: | 524 public: |
| 519 DestructAndGetRtpStateTask(VideoSendStream::RtpStateMap* state_map, | 525 DestructAndGetRtpStateTask(VideoSendStream::RtpStateMap* state_map, |
| 520 std::unique_ptr<VideoSendStreamImpl> send_stream, | 526 std::unique_ptr<VideoSendStreamImpl> send_stream, |
| 521 rtc::Event* done_event) | 527 rtc::Event* done_event) |
| 522 : state_map_(state_map), | 528 : state_map_(state_map), |
| 523 send_stream_(std::move(send_stream)), | 529 send_stream_(std::move(send_stream)), |
| 524 done_event_(done_event) {} | 530 done_event_(done_event) {} |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 encoder_config.content_type), | 638 encoder_config.content_type), |
| 633 config_(std::move(config)), | 639 config_(std::move(config)), |
| 634 content_type_(encoder_config.content_type) { | 640 content_type_(encoder_config.content_type) { |
| 635 vie_encoder_.reset( | 641 vie_encoder_.reset( |
| 636 new ViEEncoder(num_cpu_cores, &stats_proxy_, config_.encoder_settings, | 642 new ViEEncoder(num_cpu_cores, &stats_proxy_, config_.encoder_settings, |
| 637 config_.pre_encode_callback, config_.post_encode_callback, | 643 config_.pre_encode_callback, config_.post_encode_callback, |
| 638 std::unique_ptr<OveruseFrameDetector>())); | 644 std::unique_ptr<OveruseFrameDetector>())); |
| 639 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(new ConstructionTask( | 645 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(new ConstructionTask( |
| 640 &send_stream_, &thread_sync_event_, &stats_proxy_, vie_encoder_.get(), | 646 &send_stream_, &thread_sync_event_, &stats_proxy_, vie_encoder_.get(), |
| 641 module_process_thread, call_stats, transport, bitrate_allocator, | 647 module_process_thread, call_stats, transport, bitrate_allocator, |
| 642 send_delay_stats, event_log, &config_, | 648 send_delay_stats, event_log, &config_, encoder_config.max_bitrate_bps, |
| 643 encoder_config.max_bitrate_bps, suspended_ssrcs))); | 649 suspended_ssrcs, encoder_config.content_type))); |
| 644 | 650 |
| 645 // Wait for ConstructionTask to complete so that |send_stream_| can be used. | 651 // Wait for ConstructionTask to complete so that |send_stream_| can be used. |
| 646 // |module_process_thread| must be registered and deregistered on the thread | 652 // |module_process_thread| must be registered and deregistered on the thread |
| 647 // it was created on. | 653 // it was created on. |
| 648 thread_sync_event_.Wait(rtc::Event::kForever); | 654 thread_sync_event_.Wait(rtc::Event::kForever); |
| 649 send_stream_->RegisterProcessThread(module_process_thread); | 655 send_stream_->RegisterProcessThread(module_process_thread); |
| 650 // TODO(sprang): Enable this also for regular video calls if it works well. | 656 // TODO(sprang): Enable this also for regular video calls if it works well. |
| 651 if (encoder_config.content_type == VideoEncoderConfig::ContentType::kScreen) { | 657 if (encoder_config.content_type == VideoEncoderConfig::ContentType::kScreen) { |
| 652 // Only signal target bitrate for screenshare streams, for now. | 658 // Only signal target bitrate for screenshare streams, for now. |
| 653 vie_encoder_->SetBitrateObserver(send_stream_.get()); | 659 vie_encoder_->SetBitrateObserver(send_stream_.get()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 SendStatisticsProxy* stats_proxy, | 757 SendStatisticsProxy* stats_proxy, |
| 752 rtc::TaskQueue* worker_queue, | 758 rtc::TaskQueue* worker_queue, |
| 753 CallStats* call_stats, | 759 CallStats* call_stats, |
| 754 RtpTransportControllerSendInterface* transport, | 760 RtpTransportControllerSendInterface* transport, |
| 755 BitrateAllocator* bitrate_allocator, | 761 BitrateAllocator* bitrate_allocator, |
| 756 SendDelayStats* send_delay_stats, | 762 SendDelayStats* send_delay_stats, |
| 757 ViEEncoder* vie_encoder, | 763 ViEEncoder* vie_encoder, |
| 758 RtcEventLog* event_log, | 764 RtcEventLog* event_log, |
| 759 const VideoSendStream::Config* config, | 765 const VideoSendStream::Config* config, |
| 760 int initial_encoder_max_bitrate, | 766 int initial_encoder_max_bitrate, |
| 761 std::map<uint32_t, RtpState> suspended_ssrcs) | 767 std::map<uint32_t, RtpState> suspended_ssrcs, |
| 768 VideoEncoderConfig::ContentType content_type) |
| 762 : send_side_bwe_with_overhead_( | 769 : send_side_bwe_with_overhead_( |
| 763 webrtc::field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead")), | 770 webrtc::field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead")), |
| 764 stats_proxy_(stats_proxy), | 771 stats_proxy_(stats_proxy), |
| 765 config_(config), | 772 config_(config), |
| 766 suspended_ssrcs_(std::move(suspended_ssrcs)), | 773 suspended_ssrcs_(std::move(suspended_ssrcs)), |
| 767 module_process_thread_(nullptr), | 774 module_process_thread_(nullptr), |
| 768 worker_queue_(worker_queue), | 775 worker_queue_(worker_queue), |
| 769 check_encoder_activity_task_(nullptr), | 776 check_encoder_activity_task_(nullptr), |
| 770 call_stats_(call_stats), | 777 call_stats_(call_stats), |
| 771 transport_(transport), | 778 transport_(transport), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 RTC_DCHECK_RUN_ON(worker_queue_); | 811 RTC_DCHECK_RUN_ON(worker_queue_); |
| 805 LOG(LS_INFO) << "VideoSendStreamInternal: " << config_->ToString(); | 812 LOG(LS_INFO) << "VideoSendStreamInternal: " << config_->ToString(); |
| 806 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); | 813 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); |
| 807 module_process_thread_checker_.DetachFromThread(); | 814 module_process_thread_checker_.DetachFromThread(); |
| 808 | 815 |
| 809 RTC_DCHECK(!config_->rtp.ssrcs.empty()); | 816 RTC_DCHECK(!config_->rtp.ssrcs.empty()); |
| 810 RTC_DCHECK(call_stats_); | 817 RTC_DCHECK(call_stats_); |
| 811 RTC_DCHECK(transport_); | 818 RTC_DCHECK(transport_); |
| 812 RTC_DCHECK(transport_->send_side_cc()); | 819 RTC_DCHECK(transport_->send_side_cc()); |
| 813 | 820 |
| 814 transport->send_side_cc()->EnablePeriodicAlrProbing( | 821 if (content_type == VideoEncoderConfig::ContentType::kScreen) { |
| 815 config_->periodic_alr_bandwidth_probing); | 822 rtc::Optional<AlrDetector::AlrExperimentSettings> alr_settings = |
| 823 AlrDetector::ParseAlrSettingsFromFieldTrial(); |
| 824 if (alr_settings) { |
| 825 transport->send_side_cc()->EnablePeriodicAlrProbing(true); |
| 826 transport->send_side_cc()->pacer()->SetPacingFactor( |
| 827 alr_settings->pacing_factor); |
| 828 transport->send_side_cc()->pacer()->SetQueueTimeLimit( |
| 829 alr_settings->max_paced_queue_time); |
| 830 } |
| 831 } |
| 832 |
| 833 if (config_->periodic_alr_bandwidth_probing) { |
| 834 transport->send_side_cc()->EnablePeriodicAlrProbing(true); |
| 835 } |
| 816 | 836 |
| 817 // RTP/RTCP initialization. | 837 // RTP/RTCP initialization. |
| 818 | 838 |
| 819 // We add the highest spatial layer first to ensure it'll be prioritized | 839 // We add the highest spatial layer first to ensure it'll be prioritized |
| 820 // when sending padding, with the hope that the packet rate will be smaller, | 840 // when sending padding, with the hope that the packet rate will be smaller, |
| 821 // and that it's more important to protect than the lower layers. | 841 // and that it's more important to protect than the lower layers. |
| 822 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | 842 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) |
| 823 transport->packet_router()->AddSendRtpModule(rtp_rtcp); | 843 transport->packet_router()->AddSendRtpModule(rtp_rtcp); |
| 824 | 844 |
| 825 for (size_t i = 0; i < config_->rtp.extensions.size(); ++i) { | 845 for (size_t i = 0; i < config_->rtp.extensions.size(); ++i) { |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 std::min(config_->rtp.max_packet_size, | 1361 std::min(config_->rtp.max_packet_size, |
| 1342 kPathMTU - transport_overhead_bytes_per_packet_); | 1362 kPathMTU - transport_overhead_bytes_per_packet_); |
| 1343 | 1363 |
| 1344 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 1364 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
| 1345 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); | 1365 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); |
| 1346 } | 1366 } |
| 1347 } | 1367 } |
| 1348 | 1368 |
| 1349 } // namespace internal | 1369 } // namespace internal |
| 1350 } // namespace webrtc | 1370 } // namespace webrtc |
| OLD | NEW |