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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #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 Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 25 | #include "modules/audio_processing/include/audio_processing_statistics.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "rtc_base/scoped_ref_ptr.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 27 | #include "typedefs.h" // NOLINT(build/include) |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
| 30 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 31 | class AudioFrame; |
| 32 | |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 33 | class AudioSendStream { |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 34 | public: |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 35 | struct Stats { |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 36 | Stats(); |
hbos | 1acfbd2 | 2016-11-17 23:43:29 -0800 | [diff] [blame] | 37 | ~Stats(); |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 38 | |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 39 | // 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; |
hbos | 1acfbd2 | 2016-11-17 23:43:29 -0800 | [diff] [blame] | 46 | rtc::Optional<int> codec_payload_type; |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 47 | int32_t ext_seqnum = -1; |
| 48 | int32_t jitter_ms = -1; |
| 49 | int64_t rtt_ms = -1; |
| 50 | int32_t audio_level = -1; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 51 | // 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; |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 55 | bool typing_noise_detected = false; |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 56 | |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 57 | ANAStats ana_statistics; |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 58 | AudioProcessingStats apm_statistics; |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 59 | }; |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 60 | |
| 61 | struct Config { |
solenberg | 4fbae2b | 2015-08-28 04:07:10 -0700 | [diff] [blame] | 62 | Config() = delete; |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 63 | explicit Config(Transport* send_transport); |
minyue | 6b825df | 2016-10-31 04:08:32 -0700 | [diff] [blame] | 64 | ~Config(); |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 65 | std::string ToString() const; |
| 66 | |
solenberg | 971cab0 | 2016-06-14 10:02:41 -0700 | [diff] [blame] | 67 | // Send-stream specific RTP settings. |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 68 | struct Rtp { |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 69 | Rtp(); |
| 70 | ~Rtp(); |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 71 | std::string ToString() const; |
| 72 | |
| 73 | // Sender SSRC. |
| 74 | uint32_t ssrc = 0; |
| 75 | |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 76 | // RTP header extensions used for the sent stream. |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 77 | std::vector<RtpExtension> extensions; |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 78 | |
solenberg | 971cab0 | 2016-06-14 10:02:41 -0700 | [diff] [blame] | 79 | // See NackConfig for description. |
| 80 | NackConfig nack; |
| 81 | |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 82 | // RTCP CNAME, see RFC 3550. |
| 83 | std::string c_name; |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 84 | } rtp; |
| 85 | |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 86 | // Transport for outgoing packets. The transport is expected to exist for |
| 87 | // the entire life of the AudioSendStream and is owned by the API client. |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 88 | Transport* send_transport = nullptr; |
solenberg | 4fbae2b | 2015-08-28 04:07:10 -0700 | [diff] [blame] | 89 | |
mflodman | 86cc6ff | 2016-07-26 04:44:06 -0700 | [diff] [blame] | 90 | // Bitrate limits used for variable audio bitrate streams. Set both to -1 to |
| 91 | // disable audio bitrate adaptation. |
| 92 | // Note: This is still an experimental feature and not ready for real usage. |
minyue | 10cbb46 | 2016-11-07 09:29:22 -0800 | [diff] [blame] | 93 | int min_bitrate_bps = -1; |
| 94 | int max_bitrate_bps = -1; |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 95 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 96 | double bitrate_priority = 1.0; |
| 97 | |
minyue | 6b825df | 2016-10-31 04:08:32 -0700 | [diff] [blame] | 98 | // Defines whether to turn on audio network adaptor, and defines its config |
| 99 | // string. |
| 100 | rtc::Optional<std::string> audio_network_adaptor_config; |
| 101 | |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 102 | struct SendCodecSpec { |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 103 | SendCodecSpec(int payload_type, const SdpAudioFormat& format); |
| 104 | ~SendCodecSpec(); |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 105 | std::string ToString() const; |
| 106 | |
| 107 | bool operator==(const SendCodecSpec& rhs) const; |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 108 | bool operator!=(const SendCodecSpec& rhs) const { |
| 109 | return !(*this == rhs); |
| 110 | } |
| 111 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 112 | int payload_type; |
| 113 | SdpAudioFormat format; |
minyue | 7a97344 | 2016-10-20 03:27:12 -0700 | [diff] [blame] | 114 | bool nack_enabled = false; |
| 115 | bool transport_cc_enabled = false; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 116 | rtc::Optional<int> cng_payload_type; |
| 117 | // If unset, use the encoder's default target bitrate. |
| 118 | rtc::Optional<int> target_bitrate_bps; |
| 119 | }; |
| 120 | |
| 121 | rtc::Optional<SendCodecSpec> send_codec_spec; |
| 122 | rtc::scoped_refptr<AudioEncoderFactory> encoder_factory; |
Alex Narest | b3944f0 | 2017-10-13 14:56:18 +0200 | [diff] [blame] | 123 | |
| 124 | // Track ID as specified during track creation. |
| 125 | std::string track_id; |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 126 | }; |
| 127 | |
eladalon | abbc430 | 2017-07-26 02:09:44 -0700 | [diff] [blame] | 128 | virtual ~AudioSendStream() = default; |
| 129 | |
| 130 | virtual const webrtc::AudioSendStream::Config& GetConfig() const = 0; |
| 131 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 132 | // Reconfigure the stream according to the Configuration. |
| 133 | virtual void Reconfigure(const Config& config) = 0; |
| 134 | |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 135 | // Starts stream activity. |
| 136 | // When a stream is active, it can receive, process and deliver packets. |
| 137 | virtual void Start() = 0; |
| 138 | // Stops stream activity. |
| 139 | // When a stream is stopped, it can't receive, process or deliver packets. |
| 140 | virtual void Stop() = 0; |
| 141 | |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 142 | // Encode and send audio. |
| 143 | virtual void SendAudioData( |
| 144 | std::unique_ptr<webrtc::AudioFrame> audio_frame) = 0; |
| 145 | |
Fredrik Solenberg | b572768 | 2015-12-04 15:22:19 +0100 | [diff] [blame] | 146 | // TODO(solenberg): Make payload_type a config property instead. |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 147 | virtual bool SendTelephoneEvent(int payload_type, int payload_frequency, |
| 148 | int event, int duration_ms) = 0; |
solenberg | 9421853 | 2016-06-16 10:53:22 -0700 | [diff] [blame] | 149 | |
| 150 | virtual void SetMuted(bool muted) = 0; |
| 151 | |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 152 | virtual Stats GetStats() const = 0; |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 153 | virtual Stats GetStats(bool has_remote_tracks) const = 0; |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 154 | }; |
| 155 | } // namespace webrtc |
| 156 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 157 | #endif // CALL_AUDIO_SEND_STREAM_H_ |