blob: ea8b1869ba91d7ecc8e06c0614454b6c1806c92d [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MEDIA_BASE_MEDIACHANNEL_H_
12#define MEDIA_BASE_MEDIACHANNEL_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
Steve Antone78bcb92017-10-31 09:53:08 -070014#include <map>
kwiberg686a8ef2016-02-26 03:00:35 -080015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
Patrik Höglundaba85d12017-11-28 15:46:08 +010017#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <vector>
19
Danil Chapovalov00c71832018-06-15 15:58:38 +020020#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "api/audio_codecs/audio_encoder.h"
Niels Möllera6fe2612018-01-19 11:28:54 +010022#include "api/audio_options.h"
Zach Steinba37b4b2018-01-23 15:02:36 -080023#include "api/rtcerror.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "api/rtpparameters.h"
25#include "api/rtpreceiverinterface.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010026#include "api/video/video_content_type.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020027#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020028#include "api/video/video_source_interface.h"
29#include "api/video/video_timing.h"
30#include "api/video_codecs/video_encoder_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "media/base/codec.h"
Niels Möller6daa2782018-01-23 10:37:42 +010032#include "media/base/mediaconfig.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "media/base/mediaconstants.h"
34#include "media/base/streamparams.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010035#include "modules/audio_processing/include/audio_processing_statistics.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010036#include "rtc_base/asyncpacketsocket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020037#include "rtc_base/buffer.h"
38#include "rtc_base/copyonwritebuffer.h"
39#include "rtc_base/dscp.h"
40#include "rtc_base/logging.h"
41#include "rtc_base/networkroute.h"
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
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000046namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047class Timing;
48}
49
Tommif888bb52015-12-12 01:37:01 +010050namespace webrtc {
51class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080052class VideoFrame;
Yves Gerey665174f2018-06-19 15:03:05 +020053} // namespace webrtc
Tommif888bb52015-12-12 01:37:01 +010054
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055namespace cricket {
56
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080057class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080059struct RtpHeader;
60struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062const int kScreencastDefaultFps = 5;
63
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064template <class T>
Danil Chapovalov00c71832018-06-15 15:58:38 +020065static std::string ToStringIfSet(const char* key,
66 const absl::optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070068 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069 str = key;
70 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070071 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072 str += ", ";
73 }
74 return str;
75}
76
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070077template <class T>
78static std::string VectorToString(const std::vector<T>& vals) {
Yves Gerey665174f2018-06-19 15:03:05 +020079 std::ostringstream ost; // no-presubmit-check TODO(webrtc:8982)
80 ost << "[";
81 for (size_t i = 0; i < vals.size(); ++i) {
82 if (i > 0) {
83 ost << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070084 }
Yves Gerey665174f2018-06-19 15:03:05 +020085 ost << vals[i].ToString();
86 }
87 ost << "]";
88 return ost.str();
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070089}
90
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
92// Used to be flags, but that makes it hard to selectively apply options.
93// We are moving all of the setting of options to structs like this,
94// but some things currently still use flags.
95struct VideoOptions {
Paulina Hensman11b34f42018-04-09 14:24:52 +020096 VideoOptions();
97 ~VideoOptions();
98
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700100 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800101 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100102 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103 }
104
105 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800106 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100107 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
108 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 }
deadbeef119760a2016-04-04 11:43:27 -0700110 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111
112 std::string ToString() const {
113 std::ostringstream ost;
114 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800116 ost << ToStringIfSet("screencast min bitrate kbps",
117 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100118 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 ost << "}";
120 return ost.str();
121 }
122
nisseb163c3f2016-01-29 01:14:38 -0800123 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700124 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800125 // on to the codec options. Disabled by default.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200126 absl::optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800127 // Force screencast to use a minimum bitrate. This flag comes from
128 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700129 // copied to the encoder config by WebRtcVideoChannel.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200130 absl::optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100131 // Set by screencast sources. Implies selection of encoding settings
132 // suitable for screencast. Most likely not the right way to do
133 // things, e.g., screencast of a text document and screencast of a
134 // youtube video have different needs.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200135 absl::optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700136
137 private:
138 template <typename T>
Danil Chapovalov00c71832018-06-15 15:58:38 +0200139 static void SetFrom(absl::optional<T>* s, const absl::optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700140 if (o) {
141 *s = o;
142 }
143 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144};
145
isheriffa1c548b2016-05-31 16:12:24 -0700146// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
147struct RtpHeaderExtension {
148 RtpHeaderExtension() : id(0) {}
149 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
150
151 std::string ToString() const {
152 std::ostringstream ost;
153 ost << "{";
154 ost << "uri: " << uri;
155 ost << ", id: " << id;
156 ost << "}";
157 return ost.str();
158 }
159
160 std::string uri;
161 int id;
162};
163
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164class MediaChannel : public sigslot::has_slots<> {
165 public:
166 class NetworkInterface {
167 public:
168 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700169 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700170 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700171 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700172 const rtc::PacketOptions& options) = 0;
Yves Gerey665174f2018-06-19 15:03:05 +0200173 virtual int SetOption(SocketType type,
174 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;
Yves Gerey665174f2018-06-19 15:03:05 +0200244 ret = SetOption(NetworkInterface::ST_RTP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000245 if (ret == 0) {
Yves Gerey665174f2018-06-19 15:03:05 +0200246 ret = SetOption(NetworkInterface::ST_RTCP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000247 }
248 return ret;
249 }
250
jbaucheec21bd2016-03-20 06:15:43 -0700251 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700252 bool rtcp,
253 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000254 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000255 if (!network_interface_)
256 return false;
257
stefanc1aeaf02015-10-15 07:26:07 -0700258 return (!rtcp) ? network_interface_->SendPacket(packet, options)
259 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000260 }
261
nisse51542be2016-02-12 02:27:06 -0800262 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000263 // |network_interface_| can be accessed from the worker_thread and
264 // from any MediaEngine threads. This critical section is to protect accessing
265 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000266 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000267 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268};
269
wu@webrtc.org97077a32013-10-25 21:18:33 +0000270// The stats information is structured as follows:
271// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
272// Media contains a vector of SSRC infos that are exclusively used by this
273// media. (SSRCs shared between media streams can't be represented.)
274
275// Information about an SSRC.
276// This data may be locally recorded, or received in an RTCP SR or RR.
277struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800278 uint32_t ssrc = 0;
279 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000280};
281
282struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800283 uint32_t ssrc = 0;
284 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000285};
286
287struct MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200288 MediaSenderInfo();
289 ~MediaSenderInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200290 void add_ssrc(const SsrcSenderInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000291 // Temporary utility function for call sites that only provide SSRC.
292 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200293 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000294 SsrcSenderInfo stat;
295 stat.ssrc = ssrc;
296 add_ssrc(stat);
297 }
298 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200299 std::vector<uint32_t> ssrcs() const {
300 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000301 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
302 it != local_stats.end(); ++it) {
303 retval.push_back(it->ssrc);
304 }
305 return retval;
306 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100307 // Returns true if the media has been connected.
308 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000309 // Utility accessor for clients that make the assumption only one ssrc
310 // exists per media.
311 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100312 // Call sites that compare this to zero should use connected() instead.
313 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200314 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100315 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000316 return local_stats[0].ssrc;
317 } else {
318 return 0;
319 }
320 }
Steve Anton002f9212018-01-09 16:38:15 -0800321 int64_t bytes_sent = 0;
322 int packets_sent = 0;
323 int packets_lost = 0;
324 float fraction_lost = 0.0f;
325 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000326 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200327 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000328 std::vector<SsrcSenderInfo> local_stats;
329 std::vector<SsrcReceiverInfo> remote_stats;
330};
331
332struct MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200333 MediaReceiverInfo();
334 ~MediaReceiverInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200335 void add_ssrc(const SsrcReceiverInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000336 // Temporary utility function for call sites that only provide SSRC.
337 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200338 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000339 SsrcReceiverInfo stat;
340 stat.ssrc = ssrc;
341 add_ssrc(stat);
342 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200343 std::vector<uint32_t> ssrcs() const {
344 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000345 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
346 it != local_stats.end(); ++it) {
347 retval.push_back(it->ssrc);
348 }
349 return retval;
350 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100351 // Returns true if the media has been connected.
352 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000353 // Utility accessor for clients that make the assumption only one ssrc
354 // exists per media.
355 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100356 // Call sites that compare this to zero should use connected();
357 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200358 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100359 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000360 return local_stats[0].ssrc;
361 } else {
362 return 0;
363 }
364 }
365
Steve Anton002f9212018-01-09 16:38:15 -0800366 int64_t bytes_rcvd = 0;
367 int packets_rcvd = 0;
368 int packets_lost = 0;
369 float fraction_lost = 0.0f;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000370 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200371 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000372 std::vector<SsrcReceiverInfo> local_stats;
373 std::vector<SsrcSenderInfo> remote_stats;
374};
375
376struct VoiceSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200377 VoiceSenderInfo();
378 ~VoiceSenderInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800379 int ext_seqnum = 0;
380 int jitter_ms = 0;
381 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700382 // See description of "totalAudioEnergy" in the WebRTC stats spec:
383 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800384 double total_input_energy = 0.0;
385 double total_input_duration = 0.0;
Ivo Creusen56d46092017-11-24 17:29:59 +0100386 // TODO(bugs.webrtc.org/8572): Remove APM stats from this struct, since they
387 // are no longer needed now that we have apm_statistics.
Steve Anton002f9212018-01-09 16:38:15 -0800388 int echo_delay_median_ms = 0;
389 int echo_delay_std_ms = 0;
390 int echo_return_loss = 0;
391 int echo_return_loss_enhancement = 0;
392 float residual_echo_likelihood = 0.0f;
393 float residual_echo_likelihood_recent_max = 0.0f;
394 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700395 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100396 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397};
398
wu@webrtc.org97077a32013-10-25 21:18:33 +0000399struct VoiceReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200400 VoiceReceiverInfo();
401 ~VoiceReceiverInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800402 int ext_seqnum = 0;
403 int jitter_ms = 0;
404 int jitter_buffer_ms = 0;
405 int jitter_buffer_preferred_ms = 0;
406 int delay_estimate_ms = 0;
407 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200408 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
409 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800410 double total_output_energy = 0.0;
411 uint64_t total_samples_received = 0;
412 double total_output_duration = 0.0;
413 uint64_t concealed_samples = 0;
414 uint64_t concealment_events = 0;
415 double jitter_buffer_delay_seconds = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200416 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000417 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800418 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000419 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800420 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000421 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800422 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200423 // Fraction of secondary data, including FEC and RED, that is discarded.
424 // Discarding of secondary data can be caused by the reception of the primary
425 // data, obsoleting the secondary data. It can also be caused by early
426 // or late arrival of secondary data. This metric is the percentage of
427 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800428 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200429 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800430 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200431 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800432 float preemptive_expand_rate = 0.0f;
433 int decoding_calls_to_silence_generator = 0;
434 int decoding_calls_to_neteq = 0;
435 int decoding_normal = 0;
436 int decoding_plc = 0;
437 int decoding_cng = 0;
438 int decoding_plc_cng = 0;
439 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000440 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800441 int64_t capture_start_ntp_time_ms = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000442};
443
wu@webrtc.org97077a32013-10-25 21:18:33 +0000444struct VideoSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200445 VideoSenderInfo();
446 ~VideoSenderInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000447 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800448 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100449 std::string encoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800450 int packets_cached = 0;
451 int firs_rcvd = 0;
452 int plis_rcvd = 0;
453 int nacks_rcvd = 0;
454 int send_frame_width = 0;
455 int send_frame_height = 0;
456 int framerate_input = 0;
457 int framerate_sent = 0;
458 int nominal_bitrate = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800459 int adapt_reason = 0;
460 int adapt_changes = 0;
461 int avg_encode_ms = 0;
462 int encode_usage_percent = 0;
463 uint32_t frames_encoded = 0;
464 bool has_entered_low_resolution = false;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200465 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800466 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100467 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
468 uint32_t huge_frames_sent = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469};
470
wu@webrtc.org97077a32013-10-25 21:18:33 +0000471struct VideoReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200472 VideoReceiverInfo();
473 ~VideoReceiverInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000474 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800475 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100476 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800477 int packets_concealed = 0;
478 int firs_sent = 0;
479 int plis_sent = 0;
480 int nacks_sent = 0;
481 int frame_width = 0;
482 int frame_height = 0;
483 int framerate_rcvd = 0;
484 int framerate_decoded = 0;
485 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000486 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800487 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000488 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800489 int framerate_render_output = 0;
490 uint32_t frames_received = 0;
491 uint32_t frames_decoded = 0;
492 uint32_t frames_rendered = 0;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200493 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800494 int64_t interframe_delay_max_ms = -1;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000495
Steve Anton002f9212018-01-09 16:38:15 -0800496 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700497
wu@webrtc.org97077a32013-10-25 21:18:33 +0000498 // All stats below are gathered per-VideoReceiver, but some will be correlated
499 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
500 // structures, reflect this in the new layout.
501
502 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800503 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000504 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800505 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000506 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800507 int jitter_buffer_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000508 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800509 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000510 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800511 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000512 // Target overall delay: network+decode+render, accounting for
513 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800514 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000515 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800516 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000517
518 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800519 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700520
521 // Timing frame info: all important timestamps for a full lifetime of a
522 // single 'timing frame'.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200523 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524};
525
wu@webrtc.org97077a32013-10-25 21:18:33 +0000526struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800527 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000528};
529
wu@webrtc.org97077a32013-10-25 21:18:33 +0000530struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800531 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000532};
533
534struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800535 int available_send_bandwidth = 0;
536 int available_recv_bandwidth = 0;
537 int target_enc_bitrate = 0;
538 int actual_enc_bitrate = 0;
539 int retransmit_bitrate = 0;
540 int transmit_bitrate = 0;
541 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000542};
543
hbosa65704b2016-11-14 02:28:16 -0800544// Maps from payload type to |RtpCodecParameters|.
545typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
546
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000547struct VoiceMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200548 VoiceMediaInfo();
549 ~VoiceMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 void Clear() {
551 senders.clear();
552 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800553 send_codecs.clear();
554 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 }
556 std::vector<VoiceSenderInfo> senders;
557 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800558 RtpCodecParametersMap send_codecs;
559 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560};
561
562struct VideoMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200563 VideoMediaInfo();
564 ~VideoMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 void Clear() {
566 senders.clear();
567 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700568 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800569 send_codecs.clear();
570 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 }
572 std::vector<VideoSenderInfo> senders;
573 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700574 // Deprecated.
575 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700576 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800577 RtpCodecParametersMap send_codecs;
578 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579};
580
581struct DataMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200582 DataMediaInfo();
583 ~DataMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 void Clear() {
585 senders.clear();
586 receivers.clear();
587 }
588 std::vector<DataSenderInfo> senders;
589 std::vector<DataReceiverInfo> receivers;
590};
591
deadbeef13871492015-12-09 12:37:51 -0800592struct RtcpParameters {
593 bool reduced_size = false;
594};
595
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700596template <class Codec>
597struct RtpParameters {
Steve Anton003930a2018-03-29 12:37:21 -0700598 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700599
600 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700601 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700602 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800603 RtcpParameters rtcp;
Steve Anton003930a2018-03-29 12:37:21 -0700604
605 std::string ToString() const {
606 std::ostringstream ost;
607 ost << "{";
608 const char* separator = "";
609 for (const auto& entry : ToStringMap()) {
610 ost << separator << entry.first << ": " << entry.second;
611 separator = ", ";
612 }
613 ost << "}";
614 return ost.str();
615 }
616
617 protected:
618 virtual std::map<std::string, std::string> ToStringMap() const {
619 return {{"codecs", VectorToString(codecs)},
620 {"extensions", VectorToString(extensions)}};
621 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700622};
623
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700624// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
625// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700626template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700627struct RtpSendParameters : RtpParameters<Codec> {
nisse05103312016-03-16 02:22:50 -0700628 int max_bandwidth_bps = -1;
Steve Antonbb50ce52018-03-26 10:24:32 -0700629 // This is the value to be sent in the MID RTP header extension (if the header
630 // extension in included in the list of extensions).
631 std::string mid;
Steve Anton003930a2018-03-29 12:37:21 -0700632
633 protected:
634 std::map<std::string, std::string> ToStringMap() const override {
635 auto params = RtpParameters<Codec>::ToStringMap();
636 params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps);
637 params["mid"] = (mid.empty() ? "<not set>" : mid);
638 return params;
639 }
nisse05103312016-03-16 02:22:50 -0700640};
641
642struct AudioSendParameters : RtpSendParameters<AudioCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200643 AudioSendParameters();
644 ~AudioSendParameters() override;
nisse05103312016-03-16 02:22:50 -0700645 AudioOptions options;
Steve Anton003930a2018-03-29 12:37:21 -0700646
647 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200648 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700649};
650
Yves Gerey665174f2018-06-19 15:03:05 +0200651struct AudioRecvParameters : RtpParameters<AudioCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700652
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653class VoiceMediaChannel : public MediaChannel {
654 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700656 explicit VoiceMediaChannel(const MediaConfig& config)
657 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200658 ~VoiceMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200659 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
660 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700661 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800662 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700663 uint32_t ssrc,
664 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700665 // Get the receive parameters for the incoming stream identified by |ssrc|.
666 // If |ssrc| is 0, retrieve the receive parameters for the default receive
667 // stream, which is used when SSRCs are not signaled. Note that calling with
668 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
669 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700670 virtual webrtc::RtpParameters GetRtpReceiveParameters(
671 uint32_t ssrc) const = 0;
672 virtual bool SetRtpReceiveParameters(
673 uint32_t ssrc,
674 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700676 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800678 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700679 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200680 virtual bool SetAudioSend(uint32_t ssrc,
681 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700682 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800683 AudioSource* source) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700684 // Set speaker output volume of the specified ssrc.
685 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800687 virtual bool CanInsertDtmf() = 0;
688 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000690 // The valid value for the |event| are 0 to 15 which corresponding to
691 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800692 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 // Gets quality stats for the channel.
694 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100695
696 virtual void SetRawAudioSink(
697 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800698 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700699
700 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701};
702
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700703// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
704// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700705struct VideoSendParameters : RtpSendParameters<VideoCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200706 VideoSendParameters();
707 ~VideoSendParameters() override;
nisse4b4dc862016-02-17 05:25:36 -0800708 // Use conference mode? This flag comes from the remote
709 // description's SDP line 'a=x-google-flag:conference', copied over
710 // by VideoChannel::SetRemoteContent_w, and ultimately used by
711 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700712 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800713 // The special screencast behaviour is disabled by default.
714 bool conference_mode = false;
Steve Anton003930a2018-03-29 12:37:21 -0700715
716 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200717 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700718};
719
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700720// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
721// encapsulate all the parameters needed for a video RtpReceiver.
Yves Gerey665174f2018-06-19 15:03:05 +0200722struct VideoRecvParameters : RtpParameters<VideoCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700723
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724class VideoMediaChannel : public MediaChannel {
725 public:
nisse08582ff2016-02-04 01:24:52 -0800726 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700727 explicit VideoMediaChannel(const MediaConfig& config)
728 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200729 ~VideoMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200730
731 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
732 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700733 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800734 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700735 uint32_t ssrc,
736 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700737 // Get the receive parameters for the incoming stream identified by |ssrc|.
738 // If |ssrc| is 0, retrieve the receive parameters for the default receive
739 // stream, which is used when SSRCs are not signaled. Note that calling with
740 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
741 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700742 virtual webrtc::RtpParameters GetRtpReceiveParameters(
743 uint32_t ssrc) const = 0;
744 virtual bool SetRtpReceiveParameters(
745 uint32_t ssrc,
746 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 // Gets the currently set codecs/payload types to be used for outgoing media.
748 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 // Starts or stops transmission (and potentially capture) of local video.
750 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700751 // Configure stream for sending and register a source.
752 // The |ssrc| must correspond to a registered send stream.
753 virtual bool SetVideoSend(
754 uint32_t ssrc,
deadbeef5a4a75a2016-06-02 16:23:38 -0700755 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800756 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800757 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -0700758 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800759 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800760 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700761 // This fills the "bitrate parts" (rtx, video bitrate) of the
762 // BandwidthEstimationInfo, since that part that isn't possible to get
763 // through webrtc::Call::GetStats, as they are statistics of the send
764 // streams.
765 // TODO(holmer): We should change this so that either BWE graphs doesn't
766 // need access to bitrates of the streams, or change the (RTC)StatsCollector
767 // so that it's getting the send stream stats separately by calling
768 // GetStats(), and merges with BandwidthEstimationInfo by itself.
769 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000771 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772};
773
774enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000775 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
776 // values.
777 DMT_NONE = 0,
778 DMT_CONTROL = 1,
779 DMT_BINARY = 2,
780 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781};
782
783// Info about data received in DataMediaChannel. For use in
784// DataMediaChannel::SignalDataReceived and in all of the signals that
785// signal fires, on up the chain.
786struct ReceiveDataParams {
787 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800788 // RTP data channels use SSRCs, SCTP data channels use SIDs.
789 union {
790 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800791 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800792 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800794 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800796 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800798 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799};
800
801struct SendDataParams {
802 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800803 // RTP data channels use SSRCs, SCTP data channels use SIDs.
804 union {
805 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800806 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800807 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800809 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810
Steve Anton002f9212018-01-09 16:38:15 -0800811 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 // For SCTP, whether to send messages flagged as ordered or not.
813 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800814 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 // For SCTP, whether the messages are sent reliably or not.
816 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800817 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 // For SCTP, if reliable == false, provide partial reliability by
819 // resending up to this many times. Either count or millis
820 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800821 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 // For SCTP, if reliable == false, provide partial reliability by
823 // resending for up to this many milliseconds. Either count or millis
824 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800825 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826};
827
828enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
829
Yves Gerey665174f2018-06-19 15:03:05 +0200830struct DataSendParameters : RtpSendParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700831
Yves Gerey665174f2018-06-19 15:03:05 +0200832struct DataRecvParameters : RtpParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700833
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834class DataMediaChannel : public MediaChannel {
835 public:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200836 DataMediaChannel();
837 explicit DataMediaChannel(const MediaConfig& config);
838 ~DataMediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200840 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
841 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000842
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 // TODO(pthatcher): Implement this.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200844 virtual bool GetStats(DataMediaInfo* info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845
846 virtual bool SetSend(bool send) = 0;
847 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848
Paulina Hensman11b34f42018-04-09 14:24:52 +0200849 void OnNetworkRouteChanged(const std::string& transport_name,
850 const rtc::NetworkRoute& network_route) override {}
Honghai Zhangcc411c02016-03-29 17:27:21 -0700851
Yves Gerey665174f2018-06-19 15:03:05 +0200852 virtual bool SendData(const SendDataParams& params,
853 const rtc::CopyOnWriteBuffer& payload,
854 SendDataResult* result = NULL) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 // Signals when data is received (params, data, len)
Yves Gerey665174f2018-06-19 15:03:05 +0200856 sigslot::signal3<const ReceiveDataParams&, const char*, size_t>
857 SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000858 // Signal when the media channel is ready to send the stream. Arguments are:
859 // writable(bool)
860 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861};
862
863} // namespace cricket
864
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200865#endif // MEDIA_BASE_MEDIACHANNEL_H_