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