mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Stefan Holmer | a2f1533 | 2018-07-11 17:11:31 +0200 | [diff] [blame] | 11 | #ifndef CALL_PAYLOAD_ROUTER_H_ |
| 12 | #define CALL_PAYLOAD_ROUTER_H_ |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 13 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 14 | #include <map> |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 15 | #include <memory> |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 18 | #include "api/call/transport.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "api/video_codecs/video_encoder.h" |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 20 | #include "call/rtp_config.h" |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 21 | #include "call/rtp_payload_params.h" |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 22 | #include "call/rtp_transport_controller_send_interface.h" |
| 23 | #include "call/video_rtp_sender_interface.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 24 | #include "common_types.h" // NOLINT(build/include) |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 25 | #include "logging/rtc_event_log/rtc_event_log.h" |
| 26 | #include "modules/rtp_rtcp/include/flexfec_sender.h" |
philipel | 1a4746a | 2018-07-09 15:52:29 +0200 | [diff] [blame] | 27 | #include "modules/rtp_rtcp/source/rtp_video_header.h" |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 28 | #include "modules/utility/include/process_thread.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "rtc_base/constructormagic.h" |
| 30 | #include "rtc_base/criticalsection.h" |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 31 | #include "rtc_base/rate_limiter.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 32 | #include "rtc_base/thread_annotations.h" |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 33 | #include "rtc_base/thread_checker.h" |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 34 | |
| 35 | namespace webrtc { |
| 36 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 37 | class RTPFragmentationHeader; |
| 38 | class RtpRtcp; |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 39 | class RtpTransportControllerSendInterface; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 40 | |
| 41 | // PayloadRouter routes outgoing data to the correct sending RTP module, based |
| 42 | // on the simulcast layer in RTPVideoHeader. |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 43 | class PayloadRouter : public VideoRtpSenderInterface { |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 44 | public: |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 45 | // Rtp modules are assumed to be sorted in simulcast index order. |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 46 | PayloadRouter( |
| 47 | const std::vector<uint32_t>& ssrcs, |
| 48 | std::map<uint32_t, RtpState> suspended_ssrcs, |
| 49 | const std::map<uint32_t, RtpPayloadState>& states, |
| 50 | const RtpConfig& rtp_config, |
| 51 | const RtcpConfig& rtcp_config, |
| 52 | Transport* send_transport, |
| 53 | const RtpSenderObservers& observers, |
| 54 | RtpTransportControllerSendInterface* transport, |
| 55 | RtcEventLog* event_log, |
| 56 | RateLimiter* retransmission_limiter); // move inside RtpTransport |
Stefan Holmer | a2f1533 | 2018-07-11 17:11:31 +0200 | [diff] [blame] | 57 | ~PayloadRouter() override; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 58 | |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 59 | // RegisterProcessThread register |module_process_thread| with those objects |
| 60 | // that use it. Registration has to happen on the thread were |
| 61 | // |module_process_thread| was created (libjingle's worker thread). |
| 62 | // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue, |
| 63 | // maybe |worker_queue|. |
| 64 | void RegisterProcessThread(ProcessThread* module_process_thread) override; |
| 65 | void DeRegisterProcessThread() override; |
| 66 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 67 | // PayloadRouter will only route packets if being active, all packets will be |
| 68 | // dropped otherwise. |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 69 | void SetActive(bool active) override; |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 70 | // Sets the sending status of the rtp modules and appropriately sets the |
| 71 | // payload router to active if any rtp modules are active. |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 72 | void SetActiveModules(const std::vector<bool> active_modules) override; |
| 73 | bool IsActive() override; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 74 | |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 75 | void OnNetworkAvailability(bool network_available) override; |
| 76 | std::map<uint32_t, RtpState> GetRtpStates() const override; |
| 77 | std::map<uint32_t, RtpPayloadState> GetRtpPayloadStates() const override; |
| 78 | |
| 79 | bool FecEnabled() const override; |
| 80 | |
| 81 | bool NackEnabled() const override; |
| 82 | |
| 83 | void DeliverRtcp(const uint8_t* packet, size_t length) override; |
| 84 | |
| 85 | void ProtectionRequest(const FecProtectionParams* delta_params, |
| 86 | const FecProtectionParams* key_params, |
| 87 | uint32_t* sent_video_rate_bps, |
| 88 | uint32_t* sent_nack_rate_bps, |
| 89 | uint32_t* sent_fec_rate_bps) override; |
| 90 | |
| 91 | void SetMaxRtpPacketSize(size_t max_rtp_packet_size) override; |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 92 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 93 | // Implements EncodedImageCallback. |
| 94 | // Returns 0 if the packet was routed / sent, -1 otherwise. |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 95 | EncodedImageCallback::Result OnEncodedImage( |
| 96 | const EncodedImage& encoded_image, |
| 97 | const CodecSpecificInfo* codec_specific_info, |
| 98 | const RTPFragmentationHeader* fragmentation) override; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 99 | |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 100 | void OnBitrateAllocationUpdated( |
| 101 | const VideoBitrateAllocation& bitrate) override; |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 102 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 103 | private: |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 104 | void UpdateModuleSendingState() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 105 | void ConfigureProtection(const RtpConfig& rtp_config); |
| 106 | void ConfigureSsrcs(const RtpConfig& rtp_config); |
Peter Boström | 8b79b07 | 2016-02-26 16:31:37 +0100 | [diff] [blame] | 107 | |
pbos | d8de115 | 2016-02-01 09:00:51 -0800 | [diff] [blame] | 108 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 109 | bool active_ RTC_GUARDED_BY(crit_); |
mflodman@webrtc.org | 7ac374a | 2015-02-20 12:45:40 +0000 | [diff] [blame] | 110 | |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 111 | ProcessThread* module_process_thread_; |
| 112 | rtc::ThreadChecker module_process_thread_checker_; |
| 113 | std::map<uint32_t, RtpState> suspended_ssrcs_; |
| 114 | |
| 115 | std::unique_ptr<FlexfecSender> flexfec_sender_; |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 116 | // Rtp modules are assumed to be sorted in simulcast index order. Not owned. |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame^] | 117 | const std::vector<std::unique_ptr<RtpRtcp>> rtp_modules_; |
| 118 | const RtpConfig rtp_config_; |
| 119 | RtpTransportControllerSendInterface* const transport_; |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 120 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 121 | std::vector<RtpPayloadParams> params_ RTC_GUARDED_BY(crit_); |
| 122 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 123 | RTC_DISALLOW_COPY_AND_ASSIGN(PayloadRouter); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } // namespace webrtc |
| 127 | |
Stefan Holmer | a2f1533 | 2018-07-11 17:11:31 +0200 | [diff] [blame] | 128 | #endif // CALL_PAYLOAD_ROUTER_H_ |