blob: 57cbb3e4c0c7fea4e3a906b6f83f0d4e1a80f89f [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"
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"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "api/video/video_timing.h"
Patrik Höglundbe214a22018-01-04 12:14:35 +010028#include "api/videosinkinterface.h"
Patrik Höglundadc1e9b2018-01-09 14:55:05 +010029#include "api/videosourceinterface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "call/video_config.h"
31#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/basictypes.h"
38#include "rtc_base/buffer.h"
39#include "rtc_base/copyonwritebuffer.h"
40#include "rtc_base/dscp.h"
41#include "rtc_base/logging.h"
42#include "rtc_base/networkroute.h"
43#include "rtc_base/sigslot.h"
44#include "rtc_base/socket.h"
Niels Möller9a44f962017-12-08 15:57:38 +010045#include "rtc_base/stringencode.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010046
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000048namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049class 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 {
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 {
114 std::ostringstream ost;
115 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.
Karl Wibergbe579832015-11-10 22:34:18 +0100127 rtc::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.
nisseb163c3f2016-01-29 01:14:38 -0800131 rtc::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.
136 rtc::Optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700137
138 private:
139 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100140 static void SetFrom(rtc::Optional<T>* s, const rtc::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 {
153 std::ostringstream ost;
154 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;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000174 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 int option) = 0;
176 virtual ~NetworkInterface() {}
177 };
178
terelius54f91712016-06-01 11:18:56 -0700179 explicit MediaChannel(const MediaConfig& config)
nisse51542be2016-02-12 02:27:06 -0800180 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
181 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200182 ~MediaChannel() override {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000184 // Sets the abstract interface class for sending RTP/RTCP data.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200185 virtual void SetInterface(NetworkInterface* iface);
186 virtual rtc::DiffServCodePoint PreferredDscp() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700188 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000189 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700191 virtual void OnRtcpReceived(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 the socket's ability to send has changed.
194 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700195 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700196 virtual void OnNetworkRouteChanged(
197 const std::string& transport_name,
198 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199 // Creates a new outgoing media stream with SSRCs and CNAME as described
200 // by sp.
201 virtual bool AddSendStream(const StreamParams& sp) = 0;
202 // Removes an outgoing media stream.
Seth Hampson5897a6e2018-04-03 11:16:33 -0700203 // SSRC must be the first SSRC of the media stream if the stream uses
204 // multiple SSRCs. In the case of an ssrc of 0, the possibly cached
205 // StreamParams is removed.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200206 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700207 // Creates a new incoming media stream with SSRCs, CNAME as described
208 // by sp. In the case of a sp without SSRCs, the unsignaled sp is cached
209 // to be used later for unsignaled streams received.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 virtual bool AddRecvStream(const StreamParams& sp) = 0;
211 // Removes an incoming media stream.
212 // ssrc must be the first SSRC of the media stream if the stream uses
213 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200214 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000216 // Returns the absoulte sendtime extension id value from media channel.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200217 virtual int GetRtpSendTimeExtnId() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000219 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700220 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
221 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700222 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000223 }
224
jbaucheec21bd2016-03-20 06:15:43 -0700225 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
226 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700227 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000228 }
229
230 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000231 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000232 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000233 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000234 if (!network_interface_)
235 return -1;
236
237 return network_interface_->SetOption(type, opt, option);
238 }
239
nisse51542be2016-02-12 02:27:06 -0800240 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000241 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000242 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000243 int ret;
244 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000245 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000246 value);
247 if (ret == 0) {
248 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000249 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000250 value);
251 }
252 return ret;
253 }
254
jbaucheec21bd2016-03-20 06:15:43 -0700255 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700256 bool rtcp,
257 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000258 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000259 if (!network_interface_)
260 return false;
261
stefanc1aeaf02015-10-15 07:26:07 -0700262 return (!rtcp) ? network_interface_->SendPacket(packet, options)
263 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000264 }
265
nisse51542be2016-02-12 02:27:06 -0800266 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000267 // |network_interface_| can be accessed from the worker_thread and
268 // from any MediaEngine threads. This critical section is to protect accessing
269 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000270 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000271 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272};
273
wu@webrtc.org97077a32013-10-25 21:18:33 +0000274// The stats information is structured as follows:
275// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
276// Media contains a vector of SSRC infos that are exclusively used by this
277// media. (SSRCs shared between media streams can't be represented.)
278
279// Information about an SSRC.
280// This data may be locally recorded, or received in an RTCP SR or RR.
281struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800282 uint32_t ssrc = 0;
283 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000284};
285
286struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800287 uint32_t ssrc = 0;
288 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000289};
290
291struct MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200292 MediaSenderInfo();
293 ~MediaSenderInfo();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000294 void add_ssrc(const SsrcSenderInfo& stat) {
295 local_stats.push_back(stat);
296 }
297 // Temporary utility function for call sites that only provide SSRC.
298 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200299 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000300 SsrcSenderInfo stat;
301 stat.ssrc = ssrc;
302 add_ssrc(stat);
303 }
304 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200305 std::vector<uint32_t> ssrcs() const {
306 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000307 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
308 it != local_stats.end(); ++it) {
309 retval.push_back(it->ssrc);
310 }
311 return retval;
312 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100313 // Returns true if the media has been connected.
314 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000315 // Utility accessor for clients that make the assumption only one ssrc
316 // exists per media.
317 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100318 // Call sites that compare this to zero should use connected() instead.
319 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200320 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100321 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000322 return local_stats[0].ssrc;
323 } else {
324 return 0;
325 }
326 }
Steve Anton002f9212018-01-09 16:38:15 -0800327 int64_t bytes_sent = 0;
328 int packets_sent = 0;
329 int packets_lost = 0;
330 float fraction_lost = 0.0f;
331 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000332 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800333 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000334 std::vector<SsrcSenderInfo> local_stats;
335 std::vector<SsrcReceiverInfo> remote_stats;
336};
337
338struct MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200339 MediaReceiverInfo();
340 ~MediaReceiverInfo();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000341 void add_ssrc(const SsrcReceiverInfo& stat) {
342 local_stats.push_back(stat);
343 }
344 // Temporary utility function for call sites that only provide SSRC.
345 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200346 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000347 SsrcReceiverInfo stat;
348 stat.ssrc = ssrc;
349 add_ssrc(stat);
350 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200351 std::vector<uint32_t> ssrcs() const {
352 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000353 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
354 it != local_stats.end(); ++it) {
355 retval.push_back(it->ssrc);
356 }
357 return retval;
358 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100359 // Returns true if the media has been connected.
360 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000361 // Utility accessor for clients that make the assumption only one ssrc
362 // exists per media.
363 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100364 // Call sites that compare this to zero should use connected();
365 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200366 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100367 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000368 return local_stats[0].ssrc;
369 } else {
370 return 0;
371 }
372 }
373
Steve Anton002f9212018-01-09 16:38:15 -0800374 int64_t bytes_rcvd = 0;
375 int packets_rcvd = 0;
376 int packets_lost = 0;
377 float fraction_lost = 0.0f;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000378 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800379 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000380 std::vector<SsrcReceiverInfo> local_stats;
381 std::vector<SsrcSenderInfo> remote_stats;
382};
383
384struct VoiceSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200385 VoiceSenderInfo();
386 ~VoiceSenderInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800387 int ext_seqnum = 0;
388 int jitter_ms = 0;
389 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700390 // See description of "totalAudioEnergy" in the WebRTC stats spec:
391 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800392 double total_input_energy = 0.0;
393 double total_input_duration = 0.0;
Ivo Creusen56d46092017-11-24 17:29:59 +0100394 // TODO(bugs.webrtc.org/8572): Remove APM stats from this struct, since they
395 // are no longer needed now that we have apm_statistics.
Steve Anton002f9212018-01-09 16:38:15 -0800396 int echo_delay_median_ms = 0;
397 int echo_delay_std_ms = 0;
398 int echo_return_loss = 0;
399 int echo_return_loss_enhancement = 0;
400 float residual_echo_likelihood = 0.0f;
401 float residual_echo_likelihood_recent_max = 0.0f;
402 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700403 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100404 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405};
406
wu@webrtc.org97077a32013-10-25 21:18:33 +0000407struct VoiceReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200408 VoiceReceiverInfo();
409 ~VoiceReceiverInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800410 int ext_seqnum = 0;
411 int jitter_ms = 0;
412 int jitter_buffer_ms = 0;
413 int jitter_buffer_preferred_ms = 0;
414 int delay_estimate_ms = 0;
415 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200416 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
417 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800418 double total_output_energy = 0.0;
419 uint64_t total_samples_received = 0;
420 double total_output_duration = 0.0;
421 uint64_t concealed_samples = 0;
422 uint64_t concealment_events = 0;
423 double jitter_buffer_delay_seconds = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200424 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000425 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800426 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000427 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800428 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000429 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800430 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200431 // Fraction of secondary data, including FEC and RED, that is discarded.
432 // Discarding of secondary data can be caused by the reception of the primary
433 // data, obsoleting the secondary data. It can also be caused by early
434 // or late arrival of secondary data. This metric is the percentage of
435 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800436 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200437 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800438 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200439 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800440 float preemptive_expand_rate = 0.0f;
441 int decoding_calls_to_silence_generator = 0;
442 int decoding_calls_to_neteq = 0;
443 int decoding_normal = 0;
444 int decoding_plc = 0;
445 int decoding_cng = 0;
446 int decoding_plc_cng = 0;
447 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000448 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800449 int64_t capture_start_ntp_time_ms = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450};
451
wu@webrtc.org97077a32013-10-25 21:18:33 +0000452struct VideoSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200453 VideoSenderInfo();
454 ~VideoSenderInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000455 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800456 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100457 std::string encoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800458 int packets_cached = 0;
459 int firs_rcvd = 0;
460 int plis_rcvd = 0;
461 int nacks_rcvd = 0;
462 int send_frame_width = 0;
463 int send_frame_height = 0;
464 int framerate_input = 0;
465 int framerate_sent = 0;
466 int nominal_bitrate = 0;
467 int preferred_bitrate = 0;
468 int adapt_reason = 0;
469 int adapt_changes = 0;
470 int avg_encode_ms = 0;
471 int encode_usage_percent = 0;
472 uint32_t frames_encoded = 0;
473 bool has_entered_low_resolution = false;
sakal87da4042016-10-31 06:53:47 -0700474 rtc::Optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800475 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100476 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
477 uint32_t huge_frames_sent = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000478};
479
wu@webrtc.org97077a32013-10-25 21:18:33 +0000480struct VideoReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200481 VideoReceiverInfo();
482 ~VideoReceiverInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000483 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800484 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100485 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800486 int packets_concealed = 0;
487 int firs_sent = 0;
488 int plis_sent = 0;
489 int nacks_sent = 0;
490 int frame_width = 0;
491 int frame_height = 0;
492 int framerate_rcvd = 0;
493 int framerate_decoded = 0;
494 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000495 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800496 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000497 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800498 int framerate_render_output = 0;
499 uint32_t frames_received = 0;
500 uint32_t frames_decoded = 0;
501 uint32_t frames_rendered = 0;
sakalcc452e12017-02-09 04:53:45 -0800502 rtc::Optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800503 int64_t interframe_delay_max_ms = -1;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000504
Steve Anton002f9212018-01-09 16:38:15 -0800505 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700506
wu@webrtc.org97077a32013-10-25 21:18:33 +0000507 // All stats below are gathered per-VideoReceiver, but some will be correlated
508 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
509 // structures, reflect this in the new layout.
510
511 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800512 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000513 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800514 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000515 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800516 int jitter_buffer_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000517 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800518 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000519 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800520 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000521 // Target overall delay: network+decode+render, accounting for
522 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800523 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000524 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800525 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000526
527 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800528 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700529
530 // Timing frame info: all important timestamps for a full lifetime of a
531 // single 'timing frame'.
532 rtc::Optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533};
534
wu@webrtc.org97077a32013-10-25 21:18:33 +0000535struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800536 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537};
538
wu@webrtc.org97077a32013-10-25 21:18:33 +0000539struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800540 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541};
542
543struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800544 int available_send_bandwidth = 0;
545 int available_recv_bandwidth = 0;
546 int target_enc_bitrate = 0;
547 int actual_enc_bitrate = 0;
548 int retransmit_bitrate = 0;
549 int transmit_bitrate = 0;
550 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551};
552
hbosa65704b2016-11-14 02:28:16 -0800553// Maps from payload type to |RtpCodecParameters|.
554typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
555
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556struct VoiceMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200557 VoiceMediaInfo();
558 ~VoiceMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 void Clear() {
560 senders.clear();
561 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800562 send_codecs.clear();
563 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 }
565 std::vector<VoiceSenderInfo> senders;
566 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800567 RtpCodecParametersMap send_codecs;
568 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569};
570
571struct VideoMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200572 VideoMediaInfo();
573 ~VideoMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 void Clear() {
575 senders.clear();
576 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700577 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800578 send_codecs.clear();
579 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 }
581 std::vector<VideoSenderInfo> senders;
582 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700583 // Deprecated.
584 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700585 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800586 RtpCodecParametersMap send_codecs;
587 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588};
589
590struct DataMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200591 DataMediaInfo();
592 ~DataMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 void Clear() {
594 senders.clear();
595 receivers.clear();
596 }
597 std::vector<DataSenderInfo> senders;
598 std::vector<DataReceiverInfo> receivers;
599};
600
deadbeef13871492015-12-09 12:37:51 -0800601struct RtcpParameters {
602 bool reduced_size = false;
603};
604
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700605template <class Codec>
606struct RtpParameters {
Steve Anton003930a2018-03-29 12:37:21 -0700607 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700608
609 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700610 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700611 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800612 RtcpParameters rtcp;
Steve Anton003930a2018-03-29 12:37:21 -0700613
614 std::string ToString() const {
615 std::ostringstream ost;
616 ost << "{";
617 const char* separator = "";
618 for (const auto& entry : ToStringMap()) {
619 ost << separator << entry.first << ": " << entry.second;
620 separator = ", ";
621 }
622 ost << "}";
623 return ost.str();
624 }
625
626 protected:
627 virtual std::map<std::string, std::string> ToStringMap() const {
628 return {{"codecs", VectorToString(codecs)},
629 {"extensions", VectorToString(extensions)}};
630 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700631};
632
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700633// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
634// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700635template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700636struct RtpSendParameters : RtpParameters<Codec> {
nisse05103312016-03-16 02:22:50 -0700637 int max_bandwidth_bps = -1;
Steve Antonbb50ce52018-03-26 10:24:32 -0700638 // This is the value to be sent in the MID RTP header extension (if the header
639 // extension in included in the list of extensions).
640 std::string mid;
Steve Anton003930a2018-03-29 12:37:21 -0700641
642 protected:
643 std::map<std::string, std::string> ToStringMap() const override {
644 auto params = RtpParameters<Codec>::ToStringMap();
645 params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps);
646 params["mid"] = (mid.empty() ? "<not set>" : mid);
647 return params;
648 }
nisse05103312016-03-16 02:22:50 -0700649};
650
651struct AudioSendParameters : RtpSendParameters<AudioCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200652 AudioSendParameters();
653 ~AudioSendParameters() override;
nisse05103312016-03-16 02:22:50 -0700654 AudioOptions options;
Steve Anton003930a2018-03-29 12:37:21 -0700655
656 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200657 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700658};
659
660struct AudioRecvParameters : RtpParameters<AudioCodec> {
661};
662
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000663class VoiceMediaChannel : public MediaChannel {
664 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700666 explicit VoiceMediaChannel(const MediaConfig& config)
667 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200668 ~VoiceMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200669 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
670 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700671 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800672 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700673 uint32_t ssrc,
674 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700675 // Get the receive parameters for the incoming stream identified by |ssrc|.
676 // If |ssrc| is 0, retrieve the receive parameters for the default receive
677 // stream, which is used when SSRCs are not signaled. Note that calling with
678 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
679 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700680 virtual webrtc::RtpParameters GetRtpReceiveParameters(
681 uint32_t ssrc) const = 0;
682 virtual bool SetRtpReceiveParameters(
683 uint32_t ssrc,
684 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700686 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800688 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700689 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200690 virtual bool SetAudioSend(uint32_t ssrc,
691 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700692 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800693 AudioSource* source) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700694 // Set speaker output volume of the specified ssrc.
695 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800697 virtual bool CanInsertDtmf() = 0;
698 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000699 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000700 // The valid value for the |event| are 0 to 15 which corresponding to
701 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800702 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 // Gets quality stats for the channel.
704 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100705
706 virtual void SetRawAudioSink(
707 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800708 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700709
710 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711};
712
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700713// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
714// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700715struct VideoSendParameters : RtpSendParameters<VideoCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200716 VideoSendParameters();
717 ~VideoSendParameters() override;
nisse4b4dc862016-02-17 05:25:36 -0800718 // Use conference mode? This flag comes from the remote
719 // description's SDP line 'a=x-google-flag:conference', copied over
720 // by VideoChannel::SetRemoteContent_w, and ultimately used by
721 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700722 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800723 // The special screencast behaviour is disabled by default.
724 bool conference_mode = false;
Steve Anton003930a2018-03-29 12:37:21 -0700725
726 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200727 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700728};
729
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700730// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
731// encapsulate all the parameters needed for a video RtpReceiver.
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700732struct VideoRecvParameters : RtpParameters<VideoCodec> {
733};
734
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735class VideoMediaChannel : public MediaChannel {
736 public:
nisse08582ff2016-02-04 01:24:52 -0800737 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700738 explicit VideoMediaChannel(const MediaConfig& config)
739 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200740 ~VideoMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200741
742 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
743 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700744 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800745 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700746 uint32_t ssrc,
747 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700748 // Get the receive parameters for the incoming stream identified by |ssrc|.
749 // If |ssrc| is 0, retrieve the receive parameters for the default receive
750 // stream, which is used when SSRCs are not signaled. Note that calling with
751 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
752 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700753 virtual webrtc::RtpParameters GetRtpReceiveParameters(
754 uint32_t ssrc) const = 0;
755 virtual bool SetRtpReceiveParameters(
756 uint32_t ssrc,
757 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 // Gets the currently set codecs/payload types to be used for outgoing media.
759 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 // Starts or stops transmission (and potentially capture) of local video.
761 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700762 // Configure stream for sending and register a source.
763 // The |ssrc| must correspond to a registered send stream.
764 virtual bool SetVideoSend(
765 uint32_t ssrc,
deadbeef5a4a75a2016-06-02 16:23:38 -0700766 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800767 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800768 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -0700769 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800770 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800771 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700772 // This fills the "bitrate parts" (rtx, video bitrate) of the
773 // BandwidthEstimationInfo, since that part that isn't possible to get
774 // through webrtc::Call::GetStats, as they are statistics of the send
775 // streams.
776 // TODO(holmer): We should change this so that either BWE graphs doesn't
777 // need access to bitrates of the streams, or change the (RTC)StatsCollector
778 // so that it's getting the send stream stats separately by calling
779 // GetStats(), and merges with BandwidthEstimationInfo by itself.
780 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000782 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783};
784
785enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000786 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
787 // values.
788 DMT_NONE = 0,
789 DMT_CONTROL = 1,
790 DMT_BINARY = 2,
791 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792};
793
794// Info about data received in DataMediaChannel. For use in
795// DataMediaChannel::SignalDataReceived and in all of the signals that
796// signal fires, on up the chain.
797struct ReceiveDataParams {
798 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800799 // RTP data channels use SSRCs, SCTP data channels use SIDs.
800 union {
801 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800802 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800803 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800805 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800807 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800809 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810};
811
812struct SendDataParams {
813 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800814 // RTP data channels use SSRCs, SCTP data channels use SIDs.
815 union {
816 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800817 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800818 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800820 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821
Steve Anton002f9212018-01-09 16:38:15 -0800822 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 // For SCTP, whether to send messages flagged as ordered or not.
824 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800825 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 // For SCTP, whether the messages are sent reliably or not.
827 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800828 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 // For SCTP, if reliable == false, provide partial reliability by
830 // resending up to this many times. Either count or millis
831 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800832 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833 // For SCTP, if reliable == false, provide partial reliability by
834 // resending for up to this many milliseconds. Either count or millis
835 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800836 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837};
838
839enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
840
nisse05103312016-03-16 02:22:50 -0700841struct DataSendParameters : RtpSendParameters<DataCodec> {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700842};
843
844struct DataRecvParameters : RtpParameters<DataCodec> {
845};
846
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847class DataMediaChannel : public MediaChannel {
848 public:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200849 DataMediaChannel();
850 explicit DataMediaChannel(const MediaConfig& config);
851 ~DataMediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200853 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
854 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000855
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 // TODO(pthatcher): Implement this.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200857 virtual bool GetStats(DataMediaInfo* info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858
859 virtual bool SetSend(bool send) = 0;
860 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861
Paulina Hensman11b34f42018-04-09 14:24:52 +0200862 void OnNetworkRouteChanged(const std::string& transport_name,
863 const rtc::NetworkRoute& network_route) override {}
Honghai Zhangcc411c02016-03-29 17:27:21 -0700864
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 virtual bool SendData(
866 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700867 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 SendDataResult* result = NULL) = 0;
869 // Signals when data is received (params, data, len)
870 sigslot::signal3<const ReceiveDataParams&,
871 const char*,
872 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000873 // Signal when the media channel is ready to send the stream. Arguments are:
874 // writable(bool)
875 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876};
877
878} // namespace cricket
879
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200880#endif // MEDIA_BASE_MEDIACHANNEL_H_