blob: 8ee4a238a1e0720b77947350ce6a0efccae047a5 [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"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/rtc_error.h"
27#include "api/rtp_parameters.h"
Niels Möller65f17ca2019-09-12 13:59:36 +020028#include "api/transport/media/media_transport_config.h"
Niels Möllera8370302019-09-02 15:16:49 +020029#include "api/transport/rtp/rtp_source.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010030#include "api/video/video_content_type.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020031#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020032#include "api/video/video_source_interface.h"
33#include "api/video/video_timing.h"
34#include "api/video_codecs/video_encoder_config.h"
Markus Handell32565f62019-12-04 10:58:17 +010035#include "call/video_receive_stream.h"
Henrik Boströmce33b6a2019-05-28 17:42:38 +020036#include "common_video/include/quality_limitation_reason.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020037#include "media/base/codec.h"
Ruslan Burakov493a6502019-02-27 15:32:48 +010038#include "media/base/delayable.h"
Steve Anton10542f22019-01-11 09:11:00 -080039#include "media/base/media_config.h"
40#include "media/base/media_constants.h"
41#include "media/base/stream_params.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010042#include "modules/audio_processing/include/audio_processing_statistics.h"
Henrik Boström87e3f9d2019-05-27 10:44:24 +020043#include "modules/rtp_rtcp/include/report_block_data.h"
Steve Anton10542f22019-01-11 09:11:00 -080044#include "rtc_base/async_packet_socket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020045#include "rtc_base/buffer.h"
Markus Handell32565f62019-12-04 10:58:17 +010046#include "rtc_base/callback.h"
Steve Anton10542f22019-01-11 09:11:00 -080047#include "rtc_base/copy_on_write_buffer.h"
Niels Möllera8370302019-09-02 15:16:49 +020048#include "rtc_base/critical_section.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020049#include "rtc_base/dscp.h"
50#include "rtc_base/logging.h"
Steve Anton10542f22019-01-11 09:11:00 -080051#include "rtc_base/network_route.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020052#include "rtc_base/socket.h"
Steve Anton10542f22019-01-11 09:11:00 -080053#include "rtc_base/string_encode.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020054#include "rtc_base/strings/string_builder.h"
Artem Titove41c4332018-07-25 15:04:28 +020055#include "rtc_base/third_party/sigslot/sigslot.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010056
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000057namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058class Timing;
59}
60
Tommif888bb52015-12-12 01:37:01 +010061namespace webrtc {
62class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080063class VideoFrame;
Yves Gerey665174f2018-06-19 15:03:05 +020064} // namespace webrtc
Tommif888bb52015-12-12 01:37:01 +010065
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066namespace cricket {
67
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080068class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080070struct RtpHeader;
71struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073const int kScreencastDefaultFps = 5;
74
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075template <class T>
Danil Chapovalov00c71832018-06-15 15:58:38 +020076static std::string ToStringIfSet(const char* key,
77 const absl::optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070079 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080 str = key;
81 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070082 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083 str += ", ";
84 }
85 return str;
86}
87
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070088template <class T>
89static std::string VectorToString(const std::vector<T>& vals) {
Jonas Olsson366a50c2018-09-06 13:41:30 +020090 rtc::StringBuilder ost; // no-presubmit-check TODO(webrtc:8982)
Yves Gerey665174f2018-06-19 15:03:05 +020091 ost << "[";
92 for (size_t i = 0; i < vals.size(); ++i) {
93 if (i > 0) {
94 ost << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070095 }
Yves Gerey665174f2018-06-19 15:03:05 +020096 ost << vals[i].ToString();
97 }
98 ost << "]";
Jonas Olsson84df1c72018-09-14 16:59:32 +020099 return ost.Release();
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700100}
101
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
103// Used to be flags, but that makes it hard to selectively apply options.
104// We are moving all of the setting of options to structs like this,
105// but some things currently still use flags.
106struct VideoOptions {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200107 VideoOptions();
108 ~VideoOptions();
109
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700111 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800112 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100113 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114 }
115
116 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800117 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100118 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
119 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120 }
deadbeef119760a2016-04-04 11:43:27 -0700121 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122
123 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200124 rtc::StringBuilder ost;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800127 ost << ToStringIfSet("screencast min bitrate kbps",
128 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100129 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200131 return ost.Release();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132 }
133
nisseb163c3f2016-01-29 01:14:38 -0800134 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700135 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800136 // on to the codec options. Disabled by default.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200137 absl::optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800138 // Force screencast to use a minimum bitrate. This flag comes from
139 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700140 // copied to the encoder config by WebRtcVideoChannel.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200141 absl::optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100142 // Set by screencast sources. Implies selection of encoding settings
143 // suitable for screencast. Most likely not the right way to do
144 // things, e.g., screencast of a text document and screencast of a
145 // youtube video have different needs.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200146 absl::optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700147
148 private:
149 template <typename T>
Danil Chapovalov00c71832018-06-15 15:58:38 +0200150 static void SetFrom(absl::optional<T>* s, const absl::optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700151 if (o) {
152 *s = o;
153 }
154 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155};
156
isheriffa1c548b2016-05-31 16:12:24 -0700157// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
158struct RtpHeaderExtension {
159 RtpHeaderExtension() : id(0) {}
160 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
161
162 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200163 rtc::StringBuilder ost;
isheriffa1c548b2016-05-31 16:12:24 -0700164 ost << "{";
165 ost << "uri: " << uri;
166 ost << ", id: " << id;
167 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200168 return ost.Release();
isheriffa1c548b2016-05-31 16:12:24 -0700169 }
170
171 std::string uri;
172 int id;
173};
174
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175class MediaChannel : public sigslot::has_slots<> {
176 public:
177 class NetworkInterface {
178 public:
179 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700180 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700181 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700182 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700183 const rtc::PacketOptions& options) = 0;
Yves Gerey665174f2018-06-19 15:03:05 +0200184 virtual int SetOption(SocketType type,
185 rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 int option) = 0;
187 virtual ~NetworkInterface() {}
188 };
189
Benjamin Wright84583f62018-10-04 14:22:34 -0700190 explicit MediaChannel(const MediaConfig& config);
191 MediaChannel();
192 ~MediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800194 virtual cricket::MediaType media_type() const = 0;
195
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700196 // Sets the abstract interface class for sending RTP/RTCP data and
197 // interface for media transport (experimental). If media transport is
198 // provided, it should be used instead of RTP/RTCP.
199 // TODO(sukhanov): Currently media transport can co-exist with RTP/RTCP, but
200 // in the future we will refactor code to send all frames with media
201 // transport.
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700202 virtual void SetInterface(
203 NetworkInterface* iface,
204 const webrtc::MediaTransportConfig& media_transport_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 // Called when a RTP packet is received.
Amit Hilbuche7a5f7b2019-03-12 11:10:27 -0700206 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
Niels Möllere6933812018-11-05 13:01:41 +0100207 int64_t packet_time_us) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 // Called when the socket's ability to send has changed.
209 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700210 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700211 virtual void OnNetworkRouteChanged(
212 const std::string& transport_name,
213 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 // Creates a new outgoing media stream with SSRCs and CNAME as described
215 // by sp.
216 virtual bool AddSendStream(const StreamParams& sp) = 0;
217 // Removes an outgoing media stream.
Seth Hampson5897a6e2018-04-03 11:16:33 -0700218 // SSRC must be the first SSRC of the media stream if the stream uses
219 // multiple SSRCs. In the case of an ssrc of 0, the possibly cached
220 // StreamParams is removed.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200221 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700222 // Creates a new incoming media stream with SSRCs, CNAME as described
223 // by sp. In the case of a sp without SSRCs, the unsignaled sp is cached
224 // to be used later for unsignaled streams received.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 virtual bool AddRecvStream(const StreamParams& sp) = 0;
226 // Removes an incoming media stream.
227 // ssrc must be the first SSRC of the media stream if the stream uses
228 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200229 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
Saurav Dasff27da52019-09-20 11:05:30 -0700230 // Resets any cached StreamParams for an unsignaled RecvStream.
231 virtual void ResetUnsignaledRecvStream() = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000232 // Returns the absoulte sendtime extension id value from media channel.
Paulina Hensman11b34f42018-04-09 14:24:52 +0200233 virtual int GetRtpSendTimeExtnId() const;
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700234 // Set the frame encryptor to use on all outgoing frames. This is optional.
235 // This pointers lifetime is managed by the set of RtpSender it is attached
236 // 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 SetFrameEncryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700239 uint32_t ssrc,
240 rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor);
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700241 // Set the frame decryptor to use on all incoming frames. This is optional.
242 // This pointers lifetimes is managed by the set of RtpReceivers it is
243 // attached to.
Benjamin Wright84583f62018-10-04 14:22:34 -0700244 // TODO(benwright) make pure virtual once internal supports it.
Benjamin Wrightbfd412e2018-09-10 14:06:02 -0700245 virtual void SetFrameDecryptor(
Benjamin Wright84583f62018-10-04 14:22:34 -0700246 uint32_t ssrc,
247 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248
philipel16cec3b2019-10-25 12:23:02 +0200249 // Enable network condition based codec switching.
250 virtual void SetVideoCodecSwitchingEnabled(bool enabled);
251
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000252 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700253 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
254 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700255 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000256 }
257
jbaucheec21bd2016-03-20 06:15:43 -0700258 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
259 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700260 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000261 }
262
263 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000264 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000265 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000266 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000267 if (!network_interface_)
268 return -1;
269
270 return network_interface_->SetOption(type, opt, option);
271 }
272
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700273 const webrtc::MediaTransportConfig& media_transport_config() const {
274 return media_transport_config_;
275 }
276
Johannes Kron9190b822018-10-29 11:22:05 +0100277 // Corresponds to the SDP attribute extmap-allow-mixed, see RFC8285.
278 // Set to true if it's allowed to mix one- and two-byte RTP header extensions
279 // in the same stream. The setter and getter must only be called from
280 // worker_thread.
281 void SetExtmapAllowMixed(bool extmap_allow_mixed) {
282 extmap_allow_mixed_ = extmap_allow_mixed;
283 }
284 bool ExtmapAllowMixed() const { return extmap_allow_mixed_; }
285
Amit Hilbuchea7ef2a2019-02-19 15:20:21 -0800286 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
287 virtual webrtc::RTCError SetRtpSendParameters(
288 uint32_t ssrc,
289 const webrtc::RtpParameters& parameters) = 0;
290
Marina Cioceae77912b2020-02-27 16:16:55 +0100291 virtual void SetEncoderToPacketizerFrameTransformer(
292 uint32_t ssrc,
293 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer);
Marina Ciocea412a31b2020-02-28 16:02:06 +0100294 virtual void SetDepacketizerToDecoderFrameTransformer(
295 uint32_t ssrc,
296 rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer);
Marina Cioceae77912b2020-02-27 16:16:55 +0100297
Tim Haloun6ca98362018-09-17 17:06:08 -0700298 protected:
Tim Haloun6ca98362018-09-17 17:06:08 -0700299 bool DscpEnabled() const { return enable_dscp_; }
300
Steve Antone25f5952019-03-08 15:09:16 -0800301 // This is the DSCP value used for both RTP and RTCP channels if DSCP is
302 // enabled. It can be changed at any time via |SetPreferredDscp|.
303 rtc::DiffServCodePoint PreferredDscp() const {
304 rtc::CritScope cs(&network_interface_crit_);
305 return preferred_dscp_;
306 }
307
308 int SetPreferredDscp(rtc::DiffServCodePoint preferred_dscp) {
309 rtc::CritScope cs(&network_interface_crit_);
310 if (preferred_dscp == preferred_dscp_) {
311 return 0;
312 }
313 preferred_dscp_ = preferred_dscp;
314 return UpdateDscp();
315 }
316
317 private:
318 // Apply the preferred DSCP setting to the underlying network interface RTP
319 // and RTCP channels. If DSCP is disabled, then apply the default DSCP value.
320 int UpdateDscp() RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_crit_) {
Tim Haloun648d28a2018-10-18 16:52:22 -0700321 rtc::DiffServCodePoint value =
Steve Antone25f5952019-03-08 15:09:16 -0800322 enable_dscp_ ? preferred_dscp_ : rtc::DSCP_DEFAULT;
323 int ret = SetOption(NetworkInterface::ST_RTP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000324 if (ret == 0) {
Yves Gerey665174f2018-06-19 15:03:05 +0200325 ret = SetOption(NetworkInterface::ST_RTCP, rtc::Socket::OPT_DSCP, value);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000326 }
327 return ret;
328 }
329
jbaucheec21bd2016-03-20 06:15:43 -0700330 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700331 bool rtcp,
332 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000333 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000334 if (!network_interface_)
335 return false;
336
stefanc1aeaf02015-10-15 07:26:07 -0700337 return (!rtcp) ? network_interface_->SendPacket(packet, options)
338 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000339 }
340
nisse51542be2016-02-12 02:27:06 -0800341 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000342 // |network_interface_| can be accessed from the worker_thread and
343 // from any MediaEngine threads. This critical section is to protect accessing
344 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000345 rtc::CriticalSection network_interface_crit_;
Steve Antone25f5952019-03-08 15:09:16 -0800346 NetworkInterface* network_interface_ RTC_GUARDED_BY(network_interface_crit_) =
347 nullptr;
348 rtc::DiffServCodePoint preferred_dscp_
349 RTC_GUARDED_BY(network_interface_crit_) = rtc::DSCP_DEFAULT;
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700350 webrtc::MediaTransportConfig media_transport_config_;
Johannes Kron9190b822018-10-29 11:22:05 +0100351 bool extmap_allow_mixed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352};
353
wu@webrtc.org97077a32013-10-25 21:18:33 +0000354// The stats information is structured as follows:
355// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
356// Media contains a vector of SSRC infos that are exclusively used by this
357// media. (SSRCs shared between media streams can't be represented.)
358
359// Information about an SSRC.
360// This data may be locally recorded, or received in an RTCP SR or RR.
361struct SsrcSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800362 uint32_t ssrc = 0;
363 double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000364};
365
366struct SsrcReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800367 uint32_t ssrc = 0;
368 double timestamp = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000369};
370
371struct MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200372 MediaSenderInfo();
373 ~MediaSenderInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200374 void add_ssrc(const SsrcSenderInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000375 // Temporary utility function for call sites that only provide SSRC.
376 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200377 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000378 SsrcSenderInfo stat;
379 stat.ssrc = ssrc;
380 add_ssrc(stat);
381 }
382 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200383 std::vector<uint32_t> ssrcs() const {
384 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000385 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
386 it != local_stats.end(); ++it) {
387 retval.push_back(it->ssrc);
388 }
389 return retval;
390 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100391 // Returns true if the media has been connected.
392 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000393 // Utility accessor for clients that make the assumption only one ssrc
394 // exists per media.
395 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100396 // Call sites that compare this to zero should use connected() instead.
397 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200398 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100399 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000400 return local_stats[0].ssrc;
401 } else {
402 return 0;
403 }
404 }
Niels Möllerac0a4cb2019-10-09 15:01:33 +0200405 // https://w3c.github.io/webrtc-stats/#dom-rtcsentrtpstreamstats-bytessent
406 int64_t payload_bytes_sent = 0;
407 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-headerbytessent
408 int64_t header_and_padding_bytes_sent = 0;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200409 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent
410 uint64_t retransmitted_bytes_sent = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800411 int packets_sent = 0;
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200412 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent
413 uint64_t retransmitted_packets_sent = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800414 int packets_lost = 0;
415 float fraction_lost = 0.0f;
416 int64_t rtt_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000417 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200418 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000419 std::vector<SsrcSenderInfo> local_stats;
420 std::vector<SsrcReceiverInfo> remote_stats;
Henrik Boström87e3f9d2019-05-27 10:44:24 +0200421 // A snapshot of the most recent Report Block with additional data of interest
422 // to statistics. Used to implement RTCRemoteInboundRtpStreamStats. Within
423 // this list, the ReportBlockData::RTCPReportBlock::source_ssrc(), which is
424 // the SSRC of the corresponding outbound RTP stream, is unique.
425 std::vector<webrtc::ReportBlockData> report_block_datas;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000426};
427
428struct MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200429 MediaReceiverInfo();
430 ~MediaReceiverInfo();
Yves Gerey665174f2018-06-19 15:03:05 +0200431 void add_ssrc(const SsrcReceiverInfo& stat) { local_stats.push_back(stat); }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000432 // Temporary utility function for call sites that only provide SSRC.
433 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200434 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000435 SsrcReceiverInfo stat;
436 stat.ssrc = ssrc;
437 add_ssrc(stat);
438 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200439 std::vector<uint32_t> ssrcs() const {
440 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000441 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
442 it != local_stats.end(); ++it) {
443 retval.push_back(it->ssrc);
444 }
445 return retval;
446 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100447 // Returns true if the media has been connected.
448 bool connected() const { return local_stats.size() > 0; }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000449 // Utility accessor for clients that make the assumption only one ssrc
450 // exists per media.
451 // This will eventually go away.
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100452 // Call sites that compare this to zero should use connected();
453 // https://bugs.webrtc.org/8694
Peter Boström0c4e06b2015-10-07 12:23:21 +0200454 uint32_t ssrc() const {
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100455 if (connected()) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000456 return local_stats[0].ssrc;
457 } else {
458 return 0;
459 }
460 }
461
Niels Möllerac0a4cb2019-10-09 15:01:33 +0200462 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-bytesreceived
463 int64_t payload_bytes_rcvd = 0;
464 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-headerbytesreceived
465 int64_t header_and_padding_bytes_rcvd = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800466 int packets_rcvd = 0;
467 int packets_lost = 0;
Henrik Boström01738c62019-04-15 17:32:00 +0200468 // The timestamp at which the last packet was received, i.e. the time of the
469 // local clock when it was received - not the RTP timestamp of that packet.
470 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
471 absl::optional<int64_t> last_packet_received_timestamp_ms;
Åsa Perssonfcf79cc2019-10-22 15:23:44 +0200472 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp
473 absl::optional<int64_t> estimated_playout_ntp_timestamp_ms;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000474 std::string codec_name;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200475 absl::optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000476 std::vector<SsrcReceiverInfo> local_stats;
477 std::vector<SsrcSenderInfo> remote_stats;
478};
479
480struct VoiceSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200481 VoiceSenderInfo();
482 ~VoiceSenderInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800483 int jitter_ms = 0;
Henrik Boströmd2c336f2019-07-03 17:11:10 +0200484 // Current audio level, expressed linearly [0,32767].
Steve Anton002f9212018-01-09 16:38:15 -0800485 int audio_level = 0;
zsteine76bd3a2017-07-14 12:17:49 -0700486 // See description of "totalAudioEnergy" in the WebRTC stats spec:
487 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
Steve Anton002f9212018-01-09 16:38:15 -0800488 double total_input_energy = 0.0;
489 double total_input_duration = 0.0;
Steve Anton002f9212018-01-09 16:38:15 -0800490 bool typing_noise_detected = false;
ivoce1198e02017-09-08 08:13:19 -0700491 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100492 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493};
494
wu@webrtc.org97077a32013-10-25 21:18:33 +0000495struct VoiceReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200496 VoiceReceiverInfo();
497 ~VoiceReceiverInfo();
Steve Anton002f9212018-01-09 16:38:15 -0800498 int jitter_ms = 0;
499 int jitter_buffer_ms = 0;
500 int jitter_buffer_preferred_ms = 0;
501 int delay_estimate_ms = 0;
502 int audio_level = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200503 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
504 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
Steve Anton002f9212018-01-09 16:38:15 -0800505 double total_output_energy = 0.0;
506 uint64_t total_samples_received = 0;
507 double total_output_duration = 0.0;
508 uint64_t concealed_samples = 0;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200509 uint64_t silent_concealed_samples = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800510 uint64_t concealment_events = 0;
Chen Xing0acffb52019-01-15 15:46:29 +0100511 double jitter_buffer_delay_seconds = 0.0;
512 uint64_t jitter_buffer_emitted_count = 0;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200513 uint64_t inserted_samples_for_deceleration = 0;
514 uint64_t removed_samples_for_acceleration = 0;
515 uint64_t fec_packets_received = 0;
516 uint64_t fec_packets_discarded = 0;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200517 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000518 // fraction of synthesized audio inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800519 float expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000520 // fraction of synthesized speech inserted through expansion.
Steve Anton002f9212018-01-09 16:38:15 -0800521 float speech_expand_rate = 0.0f;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000522 // fraction of data out of secondary decoding, including FEC and RED.
Steve Anton002f9212018-01-09 16:38:15 -0800523 float secondary_decoded_rate = 0.0f;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200524 // Fraction of secondary data, including FEC and RED, that is discarded.
525 // Discarding of secondary data can be caused by the reception of the primary
526 // data, obsoleting the secondary data. It can also be caused by early
527 // or late arrival of secondary data. This metric is the percentage of
528 // discarded secondary data since last query of receiver info.
Steve Anton002f9212018-01-09 16:38:15 -0800529 float secondary_discarded_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200530 // Fraction of data removed through time compression.
Steve Anton002f9212018-01-09 16:38:15 -0800531 float accelerate_rate = 0.0f;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200532 // Fraction of data inserted through time stretching.
Steve Anton002f9212018-01-09 16:38:15 -0800533 float preemptive_expand_rate = 0.0f;
534 int decoding_calls_to_silence_generator = 0;
535 int decoding_calls_to_neteq = 0;
536 int decoding_normal = 0;
Alex Narest5b5d97c2019-08-07 18:15:08 +0200537 // TODO(alexnarest): Consider decoding_neteq_plc for consistency
Steve Anton002f9212018-01-09 16:38:15 -0800538 int decoding_plc = 0;
Alex Narest5b5d97c2019-08-07 18:15:08 +0200539 int decoding_codec_plc = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800540 int decoding_cng = 0;
541 int decoding_plc_cng = 0;
542 int decoding_muted_output = 0;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000543 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800544 int64_t capture_start_ntp_time_ms = -1;
Ruslan Burakov8af88962018-11-22 17:21:10 +0100545 // Count of the number of buffer flushes.
546 uint64_t jitter_buffer_flushes = 0;
Jakob Ivarsson352ce5c2018-11-27 12:52:16 +0100547 // Number of samples expanded due to delayed packets.
548 uint64_t delayed_packet_outage_samples = 0;
Jakob Ivarsson232b3fd2019-03-06 09:18:40 +0100549 // Arrival delay of received audio packets.
550 double relative_packet_arrival_delay_seconds = 0.0;
Henrik Lundin44125fa2019-04-29 17:00:46 +0200551 // Count and total duration of audio interruptions (loss-concealement periods
552 // longer than 150 ms).
553 int32_t interruption_count = 0;
554 int32_t total_interruption_duration_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555};
556
wu@webrtc.org97077a32013-10-25 21:18:33 +0000557struct VideoSenderInfo : public MediaSenderInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200558 VideoSenderInfo();
559 ~VideoSenderInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000560 std::vector<SsrcGroup> ssrc_groups;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100561 std::string encoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800562 int firs_rcvd = 0;
563 int plis_rcvd = 0;
564 int nacks_rcvd = 0;
565 int send_frame_width = 0;
566 int send_frame_height = 0;
567 int framerate_input = 0;
568 int framerate_sent = 0;
569 int nominal_bitrate = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800570 int adapt_reason = 0;
571 int adapt_changes = 0;
Henrik Boströmce33b6a2019-05-28 17:42:38 +0200572 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason
573 webrtc::QualityLimitationReason quality_limitation_reason =
574 webrtc::QualityLimitationReason::kNone;
575 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations
576 std::map<webrtc::QualityLimitationReason, int64_t>
577 quality_limitation_durations_ms;
Evan Shrubsolecc62b162019-09-09 11:26:45 +0200578 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges
579 uint32_t quality_limitation_resolution_changes = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800580 int avg_encode_ms = 0;
581 int encode_usage_percent = 0;
582 uint32_t frames_encoded = 0;
Rasmus Brandt2efae772019-06-27 14:29:34 +0200583 uint32_t key_frames_encoded = 0;
Henrik Boströmf71362f2019-04-08 16:14:23 +0200584 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodetime
585 uint64_t total_encode_time_ms = 0;
Henrik Boström23aff9b2019-05-20 15:15:38 +0200586 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalencodedbytestarget
587 uint64_t total_encoded_bytes_target = 0;
Henrik Boström9fe18342019-05-16 18:38:20 +0200588 uint64_t total_packet_send_delay_ms = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800589 bool has_entered_low_resolution = false;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200590 absl::optional<uint64_t> qp_sum;
Steve Anton002f9212018-01-09 16:38:15 -0800591 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100592 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent
593 uint32_t huge_frames_sent = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594};
595
wu@webrtc.org97077a32013-10-25 21:18:33 +0000596struct VideoReceiverInfo : public MediaReceiverInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200597 VideoReceiverInfo();
598 ~VideoReceiverInfo();
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000599 std::vector<SsrcGroup> ssrc_groups;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100600 std::string decoder_implementation_name;
Steve Anton002f9212018-01-09 16:38:15 -0800601 int packets_concealed = 0;
602 int firs_sent = 0;
603 int plis_sent = 0;
604 int nacks_sent = 0;
605 int frame_width = 0;
606 int frame_height = 0;
607 int framerate_rcvd = 0;
608 int framerate_decoded = 0;
609 int framerate_output = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000610 // Framerate as sent to the renderer.
Steve Anton002f9212018-01-09 16:38:15 -0800611 int framerate_render_input = 0;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000612 // Framerate that the renderer reports.
Steve Anton002f9212018-01-09 16:38:15 -0800613 int framerate_render_output = 0;
614 uint32_t frames_received = 0;
Johannes Kron0c141c52019-08-26 15:04:43 +0200615 uint32_t frames_dropped = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800616 uint32_t frames_decoded = 0;
Rasmus Brandt2efae772019-06-27 14:29:34 +0200617 uint32_t key_frames_decoded = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800618 uint32_t frames_rendered = 0;
Danil Chapovalov00c71832018-06-15 15:58:38 +0200619 absl::optional<uint64_t> qp_sum;
Johannes Kronbfd343b2019-07-01 10:07:50 +0200620 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totaldecodetime
621 uint64_t total_decode_time_ms = 0;
Johannes Kron00376e12019-11-25 10:25:42 +0100622 double total_inter_frame_delay = 0;
623 double total_squared_inter_frame_delay = 0;
Steve Anton002f9212018-01-09 16:38:15 -0800624 int64_t interframe_delay_max_ms = -1;
Sergey Silkin02371062019-01-31 16:45:42 +0100625 uint32_t freeze_count = 0;
626 uint32_t pause_count = 0;
627 uint32_t total_freezes_duration_ms = 0;
628 uint32_t total_pauses_duration_ms = 0;
629 uint32_t total_frames_duration_ms = 0;
630 double sum_squared_frame_durations = 0.0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000631
Steve Anton002f9212018-01-09 16:38:15 -0800632 webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED;
ilnik2e1b40b2017-09-04 07:57:17 -0700633
wu@webrtc.org97077a32013-10-25 21:18:33 +0000634 // All stats below are gathered per-VideoReceiver, but some will be correlated
635 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
636 // structures, reflect this in the new layout.
637
638 // Current frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800639 int decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000640 // Maximum observed frame decode latency.
Steve Anton002f9212018-01-09 16:38:15 -0800641 int max_decode_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000642 // Jitter (network-related) latency.
Steve Anton002f9212018-01-09 16:38:15 -0800643 int jitter_buffer_ms = 0;
Guido Urdaneta67378412019-05-28 17:38:08 +0200644 // Jitter (network-related) latency (cumulative).
645 // https://w3c.github.io/webrtc-stats/#dom-rtcvideoreceiverstats-jitterbufferdelay
646 double jitter_buffer_delay_seconds = 0;
647 // Number of observations for cumulative jitter latency.
648 // https://w3c.github.io/webrtc-stats/#dom-rtcvideoreceiverstats-jitterbufferemittedcount
649 uint64_t jitter_buffer_emitted_count = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000650 // Requested minimum playout latency.
Steve Anton002f9212018-01-09 16:38:15 -0800651 int min_playout_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000652 // Requested latency to account for rendering delay.
Steve Anton002f9212018-01-09 16:38:15 -0800653 int render_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000654 // Target overall delay: network+decode+render, accounting for
655 // min_playout_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800656 int target_delay_ms = 0;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000657 // Current overall delay, possibly ramping towards target_delay_ms.
Steve Anton002f9212018-01-09 16:38:15 -0800658 int current_delay_ms = 0;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000659
660 // Estimated capture start time in NTP time in ms.
Steve Anton002f9212018-01-09 16:38:15 -0800661 int64_t capture_start_ntp_time_ms = -1;
ilnik2edc6842017-07-06 03:06:50 -0700662
Benjamin Wright514f0842018-12-10 09:55:17 -0800663 // First frame received to first frame decoded latency.
664 int64_t first_frame_received_to_decoded_ms = -1;
665
ilnik2edc6842017-07-06 03:06:50 -0700666 // Timing frame info: all important timestamps for a full lifetime of a
667 // single 'timing frame'.
Danil Chapovalov00c71832018-06-15 15:58:38 +0200668 absl::optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669};
670
wu@webrtc.org97077a32013-10-25 21:18:33 +0000671struct DataSenderInfo : public MediaSenderInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800672 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673};
674
wu@webrtc.org97077a32013-10-25 21:18:33 +0000675struct DataReceiverInfo : public MediaReceiverInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800676 uint32_t ssrc = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677};
678
679struct BandwidthEstimationInfo {
Steve Anton002f9212018-01-09 16:38:15 -0800680 int available_send_bandwidth = 0;
681 int available_recv_bandwidth = 0;
682 int target_enc_bitrate = 0;
683 int actual_enc_bitrate = 0;
684 int retransmit_bitrate = 0;
685 int transmit_bitrate = 0;
686 int64_t bucket_delay = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687};
688
hbosa65704b2016-11-14 02:28:16 -0800689// Maps from payload type to |RtpCodecParameters|.
690typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
691
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692struct VoiceMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200693 VoiceMediaInfo();
694 ~VoiceMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695 void Clear() {
696 senders.clear();
697 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800698 send_codecs.clear();
699 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 }
701 std::vector<VoiceSenderInfo> senders;
702 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800703 RtpCodecParametersMap send_codecs;
704 RtpCodecParametersMap receive_codecs;
Alex Narestbbeb1092019-08-16 11:49:04 +0200705 int32_t device_underrun_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706};
707
708struct VideoMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200709 VideoMediaInfo();
710 ~VideoMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 void Clear() {
712 senders.clear();
713 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700714 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800715 send_codecs.clear();
716 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 }
718 std::vector<VideoSenderInfo> senders;
719 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700720 // Deprecated.
721 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700722 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800723 RtpCodecParametersMap send_codecs;
724 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725};
726
727struct DataMediaInfo {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200728 DataMediaInfo();
729 ~DataMediaInfo();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 void Clear() {
731 senders.clear();
732 receivers.clear();
733 }
734 std::vector<DataSenderInfo> senders;
735 std::vector<DataReceiverInfo> receivers;
736};
737
deadbeef13871492015-12-09 12:37:51 -0800738struct RtcpParameters {
739 bool reduced_size = false;
Sebastian Janssone1795f42019-07-24 11:38:03 +0200740 bool remote_estimate = false;
deadbeef13871492015-12-09 12:37:51 -0800741};
742
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700743template <class Codec>
744struct RtpParameters {
Steve Anton003930a2018-03-29 12:37:21 -0700745 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700746
747 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700748 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700749 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800750 RtcpParameters rtcp;
Steve Anton003930a2018-03-29 12:37:21 -0700751
752 std::string ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200753 rtc::StringBuilder ost;
Steve Anton003930a2018-03-29 12:37:21 -0700754 ost << "{";
755 const char* separator = "";
756 for (const auto& entry : ToStringMap()) {
757 ost << separator << entry.first << ": " << entry.second;
758 separator = ", ";
759 }
760 ost << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200761 return ost.Release();
Steve Anton003930a2018-03-29 12:37:21 -0700762 }
763
764 protected:
765 virtual std::map<std::string, std::string> ToStringMap() const {
766 return {{"codecs", VectorToString(codecs)},
767 {"extensions", VectorToString(extensions)}};
768 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700769};
770
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700771// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
772// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700773template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700774struct RtpSendParameters : RtpParameters<Codec> {
nisse05103312016-03-16 02:22:50 -0700775 int max_bandwidth_bps = -1;
Steve Antonbb50ce52018-03-26 10:24:32 -0700776 // This is the value to be sent in the MID RTP header extension (if the header
777 // extension in included in the list of extensions).
778 std::string mid;
Johannes Kron9190b822018-10-29 11:22:05 +0100779 bool extmap_allow_mixed = false;
Steve Anton003930a2018-03-29 12:37:21 -0700780
781 protected:
782 std::map<std::string, std::string> ToStringMap() const override {
783 auto params = RtpParameters<Codec>::ToStringMap();
784 params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps);
785 params["mid"] = (mid.empty() ? "<not set>" : mid);
Johannes Kron9190b822018-10-29 11:22:05 +0100786 params["extmap-allow-mixed"] = extmap_allow_mixed ? "true" : "false";
Steve Anton003930a2018-03-29 12:37:21 -0700787 return params;
788 }
nisse05103312016-03-16 02:22:50 -0700789};
790
791struct AudioSendParameters : RtpSendParameters<AudioCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200792 AudioSendParameters();
793 ~AudioSendParameters() override;
nisse05103312016-03-16 02:22:50 -0700794 AudioOptions options;
Steve Anton003930a2018-03-29 12:37:21 -0700795
796 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200797 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700798};
799
Yves Gerey665174f2018-06-19 15:03:05 +0200800struct AudioRecvParameters : RtpParameters<AudioCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700801
Ruslan Burakov493a6502019-02-27 15:32:48 +0100802class VoiceMediaChannel : public MediaChannel, public Delayable {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700805 explicit VoiceMediaChannel(const MediaConfig& config)
806 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200807 ~VoiceMediaChannel() override {}
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800808
809 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200810 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
811 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700812 // Get the receive parameters for the incoming stream identified by |ssrc|.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700813 virtual webrtc::RtpParameters GetRtpReceiveParameters(
814 uint32_t ssrc) const = 0;
Saurav Das749f6602019-12-04 09:31:36 -0800815 // Retrieve the receive parameters for the default receive
816 // stream, which is used when SSRCs are not signaled.
817 virtual webrtc::RtpParameters GetDefaultRtpReceiveParameters() const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700819 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800821 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700822 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200823 virtual bool SetAudioSend(uint32_t ssrc,
824 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700825 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800826 AudioSource* source) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700827 // Set speaker output volume of the specified ssrc.
828 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
Saurav Das749f6602019-12-04 09:31:36 -0800829 // Set speaker output volume for future unsignaled streams.
830 virtual bool SetDefaultOutputVolume(double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800832 virtual bool CanInsertDtmf() = 0;
833 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000835 // The valid value for the |event| are 0 to 15 which corresponding to
836 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800837 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 // Gets quality stats for the channel.
839 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100840
841 virtual void SetRawAudioSink(
842 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800843 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
Saurav Das749f6602019-12-04 09:31:36 -0800844 virtual void SetDefaultRawAudioSink(
845 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -0700846
847 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848};
849
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700850// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
851// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700852struct VideoSendParameters : RtpSendParameters<VideoCodec> {
Paulina Hensman11b34f42018-04-09 14:24:52 +0200853 VideoSendParameters();
854 ~VideoSendParameters() override;
nisse4b4dc862016-02-17 05:25:36 -0800855 // Use conference mode? This flag comes from the remote
856 // description's SDP line 'a=x-google-flag:conference', copied over
857 // by VideoChannel::SetRemoteContent_w, and ultimately used by
858 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -0700859 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -0800860 // The special screencast behaviour is disabled by default.
861 bool conference_mode = false;
Steve Anton003930a2018-03-29 12:37:21 -0700862
863 protected:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200864 std::map<std::string, std::string> ToStringMap() const override;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700865};
866
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700867// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
868// encapsulate all the parameters needed for a video RtpReceiver.
Yves Gerey665174f2018-06-19 15:03:05 +0200869struct VideoRecvParameters : RtpParameters<VideoCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700870
Ruslan Burakov493a6502019-02-27 15:32:48 +0100871class VideoMediaChannel : public MediaChannel, public Delayable {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 public:
nisse08582ff2016-02-04 01:24:52 -0800873 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700874 explicit VideoMediaChannel(const MediaConfig& config)
875 : MediaChannel(config) {}
Paulina Hensman11b34f42018-04-09 14:24:52 +0200876 ~VideoMediaChannel() override {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200877
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800878 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200879 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
880 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700881 // Get the receive parameters for the incoming stream identified by |ssrc|.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700882 virtual webrtc::RtpParameters GetRtpReceiveParameters(
883 uint32_t ssrc) const = 0;
Saurav Das749f6602019-12-04 09:31:36 -0800884 // Retrieve the receive parameters for the default receive
885 // stream, which is used when SSRCs are not signaled.
886 virtual webrtc::RtpParameters GetDefaultRtpReceiveParameters() const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 // Gets the currently set codecs/payload types to be used for outgoing media.
888 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 // Starts or stops transmission (and potentially capture) of local video.
890 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -0700891 // Configure stream for sending and register a source.
892 // The |ssrc| must correspond to a registered send stream.
893 virtual bool SetVideoSend(
894 uint32_t ssrc,
deadbeef5a4a75a2016-06-02 16:23:38 -0700895 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -0800896 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -0800897 // Sets the sink object to be used for the specified stream.
nisse08582ff2016-02-04 01:24:52 -0800898 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -0800899 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
Saurav Das749f6602019-12-04 09:31:36 -0800900 // The sink is used for the 'default' stream.
901 virtual void SetDefaultSink(
902 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -0700903 // This fills the "bitrate parts" (rtx, video bitrate) of the
904 // BandwidthEstimationInfo, since that part that isn't possible to get
905 // through webrtc::Call::GetStats, as they are statistics of the send
906 // streams.
907 // TODO(holmer): We should change this so that either BWE graphs doesn't
908 // need access to bitrates of the streams, or change the (RTC)StatsCollector
909 // so that it's getting the send stream stats separately by calling
910 // GetStats(), and merges with BandwidthEstimationInfo by itself.
911 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000913 virtual bool GetStats(VideoMediaInfo* info) = 0;
Markus Handell32565f62019-12-04 10:58:17 +0100914 // Set recordable encoded frame callback for |ssrc|
915 virtual void SetRecordableEncodedFrameCallback(
916 uint32_t ssrc,
917 std::function<void(const webrtc::RecordableEncodedFrame&)> callback) = 0;
918 // Clear recordable encoded frame callback for |ssrc|
919 virtual void ClearRecordableEncodedFrameCallback(uint32_t ssrc) = 0;
920 // Cause generation of a keyframe for |ssrc|
921 virtual void GenerateKeyFrame(uint32_t ssrc) = 0;
Jonas Oreland49ac5952018-09-26 16:04:32 +0200922
923 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924};
925
926enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000927 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
928 // values.
929 DMT_NONE = 0,
930 DMT_CONTROL = 1,
931 DMT_BINARY = 2,
932 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933};
934
935// Info about data received in DataMediaChannel. For use in
936// DataMediaChannel::SignalDataReceived and in all of the signals that
937// signal fires, on up the chain.
938struct ReceiveDataParams {
939 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800940 // RTP data channels use SSRCs, SCTP data channels use SIDs.
941 union {
942 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800943 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800944 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800946 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 // A per-stream value incremented per packet in the stream.
Steve Anton002f9212018-01-09 16:38:15 -0800948 int seq_num = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 // A per-stream value monotonically increasing with time.
Steve Anton002f9212018-01-09 16:38:15 -0800950 int timestamp = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951};
952
953struct SendDataParams {
954 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -0800955 // RTP data channels use SSRCs, SCTP data channels use SIDs.
956 union {
957 uint32_t ssrc;
Steve Anton002f9212018-01-09 16:38:15 -0800958 int sid = 0;
deadbeef953c2ce2017-01-09 14:53:41 -0800959 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 // The type of message (binary, text, or control).
Steve Anton002f9212018-01-09 16:38:15 -0800961 DataMessageType type = DMT_TEXT;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962
Steve Anton002f9212018-01-09 16:38:15 -0800963 // TODO(pthatcher): Make |ordered| and |reliable| true by default?
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 // For SCTP, whether to send messages flagged as ordered or not.
965 // If false, messages can be received out of order.
Steve Anton002f9212018-01-09 16:38:15 -0800966 bool ordered = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 // For SCTP, whether the messages are sent reliably or not.
968 // If false, messages may be lost.
Steve Anton002f9212018-01-09 16:38:15 -0800969 bool reliable = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 // For SCTP, if reliable == false, provide partial reliability by
971 // resending up to this many times. Either count or millis
972 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800973 int max_rtx_count = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974 // For SCTP, if reliable == false, provide partial reliability by
975 // resending for up to this many milliseconds. Either count or millis
976 // is supported, not both at the same time.
Steve Anton002f9212018-01-09 16:38:15 -0800977 int max_rtx_ms = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978};
979
980enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
981
Yves Gerey665174f2018-06-19 15:03:05 +0200982struct DataSendParameters : RtpSendParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700983
Yves Gerey665174f2018-06-19 15:03:05 +0200984struct DataRecvParameters : RtpParameters<DataCodec> {};
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700985
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986class DataMediaChannel : public MediaChannel {
987 public:
Paulina Hensman11b34f42018-04-09 14:24:52 +0200988 DataMediaChannel();
989 explicit DataMediaChannel(const MediaConfig& config);
990 ~DataMediaChannel() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991
Amit Hilbuchdd9390c2018-11-13 16:26:05 -0800992 cricket::MediaType media_type() const override;
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200993 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
994 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000995
Amit Hilbuchea7ef2a2019-02-19 15:20:21 -0800996 // RtpParameter methods are not supported for Data channel.
997 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
998 webrtc::RTCError SetRtpSendParameters(
999 uint32_t ssrc,
1000 const webrtc::RtpParameters& parameters) override;
1001
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002 // TODO(pthatcher): Implement this.
Paulina Hensman11b34f42018-04-09 14:24:52 +02001003 virtual bool GetStats(DataMediaInfo* info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004
1005 virtual bool SetSend(bool send) = 0;
1006 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007
Paulina Hensman11b34f42018-04-09 14:24:52 +02001008 void OnNetworkRouteChanged(const std::string& transport_name,
1009 const rtc::NetworkRoute& network_route) override {}
Honghai Zhangcc411c02016-03-29 17:27:21 -07001010
Yves Gerey665174f2018-06-19 15:03:05 +02001011 virtual bool SendData(const SendDataParams& params,
1012 const rtc::CopyOnWriteBuffer& payload,
1013 SendDataResult* result = NULL) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014 // Signals when data is received (params, data, len)
Yves Gerey665174f2018-06-19 15:03:05 +02001015 sigslot::signal3<const ReceiveDataParams&, const char*, size_t>
1016 SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001017 // Signal when the media channel is ready to send the stream. Arguments are:
1018 // writable(bool)
1019 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020};
1021
1022} // namespace cricket
1023
Steve Anton10542f22019-01-11 09:11:00 -08001024#endif // MEDIA_BASE_MEDIA_CHANNEL_H_