xref: /aosp_15_r20/external/webrtc/modules/rtp_rtcp/source/deprecated/deprecated_rtp_sender_egress.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2019 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_DEPRECATED_DEPRECATED_RTP_SENDER_EGRESS_H_
12 #define MODULES_RTP_RTCP_SOURCE_DEPRECATED_DEPRECATED_RTP_SENDER_EGRESS_H_
13 
14 #include <map>
15 #include <memory>
16 #include <vector>
17 
18 #include "absl/types/optional.h"
19 #include "api/call/transport.h"
20 #include "api/rtc_event_log/rtc_event_log.h"
21 #include "api/units/data_rate.h"
22 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
23 #include "modules/rtp_rtcp/source/packet_sequencer.h"
24 #include "modules/rtp_rtcp/source/rtp_packet_history.h"
25 #include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
26 #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
27 #include "modules/rtp_rtcp/source/rtp_sequence_number_map.h"
28 #include "rtc_base/rate_statistics.h"
29 #include "rtc_base/synchronization/mutex.h"
30 #include "rtc_base/thread_annotations.h"
31 
32 namespace webrtc {
33 
34 class DEPRECATED_RtpSenderEgress {
35  public:
36   // Helper class that redirects packets directly to the send part of this class
37   // without passing through an actual paced sender.
38   class NonPacedPacketSender : public RtpPacketSender {
39    public:
40     NonPacedPacketSender(DEPRECATED_RtpSenderEgress* sender,
41                          PacketSequencer* sequence_number_assigner);
42     virtual ~NonPacedPacketSender();
43 
44     void EnqueuePackets(
45         std::vector<std::unique_ptr<RtpPacketToSend>> packets) override;
46 
47    private:
48     uint16_t transport_sequence_number_;
49     DEPRECATED_RtpSenderEgress* const sender_;
50     PacketSequencer* sequence_number_assigner_;
51   };
52 
53   DEPRECATED_RtpSenderEgress(const RtpRtcpInterface::Configuration& config,
54                              RtpPacketHistory* packet_history);
55   ~DEPRECATED_RtpSenderEgress() = default;
56 
57   void SendPacket(RtpPacketToSend* packet, const PacedPacketInfo& pacing_info)
58       RTC_LOCKS_EXCLUDED(lock_);
Ssrc()59   uint32_t Ssrc() const { return ssrc_; }
RtxSsrc()60   absl::optional<uint32_t> RtxSsrc() const { return rtx_ssrc_; }
FlexFecSsrc()61   absl::optional<uint32_t> FlexFecSsrc() const { return flexfec_ssrc_; }
62 
63   void ProcessBitrateAndNotifyObservers() RTC_LOCKS_EXCLUDED(lock_);
64   RtpSendRates GetSendRates() const RTC_LOCKS_EXCLUDED(lock_);
65   void GetDataCounters(StreamDataCounters* rtp_stats,
66                        StreamDataCounters* rtx_stats) const
67       RTC_LOCKS_EXCLUDED(lock_);
68 
69   void ForceIncludeSendPacketsInAllocation(bool part_of_allocation)
70       RTC_LOCKS_EXCLUDED(lock_);
71   bool MediaHasBeenSent() const RTC_LOCKS_EXCLUDED(lock_);
72   void SetMediaHasBeenSent(bool media_sent) RTC_LOCKS_EXCLUDED(lock_);
73   void SetTimestampOffset(uint32_t timestamp) RTC_LOCKS_EXCLUDED(lock_);
74 
75   // For each sequence number in `sequence_number`, recall the last RTP packet
76   // which bore it - its timestamp and whether it was the first and/or last
77   // packet in that frame. If all of the given sequence numbers could be
78   // recalled, return a vector with all of them (in corresponding order).
79   // If any could not be recalled, return an empty vector.
80   std::vector<RtpSequenceNumberMap::Info> GetSentRtpPacketInfos(
81       rtc::ArrayView<const uint16_t> sequence_numbers) const
82       RTC_LOCKS_EXCLUDED(lock_);
83 
84  private:
85   // Maps capture time in milliseconds to send-side delay in milliseconds.
86   // Send-side delay is the difference between transmission time and capture
87   // time.
88   typedef std::map<int64_t, int> SendDelayMap;
89 
90   RtpSendRates GetSendRatesLocked() const RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_);
91   bool HasCorrectSsrc(const RtpPacketToSend& packet) const;
92   void AddPacketToTransportFeedback(uint16_t packet_id,
93                                     const RtpPacketToSend& packet,
94                                     const PacedPacketInfo& pacing_info);
95   void UpdateDelayStatistics(int64_t capture_time_ms,
96                              int64_t now_ms,
97                              uint32_t ssrc);
98   void RecomputeMaxSendDelay() RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_);
99   void UpdateOnSendPacket(int packet_id,
100                           int64_t capture_time_ms,
101                           uint32_t ssrc);
102   // Sends packet on to `transport_`, leaving the RTP module.
103   bool SendPacketToNetwork(const RtpPacketToSend& packet,
104                            const PacketOptions& options,
105                            const PacedPacketInfo& pacing_info);
106   void UpdateRtpStats(const RtpPacketToSend& packet)
107       RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_);
108 
109   const uint32_t ssrc_;
110   const absl::optional<uint32_t> rtx_ssrc_;
111   const absl::optional<uint32_t> flexfec_ssrc_;
112   const bool populate_network2_timestamp_;
113   Clock* const clock_;
114   RtpPacketHistory* const packet_history_;
115   Transport* const transport_;
116   RtcEventLog* const event_log_;
117   const bool is_audio_;
118   const bool need_rtp_packet_infos_;
119 
120   TransportFeedbackObserver* const transport_feedback_observer_;
121   SendSideDelayObserver* const send_side_delay_observer_;
122   SendPacketObserver* const send_packet_observer_;
123   StreamDataCountersCallback* const rtp_stats_callback_;
124   BitrateStatisticsObserver* const bitrate_callback_;
125 
126   mutable Mutex lock_;
127   bool media_has_been_sent_ RTC_GUARDED_BY(lock_);
128   bool force_part_of_allocation_ RTC_GUARDED_BY(lock_);
129   uint32_t timestamp_offset_ RTC_GUARDED_BY(lock_);
130 
131   SendDelayMap send_delays_ RTC_GUARDED_BY(lock_);
132   SendDelayMap::const_iterator max_delay_it_ RTC_GUARDED_BY(lock_);
133   // The sum of delays over a kSendSideDelayWindowMs sliding window.
134   int64_t sum_delays_ms_ RTC_GUARDED_BY(lock_);
135   StreamDataCounters rtp_stats_ RTC_GUARDED_BY(lock_);
136   StreamDataCounters rtx_rtp_stats_ RTC_GUARDED_BY(lock_);
137   // One element per value in RtpPacketMediaType, with index matching value.
138   std::vector<RateStatistics> send_rates_ RTC_GUARDED_BY(lock_);
139 
140   // Maps sent packets' sequence numbers to a tuple consisting of:
141   // 1. The timestamp, without the randomizing offset mandated by the RFC.
142   // 2. Whether the packet was the first in its frame.
143   // 3. Whether the packet was the last in its frame.
144   const std::unique_ptr<RtpSequenceNumberMap> rtp_sequence_number_map_
145       RTC_GUARDED_BY(lock_);
146 };
147 
148 }  // namespace webrtc
149 
150 #endif  // MODULES_RTP_RTCP_SOURCE_DEPRECATED_DEPRECATED_RTP_SENDER_EGRESS_H_
151