blob: 32bc813cc50fd45eb17b89c9f1755c46ca7426d8 [file] [log] [blame]
Niels Möller530ead42018-10-04 14:28:39 +02001/*
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 12:22:10 +010016#include <utility>
Niels Möller530ead42018-10-04 14:28:39 +020017#include <vector>
18
19#include "absl/types/optional.h"
20#include "api/audio/audio_mixer.h"
Niels Möller349ade32018-11-16 09:50:42 +010021#include "api/audio_codecs/audio_decoder_factory.h"
Niels Möller530ead42018-10-04 14:28:39 +020022#include "api/call/audio_sink.h"
23#include "api/call/transport.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "api/crypto/crypto_options.h"
Marina Ciocea3e9af7f2020-04-01 07:46:16 +020025#include "api/frame_transformer_interface.h"
Ivo Creusenc3d1f9b2019-11-01 11:47:51 +010026#include "api/neteq/neteq_factory.h"
Niels Möllera8370302019-09-02 15:16:49 +020027#include "api/transport/rtp/rtp_source.h"
Niels Möller349ade32018-11-16 09:50:42 +010028#include "call/rtp_packet_sink_interface.h"
Niels Möller530ead42018-10-04 14:28:39 +020029#include "call/syncable.h"
Niels Möllered44f542019-07-30 15:15:59 +020030#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
Ranveer Aggarwaldea374a2021-01-23 12:27:19 +053031#include "modules/rtp_rtcp/source/source_tracker.h"
Niels Möllered44f542019-07-30 15:15:59 +020032#include "system_wrappers/include/clock.h"
Niels Möller530ead42018-10-04 14:28:39 +020033
34// TODO(solenberg, nisse): This file contains a few NOLINT marks, to silence
Niels Möller349ade32018-11-16 09:50:42 +010035// warnings about use of unsigned short.
Niels Möller530ead42018-10-04 14:28:39 +020036// These need cleanup, in a separate cl.
37
38namespace rtc {
39class TimestampWrapAroundHandler;
40}
41
42namespace webrtc {
43
44class AudioDeviceModule;
Benjamin Wright84583f62018-10-04 14:22:34 -070045class FrameDecryptorInterface;
Niels Möller530ead42018-10-04 14:28:39 +020046class PacketRouter;
47class ProcessThread;
48class RateLimiter;
49class ReceiveStatistics;
50class RtcEventLog;
51class RtpPacketReceived;
52class RtpRtcp;
53
54struct CallReceiveStatistics {
Niels Möller530ead42018-10-04 14:28:39 +020055 unsigned int cumulativeLost;
Niels Möller530ead42018-10-04 14:28:39 +020056 unsigned int jitterSamples;
57 int64_t rttMs;
Niels Möllerac0a4cb2019-10-09 15:01:33 +020058 int64_t payload_bytes_rcvd = 0;
59 int64_t header_and_padding_bytes_rcvd = 0;
Niels Möller530ead42018-10-04 14:28:39 +020060 int packetsReceived;
61 // The capture ntp time (in local timebase) of the first played out audio
62 // frame.
63 int64_t capture_start_ntp_time_ms_;
Henrik Boström01738c62019-04-15 17:32:00 +020064 // 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;
Niels Möller530ead42018-10-04 14:28:39 +020068};
69
70namespace voe {
71
Niels Möllerdced9f62018-11-19 10:27:07 +010072class ChannelSendInterface;
Niels Möller530ead42018-10-04 14:28:39 +020073
Niels Möller349ade32018-11-16 09:50:42 +010074// Interface class needed for AudioReceiveStream tests that use a
75// MockChannelReceive.
76
77class ChannelReceiveInterface : public RtpPacketSinkInterface {
Niels Möller530ead42018-10-04 14:28:39 +020078 public:
Niels Möller349ade32018-11-16 09:50:42 +010079 virtual ~ChannelReceiveInterface() = default;
Niels Möller530ead42018-10-04 14:28:39 +020080
Niels Möller349ade32018-11-16 09:50:42 +010081 virtual void SetSink(AudioSinkInterface* sink) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020082
Niels Möller349ade32018-11-16 09:50:42 +010083 virtual void SetReceiveCodecs(
84 const std::map<int, SdpAudioFormat>& codecs) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020085
Niels Möller349ade32018-11-16 09:50:42 +010086 virtual void StartPlayout() = 0;
87 virtual void StopPlayout() = 0;
Niels Möller530ead42018-10-04 14:28:39 +020088
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +010089 // Payload type and format of last received RTP packet, if any.
Jonas Olssona4d87372019-07-05 19:08:33 +020090 virtual absl::optional<std::pair<int, SdpAudioFormat>> GetReceiveCodec()
91 const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020092
Niels Möller8fb1a6a2019-03-05 14:29:42 +010093 virtual void ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020094
Niels Möller349ade32018-11-16 09:50:42 +010095 virtual void SetChannelOutputVolumeScaling(float scaling) = 0;
96 virtual int GetSpeechOutputLevelFullRange() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020097 // See description of "totalAudioEnergy" in the WebRTC stats spec:
98 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Niels Möller349ade32018-11-16 09:50:42 +010099 virtual double GetTotalOutputEnergy() const = 0;
100 virtual double GetTotalOutputDuration() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200101
102 // Stats.
Niels Möller6b4d9622020-09-14 10:47:50 +0200103 virtual NetworkStatistics GetNetworkStatistics(
104 bool get_and_clear_legacy_stats) const = 0;
Niels Möller349ade32018-11-16 09:50:42 +0100105 virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200106
107 // Audio+Video Sync.
Niels Möller349ade32018-11-16 09:50:42 +0100108 virtual uint32_t GetDelayEstimate() const = 0;
Ivo Creusenbef7b052020-09-08 16:30:25 +0200109 virtual bool SetMinimumPlayoutDelay(int delay_ms) = 0;
Åsa Perssonfcf79cc2019-10-22 15:23:44 +0200110 virtual bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
111 int64_t* time_ms) const = 0;
112 virtual void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
113 int64_t time_ms) = 0;
114 virtual absl::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs(
115 int64_t now_ms) const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200116
Ruslan Burakov3b50f9f2019-02-06 09:45:56 +0100117 // Audio quality.
118 // Base minimum delay sets lower bound on minimum delay value which
119 // determines minimum delay until audio playout.
120 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
121 virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
122
Niels Möller530ead42018-10-04 14:28:39 +0200123 // Produces the transport-related timestamps; current_delay_ms is left unset.
Niels Möller349ade32018-11-16 09:50:42 +0100124 virtual absl::optional<Syncable::Info> GetSyncInfo() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200125
Niels Möller349ade32018-11-16 09:50:42 +0100126 virtual void RegisterReceiverCongestionControlObjects(
127 PacketRouter* packet_router) = 0;
128 virtual void ResetReceiverCongestionControlObjects() = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200129
Niels Möller349ade32018-11-16 09:50:42 +0100130 virtual CallReceiveStatistics GetRTCPStatistics() const = 0;
131 virtual void SetNACKStatus(bool enable, int max_packets) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200132
Niels Möller349ade32018-11-16 09:50:42 +0100133 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
Niels Möller530ead42018-10-04 14:28:39 +0200134 int sample_rate_hz,
Niels Möller349ade32018-11-16 09:50:42 +0100135 AudioFrame* audio_frame) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200136
Niels Möller349ade32018-11-16 09:50:42 +0100137 virtual int PreferredSampleRate() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200138
Ranveer Aggarwaldea374a2021-01-23 12:27:19 +0530139 // Sets the source tracker to notify about "delivered" packets when output is
140 // muted.
141 virtual void SetSourceTracker(SourceTracker* source_tracker) = 0;
142
Niels Möller530ead42018-10-04 14:28:39 +0200143 // Associate to a send channel.
144 // Used for obtaining RTT for a receive-only channel.
Niels Möllerdced9f62018-11-19 10:27:07 +0100145 virtual void SetAssociatedSendChannel(
146 const ChannelSendInterface* channel) = 0;
Marina Ciocea3e9af7f2020-04-01 07:46:16 +0200147
148 // Sets a frame transformer between the depacketizer and the decoder, to
149 // transform the received frames before decoding them.
150 virtual void SetDepacketizerToDecoderFrameTransformer(
151 rtc::scoped_refptr<webrtc::FrameTransformerInterface>
152 frame_transformer) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200153};
154
Niels Möller349ade32018-11-16 09:50:42 +0100155std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive(
Sebastian Jansson977b3352019-03-04 17:43:34 +0100156 Clock* clock,
Niels Möller349ade32018-11-16 09:50:42 +0100157 ProcessThread* module_process_thread,
Ivo Creusenc3d1f9b2019-11-01 11:47:51 +0100158 NetEqFactory* neteq_factory,
Niels Möller349ade32018-11-16 09:50:42 +0100159 AudioDeviceModule* audio_device_module,
Niels Möller349ade32018-11-16 09:50:42 +0100160 Transport* rtcp_send_transport,
161 RtcEventLog* rtc_event_log,
Erik Språng70efdde2019-08-21 13:36:20 +0200162 uint32_t local_ssrc,
Niels Möller349ade32018-11-16 09:50:42 +0100163 uint32_t remote_ssrc,
164 size_t jitter_buffer_max_packets,
165 bool jitter_buffer_fast_playout,
Jakob Ivarsson10403ae2018-11-27 15:45:20 +0100166 int jitter_buffer_min_delay_ms,
Jakob Ivarsson53eae872019-01-10 15:58:36 +0100167 bool jitter_buffer_enable_rtx_handling,
Niels Möller349ade32018-11-16 09:50:42 +0100168 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
169 absl::optional<AudioCodecPairId> codec_pair_id,
170 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor,
Marina Ciocea3e9af7f2020-04-01 07:46:16 +0200171 const webrtc::CryptoOptions& crypto_options,
172 rtc::scoped_refptr<FrameTransformerInterface> frame_transformer);
Niels Möller349ade32018-11-16 09:50:42 +0100173
Niels Möller530ead42018-10-04 14:28:39 +0200174} // namespace voe
175} // namespace webrtc
176
177#endif // AUDIO_CHANNEL_RECEIVE_H_