blob: 5f71ea31b4f870a94ae25257020ba82bbd228e81 [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"
Niels Möller65f17ca2019-09-12 13:59:36 +020025#include "api/transport/media/media_transport_config.h"
26#include "api/transport/media/media_transport_interface.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"
31#include "system_wrappers/include/clock.h"
Niels Möller530ead42018-10-04 14:28:39 +020032
33// TODO(solenberg, nisse): This file contains a few NOLINT marks, to silence
Niels Möller349ade32018-11-16 09:50:42 +010034// warnings about use of unsigned short.
Niels Möller530ead42018-10-04 14:28:39 +020035// These need cleanup, in a separate cl.
36
37namespace rtc {
38class TimestampWrapAroundHandler;
39}
40
41namespace webrtc {
42
43class AudioDeviceModule;
Benjamin Wright84583f62018-10-04 14:22:34 -070044class FrameDecryptorInterface;
Niels Möller530ead42018-10-04 14:28:39 +020045class PacketRouter;
46class ProcessThread;
47class RateLimiter;
48class ReceiveStatistics;
49class RtcEventLog;
50class RtpPacketReceived;
51class RtpRtcp;
52
53struct CallReceiveStatistics {
Niels Möller530ead42018-10-04 14:28:39 +020054 unsigned int cumulativeLost;
Niels Möller530ead42018-10-04 14:28:39 +020055 unsigned int jitterSamples;
56 int64_t rttMs;
Niels Möllerac0a4cb2019-10-09 15:01:33 +020057 int64_t payload_bytes_rcvd = 0;
58 int64_t header_and_padding_bytes_rcvd = 0;
Niels Möller530ead42018-10-04 14:28:39 +020059 int packetsReceived;
60 // The capture ntp time (in local timebase) of the first played out audio
61 // frame.
62 int64_t capture_start_ntp_time_ms_;
Henrik Boström01738c62019-04-15 17:32:00 +020063 // The timestamp at which the last packet was received, i.e. the time of the
64 // local clock when it was received - not the RTP timestamp of that packet.
65 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
66 absl::optional<int64_t> last_packet_received_timestamp_ms;
Niels Möller530ead42018-10-04 14:28:39 +020067};
68
69namespace voe {
70
Niels Möllerdced9f62018-11-19 10:27:07 +010071class ChannelSendInterface;
Niels Möller530ead42018-10-04 14:28:39 +020072
Niels Möller349ade32018-11-16 09:50:42 +010073// Interface class needed for AudioReceiveStream tests that use a
74// MockChannelReceive.
75
76class ChannelReceiveInterface : public RtpPacketSinkInterface {
Niels Möller530ead42018-10-04 14:28:39 +020077 public:
Niels Möller349ade32018-11-16 09:50:42 +010078 virtual ~ChannelReceiveInterface() = default;
Niels Möller530ead42018-10-04 14:28:39 +020079
Niels Möller349ade32018-11-16 09:50:42 +010080 virtual void SetSink(AudioSinkInterface* sink) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020081
Niels Möller349ade32018-11-16 09:50:42 +010082 virtual void SetReceiveCodecs(
83 const std::map<int, SdpAudioFormat>& codecs) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020084
Niels Möller349ade32018-11-16 09:50:42 +010085 virtual void StartPlayout() = 0;
86 virtual void StopPlayout() = 0;
Niels Möller530ead42018-10-04 14:28:39 +020087
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +010088 // Payload type and format of last received RTP packet, if any.
Jonas Olssona4d87372019-07-05 19:08:33 +020089 virtual absl::optional<std::pair<int, SdpAudioFormat>> GetReceiveCodec()
90 const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020091
Niels Möller8fb1a6a2019-03-05 14:29:42 +010092 virtual void ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020093
Niels Möller349ade32018-11-16 09:50:42 +010094 virtual void SetChannelOutputVolumeScaling(float scaling) = 0;
95 virtual int GetSpeechOutputLevelFullRange() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020096 // See description of "totalAudioEnergy" in the WebRTC stats spec:
97 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Niels Möller349ade32018-11-16 09:50:42 +010098 virtual double GetTotalOutputEnergy() const = 0;
99 virtual double GetTotalOutputDuration() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200100
101 // Stats.
Niels Möller349ade32018-11-16 09:50:42 +0100102 virtual NetworkStatistics GetNetworkStatistics() const = 0;
103 virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200104
105 // Audio+Video Sync.
Niels Möller349ade32018-11-16 09:50:42 +0100106 virtual uint32_t GetDelayEstimate() const = 0;
107 virtual void SetMinimumPlayoutDelay(int delay_ms) = 0;
108 virtual uint32_t GetPlayoutTimestamp() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200109
Ruslan Burakov3b50f9f2019-02-06 09:45:56 +0100110 // Audio quality.
111 // Base minimum delay sets lower bound on minimum delay value which
112 // determines minimum delay until audio playout.
113 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
114 virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
115
Niels Möller530ead42018-10-04 14:28:39 +0200116 // Produces the transport-related timestamps; current_delay_ms is left unset.
Niels Möller349ade32018-11-16 09:50:42 +0100117 virtual absl::optional<Syncable::Info> GetSyncInfo() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200118
Niels Möller349ade32018-11-16 09:50:42 +0100119 virtual void RegisterReceiverCongestionControlObjects(
120 PacketRouter* packet_router) = 0;
121 virtual void ResetReceiverCongestionControlObjects() = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200122
Niels Möller349ade32018-11-16 09:50:42 +0100123 virtual CallReceiveStatistics GetRTCPStatistics() const = 0;
124 virtual void SetNACKStatus(bool enable, int max_packets) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200125
Niels Möller349ade32018-11-16 09:50:42 +0100126 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
Niels Möller530ead42018-10-04 14:28:39 +0200127 int sample_rate_hz,
Niels Möller349ade32018-11-16 09:50:42 +0100128 AudioFrame* audio_frame) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200129
Niels Möller349ade32018-11-16 09:50:42 +0100130 virtual int PreferredSampleRate() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200131
132 // Associate to a send channel.
133 // Used for obtaining RTT for a receive-only channel.
Niels Möllerdced9f62018-11-19 10:27:07 +0100134 virtual void SetAssociatedSendChannel(
135 const ChannelSendInterface* channel) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200136};
137
Niels Möller349ade32018-11-16 09:50:42 +0100138std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive(
Sebastian Jansson977b3352019-03-04 17:43:34 +0100139 Clock* clock,
Niels Möller349ade32018-11-16 09:50:42 +0100140 ProcessThread* module_process_thread,
141 AudioDeviceModule* audio_device_module,
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700142 const MediaTransportConfig& media_transport_config,
Niels Möller349ade32018-11-16 09:50:42 +0100143 Transport* rtcp_send_transport,
144 RtcEventLog* rtc_event_log,
Erik Språng70efdde2019-08-21 13:36:20 +0200145 uint32_t local_ssrc,
Niels Möller349ade32018-11-16 09:50:42 +0100146 uint32_t remote_ssrc,
147 size_t jitter_buffer_max_packets,
148 bool jitter_buffer_fast_playout,
Jakob Ivarsson10403ae2018-11-27 15:45:20 +0100149 int jitter_buffer_min_delay_ms,
Jakob Ivarsson53eae872019-01-10 15:58:36 +0100150 bool jitter_buffer_enable_rtx_handling,
Niels Möller349ade32018-11-16 09:50:42 +0100151 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
152 absl::optional<AudioCodecPairId> codec_pair_id,
153 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor,
154 const webrtc::CryptoOptions& crypto_options);
155
Niels Möller530ead42018-10-04 14:28:39 +0200156} // namespace voe
157} // namespace webrtc
158
159#endif // AUDIO_CHANNEL_RECEIVE_H_