channel_receive.h 6.2 KB

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