blob: 28c7c0656724d9704d4c8903c08c483e48f7b25b [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öller7d76a312018-10-26 12:57:07 +020025#include "api/media_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/rtp_receiver_interface.h"
Niels Möller349ade32018-11-16 09:50:42 +010027#include "call/rtp_packet_sink_interface.h"
Niels Möller530ead42018-10-04 14:28:39 +020028#include "call/syncable.h"
Fredrik Solenberg78e88fe2018-11-19 11:09:14 +010029#include "modules/audio_coding/include/audio_coding_module.h"
Niels Möller530ead42018-10-04 14:28:39 +020030
31// TODO(solenberg, nisse): This file contains a few NOLINT marks, to silence
Niels Möller349ade32018-11-16 09:50:42 +010032// warnings about use of unsigned short.
Niels Möller530ead42018-10-04 14:28:39 +020033// These need cleanup, in a separate cl.
34
35namespace rtc {
36class TimestampWrapAroundHandler;
37}
38
39namespace webrtc {
40
41class AudioDeviceModule;
Benjamin Wright84583f62018-10-04 14:22:34 -070042class FrameDecryptorInterface;
Niels Möller530ead42018-10-04 14:28:39 +020043class PacketRouter;
44class ProcessThread;
45class RateLimiter;
46class ReceiveStatistics;
47class RtcEventLog;
48class RtpPacketReceived;
49class RtpRtcp;
50
51struct CallReceiveStatistics {
52 unsigned short fractionLost; // NOLINT
53 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_;
62};
63
64namespace voe {
65
Niels Möllerdced9f62018-11-19 10:27:07 +010066class ChannelSendInterface;
Niels Möller530ead42018-10-04 14:28:39 +020067
Niels Möller349ade32018-11-16 09:50:42 +010068// Interface class needed for AudioReceiveStream tests that use a
69// MockChannelReceive.
70
71class ChannelReceiveInterface : public RtpPacketSinkInterface {
Niels Möller530ead42018-10-04 14:28:39 +020072 public:
Niels Möller349ade32018-11-16 09:50:42 +010073 virtual ~ChannelReceiveInterface() = default;
Niels Möller530ead42018-10-04 14:28:39 +020074
Niels Möller349ade32018-11-16 09:50:42 +010075 virtual void SetSink(AudioSinkInterface* sink) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020076
Niels Möller349ade32018-11-16 09:50:42 +010077 virtual void SetReceiveCodecs(
78 const std::map<int, SdpAudioFormat>& codecs) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020079
Niels Möller349ade32018-11-16 09:50:42 +010080 virtual void StartPlayout() = 0;
81 virtual void StopPlayout() = 0;
Niels Möller530ead42018-10-04 14:28:39 +020082
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +010083 // Payload type and format of last received RTP packet, if any.
84 virtual absl::optional<std::pair<int, SdpAudioFormat>>
85 GetReceiveCodec() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020086
Niels Möller349ade32018-11-16 09:50:42 +010087 virtual bool ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020088
Niels Möller349ade32018-11-16 09:50:42 +010089 virtual void SetChannelOutputVolumeScaling(float scaling) = 0;
90 virtual int GetSpeechOutputLevelFullRange() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020091 // See description of "totalAudioEnergy" in the WebRTC stats spec:
92 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Niels Möller349ade32018-11-16 09:50:42 +010093 virtual double GetTotalOutputEnergy() const = 0;
94 virtual double GetTotalOutputDuration() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020095
96 // Stats.
Niels Möller349ade32018-11-16 09:50:42 +010097 virtual NetworkStatistics GetNetworkStatistics() const = 0;
98 virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020099
100 // Audio+Video Sync.
Niels Möller349ade32018-11-16 09:50:42 +0100101 virtual uint32_t GetDelayEstimate() const = 0;
102 virtual void SetMinimumPlayoutDelay(int delay_ms) = 0;
103 virtual uint32_t GetPlayoutTimestamp() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200104
Ruslan Burakov3b50f9f2019-02-06 09:45:56 +0100105 // Audio quality.
106 // Base minimum delay sets lower bound on minimum delay value which
107 // determines minimum delay until audio playout.
108 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
109 virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
110
Niels Möller530ead42018-10-04 14:28:39 +0200111 // Produces the transport-related timestamps; current_delay_ms is left unset.
Niels Möller349ade32018-11-16 09:50:42 +0100112 virtual absl::optional<Syncable::Info> GetSyncInfo() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200113
114 // RTP+RTCP
Niels Möller349ade32018-11-16 09:50:42 +0100115 virtual void SetLocalSSRC(uint32_t ssrc) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200116
Niels Möller349ade32018-11-16 09:50:42 +0100117 virtual void RegisterReceiverCongestionControlObjects(
118 PacketRouter* packet_router) = 0;
119 virtual void ResetReceiverCongestionControlObjects() = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200120
Niels Möller349ade32018-11-16 09:50:42 +0100121 virtual CallReceiveStatistics GetRTCPStatistics() const = 0;
122 virtual void SetNACKStatus(bool enable, int max_packets) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200123
Niels Möller349ade32018-11-16 09:50:42 +0100124 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
Niels Möller530ead42018-10-04 14:28:39 +0200125 int sample_rate_hz,
Niels Möller349ade32018-11-16 09:50:42 +0100126 AudioFrame* audio_frame) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200127
Niels Möller349ade32018-11-16 09:50:42 +0100128 virtual int PreferredSampleRate() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200129
130 // Associate to a send channel.
131 // Used for obtaining RTT for a receive-only channel.
Niels Möllerdced9f62018-11-19 10:27:07 +0100132 virtual void SetAssociatedSendChannel(
133 const ChannelSendInterface* channel) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200134
Niels Möller349ade32018-11-16 09:50:42 +0100135 virtual std::vector<RtpSource> GetSources() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200136};
137
Niels Möller349ade32018-11-16 09:50:42 +0100138std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive(
139 ProcessThread* module_process_thread,
140 AudioDeviceModule* audio_device_module,
141 MediaTransportInterface* media_transport,
142 Transport* rtcp_send_transport,
143 RtcEventLog* rtc_event_log,
144 uint32_t remote_ssrc,
145 size_t jitter_buffer_max_packets,
146 bool jitter_buffer_fast_playout,
Jakob Ivarsson10403ae2018-11-27 15:45:20 +0100147 int jitter_buffer_min_delay_ms,
Jakob Ivarsson53eae872019-01-10 15:58:36 +0100148 bool jitter_buffer_enable_rtx_handling,
Niels Möller349ade32018-11-16 09:50:42 +0100149 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
150 absl::optional<AudioCodecPairId> codec_pair_id,
151 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor,
152 const webrtc::CryptoOptions& crypto_options);
153
Niels Möller530ead42018-10-04 14:28:39 +0200154} // namespace voe
155} // namespace webrtc
156
157#endif // AUDIO_CHANNEL_RECEIVE_H_