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 14 #include <memory> 15 #include <string> 16 #include <vector> 17 18 #include "absl/functional/any_invocable.h" 19 #include "api/task_queue/task_queue_base.h" 20 #include "modules/rtp_rtcp/source/rtcp_transceiver_config.h" 21 #include "modules/rtp_rtcp/source/rtcp_transceiver_impl.h" 22 #include "rtc_base/copy_on_write_buffer.h" 23 #include "system_wrappers/include/clock.h" 24 25 namespace webrtc { 26 // 27 // Manage incoming and outgoing rtcp messages for multiple BUNDLED streams. 28 // 29 // This class is thread-safe wrapper of RtcpTransceiverImpl 30 class RtcpTransceiver : public RtcpFeedbackSenderInterface { 31 public: 32 explicit RtcpTransceiver(const RtcpTransceiverConfig& config); 33 RtcpTransceiver(const RtcpTransceiver&) = delete; 34 RtcpTransceiver& operator=(const RtcpTransceiver&) = delete; 35 // Note that interfaces provided in constructor still might be used after the 36 // destructor. However they can only be used on the confic.task_queue. 37 // Use Stop function to get notified when they are no longer used or 38 // ensure those objects outlive the task queue. 39 ~RtcpTransceiver() override; 40 41 // Start asynchronious destruction of the RtcpTransceiver. 42 // It is safe to call destructor right after Stop exits. 43 // No other methods can be called. 44 // Note that interfaces provided in constructor or registered with AddObserver 45 // still might be used by the transceiver on the task queue 46 // until `on_destroyed` runs. 47 void Stop(absl::AnyInvocable<void() &&> on_destroyed); 48 49 // Registers observer to be notified about incoming rtcp packets. 50 // Calls to observer will be done on the `config.task_queue`. 51 void AddMediaReceiverRtcpObserver(uint32_t remote_ssrc, 52 MediaReceiverRtcpObserver* observer); 53 // Deregisters the observer. Might return before observer is deregistered. 54 // Runs `on_removed` when observer is deregistered. 55 void RemoveMediaReceiverRtcpObserver( 56 uint32_t remote_ssrc, 57 MediaReceiverRtcpObserver* observer, 58 absl::AnyInvocable<void() &&> on_removed); 59 60 // Enables/disables sending rtcp packets eventually. 61 // Packets may be sent after the SetReadyToSend(false) returns, but no new 62 // packets will be scheduled. 63 void SetReadyToSend(bool ready); 64 65 // Handles incoming rtcp packets. 66 void ReceivePacket(rtc::CopyOnWriteBuffer packet); 67 68 // Sends RTCP packets starting with a sender or receiver report. 69 void SendCompoundPacket(); 70 71 // (REMB) Receiver Estimated Max Bitrate. 72 // Includes REMB in following compound packets and sends a REMB message 73 // immediately if 'RtcpTransceiverConfig::send_remb_on_change' is set. 74 void SetRemb(int64_t bitrate_bps, std::vector<uint32_t> ssrcs) override; 75 // Stops sending REMB in following compound packets. 76 void UnsetRemb() override; 77 78 // TODO(bugs.webrtc.org/8239): Remove SendCombinedRtcpPacket 79 // and move generating of the TransportFeedback message inside 80 // RtcpTransceiverImpl when there is one RtcpTransceiver per rtp transport. 81 void SendCombinedRtcpPacket( 82 std::vector<std::unique_ptr<rtcp::RtcpPacket>> rtcp_packets) override; 83 84 // Reports missing packets, https://tools.ietf.org/html/rfc4585#section-6.2.1 85 void SendNack(uint32_t ssrc, std::vector<uint16_t> sequence_numbers); 86 87 // Requests new key frame. 88 // using PLI, https://tools.ietf.org/html/rfc4585#section-6.3.1.1 89 void SendPictureLossIndication(uint32_t ssrc); 90 // using FIR, https://tools.ietf.org/html/rfc5104#section-4.3.1.2 91 // Use the SendFullIntraRequest(ssrcs, true) instead. 92 void SendFullIntraRequest(std::vector<uint32_t> ssrcs); 93 // If new_request is true then requested sequence no. will increase for each 94 // requested ssrc. 95 void SendFullIntraRequest(std::vector<uint32_t> ssrcs, bool new_request); 96 97 private: 98 Clock* const clock_; 99 TaskQueueBase* const task_queue_; 100 std::unique_ptr<RtcpTransceiverImpl> rtcp_transceiver_; 101 }; 102 103 } // namespace webrtc 104 105 #endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_H_ 106