blob: a62c618562a80460f788f76bdb2a954935fd0a91 [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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef MEDIA_BASE_MEDIA_CHANNEL_H_
12#define MEDIA_BASE_MEDIA_CHANNEL_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"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/crypto/frame_decryptor_interface.h"
24#include "api/crypto/frame_encryptor_interface.h"
Marina Cioceae77912b2020-02-27 16:16:55 +010025#include "api/frame_transformer_interface.h"
Florent Castellib05ca4b2020-03-05 13:39:55 +010026#include "api/media_stream_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "api/rtc_error.h"
28#include "api/rtp_parameters.h"
Niels Möller65f17ca2019-09-12 13:59:36 +020029#include "api/transport/media/media_transport_config.h"
Niels Möllera8370302019-09-02 15:16:49 +020030#include "api/transport/rtp/rtp_source.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010031#include "api/video/video_content_type.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020032#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020033#include "api/video/video_source_interface.h"
34#include "api/video/video_timing.h"
35#include "api/video_codecs/video_encoder_config.h"
Markus Handell32565f62019-12-04 10:58:17 +010036#include "call/video_receive_stream.h"
Henrik Boströmce33b6a2019-05-28 17:42:38 +020037#include "common_video/include/quality_limitation_reason.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020038#include "media/base/codec.h"
Ruslan Burakov493a6502019-02-27 15:32:48 +010039#include "media/base/delayable.h"
Steve Anton10542f22019-01-11 09:11:00 -080040#include "media/base/media_config.h"
41#include "media/base/media_constants.h"
42#include "media/base/stream_params.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010043#include "modules/audio_processing/include/audio_processing_statistics.h"
Henrik Boström87e3f9d2019-05-27 10:44:24 +020044#include "modules/rtp_rtcp/include/report_block_data.h"
Steve Anton10542f22019-01-11 09:11:00 -080045#include "rtc_base/async_packet_socket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020046#include "rtc_base/buffer.h"
Markus Handell32565f62019-12-04 10:58:17 +010047#include "rtc_base/callback.h"
Steve Anton10542f22019-01-11 09:11:00 -080048#include "rtc_base/copy_on_write_buffer.h"
Niels Möllera8370302019-09-02 15:16:49 +020049#include "rtc_base/critical_section.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020050#include "rtc_base/dscp.h"
51#include "rtc_base/logging.h"
Steve Anton10542f22019-01-11 09:11:00 -080052#include "rtc_base/network_route.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020053#include "rtc_base/socket.h"
Steve Anton10542f22019-01-11 09:11:00 -080054#include "rtc_base/string_encode.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020055#include "rtc_base/strings/string_builder.h"
Artem Titove41c4332018-07-25 15:04:28 +020056#include "rtc_base/third_party/sigslot/sigslot.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010057
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000058namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059class Timing;
60}
61
Tommif888bb52015-12-12 01:37:01 +010062namespace webrtc {
63class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080064class VideoFrame;
Yves Gerey665174f2018-06-19 15:03:05 +020065} // namespace webrtc
Tommif888bb52015-12-12 01:37:01 +010066
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067namespace cricket {
68
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080069class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080071struct RtpHeader;
72struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074const int kScreencastDefaultFps = 5;
75
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076template <class T>
Danil Chapovalov00c71832018-06-15 15:58:38 +020077static std::string ToStringIfSet(const char* key,
78 const absl::optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070080 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081 str = key;
82 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070083 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084 str += ", ";
85 }
86 return str;
87}
88
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070089template <class T>
90static std::string VectorToString(const std::vector<T>& vals) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020091 rtc::StringBuilder ost; // no-presubmit-check TODO(webrtc:8982)
Yves Gerey665174f2018-06-19 15:03:05 +020092 ost << "[";
93 for (size_t i = 0; i < vals.size(); ++i) {
94 if (i > 0) {
95 ost << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070096 }
Yves Gerey665174f2018-06-19 15:03:05 +020097 ost << vals[i].ToString();
98 }
99 ost << "]";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200100 return ost.Release();
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700101}
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
104// Used to be flags, but that makes it hard to selectively apply options.
105// We are moving all of the setting of options to structs like this,
106// but some things currently still use flags.
107struct VideoOptions {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200108 VideoOptions();
109 ~VideoOptions();
110
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700112 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800113 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100114 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 }
116
117 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800118 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100119 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
120 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121 }
deadbeef119760a2016-04-04 11:43:27 -0700122 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123
124 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200125 rtc::StringBuilder ost;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800128 ost << ToStringIfSet("screencast min bitrate kbps",
129 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100130 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200132 return ost.Release();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 }
134
nisseb163c3f2016-01-29 01:14:38 -0800135 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700136 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800137 // on to the codec options. Disabled by default.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200138 absl::optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800139 // Force screencast to use a minimum bitrate. This flag comes from
140 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700141 // copied to the encoder config by WebRtcVideoChannel.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200142 absl::optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100143 // Set by screencast sources. Implies selection of encoding settings
144 // suitable for screencast. Most likely not the right way to do
145 // things, e.g., screencast of a text document and screencast of a
146 // youtube video have different needs.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200147 absl::optional<bool> is_screencast;
Florent Castellib05ca4b2020-03-05 13:39:55 +0100148 webrtc::VideoTrackInterface::ContentHint content_hint;
kwiberg102c6a62015-10-30 02:47:38 -0700149
150 private:
151 template <typename T>
Danil Chapovalov00c71832018-06-15 15:58:38 +0200152 static void SetFrom(absl::optional<T>* s, const absl::optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700153 if (o) {
154 *s = o;
155 }
156 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157};
158
isheriffa1c548b2016-05-31 16:12:24 -0700159// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
160struct RtpHeaderExtension {
161 RtpHeaderExtension() : id(0) {}
162 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
163
164 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200165 rtc::StringBuilder ost;
isheriffa1c548b2016-05-31 16:12:24 -0700166 ost << "{";
167 ost << "uri: " << uri;
168 ost << ", id: " << id;
169 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200170 return ost.Release();
isheriffa1c548b2016-05-31 16:12:24 -0700171 }
172
173 std::string uri;
174 int id;
175};
176
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177class MediaChannel : public sigslot::has_slots<> {
178 public:
179 class NetworkInterface {
180 public:
181 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700182 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700183 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700184 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700185 const rtc::PacketOptions& options) = 0;
Yves Gerey665174f2018-06-19 15:03:05 +0200186 virtual int SetOption(SocketType type,
187 rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 int option) = 0;
189 virtual ~NetworkInterface() {}
190 };
191
Benjamin Wright84583f62018-10-04 14:22:34 -0700192 explicit MediaChannel(const MediaConfig& config);
193 MediaChannel();
194 ~MediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800196 virtual cricket::MediaType media_type() const = 0;
197
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700198 // Sets the abstract interface class for sending RTP/RTCP data and
199 // interface for media transport (experimental). If media transport is
200 // provided, it should be used instead of RTP/RTCP.
201 // TODO(sukhanov): Currently media transport can co-exist with RTP/RTCP, but
202 // in the future we will refactor code to send all frames with media
203 // transport.
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700204 virtual void SetInterface(
205 NetworkInterface* iface,
206 const webrtc::MediaTransportConfig& media_transport_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 // Called when a RTP packet is received.
Amit Hilbuche7a5f7b2019-03-12 11:10:27 -0700208 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
Niels Möllere6933812018-11-05 13:01:41 +0100209 int64_t packet_time_us) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 // Called when the socket's ability to send has changed.
211 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700212 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700213 virtual void OnNetworkRouteChanged(
214 const std::string& transport_name,
215 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216 // Creates a new outgoing media stream with SSRCs and CNAME as described
217 // by sp.
218 virtual bool AddSendStream(const StreamParams& sp) = 0;
219 // Removes an outgoing media stream.
Seth Hampson5897a6e2018-04-03 11:16:33 -0700220 // SSRC must be the first SSRC of the media stream if the stream uses
221 // multiple SSRCs. In the case of an ssrc of 0, the possibly cached
222 // StreamParams is removed.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200223 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700224 // Creates a new incoming media stream with SSRCs, CNAME as described
225 // by sp. In the case of a sp without SSRCs, the unsignaled sp is cached
226 // to be used later for unsignaled streams received.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 virtual bool AddRecvStream(const StreamParams& sp) = 0;
228 // Removes an incoming media stream.
229 // ssrc must be the first SSRC of the media stream if the stream uses
230 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200231 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
Saurav Dasff27da52019-09-20 11:05:30 -0700232 // Resets any cached StreamParams for an unsignaled RecvStream.
233 virtual void ResetUnsignaledRecvStream() = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000234 // Returns the absoulte sendtime extension id value from media channel.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200235 virtual int GetRtpSendTimeExtnId() const;
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700236 // Set the frame encryptor to use on all outgoing frames. This is optional.
237 // This pointers lifetime is managed by the set of RtpSender it is attached
238 // to.
Benjamin Wright84583f62018-10-04 14:22:34 -0700239 // TODO(benwright) make pure virtual once internal supports it.
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700240 virtual void SetFrameEncryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700241 uint32_t ssrc,
242 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor);
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700243 // Set the frame decryptor to use on all incoming frames. This is optional.
244 // This pointers lifetimes is managed by the set of RtpReceivers it is
245 // attached to.
Benjamin Wright84583f62018-10-04 14:22:34 -0700246 // TODO(benwright) make pure virtual once internal supports it.
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700247 virtual void SetFrameDecryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700248 uint32_t ssrc,
249 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250
philipel16cec3b2019-10-25 12:23:02 +0200251 // Enable network condition based codec switching.
252 virtual void SetVideoCodecSwitchingEnabled(bool enabled);
253
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000254 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700255 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
256 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700257 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000258 }
259
jbaucheec21bd2016-03-20 06:15:43 -0700260 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
261 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700262 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000263 }
264
265 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000266 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000267 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000268 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000269 if (!network_interface_)
270 return -1;
271
272 return network_interface_->SetOption(type, opt, option);
273 }
274
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700275 const webrtc::MediaTransportConfig& media_transport_config() const {
276 return media_transport_config_;
277 }
278
Johannes Kron9190b822018-10-29 11:22:05 +0100279 // Corresponds to the SDP attribute extmap-allow-mixed, see RFC8285.
280 // Set to true if it's allowed to mix one- and two-byte RTP header extensions
281 // in the same stream. The setter and getter must only be called from
282 // worker_thread.
283 void SetExtmapAllowMixed(bool extmap_allow_mixed) {
284 extmap_allow_mixed_ = extmap_allow_mixed;
285 }
286 bool ExtmapAllowMixed() const { return extmap_allow_mixed_; }
287
Amit Hilbuchea7ef2a2019-02-19 15:20:21 -0800288 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
289 virtual webrtc::RTCError SetRtpSendParameters(
290 uint32_t ssrc,
291 const webrtc::RtpParameters& parameters) = 0;
292
Marina Cioceae77912b2020-02-27 16:16:55 +0100293 virtual void SetEncoderToPacketizerFrameTransformer(
294 uint32_t ssrc,
295 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer);
Marina Ciocea412a31b2020-02-28 16:02:06 +0100296 virtual void SetDepacketizerToDecoderFrameTransformer(
297 uint32_t ssrc,
298 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer);
Marina Cioceae77912b2020-02-27 16:16:55 +0100299
Tim Haloun6ca98362018-09-17 17:06:08 -0700300 protected:
Tim Haloun6ca98362018-09-17 17:06:08 -0700301 bool DscpEnabled() const { return enable_dscp_; }
302
Steve Antone25f5952019-03-08 15:09:16 -0800303 // This is the DSCP value used for both RTP and RTCP channels if DSCP is
304 // enabled. It can be changed at any time via |SetPreferredDscp|.
305 rtc::DiffServCodePoint PreferredDscp() const {
306 rtc::CritScope cs(&network_interface_crit_);
307 return preferred_dscp_;
308 }
309
310 int SetPreferredDscp(rtc::DiffServCodePoint preferred_dscp) {
311 rtc::CritScope cs(&network_interface_crit_);
312 if (preferred_dscp == preferred_dscp_) {
313 return 0;
314 }
315 preferred_dscp_ = preferred_dscp;
316 return UpdateDscp();
317 }
318
319 private:
320 // Apply the preferred DSCP setting to the underlying network interface RTP
321 // and RTCP channels. If DSCP is disabled, then apply the default DSCP value.
322 int UpdateDscp() RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_crit_) {
Tim Haloun648d28a2018-10-18 16:52:22 -0700323 rtc::DiffServCodePoint value =
Steve Antone25f5952019-03-08 15:09:16 -0800324 enable_dscp_ ? preferred_dscp_ : rtc::DSCP_DEFAULT;
325 int ret = SetOption(NetworkInterface::ST_RTP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000326 if (ret == 0) {
Yves Gerey665174f2018-06-19 15:03:05 +0200327 ret = SetOption(NetworkInterface::ST_RTCP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000328 }
329 return ret;
330 }
331
jbaucheec21bd2016-03-20 06:15:43 -0700332 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700333 bool rtcp,
334 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000335 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000336 if (!network_interface_)
337 return false;
338
stefanc1aeaf02015-10-15 07:26:07 -0700339 return (!rtcp) ? network_interface_->SendPacket(packet, options)
340 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000341 }
342
nisse51542be2016-02-12 02:27:06 -0800343 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000344 // |network_interface_| can be accessed from the worker_thread and
345 // from any MediaEngine threads. This critical section is to protect accessing
346 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000347 rtc::CriticalSection network_interface_crit_;
Steve Antone25f5952019-03-08 15:09:16 -0800348 NetworkInterface* network_interface_ RTC_GUARDED_BY(network_interface_crit_) =
349 nullptr;
350 rtc::DiffServCodePoint preferred_dscp_
351 RTC_GUARDED_BY(network_interface_crit_) = rtc::DSCP_DEFAULT;
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700352 webrtc::MediaTransportConfig media_transport_config_;
Johannes Kron9190b822018-10-29 11:22:05 +0100353 bool extmap_allow_mixed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354};
355
wu@webrtc.org97077a32013-10-25 21:18:33 +0000356// The stats information is structured as follows:
357// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
358// Media contains a vector of SSRC infos that are exclusively used by this
359// media. (SSRCs shared between media streams can't be represented.)
360
361// Information about an SSRC.
362// This data may be locally recorded, or received in an RTCP SR or RR.
363struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800364 uint32_t ssrc = 0;
365 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000366};
367
368struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800369 uint32_t ssrc = 0;
370 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000371};
372
373struct MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200374 MediaSenderInfo();
375 ~MediaSenderInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200376 void add_ssrc(const SsrcSenderInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000377 // Temporary utility function for call sites that only provide SSRC.
378 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200379 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000380 SsrcSenderInfo stat;
381 stat.ssrc = ssrc;
382 add_ssrc(stat);
383 }
384 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200385 std::vector<uint32_t> ssrcs() const {
386 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000387 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
388 it != local_stats.end(); ++it) {
389 retval.push_back(it->ssrc);
390 }
391 return retval;
392 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100393 // Returns true if the media has been connected.
394 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000395 // Utility accessor for clients that make the assumption only one ssrc
396 // exists per media.
397 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100398 // Call sites that compare this to zero should use connected() instead.
399 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200400 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100401 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000402 return local_stats[0].ssrc;
403 } else {
404 return 0;
405 }
406 }
Niels Möllerac0a4cb2019-10-09 15:01:33 +0200407 // https://w3c.github.io/webrtc-stats/#dom-rtcsentrtpstreamstats-bytessent
408 int64_t payload_bytes_sent = 0;
409 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-headerbytessent
410 int64_t header_and_padding_bytes_sent = 0;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200411 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent
412 uint64_t retransmitted_bytes_sent = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800413 int packets_sent = 0;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200414 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent
415 uint64_t retransmitted_packets_sent = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800416 int packets_lost = 0;
417 float fraction_lost = 0.0f;
418 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000419 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200420 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000421 std::vector<SsrcSenderInfo> local_stats;
422 std::vector<SsrcReceiverInfo> remote_stats;
Henrik Boström87e3f9d2019-05-27 10:44:24 +0200423 // A snapshot of the most recent Report Block with additional data of interest
424 // to statistics. Used to implement RTCRemoteInboundRtpStreamStats. Within
425 // this list, the ReportBlockData::RTCPReportBlock::source_ssrc(), which is
426 // the SSRC of the corresponding outbound RTP stream, is unique.
427 std::vector<webrtc::ReportBlockData> report_block_datas;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000428};
429
430struct MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200431 MediaReceiverInfo();
432 ~MediaReceiverInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200433 void add_ssrc(const SsrcReceiverInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000434 // Temporary utility function for call sites that only provide SSRC.
435 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200436 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000437 SsrcReceiverInfo stat;
438 stat.ssrc = ssrc;
439 add_ssrc(stat);
440 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200441 std::vector<uint32_t> ssrcs() const {
442 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000443 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
444 it != local_stats.end(); ++it) {
445 retval.push_back(it->ssrc);
446 }
447 return retval;
448 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100449 // Returns true if the media has been connected.
450 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000451 // Utility accessor for clients that make the assumption only one ssrc
452 // exists per media.
453 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100454 // Call sites that compare this to zero should use connected();
455 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200456 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100457 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000458 return local_stats[0].ssrc;
459 } else {
460 return 0;
461 }
462 }
463
Niels Möllerac0a4cb2019-10-09 15:01:33 +0200464 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-bytesreceived
465 int64_t payload_bytes_rcvd = 0;
466 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-headerbytesreceived
467 int64_t header_and_padding_bytes_rcvd = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800468 int packets_rcvd = 0;
469 int packets_lost = 0;
Henrik Boström01738c62019-04-15 17:32:00 +0200470 // The timestamp at which the last packet was received, i.e. the time of the
471 // local clock when it was received - not the RTP timestamp of that packet.
472 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
473 absl::optional<int64_t> last_packet_received_timestamp_ms;
Åsa Perssonfcf79cc2019-10-22 15:23:44 +0200474 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp
475 absl::optional<int64_t> estimated_playout_ntp_timestamp_ms;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000476 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200477 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000478 std::vector<SsrcReceiverInfo> local_stats;
479 std::vector<SsrcSenderInfo> remote_stats;
480};
481
482struct VoiceSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200483 VoiceSenderInfo();
484 ~VoiceSenderInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800485 int jitter_ms = 0;
Henrik Boströmd2c336f2019-07-03 17:11:10 +0200486 // Current audio level, expressed linearly [0,32767].
Steve Anton002f9212018-01-09 16:38:15 -0800487 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700488 // See description of "totalAudioEnergy" in the WebRTC stats spec:
489 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800490 double total_input_energy = 0.0;
491 double total_input_duration = 0.0;
Steve Anton002f9212018-01-09 16:38:15 -0800492 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700493 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100494 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000495};
496
wu@webrtc.org97077a32013-10-25 21:18:33 +0000497struct VoiceReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200498 VoiceReceiverInfo();
499 ~VoiceReceiverInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800500 int jitter_ms = 0;
501 int jitter_buffer_ms = 0;
502 int jitter_buffer_preferred_ms = 0;
503 int delay_estimate_ms = 0;
504 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200505 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
506 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800507 double total_output_energy = 0.0;
508 uint64_t total_samples_received = 0;
509 double total_output_duration = 0.0;
510 uint64_t concealed_samples = 0;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200511 uint64_t silent_concealed_samples = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800512 uint64_t concealment_events = 0;
Chen Xing0acffb52019-01-15 15:46:29 +0100513 double jitter_buffer_delay_seconds = 0.0;
514 uint64_t jitter_buffer_emitted_count = 0;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200515 uint64_t inserted_samples_for_deceleration = 0;
516 uint64_t removed_samples_for_acceleration = 0;
517 uint64_t fec_packets_received = 0;
518 uint64_t fec_packets_discarded = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200519 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000520 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800521 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000522 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800523 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000524 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800525 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200526 // Fraction of secondary data, including FEC and RED, that is discarded.
527 // Discarding of secondary data can be caused by the reception of the primary
528 // data, obsoleting the secondary data. It can also be caused by early
529 // or late arrival of secondary data. This metric is the percentage of
530 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800531 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200532 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800533 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200534 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800535 float preemptive_expand_rate = 0.0f;
536 int decoding_calls_to_silence_generator = 0;
537 int decoding_calls_to_neteq = 0;
538 int decoding_normal = 0;
Alex Narest5b5d97c2019-08-07 18:15:08 +0200539 // TODO(alexnarest): Consider decoding_neteq_plc for consistency
Steve Anton002f9212018-01-09 16:38:15 -0800540 int decoding_plc = 0;
Alex Narest5b5d97c2019-08-07 18:15:08 +0200541 int decoding_codec_plc = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800542 int decoding_cng = 0;
543 int decoding_plc_cng = 0;
544 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000545 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800546 int64_t capture_start_ntp_time_ms = -1;
Ruslan Burakov8af88962018-11-22 17:21:10 +0100547 // Count of the number of buffer flushes.
548 uint64_t jitter_buffer_flushes = 0;
Jakob Ivarsson352ce5c2018-11-27 12:52:16 +0100549 // Number of samples expanded due to delayed packets.
550 uint64_t delayed_packet_outage_samples = 0;
Jakob Ivarsson232b3fd2019-03-06 09:18:40 +0100551 // Arrival delay of received audio packets.
552 double relative_packet_arrival_delay_seconds = 0.0;
Henrik Lundin44125fa2019-04-29 17:00:46 +0200553 // Count and total duration of audio interruptions (loss-concealement periods
554 // longer than 150 ms).
555 int32_t interruption_count = 0;
556 int32_t total_interruption_duration_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557};
558
wu@webrtc.org97077a32013-10-25 21:18:33 +0000559struct VideoSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200560 VideoSenderInfo();
561 ~VideoSenderInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000562 std::vector<SsrcGroup> ssrc_groups;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100563 std::string encoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800564 int firs_rcvd = 0;
565 int plis_rcvd = 0;
566 int nacks_rcvd = 0;
567 int send_frame_width = 0;
568 int send_frame_height = 0;
569 int framerate_input = 0;
570 int framerate_sent = 0;
571 int nominal_bitrate = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800572 int adapt_reason = 0;
573 int adapt_changes = 0;
Henrik Boströmce33b6a2019-05-28 17:42:38 +0200574 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason
575 webrtc::QualityLimitationReason quality_limitation_reason =
576 webrtc::QualityLimitationReason::kNone;
577 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations
578 std::map<webrtc::QualityLimitationReason, int64_t>
579 quality_limitation_durations_ms;
Evan Shrubsolecc62b162019-09-09 11:26:45 +0200580 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges
581 uint32_t quality_limitation_resolution_changes = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800582 int avg_encode_ms = 0;
583 int encode_usage_percent = 0;
584 uint32_t frames_encoded = 0;
Rasmus Brandt2efae772019-06-27 14:29:34 +0200585 uint32_t key_frames_encoded = 0;
Henrik Boströmf71362f2019-04-08 16:14:23 +0200586 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodetime
587 uint64_t total_encode_time_ms = 0;
Henrik Boström23aff9b2019-05-20 15:15:38 +0200588 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget
589 uint64_t total_encoded_bytes_target = 0;
Henrik Boström9fe18342019-05-16 18:38:20 +0200590 uint64_t total_packet_send_delay_ms = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800591 bool has_entered_low_resolution = false;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200592 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800593 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100594 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
595 uint32_t huge_frames_sent = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596};
597
wu@webrtc.org97077a32013-10-25 21:18:33 +0000598struct VideoReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200599 VideoReceiverInfo();
600 ~VideoReceiverInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000601 std::vector<SsrcGroup> ssrc_groups;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100602 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800603 int packets_concealed = 0;
604 int firs_sent = 0;
605 int plis_sent = 0;
606 int nacks_sent = 0;
607 int frame_width = 0;
608 int frame_height = 0;
609 int framerate_rcvd = 0;
610 int framerate_decoded = 0;
611 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000612 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800613 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000614 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800615 int framerate_render_output = 0;
616 uint32_t frames_received = 0;
Johannes Kron0c141c52019-08-26 15:04:43 +0200617 uint32_t frames_dropped = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800618 uint32_t frames_decoded = 0;
Rasmus Brandt2efae772019-06-27 14:29:34 +0200619 uint32_t key_frames_decoded = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800620 uint32_t frames_rendered = 0;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200621 absl::optional<uint64_t> qp_sum;
Johannes Kronbfd343b2019-07-01 10:07:50 +0200622 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totaldecodetime
623 uint64_t total_decode_time_ms = 0;
Johannes Kron00376e12019-11-25 10:25:42 +0100624 double total_inter_frame_delay = 0;
625 double total_squared_inter_frame_delay = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800626 int64_t interframe_delay_max_ms = -1;
Sergey Silkin02371062019-01-31 16:45:42 +0100627 uint32_t freeze_count = 0;
628 uint32_t pause_count = 0;
629 uint32_t total_freezes_duration_ms = 0;
630 uint32_t total_pauses_duration_ms = 0;
631 uint32_t total_frames_duration_ms = 0;
632 double sum_squared_frame_durations = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000633
Steve Anton002f9212018-01-09 16:38:15 -0800634 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700635
wu@webrtc.org97077a32013-10-25 21:18:33 +0000636 // All stats below are gathered per-VideoReceiver, but some will be correlated
637 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
638 // structures, reflect this in the new layout.
639
640 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800641 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000642 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800643 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000644 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800645 int jitter_buffer_ms = 0;
Guido Urdaneta67378412019-05-28 17:38:08 +0200646 // Jitter (network-related) latency (cumulative).
647 // https://w3c.github.io/webrtc-stats/#dom-rtcvideoreceiverstats-jitterbufferdelay
648 double jitter_buffer_delay_seconds = 0;
649 // Number of observations for cumulative jitter latency.
650 // https://w3c.github.io/webrtc-stats/#dom-rtcvideoreceiverstats-jitterbufferemittedcount
651 uint64_t jitter_buffer_emitted_count = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000652 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800653 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000654 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800655 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000656 // Target overall delay: network+decode+render, accounting for
657 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800658 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000659 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800660 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000661
662 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800663 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700664
Benjamin Wright514f0842018-12-10 09:55:17 -0800665 // First frame received to first frame decoded latency.
666 int64_t first_frame_received_to_decoded_ms = -1;
667
ilnik2edc6842017-07-06 03:06:50 -0700668 // Timing frame info: all important timestamps for a full lifetime of a
669 // single 'timing frame'.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200670 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671};
672
wu@webrtc.org97077a32013-10-25 21:18:33 +0000673struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800674 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675};
676
wu@webrtc.org97077a32013-10-25 21:18:33 +0000677struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800678 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679};
680
681struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800682 int available_send_bandwidth = 0;
683 int available_recv_bandwidth = 0;
684 int target_enc_bitrate = 0;
685 int actual_enc_bitrate = 0;
686 int retransmit_bitrate = 0;
687 int transmit_bitrate = 0;
688 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689};
690
hbosa65704b2016-11-14 02:28:16 -0800691// Maps from payload type to |RtpCodecParameters|.
692typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
693
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694struct VoiceMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200695 VoiceMediaInfo();
696 ~VoiceMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 void Clear() {
698 senders.clear();
699 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800700 send_codecs.clear();
701 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702 }
703 std::vector<VoiceSenderInfo> senders;
704 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800705 RtpCodecParametersMap send_codecs;
706 RtpCodecParametersMap receive_codecs;
Alex Narestbbeb1092019-08-16 11:49:04 +0200707 int32_t device_underrun_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708};
709
710struct VideoMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200711 VideoMediaInfo();
712 ~VideoMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 void Clear() {
714 senders.clear();
715 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700716 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800717 send_codecs.clear();
718 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719 }
720 std::vector<VideoSenderInfo> senders;
721 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700722 // Deprecated.
723 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700724 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800725 RtpCodecParametersMap send_codecs;
726 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727};
728
729struct DataMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200730 DataMediaInfo();
731 ~DataMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 void Clear() {
733 senders.clear();
734 receivers.clear();
735 }
736 std::vector<DataSenderInfo> senders;
737 std::vector<DataReceiverInfo> receivers;
738};
739
deadbeef13871492015-12-09 12:37:51 -0800740struct RtcpParameters {
741 bool reduced_size = false;
Sebastian Janssone1795f42019-07-24 11:38:03 +0200742 bool remote_estimate = false;
deadbeef13871492015-12-09 12:37:51 -0800743};
744
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700745template <class Codec>
746struct RtpParameters {
Steve Anton003930a2018-03-29 12:37:21 -0700747 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700748
749 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700750 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700751 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800752 RtcpParameters rtcp;
Steve Anton003930a2018-03-29 12:37:21 -0700753
754 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200755 rtc::StringBuilder ost;
Steve Anton003930a2018-03-29 12:37:21 -0700756 ost << "{";
757 const char* separator = "";
758 for (const auto& entry : ToStringMap()) {
759 ost << separator << entry.first << ": " << entry.second;
760 separator = ", ";
761 }
762 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200763 return ost.Release();
Steve Anton003930a2018-03-29 12:37:21 -0700764 }
765
766 protected:
767 virtual std::map<std::string, std::string> ToStringMap() const {
768 return {{"codecs", VectorToString(codecs)},
769 {"extensions", VectorToString(extensions)}};
770 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700771};
772
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700773// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
774// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700775template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700776struct RtpSendParameters : RtpParameters<Codec> {
nisse05103312016-03-16 02:22:50 -0700777 int max_bandwidth_bps = -1;
Steve Antonbb50ce52018-03-26 10:24:32 -0700778 // This is the value to be sent in the MID RTP header extension (if the header
779 // extension in included in the list of extensions).
780 std::string mid;
Johannes Kron9190b822018-10-29 11:22:05 +0100781 bool extmap_allow_mixed = false;
Steve Anton003930a2018-03-29 12:37:21 -0700782
783 protected:
784 std::map<std::string, std::string> ToStringMap() const override {
785 auto params = RtpParameters<Codec>::ToStringMap();
786 params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps);
787 params["mid"] = (mid.empty() ? "<not set>" : mid);
Johannes Kron9190b822018-10-29 11:22:05 +0100788 params["extmap-allow-mixed"] = extmap_allow_mixed ? "true" : "false";
Steve Anton003930a2018-03-29 12:37:21 -0700789 return params;
790 }
nisse05103312016-03-16 02:22:50 -0700791};
792
793struct AudioSendParameters : RtpSendParameters<AudioCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200794 AudioSendParameters();
795 ~AudioSendParameters() override;
nisse05103312016-03-16 02:22:50 -0700796 AudioOptions options;
Steve Anton003930a2018-03-29 12:37:21 -0700797
798 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200799 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700800};
801
Yves Gerey665174f2018-06-19 15:03:05 +0200802struct AudioRecvParameters : RtpParameters<AudioCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700803
Ruslan Burakov493a6502019-02-27 15:32:48 +0100804class VoiceMediaChannel : public MediaChannel, public Delayable {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700807 explicit VoiceMediaChannel(const MediaConfig& config)
808 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200809 ~VoiceMediaChannel() override {}
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800810
811 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200812 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
813 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700814 // Get the receive parameters for the incoming stream identified by |ssrc|.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700815 virtual webrtc::RtpParameters GetRtpReceiveParameters(
816 uint32_t ssrc) const = 0;
Saurav Das749f6602019-12-04 09:31:36 -0800817 // Retrieve the receive parameters for the default receive
818 // stream, which is used when SSRCs are not signaled.
819 virtual webrtc::RtpParameters GetDefaultRtpReceiveParameters() const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700821 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800823 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700824 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200825 virtual bool SetAudioSend(uint32_t ssrc,
826 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700827 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800828 AudioSource* source) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700829 // Set speaker output volume of the specified ssrc.
830 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
Saurav Das749f6602019-12-04 09:31:36 -0800831 // Set speaker output volume for future unsignaled streams.
832 virtual bool SetDefaultOutputVolume(double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800834 virtual bool CanInsertDtmf() = 0;
835 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000837 // The valid value for the |event| are 0 to 15 which corresponding to
838 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800839 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 // Gets quality stats for the channel.
841 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100842
843 virtual void SetRawAudioSink(
844 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800845 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
Saurav Das749f6602019-12-04 09:31:36 -0800846 virtual void SetDefaultRawAudioSink(
847 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700848
849 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850};
851
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700852// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
853// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700854struct VideoSendParameters : RtpSendParameters<VideoCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200855 VideoSendParameters();
856 ~VideoSendParameters() override;
nisse4b4dc862016-02-17 05:25:36 -0800857 // Use conference mode? This flag comes from the remote
858 // description's SDP line 'a=x-google-flag:conference', copied over
859 // by VideoChannel::SetRemoteContent_w, and ultimately used by
860 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700861 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800862 // The special screencast behaviour is disabled by default.
863 bool conference_mode = false;
Steve Anton003930a2018-03-29 12:37:21 -0700864
865 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200866 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700867};
868
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700869// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
870// encapsulate all the parameters needed for a video RtpReceiver.
Yves Gerey665174f2018-06-19 15:03:05 +0200871struct VideoRecvParameters : RtpParameters<VideoCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700872
Ruslan Burakov493a6502019-02-27 15:32:48 +0100873class VideoMediaChannel : public MediaChannel, public Delayable {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 public:
nisse08582ff2016-02-04 01:24:52 -0800875 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700876 explicit VideoMediaChannel(const MediaConfig& config)
877 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200878 ~VideoMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200879
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800880 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200881 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
882 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700883 // Get the receive parameters for the incoming stream identified by |ssrc|.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700884 virtual webrtc::RtpParameters GetRtpReceiveParameters(
885 uint32_t ssrc) const = 0;
Saurav Das749f6602019-12-04 09:31:36 -0800886 // Retrieve the receive parameters for the default receive
887 // stream, which is used when SSRCs are not signaled.
888 virtual webrtc::RtpParameters GetDefaultRtpReceiveParameters() const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 // Gets the currently set codecs/payload types to be used for outgoing media.
890 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 // Starts or stops transmission (and potentially capture) of local video.
892 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700893 // Configure stream for sending and register a source.
894 // The |ssrc| must correspond to a registered send stream.
895 virtual bool SetVideoSend(
896 uint32_t ssrc,
deadbeef5a4a75a2016-06-02 16:23:38 -0700897 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800898 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800899 // Sets the sink object to be used for the specified stream.
nisse08582ff2016-02-04 01:24:52 -0800900 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800901 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
Saurav Das749f6602019-12-04 09:31:36 -0800902 // The sink is used for the 'default' stream.
903 virtual void SetDefaultSink(
904 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700905 // This fills the "bitrate parts" (rtx, video bitrate) of the
906 // BandwidthEstimationInfo, since that part that isn't possible to get
907 // through webrtc::Call::GetStats, as they are statistics of the send
908 // streams.
909 // TODO(holmer): We should change this so that either BWE graphs doesn't
910 // need access to bitrates of the streams, or change the (RTC)StatsCollector
911 // so that it's getting the send stream stats separately by calling
912 // GetStats(), and merges with BandwidthEstimationInfo by itself.
913 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000915 virtual bool GetStats(VideoMediaInfo* info) = 0;
Markus Handell32565f62019-12-04 10:58:17 +0100916 // Set recordable encoded frame callback for |ssrc|
917 virtual void SetRecordableEncodedFrameCallback(
918 uint32_t ssrc,
919 std::function<void(const webrtc::RecordableEncodedFrame&)> callback) = 0;
920 // Clear recordable encoded frame callback for |ssrc|
921 virtual void ClearRecordableEncodedFrameCallback(uint32_t ssrc) = 0;
922 // Cause generation of a keyframe for |ssrc|
923 virtual void GenerateKeyFrame(uint32_t ssrc) = 0;
Jonas Oreland49ac5952018-09-26 16:04:32 +0200924
925 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926};
927
928enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000929 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
930 // values.
931 DMT_NONE = 0,
932 DMT_CONTROL = 1,
933 DMT_BINARY = 2,
934 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935};
936
937// Info about data received in DataMediaChannel. For use in
938// DataMediaChannel::SignalDataReceived and in all of the signals that
939// signal fires, on up the chain.
940struct ReceiveDataParams {
941 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800942 // RTP data channels use SSRCs, SCTP data channels use SIDs.
943 union {
944 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800945 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800946 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800948 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800950 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800952 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953};
954
955struct SendDataParams {
956 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800957 // RTP data channels use SSRCs, SCTP data channels use SIDs.
958 union {
959 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800960 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800961 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800963 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964
Steve Anton002f9212018-01-09 16:38:15 -0800965 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 // For SCTP, whether to send messages flagged as ordered or not.
967 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800968 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 // For SCTP, whether the messages are sent reliably or not.
970 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800971 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 // For SCTP, if reliable == false, provide partial reliability by
973 // resending up to this many times. Either count or millis
974 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800975 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 // For SCTP, if reliable == false, provide partial reliability by
977 // resending for up to this many milliseconds. Either count or millis
978 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800979 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980};
981
982enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
983
Yves Gerey665174f2018-06-19 15:03:05 +0200984struct DataSendParameters : RtpSendParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700985
Yves Gerey665174f2018-06-19 15:03:05 +0200986struct DataRecvParameters : RtpParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700987
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988class DataMediaChannel : public MediaChannel {
989 public:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200990 DataMediaChannel();
991 explicit DataMediaChannel(const MediaConfig& config);
992 ~DataMediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800994 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200995 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
996 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000997
Amit Hilbuchea7ef2a2019-02-19 15:20:21 -0800998 // RtpParameter methods are not supported for Data channel.
999 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
1000 webrtc::RTCError SetRtpSendParameters(
1001 uint32_t ssrc,
1002 const webrtc::RtpParameters& parameters) override;
1003
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 // TODO(pthatcher): Implement this.
Paulina Hensman11b34f42018-04-09 14:24:52 +02001005 virtual bool GetStats(DataMediaInfo* info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006
1007 virtual bool SetSend(bool send) = 0;
1008 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009
Paulina Hensman11b34f42018-04-09 14:24:52 +02001010 void OnNetworkRouteChanged(const std::string& transport_name,
1011 const rtc::NetworkRoute& network_route) override {}
Honghai Zhangcc411c02016-03-29 17:27:21 -07001012
Yves Gerey665174f2018-06-19 15:03:05 +02001013 virtual bool SendData(const SendDataParams& params,
1014 const rtc::CopyOnWriteBuffer& payload,
1015 SendDataResult* result = NULL) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 // Signals when data is received (params, data, len)
Yves Gerey665174f2018-06-19 15:03:05 +02001017 sigslot::signal3<const ReceiveDataParams&, const char*, size_t>
1018 SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001019 // Signal when the media channel is ready to send the stream. Arguments are:
1020 // writable(bool)
1021 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022};
1023
1024} // namespace cricket
1025
Steve Anton10542f22019-01-11 09:11:00 -08001026#endif // MEDIA_BASE_MEDIA_CHANNEL_H_