audio_receive_stream.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (c) 2015 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 CALL_AUDIO_RECEIVE_STREAM_H_
  11. #define CALL_AUDIO_RECEIVE_STREAM_H_
  12. #include <map>
  13. #include <memory>
  14. #include <string>
  15. #include <vector>
  16. #include "absl/types/optional.h"
  17. #include "api/audio_codecs/audio_decoder_factory.h"
  18. #include "api/call/transport.h"
  19. #include "api/crypto/crypto_options.h"
  20. #include "api/crypto/frame_decryptor_interface.h"
  21. #include "api/frame_transformer_interface.h"
  22. #include "api/rtp_parameters.h"
  23. #include "api/scoped_refptr.h"
  24. #include "api/transport/rtp/rtp_source.h"
  25. #include "call/rtp_config.h"
  26. namespace webrtc {
  27. class AudioSinkInterface;
  28. class AudioReceiveStream {
  29. public:
  30. struct Stats {
  31. Stats();
  32. ~Stats();
  33. uint32_t remote_ssrc = 0;
  34. int64_t payload_bytes_rcvd = 0;
  35. int64_t header_and_padding_bytes_rcvd = 0;
  36. uint32_t packets_rcvd = 0;
  37. uint64_t fec_packets_received = 0;
  38. uint64_t fec_packets_discarded = 0;
  39. uint32_t packets_lost = 0;
  40. std::string codec_name;
  41. absl::optional<int> codec_payload_type;
  42. uint32_t jitter_ms = 0;
  43. uint32_t jitter_buffer_ms = 0;
  44. uint32_t jitter_buffer_preferred_ms = 0;
  45. uint32_t delay_estimate_ms = 0;
  46. int32_t audio_level = -1;
  47. // Stats below correspond to similarly-named fields in the WebRTC stats
  48. // spec. https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
  49. double total_output_energy = 0.0;
  50. uint64_t total_samples_received = 0;
  51. double total_output_duration = 0.0;
  52. uint64_t concealed_samples = 0;
  53. uint64_t silent_concealed_samples = 0;
  54. uint64_t concealment_events = 0;
  55. double jitter_buffer_delay_seconds = 0.0;
  56. uint64_t jitter_buffer_emitted_count = 0;
  57. double jitter_buffer_target_delay_seconds = 0.0;
  58. uint64_t inserted_samples_for_deceleration = 0;
  59. uint64_t removed_samples_for_acceleration = 0;
  60. // Stats below DO NOT correspond directly to anything in the WebRTC stats
  61. float expand_rate = 0.0f;
  62. float speech_expand_rate = 0.0f;
  63. float secondary_decoded_rate = 0.0f;
  64. float secondary_discarded_rate = 0.0f;
  65. float accelerate_rate = 0.0f;
  66. float preemptive_expand_rate = 0.0f;
  67. uint64_t delayed_packet_outage_samples = 0;
  68. int32_t decoding_calls_to_silence_generator = 0;
  69. int32_t decoding_calls_to_neteq = 0;
  70. int32_t decoding_normal = 0;
  71. // TODO(alexnarest): Consider decoding_neteq_plc for consistency
  72. int32_t decoding_plc = 0;
  73. int32_t decoding_codec_plc = 0;
  74. int32_t decoding_cng = 0;
  75. int32_t decoding_plc_cng = 0;
  76. int32_t decoding_muted_output = 0;
  77. int64_t capture_start_ntp_time_ms = 0;
  78. // The timestamp at which the last packet was received, i.e. the time of the
  79. // local clock when it was received - not the RTP timestamp of that packet.
  80. // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
  81. absl::optional<int64_t> last_packet_received_timestamp_ms;
  82. uint64_t jitter_buffer_flushes = 0;
  83. double relative_packet_arrival_delay_seconds = 0.0;
  84. int32_t interruption_count = 0;
  85. int32_t total_interruption_duration_ms = 0;
  86. // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp
  87. absl::optional<int64_t> estimated_playout_ntp_timestamp_ms;
  88. };
  89. struct Config {
  90. Config();
  91. ~Config();
  92. std::string ToString() const;
  93. // Receive-stream specific RTP settings.
  94. struct Rtp {
  95. Rtp();
  96. ~Rtp();
  97. std::string ToString() const;
  98. // Synchronization source (stream identifier) to be received.
  99. uint32_t remote_ssrc = 0;
  100. // Sender SSRC used for sending RTCP (such as receiver reports).
  101. uint32_t local_ssrc = 0;
  102. // Enable feedback for send side bandwidth estimation.
  103. // See
  104. // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions
  105. // for details.
  106. bool transport_cc = false;
  107. // See NackConfig for description.
  108. NackConfig nack;
  109. // RTP header extensions used for the received stream.
  110. std::vector<RtpExtension> extensions;
  111. } rtp;
  112. Transport* rtcp_send_transport = nullptr;
  113. // NetEq settings.
  114. size_t jitter_buffer_max_packets = 200;
  115. bool jitter_buffer_fast_accelerate = false;
  116. int jitter_buffer_min_delay_ms = 0;
  117. bool jitter_buffer_enable_rtx_handling = false;
  118. // Identifier for an A/V synchronization group. Empty string to disable.
  119. // TODO(pbos): Synchronize streams in a sync group, not just one video
  120. // stream to one audio stream. Tracked by issue webrtc:4762.
  121. std::string sync_group;
  122. // Decoder specifications for every payload type that we can receive.
  123. std::map<int, SdpAudioFormat> decoder_map;
  124. rtc::scoped_refptr<AudioDecoderFactory> decoder_factory;
  125. absl::optional<AudioCodecPairId> codec_pair_id;
  126. // Per PeerConnection crypto options.
  127. webrtc::CryptoOptions crypto_options;
  128. // An optional custom frame decryptor that allows the entire frame to be
  129. // decrypted in whatever way the caller choses. This is not required by
  130. // default.
  131. rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor;
  132. // An optional frame transformer used by insertable streams to transform
  133. // encoded frames.
  134. rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
  135. };
  136. // Reconfigure the stream according to the Configuration.
  137. virtual void Reconfigure(const Config& config) = 0;
  138. // Starts stream activity.
  139. // When a stream is active, it can receive, process and deliver packets.
  140. virtual void Start() = 0;
  141. // Stops stream activity.
  142. // When a stream is stopped, it can't receive, process or deliver packets.
  143. virtual void Stop() = 0;
  144. virtual Stats GetStats(bool get_and_clear_legacy_stats) const = 0;
  145. Stats GetStats() { return GetStats(/*get_and_clear_legacy_stats=*/true); }
  146. // Sets an audio sink that receives unmixed audio from the receive stream.
  147. // Ownership of the sink is managed by the caller.
  148. // Only one sink can be set and passing a null sink clears an existing one.
  149. // NOTE: Audio must still somehow be pulled through AudioTransport for audio
  150. // to stream through this sink. In practice, this happens if mixed audio
  151. // is being pulled+rendered and/or if audio is being pulled for the purposes
  152. // of feeding to the AEC.
  153. virtual void SetSink(AudioSinkInterface* sink) = 0;
  154. // Sets playback gain of the stream, applied when mixing, and thus after it
  155. // is potentially forwarded to any attached AudioSinkInterface implementation.
  156. virtual void SetGain(float gain) = 0;
  157. // Sets a base minimum for the playout delay. Base minimum delay sets lower
  158. // bound on minimum delay value determining lower bound on playout delay.
  159. //
  160. // Returns true if value was successfully set, false overwise.
  161. virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
  162. // Returns current value of base minimum delay in milliseconds.
  163. virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
  164. virtual std::vector<RtpSource> GetSources() const = 0;
  165. protected:
  166. virtual ~AudioReceiveStream() {}
  167. };
  168. } // namespace webrtc
  169. #endif // CALL_AUDIO_RECEIVE_STREAM_H_