channel_receive.h (7429B)
1 /* 2 * Copyright (c) 2012 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 AUDIO_CHANNEL_RECEIVE_H_ 12 #define AUDIO_CHANNEL_RECEIVE_H_ 13 14 #include <cstddef> 15 #include <cstdint> 16 #include <map> 17 #include <memory> 18 #include <optional> 19 #include <utility> 20 #include <vector> 21 22 #include "api/audio/audio_frame.h" 23 #include "api/audio/audio_mixer.h" 24 #include "api/audio_codecs/audio_codec_pair_id.h" 25 #include "api/audio_codecs/audio_decoder_factory.h" 26 #include "api/audio_codecs/audio_format.h" 27 #include "api/call/audio_sink.h" 28 #include "api/call/transport.h" 29 #include "api/crypto/crypto_options.h" 30 #include "api/crypto/frame_decryptor_interface.h" 31 #include "api/environment/environment.h" 32 #include "api/frame_transformer_interface.h" 33 #include "api/neteq/neteq_factory.h" 34 #include "api/rtp_headers.h" 35 #include "api/scoped_refptr.h" 36 #include "api/transport/rtp/rtp_source.h" 37 #include "api/units/time_delta.h" 38 #include "api/units/timestamp.h" 39 #include "call/rtp_packet_sink_interface.h" 40 #include "call/syncable.h" 41 #include "modules/audio_coding/include/audio_coding_module_typedefs.h" 42 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" 43 #include "system_wrappers/include/ntp_time.h" 44 45 namespace webrtc { 46 47 class AudioDeviceModule; 48 class PacketRouter; 49 class RateLimiter; 50 class ReceiveStatistics; 51 class RtpPacketReceived; 52 class RtpRtcp; 53 54 struct ChannelReceiveStatistics { 55 int packets_lost = 0; 56 uint32_t jitter_ms = 0; 57 int64_t payload_bytes_received = 0; 58 int64_t header_and_padding_bytes_received = 0; 59 int packets_received = 0; 60 // https://w3c.github.io/webrtc-stats/#dom-rtcreceivedrtpstreamstats-packetsreceivedwithect1 61 int64_t packets_received_with_ect1 = 0; 62 // https://w3c.github.io/webrtc-stats/#dom-rtcreceivedrtpstreamstats-packetsreceivedwithce 63 int64_t packets_received_with_ce = 0; 64 uint32_t nacks_sent = 0; 65 // The capture NTP time (in local timebase) of the first played out audio 66 // frame. 67 int64_t capture_start_ntp_time_ms = 0; 68 // The timestamp at which the last packet was received, i.e. the time of the 69 // local clock when it was received - not the RTP timestamp of that packet. 70 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp 71 std::optional<Timestamp> last_packet_received; 72 // Remote outbound stats derived by the received RTCP sender reports. 73 // Note that the timestamps below correspond to the time elapsed since the 74 // Unix epoch. 75 // https://w3c.github.io/webrtc-stats/#remoteoutboundrtpstats-dict* 76 std::optional<Timestamp> last_sender_report_timestamp; 77 // TODO: bugs.webrtc.org/370535296 - Remove the utc timestamp when linked 78 // issue is fixed. 79 std::optional<Timestamp> last_sender_report_utc_timestamp; 80 std::optional<Timestamp> last_sender_report_remote_utc_timestamp; 81 uint64_t sender_reports_packets_sent = 0; 82 uint64_t sender_reports_bytes_sent = 0; 83 uint64_t sender_reports_reports_count = 0; 84 std::optional<TimeDelta> round_trip_time; 85 TimeDelta total_round_trip_time = TimeDelta::Zero(); 86 int round_trip_time_measurements = 0; 87 }; 88 89 namespace voe { 90 91 class ChannelSendInterface; 92 93 // Interface class needed for AudioReceiveStreamInterface tests that use a 94 // MockChannelReceive. 95 96 class ChannelReceiveInterface : public RtpPacketSinkInterface { 97 public: 98 virtual ~ChannelReceiveInterface() = default; 99 100 virtual void SetSink(AudioSinkInterface* sink) = 0; 101 102 virtual void SetReceiveCodecs( 103 const std::map<int, SdpAudioFormat>& codecs) = 0; 104 105 virtual void StartPlayout() = 0; 106 virtual void StopPlayout() = 0; 107 108 // Payload type and format of last received RTP packet, if any. 109 virtual std::optional<std::pair<int, SdpAudioFormat>> GetReceiveCodec() 110 const = 0; 111 112 virtual void ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0; 113 114 virtual void SetChannelOutputVolumeScaling(float scaling) = 0; 115 virtual int GetSpeechOutputLevelFullRange() const = 0; 116 // See description of "totalAudioEnergy" in the WebRTC stats spec: 117 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy 118 virtual double GetTotalOutputEnergy() const = 0; 119 virtual double GetTotalOutputDuration() const = 0; 120 121 // Stats. 122 virtual NetworkStatistics GetNetworkStatistics( 123 bool get_and_clear_legacy_stats) const = 0; 124 virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0; 125 126 // Audio+Video Sync. 127 virtual uint32_t GetDelayEstimate() const = 0; 128 virtual bool SetMinimumPlayoutDelay(TimeDelta delay) = 0; 129 virtual std::optional<Syncable::PlayoutInfo> GetPlayoutRtpTimestamp() 130 const = 0; 131 virtual void SetEstimatedPlayoutNtpTimestamp(NtpTime ntp_time, 132 Timestamp time) = 0; 133 virtual std::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs( 134 int64_t now_ms) const = 0; 135 136 // Audio quality. 137 // Base minimum delay sets lower bound on minimum delay value which 138 // determines minimum delay until audio playout. 139 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0; 140 virtual int GetBaseMinimumPlayoutDelayMs() const = 0; 141 142 // Produces the transport-related timestamps; current_delay_ms is left unset. 143 virtual std::optional<Syncable::Info> GetSyncInfo() const = 0; 144 145 virtual void RegisterReceiverCongestionControlObjects( 146 PacketRouter* packet_router) = 0; 147 virtual void ResetReceiverCongestionControlObjects() = 0; 148 149 virtual ChannelReceiveStatistics GetRTCPStatistics() const = 0; 150 virtual void SetNACKStatus(bool enable, int max_packets) = 0; 151 virtual void SetRtcpMode(webrtc::RtcpMode mode) = 0; 152 virtual void SetNonSenderRttMeasurement(bool enabled) = 0; 153 154 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo( 155 int sample_rate_hz, 156 AudioFrame* audio_frame) = 0; 157 158 virtual int PreferredSampleRate() const = 0; 159 160 virtual std::vector<RtpSource> GetSources() const = 0; 161 162 // Sets a frame transformer between the depacketizer and the decoder, to 163 // transform the received frames before decoding them. 164 virtual void SetDepacketizerToDecoderFrameTransformer( 165 scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer) = 0; 166 167 virtual void SetFrameDecryptor( 168 scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor) = 0; 169 170 virtual void OnLocalSsrcChange(uint32_t local_ssrc) = 0; 171 }; 172 173 std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive( 174 const Environment& env, 175 NetEqFactory* neteq_factory, 176 AudioDeviceModule* audio_device_module, 177 Transport* rtcp_send_transport, 178 uint32_t local_ssrc, 179 uint32_t remote_ssrc, 180 size_t jitter_buffer_max_packets, 181 bool jitter_buffer_fast_playout, 182 int jitter_buffer_min_delay_ms, 183 bool enable_non_sender_rtt, 184 scoped_refptr<AudioDecoderFactory> decoder_factory, 185 std::optional<AudioCodecPairId> codec_pair_id, 186 scoped_refptr<FrameDecryptorInterface> frame_decryptor, 187 const webrtc::CryptoOptions& crypto_options, 188 scoped_refptr<FrameTransformerInterface> frame_transformer, 189 RtcpEventObserver* rtcp_event_observer); 190 191 } // namespace voe 192 } // namespace webrtc 193 194 #endif // AUDIO_CHANNEL_RECEIVE_H_