blob: d91e68caa9a954811c8135539df127df1e235372 [file] [log] [blame]
Fredrik Solenberg23fba1f2015-04-29 13:24:011/*
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 04:47:3111#ifndef CALL_AUDIO_RECEIVE_STREAM_H_
12#define CALL_AUDIO_RECEIVE_STREAM_H_
Fredrik Solenberg23fba1f2015-04-29 13:24:0113
Harald Alvestrand93c9aa12024-09-02 20:55:5214#include <cstddef>
15#include <cstdint>
Fredrik Solenberg04f49312015-06-08 11:04:5616#include <map>
Florent Castelli8037fc62024-08-29 13:00:4017#include <optional>
Fredrik Solenberg23fba1f2015-04-29 13:24:0118#include <string>
Fredrik Solenberg23fba1f2015-04-29 13:24:0119
Harald Alvestrand93c9aa12024-09-02 20:55:5220#include "api/audio_codecs/audio_codec_pair_id.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3121#include "api/audio_codecs/audio_decoder_factory.h"
Harald Alvestrand93c9aa12024-09-02 20:55:5222#include "api/audio_codecs/audio_format.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3123#include "api/call/transport.h"
Steve Anton10542f22019-01-11 17:11:0024#include "api/crypto/crypto_options.h"
Harald Alvestrand93c9aa12024-09-02 20:55:5225#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"
Tommi1c1f5402021-06-14 08:54:2031#include "call/receive_stream.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3132#include "call/rtp_config.h"
Fredrik Solenberg23fba1f2015-04-29 13:24:0133
34namespace webrtc {
Tommif888bb52015-12-12 00:37:0135class AudioSinkInterface;
Fredrik Solenberg04f49312015-06-08 11:04:5636
Tommi3176ef72022-05-22 18:47:2837class AudioReceiveStreamInterface : public MediaReceiveStreamInterface {
Fredrik Solenberg23fba1f2015-04-29 13:24:0138 public:
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2739 struct Stats {
Paulina Hensman11b34f42018-04-09 12:24:5240 Stats();
41 ~Stats();
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2742 uint32_t remote_ssrc = 0;
Philipp Hancke6a7bf102023-04-21 17:32:4243 int64_t payload_bytes_received = 0;
44 int64_t header_and_padding_bytes_received = 0;
45 uint32_t packets_received = 0;
Ivo Creusen8d8ffdb2019-04-30 07:45:2146 uint64_t fec_packets_received = 0;
47 uint64_t fec_packets_discarded = 0;
Philipp Hanckeaf512282022-10-14 07:32:5848 int32_t packets_lost = 0;
Minyue Li28a2c632021-07-07 13:53:3849 uint64_t packets_discarded = 0;
Jakob Ivarssone54914a2021-07-01 09:16:0550 uint32_t nacks_sent = 0;
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2751 std::string codec_name;
Florent Castelli8037fc62024-08-29 13:00:4052 std::optional<int> codec_payload_type;
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2753 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 Ullberg9a2e9062017-09-18 07:28:2058 // Stats below correspond to similarly-named fields in the WebRTC stats
59 // spec. https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
zsteine76bd3a2017-07-14 19:17:4960 double total_output_energy = 0.0;
Steve Anton2dbc69f2017-08-25 00:15:1361 uint64_t total_samples_received = 0;
zsteine76bd3a2017-07-14 19:17:4962 double total_output_duration = 0.0;
Steve Anton2dbc69f2017-08-25 00:15:1363 uint64_t concealed_samples = 0;
Ivo Creusen8d8ffdb2019-04-30 07:45:2164 uint64_t silent_concealed_samples = 0;
Gustaf Ullberg9a2e9062017-09-18 07:28:2065 uint64_t concealment_events = 0;
Gustaf Ullbergb0a02072017-10-02 10:00:3466 double jitter_buffer_delay_seconds = 0.0;
Chen Xing0acffb52019-01-15 14:46:2967 uint64_t jitter_buffer_emitted_count = 0;
Artem Titove618cc92020-03-11 10:18:5468 double jitter_buffer_target_delay_seconds = 0.0;
Ivo Creusen1a84b562022-07-19 14:33:1069 double jitter_buffer_minimum_delay_seconds = 0.0;
Ivo Creusen8d8ffdb2019-04-30 07:45:2170 uint64_t inserted_samples_for_deceleration = 0;
71 uint64_t removed_samples_for_acceleration = 0;
Jesús de Vicente Peñafc6df052024-06-04 08:05:3172 double total_processing_delay_seconds = 0.0;
Gustaf Ullberg9a2e9062017-09-18 07:28:2073 // Stats below DO NOT correspond directly to anything in the WebRTC stats
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2774 float expand_rate = 0.0f;
75 float speech_expand_rate = 0.0f;
76 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 11:51:2777 float secondary_discarded_rate = 0.0f;
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2778 float accelerate_rate = 0.0f;
79 float preemptive_expand_rate = 0.0f;
Jakob Ivarsson352ce5c2018-11-27 11:52:1680 uint64_t delayed_packet_outage_samples = 0;
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2781 int32_t decoding_calls_to_silence_generator = 0;
82 int32_t decoding_calls_to_neteq = 0;
83 int32_t decoding_normal = 0;
Alex Narest5b5d97c2019-08-07 16:15:0884 // TODO(alexnarest): Consider decoding_neteq_plc for consistency
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2785 int32_t decoding_plc = 0;
Alex Narest5b5d97c2019-08-07 16:15:0886 int32_t decoding_codec_plc = 0;
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2787 int32_t decoding_cng = 0;
88 int32_t decoding_plc_cng = 0;
henrik.lundin63489782016-09-20 08:47:1289 int32_t decoding_muted_output = 0;
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2790 int64_t capture_start_ntp_time_ms = 0;
Henrik Boström01738c62019-04-15 15:32:0091 // 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 Castelli8037fc62024-08-29 13:00:4094 std::optional<Timestamp> last_packet_received;
Ruslan Burakov8af88962018-11-22 16:21:1095 uint64_t jitter_buffer_flushes = 0;
Jakob Ivarsson232b3fd2019-03-06 08:18:4096 double relative_packet_arrival_delay_seconds = 0.0;
Henrik Lundin44125fa2019-04-29 15:00:4697 int32_t interruption_count = 0;
98 int32_t total_interruption_duration_ms = 0;
Åsa Perssonfcf79cc2019-10-22 13:23:4499 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp
Florent Castelli8037fc62024-08-29 13:00:40100 std::optional<int64_t> estimated_playout_ntp_timestamp_ms;
Alessio Bazzicaf7b1b952021-03-23 16:23:04101 // Remote outbound stats derived by the received RTCP sender reports.
102 // https://w3c.github.io/webrtc-stats/#remoteoutboundrtpstats-dict*
Florent Castelli8037fc62024-08-29 13:00:40103 std::optional<int64_t> last_sender_report_timestamp_ms;
104 std::optional<int64_t> last_sender_report_remote_timestamp_ms;
Philipp Hanckeb3e59692023-03-14 15:17:33105 uint64_t sender_reports_packets_sent = 0;
Alessio Bazzicaf7b1b952021-03-23 16:23:04106 uint64_t sender_reports_bytes_sent = 0;
107 uint64_t sender_reports_reports_count = 0;
Florent Castelli8037fc62024-08-29 13:00:40108 std::optional<TimeDelta> round_trip_time;
Ivo Creusen2562cf02021-09-03 14:51:22109 TimeDelta total_round_trip_time = TimeDelta::Zero();
Henrik Boström0c126ed2023-03-10 10:29:17110 int round_trip_time_measurements = 0;
Fredrik Solenberg4f4ec0a2015-10-22 08:49:27111 };
Fredrik Solenberg04f49312015-06-08 11:04:56112
Fredrik Solenberg23fba1f2015-04-29 13:24:01113 struct Config {
Paulina Hensman11b34f42018-04-09 12:24:52114 Config();
115 ~Config();
116
Fredrik Solenberg23fba1f2015-04-29 13:24:01117 std::string ToString() const;
118
119 // Receive-stream specific RTP settings.
Tommi7a15ff32022-05-09 18:54:02120 struct Rtp : public ReceiveStreamRtpConfig {
Paulina Hensman11b34f42018-04-09 12:24:52121 Rtp();
122 ~Rtp();
123
Fredrik Solenberg23fba1f2015-04-29 13:24:01124 std::string ToString() const;
125
solenberg8189b022016-06-14 19:13:00126 // See NackConfig for description.
127 NackConfig nack;
Philipp Hanckebad99ab2024-05-13 15:49:42128 RtcpMode rtcp_mode = RtcpMode::kCompound;
Fredrik Solenberg23fba1f2015-04-29 13:24:01129 } rtp;
Fredrik Solenberg04f49312015-06-08 11:04:56130
Ivo Creusen2562cf02021-09-03 14:51:22131 // Receive-side RTT.
132 bool enable_non_sender_rtt = false;
133
solenbergcf18b342015-10-01 15:13:42134 Transport* rtcp_send_transport = nullptr;
135
Fredrik Solenberg8f5787a2018-01-11 12:52:30136 // NetEq settings.
Jakob Ivarsson647d5e62019-03-15 09:37:31137 size_t jitter_buffer_max_packets = 200;
Fredrik Solenberg8f5787a2018-01-11 12:52:30138 bool jitter_buffer_fast_accelerate = false;
Jakob Ivarsson10403ae2018-11-27 14:45:20139 int jitter_buffer_min_delay_ms = 0;
Fredrik Solenberg8f5787a2018-01-11 12:52:30140
pbos8fc7fa72015-07-15 15:02:58141 // 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
kwibergd32bf752017-01-19 15:03:59146 // Decoder specifications for every payload type that we can receive.
147 std::map<int, SdpAudioFormat> decoder_map;
ossu29b1a8d2016-06-13 14:34:51148
149 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory;
Karl Wiberg08126342018-03-20 18:18:55150
Florent Castelli8037fc62024-08-29 13:00:40151 std::optional<AudioCodecPairId> codec_pair_id;
Benjamin Wright84583f62018-10-04 21:22:34152
Benjamin Wrightbfb444c2018-10-15 17:20:24153 // Per PeerConnection crypto options.
154 webrtc::CryptoOptions crypto_options;
155
Benjamin Wright84583f62018-10-04 21:22:34156 // 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.
Tommi6eda26c2021-06-09 11:46:28159 // TODO(tommi): Remove this member variable from the struct. It's not
Tommi3176ef72022-05-22 18:47:28160 // a part of the AudioReceiveStreamInterface state but rather a pass through
Tommi6eda26c2021-06-09 11:46:28161 // variable.
Benjamin Wright84583f62018-10-04 21:22:34162 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor;
Marina Ciocea3e9af7f2020-04-01 05:46:16163
164 // An optional frame transformer used by insertable streams to transform
165 // encoded frames.
Tommi6eda26c2021-06-09 11:46:28166 // TODO(tommi): Remove this member variable from the struct. It's not
Tommi3176ef72022-05-22 18:47:28167 // a part of the AudioReceiveStreamInterface state but rather a pass through
Tommi6eda26c2021-06-09 11:46:28168 // variable.
Marina Ciocea3e9af7f2020-04-01 05:46:16169 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
Fredrik Solenberg23fba1f2015-04-29 13:24:01170 };
171
Tommi6eda26c2021-06-09 11:46:28172 // Methods that support reconfiguring the stream post initialization.
Tommi6eda26c2021-06-09 11:46:28173 virtual void SetDecoderMap(std::map<int, SdpAudioFormat> decoder_map) = 0;
Tommia136ed42022-05-30 13:08:13174 virtual void SetNackHistory(int history_ms) = 0;
Ivo Creusen2562cf02021-09-03 14:51:22175 virtual void SetNonSenderRttMeasurement(bool enabled) = 0;
176
Tomas Gunnarsson8467cf22021-01-17 13:36:44177 // Returns true if the stream has been started.
178 virtual bool IsRunning() const = 0;
179
Niels Möller6b4d9622020-09-14 08:47:50180 virtual Stats GetStats(bool get_and_clear_legacy_stats) const = 0;
181 Stats GetStats() { return GetStats(/*get_and_clear_legacy_stats=*/true); }
Tommif888bb52015-12-12 00:37:01182
183 // Sets an audio sink that receives unmixed audio from the receive stream.
Fredrik Solenberg8f5787a2018-01-11 12:52:30184 // Ownership of the sink is managed by the caller.
deadbeef884f5852016-01-15 17:20:04185 // Only one sink can be set and passing a null sink clears an existing one.
Tommif888bb52015-12-12 00:37:01186 // 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 Solenberg8f5787a2018-01-11 12:52:30190 virtual void SetSink(AudioSinkInterface* sink) = 0;
pbos1ba8d392016-05-02 03:18:34191
solenberg217fb662016-06-17 15:30:54192 // 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 Burakov3b50f9f2019-02-06 08:45:56196 // 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
Tommicb7c7362022-05-09 14:49:37205 // 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
pbos1ba8d392016-05-02 03:18:34210 protected:
Tommi3176ef72022-05-22 18:47:28211 virtual ~AudioReceiveStreamInterface() {}
Fredrik Solenberg23fba1f2015-04-29 13:24:01212};
Tommi3176ef72022-05-22 18:47:28213
Fredrik Solenberg23fba1f2015-04-29 13:24:01214} // namespace webrtc
215
Mirko Bonadei92ea95e2017-09-15 04:47:31216#endif // CALL_AUDIO_RECEIVE_STREAM_H_