You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
6.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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_SEND_STREAM_H_
  11. #define CALL_AUDIO_SEND_STREAM_H_
  12. #include <memory>
  13. #include <string>
  14. #include <vector>
  15. #include "absl/types/optional.h"
  16. #include "api/audio_codecs/audio_codec_pair_id.h"
  17. #include "api/audio_codecs/audio_encoder.h"
  18. #include "api/audio_codecs/audio_encoder_factory.h"
  19. #include "api/audio_codecs/audio_format.h"
  20. #include "api/call/transport.h"
  21. #include "api/crypto/crypto_options.h"
  22. #include "api/crypto/frame_encryptor_interface.h"
  23. #include "api/rtp_parameters.h"
  24. #include "api/scoped_refptr.h"
  25. #include "api/transport/media/media_transport_config.h"
  26. #include "api/transport/media/media_transport_interface.h"
  27. #include "call/rtp_config.h"
  28. #include "modules/audio_processing/include/audio_processing_statistics.h"
  29. #include "modules/rtp_rtcp/include/report_block_data.h"
  30. namespace webrtc {
  31. class AudioFrame;
  32. class AudioSendStream {
  33. public:
  34. struct Stats {
  35. Stats();
  36. ~Stats();
  37. // TODO(solenberg): Harmonize naming and defaults with receive stream stats.
  38. uint32_t local_ssrc = 0;
  39. int64_t payload_bytes_sent = 0;
  40. int64_t header_and_padding_bytes_sent = 0;
  41. // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent
  42. uint64_t retransmitted_bytes_sent = 0;
  43. int32_t packets_sent = 0;
  44. // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent
  45. uint64_t retransmitted_packets_sent = 0;
  46. int32_t packets_lost = -1;
  47. float fraction_lost = -1.0f;
  48. std::string codec_name;
  49. absl::optional<int> codec_payload_type;
  50. int32_t jitter_ms = -1;
  51. int64_t rtt_ms = -1;
  52. int16_t audio_level = 0;
  53. // See description of "totalAudioEnergy" in the WebRTC stats spec:
  54. // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
  55. double total_input_energy = 0.0;
  56. double total_input_duration = 0.0;
  57. bool typing_noise_detected = false;
  58. ANAStats ana_statistics;
  59. AudioProcessingStats apm_statistics;
  60. int64_t target_bitrate_bps = 0;
  61. // A snapshot of Report Blocks with additional data of interest to
  62. // statistics. Within this list, the sender-source SSRC pair is unique and
  63. // per-pair the ReportBlockData represents the latest Report Block that was
  64. // received for that pair.
  65. std::vector<ReportBlockData> report_block_datas;
  66. };
  67. struct Config {
  68. Config() = delete;
  69. Config(Transport* send_transport,
  70. const MediaTransportConfig& media_transport_config);
  71. explicit Config(Transport* send_transport);
  72. ~Config();
  73. std::string ToString() const;
  74. // Send-stream specific RTP settings.
  75. struct Rtp {
  76. Rtp();
  77. ~Rtp();
  78. std::string ToString() const;
  79. // Sender SSRC.
  80. uint32_t ssrc = 0;
  81. // The value to send in the RID RTP header extension if the extension is
  82. // included in the list of extensions.
  83. std::string rid;
  84. // The value to send in the MID RTP header extension if the extension is
  85. // included in the list of extensions.
  86. std::string mid;
  87. // Corresponds to the SDP attribute extmap-allow-mixed.
  88. bool extmap_allow_mixed = false;
  89. // RTP header extensions used for the sent stream.
  90. std::vector<RtpExtension> extensions;
  91. // RTCP CNAME, see RFC 3550.
  92. std::string c_name;
  93. } rtp;
  94. // Time interval between RTCP report for audio
  95. int rtcp_report_interval_ms = 5000;
  96. // Transport for outgoing packets. The transport is expected to exist for
  97. // the entire life of the AudioSendStream and is owned by the API client.
  98. Transport* send_transport = nullptr;
  99. MediaTransportConfig media_transport_config;
  100. // Bitrate limits used for variable audio bitrate streams. Set both to -1 to
  101. // disable audio bitrate adaptation.
  102. // Note: This is still an experimental feature and not ready for real usage.
  103. int min_bitrate_bps = -1;
  104. int max_bitrate_bps = -1;
  105. double bitrate_priority = 1.0;
  106. bool has_dscp = false;
  107. // Defines whether to turn on audio network adaptor, and defines its config
  108. // string.
  109. absl::optional<std::string> audio_network_adaptor_config;
  110. struct SendCodecSpec {
  111. SendCodecSpec(int payload_type, const SdpAudioFormat& format);
  112. ~SendCodecSpec();
  113. std::string ToString() const;
  114. bool operator==(const SendCodecSpec& rhs) const;
  115. bool operator!=(const SendCodecSpec& rhs) const {
  116. return !(*this == rhs);
  117. }
  118. int payload_type;
  119. SdpAudioFormat format;
  120. bool nack_enabled = false;
  121. bool transport_cc_enabled = false;
  122. absl::optional<int> cng_payload_type;
  123. // If unset, use the encoder's default target bitrate.
  124. absl::optional<int> target_bitrate_bps;
  125. };
  126. absl::optional<SendCodecSpec> send_codec_spec;
  127. rtc::scoped_refptr<AudioEncoderFactory> encoder_factory;
  128. absl::optional<AudioCodecPairId> codec_pair_id;
  129. // Track ID as specified during track creation.
  130. std::string track_id;
  131. // Per PeerConnection crypto options.
  132. webrtc::CryptoOptions crypto_options;
  133. // An optional custom frame encryptor that allows the entire frame to be
  134. // encryptor in whatever way the caller choses. This is not required by
  135. // default.
  136. rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor;
  137. };
  138. virtual ~AudioSendStream() = default;
  139. virtual const webrtc::AudioSendStream::Config& GetConfig() const = 0;
  140. // Reconfigure the stream according to the Configuration.
  141. virtual void Reconfigure(const Config& config) = 0;
  142. // Starts stream activity.
  143. // When a stream is active, it can receive, process and deliver packets.
  144. virtual void Start() = 0;
  145. // Stops stream activity.
  146. // When a stream is stopped, it can't receive, process or deliver packets.
  147. virtual void Stop() = 0;
  148. // Encode and send audio.
  149. virtual void SendAudioData(
  150. std::unique_ptr<webrtc::AudioFrame> audio_frame) = 0;
  151. // TODO(solenberg): Make payload_type a config property instead.
  152. virtual bool SendTelephoneEvent(int payload_type,
  153. int payload_frequency,
  154. int event,
  155. int duration_ms) = 0;
  156. virtual void SetMuted(bool muted) = 0;
  157. virtual Stats GetStats() const = 0;
  158. virtual Stats GetStats(bool has_remote_tracks) const = 0;
  159. };
  160. } // namespace webrtc
  161. #endif // CALL_AUDIO_SEND_STREAM_H_