Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef CALL_AUDIO_SEND_STREAM_H_ |
| 12 | #define CALL_AUDIO_SEND_STREAM_H_ |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 13 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 14 | #include <memory> |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 18 | #include "absl/types/optional.h" |
Karl Wiberg | 77490b9 | 2018-03-21 15:18:42 +0100 | [diff] [blame] | 19 | #include "api/audio_codecs/audio_codec_pair_id.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "api/audio_codecs/audio_encoder.h" |
| 21 | #include "api/audio_codecs/audio_encoder_factory.h" |
| 22 | #include "api/audio_codecs/audio_format.h" |
| 23 | #include "api/call/transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 24 | #include "api/crypto/crypto_options.h" |
| 25 | #include "api/crypto/frame_encryptor_interface.h" |
Marina Ciocea | d2aa8f9 | 2020-03-31 11:29:56 +0200 | [diff] [blame] | 26 | #include "api/frame_transformer_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 27 | #include "api/rtp_parameters.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 28 | #include "api/scoped_refptr.h" |
Tim Na | b8c775a | 2020-01-10 10:33:05 -0800 | [diff] [blame] | 29 | #include "call/audio_sender.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "call/rtp_config.h" |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 31 | #include "modules/audio_processing/include/audio_processing_statistics.h" |
Henrik Boström | 6e436d1 | 2019-05-27 12:19:33 +0200 | [diff] [blame] | 32 | #include "modules/rtp_rtcp/include/report_block_data.h" |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 33 | |
| 34 | namespace webrtc { |
| 35 | |
Tim Na | b8c775a | 2020-01-10 10:33:05 -0800 | [diff] [blame] | 36 | class AudioSendStream : public AudioSender { |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 37 | public: |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 38 | struct Stats { |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 39 | Stats(); |
hbos | 1acfbd2 | 2016-11-17 23:43:29 -0800 | [diff] [blame] | 40 | ~Stats(); |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 41 | |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 42 | // TODO(solenberg): Harmonize naming and defaults with receive stream stats. |
| 43 | uint32_t local_ssrc = 0; |
Niels Möller | ac0a4cb | 2019-10-09 15:01:33 +0200 | [diff] [blame] | 44 | int64_t payload_bytes_sent = 0; |
| 45 | int64_t header_and_padding_bytes_sent = 0; |
Henrik Boström | cf96e0f | 2019-04-17 13:51:53 +0200 | [diff] [blame] | 46 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent |
| 47 | uint64_t retransmitted_bytes_sent = 0; |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 48 | int32_t packets_sent = 0; |
Henrik Boström | cf96e0f | 2019-04-17 13:51:53 +0200 | [diff] [blame] | 49 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent |
| 50 | uint64_t retransmitted_packets_sent = 0; |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 51 | int32_t packets_lost = -1; |
| 52 | float fraction_lost = -1.0f; |
| 53 | std::string codec_name; |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 54 | absl::optional<int> codec_payload_type; |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 55 | int32_t jitter_ms = -1; |
| 56 | int64_t rtt_ms = -1; |
Henrik Boström | d2c336f | 2019-07-03 17:11:10 +0200 | [diff] [blame] | 57 | int16_t audio_level = 0; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 58 | // See description of "totalAudioEnergy" in the WebRTC stats spec: |
| 59 | // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy |
| 60 | double total_input_energy = 0.0; |
| 61 | double total_input_duration = 0.0; |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 62 | bool typing_noise_detected = false; |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 63 | |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 64 | ANAStats ana_statistics; |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 65 | AudioProcessingStats apm_statistics; |
Sebastian Jansson | 359d60a | 2018-10-25 16:22:02 +0200 | [diff] [blame] | 66 | |
| 67 | int64_t target_bitrate_bps = 0; |
Henrik Boström | 6e436d1 | 2019-05-27 12:19:33 +0200 | [diff] [blame] | 68 | // A snapshot of Report Blocks with additional data of interest to |
| 69 | // statistics. Within this list, the sender-source SSRC pair is unique and |
| 70 | // per-pair the ReportBlockData represents the latest Report Block that was |
| 71 | // received for that pair. |
| 72 | std::vector<ReportBlockData> report_block_datas; |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 73 | }; |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 74 | |
| 75 | struct Config { |
solenberg | 4fbae2b | 2015-08-28 04:07:10 -0700 | [diff] [blame] | 76 | Config() = delete; |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 77 | explicit Config(Transport* send_transport); |
minyue | 6b825df | 2016-10-31 04:08:32 -0700 | [diff] [blame] | 78 | ~Config(); |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 79 | std::string ToString() const; |
| 80 | |
solenberg | 971cab0 | 2016-06-14 10:02:41 -0700 | [diff] [blame] | 81 | // Send-stream specific RTP settings. |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 82 | struct Rtp { |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 83 | Rtp(); |
| 84 | ~Rtp(); |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 85 | std::string ToString() const; |
| 86 | |
| 87 | // Sender SSRC. |
| 88 | uint32_t ssrc = 0; |
| 89 | |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 90 | // The value to send in the RID RTP header extension if the extension is |
| 91 | // included in the list of extensions. |
| 92 | std::string rid; |
| 93 | |
Steve Anton | bb50ce5 | 2018-03-26 10:24:32 -0700 | [diff] [blame] | 94 | // The value to send in the MID RTP header extension if the extension is |
| 95 | // included in the list of extensions. |
| 96 | std::string mid; |
| 97 | |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 98 | // Corresponds to the SDP attribute extmap-allow-mixed. |
| 99 | bool extmap_allow_mixed = false; |
| 100 | |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 101 | // RTP header extensions used for the sent stream. |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 102 | std::vector<RtpExtension> extensions; |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 103 | |
| 104 | // RTCP CNAME, see RFC 3550. |
| 105 | std::string c_name; |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 106 | } rtp; |
| 107 | |
Jiawei Ou | 5571812 | 2018-11-09 13:17:39 -0800 | [diff] [blame] | 108 | // Time interval between RTCP report for audio |
| 109 | int rtcp_report_interval_ms = 5000; |
| 110 | |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 111 | // Transport for outgoing packets. The transport is expected to exist for |
| 112 | // the entire life of the AudioSendStream and is owned by the API client. |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 113 | Transport* send_transport = nullptr; |
solenberg | 4fbae2b | 2015-08-28 04:07:10 -0700 | [diff] [blame] | 114 | |
mflodman | 86cc6ff | 2016-07-26 04:44:06 -0700 | [diff] [blame] | 115 | // Bitrate limits used for variable audio bitrate streams. Set both to -1 to |
| 116 | // disable audio bitrate adaptation. |
| 117 | // Note: This is still an experimental feature and not ready for real usage. |
minyue | 10cbb46 | 2016-11-07 09:29:22 -0800 | [diff] [blame] | 118 | int min_bitrate_bps = -1; |
| 119 | int max_bitrate_bps = -1; |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 120 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 121 | double bitrate_priority = 1.0; |
Tim Haloun | 648d28a | 2018-10-18 16:52:22 -0700 | [diff] [blame] | 122 | bool has_dscp = false; |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 123 | |
minyue | 6b825df | 2016-10-31 04:08:32 -0700 | [diff] [blame] | 124 | // Defines whether to turn on audio network adaptor, and defines its config |
| 125 | // string. |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 126 | absl::optional<std::string> audio_network_adaptor_config; |
minyue | 6b825df | 2016-10-31 04:08:32 -0700 | [diff] [blame] | 127 | |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 128 | struct SendCodecSpec { |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 129 | SendCodecSpec(int payload_type, const SdpAudioFormat& format); |
| 130 | ~SendCodecSpec(); |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 131 | std::string ToString() const; |
| 132 | |
| 133 | bool operator==(const SendCodecSpec& rhs) const; |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 134 | bool operator!=(const SendCodecSpec& rhs) const { |
| 135 | return !(*this == rhs); |
| 136 | } |
| 137 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 138 | int payload_type; |
| 139 | SdpAudioFormat format; |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 140 | bool nack_enabled = false; |
| 141 | bool transport_cc_enabled = false; |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 142 | absl::optional<int> cng_payload_type; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 143 | // If unset, use the encoder's default target bitrate. |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 144 | absl::optional<int> target_bitrate_bps; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 147 | absl::optional<SendCodecSpec> send_codec_spec; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 148 | rtc::scoped_refptr<AudioEncoderFactory> encoder_factory; |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 149 | absl::optional<AudioCodecPairId> codec_pair_id; |
Alex Narest | b3944f0 | 2017-10-13 14:56:18 +0200 | [diff] [blame] | 150 | |
| 151 | // Track ID as specified during track creation. |
| 152 | std::string track_id; |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 153 | |
Benjamin Wright | bfb444c | 2018-10-15 10:20:24 -0700 | [diff] [blame] | 154 | // Per PeerConnection crypto options. |
| 155 | webrtc::CryptoOptions crypto_options; |
| 156 | |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 157 | // An optional custom frame encryptor that allows the entire frame to be |
| 158 | // encryptor in whatever way the caller choses. This is not required by |
| 159 | // default. |
| 160 | rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor; |
Marina Ciocea | d2aa8f9 | 2020-03-31 11:29:56 +0200 | [diff] [blame] | 161 | |
| 162 | // An optional frame transformer used by insertable streams to transform |
| 163 | // encoded frames. |
| 164 | rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer; |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 165 | }; |
| 166 | |
eladalon | abbc430 | 2017-07-26 02:09:44 -0700 | [diff] [blame] | 167 | virtual ~AudioSendStream() = default; |
| 168 | |
| 169 | virtual const webrtc::AudioSendStream::Config& GetConfig() const = 0; |
| 170 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 171 | // Reconfigure the stream according to the Configuration. |
| 172 | virtual void Reconfigure(const Config& config) = 0; |
| 173 | |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 174 | // Starts stream activity. |
| 175 | // When a stream is active, it can receive, process and deliver packets. |
| 176 | virtual void Start() = 0; |
| 177 | // Stops stream activity. |
| 178 | // When a stream is stopped, it can't receive, process or deliver packets. |
| 179 | virtual void Stop() = 0; |
| 180 | |
Fredrik Solenberg | b572768 | 2015-12-04 15:22:19 +0100 | [diff] [blame] | 181 | // TODO(solenberg): Make payload_type a config property instead. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 182 | virtual bool SendTelephoneEvent(int payload_type, |
| 183 | int payload_frequency, |
| 184 | int event, |
| 185 | int duration_ms) = 0; |
solenberg | 9421853 | 2016-06-16 10:53:22 -0700 | [diff] [blame] | 186 | |
| 187 | virtual void SetMuted(bool muted) = 0; |
| 188 | |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 189 | virtual Stats GetStats() const = 0; |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 190 | virtual Stats GetStats(bool has_remote_tracks) const = 0; |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 191 | }; |
Tim Na | b8c775a | 2020-01-10 10:33:05 -0800 | [diff] [blame] | 192 | |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 193 | } // namespace webrtc |
| 194 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 195 | #endif // CALL_AUDIO_SEND_STREAM_H_ |