channel_send.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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_SEND_H_
  11. #define AUDIO_CHANNEL_SEND_H_
  12. #include <memory>
  13. #include <string>
  14. #include <vector>
  15. #include "api/audio/audio_frame.h"
  16. #include "api/audio_codecs/audio_encoder.h"
  17. #include "api/crypto/crypto_options.h"
  18. #include "api/frame_transformer_interface.h"
  19. #include "api/function_view.h"
  20. #include "api/task_queue/task_queue_factory.h"
  21. #include "modules/rtp_rtcp/include/report_block_data.h"
  22. #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
  23. #include "modules/rtp_rtcp/source/rtp_sender_audio.h"
  24. namespace webrtc {
  25. class FrameEncryptorInterface;
  26. class ProcessThread;
  27. class RtcEventLog;
  28. class RtpTransportControllerSendInterface;
  29. struct CallSendStatistics {
  30. int64_t rttMs;
  31. int64_t payload_bytes_sent;
  32. int64_t header_and_padding_bytes_sent;
  33. // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent
  34. uint64_t retransmitted_bytes_sent;
  35. int packetsSent;
  36. // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent
  37. uint64_t retransmitted_packets_sent;
  38. // A snapshot of Report Blocks with additional data of interest to statistics.
  39. // Within this list, the sender-source SSRC pair is unique and per-pair the
  40. // ReportBlockData represents the latest Report Block that was received for
  41. // that pair.
  42. std::vector<ReportBlockData> report_block_datas;
  43. };
  44. // See section 6.4.2 in http://www.ietf.org/rfc/rfc3550.txt for details.
  45. struct ReportBlock {
  46. uint32_t sender_SSRC; // SSRC of sender
  47. uint32_t source_SSRC;
  48. uint8_t fraction_lost;
  49. int32_t cumulative_num_packets_lost;
  50. uint32_t extended_highest_sequence_number;
  51. uint32_t interarrival_jitter;
  52. uint32_t last_SR_timestamp;
  53. uint32_t delay_since_last_SR;
  54. };
  55. namespace voe {
  56. class ChannelSendInterface {
  57. public:
  58. virtual ~ChannelSendInterface() = default;
  59. virtual void ReceivedRTCPPacket(const uint8_t* packet, size_t length) = 0;
  60. virtual CallSendStatistics GetRTCPStatistics() const = 0;
  61. virtual void SetEncoder(int payload_type,
  62. std::unique_ptr<AudioEncoder> encoder) = 0;
  63. virtual void ModifyEncoder(
  64. rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) = 0;
  65. virtual void CallEncoder(rtc::FunctionView<void(AudioEncoder*)> modifier) = 0;
  66. // Use 0 to indicate that the extension should not be registered.
  67. virtual void SetRTCP_CNAME(absl::string_view c_name) = 0;
  68. virtual void SetSendAudioLevelIndicationStatus(bool enable, int id) = 0;
  69. virtual void RegisterSenderCongestionControlObjects(
  70. RtpTransportControllerSendInterface* transport,
  71. RtcpBandwidthObserver* bandwidth_observer) = 0;
  72. virtual void ResetSenderCongestionControlObjects() = 0;
  73. virtual std::vector<ReportBlock> GetRemoteRTCPReportBlocks() const = 0;
  74. virtual ANAStats GetANAStatistics() const = 0;
  75. virtual void RegisterCngPayloadType(int payload_type,
  76. int payload_frequency) = 0;
  77. virtual void SetSendTelephoneEventPayloadType(int payload_type,
  78. int payload_frequency) = 0;
  79. virtual bool SendTelephoneEventOutband(int event, int duration_ms) = 0;
  80. virtual void OnBitrateAllocation(BitrateAllocationUpdate update) = 0;
  81. virtual int GetBitrate() const = 0;
  82. virtual void SetInputMute(bool muted) = 0;
  83. virtual void ProcessAndEncodeAudio(
  84. std::unique_ptr<AudioFrame> audio_frame) = 0;
  85. virtual RtpRtcpInterface* GetRtpRtcp() const = 0;
  86. // In RTP we currently rely on RTCP packets (|ReceivedRTCPPacket|) to inform
  87. // about RTT.
  88. // In media transport we rely on the TargetTransferRateObserver instead.
  89. // In other words, if you are using RTP, you should expect
  90. // |ReceivedRTCPPacket| to be called, if you are using media transport,
  91. // |OnTargetTransferRate| will be called.
  92. //
  93. // In future, RTP media will move to the media transport implementation and
  94. // these conditions will be removed.
  95. // Returns the RTT in milliseconds.
  96. virtual int64_t GetRTT() const = 0;
  97. virtual void StartSend() = 0;
  98. virtual void StopSend() = 0;
  99. // E2EE Custom Audio Frame Encryption (Optional)
  100. virtual void SetFrameEncryptor(
  101. rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor) = 0;
  102. // Sets a frame transformer between encoder and packetizer, to transform
  103. // encoded frames before sending them out the network.
  104. virtual void SetEncoderToPacketizerFrameTransformer(
  105. rtc::scoped_refptr<webrtc::FrameTransformerInterface>
  106. frame_transformer) = 0;
  107. };
  108. std::unique_ptr<ChannelSendInterface> CreateChannelSend(
  109. Clock* clock,
  110. TaskQueueFactory* task_queue_factory,
  111. ProcessThread* module_process_thread,
  112. Transport* rtp_transport,
  113. RtcpRttStats* rtcp_rtt_stats,
  114. RtcEventLog* rtc_event_log,
  115. FrameEncryptorInterface* frame_encryptor,
  116. const webrtc::CryptoOptions& crypto_options,
  117. bool extmap_allow_mixed,
  118. int rtcp_report_interval_ms,
  119. uint32_t ssrc,
  120. rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
  121. TransportFeedbackObserver* feedback_observer);
  122. } // namespace voe
  123. } // namespace webrtc
  124. #endif // AUDIO_CHANNEL_SEND_H_