blob: c774875ab2e69815c3308580bc407296e51d8cf2 [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>
16#include <vector>
17
18#include "absl/types/optional.h"
19#include "api/audio/audio_mixer.h"
Niels Möller349ade32018-11-16 09:50:42 +010020#include "api/audio_codecs/audio_decoder_factory.h"
Niels Möller530ead42018-10-04 14:28:39 +020021#include "api/call/audio_sink.h"
22#include "api/call/transport.h"
Benjamin Wrightbfb444c2018-10-15 10:20:24 -070023#include "api/crypto/cryptooptions.h"
Niels Möller7d76a312018-10-26 12:57:07 +020024#include "api/media_transport_interface.h"
Niels Möller530ead42018-10-04 14:28:39 +020025#include "api/rtpreceiverinterface.h"
Niels Möller349ade32018-11-16 09:50:42 +010026#include "call/rtp_packet_sink_interface.h"
Niels Möller530ead42018-10-04 14:28:39 +020027#include "call/syncable.h"
28#include "common_types.h" // NOLINT(build/include)
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
Niels Möller349ade32018-11-16 09:50:42 +010083 virtual bool GetRecCodec(CodecInst* codec) const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020084
Niels Möller349ade32018-11-16 09:50:42 +010085 virtual bool ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020086
Niels Möller349ade32018-11-16 09:50:42 +010087 virtual void SetChannelOutputVolumeScaling(float scaling) = 0;
88 virtual int GetSpeechOutputLevelFullRange() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020089 // See description of "totalAudioEnergy" in the WebRTC stats spec:
90 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Niels Möller349ade32018-11-16 09:50:42 +010091 virtual double GetTotalOutputEnergy() const = 0;
92 virtual double GetTotalOutputDuration() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020093
94 // Stats.
Niels Möller349ade32018-11-16 09:50:42 +010095 virtual NetworkStatistics GetNetworkStatistics() const = 0;
96 virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020097
98 // Audio+Video Sync.
Niels Möller349ade32018-11-16 09:50:42 +010099 virtual uint32_t GetDelayEstimate() const = 0;
100 virtual void SetMinimumPlayoutDelay(int delay_ms) = 0;
101 virtual uint32_t GetPlayoutTimestamp() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200102
103 // Produces the transport-related timestamps; current_delay_ms is left unset.
Niels Möller349ade32018-11-16 09:50:42 +0100104 virtual absl::optional<Syncable::Info> GetSyncInfo() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200105
106 // RTP+RTCP
Niels Möller349ade32018-11-16 09:50:42 +0100107 virtual void SetLocalSSRC(uint32_t ssrc) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200108
Niels Möller349ade32018-11-16 09:50:42 +0100109 virtual void RegisterReceiverCongestionControlObjects(
110 PacketRouter* packet_router) = 0;
111 virtual void ResetReceiverCongestionControlObjects() = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200112
Niels Möller349ade32018-11-16 09:50:42 +0100113 virtual CallReceiveStatistics GetRTCPStatistics() const = 0;
114 virtual void SetNACKStatus(bool enable, int max_packets) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200115
Niels Möller349ade32018-11-16 09:50:42 +0100116 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
Niels Möller530ead42018-10-04 14:28:39 +0200117 int sample_rate_hz,
Niels Möller349ade32018-11-16 09:50:42 +0100118 AudioFrame* audio_frame) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200119
Niels Möller349ade32018-11-16 09:50:42 +0100120 virtual int PreferredSampleRate() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200121
122 // Associate to a send channel.
123 // Used for obtaining RTT for a receive-only channel.
Niels Möllerdced9f62018-11-19 10:27:07 +0100124 virtual void SetAssociatedSendChannel(
125 const ChannelSendInterface* channel) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200126
Niels Möller349ade32018-11-16 09:50:42 +0100127 virtual std::vector<RtpSource> GetSources() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200128};
129
Niels Möller349ade32018-11-16 09:50:42 +0100130std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive(
131 ProcessThread* module_process_thread,
132 AudioDeviceModule* audio_device_module,
133 MediaTransportInterface* media_transport,
134 Transport* rtcp_send_transport,
135 RtcEventLog* rtc_event_log,
136 uint32_t remote_ssrc,
137 size_t jitter_buffer_max_packets,
138 bool jitter_buffer_fast_playout,
139 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
140 absl::optional<AudioCodecPairId> codec_pair_id,
141 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor,
142 const webrtc::CryptoOptions& crypto_options);
143
Niels Möller530ead42018-10-04 14:28:39 +0200144} // namespace voe
145} // namespace webrtc
146
147#endif // AUDIO_CHANNEL_RECEIVE_H_