blob: 1bea916f305af2c23e4d721683cfe85feae1582f [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"
ilnik2edc6842017-07-06 03:06:50 -070020#include "webrtc/api/video/video_timing.h"
Henrik Kjellandera80c16a2017-07-01 16:48:15 +020021#include "webrtc/base/basictypes.h"
22#include "webrtc/base/buffer.h"
23#include "webrtc/base/copyonwritebuffer.h"
24#include "webrtc/base/dscp.h"
25#include "webrtc/base/logging.h"
26#include "webrtc/base/networkroute.h"
27#include "webrtc/base/optional.h"
28#include "webrtc/base/sigslot.h"
29#include "webrtc/base/socket.h"
30#include "webrtc/base/window.h"
isheriff6f8d6862016-05-26 11:24:55 -070031#include "webrtc/config.h"
kjellandera96e2d72016-02-04 23:52:28 -080032#include "webrtc/media/base/codec.h"
kjellanderf4752772016-03-02 05:42:30 -080033#include "webrtc/media/base/mediaconstants.h"
kjellandera96e2d72016-02-04 23:52:28 -080034#include "webrtc/media/base/streamparams.h"
nisse08582ff2016-02-04 01:24:52 -080035#include "webrtc/media/base/videosinkinterface.h"
nisse2ded9b12016-04-08 02:23:55 -070036#include "webrtc/media/base/videosourceinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037// TODO(juberti): re-evaluate this include
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010038#include "webrtc/pc/audiomonitor.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000040namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041class RateLimiter;
42class Timing;
43}
44
Tommif888bb52015-12-12 01:37:01 +010045namespace webrtc {
46class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080047class VideoFrame;
Tommif888bb52015-12-12 01:37:01 +010048}
49
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050namespace cricket {
51
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080052class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080054struct RtpHeader;
55struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057const int kScreencastDefaultFps = 5;
58
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059template <class T>
Karl Wibergbe579832015-11-10 22:34:18 +010060static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070062 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063 str = key;
64 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070065 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 str += ", ";
67 }
68 return str;
69}
70
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070071template <class T>
72static std::string VectorToString(const std::vector<T>& vals) {
73 std::ostringstream ost;
74 ost << "[";
75 for (size_t i = 0; i < vals.size(); ++i) {
76 if (i > 0) {
77 ost << ", ";
78 }
79 ost << vals[i].ToString();
80 }
81 ost << "]";
82 return ost.str();
83}
84
nisse528b7932017-05-08 03:21:43 -070085// Construction-time settings, passed on when creating
nisse51542be2016-02-12 02:27:06 -080086// MediaChannels.
87struct MediaConfig {
88 // Set DSCP value on packets. This flag comes from the
89 // PeerConnection constraint 'googDscp'.
90 bool enable_dscp = false;
91
nisse0db023a2016-03-01 04:29:59 -080092 // Video-specific config.
93 struct Video {
94 // Enable WebRTC CPU Overuse Detection. This flag comes from the
perkj803d97f2016-11-01 11:45:46 -070095 // PeerConnection constraint 'googCpuOveruseDetection'.
nisse0db023a2016-03-01 04:29:59 -080096 bool enable_cpu_overuse_detection = true;
nisse51542be2016-02-12 02:27:06 -080097
nisse0db023a2016-03-01 04:29:59 -080098 // Enable WebRTC suspension of video. No video frames will be sent
99 // when the bitrate is below the configured minimum bitrate. This
100 // flag comes from the PeerConnection constraint
eladalonf1841382017-06-12 01:16:46 -0700101 // 'googSuspendBelowMinBitrate', and WebRtcVideoChannel copies it
nisse0db023a2016-03-01 04:29:59 -0800102 // to VideoSendStream::Config::suspend_below_min_bitrate.
103 bool suspend_below_min_bitrate = false;
nisse51542be2016-02-12 02:27:06 -0800104
nisse0db023a2016-03-01 04:29:59 -0800105 // Set to true if the renderer has an algorithm of frame selection.
106 // If the value is true, then WebRTC will hand over a frame as soon as
107 // possible without delay, and rendering smoothness is completely the duty
108 // of the renderer;
109 // If the value is false, then WebRTC is responsible to delay frame release
110 // in order to increase rendering smoothness.
111 //
112 // This flag comes from PeerConnection's RtcConfiguration, but is
113 // currently only set by the command line flag
114 // 'disable-rtc-smoothness-algorithm'.
eladalonf1841382017-06-12 01:16:46 -0700115 // WebRtcVideoChannel::AddRecvStream copies it to the created
nisse0db023a2016-03-01 04:29:59 -0800116 // WebRtcVideoReceiveStream, where it is returned by the
117 // SmoothsRenderedFrames method. This method is used by the
118 // VideoReceiveStream, where the value is passed on to the
119 // IncomingVideoStream constructor.
120 bool disable_prerenderer_smoothing = false;
sergeyu80ed35e2016-11-28 13:11:13 -0800121
122 // Enables periodic bandwidth probing in application-limited region.
123 bool periodic_alr_bandwidth_probing = false;
nisse0db023a2016-03-01 04:29:59 -0800124 } video;
deadbeef293e9262017-01-11 12:28:30 -0800125
126 bool operator==(const MediaConfig& o) const {
127 return enable_dscp == o.enable_dscp &&
128 video.enable_cpu_overuse_detection ==
129 o.video.enable_cpu_overuse_detection &&
130 video.suspend_below_min_bitrate ==
131 o.video.suspend_below_min_bitrate &&
132 video.disable_prerenderer_smoothing ==
133 o.video.disable_prerenderer_smoothing &&
134 video.periodic_alr_bandwidth_probing ==
135 o.video.periodic_alr_bandwidth_probing;
136 }
137
138 bool operator!=(const MediaConfig& o) const { return !(*this == o); }
nisse51542be2016-02-12 02:27:06 -0800139};
140
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
142// Used to be flags, but that makes it hard to selectively apply options.
143// We are moving all of the setting of options to structs like this,
144// but some things currently still use flags.
145struct AudioOptions {
146 void SetAll(const AudioOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700147 SetFrom(&echo_cancellation, change.echo_cancellation);
148 SetFrom(&auto_gain_control, change.auto_gain_control);
149 SetFrom(&noise_suppression, change.noise_suppression);
150 SetFrom(&highpass_filter, change.highpass_filter);
151 SetFrom(&stereo_swapping, change.stereo_swapping);
152 SetFrom(&audio_jitter_buffer_max_packets,
153 change.audio_jitter_buffer_max_packets);
154 SetFrom(&audio_jitter_buffer_fast_accelerate,
155 change.audio_jitter_buffer_fast_accelerate);
156 SetFrom(&typing_detection, change.typing_detection);
157 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise);
kwiberg102c6a62015-10-30 02:47:38 -0700158 SetFrom(&adjust_agc_delta, change.adjust_agc_delta);
159 SetFrom(&experimental_agc, change.experimental_agc);
160 SetFrom(&extended_filter_aec, change.extended_filter_aec);
161 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec);
162 SetFrom(&experimental_ns, change.experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700163 SetFrom(&intelligibility_enhancer, change.intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700164 SetFrom(&level_control, change.level_control);
ivocb829d9f2016-11-15 02:34:47 -0800165 SetFrom(&residual_echo_detector, change.residual_echo_detector);
kwiberg102c6a62015-10-30 02:47:38 -0700166 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov);
167 SetFrom(&tx_agc_digital_compression_gain,
168 change.tx_agc_digital_compression_gain);
169 SetFrom(&tx_agc_limiter, change.tx_agc_limiter);
170 SetFrom(&recording_sample_rate, change.recording_sample_rate);
171 SetFrom(&playout_sample_rate, change.playout_sample_rate);
kwiberg102c6a62015-10-30 02:47:38 -0700172 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700173 SetFrom(&audio_network_adaptor, change.audio_network_adaptor);
174 SetFrom(&audio_network_adaptor_config, change.audio_network_adaptor_config);
aleloie33c5d92016-10-20 01:53:27 -0700175 SetFrom(&level_control_initial_peak_level_dbfs,
176 change.level_control_initial_peak_level_dbfs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 }
178
179 bool operator==(const AudioOptions& o) const {
180 return echo_cancellation == o.echo_cancellation &&
peaha3333bf2016-06-30 00:02:34 -0700181 auto_gain_control == o.auto_gain_control &&
182 noise_suppression == o.noise_suppression &&
183 highpass_filter == o.highpass_filter &&
184 stereo_swapping == o.stereo_swapping &&
185 audio_jitter_buffer_max_packets ==
186 o.audio_jitter_buffer_max_packets &&
187 audio_jitter_buffer_fast_accelerate ==
188 o.audio_jitter_buffer_fast_accelerate &&
189 typing_detection == o.typing_detection &&
190 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
191 experimental_agc == o.experimental_agc &&
192 extended_filter_aec == o.extended_filter_aec &&
193 delay_agnostic_aec == o.delay_agnostic_aec &&
194 experimental_ns == o.experimental_ns &&
195 intelligibility_enhancer == o.intelligibility_enhancer &&
196 level_control == o.level_control &&
ivocb829d9f2016-11-15 02:34:47 -0800197 residual_echo_detector == o.residual_echo_detector &&
peaha3333bf2016-06-30 00:02:34 -0700198 adjust_agc_delta == o.adjust_agc_delta &&
199 tx_agc_target_dbov == o.tx_agc_target_dbov &&
200 tx_agc_digital_compression_gain ==
201 o.tx_agc_digital_compression_gain &&
202 tx_agc_limiter == o.tx_agc_limiter &&
203 recording_sample_rate == o.recording_sample_rate &&
204 playout_sample_rate == o.playout_sample_rate &&
aleloie33c5d92016-10-20 01:53:27 -0700205 combined_audio_video_bwe == o.combined_audio_video_bwe &&
minyue6b825df2016-10-31 04:08:32 -0700206 audio_network_adaptor == o.audio_network_adaptor &&
207 audio_network_adaptor_config == o.audio_network_adaptor_config &&
aleloie33c5d92016-10-20 01:53:27 -0700208 level_control_initial_peak_level_dbfs ==
209 o.level_control_initial_peak_level_dbfs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 }
deadbeef119760a2016-04-04 11:43:27 -0700211 bool operator!=(const AudioOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212
213 std::string ToString() const {
214 std::ostringstream ost;
215 ost << "AudioOptions {";
216 ost << ToStringIfSet("aec", echo_cancellation);
217 ost << ToStringIfSet("agc", auto_gain_control);
218 ost << ToStringIfSet("ns", noise_suppression);
219 ost << ToStringIfSet("hf", highpass_filter);
220 ost << ToStringIfSet("swap", stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200221 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
222 audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200223 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
224 audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000226 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
228 ost << ToStringIfSet("experimental_agc", experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200229 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100230 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000231 ost << ToStringIfSet("experimental_ns", experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700232 ost << ToStringIfSet("intelligibility_enhancer", intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700233 ost << ToStringIfSet("level_control", level_control);
aleloie33c5d92016-10-20 01:53:27 -0700234 ost << ToStringIfSet("level_control_initial_peak_level_dbfs",
235 level_control_initial_peak_level_dbfs);
ivocb829d9f2016-11-15 02:34:47 -0800236 ost << ToStringIfSet("residual_echo_detector", residual_echo_detector);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000237 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
238 ost << ToStringIfSet("tx_agc_digital_compression_gain",
239 tx_agc_digital_compression_gain);
240 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000241 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
242 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000243 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700244 ost << ToStringIfSet("audio_network_adaptor", audio_network_adaptor);
245 // The adaptor config is a serialized proto buffer and therefore not human
246 // readable. So we comment out the following line.
247 // ost << ToStringIfSet("audio_network_adaptor_config",
248 // audio_network_adaptor_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 ost << "}";
250 return ost.str();
251 }
252
253 // Audio processing that attempts to filter away the output signal from
254 // later inbound pickup.
Karl Wibergbe579832015-11-10 22:34:18 +0100255 rtc::Optional<bool> echo_cancellation;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 // Audio processing to adjust the sensitivity of the local mic dynamically.
Karl Wibergbe579832015-11-10 22:34:18 +0100257 rtc::Optional<bool> auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 // Audio processing to filter out background noise.
Karl Wibergbe579832015-11-10 22:34:18 +0100259 rtc::Optional<bool> noise_suppression;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 // Audio processing to remove background noise of lower frequencies.
Karl Wibergbe579832015-11-10 22:34:18 +0100261 rtc::Optional<bool> highpass_filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 // Audio processing to swap the left and right channels.
Karl Wibergbe579832015-11-10 22:34:18 +0100263 rtc::Optional<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200264 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Karl Wibergbe579832015-11-10 22:34:18 +0100265 rtc::Optional<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200266 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Karl Wibergbe579832015-11-10 22:34:18 +0100267 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 // Audio processing to detect typing.
Karl Wibergbe579832015-11-10 22:34:18 +0100269 rtc::Optional<bool> typing_detection;
270 rtc::Optional<bool> aecm_generate_comfort_noise;
Karl Wibergbe579832015-11-10 22:34:18 +0100271 rtc::Optional<int> adjust_agc_delta;
272 rtc::Optional<bool> experimental_agc;
273 rtc::Optional<bool> extended_filter_aec;
274 rtc::Optional<bool> delay_agnostic_aec;
275 rtc::Optional<bool> experimental_ns;
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700276 rtc::Optional<bool> intelligibility_enhancer;
peaha3333bf2016-06-30 00:02:34 -0700277 rtc::Optional<bool> level_control;
aleloie33c5d92016-10-20 01:53:27 -0700278 // Specifies an optional initialization value for the level controller.
279 rtc::Optional<float> level_control_initial_peak_level_dbfs;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000280 // Note that tx_agc_* only applies to non-experimental AGC.
ivocb829d9f2016-11-15 02:34:47 -0800281 rtc::Optional<bool> residual_echo_detector;
Karl Wibergbe579832015-11-10 22:34:18 +0100282 rtc::Optional<uint16_t> tx_agc_target_dbov;
283 rtc::Optional<uint16_t> tx_agc_digital_compression_gain;
284 rtc::Optional<bool> tx_agc_limiter;
285 rtc::Optional<uint32_t> recording_sample_rate;
286 rtc::Optional<uint32_t> playout_sample_rate;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000287 // Enable combined audio+bandwidth BWE.
nisse51542be2016-02-12 02:27:06 -0800288 // TODO(pthatcher): This flag is set from the
289 // "googCombinedAudioVideoBwe", but not used anywhere. So delete it,
290 // and check if any other AudioOptions members are unused.
Karl Wibergbe579832015-11-10 22:34:18 +0100291 rtc::Optional<bool> combined_audio_video_bwe;
minyue6b825df2016-10-31 04:08:32 -0700292 // Enable audio network adaptor.
293 rtc::Optional<bool> audio_network_adaptor;
294 // Config string for audio network adaptor.
295 rtc::Optional<std::string> audio_network_adaptor_config;
kwiberg102c6a62015-10-30 02:47:38 -0700296
297 private:
298 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100299 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700300 if (o) {
301 *s = o;
302 }
303 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304};
305
306// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
307// Used to be flags, but that makes it hard to selectively apply options.
308// We are moving all of the setting of options to structs like this,
309// but some things currently still use flags.
310struct VideoOptions {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700312 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800313 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100314 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315 }
316
317 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800318 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100319 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
320 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 }
deadbeef119760a2016-04-04 11:43:27 -0700322 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323
324 std::string ToString() const {
325 std::ostringstream ost;
326 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800328 ost << ToStringIfSet("screencast min bitrate kbps",
329 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100330 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 ost << "}";
332 return ost.str();
333 }
334
nisseb163c3f2016-01-29 01:14:38 -0800335 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700336 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800337 // on to the codec options. Disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100338 rtc::Optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800339 // Force screencast to use a minimum bitrate. This flag comes from
340 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700341 // copied to the encoder config by WebRtcVideoChannel.
nisseb163c3f2016-01-29 01:14:38 -0800342 rtc::Optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100343 // Set by screencast sources. Implies selection of encoding settings
344 // suitable for screencast. Most likely not the right way to do
345 // things, e.g., screencast of a text document and screencast of a
346 // youtube video have different needs.
347 rtc::Optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700348
349 private:
350 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100351 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700352 if (o) {
353 *s = o;
354 }
355 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356};
357
isheriffa1c548b2016-05-31 16:12:24 -0700358// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
359struct RtpHeaderExtension {
360 RtpHeaderExtension() : id(0) {}
361 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
362
363 std::string ToString() const {
364 std::ostringstream ost;
365 ost << "{";
366 ost << "uri: " << uri;
367 ost << ", id: " << id;
368 ost << "}";
369 return ost.str();
370 }
371
372 std::string uri;
373 int id;
374};
375
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376class MediaChannel : public sigslot::has_slots<> {
377 public:
378 class NetworkInterface {
379 public:
380 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700381 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700382 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700383 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700384 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000385 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 int option) = 0;
387 virtual ~NetworkInterface() {}
388 };
389
terelius54f91712016-06-01 11:18:56 -0700390 explicit MediaChannel(const MediaConfig& config)
nisse51542be2016-02-12 02:27:06 -0800391 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
392 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 virtual ~MediaChannel() {}
394
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000395 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000397 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398 network_interface_ = iface;
nisse51542be2016-02-12 02:27:06 -0800399 SetDscp(enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400 }
nisse51542be2016-02-12 02:27:06 -0800401 virtual rtc::DiffServCodePoint PreferredDscp() const {
402 return rtc::DSCP_DEFAULT;
403 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700405 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000406 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700408 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000409 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 // Called when the socket's ability to send has changed.
411 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700412 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700413 virtual void OnNetworkRouteChanged(
414 const std::string& transport_name,
415 const rtc::NetworkRoute& network_route) = 0;
michaelt79e05882016-11-08 02:50:09 -0800416 // Called when the rtp transport overhead changed.
417 virtual void OnTransportOverheadChanged(
418 int transport_overhead_per_packet) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419 // Creates a new outgoing media stream with SSRCs and CNAME as described
420 // by sp.
421 virtual bool AddSendStream(const StreamParams& sp) = 0;
422 // Removes an outgoing media stream.
423 // ssrc must be the first SSRC of the media stream if the stream uses
424 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200425 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 // Creates a new incoming media stream with SSRCs and CNAME as described
427 // by sp.
428 virtual bool AddRecvStream(const StreamParams& sp) = 0;
429 // Removes an incoming media stream.
430 // ssrc must be the first SSRC of the media stream if the stream uses
431 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200432 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000434 // Returns the absoulte sendtime extension id value from media channel.
435 virtual int GetRtpSendTimeExtnId() const {
436 return -1;
437 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000439 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700440 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
441 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700442 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000443 }
444
jbaucheec21bd2016-03-20 06:15:43 -0700445 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
446 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700447 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000448 }
449
450 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000451 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000452 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000453 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000454 if (!network_interface_)
455 return -1;
456
457 return network_interface_->SetOption(type, opt, option);
458 }
459
nisse51542be2016-02-12 02:27:06 -0800460 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000461 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000462 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000463 int ret;
464 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000465 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000466 value);
467 if (ret == 0) {
468 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000469 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000470 value);
471 }
472 return ret;
473 }
474
jbaucheec21bd2016-03-20 06:15:43 -0700475 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700476 bool rtcp,
477 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000478 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000479 if (!network_interface_)
480 return false;
481
stefanc1aeaf02015-10-15 07:26:07 -0700482 return (!rtcp) ? network_interface_->SendPacket(packet, options)
483 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000484 }
485
nisse51542be2016-02-12 02:27:06 -0800486 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000487 // |network_interface_| can be accessed from the worker_thread and
488 // from any MediaEngine threads. This critical section is to protect accessing
489 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000490 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000491 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492};
493
wu@webrtc.org97077a32013-10-25 21:18:33 +0000494// The stats information is structured as follows:
495// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
496// Media contains a vector of SSRC infos that are exclusively used by this
497// media. (SSRCs shared between media streams can't be represented.)
498
499// Information about an SSRC.
500// This data may be locally recorded, or received in an RTCP SR or RR.
501struct SsrcSenderInfo {
502 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000503 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000504 timestamp(0) {
505 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200506 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000507 double timestamp; // NTP timestamp, represented as seconds since epoch.
508};
509
510struct SsrcReceiverInfo {
511 SsrcReceiverInfo()
512 : ssrc(0),
513 timestamp(0) {
514 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200515 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000516 double timestamp;
517};
518
519struct MediaSenderInfo {
520 MediaSenderInfo()
521 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 packets_sent(0),
523 packets_lost(0),
524 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000525 rtt_ms(0) {
526 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000527 void add_ssrc(const SsrcSenderInfo& stat) {
528 local_stats.push_back(stat);
529 }
530 // Temporary utility function for call sites that only provide SSRC.
531 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200532 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000533 SsrcSenderInfo stat;
534 stat.ssrc = ssrc;
535 add_ssrc(stat);
536 }
537 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200538 std::vector<uint32_t> ssrcs() const {
539 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000540 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
541 it != local_stats.end(); ++it) {
542 retval.push_back(it->ssrc);
543 }
544 return retval;
545 }
546 // Utility accessor for clients that make the assumption only one ssrc
547 // exists per media.
548 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200549 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000550 if (local_stats.size() > 0) {
551 return local_stats[0].ssrc;
552 } else {
553 return 0;
554 }
555 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200556 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000557 int packets_sent;
558 int packets_lost;
559 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000560 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000561 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800562 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000563 std::vector<SsrcSenderInfo> local_stats;
564 std::vector<SsrcReceiverInfo> remote_stats;
565};
566
567struct MediaReceiverInfo {
568 MediaReceiverInfo()
569 : bytes_rcvd(0),
570 packets_rcvd(0),
571 packets_lost(0),
572 fraction_lost(0.0) {
573 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000574 void add_ssrc(const SsrcReceiverInfo& stat) {
575 local_stats.push_back(stat);
576 }
577 // Temporary utility function for call sites that only provide SSRC.
578 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200579 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000580 SsrcReceiverInfo stat;
581 stat.ssrc = ssrc;
582 add_ssrc(stat);
583 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200584 std::vector<uint32_t> ssrcs() const {
585 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000586 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
587 it != local_stats.end(); ++it) {
588 retval.push_back(it->ssrc);
589 }
590 return retval;
591 }
592 // Utility accessor for clients that make the assumption only one ssrc
593 // exists per media.
594 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200595 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000596 if (local_stats.size() > 0) {
597 return local_stats[0].ssrc;
598 } else {
599 return 0;
600 }
601 }
602
Peter Boström0c4e06b2015-10-07 12:23:21 +0200603 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000604 int packets_rcvd;
605 int packets_lost;
606 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000607 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800608 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000609 std::vector<SsrcReceiverInfo> local_stats;
610 std::vector<SsrcSenderInfo> remote_stats;
611};
612
613struct VoiceSenderInfo : public MediaSenderInfo {
614 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000615 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 jitter_ms(0),
617 audio_level(0),
618 aec_quality_min(0.0),
619 echo_delay_median_ms(0),
620 echo_delay_std_ms(0),
621 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000622 echo_return_loss_enhancement(0),
ivoc8c63a822016-10-21 04:10:03 -0700623 residual_echo_likelihood(0.0f),
ivoc4e477a12017-01-15 08:29:46 -0800624 residual_echo_likelihood_recent_max(0.0f),
625 typing_noise_detected(false) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628 int jitter_ms;
629 int audio_level;
630 float aec_quality_min;
631 int echo_delay_median_ms;
632 int echo_delay_std_ms;
633 int echo_return_loss;
634 int echo_return_loss_enhancement;
ivoc8c63a822016-10-21 04:10:03 -0700635 float residual_echo_likelihood;
ivoc4e477a12017-01-15 08:29:46 -0800636 float residual_echo_likelihood_recent_max;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000637 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000638};
639
wu@webrtc.org97077a32013-10-25 21:18:33 +0000640struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000642 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643 jitter_ms(0),
644 jitter_buffer_ms(0),
645 jitter_buffer_preferred_ms(0),
646 delay_estimate_ms(0),
647 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000648 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000649 speech_expand_rate(0),
650 secondary_decoded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200651 accelerate_rate(0),
652 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000653 decoding_calls_to_silence_generator(0),
654 decoding_calls_to_neteq(0),
655 decoding_normal(0),
656 decoding_plc(0),
657 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000658 decoding_plc_cng(0),
henrik.lundin63489782016-09-20 01:47:12 -0700659 decoding_muted_output(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200660 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000662 int ext_seqnum;
663 int jitter_ms;
664 int jitter_buffer_ms;
665 int jitter_buffer_preferred_ms;
666 int delay_estimate_ms;
667 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000668 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000670 // fraction of synthesized speech inserted through expansion.
671 float speech_expand_rate;
672 // fraction of data out of secondary decoding, including FEC and RED.
673 float secondary_decoded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200674 // Fraction of data removed through time compression.
675 float accelerate_rate;
676 // Fraction of data inserted through time stretching.
677 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000678 int decoding_calls_to_silence_generator;
679 int decoding_calls_to_neteq;
680 int decoding_normal;
681 int decoding_plc;
682 int decoding_cng;
683 int decoding_plc_cng;
henrik.lundin63489782016-09-20 01:47:12 -0700684 int decoding_muted_output;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000685 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200686 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687};
688
wu@webrtc.org97077a32013-10-25 21:18:33 +0000689struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000691 : packets_cached(0),
692 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000693 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000695 send_frame_width(0),
696 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 framerate_input(0),
698 framerate_sent(0),
699 nominal_bitrate(0),
700 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000701 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000702 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000703 avg_encode_ms(0),
sakal43536c32016-10-24 01:46:43 -0700704 encode_usage_percent(0),
705 frames_encoded(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000707 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800708 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100709 std::string encoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000710 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000712 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000714 int send_frame_width;
715 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 int framerate_input;
717 int framerate_sent;
718 int nominal_bitrate;
719 int preferred_bitrate;
720 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000721 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000722 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000723 int encode_usage_percent;
sakal43536c32016-10-24 01:46:43 -0700724 uint32_t frames_encoded;
sakal87da4042016-10-31 06:53:47 -0700725 rtc::Optional<uint64_t> qp_sum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726};
727
wu@webrtc.org97077a32013-10-25 21:18:33 +0000728struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000730 : packets_concealed(0),
731 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000732 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 nacks_sent(0),
734 frame_width(0),
735 frame_height(0),
736 framerate_rcvd(0),
737 framerate_decoded(0),
738 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000739 framerate_render_input(0),
740 framerate_render_output(0),
hbos42f6d2f2017-01-20 03:56:50 -0800741 frames_received(0),
sakale5ba44e2016-10-26 07:09:24 -0700742 frames_decoded(0),
hbos50cfe1f2017-01-23 07:21:55 -0800743 frames_rendered(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000744 decode_ms(0),
745 max_decode_ms(0),
746 jitter_buffer_ms(0),
747 min_playout_delay_ms(0),
748 render_delay_ms(0),
749 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000750 current_delay_ms(0),
ilnik2edc6842017-07-06 03:06:50 -0700751 capture_start_ntp_time_ms(-1) {}
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;
ilnik2edc6842017-07-06 03:06:50 -0700796
797 // Timing frame info: all important timestamps for a full lifetime of a
798 // single 'timing frame'.
799 rtc::Optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800};
801
wu@webrtc.org97077a32013-10-25 21:18:33 +0000802struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000804 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 }
806
Peter Boström0c4e06b2015-10-07 12:23:21 +0200807 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808};
809
wu@webrtc.org97077a32013-10-25 21:18:33 +0000810struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000812 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 }
814
Peter Boström0c4e06b2015-10-07 12:23:21 +0200815 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816};
817
818struct BandwidthEstimationInfo {
819 BandwidthEstimationInfo()
820 : available_send_bandwidth(0),
821 available_recv_bandwidth(0),
822 target_enc_bitrate(0),
823 actual_enc_bitrate(0),
824 retransmit_bitrate(0),
825 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000826 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 }
828
829 int available_send_bandwidth;
830 int available_recv_bandwidth;
831 int target_enc_bitrate;
832 int actual_enc_bitrate;
833 int retransmit_bitrate;
834 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000835 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836};
837
hbosa65704b2016-11-14 02:28:16 -0800838// Maps from payload type to |RtpCodecParameters|.
839typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
840
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841struct VoiceMediaInfo {
842 void Clear() {
843 senders.clear();
844 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800845 send_codecs.clear();
846 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 }
848 std::vector<VoiceSenderInfo> senders;
849 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800850 RtpCodecParametersMap send_codecs;
851 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852};
853
854struct VideoMediaInfo {
855 void Clear() {
856 senders.clear();
857 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700858 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800859 send_codecs.clear();
860 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 }
862 std::vector<VideoSenderInfo> senders;
863 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700864 // Deprecated.
865 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700866 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800867 RtpCodecParametersMap send_codecs;
868 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869};
870
871struct DataMediaInfo {
872 void Clear() {
873 senders.clear();
874 receivers.clear();
875 }
876 std::vector<DataSenderInfo> senders;
877 std::vector<DataReceiverInfo> receivers;
878};
879
deadbeef13871492015-12-09 12:37:51 -0800880struct RtcpParameters {
881 bool reduced_size = false;
882};
883
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700884template <class Codec>
885struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800886 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700887 std::ostringstream ost;
888 ost << "{";
889 ost << "codecs: " << VectorToString(codecs) << ", ";
890 ost << "extensions: " << VectorToString(extensions);
891 ost << "}";
892 return ost.str();
893 }
894
895 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700896 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700897 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800898 RtcpParameters rtcp;
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200899 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700900};
901
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700902// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
903// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700904template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700905struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800906 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700907 std::ostringstream ost;
908 ost << "{";
909 ost << "codecs: " << VectorToString(this->codecs) << ", ";
910 ost << "extensions: " << VectorToString(this->extensions) << ", ";
pbos378dc772016-01-28 15:58:41 -0800911 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
nisse05103312016-03-16 02:22:50 -0700912 ost << "}";
913 return ost.str();
914 }
915
916 int max_bandwidth_bps = -1;
917};
918
919struct AudioSendParameters : RtpSendParameters<AudioCodec> {
920 std::string ToString() const override {
921 std::ostringstream ost;
922 ost << "{";
923 ost << "codecs: " << VectorToString(this->codecs) << ", ";
924 ost << "extensions: " << VectorToString(this->extensions) << ", ";
925 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700926 ost << "options: " << options.ToString();
927 ost << "}";
928 return ost.str();
929 }
930
nisse05103312016-03-16 02:22:50 -0700931 AudioOptions options;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700932};
933
934struct AudioRecvParameters : RtpParameters<AudioCodec> {
935};
936
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937class VoiceMediaChannel : public MediaChannel {
938 public:
939 enum Error {
940 ERROR_NONE = 0, // No error.
941 ERROR_OTHER, // Other errors.
942 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
943 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
944 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
945 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
946 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
947 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
948 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
949 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
950 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
951 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
952 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
953 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
954 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
955 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
956 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
957 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
958 };
959
960 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700961 explicit VoiceMediaChannel(const MediaConfig& config)
962 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200964 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
965 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700966 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
967 virtual bool SetRtpSendParameters(
968 uint32_t ssrc,
969 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700970 // Get the receive parameters for the incoming stream identified by |ssrc|.
971 // If |ssrc| is 0, retrieve the receive parameters for the default receive
972 // stream, which is used when SSRCs are not signaled. Note that calling with
973 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
974 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700975 virtual webrtc::RtpParameters GetRtpReceiveParameters(
976 uint32_t ssrc) const = 0;
977 virtual bool SetRtpReceiveParameters(
978 uint32_t ssrc,
979 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700981 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800983 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700984 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200985 virtual bool SetAudioSend(uint32_t ssrc,
986 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700987 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800988 AudioSource* source) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 // Gets current energy levels for all incoming streams.
990 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
991 // Get the current energy level of the stream sent to the speaker.
992 virtual int GetOutputLevel() = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700993 // Set speaker output volume of the specified ssrc.
994 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800996 virtual bool CanInsertDtmf() = 0;
997 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000999 // The valid value for the |event| are 0 to 15 which corresponding to
1000 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -08001001 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002 // Gets quality stats for the channel.
1003 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +01001004
1005 virtual void SetRawAudioSink(
1006 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -08001007 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -07001008
1009 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010};
1011
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001012// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
1013// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -07001014struct VideoSendParameters : RtpSendParameters<VideoCodec> {
nisse4b4dc862016-02-17 05:25:36 -08001015 // Use conference mode? This flag comes from the remote
1016 // description's SDP line 'a=x-google-flag:conference', copied over
1017 // by VideoChannel::SetRemoteContent_w, and ultimately used by
1018 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -07001019 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -08001020 // The special screencast behaviour is disabled by default.
1021 bool conference_mode = false;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001022};
1023
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001024// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
1025// encapsulate all the parameters needed for a video RtpReceiver.
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001026struct VideoRecvParameters : RtpParameters<VideoCodec> {
1027};
1028
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029class VideoMediaChannel : public MediaChannel {
1030 public:
1031 enum Error {
1032 ERROR_NONE = 0, // No error.
1033 ERROR_OTHER, // Other errors.
1034 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1035 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1036 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1037 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1038 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1039 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1040 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1041 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1042 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1043 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1044 };
1045
nisse08582ff2016-02-04 01:24:52 -08001046 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -07001047 explicit VideoMediaChannel(const MediaConfig& config)
1048 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001050
1051 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
1052 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001053 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
1054 virtual bool SetRtpSendParameters(
1055 uint32_t ssrc,
1056 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -07001057 // Get the receive parameters for the incoming stream identified by |ssrc|.
1058 // If |ssrc| is 0, retrieve the receive parameters for the default receive
1059 // stream, which is used when SSRCs are not signaled. Note that calling with
1060 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
1061 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001062 virtual webrtc::RtpParameters GetRtpReceiveParameters(
1063 uint32_t ssrc) const = 0;
1064 virtual bool SetRtpReceiveParameters(
1065 uint32_t ssrc,
1066 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 // Gets the currently set codecs/payload types to be used for outgoing media.
1068 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 // Starts or stops transmission (and potentially capture) of local video.
1070 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -07001071 // Configure stream for sending and register a source.
1072 // The |ssrc| must correspond to a registered send stream.
1073 virtual bool SetVideoSend(
1074 uint32_t ssrc,
1075 bool enable,
1076 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -08001077 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -08001078 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -07001079 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -08001080 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -08001081 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -07001082 // This fills the "bitrate parts" (rtx, video bitrate) of the
1083 // BandwidthEstimationInfo, since that part that isn't possible to get
1084 // through webrtc::Call::GetStats, as they are statistics of the send
1085 // streams.
1086 // TODO(holmer): We should change this so that either BWE graphs doesn't
1087 // need access to bitrates of the streams, or change the (RTC)StatsCollector
1088 // so that it's getting the send stream stats separately by calling
1089 // GetStats(), and merges with BandwidthEstimationInfo by itself.
1090 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001091 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001092 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093};
1094
1095enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001096 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1097 // values.
1098 DMT_NONE = 0,
1099 DMT_CONTROL = 1,
1100 DMT_BINARY = 2,
1101 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102};
1103
1104// Info about data received in DataMediaChannel. For use in
1105// DataMediaChannel::SignalDataReceived and in all of the signals that
1106// signal fires, on up the chain.
1107struct ReceiveDataParams {
1108 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001109 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1110 union {
1111 uint32_t ssrc;
1112 int sid;
1113 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114 // The type of message (binary, text, or control).
1115 DataMessageType type;
1116 // A per-stream value incremented per packet in the stream.
1117 int seq_num;
1118 // A per-stream value monotonically increasing with time.
1119 int timestamp;
1120
deadbeef953c2ce2017-01-09 14:53:41 -08001121 ReceiveDataParams() : sid(0), type(DMT_TEXT), seq_num(0), timestamp(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001122};
1123
1124struct SendDataParams {
1125 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001126 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1127 union {
1128 uint32_t ssrc;
1129 int sid;
1130 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 // The type of message (binary, text, or control).
1132 DataMessageType type;
1133
1134 // For SCTP, whether to send messages flagged as ordered or not.
1135 // If false, messages can be received out of order.
1136 bool ordered;
1137 // For SCTP, whether the messages are sent reliably or not.
1138 // If false, messages may be lost.
1139 bool reliable;
1140 // For SCTP, if reliable == false, provide partial reliability by
1141 // resending up to this many times. Either count or millis
1142 // is supported, not both at the same time.
1143 int max_rtx_count;
1144 // For SCTP, if reliable == false, provide partial reliability by
1145 // resending for up to this many milliseconds. Either count or millis
1146 // is supported, not both at the same time.
1147 int max_rtx_ms;
1148
deadbeef953c2ce2017-01-09 14:53:41 -08001149 SendDataParams()
1150 : sid(0),
1151 type(DMT_TEXT),
1152 // TODO(pthatcher): Make these true by default?
1153 ordered(false),
1154 reliable(false),
1155 max_rtx_count(0),
1156 max_rtx_ms(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001157};
1158
1159enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1160
nisse05103312016-03-16 02:22:50 -07001161struct DataSendParameters : RtpSendParameters<DataCodec> {
solenberg7e4e01a2015-12-02 08:05:01 -08001162 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001163 std::ostringstream ost;
1164 // Options and extensions aren't used.
1165 ost << "{";
1166 ost << "codecs: " << VectorToString(codecs) << ", ";
pbos378dc772016-01-28 15:58:41 -08001167 ost << "max_bandwidth_bps: " << max_bandwidth_bps;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001168 ost << "}";
1169 return ost.str();
1170 }
1171};
1172
1173struct DataRecvParameters : RtpParameters<DataCodec> {
1174};
1175
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001176class DataMediaChannel : public MediaChannel {
1177 public:
1178 enum Error {
1179 ERROR_NONE = 0, // No error.
1180 ERROR_OTHER, // Other errors.
1181 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1182 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1183 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1184 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1185 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1186 };
1187
zhihuangebbe4f22016-12-06 10:45:42 -08001188 DataMediaChannel() {}
1189 DataMediaChannel(const MediaConfig& config) : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001190 virtual ~DataMediaChannel() {}
1191
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001192 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1193 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001194
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001195 // TODO(pthatcher): Implement this.
1196 virtual bool GetStats(DataMediaInfo* info) { return true; }
1197
1198 virtual bool SetSend(bool send) = 0;
1199 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200
Honghai Zhangcc411c02016-03-29 17:27:21 -07001201 virtual void OnNetworkRouteChanged(const std::string& transport_name,
Honghai Zhang0e533ef2016-04-19 15:41:36 -07001202 const rtc::NetworkRoute& network_route) {}
Honghai Zhangcc411c02016-03-29 17:27:21 -07001203
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001204 virtual bool SendData(
1205 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -07001206 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001207 SendDataResult* result = NULL) = 0;
1208 // Signals when data is received (params, data, len)
1209 sigslot::signal3<const ReceiveDataParams&,
1210 const char*,
1211 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001212 // Signal when the media channel is ready to send the stream. Arguments are:
1213 // writable(bool)
1214 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001215};
1216
1217} // namespace cricket
1218
kjellandera96e2d72016-02-04 23:52:28 -08001219#endif // WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_