blob: 3b9a54c17b30503fa133377fd3ecbc187cb1c9f8 [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"
Henrik Boström87e3f9d2019-05-27 10:44:24 +020040#include "modules/rtp_rtcp/include/report_block_data.h"
Steve Anton10542f22019-01-11 09:11:00 -080041#include "rtc_base/async_packet_socket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020042#include "rtc_base/buffer.h"
Steve Anton10542f22019-01-11 09:11:00 -080043#include "rtc_base/copy_on_write_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020044#include "rtc_base/dscp.h"
45#include "rtc_base/logging.h"
Steve Anton10542f22019-01-11 09:11:00 -080046#include "rtc_base/network_route.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020047#include "rtc_base/socket.h"
Steve Anton10542f22019-01-11 09:11:00 -080048#include "rtc_base/string_encode.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020049#include "rtc_base/strings/string_builder.h"
Artem Titove41c4332018-07-25 15:04:28 +020050#include "rtc_base/third_party/sigslot/sigslot.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010051
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000052namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053class Timing;
54}
55
Tommif888bb52015-12-12 01:37:01 +010056namespace webrtc {
57class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080058class VideoFrame;
Yves Gerey665174f2018-06-19 15:03:05 +020059} // namespace webrtc
Tommif888bb52015-12-12 01:37:01 +010060
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061namespace cricket {
62
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080063class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080065struct RtpHeader;
66struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068const int kScreencastDefaultFps = 5;
69
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070template <class T>
Danil Chapovalov00c71832018-06-15 15:58:38 +020071static std::string ToStringIfSet(const char* key,
72 const absl::optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070074 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075 str = key;
76 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070077 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 str += ", ";
79 }
80 return str;
81}
82
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070083template <class T>
84static std::string VectorToString(const std::vector<T>& vals) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020085 rtc::StringBuilder ost; // no-presubmit-check TODO(webrtc:8982)
Yves Gerey665174f2018-06-19 15:03:05 +020086 ost << "[";
87 for (size_t i = 0; i < vals.size(); ++i) {
88 if (i > 0) {
89 ost << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070090 }
Yves Gerey665174f2018-06-19 15:03:05 +020091 ost << vals[i].ToString();
92 }
93 ost << "]";
Jonas Olsson84df1c72018-09-14 16:59:32 +020094 return ost.Release();
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070095}
96
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
98// Used to be flags, but that makes it hard to selectively apply options.
99// We are moving all of the setting of options to structs like this,
100// but some things currently still use flags.
101struct VideoOptions {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200102 VideoOptions();
103 ~VideoOptions();
104
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700106 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800107 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100108 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 }
110
111 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800112 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100113 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
114 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 }
deadbeef119760a2016-04-04 11:43:27 -0700116 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117
118 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200119 rtc::StringBuilder ost;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800122 ost << ToStringIfSet("screencast min bitrate kbps",
123 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100124 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200126 return ost.Release();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127 }
128
nisseb163c3f2016-01-29 01:14:38 -0800129 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700130 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800131 // on to the codec options. Disabled by default.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200132 absl::optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800133 // Force screencast to use a minimum bitrate. This flag comes from
134 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700135 // copied to the encoder config by WebRtcVideoChannel.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200136 absl::optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100137 // Set by screencast sources. Implies selection of encoding settings
138 // suitable for screencast. Most likely not the right way to do
139 // things, e.g., screencast of a text document and screencast of a
140 // youtube video have different needs.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200141 absl::optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700142
143 private:
144 template <typename T>
Danil Chapovalov00c71832018-06-15 15:58:38 +0200145 static void SetFrom(absl::optional<T>* s, const absl::optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700146 if (o) {
147 *s = o;
148 }
149 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150};
151
isheriffa1c548b2016-05-31 16:12:24 -0700152// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
153struct RtpHeaderExtension {
154 RtpHeaderExtension() : id(0) {}
155 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
156
157 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200158 rtc::StringBuilder ost;
isheriffa1c548b2016-05-31 16:12:24 -0700159 ost << "{";
160 ost << "uri: " << uri;
161 ost << ", id: " << id;
162 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200163 return ost.Release();
isheriffa1c548b2016-05-31 16:12:24 -0700164 }
165
166 std::string uri;
167 int id;
168};
169
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170class MediaChannel : public sigslot::has_slots<> {
171 public:
172 class NetworkInterface {
173 public:
174 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700175 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700176 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700177 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700178 const rtc::PacketOptions& options) = 0;
Yves Gerey665174f2018-06-19 15:03:05 +0200179 virtual int SetOption(SocketType type,
180 rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 int option) = 0;
182 virtual ~NetworkInterface() {}
183 };
184
Benjamin Wright84583f62018-10-04 14:22:34 -0700185 explicit MediaChannel(const MediaConfig& config);
186 MediaChannel();
187 ~MediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800189 virtual cricket::MediaType media_type() const = 0;
190
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700191 // Sets the abstract interface class for sending RTP/RTCP data and
192 // interface for media transport (experimental). If media transport is
193 // provided, it should be used instead of RTP/RTCP.
194 // TODO(sukhanov): Currently media transport can co-exist with RTP/RTCP, but
195 // in the future we will refactor code to send all frames with media
196 // transport.
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700197 virtual void SetInterface(
198 NetworkInterface* iface,
199 const webrtc::MediaTransportConfig& media_transport_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 // Called when a RTP packet is received.
Amit Hilbuche7a5f7b2019-03-12 11:10:27 -0700201 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
Niels Möllere6933812018-11-05 13:01:41 +0100202 int64_t packet_time_us) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 // Called when a RTCP packet is received.
Amit Hilbuche7a5f7b2019-03-12 11:10:27 -0700204 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer packet,
Niels Möllere6933812018-11-05 13:01:41 +0100205 int64_t packet_time_us) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 // Called when the socket's ability to send has changed.
207 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700208 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700209 virtual void OnNetworkRouteChanged(
210 const std::string& transport_name,
211 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 // Creates a new outgoing media stream with SSRCs and CNAME as described
213 // by sp.
214 virtual bool AddSendStream(const StreamParams& sp) = 0;
215 // Removes an outgoing media stream.
Seth Hampson5897a6e2018-04-03 11:16:33 -0700216 // SSRC must be the first SSRC of the media stream if the stream uses
217 // multiple SSRCs. In the case of an ssrc of 0, the possibly cached
218 // StreamParams is removed.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200219 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700220 // Creates a new incoming media stream with SSRCs, CNAME as described
221 // by sp. In the case of a sp without SSRCs, the unsignaled sp is cached
222 // to be used later for unsignaled streams received.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223 virtual bool AddRecvStream(const StreamParams& sp) = 0;
224 // Removes an incoming media stream.
225 // ssrc must be the first SSRC of the media stream if the stream uses
226 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200227 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000228 // Returns the absoulte sendtime extension id value from media channel.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200229 virtual int GetRtpSendTimeExtnId() const;
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700230 // Set the frame encryptor to use on all outgoing frames. This is optional.
231 // This pointers lifetime is managed by the set of RtpSender it is attached
232 // to.
Benjamin Wright84583f62018-10-04 14:22:34 -0700233 // TODO(benwright) make pure virtual once internal supports it.
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700234 virtual void SetFrameEncryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700235 uint32_t ssrc,
236 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor);
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700237 // Set the frame decryptor to use on all incoming frames. This is optional.
238 // This pointers lifetimes is managed by the set of RtpReceivers it is
239 // attached to.
Benjamin Wright84583f62018-10-04 14:22:34 -0700240 // TODO(benwright) make pure virtual once internal supports it.
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700241 virtual void SetFrameDecryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700242 uint32_t ssrc,
243 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000245 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700246 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
247 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700248 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000249 }
250
jbaucheec21bd2016-03-20 06:15:43 -0700251 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
252 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700253 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000254 }
255
256 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000257 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000258 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000259 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000260 if (!network_interface_)
261 return -1;
262
263 return network_interface_->SetOption(type, opt, option);
264 }
265
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700266 const webrtc::MediaTransportConfig& media_transport_config() const {
267 return media_transport_config_;
268 }
269
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700270 webrtc::MediaTransportInterface* media_transport() {
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700271 return media_transport_config_.media_transport;
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700272 }
273
Johannes Kron9190b822018-10-29 11:22:05 +0100274 // Corresponds to the SDP attribute extmap-allow-mixed, see RFC8285.
275 // Set to true if it's allowed to mix one- and two-byte RTP header extensions
276 // in the same stream. The setter and getter must only be called from
277 // worker_thread.
278 void SetExtmapAllowMixed(bool extmap_allow_mixed) {
279 extmap_allow_mixed_ = extmap_allow_mixed;
280 }
281 bool ExtmapAllowMixed() const { return extmap_allow_mixed_; }
282
Amit Hilbuchea7ef2a2019-02-19 15:20:21 -0800283 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
284 virtual webrtc::RTCError SetRtpSendParameters(
285 uint32_t ssrc,
286 const webrtc::RtpParameters& parameters) = 0;
287
Tim Haloun6ca98362018-09-17 17:06:08 -0700288 protected:
Tim Haloun6ca98362018-09-17 17:06:08 -0700289 bool DscpEnabled() const { return enable_dscp_; }
290
Steve Antone25f5952019-03-08 15:09:16 -0800291 // This is the DSCP value used for both RTP and RTCP channels if DSCP is
292 // enabled. It can be changed at any time via |SetPreferredDscp|.
293 rtc::DiffServCodePoint PreferredDscp() const {
294 rtc::CritScope cs(&network_interface_crit_);
295 return preferred_dscp_;
296 }
297
298 int SetPreferredDscp(rtc::DiffServCodePoint preferred_dscp) {
299 rtc::CritScope cs(&network_interface_crit_);
300 if (preferred_dscp == preferred_dscp_) {
301 return 0;
302 }
303 preferred_dscp_ = preferred_dscp;
304 return UpdateDscp();
305 }
306
307 private:
308 // Apply the preferred DSCP setting to the underlying network interface RTP
309 // and RTCP channels. If DSCP is disabled, then apply the default DSCP value.
310 int UpdateDscp() RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_crit_) {
Tim Haloun648d28a2018-10-18 16:52:22 -0700311 rtc::DiffServCodePoint value =
Steve Antone25f5952019-03-08 15:09:16 -0800312 enable_dscp_ ? preferred_dscp_ : rtc::DSCP_DEFAULT;
313 int ret = SetOption(NetworkInterface::ST_RTP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000314 if (ret == 0) {
Yves Gerey665174f2018-06-19 15:03:05 +0200315 ret = SetOption(NetworkInterface::ST_RTCP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000316 }
317 return ret;
318 }
319
jbaucheec21bd2016-03-20 06:15:43 -0700320 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700321 bool rtcp,
322 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000323 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000324 if (!network_interface_)
325 return false;
326
stefanc1aeaf02015-10-15 07:26:07 -0700327 return (!rtcp) ? network_interface_->SendPacket(packet, options)
328 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000329 }
330
nisse51542be2016-02-12 02:27:06 -0800331 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000332 // |network_interface_| can be accessed from the worker_thread and
333 // from any MediaEngine threads. This critical section is to protect accessing
334 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000335 rtc::CriticalSection network_interface_crit_;
Steve Antone25f5952019-03-08 15:09:16 -0800336 NetworkInterface* network_interface_ RTC_GUARDED_BY(network_interface_crit_) =
337 nullptr;
338 rtc::DiffServCodePoint preferred_dscp_
339 RTC_GUARDED_BY(network_interface_crit_) = rtc::DSCP_DEFAULT;
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700340 webrtc::MediaTransportConfig media_transport_config_;
Johannes Kron9190b822018-10-29 11:22:05 +0100341 bool extmap_allow_mixed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342};
343
wu@webrtc.org97077a32013-10-25 21:18:33 +0000344// The stats information is structured as follows:
345// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
346// Media contains a vector of SSRC infos that are exclusively used by this
347// media. (SSRCs shared between media streams can't be represented.)
348
349// Information about an SSRC.
350// This data may be locally recorded, or received in an RTCP SR or RR.
351struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800352 uint32_t ssrc = 0;
353 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000354};
355
356struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800357 uint32_t ssrc = 0;
358 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000359};
360
361struct MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200362 MediaSenderInfo();
363 ~MediaSenderInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200364 void add_ssrc(const SsrcSenderInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000365 // Temporary utility function for call sites that only provide SSRC.
366 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200367 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000368 SsrcSenderInfo stat;
369 stat.ssrc = ssrc;
370 add_ssrc(stat);
371 }
372 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200373 std::vector<uint32_t> ssrcs() const {
374 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000375 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
376 it != local_stats.end(); ++it) {
377 retval.push_back(it->ssrc);
378 }
379 return retval;
380 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100381 // Returns true if the media has been connected.
382 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000383 // Utility accessor for clients that make the assumption only one ssrc
384 // exists per media.
385 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100386 // Call sites that compare this to zero should use connected() instead.
387 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200388 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100389 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000390 return local_stats[0].ssrc;
391 } else {
392 return 0;
393 }
394 }
Steve Anton002f9212018-01-09 16:38:15 -0800395 int64_t bytes_sent = 0;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200396 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent
397 uint64_t retransmitted_bytes_sent = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800398 int packets_sent = 0;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200399 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent
400 uint64_t retransmitted_packets_sent = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800401 int packets_lost = 0;
402 float fraction_lost = 0.0f;
403 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000404 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200405 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000406 std::vector<SsrcSenderInfo> local_stats;
407 std::vector<SsrcReceiverInfo> remote_stats;
Henrik Boström87e3f9d2019-05-27 10:44:24 +0200408 // A snapshot of the most recent Report Block with additional data of interest
409 // to statistics. Used to implement RTCRemoteInboundRtpStreamStats. Within
410 // this list, the ReportBlockData::RTCPReportBlock::source_ssrc(), which is
411 // the SSRC of the corresponding outbound RTP stream, is unique.
412 std::vector<webrtc::ReportBlockData> report_block_datas;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000413};
414
415struct MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200416 MediaReceiverInfo();
417 ~MediaReceiverInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200418 void add_ssrc(const SsrcReceiverInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000419 // Temporary utility function for call sites that only provide SSRC.
420 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200421 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000422 SsrcReceiverInfo stat;
423 stat.ssrc = ssrc;
424 add_ssrc(stat);
425 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200426 std::vector<uint32_t> ssrcs() const {
427 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000428 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
429 it != local_stats.end(); ++it) {
430 retval.push_back(it->ssrc);
431 }
432 return retval;
433 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100434 // Returns true if the media has been connected.
435 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000436 // Utility accessor for clients that make the assumption only one ssrc
437 // exists per media.
438 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100439 // Call sites that compare this to zero should use connected();
440 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200441 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100442 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000443 return local_stats[0].ssrc;
444 } else {
445 return 0;
446 }
447 }
448
Steve Anton002f9212018-01-09 16:38:15 -0800449 int64_t bytes_rcvd = 0;
450 int packets_rcvd = 0;
451 int packets_lost = 0;
452 float fraction_lost = 0.0f;
Henrik Boström01738c62019-04-15 17:32:00 +0200453 // The timestamp at which the last packet was received, i.e. the time of the
454 // local clock when it was received - not the RTP timestamp of that packet.
455 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
456 absl::optional<int64_t> last_packet_received_timestamp_ms;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000457 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200458 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000459 std::vector<SsrcReceiverInfo> local_stats;
460 std::vector<SsrcSenderInfo> remote_stats;
461};
462
463struct VoiceSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200464 VoiceSenderInfo();
465 ~VoiceSenderInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800466 int ext_seqnum = 0;
467 int jitter_ms = 0;
468 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700469 // See description of "totalAudioEnergy" in the WebRTC stats spec:
470 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800471 double total_input_energy = 0.0;
472 double total_input_duration = 0.0;
Steve Anton002f9212018-01-09 16:38:15 -0800473 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700474 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100475 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476};
477
wu@webrtc.org97077a32013-10-25 21:18:33 +0000478struct VoiceReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200479 VoiceReceiverInfo();
480 ~VoiceReceiverInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800481 int ext_seqnum = 0;
482 int jitter_ms = 0;
483 int jitter_buffer_ms = 0;
484 int jitter_buffer_preferred_ms = 0;
485 int delay_estimate_ms = 0;
486 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200487 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
488 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800489 double total_output_energy = 0.0;
490 uint64_t total_samples_received = 0;
491 double total_output_duration = 0.0;
492 uint64_t concealed_samples = 0;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200493 uint64_t silent_concealed_samples = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800494 uint64_t concealment_events = 0;
Chen Xing0acffb52019-01-15 15:46:29 +0100495 double jitter_buffer_delay_seconds = 0.0;
496 uint64_t jitter_buffer_emitted_count = 0;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200497 uint64_t inserted_samples_for_deceleration = 0;
498 uint64_t removed_samples_for_acceleration = 0;
499 uint64_t fec_packets_received = 0;
500 uint64_t fec_packets_discarded = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200501 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000502 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800503 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000504 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800505 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000506 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800507 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200508 // Fraction of secondary data, including FEC and RED, that is discarded.
509 // Discarding of secondary data can be caused by the reception of the primary
510 // data, obsoleting the secondary data. It can also be caused by early
511 // or late arrival of secondary data. This metric is the percentage of
512 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800513 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200514 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800515 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200516 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800517 float preemptive_expand_rate = 0.0f;
518 int decoding_calls_to_silence_generator = 0;
519 int decoding_calls_to_neteq = 0;
520 int decoding_normal = 0;
521 int decoding_plc = 0;
522 int decoding_cng = 0;
523 int decoding_plc_cng = 0;
524 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000525 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800526 int64_t capture_start_ntp_time_ms = -1;
Ruslan Burakov8af88962018-11-22 17:21:10 +0100527 // Count of the number of buffer flushes.
528 uint64_t jitter_buffer_flushes = 0;
Jakob Ivarsson352ce5c2018-11-27 12:52:16 +0100529 // Number of samples expanded due to delayed packets.
530 uint64_t delayed_packet_outage_samples = 0;
Jakob Ivarsson232b3fd2019-03-06 09:18:40 +0100531 // Arrival delay of received audio packets.
532 double relative_packet_arrival_delay_seconds = 0.0;
Henrik Lundin44125fa2019-04-29 17:00:46 +0200533 // Count and total duration of audio interruptions (loss-concealement periods
534 // longer than 150 ms).
535 int32_t interruption_count = 0;
536 int32_t total_interruption_duration_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537};
538
wu@webrtc.org97077a32013-10-25 21:18:33 +0000539struct VideoSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200540 VideoSenderInfo();
541 ~VideoSenderInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000542 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800543 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100544 std::string encoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800545 int firs_rcvd = 0;
546 int plis_rcvd = 0;
547 int nacks_rcvd = 0;
548 int send_frame_width = 0;
549 int send_frame_height = 0;
550 int framerate_input = 0;
551 int framerate_sent = 0;
552 int nominal_bitrate = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800553 int adapt_reason = 0;
554 int adapt_changes = 0;
555 int avg_encode_ms = 0;
556 int encode_usage_percent = 0;
557 uint32_t frames_encoded = 0;
Henrik Boströmf71362f2019-04-08 16:14:23 +0200558 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodetime
559 uint64_t total_encode_time_ms = 0;
Henrik Boström23aff9b2019-05-20 15:15:38 +0200560 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget
561 uint64_t total_encoded_bytes_target = 0;
Henrik Boström9fe18342019-05-16 18:38:20 +0200562 uint64_t total_packet_send_delay_ms = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800563 bool has_entered_low_resolution = false;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200564 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800565 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100566 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
567 uint32_t huge_frames_sent = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568};
569
wu@webrtc.org97077a32013-10-25 21:18:33 +0000570struct VideoReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200571 VideoReceiverInfo();
572 ~VideoReceiverInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000573 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800574 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100575 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800576 int packets_concealed = 0;
577 int firs_sent = 0;
578 int plis_sent = 0;
579 int nacks_sent = 0;
580 int frame_width = 0;
581 int frame_height = 0;
582 int framerate_rcvd = 0;
583 int framerate_decoded = 0;
584 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000585 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800586 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000587 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800588 int framerate_render_output = 0;
589 uint32_t frames_received = 0;
590 uint32_t frames_decoded = 0;
591 uint32_t frames_rendered = 0;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200592 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800593 int64_t interframe_delay_max_ms = -1;
Sergey Silkin02371062019-01-31 16:45:42 +0100594 uint32_t freeze_count = 0;
595 uint32_t pause_count = 0;
596 uint32_t total_freezes_duration_ms = 0;
597 uint32_t total_pauses_duration_ms = 0;
598 uint32_t total_frames_duration_ms = 0;
599 double sum_squared_frame_durations = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000600
Steve Anton002f9212018-01-09 16:38:15 -0800601 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700602
wu@webrtc.org97077a32013-10-25 21:18:33 +0000603 // All stats below are gathered per-VideoReceiver, but some will be correlated
604 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
605 // structures, reflect this in the new layout.
606
607 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800608 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000609 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800610 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000611 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800612 int jitter_buffer_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000613 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800614 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000615 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800616 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000617 // Target overall delay: network+decode+render, accounting for
618 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800619 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000620 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800621 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000622
623 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800624 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700625
Benjamin Wright514f0842018-12-10 09:55:17 -0800626 // First frame received to first frame decoded latency.
627 int64_t first_frame_received_to_decoded_ms = -1;
628
ilnik2edc6842017-07-06 03:06:50 -0700629 // Timing frame info: all important timestamps for a full lifetime of a
630 // single 'timing frame'.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200631 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632};
633
wu@webrtc.org97077a32013-10-25 21:18:33 +0000634struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800635 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636};
637
wu@webrtc.org97077a32013-10-25 21:18:33 +0000638struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800639 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640};
641
642struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800643 int available_send_bandwidth = 0;
644 int available_recv_bandwidth = 0;
645 int target_enc_bitrate = 0;
646 int actual_enc_bitrate = 0;
647 int retransmit_bitrate = 0;
648 int transmit_bitrate = 0;
649 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000650};
651
hbosa65704b2016-11-14 02:28:16 -0800652// Maps from payload type to |RtpCodecParameters|.
653typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
654
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655struct VoiceMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200656 VoiceMediaInfo();
657 ~VoiceMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000658 void Clear() {
659 senders.clear();
660 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800661 send_codecs.clear();
662 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000663 }
664 std::vector<VoiceSenderInfo> senders;
665 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800666 RtpCodecParametersMap send_codecs;
667 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668};
669
670struct VideoMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200671 VideoMediaInfo();
672 ~VideoMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 void Clear() {
674 senders.clear();
675 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700676 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800677 send_codecs.clear();
678 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 }
680 std::vector<VideoSenderInfo> senders;
681 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700682 // Deprecated.
683 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700684 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800685 RtpCodecParametersMap send_codecs;
686 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687};
688
689struct DataMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200690 DataMediaInfo();
691 ~DataMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 void Clear() {
693 senders.clear();
694 receivers.clear();
695 }
696 std::vector<DataSenderInfo> senders;
697 std::vector<DataReceiverInfo> receivers;
698};
699
deadbeef13871492015-12-09 12:37:51 -0800700struct RtcpParameters {
701 bool reduced_size = false;
702};
703
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700704template <class Codec>
705struct RtpParameters {
Steve Anton003930a2018-03-29 12:37:21 -0700706 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700707
708 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700709 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700710 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800711 RtcpParameters rtcp;
Steve Anton003930a2018-03-29 12:37:21 -0700712
713 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200714 rtc::StringBuilder ost;
Steve Anton003930a2018-03-29 12:37:21 -0700715 ost << "{";
716 const char* separator = "";
717 for (const auto& entry : ToStringMap()) {
718 ost << separator << entry.first << ": " << entry.second;
719 separator = ", ";
720 }
721 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200722 return ost.Release();
Steve Anton003930a2018-03-29 12:37:21 -0700723 }
724
725 protected:
726 virtual std::map<std::string, std::string> ToStringMap() const {
727 return {{"codecs", VectorToString(codecs)},
728 {"extensions", VectorToString(extensions)}};
729 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700730};
731
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700732// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
733// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700734template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700735struct RtpSendParameters : RtpParameters<Codec> {
nisse05103312016-03-16 02:22:50 -0700736 int max_bandwidth_bps = -1;
Steve Antonbb50ce52018-03-26 10:24:32 -0700737 // This is the value to be sent in the MID RTP header extension (if the header
738 // extension in included in the list of extensions).
739 std::string mid;
Johannes Kron9190b822018-10-29 11:22:05 +0100740 bool extmap_allow_mixed = false;
Steve Anton003930a2018-03-29 12:37:21 -0700741
742 protected:
743 std::map<std::string, std::string> ToStringMap() const override {
744 auto params = RtpParameters<Codec>::ToStringMap();
745 params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps);
746 params["mid"] = (mid.empty() ? "<not set>" : mid);
Johannes Kron9190b822018-10-29 11:22:05 +0100747 params["extmap-allow-mixed"] = extmap_allow_mixed ? "true" : "false";
Steve Anton003930a2018-03-29 12:37:21 -0700748 return params;
749 }
nisse05103312016-03-16 02:22:50 -0700750};
751
752struct AudioSendParameters : RtpSendParameters<AudioCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200753 AudioSendParameters();
754 ~AudioSendParameters() override;
nisse05103312016-03-16 02:22:50 -0700755 AudioOptions options;
Steve Anton003930a2018-03-29 12:37:21 -0700756
757 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200758 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700759};
760
Yves Gerey665174f2018-06-19 15:03:05 +0200761struct AudioRecvParameters : RtpParameters<AudioCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700762
Ruslan Burakov493a6502019-02-27 15:32:48 +0100763class VoiceMediaChannel : public MediaChannel, public Delayable {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000764 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700766 explicit VoiceMediaChannel(const MediaConfig& config)
767 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200768 ~VoiceMediaChannel() override {}
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800769
770 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200771 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
772 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700773 // Get the receive parameters for the incoming stream identified by |ssrc|.
774 // If |ssrc| is 0, retrieve the receive parameters for the default receive
775 // stream, which is used when SSRCs are not signaled. Note that calling with
776 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
777 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700778 virtual webrtc::RtpParameters GetRtpReceiveParameters(
779 uint32_t ssrc) const = 0;
780 virtual bool SetRtpReceiveParameters(
781 uint32_t ssrc,
782 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700784 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800786 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700787 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200788 virtual bool SetAudioSend(uint32_t ssrc,
789 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700790 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800791 AudioSource* source) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700792 // Set speaker output volume of the specified ssrc.
793 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800795 virtual bool CanInsertDtmf() = 0;
796 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000798 // The valid value for the |event| are 0 to 15 which corresponding to
799 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800800 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 // Gets quality stats for the channel.
802 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100803
804 virtual void SetRawAudioSink(
805 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800806 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700807
808 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809};
810
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700811// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
812// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700813struct VideoSendParameters : RtpSendParameters<VideoCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200814 VideoSendParameters();
815 ~VideoSendParameters() override;
nisse4b4dc862016-02-17 05:25:36 -0800816 // Use conference mode? This flag comes from the remote
817 // description's SDP line 'a=x-google-flag:conference', copied over
818 // by VideoChannel::SetRemoteContent_w, and ultimately used by
819 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700820 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800821 // The special screencast behaviour is disabled by default.
822 bool conference_mode = false;
Steve Anton003930a2018-03-29 12:37:21 -0700823
824 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200825 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700826};
827
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700828// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
829// encapsulate all the parameters needed for a video RtpReceiver.
Yves Gerey665174f2018-06-19 15:03:05 +0200830struct VideoRecvParameters : RtpParameters<VideoCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700831
Ruslan Burakov493a6502019-02-27 15:32:48 +0100832class VideoMediaChannel : public MediaChannel, public Delayable {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833 public:
nisse08582ff2016-02-04 01:24:52 -0800834 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700835 explicit VideoMediaChannel(const MediaConfig& config)
836 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200837 ~VideoMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200838
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800839 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200840 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
841 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700842 // Get the receive parameters for the incoming stream identified by |ssrc|.
843 // If |ssrc| is 0, retrieve the receive parameters for the default receive
844 // stream, which is used when SSRCs are not signaled. Note that calling with
845 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
846 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700847 virtual webrtc::RtpParameters GetRtpReceiveParameters(
848 uint32_t ssrc) const = 0;
849 virtual bool SetRtpReceiveParameters(
850 uint32_t ssrc,
851 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 // Gets the currently set codecs/payload types to be used for outgoing media.
853 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 // Starts or stops transmission (and potentially capture) of local video.
855 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700856 // Configure stream for sending and register a source.
857 // The |ssrc| must correspond to a registered send stream.
858 virtual bool SetVideoSend(
859 uint32_t ssrc,
deadbeef5a4a75a2016-06-02 16:23:38 -0700860 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800861 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800862 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -0700863 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800864 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800865 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700866 // This fills the "bitrate parts" (rtx, video bitrate) of the
867 // BandwidthEstimationInfo, since that part that isn't possible to get
868 // through webrtc::Call::GetStats, as they are statistics of the send
869 // streams.
870 // TODO(holmer): We should change this so that either BWE graphs doesn't
871 // need access to bitrates of the streams, or change the (RTC)StatsCollector
872 // so that it's getting the send stream stats separately by calling
873 // GetStats(), and merges with BandwidthEstimationInfo by itself.
874 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000876 virtual bool GetStats(VideoMediaInfo* info) = 0;
Jonas Oreland49ac5952018-09-26 16:04:32 +0200877
878 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879};
880
881enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000882 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
883 // values.
884 DMT_NONE = 0,
885 DMT_CONTROL = 1,
886 DMT_BINARY = 2,
887 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888};
889
890// Info about data received in DataMediaChannel. For use in
891// DataMediaChannel::SignalDataReceived and in all of the signals that
892// signal fires, on up the chain.
893struct ReceiveDataParams {
894 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800895 // RTP data channels use SSRCs, SCTP data channels use SIDs.
896 union {
897 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800898 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800899 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800901 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800903 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800905 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906};
907
908struct SendDataParams {
909 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800910 // RTP data channels use SSRCs, SCTP data channels use SIDs.
911 union {
912 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800913 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800914 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800916 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917
Steve Anton002f9212018-01-09 16:38:15 -0800918 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 // For SCTP, whether to send messages flagged as ordered or not.
920 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800921 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 // For SCTP, whether the messages are sent reliably or not.
923 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800924 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 // For SCTP, if reliable == false, provide partial reliability by
926 // resending up to this many times. Either count or millis
927 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800928 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 // For SCTP, if reliable == false, provide partial reliability by
930 // resending for up to this many milliseconds. Either count or millis
931 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800932 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933};
934
935enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
936
Yves Gerey665174f2018-06-19 15:03:05 +0200937struct DataSendParameters : RtpSendParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700938
Yves Gerey665174f2018-06-19 15:03:05 +0200939struct DataRecvParameters : RtpParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700940
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941class DataMediaChannel : public MediaChannel {
942 public:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200943 DataMediaChannel();
944 explicit DataMediaChannel(const MediaConfig& config);
945 ~DataMediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800947 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200948 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
949 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000950
Amit Hilbuchea7ef2a2019-02-19 15:20:21 -0800951 // RtpParameter methods are not supported for Data channel.
952 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
953 webrtc::RTCError SetRtpSendParameters(
954 uint32_t ssrc,
955 const webrtc::RtpParameters& parameters) override;
956
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 // TODO(pthatcher): Implement this.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200958 virtual bool GetStats(DataMediaInfo* info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959
960 virtual bool SetSend(bool send) = 0;
961 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962
Paulina Hensman11b34f42018-04-09 14:24:52 +0200963 void OnNetworkRouteChanged(const std::string& transport_name,
964 const rtc::NetworkRoute& network_route) override {}
Honghai Zhangcc411c02016-03-29 17:27:21 -0700965
Yves Gerey665174f2018-06-19 15:03:05 +0200966 virtual bool SendData(const SendDataParams& params,
967 const rtc::CopyOnWriteBuffer& payload,
968 SendDataResult* result = NULL) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 // Signals when data is received (params, data, len)
Yves Gerey665174f2018-06-19 15:03:05 +0200970 sigslot::signal3<const ReceiveDataParams&, const char*, size_t>
971 SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000972 // Signal when the media channel is ready to send the stream. Arguments are:
973 // writable(bool)
974 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975};
976
977} // namespace cricket
978
Steve Anton10542f22019-01-11 09:11:00 -0800979#endif // MEDIA_BASE_MEDIA_CHANNEL_H_