| 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" |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 // VideoSendStreamImpl implements internal::VideoSendStream. | 326 // VideoSendStreamImpl implements internal::VideoSendStream. |
| 327 // It is created and destroyed on |worker_queue|. The intent is to decrease the | 327 // It is created and destroyed on |worker_queue|. The intent is to decrease the |
| 328 // need for locking and to ensure methods are called in sequence. | 328 // need for locking and to ensure methods are called in sequence. |
| 329 // Public methods except |DeliverRtcp| must be called on |worker_queue|. | 329 // Public methods except |DeliverRtcp| must be called on |worker_queue|. |
| 330 // DeliverRtcp is called on the libjingle worker thread or a network thread. | 330 // DeliverRtcp is called on the libjingle worker thread or a network thread. |
| 331 // An encoder may deliver frames through the EncodedImageCallback on an | 331 // An encoder may deliver frames through the EncodedImageCallback on an |
| 332 // arbitrary thread. | 332 // arbitrary thread. |
| 333 class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver, | 333 class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver, |
| 334 public webrtc::OverheadObserver, | 334 public webrtc::OverheadObserver, |
| 335 public webrtc::VCMProtectionCallback, | 335 public webrtc::VCMProtectionCallback, |
| 336 public ViEEncoder::EncoderSink, | 336 public VideoStreamEncoder::EncoderSink, |
| 337 public VideoBitrateAllocationObserver { | 337 public VideoBitrateAllocationObserver { |
| 338 public: | 338 public: |
| 339 VideoSendStreamImpl(SendStatisticsProxy* stats_proxy, | 339 VideoSendStreamImpl(SendStatisticsProxy* stats_proxy, |
| 340 rtc::TaskQueue* worker_queue, | 340 rtc::TaskQueue* worker_queue, |
| 341 CallStats* call_stats, | 341 CallStats* call_stats, |
| 342 RtpTransportControllerSendInterface* transport, | 342 RtpTransportControllerSendInterface* transport, |
| 343 BitrateAllocator* bitrate_allocator, | 343 BitrateAllocator* bitrate_allocator, |
| 344 SendDelayStats* send_delay_stats, | 344 SendDelayStats* send_delay_stats, |
| 345 ViEEncoder* vie_encoder, | 345 VideoStreamEncoder* video_stream_encoder, |
| 346 RtcEventLog* event_log, | 346 RtcEventLog* event_log, |
| 347 const VideoSendStream::Config* config, | 347 const VideoSendStream::Config* config, |
| 348 int initial_encoder_max_bitrate, | 348 int initial_encoder_max_bitrate, |
| 349 std::map<uint32_t, RtpState> suspended_ssrcs, | 349 std::map<uint32_t, RtpState> suspended_ssrcs, |
| 350 VideoEncoderConfig::ContentType content_type, | 350 VideoEncoderConfig::ContentType content_type, |
| 351 const RtpKeepAliveConfig& keepalive_config); | 351 const RtpKeepAliveConfig& keepalive_config); |
| 352 ~VideoSendStreamImpl() override; | 352 ~VideoSendStreamImpl() override; |
| 353 | 353 |
| 354 // RegisterProcessThread register |module_process_thread| with those objects | 354 // RegisterProcessThread register |module_process_thread| with those objects |
| 355 // that use it. Registration has to happen on the thread were | 355 // that use it. Registration has to happen on the thread were |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 433 |
| 434 rtc::CriticalSection ivf_writers_crit_; | 434 rtc::CriticalSection ivf_writers_crit_; |
| 435 std::unique_ptr<IvfFileWriter> file_writers_[kMaxSimulcastStreams] GUARDED_BY( | 435 std::unique_ptr<IvfFileWriter> file_writers_[kMaxSimulcastStreams] GUARDED_BY( |
| 436 ivf_writers_crit_); | 436 ivf_writers_crit_); |
| 437 | 437 |
| 438 int max_padding_bitrate_; | 438 int max_padding_bitrate_; |
| 439 int encoder_min_bitrate_bps_; | 439 int encoder_min_bitrate_bps_; |
| 440 uint32_t encoder_max_bitrate_bps_; | 440 uint32_t encoder_max_bitrate_bps_; |
| 441 uint32_t encoder_target_rate_bps_; | 441 uint32_t encoder_target_rate_bps_; |
| 442 | 442 |
| 443 ViEEncoder* const vie_encoder_; | 443 VideoStreamEncoder* const video_stream_encoder_; |
| 444 EncoderRtcpFeedback encoder_feedback_; | 444 EncoderRtcpFeedback encoder_feedback_; |
| 445 ProtectionBitrateCalculator protection_bitrate_calculator_; | 445 ProtectionBitrateCalculator protection_bitrate_calculator_; |
| 446 | 446 |
| 447 const std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; | 447 const std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; |
| 448 // RtpRtcp modules, declared here as they use other members on construction. | 448 // RtpRtcp modules, declared here as they use other members on construction. |
| 449 const std::vector<RtpRtcp*> rtp_rtcp_modules_; | 449 const std::vector<RtpRtcp*> rtp_rtcp_modules_; |
| 450 PayloadRouter payload_router_; | 450 PayloadRouter payload_router_; |
| 451 | 451 |
| 452 // |weak_ptr_| to our self. This is used since we can not call | 452 // |weak_ptr_| to our self. This is used since we can not call |
| 453 // |weak_ptr_factory_.GetWeakPtr| from multiple sequences but it is ok to copy | 453 // |weak_ptr_factory_.GetWeakPtr| from multiple sequences but it is ok to copy |
| 454 // an existing WeakPtr. | 454 // an existing WeakPtr. |
| 455 rtc::WeakPtr<VideoSendStreamImpl> weak_ptr_; | 455 rtc::WeakPtr<VideoSendStreamImpl> weak_ptr_; |
| 456 // |weak_ptr_factory_| must be declared last to make sure all WeakPtr's are | 456 // |weak_ptr_factory_| must be declared last to make sure all WeakPtr's are |
| 457 // invalidated before any other members are destroyed. | 457 // invalidated before any other members are destroyed. |
| 458 rtc::WeakPtrFactory<VideoSendStreamImpl> weak_ptr_factory_; | 458 rtc::WeakPtrFactory<VideoSendStreamImpl> weak_ptr_factory_; |
| 459 | 459 |
| 460 rtc::CriticalSection overhead_bytes_per_packet_crit_; | 460 rtc::CriticalSection overhead_bytes_per_packet_crit_; |
| 461 size_t overhead_bytes_per_packet_ GUARDED_BY(overhead_bytes_per_packet_crit_); | 461 size_t overhead_bytes_per_packet_ GUARDED_BY(overhead_bytes_per_packet_crit_); |
| 462 size_t transport_overhead_bytes_per_packet_; | 462 size_t transport_overhead_bytes_per_packet_; |
| 463 }; | 463 }; |
| 464 | 464 |
| 465 // TODO(tommi): See if there's a more elegant way to create a task that creates | 465 // TODO(tommi): See if there's a more elegant way to create a task that creates |
| 466 // an object on the correct task queue. | 466 // an object on the correct task queue. |
| 467 class VideoSendStream::ConstructionTask : public rtc::QueuedTask { | 467 class VideoSendStream::ConstructionTask : public rtc::QueuedTask { |
| 468 public: | 468 public: |
| 469 ConstructionTask(std::unique_ptr<VideoSendStreamImpl>* send_stream, | 469 ConstructionTask(std::unique_ptr<VideoSendStreamImpl>* send_stream, |
| 470 rtc::Event* done_event, | 470 rtc::Event* done_event, |
| 471 SendStatisticsProxy* stats_proxy, | 471 SendStatisticsProxy* stats_proxy, |
| 472 ViEEncoder* vie_encoder, | 472 VideoStreamEncoder* video_stream_encoder, |
| 473 ProcessThread* module_process_thread, | 473 ProcessThread* module_process_thread, |
| 474 CallStats* call_stats, | 474 CallStats* call_stats, |
| 475 RtpTransportControllerSendInterface* transport, | 475 RtpTransportControllerSendInterface* transport, |
| 476 BitrateAllocator* bitrate_allocator, | 476 BitrateAllocator* bitrate_allocator, |
| 477 SendDelayStats* send_delay_stats, | 477 SendDelayStats* send_delay_stats, |
| 478 RtcEventLog* event_log, | 478 RtcEventLog* event_log, |
| 479 const VideoSendStream::Config* config, | 479 const VideoSendStream::Config* config, |
| 480 int initial_encoder_max_bitrate, | 480 int initial_encoder_max_bitrate, |
| 481 const std::map<uint32_t, RtpState>& suspended_ssrcs, | 481 const std::map<uint32_t, RtpState>& suspended_ssrcs, |
| 482 VideoEncoderConfig::ContentType content_type, | 482 VideoEncoderConfig::ContentType content_type, |
| 483 const RtpKeepAliveConfig& keepalive_config) | 483 const RtpKeepAliveConfig& keepalive_config) |
| 484 : send_stream_(send_stream), | 484 : send_stream_(send_stream), |
| 485 done_event_(done_event), | 485 done_event_(done_event), |
| 486 stats_proxy_(stats_proxy), | 486 stats_proxy_(stats_proxy), |
| 487 vie_encoder_(vie_encoder), | 487 video_stream_encoder_(video_stream_encoder), |
| 488 call_stats_(call_stats), | 488 call_stats_(call_stats), |
| 489 transport_(transport), | 489 transport_(transport), |
| 490 bitrate_allocator_(bitrate_allocator), | 490 bitrate_allocator_(bitrate_allocator), |
| 491 send_delay_stats_(send_delay_stats), | 491 send_delay_stats_(send_delay_stats), |
| 492 event_log_(event_log), | 492 event_log_(event_log), |
| 493 config_(config), | 493 config_(config), |
| 494 initial_encoder_max_bitrate_(initial_encoder_max_bitrate), | 494 initial_encoder_max_bitrate_(initial_encoder_max_bitrate), |
| 495 suspended_ssrcs_(suspended_ssrcs), | 495 suspended_ssrcs_(suspended_ssrcs), |
| 496 content_type_(content_type), | 496 content_type_(content_type), |
| 497 keepalive_config_(keepalive_config) {} | 497 keepalive_config_(keepalive_config) {} |
| 498 | 498 |
| 499 ~ConstructionTask() override { done_event_->Set(); } | 499 ~ConstructionTask() override { done_event_->Set(); } |
| 500 | 500 |
| 501 private: | 501 private: |
| 502 bool Run() override { | 502 bool Run() override { |
| 503 send_stream_->reset(new VideoSendStreamImpl( | 503 send_stream_->reset(new VideoSendStreamImpl( |
| 504 stats_proxy_, rtc::TaskQueue::Current(), call_stats_, transport_, | 504 stats_proxy_, rtc::TaskQueue::Current(), call_stats_, transport_, |
| 505 bitrate_allocator_, send_delay_stats_, vie_encoder_, event_log_, | 505 bitrate_allocator_, send_delay_stats_, video_stream_encoder_, |
| 506 config_, initial_encoder_max_bitrate_, std::move(suspended_ssrcs_), | 506 event_log_, config_, initial_encoder_max_bitrate_, |
| 507 content_type_, keepalive_config_)); | 507 std::move(suspended_ssrcs_), content_type_, keepalive_config_)); |
| 508 return true; | 508 return true; |
| 509 } | 509 } |
| 510 | 510 |
| 511 std::unique_ptr<VideoSendStreamImpl>* const send_stream_; | 511 std::unique_ptr<VideoSendStreamImpl>* const send_stream_; |
| 512 rtc::Event* const done_event_; | 512 rtc::Event* const done_event_; |
| 513 SendStatisticsProxy* const stats_proxy_; | 513 SendStatisticsProxy* const stats_proxy_; |
| 514 ViEEncoder* const vie_encoder_; | 514 VideoStreamEncoder* const video_stream_encoder_; |
| 515 CallStats* const call_stats_; | 515 CallStats* const call_stats_; |
| 516 RtpTransportControllerSendInterface* const transport_; | 516 RtpTransportControllerSendInterface* const transport_; |
| 517 BitrateAllocator* const bitrate_allocator_; | 517 BitrateAllocator* const bitrate_allocator_; |
| 518 SendDelayStats* const send_delay_stats_; | 518 SendDelayStats* const send_delay_stats_; |
| 519 RtcEventLog* const event_log_; | 519 RtcEventLog* const event_log_; |
| 520 const VideoSendStream::Config* config_; | 520 const VideoSendStream::Config* config_; |
| 521 int initial_encoder_max_bitrate_; | 521 int initial_encoder_max_bitrate_; |
| 522 std::map<uint32_t, RtpState> suspended_ssrcs_; | 522 std::map<uint32_t, RtpState> suspended_ssrcs_; |
| 523 const VideoEncoderConfig::ContentType content_type_; | 523 const VideoEncoderConfig::ContentType content_type_; |
| 524 const RtpKeepAliveConfig& keepalive_config_; | 524 const RtpKeepAliveConfig& keepalive_config_; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 VideoEncoderConfig encoder_config, | 636 VideoEncoderConfig encoder_config, |
| 637 const std::map<uint32_t, RtpState>& suspended_ssrcs, | 637 const std::map<uint32_t, RtpState>& suspended_ssrcs, |
| 638 const RtpKeepAliveConfig& keepalive_config) | 638 const RtpKeepAliveConfig& keepalive_config) |
| 639 : worker_queue_(worker_queue), | 639 : worker_queue_(worker_queue), |
| 640 thread_sync_event_(false /* manual_reset */, false), | 640 thread_sync_event_(false /* manual_reset */, false), |
| 641 stats_proxy_(Clock::GetRealTimeClock(), | 641 stats_proxy_(Clock::GetRealTimeClock(), |
| 642 config, | 642 config, |
| 643 encoder_config.content_type), | 643 encoder_config.content_type), |
| 644 config_(std::move(config)), | 644 config_(std::move(config)), |
| 645 content_type_(encoder_config.content_type) { | 645 content_type_(encoder_config.content_type) { |
| 646 vie_encoder_.reset( | 646 video_stream_encoder_.reset( |
| 647 new ViEEncoder(num_cpu_cores, &stats_proxy_, config_.encoder_settings, | 647 new VideoStreamEncoder(num_cpu_cores, &stats_proxy_, |
| 648 config_.pre_encode_callback, config_.post_encode_callback, | 648 config_.encoder_settings, |
| 649 std::unique_ptr<OveruseFrameDetector>())); | 649 config_.pre_encode_callback, |
| 650 config_.post_encode_callback, |
| 651 std::unique_ptr<OveruseFrameDetector>())); |
| 650 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(new ConstructionTask( | 652 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(new ConstructionTask( |
| 651 &send_stream_, &thread_sync_event_, &stats_proxy_, vie_encoder_.get(), | 653 &send_stream_, &thread_sync_event_, &stats_proxy_, |
| 652 module_process_thread, call_stats, transport, bitrate_allocator, | 654 video_stream_encoder_.get(), module_process_thread, call_stats, transport, |
| 653 send_delay_stats, event_log, &config_, encoder_config.max_bitrate_bps, | 655 bitrate_allocator, send_delay_stats, event_log, &config_, |
| 654 suspended_ssrcs, encoder_config.content_type, keepalive_config))); | 656 encoder_config.max_bitrate_bps, suspended_ssrcs, |
| 657 encoder_config.content_type, keepalive_config))); |
| 655 | 658 |
| 656 // Wait for ConstructionTask to complete so that |send_stream_| can be used. | 659 // Wait for ConstructionTask to complete so that |send_stream_| can be used. |
| 657 // |module_process_thread| must be registered and deregistered on the thread | 660 // |module_process_thread| must be registered and deregistered on the thread |
| 658 // it was created on. | 661 // it was created on. |
| 659 thread_sync_event_.Wait(rtc::Event::kForever); | 662 thread_sync_event_.Wait(rtc::Event::kForever); |
| 660 send_stream_->RegisterProcessThread(module_process_thread); | 663 send_stream_->RegisterProcessThread(module_process_thread); |
| 661 // TODO(sprang): Enable this also for regular video calls if it works well. | 664 // TODO(sprang): Enable this also for regular video calls if it works well. |
| 662 if (encoder_config.content_type == VideoEncoderConfig::ContentType::kScreen) { | 665 if (encoder_config.content_type == VideoEncoderConfig::ContentType::kScreen) { |
| 663 // Only signal target bitrate for screenshare streams, for now. | 666 // Only signal target bitrate for screenshare streams, for now. |
| 664 vie_encoder_->SetBitrateObserver(send_stream_.get()); | 667 video_stream_encoder_->SetBitrateObserver(send_stream_.get()); |
| 665 } | 668 } |
| 666 vie_encoder_->RegisterProcessThread(module_process_thread); | 669 video_stream_encoder_->RegisterProcessThread(module_process_thread); |
| 667 | 670 |
| 668 ReconfigureVideoEncoder(std::move(encoder_config)); | 671 ReconfigureVideoEncoder(std::move(encoder_config)); |
| 669 } | 672 } |
| 670 | 673 |
| 671 VideoSendStream::~VideoSendStream() { | 674 VideoSendStream::~VideoSendStream() { |
| 672 RTC_DCHECK_RUN_ON(&thread_checker_); | 675 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 673 RTC_DCHECK(!send_stream_); | 676 RTC_DCHECK(!send_stream_); |
| 674 } | 677 } |
| 675 | 678 |
| 676 void VideoSendStream::Start() { | 679 void VideoSendStream::Start() { |
| 677 RTC_DCHECK_RUN_ON(&thread_checker_); | 680 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 678 LOG(LS_INFO) << "VideoSendStream::Start"; | 681 LOG(LS_INFO) << "VideoSendStream::Start"; |
| 679 VideoSendStreamImpl* send_stream = send_stream_.get(); | 682 VideoSendStreamImpl* send_stream = send_stream_.get(); |
| 680 worker_queue_->PostTask([this, send_stream] { | 683 worker_queue_->PostTask([this, send_stream] { |
| 681 send_stream->Start(); | 684 send_stream->Start(); |
| 682 thread_sync_event_.Set(); | 685 thread_sync_event_.Set(); |
| 683 }); | 686 }); |
| 684 | 687 |
| 685 // It is expected that after VideoSendStream::Start has been called, incoming | 688 // It is expected that after VideoSendStream::Start has been called, incoming |
| 686 // frames are not dropped in ViEEncoder. To ensure this, Start has to be | 689 // frames are not dropped in VideoStreamEncoder. To ensure this, Start has to |
| 687 // synchronized. | 690 // be synchronized. |
| 688 thread_sync_event_.Wait(rtc::Event::kForever); | 691 thread_sync_event_.Wait(rtc::Event::kForever); |
| 689 } | 692 } |
| 690 | 693 |
| 691 void VideoSendStream::Stop() { | 694 void VideoSendStream::Stop() { |
| 692 RTC_DCHECK_RUN_ON(&thread_checker_); | 695 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 693 LOG(LS_INFO) << "VideoSendStream::Stop"; | 696 LOG(LS_INFO) << "VideoSendStream::Stop"; |
| 694 VideoSendStreamImpl* send_stream = send_stream_.get(); | 697 VideoSendStreamImpl* send_stream = send_stream_.get(); |
| 695 worker_queue_->PostTask([send_stream] { send_stream->Stop(); }); | 698 worker_queue_->PostTask([send_stream] { send_stream->Stop(); }); |
| 696 } | 699 } |
| 697 | 700 |
| 698 void VideoSendStream::SetSource( | 701 void VideoSendStream::SetSource( |
| 699 rtc::VideoSourceInterface<webrtc::VideoFrame>* source, | 702 rtc::VideoSourceInterface<webrtc::VideoFrame>* source, |
| 700 const DegradationPreference& degradation_preference) { | 703 const DegradationPreference& degradation_preference) { |
| 701 RTC_DCHECK_RUN_ON(&thread_checker_); | 704 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 702 vie_encoder_->SetSource(source, degradation_preference); | 705 video_stream_encoder_->SetSource(source, degradation_preference); |
| 703 } | 706 } |
| 704 | 707 |
| 705 void VideoSendStream::ReconfigureVideoEncoder(VideoEncoderConfig config) { | 708 void VideoSendStream::ReconfigureVideoEncoder(VideoEncoderConfig config) { |
| 706 // TODO(perkj): Some test cases in VideoSendStreamTest call | 709 // TODO(perkj): Some test cases in VideoSendStreamTest call |
| 707 // ReconfigureVideoEncoder from the network thread. | 710 // ReconfigureVideoEncoder from the network thread. |
| 708 // RTC_DCHECK_RUN_ON(&thread_checker_); | 711 // RTC_DCHECK_RUN_ON(&thread_checker_); |
| 709 RTC_DCHECK(content_type_ == config.content_type); | 712 RTC_DCHECK(content_type_ == config.content_type); |
| 710 vie_encoder_->ConfigureEncoder(std::move(config), config_.rtp.max_packet_size, | 713 video_stream_encoder_->ConfigureEncoder(std::move(config), |
| 711 config_.rtp.nack.rtp_history_ms > 0); | 714 config_.rtp.max_packet_size, |
| 715 config_.rtp.nack.rtp_history_ms > 0); |
| 712 } | 716 } |
| 713 | 717 |
| 714 VideoSendStream::Stats VideoSendStream::GetStats() { | 718 VideoSendStream::Stats VideoSendStream::GetStats() { |
| 715 // TODO(perkj, solenberg): Some test cases in EndToEndTest call GetStats from | 719 // TODO(perkj, solenberg): Some test cases in EndToEndTest call GetStats from |
| 716 // a network thread. See comment in Call::GetStats(). | 720 // a network thread. See comment in Call::GetStats(). |
| 717 // RTC_DCHECK_RUN_ON(&thread_checker_); | 721 // RTC_DCHECK_RUN_ON(&thread_checker_); |
| 718 return stats_proxy_.GetStats(); | 722 return stats_proxy_.GetStats(); |
| 719 } | 723 } |
| 720 | 724 |
| 721 void VideoSendStream::SignalNetworkState(NetworkState state) { | 725 void VideoSendStream::SignalNetworkState(NetworkState state) { |
| 722 RTC_DCHECK_RUN_ON(&thread_checker_); | 726 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 723 VideoSendStreamImpl* send_stream = send_stream_.get(); | 727 VideoSendStreamImpl* send_stream = send_stream_.get(); |
| 724 worker_queue_->PostTask( | 728 worker_queue_->PostTask( |
| 725 [send_stream, state] { send_stream->SignalNetworkState(state); }); | 729 [send_stream, state] { send_stream->SignalNetworkState(state); }); |
| 726 } | 730 } |
| 727 | 731 |
| 728 VideoSendStream::RtpStateMap VideoSendStream::StopPermanentlyAndGetRtpStates() { | 732 VideoSendStream::RtpStateMap VideoSendStream::StopPermanentlyAndGetRtpStates() { |
| 729 RTC_DCHECK_RUN_ON(&thread_checker_); | 733 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 730 vie_encoder_->Stop(); | 734 video_stream_encoder_->Stop(); |
| 731 vie_encoder_->DeRegisterProcessThread(); | 735 video_stream_encoder_->DeRegisterProcessThread(); |
| 732 VideoSendStream::RtpStateMap state_map; | 736 VideoSendStream::RtpStateMap state_map; |
| 733 send_stream_->DeRegisterProcessThread(); | 737 send_stream_->DeRegisterProcessThread(); |
| 734 worker_queue_->PostTask( | 738 worker_queue_->PostTask( |
| 735 std::unique_ptr<rtc::QueuedTask>(new DestructAndGetRtpStateTask( | 739 std::unique_ptr<rtc::QueuedTask>(new DestructAndGetRtpStateTask( |
| 736 &state_map, std::move(send_stream_), &thread_sync_event_))); | 740 &state_map, std::move(send_stream_), &thread_sync_event_))); |
| 737 thread_sync_event_.Wait(rtc::Event::kForever); | 741 thread_sync_event_.Wait(rtc::Event::kForever); |
| 738 return state_map; | 742 return state_map; |
| 739 } | 743 } |
| 740 | 744 |
| 741 void VideoSendStream::SetTransportOverhead( | 745 void VideoSendStream::SetTransportOverhead( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 758 send_stream_->EnableEncodedFrameRecording(files, byte_limit); | 762 send_stream_->EnableEncodedFrameRecording(files, byte_limit); |
| 759 } | 763 } |
| 760 | 764 |
| 761 VideoSendStreamImpl::VideoSendStreamImpl( | 765 VideoSendStreamImpl::VideoSendStreamImpl( |
| 762 SendStatisticsProxy* stats_proxy, | 766 SendStatisticsProxy* stats_proxy, |
| 763 rtc::TaskQueue* worker_queue, | 767 rtc::TaskQueue* worker_queue, |
| 764 CallStats* call_stats, | 768 CallStats* call_stats, |
| 765 RtpTransportControllerSendInterface* transport, | 769 RtpTransportControllerSendInterface* transport, |
| 766 BitrateAllocator* bitrate_allocator, | 770 BitrateAllocator* bitrate_allocator, |
| 767 SendDelayStats* send_delay_stats, | 771 SendDelayStats* send_delay_stats, |
| 768 ViEEncoder* vie_encoder, | 772 VideoStreamEncoder* video_stream_encoder, |
| 769 RtcEventLog* event_log, | 773 RtcEventLog* event_log, |
| 770 const VideoSendStream::Config* config, | 774 const VideoSendStream::Config* config, |
| 771 int initial_encoder_max_bitrate, | 775 int initial_encoder_max_bitrate, |
| 772 std::map<uint32_t, RtpState> suspended_ssrcs, | 776 std::map<uint32_t, RtpState> suspended_ssrcs, |
| 773 VideoEncoderConfig::ContentType content_type, | 777 VideoEncoderConfig::ContentType content_type, |
| 774 const RtpKeepAliveConfig& keepalive_config) | 778 const RtpKeepAliveConfig& keepalive_config) |
| 775 : send_side_bwe_with_overhead_( | 779 : send_side_bwe_with_overhead_( |
| 776 webrtc::field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead")), | 780 webrtc::field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead")), |
| 777 stats_proxy_(stats_proxy), | 781 stats_proxy_(stats_proxy), |
| 778 config_(config), | 782 config_(config), |
| 779 suspended_ssrcs_(std::move(suspended_ssrcs)), | 783 suspended_ssrcs_(std::move(suspended_ssrcs)), |
| 780 module_process_thread_(nullptr), | 784 module_process_thread_(nullptr), |
| 781 worker_queue_(worker_queue), | 785 worker_queue_(worker_queue), |
| 782 check_encoder_activity_task_(nullptr), | 786 check_encoder_activity_task_(nullptr), |
| 783 call_stats_(call_stats), | 787 call_stats_(call_stats), |
| 784 transport_(transport), | 788 transport_(transport), |
| 785 bitrate_allocator_(bitrate_allocator), | 789 bitrate_allocator_(bitrate_allocator), |
| 786 flexfec_sender_(MaybeCreateFlexfecSender(*config_, suspended_ssrcs_)), | 790 flexfec_sender_(MaybeCreateFlexfecSender(*config_, suspended_ssrcs_)), |
| 787 max_padding_bitrate_(0), | 791 max_padding_bitrate_(0), |
| 788 encoder_min_bitrate_bps_(0), | 792 encoder_min_bitrate_bps_(0), |
| 789 encoder_max_bitrate_bps_(initial_encoder_max_bitrate), | 793 encoder_max_bitrate_bps_(initial_encoder_max_bitrate), |
| 790 encoder_target_rate_bps_(0), | 794 encoder_target_rate_bps_(0), |
| 791 vie_encoder_(vie_encoder), | 795 video_stream_encoder_(video_stream_encoder), |
| 792 encoder_feedback_(Clock::GetRealTimeClock(), | 796 encoder_feedback_(Clock::GetRealTimeClock(), |
| 793 config_->rtp.ssrcs, | 797 config_->rtp.ssrcs, |
| 794 vie_encoder), | 798 video_stream_encoder), |
| 795 protection_bitrate_calculator_(Clock::GetRealTimeClock(), this), | 799 protection_bitrate_calculator_(Clock::GetRealTimeClock(), this), |
| 796 bandwidth_observer_(transport->send_side_cc() | 800 bandwidth_observer_(transport->send_side_cc() |
| 797 ->GetBitrateController() | 801 ->GetBitrateController() |
| 798 ->CreateRtcpBandwidthObserver()), | 802 ->CreateRtcpBandwidthObserver()), |
| 799 rtp_rtcp_modules_(CreateRtpRtcpModules( | 803 rtp_rtcp_modules_(CreateRtpRtcpModules( |
| 800 config_->send_transport, | 804 config_->send_transport, |
| 801 &encoder_feedback_, | 805 &encoder_feedback_, |
| 802 bandwidth_observer_.get(), | 806 bandwidth_observer_.get(), |
| 803 transport, | 807 transport, |
| 804 call_stats_->rtcp_rtt_stats(), | 808 call_stats_->rtcp_rtt_stats(), |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 rtp_rtcp->SetMaxRtpPacketSize(config_->rtp.max_packet_size); | 884 rtp_rtcp->SetMaxRtpPacketSize(config_->rtp.max_packet_size); |
| 881 rtp_rtcp->RegisterVideoSendPayload( | 885 rtp_rtcp->RegisterVideoSendPayload( |
| 882 config_->encoder_settings.payload_type, | 886 config_->encoder_settings.payload_type, |
| 883 config_->encoder_settings.payload_name.c_str()); | 887 config_->encoder_settings.payload_name.c_str()); |
| 884 } | 888 } |
| 885 | 889 |
| 886 RTC_DCHECK(config_->encoder_settings.encoder); | 890 RTC_DCHECK(config_->encoder_settings.encoder); |
| 887 RTC_DCHECK_GE(config_->encoder_settings.payload_type, 0); | 891 RTC_DCHECK_GE(config_->encoder_settings.payload_type, 0); |
| 888 RTC_DCHECK_LE(config_->encoder_settings.payload_type, 127); | 892 RTC_DCHECK_LE(config_->encoder_settings.payload_type, 127); |
| 889 | 893 |
| 890 vie_encoder_->SetStartBitrate(bitrate_allocator_->GetStartBitrate(this)); | 894 video_stream_encoder_->SetStartBitrate( |
| 895 bitrate_allocator_->GetStartBitrate(this)); |
| 891 | 896 |
| 892 // Only request rotation at the source when we positively know that the remote | 897 // Only request rotation at the source when we positively know that the remote |
| 893 // side doesn't support the rotation extension. This allows us to prepare the | 898 // side doesn't support the rotation extension. This allows us to prepare the |
| 894 // encoder in the expectation that rotation is supported - which is the common | 899 // encoder in the expectation that rotation is supported - which is the common |
| 895 // case. | 900 // case. |
| 896 bool rotation_applied = | 901 bool rotation_applied = |
| 897 std::find_if(config_->rtp.extensions.begin(), | 902 std::find_if(config_->rtp.extensions.begin(), |
| 898 config_->rtp.extensions.end(), | 903 config_->rtp.extensions.end(), |
| 899 [](const RtpExtension& extension) { | 904 [](const RtpExtension& extension) { |
| 900 return extension.uri == RtpExtension::kVideoRotationUri; | 905 return extension.uri == RtpExtension::kVideoRotationUri; |
| 901 }) == config_->rtp.extensions.end(); | 906 }) == config_->rtp.extensions.end(); |
| 902 | 907 |
| 903 vie_encoder_->SetSink(this, rotation_applied); | 908 video_stream_encoder_->SetSink(this, rotation_applied); |
| 904 } | 909 } |
| 905 | 910 |
| 906 void VideoSendStreamImpl::RegisterProcessThread( | 911 void VideoSendStreamImpl::RegisterProcessThread( |
| 907 ProcessThread* module_process_thread) { | 912 ProcessThread* module_process_thread) { |
| 908 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); | 913 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); |
| 909 RTC_DCHECK(!module_process_thread_); | 914 RTC_DCHECK(!module_process_thread_); |
| 910 module_process_thread_ = module_process_thread; | 915 module_process_thread_ = module_process_thread; |
| 911 | 916 |
| 912 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | 917 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) |
| 913 module_process_thread_->RegisterModule(rtp_rtcp, RTC_FROM_HERE); | 918 module_process_thread_->RegisterModule(rtp_rtcp, RTC_FROM_HERE); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 // Start monitoring encoder activity. | 959 // Start monitoring encoder activity. |
| 955 { | 960 { |
| 956 rtc::CritScope lock(&encoder_activity_crit_sect_); | 961 rtc::CritScope lock(&encoder_activity_crit_sect_); |
| 957 RTC_DCHECK(!check_encoder_activity_task_); | 962 RTC_DCHECK(!check_encoder_activity_task_); |
| 958 check_encoder_activity_task_ = new CheckEncoderActivityTask(weak_ptr_); | 963 check_encoder_activity_task_ = new CheckEncoderActivityTask(weak_ptr_); |
| 959 worker_queue_->PostDelayedTask( | 964 worker_queue_->PostDelayedTask( |
| 960 std::unique_ptr<rtc::QueuedTask>(check_encoder_activity_task_), | 965 std::unique_ptr<rtc::QueuedTask>(check_encoder_activity_task_), |
| 961 CheckEncoderActivityTask::kEncoderTimeOutMs); | 966 CheckEncoderActivityTask::kEncoderTimeOutMs); |
| 962 } | 967 } |
| 963 | 968 |
| 964 vie_encoder_->SendKeyFrame(); | 969 video_stream_encoder_->SendKeyFrame(); |
| 965 } | 970 } |
| 966 | 971 |
| 967 void VideoSendStreamImpl::Stop() { | 972 void VideoSendStreamImpl::Stop() { |
| 968 RTC_DCHECK_RUN_ON(worker_queue_); | 973 RTC_DCHECK_RUN_ON(worker_queue_); |
| 969 LOG(LS_INFO) << "VideoSendStream::Stop"; | 974 LOG(LS_INFO) << "VideoSendStream::Stop"; |
| 970 if (!payload_router_.IsActive()) | 975 if (!payload_router_.IsActive()) |
| 971 return; | 976 return; |
| 972 TRACE_EVENT_INSTANT0("webrtc", "VideoSendStream::Stop"); | 977 TRACE_EVENT_INSTANT0("webrtc", "VideoSendStream::Stop"); |
| 973 payload_router_.SetActive(false); | 978 payload_router_.SetActive(false); |
| 974 bitrate_allocator_->RemoveObserver(this); | 979 bitrate_allocator_->RemoveObserver(this); |
| 975 { | 980 { |
| 976 rtc::CritScope lock(&encoder_activity_crit_sect_); | 981 rtc::CritScope lock(&encoder_activity_crit_sect_); |
| 977 check_encoder_activity_task_->Stop(); | 982 check_encoder_activity_task_->Stop(); |
| 978 check_encoder_activity_task_ = nullptr; | 983 check_encoder_activity_task_ = nullptr; |
| 979 } | 984 } |
| 980 vie_encoder_->OnBitrateUpdated(0, 0, 0); | 985 video_stream_encoder_->OnBitrateUpdated(0, 0, 0); |
| 981 stats_proxy_->OnSetEncoderTargetRate(0); | 986 stats_proxy_->OnSetEncoderTargetRate(0); |
| 982 } | 987 } |
| 983 | 988 |
| 984 void VideoSendStreamImpl::SignalEncoderTimedOut() { | 989 void VideoSendStreamImpl::SignalEncoderTimedOut() { |
| 985 RTC_DCHECK_RUN_ON(worker_queue_); | 990 RTC_DCHECK_RUN_ON(worker_queue_); |
| 986 // If the encoder has not produced anything the last kEncoderTimeOutMs and it | 991 // If the encoder has not produced anything the last kEncoderTimeOutMs and it |
| 987 // is supposed to, deregister as BitrateAllocatorObserver. This can happen | 992 // is supposed to, deregister as BitrateAllocatorObserver. This can happen |
| 988 // if a camera stops producing frames. | 993 // if a camera stops producing frames. |
| 989 if (encoder_target_rate_bps_ > 0) { | 994 if (encoder_target_rate_bps_ > 0) { |
| 990 LOG(LS_INFO) << "SignalEncoderTimedOut, Encoder timed out."; | 995 LOG(LS_INFO) << "SignalEncoderTimedOut, Encoder timed out."; |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 bitrate_bps - encoder_target_rate_bps_) | 1296 bitrate_bps - encoder_target_rate_bps_) |
| 1292 : 0; | 1297 : 0; |
| 1293 | 1298 |
| 1294 // When the field trial "WebRTC-SendSideBwe-WithOverhead" is enabled | 1299 // When the field trial "WebRTC-SendSideBwe-WithOverhead" is enabled |
| 1295 // protection_bitrate includes overhead. | 1300 // protection_bitrate includes overhead. |
| 1296 uint32_t protection_bitrate = | 1301 uint32_t protection_bitrate = |
| 1297 bitrate_bps - (encoder_target_rate_bps_ + encoder_overhead_rate_bps); | 1302 bitrate_bps - (encoder_target_rate_bps_ + encoder_overhead_rate_bps); |
| 1298 | 1303 |
| 1299 encoder_target_rate_bps_ = | 1304 encoder_target_rate_bps_ = |
| 1300 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); | 1305 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); |
| 1301 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); | 1306 video_stream_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, |
| 1307 fraction_loss, rtt); |
| 1302 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); | 1308 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); |
| 1303 return protection_bitrate; | 1309 return protection_bitrate; |
| 1304 } | 1310 } |
| 1305 | 1311 |
| 1306 void VideoSendStreamImpl::EnableEncodedFrameRecording( | 1312 void VideoSendStreamImpl::EnableEncodedFrameRecording( |
| 1307 const std::vector<rtc::PlatformFile>& files, | 1313 const std::vector<rtc::PlatformFile>& files, |
| 1308 size_t byte_limit) { | 1314 size_t byte_limit) { |
| 1309 { | 1315 { |
| 1310 rtc::CritScope lock(&ivf_writers_crit_); | 1316 rtc::CritScope lock(&ivf_writers_crit_); |
| 1311 for (unsigned int i = 0; i < kMaxSimulcastStreams; ++i) { | 1317 for (unsigned int i = 0; i < kMaxSimulcastStreams; ++i) { |
| 1312 if (i < files.size()) { | 1318 if (i < files.size()) { |
| 1313 file_writers_[i] = IvfFileWriter::Wrap(rtc::File(files[i]), byte_limit); | 1319 file_writers_[i] = IvfFileWriter::Wrap(rtc::File(files[i]), byte_limit); |
| 1314 } else { | 1320 } else { |
| 1315 file_writers_[i].reset(); | 1321 file_writers_[i].reset(); |
| 1316 } | 1322 } |
| 1317 } | 1323 } |
| 1318 } | 1324 } |
| 1319 | 1325 |
| 1320 if (!files.empty()) { | 1326 if (!files.empty()) { |
| 1321 // Make a keyframe appear as early as possible in the logs, to give actually | 1327 // Make a keyframe appear as early as possible in the logs, to give actually |
| 1322 // decodable output. | 1328 // decodable output. |
| 1323 vie_encoder_->SendKeyFrame(); | 1329 video_stream_encoder_->SendKeyFrame(); |
| 1324 } | 1330 } |
| 1325 } | 1331 } |
| 1326 | 1332 |
| 1327 int VideoSendStreamImpl::ProtectionRequest( | 1333 int VideoSendStreamImpl::ProtectionRequest( |
| 1328 const FecProtectionParams* delta_params, | 1334 const FecProtectionParams* delta_params, |
| 1329 const FecProtectionParams* key_params, | 1335 const FecProtectionParams* key_params, |
| 1330 uint32_t* sent_video_rate_bps, | 1336 uint32_t* sent_video_rate_bps, |
| 1331 uint32_t* sent_nack_rate_bps, | 1337 uint32_t* sent_nack_rate_bps, |
| 1332 uint32_t* sent_fec_rate_bps) { | 1338 uint32_t* sent_fec_rate_bps) { |
| 1333 RTC_DCHECK_RUN_ON(worker_queue_); | 1339 RTC_DCHECK_RUN_ON(worker_queue_); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 std::min(config_->rtp.max_packet_size, | 1376 std::min(config_->rtp.max_packet_size, |
| 1371 kPathMTU - transport_overhead_bytes_per_packet_); | 1377 kPathMTU - transport_overhead_bytes_per_packet_); |
| 1372 | 1378 |
| 1373 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 1379 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
| 1374 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); | 1380 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); |
| 1375 } | 1381 } |
| 1376 } | 1382 } |
| 1377 | 1383 |
| 1378 } // namespace internal | 1384 } // namespace internal |
| 1379 } // namespace webrtc | 1385 } // namespace webrtc |
| OLD | NEW |