channel_send.h (5592B)
1 /* 2 * Copyright (c) 2012 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 AUDIO_CHANNEL_SEND_H_ 12 #define AUDIO_CHANNEL_SEND_H_ 13 14 #include <cstddef> 15 #include <cstdint> 16 #include <memory> 17 #include <optional> 18 #include <vector> 19 20 #include "absl/strings/string_view.h" 21 #include "api/array_view.h" 22 #include "api/audio/audio_frame.h" 23 #include "api/audio_codecs/audio_encoder.h" 24 #include "api/audio_codecs/audio_format.h" 25 #include "api/call/bitrate_allocation.h" 26 #include "api/crypto/crypto_options.h" 27 #include "api/environment/environment.h" 28 #include "api/frame_transformer_interface.h" 29 #include "api/function_view.h" 30 #include "api/scoped_refptr.h" 31 #include "api/units/data_rate.h" 32 #include "api/units/time_delta.h" 33 #include "modules/rtp_rtcp/include/report_block_data.h" 34 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" 35 #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" 36 37 namespace webrtc { 38 39 class FrameEncryptorInterface; 40 class RtpTransportControllerSendInterface; 41 42 struct ChannelSendStatistics { 43 TimeDelta round_trip_time; 44 int64_t payload_bytes_sent; 45 int64_t header_and_padding_bytes_sent; 46 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent 47 uint64_t retransmitted_bytes_sent; 48 int packets_sent; 49 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-packetssentwithect1 50 int packets_sent_with_ect1; 51 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalpacketsenddelay 52 TimeDelta total_packet_send_delay = TimeDelta::Zero(); 53 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent 54 uint64_t retransmitted_packets_sent; 55 RtcpPacketTypeCounter rtcp_packet_type_counts; 56 // A snapshot of Report Blocks with additional data of interest to statistics. 57 // Within this list, the sender-source SSRC pair is unique and per-pair the 58 // ReportBlockData represents the latest Report Block that was received for 59 // that pair. 60 std::vector<ReportBlockData> report_block_datas; 61 uint32_t nacks_received; 62 }; 63 64 namespace voe { 65 66 class ChannelSendInterface { 67 public: 68 virtual ~ChannelSendInterface() = default; 69 70 virtual void ReceivedRTCPPacket(const uint8_t* packet, size_t length) = 0; 71 72 virtual ChannelSendStatistics GetRTCPStatistics() const = 0; 73 74 virtual void SetEncoder(int payload_type, 75 const SdpAudioFormat& encoder_format, 76 std::unique_ptr<AudioEncoder> encoder) = 0; 77 virtual void ModifyEncoder( 78 FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) = 0; 79 virtual void CallEncoder(FunctionView<void(AudioEncoder*)> modifier) = 0; 80 81 // Use 0 to indicate that the extension should not be registered. 82 virtual void SetRTCP_CNAME(absl::string_view c_name) = 0; 83 virtual void SetSendAudioLevelIndicationStatus(bool enable, int id) = 0; 84 virtual void RegisterSenderCongestionControlObjects( 85 RtpTransportControllerSendInterface* transport) = 0; 86 virtual void ResetSenderCongestionControlObjects() = 0; 87 virtual std::vector<ReportBlockData> GetRemoteRTCPReportBlocks() const = 0; 88 virtual ANAStats GetANAStatistics() const = 0; 89 virtual void RegisterCngPayloadType(int payload_type, 90 int payload_frequency) = 0; 91 virtual void SetSendTelephoneEventPayloadType(int payload_type, 92 int payload_frequency) = 0; 93 virtual bool SendTelephoneEventOutband(int event, int duration_ms) = 0; 94 virtual void OnBitrateAllocation(BitrateAllocationUpdate update) = 0; 95 virtual int GetTargetBitrate() const = 0; 96 virtual void SetInputMute(bool muted) = 0; 97 // Sets the list of CSRCs to be included in the RTP header. If more than 98 // kRtpCsrcSize CSRCs are provided, only the first kRtpCsrcSize elements are 99 // kept. 100 virtual void SetCsrcs(ArrayView<const uint32_t> csrcs) = 0; 101 102 virtual void ProcessAndEncodeAudio( 103 std::unique_ptr<AudioFrame> audio_frame) = 0; 104 virtual RtpRtcpInterface* GetRtpRtcp() const = 0; 105 106 virtual void StartSend() = 0; 107 virtual void StopSend() = 0; 108 109 // E2EE Custom Audio Frame Encryption (Optional) 110 virtual void SetFrameEncryptor( 111 scoped_refptr<FrameEncryptorInterface> frame_encryptor) = 0; 112 113 // Sets a frame transformer between encoder and packetizer, to transform 114 // encoded frames before sending them out the network. 115 virtual void SetEncoderToPacketizerFrameTransformer( 116 scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer) = 0; 117 118 // Returns payload bitrate actually used. 119 virtual std::optional<DataRate> GetUsedRate() const = 0; 120 121 // Registers per packet byte overhead. 122 virtual void RegisterPacketOverhead(int packet_byte_overhead) = 0; 123 }; 124 125 std::unique_ptr<ChannelSendInterface> CreateChannelSend( 126 const Environment& env, 127 Transport* rtp_transport, 128 RtcpRttStats* rtcp_rtt_stats, 129 FrameEncryptorInterface* frame_encryptor, 130 const webrtc::CryptoOptions& crypto_options, 131 bool extmap_allow_mixed, 132 int rtcp_report_interval_ms, 133 uint32_t ssrc, 134 scoped_refptr<FrameTransformerInterface> frame_transformer, 135 RtpTransportControllerSendInterface* transport_controller); 136 137 } // namespace voe 138 } // namespace webrtc 139 140 #endif // AUDIO_CHANNEL_SEND_H_