blob: 40869594e58956c2d3edc34ad5303732b318800a [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
terelius54f91712016-06-01 11:18:56 -070014#include <algorithm>
kwiberg686a8ef2016-02-26 03:00:35 -080015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
17#include <vector>
18
skvladdc1c62c2016-03-16 19:07:43 -070019#include "webrtc/api/rtpparameters.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000020#include "webrtc/base/basictypes.h"
kwiberga4ac4782016-04-29 08:00:22 -070021#include "webrtc/base/buffer.h"
jbaucheec21bd2016-03-20 06:15:43 -070022#include "webrtc/base/copyonwritebuffer.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000023#include "webrtc/base/dscp.h"
24#include "webrtc/base/logging.h"
Honghai Zhangcc411c02016-03-29 17:27:21 -070025#include "webrtc/base/networkroute.h"
Karl Wibergbe579832015-11-10 22:34:18 +010026#include "webrtc/base/optional.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000027#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
skvladdc1c62c2016-03-16 19:07:43 -070084template <typename T>
85static T MinPositive(T a, T b) {
86 if (a <= 0) {
87 return b;
88 }
89 if (b <= 0) {
90 return a;
91 }
92 return std::min(a, b);
93}
94
nisse528b7932017-05-08 03:21:43 -070095// Construction-time settings, passed on when creating
nisse51542be2016-02-12 02:27:06 -080096// MediaChannels.
97struct MediaConfig {
98 // Set DSCP value on packets. This flag comes from the
99 // PeerConnection constraint 'googDscp'.
100 bool enable_dscp = false;
101
nisse0db023a2016-03-01 04:29:59 -0800102 // Video-specific config.
103 struct Video {
104 // Enable WebRTC CPU Overuse Detection. This flag comes from the
perkj803d97f2016-11-01 11:45:46 -0700105 // PeerConnection constraint 'googCpuOveruseDetection'.
nisse0db023a2016-03-01 04:29:59 -0800106 bool enable_cpu_overuse_detection = true;
nisse51542be2016-02-12 02:27:06 -0800107
nisse0db023a2016-03-01 04:29:59 -0800108 // Enable WebRTC suspension of video. No video frames will be sent
109 // when the bitrate is below the configured minimum bitrate. This
110 // flag comes from the PeerConnection constraint
111 // 'googSuspendBelowMinBitrate', and WebRtcVideoChannel2 copies it
112 // to VideoSendStream::Config::suspend_below_min_bitrate.
113 bool suspend_below_min_bitrate = false;
nisse51542be2016-02-12 02:27:06 -0800114
nisse0db023a2016-03-01 04:29:59 -0800115 // Set to true if the renderer has an algorithm of frame selection.
116 // If the value is true, then WebRTC will hand over a frame as soon as
117 // possible without delay, and rendering smoothness is completely the duty
118 // of the renderer;
119 // If the value is false, then WebRTC is responsible to delay frame release
120 // in order to increase rendering smoothness.
121 //
122 // This flag comes from PeerConnection's RtcConfiguration, but is
123 // currently only set by the command line flag
124 // 'disable-rtc-smoothness-algorithm'.
125 // WebRtcVideoChannel2::AddRecvStream copies it to the created
126 // WebRtcVideoReceiveStream, where it is returned by the
127 // SmoothsRenderedFrames method. This method is used by the
128 // VideoReceiveStream, where the value is passed on to the
129 // IncomingVideoStream constructor.
130 bool disable_prerenderer_smoothing = false;
sergeyu80ed35e2016-11-28 13:11:13 -0800131
132 // Enables periodic bandwidth probing in application-limited region.
133 bool periodic_alr_bandwidth_probing = false;
nisse0db023a2016-03-01 04:29:59 -0800134 } video;
deadbeef293e9262017-01-11 12:28:30 -0800135
136 bool operator==(const MediaConfig& o) const {
137 return enable_dscp == o.enable_dscp &&
138 video.enable_cpu_overuse_detection ==
139 o.video.enable_cpu_overuse_detection &&
140 video.suspend_below_min_bitrate ==
141 o.video.suspend_below_min_bitrate &&
142 video.disable_prerenderer_smoothing ==
143 o.video.disable_prerenderer_smoothing &&
144 video.periodic_alr_bandwidth_probing ==
145 o.video.periodic_alr_bandwidth_probing;
146 }
147
148 bool operator!=(const MediaConfig& o) const { return !(*this == o); }
nisse51542be2016-02-12 02:27:06 -0800149};
150
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
152// Used to be flags, but that makes it hard to selectively apply options.
153// We are moving all of the setting of options to structs like this,
154// but some things currently still use flags.
155struct AudioOptions {
156 void SetAll(const AudioOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700157 SetFrom(&echo_cancellation, change.echo_cancellation);
158 SetFrom(&auto_gain_control, change.auto_gain_control);
159 SetFrom(&noise_suppression, change.noise_suppression);
160 SetFrom(&highpass_filter, change.highpass_filter);
161 SetFrom(&stereo_swapping, change.stereo_swapping);
162 SetFrom(&audio_jitter_buffer_max_packets,
163 change.audio_jitter_buffer_max_packets);
164 SetFrom(&audio_jitter_buffer_fast_accelerate,
165 change.audio_jitter_buffer_fast_accelerate);
166 SetFrom(&typing_detection, change.typing_detection);
167 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise);
kwiberg102c6a62015-10-30 02:47:38 -0700168 SetFrom(&adjust_agc_delta, change.adjust_agc_delta);
169 SetFrom(&experimental_agc, change.experimental_agc);
170 SetFrom(&extended_filter_aec, change.extended_filter_aec);
171 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec);
172 SetFrom(&experimental_ns, change.experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700173 SetFrom(&intelligibility_enhancer, change.intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700174 SetFrom(&level_control, change.level_control);
ivocb829d9f2016-11-15 02:34:47 -0800175 SetFrom(&residual_echo_detector, change.residual_echo_detector);
kwiberg102c6a62015-10-30 02:47:38 -0700176 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov);
177 SetFrom(&tx_agc_digital_compression_gain,
178 change.tx_agc_digital_compression_gain);
179 SetFrom(&tx_agc_limiter, change.tx_agc_limiter);
180 SetFrom(&recording_sample_rate, change.recording_sample_rate);
181 SetFrom(&playout_sample_rate, change.playout_sample_rate);
kwiberg102c6a62015-10-30 02:47:38 -0700182 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700183 SetFrom(&audio_network_adaptor, change.audio_network_adaptor);
184 SetFrom(&audio_network_adaptor_config, change.audio_network_adaptor_config);
aleloie33c5d92016-10-20 01:53:27 -0700185 SetFrom(&level_control_initial_peak_level_dbfs,
186 change.level_control_initial_peak_level_dbfs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 }
188
189 bool operator==(const AudioOptions& o) const {
190 return echo_cancellation == o.echo_cancellation &&
peaha3333bf2016-06-30 00:02:34 -0700191 auto_gain_control == o.auto_gain_control &&
192 noise_suppression == o.noise_suppression &&
193 highpass_filter == o.highpass_filter &&
194 stereo_swapping == o.stereo_swapping &&
195 audio_jitter_buffer_max_packets ==
196 o.audio_jitter_buffer_max_packets &&
197 audio_jitter_buffer_fast_accelerate ==
198 o.audio_jitter_buffer_fast_accelerate &&
199 typing_detection == o.typing_detection &&
200 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
201 experimental_agc == o.experimental_agc &&
202 extended_filter_aec == o.extended_filter_aec &&
203 delay_agnostic_aec == o.delay_agnostic_aec &&
204 experimental_ns == o.experimental_ns &&
205 intelligibility_enhancer == o.intelligibility_enhancer &&
206 level_control == o.level_control &&
ivocb829d9f2016-11-15 02:34:47 -0800207 residual_echo_detector == o.residual_echo_detector &&
peaha3333bf2016-06-30 00:02:34 -0700208 adjust_agc_delta == o.adjust_agc_delta &&
209 tx_agc_target_dbov == o.tx_agc_target_dbov &&
210 tx_agc_digital_compression_gain ==
211 o.tx_agc_digital_compression_gain &&
212 tx_agc_limiter == o.tx_agc_limiter &&
213 recording_sample_rate == o.recording_sample_rate &&
214 playout_sample_rate == o.playout_sample_rate &&
aleloie33c5d92016-10-20 01:53:27 -0700215 combined_audio_video_bwe == o.combined_audio_video_bwe &&
minyue6b825df2016-10-31 04:08:32 -0700216 audio_network_adaptor == o.audio_network_adaptor &&
217 audio_network_adaptor_config == o.audio_network_adaptor_config &&
aleloie33c5d92016-10-20 01:53:27 -0700218 level_control_initial_peak_level_dbfs ==
219 o.level_control_initial_peak_level_dbfs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 }
deadbeef119760a2016-04-04 11:43:27 -0700221 bool operator!=(const AudioOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222
223 std::string ToString() const {
224 std::ostringstream ost;
225 ost << "AudioOptions {";
226 ost << ToStringIfSet("aec", echo_cancellation);
227 ost << ToStringIfSet("agc", auto_gain_control);
228 ost << ToStringIfSet("ns", noise_suppression);
229 ost << ToStringIfSet("hf", highpass_filter);
230 ost << ToStringIfSet("swap", stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200231 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
232 audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200233 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
234 audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000236 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
238 ost << ToStringIfSet("experimental_agc", experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200239 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100240 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000241 ost << ToStringIfSet("experimental_ns", experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700242 ost << ToStringIfSet("intelligibility_enhancer", intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700243 ost << ToStringIfSet("level_control", level_control);
aleloie33c5d92016-10-20 01:53:27 -0700244 ost << ToStringIfSet("level_control_initial_peak_level_dbfs",
245 level_control_initial_peak_level_dbfs);
ivocb829d9f2016-11-15 02:34:47 -0800246 ost << ToStringIfSet("residual_echo_detector", residual_echo_detector);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000247 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
248 ost << ToStringIfSet("tx_agc_digital_compression_gain",
249 tx_agc_digital_compression_gain);
250 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000251 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
252 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000253 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700254 ost << ToStringIfSet("audio_network_adaptor", audio_network_adaptor);
255 // The adaptor config is a serialized proto buffer and therefore not human
256 // readable. So we comment out the following line.
257 // ost << ToStringIfSet("audio_network_adaptor_config",
258 // audio_network_adaptor_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 ost << "}";
260 return ost.str();
261 }
262
263 // Audio processing that attempts to filter away the output signal from
264 // later inbound pickup.
Karl Wibergbe579832015-11-10 22:34:18 +0100265 rtc::Optional<bool> echo_cancellation;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000266 // Audio processing to adjust the sensitivity of the local mic dynamically.
Karl Wibergbe579832015-11-10 22:34:18 +0100267 rtc::Optional<bool> auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 // Audio processing to filter out background noise.
Karl Wibergbe579832015-11-10 22:34:18 +0100269 rtc::Optional<bool> noise_suppression;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 // Audio processing to remove background noise of lower frequencies.
Karl Wibergbe579832015-11-10 22:34:18 +0100271 rtc::Optional<bool> highpass_filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 // Audio processing to swap the left and right channels.
Karl Wibergbe579832015-11-10 22:34:18 +0100273 rtc::Optional<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200274 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Karl Wibergbe579832015-11-10 22:34:18 +0100275 rtc::Optional<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200276 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Karl Wibergbe579832015-11-10 22:34:18 +0100277 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278 // Audio processing to detect typing.
Karl Wibergbe579832015-11-10 22:34:18 +0100279 rtc::Optional<bool> typing_detection;
280 rtc::Optional<bool> aecm_generate_comfort_noise;
Karl Wibergbe579832015-11-10 22:34:18 +0100281 rtc::Optional<int> adjust_agc_delta;
282 rtc::Optional<bool> experimental_agc;
283 rtc::Optional<bool> extended_filter_aec;
284 rtc::Optional<bool> delay_agnostic_aec;
285 rtc::Optional<bool> experimental_ns;
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700286 rtc::Optional<bool> intelligibility_enhancer;
peaha3333bf2016-06-30 00:02:34 -0700287 rtc::Optional<bool> level_control;
aleloie33c5d92016-10-20 01:53:27 -0700288 // Specifies an optional initialization value for the level controller.
289 rtc::Optional<float> level_control_initial_peak_level_dbfs;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000290 // Note that tx_agc_* only applies to non-experimental AGC.
ivocb829d9f2016-11-15 02:34:47 -0800291 rtc::Optional<bool> residual_echo_detector;
Karl Wibergbe579832015-11-10 22:34:18 +0100292 rtc::Optional<uint16_t> tx_agc_target_dbov;
293 rtc::Optional<uint16_t> tx_agc_digital_compression_gain;
294 rtc::Optional<bool> tx_agc_limiter;
295 rtc::Optional<uint32_t> recording_sample_rate;
296 rtc::Optional<uint32_t> playout_sample_rate;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000297 // Enable combined audio+bandwidth BWE.
nisse51542be2016-02-12 02:27:06 -0800298 // TODO(pthatcher): This flag is set from the
299 // "googCombinedAudioVideoBwe", but not used anywhere. So delete it,
300 // and check if any other AudioOptions members are unused.
Karl Wibergbe579832015-11-10 22:34:18 +0100301 rtc::Optional<bool> combined_audio_video_bwe;
minyue6b825df2016-10-31 04:08:32 -0700302 // Enable audio network adaptor.
303 rtc::Optional<bool> audio_network_adaptor;
304 // Config string for audio network adaptor.
305 rtc::Optional<std::string> audio_network_adaptor_config;
kwiberg102c6a62015-10-30 02:47:38 -0700306
307 private:
308 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100309 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700310 if (o) {
311 *s = o;
312 }
313 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314};
315
316// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
317// Used to be flags, but that makes it hard to selectively apply options.
318// We are moving all of the setting of options to structs like this,
319// but some things currently still use flags.
320struct VideoOptions {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700322 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800323 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100324 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 }
326
327 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800328 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100329 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
330 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 }
deadbeef119760a2016-04-04 11:43:27 -0700332 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333
334 std::string ToString() const {
335 std::ostringstream ost;
336 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800338 ost << ToStringIfSet("screencast min bitrate kbps",
339 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100340 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 ost << "}";
342 return ost.str();
343 }
344
nisseb163c3f2016-01-29 01:14:38 -0800345 // Enable denoising? This flag comes from the getUserMedia
346 // constraint 'googNoiseReduction', and WebRtcVideoEngine2 passes it
347 // on to the codec options. Disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100348 rtc::Optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800349 // Force screencast to use a minimum bitrate. This flag comes from
350 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
351 // copied to the encoder config by WebRtcVideoChannel2.
352 rtc::Optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100353 // Set by screencast sources. Implies selection of encoding settings
354 // suitable for screencast. Most likely not the right way to do
355 // things, e.g., screencast of a text document and screencast of a
356 // youtube video have different needs.
357 rtc::Optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700358
359 private:
360 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100361 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700362 if (o) {
363 *s = o;
364 }
365 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366};
367
isheriffa1c548b2016-05-31 16:12:24 -0700368// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
369struct RtpHeaderExtension {
370 RtpHeaderExtension() : id(0) {}
371 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
372
373 std::string ToString() const {
374 std::ostringstream ost;
375 ost << "{";
376 ost << "uri: " << uri;
377 ost << ", id: " << id;
378 ost << "}";
379 return ost.str();
380 }
381
382 std::string uri;
383 int id;
384};
385
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386class MediaChannel : public sigslot::has_slots<> {
387 public:
388 class NetworkInterface {
389 public:
390 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700391 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700392 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700393 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700394 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000395 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396 int option) = 0;
397 virtual ~NetworkInterface() {}
398 };
399
terelius54f91712016-06-01 11:18:56 -0700400 explicit MediaChannel(const MediaConfig& config)
nisse51542be2016-02-12 02:27:06 -0800401 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
402 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 virtual ~MediaChannel() {}
404
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000405 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000406 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000407 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 network_interface_ = iface;
nisse51542be2016-02-12 02:27:06 -0800409 SetDscp(enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 }
nisse51542be2016-02-12 02:27:06 -0800411 virtual rtc::DiffServCodePoint PreferredDscp() const {
412 return rtc::DSCP_DEFAULT;
413 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700415 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000416 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700418 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000419 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420 // Called when the socket's ability to send has changed.
421 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700422 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700423 virtual void OnNetworkRouteChanged(
424 const std::string& transport_name,
425 const rtc::NetworkRoute& network_route) = 0;
michaelt79e05882016-11-08 02:50:09 -0800426 // Called when the rtp transport overhead changed.
427 virtual void OnTransportOverheadChanged(
428 int transport_overhead_per_packet) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000429 // Creates a new outgoing media stream with SSRCs and CNAME as described
430 // by sp.
431 virtual bool AddSendStream(const StreamParams& sp) = 0;
432 // Removes an outgoing media stream.
433 // ssrc must be the first SSRC of the media stream if the stream uses
434 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200435 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436 // Creates a new incoming media stream with SSRCs and CNAME as described
437 // by sp.
438 virtual bool AddRecvStream(const StreamParams& sp) = 0;
439 // Removes an incoming media stream.
440 // ssrc must be the first SSRC of the media stream if the stream uses
441 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200442 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000444 // Returns the absoulte sendtime extension id value from media channel.
445 virtual int GetRtpSendTimeExtnId() const {
446 return -1;
447 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000449 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700450 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
451 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700452 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000453 }
454
jbaucheec21bd2016-03-20 06:15:43 -0700455 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
456 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700457 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000458 }
459
460 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000461 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000462 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000463 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000464 if (!network_interface_)
465 return -1;
466
467 return network_interface_->SetOption(type, opt, option);
468 }
469
nisse51542be2016-02-12 02:27:06 -0800470 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000471 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000472 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000473 int ret;
474 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000475 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000476 value);
477 if (ret == 0) {
478 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000479 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000480 value);
481 }
482 return ret;
483 }
484
jbaucheec21bd2016-03-20 06:15:43 -0700485 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700486 bool rtcp,
487 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000488 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000489 if (!network_interface_)
490 return false;
491
stefanc1aeaf02015-10-15 07:26:07 -0700492 return (!rtcp) ? network_interface_->SendPacket(packet, options)
493 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000494 }
495
nisse51542be2016-02-12 02:27:06 -0800496 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000497 // |network_interface_| can be accessed from the worker_thread and
498 // from any MediaEngine threads. This critical section is to protect accessing
499 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000500 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000501 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502};
503
wu@webrtc.org97077a32013-10-25 21:18:33 +0000504// The stats information is structured as follows:
505// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
506// Media contains a vector of SSRC infos that are exclusively used by this
507// media. (SSRCs shared between media streams can't be represented.)
508
509// Information about an SSRC.
510// This data may be locally recorded, or received in an RTCP SR or RR.
511struct SsrcSenderInfo {
512 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000514 timestamp(0) {
515 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200516 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000517 double timestamp; // NTP timestamp, represented as seconds since epoch.
518};
519
520struct SsrcReceiverInfo {
521 SsrcReceiverInfo()
522 : ssrc(0),
523 timestamp(0) {
524 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200525 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000526 double timestamp;
527};
528
529struct MediaSenderInfo {
530 MediaSenderInfo()
531 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000532 packets_sent(0),
533 packets_lost(0),
534 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000535 rtt_ms(0) {
536 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000537 void add_ssrc(const SsrcSenderInfo& stat) {
538 local_stats.push_back(stat);
539 }
540 // Temporary utility function for call sites that only provide SSRC.
541 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200542 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000543 SsrcSenderInfo stat;
544 stat.ssrc = ssrc;
545 add_ssrc(stat);
546 }
547 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200548 std::vector<uint32_t> ssrcs() const {
549 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000550 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
551 it != local_stats.end(); ++it) {
552 retval.push_back(it->ssrc);
553 }
554 return retval;
555 }
556 // Utility accessor for clients that make the assumption only one ssrc
557 // exists per media.
558 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200559 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000560 if (local_stats.size() > 0) {
561 return local_stats[0].ssrc;
562 } else {
563 return 0;
564 }
565 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200566 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000567 int packets_sent;
568 int packets_lost;
569 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000570 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000571 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800572 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000573 std::vector<SsrcSenderInfo> local_stats;
574 std::vector<SsrcReceiverInfo> remote_stats;
575};
576
577struct MediaReceiverInfo {
578 MediaReceiverInfo()
579 : bytes_rcvd(0),
580 packets_rcvd(0),
581 packets_lost(0),
582 fraction_lost(0.0) {
583 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000584 void add_ssrc(const SsrcReceiverInfo& stat) {
585 local_stats.push_back(stat);
586 }
587 // Temporary utility function for call sites that only provide SSRC.
588 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200589 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000590 SsrcReceiverInfo stat;
591 stat.ssrc = ssrc;
592 add_ssrc(stat);
593 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200594 std::vector<uint32_t> ssrcs() const {
595 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000596 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
597 it != local_stats.end(); ++it) {
598 retval.push_back(it->ssrc);
599 }
600 return retval;
601 }
602 // Utility accessor for clients that make the assumption only one ssrc
603 // exists per media.
604 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200605 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000606 if (local_stats.size() > 0) {
607 return local_stats[0].ssrc;
608 } else {
609 return 0;
610 }
611 }
612
Peter Boström0c4e06b2015-10-07 12:23:21 +0200613 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000614 int packets_rcvd;
615 int packets_lost;
616 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000617 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800618 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000619 std::vector<SsrcReceiverInfo> local_stats;
620 std::vector<SsrcSenderInfo> remote_stats;
621};
622
623struct VoiceSenderInfo : public MediaSenderInfo {
624 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000625 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626 jitter_ms(0),
627 audio_level(0),
628 aec_quality_min(0.0),
629 echo_delay_median_ms(0),
630 echo_delay_std_ms(0),
631 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000632 echo_return_loss_enhancement(0),
ivoc8c63a822016-10-21 04:10:03 -0700633 residual_echo_likelihood(0.0f),
ivoc4e477a12017-01-15 08:29:46 -0800634 residual_echo_likelihood_recent_max(0.0f),
635 typing_noise_detected(false) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000638 int jitter_ms;
639 int audio_level;
640 float aec_quality_min;
641 int echo_delay_median_ms;
642 int echo_delay_std_ms;
643 int echo_return_loss;
644 int echo_return_loss_enhancement;
ivoc8c63a822016-10-21 04:10:03 -0700645 float residual_echo_likelihood;
ivoc4e477a12017-01-15 08:29:46 -0800646 float residual_echo_likelihood_recent_max;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000647 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000648};
649
wu@webrtc.org97077a32013-10-25 21:18:33 +0000650struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000651 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000652 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653 jitter_ms(0),
654 jitter_buffer_ms(0),
655 jitter_buffer_preferred_ms(0),
656 delay_estimate_ms(0),
657 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000658 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000659 speech_expand_rate(0),
660 secondary_decoded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200661 accelerate_rate(0),
662 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000663 decoding_calls_to_silence_generator(0),
664 decoding_calls_to_neteq(0),
665 decoding_normal(0),
666 decoding_plc(0),
667 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000668 decoding_plc_cng(0),
henrik.lundin63489782016-09-20 01:47:12 -0700669 decoding_muted_output(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200670 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 int ext_seqnum;
673 int jitter_ms;
674 int jitter_buffer_ms;
675 int jitter_buffer_preferred_ms;
676 int delay_estimate_ms;
677 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000678 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000680 // fraction of synthesized speech inserted through expansion.
681 float speech_expand_rate;
682 // fraction of data out of secondary decoding, including FEC and RED.
683 float secondary_decoded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200684 // Fraction of data removed through time compression.
685 float accelerate_rate;
686 // Fraction of data inserted through time stretching.
687 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000688 int decoding_calls_to_silence_generator;
689 int decoding_calls_to_neteq;
690 int decoding_normal;
691 int decoding_plc;
692 int decoding_cng;
693 int decoding_plc_cng;
henrik.lundin63489782016-09-20 01:47:12 -0700694 int decoding_muted_output;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000695 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200696 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697};
698
wu@webrtc.org97077a32013-10-25 21:18:33 +0000699struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000701 : packets_cached(0),
702 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000703 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000705 send_frame_width(0),
706 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 framerate_input(0),
708 framerate_sent(0),
709 nominal_bitrate(0),
710 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000711 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000712 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000713 avg_encode_ms(0),
sakal43536c32016-10-24 01:46:43 -0700714 encode_usage_percent(0),
715 frames_encoded(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000717 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800718 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100719 std::string encoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000720 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000722 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000724 int send_frame_width;
725 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 int framerate_input;
727 int framerate_sent;
728 int nominal_bitrate;
729 int preferred_bitrate;
730 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000731 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000732 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000733 int encode_usage_percent;
sakal43536c32016-10-24 01:46:43 -0700734 uint32_t frames_encoded;
sakal87da4042016-10-31 06:53:47 -0700735 rtc::Optional<uint64_t> qp_sum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736};
737
wu@webrtc.org97077a32013-10-25 21:18:33 +0000738struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000740 : packets_concealed(0),
741 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000742 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 nacks_sent(0),
744 frame_width(0),
745 frame_height(0),
746 framerate_rcvd(0),
747 framerate_decoded(0),
748 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000749 framerate_render_input(0),
750 framerate_render_output(0),
hbos42f6d2f2017-01-20 03:56:50 -0800751 frames_received(0),
sakale5ba44e2016-10-26 07:09:24 -0700752 frames_decoded(0),
hbos50cfe1f2017-01-23 07:21:55 -0800753 frames_rendered(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000754 decode_ms(0),
755 max_decode_ms(0),
756 jitter_buffer_ms(0),
757 min_playout_delay_ms(0),
758 render_delay_ms(0),
759 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000760 current_delay_ms(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000761 capture_start_ntp_time_ms(-1) {
762 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000764 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800765 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100766 std::string decoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000767 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000769 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 int nacks_sent;
771 int frame_width;
772 int frame_height;
773 int framerate_rcvd;
774 int framerate_decoded;
775 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000776 // Framerate as sent to the renderer.
777 int framerate_render_input;
778 // Framerate that the renderer reports.
779 int framerate_render_output;
hbos42f6d2f2017-01-20 03:56:50 -0800780 uint32_t frames_received;
sakale5ba44e2016-10-26 07:09:24 -0700781 uint32_t frames_decoded;
hbos50cfe1f2017-01-23 07:21:55 -0800782 uint32_t frames_rendered;
sakalcc452e12017-02-09 04:53:45 -0800783 rtc::Optional<uint64_t> qp_sum;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000784
785 // All stats below are gathered per-VideoReceiver, but some will be correlated
786 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
787 // structures, reflect this in the new layout.
788
789 // Current frame decode latency.
790 int decode_ms;
791 // Maximum observed frame decode latency.
792 int max_decode_ms;
793 // Jitter (network-related) latency.
794 int jitter_buffer_ms;
795 // Requested minimum playout latency.
796 int min_playout_delay_ms;
797 // Requested latency to account for rendering delay.
798 int render_delay_ms;
799 // Target overall delay: network+decode+render, accounting for
800 // min_playout_delay_ms.
801 int target_delay_ms;
802 // Current overall delay, possibly ramping towards target_delay_ms.
803 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000804
805 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200806 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807};
808
wu@webrtc.org97077a32013-10-25 21:18:33 +0000809struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000811 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 }
813
Peter Boström0c4e06b2015-10-07 12:23:21 +0200814 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815};
816
wu@webrtc.org97077a32013-10-25 21:18:33 +0000817struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000819 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 }
821
Peter Boström0c4e06b2015-10-07 12:23:21 +0200822 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823};
824
825struct BandwidthEstimationInfo {
826 BandwidthEstimationInfo()
827 : available_send_bandwidth(0),
828 available_recv_bandwidth(0),
829 target_enc_bitrate(0),
830 actual_enc_bitrate(0),
831 retransmit_bitrate(0),
832 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000833 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 }
835
836 int available_send_bandwidth;
837 int available_recv_bandwidth;
838 int target_enc_bitrate;
839 int actual_enc_bitrate;
840 int retransmit_bitrate;
841 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000842 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843};
844
hbosa65704b2016-11-14 02:28:16 -0800845// Maps from payload type to |RtpCodecParameters|.
846typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
847
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848struct VoiceMediaInfo {
849 void Clear() {
850 senders.clear();
851 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800852 send_codecs.clear();
853 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 }
855 std::vector<VoiceSenderInfo> senders;
856 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800857 RtpCodecParametersMap send_codecs;
858 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859};
860
861struct VideoMediaInfo {
862 void Clear() {
863 senders.clear();
864 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700865 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800866 send_codecs.clear();
867 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 }
869 std::vector<VideoSenderInfo> senders;
870 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700871 // Deprecated.
872 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700873 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800874 RtpCodecParametersMap send_codecs;
875 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876};
877
878struct DataMediaInfo {
879 void Clear() {
880 senders.clear();
881 receivers.clear();
882 }
883 std::vector<DataSenderInfo> senders;
884 std::vector<DataReceiverInfo> receivers;
885};
886
deadbeef13871492015-12-09 12:37:51 -0800887struct RtcpParameters {
888 bool reduced_size = false;
889};
890
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700891template <class Codec>
892struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800893 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700894 std::ostringstream ost;
895 ost << "{";
896 ost << "codecs: " << VectorToString(codecs) << ", ";
897 ost << "extensions: " << VectorToString(extensions);
898 ost << "}";
899 return ost.str();
900 }
901
902 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700903 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700904 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800905 RtcpParameters rtcp;
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200906 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700907};
908
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700909// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
910// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700911template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700912struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800913 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700914 std::ostringstream ost;
915 ost << "{";
916 ost << "codecs: " << VectorToString(this->codecs) << ", ";
917 ost << "extensions: " << VectorToString(this->extensions) << ", ";
pbos378dc772016-01-28 15:58:41 -0800918 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
nisse05103312016-03-16 02:22:50 -0700919 ost << "}";
920 return ost.str();
921 }
922
923 int max_bandwidth_bps = -1;
924};
925
926struct AudioSendParameters : RtpSendParameters<AudioCodec> {
927 std::string ToString() const override {
928 std::ostringstream ost;
929 ost << "{";
930 ost << "codecs: " << VectorToString(this->codecs) << ", ";
931 ost << "extensions: " << VectorToString(this->extensions) << ", ";
932 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700933 ost << "options: " << options.ToString();
934 ost << "}";
935 return ost.str();
936 }
937
nisse05103312016-03-16 02:22:50 -0700938 AudioOptions options;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700939};
940
941struct AudioRecvParameters : RtpParameters<AudioCodec> {
942};
943
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944class VoiceMediaChannel : public MediaChannel {
945 public:
946 enum Error {
947 ERROR_NONE = 0, // No error.
948 ERROR_OTHER, // Other errors.
949 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
950 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
951 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
952 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
953 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
954 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
955 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
956 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
957 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
958 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
959 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
960 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
961 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
962 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
963 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
964 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
965 };
966
967 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700968 explicit VoiceMediaChannel(const MediaConfig& config)
969 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200971 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
972 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700973 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
974 virtual bool SetRtpSendParameters(
975 uint32_t ssrc,
976 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700977 // Get the receive parameters for the incoming stream identified by |ssrc|.
978 // If |ssrc| is 0, retrieve the receive parameters for the default receive
979 // stream, which is used when SSRCs are not signaled. Note that calling with
980 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
981 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700982 virtual webrtc::RtpParameters GetRtpReceiveParameters(
983 uint32_t ssrc) const = 0;
984 virtual bool SetRtpReceiveParameters(
985 uint32_t ssrc,
986 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700988 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800990 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700991 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200992 virtual bool SetAudioSend(uint32_t ssrc,
993 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700994 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800995 AudioSource* source) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 // Gets current energy levels for all incoming streams.
997 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
998 // Get the current energy level of the stream sent to the speaker.
999 virtual int GetOutputLevel() = 0;
solenberg4bac9c52015-10-09 02:32:53 -07001000 // Set speaker output volume of the specified ssrc.
1001 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -08001003 virtual bool CanInsertDtmf() = 0;
1004 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001006 // The valid value for the |event| are 0 to 15 which corresponding to
1007 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -08001008 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 // Gets quality stats for the channel.
1010 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +01001011
1012 virtual void SetRawAudioSink(
1013 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -08001014 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015};
1016
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001017// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
1018// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -07001019struct VideoSendParameters : RtpSendParameters<VideoCodec> {
nisse4b4dc862016-02-17 05:25:36 -08001020 // Use conference mode? This flag comes from the remote
1021 // description's SDP line 'a=x-google-flag:conference', copied over
1022 // by VideoChannel::SetRemoteContent_w, and ultimately used by
1023 // conference mode screencast logic in
1024 // WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig.
1025 // The special screencast behaviour is disabled by default.
1026 bool conference_mode = false;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001027};
1028
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001029// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
1030// encapsulate all the parameters needed for a video RtpReceiver.
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001031struct VideoRecvParameters : RtpParameters<VideoCodec> {
1032};
1033
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034class VideoMediaChannel : public MediaChannel {
1035 public:
1036 enum Error {
1037 ERROR_NONE = 0, // No error.
1038 ERROR_OTHER, // Other errors.
1039 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1040 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1041 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1042 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1043 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1044 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1045 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1046 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1047 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1048 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1049 };
1050
nisse08582ff2016-02-04 01:24:52 -08001051 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -07001052 explicit VideoMediaChannel(const MediaConfig& config)
1053 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001054 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001055
1056 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
1057 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001058 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
1059 virtual bool SetRtpSendParameters(
1060 uint32_t ssrc,
1061 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -07001062 // Get the receive parameters for the incoming stream identified by |ssrc|.
1063 // If |ssrc| is 0, retrieve the receive parameters for the default receive
1064 // stream, which is used when SSRCs are not signaled. Note that calling with
1065 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
1066 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001067 virtual webrtc::RtpParameters GetRtpReceiveParameters(
1068 uint32_t ssrc) const = 0;
1069 virtual bool SetRtpReceiveParameters(
1070 uint32_t ssrc,
1071 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 // Gets the currently set codecs/payload types to be used for outgoing media.
1073 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 // Starts or stops transmission (and potentially capture) of local video.
1075 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -07001076 // Configure stream for sending and register a source.
1077 // The |ssrc| must correspond to a registered send stream.
1078 virtual bool SetVideoSend(
1079 uint32_t ssrc,
1080 bool enable,
1081 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -08001082 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -08001083 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -07001084 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -08001085 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -08001086 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -07001087 // This fills the "bitrate parts" (rtx, video bitrate) of the
1088 // BandwidthEstimationInfo, since that part that isn't possible to get
1089 // through webrtc::Call::GetStats, as they are statistics of the send
1090 // streams.
1091 // TODO(holmer): We should change this so that either BWE graphs doesn't
1092 // need access to bitrates of the streams, or change the (RTC)StatsCollector
1093 // so that it's getting the send stream stats separately by calling
1094 // GetStats(), and merges with BandwidthEstimationInfo by itself.
1095 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001097 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098};
1099
1100enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001101 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1102 // values.
1103 DMT_NONE = 0,
1104 DMT_CONTROL = 1,
1105 DMT_BINARY = 2,
1106 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001107};
1108
1109// Info about data received in DataMediaChannel. For use in
1110// DataMediaChannel::SignalDataReceived and in all of the signals that
1111// signal fires, on up the chain.
1112struct ReceiveDataParams {
1113 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001114 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1115 union {
1116 uint32_t ssrc;
1117 int sid;
1118 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119 // The type of message (binary, text, or control).
1120 DataMessageType type;
1121 // A per-stream value incremented per packet in the stream.
1122 int seq_num;
1123 // A per-stream value monotonically increasing with time.
1124 int timestamp;
1125
deadbeef953c2ce2017-01-09 14:53:41 -08001126 ReceiveDataParams() : sid(0), type(DMT_TEXT), seq_num(0), timestamp(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127};
1128
1129struct SendDataParams {
1130 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001131 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1132 union {
1133 uint32_t ssrc;
1134 int sid;
1135 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 // The type of message (binary, text, or control).
1137 DataMessageType type;
1138
1139 // For SCTP, whether to send messages flagged as ordered or not.
1140 // If false, messages can be received out of order.
1141 bool ordered;
1142 // For SCTP, whether the messages are sent reliably or not.
1143 // If false, messages may be lost.
1144 bool reliable;
1145 // For SCTP, if reliable == false, provide partial reliability by
1146 // resending up to this many times. Either count or millis
1147 // is supported, not both at the same time.
1148 int max_rtx_count;
1149 // For SCTP, if reliable == false, provide partial reliability by
1150 // resending for up to this many milliseconds. Either count or millis
1151 // is supported, not both at the same time.
1152 int max_rtx_ms;
1153
deadbeef953c2ce2017-01-09 14:53:41 -08001154 SendDataParams()
1155 : sid(0),
1156 type(DMT_TEXT),
1157 // TODO(pthatcher): Make these true by default?
1158 ordered(false),
1159 reliable(false),
1160 max_rtx_count(0),
1161 max_rtx_ms(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001162};
1163
1164enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1165
nisse05103312016-03-16 02:22:50 -07001166struct DataSendParameters : RtpSendParameters<DataCodec> {
solenberg7e4e01a2015-12-02 08:05:01 -08001167 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001168 std::ostringstream ost;
1169 // Options and extensions aren't used.
1170 ost << "{";
1171 ost << "codecs: " << VectorToString(codecs) << ", ";
pbos378dc772016-01-28 15:58:41 -08001172 ost << "max_bandwidth_bps: " << max_bandwidth_bps;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001173 ost << "}";
1174 return ost.str();
1175 }
1176};
1177
1178struct DataRecvParameters : RtpParameters<DataCodec> {
1179};
1180
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001181class DataMediaChannel : public MediaChannel {
1182 public:
1183 enum Error {
1184 ERROR_NONE = 0, // No error.
1185 ERROR_OTHER, // Other errors.
1186 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1187 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1188 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1189 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1190 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1191 };
1192
zhihuangebbe4f22016-12-06 10:45:42 -08001193 DataMediaChannel() {}
1194 DataMediaChannel(const MediaConfig& config) : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001195 virtual ~DataMediaChannel() {}
1196
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001197 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1198 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001199
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200 // TODO(pthatcher): Implement this.
1201 virtual bool GetStats(DataMediaInfo* info) { return true; }
1202
1203 virtual bool SetSend(bool send) = 0;
1204 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001205
Honghai Zhangcc411c02016-03-29 17:27:21 -07001206 virtual void OnNetworkRouteChanged(const std::string& transport_name,
Honghai Zhang0e533ef2016-04-19 15:41:36 -07001207 const rtc::NetworkRoute& network_route) {}
Honghai Zhangcc411c02016-03-29 17:27:21 -07001208
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001209 virtual bool SendData(
1210 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -07001211 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212 SendDataResult* result = NULL) = 0;
1213 // Signals when data is received (params, data, len)
1214 sigslot::signal3<const ReceiveDataParams&,
1215 const char*,
1216 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001217 // Signal when the media channel is ready to send the stream. Arguments are:
1218 // writable(bool)
1219 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220};
1221
1222} // namespace cricket
1223
kjellandera96e2d72016-02-04 23:52:28 -08001224#endif // WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_