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/common_types.h" | 19 #include "webrtc/common_types.h" |
20 #include "webrtc/common_video/include/video_bitrate_allocator.h" | 20 #include "webrtc/common_video/include/video_bitrate_allocator.h" |
21 #include "webrtc/base/checks.h" | 21 #include "webrtc/base/checks.h" |
22 #include "webrtc/base/file.h" | 22 #include "webrtc/base/file.h" |
23 #include "webrtc/base/logging.h" | 23 #include "webrtc/base/logging.h" |
24 #include "webrtc/base/trace_event.h" | 24 #include "webrtc/base/trace_event.h" |
25 #include "webrtc/base/weak_ptr.h" | 25 #include "webrtc/base/weak_ptr.h" |
| 26 #include "webrtc/call/rtp_transport_controller.h" |
26 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 27 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
27 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 28 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
28 #include "webrtc/modules/pacing/packet_router.h" | 29 #include "webrtc/modules/pacing/packet_router.h" |
29 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 30 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
30 #include "webrtc/modules/utility/include/process_thread.h" | 31 #include "webrtc/modules/utility/include/process_thread.h" |
31 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 32 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
32 #include "webrtc/system_wrappers/include/field_trial.h" | 33 #include "webrtc/system_wrappers/include/field_trial.h" |
33 #include "webrtc/video/call_stats.h" | 34 #include "webrtc/video/call_stats.h" |
| 35 #include "webrtc/video/payload_router.h" |
34 #include "webrtc/video/vie_remb.h" | 36 #include "webrtc/video/vie_remb.h" |
35 #include "webrtc/video_send_stream.h" | 37 #include "webrtc/video_send_stream.h" |
36 | 38 |
37 namespace webrtc { | 39 namespace webrtc { |
38 | 40 |
39 static const int kMinSendSidePacketHistorySize = 600; | 41 static const int kMinSendSidePacketHistorySize = 600; |
40 namespace { | 42 namespace { |
41 | 43 |
42 // We don't do MTU discovery, so assume that we have the standard ethernet MTU. | 44 // We don't do MTU discovery, so assume that we have the standard ethernet MTU. |
43 const size_t kPathMTU = 1500; | 45 const size_t kPathMTU = 1500; |
44 | 46 |
45 std::vector<RtpRtcp*> CreateRtpRtcpModules( | 47 std::vector<RtpRtcp*> CreateRtpRtcpModules( |
46 Transport* outgoing_transport, | 48 Transport* outgoing_transport, |
47 RtcpIntraFrameObserver* intra_frame_callback, | 49 RtcpIntraFrameObserver* intra_frame_callback, |
48 RtcpBandwidthObserver* bandwidth_callback, | 50 RtcpBandwidthObserver* bandwidth_callback, |
49 TransportFeedbackObserver* transport_feedback_callback, | 51 RtpTransportControllerSendInterface* transport, |
50 RtcpRttStats* rtt_stats, | 52 RtcpRttStats* rtt_stats, |
51 RtpPacketSender* paced_sender, | |
52 TransportSequenceNumberAllocator* transport_sequence_number_allocator, | |
53 FlexfecSender* flexfec_sender, | 53 FlexfecSender* flexfec_sender, |
54 SendStatisticsProxy* stats_proxy, | 54 SendStatisticsProxy* stats_proxy, |
55 SendDelayStats* send_delay_stats, | 55 SendDelayStats* send_delay_stats, |
56 RtcEventLog* event_log, | 56 RtcEventLog* event_log, |
57 RateLimiter* retransmission_rate_limiter, | 57 RateLimiter* retransmission_rate_limiter, |
58 OverheadObserver* overhead_observer, | 58 OverheadObserver* overhead_observer, |
59 size_t num_modules) { | 59 size_t num_modules) { |
60 RTC_DCHECK_GT(num_modules, 0); | 60 RTC_DCHECK_GT(num_modules, 0); |
61 RtpRtcp::Configuration configuration; | 61 RtpRtcp::Configuration configuration; |
62 ReceiveStatistics* null_receive_statistics = configuration.receive_statistics; | 62 ReceiveStatistics* null_receive_statistics = configuration.receive_statistics; |
63 configuration.audio = false; | 63 configuration.audio = false; |
64 configuration.receiver_only = false; | 64 configuration.receiver_only = false; |
65 configuration.flexfec_sender = flexfec_sender; | 65 configuration.flexfec_sender = flexfec_sender; |
66 configuration.receive_statistics = null_receive_statistics; | 66 configuration.receive_statistics = null_receive_statistics; |
67 configuration.outgoing_transport = outgoing_transport; | 67 configuration.outgoing_transport = outgoing_transport; |
68 configuration.intra_frame_callback = intra_frame_callback; | 68 configuration.intra_frame_callback = intra_frame_callback; |
69 configuration.bandwidth_callback = bandwidth_callback; | 69 configuration.bandwidth_callback = bandwidth_callback; |
70 configuration.transport_feedback_callback = transport_feedback_callback; | 70 configuration.transport_feedback_callback = |
| 71 transport->congestion_controller()->GetTransportFeedbackObserver(); |
71 configuration.rtt_stats = rtt_stats; | 72 configuration.rtt_stats = rtt_stats; |
72 configuration.rtcp_packet_type_counter_observer = stats_proxy; | 73 configuration.rtcp_packet_type_counter_observer = stats_proxy; |
73 configuration.paced_sender = paced_sender; | 74 configuration.paced_sender = transport->congestion_controller()->pacer(); |
74 configuration.transport_sequence_number_allocator = | 75 configuration.transport_sequence_number_allocator = |
75 transport_sequence_number_allocator; | 76 transport->packet_router(); |
76 configuration.send_bitrate_observer = stats_proxy; | 77 configuration.send_bitrate_observer = stats_proxy; |
77 configuration.send_frame_count_observer = stats_proxy; | 78 configuration.send_frame_count_observer = stats_proxy; |
78 configuration.send_side_delay_observer = stats_proxy; | 79 configuration.send_side_delay_observer = stats_proxy; |
79 configuration.send_packet_observer = send_delay_stats; | 80 configuration.send_packet_observer = send_delay_stats; |
80 configuration.event_log = event_log; | 81 configuration.event_log = event_log; |
81 configuration.retransmission_rate_limiter = retransmission_rate_limiter; | 82 configuration.retransmission_rate_limiter = retransmission_rate_limiter; |
82 configuration.overhead_observer = overhead_observer; | 83 configuration.overhead_observer = overhead_observer; |
83 std::vector<RtpRtcp*> modules; | 84 std::vector<RtpRtcp*> modules; |
84 for (size_t i = 0; i < num_modules; ++i) { | 85 for (size_t i = 0; i < num_modules; ++i) { |
85 RtpRtcp* rtp_rtcp = RtpRtcp::CreateRtpRtcp(configuration); | 86 RtpRtcp* rtp_rtcp = RtpRtcp::CreateRtpRtcp(configuration); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 // arbitrary thread. | 318 // arbitrary thread. |
318 class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver, | 319 class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver, |
319 public webrtc::OverheadObserver, | 320 public webrtc::OverheadObserver, |
320 public webrtc::VCMProtectionCallback, | 321 public webrtc::VCMProtectionCallback, |
321 public ViEEncoder::EncoderSink, | 322 public ViEEncoder::EncoderSink, |
322 public VideoBitrateAllocationObserver { | 323 public VideoBitrateAllocationObserver { |
323 public: | 324 public: |
324 VideoSendStreamImpl(SendStatisticsProxy* stats_proxy, | 325 VideoSendStreamImpl(SendStatisticsProxy* stats_proxy, |
325 rtc::TaskQueue* worker_queue, | 326 rtc::TaskQueue* worker_queue, |
326 CallStats* call_stats, | 327 CallStats* call_stats, |
327 CongestionController* congestion_controller, | 328 RtpTransportControllerSendInterface* transport, |
328 PacketRouter* packet_router, | |
329 BitrateAllocator* bitrate_allocator, | 329 BitrateAllocator* bitrate_allocator, |
330 SendDelayStats* send_delay_stats, | 330 SendDelayStats* send_delay_stats, |
331 VieRemb* remb, | |
332 ViEEncoder* vie_encoder, | 331 ViEEncoder* vie_encoder, |
333 RtcEventLog* event_log, | 332 RtcEventLog* event_log, |
334 const VideoSendStream::Config* config, | 333 const VideoSendStream::Config* config, |
335 int initial_encoder_max_bitrate, | 334 int initial_encoder_max_bitrate, |
336 std::map<uint32_t, RtpState> suspended_ssrcs); | 335 std::map<uint32_t, RtpState> suspended_ssrcs); |
337 ~VideoSendStreamImpl() override; | 336 ~VideoSendStreamImpl() override; |
338 | 337 |
339 // RegisterProcessThread register |module_process_thread| with those objects | 338 // RegisterProcessThread register |module_process_thread| with those objects |
340 // that use it. Registration has to happen on the thread were | 339 // that use it. Registration has to happen on the thread were |
341 // |module_process_thread| was created (libjingle's worker thread). | 340 // |module_process_thread| was created (libjingle's worker thread). |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 402 |
404 ProcessThread* module_process_thread_; | 403 ProcessThread* module_process_thread_; |
405 rtc::ThreadChecker module_process_thread_checker_; | 404 rtc::ThreadChecker module_process_thread_checker_; |
406 rtc::TaskQueue* const worker_queue_; | 405 rtc::TaskQueue* const worker_queue_; |
407 | 406 |
408 rtc::CriticalSection encoder_activity_crit_sect_; | 407 rtc::CriticalSection encoder_activity_crit_sect_; |
409 CheckEncoderActivityTask* check_encoder_activity_task_ | 408 CheckEncoderActivityTask* check_encoder_activity_task_ |
410 GUARDED_BY(encoder_activity_crit_sect_); | 409 GUARDED_BY(encoder_activity_crit_sect_); |
411 | 410 |
412 CallStats* const call_stats_; | 411 CallStats* const call_stats_; |
413 CongestionController* const congestion_controller_; | 412 RtpTransportControllerSendInterface* const transport_; |
414 PacketRouter* const packet_router_; | |
415 BitrateAllocator* const bitrate_allocator_; | 413 BitrateAllocator* const bitrate_allocator_; |
416 VieRemb* const remb_; | |
417 | 414 |
418 // TODO(brandtr): Consider moving this to a new FlexfecSendStream class. | 415 // TODO(brandtr): Consider moving this to a new FlexfecSendStream class. |
419 std::unique_ptr<FlexfecSender> flexfec_sender_; | 416 std::unique_ptr<FlexfecSender> flexfec_sender_; |
420 | 417 |
421 rtc::CriticalSection ivf_writers_crit_; | 418 rtc::CriticalSection ivf_writers_crit_; |
422 std::unique_ptr<IvfFileWriter> file_writers_[kMaxSimulcastStreams] GUARDED_BY( | 419 std::unique_ptr<IvfFileWriter> file_writers_[kMaxSimulcastStreams] GUARDED_BY( |
423 ivf_writers_crit_); | 420 ivf_writers_crit_); |
424 | 421 |
425 int max_padding_bitrate_; | 422 int max_padding_bitrate_; |
426 int encoder_min_bitrate_bps_; | 423 int encoder_min_bitrate_bps_; |
(...skipping 25 matching lines...) Expand all Loading... |
452 // TODO(tommi): See if there's a more elegant way to create a task that creates | 449 // TODO(tommi): See if there's a more elegant way to create a task that creates |
453 // an object on the correct task queue. | 450 // an object on the correct task queue. |
454 class VideoSendStream::ConstructionTask : public rtc::QueuedTask { | 451 class VideoSendStream::ConstructionTask : public rtc::QueuedTask { |
455 public: | 452 public: |
456 ConstructionTask(std::unique_ptr<VideoSendStreamImpl>* send_stream, | 453 ConstructionTask(std::unique_ptr<VideoSendStreamImpl>* send_stream, |
457 rtc::Event* done_event, | 454 rtc::Event* done_event, |
458 SendStatisticsProxy* stats_proxy, | 455 SendStatisticsProxy* stats_proxy, |
459 ViEEncoder* vie_encoder, | 456 ViEEncoder* vie_encoder, |
460 ProcessThread* module_process_thread, | 457 ProcessThread* module_process_thread, |
461 CallStats* call_stats, | 458 CallStats* call_stats, |
462 CongestionController* congestion_controller, | 459 RtpTransportControllerSendInterface* transport, |
463 PacketRouter* packet_router, | |
464 BitrateAllocator* bitrate_allocator, | 460 BitrateAllocator* bitrate_allocator, |
465 SendDelayStats* send_delay_stats, | 461 SendDelayStats* send_delay_stats, |
466 VieRemb* remb, | |
467 RtcEventLog* event_log, | 462 RtcEventLog* event_log, |
468 const VideoSendStream::Config* config, | 463 const VideoSendStream::Config* config, |
469 int initial_encoder_max_bitrate, | 464 int initial_encoder_max_bitrate, |
470 const std::map<uint32_t, RtpState>& suspended_ssrcs) | 465 const std::map<uint32_t, RtpState>& suspended_ssrcs) |
471 : send_stream_(send_stream), | 466 : send_stream_(send_stream), |
472 done_event_(done_event), | 467 done_event_(done_event), |
473 stats_proxy_(stats_proxy), | 468 stats_proxy_(stats_proxy), |
474 vie_encoder_(vie_encoder), | 469 vie_encoder_(vie_encoder), |
475 call_stats_(call_stats), | 470 call_stats_(call_stats), |
476 congestion_controller_(congestion_controller), | 471 transport_(transport), |
477 packet_router_(packet_router), | |
478 bitrate_allocator_(bitrate_allocator), | 472 bitrate_allocator_(bitrate_allocator), |
479 send_delay_stats_(send_delay_stats), | 473 send_delay_stats_(send_delay_stats), |
480 remb_(remb), | |
481 event_log_(event_log), | 474 event_log_(event_log), |
482 config_(config), | 475 config_(config), |
483 initial_encoder_max_bitrate_(initial_encoder_max_bitrate), | 476 initial_encoder_max_bitrate_(initial_encoder_max_bitrate), |
484 suspended_ssrcs_(suspended_ssrcs) {} | 477 suspended_ssrcs_(suspended_ssrcs) {} |
485 | 478 |
486 ~ConstructionTask() override { done_event_->Set(); } | 479 ~ConstructionTask() override { done_event_->Set(); } |
487 | 480 |
488 private: | 481 private: |
489 bool Run() override { | 482 bool Run() override { |
490 send_stream_->reset(new VideoSendStreamImpl( | 483 send_stream_->reset(new VideoSendStreamImpl( |
491 stats_proxy_, rtc::TaskQueue::Current(), call_stats_, | 484 stats_proxy_, rtc::TaskQueue::Current(), call_stats_, transport_, |
492 congestion_controller_, packet_router_, bitrate_allocator_, | 485 bitrate_allocator_, send_delay_stats_, vie_encoder_, event_log_, |
493 send_delay_stats_, remb_, vie_encoder_, event_log_, config_, | 486 config_, initial_encoder_max_bitrate_, std::move(suspended_ssrcs_))); |
494 initial_encoder_max_bitrate_, std::move(suspended_ssrcs_))); | |
495 return true; | 487 return true; |
496 } | 488 } |
497 | 489 |
498 std::unique_ptr<VideoSendStreamImpl>* const send_stream_; | 490 std::unique_ptr<VideoSendStreamImpl>* const send_stream_; |
499 rtc::Event* const done_event_; | 491 rtc::Event* const done_event_; |
500 SendStatisticsProxy* const stats_proxy_; | 492 SendStatisticsProxy* const stats_proxy_; |
501 ViEEncoder* const vie_encoder_; | 493 ViEEncoder* const vie_encoder_; |
502 CallStats* const call_stats_; | 494 CallStats* const call_stats_; |
503 CongestionController* const congestion_controller_; | 495 RtpTransportControllerSendInterface* const transport_; |
504 PacketRouter* const packet_router_; | |
505 BitrateAllocator* const bitrate_allocator_; | 496 BitrateAllocator* const bitrate_allocator_; |
506 SendDelayStats* const send_delay_stats_; | 497 SendDelayStats* const send_delay_stats_; |
507 VieRemb* const remb_; | |
508 RtcEventLog* const event_log_; | 498 RtcEventLog* const event_log_; |
509 const VideoSendStream::Config* config_; | 499 const VideoSendStream::Config* config_; |
510 int initial_encoder_max_bitrate_; | 500 int initial_encoder_max_bitrate_; |
511 std::map<uint32_t, RtpState> suspended_ssrcs_; | 501 std::map<uint32_t, RtpState> suspended_ssrcs_; |
512 }; | 502 }; |
513 | 503 |
514 class VideoSendStream::DestructAndGetRtpStateTask : public rtc::QueuedTask { | 504 class VideoSendStream::DestructAndGetRtpStateTask : public rtc::QueuedTask { |
515 public: | 505 public: |
516 DestructAndGetRtpStateTask(VideoSendStream::RtpStateMap* state_map, | 506 DestructAndGetRtpStateTask(VideoSendStream::RtpStateMap* state_map, |
517 std::unique_ptr<VideoSendStreamImpl> send_stream, | 507 std::unique_ptr<VideoSendStreamImpl> send_stream, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 rtc::WeakPtr<VideoSendStreamImpl> send_stream_; | 598 rtc::WeakPtr<VideoSendStreamImpl> send_stream_; |
609 std::vector<VideoStream> streams_; | 599 std::vector<VideoStream> streams_; |
610 int min_transmit_bitrate_bps_; | 600 int min_transmit_bitrate_bps_; |
611 }; | 601 }; |
612 | 602 |
613 VideoSendStream::VideoSendStream( | 603 VideoSendStream::VideoSendStream( |
614 int num_cpu_cores, | 604 int num_cpu_cores, |
615 ProcessThread* module_process_thread, | 605 ProcessThread* module_process_thread, |
616 rtc::TaskQueue* worker_queue, | 606 rtc::TaskQueue* worker_queue, |
617 CallStats* call_stats, | 607 CallStats* call_stats, |
618 CongestionController* congestion_controller, | 608 RtpTransportControllerSendInterface* transport, |
619 PacketRouter* packet_router, | |
620 BitrateAllocator* bitrate_allocator, | 609 BitrateAllocator* bitrate_allocator, |
621 SendDelayStats* send_delay_stats, | 610 SendDelayStats* send_delay_stats, |
622 VieRemb* remb, | |
623 RtcEventLog* event_log, | 611 RtcEventLog* event_log, |
624 VideoSendStream::Config config, | 612 VideoSendStream::Config config, |
625 VideoEncoderConfig encoder_config, | 613 VideoEncoderConfig encoder_config, |
626 const std::map<uint32_t, RtpState>& suspended_ssrcs) | 614 const std::map<uint32_t, RtpState>& suspended_ssrcs) |
627 : worker_queue_(worker_queue), | 615 : worker_queue_(worker_queue), |
628 thread_sync_event_(false /* manual_reset */, false), | 616 thread_sync_event_(false /* manual_reset */, false), |
629 stats_proxy_(Clock::GetRealTimeClock(), | 617 stats_proxy_(Clock::GetRealTimeClock(), |
630 config, | 618 config, |
631 encoder_config.content_type), | 619 encoder_config.content_type), |
632 config_(std::move(config)) { | 620 config_(std::move(config)) { |
633 vie_encoder_.reset(new ViEEncoder( | 621 vie_encoder_.reset(new ViEEncoder( |
634 num_cpu_cores, &stats_proxy_, config_.encoder_settings, | 622 num_cpu_cores, &stats_proxy_, config_.encoder_settings, |
635 config_.pre_encode_callback, config_.post_encode_callback)); | 623 config_.pre_encode_callback, config_.post_encode_callback)); |
636 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(new ConstructionTask( | 624 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(new ConstructionTask( |
637 &send_stream_, &thread_sync_event_, &stats_proxy_, vie_encoder_.get(), | 625 &send_stream_, &thread_sync_event_, &stats_proxy_, vie_encoder_.get(), |
638 module_process_thread, call_stats, congestion_controller, packet_router, | 626 module_process_thread, call_stats, transport, bitrate_allocator, |
639 bitrate_allocator, send_delay_stats, remb, event_log, &config_, | 627 send_delay_stats, event_log, &config_, encoder_config.max_bitrate_bps, |
640 encoder_config.max_bitrate_bps, suspended_ssrcs))); | 628 suspended_ssrcs))); |
641 | 629 |
642 // Wait for ConstructionTask to complete so that |send_stream_| can be used. | 630 // Wait for ConstructionTask to complete so that |send_stream_| can be used. |
643 // |module_process_thread| must be registered and deregistered on the thread | 631 // |module_process_thread| must be registered and deregistered on the thread |
644 // it was created on. | 632 // it was created on. |
645 thread_sync_event_.Wait(rtc::Event::kForever); | 633 thread_sync_event_.Wait(rtc::Event::kForever); |
646 send_stream_->RegisterProcessThread(module_process_thread); | 634 send_stream_->RegisterProcessThread(module_process_thread); |
647 // TODO(sprang): Enable this also for regular video calls if it works well. | 635 // TODO(sprang): Enable this also for regular video calls if it works well. |
648 if (encoder_config.content_type == VideoEncoderConfig::ContentType::kScreen) { | 636 if (encoder_config.content_type == VideoEncoderConfig::ContentType::kScreen) { |
649 // Only signal target bitrate for screenshare streams, for now. | 637 // Only signal target bitrate for screenshare streams, for now. |
650 vie_encoder_->SetBitrateObserver(send_stream_.get()); | 638 vie_encoder_->SetBitrateObserver(send_stream_.get()); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 void VideoSendStream::EnableEncodedFrameRecording( | 728 void VideoSendStream::EnableEncodedFrameRecording( |
741 const std::vector<rtc::PlatformFile>& files, | 729 const std::vector<rtc::PlatformFile>& files, |
742 size_t byte_limit) { | 730 size_t byte_limit) { |
743 send_stream_->EnableEncodedFrameRecording(files, byte_limit); | 731 send_stream_->EnableEncodedFrameRecording(files, byte_limit); |
744 } | 732 } |
745 | 733 |
746 VideoSendStreamImpl::VideoSendStreamImpl( | 734 VideoSendStreamImpl::VideoSendStreamImpl( |
747 SendStatisticsProxy* stats_proxy, | 735 SendStatisticsProxy* stats_proxy, |
748 rtc::TaskQueue* worker_queue, | 736 rtc::TaskQueue* worker_queue, |
749 CallStats* call_stats, | 737 CallStats* call_stats, |
750 CongestionController* congestion_controller, | 738 RtpTransportControllerSendInterface* transport, |
751 PacketRouter* packet_router, | |
752 BitrateAllocator* bitrate_allocator, | 739 BitrateAllocator* bitrate_allocator, |
753 SendDelayStats* send_delay_stats, | 740 SendDelayStats* send_delay_stats, |
754 VieRemb* remb, | |
755 ViEEncoder* vie_encoder, | 741 ViEEncoder* vie_encoder, |
756 RtcEventLog* event_log, | 742 RtcEventLog* event_log, |
757 const VideoSendStream::Config* config, | 743 const VideoSendStream::Config* config, |
758 int initial_encoder_max_bitrate, | 744 int initial_encoder_max_bitrate, |
759 std::map<uint32_t, RtpState> suspended_ssrcs) | 745 std::map<uint32_t, RtpState> suspended_ssrcs) |
760 : send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName( | 746 : send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName( |
761 "WebRTC-SendSideBwe-WithOverhead") == "Enabled"), | 747 "WebRTC-SendSideBwe-WithOverhead") == |
| 748 "Enabled"), |
762 stats_proxy_(stats_proxy), | 749 stats_proxy_(stats_proxy), |
763 config_(config), | 750 config_(config), |
764 suspended_ssrcs_(std::move(suspended_ssrcs)), | 751 suspended_ssrcs_(std::move(suspended_ssrcs)), |
765 module_process_thread_(nullptr), | 752 module_process_thread_(nullptr), |
766 worker_queue_(worker_queue), | 753 worker_queue_(worker_queue), |
767 check_encoder_activity_task_(nullptr), | 754 check_encoder_activity_task_(nullptr), |
768 call_stats_(call_stats), | 755 call_stats_(call_stats), |
769 congestion_controller_(congestion_controller), | 756 transport_(transport), |
770 packet_router_(packet_router), | |
771 bitrate_allocator_(bitrate_allocator), | 757 bitrate_allocator_(bitrate_allocator), |
772 remb_(remb), | |
773 flexfec_sender_(MaybeCreateFlexfecSender(*config_)), | 758 flexfec_sender_(MaybeCreateFlexfecSender(*config_)), |
774 max_padding_bitrate_(0), | 759 max_padding_bitrate_(0), |
775 encoder_min_bitrate_bps_(0), | 760 encoder_min_bitrate_bps_(0), |
776 encoder_max_bitrate_bps_(initial_encoder_max_bitrate), | 761 encoder_max_bitrate_bps_(initial_encoder_max_bitrate), |
777 encoder_target_rate_bps_(0), | 762 encoder_target_rate_bps_(0), |
778 vie_encoder_(vie_encoder), | 763 vie_encoder_(vie_encoder), |
779 encoder_feedback_(Clock::GetRealTimeClock(), | 764 encoder_feedback_(Clock::GetRealTimeClock(), |
780 config_->rtp.ssrcs, | 765 config_->rtp.ssrcs, |
781 vie_encoder), | 766 vie_encoder), |
782 protection_bitrate_calculator_(Clock::GetRealTimeClock(), this), | 767 protection_bitrate_calculator_(Clock::GetRealTimeClock(), this), |
783 bandwidth_observer_(congestion_controller_->GetBitrateController() | 768 bandwidth_observer_(transport->congestion_controller() |
| 769 ->GetBitrateController() |
784 ->CreateRtcpBandwidthObserver()), | 770 ->CreateRtcpBandwidthObserver()), |
785 rtp_rtcp_modules_(CreateRtpRtcpModules( | 771 rtp_rtcp_modules_(CreateRtpRtcpModules( |
786 config_->send_transport, | 772 config_->send_transport, |
787 &encoder_feedback_, | 773 &encoder_feedback_, |
788 bandwidth_observer_.get(), | 774 bandwidth_observer_.get(), |
789 congestion_controller_->GetTransportFeedbackObserver(), | 775 transport, |
790 call_stats_->rtcp_rtt_stats(), | 776 call_stats_->rtcp_rtt_stats(), |
791 congestion_controller_->pacer(), | |
792 packet_router_, | |
793 flexfec_sender_.get(), | 777 flexfec_sender_.get(), |
794 stats_proxy_, | 778 stats_proxy_, |
795 send_delay_stats, | 779 send_delay_stats, |
796 event_log, | 780 event_log, |
797 congestion_controller_->GetRetransmissionRateLimiter(), | 781 transport->congestion_controller()->GetRetransmissionRateLimiter(), |
798 this, | 782 this, |
799 config_->rtp.ssrcs.size())), | 783 config_->rtp.ssrcs.size())), |
800 payload_router_(rtp_rtcp_modules_, | 784 payload_router_(rtp_rtcp_modules_, |
801 config_->encoder_settings.payload_type), | 785 config_->encoder_settings.payload_type), |
802 weak_ptr_factory_(this), | 786 weak_ptr_factory_(this), |
803 overhead_bytes_per_packet_(0), | 787 overhead_bytes_per_packet_(0), |
804 transport_overhead_bytes_per_packet_(0) { | 788 transport_overhead_bytes_per_packet_(0) { |
805 RTC_DCHECK_RUN_ON(worker_queue_); | 789 RTC_DCHECK_RUN_ON(worker_queue_); |
806 LOG(LS_INFO) << "VideoSendStreamInternal: " << config_->ToString(); | 790 LOG(LS_INFO) << "VideoSendStreamInternal: " << config_->ToString(); |
807 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); | 791 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); |
808 module_process_thread_checker_.DetachFromThread(); | 792 module_process_thread_checker_.DetachFromThread(); |
809 | 793 |
810 RTC_DCHECK(!config_->rtp.ssrcs.empty()); | 794 RTC_DCHECK(!config_->rtp.ssrcs.empty()); |
811 RTC_DCHECK(call_stats_); | 795 RTC_DCHECK(call_stats_); |
812 RTC_DCHECK(congestion_controller_); | 796 RTC_DCHECK(transport_); |
813 RTC_DCHECK(remb_); | 797 RTC_DCHECK(transport_->congestion_controller()); |
| 798 RTC_DCHECK(transport_->remb()); |
814 | 799 |
815 congestion_controller_->EnablePeriodicAlrProbing( | 800 transport->congestion_controller()->EnablePeriodicAlrProbing( |
816 config_->periodic_alr_bandwidth_probing); | 801 config_->periodic_alr_bandwidth_probing); |
817 | 802 |
818 // RTP/RTCP initialization. | 803 // RTP/RTCP initialization. |
819 | 804 |
820 // We add the highest spatial layer first to ensure it'll be prioritized | 805 // We add the highest spatial layer first to ensure it'll be prioritized |
821 // when sending padding, with the hope that the packet rate will be smaller, | 806 // when sending padding, with the hope that the packet rate will be smaller, |
822 // and that it's more important to protect than the lower layers. | 807 // and that it's more important to protect than the lower layers. |
823 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | 808 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) |
824 packet_router_->AddRtpModule(rtp_rtcp); | 809 transport->packet_router()->AddRtpModule(rtp_rtcp); |
825 | 810 |
826 for (size_t i = 0; i < config_->rtp.extensions.size(); ++i) { | 811 for (size_t i = 0; i < config_->rtp.extensions.size(); ++i) { |
827 const std::string& extension = config_->rtp.extensions[i].uri; | 812 const std::string& extension = config_->rtp.extensions[i].uri; |
828 int id = config_->rtp.extensions[i].id; | 813 int id = config_->rtp.extensions[i].id; |
829 // One-byte-extension local identifiers are in the range 1-14 inclusive. | 814 // One-byte-extension local identifiers are in the range 1-14 inclusive. |
830 RTC_DCHECK_GE(id, 1); | 815 RTC_DCHECK_GE(id, 1); |
831 RTC_DCHECK_LE(id, 14); | 816 RTC_DCHECK_LE(id, 14); |
832 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); | 817 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); |
833 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 818 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
834 RTC_CHECK_EQ(0, rtp_rtcp->RegisterSendRtpHeaderExtension( | 819 RTC_CHECK_EQ(0, rtp_rtcp->RegisterSendRtpHeaderExtension( |
835 StringToRtpExtensionType(extension), id)); | 820 StringToRtpExtensionType(extension), id)); |
836 } | 821 } |
837 } | 822 } |
838 | 823 |
839 remb_->AddRembSender(rtp_rtcp_modules_[0]); | 824 transport->remb()->AddRembSender(rtp_rtcp_modules_[0]); |
840 rtp_rtcp_modules_[0]->SetREMBStatus(true); | 825 rtp_rtcp_modules_[0]->SetREMBStatus(true); |
841 | 826 |
842 ConfigureProtection(); | 827 ConfigureProtection(); |
843 ConfigureSsrcs(); | 828 ConfigureSsrcs(); |
844 | 829 |
845 // TODO(pbos): Should we set CNAME on all RTP modules? | 830 // TODO(pbos): Should we set CNAME on all RTP modules? |
846 rtp_rtcp_modules_.front()->SetCNAME(config_->rtp.c_name.c_str()); | 831 rtp_rtcp_modules_.front()->SetCNAME(config_->rtp.c_name.c_str()); |
847 | 832 |
848 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 833 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
849 rtp_rtcp->RegisterRtcpStatisticsCallback(stats_proxy_); | 834 rtp_rtcp->RegisterRtcpStatisticsCallback(stats_proxy_); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 module_process_thread_->DeRegisterModule(rtp_rtcp); | 875 module_process_thread_->DeRegisterModule(rtp_rtcp); |
891 } | 876 } |
892 | 877 |
893 VideoSendStreamImpl::~VideoSendStreamImpl() { | 878 VideoSendStreamImpl::~VideoSendStreamImpl() { |
894 RTC_DCHECK_RUN_ON(worker_queue_); | 879 RTC_DCHECK_RUN_ON(worker_queue_); |
895 RTC_DCHECK(!payload_router_.IsActive()) | 880 RTC_DCHECK(!payload_router_.IsActive()) |
896 << "VideoSendStreamImpl::Stop not called"; | 881 << "VideoSendStreamImpl::Stop not called"; |
897 LOG(LS_INFO) << "~VideoSendStreamInternal: " << config_->ToString(); | 882 LOG(LS_INFO) << "~VideoSendStreamInternal: " << config_->ToString(); |
898 | 883 |
899 rtp_rtcp_modules_[0]->SetREMBStatus(false); | 884 rtp_rtcp_modules_[0]->SetREMBStatus(false); |
900 remb_->RemoveRembSender(rtp_rtcp_modules_[0]); | 885 transport_->remb()->RemoveRembSender(rtp_rtcp_modules_[0]); |
901 | 886 |
902 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 887 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
903 packet_router_->RemoveRtpModule(rtp_rtcp); | 888 transport_->packet_router()->RemoveRtpModule(rtp_rtcp); |
904 delete rtp_rtcp; | 889 delete rtp_rtcp; |
905 } | 890 } |
906 } | 891 } |
907 | 892 |
908 bool VideoSendStreamImpl::DeliverRtcp(const uint8_t* packet, size_t length) { | 893 bool VideoSendStreamImpl::DeliverRtcp(const uint8_t* packet, size_t length) { |
909 // Runs on a network thread. | 894 // Runs on a network thread. |
910 RTC_DCHECK(!worker_queue_->IsCurrent()); | 895 RTC_DCHECK(!worker_queue_->IsCurrent()); |
911 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | 896 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) |
912 rtp_rtcp->IncomingRtcpPacket(packet, length); | 897 rtp_rtcp->IncomingRtcpPacket(packet, length); |
913 return true; | 898 return true; |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 | 1306 |
1322 void VideoSendStreamImpl::SetTransportOverhead( | 1307 void VideoSendStreamImpl::SetTransportOverhead( |
1323 size_t transport_overhead_bytes_per_packet) { | 1308 size_t transport_overhead_bytes_per_packet) { |
1324 if (transport_overhead_bytes_per_packet >= static_cast<int>(kPathMTU)) { | 1309 if (transport_overhead_bytes_per_packet >= static_cast<int>(kPathMTU)) { |
1325 LOG(LS_ERROR) << "Transport overhead exceeds size of ethernet frame"; | 1310 LOG(LS_ERROR) << "Transport overhead exceeds size of ethernet frame"; |
1326 return; | 1311 return; |
1327 } | 1312 } |
1328 | 1313 |
1329 transport_overhead_bytes_per_packet_ = transport_overhead_bytes_per_packet; | 1314 transport_overhead_bytes_per_packet_ = transport_overhead_bytes_per_packet; |
1330 | 1315 |
1331 congestion_controller_->SetTransportOverhead( | 1316 transport_->congestion_controller()->SetTransportOverhead( |
1332 transport_overhead_bytes_per_packet_); | 1317 transport_overhead_bytes_per_packet_); |
1333 | 1318 |
1334 size_t rtp_packet_size = | 1319 size_t rtp_packet_size = |
1335 std::min(config_->rtp.max_packet_size, | 1320 std::min(config_->rtp.max_packet_size, |
1336 kPathMTU - transport_overhead_bytes_per_packet_); | 1321 kPathMTU - transport_overhead_bytes_per_packet_); |
1337 | 1322 |
1338 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 1323 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
1339 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); | 1324 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); |
1340 } | 1325 } |
1341 } | 1326 } |
1342 | 1327 |
1343 } // namespace internal | 1328 } // namespace internal |
1344 } // namespace webrtc | 1329 } // namespace webrtc |
OLD | NEW |