blob: df20582eeab2c447d2bdc1246e4318a26045eb54 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MEDIA_BASE_MEDIACHANNEL_H_
12#define MEDIA_BASE_MEDIACHANNEL_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
Steve Antone78bcb92017-10-31 09:53:08 -070014#include <map>
kwiberg686a8ef2016-02-26 03:00:35 -080015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
Patrik Höglundaba85d12017-11-28 15:46:08 +010017#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <vector>
19
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "api/audio_codecs/audio_encoder.h"
Niels Möllera6fe2612018-01-19 11:28:54 +010021#include "api/audio_options.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "api/optional.h"
Zach Steinba37b4b2018-01-23 15:02:36 -080023#include "api/rtcerror.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "api/rtpparameters.h"
25#include "api/rtpreceiverinterface.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010026#include "api/video/video_content_type.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "api/video/video_timing.h"
Patrik Höglundbe214a22018-01-04 12:14:35 +010028#include "api/videosinkinterface.h"
Patrik Höglundadc1e9b2018-01-09 14:55:05 +010029#include "api/videosourceinterface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "call/video_config.h"
31#include "media/base/codec.h"
Niels Möller6daa2782018-01-23 10:37:42 +010032#include "media/base/mediaconfig.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "media/base/mediaconstants.h"
34#include "media/base/streamparams.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010035#include "modules/audio_processing/include/audio_processing_statistics.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010036#include "rtc_base/asyncpacketsocket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020037#include "rtc_base/basictypes.h"
38#include "rtc_base/buffer.h"
39#include "rtc_base/copyonwritebuffer.h"
40#include "rtc_base/dscp.h"
41#include "rtc_base/logging.h"
42#include "rtc_base/networkroute.h"
43#include "rtc_base/sigslot.h"
44#include "rtc_base/socket.h"
Niels Möller9a44f962017-12-08 15:57:38 +010045#include "rtc_base/stringencode.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010046
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000048namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049class Timing;
50}
51
Tommif888bb52015-12-12 01:37:01 +010052namespace webrtc {
53class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080054class VideoFrame;
Tommif888bb52015-12-12 01:37:01 +010055}
56
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057namespace cricket {
58
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080059class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080061struct RtpHeader;
62struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064const int kScreencastDefaultFps = 5;
65
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066template <class T>
Karl Wibergbe579832015-11-10 22:34:18 +010067static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070069 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070 str = key;
71 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070072 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 str += ", ";
74 }
75 return str;
76}
77
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070078template <class T>
79static std::string VectorToString(const std::vector<T>& vals) {
80 std::ostringstream ost;
81 ost << "[";
82 for (size_t i = 0; i < vals.size(); ++i) {
83 if (i > 0) {
84 ost << ", ";
85 }
86 ost << vals[i].ToString();
87 }
88 ost << "]";
89 return ost.str();
90}
91
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
93// Used to be flags, but that makes it hard to selectively apply options.
94// We are moving all of the setting of options to structs like this,
95// but some things currently still use flags.
96struct VideoOptions {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -070098 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -080099 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100100 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 }
102
103 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800104 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100105 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
106 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 }
deadbeef119760a2016-04-04 11:43:27 -0700108 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109
110 std::string ToString() const {
111 std::ostringstream ost;
112 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800114 ost << ToStringIfSet("screencast min bitrate kbps",
115 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100116 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117 ost << "}";
118 return ost.str();
119 }
120
nisseb163c3f2016-01-29 01:14:38 -0800121 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700122 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800123 // on to the codec options. Disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100124 rtc::Optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800125 // Force screencast to use a minimum bitrate. This flag comes from
126 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700127 // copied to the encoder config by WebRtcVideoChannel.
nisseb163c3f2016-01-29 01:14:38 -0800128 rtc::Optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100129 // Set by screencast sources. Implies selection of encoding settings
130 // suitable for screencast. Most likely not the right way to do
131 // things, e.g., screencast of a text document and screencast of a
132 // youtube video have different needs.
133 rtc::Optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700134
135 private:
136 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100137 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700138 if (o) {
139 *s = o;
140 }
141 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142};
143
isheriffa1c548b2016-05-31 16:12:24 -0700144// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
145struct RtpHeaderExtension {
146 RtpHeaderExtension() : id(0) {}
147 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
148
149 std::string ToString() const {
150 std::ostringstream ost;
151 ost << "{";
152 ost << "uri: " << uri;
153 ost << ", id: " << id;
154 ost << "}";
155 return ost.str();
156 }
157
158 std::string uri;
159 int id;
160};
161
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162class MediaChannel : public sigslot::has_slots<> {
163 public:
164 class NetworkInterface {
165 public:
166 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700167 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700168 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700169 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700170 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000171 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 int option) = 0;
173 virtual ~NetworkInterface() {}
174 };
175
terelius54f91712016-06-01 11:18:56 -0700176 explicit MediaChannel(const MediaConfig& config)
nisse51542be2016-02-12 02:27:06 -0800177 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
178 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 virtual ~MediaChannel() {}
180
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000181 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000183 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 network_interface_ = iface;
nisse51542be2016-02-12 02:27:06 -0800185 SetDscp(enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 }
nisse51542be2016-02-12 02:27:06 -0800187 virtual rtc::DiffServCodePoint PreferredDscp() const {
188 return rtc::DSCP_DEFAULT;
189 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700191 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000192 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700194 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000195 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 // Called when the socket's ability to send has changed.
197 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700198 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700199 virtual void OnNetworkRouteChanged(
200 const std::string& transport_name,
201 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202 // Creates a new outgoing media stream with SSRCs and CNAME as described
203 // by sp.
204 virtual bool AddSendStream(const StreamParams& sp) = 0;
205 // Removes an outgoing media stream.
Seth Hampson5897a6e2018-04-03 11:16:33 -0700206 // SSRC must be the first SSRC of the media stream if the stream uses
207 // multiple SSRCs. In the case of an ssrc of 0, the possibly cached
208 // StreamParams is removed.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200209 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700210 // Creates a new incoming media stream with SSRCs, CNAME as described
211 // by sp. In the case of a sp without SSRCs, the unsignaled sp is cached
212 // to be used later for unsignaled streams received.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 virtual bool AddRecvStream(const StreamParams& sp) = 0;
214 // Removes an incoming media stream.
215 // ssrc must be the first SSRC of the media stream if the stream uses
216 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200217 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000219 // Returns the absoulte sendtime extension id value from media channel.
220 virtual int GetRtpSendTimeExtnId() const {
221 return -1;
222 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000224 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700225 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
226 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700227 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000228 }
229
jbaucheec21bd2016-03-20 06:15:43 -0700230 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
231 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700232 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000233 }
234
235 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000236 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000237 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000238 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000239 if (!network_interface_)
240 return -1;
241
242 return network_interface_->SetOption(type, opt, option);
243 }
244
nisse51542be2016-02-12 02:27:06 -0800245 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000246 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000247 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000248 int ret;
249 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000250 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000251 value);
252 if (ret == 0) {
253 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000254 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000255 value);
256 }
257 return ret;
258 }
259
jbaucheec21bd2016-03-20 06:15:43 -0700260 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700261 bool rtcp,
262 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000263 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000264 if (!network_interface_)
265 return false;
266
stefanc1aeaf02015-10-15 07:26:07 -0700267 return (!rtcp) ? network_interface_->SendPacket(packet, options)
268 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000269 }
270
nisse51542be2016-02-12 02:27:06 -0800271 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000272 // |network_interface_| can be accessed from the worker_thread and
273 // from any MediaEngine threads. This critical section is to protect accessing
274 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000275 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000276 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277};
278
wu@webrtc.org97077a32013-10-25 21:18:33 +0000279// The stats information is structured as follows:
280// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
281// Media contains a vector of SSRC infos that are exclusively used by this
282// media. (SSRCs shared between media streams can't be represented.)
283
284// Information about an SSRC.
285// This data may be locally recorded, or received in an RTCP SR or RR.
286struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800287 uint32_t ssrc = 0;
288 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000289};
290
291struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800292 uint32_t ssrc = 0;
293 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000294};
295
296struct MediaSenderInfo {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000297 void add_ssrc(const SsrcSenderInfo& stat) {
298 local_stats.push_back(stat);
299 }
300 // Temporary utility function for call sites that only provide SSRC.
301 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200302 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000303 SsrcSenderInfo stat;
304 stat.ssrc = ssrc;
305 add_ssrc(stat);
306 }
307 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200308 std::vector<uint32_t> ssrcs() const {
309 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000310 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
311 it != local_stats.end(); ++it) {
312 retval.push_back(it->ssrc);
313 }
314 return retval;
315 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100316 // Returns true if the media has been connected.
317 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000318 // Utility accessor for clients that make the assumption only one ssrc
319 // exists per media.
320 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100321 // Call sites that compare this to zero should use connected() instead.
322 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200323 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100324 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000325 return local_stats[0].ssrc;
326 } else {
327 return 0;
328 }
329 }
Steve Anton002f9212018-01-09 16:38:15 -0800330 int64_t bytes_sent = 0;
331 int packets_sent = 0;
332 int packets_lost = 0;
333 float fraction_lost = 0.0f;
334 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000335 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800336 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000337 std::vector<SsrcSenderInfo> local_stats;
338 std::vector<SsrcReceiverInfo> remote_stats;
339};
340
341struct MediaReceiverInfo {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000342 void add_ssrc(const SsrcReceiverInfo& stat) {
343 local_stats.push_back(stat);
344 }
345 // Temporary utility function for call sites that only provide SSRC.
346 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200347 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000348 SsrcReceiverInfo stat;
349 stat.ssrc = ssrc;
350 add_ssrc(stat);
351 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200352 std::vector<uint32_t> ssrcs() const {
353 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000354 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
355 it != local_stats.end(); ++it) {
356 retval.push_back(it->ssrc);
357 }
358 return retval;
359 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100360 // Returns true if the media has been connected.
361 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000362 // Utility accessor for clients that make the assumption only one ssrc
363 // exists per media.
364 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100365 // Call sites that compare this to zero should use connected();
366 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200367 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100368 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000369 return local_stats[0].ssrc;
370 } else {
371 return 0;
372 }
373 }
374
Steve Anton002f9212018-01-09 16:38:15 -0800375 int64_t bytes_rcvd = 0;
376 int packets_rcvd = 0;
377 int packets_lost = 0;
378 float fraction_lost = 0.0f;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000379 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800380 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000381 std::vector<SsrcReceiverInfo> local_stats;
382 std::vector<SsrcSenderInfo> remote_stats;
383};
384
385struct VoiceSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800386 int ext_seqnum = 0;
387 int jitter_ms = 0;
388 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700389 // See description of "totalAudioEnergy" in the WebRTC stats spec:
390 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800391 double total_input_energy = 0.0;
392 double total_input_duration = 0.0;
Ivo Creusen56d46092017-11-24 17:29:59 +0100393 // TODO(bugs.webrtc.org/8572): Remove APM stats from this struct, since they
394 // are no longer needed now that we have apm_statistics.
Steve Anton002f9212018-01-09 16:38:15 -0800395 int echo_delay_median_ms = 0;
396 int echo_delay_std_ms = 0;
397 int echo_return_loss = 0;
398 int echo_return_loss_enhancement = 0;
399 float residual_echo_likelihood = 0.0f;
400 float residual_echo_likelihood_recent_max = 0.0f;
401 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700402 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100403 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404};
405
wu@webrtc.org97077a32013-10-25 21:18:33 +0000406struct VoiceReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800407 int ext_seqnum = 0;
408 int jitter_ms = 0;
409 int jitter_buffer_ms = 0;
410 int jitter_buffer_preferred_ms = 0;
411 int delay_estimate_ms = 0;
412 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200413 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
414 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800415 double total_output_energy = 0.0;
416 uint64_t total_samples_received = 0;
417 double total_output_duration = 0.0;
418 uint64_t concealed_samples = 0;
419 uint64_t concealment_events = 0;
420 double jitter_buffer_delay_seconds = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200421 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000422 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800423 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000424 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800425 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000426 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800427 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200428 // Fraction of secondary data, including FEC and RED, that is discarded.
429 // Discarding of secondary data can be caused by the reception of the primary
430 // data, obsoleting the secondary data. It can also be caused by early
431 // or late arrival of secondary data. This metric is the percentage of
432 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800433 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200434 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800435 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200436 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800437 float preemptive_expand_rate = 0.0f;
438 int decoding_calls_to_silence_generator = 0;
439 int decoding_calls_to_neteq = 0;
440 int decoding_normal = 0;
441 int decoding_plc = 0;
442 int decoding_cng = 0;
443 int decoding_plc_cng = 0;
444 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000445 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800446 int64_t capture_start_ntp_time_ms = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447};
448
wu@webrtc.org97077a32013-10-25 21:18:33 +0000449struct VideoSenderInfo : public MediaSenderInfo {
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000450 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800451 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100452 std::string encoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800453 int packets_cached = 0;
454 int firs_rcvd = 0;
455 int plis_rcvd = 0;
456 int nacks_rcvd = 0;
457 int send_frame_width = 0;
458 int send_frame_height = 0;
459 int framerate_input = 0;
460 int framerate_sent = 0;
461 int nominal_bitrate = 0;
462 int preferred_bitrate = 0;
463 int adapt_reason = 0;
464 int adapt_changes = 0;
465 int avg_encode_ms = 0;
466 int encode_usage_percent = 0;
467 uint32_t frames_encoded = 0;
468 bool has_entered_low_resolution = false;
sakal87da4042016-10-31 06:53:47 -0700469 rtc::Optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800470 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100471 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
472 uint32_t huge_frames_sent = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473};
474
wu@webrtc.org97077a32013-10-25 21:18:33 +0000475struct VideoReceiverInfo : public MediaReceiverInfo {
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000476 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800477 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100478 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800479 int packets_concealed = 0;
480 int firs_sent = 0;
481 int plis_sent = 0;
482 int nacks_sent = 0;
483 int frame_width = 0;
484 int frame_height = 0;
485 int framerate_rcvd = 0;
486 int framerate_decoded = 0;
487 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000488 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800489 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000490 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800491 int framerate_render_output = 0;
492 uint32_t frames_received = 0;
493 uint32_t frames_decoded = 0;
494 uint32_t frames_rendered = 0;
sakalcc452e12017-02-09 04:53:45 -0800495 rtc::Optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800496 int64_t interframe_delay_max_ms = -1;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000497
Steve Anton002f9212018-01-09 16:38:15 -0800498 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700499
wu@webrtc.org97077a32013-10-25 21:18:33 +0000500 // All stats below are gathered per-VideoReceiver, but some will be correlated
501 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
502 // structures, reflect this in the new layout.
503
504 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800505 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000506 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800507 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000508 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800509 int jitter_buffer_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000510 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800511 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000512 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800513 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000514 // Target overall delay: network+decode+render, accounting for
515 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800516 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000517 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800518 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000519
520 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800521 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700522
523 // Timing frame info: all important timestamps for a full lifetime of a
524 // single 'timing frame'.
525 rtc::Optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526};
527
wu@webrtc.org97077a32013-10-25 21:18:33 +0000528struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800529 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530};
531
wu@webrtc.org97077a32013-10-25 21:18:33 +0000532struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800533 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534};
535
536struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800537 int available_send_bandwidth = 0;
538 int available_recv_bandwidth = 0;
539 int target_enc_bitrate = 0;
540 int actual_enc_bitrate = 0;
541 int retransmit_bitrate = 0;
542 int transmit_bitrate = 0;
543 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000544};
545
hbosa65704b2016-11-14 02:28:16 -0800546// Maps from payload type to |RtpCodecParameters|.
547typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
548
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549struct VoiceMediaInfo {
550 void Clear() {
551 senders.clear();
552 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800553 send_codecs.clear();
554 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 }
556 std::vector<VoiceSenderInfo> senders;
557 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800558 RtpCodecParametersMap send_codecs;
559 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560};
561
562struct VideoMediaInfo {
563 void Clear() {
564 senders.clear();
565 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700566 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800567 send_codecs.clear();
568 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569 }
570 std::vector<VideoSenderInfo> senders;
571 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700572 // Deprecated.
573 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700574 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800575 RtpCodecParametersMap send_codecs;
576 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000577};
578
579struct DataMediaInfo {
580 void Clear() {
581 senders.clear();
582 receivers.clear();
583 }
584 std::vector<DataSenderInfo> senders;
585 std::vector<DataReceiverInfo> receivers;
586};
587
deadbeef13871492015-12-09 12:37:51 -0800588struct RtcpParameters {
589 bool reduced_size = false;
590};
591
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700592template <class Codec>
593struct RtpParameters {
Steve Anton003930a2018-03-29 12:37:21 -0700594 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700595
596 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700597 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700598 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800599 RtcpParameters rtcp;
Steve Anton003930a2018-03-29 12:37:21 -0700600
601 std::string ToString() const {
602 std::ostringstream ost;
603 ost << "{";
604 const char* separator = "";
605 for (const auto& entry : ToStringMap()) {
606 ost << separator << entry.first << ": " << entry.second;
607 separator = ", ";
608 }
609 ost << "}";
610 return ost.str();
611 }
612
613 protected:
614 virtual std::map<std::string, std::string> ToStringMap() const {
615 return {{"codecs", VectorToString(codecs)},
616 {"extensions", VectorToString(extensions)}};
617 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700618};
619
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700620// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
621// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700622template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700623struct RtpSendParameters : RtpParameters<Codec> {
nisse05103312016-03-16 02:22:50 -0700624 int max_bandwidth_bps = -1;
Steve Antonbb50ce52018-03-26 10:24:32 -0700625 // This is the value to be sent in the MID RTP header extension (if the header
626 // extension in included in the list of extensions).
627 std::string mid;
Steve Anton003930a2018-03-29 12:37:21 -0700628
629 protected:
630 std::map<std::string, std::string> ToStringMap() const override {
631 auto params = RtpParameters<Codec>::ToStringMap();
632 params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps);
633 params["mid"] = (mid.empty() ? "<not set>" : mid);
634 return params;
635 }
nisse05103312016-03-16 02:22:50 -0700636};
637
638struct AudioSendParameters : RtpSendParameters<AudioCodec> {
nisse05103312016-03-16 02:22:50 -0700639 AudioOptions options;
Steve Anton003930a2018-03-29 12:37:21 -0700640
641 protected:
642 std::map<std::string, std::string> ToStringMap() const override {
643 auto params = RtpSendParameters<AudioCodec>::ToStringMap();
644 params["options"] = options.ToString();
645 return params;
646 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700647};
648
649struct AudioRecvParameters : RtpParameters<AudioCodec> {
650};
651
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000652class VoiceMediaChannel : public MediaChannel {
653 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000654 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700655 explicit VoiceMediaChannel(const MediaConfig& config)
656 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200658 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
659 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700660 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800661 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700662 uint32_t ssrc,
663 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700664 // Get the receive parameters for the incoming stream identified by |ssrc|.
665 // If |ssrc| is 0, retrieve the receive parameters for the default receive
666 // stream, which is used when SSRCs are not signaled. Note that calling with
667 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
668 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700669 virtual webrtc::RtpParameters GetRtpReceiveParameters(
670 uint32_t ssrc) const = 0;
671 virtual bool SetRtpReceiveParameters(
672 uint32_t ssrc,
673 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700675 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800677 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700678 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200679 virtual bool SetAudioSend(uint32_t ssrc,
680 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700681 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800682 AudioSource* source) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700683 // Set speaker output volume of the specified ssrc.
684 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800686 virtual bool CanInsertDtmf() = 0;
687 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000689 // The valid value for the |event| are 0 to 15 which corresponding to
690 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800691 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 // Gets quality stats for the channel.
693 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100694
695 virtual void SetRawAudioSink(
696 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800697 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700698
699 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700};
701
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700702// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
703// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700704struct VideoSendParameters : RtpSendParameters<VideoCodec> {
nisse4b4dc862016-02-17 05:25:36 -0800705 // Use conference mode? This flag comes from the remote
706 // description's SDP line 'a=x-google-flag:conference', copied over
707 // by VideoChannel::SetRemoteContent_w, and ultimately used by
708 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700709 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800710 // The special screencast behaviour is disabled by default.
711 bool conference_mode = false;
Steve Anton003930a2018-03-29 12:37:21 -0700712
713 protected:
714 std::map<std::string, std::string> ToStringMap() const override {
715 auto params = RtpSendParameters<VideoCodec>::ToStringMap();
716 params["conference_mode"] = (conference_mode ? "yes" : "no");
717 return params;
718 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700719};
720
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700721// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
722// encapsulate all the parameters needed for a video RtpReceiver.
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700723struct VideoRecvParameters : RtpParameters<VideoCodec> {
724};
725
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726class VideoMediaChannel : public MediaChannel {
727 public:
nisse08582ff2016-02-04 01:24:52 -0800728 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700729 explicit VideoMediaChannel(const MediaConfig& config)
730 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200732
733 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
734 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700735 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800736 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700737 uint32_t ssrc,
738 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700739 // Get the receive parameters for the incoming stream identified by |ssrc|.
740 // If |ssrc| is 0, retrieve the receive parameters for the default receive
741 // stream, which is used when SSRCs are not signaled. Note that calling with
742 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
743 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700744 virtual webrtc::RtpParameters GetRtpReceiveParameters(
745 uint32_t ssrc) const = 0;
746 virtual bool SetRtpReceiveParameters(
747 uint32_t ssrc,
748 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 // Gets the currently set codecs/payload types to be used for outgoing media.
750 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751 // Starts or stops transmission (and potentially capture) of local video.
752 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700753 // Configure stream for sending and register a source.
754 // The |ssrc| must correspond to a registered send stream.
755 virtual bool SetVideoSend(
756 uint32_t ssrc,
757 bool enable,
758 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800759 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800760 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -0700761 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800762 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800763 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700764 // This fills the "bitrate parts" (rtx, video bitrate) of the
765 // BandwidthEstimationInfo, since that part that isn't possible to get
766 // through webrtc::Call::GetStats, as they are statistics of the send
767 // streams.
768 // TODO(holmer): We should change this so that either BWE graphs doesn't
769 // need access to bitrates of the streams, or change the (RTC)StatsCollector
770 // so that it's getting the send stream stats separately by calling
771 // GetStats(), and merges with BandwidthEstimationInfo by itself.
772 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000774 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775};
776
777enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000778 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
779 // values.
780 DMT_NONE = 0,
781 DMT_CONTROL = 1,
782 DMT_BINARY = 2,
783 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784};
785
786// Info about data received in DataMediaChannel. For use in
787// DataMediaChannel::SignalDataReceived and in all of the signals that
788// signal fires, on up the chain.
789struct ReceiveDataParams {
790 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800791 // RTP data channels use SSRCs, SCTP data channels use SIDs.
792 union {
793 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800794 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800795 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800797 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800799 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800801 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802};
803
804struct SendDataParams {
805 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800806 // RTP data channels use SSRCs, SCTP data channels use SIDs.
807 union {
808 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800809 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800810 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800812 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813
Steve Anton002f9212018-01-09 16:38:15 -0800814 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 // For SCTP, whether to send messages flagged as ordered or not.
816 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800817 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 // For SCTP, whether the messages are sent reliably or not.
819 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800820 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 // For SCTP, if reliable == false, provide partial reliability by
822 // resending up to this many times. Either count or millis
823 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800824 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 // For SCTP, if reliable == false, provide partial reliability by
826 // resending for up to this many milliseconds. Either count or millis
827 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800828 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829};
830
831enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
832
nisse05103312016-03-16 02:22:50 -0700833struct DataSendParameters : RtpSendParameters<DataCodec> {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700834};
835
836struct DataRecvParameters : RtpParameters<DataCodec> {
837};
838
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839class DataMediaChannel : public MediaChannel {
840 public:
zhihuangebbe4f22016-12-06 10:45:42 -0800841 DataMediaChannel() {}
Steve Antone78bcb92017-10-31 09:53:08 -0700842 explicit DataMediaChannel(const MediaConfig& config) : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 virtual ~DataMediaChannel() {}
844
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200845 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
846 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000847
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 // TODO(pthatcher): Implement this.
849 virtual bool GetStats(DataMediaInfo* info) { return true; }
850
851 virtual bool SetSend(bool send) = 0;
852 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853
Honghai Zhangcc411c02016-03-29 17:27:21 -0700854 virtual void OnNetworkRouteChanged(const std::string& transport_name,
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700855 const rtc::NetworkRoute& network_route) {}
Honghai Zhangcc411c02016-03-29 17:27:21 -0700856
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 virtual bool SendData(
858 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700859 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 SendDataResult* result = NULL) = 0;
861 // Signals when data is received (params, data, len)
862 sigslot::signal3<const ReceiveDataParams&,
863 const char*,
864 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000865 // Signal when the media channel is ready to send the stream. Arguments are:
866 // writable(bool)
867 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868};
869
870} // namespace cricket
871
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200872#endif // MEDIA_BASE_MEDIACHANNEL_H_