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 | 65f17ca | 2019-09-12 13:59:36 +0200 | [diff] [blame] | 25 | #include "api/transport/media/media_transport_config.h" |
| 26 | #include "api/transport/media/media_transport_interface.h" |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 27 | #include "api/transport/rtp/rtp_source.h" |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 28 | #include "call/rtp_packet_sink_interface.h" |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 29 | #include "call/syncable.h" |
Niels Möller | ed44f54 | 2019-07-30 15:15:59 +0200 | [diff] [blame] | 30 | #include "modules/audio_coding/include/audio_coding_module_typedefs.h" |
| 31 | #include "system_wrappers/include/clock.h" |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 32 | |
| 33 | // 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] | 34 | // warnings about use of unsigned short. |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 35 | // These need cleanup, in a separate cl. |
| 36 | |
| 37 | namespace rtc { |
| 38 | class TimestampWrapAroundHandler; |
| 39 | } |
| 40 | |
| 41 | namespace webrtc { |
| 42 | |
| 43 | class AudioDeviceModule; |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 44 | class FrameDecryptorInterface; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 45 | class PacketRouter; |
| 46 | class ProcessThread; |
| 47 | class RateLimiter; |
| 48 | class ReceiveStatistics; |
| 49 | class RtcEventLog; |
| 50 | class RtpPacketReceived; |
| 51 | class RtpRtcp; |
| 52 | |
| 53 | struct CallReceiveStatistics { |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 54 | unsigned int cumulativeLost; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 55 | unsigned int jitterSamples; |
| 56 | int64_t rttMs; |
Mirko Bonadei | ef0627f | 2019-10-15 08:54:49 +0000 | [diff] [blame] | 57 | size_t bytesReceived; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 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_; |
Henrik Boström | 01738c6 | 2019-04-15 17:32:00 +0200 | [diff] [blame] | 62 | // The timestamp at which the last packet was received, i.e. the time of the |
| 63 | // local clock when it was received - not the RTP timestamp of that packet. |
| 64 | // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp |
| 65 | absl::optional<int64_t> last_packet_received_timestamp_ms; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | namespace voe { |
| 69 | |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 70 | class ChannelSendInterface; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 71 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 72 | // Interface class needed for AudioReceiveStream tests that use a |
| 73 | // MockChannelReceive. |
| 74 | |
| 75 | class ChannelReceiveInterface : public RtpPacketSinkInterface { |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 76 | public: |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 77 | virtual ~ChannelReceiveInterface() = default; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 78 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 79 | virtual void SetSink(AudioSinkInterface* sink) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 80 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 81 | virtual void SetReceiveCodecs( |
| 82 | const std::map<int, SdpAudioFormat>& codecs) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 83 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 84 | virtual void StartPlayout() = 0; |
| 85 | virtual void StopPlayout() = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 86 | |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 87 | // Payload type and format of last received RTP packet, if any. |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 88 | virtual absl::optional<std::pair<int, SdpAudioFormat>> GetReceiveCodec() |
| 89 | const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 90 | |
Niels Möller | 8fb1a6a | 2019-03-05 14:29:42 +0100 | [diff] [blame] | 91 | virtual void ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 92 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 93 | virtual void SetChannelOutputVolumeScaling(float scaling) = 0; |
| 94 | virtual int GetSpeechOutputLevelFullRange() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 95 | // See description of "totalAudioEnergy" in the WebRTC stats spec: |
| 96 | // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 97 | virtual double GetTotalOutputEnergy() const = 0; |
| 98 | virtual double GetTotalOutputDuration() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 99 | |
| 100 | // Stats. |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 101 | virtual NetworkStatistics GetNetworkStatistics() const = 0; |
| 102 | virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 103 | |
| 104 | // Audio+Video Sync. |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 105 | virtual uint32_t GetDelayEstimate() const = 0; |
| 106 | virtual void SetMinimumPlayoutDelay(int delay_ms) = 0; |
| 107 | virtual uint32_t GetPlayoutTimestamp() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 108 | |
Ruslan Burakov | 3b50f9f | 2019-02-06 09:45:56 +0100 | [diff] [blame] | 109 | // Audio quality. |
| 110 | // Base minimum delay sets lower bound on minimum delay value which |
| 111 | // determines minimum delay until audio playout. |
| 112 | virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0; |
| 113 | virtual int GetBaseMinimumPlayoutDelayMs() const = 0; |
| 114 | |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 115 | // Produces the transport-related timestamps; current_delay_ms is left unset. |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 116 | virtual absl::optional<Syncable::Info> GetSyncInfo() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 117 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 118 | virtual void RegisterReceiverCongestionControlObjects( |
| 119 | PacketRouter* packet_router) = 0; |
| 120 | virtual void ResetReceiverCongestionControlObjects() = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 121 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 122 | virtual CallReceiveStatistics GetRTCPStatistics() const = 0; |
| 123 | virtual void SetNACKStatus(bool enable, int max_packets) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 124 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 125 | virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo( |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 126 | int sample_rate_hz, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 127 | AudioFrame* audio_frame) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 128 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 129 | virtual int PreferredSampleRate() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 130 | |
| 131 | // Associate to a send channel. |
| 132 | // Used for obtaining RTT for a receive-only channel. |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 133 | virtual void SetAssociatedSendChannel( |
| 134 | const ChannelSendInterface* channel) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 135 | }; |
| 136 | |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 137 | std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive( |
Sebastian Jansson | 977b335 | 2019-03-04 17:43:34 +0100 | [diff] [blame] | 138 | Clock* clock, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 139 | ProcessThread* module_process_thread, |
| 140 | AudioDeviceModule* audio_device_module, |
Anton Sukhanov | 4f08faa | 2019-05-21 11:12:57 -0700 | [diff] [blame] | 141 | const MediaTransportConfig& media_transport_config, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 142 | Transport* rtcp_send_transport, |
| 143 | RtcEventLog* rtc_event_log, |
Erik Språng | 70efdde | 2019-08-21 13:36:20 +0200 | [diff] [blame] | 144 | uint32_t local_ssrc, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 145 | uint32_t remote_ssrc, |
| 146 | size_t jitter_buffer_max_packets, |
| 147 | bool jitter_buffer_fast_playout, |
Jakob Ivarsson | 10403ae | 2018-11-27 15:45:20 +0100 | [diff] [blame] | 148 | int jitter_buffer_min_delay_ms, |
Jakob Ivarsson | 53eae87 | 2019-01-10 15:58:36 +0100 | [diff] [blame] | 149 | bool jitter_buffer_enable_rtx_handling, |
Niels Möller | 349ade3 | 2018-11-16 09:50:42 +0100 | [diff] [blame] | 150 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory, |
| 151 | absl::optional<AudioCodecPairId> codec_pair_id, |
| 152 | rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor, |
| 153 | const webrtc::CryptoOptions& crypto_options); |
| 154 | |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 155 | } // namespace voe |
| 156 | } // namespace webrtc |
| 157 | |
| 158 | #endif // AUDIO_CHANNEL_RECEIVE_H_ |