audio_send_stream.h 6.8 KB

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