blob: 0f42d0fb82ef8bf382166c344f506500d638bb75 [file] [log] [blame]
Fredrik Solenberg04f49312015-06-08 13:04:56 +02001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef CALL_AUDIO_SEND_STREAM_H_
12#define CALL_AUDIO_SEND_STREAM_H_
Fredrik Solenberg04f49312015-06-08 13:04:56 +020013
kwibergbfefb032016-05-01 14:53:46 -070014#include <memory>
Fredrik Solenberg04f49312015-06-08 13:04:56 +020015#include <string>
16#include <vector>
17
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020018#include "absl/types/optional.h"
Karl Wiberg77490b92018-03-21 15:18:42 +010019#include "api/audio_codecs/audio_codec_pair_id.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#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 Anton10542f22019-01-11 09:11:00 -080024#include "api/crypto/crypto_options.h"
25#include "api/crypto/frame_encryptor_interface.h"
Marina Ciocead2aa8f92020-03-31 11:29:56 +020026#include "api/frame_transformer_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "api/rtp_parameters.h"
Florent Castelliacabb362022-10-18 17:05:16 +020028#include "api/rtp_sender_interface.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010029#include "api/scoped_refptr.h"
Tim Nab8c775a2020-01-10 10:33:05 -080030#include "call/audio_sender.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "call/rtp_config.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010032#include "modules/audio_processing/include/audio_processing_statistics.h"
Henrik Boström6e436d12019-05-27 12:19:33 +020033#include "modules/rtp_rtcp/include/report_block_data.h"
Fredrik Solenberg04f49312015-06-08 13:04:56 +020034
35namespace webrtc {
36
Tim Nab8c775a2020-01-10 10:33:05 -080037class AudioSendStream : public AudioSender {
Fredrik Solenberg04f49312015-06-08 13:04:56 +020038 public:
solenberg85a04962015-10-27 03:35:21 -070039 struct Stats {
solenberg940b6d62016-10-25 11:19:07 -070040 Stats();
hbos1acfbd22016-11-17 23:43:29 -080041 ~Stats();
solenberg940b6d62016-10-25 11:19:07 -070042
solenberg85a04962015-10-27 03:35:21 -070043 // TODO(solenberg): Harmonize naming and defaults with receive stream stats.
44 uint32_t local_ssrc = 0;
Niels Möllerac0a4cb2019-10-09 15:01:33 +020045 int64_t payload_bytes_sent = 0;
46 int64_t header_and_padding_bytes_sent = 0;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +020047 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent
48 uint64_t retransmitted_bytes_sent = 0;
solenberg85a04962015-10-27 03:35:21 -070049 int32_t packets_sent = 0;
Henrik Boströmaebba7b2022-10-26 16:53:03 +020050 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalpacketsenddelay
51 TimeDelta total_packet_send_delay = TimeDelta::Zero();
Henrik Boströmcf96e0f2019-04-17 13:51:53 +020052 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent
53 uint64_t retransmitted_packets_sent = 0;
solenberg85a04962015-10-27 03:35:21 -070054 int32_t packets_lost = -1;
55 float fraction_lost = -1.0f;
56 std::string codec_name;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020057 absl::optional<int> codec_payload_type;
solenberg85a04962015-10-27 03:35:21 -070058 int32_t jitter_ms = -1;
59 int64_t rtt_ms = -1;
Henrik Boströmd2c336f2019-07-03 17:11:10 +020060 int16_t audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -070061 // See description of "totalAudioEnergy" in the WebRTC stats spec:
62 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
63 double total_input_energy = 0.0;
64 double total_input_duration = 0.0;
Ivo Creusen56d46092017-11-24 17:29:59 +010065
ivoce1198e02017-09-08 08:13:19 -070066 ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +010067 AudioProcessingStats apm_statistics;
Sebastian Jansson359d60a2018-10-25 16:22:02 +020068
69 int64_t target_bitrate_bps = 0;
Henrik Boström6e436d12019-05-27 12:19:33 +020070 // A snapshot of Report Blocks with additional data of interest to
71 // statistics. Within this list, the sender-source SSRC pair is unique and
72 // per-pair the ReportBlockData represents the latest Report Block that was
73 // received for that pair.
74 std::vector<ReportBlockData> report_block_datas;
Jakob Ivarssone91c9922021-07-06 09:55:43 +020075 uint32_t nacks_rcvd = 0;
solenberg85a04962015-10-27 03:35:21 -070076 };
Fredrik Solenberg04f49312015-06-08 13:04:56 +020077
78 struct Config {
solenberg4fbae2b2015-08-28 04:07:10 -070079 Config() = delete;
solenberg940b6d62016-10-25 11:19:07 -070080 explicit Config(Transport* send_transport);
minyue6b825df2016-10-31 04:08:32 -070081 ~Config();
Fredrik Solenberg04f49312015-06-08 13:04:56 +020082 std::string ToString() const;
83
solenberg971cab02016-06-14 10:02:41 -070084 // Send-stream specific RTP settings.
Fredrik Solenberg04f49312015-06-08 13:04:56 +020085 struct Rtp {
solenberg940b6d62016-10-25 11:19:07 -070086 Rtp();
87 ~Rtp();
Fredrik Solenberg04f49312015-06-08 13:04:56 +020088 std::string ToString() const;
89
90 // Sender SSRC.
91 uint32_t ssrc = 0;
92
Amit Hilbuch77938e62018-12-21 09:23:38 -080093 // The value to send in the RID RTP header extension if the extension is
94 // included in the list of extensions.
95 std::string rid;
96
Steve Antonbb50ce52018-03-26 10:24:32 -070097 // The value to send in the MID RTP header extension if the extension is
98 // included in the list of extensions.
99 std::string mid;
100
Johannes Kron9190b822018-10-29 11:22:05 +0100101 // Corresponds to the SDP attribute extmap-allow-mixed.
102 bool extmap_allow_mixed = false;
103
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100104 // RTP header extensions used for the sent stream.
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200105 std::vector<RtpExtension> extensions;
solenberg3a941542015-11-16 07:34:50 -0800106
107 // RTCP CNAME, see RFC 3550.
108 std::string c_name;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200109 } rtp;
110
Jiawei Ou55718122018-11-09 13:17:39 -0800111 // Time interval between RTCP report for audio
112 int rtcp_report_interval_ms = 5000;
113
solenbergc7a8b082015-10-16 14:35:07 -0700114 // Transport for outgoing packets. The transport is expected to exist for
115 // the entire life of the AudioSendStream and is owned by the API client.
pbos2d566682015-09-28 09:59:31 -0700116 Transport* send_transport = nullptr;
solenberg4fbae2b2015-08-28 04:07:10 -0700117
mflodman86cc6ff2016-07-26 04:44:06 -0700118 // Bitrate limits used for variable audio bitrate streams. Set both to -1 to
119 // disable audio bitrate adaptation.
120 // Note: This is still an experimental feature and not ready for real usage.
minyue10cbb462016-11-07 09:29:22 -0800121 int min_bitrate_bps = -1;
122 int max_bitrate_bps = -1;
minyue7a973442016-10-20 03:27:12 -0700123
Seth Hampson24722b32017-12-22 09:36:42 -0800124 double bitrate_priority = 1.0;
Tim Haloun648d28a2018-10-18 16:52:22 -0700125 bool has_dscp = false;
Seth Hampson24722b32017-12-22 09:36:42 -0800126
minyue6b825df2016-10-31 04:08:32 -0700127 // Defines whether to turn on audio network adaptor, and defines its config
128 // string.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200129 absl::optional<std::string> audio_network_adaptor_config;
minyue6b825df2016-10-31 04:08:32 -0700130
minyue7a973442016-10-20 03:27:12 -0700131 struct SendCodecSpec {
ossu20a4b3f2017-04-27 02:08:52 -0700132 SendCodecSpec(int payload_type, const SdpAudioFormat& format);
133 ~SendCodecSpec();
solenberg940b6d62016-10-25 11:19:07 -0700134 std::string ToString() const;
135
136 bool operator==(const SendCodecSpec& rhs) const;
minyue7a973442016-10-20 03:27:12 -0700137 bool operator!=(const SendCodecSpec& rhs) const {
138 return !(*this == rhs);
139 }
140
ossu20a4b3f2017-04-27 02:08:52 -0700141 int payload_type;
142 SdpAudioFormat format;
minyue7a973442016-10-20 03:27:12 -0700143 bool nack_enabled = false;
144 bool transport_cc_enabled = false;
Ivo Creusen2562cf02021-09-03 14:51:22 +0000145 bool enable_non_sender_rtt = false;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200146 absl::optional<int> cng_payload_type;
Philipp Hanckeedcd9662020-06-24 12:52:42 +0200147 absl::optional<int> red_payload_type;
ossu20a4b3f2017-04-27 02:08:52 -0700148 // If unset, use the encoder's default target bitrate.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200149 absl::optional<int> target_bitrate_bps;
ossu20a4b3f2017-04-27 02:08:52 -0700150 };
151
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200152 absl::optional<SendCodecSpec> send_codec_spec;
ossu20a4b3f2017-04-27 02:08:52 -0700153 rtc::scoped_refptr<AudioEncoderFactory> encoder_factory;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200154 absl::optional<AudioCodecPairId> codec_pair_id;
Alex Narestb3944f02017-10-13 14:56:18 +0200155
156 // Track ID as specified during track creation.
157 std::string track_id;
Benjamin Wright84583f62018-10-04 14:22:34 -0700158
Benjamin Wrightbfb444c2018-10-15 10:20:24 -0700159 // Per PeerConnection crypto options.
160 webrtc::CryptoOptions crypto_options;
161
Benjamin Wright84583f62018-10-04 14:22:34 -0700162 // An optional custom frame encryptor that allows the entire frame to be
163 // encryptor in whatever way the caller choses. This is not required by
164 // default.
165 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor;
Marina Ciocead2aa8f92020-03-31 11:29:56 +0200166
167 // An optional frame transformer used by insertable streams to transform
168 // encoded frames.
169 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200170 };
171
eladalonabbc4302017-07-26 02:09:44 -0700172 virtual ~AudioSendStream() = default;
173
174 virtual const webrtc::AudioSendStream::Config& GetConfig() const = 0;
175
ossu20a4b3f2017-04-27 02:08:52 -0700176 // Reconfigure the stream according to the Configuration.
Florent Castelliacabb362022-10-18 17:05:16 +0200177 virtual void Reconfigure(const Config& config,
178 SetParametersCallback callback) = 0;
ossu20a4b3f2017-04-27 02:08:52 -0700179
pbos1ba8d392016-05-01 20:18:34 -0700180 // Starts stream activity.
181 // When a stream is active, it can receive, process and deliver packets.
182 virtual void Start() = 0;
183 // Stops stream activity.
184 // When a stream is stopped, it can't receive, process or deliver packets.
185 virtual void Stop() = 0;
186
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100187 // TODO(solenberg): Make payload_type a config property instead.
Yves Gerey665174f2018-06-19 15:03:05 +0200188 virtual bool SendTelephoneEvent(int payload_type,
189 int payload_frequency,
190 int event,
191 int duration_ms) = 0;
solenberg94218532016-06-16 10:53:22 -0700192
193 virtual void SetMuted(bool muted) = 0;
194
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200195 virtual Stats GetStats() const = 0;
Ivo Creusen56d46092017-11-24 17:29:59 +0100196 virtual Stats GetStats(bool has_remote_tracks) const = 0;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200197};
Tim Nab8c775a2020-01-10 10:33:05 -0800198
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200199} // namespace webrtc
200
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200201#endif // CALL_AUDIO_SEND_STREAM_H_