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 11 #ifndef CALL_AUDIO_RECEIVE_STREAM_H_ 12 #define CALL_AUDIO_RECEIVE_STREAM_H_ 13 14 #include <map> 15 #include <memory> 16 #include <string> 17 #include <vector> 18 19 #include "absl/types/optional.h" 20 #include "api/audio_codecs/audio_decoder_factory.h" 21 #include "api/call/transport.h" 22 #include "api/crypto/crypto_options.h" 23 #include "api/rtp_parameters.h" 24 #include "call/receive_stream.h" 25 #include "call/rtp_config.h" 26 27 namespace webrtc { 28 class AudioSinkInterface; 29 30 class AudioReceiveStreamInterface : public MediaReceiveStreamInterface { 31 public: 32 struct Stats { 33 Stats(); 34 ~Stats(); 35 uint32_t remote_ssrc = 0; 36 int64_t payload_bytes_rcvd = 0; 37 int64_t header_and_padding_bytes_rcvd = 0; 38 uint32_t packets_rcvd = 0; 39 uint64_t fec_packets_received = 0; 40 uint64_t fec_packets_discarded = 0; 41 int32_t packets_lost = 0; 42 uint64_t packets_discarded = 0; 43 uint32_t nacks_sent = 0; 44 std::string codec_name; 45 absl::optional<int> codec_payload_type; 46 uint32_t jitter_ms = 0; 47 uint32_t jitter_buffer_ms = 0; 48 uint32_t jitter_buffer_preferred_ms = 0; 49 uint32_t delay_estimate_ms = 0; 50 int32_t audio_level = -1; 51 // Stats below correspond to similarly-named fields in the WebRTC stats 52 // spec. https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats 53 double total_output_energy = 0.0; 54 uint64_t total_samples_received = 0; 55 double total_output_duration = 0.0; 56 uint64_t concealed_samples = 0; 57 uint64_t silent_concealed_samples = 0; 58 uint64_t concealment_events = 0; 59 double jitter_buffer_delay_seconds = 0.0; 60 uint64_t jitter_buffer_emitted_count = 0; 61 double jitter_buffer_target_delay_seconds = 0.0; 62 double jitter_buffer_minimum_delay_seconds = 0.0; 63 uint64_t inserted_samples_for_deceleration = 0; 64 uint64_t removed_samples_for_acceleration = 0; 65 // Stats below DO NOT correspond directly to anything in the WebRTC stats 66 float expand_rate = 0.0f; 67 float speech_expand_rate = 0.0f; 68 float secondary_decoded_rate = 0.0f; 69 float secondary_discarded_rate = 0.0f; 70 float accelerate_rate = 0.0f; 71 float preemptive_expand_rate = 0.0f; 72 uint64_t delayed_packet_outage_samples = 0; 73 int32_t decoding_calls_to_silence_generator = 0; 74 int32_t decoding_calls_to_neteq = 0; 75 int32_t decoding_normal = 0; 76 // TODO(alexnarest): Consider decoding_neteq_plc for consistency 77 int32_t decoding_plc = 0; 78 int32_t decoding_codec_plc = 0; 79 int32_t decoding_cng = 0; 80 int32_t decoding_plc_cng = 0; 81 int32_t decoding_muted_output = 0; 82 int64_t capture_start_ntp_time_ms = 0; 83 // The timestamp at which the last packet was received, i.e. the time of the 84 // local clock when it was received - not the RTP timestamp of that packet. 85 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp 86 absl::optional<int64_t> last_packet_received_timestamp_ms; 87 uint64_t jitter_buffer_flushes = 0; 88 double relative_packet_arrival_delay_seconds = 0.0; 89 int32_t interruption_count = 0; 90 int32_t total_interruption_duration_ms = 0; 91 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp 92 absl::optional<int64_t> estimated_playout_ntp_timestamp_ms; 93 // Remote outbound stats derived by the received RTCP sender reports. 94 // https://w3c.github.io/webrtc-stats/#remoteoutboundrtpstats-dict* 95 absl::optional<int64_t> last_sender_report_timestamp_ms; 96 absl::optional<int64_t> last_sender_report_remote_timestamp_ms; 97 uint32_t sender_reports_packets_sent = 0; 98 uint64_t sender_reports_bytes_sent = 0; 99 uint64_t sender_reports_reports_count = 0; 100 absl::optional<TimeDelta> round_trip_time; 101 TimeDelta total_round_trip_time = TimeDelta::Zero(); 102 int round_trip_time_measurements; 103 }; 104 105 struct Config { 106 Config(); 107 ~Config(); 108 109 std::string ToString() const; 110 111 // Receive-stream specific RTP settings. 112 struct Rtp : public ReceiveStreamRtpConfig { 113 Rtp(); 114 ~Rtp(); 115 116 std::string ToString() const; 117 118 // See NackConfig for description. 119 NackConfig nack; 120 } rtp; 121 122 // Receive-side RTT. 123 bool enable_non_sender_rtt = false; 124 125 Transport* rtcp_send_transport = nullptr; 126 127 // NetEq settings. 128 size_t jitter_buffer_max_packets = 200; 129 bool jitter_buffer_fast_accelerate = false; 130 int jitter_buffer_min_delay_ms = 0; 131 132 // Identifier for an A/V synchronization group. Empty string to disable. 133 // TODO(pbos): Synchronize streams in a sync group, not just one video 134 // stream to one audio stream. Tracked by issue webrtc:4762. 135 std::string sync_group; 136 137 // Decoder specifications for every payload type that we can receive. 138 std::map<int, SdpAudioFormat> decoder_map; 139 140 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory; 141 142 absl::optional<AudioCodecPairId> codec_pair_id; 143 144 // Per PeerConnection crypto options. 145 webrtc::CryptoOptions crypto_options; 146 147 // An optional custom frame decryptor that allows the entire frame to be 148 // decrypted in whatever way the caller choses. This is not required by 149 // default. 150 // TODO(tommi): Remove this member variable from the struct. It's not 151 // a part of the AudioReceiveStreamInterface state but rather a pass through 152 // variable. 153 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor; 154 155 // An optional frame transformer used by insertable streams to transform 156 // encoded frames. 157 // TODO(tommi): Remove this member variable from the struct. It's not 158 // a part of the AudioReceiveStreamInterface state but rather a pass through 159 // variable. 160 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer; 161 }; 162 163 // Methods that support reconfiguring the stream post initialization. 164 virtual void SetDecoderMap(std::map<int, SdpAudioFormat> decoder_map) = 0; 165 virtual void SetNackHistory(int history_ms) = 0; 166 virtual void SetNonSenderRttMeasurement(bool enabled) = 0; 167 168 // Returns true if the stream has been started. 169 virtual bool IsRunning() const = 0; 170 171 virtual Stats GetStats(bool get_and_clear_legacy_stats) const = 0; GetStats()172 Stats GetStats() { return GetStats(/*get_and_clear_legacy_stats=*/true); } 173 174 // Sets an audio sink that receives unmixed audio from the receive stream. 175 // Ownership of the sink is managed by the caller. 176 // Only one sink can be set and passing a null sink clears an existing one. 177 // NOTE: Audio must still somehow be pulled through AudioTransport for audio 178 // to stream through this sink. In practice, this happens if mixed audio 179 // is being pulled+rendered and/or if audio is being pulled for the purposes 180 // of feeding to the AEC. 181 virtual void SetSink(AudioSinkInterface* sink) = 0; 182 183 // Sets playback gain of the stream, applied when mixing, and thus after it 184 // is potentially forwarded to any attached AudioSinkInterface implementation. 185 virtual void SetGain(float gain) = 0; 186 187 // Sets a base minimum for the playout delay. Base minimum delay sets lower 188 // bound on minimum delay value determining lower bound on playout delay. 189 // 190 // Returns true if value was successfully set, false overwise. 191 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0; 192 193 // Returns current value of base minimum delay in milliseconds. 194 virtual int GetBaseMinimumPlayoutDelayMs() const = 0; 195 196 // Synchronization source (stream identifier) to be received. 197 // This member will not change mid-stream and can be assumed to be const 198 // post initialization. 199 virtual uint32_t remote_ssrc() const = 0; 200 201 // Access the currently set rtp extensions. Must be called on the packet 202 // delivery thread. 203 // TODO(tommi): This is currently only called from 204 // `WebRtcAudioReceiveStream::GetRtpParameters()`. See if we can remove it. 205 virtual const std::vector<RtpExtension>& GetRtpExtensions() const = 0; 206 207 protected: ~AudioReceiveStreamInterface()208 virtual ~AudioReceiveStreamInterface() {} 209 }; 210 211 } // namespace webrtc 212 213 #endif // CALL_AUDIO_RECEIVE_STREAM_H_ 214