Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 1 | /* |
| 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 Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 16 | #include <utility> |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
| 19 | #include "absl/types/optional.h" |
| 20 | #include "api/audio/audio_mixer.h" |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 21 | #include "api/audio_codecs/audio_decoder_factory.h" |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 22 | #include "api/call/audio_sink.h" |
| 23 | #include "api/call/transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 24 | #include "api/crypto/crypto_options.h" |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 25 | #include "api/media_transport_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 26 | #include "api/rtp_receiver_interface.h" |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 27 | #include "call/rtp_packet_sink_interface.h" |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 28 | #include "call/syncable.h" |
Fredrik Solenberg | 78e88fe | 2018-11-19 11:09:14 +0100 | [diff] [blame] | 29 | #include "modules/audio_coding/include/audio_coding_module.h" |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 30 | |
| 31 | // TODO(solenberg, nisse): This file contains a few NOLINT marks, to silence |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 32 | // warnings about use of unsigned short. |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 33 | // These need cleanup, in a separate cl. |
| 34 | |
| 35 | namespace rtc { |
| 36 | class TimestampWrapAroundHandler; |
| 37 | } |
| 38 | |
| 39 | namespace webrtc { |
| 40 | |
| 41 | class AudioDeviceModule; |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 42 | class FrameDecryptorInterface; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 43 | class PacketRouter; |
| 44 | class ProcessThread; |
| 45 | class RateLimiter; |
| 46 | class ReceiveStatistics; |
| 47 | class RtcEventLog; |
| 48 | class RtpPacketReceived; |
| 49 | class RtpRtcp; |
| 50 | |
| 51 | struct 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 | |
| 64 | namespace voe { |
| 65 | |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 66 | class ChannelSendInterface; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 67 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 68 | // Interface class needed for AudioReceiveStream tests that use a |
| 69 | // MockChannelReceive. |
| 70 | |
| 71 | class ChannelReceiveInterface : public RtpPacketSinkInterface { |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 72 | public: |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 73 | virtual ~ChannelReceiveInterface() = default; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 74 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 75 | virtual void SetSink(AudioSinkInterface* sink) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 76 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 77 | virtual void SetReceiveCodecs( |
| 78 | const std::map<int, SdpAudioFormat>& codecs) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 79 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 80 | virtual void StartPlayout() = 0; |
| 81 | virtual void StopPlayout() = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 82 | |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 83 | // 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öller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 86 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 87 | virtual bool ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 88 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 89 | virtual void SetChannelOutputVolumeScaling(float scaling) = 0; |
| 90 | virtual int GetSpeechOutputLevelFullRange() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 91 | // See description of "totalAudioEnergy" in the WebRTC stats spec: |
| 92 | // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 93 | virtual double GetTotalOutputEnergy() const = 0; |
| 94 | virtual double GetTotalOutputDuration() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 95 | |
| 96 | // Stats. |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 97 | virtual NetworkStatistics GetNetworkStatistics() const = 0; |
| 98 | virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 99 | |
| 100 | // Audio+Video Sync. |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 101 | virtual uint32_t GetDelayEstimate() const = 0; |
| 102 | virtual void SetMinimumPlayoutDelay(int delay_ms) = 0; |
| 103 | virtual uint32_t GetPlayoutTimestamp() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 104 | |
Ruslan Burakov | 3b50f9f | 2019-02-06 09:45:56 +0100 | [diff] [blame] | 105 | // 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öller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 111 | // Produces the transport-related timestamps; current_delay_ms is left unset. |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 112 | virtual absl::optional<Syncable::Info> GetSyncInfo() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 113 | |
| 114 | // RTP+RTCP |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 115 | virtual void SetLocalSSRC(uint32_t ssrc) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 116 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 117 | virtual void RegisterReceiverCongestionControlObjects( |
| 118 | PacketRouter* packet_router) = 0; |
| 119 | virtual void ResetReceiverCongestionControlObjects() = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 120 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 121 | virtual CallReceiveStatistics GetRTCPStatistics() const = 0; |
| 122 | virtual void SetNACKStatus(bool enable, int max_packets) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 123 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 124 | virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo( |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 125 | int sample_rate_hz, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 126 | AudioFrame* audio_frame) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 127 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 128 | virtual int PreferredSampleRate() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 129 | |
| 130 | // Associate to a send channel. |
| 131 | // Used for obtaining RTT for a receive-only channel. |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 132 | virtual void SetAssociatedSendChannel( |
| 133 | const ChannelSendInterface* channel) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 134 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 135 | virtual std::vector<RtpSource> GetSources() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 136 | }; |
| 137 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 138 | std::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 Ivarsson | 10403ae | 2018-11-27 15:45:20 +0100 | [diff] [blame] | 147 | int jitter_buffer_min_delay_ms, |
Jakob Ivarsson | 53eae87 | 2019-01-10 15:58:36 +0100 | [diff] [blame] | 148 | bool jitter_buffer_enable_rtx_handling, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 149 | 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öller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 154 | } // namespace voe |
| 155 | } // namespace webrtc |
| 156 | |
| 157 | #endif // AUDIO_CHANNEL_RECEIVE_H_ |