Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [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 04:47:31 | [diff] [blame] | 11 | #ifndef CALL_AUDIO_RECEIVE_STREAM_H_ |
| 12 | #define CALL_AUDIO_RECEIVE_STREAM_H_ |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 13 | |
Harald Alvestrand | 93c9aa1 | 2024-09-02 20:55:52 | [diff] [blame] | 14 | #include <cstddef> |
| 15 | #include <cstdint> |
Fredrik Solenberg | 04f4931 | 2015-06-08 11:04:56 | [diff] [blame] | 16 | #include <map> |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 17 | #include <optional> |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 18 | #include <string> |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 19 | |
Harald Alvestrand | 93c9aa1 | 2024-09-02 20:55:52 | [diff] [blame] | 20 | #include "api/audio_codecs/audio_codec_pair_id.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 21 | #include "api/audio_codecs/audio_decoder_factory.h" |
Harald Alvestrand | 93c9aa1 | 2024-09-02 20:55:52 | [diff] [blame] | 22 | #include "api/audio_codecs/audio_format.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 23 | #include "api/call/transport.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 24 | #include "api/crypto/crypto_options.h" |
Harald Alvestrand | 93c9aa1 | 2024-09-02 20:55:52 | [diff] [blame] | 25 | #include "api/crypto/frame_decryptor_interface.h" |
| 26 | #include "api/frame_transformer_interface.h" |
| 27 | #include "api/rtp_headers.h" |
| 28 | #include "api/scoped_refptr.h" |
| 29 | #include "api/units/time_delta.h" |
| 30 | #include "api/units/timestamp.h" |
Tommi | 1c1f540 | 2021-06-14 08:54:20 | [diff] [blame] | 31 | #include "call/receive_stream.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 32 | #include "call/rtp_config.h" |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 33 | |
| 34 | namespace webrtc { |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 35 | class AudioSinkInterface; |
Fredrik Solenberg | 04f4931 | 2015-06-08 11:04:56 | [diff] [blame] | 36 | |
Tommi | 3176ef7 | 2022-05-22 18:47:28 | [diff] [blame] | 37 | class AudioReceiveStreamInterface : public MediaReceiveStreamInterface { |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 38 | public: |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 08:49:27 | [diff] [blame] | 39 | struct Stats { |
Paulina Hensman | 11b34f4 | 2018-04-09 12:24:52 | [diff] [blame] | 40 | Stats(); |
| 41 | ~Stats(); |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 08:49:27 | [diff] [blame] | 42 | uint32_t remote_ssrc = 0; |
Philipp Hancke | 6a7bf10 | 2023-04-21 17:32:42 | [diff] [blame] | 43 | int64_t payload_bytes_received = 0; |
| 44 | int64_t header_and_padding_bytes_received = 0; |
| 45 | uint32_t packets_received = 0; |
Ivo Creusen | 8d8ffdb | 2019-04-30 07:45:21 | [diff] [blame] | 46 | uint64_t fec_packets_received = 0; |
| 47 | uint64_t fec_packets_discarded = 0; |
Philipp Hancke | af51228 | 2022-10-14 07:32:58 | [diff] [blame] | 48 | int32_t packets_lost = 0; |
Minyue Li | 28a2c63 | 2021-07-07 13:53:38 | [diff] [blame] | 49 | uint64_t packets_discarded = 0; |
Jakob Ivarsson | e54914a | 2021-07-01 09:16:05 | [diff] [blame] | 50 | uint32_t nacks_sent = 0; |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 08:49:27 | [diff] [blame] | 51 | std::string codec_name; |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 52 | std::optional<int> codec_payload_type; |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 08:49:27 | [diff] [blame] | 53 | uint32_t jitter_ms = 0; |
| 54 | uint32_t jitter_buffer_ms = 0; |
| 55 | uint32_t jitter_buffer_preferred_ms = 0; |
| 56 | uint32_t delay_estimate_ms = 0; |
| 57 | int32_t audio_level = -1; |
Gustaf Ullberg | 9a2e906 | 2017-09-18 07:28:20 | [diff] [blame] | 58 | // Stats below correspond to similarly-named fields in the WebRTC stats |
| 59 | // spec. https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats |
zstein | e76bd3a | 2017-07-14 19:17:49 | [diff] [blame] | 60 | double total_output_energy = 0.0; |
Steve Anton | 2dbc69f | 2017-08-25 00:15:13 | [diff] [blame] | 61 | uint64_t total_samples_received = 0; |
zstein | e76bd3a | 2017-07-14 19:17:49 | [diff] [blame] | 62 | double total_output_duration = 0.0; |
Steve Anton | 2dbc69f | 2017-08-25 00:15:13 | [diff] [blame] | 63 | uint64_t concealed_samples = 0; |
Ivo Creusen | 8d8ffdb | 2019-04-30 07:45:21 | [diff] [blame] | 64 | uint64_t silent_concealed_samples = 0; |
Gustaf Ullberg | 9a2e906 | 2017-09-18 07:28:20 | [diff] [blame] | 65 | uint64_t concealment_events = 0; |
Gustaf Ullberg | b0a0207 | 2017-10-02 10:00:34 | [diff] [blame] | 66 | double jitter_buffer_delay_seconds = 0.0; |
Chen Xing | 0acffb5 | 2019-01-15 14:46:29 | [diff] [blame] | 67 | uint64_t jitter_buffer_emitted_count = 0; |
Artem Titov | e618cc9 | 2020-03-11 10:18:54 | [diff] [blame] | 68 | double jitter_buffer_target_delay_seconds = 0.0; |
Ivo Creusen | 1a84b56 | 2022-07-19 14:33:10 | [diff] [blame] | 69 | double jitter_buffer_minimum_delay_seconds = 0.0; |
Ivo Creusen | 8d8ffdb | 2019-04-30 07:45:21 | [diff] [blame] | 70 | uint64_t inserted_samples_for_deceleration = 0; |
| 71 | uint64_t removed_samples_for_acceleration = 0; |
Jesús de Vicente Peña | fc6df05 | 2024-06-04 08:05:31 | [diff] [blame] | 72 | double total_processing_delay_seconds = 0.0; |
Gustaf Ullberg | 9a2e906 | 2017-09-18 07:28:20 | [diff] [blame] | 73 | // Stats below DO NOT correspond directly to anything in the WebRTC stats |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 08:49:27 | [diff] [blame] | 74 | float expand_rate = 0.0f; |
| 75 | float speech_expand_rate = 0.0f; |
| 76 | float secondary_decoded_rate = 0.0f; |
minyue-webrtc | 0e320ec | 2017-08-28 11:51:27 | [diff] [blame] | 77 | float secondary_discarded_rate = 0.0f; |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 08:49:27 | [diff] [blame] | 78 | float accelerate_rate = 0.0f; |
| 79 | float preemptive_expand_rate = 0.0f; |
Jakob Ivarsson | 352ce5c | 2018-11-27 11:52:16 | [diff] [blame] | 80 | uint64_t delayed_packet_outage_samples = 0; |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 08:49:27 | [diff] [blame] | 81 | int32_t decoding_calls_to_silence_generator = 0; |
| 82 | int32_t decoding_calls_to_neteq = 0; |
| 83 | int32_t decoding_normal = 0; |
Alex Narest | 5b5d97c | 2019-08-07 16:15:08 | [diff] [blame] | 84 | // TODO(alexnarest): Consider decoding_neteq_plc for consistency |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 08:49:27 | [diff] [blame] | 85 | int32_t decoding_plc = 0; |
Alex Narest | 5b5d97c | 2019-08-07 16:15:08 | [diff] [blame] | 86 | int32_t decoding_codec_plc = 0; |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 08:49:27 | [diff] [blame] | 87 | int32_t decoding_cng = 0; |
| 88 | int32_t decoding_plc_cng = 0; |
henrik.lundin | 6348978 | 2016-09-20 08:47:12 | [diff] [blame] | 89 | int32_t decoding_muted_output = 0; |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 08:49:27 | [diff] [blame] | 90 | int64_t capture_start_ntp_time_ms = 0; |
Henrik Boström | 01738c6 | 2019-04-15 15:32:00 | [diff] [blame] | 91 | // The timestamp at which the last packet was received, i.e. the time of the |
| 92 | // local clock when it was received - not the RTP timestamp of that packet. |
| 93 | // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 94 | std::optional<Timestamp> last_packet_received; |
Ruslan Burakov | 8af8896 | 2018-11-22 16:21:10 | [diff] [blame] | 95 | uint64_t jitter_buffer_flushes = 0; |
Jakob Ivarsson | 232b3fd | 2019-03-06 08:18:40 | [diff] [blame] | 96 | double relative_packet_arrival_delay_seconds = 0.0; |
Henrik Lundin | 44125fa | 2019-04-29 15:00:46 | [diff] [blame] | 97 | int32_t interruption_count = 0; |
| 98 | int32_t total_interruption_duration_ms = 0; |
Åsa Persson | fcf79cc | 2019-10-22 13:23:44 | [diff] [blame] | 99 | // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 100 | std::optional<int64_t> estimated_playout_ntp_timestamp_ms; |
Alessio Bazzica | f7b1b95 | 2021-03-23 16:23:04 | [diff] [blame] | 101 | // Remote outbound stats derived by the received RTCP sender reports. |
| 102 | // https://w3c.github.io/webrtc-stats/#remoteoutboundrtpstats-dict* |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 103 | std::optional<int64_t> last_sender_report_timestamp_ms; |
| 104 | std::optional<int64_t> last_sender_report_remote_timestamp_ms; |
Philipp Hancke | b3e5969 | 2023-03-14 15:17:33 | [diff] [blame] | 105 | uint64_t sender_reports_packets_sent = 0; |
Alessio Bazzica | f7b1b95 | 2021-03-23 16:23:04 | [diff] [blame] | 106 | uint64_t sender_reports_bytes_sent = 0; |
| 107 | uint64_t sender_reports_reports_count = 0; |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 108 | std::optional<TimeDelta> round_trip_time; |
Ivo Creusen | 2562cf0 | 2021-09-03 14:51:22 | [diff] [blame] | 109 | TimeDelta total_round_trip_time = TimeDelta::Zero(); |
Henrik Boström | 0c126ed | 2023-03-10 10:29:17 | [diff] [blame] | 110 | int round_trip_time_measurements = 0; |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 08:49:27 | [diff] [blame] | 111 | }; |
Fredrik Solenberg | 04f4931 | 2015-06-08 11:04:56 | [diff] [blame] | 112 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 113 | struct Config { |
Paulina Hensman | 11b34f4 | 2018-04-09 12:24:52 | [diff] [blame] | 114 | Config(); |
| 115 | ~Config(); |
| 116 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 117 | std::string ToString() const; |
| 118 | |
| 119 | // Receive-stream specific RTP settings. |
Tommi | 7a15ff3 | 2022-05-09 18:54:02 | [diff] [blame] | 120 | struct Rtp : public ReceiveStreamRtpConfig { |
Paulina Hensman | 11b34f4 | 2018-04-09 12:24:52 | [diff] [blame] | 121 | Rtp(); |
| 122 | ~Rtp(); |
| 123 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 124 | std::string ToString() const; |
| 125 | |
solenberg | 8189b02 | 2016-06-14 19:13:00 | [diff] [blame] | 126 | // See NackConfig for description. |
| 127 | NackConfig nack; |
Philipp Hancke | bad99ab | 2024-05-13 15:49:42 | [diff] [blame] | 128 | RtcpMode rtcp_mode = RtcpMode::kCompound; |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 129 | } rtp; |
Fredrik Solenberg | 04f4931 | 2015-06-08 11:04:56 | [diff] [blame] | 130 | |
Ivo Creusen | 2562cf0 | 2021-09-03 14:51:22 | [diff] [blame] | 131 | // Receive-side RTT. |
| 132 | bool enable_non_sender_rtt = false; |
| 133 | |
solenberg | cf18b34 | 2015-10-01 15:13:42 | [diff] [blame] | 134 | Transport* rtcp_send_transport = nullptr; |
| 135 | |
Fredrik Solenberg | 8f5787a | 2018-01-11 12:52:30 | [diff] [blame] | 136 | // NetEq settings. |
Jakob Ivarsson | 647d5e6 | 2019-03-15 09:37:31 | [diff] [blame] | 137 | size_t jitter_buffer_max_packets = 200; |
Fredrik Solenberg | 8f5787a | 2018-01-11 12:52:30 | [diff] [blame] | 138 | bool jitter_buffer_fast_accelerate = false; |
Jakob Ivarsson | 10403ae | 2018-11-27 14:45:20 | [diff] [blame] | 139 | int jitter_buffer_min_delay_ms = 0; |
Fredrik Solenberg | 8f5787a | 2018-01-11 12:52:30 | [diff] [blame] | 140 | |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 141 | // Identifier for an A/V synchronization group. Empty string to disable. |
| 142 | // TODO(pbos): Synchronize streams in a sync group, not just one video |
| 143 | // stream to one audio stream. Tracked by issue webrtc:4762. |
| 144 | std::string sync_group; |
| 145 | |
kwiberg | d32bf75 | 2017-01-19 15:03:59 | [diff] [blame] | 146 | // Decoder specifications for every payload type that we can receive. |
| 147 | std::map<int, SdpAudioFormat> decoder_map; |
ossu | 29b1a8d | 2016-06-13 14:34:51 | [diff] [blame] | 148 | |
| 149 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory; |
Karl Wiberg | 0812634 | 2018-03-20 18:18:55 | [diff] [blame] | 150 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 151 | std::optional<AudioCodecPairId> codec_pair_id; |
Benjamin Wright | 84583f6 | 2018-10-04 21:22:34 | [diff] [blame] | 152 | |
Benjamin Wright | bfb444c | 2018-10-15 17:20:24 | [diff] [blame] | 153 | // Per PeerConnection crypto options. |
| 154 | webrtc::CryptoOptions crypto_options; |
| 155 | |
Benjamin Wright | 84583f6 | 2018-10-04 21:22:34 | [diff] [blame] | 156 | // An optional custom frame decryptor that allows the entire frame to be |
| 157 | // decrypted in whatever way the caller choses. This is not required by |
| 158 | // default. |
Tommi | 6eda26c | 2021-06-09 11:46:28 | [diff] [blame] | 159 | // TODO(tommi): Remove this member variable from the struct. It's not |
Tommi | 3176ef7 | 2022-05-22 18:47:28 | [diff] [blame] | 160 | // a part of the AudioReceiveStreamInterface state but rather a pass through |
Tommi | 6eda26c | 2021-06-09 11:46:28 | [diff] [blame] | 161 | // variable. |
Benjamin Wright | 84583f6 | 2018-10-04 21:22:34 | [diff] [blame] | 162 | rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor; |
Marina Ciocea | 3e9af7f | 2020-04-01 05:46:16 | [diff] [blame] | 163 | |
| 164 | // An optional frame transformer used by insertable streams to transform |
| 165 | // encoded frames. |
Tommi | 6eda26c | 2021-06-09 11:46:28 | [diff] [blame] | 166 | // TODO(tommi): Remove this member variable from the struct. It's not |
Tommi | 3176ef7 | 2022-05-22 18:47:28 | [diff] [blame] | 167 | // a part of the AudioReceiveStreamInterface state but rather a pass through |
Tommi | 6eda26c | 2021-06-09 11:46:28 | [diff] [blame] | 168 | // variable. |
Marina Ciocea | 3e9af7f | 2020-04-01 05:46:16 | [diff] [blame] | 169 | rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer; |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 170 | }; |
| 171 | |
Tommi | 6eda26c | 2021-06-09 11:46:28 | [diff] [blame] | 172 | // Methods that support reconfiguring the stream post initialization. |
Tommi | 6eda26c | 2021-06-09 11:46:28 | [diff] [blame] | 173 | virtual void SetDecoderMap(std::map<int, SdpAudioFormat> decoder_map) = 0; |
Tommi | a136ed4 | 2022-05-30 13:08:13 | [diff] [blame] | 174 | virtual void SetNackHistory(int history_ms) = 0; |
Ivo Creusen | 2562cf0 | 2021-09-03 14:51:22 | [diff] [blame] | 175 | virtual void SetNonSenderRttMeasurement(bool enabled) = 0; |
| 176 | |
Tomas Gunnarsson | 8467cf2 | 2021-01-17 13:36:44 | [diff] [blame] | 177 | // Returns true if the stream has been started. |
| 178 | virtual bool IsRunning() const = 0; |
| 179 | |
Niels Möller | 6b4d962 | 2020-09-14 08:47:50 | [diff] [blame] | 180 | virtual Stats GetStats(bool get_and_clear_legacy_stats) const = 0; |
| 181 | Stats GetStats() { return GetStats(/*get_and_clear_legacy_stats=*/true); } |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 182 | |
| 183 | // Sets an audio sink that receives unmixed audio from the receive stream. |
Fredrik Solenberg | 8f5787a | 2018-01-11 12:52:30 | [diff] [blame] | 184 | // Ownership of the sink is managed by the caller. |
deadbeef | 884f585 | 2016-01-15 17:20:04 | [diff] [blame] | 185 | // Only one sink can be set and passing a null sink clears an existing one. |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 186 | // NOTE: Audio must still somehow be pulled through AudioTransport for audio |
| 187 | // to stream through this sink. In practice, this happens if mixed audio |
| 188 | // is being pulled+rendered and/or if audio is being pulled for the purposes |
| 189 | // of feeding to the AEC. |
Fredrik Solenberg | 8f5787a | 2018-01-11 12:52:30 | [diff] [blame] | 190 | virtual void SetSink(AudioSinkInterface* sink) = 0; |
pbos | 1ba8d39 | 2016-05-02 03:18:34 | [diff] [blame] | 191 | |
solenberg | 217fb66 | 2016-06-17 15:30:54 | [diff] [blame] | 192 | // Sets playback gain of the stream, applied when mixing, and thus after it |
| 193 | // is potentially forwarded to any attached AudioSinkInterface implementation. |
| 194 | virtual void SetGain(float gain) = 0; |
| 195 | |
Ruslan Burakov | 3b50f9f | 2019-02-06 08:45:56 | [diff] [blame] | 196 | // Sets a base minimum for the playout delay. Base minimum delay sets lower |
| 197 | // bound on minimum delay value determining lower bound on playout delay. |
| 198 | // |
| 199 | // Returns true if value was successfully set, false overwise. |
| 200 | virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0; |
| 201 | |
| 202 | // Returns current value of base minimum delay in milliseconds. |
| 203 | virtual int GetBaseMinimumPlayoutDelayMs() const = 0; |
| 204 | |
Tommi | cb7c736 | 2022-05-09 14:49:37 | [diff] [blame] | 205 | // Synchronization source (stream identifier) to be received. |
| 206 | // This member will not change mid-stream and can be assumed to be const |
| 207 | // post initialization. |
| 208 | virtual uint32_t remote_ssrc() const = 0; |
| 209 | |
pbos | 1ba8d39 | 2016-05-02 03:18:34 | [diff] [blame] | 210 | protected: |
Tommi | 3176ef7 | 2022-05-22 18:47:28 | [diff] [blame] | 211 | virtual ~AudioReceiveStreamInterface() {} |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 212 | }; |
Tommi | 3176ef7 | 2022-05-22 18:47:28 | [diff] [blame] | 213 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 214 | } // namespace webrtc |
| 215 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 216 | #endif // CALL_AUDIO_RECEIVE_STREAM_H_ |