audio_send_stream.h (7596B)
1 /* 2 * Copyright (c) 2015 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_AUDIO_SEND_STREAM_H_ 12 #define CALL_AUDIO_SEND_STREAM_H_ 13 14 #include <cstdint> 15 #include <optional> 16 #include <string> 17 #include <vector> 18 19 #include "api/audio/audio_processing_statistics.h" 20 #include "api/audio_codecs/audio_codec_pair_id.h" 21 #include "api/audio_codecs/audio_encoder.h" 22 #include "api/audio_codecs/audio_encoder_factory.h" 23 #include "api/audio_codecs/audio_format.h" 24 #include "api/call/transport.h" 25 #include "api/crypto/crypto_options.h" 26 #include "api/crypto/frame_encryptor_interface.h" 27 #include "api/frame_transformer_interface.h" 28 #include "api/rtp_headers.h" 29 #include "api/rtp_parameters.h" 30 #include "api/rtp_sender_setparameters_callback.h" 31 #include "api/scoped_refptr.h" 32 #include "api/units/time_delta.h" 33 #include "call/audio_sender.h" 34 #include "modules/rtp_rtcp/include/report_block_data.h" 35 #include "modules/rtp_rtcp/include/rtcp_statistics.h" 36 37 namespace webrtc { 38 39 class AudioSendStream : public AudioSender { 40 public: 41 struct Stats { 42 Stats(); 43 ~Stats(); 44 45 // TODO(solenberg): Harmonize naming and defaults with receive stream stats. 46 uint32_t local_ssrc = 0; 47 int64_t payload_bytes_sent = 0; 48 int64_t header_and_padding_bytes_sent = 0; 49 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent 50 uint64_t retransmitted_bytes_sent = 0; 51 int32_t packets_sent = 0; 52 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-packetssentwithect1 53 int32_t packets_sent_with_ect1 = 0; 54 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalpacketsenddelay 55 TimeDelta total_packet_send_delay = TimeDelta::Zero(); 56 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent 57 uint64_t retransmitted_packets_sent = 0; 58 int32_t packets_lost = -1; 59 float fraction_lost = -1.0f; 60 std::string codec_name; 61 std::optional<int> codec_payload_type; 62 int32_t jitter_ms = -1; 63 int64_t rtt_ms = -1; 64 int16_t audio_level = 0; 65 // See description of "totalAudioEnergy" in the WebRTC stats spec: 66 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy 67 double total_input_energy = 0.0; 68 double total_input_duration = 0.0; 69 70 ANAStats ana_statistics; 71 AudioProcessingStats apm_statistics; 72 RtcpPacketTypeCounter rtcp_packet_type_counts; 73 74 int64_t target_bitrate_bps = 0; 75 // A snapshot of Report Blocks with additional data of interest to 76 // statistics. Within this list, the sender-source SSRC pair is unique and 77 // per-pair the ReportBlockData represents the latest Report Block that was 78 // received for that pair. 79 std::vector<ReportBlockData> report_block_datas; 80 uint32_t nacks_received = 0; 81 }; 82 83 struct Config { 84 Config() = delete; 85 explicit Config(Transport* send_transport); 86 ~Config(); 87 std::string ToString() const; 88 89 // Send-stream specific RTP settings. 90 struct Rtp { 91 Rtp(); 92 ~Rtp(); 93 std::string ToString() const; 94 95 // Sender SSRC. 96 uint32_t ssrc = 0; 97 98 // The value to send in the RID RTP header extension if the extension is 99 // included in the list of extensions. 100 std::string rid; 101 102 // The value to send in the MID RTP header extension if the extension is 103 // included in the list of extensions. 104 std::string mid; 105 106 // The list of CSRCs to be included in the RTP header. 107 std::vector<uint32_t> csrcs; 108 109 // Corresponds to the SDP attribute extmap-allow-mixed. 110 bool extmap_allow_mixed = false; 111 112 // RTP header extensions used for the sent stream. 113 std::vector<RtpExtension> extensions; 114 115 // RTCP CNAME, see RFC 3550. 116 std::string c_name; 117 118 // Compound or reduced size RTCP. 119 RtcpMode rtcp_mode = RtcpMode::kCompound; 120 } rtp; 121 122 // Time interval between RTCP report for audio 123 int rtcp_report_interval_ms = 5000; 124 125 // Transport for outgoing packets. The transport is expected to exist for 126 // the entire life of the AudioSendStream and is owned by the API client. 127 Transport* send_transport = nullptr; 128 129 // Bitrate limits used for variable audio bitrate streams. Set both to -1 to 130 // disable audio bitrate adaptation. 131 // Note: This is still an experimental feature and not ready for real usage. 132 int min_bitrate_bps = -1; 133 int max_bitrate_bps = -1; 134 135 double bitrate_priority = 1.0; 136 bool has_dscp = false; 137 // If true, the stream will allocate bandwidth from the bandwidth estimate 138 // created by the congestion controller. 139 bool include_in_congestion_control_allocation = false; 140 141 // Defines whether to turn on audio network adaptor, and defines its config 142 // string. 143 std::optional<std::string> audio_network_adaptor_config; 144 145 struct SendCodecSpec { 146 SendCodecSpec(int payload_type, const SdpAudioFormat& format); 147 ~SendCodecSpec(); 148 std::string ToString() const; 149 150 bool operator==(const SendCodecSpec& rhs) const; 151 bool operator!=(const SendCodecSpec& rhs) const { 152 return !(*this == rhs); 153 } 154 155 int payload_type; 156 SdpAudioFormat format; 157 bool nack_enabled = false; 158 bool enable_non_sender_rtt = false; 159 std::optional<int> cng_payload_type; 160 std::optional<int> red_payload_type; 161 // If unset, use the encoder's default target bitrate. 162 std::optional<int> target_bitrate_bps; 163 }; 164 165 std::optional<SendCodecSpec> send_codec_spec; 166 scoped_refptr<AudioEncoderFactory> encoder_factory; 167 std::optional<AudioCodecPairId> codec_pair_id; 168 169 // Track ID as specified during track creation. 170 std::string track_id; 171 172 // Per PeerConnection crypto options. 173 webrtc::CryptoOptions crypto_options; 174 175 // An optional custom frame encryptor that allows the entire frame to be 176 // encryptor in whatever way the caller choses. This is not required by 177 // default. 178 scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor; 179 180 // An optional frame transformer used by insertable streams to transform 181 // encoded frames. 182 scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer; 183 }; 184 185 virtual ~AudioSendStream() = default; 186 187 virtual const webrtc::AudioSendStream::Config& GetConfig() const = 0; 188 189 // Reconfigure the stream according to the Configuration. 190 virtual void Reconfigure(const Config& config, 191 SetParametersCallback callback) = 0; 192 193 // Starts stream activity. 194 // When a stream is active, it can receive, process and deliver packets. 195 virtual void Start() = 0; 196 // Stops stream activity. 197 // When a stream is stopped, it can't receive, process or deliver packets. 198 virtual void Stop() = 0; 199 200 // TODO(solenberg): Make payload_type a config property instead. 201 virtual bool SendTelephoneEvent(int payload_type, 202 int payload_frequency, 203 int event, 204 int duration_ms) = 0; 205 206 virtual void SetMuted(bool muted) = 0; 207 208 virtual Stats GetStats() const = 0; 209 virtual Stats GetStats(bool has_remote_tracks) const = 0; 210 }; 211 212 } // namespace webrtc 213 214 #endif // CALL_AUDIO_SEND_STREAM_H_