• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2015 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 CALL_AUDIO_SEND_STREAM_H_
12 #define CALL_AUDIO_SEND_STREAM_H_
13 
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "absl/types/optional.h"
19 #include "api/audio_codecs/audio_codec_pair_id.h"
20 #include "api/audio_codecs/audio_encoder.h"
21 #include "api/audio_codecs/audio_encoder_factory.h"
22 #include "api/audio_codecs/audio_format.h"
23 #include "api/call/transport.h"
24 #include "api/crypto/crypto_options.h"
25 #include "api/crypto/frame_encryptor_interface.h"
26 #include "api/frame_transformer_interface.h"
27 #include "api/rtp_parameters.h"
28 #include "api/rtp_sender_interface.h"
29 #include "api/scoped_refptr.h"
30 #include "call/audio_sender.h"
31 #include "call/rtp_config.h"
32 #include "modules/audio_processing/include/audio_processing_statistics.h"
33 #include "modules/rtp_rtcp/include/report_block_data.h"
34 
35 namespace webrtc {
36 
37 class AudioSendStream : public AudioSender {
38  public:
39   struct Stats {
40     Stats();
41     ~Stats();
42 
43     // TODO(solenberg): Harmonize naming and defaults with receive stream stats.
44     uint32_t local_ssrc = 0;
45     int64_t payload_bytes_sent = 0;
46     int64_t header_and_padding_bytes_sent = 0;
47     // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent
48     uint64_t retransmitted_bytes_sent = 0;
49     int32_t packets_sent = 0;
50     // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalpacketsenddelay
51     TimeDelta total_packet_send_delay = TimeDelta::Zero();
52     // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent
53     uint64_t retransmitted_packets_sent = 0;
54     int32_t packets_lost = -1;
55     float fraction_lost = -1.0f;
56     std::string codec_name;
57     absl::optional<int> codec_payload_type;
58     int32_t jitter_ms = -1;
59     int64_t rtt_ms = -1;
60     int16_t audio_level = 0;
61     // See description of "totalAudioEnergy" in the WebRTC stats spec:
62     // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
63     double total_input_energy = 0.0;
64     double total_input_duration = 0.0;
65 
66     ANAStats ana_statistics;
67     AudioProcessingStats apm_statistics;
68 
69     int64_t target_bitrate_bps = 0;
70     // A snapshot of Report Blocks with additional data of interest to
71     // statistics. Within this list, the sender-source SSRC pair is unique and
72     // per-pair the ReportBlockData represents the latest Report Block that was
73     // received for that pair.
74     std::vector<ReportBlockData> report_block_datas;
75     uint32_t nacks_rcvd = 0;
76   };
77 
78   struct Config {
79     Config() = delete;
80     explicit Config(Transport* send_transport);
81     ~Config();
82     std::string ToString() const;
83 
84     // Send-stream specific RTP settings.
85     struct Rtp {
86       Rtp();
87       ~Rtp();
88       std::string ToString() const;
89 
90       // Sender SSRC.
91       uint32_t ssrc = 0;
92 
93       // The value to send in the RID RTP header extension if the extension is
94       // included in the list of extensions.
95       std::string rid;
96 
97       // The value to send in the MID RTP header extension if the extension is
98       // included in the list of extensions.
99       std::string mid;
100 
101       // Corresponds to the SDP attribute extmap-allow-mixed.
102       bool extmap_allow_mixed = false;
103 
104       // RTP header extensions used for the sent stream.
105       std::vector<RtpExtension> extensions;
106 
107       // RTCP CNAME, see RFC 3550.
108       std::string c_name;
109     } rtp;
110 
111     // Time interval between RTCP report for audio
112     int rtcp_report_interval_ms = 5000;
113 
114     // Transport for outgoing packets. The transport is expected to exist for
115     // the entire life of the AudioSendStream and is owned by the API client.
116     Transport* send_transport = nullptr;
117 
118     // Bitrate limits used for variable audio bitrate streams. Set both to -1 to
119     // disable audio bitrate adaptation.
120     // Note: This is still an experimental feature and not ready for real usage.
121     int min_bitrate_bps = -1;
122     int max_bitrate_bps = -1;
123 
124     double bitrate_priority = 1.0;
125     bool has_dscp = false;
126 
127     // Defines whether to turn on audio network adaptor, and defines its config
128     // string.
129     absl::optional<std::string> audio_network_adaptor_config;
130 
131     struct SendCodecSpec {
132       SendCodecSpec(int payload_type, const SdpAudioFormat& format);
133       ~SendCodecSpec();
134       std::string ToString() const;
135 
136       bool operator==(const SendCodecSpec& rhs) const;
137       bool operator!=(const SendCodecSpec& rhs) const {
138         return !(*this == rhs);
139       }
140 
141       int payload_type;
142       SdpAudioFormat format;
143       bool nack_enabled = false;
144       bool transport_cc_enabled = false;
145       bool enable_non_sender_rtt = false;
146       absl::optional<int> cng_payload_type;
147       absl::optional<int> red_payload_type;
148       // If unset, use the encoder's default target bitrate.
149       absl::optional<int> target_bitrate_bps;
150     };
151 
152     absl::optional<SendCodecSpec> send_codec_spec;
153     rtc::scoped_refptr<AudioEncoderFactory> encoder_factory;
154     absl::optional<AudioCodecPairId> codec_pair_id;
155 
156     // Track ID as specified during track creation.
157     std::string track_id;
158 
159     // Per PeerConnection crypto options.
160     webrtc::CryptoOptions crypto_options;
161 
162     // An optional custom frame encryptor that allows the entire frame to be
163     // encryptor in whatever way the caller choses. This is not required by
164     // default.
165     rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor;
166 
167     // An optional frame transformer used by insertable streams to transform
168     // encoded frames.
169     rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
170   };
171 
172   virtual ~AudioSendStream() = default;
173 
174   virtual const webrtc::AudioSendStream::Config& GetConfig() const = 0;
175 
176   // Reconfigure the stream according to the Configuration.
177   virtual void Reconfigure(const Config& config,
178                            SetParametersCallback callback) = 0;
179 
180   // Starts stream activity.
181   // When a stream is active, it can receive, process and deliver packets.
182   virtual void Start() = 0;
183   // Stops stream activity.
184   // When a stream is stopped, it can't receive, process or deliver packets.
185   virtual void Stop() = 0;
186 
187   // TODO(solenberg): Make payload_type a config property instead.
188   virtual bool SendTelephoneEvent(int payload_type,
189                                   int payload_frequency,
190                                   int event,
191                                   int duration_ms) = 0;
192 
193   virtual void SetMuted(bool muted) = 0;
194 
195   virtual Stats GetStats() const = 0;
196   virtual Stats GetStats(bool has_remote_tracks) const = 0;
197 };
198 
199 }  // namespace webrtc
200 
201 #endif  // CALL_AUDIO_SEND_STREAM_H_
202