blob: 3b78144c03c7d63977d942c974674e2931d27ef8 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "api/audio_codecs/audio_encoder.h"
Niels Möllera6fe2612018-01-19 11:28:54 +010021#include "api/audio_options.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "api/optional.h"
23#include "api/rtpparameters.h"
24#include "api/rtpreceiverinterface.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010025#include "api/video/video_content_type.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "api/video/video_timing.h"
Patrik Höglundbe214a22018-01-04 12:14:35 +010027#include "api/videosinkinterface.h"
Patrik Höglundadc1e9b2018-01-09 14:55:05 +010028#include "api/videosourceinterface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "call/video_config.h"
30#include "media/base/codec.h"
Niels Möller6daa2782018-01-23 10:37:42 +010031#include "media/base/mediaconfig.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "media/base/mediaconstants.h"
33#include "media/base/streamparams.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010034#include "modules/audio_processing/include/audio_processing_statistics.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010035#include "rtc_base/asyncpacketsocket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#include "rtc_base/basictypes.h"
37#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"
42#include "rtc_base/sigslot.h"
43#include "rtc_base/socket.h"
Niels Möller9a44f962017-12-08 15:57:38 +010044#include "rtc_base/stringencode.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010045
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000047namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048class RateLimiter;
49class Timing;
50}
51
Tommif888bb52015-12-12 01:37:01 +010052namespace webrtc {
53class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080054class VideoFrame;
Tommif888bb52015-12-12 01:37:01 +010055}
56
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057namespace cricket {
58
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080059class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080061struct RtpHeader;
62struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064const int kScreencastDefaultFps = 5;
65
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066template <class T>
Karl Wibergbe579832015-11-10 22:34:18 +010067static std::string ToStringIfSet(const char* key, const rtc::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) {
80 std::ostringstream ost;
81 ost << "[";
82 for (size_t i = 0; i < vals.size(); ++i) {
83 if (i > 0) {
84 ost << ", ";
85 }
86 ost << vals[i].ToString();
87 }
88 ost << "]";
89 return ost.str();
90}
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 {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -070098 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -080099 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100100 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 }
102
103 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800104 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100105 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
106 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 }
deadbeef119760a2016-04-04 11:43:27 -0700108 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109
110 std::string ToString() const {
111 std::ostringstream ost;
112 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800114 ost << ToStringIfSet("screencast min bitrate kbps",
115 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100116 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117 ost << "}";
118 return ost.str();
119 }
120
nisseb163c3f2016-01-29 01:14:38 -0800121 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700122 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800123 // on to the codec options. Disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100124 rtc::Optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800125 // Force screencast to use a minimum bitrate. This flag comes from
126 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700127 // copied to the encoder config by WebRtcVideoChannel.
nisseb163c3f2016-01-29 01:14:38 -0800128 rtc::Optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100129 // Set by screencast sources. Implies selection of encoding settings
130 // suitable for screencast. Most likely not the right way to do
131 // things, e.g., screencast of a text document and screencast of a
132 // youtube video have different needs.
133 rtc::Optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700134
135 private:
136 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100137 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700138 if (o) {
139 *s = o;
140 }
141 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142};
143
isheriffa1c548b2016-05-31 16:12:24 -0700144// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
145struct RtpHeaderExtension {
146 RtpHeaderExtension() : id(0) {}
147 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
148
149 std::string ToString() const {
150 std::ostringstream ost;
151 ost << "{";
152 ost << "uri: " << uri;
153 ost << ", id: " << id;
154 ost << "}";
155 return ost.str();
156 }
157
158 std::string uri;
159 int id;
160};
161
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162class MediaChannel : public sigslot::has_slots<> {
163 public:
164 class NetworkInterface {
165 public:
166 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700167 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700168 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700169 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700170 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000171 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 int option) = 0;
173 virtual ~NetworkInterface() {}
174 };
175
terelius54f91712016-06-01 11:18:56 -0700176 explicit MediaChannel(const MediaConfig& config)
nisse51542be2016-02-12 02:27:06 -0800177 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
178 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 virtual ~MediaChannel() {}
180
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000181 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000183 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 network_interface_ = iface;
nisse51542be2016-02-12 02:27:06 -0800185 SetDscp(enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 }
nisse51542be2016-02-12 02:27:06 -0800187 virtual rtc::DiffServCodePoint PreferredDscp() const {
188 return rtc::DSCP_DEFAULT;
189 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700191 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000192 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700194 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000195 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 // Called when the socket's ability to send has changed.
197 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700198 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700199 virtual void OnNetworkRouteChanged(
200 const std::string& transport_name,
201 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202 // Creates a new outgoing media stream with SSRCs and CNAME as described
203 // by sp.
204 virtual bool AddSendStream(const StreamParams& sp) = 0;
205 // Removes an outgoing media stream.
206 // ssrc must be the first SSRC of the media stream if the stream uses
207 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200208 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 // Creates a new incoming media stream with SSRCs and CNAME as described
210 // by sp.
211 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.
218 virtual int GetRtpSendTimeExtnId() const {
219 return -1;
220 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000222 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700223 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
224 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700225 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000226 }
227
jbaucheec21bd2016-03-20 06:15:43 -0700228 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
229 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700230 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000231 }
232
233 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000234 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000235 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000236 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000237 if (!network_interface_)
238 return -1;
239
240 return network_interface_->SetOption(type, opt, option);
241 }
242
nisse51542be2016-02-12 02:27:06 -0800243 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000244 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000245 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000246 int ret;
247 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000248 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000249 value);
250 if (ret == 0) {
251 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000252 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000253 value);
254 }
255 return ret;
256 }
257
jbaucheec21bd2016-03-20 06:15:43 -0700258 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700259 bool rtcp,
260 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000261 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000262 if (!network_interface_)
263 return false;
264
stefanc1aeaf02015-10-15 07:26:07 -0700265 return (!rtcp) ? network_interface_->SendPacket(packet, options)
266 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000267 }
268
nisse51542be2016-02-12 02:27:06 -0800269 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000270 // |network_interface_| can be accessed from the worker_thread and
271 // from any MediaEngine threads. This critical section is to protect accessing
272 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000273 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000274 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275};
276
wu@webrtc.org97077a32013-10-25 21:18:33 +0000277// The stats information is structured as follows:
278// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
279// Media contains a vector of SSRC infos that are exclusively used by this
280// media. (SSRCs shared between media streams can't be represented.)
281
282// Information about an SSRC.
283// This data may be locally recorded, or received in an RTCP SR or RR.
284struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800285 uint32_t ssrc = 0;
286 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000287};
288
289struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800290 uint32_t ssrc = 0;
291 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000292};
293
294struct MediaSenderInfo {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000295 void add_ssrc(const SsrcSenderInfo& stat) {
296 local_stats.push_back(stat);
297 }
298 // Temporary utility function for call sites that only provide SSRC.
299 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200300 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000301 SsrcSenderInfo stat;
302 stat.ssrc = ssrc;
303 add_ssrc(stat);
304 }
305 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200306 std::vector<uint32_t> ssrcs() const {
307 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000308 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
309 it != local_stats.end(); ++it) {
310 retval.push_back(it->ssrc);
311 }
312 return retval;
313 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100314 // Returns true if the media has been connected.
315 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000316 // Utility accessor for clients that make the assumption only one ssrc
317 // exists per media.
318 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100319 // Call sites that compare this to zero should use connected() instead.
320 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200321 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100322 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000323 return local_stats[0].ssrc;
324 } else {
325 return 0;
326 }
327 }
Steve Anton002f9212018-01-09 16:38:15 -0800328 int64_t bytes_sent = 0;
329 int packets_sent = 0;
330 int packets_lost = 0;
331 float fraction_lost = 0.0f;
332 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000333 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800334 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000335 std::vector<SsrcSenderInfo> local_stats;
336 std::vector<SsrcReceiverInfo> remote_stats;
337};
338
339struct MediaReceiverInfo {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000340 void add_ssrc(const SsrcReceiverInfo& stat) {
341 local_stats.push_back(stat);
342 }
343 // Temporary utility function for call sites that only provide SSRC.
344 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200345 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000346 SsrcReceiverInfo stat;
347 stat.ssrc = ssrc;
348 add_ssrc(stat);
349 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200350 std::vector<uint32_t> ssrcs() const {
351 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000352 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
353 it != local_stats.end(); ++it) {
354 retval.push_back(it->ssrc);
355 }
356 return retval;
357 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100358 // Returns true if the media has been connected.
359 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000360 // Utility accessor for clients that make the assumption only one ssrc
361 // exists per media.
362 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100363 // Call sites that compare this to zero should use connected();
364 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200365 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100366 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000367 return local_stats[0].ssrc;
368 } else {
369 return 0;
370 }
371 }
372
Steve Anton002f9212018-01-09 16:38:15 -0800373 int64_t bytes_rcvd = 0;
374 int packets_rcvd = 0;
375 int packets_lost = 0;
376 float fraction_lost = 0.0f;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000377 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800378 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000379 std::vector<SsrcReceiverInfo> local_stats;
380 std::vector<SsrcSenderInfo> remote_stats;
381};
382
383struct VoiceSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800384 int ext_seqnum = 0;
385 int jitter_ms = 0;
386 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700387 // See description of "totalAudioEnergy" in the WebRTC stats spec:
388 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800389 double total_input_energy = 0.0;
390 double total_input_duration = 0.0;
Ivo Creusen56d46092017-11-24 17:29:59 +0100391 // TODO(bugs.webrtc.org/8572): Remove APM stats from this struct, since they
392 // are no longer needed now that we have apm_statistics.
Steve Anton002f9212018-01-09 16:38:15 -0800393 int echo_delay_median_ms = 0;
394 int echo_delay_std_ms = 0;
395 int echo_return_loss = 0;
396 int echo_return_loss_enhancement = 0;
397 float residual_echo_likelihood = 0.0f;
398 float residual_echo_likelihood_recent_max = 0.0f;
399 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700400 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100401 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402};
403
wu@webrtc.org97077a32013-10-25 21:18:33 +0000404struct VoiceReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800405 int ext_seqnum = 0;
406 int jitter_ms = 0;
407 int jitter_buffer_ms = 0;
408 int jitter_buffer_preferred_ms = 0;
409 int delay_estimate_ms = 0;
410 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200411 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
412 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800413 double total_output_energy = 0.0;
414 uint64_t total_samples_received = 0;
415 double total_output_duration = 0.0;
416 uint64_t concealed_samples = 0;
417 uint64_t concealment_events = 0;
418 double jitter_buffer_delay_seconds = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200419 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000420 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800421 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000422 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800423 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000424 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800425 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200426 // Fraction of secondary data, including FEC and RED, that is discarded.
427 // Discarding of secondary data can be caused by the reception of the primary
428 // data, obsoleting the secondary data. It can also be caused by early
429 // or late arrival of secondary data. This metric is the percentage of
430 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800431 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200432 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800433 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200434 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800435 float preemptive_expand_rate = 0.0f;
436 int decoding_calls_to_silence_generator = 0;
437 int decoding_calls_to_neteq = 0;
438 int decoding_normal = 0;
439 int decoding_plc = 0;
440 int decoding_cng = 0;
441 int decoding_plc_cng = 0;
442 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000443 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800444 int64_t capture_start_ntp_time_ms = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445};
446
wu@webrtc.org97077a32013-10-25 21:18:33 +0000447struct VideoSenderInfo : public MediaSenderInfo {
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 packets_cached = 0;
452 int firs_rcvd = 0;
453 int plis_rcvd = 0;
454 int nacks_rcvd = 0;
455 int send_frame_width = 0;
456 int send_frame_height = 0;
457 int framerate_input = 0;
458 int framerate_sent = 0;
459 int nominal_bitrate = 0;
460 int preferred_bitrate = 0;
461 int adapt_reason = 0;
462 int adapt_changes = 0;
463 int avg_encode_ms = 0;
464 int encode_usage_percent = 0;
465 uint32_t frames_encoded = 0;
466 bool has_entered_low_resolution = false;
sakal87da4042016-10-31 06:53:47 -0700467 rtc::Optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800468 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469};
470
wu@webrtc.org97077a32013-10-25 21:18:33 +0000471struct VideoReceiverInfo : public MediaReceiverInfo {
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000472 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800473 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100474 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800475 int packets_concealed = 0;
476 int firs_sent = 0;
477 int plis_sent = 0;
478 int nacks_sent = 0;
479 int frame_width = 0;
480 int frame_height = 0;
481 int framerate_rcvd = 0;
482 int framerate_decoded = 0;
483 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000484 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800485 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000486 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800487 int framerate_render_output = 0;
488 uint32_t frames_received = 0;
489 uint32_t frames_decoded = 0;
490 uint32_t frames_rendered = 0;
sakalcc452e12017-02-09 04:53:45 -0800491 rtc::Optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800492 int64_t interframe_delay_max_ms = -1;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000493
Steve Anton002f9212018-01-09 16:38:15 -0800494 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700495
wu@webrtc.org97077a32013-10-25 21:18:33 +0000496 // All stats below are gathered per-VideoReceiver, but some will be correlated
497 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
498 // structures, reflect this in the new layout.
499
500 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800501 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000502 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800503 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000504 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800505 int jitter_buffer_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000506 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800507 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000508 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800509 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000510 // Target overall delay: network+decode+render, accounting for
511 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800512 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000513 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800514 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000515
516 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800517 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700518
519 // Timing frame info: all important timestamps for a full lifetime of a
520 // single 'timing frame'.
521 rtc::Optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522};
523
wu@webrtc.org97077a32013-10-25 21:18:33 +0000524struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800525 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526};
527
wu@webrtc.org97077a32013-10-25 21:18:33 +0000528struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800529 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530};
531
532struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800533 int available_send_bandwidth = 0;
534 int available_recv_bandwidth = 0;
535 int target_enc_bitrate = 0;
536 int actual_enc_bitrate = 0;
537 int retransmit_bitrate = 0;
538 int transmit_bitrate = 0;
539 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000540};
541
hbosa65704b2016-11-14 02:28:16 -0800542// Maps from payload type to |RtpCodecParameters|.
543typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
544
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000545struct VoiceMediaInfo {
546 void Clear() {
547 senders.clear();
548 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800549 send_codecs.clear();
550 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551 }
552 std::vector<VoiceSenderInfo> senders;
553 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800554 RtpCodecParametersMap send_codecs;
555 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556};
557
558struct VideoMediaInfo {
559 void Clear() {
560 senders.clear();
561 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700562 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800563 send_codecs.clear();
564 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 }
566 std::vector<VideoSenderInfo> senders;
567 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700568 // Deprecated.
569 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700570 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800571 RtpCodecParametersMap send_codecs;
572 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573};
574
575struct DataMediaInfo {
576 void Clear() {
577 senders.clear();
578 receivers.clear();
579 }
580 std::vector<DataSenderInfo> senders;
581 std::vector<DataReceiverInfo> receivers;
582};
583
deadbeef13871492015-12-09 12:37:51 -0800584struct RtcpParameters {
585 bool reduced_size = false;
586};
587
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700588template <class Codec>
589struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800590 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700591 std::ostringstream ost;
592 ost << "{";
593 ost << "codecs: " << VectorToString(codecs) << ", ";
594 ost << "extensions: " << VectorToString(extensions);
595 ost << "}";
596 return ost.str();
597 }
598
599 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700600 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700601 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800602 RtcpParameters rtcp;
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200603 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700604};
605
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700606// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
607// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700608template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700609struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800610 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700611 std::ostringstream ost;
612 ost << "{";
613 ost << "codecs: " << VectorToString(this->codecs) << ", ";
614 ost << "extensions: " << VectorToString(this->extensions) << ", ";
pbos378dc772016-01-28 15:58:41 -0800615 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
nisse05103312016-03-16 02:22:50 -0700616 ost << "}";
617 return ost.str();
618 }
619
620 int max_bandwidth_bps = -1;
621};
622
623struct AudioSendParameters : RtpSendParameters<AudioCodec> {
624 std::string ToString() const override {
625 std::ostringstream ost;
626 ost << "{";
627 ost << "codecs: " << VectorToString(this->codecs) << ", ";
628 ost << "extensions: " << VectorToString(this->extensions) << ", ";
629 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700630 ost << "options: " << options.ToString();
631 ost << "}";
632 return ost.str();
633 }
634
nisse05103312016-03-16 02:22:50 -0700635 AudioOptions options;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700636};
637
638struct AudioRecvParameters : RtpParameters<AudioCodec> {
639};
640
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641class VoiceMediaChannel : public MediaChannel {
642 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700644 explicit VoiceMediaChannel(const MediaConfig& config)
645 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200647 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
648 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700649 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
650 virtual bool SetRtpSendParameters(
651 uint32_t ssrc,
652 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700653 // Get the receive parameters for the incoming stream identified by |ssrc|.
654 // If |ssrc| is 0, retrieve the receive parameters for the default receive
655 // stream, which is used when SSRCs are not signaled. Note that calling with
656 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
657 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700658 virtual webrtc::RtpParameters GetRtpReceiveParameters(
659 uint32_t ssrc) const = 0;
660 virtual bool SetRtpReceiveParameters(
661 uint32_t ssrc,
662 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000663 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700664 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800666 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700667 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200668 virtual bool SetAudioSend(uint32_t ssrc,
669 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700670 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800671 AudioSource* source) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 // Gets current energy levels for all incoming streams.
Patrik Höglundaba85d12017-11-28 15:46:08 +0100673 typedef std::vector<std::pair<uint32_t, int>> StreamList;
674 virtual bool GetActiveStreams(StreamList* actives) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675 // Get the current energy level of the stream sent to the speaker.
676 virtual int GetOutputLevel() = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700677 // Set speaker output volume of the specified ssrc.
678 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800680 virtual bool CanInsertDtmf() = 0;
681 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000683 // The valid value for the |event| are 0 to 15 which corresponding to
684 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800685 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 // Gets quality stats for the channel.
687 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100688
689 virtual void SetRawAudioSink(
690 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800691 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700692
693 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694};
695
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700696// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
697// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700698struct VideoSendParameters : RtpSendParameters<VideoCodec> {
nisse4b4dc862016-02-17 05:25:36 -0800699 // Use conference mode? This flag comes from the remote
700 // description's SDP line 'a=x-google-flag:conference', copied over
701 // by VideoChannel::SetRemoteContent_w, and ultimately used by
702 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700703 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800704 // The special screencast behaviour is disabled by default.
705 bool conference_mode = false;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700706};
707
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700708// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
709// encapsulate all the parameters needed for a video RtpReceiver.
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700710struct VideoRecvParameters : RtpParameters<VideoCodec> {
711};
712
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713class VideoMediaChannel : public MediaChannel {
714 public:
nisse08582ff2016-02-04 01:24:52 -0800715 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700716 explicit VideoMediaChannel(const MediaConfig& config)
717 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200719
720 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
721 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700722 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
723 virtual bool SetRtpSendParameters(
724 uint32_t ssrc,
725 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700726 // Get the receive parameters for the incoming stream identified by |ssrc|.
727 // If |ssrc| is 0, retrieve the receive parameters for the default receive
728 // stream, which is used when SSRCs are not signaled. Note that calling with
729 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
730 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700731 virtual webrtc::RtpParameters GetRtpReceiveParameters(
732 uint32_t ssrc) const = 0;
733 virtual bool SetRtpReceiveParameters(
734 uint32_t ssrc,
735 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 // Gets the currently set codecs/payload types to be used for outgoing media.
737 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 // Starts or stops transmission (and potentially capture) of local video.
739 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700740 // Configure stream for sending and register a source.
741 // The |ssrc| must correspond to a registered send stream.
742 virtual bool SetVideoSend(
743 uint32_t ssrc,
744 bool enable,
745 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800746 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800747 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -0700748 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800749 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800750 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700751 // This fills the "bitrate parts" (rtx, video bitrate) of the
752 // BandwidthEstimationInfo, since that part that isn't possible to get
753 // through webrtc::Call::GetStats, as they are statistics of the send
754 // streams.
755 // TODO(holmer): We should change this so that either BWE graphs doesn't
756 // need access to bitrates of the streams, or change the (RTC)StatsCollector
757 // so that it's getting the send stream stats separately by calling
758 // GetStats(), and merges with BandwidthEstimationInfo by itself.
759 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000761 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762};
763
764enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000765 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
766 // values.
767 DMT_NONE = 0,
768 DMT_CONTROL = 1,
769 DMT_BINARY = 2,
770 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771};
772
773// Info about data received in DataMediaChannel. For use in
774// DataMediaChannel::SignalDataReceived and in all of the signals that
775// signal fires, on up the chain.
776struct ReceiveDataParams {
777 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800778 // RTP data channels use SSRCs, SCTP data channels use SIDs.
779 union {
780 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800781 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800782 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800784 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800786 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800788 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789};
790
791struct SendDataParams {
792 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800793 // RTP data channels use SSRCs, SCTP data channels use SIDs.
794 union {
795 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800796 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800797 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800799 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800
Steve Anton002f9212018-01-09 16:38:15 -0800801 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 // For SCTP, whether to send messages flagged as ordered or not.
803 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800804 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 // For SCTP, whether the messages are sent reliably or not.
806 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800807 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 // For SCTP, if reliable == false, provide partial reliability by
809 // resending up to this many times. Either count or millis
810 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800811 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 // For SCTP, if reliable == false, provide partial reliability by
813 // resending for up to this many milliseconds. Either count or millis
814 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800815 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816};
817
818enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
819
nisse05103312016-03-16 02:22:50 -0700820struct DataSendParameters : RtpSendParameters<DataCodec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800821 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700822 std::ostringstream ost;
823 // Options and extensions aren't used.
824 ost << "{";
825 ost << "codecs: " << VectorToString(codecs) << ", ";
pbos378dc772016-01-28 15:58:41 -0800826 ost << "max_bandwidth_bps: " << max_bandwidth_bps;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700827 ost << "}";
828 return ost.str();
829 }
830};
831
832struct DataRecvParameters : RtpParameters<DataCodec> {
833};
834
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835class DataMediaChannel : public MediaChannel {
836 public:
zhihuangebbe4f22016-12-06 10:45:42 -0800837 DataMediaChannel() {}
Steve Antone78bcb92017-10-31 09:53:08 -0700838 explicit DataMediaChannel(const MediaConfig& config) : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 virtual ~DataMediaChannel() {}
840
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200841 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
842 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000843
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 // TODO(pthatcher): Implement this.
845 virtual bool GetStats(DataMediaInfo* info) { return true; }
846
847 virtual bool SetSend(bool send) = 0;
848 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849
Honghai Zhangcc411c02016-03-29 17:27:21 -0700850 virtual void OnNetworkRouteChanged(const std::string& transport_name,
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700851 const rtc::NetworkRoute& network_route) {}
Honghai Zhangcc411c02016-03-29 17:27:21 -0700852
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 virtual bool SendData(
854 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700855 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 SendDataResult* result = NULL) = 0;
857 // Signals when data is received (params, data, len)
858 sigslot::signal3<const ReceiveDataParams&,
859 const char*,
860 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000861 // Signal when the media channel is ready to send the stream. Arguments are:
862 // writable(bool)
863 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864};
865
866} // namespace cricket
867
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200868#endif // MEDIA_BASE_MEDIACHANNEL_H_