blob: 4912182c1208401a3e6639111332883d093a0984 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/audio_codecs/audio_encoder.h"
19#include "api/audio_codecs/audio_encoder_factory.h"
20#include "api/audio_codecs/audio_format.h"
21#include "api/call/transport.h"
22#include "api/optional.h"
23#include "api/rtpparameters.h"
24#include "call/rtp_config.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010025#include "modules/audio_processing/include/audio_processing_statistics.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/scoped_ref_ptr.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020027#include "typedefs.h" // NOLINT(build/include)
Fredrik Solenberg04f49312015-06-08 13:04:56 +020028
29namespace webrtc {
30
Fredrik Solenberga4527c82015-12-03 13:06:20 +010031// WORK IN PROGRESS
32// This class is under development and is not yet intended for for use outside
33// of WebRtc/Libjingle. Please use the VoiceEngine API instead.
34// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4690
35
pbos1ba8d392016-05-01 20:18:34 -070036class AudioSendStream {
Fredrik Solenberg04f49312015-06-08 13:04:56 +020037 public:
solenberg85a04962015-10-27 03:35:21 -070038 struct Stats {
solenberg940b6d62016-10-25 11:19:07 -070039 Stats();
hbos1acfbd22016-11-17 23:43:29 -080040 ~Stats();
solenberg940b6d62016-10-25 11:19:07 -070041
solenberg85a04962015-10-27 03:35:21 -070042 // TODO(solenberg): Harmonize naming and defaults with receive stream stats.
43 uint32_t local_ssrc = 0;
44 int64_t bytes_sent = 0;
45 int32_t packets_sent = 0;
46 int32_t packets_lost = -1;
47 float fraction_lost = -1.0f;
48 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -080049 rtc::Optional<int> codec_payload_type;
solenberg85a04962015-10-27 03:35:21 -070050 int32_t ext_seqnum = -1;
51 int32_t jitter_ms = -1;
52 int64_t rtt_ms = -1;
53 int32_t audio_level = -1;
zsteine76bd3a2017-07-14 12:17:49 -070054 // See description of "totalAudioEnergy" in the WebRTC stats spec:
55 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
56 double total_input_energy = 0.0;
57 double total_input_duration = 0.0;
solenberg85a04962015-10-27 03:35:21 -070058 bool typing_noise_detected = false;
Ivo Creusen56d46092017-11-24 17:29:59 +010059
ivoce1198e02017-09-08 08:13:19 -070060 ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +010061 AudioProcessingStats apm_statistics;
solenberg85a04962015-10-27 03:35:21 -070062 };
Fredrik Solenberg04f49312015-06-08 13:04:56 +020063
64 struct Config {
solenberg4fbae2b2015-08-28 04:07:10 -070065 Config() = delete;
solenberg940b6d62016-10-25 11:19:07 -070066 explicit Config(Transport* send_transport);
minyue6b825df2016-10-31 04:08:32 -070067 ~Config();
Fredrik Solenberg04f49312015-06-08 13:04:56 +020068 std::string ToString() const;
69
solenberg971cab02016-06-14 10:02:41 -070070 // Send-stream specific RTP settings.
Fredrik Solenberg04f49312015-06-08 13:04:56 +020071 struct Rtp {
solenberg940b6d62016-10-25 11:19:07 -070072 Rtp();
73 ~Rtp();
Fredrik Solenberg04f49312015-06-08 13:04:56 +020074 std::string ToString() const;
75
76 // Sender SSRC.
77 uint32_t ssrc = 0;
78
Stefan Holmerb86d4e42015-12-07 10:26:18 +010079 // RTP header extensions used for the sent stream.
Fredrik Solenberg04f49312015-06-08 13:04:56 +020080 std::vector<RtpExtension> extensions;
solenberg3a941542015-11-16 07:34:50 -080081
solenberg971cab02016-06-14 10:02:41 -070082 // See NackConfig for description.
83 NackConfig nack;
84
solenberg3a941542015-11-16 07:34:50 -080085 // RTCP CNAME, see RFC 3550.
86 std::string c_name;
Fredrik Solenberg04f49312015-06-08 13:04:56 +020087 } rtp;
88
solenbergc7a8b082015-10-16 14:35:07 -070089 // Transport for outgoing packets. The transport is expected to exist for
90 // the entire life of the AudioSendStream and is owned by the API client.
pbos2d566682015-09-28 09:59:31 -070091 Transport* send_transport = nullptr;
solenberg4fbae2b2015-08-28 04:07:10 -070092
solenbergcf18b342015-10-01 08:13:42 -070093 // Underlying VoiceEngine handle, used to map AudioSendStream to lower-level
94 // components.
95 // TODO(solenberg): Remove when VoiceEngine channels are created outside
96 // of Call.
97 int voe_channel_id = -1;
98
mflodman86cc6ff2016-07-26 04:44:06 -070099 // Bitrate limits used for variable audio bitrate streams. Set both to -1 to
100 // disable audio bitrate adaptation.
101 // Note: This is still an experimental feature and not ready for real usage.
minyue10cbb462016-11-07 09:29:22 -0800102 int min_bitrate_bps = -1;
103 int max_bitrate_bps = -1;
minyue7a973442016-10-20 03:27:12 -0700104
minyue6b825df2016-10-31 04:08:32 -0700105 // Defines whether to turn on audio network adaptor, and defines its config
106 // string.
107 rtc::Optional<std::string> audio_network_adaptor_config;
108
minyue7a973442016-10-20 03:27:12 -0700109 struct SendCodecSpec {
ossu20a4b3f2017-04-27 02:08:52 -0700110 SendCodecSpec(int payload_type, const SdpAudioFormat& format);
111 ~SendCodecSpec();
solenberg940b6d62016-10-25 11:19:07 -0700112 std::string ToString() const;
113
114 bool operator==(const SendCodecSpec& rhs) const;
minyue7a973442016-10-20 03:27:12 -0700115 bool operator!=(const SendCodecSpec& rhs) const {
116 return !(*this == rhs);
117 }
118
ossu20a4b3f2017-04-27 02:08:52 -0700119 int payload_type;
120 SdpAudioFormat format;
minyue7a973442016-10-20 03:27:12 -0700121 bool nack_enabled = false;
122 bool transport_cc_enabled = false;
ossu20a4b3f2017-04-27 02:08:52 -0700123 rtc::Optional<int> cng_payload_type;
124 // If unset, use the encoder's default target bitrate.
125 rtc::Optional<int> target_bitrate_bps;
126 };
127
128 rtc::Optional<SendCodecSpec> send_codec_spec;
129 rtc::scoped_refptr<AudioEncoderFactory> encoder_factory;
Alex Narestb3944f02017-10-13 14:56:18 +0200130
131 // Track ID as specified during track creation.
132 std::string track_id;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200133 };
134
eladalonabbc4302017-07-26 02:09:44 -0700135 virtual ~AudioSendStream() = default;
136
137 virtual const webrtc::AudioSendStream::Config& GetConfig() const = 0;
138
ossu20a4b3f2017-04-27 02:08:52 -0700139 // Reconfigure the stream according to the Configuration.
140 virtual void Reconfigure(const Config& config) = 0;
141
pbos1ba8d392016-05-01 20:18:34 -0700142 // Starts stream activity.
143 // When a stream is active, it can receive, process and deliver packets.
144 virtual void Start() = 0;
145 // Stops stream activity.
146 // When a stream is stopped, it can't receive, process or deliver packets.
147 virtual void Stop() = 0;
148
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100149 // TODO(solenberg): Make payload_type a config property instead.
solenbergffbbcac2016-11-17 05:25:37 -0800150 virtual bool SendTelephoneEvent(int payload_type, int payload_frequency,
151 int event, int duration_ms) = 0;
solenberg94218532016-06-16 10:53:22 -0700152
153 virtual void SetMuted(bool muted) = 0;
154
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200155 virtual Stats GetStats() const = 0;
Ivo Creusen56d46092017-11-24 17:29:59 +0100156 virtual Stats GetStats(bool has_remote_tracks) const = 0;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200157};
158} // namespace webrtc
159
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200160#endif // CALL_AUDIO_SEND_STREAM_H_