blob: ff3368cf401d5f78af0779c547cf0b2ed7cb282e [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"
Benjamin Wrightbfd412e2018-09-10 14:06:02 -070023#include "api/crypto/framedecryptorinterface.h"
24#include "api/crypto/frameencryptorinterface.h"
Zach Steinba37b4b2018-01-23 15:02:36 -080025#include "api/rtcerror.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "api/rtpparameters.h"
27#include "api/rtpreceiverinterface.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010028#include "api/video/video_content_type.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020029#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020030#include "api/video/video_source_interface.h"
31#include "api/video/video_timing.h"
32#include "api/video_codecs/video_encoder_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "media/base/codec.h"
Niels Möller6daa2782018-01-23 10:37:42 +010034#include "media/base/mediaconfig.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020035#include "media/base/mediaconstants.h"
36#include "media/base/streamparams.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010037#include "modules/audio_processing/include/audio_processing_statistics.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010038#include "rtc_base/asyncpacketsocket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020039#include "rtc_base/buffer.h"
40#include "rtc_base/copyonwritebuffer.h"
41#include "rtc_base/dscp.h"
42#include "rtc_base/logging.h"
43#include "rtc_base/networkroute.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020044#include "rtc_base/socket.h"
Niels Möller9a44f962017-12-08 15:57:38 +010045#include "rtc_base/stringencode.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020046#include "rtc_base/strings/string_builder.h"
Artem Titove41c4332018-07-25 15:04:28 +020047#include "rtc_base/third_party/sigslot/sigslot.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010048
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000049namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050class Timing;
51}
52
Tommif888bb52015-12-12 01:37:01 +010053namespace webrtc {
54class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080055class VideoFrame;
Yves Gerey665174f2018-06-19 15:03:05 +020056} // namespace webrtc
Tommif888bb52015-12-12 01:37:01 +010057
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058namespace cricket {
59
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080060class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080062struct RtpHeader;
63struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065const int kScreencastDefaultFps = 5;
66
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067template <class T>
Danil Chapovalov00c71832018-06-15 15:58:38 +020068static std::string ToStringIfSet(const char* key,
69 const absl::optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070071 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072 str = key;
73 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070074 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075 str += ", ";
76 }
77 return str;
78}
79
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070080template <class T>
81static std::string VectorToString(const std::vector<T>& vals) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020082 rtc::StringBuilder ost; // no-presubmit-check TODO(webrtc:8982)
Yves Gerey665174f2018-06-19 15:03:05 +020083 ost << "[";
84 for (size_t i = 0; i < vals.size(); ++i) {
85 if (i > 0) {
86 ost << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070087 }
Yves Gerey665174f2018-06-19 15:03:05 +020088 ost << vals[i].ToString();
89 }
90 ost << "]";
Jonas Olsson84df1c72018-09-14 16:59:32 +020091 return ost.Release();
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070092}
93
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
95// Used to be flags, but that makes it hard to selectively apply options.
96// We are moving all of the setting of options to structs like this,
97// but some things currently still use flags.
98struct VideoOptions {
Paulina Hensman11b34f42018-04-09 14:24:52 +020099 VideoOptions();
100 ~VideoOptions();
101
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700103 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800104 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100105 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106 }
107
108 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800109 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100110 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
111 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112 }
deadbeef119760a2016-04-04 11:43:27 -0700113 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114
115 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200116 rtc::StringBuilder ost;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800119 ost << ToStringIfSet("screencast min bitrate kbps",
120 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100121 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200123 return ost.Release();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124 }
125
nisseb163c3f2016-01-29 01:14:38 -0800126 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700127 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800128 // on to the codec options. Disabled by default.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200129 absl::optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800130 // Force screencast to use a minimum bitrate. This flag comes from
131 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700132 // copied to the encoder config by WebRtcVideoChannel.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200133 absl::optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100134 // Set by screencast sources. Implies selection of encoding settings
135 // suitable for screencast. Most likely not the right way to do
136 // things, e.g., screencast of a text document and screencast of a
137 // youtube video have different needs.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200138 absl::optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700139
140 private:
141 template <typename T>
Danil Chapovalov00c71832018-06-15 15:58:38 +0200142 static void SetFrom(absl::optional<T>* s, const absl::optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700143 if (o) {
144 *s = o;
145 }
146 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147};
148
isheriffa1c548b2016-05-31 16:12:24 -0700149// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
150struct RtpHeaderExtension {
151 RtpHeaderExtension() : id(0) {}
152 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
153
154 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200155 rtc::StringBuilder ost;
isheriffa1c548b2016-05-31 16:12:24 -0700156 ost << "{";
157 ost << "uri: " << uri;
158 ost << ", id: " << id;
159 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200160 return ost.Release();
isheriffa1c548b2016-05-31 16:12:24 -0700161 }
162
163 std::string uri;
164 int id;
165};
166
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167class MediaChannel : public sigslot::has_slots<> {
168 public:
169 class NetworkInterface {
170 public:
171 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700172 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700173 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700174 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700175 const rtc::PacketOptions& options) = 0;
Yves Gerey665174f2018-06-19 15:03:05 +0200176 virtual int SetOption(SocketType type,
177 rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 int option) = 0;
179 virtual ~NetworkInterface() {}
180 };
181
Benjamin Wright84583f62018-10-04 14:22:34 -0700182 explicit MediaChannel(const MediaConfig& config);
183 MediaChannel();
184 ~MediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000186 // Sets the abstract interface class for sending RTP/RTCP data.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200187 virtual void SetInterface(NetworkInterface* iface);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700189 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000190 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700192 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000193 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 // Called when the socket's ability to send has changed.
195 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700196 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700197 virtual void OnNetworkRouteChanged(
198 const std::string& transport_name,
199 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 // Creates a new outgoing media stream with SSRCs and CNAME as described
201 // by sp.
202 virtual bool AddSendStream(const StreamParams& sp) = 0;
203 // Removes an outgoing media stream.
Seth Hampson5897a6e2018-04-03 11:16:33 -0700204 // SSRC must be the first SSRC of the media stream if the stream uses
205 // multiple SSRCs. In the case of an ssrc of 0, the possibly cached
206 // StreamParams is removed.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200207 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700208 // Creates a new incoming media stream with SSRCs, CNAME as described
209 // by sp. In the case of a sp without SSRCs, the unsignaled sp is cached
210 // to be used later for unsignaled streams received.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 virtual bool AddRecvStream(const StreamParams& sp) = 0;
212 // Removes an incoming media stream.
213 // ssrc must be the first SSRC of the media stream if the stream uses
214 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200215 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
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;
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700218 // Set the frame encryptor to use on all outgoing frames. This is optional.
219 // This pointers lifetime is managed by the set of RtpSender it is attached
220 // to.
Benjamin Wright84583f62018-10-04 14:22:34 -0700221 // TODO(benwright) make pure virtual once internal supports it.
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700222 virtual void SetFrameEncryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700223 uint32_t ssrc,
224 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor);
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700225 // Set the frame decryptor to use on all incoming frames. This is optional.
226 // This pointers lifetimes is managed by the set of RtpReceivers it is
227 // attached to.
Benjamin Wright84583f62018-10-04 14:22:34 -0700228 // TODO(benwright) make pure virtual once internal supports it.
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700229 virtual void SetFrameDecryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700230 uint32_t ssrc,
231 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000233 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700234 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
235 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700236 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000237 }
238
jbaucheec21bd2016-03-20 06:15:43 -0700239 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
240 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700241 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000242 }
243
244 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000245 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000246 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000247 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000248 if (!network_interface_)
249 return -1;
250
251 return network_interface_->SetOption(type, opt, option);
252 }
253
Tim Haloun6ca98362018-09-17 17:06:08 -0700254 protected:
255 virtual rtc::DiffServCodePoint PreferredDscp() const;
256
257 bool DscpEnabled() const { return enable_dscp_; }
258
nisse51542be2016-02-12 02:27:06 -0800259 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000260 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000261 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000262 int ret;
Yves Gerey665174f2018-06-19 15:03:05 +0200263 ret = SetOption(NetworkInterface::ST_RTP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000264 if (ret == 0) {
Yves Gerey665174f2018-06-19 15:03:05 +0200265 ret = SetOption(NetworkInterface::ST_RTCP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000266 }
267 return ret;
268 }
269
jbaucheec21bd2016-03-20 06:15:43 -0700270 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700271 bool rtcp,
272 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000273 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000274 if (!network_interface_)
275 return false;
276
stefanc1aeaf02015-10-15 07:26:07 -0700277 return (!rtcp) ? network_interface_->SendPacket(packet, options)
278 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000279 }
280
nisse51542be2016-02-12 02:27:06 -0800281 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000282 // |network_interface_| can be accessed from the worker_thread and
283 // from any MediaEngine threads. This critical section is to protect accessing
284 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000285 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000286 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287};
288
wu@webrtc.org97077a32013-10-25 21:18:33 +0000289// The stats information is structured as follows:
290// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
291// Media contains a vector of SSRC infos that are exclusively used by this
292// media. (SSRCs shared between media streams can't be represented.)
293
294// Information about an SSRC.
295// This data may be locally recorded, or received in an RTCP SR or RR.
296struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800297 uint32_t ssrc = 0;
298 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000299};
300
301struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800302 uint32_t ssrc = 0;
303 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000304};
305
306struct MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200307 MediaSenderInfo();
308 ~MediaSenderInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200309 void add_ssrc(const SsrcSenderInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000310 // Temporary utility function for call sites that only provide SSRC.
311 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200312 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000313 SsrcSenderInfo stat;
314 stat.ssrc = ssrc;
315 add_ssrc(stat);
316 }
317 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200318 std::vector<uint32_t> ssrcs() const {
319 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000320 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
321 it != local_stats.end(); ++it) {
322 retval.push_back(it->ssrc);
323 }
324 return retval;
325 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100326 // Returns true if the media has been connected.
327 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000328 // Utility accessor for clients that make the assumption only one ssrc
329 // exists per media.
330 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100331 // Call sites that compare this to zero should use connected() instead.
332 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200333 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100334 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000335 return local_stats[0].ssrc;
336 } else {
337 return 0;
338 }
339 }
Steve Anton002f9212018-01-09 16:38:15 -0800340 int64_t bytes_sent = 0;
341 int packets_sent = 0;
342 int packets_lost = 0;
343 float fraction_lost = 0.0f;
344 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000345 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200346 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000347 std::vector<SsrcSenderInfo> local_stats;
348 std::vector<SsrcReceiverInfo> remote_stats;
349};
350
351struct MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200352 MediaReceiverInfo();
353 ~MediaReceiverInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200354 void add_ssrc(const SsrcReceiverInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000355 // Temporary utility function for call sites that only provide SSRC.
356 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200357 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000358 SsrcReceiverInfo stat;
359 stat.ssrc = ssrc;
360 add_ssrc(stat);
361 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200362 std::vector<uint32_t> ssrcs() const {
363 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000364 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
365 it != local_stats.end(); ++it) {
366 retval.push_back(it->ssrc);
367 }
368 return retval;
369 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100370 // Returns true if the media has been connected.
371 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000372 // Utility accessor for clients that make the assumption only one ssrc
373 // exists per media.
374 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100375 // Call sites that compare this to zero should use connected();
376 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200377 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100378 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000379 return local_stats[0].ssrc;
380 } else {
381 return 0;
382 }
383 }
384
Steve Anton002f9212018-01-09 16:38:15 -0800385 int64_t bytes_rcvd = 0;
386 int packets_rcvd = 0;
387 int packets_lost = 0;
388 float fraction_lost = 0.0f;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000389 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200390 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000391 std::vector<SsrcReceiverInfo> local_stats;
392 std::vector<SsrcSenderInfo> remote_stats;
393};
394
395struct VoiceSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200396 VoiceSenderInfo();
397 ~VoiceSenderInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800398 int ext_seqnum = 0;
399 int jitter_ms = 0;
400 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700401 // See description of "totalAudioEnergy" in the WebRTC stats spec:
402 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800403 double total_input_energy = 0.0;
404 double total_input_duration = 0.0;
Ivo Creusen56d46092017-11-24 17:29:59 +0100405 // TODO(bugs.webrtc.org/8572): Remove APM stats from this struct, since they
406 // are no longer needed now that we have apm_statistics.
Steve Anton002f9212018-01-09 16:38:15 -0800407 int echo_delay_median_ms = 0;
408 int echo_delay_std_ms = 0;
409 int echo_return_loss = 0;
410 int echo_return_loss_enhancement = 0;
411 float residual_echo_likelihood = 0.0f;
412 float residual_echo_likelihood_recent_max = 0.0f;
413 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700414 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100415 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416};
417
wu@webrtc.org97077a32013-10-25 21:18:33 +0000418struct VoiceReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200419 VoiceReceiverInfo();
420 ~VoiceReceiverInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800421 int ext_seqnum = 0;
422 int jitter_ms = 0;
423 int jitter_buffer_ms = 0;
424 int jitter_buffer_preferred_ms = 0;
425 int delay_estimate_ms = 0;
426 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200427 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
428 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800429 double total_output_energy = 0.0;
430 uint64_t total_samples_received = 0;
431 double total_output_duration = 0.0;
432 uint64_t concealed_samples = 0;
433 uint64_t concealment_events = 0;
434 double jitter_buffer_delay_seconds = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200435 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000436 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800437 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000438 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800439 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000440 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800441 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200442 // Fraction of secondary data, including FEC and RED, that is discarded.
443 // Discarding of secondary data can be caused by the reception of the primary
444 // data, obsoleting the secondary data. It can also be caused by early
445 // or late arrival of secondary data. This metric is the percentage of
446 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800447 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200448 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800449 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200450 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800451 float preemptive_expand_rate = 0.0f;
452 int decoding_calls_to_silence_generator = 0;
453 int decoding_calls_to_neteq = 0;
454 int decoding_normal = 0;
455 int decoding_plc = 0;
456 int decoding_cng = 0;
457 int decoding_plc_cng = 0;
458 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000459 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800460 int64_t capture_start_ntp_time_ms = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461};
462
wu@webrtc.org97077a32013-10-25 21:18:33 +0000463struct VideoSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200464 VideoSenderInfo();
465 ~VideoSenderInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000466 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800467 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100468 std::string encoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800469 int firs_rcvd = 0;
470 int plis_rcvd = 0;
471 int nacks_rcvd = 0;
472 int send_frame_width = 0;
473 int send_frame_height = 0;
474 int framerate_input = 0;
475 int framerate_sent = 0;
476 int nominal_bitrate = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800477 int adapt_reason = 0;
478 int adapt_changes = 0;
479 int avg_encode_ms = 0;
480 int encode_usage_percent = 0;
481 uint32_t frames_encoded = 0;
482 bool has_entered_low_resolution = false;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200483 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800484 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100485 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
486 uint32_t huge_frames_sent = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000487};
488
wu@webrtc.org97077a32013-10-25 21:18:33 +0000489struct VideoReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200490 VideoReceiverInfo();
491 ~VideoReceiverInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000492 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800493 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100494 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800495 int packets_concealed = 0;
496 int firs_sent = 0;
497 int plis_sent = 0;
498 int nacks_sent = 0;
499 int frame_width = 0;
500 int frame_height = 0;
501 int framerate_rcvd = 0;
502 int framerate_decoded = 0;
503 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000504 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800505 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000506 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800507 int framerate_render_output = 0;
508 uint32_t frames_received = 0;
509 uint32_t frames_decoded = 0;
510 uint32_t frames_rendered = 0;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200511 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800512 int64_t interframe_delay_max_ms = -1;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000513
Steve Anton002f9212018-01-09 16:38:15 -0800514 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700515
wu@webrtc.org97077a32013-10-25 21:18:33 +0000516 // All stats below are gathered per-VideoReceiver, but some will be correlated
517 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
518 // structures, reflect this in the new layout.
519
520 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800521 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000522 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800523 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000524 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800525 int jitter_buffer_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000526 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800527 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000528 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800529 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000530 // Target overall delay: network+decode+render, accounting for
531 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800532 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000533 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800534 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000535
536 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800537 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700538
539 // Timing frame info: all important timestamps for a full lifetime of a
540 // single 'timing frame'.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200541 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000542};
543
wu@webrtc.org97077a32013-10-25 21:18:33 +0000544struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800545 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546};
547
wu@webrtc.org97077a32013-10-25 21:18:33 +0000548struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800549 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550};
551
552struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800553 int available_send_bandwidth = 0;
554 int available_recv_bandwidth = 0;
555 int target_enc_bitrate = 0;
556 int actual_enc_bitrate = 0;
557 int retransmit_bitrate = 0;
558 int transmit_bitrate = 0;
559 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560};
561
hbosa65704b2016-11-14 02:28:16 -0800562// Maps from payload type to |RtpCodecParameters|.
563typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
564
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565struct VoiceMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200566 VoiceMediaInfo();
567 ~VoiceMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 void Clear() {
569 senders.clear();
570 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800571 send_codecs.clear();
572 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 }
574 std::vector<VoiceSenderInfo> senders;
575 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800576 RtpCodecParametersMap send_codecs;
577 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578};
579
580struct VideoMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200581 VideoMediaInfo();
582 ~VideoMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 void Clear() {
584 senders.clear();
585 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700586 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800587 send_codecs.clear();
588 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000589 }
590 std::vector<VideoSenderInfo> senders;
591 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700592 // Deprecated.
593 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700594 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800595 RtpCodecParametersMap send_codecs;
596 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597};
598
599struct DataMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200600 DataMediaInfo();
601 ~DataMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602 void Clear() {
603 senders.clear();
604 receivers.clear();
605 }
606 std::vector<DataSenderInfo> senders;
607 std::vector<DataReceiverInfo> receivers;
608};
609
deadbeef13871492015-12-09 12:37:51 -0800610struct RtcpParameters {
611 bool reduced_size = false;
612};
613
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700614template <class Codec>
615struct RtpParameters {
Steve Anton003930a2018-03-29 12:37:21 -0700616 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700617
618 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700619 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700620 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800621 RtcpParameters rtcp;
Steve Anton003930a2018-03-29 12:37:21 -0700622
623 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200624 rtc::StringBuilder ost;
Steve Anton003930a2018-03-29 12:37:21 -0700625 ost << "{";
626 const char* separator = "";
627 for (const auto& entry : ToStringMap()) {
628 ost << separator << entry.first << ": " << entry.second;
629 separator = ", ";
630 }
631 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200632 return ost.Release();
Steve Anton003930a2018-03-29 12:37:21 -0700633 }
634
635 protected:
636 virtual std::map<std::string, std::string> ToStringMap() const {
637 return {{"codecs", VectorToString(codecs)},
638 {"extensions", VectorToString(extensions)}};
639 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700640};
641
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700642// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
643// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700644template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700645struct RtpSendParameters : RtpParameters<Codec> {
nisse05103312016-03-16 02:22:50 -0700646 int max_bandwidth_bps = -1;
Steve Antonbb50ce52018-03-26 10:24:32 -0700647 // This is the value to be sent in the MID RTP header extension (if the header
648 // extension in included in the list of extensions).
649 std::string mid;
Steve Anton003930a2018-03-29 12:37:21 -0700650
651 protected:
652 std::map<std::string, std::string> ToStringMap() const override {
653 auto params = RtpParameters<Codec>::ToStringMap();
654 params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps);
655 params["mid"] = (mid.empty() ? "<not set>" : mid);
656 return params;
657 }
nisse05103312016-03-16 02:22:50 -0700658};
659
660struct AudioSendParameters : RtpSendParameters<AudioCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200661 AudioSendParameters();
662 ~AudioSendParameters() override;
nisse05103312016-03-16 02:22:50 -0700663 AudioOptions options;
Steve Anton003930a2018-03-29 12:37:21 -0700664
665 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200666 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700667};
668
Yves Gerey665174f2018-06-19 15:03:05 +0200669struct AudioRecvParameters : RtpParameters<AudioCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700670
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671class VoiceMediaChannel : public MediaChannel {
672 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700674 explicit VoiceMediaChannel(const MediaConfig& config)
675 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200676 ~VoiceMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200677 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
678 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700679 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800680 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700681 uint32_t ssrc,
682 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700683 // Get the receive parameters for the incoming stream identified by |ssrc|.
684 // If |ssrc| is 0, retrieve the receive parameters for the default receive
685 // stream, which is used when SSRCs are not signaled. Note that calling with
686 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
687 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700688 virtual webrtc::RtpParameters GetRtpReceiveParameters(
689 uint32_t ssrc) const = 0;
690 virtual bool SetRtpReceiveParameters(
691 uint32_t ssrc,
692 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700694 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800696 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700697 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200698 virtual bool SetAudioSend(uint32_t ssrc,
699 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700700 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800701 AudioSource* source) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700702 // Set speaker output volume of the specified ssrc.
703 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800705 virtual bool CanInsertDtmf() = 0;
706 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000708 // The valid value for the |event| are 0 to 15 which corresponding to
709 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800710 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 // Gets quality stats for the channel.
712 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100713
714 virtual void SetRawAudioSink(
715 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800716 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700717
718 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719};
720
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700721// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
722// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700723struct VideoSendParameters : RtpSendParameters<VideoCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200724 VideoSendParameters();
725 ~VideoSendParameters() override;
nisse4b4dc862016-02-17 05:25:36 -0800726 // Use conference mode? This flag comes from the remote
727 // description's SDP line 'a=x-google-flag:conference', copied over
728 // by VideoChannel::SetRemoteContent_w, and ultimately used by
729 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700730 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800731 // The special screencast behaviour is disabled by default.
732 bool conference_mode = false;
Steve Anton003930a2018-03-29 12:37:21 -0700733
734 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200735 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700736};
737
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700738// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
739// encapsulate all the parameters needed for a video RtpReceiver.
Yves Gerey665174f2018-06-19 15:03:05 +0200740struct VideoRecvParameters : RtpParameters<VideoCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700741
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742class VideoMediaChannel : public MediaChannel {
743 public:
nisse08582ff2016-02-04 01:24:52 -0800744 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700745 explicit VideoMediaChannel(const MediaConfig& config)
746 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200747 ~VideoMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200748
749 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
750 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700751 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800752 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700753 uint32_t ssrc,
754 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700755 // Get the receive parameters for the incoming stream identified by |ssrc|.
756 // If |ssrc| is 0, retrieve the receive parameters for the default receive
757 // stream, which is used when SSRCs are not signaled. Note that calling with
758 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
759 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700760 virtual webrtc::RtpParameters GetRtpReceiveParameters(
761 uint32_t ssrc) const = 0;
762 virtual bool SetRtpReceiveParameters(
763 uint32_t ssrc,
764 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765 // Gets the currently set codecs/payload types to be used for outgoing media.
766 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767 // Starts or stops transmission (and potentially capture) of local video.
768 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700769 // Configure stream for sending and register a source.
770 // The |ssrc| must correspond to a registered send stream.
771 virtual bool SetVideoSend(
772 uint32_t ssrc,
deadbeef5a4a75a2016-06-02 16:23:38 -0700773 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800774 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800775 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -0700776 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800777 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800778 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700779 // This fills the "bitrate parts" (rtx, video bitrate) of the
780 // BandwidthEstimationInfo, since that part that isn't possible to get
781 // through webrtc::Call::GetStats, as they are statistics of the send
782 // streams.
783 // TODO(holmer): We should change this so that either BWE graphs doesn't
784 // need access to bitrates of the streams, or change the (RTC)StatsCollector
785 // so that it's getting the send stream stats separately by calling
786 // GetStats(), and merges with BandwidthEstimationInfo by itself.
787 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000789 virtual bool GetStats(VideoMediaInfo* info) = 0;
Jonas Oreland49ac5952018-09-26 16:04:32 +0200790
791 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792};
793
794enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000795 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
796 // values.
797 DMT_NONE = 0,
798 DMT_CONTROL = 1,
799 DMT_BINARY = 2,
800 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801};
802
803// Info about data received in DataMediaChannel. For use in
804// DataMediaChannel::SignalDataReceived and in all of the signals that
805// signal fires, on up the chain.
806struct ReceiveDataParams {
807 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800808 // RTP data channels use SSRCs, SCTP data channels use SIDs.
809 union {
810 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800811 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800812 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800814 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800816 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800818 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819};
820
821struct SendDataParams {
822 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800823 // RTP data channels use SSRCs, SCTP data channels use SIDs.
824 union {
825 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800826 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800827 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800829 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830
Steve Anton002f9212018-01-09 16:38:15 -0800831 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 // For SCTP, whether to send messages flagged as ordered or not.
833 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800834 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 // For SCTP, whether the messages are sent reliably or not.
836 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800837 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 // For SCTP, if reliable == false, provide partial reliability by
839 // resending up to this many times. Either count or millis
840 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800841 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 // For SCTP, if reliable == false, provide partial reliability by
843 // resending for up to this many milliseconds. Either count or millis
844 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800845 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846};
847
848enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
849
Yves Gerey665174f2018-06-19 15:03:05 +0200850struct DataSendParameters : RtpSendParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700851
Yves Gerey665174f2018-06-19 15:03:05 +0200852struct DataRecvParameters : RtpParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700853
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854class DataMediaChannel : public MediaChannel {
855 public:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200856 DataMediaChannel();
857 explicit DataMediaChannel(const MediaConfig& config);
858 ~DataMediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200860 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
861 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000862
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 // TODO(pthatcher): Implement this.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200864 virtual bool GetStats(DataMediaInfo* info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865
866 virtual bool SetSend(bool send) = 0;
867 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868
Paulina Hensman11b34f42018-04-09 14:24:52 +0200869 void OnNetworkRouteChanged(const std::string& transport_name,
870 const rtc::NetworkRoute& network_route) override {}
Honghai Zhangcc411c02016-03-29 17:27:21 -0700871
Yves Gerey665174f2018-06-19 15:03:05 +0200872 virtual bool SendData(const SendDataParams& params,
873 const rtc::CopyOnWriteBuffer& payload,
874 SendDataResult* result = NULL) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 // Signals when data is received (params, data, len)
Yves Gerey665174f2018-06-19 15:03:05 +0200876 sigslot::signal3<const ReceiveDataParams&, const char*, size_t>
877 SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000878 // Signal when the media channel is ready to send the stream. Arguments are:
879 // writable(bool)
880 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881};
882
883} // namespace cricket
884
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200885#endif // MEDIA_BASE_MEDIACHANNEL_H_