Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 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 <map> |
| 15 | #include <memory> |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 16 | #include <utility> |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
| 19 | #include "absl/types/optional.h" |
| 20 | #include "api/audio/audio_mixer.h" |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 21 | #include "api/audio_codecs/audio_decoder_factory.h" |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 22 | #include "api/call/audio_sink.h" |
| 23 | #include "api/call/transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 24 | #include "api/crypto/crypto_options.h" |
Marina Ciocea | 3e9af7f | 2020-04-01 07:46:16 +0200 | [diff] [blame] | 25 | #include "api/frame_transformer_interface.h" |
Ivo Creusen | c3d1f9b | 2019-11-01 11:47:51 +0100 | [diff] [blame] | 26 | #include "api/neteq/neteq_factory.h" |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 27 | #include "api/transport/rtp/rtp_source.h" |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 28 | #include "call/rtp_packet_sink_interface.h" |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 29 | #include "call/syncable.h" |
Niels Möller | ed44f54 | 2019-07-30 15:15:59 +0200 | [diff] [blame] | 30 | #include "modules/audio_coding/include/audio_coding_module_typedefs.h" |
Ranveer Aggarwal | dea374a | 2021-01-23 12:27:19 +0530 | [diff] [blame] | 31 | #include "modules/rtp_rtcp/source/source_tracker.h" |
Niels Möller | ed44f54 | 2019-07-30 15:15:59 +0200 | [diff] [blame] | 32 | #include "system_wrappers/include/clock.h" |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 33 | |
| 34 | // TODO(solenberg, nisse): This file contains a few NOLINT marks, to silence |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 35 | // warnings about use of unsigned short. |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 36 | // These need cleanup, in a separate cl. |
| 37 | |
| 38 | namespace rtc { |
| 39 | class TimestampWrapAroundHandler; |
| 40 | } |
| 41 | |
| 42 | namespace webrtc { |
| 43 | |
| 44 | class AudioDeviceModule; |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 45 | class FrameDecryptorInterface; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 46 | class PacketRouter; |
| 47 | class ProcessThread; |
| 48 | class RateLimiter; |
| 49 | class ReceiveStatistics; |
| 50 | class RtcEventLog; |
| 51 | class RtpPacketReceived; |
| 52 | class RtpRtcp; |
| 53 | |
| 54 | struct CallReceiveStatistics { |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 55 | unsigned int cumulativeLost; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 56 | unsigned int jitterSamples; |
| 57 | int64_t rttMs; |
Niels Möller | ac0a4cb | 2019-10-09 15:01:33 +0200 | [diff] [blame] | 58 | int64_t payload_bytes_rcvd = 0; |
| 59 | int64_t header_and_padding_bytes_rcvd = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 60 | int packetsReceived; |
Alessio Bazzica | f0adf38 | 2021-03-23 09:36:51 +0100 | [diff] [blame] | 61 | // The capture NTP time (in local timebase) of the first played out audio |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 62 | // frame. |
| 63 | int64_t capture_start_ntp_time_ms_; |
Henrik Boström | 01738c6 | 2019-04-15 17:32:00 +0200 | [diff] [blame] | 64 | // The timestamp at which the last packet was received, i.e. the time of the |
| 65 | // local clock when it was received - not the RTP timestamp of that packet. |
| 66 | // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp |
| 67 | absl::optional<int64_t> last_packet_received_timestamp_ms; |
Alessio Bazzica | bc1c93d | 2021-03-12 17:45:26 +0100 | [diff] [blame] | 68 | // Remote outbound stats derived by the received RTCP sender reports. |
Alessio Bazzica | f0adf38 | 2021-03-23 09:36:51 +0100 | [diff] [blame] | 69 | // Note that the timestamps below correspond to the time elapsed since the |
| 70 | // Unix epoch. |
Alessio Bazzica | bc1c93d | 2021-03-12 17:45:26 +0100 | [diff] [blame] | 71 | // https://w3c.github.io/webrtc-stats/#remoteoutboundrtpstats-dict* |
| 72 | absl::optional<int64_t> last_sender_report_timestamp_ms; |
| 73 | absl::optional<int64_t> last_sender_report_remote_timestamp_ms; |
| 74 | uint32_t sender_reports_packets_sent = 0; |
| 75 | uint64_t sender_reports_bytes_sent = 0; |
| 76 | uint64_t sender_reports_reports_count = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | namespace voe { |
| 80 | |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 81 | class ChannelSendInterface; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 82 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 83 | // Interface class needed for AudioReceiveStream tests that use a |
| 84 | // MockChannelReceive. |
| 85 | |
| 86 | class ChannelReceiveInterface : public RtpPacketSinkInterface { |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 87 | public: |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 88 | virtual ~ChannelReceiveInterface() = default; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 89 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 90 | virtual void SetSink(AudioSinkInterface* sink) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 91 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 92 | virtual void SetReceiveCodecs( |
| 93 | const std::map<int, SdpAudioFormat>& codecs) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 94 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 95 | virtual void StartPlayout() = 0; |
| 96 | virtual void StopPlayout() = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 97 | |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 98 | // Payload type and format of last received RTP packet, if any. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 99 | virtual absl::optional<std::pair<int, SdpAudioFormat>> GetReceiveCodec() |
| 100 | const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 101 | |
Niels Möller | 8fb1a6a | 2019-03-05 14:29:42 +0100 | [diff] [blame] | 102 | virtual void ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 103 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 104 | virtual void SetChannelOutputVolumeScaling(float scaling) = 0; |
| 105 | virtual int GetSpeechOutputLevelFullRange() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 106 | // See description of "totalAudioEnergy" in the WebRTC stats spec: |
| 107 | // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 108 | virtual double GetTotalOutputEnergy() const = 0; |
| 109 | virtual double GetTotalOutputDuration() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 110 | |
| 111 | // Stats. |
Niels Möller | 6b4d962 | 2020-09-14 10:47:50 +0200 | [diff] [blame] | 112 | virtual NetworkStatistics GetNetworkStatistics( |
| 113 | bool get_and_clear_legacy_stats) const = 0; |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 114 | virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 115 | |
| 116 | // Audio+Video Sync. |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 117 | virtual uint32_t GetDelayEstimate() const = 0; |
Ivo Creusen | bef7b05 | 2020-09-08 16:30:25 +0200 | [diff] [blame] | 118 | virtual bool SetMinimumPlayoutDelay(int delay_ms) = 0; |
Åsa Persson | fcf79cc | 2019-10-22 15:23:44 +0200 | [diff] [blame] | 119 | virtual bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp, |
| 120 | int64_t* time_ms) const = 0; |
| 121 | virtual void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms, |
| 122 | int64_t time_ms) = 0; |
| 123 | virtual absl::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs( |
| 124 | int64_t now_ms) const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 125 | |
Ruslan Burakov | 3b50f9f | 2019-02-06 09:45:56 +0100 | [diff] [blame] | 126 | // Audio quality. |
| 127 | // Base minimum delay sets lower bound on minimum delay value which |
| 128 | // determines minimum delay until audio playout. |
| 129 | virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0; |
| 130 | virtual int GetBaseMinimumPlayoutDelayMs() const = 0; |
| 131 | |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 132 | // Produces the transport-related timestamps; current_delay_ms is left unset. |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 133 | virtual absl::optional<Syncable::Info> GetSyncInfo() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 134 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 135 | virtual void RegisterReceiverCongestionControlObjects( |
| 136 | PacketRouter* packet_router) = 0; |
| 137 | virtual void ResetReceiverCongestionControlObjects() = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 138 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 139 | virtual CallReceiveStatistics GetRTCPStatistics() const = 0; |
| 140 | virtual void SetNACKStatus(bool enable, int max_packets) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 141 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 142 | virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo( |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 143 | int sample_rate_hz, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 144 | AudioFrame* audio_frame) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 145 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 146 | virtual int PreferredSampleRate() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 147 | |
Ranveer Aggarwal | dea374a | 2021-01-23 12:27:19 +0530 | [diff] [blame] | 148 | // Sets the source tracker to notify about "delivered" packets when output is |
| 149 | // muted. |
| 150 | virtual void SetSourceTracker(SourceTracker* source_tracker) = 0; |
| 151 | |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 152 | // Associate to a send channel. |
| 153 | // Used for obtaining RTT for a receive-only channel. |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 154 | virtual void SetAssociatedSendChannel( |
| 155 | const ChannelSendInterface* channel) = 0; |
Marina Ciocea | 3e9af7f | 2020-04-01 07:46:16 +0200 | [diff] [blame] | 156 | |
| 157 | // Sets a frame transformer between the depacketizer and the decoder, to |
| 158 | // transform the received frames before decoding them. |
| 159 | virtual void SetDepacketizerToDecoderFrameTransformer( |
| 160 | rtc::scoped_refptr<webrtc::FrameTransformerInterface> |
| 161 | frame_transformer) = 0; |
Tommi | e097282 | 2021-06-14 08:11:10 +0200 | [diff] [blame] | 162 | |
| 163 | virtual void SetFrameDecryptor( |
| 164 | rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor) = 0; |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame^] | 165 | |
| 166 | virtual void OnLocalSsrcChange(uint32_t local_ssrc) = 0; |
| 167 | virtual uint32_t GetLocalSsrc() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 168 | }; |
| 169 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 170 | std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive( |
Sebastian Jansson | 977b335 | 2019-03-04 17:43:34 +0100 | [diff] [blame] | 171 | Clock* clock, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 172 | ProcessThread* module_process_thread, |
Ivo Creusen | c3d1f9b | 2019-11-01 11:47:51 +0100 | [diff] [blame] | 173 | NetEqFactory* neteq_factory, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 174 | AudioDeviceModule* audio_device_module, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 175 | Transport* rtcp_send_transport, |
| 176 | RtcEventLog* rtc_event_log, |
Erik Språng | 70efdde | 2019-08-21 13:36:20 +0200 | [diff] [blame] | 177 | uint32_t local_ssrc, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 178 | uint32_t remote_ssrc, |
| 179 | size_t jitter_buffer_max_packets, |
| 180 | bool jitter_buffer_fast_playout, |
Jakob Ivarsson | 10403ae | 2018-11-27 15:45:20 +0100 | [diff] [blame] | 181 | int jitter_buffer_min_delay_ms, |
Jakob Ivarsson | 53eae87 | 2019-01-10 15:58:36 +0100 | [diff] [blame] | 182 | bool jitter_buffer_enable_rtx_handling, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 183 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory, |
| 184 | absl::optional<AudioCodecPairId> codec_pair_id, |
| 185 | rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor, |
Marina Ciocea | 3e9af7f | 2020-04-01 07:46:16 +0200 | [diff] [blame] | 186 | const webrtc::CryptoOptions& crypto_options, |
| 187 | rtc::scoped_refptr<FrameTransformerInterface> frame_transformer); |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 188 | |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 189 | } // namespace voe |
| 190 | } // namespace webrtc |
| 191 | |
| 192 | #endif // AUDIO_CHANNEL_RECEIVE_H_ |