blob: a4a75ed4dd6d07c905e3b78cf63b305b7131218d [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MEDIA_BASE_MEDIACHANNEL_H_
12#define MEDIA_BASE_MEDIACHANNEL_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"
Zach Steinba37b4b2018-01-23 15:02:36 -080023#include "api/rtcerror.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "api/rtpparameters.h"
25#include "api/rtpreceiverinterface.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010026#include "api/video/video_content_type.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020027#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020028#include "api/video/video_source_interface.h"
29#include "api/video/video_timing.h"
30#include "api/video_codecs/video_encoder_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "media/base/codec.h"
Niels Möller6daa2782018-01-23 10:37:42 +010032#include "media/base/mediaconfig.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "media/base/mediaconstants.h"
34#include "media/base/streamparams.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010035#include "modules/audio_processing/include/audio_processing_statistics.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010036#include "rtc_base/asyncpacketsocket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020037#include "rtc_base/buffer.h"
38#include "rtc_base/copyonwritebuffer.h"
39#include "rtc_base/dscp.h"
40#include "rtc_base/logging.h"
41#include "rtc_base/networkroute.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020042#include "rtc_base/socket.h"
Niels Möller9a44f962017-12-08 15:57:38 +010043#include "rtc_base/stringencode.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020044#include "rtc_base/strings/string_builder.h"
Artem Titove41c4332018-07-25 15:04:28 +020045#include "rtc_base/third_party/sigslot/sigslot.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010046
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000047namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048class Timing;
49}
50
Tommif888bb52015-12-12 01:37:01 +010051namespace webrtc {
52class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080053class VideoFrame;
Yves Gerey665174f2018-06-19 15:03:05 +020054} // namespace webrtc
Tommif888bb52015-12-12 01:37:01 +010055
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056namespace cricket {
57
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080058class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080060struct RtpHeader;
61struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063const int kScreencastDefaultFps = 5;
64
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065template <class T>
Danil Chapovalov00c71832018-06-15 15:58:38 +020066static std::string ToStringIfSet(const char* key,
67 const absl::optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070069 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070 str = key;
71 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070072 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 str += ", ";
74 }
75 return str;
76}
77
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070078template <class T>
79static std::string VectorToString(const std::vector<T>& vals) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020080 rtc::StringBuilder ost; // no-presubmit-check TODO(webrtc:8982)
Yves Gerey665174f2018-06-19 15:03:05 +020081 ost << "[";
82 for (size_t i = 0; i < vals.size(); ++i) {
83 if (i > 0) {
84 ost << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070085 }
Yves Gerey665174f2018-06-19 15:03:05 +020086 ost << vals[i].ToString();
87 }
88 ost << "]";
89 return ost.str();
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070090}
91
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
93// Used to be flags, but that makes it hard to selectively apply options.
94// We are moving all of the setting of options to structs like this,
95// but some things currently still use flags.
96struct VideoOptions {
Paulina Hensman11b34f42018-04-09 14:24:52 +020097 VideoOptions();
98 ~VideoOptions();
99
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700101 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800102 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100103 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104 }
105
106 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800107 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100108 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
109 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110 }
deadbeef119760a2016-04-04 11:43:27 -0700111 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112
113 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200114 rtc::StringBuilder ost;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800117 ost << ToStringIfSet("screencast min bitrate kbps",
118 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100119 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120 ost << "}";
121 return ost.str();
122 }
123
nisseb163c3f2016-01-29 01:14:38 -0800124 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700125 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800126 // on to the codec options. Disabled by default.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200127 absl::optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800128 // Force screencast to use a minimum bitrate. This flag comes from
129 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700130 // copied to the encoder config by WebRtcVideoChannel.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200131 absl::optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100132 // Set by screencast sources. Implies selection of encoding settings
133 // suitable for screencast. Most likely not the right way to do
134 // things, e.g., screencast of a text document and screencast of a
135 // youtube video have different needs.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200136 absl::optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700137
138 private:
139 template <typename T>
Danil Chapovalov00c71832018-06-15 15:58:38 +0200140 static void SetFrom(absl::optional<T>* s, const absl::optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700141 if (o) {
142 *s = o;
143 }
144 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145};
146
isheriffa1c548b2016-05-31 16:12:24 -0700147// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
148struct RtpHeaderExtension {
149 RtpHeaderExtension() : id(0) {}
150 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
151
152 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200153 rtc::StringBuilder ost;
isheriffa1c548b2016-05-31 16:12:24 -0700154 ost << "{";
155 ost << "uri: " << uri;
156 ost << ", id: " << id;
157 ost << "}";
158 return ost.str();
159 }
160
161 std::string uri;
162 int id;
163};
164
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165class MediaChannel : public sigslot::has_slots<> {
166 public:
167 class NetworkInterface {
168 public:
169 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700170 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700171 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700172 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700173 const rtc::PacketOptions& options) = 0;
Yves Gerey665174f2018-06-19 15:03:05 +0200174 virtual int SetOption(SocketType type,
175 rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176 int option) = 0;
177 virtual ~NetworkInterface() {}
178 };
179
terelius54f91712016-06-01 11:18:56 -0700180 explicit MediaChannel(const MediaConfig& config)
nisse51542be2016-02-12 02:27:06 -0800181 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
182 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200183 ~MediaChannel() override {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000185 // Sets the abstract interface class for sending RTP/RTCP data.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200186 virtual void SetInterface(NetworkInterface* iface);
187 virtual rtc::DiffServCodePoint PreferredDscp() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700189 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000190 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700192 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000193 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 // Called when the socket's ability to send has changed.
195 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700196 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700197 virtual void OnNetworkRouteChanged(
198 const std::string& transport_name,
199 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 // Creates a new outgoing media stream with SSRCs and CNAME as described
201 // by sp.
202 virtual bool AddSendStream(const StreamParams& sp) = 0;
203 // Removes an outgoing media stream.
Seth Hampson5897a6e2018-04-03 11:16:33 -0700204 // SSRC must be the first SSRC of the media stream if the stream uses
205 // multiple SSRCs. In the case of an ssrc of 0, the possibly cached
206 // StreamParams is removed.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200207 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700208 // Creates a new incoming media stream with SSRCs, CNAME as described
209 // by sp. In the case of a sp without SSRCs, the unsignaled sp is cached
210 // to be used later for unsignaled streams received.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 virtual bool AddRecvStream(const StreamParams& sp) = 0;
212 // Removes an incoming media stream.
213 // ssrc must be the first SSRC of the media stream if the stream uses
214 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200215 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000217 // Returns the absoulte sendtime extension id value from media channel.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200218 virtual int GetRtpSendTimeExtnId() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000220 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700221 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
222 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700223 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000224 }
225
jbaucheec21bd2016-03-20 06:15:43 -0700226 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
227 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700228 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000229 }
230
231 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000232 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000233 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000234 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000235 if (!network_interface_)
236 return -1;
237
238 return network_interface_->SetOption(type, opt, option);
239 }
240
nisse51542be2016-02-12 02:27:06 -0800241 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000242 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000243 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000244 int ret;
Yves Gerey665174f2018-06-19 15:03:05 +0200245 ret = SetOption(NetworkInterface::ST_RTP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000246 if (ret == 0) {
Yves Gerey665174f2018-06-19 15:03:05 +0200247 ret = SetOption(NetworkInterface::ST_RTCP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000248 }
249 return ret;
250 }
251
jbaucheec21bd2016-03-20 06:15:43 -0700252 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700253 bool rtcp,
254 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000255 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000256 if (!network_interface_)
257 return false;
258
stefanc1aeaf02015-10-15 07:26:07 -0700259 return (!rtcp) ? network_interface_->SendPacket(packet, options)
260 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000261 }
262
nisse51542be2016-02-12 02:27:06 -0800263 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000264 // |network_interface_| can be accessed from the worker_thread and
265 // from any MediaEngine threads. This critical section is to protect accessing
266 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000267 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000268 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269};
270
wu@webrtc.org97077a32013-10-25 21:18:33 +0000271// The stats information is structured as follows:
272// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
273// Media contains a vector of SSRC infos that are exclusively used by this
274// media. (SSRCs shared between media streams can't be represented.)
275
276// Information about an SSRC.
277// This data may be locally recorded, or received in an RTCP SR or RR.
278struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800279 uint32_t ssrc = 0;
280 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000281};
282
283struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800284 uint32_t ssrc = 0;
285 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000286};
287
288struct MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200289 MediaSenderInfo();
290 ~MediaSenderInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200291 void add_ssrc(const SsrcSenderInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000292 // Temporary utility function for call sites that only provide SSRC.
293 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200294 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000295 SsrcSenderInfo stat;
296 stat.ssrc = ssrc;
297 add_ssrc(stat);
298 }
299 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200300 std::vector<uint32_t> ssrcs() const {
301 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000302 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
303 it != local_stats.end(); ++it) {
304 retval.push_back(it->ssrc);
305 }
306 return retval;
307 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100308 // Returns true if the media has been connected.
309 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000310 // Utility accessor for clients that make the assumption only one ssrc
311 // exists per media.
312 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100313 // Call sites that compare this to zero should use connected() instead.
314 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200315 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100316 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000317 return local_stats[0].ssrc;
318 } else {
319 return 0;
320 }
321 }
Steve Anton002f9212018-01-09 16:38:15 -0800322 int64_t bytes_sent = 0;
323 int packets_sent = 0;
324 int packets_lost = 0;
325 float fraction_lost = 0.0f;
326 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000327 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200328 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000329 std::vector<SsrcSenderInfo> local_stats;
330 std::vector<SsrcReceiverInfo> remote_stats;
331};
332
333struct MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200334 MediaReceiverInfo();
335 ~MediaReceiverInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200336 void add_ssrc(const SsrcReceiverInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000337 // Temporary utility function for call sites that only provide SSRC.
338 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200339 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000340 SsrcReceiverInfo stat;
341 stat.ssrc = ssrc;
342 add_ssrc(stat);
343 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200344 std::vector<uint32_t> ssrcs() const {
345 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000346 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
347 it != local_stats.end(); ++it) {
348 retval.push_back(it->ssrc);
349 }
350 return retval;
351 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100352 // Returns true if the media has been connected.
353 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000354 // Utility accessor for clients that make the assumption only one ssrc
355 // exists per media.
356 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100357 // Call sites that compare this to zero should use connected();
358 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200359 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100360 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000361 return local_stats[0].ssrc;
362 } else {
363 return 0;
364 }
365 }
366
Steve Anton002f9212018-01-09 16:38:15 -0800367 int64_t bytes_rcvd = 0;
368 int packets_rcvd = 0;
369 int packets_lost = 0;
370 float fraction_lost = 0.0f;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000371 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200372 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000373 std::vector<SsrcReceiverInfo> local_stats;
374 std::vector<SsrcSenderInfo> remote_stats;
375};
376
377struct VoiceSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200378 VoiceSenderInfo();
379 ~VoiceSenderInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800380 int ext_seqnum = 0;
381 int jitter_ms = 0;
382 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700383 // See description of "totalAudioEnergy" in the WebRTC stats spec:
384 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800385 double total_input_energy = 0.0;
386 double total_input_duration = 0.0;
Ivo Creusen56d46092017-11-24 17:29:59 +0100387 // TODO(bugs.webrtc.org/8572): Remove APM stats from this struct, since they
388 // are no longer needed now that we have apm_statistics.
Steve Anton002f9212018-01-09 16:38:15 -0800389 int echo_delay_median_ms = 0;
390 int echo_delay_std_ms = 0;
391 int echo_return_loss = 0;
392 int echo_return_loss_enhancement = 0;
393 float residual_echo_likelihood = 0.0f;
394 float residual_echo_likelihood_recent_max = 0.0f;
395 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700396 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100397 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398};
399
wu@webrtc.org97077a32013-10-25 21:18:33 +0000400struct VoiceReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200401 VoiceReceiverInfo();
402 ~VoiceReceiverInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800403 int ext_seqnum = 0;
404 int jitter_ms = 0;
405 int jitter_buffer_ms = 0;
406 int jitter_buffer_preferred_ms = 0;
407 int delay_estimate_ms = 0;
408 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200409 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
410 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800411 double total_output_energy = 0.0;
412 uint64_t total_samples_received = 0;
413 double total_output_duration = 0.0;
414 uint64_t concealed_samples = 0;
415 uint64_t concealment_events = 0;
416 double jitter_buffer_delay_seconds = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200417 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000418 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800419 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000420 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800421 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000422 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800423 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200424 // Fraction of secondary data, including FEC and RED, that is discarded.
425 // Discarding of secondary data can be caused by the reception of the primary
426 // data, obsoleting the secondary data. It can also be caused by early
427 // or late arrival of secondary data. This metric is the percentage of
428 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800429 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200430 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800431 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200432 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800433 float preemptive_expand_rate = 0.0f;
434 int decoding_calls_to_silence_generator = 0;
435 int decoding_calls_to_neteq = 0;
436 int decoding_normal = 0;
437 int decoding_plc = 0;
438 int decoding_cng = 0;
439 int decoding_plc_cng = 0;
440 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000441 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800442 int64_t capture_start_ntp_time_ms = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443};
444
wu@webrtc.org97077a32013-10-25 21:18:33 +0000445struct VideoSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200446 VideoSenderInfo();
447 ~VideoSenderInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000448 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800449 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100450 std::string encoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800451 int firs_rcvd = 0;
452 int plis_rcvd = 0;
453 int nacks_rcvd = 0;
454 int send_frame_width = 0;
455 int send_frame_height = 0;
456 int framerate_input = 0;
457 int framerate_sent = 0;
458 int nominal_bitrate = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800459 int adapt_reason = 0;
460 int adapt_changes = 0;
461 int avg_encode_ms = 0;
462 int encode_usage_percent = 0;
463 uint32_t frames_encoded = 0;
464 bool has_entered_low_resolution = false;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200465 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800466 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100467 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
468 uint32_t huge_frames_sent = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469};
470
wu@webrtc.org97077a32013-10-25 21:18:33 +0000471struct VideoReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200472 VideoReceiverInfo();
473 ~VideoReceiverInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000474 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800475 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100476 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800477 int packets_concealed = 0;
478 int firs_sent = 0;
479 int plis_sent = 0;
480 int nacks_sent = 0;
481 int frame_width = 0;
482 int frame_height = 0;
483 int framerate_rcvd = 0;
484 int framerate_decoded = 0;
485 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000486 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800487 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000488 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800489 int framerate_render_output = 0;
490 uint32_t frames_received = 0;
491 uint32_t frames_decoded = 0;
492 uint32_t frames_rendered = 0;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200493 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800494 int64_t interframe_delay_max_ms = -1;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000495
Steve Anton002f9212018-01-09 16:38:15 -0800496 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700497
wu@webrtc.org97077a32013-10-25 21:18:33 +0000498 // All stats below are gathered per-VideoReceiver, but some will be correlated
499 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
500 // structures, reflect this in the new layout.
501
502 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800503 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000504 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800505 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000506 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800507 int jitter_buffer_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000508 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800509 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000510 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800511 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000512 // Target overall delay: network+decode+render, accounting for
513 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800514 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000515 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800516 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000517
518 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800519 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700520
521 // Timing frame info: all important timestamps for a full lifetime of a
522 // single 'timing frame'.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200523 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524};
525
wu@webrtc.org97077a32013-10-25 21:18:33 +0000526struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800527 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000528};
529
wu@webrtc.org97077a32013-10-25 21:18:33 +0000530struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800531 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000532};
533
534struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800535 int available_send_bandwidth = 0;
536 int available_recv_bandwidth = 0;
537 int target_enc_bitrate = 0;
538 int actual_enc_bitrate = 0;
539 int retransmit_bitrate = 0;
540 int transmit_bitrate = 0;
541 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000542};
543
hbosa65704b2016-11-14 02:28:16 -0800544// Maps from payload type to |RtpCodecParameters|.
545typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
546
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000547struct VoiceMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200548 VoiceMediaInfo();
549 ~VoiceMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 void Clear() {
551 senders.clear();
552 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800553 send_codecs.clear();
554 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 }
556 std::vector<VoiceSenderInfo> senders;
557 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800558 RtpCodecParametersMap send_codecs;
559 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560};
561
562struct VideoMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200563 VideoMediaInfo();
564 ~VideoMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 void Clear() {
566 senders.clear();
567 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700568 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800569 send_codecs.clear();
570 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 }
572 std::vector<VideoSenderInfo> senders;
573 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700574 // Deprecated.
575 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700576 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800577 RtpCodecParametersMap send_codecs;
578 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579};
580
581struct DataMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200582 DataMediaInfo();
583 ~DataMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 void Clear() {
585 senders.clear();
586 receivers.clear();
587 }
588 std::vector<DataSenderInfo> senders;
589 std::vector<DataReceiverInfo> receivers;
590};
591
deadbeef13871492015-12-09 12:37:51 -0800592struct RtcpParameters {
593 bool reduced_size = false;
594};
595
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700596template <class Codec>
597struct RtpParameters {
Steve Anton003930a2018-03-29 12:37:21 -0700598 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700599
600 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700601 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700602 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800603 RtcpParameters rtcp;
Steve Anton003930a2018-03-29 12:37:21 -0700604
605 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200606 rtc::StringBuilder ost;
Steve Anton003930a2018-03-29 12:37:21 -0700607 ost << "{";
608 const char* separator = "";
609 for (const auto& entry : ToStringMap()) {
610 ost << separator << entry.first << ": " << entry.second;
611 separator = ", ";
612 }
613 ost << "}";
614 return ost.str();
615 }
616
617 protected:
618 virtual std::map<std::string, std::string> ToStringMap() const {
619 return {{"codecs", VectorToString(codecs)},
620 {"extensions", VectorToString(extensions)}};
621 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700622};
623
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700624// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
625// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700626template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700627struct RtpSendParameters : RtpParameters<Codec> {
nisse05103312016-03-16 02:22:50 -0700628 int max_bandwidth_bps = -1;
Steve Antonbb50ce52018-03-26 10:24:32 -0700629 // This is the value to be sent in the MID RTP header extension (if the header
630 // extension in included in the list of extensions).
631 std::string mid;
Steve Anton003930a2018-03-29 12:37:21 -0700632
633 protected:
634 std::map<std::string, std::string> ToStringMap() const override {
635 auto params = RtpParameters<Codec>::ToStringMap();
636 params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps);
637 params["mid"] = (mid.empty() ? "<not set>" : mid);
638 return params;
639 }
nisse05103312016-03-16 02:22:50 -0700640};
641
642struct AudioSendParameters : RtpSendParameters<AudioCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200643 AudioSendParameters();
644 ~AudioSendParameters() override;
nisse05103312016-03-16 02:22:50 -0700645 AudioOptions options;
Steve Anton003930a2018-03-29 12:37:21 -0700646
647 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200648 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700649};
650
Yves Gerey665174f2018-06-19 15:03:05 +0200651struct AudioRecvParameters : RtpParameters<AudioCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700652
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653class VoiceMediaChannel : public MediaChannel {
654 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700656 explicit VoiceMediaChannel(const MediaConfig& config)
657 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200658 ~VoiceMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200659 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
660 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700661 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800662 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700663 uint32_t ssrc,
664 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700665 // Get the receive parameters for the incoming stream identified by |ssrc|.
666 // If |ssrc| is 0, retrieve the receive parameters for the default receive
667 // stream, which is used when SSRCs are not signaled. Note that calling with
668 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
669 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700670 virtual webrtc::RtpParameters GetRtpReceiveParameters(
671 uint32_t ssrc) const = 0;
672 virtual bool SetRtpReceiveParameters(
673 uint32_t ssrc,
674 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700676 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800678 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700679 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200680 virtual bool SetAudioSend(uint32_t ssrc,
681 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700682 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800683 AudioSource* source) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700684 // Set speaker output volume of the specified ssrc.
685 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800687 virtual bool CanInsertDtmf() = 0;
688 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000690 // The valid value for the |event| are 0 to 15 which corresponding to
691 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800692 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 // Gets quality stats for the channel.
694 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100695
696 virtual void SetRawAudioSink(
697 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800698 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700699
700 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701};
702
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700703// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
704// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700705struct VideoSendParameters : RtpSendParameters<VideoCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200706 VideoSendParameters();
707 ~VideoSendParameters() override;
nisse4b4dc862016-02-17 05:25:36 -0800708 // Use conference mode? This flag comes from the remote
709 // description's SDP line 'a=x-google-flag:conference', copied over
710 // by VideoChannel::SetRemoteContent_w, and ultimately used by
711 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700712 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800713 // The special screencast behaviour is disabled by default.
714 bool conference_mode = false;
Steve Anton003930a2018-03-29 12:37:21 -0700715
716 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200717 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700718};
719
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700720// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
721// encapsulate all the parameters needed for a video RtpReceiver.
Yves Gerey665174f2018-06-19 15:03:05 +0200722struct VideoRecvParameters : RtpParameters<VideoCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700723
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724class VideoMediaChannel : public MediaChannel {
725 public:
nisse08582ff2016-02-04 01:24:52 -0800726 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700727 explicit VideoMediaChannel(const MediaConfig& config)
728 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200729 ~VideoMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200730
731 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
732 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700733 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800734 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700735 uint32_t ssrc,
736 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700737 // Get the receive parameters for the incoming stream identified by |ssrc|.
738 // If |ssrc| is 0, retrieve the receive parameters for the default receive
739 // stream, which is used when SSRCs are not signaled. Note that calling with
740 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
741 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700742 virtual webrtc::RtpParameters GetRtpReceiveParameters(
743 uint32_t ssrc) const = 0;
744 virtual bool SetRtpReceiveParameters(
745 uint32_t ssrc,
746 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 // Gets the currently set codecs/payload types to be used for outgoing media.
748 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 // Starts or stops transmission (and potentially capture) of local video.
750 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700751 // Configure stream for sending and register a source.
752 // The |ssrc| must correspond to a registered send stream.
753 virtual bool SetVideoSend(
754 uint32_t ssrc,
deadbeef5a4a75a2016-06-02 16:23:38 -0700755 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800756 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800757 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -0700758 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800759 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800760 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700761 // This fills the "bitrate parts" (rtx, video bitrate) of the
762 // BandwidthEstimationInfo, since that part that isn't possible to get
763 // through webrtc::Call::GetStats, as they are statistics of the send
764 // streams.
765 // TODO(holmer): We should change this so that either BWE graphs doesn't
766 // need access to bitrates of the streams, or change the (RTC)StatsCollector
767 // so that it's getting the send stream stats separately by calling
768 // GetStats(), and merges with BandwidthEstimationInfo by itself.
769 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000771 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772};
773
774enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000775 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
776 // values.
777 DMT_NONE = 0,
778 DMT_CONTROL = 1,
779 DMT_BINARY = 2,
780 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781};
782
783// Info about data received in DataMediaChannel. For use in
784// DataMediaChannel::SignalDataReceived and in all of the signals that
785// signal fires, on up the chain.
786struct ReceiveDataParams {
787 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800788 // RTP data channels use SSRCs, SCTP data channels use SIDs.
789 union {
790 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800791 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800792 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800794 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800796 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800798 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799};
800
801struct SendDataParams {
802 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800803 // RTP data channels use SSRCs, SCTP data channels use SIDs.
804 union {
805 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800806 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800807 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800809 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810
Steve Anton002f9212018-01-09 16:38:15 -0800811 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 // For SCTP, whether to send messages flagged as ordered or not.
813 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800814 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 // For SCTP, whether the messages are sent reliably or not.
816 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800817 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 // For SCTP, if reliable == false, provide partial reliability by
819 // resending up to this many times. Either count or millis
820 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800821 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 // For SCTP, if reliable == false, provide partial reliability by
823 // resending for up to this many milliseconds. Either count or millis
824 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800825 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826};
827
828enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
829
Yves Gerey665174f2018-06-19 15:03:05 +0200830struct DataSendParameters : RtpSendParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700831
Yves Gerey665174f2018-06-19 15:03:05 +0200832struct DataRecvParameters : RtpParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700833
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834class DataMediaChannel : public MediaChannel {
835 public:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200836 DataMediaChannel();
837 explicit DataMediaChannel(const MediaConfig& config);
838 ~DataMediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200840 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
841 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000842
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 // TODO(pthatcher): Implement this.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200844 virtual bool GetStats(DataMediaInfo* info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845
846 virtual bool SetSend(bool send) = 0;
847 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848
Paulina Hensman11b34f42018-04-09 14:24:52 +0200849 void OnNetworkRouteChanged(const std::string& transport_name,
850 const rtc::NetworkRoute& network_route) override {}
Honghai Zhangcc411c02016-03-29 17:27:21 -0700851
Yves Gerey665174f2018-06-19 15:03:05 +0200852 virtual bool SendData(const SendDataParams& params,
853 const rtc::CopyOnWriteBuffer& payload,
854 SendDataResult* result = NULL) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 // Signals when data is received (params, data, len)
Yves Gerey665174f2018-06-19 15:03:05 +0200856 sigslot::signal3<const ReceiveDataParams&, const char*, size_t>
857 SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000858 // Signal when the media channel is ready to send the stream. Arguments are:
859 // writable(bool)
860 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861};
862
863} // namespace cricket
864
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200865#endif // MEDIA_BASE_MEDIACHANNEL_H_