blob: 60909ae128ba7345f8265c73e68b759b9cf4ceab [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"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "api/rtpparameters.h"
25#include "call/rtp_config.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010026#include "modules/audio_processing/include/audio_processing_statistics.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "rtc_base/scoped_ref_ptr.h"
Fredrik Solenberg04f49312015-06-08 13:04:56 +020028
29namespace webrtc {
30
Fredrik Solenberg2a877972017-12-15 16:42:15 +010031class AudioFrame;
32
pbos1ba8d392016-05-01 20:18:34 -070033class AudioSendStream {
Fredrik Solenberg04f49312015-06-08 13:04:56 +020034 public:
solenberg85a04962015-10-27 03:35:21 -070035 struct Stats {
solenberg940b6d62016-10-25 11:19:07 -070036 Stats();
hbos1acfbd22016-11-17 23:43:29 -080037 ~Stats();
solenberg940b6d62016-10-25 11:19:07 -070038
solenberg85a04962015-10-27 03:35:21 -070039 // TODO(solenberg): Harmonize naming and defaults with receive stream stats.
40 uint32_t local_ssrc = 0;
41 int64_t bytes_sent = 0;
42 int32_t packets_sent = 0;
43 int32_t packets_lost = -1;
44 float fraction_lost = -1.0f;
45 std::string codec_name;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020046 absl::optional<int> codec_payload_type;
solenberg85a04962015-10-27 03:35:21 -070047 int32_t ext_seqnum = -1;
48 int32_t jitter_ms = -1;
49 int64_t rtt_ms = -1;
50 int32_t audio_level = -1;
zsteine76bd3a2017-07-14 12:17:49 -070051 // See description of "totalAudioEnergy" in the WebRTC stats spec:
52 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
53 double total_input_energy = 0.0;
54 double total_input_duration = 0.0;
solenberg85a04962015-10-27 03:35:21 -070055 bool typing_noise_detected = false;
Ivo Creusen56d46092017-11-24 17:29:59 +010056
ivoce1198e02017-09-08 08:13:19 -070057 ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +010058 AudioProcessingStats apm_statistics;
solenberg85a04962015-10-27 03:35:21 -070059 };
Fredrik Solenberg04f49312015-06-08 13:04:56 +020060
61 struct Config {
solenberg4fbae2b2015-08-28 04:07:10 -070062 Config() = delete;
solenberg940b6d62016-10-25 11:19:07 -070063 explicit Config(Transport* send_transport);
minyue6b825df2016-10-31 04:08:32 -070064 ~Config();
Fredrik Solenberg04f49312015-06-08 13:04:56 +020065 std::string ToString() const;
66
solenberg971cab02016-06-14 10:02:41 -070067 // Send-stream specific RTP settings.
Fredrik Solenberg04f49312015-06-08 13:04:56 +020068 struct Rtp {
solenberg940b6d62016-10-25 11:19:07 -070069 Rtp();
70 ~Rtp();
Fredrik Solenberg04f49312015-06-08 13:04:56 +020071 std::string ToString() const;
72
73 // Sender SSRC.
74 uint32_t ssrc = 0;
75
Steve Antonbb50ce52018-03-26 10:24:32 -070076 // The value to send in the MID RTP header extension if the extension is
77 // included in the list of extensions.
78 std::string mid;
79
Stefan Holmerb86d4e42015-12-07 10:26:18 +010080 // RTP header extensions used for the sent stream.
Fredrik Solenberg04f49312015-06-08 13:04:56 +020081 std::vector<RtpExtension> extensions;
solenberg3a941542015-11-16 07:34:50 -080082
solenberg971cab02016-06-14 10:02:41 -070083 // See NackConfig for description.
84 NackConfig nack;
85
solenberg3a941542015-11-16 07:34:50 -080086 // RTCP CNAME, see RFC 3550.
87 std::string c_name;
Fredrik Solenberg04f49312015-06-08 13:04:56 +020088 } rtp;
89
solenbergc7a8b082015-10-16 14:35:07 -070090 // Transport for outgoing packets. The transport is expected to exist for
91 // the entire life of the AudioSendStream and is owned by the API client.
pbos2d566682015-09-28 09:59:31 -070092 Transport* send_transport = nullptr;
solenberg4fbae2b2015-08-28 04:07:10 -070093
mflodman86cc6ff2016-07-26 04:44:06 -070094 // Bitrate limits used for variable audio bitrate streams. Set both to -1 to
95 // disable audio bitrate adaptation.
96 // Note: This is still an experimental feature and not ready for real usage.
minyue10cbb462016-11-07 09:29:22 -080097 int min_bitrate_bps = -1;
98 int max_bitrate_bps = -1;
minyue7a973442016-10-20 03:27:12 -070099
Seth Hampson24722b32017-12-22 09:36:42 -0800100 double bitrate_priority = 1.0;
101
minyue6b825df2016-10-31 04:08:32 -0700102 // Defines whether to turn on audio network adaptor, and defines its config
103 // string.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200104 absl::optional<std::string> audio_network_adaptor_config;
minyue6b825df2016-10-31 04:08:32 -0700105
minyue7a973442016-10-20 03:27:12 -0700106 struct SendCodecSpec {
ossu20a4b3f2017-04-27 02:08:52 -0700107 SendCodecSpec(int payload_type, const SdpAudioFormat& format);
108 ~SendCodecSpec();
solenberg940b6d62016-10-25 11:19:07 -0700109 std::string ToString() const;
110
111 bool operator==(const SendCodecSpec& rhs) const;
minyue7a973442016-10-20 03:27:12 -0700112 bool operator!=(const SendCodecSpec& rhs) const {
113 return !(*this == rhs);
114 }
115
ossu20a4b3f2017-04-27 02:08:52 -0700116 int payload_type;
117 SdpAudioFormat format;
minyue7a973442016-10-20 03:27:12 -0700118 bool nack_enabled = false;
119 bool transport_cc_enabled = false;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200120 absl::optional<int> cng_payload_type;
ossu20a4b3f2017-04-27 02:08:52 -0700121 // If unset, use the encoder's default target bitrate.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200122 absl::optional<int> target_bitrate_bps;
ossu20a4b3f2017-04-27 02:08:52 -0700123 };
124
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200125 absl::optional<SendCodecSpec> send_codec_spec;
ossu20a4b3f2017-04-27 02:08:52 -0700126 rtc::scoped_refptr<AudioEncoderFactory> encoder_factory;
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200127 absl::optional<AudioCodecPairId> codec_pair_id;
Alex Narestb3944f02017-10-13 14:56:18 +0200128
129 // Track ID as specified during track creation.
130 std::string track_id;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200131 };
132
eladalonabbc4302017-07-26 02:09:44 -0700133 virtual ~AudioSendStream() = default;
134
135 virtual const webrtc::AudioSendStream::Config& GetConfig() const = 0;
136
ossu20a4b3f2017-04-27 02:08:52 -0700137 // Reconfigure the stream according to the Configuration.
138 virtual void Reconfigure(const Config& config) = 0;
139
pbos1ba8d392016-05-01 20:18:34 -0700140 // Starts stream activity.
141 // When a stream is active, it can receive, process and deliver packets.
142 virtual void Start() = 0;
143 // Stops stream activity.
144 // When a stream is stopped, it can't receive, process or deliver packets.
145 virtual void Stop() = 0;
146
Fredrik Solenberg2a877972017-12-15 16:42:15 +0100147 // Encode and send audio.
148 virtual void SendAudioData(
149 std::unique_ptr<webrtc::AudioFrame> audio_frame) = 0;
150
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100151 // TODO(solenberg): Make payload_type a config property instead.
Yves Gerey665174f2018-06-19 15:03:05 +0200152 virtual bool SendTelephoneEvent(int payload_type,
153 int payload_frequency,
154 int event,
155 int duration_ms) = 0;
solenberg94218532016-06-16 10:53:22 -0700156
157 virtual void SetMuted(bool muted) = 0;
158
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200159 virtual Stats GetStats() const = 0;
Ivo Creusen56d46092017-11-24 17:29:59 +0100160 virtual Stats GetStats(bool has_remote_tracks) const = 0;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200161};
162} // namespace webrtc
163
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200164#endif // CALL_AUDIO_SEND_STREAM_H_