blob: ae9cd59db836909b6ff82f267b69ede658881145 [file] [log] [blame]
Niels Möller530ead42018-10-04 12:28:391/*
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 Solenbergf693bfa2018-12-11 11:22:1016#include <utility>
Niels Möller530ead42018-10-04 12:28:3917#include <vector>
18
19#include "absl/types/optional.h"
20#include "api/audio/audio_mixer.h"
Niels Möller349ade32018-11-16 08:50:4221#include "api/audio_codecs/audio_decoder_factory.h"
Niels Möller530ead42018-10-04 12:28:3922#include "api/call/audio_sink.h"
23#include "api/call/transport.h"
Steve Anton10542f22019-01-11 17:11:0024#include "api/crypto/crypto_options.h"
Marina Ciocea3e9af7f2020-04-01 05:46:1625#include "api/frame_transformer_interface.h"
Ivo Creusenc3d1f9b2019-11-01 10:47:5126#include "api/neteq/neteq_factory.h"
Niels Möllera8370302019-09-02 13:16:4927#include "api/transport/rtp/rtp_source.h"
Niels Möller349ade32018-11-16 08:50:4228#include "call/rtp_packet_sink_interface.h"
Niels Möller530ead42018-10-04 12:28:3929#include "call/syncable.h"
Niels Möllered44f542019-07-30 13:15:5930#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
Ranveer Aggarwaldea374a2021-01-23 06:57:1931#include "modules/rtp_rtcp/source/source_tracker.h"
Niels Möllered44f542019-07-30 13:15:5932#include "system_wrappers/include/clock.h"
Niels Möller530ead42018-10-04 12:28:3933
34// TODO(solenberg, nisse): This file contains a few NOLINT marks, to silence
Niels Möller349ade32018-11-16 08:50:4235// warnings about use of unsigned short.
Niels Möller530ead42018-10-04 12:28:3936// These need cleanup, in a separate cl.
37
38namespace rtc {
39class TimestampWrapAroundHandler;
40}
41
42namespace webrtc {
43
44class AudioDeviceModule;
Benjamin Wright84583f62018-10-04 21:22:3445class FrameDecryptorInterface;
Niels Möller530ead42018-10-04 12:28:3946class PacketRouter;
Niels Möller530ead42018-10-04 12:28:3947class RateLimiter;
48class ReceiveStatistics;
49class RtcEventLog;
50class RtpPacketReceived;
51class RtpRtcp;
52
53struct CallReceiveStatistics {
Niels Möller530ead42018-10-04 12:28:3954 unsigned int cumulativeLost;
Niels Möller530ead42018-10-04 12:28:3955 unsigned int jitterSamples;
56 int64_t rttMs;
Niels Möllerac0a4cb2019-10-09 13:01:3357 int64_t payload_bytes_rcvd = 0;
58 int64_t header_and_padding_bytes_rcvd = 0;
Niels Möller530ead42018-10-04 12:28:3959 int packetsReceived;
Jakob Ivarssone54914a2021-07-01 09:16:0560 uint32_t nacks_sent = 0;
Alessio Bazzicaf0adf382021-03-23 08:36:5161 // The capture NTP time (in local timebase) of the first played out audio
Niels Möller530ead42018-10-04 12:28:3962 // frame.
63 int64_t capture_start_ntp_time_ms_;
Henrik Boström01738c62019-04-15 15:32:0064 // 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 Bazzicabc1c93d2021-03-12 16:45:2668 // Remote outbound stats derived by the received RTCP sender reports.
Alessio Bazzicaf0adf382021-03-23 08:36:5169 // Note that the timestamps below correspond to the time elapsed since the
70 // Unix epoch.
Alessio Bazzicabc1c93d2021-03-12 16:45:2671 // 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;
Ivo Creusen2562cf02021-09-03 14:51:2277 absl::optional<TimeDelta> round_trip_time;
78 TimeDelta total_round_trip_time = TimeDelta::Zero();
79 int round_trip_time_measurements;
Niels Möller530ead42018-10-04 12:28:3980};
81
82namespace voe {
83
Niels Möllerdced9f62018-11-19 09:27:0784class ChannelSendInterface;
Niels Möller530ead42018-10-04 12:28:3985
Tommi3176ef72022-05-22 18:47:2886// Interface class needed for AudioReceiveStreamInterface tests that use a
Niels Möller349ade32018-11-16 08:50:4287// MockChannelReceive.
88
89class ChannelReceiveInterface : public RtpPacketSinkInterface {
Niels Möller530ead42018-10-04 12:28:3990 public:
Niels Möller349ade32018-11-16 08:50:4291 virtual ~ChannelReceiveInterface() = default;
Niels Möller530ead42018-10-04 12:28:3992
Niels Möller349ade32018-11-16 08:50:4293 virtual void SetSink(AudioSinkInterface* sink) = 0;
Niels Möller530ead42018-10-04 12:28:3994
Niels Möller349ade32018-11-16 08:50:4295 virtual void SetReceiveCodecs(
96 const std::map<int, SdpAudioFormat>& codecs) = 0;
Niels Möller530ead42018-10-04 12:28:3997
Niels Möller349ade32018-11-16 08:50:4298 virtual void StartPlayout() = 0;
99 virtual void StopPlayout() = 0;
Niels Möller530ead42018-10-04 12:28:39100
Fredrik Solenbergf693bfa2018-12-11 11:22:10101 // Payload type and format of last received RTP packet, if any.
Jonas Olssona4d87372019-07-05 17:08:33102 virtual absl::optional<std::pair<int, SdpAudioFormat>> GetReceiveCodec()
103 const = 0;
Niels Möller530ead42018-10-04 12:28:39104
Niels Möller8fb1a6a2019-03-05 13:29:42105 virtual void ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0;
Niels Möller530ead42018-10-04 12:28:39106
Niels Möller349ade32018-11-16 08:50:42107 virtual void SetChannelOutputVolumeScaling(float scaling) = 0;
108 virtual int GetSpeechOutputLevelFullRange() const = 0;
Niels Möller530ead42018-10-04 12:28:39109 // See description of "totalAudioEnergy" in the WebRTC stats spec:
110 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Niels Möller349ade32018-11-16 08:50:42111 virtual double GetTotalOutputEnergy() const = 0;
112 virtual double GetTotalOutputDuration() const = 0;
Niels Möller530ead42018-10-04 12:28:39113
114 // Stats.
Niels Möller6b4d9622020-09-14 08:47:50115 virtual NetworkStatistics GetNetworkStatistics(
116 bool get_and_clear_legacy_stats) const = 0;
Niels Möller349ade32018-11-16 08:50:42117 virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0;
Niels Möller530ead42018-10-04 12:28:39118
119 // Audio+Video Sync.
Niels Möller349ade32018-11-16 08:50:42120 virtual uint32_t GetDelayEstimate() const = 0;
Ivo Creusenbef7b052020-09-08 14:30:25121 virtual bool SetMinimumPlayoutDelay(int delay_ms) = 0;
Åsa Perssonfcf79cc2019-10-22 13:23:44122 virtual bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
123 int64_t* time_ms) const = 0;
124 virtual void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
125 int64_t time_ms) = 0;
126 virtual absl::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs(
127 int64_t now_ms) const = 0;
Niels Möller530ead42018-10-04 12:28:39128
Ruslan Burakov3b50f9f2019-02-06 08:45:56129 // Audio quality.
130 // Base minimum delay sets lower bound on minimum delay value which
131 // determines minimum delay until audio playout.
132 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
133 virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
134
Niels Möller530ead42018-10-04 12:28:39135 // Produces the transport-related timestamps; current_delay_ms is left unset.
Niels Möller349ade32018-11-16 08:50:42136 virtual absl::optional<Syncable::Info> GetSyncInfo() const = 0;
Niels Möller530ead42018-10-04 12:28:39137
Niels Möller349ade32018-11-16 08:50:42138 virtual void RegisterReceiverCongestionControlObjects(
139 PacketRouter* packet_router) = 0;
140 virtual void ResetReceiverCongestionControlObjects() = 0;
Niels Möller530ead42018-10-04 12:28:39141
Niels Möller349ade32018-11-16 08:50:42142 virtual CallReceiveStatistics GetRTCPStatistics() const = 0;
143 virtual void SetNACKStatus(bool enable, int max_packets) = 0;
Ivo Creusen2562cf02021-09-03 14:51:22144 virtual void SetNonSenderRttMeasurement(bool enabled) = 0;
Niels Möller530ead42018-10-04 12:28:39145
Niels Möller349ade32018-11-16 08:50:42146 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
Niels Möller530ead42018-10-04 12:28:39147 int sample_rate_hz,
Niels Möller349ade32018-11-16 08:50:42148 AudioFrame* audio_frame) = 0;
Niels Möller530ead42018-10-04 12:28:39149
Niels Möller349ade32018-11-16 08:50:42150 virtual int PreferredSampleRate() const = 0;
Niels Möller530ead42018-10-04 12:28:39151
Ranveer Aggarwaldea374a2021-01-23 06:57:19152 // Sets the source tracker to notify about "delivered" packets when output is
153 // muted.
154 virtual void SetSourceTracker(SourceTracker* source_tracker) = 0;
155
Niels Möller530ead42018-10-04 12:28:39156 // Associate to a send channel.
157 // Used for obtaining RTT for a receive-only channel.
Niels Möllerdced9f62018-11-19 09:27:07158 virtual void SetAssociatedSendChannel(
159 const ChannelSendInterface* channel) = 0;
Marina Ciocea3e9af7f2020-04-01 05:46:16160
161 // Sets a frame transformer between the depacketizer and the decoder, to
162 // transform the received frames before decoding them.
163 virtual void SetDepacketizerToDecoderFrameTransformer(
164 rtc::scoped_refptr<webrtc::FrameTransformerInterface>
165 frame_transformer) = 0;
Tommie0972822021-06-14 06:11:10166
167 virtual void SetFrameDecryptor(
168 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor) = 0;
Tommi08be9ba2021-06-15 21:01:57169
170 virtual void OnLocalSsrcChange(uint32_t local_ssrc) = 0;
171 virtual uint32_t GetLocalSsrc() const = 0;
Niels Möller530ead42018-10-04 12:28:39172};
173
Niels Möller349ade32018-11-16 08:50:42174std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive(
Sebastian Jansson977b3352019-03-04 16:43:34175 Clock* clock,
Ivo Creusenc3d1f9b2019-11-01 10:47:51176 NetEqFactory* neteq_factory,
Niels Möller349ade32018-11-16 08:50:42177 AudioDeviceModule* audio_device_module,
Niels Möller349ade32018-11-16 08:50:42178 Transport* rtcp_send_transport,
179 RtcEventLog* rtc_event_log,
Erik Språng70efdde2019-08-21 11:36:20180 uint32_t local_ssrc,
Niels Möller349ade32018-11-16 08:50:42181 uint32_t remote_ssrc,
182 size_t jitter_buffer_max_packets,
183 bool jitter_buffer_fast_playout,
Jakob Ivarsson10403ae2018-11-27 14:45:20184 int jitter_buffer_min_delay_ms,
Ivo Creusen2562cf02021-09-03 14:51:22185 bool enable_non_sender_rtt,
Niels Möller349ade32018-11-16 08:50:42186 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
187 absl::optional<AudioCodecPairId> codec_pair_id,
188 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor,
Marina Ciocea3e9af7f2020-04-01 05:46:16189 const webrtc::CryptoOptions& crypto_options,
190 rtc::scoped_refptr<FrameTransformerInterface> frame_transformer);
Niels Möller349ade32018-11-16 08:50:42191
Niels Möller530ead42018-10-04 12:28:39192} // namespace voe
193} // namespace webrtc
194
195#endif // AUDIO_CHANNEL_RECEIVE_H_