blob: 8bdcd2b55e6171500c6ce7985c20e08bf8813cdf [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef MEDIA_BASE_MEDIA_CHANNEL_H_
12#define MEDIA_BASE_MEDIA_CHANNEL_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
Steve Antone78bcb92017-10-31 09:53:08 -070014#include <map>
kwiberg686a8ef2016-02-26 03:00:35 -080015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
Patrik Höglundaba85d12017-11-28 15:46:08 +010017#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <vector>
19
Danil Chapovalov00c71832018-06-15 15:58:38 +020020#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "api/audio_codecs/audio_encoder.h"
Niels Möllera6fe2612018-01-19 11:28:54 +010022#include "api/audio_options.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/crypto/frame_decryptor_interface.h"
24#include "api/crypto/frame_encryptor_interface.h"
Anton Sukhanov4f08faa2019-05-21 11:12:57 -070025#include "api/media_transport_config.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/rtc_error.h"
27#include "api/rtp_parameters.h"
28#include "api/rtp_receiver_interface.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010029#include "api/video/video_content_type.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020030#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020031#include "api/video/video_source_interface.h"
32#include "api/video/video_timing.h"
33#include "api/video_codecs/video_encoder_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020034#include "media/base/codec.h"
Ruslan Burakov493a6502019-02-27 15:32:48 +010035#include "media/base/delayable.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "media/base/media_config.h"
37#include "media/base/media_constants.h"
38#include "media/base/stream_params.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010039#include "modules/audio_processing/include/audio_processing_statistics.h"
Steve Anton10542f22019-01-11 09:11:00 -080040#include "rtc_base/async_packet_socket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020041#include "rtc_base/buffer.h"
Steve Anton10542f22019-01-11 09:11:00 -080042#include "rtc_base/copy_on_write_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020043#include "rtc_base/dscp.h"
44#include "rtc_base/logging.h"
Steve Anton10542f22019-01-11 09:11:00 -080045#include "rtc_base/network_route.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020046#include "rtc_base/socket.h"
Steve Anton10542f22019-01-11 09:11:00 -080047#include "rtc_base/string_encode.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020048#include "rtc_base/strings/string_builder.h"
Artem Titove41c4332018-07-25 15:04:28 +020049#include "rtc_base/third_party/sigslot/sigslot.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010050
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000051namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052class Timing;
53}
54
Tommif888bb52015-12-12 01:37:01 +010055namespace webrtc {
56class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080057class VideoFrame;
Yves Gerey665174f2018-06-19 15:03:05 +020058} // namespace webrtc
Tommif888bb52015-12-12 01:37:01 +010059
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060namespace cricket {
61
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080062class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080064struct RtpHeader;
65struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067const int kScreencastDefaultFps = 5;
68
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069template <class T>
Danil Chapovalov00c71832018-06-15 15:58:38 +020070static std::string ToStringIfSet(const char* key,
71 const absl::optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070073 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074 str = key;
75 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070076 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077 str += ", ";
78 }
79 return str;
80}
81
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070082template <class T>
83static std::string VectorToString(const std::vector<T>& vals) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020084 rtc::StringBuilder ost; // no-presubmit-check TODO(webrtc:8982)
Yves Gerey665174f2018-06-19 15:03:05 +020085 ost << "[";
86 for (size_t i = 0; i < vals.size(); ++i) {
87 if (i > 0) {
88 ost << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070089 }
Yves Gerey665174f2018-06-19 15:03:05 +020090 ost << vals[i].ToString();
91 }
92 ost << "]";
Jonas Olsson84df1c72018-09-14 16:59:32 +020093 return ost.Release();
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070094}
95
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
97// Used to be flags, but that makes it hard to selectively apply options.
98// We are moving all of the setting of options to structs like this,
99// but some things currently still use flags.
100struct VideoOptions {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200101 VideoOptions();
102 ~VideoOptions();
103
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700105 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800106 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100107 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108 }
109
110 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800111 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100112 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
113 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114 }
deadbeef119760a2016-04-04 11:43:27 -0700115 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116
117 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200118 rtc::StringBuilder ost;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800121 ost << ToStringIfSet("screencast min bitrate kbps",
122 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100123 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200125 return ost.Release();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126 }
127
nisseb163c3f2016-01-29 01:14:38 -0800128 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700129 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800130 // on to the codec options. Disabled by default.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200131 absl::optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800132 // Force screencast to use a minimum bitrate. This flag comes from
133 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700134 // copied to the encoder config by WebRtcVideoChannel.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200135 absl::optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100136 // Set by screencast sources. Implies selection of encoding settings
137 // suitable for screencast. Most likely not the right way to do
138 // things, e.g., screencast of a text document and screencast of a
139 // youtube video have different needs.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200140 absl::optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700141
142 private:
143 template <typename T>
Danil Chapovalov00c71832018-06-15 15:58:38 +0200144 static void SetFrom(absl::optional<T>* s, const absl::optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700145 if (o) {
146 *s = o;
147 }
148 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149};
150
isheriffa1c548b2016-05-31 16:12:24 -0700151// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
152struct RtpHeaderExtension {
153 RtpHeaderExtension() : id(0) {}
154 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
155
156 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200157 rtc::StringBuilder ost;
isheriffa1c548b2016-05-31 16:12:24 -0700158 ost << "{";
159 ost << "uri: " << uri;
160 ost << ", id: " << id;
161 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200162 return ost.Release();
isheriffa1c548b2016-05-31 16:12:24 -0700163 }
164
165 std::string uri;
166 int id;
167};
168
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169class MediaChannel : public sigslot::has_slots<> {
170 public:
171 class NetworkInterface {
172 public:
173 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700174 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700175 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700176 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700177 const rtc::PacketOptions& options) = 0;
Yves Gerey665174f2018-06-19 15:03:05 +0200178 virtual int SetOption(SocketType type,
179 rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 int option) = 0;
181 virtual ~NetworkInterface() {}
182 };
183
Benjamin Wright84583f62018-10-04 14:22:34 -0700184 explicit MediaChannel(const MediaConfig& config);
185 MediaChannel();
186 ~MediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800188 virtual cricket::MediaType media_type() const = 0;
189
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700190 // Sets the abstract interface class for sending RTP/RTCP data and
191 // interface for media transport (experimental). If media transport is
192 // provided, it should be used instead of RTP/RTCP.
193 // TODO(sukhanov): Currently media transport can co-exist with RTP/RTCP, but
194 // in the future we will refactor code to send all frames with media
195 // transport.
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700196 virtual void SetInterface(
197 NetworkInterface* iface,
198 const webrtc::MediaTransportConfig& media_transport_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199 // Called when a RTP packet is received.
Amit Hilbuche7a5f7b2019-03-12 11:10:27 -0700200 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
Niels Möllere6933812018-11-05 13:01:41 +0100201 int64_t packet_time_us) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202 // Called when a RTCP packet is received.
Amit Hilbuche7a5f7b2019-03-12 11:10:27 -0700203 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer packet,
Niels Möllere6933812018-11-05 13:01:41 +0100204 int64_t packet_time_us) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 // Called when the socket's ability to send has changed.
206 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700207 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700208 virtual void OnNetworkRouteChanged(
209 const std::string& transport_name,
210 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 // Creates a new outgoing media stream with SSRCs and CNAME as described
212 // by sp.
213 virtual bool AddSendStream(const StreamParams& sp) = 0;
214 // Removes an outgoing media stream.
Seth Hampson5897a6e2018-04-03 11:16:33 -0700215 // SSRC must be the first SSRC of the media stream if the stream uses
216 // multiple SSRCs. In the case of an ssrc of 0, the possibly cached
217 // StreamParams is removed.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200218 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700219 // Creates a new incoming media stream with SSRCs, CNAME as described
220 // by sp. In the case of a sp without SSRCs, the unsignaled sp is cached
221 // to be used later for unsignaled streams received.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 virtual bool AddRecvStream(const StreamParams& sp) = 0;
223 // Removes an incoming media stream.
224 // ssrc must be the first SSRC of the media stream if the stream uses
225 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200226 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000227 // Returns the absoulte sendtime extension id value from media channel.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200228 virtual int GetRtpSendTimeExtnId() const;
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700229 // Set the frame encryptor to use on all outgoing frames. This is optional.
230 // This pointers lifetime is managed by the set of RtpSender it is attached
231 // to.
Benjamin Wright84583f62018-10-04 14:22:34 -0700232 // TODO(benwright) make pure virtual once internal supports it.
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700233 virtual void SetFrameEncryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700234 uint32_t ssrc,
235 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor);
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700236 // Set the frame decryptor to use on all incoming frames. This is optional.
237 // This pointers lifetimes is managed by the set of RtpReceivers it is
238 // attached to.
Benjamin Wright84583f62018-10-04 14:22:34 -0700239 // TODO(benwright) make pure virtual once internal supports it.
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700240 virtual void SetFrameDecryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700241 uint32_t ssrc,
242 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000244 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700245 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
246 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700247 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000248 }
249
jbaucheec21bd2016-03-20 06:15:43 -0700250 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
251 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700252 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000253 }
254
255 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000256 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000257 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000258 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000259 if (!network_interface_)
260 return -1;
261
262 return network_interface_->SetOption(type, opt, option);
263 }
264
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700265 const webrtc::MediaTransportConfig& media_transport_config() const {
266 return media_transport_config_;
267 }
268
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700269 webrtc::MediaTransportInterface* media_transport() {
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700270 return media_transport_config_.media_transport;
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700271 }
272
Johannes Kron9190b822018-10-29 11:22:05 +0100273 // Corresponds to the SDP attribute extmap-allow-mixed, see RFC8285.
274 // Set to true if it's allowed to mix one- and two-byte RTP header extensions
275 // in the same stream. The setter and getter must only be called from
276 // worker_thread.
277 void SetExtmapAllowMixed(bool extmap_allow_mixed) {
278 extmap_allow_mixed_ = extmap_allow_mixed;
279 }
280 bool ExtmapAllowMixed() const { return extmap_allow_mixed_; }
281
Amit Hilbuchea7ef2a2019-02-19 15:20:21 -0800282 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
283 virtual webrtc::RTCError SetRtpSendParameters(
284 uint32_t ssrc,
285 const webrtc::RtpParameters& parameters) = 0;
286
Tim Haloun6ca98362018-09-17 17:06:08 -0700287 protected:
Tim Haloun6ca98362018-09-17 17:06:08 -0700288 bool DscpEnabled() const { return enable_dscp_; }
289
Steve Antone25f5952019-03-08 15:09:16 -0800290 // This is the DSCP value used for both RTP and RTCP channels if DSCP is
291 // enabled. It can be changed at any time via |SetPreferredDscp|.
292 rtc::DiffServCodePoint PreferredDscp() const {
293 rtc::CritScope cs(&network_interface_crit_);
294 return preferred_dscp_;
295 }
296
297 int SetPreferredDscp(rtc::DiffServCodePoint preferred_dscp) {
298 rtc::CritScope cs(&network_interface_crit_);
299 if (preferred_dscp == preferred_dscp_) {
300 return 0;
301 }
302 preferred_dscp_ = preferred_dscp;
303 return UpdateDscp();
304 }
305
306 private:
307 // Apply the preferred DSCP setting to the underlying network interface RTP
308 // and RTCP channels. If DSCP is disabled, then apply the default DSCP value.
309 int UpdateDscp() RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_crit_) {
Tim Haloun648d28a2018-10-18 16:52:22 -0700310 rtc::DiffServCodePoint value =
Steve Antone25f5952019-03-08 15:09:16 -0800311 enable_dscp_ ? preferred_dscp_ : rtc::DSCP_DEFAULT;
312 int ret = SetOption(NetworkInterface::ST_RTP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000313 if (ret == 0) {
Yves Gerey665174f2018-06-19 15:03:05 +0200314 ret = SetOption(NetworkInterface::ST_RTCP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000315 }
316 return ret;
317 }
318
jbaucheec21bd2016-03-20 06:15:43 -0700319 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700320 bool rtcp,
321 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000322 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000323 if (!network_interface_)
324 return false;
325
stefanc1aeaf02015-10-15 07:26:07 -0700326 return (!rtcp) ? network_interface_->SendPacket(packet, options)
327 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000328 }
329
nisse51542be2016-02-12 02:27:06 -0800330 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000331 // |network_interface_| can be accessed from the worker_thread and
332 // from any MediaEngine threads. This critical section is to protect accessing
333 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000334 rtc::CriticalSection network_interface_crit_;
Steve Antone25f5952019-03-08 15:09:16 -0800335 NetworkInterface* network_interface_ RTC_GUARDED_BY(network_interface_crit_) =
336 nullptr;
337 rtc::DiffServCodePoint preferred_dscp_
338 RTC_GUARDED_BY(network_interface_crit_) = rtc::DSCP_DEFAULT;
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700339 webrtc::MediaTransportConfig media_transport_config_;
Johannes Kron9190b822018-10-29 11:22:05 +0100340 bool extmap_allow_mixed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341};
342
wu@webrtc.org97077a32013-10-25 21:18:33 +0000343// The stats information is structured as follows:
344// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
345// Media contains a vector of SSRC infos that are exclusively used by this
346// media. (SSRCs shared between media streams can't be represented.)
347
348// Information about an SSRC.
349// This data may be locally recorded, or received in an RTCP SR or RR.
350struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800351 uint32_t ssrc = 0;
352 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000353};
354
355struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800356 uint32_t ssrc = 0;
357 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000358};
359
360struct MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200361 MediaSenderInfo();
362 ~MediaSenderInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200363 void add_ssrc(const SsrcSenderInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000364 // Temporary utility function for call sites that only provide SSRC.
365 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200366 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000367 SsrcSenderInfo stat;
368 stat.ssrc = ssrc;
369 add_ssrc(stat);
370 }
371 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200372 std::vector<uint32_t> ssrcs() const {
373 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000374 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
375 it != local_stats.end(); ++it) {
376 retval.push_back(it->ssrc);
377 }
378 return retval;
379 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100380 // Returns true if the media has been connected.
381 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000382 // Utility accessor for clients that make the assumption only one ssrc
383 // exists per media.
384 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100385 // Call sites that compare this to zero should use connected() instead.
386 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200387 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100388 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000389 return local_stats[0].ssrc;
390 } else {
391 return 0;
392 }
393 }
Steve Anton002f9212018-01-09 16:38:15 -0800394 int64_t bytes_sent = 0;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200395 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent
396 uint64_t retransmitted_bytes_sent = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800397 int packets_sent = 0;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200398 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent
399 uint64_t retransmitted_packets_sent = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800400 int packets_lost = 0;
401 float fraction_lost = 0.0f;
402 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000403 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200404 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000405 std::vector<SsrcSenderInfo> local_stats;
406 std::vector<SsrcReceiverInfo> remote_stats;
407};
408
409struct MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200410 MediaReceiverInfo();
411 ~MediaReceiverInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200412 void add_ssrc(const SsrcReceiverInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000413 // Temporary utility function for call sites that only provide SSRC.
414 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200415 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000416 SsrcReceiverInfo stat;
417 stat.ssrc = ssrc;
418 add_ssrc(stat);
419 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200420 std::vector<uint32_t> ssrcs() const {
421 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000422 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
423 it != local_stats.end(); ++it) {
424 retval.push_back(it->ssrc);
425 }
426 return retval;
427 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100428 // Returns true if the media has been connected.
429 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000430 // Utility accessor for clients that make the assumption only one ssrc
431 // exists per media.
432 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100433 // Call sites that compare this to zero should use connected();
434 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200435 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100436 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000437 return local_stats[0].ssrc;
438 } else {
439 return 0;
440 }
441 }
442
Steve Anton002f9212018-01-09 16:38:15 -0800443 int64_t bytes_rcvd = 0;
444 int packets_rcvd = 0;
445 int packets_lost = 0;
446 float fraction_lost = 0.0f;
Henrik Boström01738c62019-04-15 17:32:00 +0200447 // The timestamp at which the last packet was received, i.e. the time of the
448 // local clock when it was received - not the RTP timestamp of that packet.
449 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
450 absl::optional<int64_t> last_packet_received_timestamp_ms;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000451 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200452 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000453 std::vector<SsrcReceiverInfo> local_stats;
454 std::vector<SsrcSenderInfo> remote_stats;
455};
456
457struct VoiceSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200458 VoiceSenderInfo();
459 ~VoiceSenderInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800460 int ext_seqnum = 0;
461 int jitter_ms = 0;
462 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700463 // See description of "totalAudioEnergy" in the WebRTC stats spec:
464 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800465 double total_input_energy = 0.0;
466 double total_input_duration = 0.0;
Steve Anton002f9212018-01-09 16:38:15 -0800467 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700468 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100469 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470};
471
wu@webrtc.org97077a32013-10-25 21:18:33 +0000472struct VoiceReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200473 VoiceReceiverInfo();
474 ~VoiceReceiverInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800475 int ext_seqnum = 0;
476 int jitter_ms = 0;
477 int jitter_buffer_ms = 0;
478 int jitter_buffer_preferred_ms = 0;
479 int delay_estimate_ms = 0;
480 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200481 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
482 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800483 double total_output_energy = 0.0;
484 uint64_t total_samples_received = 0;
485 double total_output_duration = 0.0;
486 uint64_t concealed_samples = 0;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200487 uint64_t silent_concealed_samples = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800488 uint64_t concealment_events = 0;
Chen Xing0acffb52019-01-15 15:46:29 +0100489 double jitter_buffer_delay_seconds = 0.0;
490 uint64_t jitter_buffer_emitted_count = 0;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200491 uint64_t inserted_samples_for_deceleration = 0;
492 uint64_t removed_samples_for_acceleration = 0;
493 uint64_t fec_packets_received = 0;
494 uint64_t fec_packets_discarded = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200495 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000496 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800497 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000498 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800499 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000500 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800501 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200502 // Fraction of secondary data, including FEC and RED, that is discarded.
503 // Discarding of secondary data can be caused by the reception of the primary
504 // data, obsoleting the secondary data. It can also be caused by early
505 // or late arrival of secondary data. This metric is the percentage of
506 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800507 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200508 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800509 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200510 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800511 float preemptive_expand_rate = 0.0f;
512 int decoding_calls_to_silence_generator = 0;
513 int decoding_calls_to_neteq = 0;
514 int decoding_normal = 0;
515 int decoding_plc = 0;
516 int decoding_cng = 0;
517 int decoding_plc_cng = 0;
518 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000519 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800520 int64_t capture_start_ntp_time_ms = -1;
Ruslan Burakov8af88962018-11-22 17:21:10 +0100521 // Count of the number of buffer flushes.
522 uint64_t jitter_buffer_flushes = 0;
Jakob Ivarsson352ce5c2018-11-27 12:52:16 +0100523 // Number of samples expanded due to delayed packets.
524 uint64_t delayed_packet_outage_samples = 0;
Jakob Ivarsson232b3fd2019-03-06 09:18:40 +0100525 // Arrival delay of received audio packets.
526 double relative_packet_arrival_delay_seconds = 0.0;
Henrik Lundin44125fa2019-04-29 17:00:46 +0200527 // Count and total duration of audio interruptions (loss-concealement periods
528 // longer than 150 ms).
529 int32_t interruption_count = 0;
530 int32_t total_interruption_duration_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000531};
532
wu@webrtc.org97077a32013-10-25 21:18:33 +0000533struct VideoSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200534 VideoSenderInfo();
535 ~VideoSenderInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000536 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800537 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100538 std::string encoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800539 int firs_rcvd = 0;
540 int plis_rcvd = 0;
541 int nacks_rcvd = 0;
542 int send_frame_width = 0;
543 int send_frame_height = 0;
544 int framerate_input = 0;
545 int framerate_sent = 0;
546 int nominal_bitrate = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800547 int adapt_reason = 0;
548 int adapt_changes = 0;
549 int avg_encode_ms = 0;
550 int encode_usage_percent = 0;
551 uint32_t frames_encoded = 0;
Henrik Boströmf71362f2019-04-08 16:14:23 +0200552 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodetime
553 uint64_t total_encode_time_ms = 0;
Henrik Boström23aff9b2019-05-20 15:15:38 +0200554 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget
555 uint64_t total_encoded_bytes_target = 0;
Henrik Boström9fe18342019-05-16 18:38:20 +0200556 uint64_t total_packet_send_delay_ms = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800557 bool has_entered_low_resolution = false;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200558 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800559 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100560 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
561 uint32_t huge_frames_sent = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000562};
563
wu@webrtc.org97077a32013-10-25 21:18:33 +0000564struct VideoReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200565 VideoReceiverInfo();
566 ~VideoReceiverInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000567 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800568 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100569 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800570 int packets_concealed = 0;
571 int firs_sent = 0;
572 int plis_sent = 0;
573 int nacks_sent = 0;
574 int frame_width = 0;
575 int frame_height = 0;
576 int framerate_rcvd = 0;
577 int framerate_decoded = 0;
578 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000579 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800580 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000581 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800582 int framerate_render_output = 0;
583 uint32_t frames_received = 0;
584 uint32_t frames_decoded = 0;
585 uint32_t frames_rendered = 0;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200586 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800587 int64_t interframe_delay_max_ms = -1;
Sergey Silkin02371062019-01-31 16:45:42 +0100588 uint32_t freeze_count = 0;
589 uint32_t pause_count = 0;
590 uint32_t total_freezes_duration_ms = 0;
591 uint32_t total_pauses_duration_ms = 0;
592 uint32_t total_frames_duration_ms = 0;
593 double sum_squared_frame_durations = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000594
Steve Anton002f9212018-01-09 16:38:15 -0800595 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700596
wu@webrtc.org97077a32013-10-25 21:18:33 +0000597 // All stats below are gathered per-VideoReceiver, but some will be correlated
598 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
599 // structures, reflect this in the new layout.
600
601 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800602 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000603 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800604 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000605 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800606 int jitter_buffer_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000607 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800608 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000609 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800610 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000611 // Target overall delay: network+decode+render, accounting for
612 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800613 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000614 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800615 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000616
617 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800618 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700619
Benjamin Wright514f0842018-12-10 09:55:17 -0800620 // First frame received to first frame decoded latency.
621 int64_t first_frame_received_to_decoded_ms = -1;
622
ilnik2edc6842017-07-06 03:06:50 -0700623 // Timing frame info: all important timestamps for a full lifetime of a
624 // single 'timing frame'.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200625 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626};
627
wu@webrtc.org97077a32013-10-25 21:18:33 +0000628struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800629 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630};
631
wu@webrtc.org97077a32013-10-25 21:18:33 +0000632struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800633 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000634};
635
636struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800637 int available_send_bandwidth = 0;
638 int available_recv_bandwidth = 0;
639 int target_enc_bitrate = 0;
640 int actual_enc_bitrate = 0;
641 int retransmit_bitrate = 0;
642 int transmit_bitrate = 0;
643 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644};
645
hbosa65704b2016-11-14 02:28:16 -0800646// Maps from payload type to |RtpCodecParameters|.
647typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
648
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000649struct VoiceMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200650 VoiceMediaInfo();
651 ~VoiceMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000652 void Clear() {
653 senders.clear();
654 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800655 send_codecs.clear();
656 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657 }
658 std::vector<VoiceSenderInfo> senders;
659 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800660 RtpCodecParametersMap send_codecs;
661 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000662};
663
664struct VideoMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200665 VideoMediaInfo();
666 ~VideoMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000667 void Clear() {
668 senders.clear();
669 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700670 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800671 send_codecs.clear();
672 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 }
674 std::vector<VideoSenderInfo> senders;
675 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700676 // Deprecated.
677 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700678 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800679 RtpCodecParametersMap send_codecs;
680 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681};
682
683struct DataMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200684 DataMediaInfo();
685 ~DataMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 void Clear() {
687 senders.clear();
688 receivers.clear();
689 }
690 std::vector<DataSenderInfo> senders;
691 std::vector<DataReceiverInfo> receivers;
692};
693
deadbeef13871492015-12-09 12:37:51 -0800694struct RtcpParameters {
695 bool reduced_size = false;
696};
697
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700698template <class Codec>
699struct RtpParameters {
Steve Anton003930a2018-03-29 12:37:21 -0700700 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700701
702 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700703 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700704 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800705 RtcpParameters rtcp;
Steve Anton003930a2018-03-29 12:37:21 -0700706
707 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200708 rtc::StringBuilder ost;
Steve Anton003930a2018-03-29 12:37:21 -0700709 ost << "{";
710 const char* separator = "";
711 for (const auto& entry : ToStringMap()) {
712 ost << separator << entry.first << ": " << entry.second;
713 separator = ", ";
714 }
715 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200716 return ost.Release();
Steve Anton003930a2018-03-29 12:37:21 -0700717 }
718
719 protected:
720 virtual std::map<std::string, std::string> ToStringMap() const {
721 return {{"codecs", VectorToString(codecs)},
722 {"extensions", VectorToString(extensions)}};
723 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700724};
725
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700726// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
727// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700728template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700729struct RtpSendParameters : RtpParameters<Codec> {
nisse05103312016-03-16 02:22:50 -0700730 int max_bandwidth_bps = -1;
Steve Antonbb50ce52018-03-26 10:24:32 -0700731 // This is the value to be sent in the MID RTP header extension (if the header
732 // extension in included in the list of extensions).
733 std::string mid;
Johannes Kron9190b822018-10-29 11:22:05 +0100734 bool extmap_allow_mixed = false;
Steve Anton003930a2018-03-29 12:37:21 -0700735
736 protected:
737 std::map<std::string, std::string> ToStringMap() const override {
738 auto params = RtpParameters<Codec>::ToStringMap();
739 params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps);
740 params["mid"] = (mid.empty() ? "<not set>" : mid);
Johannes Kron9190b822018-10-29 11:22:05 +0100741 params["extmap-allow-mixed"] = extmap_allow_mixed ? "true" : "false";
Steve Anton003930a2018-03-29 12:37:21 -0700742 return params;
743 }
nisse05103312016-03-16 02:22:50 -0700744};
745
746struct AudioSendParameters : RtpSendParameters<AudioCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200747 AudioSendParameters();
748 ~AudioSendParameters() override;
nisse05103312016-03-16 02:22:50 -0700749 AudioOptions options;
Steve Anton003930a2018-03-29 12:37:21 -0700750
751 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200752 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700753};
754
Yves Gerey665174f2018-06-19 15:03:05 +0200755struct AudioRecvParameters : RtpParameters<AudioCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700756
Ruslan Burakov493a6502019-02-27 15:32:48 +0100757class VoiceMediaChannel : public MediaChannel, public Delayable {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700760 explicit VoiceMediaChannel(const MediaConfig& config)
761 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200762 ~VoiceMediaChannel() override {}
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800763
764 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200765 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
766 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700767 // Get the receive parameters for the incoming stream identified by |ssrc|.
768 // If |ssrc| is 0, retrieve the receive parameters for the default receive
769 // stream, which is used when SSRCs are not signaled. Note that calling with
770 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
771 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700772 virtual webrtc::RtpParameters GetRtpReceiveParameters(
773 uint32_t ssrc) const = 0;
774 virtual bool SetRtpReceiveParameters(
775 uint32_t ssrc,
776 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000777 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700778 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800780 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700781 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200782 virtual bool SetAudioSend(uint32_t ssrc,
783 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700784 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800785 AudioSource* source) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700786 // Set speaker output volume of the specified ssrc.
787 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800789 virtual bool CanInsertDtmf() = 0;
790 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000792 // The valid value for the |event| are 0 to 15 which corresponding to
793 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800794 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 // Gets quality stats for the channel.
796 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100797
798 virtual void SetRawAudioSink(
799 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800800 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700801
802 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803};
804
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700805// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
806// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700807struct VideoSendParameters : RtpSendParameters<VideoCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200808 VideoSendParameters();
809 ~VideoSendParameters() override;
nisse4b4dc862016-02-17 05:25:36 -0800810 // Use conference mode? This flag comes from the remote
811 // description's SDP line 'a=x-google-flag:conference', copied over
812 // by VideoChannel::SetRemoteContent_w, and ultimately used by
813 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700814 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800815 // The special screencast behaviour is disabled by default.
816 bool conference_mode = false;
Steve Anton003930a2018-03-29 12:37:21 -0700817
818 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200819 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700820};
821
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700822// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
823// encapsulate all the parameters needed for a video RtpReceiver.
Yves Gerey665174f2018-06-19 15:03:05 +0200824struct VideoRecvParameters : RtpParameters<VideoCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700825
Ruslan Burakov493a6502019-02-27 15:32:48 +0100826class VideoMediaChannel : public MediaChannel, public Delayable {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 public:
nisse08582ff2016-02-04 01:24:52 -0800828 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700829 explicit VideoMediaChannel(const MediaConfig& config)
830 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200831 ~VideoMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200832
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800833 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200834 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
835 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700836 // Get the receive parameters for the incoming stream identified by |ssrc|.
837 // If |ssrc| is 0, retrieve the receive parameters for the default receive
838 // stream, which is used when SSRCs are not signaled. Note that calling with
839 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
840 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700841 virtual webrtc::RtpParameters GetRtpReceiveParameters(
842 uint32_t ssrc) const = 0;
843 virtual bool SetRtpReceiveParameters(
844 uint32_t ssrc,
845 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 // Gets the currently set codecs/payload types to be used for outgoing media.
847 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 // Starts or stops transmission (and potentially capture) of local video.
849 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700850 // Configure stream for sending and register a source.
851 // The |ssrc| must correspond to a registered send stream.
852 virtual bool SetVideoSend(
853 uint32_t ssrc,
deadbeef5a4a75a2016-06-02 16:23:38 -0700854 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800855 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800856 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -0700857 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800858 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800859 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700860 // This fills the "bitrate parts" (rtx, video bitrate) of the
861 // BandwidthEstimationInfo, since that part that isn't possible to get
862 // through webrtc::Call::GetStats, as they are statistics of the send
863 // streams.
864 // TODO(holmer): We should change this so that either BWE graphs doesn't
865 // need access to bitrates of the streams, or change the (RTC)StatsCollector
866 // so that it's getting the send stream stats separately by calling
867 // GetStats(), and merges with BandwidthEstimationInfo by itself.
868 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000870 virtual bool GetStats(VideoMediaInfo* info) = 0;
Jonas Oreland49ac5952018-09-26 16:04:32 +0200871
872 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873};
874
875enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000876 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
877 // values.
878 DMT_NONE = 0,
879 DMT_CONTROL = 1,
880 DMT_BINARY = 2,
881 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882};
883
884// Info about data received in DataMediaChannel. For use in
885// DataMediaChannel::SignalDataReceived and in all of the signals that
886// signal fires, on up the chain.
887struct ReceiveDataParams {
888 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800889 // RTP data channels use SSRCs, SCTP data channels use SIDs.
890 union {
891 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800892 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800893 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800895 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800897 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800899 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900};
901
902struct SendDataParams {
903 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800904 // RTP data channels use SSRCs, SCTP data channels use SIDs.
905 union {
906 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800907 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800908 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800910 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911
Steve Anton002f9212018-01-09 16:38:15 -0800912 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 // For SCTP, whether to send messages flagged as ordered or not.
914 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800915 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 // For SCTP, whether the messages are sent reliably or not.
917 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800918 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 // For SCTP, if reliable == false, provide partial reliability by
920 // resending up to this many times. Either count or millis
921 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800922 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 // For SCTP, if reliable == false, provide partial reliability by
924 // resending for up to this many milliseconds. Either count or millis
925 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800926 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927};
928
929enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
930
Yves Gerey665174f2018-06-19 15:03:05 +0200931struct DataSendParameters : RtpSendParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700932
Yves Gerey665174f2018-06-19 15:03:05 +0200933struct DataRecvParameters : RtpParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700934
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935class DataMediaChannel : public MediaChannel {
936 public:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200937 DataMediaChannel();
938 explicit DataMediaChannel(const MediaConfig& config);
939 ~DataMediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800941 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200942 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
943 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000944
Amit Hilbuchea7ef2a2019-02-19 15:20:21 -0800945 // RtpParameter methods are not supported for Data channel.
946 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
947 webrtc::RTCError SetRtpSendParameters(
948 uint32_t ssrc,
949 const webrtc::RtpParameters& parameters) override;
950
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 // TODO(pthatcher): Implement this.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200952 virtual bool GetStats(DataMediaInfo* info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953
954 virtual bool SetSend(bool send) = 0;
955 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956
Paulina Hensman11b34f42018-04-09 14:24:52 +0200957 void OnNetworkRouteChanged(const std::string& transport_name,
958 const rtc::NetworkRoute& network_route) override {}
Honghai Zhangcc411c02016-03-29 17:27:21 -0700959
Yves Gerey665174f2018-06-19 15:03:05 +0200960 virtual bool SendData(const SendDataParams& params,
961 const rtc::CopyOnWriteBuffer& payload,
962 SendDataResult* result = NULL) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 // Signals when data is received (params, data, len)
Yves Gerey665174f2018-06-19 15:03:05 +0200964 sigslot::signal3<const ReceiveDataParams&, const char*, size_t>
965 SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000966 // Signal when the media channel is ready to send the stream. Arguments are:
967 // writable(bool)
968 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969};
970
971} // namespace cricket
972
Steve Anton10542f22019-01-11 09:11:00 -0800973#endif // MEDIA_BASE_MEDIA_CHANNEL_H_