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> 16 #include <utility> 17 #include <vector> 18 19 #include "absl/types/optional.h" 20 #include "api/audio/audio_mixer.h" 21 #include "api/audio_codecs/audio_decoder_factory.h" 22 #include "api/call/audio_sink.h" 23 #include "api/call/transport.h" 24 #include "api/crypto/crypto_options.h" 25 #include "api/frame_transformer_interface.h" 26 #include "api/neteq/neteq_factory.h" 27 #include "api/transport/rtp/rtp_source.h" 28 #include "call/rtp_packet_sink_interface.h" 29 #include "call/syncable.h" 30 #include "modules/audio_coding/include/audio_coding_module_typedefs.h" 31 #include "system_wrappers/include/clock.h" 32 33 // TODO(solenberg, nisse): This file contains a few NOLINT marks, to silence 34 // warnings about use of unsigned short. 35 // These need cleanup, in a separate cl. 36 37 namespace rtc { 38 class TimestampWrapAroundHandler; 39 } 40 41 namespace webrtc { 42 43 class AudioDeviceModule; 44 class FrameDecryptorInterface; 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 { 54 unsigned int cumulativeLost; 55 unsigned int jitterSamples; 56 int64_t rttMs; 57 int64_t payload_bytes_rcvd = 0; 58 int64_t header_and_padding_bytes_rcvd = 0; 59 int packetsReceived; 60 // The capture ntp time (in local timebase) of the first played out audio 61 // frame. 62 int64_t capture_start_ntp_time_ms_; 63 // The timestamp at which the last packet was received, i.e. the time of the 64 // local clock when it was received - not the RTP timestamp of that packet. 65 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp 66 absl::optional<int64_t> last_packet_received_timestamp_ms; 67 }; 68 69 namespace voe { 70 71 class ChannelSendInterface; 72 73 // Interface class needed for AudioReceiveStream tests that use a 74 // MockChannelReceive. 75 76 class ChannelReceiveInterface : public RtpPacketSinkInterface { 77 public: 78 virtual ~ChannelReceiveInterface() = default; 79 80 virtual void SetSink(AudioSinkInterface* sink) = 0; 81 82 virtual void SetReceiveCodecs( 83 const std::map<int, SdpAudioFormat>& codecs) = 0; 84 85 virtual void StartPlayout() = 0; 86 virtual void StopPlayout() = 0; 87 88 // Payload type and format of last received RTP packet, if any. 89 virtual absl::optional<std::pair<int, SdpAudioFormat>> GetReceiveCodec() 90 const = 0; 91 92 virtual void ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0; 93 94 virtual void SetChannelOutputVolumeScaling(float scaling) = 0; 95 virtual int GetSpeechOutputLevelFullRange() const = 0; 96 // See description of "totalAudioEnergy" in the WebRTC stats spec: 97 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy 98 virtual double GetTotalOutputEnergy() const = 0; 99 virtual double GetTotalOutputDuration() const = 0; 100 101 // Stats. 102 virtual NetworkStatistics GetNetworkStatistics() const = 0; 103 virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0; 104 105 // Audio+Video Sync. 106 virtual uint32_t GetDelayEstimate() const = 0; 107 virtual void SetMinimumPlayoutDelay(int delay_ms) = 0; 108 virtual bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp, 109 int64_t* time_ms) const = 0; 110 virtual void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms, 111 int64_t time_ms) = 0; 112 virtual absl::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs( 113 int64_t now_ms) const = 0; 114 115 // Audio quality. 116 // Base minimum delay sets lower bound on minimum delay value which 117 // determines minimum delay until audio playout. 118 virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0; 119 virtual int GetBaseMinimumPlayoutDelayMs() const = 0; 120 121 // Produces the transport-related timestamps; current_delay_ms is left unset. 122 virtual absl::optional<Syncable::Info> GetSyncInfo() const = 0; 123 124 virtual void RegisterReceiverCongestionControlObjects( 125 PacketRouter* packet_router) = 0; 126 virtual void ResetReceiverCongestionControlObjects() = 0; 127 128 virtual CallReceiveStatistics GetRTCPStatistics() const = 0; 129 virtual void SetNACKStatus(bool enable, int max_packets) = 0; 130 131 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo( 132 int sample_rate_hz, 133 AudioFrame* audio_frame) = 0; 134 135 virtual int PreferredSampleRate() const = 0; 136 137 // Associate to a send channel. 138 // Used for obtaining RTT for a receive-only channel. 139 virtual void SetAssociatedSendChannel( 140 const ChannelSendInterface* channel) = 0; 141 142 // Sets a frame transformer between the depacketizer and the decoder, to 143 // transform the received frames before decoding them. 144 virtual void SetDepacketizerToDecoderFrameTransformer( 145 rtc::scoped_refptr<webrtc::FrameTransformerInterface> 146 frame_transformer) = 0; 147 }; 148 149 std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive( 150 Clock* clock, 151 ProcessThread* module_process_thread, 152 NetEqFactory* neteq_factory, 153 AudioDeviceModule* audio_device_module, 154 Transport* rtcp_send_transport, 155 RtcEventLog* rtc_event_log, 156 uint32_t local_ssrc, 157 uint32_t remote_ssrc, 158 size_t jitter_buffer_max_packets, 159 bool jitter_buffer_fast_playout, 160 int jitter_buffer_min_delay_ms, 161 bool jitter_buffer_enable_rtx_handling, 162 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory, 163 absl::optional<AudioCodecPairId> codec_pair_id, 164 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor, 165 const webrtc::CryptoOptions& crypto_options, 166 rtc::scoped_refptr<FrameTransformerInterface> frame_transformer); 167 168 } // namespace voe 169 } // namespace webrtc 170 171 #endif // AUDIO_CHANNEL_RECEIVE_H_ 172