Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 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 | |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 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" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "api/crypto/crypto_options.h" |
Marina Ciocea | d2aa8f9 | 2020-03-31 11:29:56 +0200 | [diff] [blame] | 21 | #include "api/frame_transformer_interface.h" |
Artem Titov | 741daaf | 2019-03-21 14:37:36 +0100 | [diff] [blame] | 22 | #include "api/function_view.h" |
Sebastian Jansson | 44dd9f2 | 2019-03-08 14:50:30 +0100 | [diff] [blame] | 23 | #include "api/task_queue/task_queue_factory.h" |
Henrik Boström | 6e436d1 | 2019-05-27 12:19:33 +0200 | [diff] [blame] | 24 | #include "modules/rtp_rtcp/include/report_block_data.h" |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 25 | #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" |
Niels Möller | ee5ccbc | 2019-03-06 16:47:29 +0100 | [diff] [blame] | 26 | #include "modules/rtp_rtcp/source/rtp_sender_audio.h" |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
| 29 | |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 30 | class FrameEncryptorInterface; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 31 | class RtcEventLog; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 32 | class RtpTransportControllerSendInterface; |
| 33 | |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 34 | struct CallSendStatistics { |
| 35 | int64_t rttMs; |
Niels Möller | ac0a4cb | 2019-10-09 15:01:33 +0200 | [diff] [blame] | 36 | int64_t payload_bytes_sent; |
| 37 | int64_t header_and_padding_bytes_sent; |
Henrik Boström | cf96e0f | 2019-04-17 13:51:53 +0200 | [diff] [blame] | 38 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent |
| 39 | uint64_t retransmitted_bytes_sent; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 40 | int packetsSent; |
Henrik Boström | cf96e0f | 2019-04-17 13:51:53 +0200 | [diff] [blame] | 41 | // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent |
| 42 | uint64_t retransmitted_packets_sent; |
Henrik Boström | 6e436d1 | 2019-05-27 12:19:33 +0200 | [diff] [blame] | 43 | // A snapshot of Report Blocks with additional data of interest to statistics. |
| 44 | // Within this list, the sender-source SSRC pair is unique and per-pair the |
| 45 | // ReportBlockData represents the latest Report Block that was received for |
| 46 | // that pair. |
| 47 | std::vector<ReportBlockData> report_block_datas; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | // See section 6.4.2 in http://www.ietf.org/rfc/rfc3550.txt for details. |
| 51 | struct ReportBlock { |
| 52 | uint32_t sender_SSRC; // SSRC of sender |
| 53 | uint32_t source_SSRC; |
| 54 | uint8_t fraction_lost; |
| 55 | int32_t cumulative_num_packets_lost; |
| 56 | uint32_t extended_highest_sequence_number; |
| 57 | uint32_t interarrival_jitter; |
| 58 | uint32_t last_SR_timestamp; |
| 59 | uint32_t delay_since_last_SR; |
| 60 | }; |
| 61 | |
| 62 | namespace voe { |
| 63 | |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 64 | class ChannelSendInterface { |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 65 | public: |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 66 | virtual ~ChannelSendInterface() = default; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 67 | |
Niels Möller | 8fb1a6a | 2019-03-05 14:29:42 +0100 | [diff] [blame] | 68 | virtual void ReceivedRTCPPacket(const uint8_t* packet, size_t length) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 69 | |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 70 | virtual CallSendStatistics GetRTCPStatistics() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 71 | |
Niels Möller | 8fb1a6a | 2019-03-05 14:29:42 +0100 | [diff] [blame] | 72 | virtual void SetEncoder(int payload_type, |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 73 | std::unique_ptr<AudioEncoder> encoder) = 0; |
| 74 | virtual void ModifyEncoder( |
| 75 | rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) = 0; |
Sebastian Jansson | 14a7cf9 | 2019-02-13 15:11:42 +0100 | [diff] [blame] | 76 | virtual void CallEncoder(rtc::FunctionView<void(AudioEncoder*)> modifier) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 77 | |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 78 | // Use 0 to indicate that the extension should not be registered. |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 79 | virtual void SetRTCP_CNAME(absl::string_view c_name) = 0; |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 80 | virtual void SetSendAudioLevelIndicationStatus(bool enable, int id) = 0; |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 81 | virtual void RegisterSenderCongestionControlObjects( |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 82 | RtpTransportControllerSendInterface* transport, |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 83 | RtcpBandwidthObserver* bandwidth_observer) = 0; |
| 84 | virtual void ResetSenderCongestionControlObjects() = 0; |
| 85 | virtual std::vector<ReportBlock> GetRemoteRTCPReportBlocks() const = 0; |
| 86 | virtual ANAStats GetANAStatistics() const = 0; |
Niels Möller | ee5ccbc | 2019-03-06 16:47:29 +0100 | [diff] [blame] | 87 | virtual void RegisterCngPayloadType(int payload_type, |
| 88 | int payload_frequency) = 0; |
Niels Möller | 8fb1a6a | 2019-03-05 14:29:42 +0100 | [diff] [blame] | 89 | virtual void SetSendTelephoneEventPayloadType(int payload_type, |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 90 | int payload_frequency) = 0; |
| 91 | virtual bool SendTelephoneEventOutband(int event, int duration_ms) = 0; |
Sebastian Jansson | 254d869 | 2018-11-21 19:19:00 +0100 | [diff] [blame] | 92 | virtual void OnBitrateAllocation(BitrateAllocationUpdate update) = 0; |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 93 | virtual int GetBitrate() const = 0; |
| 94 | virtual void SetInputMute(bool muted) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 95 | |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 96 | virtual void ProcessAndEncodeAudio( |
| 97 | std::unique_ptr<AudioFrame> audio_frame) = 0; |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 98 | virtual RtpRtcpInterface* GetRtpRtcp() const = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 99 | |
Piotr (Peter) Slatala | 179a392 | 2018-11-16 09:57:58 -0800 | [diff] [blame] | 100 | // In RTP we currently rely on RTCP packets (|ReceivedRTCPPacket|) to inform |
| 101 | // about RTT. |
| 102 | // In media transport we rely on the TargetTransferRateObserver instead. |
| 103 | // In other words, if you are using RTP, you should expect |
| 104 | // |ReceivedRTCPPacket| to be called, if you are using media transport, |
| 105 | // |OnTargetTransferRate| will be called. |
| 106 | // |
| 107 | // In future, RTP media will move to the media transport implementation and |
| 108 | // these conditions will be removed. |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 109 | // Returns the RTT in milliseconds. |
| 110 | virtual int64_t GetRTT() const = 0; |
| 111 | virtual void StartSend() = 0; |
| 112 | virtual void StopSend() = 0; |
Piotr (Peter) Slatala | 179a392 | 2018-11-16 09:57:58 -0800 | [diff] [blame] | 113 | |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 114 | // E2EE Custom Audio Frame Encryption (Optional) |
| 115 | virtual void SetFrameEncryptor( |
| 116 | rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor) = 0; |
Marina Ciocea | d2aa8f9 | 2020-03-31 11:29:56 +0200 | [diff] [blame] | 117 | |
| 118 | // Sets a frame transformer between encoder and packetizer, to transform |
| 119 | // encoded frames before sending them out the network. |
| 120 | virtual void SetEncoderToPacketizerFrameTransformer( |
| 121 | rtc::scoped_refptr<webrtc::FrameTransformerInterface> |
| 122 | frame_transformer) = 0; |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 123 | }; |
| 124 | |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 125 | std::unique_ptr<ChannelSendInterface> CreateChannelSend( |
Sebastian Jansson | 977b335 | 2019-03-04 17:43:34 +0100 | [diff] [blame] | 126 | Clock* clock, |
Sebastian Jansson | 44dd9f2 | 2019-03-08 14:50:30 +0100 | [diff] [blame] | 127 | TaskQueueFactory* task_queue_factory, |
Niels Möller | e977199 | 2018-11-26 10:55:07 +0100 | [diff] [blame] | 128 | Transport* rtp_transport, |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 129 | RtcpRttStats* rtcp_rtt_stats, |
| 130 | RtcEventLog* rtc_event_log, |
| 131 | FrameEncryptorInterface* frame_encryptor, |
| 132 | const webrtc::CryptoOptions& crypto_options, |
| 133 | bool extmap_allow_mixed, |
Erik Språng | 4c2c412 | 2019-07-11 15:20:15 +0200 | [diff] [blame] | 134 | int rtcp_report_interval_ms, |
Marina Ciocea | d2aa8f9 | 2020-03-31 11:29:56 +0200 | [diff] [blame] | 135 | uint32_t ssrc, |
Erik Språng | 2b4d2f3 | 2020-06-29 16:37:44 +0200 | [diff] [blame] | 136 | rtc::scoped_refptr<FrameTransformerInterface> frame_transformer, |
| 137 | TransportFeedbackObserver* feedback_observer); |
Niels Möller | dced9f6 | 2018-11-19 10:27:07 +0100 | [diff] [blame] | 138 | |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 139 | } // namespace voe |
| 140 | } // namespace webrtc |
| 141 | |
| 142 | #endif // AUDIO_CHANNEL_SEND_H_ |