blob: fbfd7f038bd012fd827f4c9cb9569f0162bd4718 [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)
Niels Möller530ead42018-10-04 14:28:39 +020029
30// TODO(solenberg, nisse): This file contains a few NOLINT marks, to silence
Niels Möller349ade32018-11-16 09:50:42 +010031// warnings about use of unsigned short.
Niels Möller530ead42018-10-04 14:28:39 +020032// These need cleanup, in a separate cl.
33
34namespace rtc {
35class TimestampWrapAroundHandler;
36}
37
38namespace webrtc {
39
40class AudioDeviceModule;
Benjamin Wright84583f62018-10-04 14:22:34 -070041class FrameDecryptorInterface;
Niels Möller530ead42018-10-04 14:28:39 +020042class PacketRouter;
43class ProcessThread;
44class RateLimiter;
45class ReceiveStatistics;
46class RtcEventLog;
47class RtpPacketReceived;
48class RtpRtcp;
49
50struct CallReceiveStatistics {
51 unsigned short fractionLost; // NOLINT
52 unsigned int cumulativeLost;
53 unsigned int extendedMax;
54 unsigned int jitterSamples;
55 int64_t rttMs;
56 size_t bytesReceived;
57 int packetsReceived;
58 // The capture ntp time (in local timebase) of the first played out audio
59 // frame.
60 int64_t capture_start_ntp_time_ms_;
61};
62
63namespace voe {
64
65class ChannelSend;
66
Niels Möller349ade32018-11-16 09:50:42 +010067// Interface class needed for AudioReceiveStream tests that use a
68// MockChannelReceive.
69
70class ChannelReceiveInterface : public RtpPacketSinkInterface {
Niels Möller530ead42018-10-04 14:28:39 +020071 public:
Niels Möller349ade32018-11-16 09:50:42 +010072 virtual ~ChannelReceiveInterface() = default;
Niels Möller530ead42018-10-04 14:28:39 +020073
Niels Möller349ade32018-11-16 09:50:42 +010074 virtual void SetSink(AudioSinkInterface* sink) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020075
Niels Möller349ade32018-11-16 09:50:42 +010076 virtual void SetReceiveCodecs(
77 const std::map<int, SdpAudioFormat>& codecs) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020078
Niels Möller349ade32018-11-16 09:50:42 +010079 virtual void StartPlayout() = 0;
80 virtual void StopPlayout() = 0;
Niels Möller530ead42018-10-04 14:28:39 +020081
Niels Möller349ade32018-11-16 09:50:42 +010082 virtual bool GetRecCodec(CodecInst* codec) const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020083
Niels Möller349ade32018-11-16 09:50:42 +010084 virtual bool ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020085
Niels Möller349ade32018-11-16 09:50:42 +010086 virtual void SetChannelOutputVolumeScaling(float scaling) = 0;
87 virtual int GetSpeechOutputLevelFullRange() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020088 // See description of "totalAudioEnergy" in the WebRTC stats spec:
89 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Niels Möller349ade32018-11-16 09:50:42 +010090 virtual double GetTotalOutputEnergy() const = 0;
91 virtual double GetTotalOutputDuration() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020092
93 // Stats.
Niels Möller349ade32018-11-16 09:50:42 +010094 virtual NetworkStatistics GetNetworkStatistics() const = 0;
95 virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020096
97 // Audio+Video Sync.
Niels Möller349ade32018-11-16 09:50:42 +010098 virtual uint32_t GetDelayEstimate() const = 0;
99 virtual void SetMinimumPlayoutDelay(int delay_ms) = 0;
100 virtual uint32_t GetPlayoutTimestamp() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200101
102 // Produces the transport-related timestamps; current_delay_ms is left unset.
Niels Möller349ade32018-11-16 09:50:42 +0100103 virtual absl::optional<Syncable::Info> GetSyncInfo() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200104
105 // RTP+RTCP
Niels Möller349ade32018-11-16 09:50:42 +0100106 virtual void SetLocalSSRC(uint32_t ssrc) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200107
Niels Möller349ade32018-11-16 09:50:42 +0100108 virtual void RegisterReceiverCongestionControlObjects(
109 PacketRouter* packet_router) = 0;
110 virtual void ResetReceiverCongestionControlObjects() = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200111
Niels Möller349ade32018-11-16 09:50:42 +0100112 virtual CallReceiveStatistics GetRTCPStatistics() const = 0;
113 virtual void SetNACKStatus(bool enable, int max_packets) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200114
Niels Möller349ade32018-11-16 09:50:42 +0100115 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
Niels Möller530ead42018-10-04 14:28:39 +0200116 int sample_rate_hz,
Niels Möller349ade32018-11-16 09:50:42 +0100117 AudioFrame* audio_frame) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200118
Niels Möller349ade32018-11-16 09:50:42 +0100119 virtual int PreferredSampleRate() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200120
121 // Associate to a send channel.
122 // Used for obtaining RTT for a receive-only channel.
Niels Möller349ade32018-11-16 09:50:42 +0100123 virtual void SetAssociatedSendChannel(const ChannelSend* channel) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200124
Niels Möller349ade32018-11-16 09:50:42 +0100125 virtual std::vector<RtpSource> GetSources() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200126};
127
Niels Möller349ade32018-11-16 09:50:42 +0100128std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive(
129 ProcessThread* module_process_thread,
130 AudioDeviceModule* audio_device_module,
131 MediaTransportInterface* media_transport,
132 Transport* rtcp_send_transport,
133 RtcEventLog* rtc_event_log,
134 uint32_t remote_ssrc,
135 size_t jitter_buffer_max_packets,
136 bool jitter_buffer_fast_playout,
137 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
138 absl::optional<AudioCodecPairId> codec_pair_id,
139 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor,
140 const webrtc::CryptoOptions& crypto_options);
141
Niels Möller530ead42018-10-04 14:28:39 +0200142} // namespace voe
143} // namespace webrtc
144
145#endif // AUDIO_CHANNEL_RECEIVE_H_