blob: 19cb9a38da2b7c03795469f03a394d804368a8e1 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2004 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef TALK_MEDIA_BASE_MEDIACHANNEL_H_
29#define TALK_MEDIA_BASE_MEDIACHANNEL_H_
30
31#include <string>
32#include <vector>
33
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000034#include "talk/media/base/codec.h"
35#include "talk/media/base/constants.h"
36#include "talk/media/base/streamparams.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000037#include "webrtc/base/basictypes.h"
38#include "webrtc/base/buffer.h"
39#include "webrtc/base/dscp.h"
40#include "webrtc/base/logging.h"
41#include "webrtc/base/sigslot.h"
42#include "webrtc/base/socket.h"
43#include "webrtc/base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044// TODO(juberti): re-evaluate this include
45#include "talk/session/media/audiomonitor.h"
46
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000047namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048class Buffer;
49class RateLimiter;
50class Timing;
51}
52
53namespace cricket {
54
55class AudioRenderer;
56struct RtpHeader;
57class ScreencastId;
58struct VideoFormat;
59class VideoCapturer;
60class VideoRenderer;
61
62const int kMinRtpHeaderExtensionId = 1;
63const int kMaxRtpHeaderExtensionId = 255;
64const int kScreencastDefaultFps = 5;
wu@webrtc.orgcfe5e9c2014-03-27 17:03:58 +000065const int kHighStartBitrate = 1500;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066
67// Used in AudioOptions and VideoOptions to signify "unset" values.
68template <class T>
69class Settable {
70 public:
71 Settable() : set_(false), val_() {}
72 explicit Settable(T val) : set_(true), val_(val) {}
73
74 bool IsSet() const {
75 return set_;
76 }
77
78 bool Get(T* out) const {
79 *out = val_;
80 return set_;
81 }
82
83 T GetWithDefaultIfUnset(const T& default_value) const {
84 return set_ ? val_ : default_value;
85 }
86
pthatcher@webrtc.org40b276e2014-12-12 02:44:30 +000087 void Set(T val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 set_ = true;
89 val_ = val;
90 }
91
92 void Clear() {
93 Set(T());
94 set_ = false;
95 }
96
97 void SetFrom(const Settable<T>& o) {
98 // Set this value based on the value of o, iff o is set. If this value is
99 // set and o is unset, the current value will be unchanged.
100 T val;
101 if (o.Get(&val)) {
102 Set(val);
103 }
104 }
105
106 std::string ToString() const {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000107 return set_ ? rtc::ToString(val_) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108 }
109
110 bool operator==(const Settable<T>& o) const {
111 // Equal if both are unset with any value or both set with the same value.
112 return (set_ == o.set_) && (!set_ || (val_ == o.val_));
113 }
114
115 bool operator!=(const Settable<T>& o) const {
116 return !operator==(o);
117 }
118
119 protected:
120 void InitializeValue(const T &val) {
121 val_ = val;
122 }
123
124 private:
125 bool set_;
126 T val_;
127};
128
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129template <class T>
130static std::string ToStringIfSet(const char* key, const Settable<T>& val) {
131 std::string str;
132 if (val.IsSet()) {
133 str = key;
134 str += ": ";
135 str += val.ToString();
136 str += ", ";
137 }
138 return str;
139}
140
141// 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) {
147 echo_cancellation.SetFrom(change.echo_cancellation);
148 auto_gain_control.SetFrom(change.auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000149 rx_auto_gain_control.SetFrom(change.rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 noise_suppression.SetFrom(change.noise_suppression);
151 highpass_filter.SetFrom(change.highpass_filter);
152 stereo_swapping.SetFrom(change.stereo_swapping);
153 typing_detection.SetFrom(change.typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000154 aecm_generate_comfort_noise.SetFrom(change.aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 conference_mode.SetFrom(change.conference_mode);
156 adjust_agc_delta.SetFrom(change.adjust_agc_delta);
157 experimental_agc.SetFrom(change.experimental_agc);
158 experimental_aec.SetFrom(change.experimental_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000159 experimental_ns.SetFrom(change.experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000160 aec_dump.SetFrom(change.aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000161 tx_agc_target_dbov.SetFrom(change.tx_agc_target_dbov);
162 tx_agc_digital_compression_gain.SetFrom(
163 change.tx_agc_digital_compression_gain);
164 tx_agc_limiter.SetFrom(change.tx_agc_limiter);
165 rx_agc_target_dbov.SetFrom(change.rx_agc_target_dbov);
166 rx_agc_digital_compression_gain.SetFrom(
167 change.rx_agc_digital_compression_gain);
168 rx_agc_limiter.SetFrom(change.rx_agc_limiter);
169 recording_sample_rate.SetFrom(change.recording_sample_rate);
170 playout_sample_rate.SetFrom(change.playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000171 dscp.SetFrom(change.dscp);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000172 combined_audio_video_bwe.SetFrom(change.combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 }
174
175 bool operator==(const AudioOptions& o) const {
176 return echo_cancellation == o.echo_cancellation &&
177 auto_gain_control == o.auto_gain_control &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000178 rx_auto_gain_control == o.rx_auto_gain_control &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 noise_suppression == o.noise_suppression &&
180 highpass_filter == o.highpass_filter &&
181 stereo_swapping == o.stereo_swapping &&
182 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000183 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 conference_mode == o.conference_mode &&
185 experimental_agc == o.experimental_agc &&
186 experimental_aec == o.experimental_aec &&
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000187 experimental_ns == o.experimental_ns &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000189 aec_dump == o.aec_dump &&
190 tx_agc_target_dbov == o.tx_agc_target_dbov &&
191 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
192 tx_agc_limiter == o.tx_agc_limiter &&
193 rx_agc_target_dbov == o.rx_agc_target_dbov &&
194 rx_agc_digital_compression_gain == o.rx_agc_digital_compression_gain &&
195 rx_agc_limiter == o.rx_agc_limiter &&
196 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000197 playout_sample_rate == o.playout_sample_rate &&
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000198 dscp == o.dscp &&
199 combined_audio_video_bwe == o.combined_audio_video_bwe;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 }
201
202 std::string ToString() const {
203 std::ostringstream ost;
204 ost << "AudioOptions {";
205 ost << ToStringIfSet("aec", echo_cancellation);
206 ost << ToStringIfSet("agc", auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000207 ost << ToStringIfSet("rx_agc", rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 ost << ToStringIfSet("ns", noise_suppression);
209 ost << ToStringIfSet("hf", highpass_filter);
210 ost << ToStringIfSet("swap", stereo_swapping);
211 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000212 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 ost << ToStringIfSet("conference", conference_mode);
214 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
215 ost << ToStringIfSet("experimental_agc", experimental_agc);
216 ost << ToStringIfSet("experimental_aec", experimental_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000217 ost << ToStringIfSet("experimental_ns", experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 ost << ToStringIfSet("aec_dump", aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000219 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
220 ost << ToStringIfSet("tx_agc_digital_compression_gain",
221 tx_agc_digital_compression_gain);
222 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
223 ost << ToStringIfSet("rx_agc_target_dbov", rx_agc_target_dbov);
224 ost << ToStringIfSet("rx_agc_digital_compression_gain",
225 rx_agc_digital_compression_gain);
226 ost << ToStringIfSet("rx_agc_limiter", rx_agc_limiter);
227 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
228 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000229 ost << ToStringIfSet("dscp", dscp);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000230 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 ost << "}";
232 return ost.str();
233 }
234
235 // Audio processing that attempts to filter away the output signal from
236 // later inbound pickup.
237 Settable<bool> echo_cancellation;
238 // Audio processing to adjust the sensitivity of the local mic dynamically.
239 Settable<bool> auto_gain_control;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000240 // Audio processing to apply gain to the remote audio.
241 Settable<bool> rx_auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 // Audio processing to filter out background noise.
243 Settable<bool> noise_suppression;
244 // Audio processing to remove background noise of lower frequencies.
245 Settable<bool> highpass_filter;
246 // Audio processing to swap the left and right channels.
247 Settable<bool> stereo_swapping;
248 // Audio processing to detect typing.
249 Settable<bool> typing_detection;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000250 Settable<bool> aecm_generate_comfort_noise;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 Settable<bool> conference_mode;
252 Settable<int> adjust_agc_delta;
253 Settable<bool> experimental_agc;
254 Settable<bool> experimental_aec;
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000255 Settable<bool> experimental_ns;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 Settable<bool> aec_dump;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000257 // Note that tx_agc_* only applies to non-experimental AGC.
258 Settable<uint16> tx_agc_target_dbov;
259 Settable<uint16> tx_agc_digital_compression_gain;
260 Settable<bool> tx_agc_limiter;
261 Settable<uint16> rx_agc_target_dbov;
262 Settable<uint16> rx_agc_digital_compression_gain;
263 Settable<bool> rx_agc_limiter;
264 Settable<uint32> recording_sample_rate;
265 Settable<uint32> playout_sample_rate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000266 // Set DSCP value for packet sent from audio channel.
267 Settable<bool> dscp;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000268 // Enable combined audio+bandwidth BWE.
269 Settable<bool> combined_audio_video_bwe;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270};
271
272// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
273// Used to be flags, but that makes it hard to selectively apply options.
274// We are moving all of the setting of options to structs like this,
275// but some things currently still use flags.
276struct VideoOptions {
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000277 enum HighestBitrate {
278 NORMAL,
279 HIGH,
280 VERY_HIGH
281 };
282
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 VideoOptions() {
284 process_adaptation_threshhold.Set(kProcessCpuThreshold);
285 system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold);
286 system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000287 unsignalled_recv_stream_limit.Set(kNumDefaultUnsignalledVideoRecvStreams);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 }
289
290 void SetAll(const VideoOptions& change) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291 adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000292 adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000293 video_adapt_third.SetFrom(change.video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 video_noise_reduction.SetFrom(change.video_noise_reduction);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000295 video_start_bitrate.SetFrom(change.video_start_bitrate);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000296 video_highest_bitrate.SetFrom(change.video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000297 cpu_overuse_detection.SetFrom(change.cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000298 cpu_underuse_threshold.SetFrom(change.cpu_underuse_threshold);
299 cpu_overuse_threshold.SetFrom(change.cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000300 cpu_underuse_encode_rsd_threshold.SetFrom(
301 change.cpu_underuse_encode_rsd_threshold);
302 cpu_overuse_encode_rsd_threshold.SetFrom(
303 change.cpu_overuse_encode_rsd_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000304 cpu_overuse_encode_usage.SetFrom(change.cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 conference_mode.SetFrom(change.conference_mode);
306 process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
307 system_low_adaptation_threshhold.SetFrom(
308 change.system_low_adaptation_threshhold);
309 system_high_adaptation_threshhold.SetFrom(
310 change.system_high_adaptation_threshhold);
311 buffered_mode_latency.SetFrom(change.buffered_mode_latency);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000312 dscp.SetFrom(change.dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000313 suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000314 unsignalled_recv_stream_limit.SetFrom(change.unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000315 use_simulcast_adapter.SetFrom(change.use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000316 screencast_min_bitrate.SetFrom(change.screencast_min_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 }
318
319 bool operator==(const VideoOptions& o) const {
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000320 return adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
321 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
322 video_adapt_third == o.video_adapt_third &&
323 video_noise_reduction == o.video_noise_reduction &&
324 video_start_bitrate == o.video_start_bitrate &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000325 video_highest_bitrate == o.video_highest_bitrate &&
326 cpu_overuse_detection == o.cpu_overuse_detection &&
327 cpu_underuse_threshold == o.cpu_underuse_threshold &&
328 cpu_overuse_threshold == o.cpu_overuse_threshold &&
329 cpu_underuse_encode_rsd_threshold ==
330 o.cpu_underuse_encode_rsd_threshold &&
331 cpu_overuse_encode_rsd_threshold ==
332 o.cpu_overuse_encode_rsd_threshold &&
333 cpu_overuse_encode_usage == o.cpu_overuse_encode_usage &&
334 conference_mode == o.conference_mode &&
335 process_adaptation_threshhold == o.process_adaptation_threshhold &&
336 system_low_adaptation_threshhold ==
337 o.system_low_adaptation_threshhold &&
338 system_high_adaptation_threshhold ==
339 o.system_high_adaptation_threshhold &&
340 buffered_mode_latency == o.buffered_mode_latency && dscp == o.dscp &&
341 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
342 unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit &&
343 use_simulcast_adapter == o.use_simulcast_adapter &&
stefan@webrtc.org742386a2014-12-19 15:33:17 +0000344 screencast_min_bitrate == o.screencast_min_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 }
346
347 std::string ToString() const {
348 std::ostringstream ost;
349 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000351 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000352 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000354 ost << ToStringIfSet("start bitrate", video_start_bitrate);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000355 ost << ToStringIfSet("highest video bitrate", video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000356 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000357 ost << ToStringIfSet("cpu underuse threshold", cpu_underuse_threshold);
358 ost << ToStringIfSet("cpu overuse threshold", cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000359 ost << ToStringIfSet("cpu underuse encode rsd threshold",
360 cpu_underuse_encode_rsd_threshold);
361 ost << ToStringIfSet("cpu overuse encode rsd threshold",
362 cpu_overuse_encode_rsd_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000363 ost << ToStringIfSet("cpu overuse encode usage",
364 cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365 ost << ToStringIfSet("conference mode", conference_mode);
366 ost << ToStringIfSet("process", process_adaptation_threshhold);
367 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
368 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
369 ost << ToStringIfSet("buffered mode latency", buffered_mode_latency);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000370 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000371 ost << ToStringIfSet("suspend below min bitrate",
372 suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000373 ost << ToStringIfSet("num channels for early receive",
374 unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000375 ost << ToStringIfSet("use simulcast adapter", use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000376 ost << ToStringIfSet("screencast min bitrate", screencast_min_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377 ost << "}";
378 return ost.str();
379 }
380
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 // Enable CPU adaptation?
382 Settable<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000383 // Enable CPU adaptation smoothing?
384 Settable<bool> adapt_cpu_with_smoothing;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000385 // Enable video adapt third?
386 Settable<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387 // Enable denoising?
388 Settable<bool> video_noise_reduction;
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000389 // Experimental: Enable WebRtc higher start bitrate?
390 Settable<int> video_start_bitrate;
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000391 // Set highest bitrate mode for video.
wu@webrtc.orgcfe5e9c2014-03-27 17:03:58 +0000392 Settable<HighestBitrate> video_highest_bitrate;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000393 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
394 // adaptation algorithm. So this option will override the
395 // |adapt_input_to_cpu_usage|.
396 Settable<bool> cpu_overuse_detection;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000397 // Low threshold (t1) for cpu overuse adaptation. (Adapt up)
398 // Metric: encode usage (m1). m1 < t1 => underuse.
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000399 Settable<int> cpu_underuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000400 // High threshold (t1) for cpu overuse adaptation. (Adapt down)
401 // Metric: encode usage (m1). m1 > t1 => overuse.
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000402 Settable<int> cpu_overuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000403 // Low threshold (t2) for cpu overuse adaptation. (Adapt up)
404 // Metric: relative standard deviation of encode time (m2).
405 // Optional threshold. If set, (m1 < t1 && m2 < t2) => underuse.
406 // Note: t2 will have no effect if t1 is not set.
407 Settable<int> cpu_underuse_encode_rsd_threshold;
408 // High threshold (t2) for cpu overuse adaptation. (Adapt down)
409 // Metric: relative standard deviation of encode time (m2).
410 // Optional threshold. If set, (m1 > t1 || m2 > t2) => overuse.
411 // Note: t2 will have no effect if t1 is not set.
412 Settable<int> cpu_overuse_encode_rsd_threshold;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000413 // Use encode usage for cpu detection.
414 Settable<bool> cpu_overuse_encode_usage;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 // Use conference mode?
416 Settable<bool> conference_mode;
417 // Threshhold for process cpu adaptation. (Process limit)
pthatcher@webrtc.org40b276e2014-12-12 02:44:30 +0000418 Settable<float> process_adaptation_threshhold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419 // Low threshhold for cpu adaptation. (Adapt up)
pthatcher@webrtc.org40b276e2014-12-12 02:44:30 +0000420 Settable<float> system_low_adaptation_threshhold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421 // High threshhold for cpu adaptation. (Adapt down)
pthatcher@webrtc.org40b276e2014-12-12 02:44:30 +0000422 Settable<float> system_high_adaptation_threshhold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000423 // Specify buffered mode latency in milliseconds.
424 Settable<int> buffered_mode_latency;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000425 // Set DSCP value for packet sent from video channel.
426 Settable<bool> dscp;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000427 // Enable WebRTC suspension of video. No video frames will be sent when the
428 // bitrate is below the configured minimum bitrate.
429 Settable<bool> suspend_below_min_bitrate;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000430 // Limit on the number of early receive channels that can be created.
431 Settable<int> unsignalled_recv_stream_limit;
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000432 // Enable use of simulcast adapter.
433 Settable<bool> use_simulcast_adapter;
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000434 // Force screencast to use a minimum bitrate
435 Settable<int> screencast_min_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436};
437
438// A class for playing out soundclips.
439class SoundclipMedia {
440 public:
441 enum SoundclipFlags {
442 SF_LOOP = 1,
443 };
444
445 virtual ~SoundclipMedia() {}
446
447 // Plays a sound out to the speakers with the given audio stream. The stream
448 // must be 16-bit little-endian 16 kHz PCM. If a stream is already playing
449 // on this SoundclipMedia, it is stopped. If clip is NULL, nothing is played.
450 // Returns whether it was successful.
451 virtual bool PlaySound(const char *clip, int len, int flags) = 0;
452};
453
454struct RtpHeaderExtension {
455 RtpHeaderExtension() : id(0) {}
456 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
457 std::string uri;
458 int id;
459 // TODO(juberti): SendRecv direction;
460
461 bool operator==(const RtpHeaderExtension& ext) const {
462 // id is a reserved word in objective-c. Therefore the id attribute has to
463 // be a fully qualified name in order to compile on IOS.
464 return this->id == ext.id &&
465 uri == ext.uri;
466 }
467};
468
469// Returns the named header extension if found among all extensions, NULL
470// otherwise.
471inline const RtpHeaderExtension* FindHeaderExtension(
472 const std::vector<RtpHeaderExtension>& extensions,
473 const std::string& name) {
474 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
475 it != extensions.end(); ++it) {
476 if (it->uri == name)
477 return &(*it);
478 }
479 return NULL;
480}
481
482enum MediaChannelOptions {
483 // Tune the stream for conference mode.
484 OPT_CONFERENCE = 0x0001
485};
486
487enum VoiceMediaChannelOptions {
488 // Tune the audio stream for vcs with different target levels.
489 OPT_AGC_MINUS_10DB = 0x80000000
490};
491
492// DTMF flags to control if a DTMF tone should be played and/or sent.
493enum DtmfFlags {
494 DF_PLAY = 0x01,
495 DF_SEND = 0x02,
496};
497
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000498class MediaChannel : public sigslot::has_slots<> {
499 public:
500 class NetworkInterface {
501 public:
502 enum SocketType { ST_RTP, ST_RTCP };
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000503 virtual bool SendPacket(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000504 rtc::Buffer* packet,
505 rtc::DiffServCodePoint dscp = rtc::DSCP_NO_CHANGE) = 0;
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000506 virtual bool SendRtcp(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000507 rtc::Buffer* packet,
508 rtc::DiffServCodePoint dscp = rtc::DSCP_NO_CHANGE) = 0;
509 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510 int option) = 0;
511 virtual ~NetworkInterface() {}
512 };
513
514 MediaChannel() : network_interface_(NULL) {}
515 virtual ~MediaChannel() {}
516
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000517 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000519 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000520 network_interface_ = iface;
521 }
522
523 // Called when a RTP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000524 virtual void OnPacketReceived(rtc::Buffer* packet,
525 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526 // Called when a RTCP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000527 virtual void OnRtcpReceived(rtc::Buffer* packet,
528 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000529 // Called when the socket's ability to send has changed.
530 virtual void OnReadyToSend(bool ready) = 0;
531 // Creates a new outgoing media stream with SSRCs and CNAME as described
532 // by sp.
533 virtual bool AddSendStream(const StreamParams& sp) = 0;
534 // Removes an outgoing media stream.
535 // ssrc must be the first SSRC of the media stream if the stream uses
536 // multiple SSRCs.
537 virtual bool RemoveSendStream(uint32 ssrc) = 0;
538 // Creates a new incoming media stream with SSRCs and CNAME as described
539 // by sp.
540 virtual bool AddRecvStream(const StreamParams& sp) = 0;
541 // Removes an incoming media stream.
542 // ssrc must be the first SSRC of the media stream if the stream uses
543 // multiple SSRCs.
544 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
545
546 // Mutes the channel.
547 virtual bool MuteStream(uint32 ssrc, bool on) = 0;
548
549 // Sets the RTP extension headers and IDs to use when sending RTP.
550 virtual bool SetRecvRtpHeaderExtensions(
551 const std::vector<RtpHeaderExtension>& extensions) = 0;
552 virtual bool SetSendRtpHeaderExtensions(
553 const std::vector<RtpHeaderExtension>& extensions) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000554 // Returns the absoulte sendtime extension id value from media channel.
555 virtual int GetRtpSendTimeExtnId() const {
556 return -1;
557 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000558 // Sets the maximum allowed bandwidth to use when sending data.
559 virtual bool SetMaxSendBandwidth(int bps) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000561 // Base method to send packet using NetworkInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000562 bool SendPacket(rtc::Buffer* packet) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000563 return DoSendPacket(packet, false);
564 }
565
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000566 bool SendRtcp(rtc::Buffer* packet) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000567 return DoSendPacket(packet, true);
568 }
569
570 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000571 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000572 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000573 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000574 if (!network_interface_)
575 return -1;
576
577 return network_interface_->SetOption(type, opt, option);
578 }
579
wu@webrtc.orgde305012013-10-31 15:40:38 +0000580 protected:
581 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000582 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000583 int ret;
584 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000585 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000586 value);
587 if (ret == 0) {
588 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000589 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000590 value);
591 }
592 return ret;
593 }
594
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000595 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000596 bool DoSendPacket(rtc::Buffer* packet, bool rtcp) {
597 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000598 if (!network_interface_)
599 return false;
600
601 return (!rtcp) ? network_interface_->SendPacket(packet) :
602 network_interface_->SendRtcp(packet);
603 }
604
605 // |network_interface_| can be accessed from the worker_thread and
606 // from any MediaEngine threads. This critical section is to protect accessing
607 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000608 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000609 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610};
611
612enum SendFlags {
613 SEND_NOTHING,
614 SEND_RINGBACKTONE,
615 SEND_MICROPHONE
616};
617
wu@webrtc.org97077a32013-10-25 21:18:33 +0000618// The stats information is structured as follows:
619// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
620// Media contains a vector of SSRC infos that are exclusively used by this
621// media. (SSRCs shared between media streams can't be represented.)
622
623// Information about an SSRC.
624// This data may be locally recorded, or received in an RTCP SR or RR.
625struct SsrcSenderInfo {
626 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000628 timestamp(0) {
629 }
630 uint32 ssrc;
631 double timestamp; // NTP timestamp, represented as seconds since epoch.
632};
633
634struct SsrcReceiverInfo {
635 SsrcReceiverInfo()
636 : ssrc(0),
637 timestamp(0) {
638 }
639 uint32 ssrc;
640 double timestamp;
641};
642
643struct MediaSenderInfo {
644 MediaSenderInfo()
645 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646 packets_sent(0),
647 packets_lost(0),
648 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000649 rtt_ms(0) {
650 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000651 void add_ssrc(const SsrcSenderInfo& stat) {
652 local_stats.push_back(stat);
653 }
654 // Temporary utility function for call sites that only provide SSRC.
655 // As more info is added into SsrcSenderInfo, this function should go away.
656 void add_ssrc(uint32 ssrc) {
657 SsrcSenderInfo stat;
658 stat.ssrc = ssrc;
659 add_ssrc(stat);
660 }
661 // Utility accessor for clients that are only interested in ssrc numbers.
662 std::vector<uint32> ssrcs() const {
663 std::vector<uint32> retval;
664 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
665 it != local_stats.end(); ++it) {
666 retval.push_back(it->ssrc);
667 }
668 return retval;
669 }
670 // Utility accessor for clients that make the assumption only one ssrc
671 // exists per media.
672 // This will eventually go away.
673 uint32 ssrc() const {
674 if (local_stats.size() > 0) {
675 return local_stats[0].ssrc;
676 } else {
677 return 0;
678 }
679 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000680 int64 bytes_sent;
681 int packets_sent;
682 int packets_lost;
683 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000684 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000685 std::string codec_name;
686 std::vector<SsrcSenderInfo> local_stats;
687 std::vector<SsrcReceiverInfo> remote_stats;
688};
689
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000690template<class T>
691struct VariableInfo {
692 VariableInfo()
693 : min_val(),
694 mean(0.0),
695 max_val(),
696 variance(0.0) {
697 }
698 T min_val;
699 double mean;
700 T max_val;
701 double variance;
702};
703
wu@webrtc.org97077a32013-10-25 21:18:33 +0000704struct MediaReceiverInfo {
705 MediaReceiverInfo()
706 : bytes_rcvd(0),
707 packets_rcvd(0),
708 packets_lost(0),
709 fraction_lost(0.0) {
710 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000711 void add_ssrc(const SsrcReceiverInfo& stat) {
712 local_stats.push_back(stat);
713 }
714 // Temporary utility function for call sites that only provide SSRC.
715 // As more info is added into SsrcSenderInfo, this function should go away.
716 void add_ssrc(uint32 ssrc) {
717 SsrcReceiverInfo stat;
718 stat.ssrc = ssrc;
719 add_ssrc(stat);
720 }
721 std::vector<uint32> ssrcs() const {
722 std::vector<uint32> retval;
723 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
724 it != local_stats.end(); ++it) {
725 retval.push_back(it->ssrc);
726 }
727 return retval;
728 }
729 // Utility accessor for clients that make the assumption only one ssrc
730 // exists per media.
731 // This will eventually go away.
732 uint32 ssrc() const {
733 if (local_stats.size() > 0) {
734 return local_stats[0].ssrc;
735 } else {
736 return 0;
737 }
738 }
739
wu@webrtc.org97077a32013-10-25 21:18:33 +0000740 int64 bytes_rcvd;
741 int packets_rcvd;
742 int packets_lost;
743 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000744 std::string codec_name;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000745 std::vector<SsrcReceiverInfo> local_stats;
746 std::vector<SsrcSenderInfo> remote_stats;
747};
748
749struct VoiceSenderInfo : public MediaSenderInfo {
750 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000751 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 jitter_ms(0),
753 audio_level(0),
754 aec_quality_min(0.0),
755 echo_delay_median_ms(0),
756 echo_delay_std_ms(0),
757 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000758 echo_return_loss_enhancement(0),
759 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 }
761
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 int jitter_ms;
764 int audio_level;
765 float aec_quality_min;
766 int echo_delay_median_ms;
767 int echo_delay_std_ms;
768 int echo_return_loss;
769 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000770 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771};
772
wu@webrtc.org97077a32013-10-25 21:18:33 +0000773struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000775 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000776 jitter_ms(0),
777 jitter_buffer_ms(0),
778 jitter_buffer_preferred_ms(0),
779 delay_estimate_ms(0),
780 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000781 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000782 speech_expand_rate(0),
783 secondary_decoded_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000784 decoding_calls_to_silence_generator(0),
785 decoding_calls_to_neteq(0),
786 decoding_normal(0),
787 decoding_plc(0),
788 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000789 decoding_plc_cng(0),
790 capture_start_ntp_time_ms(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 }
792
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 int ext_seqnum;
794 int jitter_ms;
795 int jitter_buffer_ms;
796 int jitter_buffer_preferred_ms;
797 int delay_estimate_ms;
798 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000799 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000801 // fraction of synthesized speech inserted through expansion.
802 float speech_expand_rate;
803 // fraction of data out of secondary decoding, including FEC and RED.
804 float secondary_decoded_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000805 int decoding_calls_to_silence_generator;
806 int decoding_calls_to_neteq;
807 int decoding_normal;
808 int decoding_plc;
809 int decoding_cng;
810 int decoding_plc_cng;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000811 // Estimated capture start time in NTP time in ms.
812 int64 capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813};
814
wu@webrtc.org97077a32013-10-25 21:18:33 +0000815struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000817 : packets_cached(0),
818 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000819 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000821 input_frame_width(0),
822 input_frame_height(0),
823 send_frame_width(0),
824 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 framerate_input(0),
826 framerate_sent(0),
827 nominal_bitrate(0),
828 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000829 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000830 adapt_changes(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000831 capture_jitter_ms(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000832 avg_encode_ms(0),
833 encode_usage_percent(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000834 capture_queue_delay_ms_per_s(0) {
835 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000837 std::vector<SsrcGroup> ssrc_groups;
838 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000840 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000842 int input_frame_width;
843 int input_frame_height;
844 int send_frame_width;
845 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 int framerate_input;
847 int framerate_sent;
848 int nominal_bitrate;
849 int preferred_bitrate;
850 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000851 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000852 int capture_jitter_ms;
853 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000854 int encode_usage_percent;
855 int capture_queue_delay_ms_per_s;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000856 VariableInfo<int> adapt_frame_drops;
857 VariableInfo<int> effects_frame_drops;
858 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859};
860
wu@webrtc.org97077a32013-10-25 21:18:33 +0000861struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000863 : packets_concealed(0),
864 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000865 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 nacks_sent(0),
867 frame_width(0),
868 frame_height(0),
869 framerate_rcvd(0),
870 framerate_decoded(0),
871 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000872 framerate_render_input(0),
873 framerate_render_output(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000874 decode_ms(0),
875 max_decode_ms(0),
876 jitter_buffer_ms(0),
877 min_playout_delay_ms(0),
878 render_delay_ms(0),
879 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000880 current_delay_ms(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000881 capture_start_ntp_time_ms(-1) {
882 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000884 std::vector<SsrcGroup> ssrc_groups;
885 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000887 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 int nacks_sent;
889 int frame_width;
890 int frame_height;
891 int framerate_rcvd;
892 int framerate_decoded;
893 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000894 // Framerate as sent to the renderer.
895 int framerate_render_input;
896 // Framerate that the renderer reports.
897 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000898
899 // All stats below are gathered per-VideoReceiver, but some will be correlated
900 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
901 // structures, reflect this in the new layout.
902
903 // Current frame decode latency.
904 int decode_ms;
905 // Maximum observed frame decode latency.
906 int max_decode_ms;
907 // Jitter (network-related) latency.
908 int jitter_buffer_ms;
909 // Requested minimum playout latency.
910 int min_playout_delay_ms;
911 // Requested latency to account for rendering delay.
912 int render_delay_ms;
913 // Target overall delay: network+decode+render, accounting for
914 // min_playout_delay_ms.
915 int target_delay_ms;
916 // Current overall delay, possibly ramping towards target_delay_ms.
917 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000918
919 // Estimated capture start time in NTP time in ms.
920 int64 capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921};
922
wu@webrtc.org97077a32013-10-25 21:18:33 +0000923struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000925 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 }
927
928 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929};
930
wu@webrtc.org97077a32013-10-25 21:18:33 +0000931struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000932 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000933 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 }
935
936 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937};
938
939struct BandwidthEstimationInfo {
940 BandwidthEstimationInfo()
941 : available_send_bandwidth(0),
942 available_recv_bandwidth(0),
943 target_enc_bitrate(0),
944 actual_enc_bitrate(0),
945 retransmit_bitrate(0),
946 transmit_bitrate(0),
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000947 bucket_delay(0),
948 total_received_propagation_delta_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 }
950
951 int available_send_bandwidth;
952 int available_recv_bandwidth;
953 int target_enc_bitrate;
954 int actual_enc_bitrate;
955 int retransmit_bitrate;
956 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000957 int64_t bucket_delay;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000958 // The following stats are only valid when
959 // StatsOptions::include_received_propagation_stats is true.
960 int total_received_propagation_delta_ms;
961 std::vector<int> recent_received_propagation_delta_ms;
tkchin@webrtc.org14146e42014-10-31 00:14:39 +0000962 std::vector<int64_t> recent_received_packet_group_arrival_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963};
964
965struct VoiceMediaInfo {
966 void Clear() {
967 senders.clear();
968 receivers.clear();
969 }
970 std::vector<VoiceSenderInfo> senders;
971 std::vector<VoiceReceiverInfo> receivers;
972};
973
974struct VideoMediaInfo {
975 void Clear() {
976 senders.clear();
977 receivers.clear();
978 bw_estimations.clear();
979 }
980 std::vector<VideoSenderInfo> senders;
981 std::vector<VideoReceiverInfo> receivers;
982 std::vector<BandwidthEstimationInfo> bw_estimations;
983};
984
985struct DataMediaInfo {
986 void Clear() {
987 senders.clear();
988 receivers.clear();
989 }
990 std::vector<DataSenderInfo> senders;
991 std::vector<DataReceiverInfo> receivers;
992};
993
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000994struct StatsOptions {
995 StatsOptions() : include_received_propagation_stats(false) {}
996
997 bool include_received_propagation_stats;
998};
999
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000class VoiceMediaChannel : public MediaChannel {
1001 public:
1002 enum Error {
1003 ERROR_NONE = 0, // No error.
1004 ERROR_OTHER, // Other errors.
1005 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
1006 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
1007 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
1008 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
1009 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
1010 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
1011 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
1012 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1013 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
1014 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
1015 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
1016 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
1017 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
1018 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
1019 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1020 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1021 };
1022
1023 VoiceMediaChannel() {}
1024 virtual ~VoiceMediaChannel() {}
1025 // Sets the codecs/payload types to be used for incoming media.
1026 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
1027 // Sets the codecs/payload types to be used for outgoing media.
1028 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
1029 // Starts or stops playout of received audio.
1030 virtual bool SetPlayout(bool playout) = 0;
1031 // Starts or stops sending (and potentially capture) of local audio.
1032 virtual bool SetSend(SendFlags flag) = 0;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001033 // Sets the renderer object to be used for the specified remote audio stream.
1034 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
1035 // Sets the renderer object to be used for the specified local audio stream.
1036 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001037 // Gets current energy levels for all incoming streams.
1038 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1039 // Get the current energy level of the stream sent to the speaker.
1040 virtual int GetOutputLevel() = 0;
1041 // Get the time in milliseconds since last recorded keystroke, or negative.
1042 virtual int GetTimeSinceLastTyping() = 0;
1043 // Temporarily exposed field for tuning typing detect options.
1044 virtual void SetTypingDetectionParameters(int time_window,
1045 int cost_per_typing, int reporting_threshold, int penalty_decay,
1046 int type_event_delay) = 0;
1047 // Set left and right scale for speaker output volume of the specified ssrc.
1048 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
1049 // Get left and right scale for speaker output volume of the specified ssrc.
1050 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0;
1051 // Specifies a ringback tone to be played during call setup.
1052 virtual bool SetRingbackTone(const char *buf, int len) = 0;
1053 // Plays or stops the aforementioned ringback tone
1054 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
1055 // Returns if the telephone-event has been negotiated.
1056 virtual bool CanInsertDtmf() { return false; }
1057 // Send and/or play a DTMF |event| according to the |flags|.
1058 // The DTMF out-of-band signal will be used on sending.
1059 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001060 // The valid value for the |event| are 0 to 15 which corresponding to
1061 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
1063 // Gets quality stats for the channel.
1064 virtual bool GetStats(VoiceMediaInfo* info) = 0;
1065 // Gets last reported error for this media channel.
1066 virtual void GetLastMediaError(uint32* ssrc,
1067 VoiceMediaChannel::Error* error) {
1068 ASSERT(error != NULL);
1069 *error = ERROR_NONE;
1070 }
1071 // Sets the media options to use.
1072 virtual bool SetOptions(const AudioOptions& options) = 0;
1073 virtual bool GetOptions(AudioOptions* options) const = 0;
1074
1075 // Signal errors from MediaChannel. Arguments are:
1076 // ssrc(uint32), and error(VoiceMediaChannel::Error).
1077 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
1078};
1079
1080class VideoMediaChannel : public MediaChannel {
1081 public:
1082 enum Error {
1083 ERROR_NONE = 0, // No error.
1084 ERROR_OTHER, // Other errors.
1085 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1086 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1087 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1088 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1089 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1090 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1091 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1092 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1093 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1094 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1095 };
1096
1097 VideoMediaChannel() : renderer_(NULL) {}
1098 virtual ~VideoMediaChannel() {}
1099 // Sets the codecs/payload types to be used for incoming media.
1100 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
1101 // Sets the codecs/payload types to be used for outgoing media.
1102 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
1103 // Gets the currently set codecs/payload types to be used for outgoing media.
1104 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1105 // Sets the format of a specified outgoing stream.
1106 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
1107 // Starts or stops playout of received video.
1108 virtual bool SetRender(bool render) = 0;
1109 // Starts or stops transmission (and potentially capture) of local video.
1110 virtual bool SetSend(bool send) = 0;
1111 // Sets the renderer object to be used for the specified stream.
1112 // If SSRC is 0, the renderer is used for the 'default' stream.
1113 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
1114 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1115 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
1116 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
1117 // Gets quality stats for the channel.
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001118 virtual bool GetStats(const StatsOptions& options, VideoMediaInfo* info) = 0;
1119 // This is needed for MediaMonitor to use the same template for voice, video
1120 // and data MediaChannels.
1121 bool GetStats(VideoMediaInfo* info) {
1122 return GetStats(StatsOptions(), info);
1123 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124
1125 // Send an intra frame to the receivers.
1126 virtual bool SendIntraFrame() = 0;
1127 // Reuqest each of the remote senders to send an intra frame.
1128 virtual bool RequestIntraFrame() = 0;
1129 // Sets the media options to use.
1130 virtual bool SetOptions(const VideoOptions& options) = 0;
1131 virtual bool GetOptions(VideoOptions* options) const = 0;
1132 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1133
1134 // Signal errors from MediaChannel. Arguments are:
1135 // ssrc(uint32), and error(VideoMediaChannel::Error).
1136 sigslot::signal2<uint32, Error> SignalMediaError;
1137
1138 protected:
1139 VideoRenderer *renderer_;
1140};
1141
1142enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001143 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1144 // values.
1145 DMT_NONE = 0,
1146 DMT_CONTROL = 1,
1147 DMT_BINARY = 2,
1148 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149};
1150
1151// Info about data received in DataMediaChannel. For use in
1152// DataMediaChannel::SignalDataReceived and in all of the signals that
1153// signal fires, on up the chain.
1154struct ReceiveDataParams {
1155 // The in-packet stream indentifier.
1156 // For SCTP, this is really SID, not SSRC.
1157 uint32 ssrc;
1158 // The type of message (binary, text, or control).
1159 DataMessageType type;
1160 // A per-stream value incremented per packet in the stream.
1161 int seq_num;
1162 // A per-stream value monotonically increasing with time.
1163 int timestamp;
1164
1165 ReceiveDataParams() :
1166 ssrc(0),
1167 type(DMT_TEXT),
1168 seq_num(0),
1169 timestamp(0) {
1170 }
1171};
1172
1173struct SendDataParams {
1174 // The in-packet stream indentifier.
1175 // For SCTP, this is really SID, not SSRC.
1176 uint32 ssrc;
1177 // The type of message (binary, text, or control).
1178 DataMessageType type;
1179
1180 // For SCTP, whether to send messages flagged as ordered or not.
1181 // If false, messages can be received out of order.
1182 bool ordered;
1183 // For SCTP, whether the messages are sent reliably or not.
1184 // If false, messages may be lost.
1185 bool reliable;
1186 // For SCTP, if reliable == false, provide partial reliability by
1187 // resending up to this many times. Either count or millis
1188 // is supported, not both at the same time.
1189 int max_rtx_count;
1190 // For SCTP, if reliable == false, provide partial reliability by
1191 // resending for up to this many milliseconds. Either count or millis
1192 // is supported, not both at the same time.
1193 int max_rtx_ms;
1194
1195 SendDataParams() :
1196 ssrc(0),
1197 type(DMT_TEXT),
1198 // TODO(pthatcher): Make these true by default?
1199 ordered(false),
1200 reliable(false),
1201 max_rtx_count(0),
1202 max_rtx_ms(0) {
1203 }
1204};
1205
1206enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1207
1208class DataMediaChannel : public MediaChannel {
1209 public:
1210 enum Error {
1211 ERROR_NONE = 0, // No error.
1212 ERROR_OTHER, // Other errors.
1213 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1214 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1215 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1216 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1217 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1218 };
1219
1220 virtual ~DataMediaChannel() {}
1221
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001222 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
1223 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001224
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001225 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
1226 // TODO(pthatcher): Implement this.
1227 virtual bool GetStats(DataMediaInfo* info) { return true; }
1228
1229 virtual bool SetSend(bool send) = 0;
1230 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001231
1232 virtual bool SendData(
1233 const SendDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001234 const rtc::Buffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 SendDataResult* result = NULL) = 0;
1236 // Signals when data is received (params, data, len)
1237 sigslot::signal3<const ReceiveDataParams&,
1238 const char*,
1239 size_t> SignalDataReceived;
1240 // Signal errors from MediaChannel. Arguments are:
1241 // ssrc(uint32), and error(DataMediaChannel::Error).
1242 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001243 // Signal when the media channel is ready to send the stream. Arguments are:
1244 // writable(bool)
1245 sigslot::signal1<bool> SignalReadyToSend;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001246 // Signal for notifying that the remote side has closed the DataChannel.
1247 sigslot::signal1<uint32> SignalStreamClosedRemotely;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248};
1249
1250} // namespace cricket
1251
1252#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_