• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/frame_transformer_interface.h"
22 #include "api/function_view.h"
23 #include "api/task_queue/task_queue_factory.h"
24 #include "modules/rtp_rtcp/include/report_block_data.h"
25 #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
26 #include "modules/rtp_rtcp/source/rtp_sender_audio.h"
27 
28 namespace webrtc {
29 
30 class FrameEncryptorInterface;
31 class ProcessThread;
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-retransmittedpacketssent
43   uint64_t retransmitted_packets_sent;
44   // 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;
49 };
50 
51 // See section 6.4.2 in http://www.ietf.org/rfc/rfc3550.txt for details.
52 struct ReportBlock {
53   uint32_t sender_SSRC;  // SSRC of sender
54   uint32_t source_SSRC;
55   uint8_t fraction_lost;
56   int32_t cumulative_num_packets_lost;
57   uint32_t extended_highest_sequence_number;
58   uint32_t interarrival_jitter;
59   uint32_t last_SR_timestamp;
60   uint32_t delay_since_last_SR;
61 };
62 
63 namespace voe {
64 
65 class ChannelSendInterface {
66  public:
67   virtual ~ChannelSendInterface() = default;
68 
69   virtual void ReceivedRTCPPacket(const uint8_t* packet, size_t length) = 0;
70 
71   virtual CallSendStatistics GetRTCPStatistics() const = 0;
72 
73   virtual void SetEncoder(int payload_type,
74                           std::unique_ptr<AudioEncoder> encoder) = 0;
75   virtual void ModifyEncoder(
76       rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) = 0;
77   virtual void CallEncoder(rtc::FunctionView<void(AudioEncoder*)> modifier) = 0;
78 
79   // Use 0 to indicate that the extension should not be registered.
80   virtual void SetRTCP_CNAME(absl::string_view c_name) = 0;
81   virtual void SetSendAudioLevelIndicationStatus(bool enable, int id) = 0;
82   virtual void RegisterSenderCongestionControlObjects(
83       RtpTransportControllerSendInterface* transport,
84       RtcpBandwidthObserver* bandwidth_observer) = 0;
85   virtual void ResetSenderCongestionControlObjects() = 0;
86   virtual std::vector<ReportBlock> GetRemoteRTCPReportBlocks() const = 0;
87   virtual ANAStats GetANAStatistics() const = 0;
88   virtual void RegisterCngPayloadType(int payload_type,
89                                       int payload_frequency) = 0;
90   virtual void SetSendTelephoneEventPayloadType(int payload_type,
91                                                 int payload_frequency) = 0;
92   virtual bool SendTelephoneEventOutband(int event, int duration_ms) = 0;
93   virtual void OnBitrateAllocation(BitrateAllocationUpdate update) = 0;
94   virtual int GetBitrate() const = 0;
95   virtual void SetInputMute(bool muted) = 0;
96 
97   virtual void ProcessAndEncodeAudio(
98       std::unique_ptr<AudioFrame> audio_frame) = 0;
99   virtual RtpRtcpInterface* GetRtpRtcp() const = 0;
100 
101   // In RTP we currently rely on RTCP packets (|ReceivedRTCPPacket|) to inform
102   // about RTT.
103   // In media transport we rely on the TargetTransferRateObserver instead.
104   // In other words, if you are using RTP, you should expect
105   // |ReceivedRTCPPacket| to be called, if you are using media transport,
106   // |OnTargetTransferRate| will be called.
107   //
108   // In future, RTP media will move to the media transport implementation and
109   // these conditions will be removed.
110   // Returns the RTT in milliseconds.
111   virtual int64_t GetRTT() const = 0;
112   virtual void StartSend() = 0;
113   virtual void StopSend() = 0;
114 
115   // E2EE Custom Audio Frame Encryption (Optional)
116   virtual void SetFrameEncryptor(
117       rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor) = 0;
118 
119   // Sets a frame transformer between encoder and packetizer, to transform
120   // encoded frames before sending them out the network.
121   virtual void SetEncoderToPacketizerFrameTransformer(
122       rtc::scoped_refptr<webrtc::FrameTransformerInterface>
123           frame_transformer) = 0;
124 };
125 
126 std::unique_ptr<ChannelSendInterface> CreateChannelSend(
127     Clock* clock,
128     TaskQueueFactory* task_queue_factory,
129     ProcessThread* module_process_thread,
130     Transport* rtp_transport,
131     RtcpRttStats* rtcp_rtt_stats,
132     RtcEventLog* rtc_event_log,
133     FrameEncryptorInterface* frame_encryptor,
134     const webrtc::CryptoOptions& crypto_options,
135     bool extmap_allow_mixed,
136     int rtcp_report_interval_ms,
137     uint32_t ssrc,
138     rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
139     TransportFeedbackObserver* feedback_observer);
140 
141 }  // namespace voe
142 }  // namespace webrtc
143 
144 #endif  // AUDIO_CHANNEL_SEND_H_
145