blob: a9b586a0521fabb12016fecb607bf77c0ff764ee [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;
Tommif888bb52015-12-12 01:37:01 +010053}
54
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) {
79 std::ostringstream ost;
80 ost << "[";
81 for (size_t i = 0; i < vals.size(); ++i) {
82 if (i > 0) {
83 ost << ", ";
84 }
85 ost << vals[i].ToString();
86 }
87 ost << "]";
88 return ost.str();
89}
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;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000173 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 int option) = 0;
175 virtual ~NetworkInterface() {}
176 };
177
terelius54f91712016-06-01 11:18:56 -0700178 explicit MediaChannel(const MediaConfig& config)
nisse51542be2016-02-12 02:27:06 -0800179 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
180 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200181 ~MediaChannel() override {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000183 // Sets the abstract interface class for sending RTP/RTCP data.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200184 virtual void SetInterface(NetworkInterface* iface);
185 virtual rtc::DiffServCodePoint PreferredDscp() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700187 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000188 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700190 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000191 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 // Called when the socket's ability to send has changed.
193 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700194 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700195 virtual void OnNetworkRouteChanged(
196 const std::string& transport_name,
197 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 // Creates a new outgoing media stream with SSRCs and CNAME as described
199 // by sp.
200 virtual bool AddSendStream(const StreamParams& sp) = 0;
201 // Removes an outgoing media stream.
Seth Hampson5897a6e2018-04-03 11:16:33 -0700202 // SSRC must be the first SSRC of the media stream if the stream uses
203 // multiple SSRCs. In the case of an ssrc of 0, the possibly cached
204 // StreamParams is removed.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200205 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700206 // Creates a new incoming media stream with SSRCs, CNAME as described
207 // by sp. In the case of a sp without SSRCs, the unsignaled sp is cached
208 // to be used later for unsignaled streams received.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 virtual bool AddRecvStream(const StreamParams& sp) = 0;
210 // Removes an incoming media stream.
211 // ssrc must be the first SSRC of the media stream if the stream uses
212 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200213 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000215 // Returns the absoulte sendtime extension id value from media channel.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200216 virtual int GetRtpSendTimeExtnId() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000218 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700219 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
220 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700221 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000222 }
223
jbaucheec21bd2016-03-20 06:15:43 -0700224 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
225 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700226 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000227 }
228
229 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000230 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000231 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000232 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000233 if (!network_interface_)
234 return -1;
235
236 return network_interface_->SetOption(type, opt, option);
237 }
238
nisse51542be2016-02-12 02:27:06 -0800239 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000240 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000241 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000242 int ret;
243 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000244 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000245 value);
246 if (ret == 0) {
247 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000248 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000249 value);
250 }
251 return ret;
252 }
253
jbaucheec21bd2016-03-20 06:15:43 -0700254 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700255 bool rtcp,
256 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000257 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000258 if (!network_interface_)
259 return false;
260
stefanc1aeaf02015-10-15 07:26:07 -0700261 return (!rtcp) ? network_interface_->SendPacket(packet, options)
262 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000263 }
264
nisse51542be2016-02-12 02:27:06 -0800265 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000266 // |network_interface_| can be accessed from the worker_thread and
267 // from any MediaEngine threads. This critical section is to protect accessing
268 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000269 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000270 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271};
272
wu@webrtc.org97077a32013-10-25 21:18:33 +0000273// The stats information is structured as follows:
274// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
275// Media contains a vector of SSRC infos that are exclusively used by this
276// media. (SSRCs shared between media streams can't be represented.)
277
278// Information about an SSRC.
279// This data may be locally recorded, or received in an RTCP SR or RR.
280struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800281 uint32_t ssrc = 0;
282 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000283};
284
285struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800286 uint32_t ssrc = 0;
287 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000288};
289
290struct MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200291 MediaSenderInfo();
292 ~MediaSenderInfo();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000293 void add_ssrc(const SsrcSenderInfo& stat) {
294 local_stats.push_back(stat);
295 }
296 // Temporary utility function for call sites that only provide SSRC.
297 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200298 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000299 SsrcSenderInfo stat;
300 stat.ssrc = ssrc;
301 add_ssrc(stat);
302 }
303 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200304 std::vector<uint32_t> ssrcs() const {
305 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000306 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
307 it != local_stats.end(); ++it) {
308 retval.push_back(it->ssrc);
309 }
310 return retval;
311 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100312 // Returns true if the media has been connected.
313 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000314 // Utility accessor for clients that make the assumption only one ssrc
315 // exists per media.
316 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100317 // Call sites that compare this to zero should use connected() instead.
318 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200319 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100320 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000321 return local_stats[0].ssrc;
322 } else {
323 return 0;
324 }
325 }
Steve Anton002f9212018-01-09 16:38:15 -0800326 int64_t bytes_sent = 0;
327 int packets_sent = 0;
328 int packets_lost = 0;
329 float fraction_lost = 0.0f;
330 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000331 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200332 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000333 std::vector<SsrcSenderInfo> local_stats;
334 std::vector<SsrcReceiverInfo> remote_stats;
335};
336
337struct MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200338 MediaReceiverInfo();
339 ~MediaReceiverInfo();
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000340 void add_ssrc(const SsrcReceiverInfo& stat) {
341 local_stats.push_back(stat);
342 }
343 // Temporary utility function for call sites that only provide SSRC.
344 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200345 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000346 SsrcReceiverInfo stat;
347 stat.ssrc = ssrc;
348 add_ssrc(stat);
349 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200350 std::vector<uint32_t> ssrcs() const {
351 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000352 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
353 it != local_stats.end(); ++it) {
354 retval.push_back(it->ssrc);
355 }
356 return retval;
357 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100358 // Returns true if the media has been connected.
359 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000360 // Utility accessor for clients that make the assumption only one ssrc
361 // exists per media.
362 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100363 // Call sites that compare this to zero should use connected();
364 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200365 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100366 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000367 return local_stats[0].ssrc;
368 } else {
369 return 0;
370 }
371 }
372
Steve Anton002f9212018-01-09 16:38:15 -0800373 int64_t bytes_rcvd = 0;
374 int packets_rcvd = 0;
375 int packets_lost = 0;
376 float fraction_lost = 0.0f;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000377 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200378 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000379 std::vector<SsrcReceiverInfo> local_stats;
380 std::vector<SsrcSenderInfo> remote_stats;
381};
382
383struct VoiceSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200384 VoiceSenderInfo();
385 ~VoiceSenderInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800386 int ext_seqnum = 0;
387 int jitter_ms = 0;
388 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700389 // See description of "totalAudioEnergy" in the WebRTC stats spec:
390 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800391 double total_input_energy = 0.0;
392 double total_input_duration = 0.0;
Ivo Creusen56d46092017-11-24 17:29:59 +0100393 // TODO(bugs.webrtc.org/8572): Remove APM stats from this struct, since they
394 // are no longer needed now that we have apm_statistics.
Steve Anton002f9212018-01-09 16:38:15 -0800395 int echo_delay_median_ms = 0;
396 int echo_delay_std_ms = 0;
397 int echo_return_loss = 0;
398 int echo_return_loss_enhancement = 0;
399 float residual_echo_likelihood = 0.0f;
400 float residual_echo_likelihood_recent_max = 0.0f;
401 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700402 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100403 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404};
405
wu@webrtc.org97077a32013-10-25 21:18:33 +0000406struct VoiceReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200407 VoiceReceiverInfo();
408 ~VoiceReceiverInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800409 int ext_seqnum = 0;
410 int jitter_ms = 0;
411 int jitter_buffer_ms = 0;
412 int jitter_buffer_preferred_ms = 0;
413 int delay_estimate_ms = 0;
414 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200415 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
416 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800417 double total_output_energy = 0.0;
418 uint64_t total_samples_received = 0;
419 double total_output_duration = 0.0;
420 uint64_t concealed_samples = 0;
421 uint64_t concealment_events = 0;
422 double jitter_buffer_delay_seconds = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200423 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000424 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800425 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000426 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800427 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000428 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800429 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200430 // Fraction of secondary data, including FEC and RED, that is discarded.
431 // Discarding of secondary data can be caused by the reception of the primary
432 // data, obsoleting the secondary data. It can also be caused by early
433 // or late arrival of secondary data. This metric is the percentage of
434 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800435 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200436 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800437 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200438 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800439 float preemptive_expand_rate = 0.0f;
440 int decoding_calls_to_silence_generator = 0;
441 int decoding_calls_to_neteq = 0;
442 int decoding_normal = 0;
443 int decoding_plc = 0;
444 int decoding_cng = 0;
445 int decoding_plc_cng = 0;
446 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000447 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800448 int64_t capture_start_ntp_time_ms = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449};
450
wu@webrtc.org97077a32013-10-25 21:18:33 +0000451struct VideoSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200452 VideoSenderInfo();
453 ~VideoSenderInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000454 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800455 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100456 std::string encoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800457 int packets_cached = 0;
458 int firs_rcvd = 0;
459 int plis_rcvd = 0;
460 int nacks_rcvd = 0;
461 int send_frame_width = 0;
462 int send_frame_height = 0;
463 int framerate_input = 0;
464 int framerate_sent = 0;
465 int nominal_bitrate = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800466 int adapt_reason = 0;
467 int adapt_changes = 0;
468 int avg_encode_ms = 0;
469 int encode_usage_percent = 0;
470 uint32_t frames_encoded = 0;
471 bool has_entered_low_resolution = false;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200472 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800473 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100474 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
475 uint32_t huge_frames_sent = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476};
477
wu@webrtc.org97077a32013-10-25 21:18:33 +0000478struct VideoReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200479 VideoReceiverInfo();
480 ~VideoReceiverInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000481 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800482 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100483 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800484 int packets_concealed = 0;
485 int firs_sent = 0;
486 int plis_sent = 0;
487 int nacks_sent = 0;
488 int frame_width = 0;
489 int frame_height = 0;
490 int framerate_rcvd = 0;
491 int framerate_decoded = 0;
492 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000493 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800494 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000495 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800496 int framerate_render_output = 0;
497 uint32_t frames_received = 0;
498 uint32_t frames_decoded = 0;
499 uint32_t frames_rendered = 0;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200500 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800501 int64_t interframe_delay_max_ms = -1;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000502
Steve Anton002f9212018-01-09 16:38:15 -0800503 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700504
wu@webrtc.org97077a32013-10-25 21:18:33 +0000505 // All stats below are gathered per-VideoReceiver, but some will be correlated
506 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
507 // structures, reflect this in the new layout.
508
509 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800510 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000511 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800512 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000513 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800514 int jitter_buffer_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000515 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800516 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000517 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800518 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000519 // Target overall delay: network+decode+render, accounting for
520 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800521 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000522 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800523 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000524
525 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800526 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700527
528 // Timing frame info: all important timestamps for a full lifetime of a
529 // single 'timing frame'.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200530 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000531};
532
wu@webrtc.org97077a32013-10-25 21:18:33 +0000533struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800534 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535};
536
wu@webrtc.org97077a32013-10-25 21:18:33 +0000537struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800538 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539};
540
541struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800542 int available_send_bandwidth = 0;
543 int available_recv_bandwidth = 0;
544 int target_enc_bitrate = 0;
545 int actual_enc_bitrate = 0;
546 int retransmit_bitrate = 0;
547 int transmit_bitrate = 0;
548 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549};
550
hbosa65704b2016-11-14 02:28:16 -0800551// Maps from payload type to |RtpCodecParameters|.
552typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
553
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554struct VoiceMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200555 VoiceMediaInfo();
556 ~VoiceMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 void Clear() {
558 senders.clear();
559 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800560 send_codecs.clear();
561 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000562 }
563 std::vector<VoiceSenderInfo> senders;
564 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800565 RtpCodecParametersMap send_codecs;
566 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567};
568
569struct VideoMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200570 VideoMediaInfo();
571 ~VideoMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 void Clear() {
573 senders.clear();
574 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700575 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800576 send_codecs.clear();
577 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 }
579 std::vector<VideoSenderInfo> senders;
580 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700581 // Deprecated.
582 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700583 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800584 RtpCodecParametersMap send_codecs;
585 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000586};
587
588struct DataMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200589 DataMediaInfo();
590 ~DataMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 void Clear() {
592 senders.clear();
593 receivers.clear();
594 }
595 std::vector<DataSenderInfo> senders;
596 std::vector<DataReceiverInfo> receivers;
597};
598
deadbeef13871492015-12-09 12:37:51 -0800599struct RtcpParameters {
600 bool reduced_size = false;
601};
602
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700603template <class Codec>
604struct RtpParameters {
Steve Anton003930a2018-03-29 12:37:21 -0700605 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700606
607 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700608 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700609 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800610 RtcpParameters rtcp;
Steve Anton003930a2018-03-29 12:37:21 -0700611
612 std::string ToString() const {
613 std::ostringstream ost;
614 ost << "{";
615 const char* separator = "";
616 for (const auto& entry : ToStringMap()) {
617 ost << separator << entry.first << ": " << entry.second;
618 separator = ", ";
619 }
620 ost << "}";
621 return ost.str();
622 }
623
624 protected:
625 virtual std::map<std::string, std::string> ToStringMap() const {
626 return {{"codecs", VectorToString(codecs)},
627 {"extensions", VectorToString(extensions)}};
628 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700629};
630
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700631// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
632// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700633template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700634struct RtpSendParameters : RtpParameters<Codec> {
nisse05103312016-03-16 02:22:50 -0700635 int max_bandwidth_bps = -1;
Steve Antonbb50ce52018-03-26 10:24:32 -0700636 // This is the value to be sent in the MID RTP header extension (if the header
637 // extension in included in the list of extensions).
638 std::string mid;
Steve Anton003930a2018-03-29 12:37:21 -0700639
640 protected:
641 std::map<std::string, std::string> ToStringMap() const override {
642 auto params = RtpParameters<Codec>::ToStringMap();
643 params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps);
644 params["mid"] = (mid.empty() ? "<not set>" : mid);
645 return params;
646 }
nisse05103312016-03-16 02:22:50 -0700647};
648
649struct AudioSendParameters : RtpSendParameters<AudioCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200650 AudioSendParameters();
651 ~AudioSendParameters() override;
nisse05103312016-03-16 02:22:50 -0700652 AudioOptions options;
Steve Anton003930a2018-03-29 12:37:21 -0700653
654 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200655 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700656};
657
658struct AudioRecvParameters : RtpParameters<AudioCodec> {
659};
660
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661class VoiceMediaChannel : public MediaChannel {
662 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000663 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700664 explicit VoiceMediaChannel(const MediaConfig& config)
665 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200666 ~VoiceMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200667 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
668 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700669 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800670 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700671 uint32_t ssrc,
672 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700673 // Get the receive parameters for the incoming stream identified by |ssrc|.
674 // If |ssrc| is 0, retrieve the receive parameters for the default receive
675 // stream, which is used when SSRCs are not signaled. Note that calling with
676 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
677 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700678 virtual webrtc::RtpParameters GetRtpReceiveParameters(
679 uint32_t ssrc) const = 0;
680 virtual bool SetRtpReceiveParameters(
681 uint32_t ssrc,
682 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700684 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800686 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700687 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200688 virtual bool SetAudioSend(uint32_t ssrc,
689 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700690 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800691 AudioSource* source) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700692 // Set speaker output volume of the specified ssrc.
693 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800695 virtual bool CanInsertDtmf() = 0;
696 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000698 // The valid value for the |event| are 0 to 15 which corresponding to
699 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800700 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 // Gets quality stats for the channel.
702 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100703
704 virtual void SetRawAudioSink(
705 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800706 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700707
708 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709};
710
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700711// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
712// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700713struct VideoSendParameters : RtpSendParameters<VideoCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200714 VideoSendParameters();
715 ~VideoSendParameters() override;
nisse4b4dc862016-02-17 05:25:36 -0800716 // Use conference mode? This flag comes from the remote
717 // description's SDP line 'a=x-google-flag:conference', copied over
718 // by VideoChannel::SetRemoteContent_w, and ultimately used by
719 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700720 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800721 // The special screencast behaviour is disabled by default.
722 bool conference_mode = false;
Steve Anton003930a2018-03-29 12:37:21 -0700723
724 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200725 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700726};
727
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700728// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
729// encapsulate all the parameters needed for a video RtpReceiver.
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700730struct VideoRecvParameters : RtpParameters<VideoCodec> {
731};
732
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733class VideoMediaChannel : public MediaChannel {
734 public:
nisse08582ff2016-02-04 01:24:52 -0800735 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700736 explicit VideoMediaChannel(const MediaConfig& config)
737 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200738 ~VideoMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200739
740 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
741 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700742 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800743 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700744 uint32_t ssrc,
745 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700746 // Get the receive parameters for the incoming stream identified by |ssrc|.
747 // If |ssrc| is 0, retrieve the receive parameters for the default receive
748 // stream, which is used when SSRCs are not signaled. Note that calling with
749 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
750 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700751 virtual webrtc::RtpParameters GetRtpReceiveParameters(
752 uint32_t ssrc) const = 0;
753 virtual bool SetRtpReceiveParameters(
754 uint32_t ssrc,
755 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 // Gets the currently set codecs/payload types to be used for outgoing media.
757 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 // Starts or stops transmission (and potentially capture) of local video.
759 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700760 // Configure stream for sending and register a source.
761 // The |ssrc| must correspond to a registered send stream.
762 virtual bool SetVideoSend(
763 uint32_t ssrc,
deadbeef5a4a75a2016-06-02 16:23:38 -0700764 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800765 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800766 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -0700767 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800768 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800769 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700770 // This fills the "bitrate parts" (rtx, video bitrate) of the
771 // BandwidthEstimationInfo, since that part that isn't possible to get
772 // through webrtc::Call::GetStats, as they are statistics of the send
773 // streams.
774 // TODO(holmer): We should change this so that either BWE graphs doesn't
775 // need access to bitrates of the streams, or change the (RTC)StatsCollector
776 // so that it's getting the send stream stats separately by calling
777 // GetStats(), and merges with BandwidthEstimationInfo by itself.
778 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000780 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781};
782
783enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000784 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
785 // values.
786 DMT_NONE = 0,
787 DMT_CONTROL = 1,
788 DMT_BINARY = 2,
789 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790};
791
792// Info about data received in DataMediaChannel. For use in
793// DataMediaChannel::SignalDataReceived and in all of the signals that
794// signal fires, on up the chain.
795struct ReceiveDataParams {
796 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800797 // RTP data channels use SSRCs, SCTP data channels use SIDs.
798 union {
799 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800800 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800801 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800803 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800805 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800807 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808};
809
810struct SendDataParams {
811 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800812 // RTP data channels use SSRCs, SCTP data channels use SIDs.
813 union {
814 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800815 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800816 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800818 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819
Steve Anton002f9212018-01-09 16:38:15 -0800820 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 // For SCTP, whether to send messages flagged as ordered or not.
822 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800823 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 // For SCTP, whether the messages are sent reliably or not.
825 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800826 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 // For SCTP, if reliable == false, provide partial reliability by
828 // resending up to this many times. Either count or millis
829 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800830 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 // For SCTP, if reliable == false, provide partial reliability by
832 // resending for up to this many milliseconds. Either count or millis
833 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800834 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835};
836
837enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
838
nisse05103312016-03-16 02:22:50 -0700839struct DataSendParameters : RtpSendParameters<DataCodec> {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700840};
841
842struct DataRecvParameters : RtpParameters<DataCodec> {
843};
844
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845class DataMediaChannel : public MediaChannel {
846 public:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200847 DataMediaChannel();
848 explicit DataMediaChannel(const MediaConfig& config);
849 ~DataMediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200851 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
852 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000853
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 // TODO(pthatcher): Implement this.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200855 virtual bool GetStats(DataMediaInfo* info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856
857 virtual bool SetSend(bool send) = 0;
858 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859
Paulina Hensman11b34f42018-04-09 14:24:52 +0200860 void OnNetworkRouteChanged(const std::string& transport_name,
861 const rtc::NetworkRoute& network_route) override {}
Honghai Zhangcc411c02016-03-29 17:27:21 -0700862
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 virtual bool SendData(
864 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700865 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 SendDataResult* result = NULL) = 0;
867 // Signals when data is received (params, data, len)
868 sigslot::signal3<const ReceiveDataParams&,
869 const char*,
870 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000871 // Signal when the media channel is ready to send the stream. Arguments are:
872 // writable(bool)
873 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874};
875
876} // namespace cricket
877
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200878#endif // MEDIA_BASE_MEDIACHANNEL_H_