xref: /aosp_15_r20/external/webrtc/call/rtp_transport_controller_send_interface.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 CALL_RTP_TRANSPORT_CONTROLLER_SEND_INTERFACE_H_
12 #define CALL_RTP_TRANSPORT_CONTROLLER_SEND_INTERFACE_H_
13 #include <stddef.h>
14 #include <stdint.h>
15 
16 #include <map>
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 #include "absl/strings/string_view.h"
22 #include "absl/types/optional.h"
23 #include "api/crypto/crypto_options.h"
24 #include "api/fec_controller.h"
25 #include "api/frame_transformer_interface.h"
26 #include "api/rtc_event_log/rtc_event_log.h"
27 #include "api/transport/bitrate_settings.h"
28 #include "api/units/timestamp.h"
29 #include "call/rtp_config.h"
30 #include "common_video/frame_counts.h"
31 #include "modules/rtp_rtcp/include/report_block_data.h"
32 #include "modules/rtp_rtcp/include/rtcp_statistics.h"
33 #include "modules/rtp_rtcp/include/rtp_packet_sender.h"
34 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
35 #include "modules/rtp_rtcp/source/rtp_packet_received.h"
36 
37 namespace rtc {
38 struct SentPacket;
39 struct NetworkRoute;
40 class TaskQueue;
41 }  // namespace rtc
42 namespace webrtc {
43 
44 class FrameEncryptorInterface;
45 class MaybeWorkerThread;
46 class TargetTransferRateObserver;
47 class Transport;
48 class PacketRouter;
49 class RtpVideoSenderInterface;
50 class RtcpBandwidthObserver;
51 class RtpPacketSender;
52 
53 struct RtpSenderObservers {
54   RtcpRttStats* rtcp_rtt_stats;
55   RtcpIntraFrameObserver* intra_frame_callback;
56   RtcpLossNotificationObserver* rtcp_loss_notification_observer;
57   ReportBlockDataObserver* report_block_data_observer;
58   StreamDataCountersCallback* rtp_stats;
59   BitrateStatisticsObserver* bitrate_observer;
60   FrameCountObserver* frame_count_observer;
61   RtcpPacketTypeCounterObserver* rtcp_type_observer;
62   SendSideDelayObserver* send_delay_observer;
63   SendPacketObserver* send_packet_observer;
64 };
65 
66 struct RtpSenderFrameEncryptionConfig {
67   FrameEncryptorInterface* frame_encryptor = nullptr;
68   CryptoOptions crypto_options;
69 };
70 
71 // An RtpTransportController should own everything related to the RTP
72 // transport to/from a remote endpoint. We should have separate
73 // interfaces for send and receive side, even if they are implemented
74 // by the same class. This is an ongoing refactoring project. At some
75 // point, this class should be promoted to a public api under
76 // webrtc/api/rtp/.
77 //
78 // For a start, this object is just a collection of the objects needed
79 // by the VideoSendStream constructor. The plan is to move ownership
80 // of all RTP-related objects here, and add methods to create per-ssrc
81 // objects which would then be passed to VideoSendStream. Eventually,
82 // direct accessors like packet_router() should be removed.
83 //
84 // This should also have a reference to the underlying
85 // webrtc::Transport(s). Currently, webrtc::Transport is implemented by
86 // WebRtcVideoChannel and WebRtcVoiceMediaChannel, and owned by
87 // WebrtcSession. Video and audio always uses different transport
88 // objects, even in the common case where they are bundled over the
89 // same underlying transport.
90 //
91 // Extracting the logic of the webrtc::Transport from BaseChannel and
92 // subclasses into a separate class seems to be a prerequesite for
93 // moving the transport here.
94 class RtpTransportControllerSendInterface {
95  public:
~RtpTransportControllerSendInterface()96   virtual ~RtpTransportControllerSendInterface() {}
97   // TODO(webrtc:14502): Remove MaybeWorkerThread when experiment has been
98   // evaluated.
99   virtual MaybeWorkerThread* GetWorkerQueue() = 0;
100   virtual PacketRouter* packet_router() = 0;
101 
102   virtual RtpVideoSenderInterface* CreateRtpVideoSender(
103       const std::map<uint32_t, RtpState>& suspended_ssrcs,
104       // TODO(holmer): Move states into RtpTransportControllerSend.
105       const std::map<uint32_t, RtpPayloadState>& states,
106       const RtpConfig& rtp_config,
107       int rtcp_report_interval_ms,
108       Transport* send_transport,
109       const RtpSenderObservers& observers,
110       RtcEventLog* event_log,
111       std::unique_ptr<FecController> fec_controller,
112       const RtpSenderFrameEncryptionConfig& frame_encryption_config,
113       rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) = 0;
114   virtual void DestroyRtpVideoSender(
115       RtpVideoSenderInterface* rtp_video_sender) = 0;
116 
117   virtual NetworkStateEstimateObserver* network_state_estimate_observer() = 0;
118   virtual TransportFeedbackObserver* transport_feedback_observer() = 0;
119 
120   virtual RtpPacketSender* packet_sender() = 0;
121 
122   // SetAllocatedSendBitrateLimits sets bitrates limits imposed by send codec
123   // settings.
124   virtual void SetAllocatedSendBitrateLimits(
125       BitrateAllocationLimits limits) = 0;
126 
127   virtual void SetPacingFactor(float pacing_factor) = 0;
128   virtual void SetQueueTimeLimit(int limit_ms) = 0;
129 
130   virtual StreamFeedbackProvider* GetStreamFeedbackProvider() = 0;
131   virtual void RegisterTargetTransferRateObserver(
132       TargetTransferRateObserver* observer) = 0;
133   virtual void OnNetworkRouteChanged(
134       absl::string_view transport_name,
135       const rtc::NetworkRoute& network_route) = 0;
136   virtual void OnNetworkAvailability(bool network_available) = 0;
137   virtual RtcpBandwidthObserver* GetBandwidthObserver() = 0;
138   virtual int64_t GetPacerQueuingDelayMs() const = 0;
139   virtual absl::optional<Timestamp> GetFirstPacketTime() const = 0;
140   virtual void EnablePeriodicAlrProbing(bool enable) = 0;
141 
142   // Called when a packet has been sent.
143   // The call should arrive on the network thread, but may not in all cases
144   // (some tests don't adhere to this). Implementations today should not block
145   // the calling thread or make assumptions about the thread context.
146   virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
147 
148   virtual void OnReceivedPacket(const ReceivedPacket& received_packet) = 0;
149 
150   virtual void SetSdpBitrateParameters(
151       const BitrateConstraints& constraints) = 0;
152   virtual void SetClientBitratePreferences(
153       const BitrateSettings& preferences) = 0;
154 
155   virtual void OnTransportOverheadChanged(
156       size_t transport_overhead_per_packet) = 0;
157 
158   virtual void AccountForAudioPacketsInPacedSender(bool account_for_audio) = 0;
159   virtual void IncludeOverheadInPacedSender() = 0;
160 
161   virtual void EnsureStarted() = 0;
162 };
163 
164 }  // namespace webrtc
165 
166 #endif  // CALL_RTP_TRANSPORT_CONTROLLER_SEND_INTERFACE_H_
167