Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | |
| 11 | #ifndef MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_H_ |
| 12 | #define MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_H_ |
| 13 | |
Danil Chapovalov | 98f5f6c | 2018-10-22 14:22:31 +0200 | [diff] [blame] | 14 | #include <functional> |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 15 | #include <memory> |
| 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
| 19 | #include "modules/rtp_rtcp/source/rtcp_transceiver_config.h" |
| 20 | #include "modules/rtp_rtcp/source/rtcp_transceiver_impl.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 21 | #include "rtc_base/copy_on_write_buffer.h" |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 22 | #include "rtc_base/task_queue.h" |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | // |
| 26 | // Manage incoming and outgoing rtcp messages for multiple BUNDLED streams. |
| 27 | // |
| 28 | // This class is thread-safe wrapper of RtcpTransceiverImpl |
Danil Chapovalov | eb0edd8 | 2017-12-14 16:02:31 +0100 | [diff] [blame] | 29 | class RtcpTransceiver : public RtcpFeedbackSenderInterface { |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 30 | public: |
| 31 | explicit RtcpTransceiver(const RtcpTransceiverConfig& config); |
Danil Chapovalov | 067818f | 2018-09-10 09:59:51 +0200 | [diff] [blame] | 32 | RtcpTransceiver(const RtcpTransceiver&) = delete; |
| 33 | RtcpTransceiver& operator=(const RtcpTransceiver&) = delete; |
Danil Chapovalov | 792df6b | 2018-09-07 13:03:32 +0200 | [diff] [blame] | 34 | // Note that interfaces provided in constructor still might be used after the |
| 35 | // destructor. However they can only be used on the confic.task_queue. |
| 36 | // Use Stop function to get notified when they are no longer used or |
| 37 | // ensure those objects outlive the task queue. |
Danil Chapovalov | eb0edd8 | 2017-12-14 16:02:31 +0100 | [diff] [blame] | 38 | ~RtcpTransceiver() override; |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 39 | |
Danil Chapovalov | f0076d3 | 2018-09-05 16:46:40 +0200 | [diff] [blame] | 40 | // Start asynchronious destruction of the RtcpTransceiver. |
| 41 | // It is safe to call destructor right after Stop exits. |
| 42 | // No other methods can be called. |
Danil Chapovalov | 792df6b | 2018-09-07 13:03:32 +0200 | [diff] [blame] | 43 | // Note that interfaces provided in constructor or registered with AddObserver |
| 44 | // still might be used by the transceiver on the task queue |
| 45 | // until |on_destroyed| runs. |
Danil Chapovalov | 98f5f6c | 2018-10-22 14:22:31 +0200 | [diff] [blame] | 46 | void Stop(std::function<void()> on_destroyed); |
Danil Chapovalov | f0076d3 | 2018-09-05 16:46:40 +0200 | [diff] [blame] | 47 | |
Danil Chapovalov | a32d710 | 2017-12-14 17:28:27 +0100 | [diff] [blame] | 48 | // Registers observer to be notified about incoming rtcp packets. |
| 49 | // Calls to observer will be done on the |config.task_queue|. |
| 50 | void AddMediaReceiverRtcpObserver(uint32_t remote_ssrc, |
| 51 | MediaReceiverRtcpObserver* observer); |
| 52 | // Deregisters the observer. Might return before observer is deregistered. |
Danil Chapovalov | 98f5f6c | 2018-10-22 14:22:31 +0200 | [diff] [blame] | 53 | // Runs |on_removed| when observer is deregistered. |
Danil Chapovalov | 98f5f6c | 2018-10-22 14:22:31 +0200 | [diff] [blame] | 54 | void RemoveMediaReceiverRtcpObserver(uint32_t remote_ssrc, |
| 55 | MediaReceiverRtcpObserver* observer, |
| 56 | std::function<void()> on_removed); |
Danil Chapovalov | a32d710 | 2017-12-14 17:28:27 +0100 | [diff] [blame] | 57 | |
Danil Chapovalov | e3927c5 | 2018-03-06 14:33:20 +0100 | [diff] [blame] | 58 | // Enables/disables sending rtcp packets eventually. |
| 59 | // Packets may be sent after the SetReadyToSend(false) returns, but no new |
| 60 | // packets will be scheduled. |
| 61 | void SetReadyToSend(bool ready); |
| 62 | |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 63 | // Handles incoming rtcp packets. |
| 64 | void ReceivePacket(rtc::CopyOnWriteBuffer packet); |
| 65 | |
| 66 | // Sends RTCP packets starting with a sender or receiver report. |
| 67 | void SendCompoundPacket(); |
| 68 | |
| 69 | // (REMB) Receiver Estimated Max Bitrate. |
| 70 | // Includes REMB in following compound packets. |
Danil Chapovalov | eb0edd8 | 2017-12-14 16:02:31 +0100 | [diff] [blame] | 71 | void SetRemb(int64_t bitrate_bps, std::vector<uint32_t> ssrcs) override; |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 72 | // Stops sending REMB in following compound packets. |
Danil Chapovalov | eb0edd8 | 2017-12-14 16:02:31 +0100 | [diff] [blame] | 73 | void UnsetRemb() override; |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 74 | |
Danil Chapovalov | d5cae4d | 2017-12-14 11:14:35 +0100 | [diff] [blame] | 75 | // TODO(bugs.webrtc.org/8239): Remove SendFeedbackPacket and SSRC functions |
| 76 | // and move generating of the TransportFeedback message inside |
| 77 | // RtcpTransceiverImpl when there is one RtcpTransceiver per rtp transport. |
| 78 | |
| 79 | // Returns ssrc to put as sender ssrc into rtcp::TransportFeedback. |
Danil Chapovalov | eb0edd8 | 2017-12-14 16:02:31 +0100 | [diff] [blame] | 80 | uint32_t SSRC() const override; |
| 81 | bool SendFeedbackPacket(const rtcp::TransportFeedback& packet) override; |
Sebastian Jansson | e1795f4 | 2019-07-24 11:38:03 +0200 | [diff] [blame] | 82 | bool SendNetworkStateEstimatePacket( |
| 83 | const rtcp::RemoteEstimate& packet) override; |
Danil Chapovalov | d5cae4d | 2017-12-14 11:14:35 +0100 | [diff] [blame] | 84 | |
Danil Chapovalov | 327c43c | 2017-11-27 17:23:04 +0100 | [diff] [blame] | 85 | // Reports missing packets, https://tools.ietf.org/html/rfc4585#section-6.2.1 |
| 86 | void SendNack(uint32_t ssrc, std::vector<uint16_t> sequence_numbers); |
| 87 | |
| 88 | // Requests new key frame. |
Danil Chapovalov | 2ddf98d | 2017-11-22 14:00:41 +0100 | [diff] [blame] | 89 | // using PLI, https://tools.ietf.org/html/rfc4585#section-6.3.1.1 |
Danil Chapovalov | 8d19e03 | 2017-11-28 19:53:33 +0100 | [diff] [blame] | 90 | void SendPictureLossIndication(uint32_t ssrc); |
Danil Chapovalov | 2ddf98d | 2017-11-22 14:00:41 +0100 | [diff] [blame] | 91 | // using FIR, https://tools.ietf.org/html/rfc5104#section-4.3.1.2 |
| 92 | void SendFullIntraRequest(std::vector<uint32_t> ssrcs); |
Danil Chapovalov | a7e418c | 2017-11-21 11:08:53 +0100 | [diff] [blame] | 93 | |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 94 | private: |
| 95 | rtc::TaskQueue* const task_queue_; |
| 96 | std::unique_ptr<RtcpTransceiverImpl> rtcp_transceiver_; |
Danil Chapovalov | c0fd5f9 | 2017-11-16 14:35:32 +0100 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | } // namespace webrtc |
| 100 | |
| 101 | #endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_H_ |