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