blob: 7306ebf430cd69458ed3f0ab2737676881e5188f [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MEDIA_BASE_MEDIACHANNEL_H_
12#define MEDIA_BASE_MEDIACHANNEL_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
Steve Antone78bcb92017-10-31 09:53:08 -070014#include <map>
kwiberg686a8ef2016-02-26 03:00:35 -080015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
17#include <vector>
18
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/audio_codecs/audio_encoder.h"
20#include "api/optional.h"
21#include "api/rtpparameters.h"
22#include "api/rtpreceiverinterface.h"
23#include "api/video/video_timing.h"
24#include "call/video_config.h"
25#include "media/base/codec.h"
26#include "media/base/mediaconstants.h"
27#include "media/base/streamparams.h"
28#include "media/base/videosinkinterface.h"
29#include "media/base/videosourceinterface.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010030#include "modules/audio_processing/include/audio_processing_statistics.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "rtc_base/basictypes.h"
32#include "rtc_base/buffer.h"
33#include "rtc_base/copyonwritebuffer.h"
34#include "rtc_base/dscp.h"
35#include "rtc_base/logging.h"
36#include "rtc_base/networkroute.h"
37#include "rtc_base/sigslot.h"
38#include "rtc_base/socket.h"
39#include "rtc_base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040// TODO(juberti): re-evaluate this include
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020041#include "pc/audiomonitor.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000043namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044class RateLimiter;
45class Timing;
46}
47
Tommif888bb52015-12-12 01:37:01 +010048namespace webrtc {
49class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080050class VideoFrame;
Tommif888bb52015-12-12 01:37:01 +010051}
52
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053namespace cricket {
54
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080055class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080057struct RtpHeader;
58struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060const int kScreencastDefaultFps = 5;
61
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062template <class T>
Karl Wibergbe579832015-11-10 22:34:18 +010063static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070065 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 str = key;
67 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070068 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069 str += ", ";
70 }
71 return str;
72}
73
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070074template <class T>
75static std::string VectorToString(const std::vector<T>& vals) {
76 std::ostringstream ost;
77 ost << "[";
78 for (size_t i = 0; i < vals.size(); ++i) {
79 if (i > 0) {
80 ost << ", ";
81 }
82 ost << vals[i].ToString();
83 }
84 ost << "]";
85 return ost.str();
86}
87
nisse528b7932017-05-08 03:21:43 -070088// Construction-time settings, passed on when creating
nisse51542be2016-02-12 02:27:06 -080089// MediaChannels.
90struct MediaConfig {
91 // Set DSCP value on packets. This flag comes from the
92 // PeerConnection constraint 'googDscp'.
93 bool enable_dscp = false;
94
nisse0db023a2016-03-01 04:29:59 -080095 // Video-specific config.
96 struct Video {
97 // Enable WebRTC CPU Overuse Detection. This flag comes from the
perkj803d97f2016-11-01 11:45:46 -070098 // PeerConnection constraint 'googCpuOveruseDetection'.
nisse0db023a2016-03-01 04:29:59 -080099 bool enable_cpu_overuse_detection = true;
nisse51542be2016-02-12 02:27:06 -0800100
nisse0db023a2016-03-01 04:29:59 -0800101 // Enable WebRTC suspension of video. No video frames will be sent
102 // when the bitrate is below the configured minimum bitrate. This
103 // flag comes from the PeerConnection constraint
eladalonf1841382017-06-12 01:16:46 -0700104 // 'googSuspendBelowMinBitrate', and WebRtcVideoChannel copies it
nisse0db023a2016-03-01 04:29:59 -0800105 // to VideoSendStream::Config::suspend_below_min_bitrate.
106 bool suspend_below_min_bitrate = false;
nisse51542be2016-02-12 02:27:06 -0800107
nisse0db023a2016-03-01 04:29:59 -0800108 // Set to true if the renderer has an algorithm of frame selection.
109 // If the value is true, then WebRTC will hand over a frame as soon as
110 // possible without delay, and rendering smoothness is completely the duty
111 // of the renderer;
112 // If the value is false, then WebRTC is responsible to delay frame release
113 // in order to increase rendering smoothness.
114 //
115 // This flag comes from PeerConnection's RtcConfiguration, but is
116 // currently only set by the command line flag
117 // 'disable-rtc-smoothness-algorithm'.
eladalonf1841382017-06-12 01:16:46 -0700118 // WebRtcVideoChannel::AddRecvStream copies it to the created
nisse0db023a2016-03-01 04:29:59 -0800119 // WebRtcVideoReceiveStream, where it is returned by the
120 // SmoothsRenderedFrames method. This method is used by the
121 // VideoReceiveStream, where the value is passed on to the
122 // IncomingVideoStream constructor.
123 bool disable_prerenderer_smoothing = false;
sergeyu80ed35e2016-11-28 13:11:13 -0800124
125 // Enables periodic bandwidth probing in application-limited region.
126 bool periodic_alr_bandwidth_probing = false;
nisse0db023a2016-03-01 04:29:59 -0800127 } video;
deadbeef293e9262017-01-11 12:28:30 -0800128
129 bool operator==(const MediaConfig& o) const {
130 return enable_dscp == o.enable_dscp &&
131 video.enable_cpu_overuse_detection ==
132 o.video.enable_cpu_overuse_detection &&
133 video.suspend_below_min_bitrate ==
134 o.video.suspend_below_min_bitrate &&
135 video.disable_prerenderer_smoothing ==
136 o.video.disable_prerenderer_smoothing &&
137 video.periodic_alr_bandwidth_probing ==
138 o.video.periodic_alr_bandwidth_probing;
139 }
140
141 bool operator!=(const MediaConfig& o) const { return !(*this == o); }
nisse51542be2016-02-12 02:27:06 -0800142};
143
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
145// Used to be flags, but that makes it hard to selectively apply options.
146// We are moving all of the setting of options to structs like this,
147// but some things currently still use flags.
148struct AudioOptions {
149 void SetAll(const AudioOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700150 SetFrom(&echo_cancellation, change.echo_cancellation);
151 SetFrom(&auto_gain_control, change.auto_gain_control);
152 SetFrom(&noise_suppression, change.noise_suppression);
153 SetFrom(&highpass_filter, change.highpass_filter);
154 SetFrom(&stereo_swapping, change.stereo_swapping);
155 SetFrom(&audio_jitter_buffer_max_packets,
156 change.audio_jitter_buffer_max_packets);
157 SetFrom(&audio_jitter_buffer_fast_accelerate,
158 change.audio_jitter_buffer_fast_accelerate);
159 SetFrom(&typing_detection, change.typing_detection);
160 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise);
kwiberg102c6a62015-10-30 02:47:38 -0700161 SetFrom(&adjust_agc_delta, change.adjust_agc_delta);
162 SetFrom(&experimental_agc, change.experimental_agc);
163 SetFrom(&extended_filter_aec, change.extended_filter_aec);
164 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec);
165 SetFrom(&experimental_ns, change.experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700166 SetFrom(&intelligibility_enhancer, change.intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700167 SetFrom(&level_control, change.level_control);
ivocb829d9f2016-11-15 02:34:47 -0800168 SetFrom(&residual_echo_detector, change.residual_echo_detector);
kwiberg102c6a62015-10-30 02:47:38 -0700169 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov);
170 SetFrom(&tx_agc_digital_compression_gain,
171 change.tx_agc_digital_compression_gain);
172 SetFrom(&tx_agc_limiter, change.tx_agc_limiter);
kwiberg102c6a62015-10-30 02:47:38 -0700173 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700174 SetFrom(&audio_network_adaptor, change.audio_network_adaptor);
175 SetFrom(&audio_network_adaptor_config, change.audio_network_adaptor_config);
aleloie33c5d92016-10-20 01:53:27 -0700176 SetFrom(&level_control_initial_peak_level_dbfs,
177 change.level_control_initial_peak_level_dbfs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 }
179
180 bool operator==(const AudioOptions& o) const {
181 return echo_cancellation == o.echo_cancellation &&
peaha3333bf2016-06-30 00:02:34 -0700182 auto_gain_control == o.auto_gain_control &&
183 noise_suppression == o.noise_suppression &&
184 highpass_filter == o.highpass_filter &&
185 stereo_swapping == o.stereo_swapping &&
186 audio_jitter_buffer_max_packets ==
187 o.audio_jitter_buffer_max_packets &&
188 audio_jitter_buffer_fast_accelerate ==
189 o.audio_jitter_buffer_fast_accelerate &&
190 typing_detection == o.typing_detection &&
191 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
192 experimental_agc == o.experimental_agc &&
193 extended_filter_aec == o.extended_filter_aec &&
194 delay_agnostic_aec == o.delay_agnostic_aec &&
195 experimental_ns == o.experimental_ns &&
196 intelligibility_enhancer == o.intelligibility_enhancer &&
197 level_control == o.level_control &&
ivocb829d9f2016-11-15 02:34:47 -0800198 residual_echo_detector == o.residual_echo_detector &&
peaha3333bf2016-06-30 00:02:34 -0700199 adjust_agc_delta == o.adjust_agc_delta &&
200 tx_agc_target_dbov == o.tx_agc_target_dbov &&
201 tx_agc_digital_compression_gain ==
202 o.tx_agc_digital_compression_gain &&
203 tx_agc_limiter == o.tx_agc_limiter &&
aleloie33c5d92016-10-20 01:53:27 -0700204 combined_audio_video_bwe == o.combined_audio_video_bwe &&
minyue6b825df2016-10-31 04:08:32 -0700205 audio_network_adaptor == o.audio_network_adaptor &&
206 audio_network_adaptor_config == o.audio_network_adaptor_config &&
aleloie33c5d92016-10-20 01:53:27 -0700207 level_control_initial_peak_level_dbfs ==
208 o.level_control_initial_peak_level_dbfs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 }
deadbeef119760a2016-04-04 11:43:27 -0700210 bool operator!=(const AudioOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211
212 std::string ToString() const {
213 std::ostringstream ost;
214 ost << "AudioOptions {";
215 ost << ToStringIfSet("aec", echo_cancellation);
216 ost << ToStringIfSet("agc", auto_gain_control);
217 ost << ToStringIfSet("ns", noise_suppression);
218 ost << ToStringIfSet("hf", highpass_filter);
219 ost << ToStringIfSet("swap", stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200220 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
221 audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200222 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
223 audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000225 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
227 ost << ToStringIfSet("experimental_agc", experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200228 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100229 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000230 ost << ToStringIfSet("experimental_ns", experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700231 ost << ToStringIfSet("intelligibility_enhancer", intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700232 ost << ToStringIfSet("level_control", level_control);
aleloie33c5d92016-10-20 01:53:27 -0700233 ost << ToStringIfSet("level_control_initial_peak_level_dbfs",
234 level_control_initial_peak_level_dbfs);
ivocb829d9f2016-11-15 02:34:47 -0800235 ost << ToStringIfSet("residual_echo_detector", residual_echo_detector);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000236 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
237 ost << ToStringIfSet("tx_agc_digital_compression_gain",
238 tx_agc_digital_compression_gain);
239 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000240 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700241 ost << ToStringIfSet("audio_network_adaptor", audio_network_adaptor);
242 // The adaptor config is a serialized proto buffer and therefore not human
243 // readable. So we comment out the following line.
244 // ost << ToStringIfSet("audio_network_adaptor_config",
245 // audio_network_adaptor_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246 ost << "}";
247 return ost.str();
248 }
249
250 // Audio processing that attempts to filter away the output signal from
251 // later inbound pickup.
Karl Wibergbe579832015-11-10 22:34:18 +0100252 rtc::Optional<bool> echo_cancellation;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 // Audio processing to adjust the sensitivity of the local mic dynamically.
Karl Wibergbe579832015-11-10 22:34:18 +0100254 rtc::Optional<bool> auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 // Audio processing to filter out background noise.
Karl Wibergbe579832015-11-10 22:34:18 +0100256 rtc::Optional<bool> noise_suppression;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 // Audio processing to remove background noise of lower frequencies.
Karl Wibergbe579832015-11-10 22:34:18 +0100258 rtc::Optional<bool> highpass_filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 // Audio processing to swap the left and right channels.
Karl Wibergbe579832015-11-10 22:34:18 +0100260 rtc::Optional<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200261 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Karl Wibergbe579832015-11-10 22:34:18 +0100262 rtc::Optional<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200263 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Karl Wibergbe579832015-11-10 22:34:18 +0100264 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265 // Audio processing to detect typing.
Karl Wibergbe579832015-11-10 22:34:18 +0100266 rtc::Optional<bool> typing_detection;
267 rtc::Optional<bool> aecm_generate_comfort_noise;
Karl Wibergbe579832015-11-10 22:34:18 +0100268 rtc::Optional<int> adjust_agc_delta;
269 rtc::Optional<bool> experimental_agc;
270 rtc::Optional<bool> extended_filter_aec;
271 rtc::Optional<bool> delay_agnostic_aec;
272 rtc::Optional<bool> experimental_ns;
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700273 rtc::Optional<bool> intelligibility_enhancer;
peaha3333bf2016-06-30 00:02:34 -0700274 rtc::Optional<bool> level_control;
aleloie33c5d92016-10-20 01:53:27 -0700275 // Specifies an optional initialization value for the level controller.
276 rtc::Optional<float> level_control_initial_peak_level_dbfs;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000277 // Note that tx_agc_* only applies to non-experimental AGC.
ivocb829d9f2016-11-15 02:34:47 -0800278 rtc::Optional<bool> residual_echo_detector;
Karl Wibergbe579832015-11-10 22:34:18 +0100279 rtc::Optional<uint16_t> tx_agc_target_dbov;
280 rtc::Optional<uint16_t> tx_agc_digital_compression_gain;
281 rtc::Optional<bool> tx_agc_limiter;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000282 // Enable combined audio+bandwidth BWE.
nisse51542be2016-02-12 02:27:06 -0800283 // TODO(pthatcher): This flag is set from the
284 // "googCombinedAudioVideoBwe", but not used anywhere. So delete it,
285 // and check if any other AudioOptions members are unused.
Karl Wibergbe579832015-11-10 22:34:18 +0100286 rtc::Optional<bool> combined_audio_video_bwe;
minyue6b825df2016-10-31 04:08:32 -0700287 // Enable audio network adaptor.
288 rtc::Optional<bool> audio_network_adaptor;
289 // Config string for audio network adaptor.
290 rtc::Optional<std::string> audio_network_adaptor_config;
kwiberg102c6a62015-10-30 02:47:38 -0700291
292 private:
293 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100294 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700295 if (o) {
296 *s = o;
297 }
298 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299};
300
301// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
302// Used to be flags, but that makes it hard to selectively apply options.
303// We are moving all of the setting of options to structs like this,
304// but some things currently still use flags.
305struct VideoOptions {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700307 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800308 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100309 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 }
311
312 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800313 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100314 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
315 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 }
deadbeef119760a2016-04-04 11:43:27 -0700317 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318
319 std::string ToString() const {
320 std::ostringstream ost;
321 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800323 ost << ToStringIfSet("screencast min bitrate kbps",
324 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100325 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 ost << "}";
327 return ost.str();
328 }
329
nisseb163c3f2016-01-29 01:14:38 -0800330 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700331 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800332 // on to the codec options. Disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100333 rtc::Optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800334 // Force screencast to use a minimum bitrate. This flag comes from
335 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700336 // copied to the encoder config by WebRtcVideoChannel.
nisseb163c3f2016-01-29 01:14:38 -0800337 rtc::Optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100338 // Set by screencast sources. Implies selection of encoding settings
339 // suitable for screencast. Most likely not the right way to do
340 // things, e.g., screencast of a text document and screencast of a
341 // youtube video have different needs.
342 rtc::Optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700343
344 private:
345 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100346 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700347 if (o) {
348 *s = o;
349 }
350 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351};
352
isheriffa1c548b2016-05-31 16:12:24 -0700353// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
354struct RtpHeaderExtension {
355 RtpHeaderExtension() : id(0) {}
356 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
357
358 std::string ToString() const {
359 std::ostringstream ost;
360 ost << "{";
361 ost << "uri: " << uri;
362 ost << ", id: " << id;
363 ost << "}";
364 return ost.str();
365 }
366
367 std::string uri;
368 int id;
369};
370
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371class MediaChannel : public sigslot::has_slots<> {
372 public:
373 class NetworkInterface {
374 public:
375 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700376 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700377 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700378 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700379 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000380 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 int option) = 0;
382 virtual ~NetworkInterface() {}
383 };
384
terelius54f91712016-06-01 11:18:56 -0700385 explicit MediaChannel(const MediaConfig& config)
nisse51542be2016-02-12 02:27:06 -0800386 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
387 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 virtual ~MediaChannel() {}
389
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000390 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000392 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 network_interface_ = iface;
nisse51542be2016-02-12 02:27:06 -0800394 SetDscp(enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395 }
nisse51542be2016-02-12 02:27:06 -0800396 virtual rtc::DiffServCodePoint PreferredDscp() const {
397 return rtc::DSCP_DEFAULT;
398 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700400 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000401 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700403 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000404 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 // Called when the socket's ability to send has changed.
406 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700407 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700408 virtual void OnNetworkRouteChanged(
409 const std::string& transport_name,
410 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 // Creates a new outgoing media stream with SSRCs and CNAME as described
412 // by sp.
413 virtual bool AddSendStream(const StreamParams& sp) = 0;
414 // Removes an outgoing media stream.
415 // ssrc must be the first SSRC of the media stream if the stream uses
416 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200417 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 // Creates a new incoming media stream with SSRCs and CNAME as described
419 // by sp.
420 virtual bool AddRecvStream(const StreamParams& sp) = 0;
421 // Removes an incoming media stream.
422 // ssrc must be the first SSRC of the media stream if the stream uses
423 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200424 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000426 // Returns the absoulte sendtime extension id value from media channel.
427 virtual int GetRtpSendTimeExtnId() const {
428 return -1;
429 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000431 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700432 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
433 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700434 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000435 }
436
jbaucheec21bd2016-03-20 06:15:43 -0700437 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
438 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700439 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000440 }
441
442 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000443 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000444 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000445 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000446 if (!network_interface_)
447 return -1;
448
449 return network_interface_->SetOption(type, opt, option);
450 }
451
nisse51542be2016-02-12 02:27:06 -0800452 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000453 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000454 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000455 int ret;
456 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000457 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000458 value);
459 if (ret == 0) {
460 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000461 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000462 value);
463 }
464 return ret;
465 }
466
jbaucheec21bd2016-03-20 06:15:43 -0700467 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700468 bool rtcp,
469 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000470 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000471 if (!network_interface_)
472 return false;
473
stefanc1aeaf02015-10-15 07:26:07 -0700474 return (!rtcp) ? network_interface_->SendPacket(packet, options)
475 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000476 }
477
nisse51542be2016-02-12 02:27:06 -0800478 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000479 // |network_interface_| can be accessed from the worker_thread and
480 // from any MediaEngine threads. This critical section is to protect accessing
481 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000482 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000483 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484};
485
wu@webrtc.org97077a32013-10-25 21:18:33 +0000486// The stats information is structured as follows:
487// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
488// Media contains a vector of SSRC infos that are exclusively used by this
489// media. (SSRCs shared between media streams can't be represented.)
490
491// Information about an SSRC.
492// This data may be locally recorded, or received in an RTCP SR or RR.
493struct SsrcSenderInfo {
494 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000495 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000496 timestamp(0) {
497 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200498 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000499 double timestamp; // NTP timestamp, represented as seconds since epoch.
500};
501
502struct SsrcReceiverInfo {
503 SsrcReceiverInfo()
504 : ssrc(0),
505 timestamp(0) {
506 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200507 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000508 double timestamp;
509};
510
511struct MediaSenderInfo {
512 MediaSenderInfo()
513 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514 packets_sent(0),
515 packets_lost(0),
516 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000517 rtt_ms(0) {
518 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000519 void add_ssrc(const SsrcSenderInfo& stat) {
520 local_stats.push_back(stat);
521 }
522 // Temporary utility function for call sites that only provide SSRC.
523 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200524 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000525 SsrcSenderInfo stat;
526 stat.ssrc = ssrc;
527 add_ssrc(stat);
528 }
529 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200530 std::vector<uint32_t> ssrcs() const {
531 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000532 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
533 it != local_stats.end(); ++it) {
534 retval.push_back(it->ssrc);
535 }
536 return retval;
537 }
538 // Utility accessor for clients that make the assumption only one ssrc
539 // exists per media.
540 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200541 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000542 if (local_stats.size() > 0) {
543 return local_stats[0].ssrc;
544 } else {
545 return 0;
546 }
547 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200548 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000549 int packets_sent;
550 int packets_lost;
551 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000552 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000553 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800554 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000555 std::vector<SsrcSenderInfo> local_stats;
556 std::vector<SsrcReceiverInfo> remote_stats;
557};
558
559struct MediaReceiverInfo {
560 MediaReceiverInfo()
561 : bytes_rcvd(0),
562 packets_rcvd(0),
563 packets_lost(0),
564 fraction_lost(0.0) {
565 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000566 void add_ssrc(const SsrcReceiverInfo& stat) {
567 local_stats.push_back(stat);
568 }
569 // Temporary utility function for call sites that only provide SSRC.
570 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200571 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000572 SsrcReceiverInfo stat;
573 stat.ssrc = ssrc;
574 add_ssrc(stat);
575 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200576 std::vector<uint32_t> ssrcs() const {
577 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000578 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
579 it != local_stats.end(); ++it) {
580 retval.push_back(it->ssrc);
581 }
582 return retval;
583 }
584 // Utility accessor for clients that make the assumption only one ssrc
585 // exists per media.
586 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200587 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000588 if (local_stats.size() > 0) {
589 return local_stats[0].ssrc;
590 } else {
591 return 0;
592 }
593 }
594
Peter Boström0c4e06b2015-10-07 12:23:21 +0200595 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000596 int packets_rcvd;
597 int packets_lost;
598 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000599 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800600 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000601 std::vector<SsrcReceiverInfo> local_stats;
602 std::vector<SsrcSenderInfo> remote_stats;
603};
604
605struct VoiceSenderInfo : public MediaSenderInfo {
606 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000607 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000608 jitter_ms(0),
609 audio_level(0),
zsteine76bd3a2017-07-14 12:17:49 -0700610 total_input_energy(0.0),
611 total_input_duration(0.0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 aec_quality_min(0.0),
613 echo_delay_median_ms(0),
614 echo_delay_std_ms(0),
615 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000616 echo_return_loss_enhancement(0),
ivoc8c63a822016-10-21 04:10:03 -0700617 residual_echo_likelihood(0.0f),
ivoc4e477a12017-01-15 08:29:46 -0800618 residual_echo_likelihood_recent_max(0.0f),
619 typing_noise_detected(false) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000620
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000621 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 int jitter_ms;
623 int audio_level;
zsteine76bd3a2017-07-14 12:17:49 -0700624 // See description of "totalAudioEnergy" in the WebRTC stats spec:
625 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
626 double total_input_energy;
627 double total_input_duration;
Ivo Creusen56d46092017-11-24 17:29:59 +0100628 // TODO(bugs.webrtc.org/8572): Remove APM stats from this struct, since they
629 // are no longer needed now that we have apm_statistics.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630 float aec_quality_min;
631 int echo_delay_median_ms;
632 int echo_delay_std_ms;
633 int echo_return_loss;
634 int echo_return_loss_enhancement;
ivoc8c63a822016-10-21 04:10:03 -0700635 float residual_echo_likelihood;
ivoc4e477a12017-01-15 08:29:46 -0800636 float residual_echo_likelihood_recent_max;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000637 bool typing_noise_detected;
ivoce1198e02017-09-08 08:13:19 -0700638 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100639 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640};
641
wu@webrtc.org97077a32013-10-25 21:18:33 +0000642struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000644 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645 jitter_ms(0),
646 jitter_buffer_ms(0),
647 jitter_buffer_preferred_ms(0),
648 delay_estimate_ms(0),
649 audio_level(0),
zsteine76bd3a2017-07-14 12:17:49 -0700650 total_output_energy(0.0),
Steve Anton2dbc69f2017-08-24 17:15:13 -0700651 total_samples_received(0),
zsteine76bd3a2017-07-14 12:17:49 -0700652 total_output_duration(0.0),
Steve Anton2dbc69f2017-08-24 17:15:13 -0700653 concealed_samples(0),
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200654 concealment_events(0),
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200655 jitter_buffer_delay_seconds(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000656 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000657 speech_expand_rate(0),
658 secondary_decoded_rate(0),
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200659 secondary_discarded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200660 accelerate_rate(0),
661 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000662 decoding_calls_to_silence_generator(0),
663 decoding_calls_to_neteq(0),
664 decoding_normal(0),
665 decoding_plc(0),
666 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000667 decoding_plc_cng(0),
henrik.lundin63489782016-09-20 01:47:12 -0700668 decoding_muted_output(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200669 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000670
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671 int ext_seqnum;
672 int jitter_ms;
673 int jitter_buffer_ms;
674 int jitter_buffer_preferred_ms;
675 int delay_estimate_ms;
676 int audio_level;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200677 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
678 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
zsteine76bd3a2017-07-14 12:17:49 -0700679 double total_output_energy;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700680 uint64_t total_samples_received;
zsteine76bd3a2017-07-14 12:17:49 -0700681 double total_output_duration;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700682 uint64_t concealed_samples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200683 uint64_t concealment_events;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200684 double jitter_buffer_delay_seconds;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200685 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000686 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000688 // fraction of synthesized speech inserted through expansion.
689 float speech_expand_rate;
690 // fraction of data out of secondary decoding, including FEC and RED.
691 float secondary_decoded_rate;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200692 // Fraction of secondary data, including FEC and RED, that is discarded.
693 // Discarding of secondary data can be caused by the reception of the primary
694 // data, obsoleting the secondary data. It can also be caused by early
695 // or late arrival of secondary data. This metric is the percentage of
696 // discarded secondary data since last query of receiver info.
697 float secondary_discarded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200698 // Fraction of data removed through time compression.
699 float accelerate_rate;
700 // Fraction of data inserted through time stretching.
701 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000702 int decoding_calls_to_silence_generator;
703 int decoding_calls_to_neteq;
704 int decoding_normal;
705 int decoding_plc;
706 int decoding_cng;
707 int decoding_plc_cng;
henrik.lundin63489782016-09-20 01:47:12 -0700708 int decoding_muted_output;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000709 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200710 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711};
712
wu@webrtc.org97077a32013-10-25 21:18:33 +0000713struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000715 : packets_cached(0),
716 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000717 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000719 send_frame_width(0),
720 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 framerate_input(0),
722 framerate_sent(0),
723 nominal_bitrate(0),
724 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000725 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000726 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000727 avg_encode_ms(0),
sakal43536c32016-10-24 01:46:43 -0700728 encode_usage_percent(0),
ilnik50864a82017-09-06 12:32:35 -0700729 frames_encoded(0),
Ã…sa Perssonc3ed6302017-11-16 14:04:52 +0100730 has_entered_low_resolution(false),
ilnik50864a82017-09-06 12:32:35 -0700731 content_type(webrtc::VideoContentType::UNSPECIFIED) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000733 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800734 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100735 std::string encoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000736 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000738 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000740 int send_frame_width;
741 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 int framerate_input;
743 int framerate_sent;
744 int nominal_bitrate;
745 int preferred_bitrate;
746 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000747 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000748 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000749 int encode_usage_percent;
sakal43536c32016-10-24 01:46:43 -0700750 uint32_t frames_encoded;
Ã…sa Perssonc3ed6302017-11-16 14:04:52 +0100751 bool has_entered_low_resolution;
sakal87da4042016-10-31 06:53:47 -0700752 rtc::Optional<uint64_t> qp_sum;
ilnik50864a82017-09-06 12:32:35 -0700753 webrtc::VideoContentType content_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754};
755
wu@webrtc.org97077a32013-10-25 21:18:33 +0000756struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000758 : packets_concealed(0),
759 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000760 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 nacks_sent(0),
762 frame_width(0),
763 frame_height(0),
764 framerate_rcvd(0),
765 framerate_decoded(0),
766 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000767 framerate_render_input(0),
768 framerate_render_output(0),
hbos42f6d2f2017-01-20 03:56:50 -0800769 frames_received(0),
sakale5ba44e2016-10-26 07:09:24 -0700770 frames_decoded(0),
hbos50cfe1f2017-01-23 07:21:55 -0800771 frames_rendered(0),
ilnika79cc282017-08-23 05:24:10 -0700772 interframe_delay_max_ms(-1),
ilnik2e1b40b2017-09-04 07:57:17 -0700773 content_type(webrtc::VideoContentType::UNSPECIFIED),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000774 decode_ms(0),
775 max_decode_ms(0),
776 jitter_buffer_ms(0),
777 min_playout_delay_ms(0),
778 render_delay_ms(0),
779 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000780 current_delay_ms(0),
ilnik2edc6842017-07-06 03:06:50 -0700781 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000783 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800784 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100785 std::string decoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000786 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000788 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 int nacks_sent;
790 int frame_width;
791 int frame_height;
792 int framerate_rcvd;
793 int framerate_decoded;
794 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000795 // Framerate as sent to the renderer.
796 int framerate_render_input;
797 // Framerate that the renderer reports.
798 int framerate_render_output;
hbos42f6d2f2017-01-20 03:56:50 -0800799 uint32_t frames_received;
sakale5ba44e2016-10-26 07:09:24 -0700800 uint32_t frames_decoded;
hbos50cfe1f2017-01-23 07:21:55 -0800801 uint32_t frames_rendered;
sakalcc452e12017-02-09 04:53:45 -0800802 rtc::Optional<uint64_t> qp_sum;
ilnika79cc282017-08-23 05:24:10 -0700803 int64_t interframe_delay_max_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000804
ilnik2e1b40b2017-09-04 07:57:17 -0700805 webrtc::VideoContentType content_type;
806
wu@webrtc.org97077a32013-10-25 21:18:33 +0000807 // All stats below are gathered per-VideoReceiver, but some will be correlated
808 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
809 // structures, reflect this in the new layout.
810
811 // Current frame decode latency.
812 int decode_ms;
813 // Maximum observed frame decode latency.
814 int max_decode_ms;
815 // Jitter (network-related) latency.
816 int jitter_buffer_ms;
817 // Requested minimum playout latency.
818 int min_playout_delay_ms;
819 // Requested latency to account for rendering delay.
820 int render_delay_ms;
821 // Target overall delay: network+decode+render, accounting for
822 // min_playout_delay_ms.
823 int target_delay_ms;
824 // Current overall delay, possibly ramping towards target_delay_ms.
825 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000826
827 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200828 int64_t capture_start_ntp_time_ms;
ilnik2edc6842017-07-06 03:06:50 -0700829
830 // Timing frame info: all important timestamps for a full lifetime of a
831 // single 'timing frame'.
832 rtc::Optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833};
834
wu@webrtc.org97077a32013-10-25 21:18:33 +0000835struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000837 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 }
839
Peter Boström0c4e06b2015-10-07 12:23:21 +0200840 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841};
842
wu@webrtc.org97077a32013-10-25 21:18:33 +0000843struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000845 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 }
847
Peter Boström0c4e06b2015-10-07 12:23:21 +0200848 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849};
850
851struct BandwidthEstimationInfo {
852 BandwidthEstimationInfo()
853 : available_send_bandwidth(0),
854 available_recv_bandwidth(0),
855 target_enc_bitrate(0),
856 actual_enc_bitrate(0),
857 retransmit_bitrate(0),
858 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000859 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 }
861
862 int available_send_bandwidth;
863 int available_recv_bandwidth;
864 int target_enc_bitrate;
865 int actual_enc_bitrate;
866 int retransmit_bitrate;
867 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000868 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869};
870
hbosa65704b2016-11-14 02:28:16 -0800871// Maps from payload type to |RtpCodecParameters|.
872typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
873
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874struct VoiceMediaInfo {
875 void Clear() {
876 senders.clear();
877 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800878 send_codecs.clear();
879 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 }
881 std::vector<VoiceSenderInfo> senders;
882 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800883 RtpCodecParametersMap send_codecs;
884 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885};
886
887struct VideoMediaInfo {
888 void Clear() {
889 senders.clear();
890 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700891 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800892 send_codecs.clear();
893 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 }
895 std::vector<VideoSenderInfo> senders;
896 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700897 // Deprecated.
898 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700899 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800900 RtpCodecParametersMap send_codecs;
901 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902};
903
904struct DataMediaInfo {
905 void Clear() {
906 senders.clear();
907 receivers.clear();
908 }
909 std::vector<DataSenderInfo> senders;
910 std::vector<DataReceiverInfo> receivers;
911};
912
deadbeef13871492015-12-09 12:37:51 -0800913struct RtcpParameters {
914 bool reduced_size = false;
915};
916
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700917template <class Codec>
918struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800919 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700920 std::ostringstream ost;
921 ost << "{";
922 ost << "codecs: " << VectorToString(codecs) << ", ";
923 ost << "extensions: " << VectorToString(extensions);
924 ost << "}";
925 return ost.str();
926 }
927
928 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700929 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700930 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800931 RtcpParameters rtcp;
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200932 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700933};
934
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700935// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
936// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700937template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700938struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800939 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700940 std::ostringstream ost;
941 ost << "{";
942 ost << "codecs: " << VectorToString(this->codecs) << ", ";
943 ost << "extensions: " << VectorToString(this->extensions) << ", ";
pbos378dc772016-01-28 15:58:41 -0800944 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
nisse05103312016-03-16 02:22:50 -0700945 ost << "}";
946 return ost.str();
947 }
948
949 int max_bandwidth_bps = -1;
950};
951
952struct AudioSendParameters : RtpSendParameters<AudioCodec> {
953 std::string ToString() const override {
954 std::ostringstream ost;
955 ost << "{";
956 ost << "codecs: " << VectorToString(this->codecs) << ", ";
957 ost << "extensions: " << VectorToString(this->extensions) << ", ";
958 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700959 ost << "options: " << options.ToString();
960 ost << "}";
961 return ost.str();
962 }
963
nisse05103312016-03-16 02:22:50 -0700964 AudioOptions options;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700965};
966
967struct AudioRecvParameters : RtpParameters<AudioCodec> {
968};
969
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970class VoiceMediaChannel : public MediaChannel {
971 public:
972 enum Error {
973 ERROR_NONE = 0, // No error.
974 ERROR_OTHER, // Other errors.
975 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
976 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
977 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
978 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
979 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
980 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
981 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
982 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
983 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
984 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
985 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
986 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
987 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
988 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
989 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
990 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
991 };
992
993 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700994 explicit VoiceMediaChannel(const MediaConfig& config)
995 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200997 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
998 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700999 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
1000 virtual bool SetRtpSendParameters(
1001 uint32_t ssrc,
1002 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -07001003 // Get the receive parameters for the incoming stream identified by |ssrc|.
1004 // If |ssrc| is 0, retrieve the receive parameters for the default receive
1005 // stream, which is used when SSRCs are not signaled. Note that calling with
1006 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
1007 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001008 virtual webrtc::RtpParameters GetRtpReceiveParameters(
1009 uint32_t ssrc) const = 0;
1010 virtual bool SetRtpReceiveParameters(
1011 uint32_t ssrc,
1012 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -07001014 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08001016 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -07001017 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001018 virtual bool SetAudioSend(uint32_t ssrc,
1019 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -07001020 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08001021 AudioSource* source) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 // Gets current energy levels for all incoming streams.
1023 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1024 // Get the current energy level of the stream sent to the speaker.
1025 virtual int GetOutputLevel() = 0;
solenberg4bac9c52015-10-09 02:32:53 -07001026 // Set speaker output volume of the specified ssrc.
1027 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -08001029 virtual bool CanInsertDtmf() = 0;
1030 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001032 // The valid value for the |event| are 0 to 15 which corresponding to
1033 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -08001034 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035 // Gets quality stats for the channel.
1036 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +01001037
1038 virtual void SetRawAudioSink(
1039 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -08001040 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -07001041
1042 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043};
1044
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001045// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
1046// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -07001047struct VideoSendParameters : RtpSendParameters<VideoCodec> {
nisse4b4dc862016-02-17 05:25:36 -08001048 // Use conference mode? This flag comes from the remote
1049 // description's SDP line 'a=x-google-flag:conference', copied over
1050 // by VideoChannel::SetRemoteContent_w, and ultimately used by
1051 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -07001052 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -08001053 // The special screencast behaviour is disabled by default.
1054 bool conference_mode = false;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001055};
1056
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001057// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
1058// encapsulate all the parameters needed for a video RtpReceiver.
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001059struct VideoRecvParameters : RtpParameters<VideoCodec> {
1060};
1061
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062class VideoMediaChannel : public MediaChannel {
1063 public:
1064 enum Error {
1065 ERROR_NONE = 0, // No error.
1066 ERROR_OTHER, // Other errors.
1067 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1068 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1069 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1070 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1071 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1072 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1073 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1074 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1075 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1076 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1077 };
1078
nisse08582ff2016-02-04 01:24:52 -08001079 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -07001080 explicit VideoMediaChannel(const MediaConfig& config)
1081 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001083
1084 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
1085 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001086 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
1087 virtual bool SetRtpSendParameters(
1088 uint32_t ssrc,
1089 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -07001090 // Get the receive parameters for the incoming stream identified by |ssrc|.
1091 // If |ssrc| is 0, retrieve the receive parameters for the default receive
1092 // stream, which is used when SSRCs are not signaled. Note that calling with
1093 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
1094 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001095 virtual webrtc::RtpParameters GetRtpReceiveParameters(
1096 uint32_t ssrc) const = 0;
1097 virtual bool SetRtpReceiveParameters(
1098 uint32_t ssrc,
1099 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 // Gets the currently set codecs/payload types to be used for outgoing media.
1101 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 // Starts or stops transmission (and potentially capture) of local video.
1103 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -07001104 // Configure stream for sending and register a source.
1105 // The |ssrc| must correspond to a registered send stream.
1106 virtual bool SetVideoSend(
1107 uint32_t ssrc,
1108 bool enable,
1109 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -08001110 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -08001111 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -07001112 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -08001113 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -08001114 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -07001115 // This fills the "bitrate parts" (rtx, video bitrate) of the
1116 // BandwidthEstimationInfo, since that part that isn't possible to get
1117 // through webrtc::Call::GetStats, as they are statistics of the send
1118 // streams.
1119 // TODO(holmer): We should change this so that either BWE graphs doesn't
1120 // need access to bitrates of the streams, or change the (RTC)StatsCollector
1121 // so that it's getting the send stream stats separately by calling
1122 // GetStats(), and merges with BandwidthEstimationInfo by itself.
1123 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001125 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001126};
1127
1128enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001129 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1130 // values.
1131 DMT_NONE = 0,
1132 DMT_CONTROL = 1,
1133 DMT_BINARY = 2,
1134 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001135};
1136
1137// Info about data received in DataMediaChannel. For use in
1138// DataMediaChannel::SignalDataReceived and in all of the signals that
1139// signal fires, on up the chain.
1140struct ReceiveDataParams {
1141 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001142 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1143 union {
1144 uint32_t ssrc;
1145 int sid;
1146 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001147 // The type of message (binary, text, or control).
1148 DataMessageType type;
1149 // A per-stream value incremented per packet in the stream.
1150 int seq_num;
1151 // A per-stream value monotonically increasing with time.
1152 int timestamp;
1153
deadbeef953c2ce2017-01-09 14:53:41 -08001154 ReceiveDataParams() : sid(0), type(DMT_TEXT), seq_num(0), timestamp(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155};
1156
1157struct SendDataParams {
1158 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001159 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1160 union {
1161 uint32_t ssrc;
1162 int sid;
1163 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001164 // The type of message (binary, text, or control).
1165 DataMessageType type;
1166
1167 // For SCTP, whether to send messages flagged as ordered or not.
1168 // If false, messages can be received out of order.
1169 bool ordered;
1170 // For SCTP, whether the messages are sent reliably or not.
1171 // If false, messages may be lost.
1172 bool reliable;
1173 // For SCTP, if reliable == false, provide partial reliability by
1174 // resending up to this many times. Either count or millis
1175 // is supported, not both at the same time.
1176 int max_rtx_count;
1177 // For SCTP, if reliable == false, provide partial reliability by
1178 // resending for up to this many milliseconds. Either count or millis
1179 // is supported, not both at the same time.
1180 int max_rtx_ms;
1181
deadbeef953c2ce2017-01-09 14:53:41 -08001182 SendDataParams()
1183 : sid(0),
1184 type(DMT_TEXT),
1185 // TODO(pthatcher): Make these true by default?
1186 ordered(false),
1187 reliable(false),
1188 max_rtx_count(0),
1189 max_rtx_ms(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001190};
1191
1192enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1193
nisse05103312016-03-16 02:22:50 -07001194struct DataSendParameters : RtpSendParameters<DataCodec> {
solenberg7e4e01a2015-12-02 08:05:01 -08001195 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001196 std::ostringstream ost;
1197 // Options and extensions aren't used.
1198 ost << "{";
1199 ost << "codecs: " << VectorToString(codecs) << ", ";
pbos378dc772016-01-28 15:58:41 -08001200 ost << "max_bandwidth_bps: " << max_bandwidth_bps;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001201 ost << "}";
1202 return ost.str();
1203 }
1204};
1205
1206struct DataRecvParameters : RtpParameters<DataCodec> {
1207};
1208
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001209class DataMediaChannel : public MediaChannel {
1210 public:
1211 enum Error {
1212 ERROR_NONE = 0, // No error.
1213 ERROR_OTHER, // Other errors.
1214 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1215 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1216 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1217 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1218 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1219 };
1220
zhihuangebbe4f22016-12-06 10:45:42 -08001221 DataMediaChannel() {}
Steve Antone78bcb92017-10-31 09:53:08 -07001222 explicit DataMediaChannel(const MediaConfig& config) : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001223 virtual ~DataMediaChannel() {}
1224
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001225 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1226 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001227
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001228 // TODO(pthatcher): Implement this.
1229 virtual bool GetStats(DataMediaInfo* info) { return true; }
1230
1231 virtual bool SetSend(bool send) = 0;
1232 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001233
Honghai Zhangcc411c02016-03-29 17:27:21 -07001234 virtual void OnNetworkRouteChanged(const std::string& transport_name,
Honghai Zhang0e533ef2016-04-19 15:41:36 -07001235 const rtc::NetworkRoute& network_route) {}
Honghai Zhangcc411c02016-03-29 17:27:21 -07001236
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237 virtual bool SendData(
1238 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -07001239 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001240 SendDataResult* result = NULL) = 0;
1241 // Signals when data is received (params, data, len)
1242 sigslot::signal3<const ReceiveDataParams&,
1243 const char*,
1244 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001245 // Signal when the media channel is ready to send the stream. Arguments are:
1246 // writable(bool)
1247 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248};
1249
1250} // namespace cricket
1251
Mirko Bonadei92ea95e2017-09-15 06:47:31 +02001252#endif // MEDIA_BASE_MEDIACHANNEL_H_