blob: 34d2deff709ed4e607f7f32241b155cdd65b0366 [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
34#include "talk/base/basictypes.h"
35#include "talk/base/buffer.h"
mallinath@webrtc.org1112c302013-09-23 20:34:45 +000036#include "talk/base/dscp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/base/logging.h"
38#include "talk/base/sigslot.h"
39#include "talk/base/socket.h"
40#include "talk/base/window.h"
41#include "talk/media/base/codec.h"
42#include "talk/media/base/constants.h"
43#include "talk/media/base/streamparams.h"
44// TODO(juberti): re-evaluate this include
45#include "talk/session/media/audiomonitor.h"
46
47namespace talk_base {
48class 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
87 virtual void Set(T val) {
88 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 {
107 return set_ ? talk_base::ToString(val_) : "";
108 }
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
129class SettablePercent : public Settable<float> {
130 public:
131 virtual void Set(float val) {
132 if (val < 0) {
133 val = 0;
134 }
135 if (val > 1.0) {
136 val = 1.0;
137 }
138 Settable<float>::Set(val);
139 }
140};
141
142template <class T>
143static std::string ToStringIfSet(const char* key, const Settable<T>& val) {
144 std::string str;
145 if (val.IsSet()) {
146 str = key;
147 str += ": ";
148 str += val.ToString();
149 str += ", ";
150 }
151 return str;
152}
153
154// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
155// Used to be flags, but that makes it hard to selectively apply options.
156// We are moving all of the setting of options to structs like this,
157// but some things currently still use flags.
158struct AudioOptions {
159 void SetAll(const AudioOptions& change) {
160 echo_cancellation.SetFrom(change.echo_cancellation);
161 auto_gain_control.SetFrom(change.auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000162 rx_auto_gain_control.SetFrom(change.rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 noise_suppression.SetFrom(change.noise_suppression);
164 highpass_filter.SetFrom(change.highpass_filter);
165 stereo_swapping.SetFrom(change.stereo_swapping);
166 typing_detection.SetFrom(change.typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000167 aecm_generate_comfort_noise.SetFrom(change.aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 conference_mode.SetFrom(change.conference_mode);
169 adjust_agc_delta.SetFrom(change.adjust_agc_delta);
170 experimental_agc.SetFrom(change.experimental_agc);
171 experimental_aec.SetFrom(change.experimental_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000172 experimental_ns.SetFrom(change.experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 aec_dump.SetFrom(change.aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000174 tx_agc_target_dbov.SetFrom(change.tx_agc_target_dbov);
175 tx_agc_digital_compression_gain.SetFrom(
176 change.tx_agc_digital_compression_gain);
177 tx_agc_limiter.SetFrom(change.tx_agc_limiter);
178 rx_agc_target_dbov.SetFrom(change.rx_agc_target_dbov);
179 rx_agc_digital_compression_gain.SetFrom(
180 change.rx_agc_digital_compression_gain);
181 rx_agc_limiter.SetFrom(change.rx_agc_limiter);
182 recording_sample_rate.SetFrom(change.recording_sample_rate);
183 playout_sample_rate.SetFrom(change.playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000184 dscp.SetFrom(change.dscp);
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +0000185 opus_fec.SetFrom(change.opus_fec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 }
187
188 bool operator==(const AudioOptions& o) const {
189 return echo_cancellation == o.echo_cancellation &&
190 auto_gain_control == o.auto_gain_control &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000191 rx_auto_gain_control == o.rx_auto_gain_control &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 noise_suppression == o.noise_suppression &&
193 highpass_filter == o.highpass_filter &&
194 stereo_swapping == o.stereo_swapping &&
195 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000196 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197 conference_mode == o.conference_mode &&
198 experimental_agc == o.experimental_agc &&
199 experimental_aec == o.experimental_aec &&
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000200 experimental_ns == o.experimental_ns &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000202 aec_dump == o.aec_dump &&
203 tx_agc_target_dbov == o.tx_agc_target_dbov &&
204 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
205 tx_agc_limiter == o.tx_agc_limiter &&
206 rx_agc_target_dbov == o.rx_agc_target_dbov &&
207 rx_agc_digital_compression_gain == o.rx_agc_digital_compression_gain &&
208 rx_agc_limiter == o.rx_agc_limiter &&
209 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000210 playout_sample_rate == o.playout_sample_rate &&
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +0000211 dscp == o.dscp &&
212 opus_fec == o.opus_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 }
214
215 std::string ToString() const {
216 std::ostringstream ost;
217 ost << "AudioOptions {";
218 ost << ToStringIfSet("aec", echo_cancellation);
219 ost << ToStringIfSet("agc", auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000220 ost << ToStringIfSet("rx_agc", rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 ost << ToStringIfSet("ns", noise_suppression);
222 ost << ToStringIfSet("hf", highpass_filter);
223 ost << ToStringIfSet("swap", stereo_swapping);
224 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000225 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 ost << ToStringIfSet("conference", conference_mode);
227 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
228 ost << ToStringIfSet("experimental_agc", experimental_agc);
229 ost << ToStringIfSet("experimental_aec", experimental_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000230 ost << ToStringIfSet("experimental_ns", experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 ost << ToStringIfSet("aec_dump", aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000232 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
233 ost << ToStringIfSet("tx_agc_digital_compression_gain",
234 tx_agc_digital_compression_gain);
235 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
236 ost << ToStringIfSet("rx_agc_target_dbov", rx_agc_target_dbov);
237 ost << ToStringIfSet("rx_agc_digital_compression_gain",
238 rx_agc_digital_compression_gain);
239 ost << ToStringIfSet("rx_agc_limiter", rx_agc_limiter);
240 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
241 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000242 ost << ToStringIfSet("dscp", dscp);
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +0000243 ost << ToStringIfSet("opus_fec", opus_fec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 ost << "}";
245 return ost.str();
246 }
247
248 // Audio processing that attempts to filter away the output signal from
249 // later inbound pickup.
250 Settable<bool> echo_cancellation;
251 // Audio processing to adjust the sensitivity of the local mic dynamically.
252 Settable<bool> auto_gain_control;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000253 // Audio processing to apply gain to the remote audio.
254 Settable<bool> rx_auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 // Audio processing to filter out background noise.
256 Settable<bool> noise_suppression;
257 // Audio processing to remove background noise of lower frequencies.
258 Settable<bool> highpass_filter;
259 // Audio processing to swap the left and right channels.
260 Settable<bool> stereo_swapping;
261 // Audio processing to detect typing.
262 Settable<bool> typing_detection;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000263 Settable<bool> aecm_generate_comfort_noise;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 Settable<bool> conference_mode;
265 Settable<int> adjust_agc_delta;
266 Settable<bool> experimental_agc;
267 Settable<bool> experimental_aec;
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000268 Settable<bool> experimental_ns;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269 Settable<bool> aec_dump;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000270 // Note that tx_agc_* only applies to non-experimental AGC.
271 Settable<uint16> tx_agc_target_dbov;
272 Settable<uint16> tx_agc_digital_compression_gain;
273 Settable<bool> tx_agc_limiter;
274 Settable<uint16> rx_agc_target_dbov;
275 Settable<uint16> rx_agc_digital_compression_gain;
276 Settable<bool> rx_agc_limiter;
277 Settable<uint32> recording_sample_rate;
278 Settable<uint32> playout_sample_rate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000279 // Set DSCP value for packet sent from audio channel.
280 Settable<bool> dscp;
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +0000281 // Set Opus FEC
282 Settable<bool> opus_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283};
284
285// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
286// Used to be flags, but that makes it hard to selectively apply options.
287// We are moving all of the setting of options to structs like this,
288// but some things currently still use flags.
289struct VideoOptions {
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000290 enum HighestBitrate {
291 NORMAL,
292 HIGH,
293 VERY_HIGH
294 };
295
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296 VideoOptions() {
297 process_adaptation_threshhold.Set(kProcessCpuThreshold);
298 system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold);
299 system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000300 unsignalled_recv_stream_limit.Set(kNumDefaultUnsignalledVideoRecvStreams);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301 }
302
303 void SetAll(const VideoOptions& change) {
304 adapt_input_to_encoder.SetFrom(change.adapt_input_to_encoder);
305 adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000306 adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 adapt_view_switch.SetFrom(change.adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000308 video_adapt_third.SetFrom(change.video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 video_noise_reduction.SetFrom(change.video_noise_reduction);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 video_one_layer_screencast.SetFrom(change.video_one_layer_screencast);
311 video_high_bitrate.SetFrom(change.video_high_bitrate);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000312 video_start_bitrate.SetFrom(change.video_start_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 video_temporal_layer_screencast.SetFrom(
314 change.video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000315 video_temporal_layer_realtime.SetFrom(
316 change.video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 video_leaky_bucket.SetFrom(change.video_leaky_bucket);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000318 video_highest_bitrate.SetFrom(change.video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000319 cpu_overuse_detection.SetFrom(change.cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000320 cpu_underuse_threshold.SetFrom(change.cpu_underuse_threshold);
321 cpu_overuse_threshold.SetFrom(change.cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000322 cpu_underuse_encode_rsd_threshold.SetFrom(
323 change.cpu_underuse_encode_rsd_threshold);
324 cpu_overuse_encode_rsd_threshold.SetFrom(
325 change.cpu_overuse_encode_rsd_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000326 cpu_overuse_encode_usage.SetFrom(change.cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 conference_mode.SetFrom(change.conference_mode);
328 process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
329 system_low_adaptation_threshhold.SetFrom(
330 change.system_low_adaptation_threshhold);
331 system_high_adaptation_threshhold.SetFrom(
332 change.system_high_adaptation_threshhold);
333 buffered_mode_latency.SetFrom(change.buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000334 lower_min_bitrate.SetFrom(change.lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000335 dscp.SetFrom(change.dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000336 suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000337 unsignalled_recv_stream_limit.SetFrom(change.unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000338 use_simulcast_adapter.SetFrom(change.use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000339 skip_encoding_unused_streams.SetFrom(change.skip_encoding_unused_streams);
340 screencast_min_bitrate.SetFrom(change.screencast_min_bitrate);
341 use_improved_wifi_bandwidth_estimator.SetFrom(
342 change.use_improved_wifi_bandwidth_estimator);
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000343 use_payload_padding.SetFrom(change.use_payload_padding);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 }
345
346 bool operator==(const VideoOptions& o) const {
347 return adapt_input_to_encoder == o.adapt_input_to_encoder &&
348 adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000349 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 adapt_view_switch == o.adapt_view_switch &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000351 video_adapt_third == o.video_adapt_third &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 video_noise_reduction == o.video_noise_reduction &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 video_one_layer_screencast == o.video_one_layer_screencast &&
354 video_high_bitrate == o.video_high_bitrate &&
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000355 video_start_bitrate == o.video_start_bitrate &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 video_temporal_layer_screencast == o.video_temporal_layer_screencast &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000357 video_temporal_layer_realtime == o.video_temporal_layer_realtime &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 video_leaky_bucket == o.video_leaky_bucket &&
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000359 video_highest_bitrate == o.video_highest_bitrate &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000360 cpu_overuse_detection == o.cpu_overuse_detection &&
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000361 cpu_underuse_threshold == o.cpu_underuse_threshold &&
362 cpu_overuse_threshold == o.cpu_overuse_threshold &&
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000363 cpu_underuse_encode_rsd_threshold ==
364 o.cpu_underuse_encode_rsd_threshold &&
365 cpu_overuse_encode_rsd_threshold ==
366 o.cpu_overuse_encode_rsd_threshold &&
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000367 cpu_overuse_encode_usage == o.cpu_overuse_encode_usage &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 conference_mode == o.conference_mode &&
369 process_adaptation_threshhold == o.process_adaptation_threshhold &&
370 system_low_adaptation_threshhold ==
371 o.system_low_adaptation_threshhold &&
372 system_high_adaptation_threshhold ==
373 o.system_high_adaptation_threshhold &&
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000374 buffered_mode_latency == o.buffered_mode_latency &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000375 lower_min_bitrate == o.lower_min_bitrate &&
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000376 dscp == o.dscp &&
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000377 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000378 unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit &&
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000379 use_simulcast_adapter == o.use_simulcast_adapter &&
380 skip_encoding_unused_streams == o.skip_encoding_unused_streams &&
henrike@webrtc.org5fb74282014-03-26 02:00:10 +0000381 screencast_min_bitrate == o.screencast_min_bitrate &&
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000382 use_improved_wifi_bandwidth_estimator ==
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000383 o.use_improved_wifi_bandwidth_estimator &&
384 use_payload_padding == o.use_payload_padding;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 }
386
387 std::string ToString() const {
388 std::ostringstream ost;
389 ost << "VideoOptions {";
390 ost << ToStringIfSet("encoder adaption", adapt_input_to_encoder);
391 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000392 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 ost << ToStringIfSet("adapt view switch", adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000394 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000396 ost << ToStringIfSet("1 layer screencast", video_one_layer_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 ost << ToStringIfSet("high bitrate", video_high_bitrate);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000398 ost << ToStringIfSet("start bitrate", video_start_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399 ost << ToStringIfSet("video temporal layer screencast",
400 video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000401 ost << ToStringIfSet("video temporal layer realtime",
402 video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 ost << ToStringIfSet("leaky bucket", video_leaky_bucket);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000404 ost << ToStringIfSet("highest video bitrate", video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000405 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000406 ost << ToStringIfSet("cpu underuse threshold", cpu_underuse_threshold);
407 ost << ToStringIfSet("cpu overuse threshold", cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000408 ost << ToStringIfSet("cpu underuse encode rsd threshold",
409 cpu_underuse_encode_rsd_threshold);
410 ost << ToStringIfSet("cpu overuse encode rsd threshold",
411 cpu_overuse_encode_rsd_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000412 ost << ToStringIfSet("cpu overuse encode usage",
413 cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 ost << ToStringIfSet("conference mode", conference_mode);
415 ost << ToStringIfSet("process", process_adaptation_threshhold);
416 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
417 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
418 ost << ToStringIfSet("buffered mode latency", buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000419 ost << ToStringIfSet("lower min bitrate", lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000420 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000421 ost << ToStringIfSet("suspend below min bitrate",
422 suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000423 ost << ToStringIfSet("num channels for early receive",
424 unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000425 ost << ToStringIfSet("use simulcast adapter", use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000426 ost << ToStringIfSet("skip encoding unused streams",
427 skip_encoding_unused_streams);
428 ost << ToStringIfSet("screencast min bitrate", screencast_min_bitrate);
429 ost << ToStringIfSet("improved wifi bwe",
430 use_improved_wifi_bandwidth_estimator);
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000431 ost << ToStringIfSet("payload padding", use_payload_padding);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432 ost << "}";
433 return ost.str();
434 }
435
436 // Encoder adaption, which is the gd callback in LMI, and TBA in WebRTC.
437 Settable<bool> adapt_input_to_encoder;
438 // Enable CPU adaptation?
439 Settable<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000440 // Enable CPU adaptation smoothing?
441 Settable<bool> adapt_cpu_with_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000442 // Enable Adapt View Switch?
443 Settable<bool> adapt_view_switch;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000444 // Enable video adapt third?
445 Settable<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 // Enable denoising?
447 Settable<bool> video_noise_reduction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448 // Experimental: Enable one layer screencast?
449 Settable<bool> video_one_layer_screencast;
450 // Experimental: Enable WebRtc higher bitrate?
451 Settable<bool> video_high_bitrate;
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000452 // Experimental: Enable WebRtc higher start bitrate?
453 Settable<int> video_start_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454 // Experimental: Enable WebRTC layered screencast.
455 Settable<bool> video_temporal_layer_screencast;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000456 // Experimental: Enable WebRTC temporal layer strategy for realtime video.
457 Settable<bool> video_temporal_layer_realtime;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 // Enable WebRTC leaky bucket when sending media packets.
459 Settable<bool> video_leaky_bucket;
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000460 // Set highest bitrate mode for video.
wu@webrtc.orgcfe5e9c2014-03-27 17:03:58 +0000461 Settable<HighestBitrate> video_highest_bitrate;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000462 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
463 // adaptation algorithm. So this option will override the
464 // |adapt_input_to_cpu_usage|.
465 Settable<bool> cpu_overuse_detection;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000466 // Low threshold (t1) for cpu overuse adaptation. (Adapt up)
467 // Metric: encode usage (m1). m1 < t1 => underuse.
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000468 Settable<int> cpu_underuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000469 // High threshold (t1) for cpu overuse adaptation. (Adapt down)
470 // Metric: encode usage (m1). m1 > t1 => overuse.
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000471 Settable<int> cpu_overuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000472 // Low threshold (t2) for cpu overuse adaptation. (Adapt up)
473 // Metric: relative standard deviation of encode time (m2).
474 // Optional threshold. If set, (m1 < t1 && m2 < t2) => underuse.
475 // Note: t2 will have no effect if t1 is not set.
476 Settable<int> cpu_underuse_encode_rsd_threshold;
477 // High threshold (t2) for cpu overuse adaptation. (Adapt down)
478 // Metric: relative standard deviation of encode time (m2).
479 // Optional threshold. If set, (m1 > t1 || m2 > t2) => overuse.
480 // Note: t2 will have no effect if t1 is not set.
481 Settable<int> cpu_overuse_encode_rsd_threshold;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000482 // Use encode usage for cpu detection.
483 Settable<bool> cpu_overuse_encode_usage;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 // Use conference mode?
485 Settable<bool> conference_mode;
486 // Threshhold for process cpu adaptation. (Process limit)
487 SettablePercent process_adaptation_threshhold;
488 // Low threshhold for cpu adaptation. (Adapt up)
489 SettablePercent system_low_adaptation_threshhold;
490 // High threshhold for cpu adaptation. (Adapt down)
491 SettablePercent system_high_adaptation_threshhold;
492 // Specify buffered mode latency in milliseconds.
493 Settable<int> buffered_mode_latency;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000494 // Make minimum configured send bitrate even lower than usual, at 30kbit.
495 Settable<bool> lower_min_bitrate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000496 // Set DSCP value for packet sent from video channel.
497 Settable<bool> dscp;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000498 // Enable WebRTC suspension of video. No video frames will be sent when the
499 // bitrate is below the configured minimum bitrate.
500 Settable<bool> suspend_below_min_bitrate;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000501 // Limit on the number of early receive channels that can be created.
502 Settable<int> unsignalled_recv_stream_limit;
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000503 // Enable use of simulcast adapter.
504 Settable<bool> use_simulcast_adapter;
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000505 // Enables the encoder to skip encoding stream not actually sent due to too
506 // low available bit rate.
507 Settable<bool> skip_encoding_unused_streams;
508 // Force screencast to use a minimum bitrate
509 Settable<int> screencast_min_bitrate;
510 // Enable improved bandwidth estiamtor on wifi.
511 Settable<bool> use_improved_wifi_bandwidth_estimator;
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000512 // Enable payload padding.
513 Settable<bool> use_payload_padding;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514};
515
516// A class for playing out soundclips.
517class SoundclipMedia {
518 public:
519 enum SoundclipFlags {
520 SF_LOOP = 1,
521 };
522
523 virtual ~SoundclipMedia() {}
524
525 // Plays a sound out to the speakers with the given audio stream. The stream
526 // must be 16-bit little-endian 16 kHz PCM. If a stream is already playing
527 // on this SoundclipMedia, it is stopped. If clip is NULL, nothing is played.
528 // Returns whether it was successful.
529 virtual bool PlaySound(const char *clip, int len, int flags) = 0;
530};
531
532struct RtpHeaderExtension {
533 RtpHeaderExtension() : id(0) {}
534 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
535 std::string uri;
536 int id;
537 // TODO(juberti): SendRecv direction;
538
539 bool operator==(const RtpHeaderExtension& ext) const {
540 // id is a reserved word in objective-c. Therefore the id attribute has to
541 // be a fully qualified name in order to compile on IOS.
542 return this->id == ext.id &&
543 uri == ext.uri;
544 }
545};
546
547// Returns the named header extension if found among all extensions, NULL
548// otherwise.
549inline const RtpHeaderExtension* FindHeaderExtension(
550 const std::vector<RtpHeaderExtension>& extensions,
551 const std::string& name) {
552 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
553 it != extensions.end(); ++it) {
554 if (it->uri == name)
555 return &(*it);
556 }
557 return NULL;
558}
559
560enum MediaChannelOptions {
561 // Tune the stream for conference mode.
562 OPT_CONFERENCE = 0x0001
563};
564
565enum VoiceMediaChannelOptions {
566 // Tune the audio stream for vcs with different target levels.
567 OPT_AGC_MINUS_10DB = 0x80000000
568};
569
570// DTMF flags to control if a DTMF tone should be played and/or sent.
571enum DtmfFlags {
572 DF_PLAY = 0x01,
573 DF_SEND = 0x02,
574};
575
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576class MediaChannel : public sigslot::has_slots<> {
577 public:
578 class NetworkInterface {
579 public:
580 enum SocketType { ST_RTP, ST_RTCP };
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000581 virtual bool SendPacket(
582 talk_base::Buffer* packet,
583 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
584 virtual bool SendRtcp(
585 talk_base::Buffer* packet,
586 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587 virtual int SetOption(SocketType type, talk_base::Socket::Option opt,
588 int option) = 0;
589 virtual ~NetworkInterface() {}
590 };
591
592 MediaChannel() : network_interface_(NULL) {}
593 virtual ~MediaChannel() {}
594
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000595 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596 virtual void SetInterface(NetworkInterface *iface) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000597 talk_base::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 network_interface_ = iface;
599 }
600
601 // Called when a RTP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000602 virtual void OnPacketReceived(talk_base::Buffer* packet,
603 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000604 // Called when a RTCP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000605 virtual void OnRtcpReceived(talk_base::Buffer* packet,
606 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607 // Called when the socket's ability to send has changed.
608 virtual void OnReadyToSend(bool ready) = 0;
609 // Creates a new outgoing media stream with SSRCs and CNAME as described
610 // by sp.
611 virtual bool AddSendStream(const StreamParams& sp) = 0;
612 // Removes an outgoing media stream.
613 // ssrc must be the first SSRC of the media stream if the stream uses
614 // multiple SSRCs.
615 virtual bool RemoveSendStream(uint32 ssrc) = 0;
616 // Creates a new incoming media stream with SSRCs and CNAME as described
617 // by sp.
618 virtual bool AddRecvStream(const StreamParams& sp) = 0;
619 // Removes an incoming media stream.
620 // ssrc must be the first SSRC of the media stream if the stream uses
621 // multiple SSRCs.
622 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
623
624 // Mutes the channel.
625 virtual bool MuteStream(uint32 ssrc, bool on) = 0;
626
627 // Sets the RTP extension headers and IDs to use when sending RTP.
628 virtual bool SetRecvRtpHeaderExtensions(
629 const std::vector<RtpHeaderExtension>& extensions) = 0;
630 virtual bool SetSendRtpHeaderExtensions(
631 const std::vector<RtpHeaderExtension>& extensions) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000632 // Returns the absoulte sendtime extension id value from media channel.
633 virtual int GetRtpSendTimeExtnId() const {
634 return -1;
635 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000636 // Sets the initial bandwidth to use when sending starts.
637 virtual bool SetStartSendBandwidth(int bps) = 0;
638 // Sets the maximum allowed bandwidth to use when sending data.
639 virtual bool SetMaxSendBandwidth(int bps) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000641 // Base method to send packet using NetworkInterface.
642 bool SendPacket(talk_base::Buffer* packet) {
643 return DoSendPacket(packet, false);
644 }
645
646 bool SendRtcp(talk_base::Buffer* packet) {
647 return DoSendPacket(packet, true);
648 }
649
650 int SetOption(NetworkInterface::SocketType type,
651 talk_base::Socket::Option opt,
652 int option) {
653 talk_base::CritScope cs(&network_interface_crit_);
654 if (!network_interface_)
655 return -1;
656
657 return network_interface_->SetOption(type, opt, option);
658 }
659
wu@webrtc.orgde305012013-10-31 15:40:38 +0000660 protected:
661 // This method sets DSCP |value| on both RTP and RTCP channels.
662 int SetDscp(talk_base::DiffServCodePoint value) {
663 int ret;
664 ret = SetOption(NetworkInterface::ST_RTP,
665 talk_base::Socket::OPT_DSCP,
666 value);
667 if (ret == 0) {
668 ret = SetOption(NetworkInterface::ST_RTCP,
669 talk_base::Socket::OPT_DSCP,
670 value);
671 }
672 return ret;
673 }
674
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000675 private:
676 bool DoSendPacket(talk_base::Buffer* packet, bool rtcp) {
677 talk_base::CritScope cs(&network_interface_crit_);
678 if (!network_interface_)
679 return false;
680
681 return (!rtcp) ? network_interface_->SendPacket(packet) :
682 network_interface_->SendRtcp(packet);
683 }
684
685 // |network_interface_| can be accessed from the worker_thread and
686 // from any MediaEngine threads. This critical section is to protect accessing
687 // of network_interface_ object.
688 talk_base::CriticalSection network_interface_crit_;
689 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690};
691
692enum SendFlags {
693 SEND_NOTHING,
694 SEND_RINGBACKTONE,
695 SEND_MICROPHONE
696};
697
wu@webrtc.org97077a32013-10-25 21:18:33 +0000698// The stats information is structured as follows:
699// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
700// Media contains a vector of SSRC infos that are exclusively used by this
701// media. (SSRCs shared between media streams can't be represented.)
702
703// Information about an SSRC.
704// This data may be locally recorded, or received in an RTCP SR or RR.
705struct SsrcSenderInfo {
706 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000708 timestamp(0) {
709 }
710 uint32 ssrc;
711 double timestamp; // NTP timestamp, represented as seconds since epoch.
712};
713
714struct SsrcReceiverInfo {
715 SsrcReceiverInfo()
716 : ssrc(0),
717 timestamp(0) {
718 }
719 uint32 ssrc;
720 double timestamp;
721};
722
723struct MediaSenderInfo {
724 MediaSenderInfo()
725 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 packets_sent(0),
727 packets_lost(0),
728 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000729 rtt_ms(0) {
730 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000731 void add_ssrc(const SsrcSenderInfo& stat) {
732 local_stats.push_back(stat);
733 }
734 // Temporary utility function for call sites that only provide SSRC.
735 // As more info is added into SsrcSenderInfo, this function should go away.
736 void add_ssrc(uint32 ssrc) {
737 SsrcSenderInfo stat;
738 stat.ssrc = ssrc;
739 add_ssrc(stat);
740 }
741 // Utility accessor for clients that are only interested in ssrc numbers.
742 std::vector<uint32> ssrcs() const {
743 std::vector<uint32> retval;
744 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
745 it != local_stats.end(); ++it) {
746 retval.push_back(it->ssrc);
747 }
748 return retval;
749 }
750 // Utility accessor for clients that make the assumption only one ssrc
751 // exists per media.
752 // This will eventually go away.
753 uint32 ssrc() const {
754 if (local_stats.size() > 0) {
755 return local_stats[0].ssrc;
756 } else {
757 return 0;
758 }
759 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000760 int64 bytes_sent;
761 int packets_sent;
762 int packets_lost;
763 float fraction_lost;
764 int rtt_ms;
765 std::string codec_name;
766 std::vector<SsrcSenderInfo> local_stats;
767 std::vector<SsrcReceiverInfo> remote_stats;
768};
769
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000770template<class T>
771struct VariableInfo {
772 VariableInfo()
773 : min_val(),
774 mean(0.0),
775 max_val(),
776 variance(0.0) {
777 }
778 T min_val;
779 double mean;
780 T max_val;
781 double variance;
782};
783
wu@webrtc.org97077a32013-10-25 21:18:33 +0000784struct MediaReceiverInfo {
785 MediaReceiverInfo()
786 : bytes_rcvd(0),
787 packets_rcvd(0),
788 packets_lost(0),
789 fraction_lost(0.0) {
790 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000791 void add_ssrc(const SsrcReceiverInfo& stat) {
792 local_stats.push_back(stat);
793 }
794 // Temporary utility function for call sites that only provide SSRC.
795 // As more info is added into SsrcSenderInfo, this function should go away.
796 void add_ssrc(uint32 ssrc) {
797 SsrcReceiverInfo stat;
798 stat.ssrc = ssrc;
799 add_ssrc(stat);
800 }
801 std::vector<uint32> ssrcs() const {
802 std::vector<uint32> retval;
803 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
804 it != local_stats.end(); ++it) {
805 retval.push_back(it->ssrc);
806 }
807 return retval;
808 }
809 // Utility accessor for clients that make the assumption only one ssrc
810 // exists per media.
811 // This will eventually go away.
812 uint32 ssrc() const {
813 if (local_stats.size() > 0) {
814 return local_stats[0].ssrc;
815 } else {
816 return 0;
817 }
818 }
819
wu@webrtc.org97077a32013-10-25 21:18:33 +0000820 int64 bytes_rcvd;
821 int packets_rcvd;
822 int packets_lost;
823 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000824 std::string codec_name;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000825 std::vector<SsrcReceiverInfo> local_stats;
826 std::vector<SsrcSenderInfo> remote_stats;
827};
828
829struct VoiceSenderInfo : public MediaSenderInfo {
830 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000831 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 jitter_ms(0),
833 audio_level(0),
834 aec_quality_min(0.0),
835 echo_delay_median_ms(0),
836 echo_delay_std_ms(0),
837 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000838 echo_return_loss_enhancement(0),
839 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 }
841
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 int jitter_ms;
844 int audio_level;
845 float aec_quality_min;
846 int echo_delay_median_ms;
847 int echo_delay_std_ms;
848 int echo_return_loss;
849 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000850 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851};
852
wu@webrtc.org97077a32013-10-25 21:18:33 +0000853struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000855 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 jitter_ms(0),
857 jitter_buffer_ms(0),
858 jitter_buffer_preferred_ms(0),
859 delay_estimate_ms(0),
860 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000861 expand_rate(0),
862 decoding_calls_to_silence_generator(0),
863 decoding_calls_to_neteq(0),
864 decoding_normal(0),
865 decoding_plc(0),
866 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000867 decoding_plc_cng(0),
868 capture_start_ntp_time_ms(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 }
870
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 int ext_seqnum;
872 int jitter_ms;
873 int jitter_buffer_ms;
874 int jitter_buffer_preferred_ms;
875 int delay_estimate_ms;
876 int audio_level;
877 // fraction of synthesized speech inserted through pre-emptive expansion
878 float expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000879 int decoding_calls_to_silence_generator;
880 int decoding_calls_to_neteq;
881 int decoding_normal;
882 int decoding_plc;
883 int decoding_cng;
884 int decoding_plc_cng;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000885 // Estimated capture start time in NTP time in ms.
886 int64 capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887};
888
wu@webrtc.org97077a32013-10-25 21:18:33 +0000889struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 VideoSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000891 : packets_cached(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000893 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000895 input_frame_width(0),
896 input_frame_height(0),
897 send_frame_width(0),
898 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 framerate_input(0),
900 framerate_sent(0),
901 nominal_bitrate(0),
902 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000903 adapt_reason(0),
904 capture_jitter_ms(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000905 avg_encode_ms(0),
906 encode_usage_percent(0),
buildbot@webrtc.orgc800c1c2014-06-13 07:56:17 +0000907 encode_rsd(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000908 capture_queue_delay_ms_per_s(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 }
910
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000914 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000916 int input_frame_width;
917 int input_frame_height;
918 int send_frame_width;
919 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 int framerate_input;
921 int framerate_sent;
922 int nominal_bitrate;
923 int preferred_bitrate;
924 int adapt_reason;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000925 int capture_jitter_ms;
926 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000927 int encode_usage_percent;
buildbot@webrtc.orgc800c1c2014-06-13 07:56:17 +0000928 int encode_rsd;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000929 int capture_queue_delay_ms_per_s;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000930 VariableInfo<int> adapt_frame_drops;
931 VariableInfo<int> effects_frame_drops;
932 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933};
934
wu@webrtc.org97077a32013-10-25 21:18:33 +0000935struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 VideoReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000937 : packets_concealed(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000939 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 nacks_sent(0),
941 frame_width(0),
942 frame_height(0),
943 framerate_rcvd(0),
944 framerate_decoded(0),
945 framerate_output(0),
946 framerate_render_input(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000947 framerate_render_output(0),
948 decode_ms(0),
949 max_decode_ms(0),
950 jitter_buffer_ms(0),
951 min_playout_delay_ms(0),
952 render_delay_ms(0),
953 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000954 current_delay_ms(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000955 capture_start_ntp_time_ms(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 }
957
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000961 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 int nacks_sent;
963 int frame_width;
964 int frame_height;
965 int framerate_rcvd;
966 int framerate_decoded;
967 int framerate_output;
968 // Framerate as sent to the renderer.
969 int framerate_render_input;
970 // Framerate that the renderer reports.
971 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000972
973 // All stats below are gathered per-VideoReceiver, but some will be correlated
974 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
975 // structures, reflect this in the new layout.
976
977 // Current frame decode latency.
978 int decode_ms;
979 // Maximum observed frame decode latency.
980 int max_decode_ms;
981 // Jitter (network-related) latency.
982 int jitter_buffer_ms;
983 // Requested minimum playout latency.
984 int min_playout_delay_ms;
985 // Requested latency to account for rendering delay.
986 int render_delay_ms;
987 // Target overall delay: network+decode+render, accounting for
988 // min_playout_delay_ms.
989 int target_delay_ms;
990 // Current overall delay, possibly ramping towards target_delay_ms.
991 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000992
993 // Estimated capture start time in NTP time in ms.
994 int64 capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995};
996
wu@webrtc.org97077a32013-10-25 21:18:33 +0000997struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000999 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 }
1001
1002 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003};
1004
wu@webrtc.org97077a32013-10-25 21:18:33 +00001005struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +00001007 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 }
1009
1010 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011};
1012
1013struct BandwidthEstimationInfo {
1014 BandwidthEstimationInfo()
1015 : available_send_bandwidth(0),
1016 available_recv_bandwidth(0),
1017 target_enc_bitrate(0),
1018 actual_enc_bitrate(0),
1019 retransmit_bitrate(0),
1020 transmit_bitrate(0),
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001021 bucket_delay(0),
1022 total_received_propagation_delta_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001023 }
1024
1025 int available_send_bandwidth;
1026 int available_recv_bandwidth;
1027 int target_enc_bitrate;
1028 int actual_enc_bitrate;
1029 int retransmit_bitrate;
1030 int transmit_bitrate;
1031 int bucket_delay;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001032 // The following stats are only valid when
1033 // StatsOptions::include_received_propagation_stats is true.
1034 int total_received_propagation_delta_ms;
1035 std::vector<int> recent_received_propagation_delta_ms;
1036 std::vector<int64> recent_received_packet_group_arrival_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001037};
1038
1039struct VoiceMediaInfo {
1040 void Clear() {
1041 senders.clear();
1042 receivers.clear();
1043 }
1044 std::vector<VoiceSenderInfo> senders;
1045 std::vector<VoiceReceiverInfo> receivers;
1046};
1047
1048struct VideoMediaInfo {
1049 void Clear() {
1050 senders.clear();
1051 receivers.clear();
1052 bw_estimations.clear();
1053 }
1054 std::vector<VideoSenderInfo> senders;
1055 std::vector<VideoReceiverInfo> receivers;
1056 std::vector<BandwidthEstimationInfo> bw_estimations;
1057};
1058
1059struct DataMediaInfo {
1060 void Clear() {
1061 senders.clear();
1062 receivers.clear();
1063 }
1064 std::vector<DataSenderInfo> senders;
1065 std::vector<DataReceiverInfo> receivers;
1066};
1067
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001068struct StatsOptions {
1069 StatsOptions() : include_received_propagation_stats(false) {}
1070
1071 bool include_received_propagation_stats;
1072};
1073
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074class VoiceMediaChannel : public MediaChannel {
1075 public:
1076 enum Error {
1077 ERROR_NONE = 0, // No error.
1078 ERROR_OTHER, // Other errors.
1079 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
1080 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
1081 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
1082 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
1083 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
1084 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
1085 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
1086 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1087 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
1088 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
1089 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
1090 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
1091 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
1092 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
1093 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1094 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1095 };
1096
1097 VoiceMediaChannel() {}
1098 virtual ~VoiceMediaChannel() {}
1099 // Sets the codecs/payload types to be used for incoming media.
1100 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
1101 // Sets the codecs/payload types to be used for outgoing media.
1102 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
1103 // Starts or stops playout of received audio.
1104 virtual bool SetPlayout(bool playout) = 0;
1105 // Starts or stops sending (and potentially capture) of local audio.
1106 virtual bool SetSend(SendFlags flag) = 0;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001107 // Sets the renderer object to be used for the specified remote audio stream.
1108 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
1109 // Sets the renderer object to be used for the specified local audio stream.
1110 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 // Gets current energy levels for all incoming streams.
1112 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1113 // Get the current energy level of the stream sent to the speaker.
1114 virtual int GetOutputLevel() = 0;
1115 // Get the time in milliseconds since last recorded keystroke, or negative.
1116 virtual int GetTimeSinceLastTyping() = 0;
1117 // Temporarily exposed field for tuning typing detect options.
1118 virtual void SetTypingDetectionParameters(int time_window,
1119 int cost_per_typing, int reporting_threshold, int penalty_decay,
1120 int type_event_delay) = 0;
1121 // Set left and right scale for speaker output volume of the specified ssrc.
1122 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
1123 // Get left and right scale for speaker output volume of the specified ssrc.
1124 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0;
1125 // Specifies a ringback tone to be played during call setup.
1126 virtual bool SetRingbackTone(const char *buf, int len) = 0;
1127 // Plays or stops the aforementioned ringback tone
1128 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
1129 // Returns if the telephone-event has been negotiated.
1130 virtual bool CanInsertDtmf() { return false; }
1131 // Send and/or play a DTMF |event| according to the |flags|.
1132 // The DTMF out-of-band signal will be used on sending.
1133 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001134 // The valid value for the |event| are 0 to 15 which corresponding to
1135 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
1137 // Gets quality stats for the channel.
1138 virtual bool GetStats(VoiceMediaInfo* info) = 0;
1139 // Gets last reported error for this media channel.
1140 virtual void GetLastMediaError(uint32* ssrc,
1141 VoiceMediaChannel::Error* error) {
1142 ASSERT(error != NULL);
1143 *error = ERROR_NONE;
1144 }
1145 // Sets the media options to use.
1146 virtual bool SetOptions(const AudioOptions& options) = 0;
1147 virtual bool GetOptions(AudioOptions* options) const = 0;
1148
1149 // Signal errors from MediaChannel. Arguments are:
1150 // ssrc(uint32), and error(VoiceMediaChannel::Error).
1151 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
1152};
1153
1154class VideoMediaChannel : public MediaChannel {
1155 public:
1156 enum Error {
1157 ERROR_NONE = 0, // No error.
1158 ERROR_OTHER, // Other errors.
1159 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1160 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1161 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1162 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1163 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1164 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1165 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1166 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1167 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1168 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1169 };
1170
1171 VideoMediaChannel() : renderer_(NULL) {}
1172 virtual ~VideoMediaChannel() {}
1173 // Sets the codecs/payload types to be used for incoming media.
1174 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
1175 // Sets the codecs/payload types to be used for outgoing media.
1176 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
1177 // Gets the currently set codecs/payload types to be used for outgoing media.
1178 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1179 // Sets the format of a specified outgoing stream.
1180 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
1181 // Starts or stops playout of received video.
1182 virtual bool SetRender(bool render) = 0;
1183 // Starts or stops transmission (and potentially capture) of local video.
1184 virtual bool SetSend(bool send) = 0;
1185 // Sets the renderer object to be used for the specified stream.
1186 // If SSRC is 0, the renderer is used for the 'default' stream.
1187 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
1188 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1189 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
1190 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
1191 // Gets quality stats for the channel.
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001192 virtual bool GetStats(const StatsOptions& options, VideoMediaInfo* info) = 0;
1193 // This is needed for MediaMonitor to use the same template for voice, video
1194 // and data MediaChannels.
1195 bool GetStats(VideoMediaInfo* info) {
1196 return GetStats(StatsOptions(), info);
1197 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001198
1199 // Send an intra frame to the receivers.
1200 virtual bool SendIntraFrame() = 0;
1201 // Reuqest each of the remote senders to send an intra frame.
1202 virtual bool RequestIntraFrame() = 0;
1203 // Sets the media options to use.
1204 virtual bool SetOptions(const VideoOptions& options) = 0;
1205 virtual bool GetOptions(VideoOptions* options) const = 0;
1206 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1207
1208 // Signal errors from MediaChannel. Arguments are:
1209 // ssrc(uint32), and error(VideoMediaChannel::Error).
1210 sigslot::signal2<uint32, Error> SignalMediaError;
1211
1212 protected:
1213 VideoRenderer *renderer_;
1214};
1215
1216enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001217 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1218 // values.
1219 DMT_NONE = 0,
1220 DMT_CONTROL = 1,
1221 DMT_BINARY = 2,
1222 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001223};
1224
1225// Info about data received in DataMediaChannel. For use in
1226// DataMediaChannel::SignalDataReceived and in all of the signals that
1227// signal fires, on up the chain.
1228struct ReceiveDataParams {
1229 // The in-packet stream indentifier.
1230 // For SCTP, this is really SID, not SSRC.
1231 uint32 ssrc;
1232 // The type of message (binary, text, or control).
1233 DataMessageType type;
1234 // A per-stream value incremented per packet in the stream.
1235 int seq_num;
1236 // A per-stream value monotonically increasing with time.
1237 int timestamp;
1238
1239 ReceiveDataParams() :
1240 ssrc(0),
1241 type(DMT_TEXT),
1242 seq_num(0),
1243 timestamp(0) {
1244 }
1245};
1246
1247struct SendDataParams {
1248 // The in-packet stream indentifier.
1249 // For SCTP, this is really SID, not SSRC.
1250 uint32 ssrc;
1251 // The type of message (binary, text, or control).
1252 DataMessageType type;
1253
1254 // For SCTP, whether to send messages flagged as ordered or not.
1255 // If false, messages can be received out of order.
1256 bool ordered;
1257 // For SCTP, whether the messages are sent reliably or not.
1258 // If false, messages may be lost.
1259 bool reliable;
1260 // For SCTP, if reliable == false, provide partial reliability by
1261 // resending up to this many times. Either count or millis
1262 // is supported, not both at the same time.
1263 int max_rtx_count;
1264 // For SCTP, if reliable == false, provide partial reliability by
1265 // resending for up to this many milliseconds. Either count or millis
1266 // is supported, not both at the same time.
1267 int max_rtx_ms;
1268
1269 SendDataParams() :
1270 ssrc(0),
1271 type(DMT_TEXT),
1272 // TODO(pthatcher): Make these true by default?
1273 ordered(false),
1274 reliable(false),
1275 max_rtx_count(0),
1276 max_rtx_ms(0) {
1277 }
1278};
1279
1280enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1281
1282class DataMediaChannel : public MediaChannel {
1283 public:
1284 enum Error {
1285 ERROR_NONE = 0, // No error.
1286 ERROR_OTHER, // Other errors.
1287 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1288 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1289 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1290 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1291 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1292 };
1293
1294 virtual ~DataMediaChannel() {}
1295
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
1297 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001298
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
1300 // TODO(pthatcher): Implement this.
1301 virtual bool GetStats(DataMediaInfo* info) { return true; }
1302
1303 virtual bool SetSend(bool send) = 0;
1304 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305
1306 virtual bool SendData(
1307 const SendDataParams& params,
1308 const talk_base::Buffer& payload,
1309 SendDataResult* result = NULL) = 0;
1310 // Signals when data is received (params, data, len)
1311 sigslot::signal3<const ReceiveDataParams&,
1312 const char*,
1313 size_t> SignalDataReceived;
1314 // Signal errors from MediaChannel. Arguments are:
1315 // ssrc(uint32), and error(DataMediaChannel::Error).
1316 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001317 // Signal when the media channel is ready to send the stream. Arguments are:
1318 // writable(bool)
1319 sigslot::signal1<bool> SignalReadyToSend;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001320 // Signal for notifying that the remote side has closed the DataChannel.
1321 sigslot::signal1<uint32> SignalStreamClosedRemotely;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322};
1323
1324} // namespace cricket
1325
1326#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_