blob: bfbfbeedfa834457248be8789b5aa12ec110dd3f [file] [log] [blame]
Niels Möller530ead42018-10-04 14:28:39 +02001/*
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öller530ead42018-10-04 14:28:39 +020014#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 Anton10542f22019-01-11 09:11:00 -080020#include "api/crypto/crypto_options.h"
Marina Ciocead2aa8f92020-03-31 11:29:56 +020021#include "api/frame_transformer_interface.h"
Artem Titov741daaf2019-03-21 14:37:36 +010022#include "api/function_view.h"
Sebastian Jansson44dd9f22019-03-08 14:50:30 +010023#include "api/task_queue/task_queue_factory.h"
Jonas Orelanda943e732022-03-16 13:50:58 +010024#include "api/webrtc_key_value_config.h"
Henrik Boström6e436d12019-05-27 12:19:33 +020025#include "modules/rtp_rtcp/include/report_block_data.h"
Tomas Gunnarssonf25761d2020-06-03 22:55:33 +020026#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
Niels Mölleree5ccbc2019-03-06 16:47:29 +010027#include "modules/rtp_rtcp/source/rtp_sender_audio.h"
Niels Möller530ead42018-10-04 14:28:39 +020028
29namespace webrtc {
30
Benjamin Wright84583f62018-10-04 14:22:34 -070031class FrameEncryptorInterface;
Niels Möller530ead42018-10-04 14:28:39 +020032class RtcEventLog;
Niels Möller530ead42018-10-04 14:28:39 +020033class RtpTransportControllerSendInterface;
34
Niels Möller530ead42018-10-04 14:28:39 +020035struct CallSendStatistics {
36 int64_t rttMs;
Niels Möllerac0a4cb2019-10-09 15:01:33 +020037 int64_t payload_bytes_sent;
38 int64_t header_and_padding_bytes_sent;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +020039 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent
40 uint64_t retransmitted_bytes_sent;
Niels Möller530ead42018-10-04 14:28:39 +020041 int packetsSent;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +020042 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent
43 uint64_t retransmitted_packets_sent;
Henrik Boström6e436d12019-05-27 12:19:33 +020044 // A snapshot of Report Blocks with additional data of interest to statistics.
45 // Within this list, the sender-source SSRC pair is unique and per-pair the
46 // ReportBlockData represents the latest Report Block that was received for
47 // that pair.
48 std::vector<ReportBlockData> report_block_datas;
Jakob Ivarssone91c9922021-07-06 09:55:43 +020049 uint32_t nacks_rcvd;
Niels Möller530ead42018-10-04 14:28:39 +020050};
51
52// See section 6.4.2 in http://www.ietf.org/rfc/rfc3550.txt for details.
53struct ReportBlock {
54 uint32_t sender_SSRC; // SSRC of sender
55 uint32_t source_SSRC;
56 uint8_t fraction_lost;
57 int32_t cumulative_num_packets_lost;
58 uint32_t extended_highest_sequence_number;
59 uint32_t interarrival_jitter;
60 uint32_t last_SR_timestamp;
61 uint32_t delay_since_last_SR;
62};
63
64namespace voe {
65
Niels Möllerdced9f62018-11-19 10:27:07 +010066class ChannelSendInterface {
Niels Möller530ead42018-10-04 14:28:39 +020067 public:
Niels Möllerdced9f62018-11-19 10:27:07 +010068 virtual ~ChannelSendInterface() = default;
Niels Möller530ead42018-10-04 14:28:39 +020069
Niels Möller8fb1a6a2019-03-05 14:29:42 +010070 virtual void ReceivedRTCPPacket(const uint8_t* packet, size_t length) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020071
Niels Möllerdced9f62018-11-19 10:27:07 +010072 virtual CallSendStatistics GetRTCPStatistics() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020073
Niels Möller8fb1a6a2019-03-05 14:29:42 +010074 virtual void SetEncoder(int payload_type,
Niels Möllerdced9f62018-11-19 10:27:07 +010075 std::unique_ptr<AudioEncoder> encoder) = 0;
76 virtual void ModifyEncoder(
77 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) = 0;
Sebastian Jansson14a7cf92019-02-13 15:11:42 +010078 virtual void CallEncoder(rtc::FunctionView<void(AudioEncoder*)> modifier) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020079
Amit Hilbuch77938e62018-12-21 09:23:38 -080080 // Use 0 to indicate that the extension should not be registered.
Niels Möllerdced9f62018-11-19 10:27:07 +010081 virtual void SetRTCP_CNAME(absl::string_view c_name) = 0;
Niels Möllerdced9f62018-11-19 10:27:07 +010082 virtual void SetSendAudioLevelIndicationStatus(bool enable, int id) = 0;
Niels Möllerdced9f62018-11-19 10:27:07 +010083 virtual void RegisterSenderCongestionControlObjects(
Niels Möller530ead42018-10-04 14:28:39 +020084 RtpTransportControllerSendInterface* transport,
Niels Möllerdced9f62018-11-19 10:27:07 +010085 RtcpBandwidthObserver* bandwidth_observer) = 0;
86 virtual void ResetSenderCongestionControlObjects() = 0;
87 virtual std::vector<ReportBlock> GetRemoteRTCPReportBlocks() const = 0;
88 virtual ANAStats GetANAStatistics() const = 0;
Niels Mölleree5ccbc2019-03-06 16:47:29 +010089 virtual void RegisterCngPayloadType(int payload_type,
90 int payload_frequency) = 0;
Niels Möller8fb1a6a2019-03-05 14:29:42 +010091 virtual void SetSendTelephoneEventPayloadType(int payload_type,
Niels Möllerdced9f62018-11-19 10:27:07 +010092 int payload_frequency) = 0;
93 virtual bool SendTelephoneEventOutband(int event, int duration_ms) = 0;
Sebastian Jansson254d8692018-11-21 19:19:00 +010094 virtual void OnBitrateAllocation(BitrateAllocationUpdate update) = 0;
Jakob Ivarssonbf087452021-11-11 13:43:49 +010095 virtual int GetTargetBitrate() const = 0;
Niels Möllerdced9f62018-11-19 10:27:07 +010096 virtual void SetInputMute(bool muted) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020097
Niels Möllerdced9f62018-11-19 10:27:07 +010098 virtual void ProcessAndEncodeAudio(
99 std::unique_ptr<AudioFrame> audio_frame) = 0;
Tomas Gunnarssonf25761d2020-06-03 22:55:33 +0200100 virtual RtpRtcpInterface* GetRtpRtcp() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200101
Artem Titovb0ea6372021-07-26 11:47:07 +0200102 // In RTP we currently rely on RTCP packets (`ReceivedRTCPPacket`) to inform
Piotr (Peter) Slatala179a3922018-11-16 09:57:58 -0800103 // about RTT.
104 // In media transport we rely on the TargetTransferRateObserver instead.
105 // In other words, if you are using RTP, you should expect
Artem Titovb0ea6372021-07-26 11:47:07 +0200106 // `ReceivedRTCPPacket` to be called, if you are using media transport,
107 // `OnTargetTransferRate` will be called.
Piotr (Peter) Slatala179a3922018-11-16 09:57:58 -0800108 //
109 // In future, RTP media will move to the media transport implementation and
110 // these conditions will be removed.
Niels Möllerdced9f62018-11-19 10:27:07 +0100111 // Returns the RTT in milliseconds.
112 virtual int64_t GetRTT() const = 0;
113 virtual void StartSend() = 0;
114 virtual void StopSend() = 0;
Piotr (Peter) Slatala179a3922018-11-16 09:57:58 -0800115
Niels Möllerdced9f62018-11-19 10:27:07 +0100116 // E2EE Custom Audio Frame Encryption (Optional)
117 virtual void SetFrameEncryptor(
118 rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor) = 0;
Marina Ciocead2aa8f92020-03-31 11:29:56 +0200119
120 // Sets a frame transformer between encoder and packetizer, to transform
121 // encoded frames before sending them out the network.
122 virtual void SetEncoderToPacketizerFrameTransformer(
123 rtc::scoped_refptr<webrtc::FrameTransformerInterface>
124 frame_transformer) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200125};
126
Niels Möllerdced9f62018-11-19 10:27:07 +0100127std::unique_ptr<ChannelSendInterface> CreateChannelSend(
Sebastian Jansson977b3352019-03-04 17:43:34 +0100128 Clock* clock,
Sebastian Jansson44dd9f22019-03-08 14:50:30 +0100129 TaskQueueFactory* task_queue_factory,
Niels Möllere9771992018-11-26 10:55:07 +0100130 Transport* rtp_transport,
Niels Möllerdced9f62018-11-19 10:27:07 +0100131 RtcpRttStats* rtcp_rtt_stats,
132 RtcEventLog* rtc_event_log,
133 FrameEncryptorInterface* frame_encryptor,
134 const webrtc::CryptoOptions& crypto_options,
135 bool extmap_allow_mixed,
Erik Språng4c2c4122019-07-11 15:20:15 +0200136 int rtcp_report_interval_ms,
Marina Ciocead2aa8f92020-03-31 11:29:56 +0200137 uint32_t ssrc,
Erik Språng2b4d2f32020-06-29 16:37:44 +0200138 rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
Jonas Orelanda943e732022-03-16 13:50:58 +0100139 TransportFeedbackObserver* feedback_observer,
140 const WebRtcKeyValueConfig& field_trials);
Niels Möllerdced9f62018-11-19 10:27:07 +0100141
Niels Möller530ead42018-10-04 14:28:39 +0200142} // namespace voe
143} // namespace webrtc
144
145#endif // AUDIO_CHANNEL_SEND_H_