blob: 816dfd18fc987a3995396e4afa31839f69a3eac8 [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
kjellandera96e2d72016-02-04 23:52:28 -080011#ifndef WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_
12#define WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
kwiberg686a8ef2016-02-26 03:00:35 -080014#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015#include <string>
16#include <vector>
17
skvladdc1c62c2016-03-16 19:07:43 -070018#include "webrtc/api/rtpparameters.h"
zhihuang38ede132017-06-15 12:52:32 -070019#include "webrtc/api/rtpreceiverinterface.h"
Henrik Kjellandera80c16a2017-07-01 16:48:15 +020020#include "webrtc/base/basictypes.h"
21#include "webrtc/base/buffer.h"
22#include "webrtc/base/copyonwritebuffer.h"
23#include "webrtc/base/dscp.h"
24#include "webrtc/base/logging.h"
25#include "webrtc/base/networkroute.h"
26#include "webrtc/base/optional.h"
27#include "webrtc/base/sigslot.h"
28#include "webrtc/base/socket.h"
29#include "webrtc/base/window.h"
isheriff6f8d6862016-05-26 11:24:55 -070030#include "webrtc/config.h"
kjellandera96e2d72016-02-04 23:52:28 -080031#include "webrtc/media/base/codec.h"
kjellanderf4752772016-03-02 05:42:30 -080032#include "webrtc/media/base/mediaconstants.h"
kjellandera96e2d72016-02-04 23:52:28 -080033#include "webrtc/media/base/streamparams.h"
nisse08582ff2016-02-04 01:24:52 -080034#include "webrtc/media/base/videosinkinterface.h"
nisse2ded9b12016-04-08 02:23:55 -070035#include "webrtc/media/base/videosourceinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036// TODO(juberti): re-evaluate this include
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010037#include "webrtc/pc/audiomonitor.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000039namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040class RateLimiter;
41class Timing;
42}
43
Tommif888bb52015-12-12 01:37:01 +010044namespace webrtc {
45class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080046class VideoFrame;
Tommif888bb52015-12-12 01:37:01 +010047}
48
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049namespace cricket {
50
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080051class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080053struct RtpHeader;
54struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056const int kScreencastDefaultFps = 5;
57
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058template <class T>
Karl Wibergbe579832015-11-10 22:34:18 +010059static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070061 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062 str = key;
63 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070064 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065 str += ", ";
66 }
67 return str;
68}
69
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070070template <class T>
71static std::string VectorToString(const std::vector<T>& vals) {
72 std::ostringstream ost;
73 ost << "[";
74 for (size_t i = 0; i < vals.size(); ++i) {
75 if (i > 0) {
76 ost << ", ";
77 }
78 ost << vals[i].ToString();
79 }
80 ost << "]";
81 return ost.str();
82}
83
nisse528b7932017-05-08 03:21:43 -070084// Construction-time settings, passed on when creating
nisse51542be2016-02-12 02:27:06 -080085// MediaChannels.
86struct MediaConfig {
87 // Set DSCP value on packets. This flag comes from the
88 // PeerConnection constraint 'googDscp'.
89 bool enable_dscp = false;
90
nisse0db023a2016-03-01 04:29:59 -080091 // Video-specific config.
92 struct Video {
93 // Enable WebRTC CPU Overuse Detection. This flag comes from the
perkj803d97f2016-11-01 11:45:46 -070094 // PeerConnection constraint 'googCpuOveruseDetection'.
nisse0db023a2016-03-01 04:29:59 -080095 bool enable_cpu_overuse_detection = true;
nisse51542be2016-02-12 02:27:06 -080096
nisse0db023a2016-03-01 04:29:59 -080097 // Enable WebRTC suspension of video. No video frames will be sent
98 // when the bitrate is below the configured minimum bitrate. This
99 // flag comes from the PeerConnection constraint
eladalonf1841382017-06-12 01:16:46 -0700100 // 'googSuspendBelowMinBitrate', and WebRtcVideoChannel copies it
nisse0db023a2016-03-01 04:29:59 -0800101 // to VideoSendStream::Config::suspend_below_min_bitrate.
102 bool suspend_below_min_bitrate = false;
nisse51542be2016-02-12 02:27:06 -0800103
nisse0db023a2016-03-01 04:29:59 -0800104 // Set to true if the renderer has an algorithm of frame selection.
105 // If the value is true, then WebRTC will hand over a frame as soon as
106 // possible without delay, and rendering smoothness is completely the duty
107 // of the renderer;
108 // If the value is false, then WebRTC is responsible to delay frame release
109 // in order to increase rendering smoothness.
110 //
111 // This flag comes from PeerConnection's RtcConfiguration, but is
112 // currently only set by the command line flag
113 // 'disable-rtc-smoothness-algorithm'.
eladalonf1841382017-06-12 01:16:46 -0700114 // WebRtcVideoChannel::AddRecvStream copies it to the created
nisse0db023a2016-03-01 04:29:59 -0800115 // WebRtcVideoReceiveStream, where it is returned by the
116 // SmoothsRenderedFrames method. This method is used by the
117 // VideoReceiveStream, where the value is passed on to the
118 // IncomingVideoStream constructor.
119 bool disable_prerenderer_smoothing = false;
sergeyu80ed35e2016-11-28 13:11:13 -0800120
121 // Enables periodic bandwidth probing in application-limited region.
122 bool periodic_alr_bandwidth_probing = false;
nisse0db023a2016-03-01 04:29:59 -0800123 } video;
deadbeef293e9262017-01-11 12:28:30 -0800124
125 bool operator==(const MediaConfig& o) const {
126 return enable_dscp == o.enable_dscp &&
127 video.enable_cpu_overuse_detection ==
128 o.video.enable_cpu_overuse_detection &&
129 video.suspend_below_min_bitrate ==
130 o.video.suspend_below_min_bitrate &&
131 video.disable_prerenderer_smoothing ==
132 o.video.disable_prerenderer_smoothing &&
133 video.periodic_alr_bandwidth_probing ==
134 o.video.periodic_alr_bandwidth_probing;
135 }
136
137 bool operator!=(const MediaConfig& o) const { return !(*this == o); }
nisse51542be2016-02-12 02:27:06 -0800138};
139
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
141// Used to be flags, but that makes it hard to selectively apply options.
142// We are moving all of the setting of options to structs like this,
143// but some things currently still use flags.
144struct AudioOptions {
145 void SetAll(const AudioOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700146 SetFrom(&echo_cancellation, change.echo_cancellation);
147 SetFrom(&auto_gain_control, change.auto_gain_control);
148 SetFrom(&noise_suppression, change.noise_suppression);
149 SetFrom(&highpass_filter, change.highpass_filter);
150 SetFrom(&stereo_swapping, change.stereo_swapping);
151 SetFrom(&audio_jitter_buffer_max_packets,
152 change.audio_jitter_buffer_max_packets);
153 SetFrom(&audio_jitter_buffer_fast_accelerate,
154 change.audio_jitter_buffer_fast_accelerate);
155 SetFrom(&typing_detection, change.typing_detection);
156 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise);
kwiberg102c6a62015-10-30 02:47:38 -0700157 SetFrom(&adjust_agc_delta, change.adjust_agc_delta);
158 SetFrom(&experimental_agc, change.experimental_agc);
159 SetFrom(&extended_filter_aec, change.extended_filter_aec);
160 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec);
161 SetFrom(&experimental_ns, change.experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700162 SetFrom(&intelligibility_enhancer, change.intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700163 SetFrom(&level_control, change.level_control);
ivocb829d9f2016-11-15 02:34:47 -0800164 SetFrom(&residual_echo_detector, change.residual_echo_detector);
kwiberg102c6a62015-10-30 02:47:38 -0700165 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov);
166 SetFrom(&tx_agc_digital_compression_gain,
167 change.tx_agc_digital_compression_gain);
168 SetFrom(&tx_agc_limiter, change.tx_agc_limiter);
169 SetFrom(&recording_sample_rate, change.recording_sample_rate);
170 SetFrom(&playout_sample_rate, change.playout_sample_rate);
kwiberg102c6a62015-10-30 02:47:38 -0700171 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700172 SetFrom(&audio_network_adaptor, change.audio_network_adaptor);
173 SetFrom(&audio_network_adaptor_config, change.audio_network_adaptor_config);
aleloie33c5d92016-10-20 01:53:27 -0700174 SetFrom(&level_control_initial_peak_level_dbfs,
175 change.level_control_initial_peak_level_dbfs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176 }
177
178 bool operator==(const AudioOptions& o) const {
179 return echo_cancellation == o.echo_cancellation &&
peaha3333bf2016-06-30 00:02:34 -0700180 auto_gain_control == o.auto_gain_control &&
181 noise_suppression == o.noise_suppression &&
182 highpass_filter == o.highpass_filter &&
183 stereo_swapping == o.stereo_swapping &&
184 audio_jitter_buffer_max_packets ==
185 o.audio_jitter_buffer_max_packets &&
186 audio_jitter_buffer_fast_accelerate ==
187 o.audio_jitter_buffer_fast_accelerate &&
188 typing_detection == o.typing_detection &&
189 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
190 experimental_agc == o.experimental_agc &&
191 extended_filter_aec == o.extended_filter_aec &&
192 delay_agnostic_aec == o.delay_agnostic_aec &&
193 experimental_ns == o.experimental_ns &&
194 intelligibility_enhancer == o.intelligibility_enhancer &&
195 level_control == o.level_control &&
ivocb829d9f2016-11-15 02:34:47 -0800196 residual_echo_detector == o.residual_echo_detector &&
peaha3333bf2016-06-30 00:02:34 -0700197 adjust_agc_delta == o.adjust_agc_delta &&
198 tx_agc_target_dbov == o.tx_agc_target_dbov &&
199 tx_agc_digital_compression_gain ==
200 o.tx_agc_digital_compression_gain &&
201 tx_agc_limiter == o.tx_agc_limiter &&
202 recording_sample_rate == o.recording_sample_rate &&
203 playout_sample_rate == o.playout_sample_rate &&
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);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000240 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
241 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000242 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700243 ost << ToStringIfSet("audio_network_adaptor", audio_network_adaptor);
244 // The adaptor config is a serialized proto buffer and therefore not human
245 // readable. So we comment out the following line.
246 // ost << ToStringIfSet("audio_network_adaptor_config",
247 // audio_network_adaptor_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 ost << "}";
249 return ost.str();
250 }
251
252 // Audio processing that attempts to filter away the output signal from
253 // later inbound pickup.
Karl Wibergbe579832015-11-10 22:34:18 +0100254 rtc::Optional<bool> echo_cancellation;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 // Audio processing to adjust the sensitivity of the local mic dynamically.
Karl Wibergbe579832015-11-10 22:34:18 +0100256 rtc::Optional<bool> auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 // Audio processing to filter out background noise.
Karl Wibergbe579832015-11-10 22:34:18 +0100258 rtc::Optional<bool> noise_suppression;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 // Audio processing to remove background noise of lower frequencies.
Karl Wibergbe579832015-11-10 22:34:18 +0100260 rtc::Optional<bool> highpass_filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 // Audio processing to swap the left and right channels.
Karl Wibergbe579832015-11-10 22:34:18 +0100262 rtc::Optional<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200263 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Karl Wibergbe579832015-11-10 22:34:18 +0100264 rtc::Optional<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200265 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Karl Wibergbe579832015-11-10 22:34:18 +0100266 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 // Audio processing to detect typing.
Karl Wibergbe579832015-11-10 22:34:18 +0100268 rtc::Optional<bool> typing_detection;
269 rtc::Optional<bool> aecm_generate_comfort_noise;
Karl Wibergbe579832015-11-10 22:34:18 +0100270 rtc::Optional<int> adjust_agc_delta;
271 rtc::Optional<bool> experimental_agc;
272 rtc::Optional<bool> extended_filter_aec;
273 rtc::Optional<bool> delay_agnostic_aec;
274 rtc::Optional<bool> experimental_ns;
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700275 rtc::Optional<bool> intelligibility_enhancer;
peaha3333bf2016-06-30 00:02:34 -0700276 rtc::Optional<bool> level_control;
aleloie33c5d92016-10-20 01:53:27 -0700277 // Specifies an optional initialization value for the level controller.
278 rtc::Optional<float> level_control_initial_peak_level_dbfs;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000279 // Note that tx_agc_* only applies to non-experimental AGC.
ivocb829d9f2016-11-15 02:34:47 -0800280 rtc::Optional<bool> residual_echo_detector;
Karl Wibergbe579832015-11-10 22:34:18 +0100281 rtc::Optional<uint16_t> tx_agc_target_dbov;
282 rtc::Optional<uint16_t> tx_agc_digital_compression_gain;
283 rtc::Optional<bool> tx_agc_limiter;
284 rtc::Optional<uint32_t> recording_sample_rate;
285 rtc::Optional<uint32_t> playout_sample_rate;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000286 // Enable combined audio+bandwidth BWE.
nisse51542be2016-02-12 02:27:06 -0800287 // TODO(pthatcher): This flag is set from the
288 // "googCombinedAudioVideoBwe", but not used anywhere. So delete it,
289 // and check if any other AudioOptions members are unused.
Karl Wibergbe579832015-11-10 22:34:18 +0100290 rtc::Optional<bool> combined_audio_video_bwe;
minyue6b825df2016-10-31 04:08:32 -0700291 // Enable audio network adaptor.
292 rtc::Optional<bool> audio_network_adaptor;
293 // Config string for audio network adaptor.
294 rtc::Optional<std::string> audio_network_adaptor_config;
kwiberg102c6a62015-10-30 02:47:38 -0700295
296 private:
297 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100298 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700299 if (o) {
300 *s = o;
301 }
302 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303};
304
305// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
306// Used to be flags, but that makes it hard to selectively apply options.
307// We are moving all of the setting of options to structs like this,
308// but some things currently still use flags.
309struct VideoOptions {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700311 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800312 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100313 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 }
315
316 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800317 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100318 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
319 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 }
deadbeef119760a2016-04-04 11:43:27 -0700321 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322
323 std::string ToString() const {
324 std::ostringstream ost;
325 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800327 ost << ToStringIfSet("screencast min bitrate kbps",
328 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100329 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 ost << "}";
331 return ost.str();
332 }
333
nisseb163c3f2016-01-29 01:14:38 -0800334 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700335 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800336 // on to the codec options. Disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100337 rtc::Optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800338 // Force screencast to use a minimum bitrate. This flag comes from
339 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700340 // copied to the encoder config by WebRtcVideoChannel.
nisseb163c3f2016-01-29 01:14:38 -0800341 rtc::Optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100342 // Set by screencast sources. Implies selection of encoding settings
343 // suitable for screencast. Most likely not the right way to do
344 // things, e.g., screencast of a text document and screencast of a
345 // youtube video have different needs.
346 rtc::Optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700347
348 private:
349 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100350 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700351 if (o) {
352 *s = o;
353 }
354 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355};
356
isheriffa1c548b2016-05-31 16:12:24 -0700357// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
358struct RtpHeaderExtension {
359 RtpHeaderExtension() : id(0) {}
360 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
361
362 std::string ToString() const {
363 std::ostringstream ost;
364 ost << "{";
365 ost << "uri: " << uri;
366 ost << ", id: " << id;
367 ost << "}";
368 return ost.str();
369 }
370
371 std::string uri;
372 int id;
373};
374
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375class MediaChannel : public sigslot::has_slots<> {
376 public:
377 class NetworkInterface {
378 public:
379 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700380 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700381 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700382 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700383 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000384 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 int option) = 0;
386 virtual ~NetworkInterface() {}
387 };
388
terelius54f91712016-06-01 11:18:56 -0700389 explicit MediaChannel(const MediaConfig& config)
nisse51542be2016-02-12 02:27:06 -0800390 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
391 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 virtual ~MediaChannel() {}
393
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000394 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000396 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 network_interface_ = iface;
nisse51542be2016-02-12 02:27:06 -0800398 SetDscp(enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399 }
nisse51542be2016-02-12 02:27:06 -0800400 virtual rtc::DiffServCodePoint PreferredDscp() const {
401 return rtc::DSCP_DEFAULT;
402 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700404 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000405 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000406 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700407 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000408 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000409 // Called when the socket's ability to send has changed.
410 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700411 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700412 virtual void OnNetworkRouteChanged(
413 const std::string& transport_name,
414 const rtc::NetworkRoute& network_route) = 0;
michaelt79e05882016-11-08 02:50:09 -0800415 // Called when the rtp transport overhead changed.
416 virtual void OnTransportOverheadChanged(
417 int transport_overhead_per_packet) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 // Creates a new outgoing media stream with SSRCs and CNAME as described
419 // by sp.
420 virtual bool AddSendStream(const StreamParams& sp) = 0;
421 // Removes an outgoing 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 RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425 // Creates a new incoming media stream with SSRCs and CNAME as described
426 // by sp.
427 virtual bool AddRecvStream(const StreamParams& sp) = 0;
428 // Removes an incoming media stream.
429 // ssrc must be the first SSRC of the media stream if the stream uses
430 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200431 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000433 // Returns the absoulte sendtime extension id value from media channel.
434 virtual int GetRtpSendTimeExtnId() const {
435 return -1;
436 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000438 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700439 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
440 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700441 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000442 }
443
jbaucheec21bd2016-03-20 06:15:43 -0700444 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
445 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700446 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000447 }
448
449 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000450 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000451 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000452 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000453 if (!network_interface_)
454 return -1;
455
456 return network_interface_->SetOption(type, opt, option);
457 }
458
nisse51542be2016-02-12 02:27:06 -0800459 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000460 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000461 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000462 int ret;
463 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000464 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000465 value);
466 if (ret == 0) {
467 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000468 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000469 value);
470 }
471 return ret;
472 }
473
jbaucheec21bd2016-03-20 06:15:43 -0700474 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700475 bool rtcp,
476 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000477 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000478 if (!network_interface_)
479 return false;
480
stefanc1aeaf02015-10-15 07:26:07 -0700481 return (!rtcp) ? network_interface_->SendPacket(packet, options)
482 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000483 }
484
nisse51542be2016-02-12 02:27:06 -0800485 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000486 // |network_interface_| can be accessed from the worker_thread and
487 // from any MediaEngine threads. This critical section is to protect accessing
488 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000489 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000490 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000491};
492
wu@webrtc.org97077a32013-10-25 21:18:33 +0000493// The stats information is structured as follows:
494// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
495// Media contains a vector of SSRC infos that are exclusively used by this
496// media. (SSRCs shared between media streams can't be represented.)
497
498// Information about an SSRC.
499// This data may be locally recorded, or received in an RTCP SR or RR.
500struct SsrcSenderInfo {
501 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000503 timestamp(0) {
504 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200505 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000506 double timestamp; // NTP timestamp, represented as seconds since epoch.
507};
508
509struct SsrcReceiverInfo {
510 SsrcReceiverInfo()
511 : ssrc(0),
512 timestamp(0) {
513 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200514 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000515 double timestamp;
516};
517
518struct MediaSenderInfo {
519 MediaSenderInfo()
520 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 packets_sent(0),
522 packets_lost(0),
523 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000524 rtt_ms(0) {
525 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000526 void add_ssrc(const SsrcSenderInfo& stat) {
527 local_stats.push_back(stat);
528 }
529 // Temporary utility function for call sites that only provide SSRC.
530 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200531 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000532 SsrcSenderInfo stat;
533 stat.ssrc = ssrc;
534 add_ssrc(stat);
535 }
536 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200537 std::vector<uint32_t> ssrcs() const {
538 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000539 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
540 it != local_stats.end(); ++it) {
541 retval.push_back(it->ssrc);
542 }
543 return retval;
544 }
545 // Utility accessor for clients that make the assumption only one ssrc
546 // exists per media.
547 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200548 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000549 if (local_stats.size() > 0) {
550 return local_stats[0].ssrc;
551 } else {
552 return 0;
553 }
554 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200555 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000556 int packets_sent;
557 int packets_lost;
558 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000559 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000560 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800561 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000562 std::vector<SsrcSenderInfo> local_stats;
563 std::vector<SsrcReceiverInfo> remote_stats;
564};
565
566struct MediaReceiverInfo {
567 MediaReceiverInfo()
568 : bytes_rcvd(0),
569 packets_rcvd(0),
570 packets_lost(0),
571 fraction_lost(0.0) {
572 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000573 void add_ssrc(const SsrcReceiverInfo& stat) {
574 local_stats.push_back(stat);
575 }
576 // Temporary utility function for call sites that only provide SSRC.
577 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200578 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000579 SsrcReceiverInfo stat;
580 stat.ssrc = ssrc;
581 add_ssrc(stat);
582 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200583 std::vector<uint32_t> ssrcs() const {
584 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000585 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
586 it != local_stats.end(); ++it) {
587 retval.push_back(it->ssrc);
588 }
589 return retval;
590 }
591 // Utility accessor for clients that make the assumption only one ssrc
592 // exists per media.
593 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200594 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000595 if (local_stats.size() > 0) {
596 return local_stats[0].ssrc;
597 } else {
598 return 0;
599 }
600 }
601
Peter Boström0c4e06b2015-10-07 12:23:21 +0200602 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000603 int packets_rcvd;
604 int packets_lost;
605 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000606 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800607 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000608 std::vector<SsrcReceiverInfo> local_stats;
609 std::vector<SsrcSenderInfo> remote_stats;
610};
611
612struct VoiceSenderInfo : public MediaSenderInfo {
613 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000614 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000615 jitter_ms(0),
616 audio_level(0),
617 aec_quality_min(0.0),
618 echo_delay_median_ms(0),
619 echo_delay_std_ms(0),
620 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000621 echo_return_loss_enhancement(0),
ivoc8c63a822016-10-21 04:10:03 -0700622 residual_echo_likelihood(0.0f),
ivoc4e477a12017-01-15 08:29:46 -0800623 residual_echo_likelihood_recent_max(0.0f),
624 typing_noise_detected(false) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 int jitter_ms;
628 int audio_level;
629 float aec_quality_min;
630 int echo_delay_median_ms;
631 int echo_delay_std_ms;
632 int echo_return_loss;
633 int echo_return_loss_enhancement;
ivoc8c63a822016-10-21 04:10:03 -0700634 float residual_echo_likelihood;
ivoc4e477a12017-01-15 08:29:46 -0800635 float residual_echo_likelihood_recent_max;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000636 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637};
638
wu@webrtc.org97077a32013-10-25 21:18:33 +0000639struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000641 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000642 jitter_ms(0),
643 jitter_buffer_ms(0),
644 jitter_buffer_preferred_ms(0),
645 delay_estimate_ms(0),
646 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000647 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000648 speech_expand_rate(0),
649 secondary_decoded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200650 accelerate_rate(0),
651 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000652 decoding_calls_to_silence_generator(0),
653 decoding_calls_to_neteq(0),
654 decoding_normal(0),
655 decoding_plc(0),
656 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000657 decoding_plc_cng(0),
henrik.lundin63489782016-09-20 01:47:12 -0700658 decoding_muted_output(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200659 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661 int ext_seqnum;
662 int jitter_ms;
663 int jitter_buffer_ms;
664 int jitter_buffer_preferred_ms;
665 int delay_estimate_ms;
666 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000667 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000669 // fraction of synthesized speech inserted through expansion.
670 float speech_expand_rate;
671 // fraction of data out of secondary decoding, including FEC and RED.
672 float secondary_decoded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200673 // Fraction of data removed through time compression.
674 float accelerate_rate;
675 // Fraction of data inserted through time stretching.
676 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000677 int decoding_calls_to_silence_generator;
678 int decoding_calls_to_neteq;
679 int decoding_normal;
680 int decoding_plc;
681 int decoding_cng;
682 int decoding_plc_cng;
henrik.lundin63489782016-09-20 01:47:12 -0700683 int decoding_muted_output;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000684 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200685 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686};
687
wu@webrtc.org97077a32013-10-25 21:18:33 +0000688struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000690 : packets_cached(0),
691 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000692 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000694 send_frame_width(0),
695 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696 framerate_input(0),
697 framerate_sent(0),
698 nominal_bitrate(0),
699 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000700 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000701 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000702 avg_encode_ms(0),
sakal43536c32016-10-24 01:46:43 -0700703 encode_usage_percent(0),
704 frames_encoded(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000706 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800707 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100708 std::string encoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000709 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000711 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000713 int send_frame_width;
714 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 int framerate_input;
716 int framerate_sent;
717 int nominal_bitrate;
718 int preferred_bitrate;
719 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000720 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000721 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000722 int encode_usage_percent;
sakal43536c32016-10-24 01:46:43 -0700723 uint32_t frames_encoded;
sakal87da4042016-10-31 06:53:47 -0700724 rtc::Optional<uint64_t> qp_sum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725};
726
wu@webrtc.org97077a32013-10-25 21:18:33 +0000727struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000729 : packets_concealed(0),
730 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000731 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 nacks_sent(0),
733 frame_width(0),
734 frame_height(0),
735 framerate_rcvd(0),
736 framerate_decoded(0),
737 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000738 framerate_render_input(0),
739 framerate_render_output(0),
hbos42f6d2f2017-01-20 03:56:50 -0800740 frames_received(0),
sakale5ba44e2016-10-26 07:09:24 -0700741 frames_decoded(0),
hbos50cfe1f2017-01-23 07:21:55 -0800742 frames_rendered(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000743 decode_ms(0),
744 max_decode_ms(0),
745 jitter_buffer_ms(0),
746 min_playout_delay_ms(0),
747 render_delay_ms(0),
748 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000749 current_delay_ms(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000750 capture_start_ntp_time_ms(-1) {
751 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000753 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800754 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100755 std::string decoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000756 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000758 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 int nacks_sent;
760 int frame_width;
761 int frame_height;
762 int framerate_rcvd;
763 int framerate_decoded;
764 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000765 // Framerate as sent to the renderer.
766 int framerate_render_input;
767 // Framerate that the renderer reports.
768 int framerate_render_output;
hbos42f6d2f2017-01-20 03:56:50 -0800769 uint32_t frames_received;
sakale5ba44e2016-10-26 07:09:24 -0700770 uint32_t frames_decoded;
hbos50cfe1f2017-01-23 07:21:55 -0800771 uint32_t frames_rendered;
sakalcc452e12017-02-09 04:53:45 -0800772 rtc::Optional<uint64_t> qp_sum;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000773
774 // All stats below are gathered per-VideoReceiver, but some will be correlated
775 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
776 // structures, reflect this in the new layout.
777
778 // Current frame decode latency.
779 int decode_ms;
780 // Maximum observed frame decode latency.
781 int max_decode_ms;
782 // Jitter (network-related) latency.
783 int jitter_buffer_ms;
784 // Requested minimum playout latency.
785 int min_playout_delay_ms;
786 // Requested latency to account for rendering delay.
787 int render_delay_ms;
788 // Target overall delay: network+decode+render, accounting for
789 // min_playout_delay_ms.
790 int target_delay_ms;
791 // Current overall delay, possibly ramping towards target_delay_ms.
792 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000793
794 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200795 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796};
797
wu@webrtc.org97077a32013-10-25 21:18:33 +0000798struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000800 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 }
802
Peter Boström0c4e06b2015-10-07 12:23:21 +0200803 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804};
805
wu@webrtc.org97077a32013-10-25 21:18:33 +0000806struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000808 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 }
810
Peter Boström0c4e06b2015-10-07 12:23:21 +0200811 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812};
813
814struct BandwidthEstimationInfo {
815 BandwidthEstimationInfo()
816 : available_send_bandwidth(0),
817 available_recv_bandwidth(0),
818 target_enc_bitrate(0),
819 actual_enc_bitrate(0),
820 retransmit_bitrate(0),
821 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000822 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 }
824
825 int available_send_bandwidth;
826 int available_recv_bandwidth;
827 int target_enc_bitrate;
828 int actual_enc_bitrate;
829 int retransmit_bitrate;
830 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000831 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832};
833
hbosa65704b2016-11-14 02:28:16 -0800834// Maps from payload type to |RtpCodecParameters|.
835typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
836
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837struct VoiceMediaInfo {
838 void Clear() {
839 senders.clear();
840 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800841 send_codecs.clear();
842 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 }
844 std::vector<VoiceSenderInfo> senders;
845 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800846 RtpCodecParametersMap send_codecs;
847 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848};
849
850struct VideoMediaInfo {
851 void Clear() {
852 senders.clear();
853 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700854 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800855 send_codecs.clear();
856 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 }
858 std::vector<VideoSenderInfo> senders;
859 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700860 // Deprecated.
861 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700862 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800863 RtpCodecParametersMap send_codecs;
864 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865};
866
867struct DataMediaInfo {
868 void Clear() {
869 senders.clear();
870 receivers.clear();
871 }
872 std::vector<DataSenderInfo> senders;
873 std::vector<DataReceiverInfo> receivers;
874};
875
deadbeef13871492015-12-09 12:37:51 -0800876struct RtcpParameters {
877 bool reduced_size = false;
878};
879
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700880template <class Codec>
881struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800882 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700883 std::ostringstream ost;
884 ost << "{";
885 ost << "codecs: " << VectorToString(codecs) << ", ";
886 ost << "extensions: " << VectorToString(extensions);
887 ost << "}";
888 return ost.str();
889 }
890
891 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700892 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700893 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800894 RtcpParameters rtcp;
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200895 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700896};
897
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700898// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
899// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700900template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700901struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800902 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700903 std::ostringstream ost;
904 ost << "{";
905 ost << "codecs: " << VectorToString(this->codecs) << ", ";
906 ost << "extensions: " << VectorToString(this->extensions) << ", ";
pbos378dc772016-01-28 15:58:41 -0800907 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
nisse05103312016-03-16 02:22:50 -0700908 ost << "}";
909 return ost.str();
910 }
911
912 int max_bandwidth_bps = -1;
913};
914
915struct AudioSendParameters : RtpSendParameters<AudioCodec> {
916 std::string ToString() const override {
917 std::ostringstream ost;
918 ost << "{";
919 ost << "codecs: " << VectorToString(this->codecs) << ", ";
920 ost << "extensions: " << VectorToString(this->extensions) << ", ";
921 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700922 ost << "options: " << options.ToString();
923 ost << "}";
924 return ost.str();
925 }
926
nisse05103312016-03-16 02:22:50 -0700927 AudioOptions options;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700928};
929
930struct AudioRecvParameters : RtpParameters<AudioCodec> {
931};
932
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933class VoiceMediaChannel : public MediaChannel {
934 public:
935 enum Error {
936 ERROR_NONE = 0, // No error.
937 ERROR_OTHER, // Other errors.
938 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
939 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
940 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
941 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
942 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
943 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
944 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
945 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
946 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
947 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
948 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
949 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
950 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
951 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
952 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
953 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
954 };
955
956 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700957 explicit VoiceMediaChannel(const MediaConfig& config)
958 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200960 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
961 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700962 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
963 virtual bool SetRtpSendParameters(
964 uint32_t ssrc,
965 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700966 // Get the receive parameters for the incoming stream identified by |ssrc|.
967 // If |ssrc| is 0, retrieve the receive parameters for the default receive
968 // stream, which is used when SSRCs are not signaled. Note that calling with
969 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
970 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700971 virtual webrtc::RtpParameters GetRtpReceiveParameters(
972 uint32_t ssrc) const = 0;
973 virtual bool SetRtpReceiveParameters(
974 uint32_t ssrc,
975 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700977 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800979 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700980 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200981 virtual bool SetAudioSend(uint32_t ssrc,
982 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700983 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800984 AudioSource* source) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 // Gets current energy levels for all incoming streams.
986 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
987 // Get the current energy level of the stream sent to the speaker.
988 virtual int GetOutputLevel() = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700989 // Set speaker output volume of the specified ssrc.
990 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800992 virtual bool CanInsertDtmf() = 0;
993 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000995 // The valid value for the |event| are 0 to 15 which corresponding to
996 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800997 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 // Gets quality stats for the channel.
999 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +01001000
1001 virtual void SetRawAudioSink(
1002 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -08001003 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -07001004
1005 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006};
1007
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001008// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
1009// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -07001010struct VideoSendParameters : RtpSendParameters<VideoCodec> {
nisse4b4dc862016-02-17 05:25:36 -08001011 // Use conference mode? This flag comes from the remote
1012 // description's SDP line 'a=x-google-flag:conference', copied over
1013 // by VideoChannel::SetRemoteContent_w, and ultimately used by
1014 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -07001015 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -08001016 // The special screencast behaviour is disabled by default.
1017 bool conference_mode = false;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001018};
1019
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001020// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
1021// encapsulate all the parameters needed for a video RtpReceiver.
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001022struct VideoRecvParameters : RtpParameters<VideoCodec> {
1023};
1024
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025class VideoMediaChannel : public MediaChannel {
1026 public:
1027 enum Error {
1028 ERROR_NONE = 0, // No error.
1029 ERROR_OTHER, // Other errors.
1030 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1031 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1032 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1033 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1034 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1035 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1036 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1037 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1038 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1039 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1040 };
1041
nisse08582ff2016-02-04 01:24:52 -08001042 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -07001043 explicit VideoMediaChannel(const MediaConfig& config)
1044 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001046
1047 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
1048 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001049 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
1050 virtual bool SetRtpSendParameters(
1051 uint32_t ssrc,
1052 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -07001053 // Get the receive parameters for the incoming stream identified by |ssrc|.
1054 // If |ssrc| is 0, retrieve the receive parameters for the default receive
1055 // stream, which is used when SSRCs are not signaled. Note that calling with
1056 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
1057 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001058 virtual webrtc::RtpParameters GetRtpReceiveParameters(
1059 uint32_t ssrc) const = 0;
1060 virtual bool SetRtpReceiveParameters(
1061 uint32_t ssrc,
1062 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 // Gets the currently set codecs/payload types to be used for outgoing media.
1064 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 // Starts or stops transmission (and potentially capture) of local video.
1066 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -07001067 // Configure stream for sending and register a source.
1068 // The |ssrc| must correspond to a registered send stream.
1069 virtual bool SetVideoSend(
1070 uint32_t ssrc,
1071 bool enable,
1072 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -08001073 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -08001074 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -07001075 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -08001076 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -08001077 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -07001078 // This fills the "bitrate parts" (rtx, video bitrate) of the
1079 // BandwidthEstimationInfo, since that part that isn't possible to get
1080 // through webrtc::Call::GetStats, as they are statistics of the send
1081 // streams.
1082 // TODO(holmer): We should change this so that either BWE graphs doesn't
1083 // need access to bitrates of the streams, or change the (RTC)StatsCollector
1084 // so that it's getting the send stream stats separately by calling
1085 // GetStats(), and merges with BandwidthEstimationInfo by itself.
1086 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001088 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089};
1090
1091enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001092 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1093 // values.
1094 DMT_NONE = 0,
1095 DMT_CONTROL = 1,
1096 DMT_BINARY = 2,
1097 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098};
1099
1100// Info about data received in DataMediaChannel. For use in
1101// DataMediaChannel::SignalDataReceived and in all of the signals that
1102// signal fires, on up the chain.
1103struct ReceiveDataParams {
1104 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001105 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1106 union {
1107 uint32_t ssrc;
1108 int sid;
1109 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 // The type of message (binary, text, or control).
1111 DataMessageType type;
1112 // A per-stream value incremented per packet in the stream.
1113 int seq_num;
1114 // A per-stream value monotonically increasing with time.
1115 int timestamp;
1116
deadbeef953c2ce2017-01-09 14:53:41 -08001117 ReceiveDataParams() : sid(0), type(DMT_TEXT), seq_num(0), timestamp(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118};
1119
1120struct SendDataParams {
1121 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001122 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1123 union {
1124 uint32_t ssrc;
1125 int sid;
1126 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127 // The type of message (binary, text, or control).
1128 DataMessageType type;
1129
1130 // For SCTP, whether to send messages flagged as ordered or not.
1131 // If false, messages can be received out of order.
1132 bool ordered;
1133 // For SCTP, whether the messages are sent reliably or not.
1134 // If false, messages may be lost.
1135 bool reliable;
1136 // For SCTP, if reliable == false, provide partial reliability by
1137 // resending up to this many times. Either count or millis
1138 // is supported, not both at the same time.
1139 int max_rtx_count;
1140 // For SCTP, if reliable == false, provide partial reliability by
1141 // resending for up to this many milliseconds. Either count or millis
1142 // is supported, not both at the same time.
1143 int max_rtx_ms;
1144
deadbeef953c2ce2017-01-09 14:53:41 -08001145 SendDataParams()
1146 : sid(0),
1147 type(DMT_TEXT),
1148 // TODO(pthatcher): Make these true by default?
1149 ordered(false),
1150 reliable(false),
1151 max_rtx_count(0),
1152 max_rtx_ms(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001153};
1154
1155enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1156
nisse05103312016-03-16 02:22:50 -07001157struct DataSendParameters : RtpSendParameters<DataCodec> {
solenberg7e4e01a2015-12-02 08:05:01 -08001158 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001159 std::ostringstream ost;
1160 // Options and extensions aren't used.
1161 ost << "{";
1162 ost << "codecs: " << VectorToString(codecs) << ", ";
pbos378dc772016-01-28 15:58:41 -08001163 ost << "max_bandwidth_bps: " << max_bandwidth_bps;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001164 ost << "}";
1165 return ost.str();
1166 }
1167};
1168
1169struct DataRecvParameters : RtpParameters<DataCodec> {
1170};
1171
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001172class DataMediaChannel : public MediaChannel {
1173 public:
1174 enum Error {
1175 ERROR_NONE = 0, // No error.
1176 ERROR_OTHER, // Other errors.
1177 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1178 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1179 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1180 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1181 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1182 };
1183
zhihuangebbe4f22016-12-06 10:45:42 -08001184 DataMediaChannel() {}
1185 DataMediaChannel(const MediaConfig& config) : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001186 virtual ~DataMediaChannel() {}
1187
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001188 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1189 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001190
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001191 // TODO(pthatcher): Implement this.
1192 virtual bool GetStats(DataMediaInfo* info) { return true; }
1193
1194 virtual bool SetSend(bool send) = 0;
1195 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001196
Honghai Zhangcc411c02016-03-29 17:27:21 -07001197 virtual void OnNetworkRouteChanged(const std::string& transport_name,
Honghai Zhang0e533ef2016-04-19 15:41:36 -07001198 const rtc::NetworkRoute& network_route) {}
Honghai Zhangcc411c02016-03-29 17:27:21 -07001199
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200 virtual bool SendData(
1201 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -07001202 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001203 SendDataResult* result = NULL) = 0;
1204 // Signals when data is received (params, data, len)
1205 sigslot::signal3<const ReceiveDataParams&,
1206 const char*,
1207 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001208 // Signal when the media channel is ready to send the stream. Arguments are:
1209 // writable(bool)
1210 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001211};
1212
1213} // namespace cricket
1214
kjellandera96e2d72016-02-04 23:52:28 -08001215#endif // WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_