blob: 56edab72f29dfd43e08437692c3a208481eb28a5 [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"
Anton Sukhanov98a462c2018-10-17 13:15:42 -070025#include "api/media_transport_interface.h"
Zach Steinba37b4b2018-01-23 15:02:36 -080026#include "api/rtcerror.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "api/rtpparameters.h"
28#include "api/rtpreceiverinterface.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010029#include "api/video/video_content_type.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020030#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020031#include "api/video/video_source_interface.h"
32#include "api/video/video_timing.h"
33#include "api/video_codecs/video_encoder_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020034#include "media/base/codec.h"
Niels Möller6daa2782018-01-23 10:37:42 +010035#include "media/base/mediaconfig.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#include "media/base/mediaconstants.h"
37#include "media/base/streamparams.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010038#include "modules/audio_processing/include/audio_processing_statistics.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010039#include "rtc_base/asyncpacketsocket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020040#include "rtc_base/buffer.h"
41#include "rtc_base/copyonwritebuffer.h"
42#include "rtc_base/dscp.h"
43#include "rtc_base/logging.h"
44#include "rtc_base/networkroute.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020045#include "rtc_base/socket.h"
Niels Möller9a44f962017-12-08 15:57:38 +010046#include "rtc_base/stringencode.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020047#include "rtc_base/strings/string_builder.h"
Artem Titove41c4332018-07-25 15:04:28 +020048#include "rtc_base/third_party/sigslot/sigslot.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010049
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000050namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051class Timing;
52}
53
Tommif888bb52015-12-12 01:37:01 +010054namespace webrtc {
55class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080056class VideoFrame;
Yves Gerey665174f2018-06-19 15:03:05 +020057} // namespace webrtc
Tommif888bb52015-12-12 01:37:01 +010058
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059namespace cricket {
60
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080061class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080063struct RtpHeader;
64struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066const int kScreencastDefaultFps = 5;
67
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068template <class T>
Danil Chapovalov00c71832018-06-15 15:58:38 +020069static std::string ToStringIfSet(const char* key,
70 const absl::optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070072 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 str = key;
74 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070075 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076 str += ", ";
77 }
78 return str;
79}
80
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070081template <class T>
82static std::string VectorToString(const std::vector<T>& vals) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020083 rtc::StringBuilder ost; // no-presubmit-check TODO(webrtc:8982)
Yves Gerey665174f2018-06-19 15:03:05 +020084 ost << "[";
85 for (size_t i = 0; i < vals.size(); ++i) {
86 if (i > 0) {
87 ost << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070088 }
Yves Gerey665174f2018-06-19 15:03:05 +020089 ost << vals[i].ToString();
90 }
91 ost << "]";
Jonas Olsson84df1c72018-09-14 16:59:32 +020092 return ost.Release();
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070093}
94
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
96// Used to be flags, but that makes it hard to selectively apply options.
97// We are moving all of the setting of options to structs like this,
98// but some things currently still use flags.
99struct VideoOptions {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200100 VideoOptions();
101 ~VideoOptions();
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700104 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800105 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100106 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 }
108
109 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800110 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100111 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
112 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113 }
deadbeef119760a2016-04-04 11:43:27 -0700114 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115
116 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200117 rtc::StringBuilder ost;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800120 ost << ToStringIfSet("screencast min bitrate kbps",
121 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100122 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200124 return ost.Release();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 }
126
nisseb163c3f2016-01-29 01:14:38 -0800127 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700128 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800129 // on to the codec options. Disabled by default.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200130 absl::optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800131 // Force screencast to use a minimum bitrate. This flag comes from
132 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700133 // copied to the encoder config by WebRtcVideoChannel.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200134 absl::optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100135 // Set by screencast sources. Implies selection of encoding settings
136 // suitable for screencast. Most likely not the right way to do
137 // things, e.g., screencast of a text document and screencast of a
138 // youtube video have different needs.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200139 absl::optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700140
141 private:
142 template <typename T>
Danil Chapovalov00c71832018-06-15 15:58:38 +0200143 static void SetFrom(absl::optional<T>* s, const absl::optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700144 if (o) {
145 *s = o;
146 }
147 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148};
149
isheriffa1c548b2016-05-31 16:12:24 -0700150// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
151struct RtpHeaderExtension {
152 RtpHeaderExtension() : id(0) {}
153 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
154
155 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200156 rtc::StringBuilder ost;
isheriffa1c548b2016-05-31 16:12:24 -0700157 ost << "{";
158 ost << "uri: " << uri;
159 ost << ", id: " << id;
160 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200161 return ost.Release();
isheriffa1c548b2016-05-31 16:12:24 -0700162 }
163
164 std::string uri;
165 int id;
166};
167
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168class MediaChannel : public sigslot::has_slots<> {
169 public:
170 class NetworkInterface {
171 public:
172 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700173 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700174 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700175 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700176 const rtc::PacketOptions& options) = 0;
Yves Gerey665174f2018-06-19 15:03:05 +0200177 virtual int SetOption(SocketType type,
178 rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 int option) = 0;
180 virtual ~NetworkInterface() {}
181 };
182
Benjamin Wright84583f62018-10-04 14:22:34 -0700183 explicit MediaChannel(const MediaConfig& config);
184 MediaChannel();
185 ~MediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700187 // Sets the abstract interface class for sending RTP/RTCP data and
188 // interface for media transport (experimental). If media transport is
189 // provided, it should be used instead of RTP/RTCP.
190 // TODO(sukhanov): Currently media transport can co-exist with RTP/RTCP, but
191 // in the future we will refactor code to send all frames with media
192 // transport.
193 virtual void SetInterface(NetworkInterface* iface,
194 webrtc::MediaTransportInterface* media_transport);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700196 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000197 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700199 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000200 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 // Called when the socket's ability to send has changed.
202 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700203 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700204 virtual void OnNetworkRouteChanged(
205 const std::string& transport_name,
206 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 // Creates a new outgoing media stream with SSRCs and CNAME as described
208 // by sp.
209 virtual bool AddSendStream(const StreamParams& sp) = 0;
210 // Removes an outgoing media stream.
Seth Hampson5897a6e2018-04-03 11:16:33 -0700211 // SSRC must be the first SSRC of the media stream if the stream uses
212 // multiple SSRCs. In the case of an ssrc of 0, the possibly cached
213 // StreamParams is removed.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200214 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700215 // Creates a new incoming media stream with SSRCs, CNAME as described
216 // by sp. In the case of a sp without SSRCs, the unsignaled sp is cached
217 // to be used later for unsignaled streams received.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 virtual bool AddRecvStream(const StreamParams& sp) = 0;
219 // Removes an incoming media stream.
220 // ssrc must be the first SSRC of the media stream if the stream uses
221 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200222 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000223 // Returns the absoulte sendtime extension id value from media channel.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200224 virtual int GetRtpSendTimeExtnId() const;
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700225 // Set the frame encryptor to use on all outgoing frames. This is optional.
226 // This pointers lifetime is managed by the set of RtpSender it is attached
227 // 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 SetFrameEncryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700230 uint32_t ssrc,
231 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor);
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700232 // Set the frame decryptor to use on all incoming frames. This is optional.
233 // This pointers lifetimes is managed by the set of RtpReceivers it is
234 // attached to.
Benjamin Wright84583f62018-10-04 14:22:34 -0700235 // TODO(benwright) make pure virtual once internal supports it.
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700236 virtual void SetFrameDecryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700237 uint32_t ssrc,
238 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000240 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700241 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
242 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700243 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000244 }
245
jbaucheec21bd2016-03-20 06:15:43 -0700246 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
247 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700248 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000249 }
250
251 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000252 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000253 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000254 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000255 if (!network_interface_)
256 return -1;
257
258 return network_interface_->SetOption(type, opt, option);
259 }
260
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700261 webrtc::MediaTransportInterface* media_transport() {
262 return media_transport_;
263 }
264
Tim Haloun6ca98362018-09-17 17:06:08 -0700265 protected:
266 virtual rtc::DiffServCodePoint PreferredDscp() const;
267
268 bool DscpEnabled() const { return enable_dscp_; }
269
wu@webrtc.orgde305012013-10-31 15:40:38 +0000270 // This method sets DSCP |value| on both RTP and RTCP channels.
Tim Haloun648d28a2018-10-18 16:52:22 -0700271 int UpdateDscp() {
272 rtc::DiffServCodePoint value =
273 enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000274 int ret;
Yves Gerey665174f2018-06-19 15:03:05 +0200275 ret = SetOption(NetworkInterface::ST_RTP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000276 if (ret == 0) {
Yves Gerey665174f2018-06-19 15:03:05 +0200277 ret = SetOption(NetworkInterface::ST_RTCP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000278 }
279 return ret;
280 }
281
Tim Haloun648d28a2018-10-18 16:52:22 -0700282 private:
jbaucheec21bd2016-03-20 06:15:43 -0700283 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700284 bool rtcp,
285 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000286 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000287 if (!network_interface_)
288 return false;
289
stefanc1aeaf02015-10-15 07:26:07 -0700290 return (!rtcp) ? network_interface_->SendPacket(packet, options)
291 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000292 }
293
nisse51542be2016-02-12 02:27:06 -0800294 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000295 // |network_interface_| can be accessed from the worker_thread and
296 // from any MediaEngine threads. This critical section is to protect accessing
297 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000298 rtc::CriticalSection network_interface_crit_;
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700299 NetworkInterface* network_interface_ = nullptr;
300 webrtc::MediaTransportInterface* media_transport_ = nullptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301};
302
wu@webrtc.org97077a32013-10-25 21:18:33 +0000303// The stats information is structured as follows:
304// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
305// Media contains a vector of SSRC infos that are exclusively used by this
306// media. (SSRCs shared between media streams can't be represented.)
307
308// Information about an SSRC.
309// This data may be locally recorded, or received in an RTCP SR or RR.
310struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800311 uint32_t ssrc = 0;
312 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000313};
314
315struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800316 uint32_t ssrc = 0;
317 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000318};
319
320struct MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200321 MediaSenderInfo();
322 ~MediaSenderInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200323 void add_ssrc(const SsrcSenderInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000324 // Temporary utility function for call sites that only provide SSRC.
325 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200326 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000327 SsrcSenderInfo stat;
328 stat.ssrc = ssrc;
329 add_ssrc(stat);
330 }
331 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200332 std::vector<uint32_t> ssrcs() const {
333 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000334 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
335 it != local_stats.end(); ++it) {
336 retval.push_back(it->ssrc);
337 }
338 return retval;
339 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100340 // Returns true if the media has been connected.
341 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000342 // Utility accessor for clients that make the assumption only one ssrc
343 // exists per media.
344 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100345 // Call sites that compare this to zero should use connected() instead.
346 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200347 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100348 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000349 return local_stats[0].ssrc;
350 } else {
351 return 0;
352 }
353 }
Steve Anton002f9212018-01-09 16:38:15 -0800354 int64_t bytes_sent = 0;
355 int packets_sent = 0;
356 int packets_lost = 0;
357 float fraction_lost = 0.0f;
358 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000359 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200360 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000361 std::vector<SsrcSenderInfo> local_stats;
362 std::vector<SsrcReceiverInfo> remote_stats;
363};
364
365struct MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200366 MediaReceiverInfo();
367 ~MediaReceiverInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200368 void add_ssrc(const SsrcReceiverInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000369 // Temporary utility function for call sites that only provide SSRC.
370 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200371 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000372 SsrcReceiverInfo stat;
373 stat.ssrc = ssrc;
374 add_ssrc(stat);
375 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200376 std::vector<uint32_t> ssrcs() const {
377 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000378 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
379 it != local_stats.end(); ++it) {
380 retval.push_back(it->ssrc);
381 }
382 return retval;
383 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100384 // Returns true if the media has been connected.
385 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000386 // Utility accessor for clients that make the assumption only one ssrc
387 // exists per media.
388 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100389 // Call sites that compare this to zero should use connected();
390 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200391 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100392 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000393 return local_stats[0].ssrc;
394 } else {
395 return 0;
396 }
397 }
398
Steve Anton002f9212018-01-09 16:38:15 -0800399 int64_t bytes_rcvd = 0;
400 int packets_rcvd = 0;
401 int packets_lost = 0;
402 float fraction_lost = 0.0f;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000403 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200404 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000405 std::vector<SsrcReceiverInfo> local_stats;
406 std::vector<SsrcSenderInfo> remote_stats;
407};
408
409struct VoiceSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200410 VoiceSenderInfo();
411 ~VoiceSenderInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800412 int ext_seqnum = 0;
413 int jitter_ms = 0;
414 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700415 // See description of "totalAudioEnergy" in the WebRTC stats spec:
416 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800417 double total_input_energy = 0.0;
418 double total_input_duration = 0.0;
Ivo Creusen56d46092017-11-24 17:29:59 +0100419 // TODO(bugs.webrtc.org/8572): Remove APM stats from this struct, since they
420 // are no longer needed now that we have apm_statistics.
Steve Anton002f9212018-01-09 16:38:15 -0800421 int echo_delay_median_ms = 0;
422 int echo_delay_std_ms = 0;
423 int echo_return_loss = 0;
424 int echo_return_loss_enhancement = 0;
425 float residual_echo_likelihood = 0.0f;
426 float residual_echo_likelihood_recent_max = 0.0f;
427 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700428 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100429 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430};
431
wu@webrtc.org97077a32013-10-25 21:18:33 +0000432struct VoiceReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200433 VoiceReceiverInfo();
434 ~VoiceReceiverInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800435 int ext_seqnum = 0;
436 int jitter_ms = 0;
437 int jitter_buffer_ms = 0;
438 int jitter_buffer_preferred_ms = 0;
439 int delay_estimate_ms = 0;
440 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200441 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
442 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800443 double total_output_energy = 0.0;
444 uint64_t total_samples_received = 0;
445 double total_output_duration = 0.0;
446 uint64_t concealed_samples = 0;
447 uint64_t concealment_events = 0;
448 double jitter_buffer_delay_seconds = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200449 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000450 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800451 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000452 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800453 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000454 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800455 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200456 // Fraction of secondary data, including FEC and RED, that is discarded.
457 // Discarding of secondary data can be caused by the reception of the primary
458 // data, obsoleting the secondary data. It can also be caused by early
459 // or late arrival of secondary data. This metric is the percentage of
460 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800461 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200462 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800463 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200464 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800465 float preemptive_expand_rate = 0.0f;
466 int decoding_calls_to_silence_generator = 0;
467 int decoding_calls_to_neteq = 0;
468 int decoding_normal = 0;
469 int decoding_plc = 0;
470 int decoding_cng = 0;
471 int decoding_plc_cng = 0;
472 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000473 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800474 int64_t capture_start_ntp_time_ms = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475};
476
wu@webrtc.org97077a32013-10-25 21:18:33 +0000477struct VideoSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200478 VideoSenderInfo();
479 ~VideoSenderInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000480 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800481 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100482 std::string encoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800483 int firs_rcvd = 0;
484 int plis_rcvd = 0;
485 int nacks_rcvd = 0;
486 int send_frame_width = 0;
487 int send_frame_height = 0;
488 int framerate_input = 0;
489 int framerate_sent = 0;
490 int nominal_bitrate = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800491 int adapt_reason = 0;
492 int adapt_changes = 0;
493 int avg_encode_ms = 0;
494 int encode_usage_percent = 0;
495 uint32_t frames_encoded = 0;
496 bool has_entered_low_resolution = false;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200497 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800498 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100499 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
500 uint32_t huge_frames_sent = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501};
502
wu@webrtc.org97077a32013-10-25 21:18:33 +0000503struct VideoReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200504 VideoReceiverInfo();
505 ~VideoReceiverInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000506 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800507 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100508 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800509 int packets_concealed = 0;
510 int firs_sent = 0;
511 int plis_sent = 0;
512 int nacks_sent = 0;
513 int frame_width = 0;
514 int frame_height = 0;
515 int framerate_rcvd = 0;
516 int framerate_decoded = 0;
517 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000518 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800519 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000520 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800521 int framerate_render_output = 0;
522 uint32_t frames_received = 0;
523 uint32_t frames_decoded = 0;
524 uint32_t frames_rendered = 0;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200525 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800526 int64_t interframe_delay_max_ms = -1;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000527
Steve Anton002f9212018-01-09 16:38:15 -0800528 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700529
wu@webrtc.org97077a32013-10-25 21:18:33 +0000530 // All stats below are gathered per-VideoReceiver, but some will be correlated
531 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
532 // structures, reflect this in the new layout.
533
534 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800535 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000536 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800537 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000538 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800539 int jitter_buffer_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000540 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800541 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000542 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800543 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000544 // Target overall delay: network+decode+render, accounting for
545 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800546 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000547 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800548 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000549
550 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800551 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700552
553 // Timing frame info: all important timestamps for a full lifetime of a
554 // single 'timing frame'.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200555 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556};
557
wu@webrtc.org97077a32013-10-25 21:18:33 +0000558struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800559 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560};
561
wu@webrtc.org97077a32013-10-25 21:18:33 +0000562struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800563 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564};
565
566struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800567 int available_send_bandwidth = 0;
568 int available_recv_bandwidth = 0;
569 int target_enc_bitrate = 0;
570 int actual_enc_bitrate = 0;
571 int retransmit_bitrate = 0;
572 int transmit_bitrate = 0;
573 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574};
575
hbosa65704b2016-11-14 02:28:16 -0800576// Maps from payload type to |RtpCodecParameters|.
577typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
578
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579struct VoiceMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200580 VoiceMediaInfo();
581 ~VoiceMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 void Clear() {
583 senders.clear();
584 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800585 send_codecs.clear();
586 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587 }
588 std::vector<VoiceSenderInfo> senders;
589 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800590 RtpCodecParametersMap send_codecs;
591 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592};
593
594struct VideoMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200595 VideoMediaInfo();
596 ~VideoMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597 void Clear() {
598 senders.clear();
599 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700600 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800601 send_codecs.clear();
602 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 }
604 std::vector<VideoSenderInfo> senders;
605 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700606 // Deprecated.
607 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700608 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800609 RtpCodecParametersMap send_codecs;
610 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000611};
612
613struct DataMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200614 DataMediaInfo();
615 ~DataMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 void Clear() {
617 senders.clear();
618 receivers.clear();
619 }
620 std::vector<DataSenderInfo> senders;
621 std::vector<DataReceiverInfo> receivers;
622};
623
deadbeef13871492015-12-09 12:37:51 -0800624struct RtcpParameters {
625 bool reduced_size = false;
626};
627
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700628template <class Codec>
629struct RtpParameters {
Steve Anton003930a2018-03-29 12:37:21 -0700630 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700631
632 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700633 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700634 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800635 RtcpParameters rtcp;
Steve Anton003930a2018-03-29 12:37:21 -0700636
637 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200638 rtc::StringBuilder ost;
Steve Anton003930a2018-03-29 12:37:21 -0700639 ost << "{";
640 const char* separator = "";
641 for (const auto& entry : ToStringMap()) {
642 ost << separator << entry.first << ": " << entry.second;
643 separator = ", ";
644 }
645 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200646 return ost.Release();
Steve Anton003930a2018-03-29 12:37:21 -0700647 }
648
649 protected:
650 virtual std::map<std::string, std::string> ToStringMap() const {
651 return {{"codecs", VectorToString(codecs)},
652 {"extensions", VectorToString(extensions)}};
653 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700654};
655
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700656// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
657// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700658template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700659struct RtpSendParameters : RtpParameters<Codec> {
nisse05103312016-03-16 02:22:50 -0700660 int max_bandwidth_bps = -1;
Steve Antonbb50ce52018-03-26 10:24:32 -0700661 // This is the value to be sent in the MID RTP header extension (if the header
662 // extension in included in the list of extensions).
663 std::string mid;
Steve Anton003930a2018-03-29 12:37:21 -0700664
665 protected:
666 std::map<std::string, std::string> ToStringMap() const override {
667 auto params = RtpParameters<Codec>::ToStringMap();
668 params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps);
669 params["mid"] = (mid.empty() ? "<not set>" : mid);
670 return params;
671 }
nisse05103312016-03-16 02:22:50 -0700672};
673
674struct AudioSendParameters : RtpSendParameters<AudioCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200675 AudioSendParameters();
676 ~AudioSendParameters() override;
nisse05103312016-03-16 02:22:50 -0700677 AudioOptions options;
Steve Anton003930a2018-03-29 12:37:21 -0700678
679 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200680 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700681};
682
Yves Gerey665174f2018-06-19 15:03:05 +0200683struct AudioRecvParameters : RtpParameters<AudioCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700684
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685class VoiceMediaChannel : public MediaChannel {
686 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700688 explicit VoiceMediaChannel(const MediaConfig& config)
689 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200690 ~VoiceMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200691 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
692 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700693 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800694 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700695 uint32_t ssrc,
696 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700697 // Get the receive parameters for the incoming stream identified by |ssrc|.
698 // If |ssrc| is 0, retrieve the receive parameters for the default receive
699 // stream, which is used when SSRCs are not signaled. Note that calling with
700 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
701 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700702 virtual webrtc::RtpParameters GetRtpReceiveParameters(
703 uint32_t ssrc) const = 0;
704 virtual bool SetRtpReceiveParameters(
705 uint32_t ssrc,
706 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700708 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800710 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700711 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200712 virtual bool SetAudioSend(uint32_t ssrc,
713 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700714 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800715 AudioSource* source) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700716 // Set speaker output volume of the specified ssrc.
717 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800719 virtual bool CanInsertDtmf() = 0;
720 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000722 // The valid value for the |event| are 0 to 15 which corresponding to
723 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800724 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 // Gets quality stats for the channel.
726 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100727
728 virtual void SetRawAudioSink(
729 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800730 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700731
732 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733};
734
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700735// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
736// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700737struct VideoSendParameters : RtpSendParameters<VideoCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200738 VideoSendParameters();
739 ~VideoSendParameters() override;
nisse4b4dc862016-02-17 05:25:36 -0800740 // Use conference mode? This flag comes from the remote
741 // description's SDP line 'a=x-google-flag:conference', copied over
742 // by VideoChannel::SetRemoteContent_w, and ultimately used by
743 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700744 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800745 // The special screencast behaviour is disabled by default.
746 bool conference_mode = false;
Steve Anton003930a2018-03-29 12:37:21 -0700747
748 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200749 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700750};
751
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700752// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
753// encapsulate all the parameters needed for a video RtpReceiver.
Yves Gerey665174f2018-06-19 15:03:05 +0200754struct VideoRecvParameters : RtpParameters<VideoCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700755
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756class VideoMediaChannel : public MediaChannel {
757 public:
nisse08582ff2016-02-04 01:24:52 -0800758 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700759 explicit VideoMediaChannel(const MediaConfig& config)
760 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200761 ~VideoMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200762
763 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
764 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700765 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800766 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700767 uint32_t ssrc,
768 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700769 // Get the receive parameters for the incoming stream identified by |ssrc|.
770 // If |ssrc| is 0, retrieve the receive parameters for the default receive
771 // stream, which is used when SSRCs are not signaled. Note that calling with
772 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
773 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700774 virtual webrtc::RtpParameters GetRtpReceiveParameters(
775 uint32_t ssrc) const = 0;
776 virtual bool SetRtpReceiveParameters(
777 uint32_t ssrc,
778 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 // Gets the currently set codecs/payload types to be used for outgoing media.
780 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 // Starts or stops transmission (and potentially capture) of local video.
782 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700783 // Configure stream for sending and register a source.
784 // The |ssrc| must correspond to a registered send stream.
785 virtual bool SetVideoSend(
786 uint32_t ssrc,
deadbeef5a4a75a2016-06-02 16:23:38 -0700787 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800788 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800789 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -0700790 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800791 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800792 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700793 // This fills the "bitrate parts" (rtx, video bitrate) of the
794 // BandwidthEstimationInfo, since that part that isn't possible to get
795 // through webrtc::Call::GetStats, as they are statistics of the send
796 // streams.
797 // TODO(holmer): We should change this so that either BWE graphs doesn't
798 // need access to bitrates of the streams, or change the (RTC)StatsCollector
799 // so that it's getting the send stream stats separately by calling
800 // GetStats(), and merges with BandwidthEstimationInfo by itself.
801 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000803 virtual bool GetStats(VideoMediaInfo* info) = 0;
Jonas Oreland49ac5952018-09-26 16:04:32 +0200804
805 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806};
807
808enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000809 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
810 // values.
811 DMT_NONE = 0,
812 DMT_CONTROL = 1,
813 DMT_BINARY = 2,
814 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815};
816
817// Info about data received in DataMediaChannel. For use in
818// DataMediaChannel::SignalDataReceived and in all of the signals that
819// signal fires, on up the chain.
820struct ReceiveDataParams {
821 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800822 // RTP data channels use SSRCs, SCTP data channels use SIDs.
823 union {
824 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800825 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800826 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800828 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800830 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800832 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833};
834
835struct SendDataParams {
836 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800837 // RTP data channels use SSRCs, SCTP data channels use SIDs.
838 union {
839 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800840 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800841 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800843 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844
Steve Anton002f9212018-01-09 16:38:15 -0800845 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 // For SCTP, whether to send messages flagged as ordered or not.
847 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800848 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 // For SCTP, whether the messages are sent reliably or not.
850 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800851 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 // For SCTP, if reliable == false, provide partial reliability by
853 // resending up to this many times. Either count or millis
854 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800855 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 // For SCTP, if reliable == false, provide partial reliability by
857 // resending for up to this many milliseconds. Either count or millis
858 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800859 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860};
861
862enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
863
Yves Gerey665174f2018-06-19 15:03:05 +0200864struct DataSendParameters : RtpSendParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700865
Yves Gerey665174f2018-06-19 15:03:05 +0200866struct DataRecvParameters : RtpParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700867
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868class DataMediaChannel : public MediaChannel {
869 public:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200870 DataMediaChannel();
871 explicit DataMediaChannel(const MediaConfig& config);
872 ~DataMediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200874 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
875 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000876
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 // TODO(pthatcher): Implement this.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200878 virtual bool GetStats(DataMediaInfo* info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879
880 virtual bool SetSend(bool send) = 0;
881 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882
Paulina Hensman11b34f42018-04-09 14:24:52 +0200883 void OnNetworkRouteChanged(const std::string& transport_name,
884 const rtc::NetworkRoute& network_route) override {}
Honghai Zhangcc411c02016-03-29 17:27:21 -0700885
Yves Gerey665174f2018-06-19 15:03:05 +0200886 virtual bool SendData(const SendDataParams& params,
887 const rtc::CopyOnWriteBuffer& payload,
888 SendDataResult* result = NULL) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 // Signals when data is received (params, data, len)
Yves Gerey665174f2018-06-19 15:03:05 +0200890 sigslot::signal3<const ReceiveDataParams&, const char*, size_t>
891 SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000892 // Signal when the media channel is ready to send the stream. Arguments are:
893 // writable(bool)
894 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895};
896
897} // namespace cricket
898
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200899#endif // MEDIA_BASE_MEDIACHANNEL_H_