blob: 09e752a343cb0740714d39cbdeb9cd9f00fd4361 [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
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800187 virtual cricket::MediaType media_type() const = 0;
188
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700189 // Sets the abstract interface class for sending RTP/RTCP data and
190 // interface for media transport (experimental). If media transport is
191 // provided, it should be used instead of RTP/RTCP.
192 // TODO(sukhanov): Currently media transport can co-exist with RTP/RTCP, but
193 // in the future we will refactor code to send all frames with media
194 // transport.
195 virtual void SetInterface(NetworkInterface* iface,
196 webrtc::MediaTransportInterface* media_transport);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700198 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
Niels Möllere6933812018-11-05 13:01:41 +0100199 int64_t packet_time_us) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700201 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
Niels Möllere6933812018-11-05 13:01:41 +0100202 int64_t packet_time_us) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 // Called when the socket's ability to send has changed.
204 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700205 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700206 virtual void OnNetworkRouteChanged(
207 const std::string& transport_name,
208 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 // Creates a new outgoing media stream with SSRCs and CNAME as described
210 // by sp.
211 virtual bool AddSendStream(const StreamParams& sp) = 0;
212 // Removes an outgoing media stream.
Seth Hampson5897a6e2018-04-03 11:16:33 -0700213 // SSRC must be the first SSRC of the media stream if the stream uses
214 // multiple SSRCs. In the case of an ssrc of 0, the possibly cached
215 // StreamParams is removed.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200216 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700217 // Creates a new incoming media stream with SSRCs, CNAME as described
218 // by sp. In the case of a sp without SSRCs, the unsignaled sp is cached
219 // to be used later for unsignaled streams received.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 virtual bool AddRecvStream(const StreamParams& sp) = 0;
221 // Removes an incoming media stream.
222 // ssrc must be the first SSRC of the media stream if the stream uses
223 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200224 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000225 // Returns the absoulte sendtime extension id value from media channel.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200226 virtual int GetRtpSendTimeExtnId() const;
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700227 // Set the frame encryptor to use on all outgoing frames. This is optional.
228 // This pointers lifetime is managed by the set of RtpSender it is attached
229 // to.
Benjamin Wright84583f62018-10-04 14:22:34 -0700230 // TODO(benwright) make pure virtual once internal supports it.
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700231 virtual void SetFrameEncryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700232 uint32_t ssrc,
233 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor);
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700234 // Set the frame decryptor to use on all incoming frames. This is optional.
235 // This pointers lifetimes is managed by the set of RtpReceivers it is
236 // attached to.
Benjamin Wright84583f62018-10-04 14:22:34 -0700237 // TODO(benwright) make pure virtual once internal supports it.
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700238 virtual void SetFrameDecryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700239 uint32_t ssrc,
240 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000242 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700243 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
244 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700245 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000246 }
247
jbaucheec21bd2016-03-20 06:15:43 -0700248 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
249 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700250 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000251 }
252
253 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000254 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000255 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000256 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000257 if (!network_interface_)
258 return -1;
259
260 return network_interface_->SetOption(type, opt, option);
261 }
262
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700263 webrtc::MediaTransportInterface* media_transport() {
264 return media_transport_;
265 }
266
Johannes Kron9190b822018-10-29 11:22:05 +0100267 // Corresponds to the SDP attribute extmap-allow-mixed, see RFC8285.
268 // Set to true if it's allowed to mix one- and two-byte RTP header extensions
269 // in the same stream. The setter and getter must only be called from
270 // worker_thread.
271 void SetExtmapAllowMixed(bool extmap_allow_mixed) {
272 extmap_allow_mixed_ = extmap_allow_mixed;
273 }
274 bool ExtmapAllowMixed() const { return extmap_allow_mixed_; }
275
Tim Haloun6ca98362018-09-17 17:06:08 -0700276 protected:
277 virtual rtc::DiffServCodePoint PreferredDscp() const;
278
279 bool DscpEnabled() const { return enable_dscp_; }
280
wu@webrtc.orgde305012013-10-31 15:40:38 +0000281 // This method sets DSCP |value| on both RTP and RTCP channels.
Tim Haloun648d28a2018-10-18 16:52:22 -0700282 int UpdateDscp() {
283 rtc::DiffServCodePoint value =
284 enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000285 int ret;
Yves Gerey665174f2018-06-19 15:03:05 +0200286 ret = SetOption(NetworkInterface::ST_RTP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000287 if (ret == 0) {
Yves Gerey665174f2018-06-19 15:03:05 +0200288 ret = SetOption(NetworkInterface::ST_RTCP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000289 }
290 return ret;
291 }
292
Tim Haloun648d28a2018-10-18 16:52:22 -0700293 private:
jbaucheec21bd2016-03-20 06:15:43 -0700294 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700295 bool rtcp,
296 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000297 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000298 if (!network_interface_)
299 return false;
300
stefanc1aeaf02015-10-15 07:26:07 -0700301 return (!rtcp) ? network_interface_->SendPacket(packet, options)
302 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000303 }
304
nisse51542be2016-02-12 02:27:06 -0800305 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000306 // |network_interface_| can be accessed from the worker_thread and
307 // from any MediaEngine threads. This critical section is to protect accessing
308 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000309 rtc::CriticalSection network_interface_crit_;
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700310 NetworkInterface* network_interface_ = nullptr;
311 webrtc::MediaTransportInterface* media_transport_ = nullptr;
Johannes Kron9190b822018-10-29 11:22:05 +0100312 bool extmap_allow_mixed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313};
314
wu@webrtc.org97077a32013-10-25 21:18:33 +0000315// The stats information is structured as follows:
316// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
317// Media contains a vector of SSRC infos that are exclusively used by this
318// media. (SSRCs shared between media streams can't be represented.)
319
320// Information about an SSRC.
321// This data may be locally recorded, or received in an RTCP SR or RR.
322struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800323 uint32_t ssrc = 0;
324 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000325};
326
327struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800328 uint32_t ssrc = 0;
329 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000330};
331
332struct MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200333 MediaSenderInfo();
334 ~MediaSenderInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200335 void add_ssrc(const SsrcSenderInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000336 // Temporary utility function for call sites that only provide SSRC.
337 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200338 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000339 SsrcSenderInfo stat;
340 stat.ssrc = ssrc;
341 add_ssrc(stat);
342 }
343 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200344 std::vector<uint32_t> ssrcs() const {
345 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000346 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
347 it != local_stats.end(); ++it) {
348 retval.push_back(it->ssrc);
349 }
350 return retval;
351 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100352 // Returns true if the media has been connected.
353 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000354 // Utility accessor for clients that make the assumption only one ssrc
355 // exists per media.
356 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100357 // Call sites that compare this to zero should use connected() instead.
358 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200359 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100360 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000361 return local_stats[0].ssrc;
362 } else {
363 return 0;
364 }
365 }
Steve Anton002f9212018-01-09 16:38:15 -0800366 int64_t bytes_sent = 0;
367 int packets_sent = 0;
368 int packets_lost = 0;
369 float fraction_lost = 0.0f;
370 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000371 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200372 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000373 std::vector<SsrcSenderInfo> local_stats;
374 std::vector<SsrcReceiverInfo> remote_stats;
375};
376
377struct MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200378 MediaReceiverInfo();
379 ~MediaReceiverInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200380 void add_ssrc(const SsrcReceiverInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000381 // Temporary utility function for call sites that only provide SSRC.
382 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200383 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000384 SsrcReceiverInfo stat;
385 stat.ssrc = ssrc;
386 add_ssrc(stat);
387 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200388 std::vector<uint32_t> ssrcs() const {
389 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000390 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
391 it != local_stats.end(); ++it) {
392 retval.push_back(it->ssrc);
393 }
394 return retval;
395 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100396 // Returns true if the media has been connected.
397 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000398 // Utility accessor for clients that make the assumption only one ssrc
399 // exists per media.
400 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100401 // Call sites that compare this to zero should use connected();
402 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200403 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100404 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000405 return local_stats[0].ssrc;
406 } else {
407 return 0;
408 }
409 }
410
Steve Anton002f9212018-01-09 16:38:15 -0800411 int64_t bytes_rcvd = 0;
412 int packets_rcvd = 0;
413 int packets_lost = 0;
414 float fraction_lost = 0.0f;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000415 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200416 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000417 std::vector<SsrcReceiverInfo> local_stats;
418 std::vector<SsrcSenderInfo> remote_stats;
419};
420
421struct VoiceSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200422 VoiceSenderInfo();
423 ~VoiceSenderInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800424 int ext_seqnum = 0;
425 int jitter_ms = 0;
426 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700427 // See description of "totalAudioEnergy" in the WebRTC stats spec:
428 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800429 double total_input_energy = 0.0;
430 double total_input_duration = 0.0;
Steve Anton002f9212018-01-09 16:38:15 -0800431 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700432 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100433 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434};
435
wu@webrtc.org97077a32013-10-25 21:18:33 +0000436struct VoiceReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200437 VoiceReceiverInfo();
438 ~VoiceReceiverInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800439 int ext_seqnum = 0;
440 int jitter_ms = 0;
441 int jitter_buffer_ms = 0;
442 int jitter_buffer_preferred_ms = 0;
443 int delay_estimate_ms = 0;
444 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200445 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
446 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800447 double total_output_energy = 0.0;
448 uint64_t total_samples_received = 0;
449 double total_output_duration = 0.0;
450 uint64_t concealed_samples = 0;
451 uint64_t concealment_events = 0;
452 double jitter_buffer_delay_seconds = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200453 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000454 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800455 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000456 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800457 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000458 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800459 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200460 // Fraction of secondary data, including FEC and RED, that is discarded.
461 // Discarding of secondary data can be caused by the reception of the primary
462 // data, obsoleting the secondary data. It can also be caused by early
463 // or late arrival of secondary data. This metric is the percentage of
464 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800465 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200466 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800467 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200468 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800469 float preemptive_expand_rate = 0.0f;
470 int decoding_calls_to_silence_generator = 0;
471 int decoding_calls_to_neteq = 0;
472 int decoding_normal = 0;
473 int decoding_plc = 0;
474 int decoding_cng = 0;
475 int decoding_plc_cng = 0;
476 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000477 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800478 int64_t capture_start_ntp_time_ms = -1;
Ruslan Burakov8af88962018-11-22 17:21:10 +0100479 // Count of the number of buffer flushes.
480 uint64_t jitter_buffer_flushes = 0;
Jakob Ivarsson352ce5c2018-11-27 12:52:16 +0100481 // Number of samples expanded due to delayed packets.
482 uint64_t delayed_packet_outage_samples = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483};
484
wu@webrtc.org97077a32013-10-25 21:18:33 +0000485struct VideoSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200486 VideoSenderInfo();
487 ~VideoSenderInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000488 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800489 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100490 std::string encoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800491 int firs_rcvd = 0;
492 int plis_rcvd = 0;
493 int nacks_rcvd = 0;
494 int send_frame_width = 0;
495 int send_frame_height = 0;
496 int framerate_input = 0;
497 int framerate_sent = 0;
498 int nominal_bitrate = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800499 int adapt_reason = 0;
500 int adapt_changes = 0;
501 int avg_encode_ms = 0;
502 int encode_usage_percent = 0;
503 uint32_t frames_encoded = 0;
504 bool has_entered_low_resolution = false;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200505 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800506 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100507 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
508 uint32_t huge_frames_sent = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509};
510
wu@webrtc.org97077a32013-10-25 21:18:33 +0000511struct VideoReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200512 VideoReceiverInfo();
513 ~VideoReceiverInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000514 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800515 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100516 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800517 int packets_concealed = 0;
518 int firs_sent = 0;
519 int plis_sent = 0;
520 int nacks_sent = 0;
521 int frame_width = 0;
522 int frame_height = 0;
523 int framerate_rcvd = 0;
524 int framerate_decoded = 0;
525 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000526 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800527 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000528 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800529 int framerate_render_output = 0;
530 uint32_t frames_received = 0;
531 uint32_t frames_decoded = 0;
532 uint32_t frames_rendered = 0;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200533 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800534 int64_t interframe_delay_max_ms = -1;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000535
Steve Anton002f9212018-01-09 16:38:15 -0800536 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700537
wu@webrtc.org97077a32013-10-25 21:18:33 +0000538 // All stats below are gathered per-VideoReceiver, but some will be correlated
539 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
540 // structures, reflect this in the new layout.
541
542 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800543 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000544 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800545 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000546 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800547 int jitter_buffer_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000548 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800549 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000550 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800551 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000552 // Target overall delay: network+decode+render, accounting for
553 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800554 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000555 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800556 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000557
558 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800559 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700560
Benjamin Wright514f0842018-12-10 09:55:17 -0800561 // First frame received to first frame decoded latency.
562 int64_t first_frame_received_to_decoded_ms = -1;
563
ilnik2edc6842017-07-06 03:06:50 -0700564 // Timing frame info: all important timestamps for a full lifetime of a
565 // single 'timing frame'.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200566 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567};
568
wu@webrtc.org97077a32013-10-25 21:18:33 +0000569struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800570 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571};
572
wu@webrtc.org97077a32013-10-25 21:18:33 +0000573struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800574 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575};
576
577struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800578 int available_send_bandwidth = 0;
579 int available_recv_bandwidth = 0;
580 int target_enc_bitrate = 0;
581 int actual_enc_bitrate = 0;
582 int retransmit_bitrate = 0;
583 int transmit_bitrate = 0;
584 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000585};
586
hbosa65704b2016-11-14 02:28:16 -0800587// Maps from payload type to |RtpCodecParameters|.
588typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
589
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590struct VoiceMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200591 VoiceMediaInfo();
592 ~VoiceMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 void Clear() {
594 senders.clear();
595 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800596 send_codecs.clear();
597 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 }
599 std::vector<VoiceSenderInfo> senders;
600 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800601 RtpCodecParametersMap send_codecs;
602 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603};
604
605struct VideoMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200606 VideoMediaInfo();
607 ~VideoMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000608 void Clear() {
609 senders.clear();
610 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700611 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800612 send_codecs.clear();
613 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614 }
615 std::vector<VideoSenderInfo> senders;
616 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700617 // Deprecated.
618 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700619 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800620 RtpCodecParametersMap send_codecs;
621 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622};
623
624struct DataMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200625 DataMediaInfo();
626 ~DataMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 void Clear() {
628 senders.clear();
629 receivers.clear();
630 }
631 std::vector<DataSenderInfo> senders;
632 std::vector<DataReceiverInfo> receivers;
633};
634
deadbeef13871492015-12-09 12:37:51 -0800635struct RtcpParameters {
636 bool reduced_size = false;
637};
638
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700639template <class Codec>
640struct RtpParameters {
Steve Anton003930a2018-03-29 12:37:21 -0700641 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700642
643 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700644 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700645 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800646 RtcpParameters rtcp;
Steve Anton003930a2018-03-29 12:37:21 -0700647
648 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200649 rtc::StringBuilder ost;
Steve Anton003930a2018-03-29 12:37:21 -0700650 ost << "{";
651 const char* separator = "";
652 for (const auto& entry : ToStringMap()) {
653 ost << separator << entry.first << ": " << entry.second;
654 separator = ", ";
655 }
656 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200657 return ost.Release();
Steve Anton003930a2018-03-29 12:37:21 -0700658 }
659
660 protected:
661 virtual std::map<std::string, std::string> ToStringMap() const {
662 return {{"codecs", VectorToString(codecs)},
663 {"extensions", VectorToString(extensions)}};
664 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700665};
666
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700667// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
668// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700669template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700670struct RtpSendParameters : RtpParameters<Codec> {
nisse05103312016-03-16 02:22:50 -0700671 int max_bandwidth_bps = -1;
Steve Antonbb50ce52018-03-26 10:24:32 -0700672 // This is the value to be sent in the MID RTP header extension (if the header
673 // extension in included in the list of extensions).
674 std::string mid;
Johannes Kron9190b822018-10-29 11:22:05 +0100675 bool extmap_allow_mixed = false;
Steve Anton003930a2018-03-29 12:37:21 -0700676
677 protected:
678 std::map<std::string, std::string> ToStringMap() const override {
679 auto params = RtpParameters<Codec>::ToStringMap();
680 params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps);
681 params["mid"] = (mid.empty() ? "<not set>" : mid);
Johannes Kron9190b822018-10-29 11:22:05 +0100682 params["extmap-allow-mixed"] = extmap_allow_mixed ? "true" : "false";
Steve Anton003930a2018-03-29 12:37:21 -0700683 return params;
684 }
nisse05103312016-03-16 02:22:50 -0700685};
686
687struct AudioSendParameters : RtpSendParameters<AudioCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200688 AudioSendParameters();
689 ~AudioSendParameters() override;
nisse05103312016-03-16 02:22:50 -0700690 AudioOptions options;
Steve Anton003930a2018-03-29 12:37:21 -0700691
692 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200693 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700694};
695
Yves Gerey665174f2018-06-19 15:03:05 +0200696struct AudioRecvParameters : RtpParameters<AudioCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700697
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698class VoiceMediaChannel : public MediaChannel {
699 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700701 explicit VoiceMediaChannel(const MediaConfig& config)
702 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200703 ~VoiceMediaChannel() override {}
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800704
705 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200706 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
707 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700708 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800709 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700710 uint32_t ssrc,
711 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700712 // Get the receive parameters for the incoming stream identified by |ssrc|.
713 // If |ssrc| is 0, retrieve the receive parameters for the default receive
714 // stream, which is used when SSRCs are not signaled. Note that calling with
715 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
716 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700717 virtual webrtc::RtpParameters GetRtpReceiveParameters(
718 uint32_t ssrc) const = 0;
719 virtual bool SetRtpReceiveParameters(
720 uint32_t ssrc,
721 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700723 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800725 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700726 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200727 virtual bool SetAudioSend(uint32_t ssrc,
728 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700729 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800730 AudioSource* source) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700731 // Set speaker output volume of the specified ssrc.
732 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800734 virtual bool CanInsertDtmf() = 0;
735 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000737 // The valid value for the |event| are 0 to 15 which corresponding to
738 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800739 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 // Gets quality stats for the channel.
741 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100742
743 virtual void SetRawAudioSink(
744 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800745 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700746
747 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000748};
749
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700750// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
751// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700752struct VideoSendParameters : RtpSendParameters<VideoCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200753 VideoSendParameters();
754 ~VideoSendParameters() override;
nisse4b4dc862016-02-17 05:25:36 -0800755 // Use conference mode? This flag comes from the remote
756 // description's SDP line 'a=x-google-flag:conference', copied over
757 // by VideoChannel::SetRemoteContent_w, and ultimately used by
758 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700759 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800760 // The special screencast behaviour is disabled by default.
761 bool conference_mode = false;
Steve Anton003930a2018-03-29 12:37:21 -0700762
763 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200764 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700765};
766
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700767// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
768// encapsulate all the parameters needed for a video RtpReceiver.
Yves Gerey665174f2018-06-19 15:03:05 +0200769struct VideoRecvParameters : RtpParameters<VideoCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700770
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771class VideoMediaChannel : public MediaChannel {
772 public:
nisse08582ff2016-02-04 01:24:52 -0800773 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700774 explicit VideoMediaChannel(const MediaConfig& config)
775 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200776 ~VideoMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200777
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800778 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200779 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
780 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700781 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
Zach Steinba37b4b2018-01-23 15:02:36 -0800782 virtual webrtc::RTCError SetRtpSendParameters(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700783 uint32_t ssrc,
784 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700785 // Get the receive parameters for the incoming stream identified by |ssrc|.
786 // If |ssrc| is 0, retrieve the receive parameters for the default receive
787 // stream, which is used when SSRCs are not signaled. Note that calling with
788 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
789 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700790 virtual webrtc::RtpParameters GetRtpReceiveParameters(
791 uint32_t ssrc) const = 0;
792 virtual bool SetRtpReceiveParameters(
793 uint32_t ssrc,
794 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 // Gets the currently set codecs/payload types to be used for outgoing media.
796 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 // Starts or stops transmission (and potentially capture) of local video.
798 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700799 // Configure stream for sending and register a source.
800 // The |ssrc| must correspond to a registered send stream.
801 virtual bool SetVideoSend(
802 uint32_t ssrc,
deadbeef5a4a75a2016-06-02 16:23:38 -0700803 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800804 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800805 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -0700806 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800807 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800808 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700809 // This fills the "bitrate parts" (rtx, video bitrate) of the
810 // BandwidthEstimationInfo, since that part that isn't possible to get
811 // through webrtc::Call::GetStats, as they are statistics of the send
812 // streams.
813 // TODO(holmer): We should change this so that either BWE graphs doesn't
814 // need access to bitrates of the streams, or change the (RTC)StatsCollector
815 // so that it's getting the send stream stats separately by calling
816 // GetStats(), and merges with BandwidthEstimationInfo by itself.
817 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000819 virtual bool GetStats(VideoMediaInfo* info) = 0;
Jonas Oreland49ac5952018-09-26 16:04:32 +0200820
821 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822};
823
824enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000825 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
826 // values.
827 DMT_NONE = 0,
828 DMT_CONTROL = 1,
829 DMT_BINARY = 2,
830 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831};
832
833// Info about data received in DataMediaChannel. For use in
834// DataMediaChannel::SignalDataReceived and in all of the signals that
835// signal fires, on up the chain.
836struct ReceiveDataParams {
837 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800838 // RTP data channels use SSRCs, SCTP data channels use SIDs.
839 union {
840 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800841 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800842 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800844 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800846 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800848 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849};
850
851struct SendDataParams {
852 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800853 // RTP data channels use SSRCs, SCTP data channels use SIDs.
854 union {
855 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800856 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800857 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800859 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860
Steve Anton002f9212018-01-09 16:38:15 -0800861 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 // For SCTP, whether to send messages flagged as ordered or not.
863 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800864 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 // For SCTP, whether the messages are sent reliably or not.
866 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800867 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 // For SCTP, if reliable == false, provide partial reliability by
869 // resending up to this many times. Either count or millis
870 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800871 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 // For SCTP, if reliable == false, provide partial reliability by
873 // resending for up to this many milliseconds. Either count or millis
874 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800875 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876};
877
878enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
879
Yves Gerey665174f2018-06-19 15:03:05 +0200880struct DataSendParameters : RtpSendParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700881
Yves Gerey665174f2018-06-19 15:03:05 +0200882struct DataRecvParameters : RtpParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700883
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884class DataMediaChannel : public MediaChannel {
885 public:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200886 DataMediaChannel();
887 explicit DataMediaChannel(const MediaConfig& config);
888 ~DataMediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800890 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200891 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
892 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000893
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 // TODO(pthatcher): Implement this.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200895 virtual bool GetStats(DataMediaInfo* info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896
897 virtual bool SetSend(bool send) = 0;
898 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899
Paulina Hensman11b34f42018-04-09 14:24:52 +0200900 void OnNetworkRouteChanged(const std::string& transport_name,
901 const rtc::NetworkRoute& network_route) override {}
Honghai Zhangcc411c02016-03-29 17:27:21 -0700902
Yves Gerey665174f2018-06-19 15:03:05 +0200903 virtual bool SendData(const SendDataParams& params,
904 const rtc::CopyOnWriteBuffer& payload,
905 SendDataResult* result = NULL) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 // Signals when data is received (params, data, len)
Yves Gerey665174f2018-06-19 15:03:05 +0200907 sigslot::signal3<const ReceiveDataParams&, const char*, size_t>
908 SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000909 // Signal when the media channel is ready to send the stream. Arguments are:
910 // writable(bool)
911 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912};
913
914} // namespace cricket
915
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200916#endif // MEDIA_BASE_MEDIACHANNEL_H_