blob: 053b69a4e040a4d3e542c5eb175476b76b2cedce [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"
Artem Titov741daaf2019-03-21 14:37:36 +010021#include "api/function_view.h"
Sebastian Jansson44dd9f22019-03-08 14:50:30 +010022#include "api/task_queue/task_queue_factory.h"
Niels Möller65f17ca2019-09-12 13:59:36 +020023#include "api/transport/media/media_transport_config.h"
24#include "api/transport/media/media_transport_interface.h"
Henrik Boström6e436d12019-05-27 12:19:33 +020025#include "modules/rtp_rtcp/include/report_block_data.h"
Niels Möller530ead42018-10-04 14:28:39 +020026#include "modules/rtp_rtcp/include/rtp_rtcp.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 ProcessThread;
Niels Möller530ead42018-10-04 14:28:39 +020033class RtcEventLog;
34class RtpRtcp;
35class RtpTransportControllerSendInterface;
36
Niels Möller530ead42018-10-04 14:28:39 +020037struct CallSendStatistics {
38 int64_t rttMs;
Niels Möllerac0a4cb2019-10-09 15:01:33 +020039 int64_t payload_bytes_sent;
40 int64_t header_and_padding_bytes_sent;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +020041 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent
42 uint64_t retransmitted_bytes_sent;
Niels Möller530ead42018-10-04 14:28:39 +020043 int packetsSent;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +020044 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent
45 uint64_t retransmitted_packets_sent;
Henrik Boström6e436d12019-05-27 12:19:33 +020046 // 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;
Niels Möller530ead42018-10-04 14:28:39 +020051};
52
53// See section 6.4.2 in http://www.ietf.org/rfc/rfc3550.txt for details.
54struct ReportBlock {
55 uint32_t sender_SSRC; // SSRC of sender
56 uint32_t source_SSRC;
57 uint8_t fraction_lost;
58 int32_t cumulative_num_packets_lost;
59 uint32_t extended_highest_sequence_number;
60 uint32_t interarrival_jitter;
61 uint32_t last_SR_timestamp;
62 uint32_t delay_since_last_SR;
63};
64
65namespace voe {
66
Niels Möllerdced9f62018-11-19 10:27:07 +010067class ChannelSendInterface {
Niels Möller530ead42018-10-04 14:28:39 +020068 public:
Niels Möllerdced9f62018-11-19 10:27:07 +010069 virtual ~ChannelSendInterface() = default;
Niels Möller530ead42018-10-04 14:28:39 +020070
Niels Möller8fb1a6a2019-03-05 14:29:42 +010071 virtual void ReceivedRTCPPacket(const uint8_t* packet, size_t length) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020072
Niels Möllerdced9f62018-11-19 10:27:07 +010073 virtual CallSendStatistics GetRTCPStatistics() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +020074
Niels Möller8fb1a6a2019-03-05 14:29:42 +010075 virtual void SetEncoder(int payload_type,
Niels Möllerdced9f62018-11-19 10:27:07 +010076 std::unique_ptr<AudioEncoder> encoder) = 0;
77 virtual void ModifyEncoder(
78 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) = 0;
Sebastian Jansson14a7cf92019-02-13 15:11:42 +010079 virtual void CallEncoder(rtc::FunctionView<void(AudioEncoder*)> modifier) = 0;
Niels Möller530ead42018-10-04 14:28:39 +020080
Amit Hilbuch77938e62018-12-21 09:23:38 -080081 // Use 0 to indicate that the extension should not be registered.
82 virtual void SetRid(const std::string& rid,
83 int extension_id,
84 int repaired_extension_id) = 0;
Niels Möllerdced9f62018-11-19 10:27:07 +010085 virtual void SetMid(const std::string& mid, int extension_id) = 0;
86 virtual void SetRTCP_CNAME(absl::string_view c_name) = 0;
87 virtual void SetExtmapAllowMixed(bool extmap_allow_mixed) = 0;
88 virtual void SetSendAudioLevelIndicationStatus(bool enable, int id) = 0;
89 virtual void EnableSendTransportSequenceNumber(int id) = 0;
90 virtual void RegisterSenderCongestionControlObjects(
Niels Möller530ead42018-10-04 14:28:39 +020091 RtpTransportControllerSendInterface* transport,
Niels Möllerdced9f62018-11-19 10:27:07 +010092 RtcpBandwidthObserver* bandwidth_observer) = 0;
93 virtual void ResetSenderCongestionControlObjects() = 0;
94 virtual std::vector<ReportBlock> GetRemoteRTCPReportBlocks() const = 0;
95 virtual ANAStats GetANAStatistics() const = 0;
Niels Mölleree5ccbc2019-03-06 16:47:29 +010096 virtual void RegisterCngPayloadType(int payload_type,
97 int payload_frequency) = 0;
Niels Möller8fb1a6a2019-03-05 14:29:42 +010098 virtual void SetSendTelephoneEventPayloadType(int payload_type,
Niels Möllerdced9f62018-11-19 10:27:07 +010099 int payload_frequency) = 0;
100 virtual bool SendTelephoneEventOutband(int event, int duration_ms) = 0;
Sebastian Jansson254d8692018-11-21 19:19:00 +0100101 virtual void OnBitrateAllocation(BitrateAllocationUpdate update) = 0;
Niels Möllerdced9f62018-11-19 10:27:07 +0100102 virtual int GetBitrate() const = 0;
103 virtual void SetInputMute(bool muted) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200104
Niels Möllerdced9f62018-11-19 10:27:07 +0100105 virtual void ProcessAndEncodeAudio(
106 std::unique_ptr<AudioFrame> audio_frame) = 0;
Niels Möllerdced9f62018-11-19 10:27:07 +0100107 virtual RtpRtcp* GetRtpRtcp() const = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200108
Piotr (Peter) Slatala179a3922018-11-16 09:57:58 -0800109 // In RTP we currently rely on RTCP packets (|ReceivedRTCPPacket|) to inform
110 // about RTT.
111 // In media transport we rely on the TargetTransferRateObserver instead.
112 // In other words, if you are using RTP, you should expect
113 // |ReceivedRTCPPacket| to be called, if you are using media transport,
114 // |OnTargetTransferRate| will be called.
115 //
116 // In future, RTP media will move to the media transport implementation and
117 // these conditions will be removed.
Niels Möllerdced9f62018-11-19 10:27:07 +0100118 // Returns the RTT in milliseconds.
119 virtual int64_t GetRTT() const = 0;
120 virtual void StartSend() = 0;
121 virtual void StopSend() = 0;
Piotr (Peter) Slatala179a3922018-11-16 09:57:58 -0800122
Niels Möllerdced9f62018-11-19 10:27:07 +0100123 // E2EE Custom Audio Frame Encryption (Optional)
124 virtual void SetFrameEncryptor(
125 rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor) = 0;
Niels Möller530ead42018-10-04 14:28:39 +0200126};
127
Niels Möllerdced9f62018-11-19 10:27:07 +0100128std::unique_ptr<ChannelSendInterface> CreateChannelSend(
Sebastian Jansson977b3352019-03-04 17:43:34 +0100129 Clock* clock,
Sebastian Jansson44dd9f22019-03-08 14:50:30 +0100130 TaskQueueFactory* task_queue_factory,
Niels Möllerdced9f62018-11-19 10:27:07 +0100131 ProcessThread* module_process_thread,
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700132 const MediaTransportConfig& media_transport_config,
Anton Sukhanov626015d2019-02-04 15:16:06 -0800133 OverheadObserver* overhead_observer,
Niels Möllere9771992018-11-26 10:55:07 +0100134 Transport* rtp_transport,
Niels Möllerdced9f62018-11-19 10:27:07 +0100135 RtcpRttStats* rtcp_rtt_stats,
136 RtcEventLog* rtc_event_log,
137 FrameEncryptorInterface* frame_encryptor,
138 const webrtc::CryptoOptions& crypto_options,
139 bool extmap_allow_mixed,
Erik Språng4c2c4122019-07-11 15:20:15 +0200140 int rtcp_report_interval_ms,
141 uint32_t ssrc);
Niels Möllerdced9f62018-11-19 10:27:07 +0100142
Niels Möller530ead42018-10-04 14:28:39 +0200143} // namespace voe
144} // namespace webrtc
145
146#endif // AUDIO_CHANNEL_SEND_H_