blob: 1e16304fa0679b71251dfdc9283434cd86dee36b [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"
Anton Sukhanov4f08faa2019-05-21 11:12:57 -070025#include "api/media_transport_config.h"
Niels Möller7d76a312018-10-26 12:57:07 +020026#include "api/media_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "api/rtp_receiver_interface.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"
Fredrik Solenberg78e88fe2018-11-19 11:09:14 +010030#include "modules/audio_coding/include/audio_coding_module.h"
Niels Möller530ead42018-10-04 14:28:39 +020031
32// TODO(solenberg, nisse): This file contains a few NOLINT marks, to silence
Niels Möller349ade32018-11-16 09:50:42 +010033// warnings about use of unsigned short.
Niels Möller530ead42018-10-04 14:28:39 +020034// These need cleanup, in a separate cl.
35
36namespace rtc {
37class TimestampWrapAroundHandler;
38}
39
40namespace webrtc {
41
42class AudioDeviceModule;
Benjamin Wright84583f62018-10-04 14:22:34 -070043class FrameDecryptorInterface;
Niels Möller530ead42018-10-04 14:28:39 +020044class PacketRouter;
45class ProcessThread;
46class RateLimiter;
47class ReceiveStatistics;
48class RtcEventLog;
49class RtpPacketReceived;
50class RtpRtcp;
51
52struct CallReceiveStatistics {
Niels Möller530ead42018-10-04 14:28:39 +020053 unsigned int cumulativeLost;
54 unsigned int extendedMax;
55 unsigned int jitterSamples;
56 int64_t rttMs;
57 size_t bytesReceived;
58 int packetsReceived;
59 // The capture ntp time (in local timebase) of the first played out audio
60 // frame.
61 int64_t capture_start_ntp_time_ms_;
Henrik Boström01738c62019-04-15 17:32:00 +020062 // The timestamp at which the last packet was received, i.e. the time of the
63 // local clock when it was received - not the RTP timestamp of that packet.
64 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
65 absl::optional<int64_t> last_packet_received_timestamp_ms;
Niels Möller530ead42018-10-04 14:28:39 +020066};
67
68namespace voe {
69
Niels Möllerdced9f62018-11-19 10:27:07 +010070class ChannelSendInterface;
Niels Möller530ead42018-10-04 14:28:39 +020071
Niels Möller349ade32018-11-16 09:50:42 +010072// Interface class needed for AudioReceiveStream tests that use a
73// MockChannelReceive.
74
75class ChannelReceiveInterface : public RtpPacketSinkInterface {
Niels Möller530ead42018-10-04 14:28:39 +020076 public:
Niels Möller349ade32018-11-16 09:50:42 +010077 virtual ~ChannelReceiveInterface() = default;
Niels Möller530ead42018-10-04 14:28:39 +020078
Niels Möller349ade32018-11-16 09:50:42 +010079 virtual void SetSink(AudioSinkInterface* sink) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020080
Niels Möller349ade32018-11-16 09:50:42 +010081 virtual void SetReceiveCodecs(
82 const std::map<int, SdpAudioFormat>& codecs) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020083
Niels Möller349ade32018-11-16 09:50:42 +010084 virtual void StartPlayout() = 0;
85 virtual void StopPlayout() = 0;
Niels Möller530ead42018-10-04 14:28:39 +020086
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +010087 // Payload type and format of last received RTP packet, if any.
Jonas Olssona4d87372019-07-05 19:08:33 +020088 virtual absl::optional<std::pair<int, SdpAudioFormat>> GetReceiveCodec()
89 const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020090
Niels Möller8fb1a6a2019-03-05 14:29:42 +010091 virtual void ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020092
Niels Möller349ade32018-11-16 09:50:42 +010093 virtual void SetChannelOutputVolumeScaling(float scaling) = 0;
94 virtual int GetSpeechOutputLevelFullRange() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020095 // See description of "totalAudioEnergy" in the WebRTC stats spec:
96 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Niels Möller349ade32018-11-16 09:50:42 +010097 virtual double GetTotalOutputEnergy() const = 0;
98 virtual double GetTotalOutputDuration() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020099
100 // Stats.
Niels Möller349ade32018-11-16 09:50:42 +0100101 virtual NetworkStatistics GetNetworkStatistics() const = 0;
102 virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200103
104 // Audio+Video Sync.
Niels Möller349ade32018-11-16 09:50:42 +0100105 virtual uint32_t GetDelayEstimate() const = 0;
106 virtual void SetMinimumPlayoutDelay(int delay_ms) = 0;
107 virtual uint32_t GetPlayoutTimestamp() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200108
Ruslan Burakov3b50f9f2019-02-06 09:45:56 +0100109 // Audio quality.
110 // Base minimum delay sets lower bound on minimum delay value which
111 // determines minimum delay until audio playout.
112 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
113 virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
114
Niels Möller530ead42018-10-04 14:28:39 +0200115 // Produces the transport-related timestamps; current_delay_ms is left unset.
Niels Möller349ade32018-11-16 09:50:42 +0100116 virtual absl::optional<Syncable::Info> GetSyncInfo() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200117
118 // RTP+RTCP
Niels Möller349ade32018-11-16 09:50:42 +0100119 virtual void SetLocalSSRC(uint32_t ssrc) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200120
Niels Möller349ade32018-11-16 09:50:42 +0100121 virtual void RegisterReceiverCongestionControlObjects(
122 PacketRouter* packet_router) = 0;
123 virtual void ResetReceiverCongestionControlObjects() = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200124
Niels Möller349ade32018-11-16 09:50:42 +0100125 virtual CallReceiveStatistics GetRTCPStatistics() const = 0;
126 virtual void SetNACKStatus(bool enable, int max_packets) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200127
Niels Möller349ade32018-11-16 09:50:42 +0100128 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
Niels Möller530ead42018-10-04 14:28:39 +0200129 int sample_rate_hz,
Niels Möller349ade32018-11-16 09:50:42 +0100130 AudioFrame* audio_frame) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200131
Niels Möller349ade32018-11-16 09:50:42 +0100132 virtual int PreferredSampleRate() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200133
134 // Associate to a send channel.
135 // Used for obtaining RTT for a receive-only channel.
Niels Möllerdced9f62018-11-19 10:27:07 +0100136 virtual void SetAssociatedSendChannel(
137 const ChannelSendInterface* channel) = 0;
Artem Titov67008df2019-07-04 07:14:11 +0000138
139 virtual std::vector<RtpSource> GetSources() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200140};
141
Niels Möller349ade32018-11-16 09:50:42 +0100142std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive(
Sebastian Jansson977b3352019-03-04 17:43:34 +0100143 Clock* clock,
Niels Möller349ade32018-11-16 09:50:42 +0100144 ProcessThread* module_process_thread,
145 AudioDeviceModule* audio_device_module,
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700146 const MediaTransportConfig& media_transport_config,
Niels Möller349ade32018-11-16 09:50:42 +0100147 Transport* rtcp_send_transport,
148 RtcEventLog* rtc_event_log,
149 uint32_t remote_ssrc,
150 size_t jitter_buffer_max_packets,
151 bool jitter_buffer_fast_playout,
Jakob Ivarsson10403ae2018-11-27 15:45:20 +0100152 int jitter_buffer_min_delay_ms,
Jakob Ivarsson53eae872019-01-10 15:58:36 +0100153 bool jitter_buffer_enable_rtx_handling,
Niels Möller349ade32018-11-16 09:50:42 +0100154 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
155 absl::optional<AudioCodecPairId> codec_pair_id,
156 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor,
157 const webrtc::CryptoOptions& crypto_options);
158
Niels Möller530ead42018-10-04 14:28:39 +0200159} // namespace voe
160} // namespace webrtc
161
162#endif // AUDIO_CHANNEL_RECEIVE_H_