blob: 2d65daf593dcb8baef19058362274ba25682af91 [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);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 }
186
187 bool operator==(const AudioOptions& o) const {
188 return echo_cancellation == o.echo_cancellation &&
189 auto_gain_control == o.auto_gain_control &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000190 rx_auto_gain_control == o.rx_auto_gain_control &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 noise_suppression == o.noise_suppression &&
192 highpass_filter == o.highpass_filter &&
193 stereo_swapping == o.stereo_swapping &&
194 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000195 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 conference_mode == o.conference_mode &&
197 experimental_agc == o.experimental_agc &&
198 experimental_aec == o.experimental_aec &&
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000199 experimental_ns == o.experimental_ns &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000201 aec_dump == o.aec_dump &&
202 tx_agc_target_dbov == o.tx_agc_target_dbov &&
203 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
204 tx_agc_limiter == o.tx_agc_limiter &&
205 rx_agc_target_dbov == o.rx_agc_target_dbov &&
206 rx_agc_digital_compression_gain == o.rx_agc_digital_compression_gain &&
207 rx_agc_limiter == o.rx_agc_limiter &&
208 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000209 playout_sample_rate == o.playout_sample_rate &&
210 dscp == o.dscp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 }
212
213 std::string ToString() const {
214 std::ostringstream ost;
215 ost << "AudioOptions {";
216 ost << ToStringIfSet("aec", echo_cancellation);
217 ost << ToStringIfSet("agc", auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000218 ost << ToStringIfSet("rx_agc", rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 ost << ToStringIfSet("ns", noise_suppression);
220 ost << ToStringIfSet("hf", highpass_filter);
221 ost << ToStringIfSet("swap", stereo_swapping);
222 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000223 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 ost << ToStringIfSet("conference", conference_mode);
225 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
226 ost << ToStringIfSet("experimental_agc", experimental_agc);
227 ost << ToStringIfSet("experimental_aec", experimental_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000228 ost << ToStringIfSet("experimental_ns", experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 ost << ToStringIfSet("aec_dump", aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000230 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
231 ost << ToStringIfSet("tx_agc_digital_compression_gain",
232 tx_agc_digital_compression_gain);
233 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
234 ost << ToStringIfSet("rx_agc_target_dbov", rx_agc_target_dbov);
235 ost << ToStringIfSet("rx_agc_digital_compression_gain",
236 rx_agc_digital_compression_gain);
237 ost << ToStringIfSet("rx_agc_limiter", rx_agc_limiter);
238 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
239 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000240 ost << ToStringIfSet("dscp", dscp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 ost << "}";
242 return ost.str();
243 }
244
245 // Audio processing that attempts to filter away the output signal from
246 // later inbound pickup.
247 Settable<bool> echo_cancellation;
248 // Audio processing to adjust the sensitivity of the local mic dynamically.
249 Settable<bool> auto_gain_control;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000250 // Audio processing to apply gain to the remote audio.
251 Settable<bool> rx_auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 // Audio processing to filter out background noise.
253 Settable<bool> noise_suppression;
254 // Audio processing to remove background noise of lower frequencies.
255 Settable<bool> highpass_filter;
256 // Audio processing to swap the left and right channels.
257 Settable<bool> stereo_swapping;
258 // Audio processing to detect typing.
259 Settable<bool> typing_detection;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000260 Settable<bool> aecm_generate_comfort_noise;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 Settable<bool> conference_mode;
262 Settable<int> adjust_agc_delta;
263 Settable<bool> experimental_agc;
264 Settable<bool> experimental_aec;
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000265 Settable<bool> experimental_ns;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000266 Settable<bool> aec_dump;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000267 // Note that tx_agc_* only applies to non-experimental AGC.
268 Settable<uint16> tx_agc_target_dbov;
269 Settable<uint16> tx_agc_digital_compression_gain;
270 Settable<bool> tx_agc_limiter;
271 Settable<uint16> rx_agc_target_dbov;
272 Settable<uint16> rx_agc_digital_compression_gain;
273 Settable<bool> rx_agc_limiter;
274 Settable<uint32> recording_sample_rate;
275 Settable<uint32> playout_sample_rate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000276 // Set DSCP value for packet sent from audio channel.
277 Settable<bool> dscp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278};
279
280// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
281// Used to be flags, but that makes it hard to selectively apply options.
282// We are moving all of the setting of options to structs like this,
283// but some things currently still use flags.
284struct VideoOptions {
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000285 enum HighestBitrate {
286 NORMAL,
287 HIGH,
288 VERY_HIGH
289 };
290
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291 VideoOptions() {
292 process_adaptation_threshhold.Set(kProcessCpuThreshold);
293 system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold);
294 system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000295 unsignalled_recv_stream_limit.Set(kNumDefaultUnsignalledVideoRecvStreams);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296 }
297
298 void SetAll(const VideoOptions& change) {
299 adapt_input_to_encoder.SetFrom(change.adapt_input_to_encoder);
300 adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000301 adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 adapt_view_switch.SetFrom(change.adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000303 video_adapt_third.SetFrom(change.video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 video_noise_reduction.SetFrom(change.video_noise_reduction);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 video_one_layer_screencast.SetFrom(change.video_one_layer_screencast);
306 video_high_bitrate.SetFrom(change.video_high_bitrate);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000307 video_start_bitrate.SetFrom(change.video_start_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 video_temporal_layer_screencast.SetFrom(
309 change.video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000310 video_temporal_layer_realtime.SetFrom(
311 change.video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 video_leaky_bucket.SetFrom(change.video_leaky_bucket);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000313 video_highest_bitrate.SetFrom(change.video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000314 cpu_overuse_detection.SetFrom(change.cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000315 cpu_underuse_threshold.SetFrom(change.cpu_underuse_threshold);
316 cpu_overuse_threshold.SetFrom(change.cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000317 cpu_underuse_encode_rsd_threshold.SetFrom(
318 change.cpu_underuse_encode_rsd_threshold);
319 cpu_overuse_encode_rsd_threshold.SetFrom(
320 change.cpu_overuse_encode_rsd_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000321 cpu_overuse_encode_usage.SetFrom(change.cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 conference_mode.SetFrom(change.conference_mode);
323 process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
324 system_low_adaptation_threshhold.SetFrom(
325 change.system_low_adaptation_threshhold);
326 system_high_adaptation_threshhold.SetFrom(
327 change.system_high_adaptation_threshhold);
328 buffered_mode_latency.SetFrom(change.buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000329 lower_min_bitrate.SetFrom(change.lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000330 dscp.SetFrom(change.dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000331 suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000332 unsignalled_recv_stream_limit.SetFrom(change.unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000333 use_simulcast_adapter.SetFrom(change.use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000334 skip_encoding_unused_streams.SetFrom(change.skip_encoding_unused_streams);
335 screencast_min_bitrate.SetFrom(change.screencast_min_bitrate);
336 use_improved_wifi_bandwidth_estimator.SetFrom(
337 change.use_improved_wifi_bandwidth_estimator);
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000338 use_payload_padding.SetFrom(change.use_payload_padding);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 }
340
341 bool operator==(const VideoOptions& o) const {
342 return adapt_input_to_encoder == o.adapt_input_to_encoder &&
343 adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000344 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 adapt_view_switch == o.adapt_view_switch &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000346 video_adapt_third == o.video_adapt_third &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 video_noise_reduction == o.video_noise_reduction &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 video_one_layer_screencast == o.video_one_layer_screencast &&
349 video_high_bitrate == o.video_high_bitrate &&
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000350 video_start_bitrate == o.video_start_bitrate &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 video_temporal_layer_screencast == o.video_temporal_layer_screencast &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000352 video_temporal_layer_realtime == o.video_temporal_layer_realtime &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 video_leaky_bucket == o.video_leaky_bucket &&
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000354 video_highest_bitrate == o.video_highest_bitrate &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000355 cpu_overuse_detection == o.cpu_overuse_detection &&
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000356 cpu_underuse_threshold == o.cpu_underuse_threshold &&
357 cpu_overuse_threshold == o.cpu_overuse_threshold &&
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000358 cpu_underuse_encode_rsd_threshold ==
359 o.cpu_underuse_encode_rsd_threshold &&
360 cpu_overuse_encode_rsd_threshold ==
361 o.cpu_overuse_encode_rsd_threshold &&
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000362 cpu_overuse_encode_usage == o.cpu_overuse_encode_usage &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 conference_mode == o.conference_mode &&
364 process_adaptation_threshhold == o.process_adaptation_threshhold &&
365 system_low_adaptation_threshhold ==
366 o.system_low_adaptation_threshhold &&
367 system_high_adaptation_threshhold ==
368 o.system_high_adaptation_threshhold &&
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000369 buffered_mode_latency == o.buffered_mode_latency &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000370 lower_min_bitrate == o.lower_min_bitrate &&
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000371 dscp == o.dscp &&
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000372 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000373 unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit &&
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000374 use_simulcast_adapter == o.use_simulcast_adapter &&
375 skip_encoding_unused_streams == o.skip_encoding_unused_streams &&
henrike@webrtc.org5fb74282014-03-26 02:00:10 +0000376 screencast_min_bitrate == o.screencast_min_bitrate &&
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000377 use_improved_wifi_bandwidth_estimator ==
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000378 o.use_improved_wifi_bandwidth_estimator &&
379 use_payload_padding == o.use_payload_padding;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 }
381
382 std::string ToString() const {
383 std::ostringstream ost;
384 ost << "VideoOptions {";
385 ost << ToStringIfSet("encoder adaption", adapt_input_to_encoder);
386 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000387 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 ost << ToStringIfSet("adapt view switch", adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000389 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000391 ost << ToStringIfSet("1 layer screencast", video_one_layer_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 ost << ToStringIfSet("high bitrate", video_high_bitrate);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000393 ost << ToStringIfSet("start bitrate", video_start_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394 ost << ToStringIfSet("video temporal layer screencast",
395 video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000396 ost << ToStringIfSet("video temporal layer realtime",
397 video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398 ost << ToStringIfSet("leaky bucket", video_leaky_bucket);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000399 ost << ToStringIfSet("highest video bitrate", video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000400 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000401 ost << ToStringIfSet("cpu underuse threshold", cpu_underuse_threshold);
402 ost << ToStringIfSet("cpu overuse threshold", cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000403 ost << ToStringIfSet("cpu underuse encode rsd threshold",
404 cpu_underuse_encode_rsd_threshold);
405 ost << ToStringIfSet("cpu overuse encode rsd threshold",
406 cpu_overuse_encode_rsd_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000407 ost << ToStringIfSet("cpu overuse encode usage",
408 cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000409 ost << ToStringIfSet("conference mode", conference_mode);
410 ost << ToStringIfSet("process", process_adaptation_threshhold);
411 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
412 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
413 ost << ToStringIfSet("buffered mode latency", buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000414 ost << ToStringIfSet("lower min bitrate", lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000415 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000416 ost << ToStringIfSet("suspend below min bitrate",
417 suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000418 ost << ToStringIfSet("num channels for early receive",
419 unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000420 ost << ToStringIfSet("use simulcast adapter", use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000421 ost << ToStringIfSet("skip encoding unused streams",
422 skip_encoding_unused_streams);
423 ost << ToStringIfSet("screencast min bitrate", screencast_min_bitrate);
424 ost << ToStringIfSet("improved wifi bwe",
425 use_improved_wifi_bandwidth_estimator);
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000426 ost << ToStringIfSet("payload padding", use_payload_padding);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427 ost << "}";
428 return ost.str();
429 }
430
431 // Encoder adaption, which is the gd callback in LMI, and TBA in WebRTC.
432 Settable<bool> adapt_input_to_encoder;
433 // Enable CPU adaptation?
434 Settable<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000435 // Enable CPU adaptation smoothing?
436 Settable<bool> adapt_cpu_with_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437 // Enable Adapt View Switch?
438 Settable<bool> adapt_view_switch;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000439 // Enable video adapt third?
440 Settable<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 // Enable denoising?
442 Settable<bool> video_noise_reduction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443 // Experimental: Enable one layer screencast?
444 Settable<bool> video_one_layer_screencast;
445 // Experimental: Enable WebRtc higher bitrate?
446 Settable<bool> video_high_bitrate;
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000447 // Experimental: Enable WebRtc higher start bitrate?
448 Settable<int> video_start_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 // Experimental: Enable WebRTC layered screencast.
450 Settable<bool> video_temporal_layer_screencast;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000451 // Experimental: Enable WebRTC temporal layer strategy for realtime video.
452 Settable<bool> video_temporal_layer_realtime;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 // Enable WebRTC leaky bucket when sending media packets.
454 Settable<bool> video_leaky_bucket;
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000455 // Set highest bitrate mode for video.
wu@webrtc.orgcfe5e9c2014-03-27 17:03:58 +0000456 Settable<HighestBitrate> video_highest_bitrate;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000457 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
458 // adaptation algorithm. So this option will override the
459 // |adapt_input_to_cpu_usage|.
460 Settable<bool> cpu_overuse_detection;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000461 // Low threshold (t1) for cpu overuse adaptation. (Adapt up)
462 // Metric: encode usage (m1). m1 < t1 => underuse.
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000463 Settable<int> cpu_underuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000464 // High threshold (t1) for cpu overuse adaptation. (Adapt down)
465 // Metric: encode usage (m1). m1 > t1 => overuse.
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000466 Settable<int> cpu_overuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000467 // Low threshold (t2) for cpu overuse adaptation. (Adapt up)
468 // Metric: relative standard deviation of encode time (m2).
469 // Optional threshold. If set, (m1 < t1 && m2 < t2) => underuse.
470 // Note: t2 will have no effect if t1 is not set.
471 Settable<int> cpu_underuse_encode_rsd_threshold;
472 // High threshold (t2) for cpu overuse adaptation. (Adapt down)
473 // Metric: relative standard deviation of encode time (m2).
474 // Optional threshold. If set, (m1 > t1 || m2 > t2) => overuse.
475 // Note: t2 will have no effect if t1 is not set.
476 Settable<int> cpu_overuse_encode_rsd_threshold;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000477 // Use encode usage for cpu detection.
478 Settable<bool> cpu_overuse_encode_usage;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 // Use conference mode?
480 Settable<bool> conference_mode;
481 // Threshhold for process cpu adaptation. (Process limit)
482 SettablePercent process_adaptation_threshhold;
483 // Low threshhold for cpu adaptation. (Adapt up)
484 SettablePercent system_low_adaptation_threshhold;
485 // High threshhold for cpu adaptation. (Adapt down)
486 SettablePercent system_high_adaptation_threshhold;
487 // Specify buffered mode latency in milliseconds.
488 Settable<int> buffered_mode_latency;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000489 // Make minimum configured send bitrate even lower than usual, at 30kbit.
490 Settable<bool> lower_min_bitrate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000491 // Set DSCP value for packet sent from video channel.
492 Settable<bool> dscp;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000493 // Enable WebRTC suspension of video. No video frames will be sent when the
494 // bitrate is below the configured minimum bitrate.
495 Settable<bool> suspend_below_min_bitrate;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000496 // Limit on the number of early receive channels that can be created.
497 Settable<int> unsignalled_recv_stream_limit;
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000498 // Enable use of simulcast adapter.
499 Settable<bool> use_simulcast_adapter;
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000500 // Enables the encoder to skip encoding stream not actually sent due to too
501 // low available bit rate.
502 Settable<bool> skip_encoding_unused_streams;
503 // Force screencast to use a minimum bitrate
504 Settable<int> screencast_min_bitrate;
505 // Enable improved bandwidth estiamtor on wifi.
506 Settable<bool> use_improved_wifi_bandwidth_estimator;
buildbot@webrtc.org44a317a2014-06-17 07:49:15 +0000507 // Enable payload padding.
508 Settable<bool> use_payload_padding;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509};
510
511// A class for playing out soundclips.
512class SoundclipMedia {
513 public:
514 enum SoundclipFlags {
515 SF_LOOP = 1,
516 };
517
518 virtual ~SoundclipMedia() {}
519
520 // Plays a sound out to the speakers with the given audio stream. The stream
521 // must be 16-bit little-endian 16 kHz PCM. If a stream is already playing
522 // on this SoundclipMedia, it is stopped. If clip is NULL, nothing is played.
523 // Returns whether it was successful.
524 virtual bool PlaySound(const char *clip, int len, int flags) = 0;
525};
526
527struct RtpHeaderExtension {
528 RtpHeaderExtension() : id(0) {}
529 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
530 std::string uri;
531 int id;
532 // TODO(juberti): SendRecv direction;
533
534 bool operator==(const RtpHeaderExtension& ext) const {
535 // id is a reserved word in objective-c. Therefore the id attribute has to
536 // be a fully qualified name in order to compile on IOS.
537 return this->id == ext.id &&
538 uri == ext.uri;
539 }
540};
541
542// Returns the named header extension if found among all extensions, NULL
543// otherwise.
544inline const RtpHeaderExtension* FindHeaderExtension(
545 const std::vector<RtpHeaderExtension>& extensions,
546 const std::string& name) {
547 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
548 it != extensions.end(); ++it) {
549 if (it->uri == name)
550 return &(*it);
551 }
552 return NULL;
553}
554
555enum MediaChannelOptions {
556 // Tune the stream for conference mode.
557 OPT_CONFERENCE = 0x0001
558};
559
560enum VoiceMediaChannelOptions {
561 // Tune the audio stream for vcs with different target levels.
562 OPT_AGC_MINUS_10DB = 0x80000000
563};
564
565// DTMF flags to control if a DTMF tone should be played and/or sent.
566enum DtmfFlags {
567 DF_PLAY = 0x01,
568 DF_SEND = 0x02,
569};
570
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571class MediaChannel : public sigslot::has_slots<> {
572 public:
573 class NetworkInterface {
574 public:
575 enum SocketType { ST_RTP, ST_RTCP };
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000576 virtual bool SendPacket(
577 talk_base::Buffer* packet,
578 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
579 virtual bool SendRtcp(
580 talk_base::Buffer* packet,
581 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 virtual int SetOption(SocketType type, talk_base::Socket::Option opt,
583 int option) = 0;
584 virtual ~NetworkInterface() {}
585 };
586
587 MediaChannel() : network_interface_(NULL) {}
588 virtual ~MediaChannel() {}
589
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000590 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 virtual void SetInterface(NetworkInterface *iface) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000592 talk_base::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 network_interface_ = iface;
594 }
595
596 // Called when a RTP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000597 virtual void OnPacketReceived(talk_base::Buffer* packet,
598 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599 // Called when a RTCP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000600 virtual void OnRtcpReceived(talk_base::Buffer* packet,
601 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602 // Called when the socket's ability to send has changed.
603 virtual void OnReadyToSend(bool ready) = 0;
604 // Creates a new outgoing media stream with SSRCs and CNAME as described
605 // by sp.
606 virtual bool AddSendStream(const StreamParams& sp) = 0;
607 // Removes an outgoing media stream.
608 // ssrc must be the first SSRC of the media stream if the stream uses
609 // multiple SSRCs.
610 virtual bool RemoveSendStream(uint32 ssrc) = 0;
611 // Creates a new incoming media stream with SSRCs and CNAME as described
612 // by sp.
613 virtual bool AddRecvStream(const StreamParams& sp) = 0;
614 // Removes an incoming media stream.
615 // ssrc must be the first SSRC of the media stream if the stream uses
616 // multiple SSRCs.
617 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
618
619 // Mutes the channel.
620 virtual bool MuteStream(uint32 ssrc, bool on) = 0;
621
622 // Sets the RTP extension headers and IDs to use when sending RTP.
623 virtual bool SetRecvRtpHeaderExtensions(
624 const std::vector<RtpHeaderExtension>& extensions) = 0;
625 virtual bool SetSendRtpHeaderExtensions(
626 const std::vector<RtpHeaderExtension>& extensions) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000627 // Returns the absoulte sendtime extension id value from media channel.
628 virtual int GetRtpSendTimeExtnId() const {
629 return -1;
630 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000631 // Sets the initial bandwidth to use when sending starts.
632 virtual bool SetStartSendBandwidth(int bps) = 0;
633 // Sets the maximum allowed bandwidth to use when sending data.
634 virtual bool SetMaxSendBandwidth(int bps) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000635
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000636 // Base method to send packet using NetworkInterface.
637 bool SendPacket(talk_base::Buffer* packet) {
638 return DoSendPacket(packet, false);
639 }
640
641 bool SendRtcp(talk_base::Buffer* packet) {
642 return DoSendPacket(packet, true);
643 }
644
645 int SetOption(NetworkInterface::SocketType type,
646 talk_base::Socket::Option opt,
647 int option) {
648 talk_base::CritScope cs(&network_interface_crit_);
649 if (!network_interface_)
650 return -1;
651
652 return network_interface_->SetOption(type, opt, option);
653 }
654
wu@webrtc.orgde305012013-10-31 15:40:38 +0000655 protected:
656 // This method sets DSCP |value| on both RTP and RTCP channels.
657 int SetDscp(talk_base::DiffServCodePoint value) {
658 int ret;
659 ret = SetOption(NetworkInterface::ST_RTP,
660 talk_base::Socket::OPT_DSCP,
661 value);
662 if (ret == 0) {
663 ret = SetOption(NetworkInterface::ST_RTCP,
664 talk_base::Socket::OPT_DSCP,
665 value);
666 }
667 return ret;
668 }
669
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000670 private:
671 bool DoSendPacket(talk_base::Buffer* packet, bool rtcp) {
672 talk_base::CritScope cs(&network_interface_crit_);
673 if (!network_interface_)
674 return false;
675
676 return (!rtcp) ? network_interface_->SendPacket(packet) :
677 network_interface_->SendRtcp(packet);
678 }
679
680 // |network_interface_| can be accessed from the worker_thread and
681 // from any MediaEngine threads. This critical section is to protect accessing
682 // of network_interface_ object.
683 talk_base::CriticalSection network_interface_crit_;
684 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685};
686
687enum SendFlags {
688 SEND_NOTHING,
689 SEND_RINGBACKTONE,
690 SEND_MICROPHONE
691};
692
wu@webrtc.org97077a32013-10-25 21:18:33 +0000693// The stats information is structured as follows:
694// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
695// Media contains a vector of SSRC infos that are exclusively used by this
696// media. (SSRCs shared between media streams can't be represented.)
697
698// Information about an SSRC.
699// This data may be locally recorded, or received in an RTCP SR or RR.
700struct SsrcSenderInfo {
701 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000703 timestamp(0) {
704 }
705 uint32 ssrc;
706 double timestamp; // NTP timestamp, represented as seconds since epoch.
707};
708
709struct SsrcReceiverInfo {
710 SsrcReceiverInfo()
711 : ssrc(0),
712 timestamp(0) {
713 }
714 uint32 ssrc;
715 double timestamp;
716};
717
718struct MediaSenderInfo {
719 MediaSenderInfo()
720 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 packets_sent(0),
722 packets_lost(0),
723 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000724 rtt_ms(0) {
725 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000726 void add_ssrc(const SsrcSenderInfo& stat) {
727 local_stats.push_back(stat);
728 }
729 // Temporary utility function for call sites that only provide SSRC.
730 // As more info is added into SsrcSenderInfo, this function should go away.
731 void add_ssrc(uint32 ssrc) {
732 SsrcSenderInfo stat;
733 stat.ssrc = ssrc;
734 add_ssrc(stat);
735 }
736 // Utility accessor for clients that are only interested in ssrc numbers.
737 std::vector<uint32> ssrcs() const {
738 std::vector<uint32> retval;
739 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
740 it != local_stats.end(); ++it) {
741 retval.push_back(it->ssrc);
742 }
743 return retval;
744 }
745 // Utility accessor for clients that make the assumption only one ssrc
746 // exists per media.
747 // This will eventually go away.
748 uint32 ssrc() const {
749 if (local_stats.size() > 0) {
750 return local_stats[0].ssrc;
751 } else {
752 return 0;
753 }
754 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000755 int64 bytes_sent;
756 int packets_sent;
757 int packets_lost;
758 float fraction_lost;
759 int rtt_ms;
760 std::string codec_name;
761 std::vector<SsrcSenderInfo> local_stats;
762 std::vector<SsrcReceiverInfo> remote_stats;
763};
764
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000765template<class T>
766struct VariableInfo {
767 VariableInfo()
768 : min_val(),
769 mean(0.0),
770 max_val(),
771 variance(0.0) {
772 }
773 T min_val;
774 double mean;
775 T max_val;
776 double variance;
777};
778
wu@webrtc.org97077a32013-10-25 21:18:33 +0000779struct MediaReceiverInfo {
780 MediaReceiverInfo()
781 : bytes_rcvd(0),
782 packets_rcvd(0),
783 packets_lost(0),
784 fraction_lost(0.0) {
785 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000786 void add_ssrc(const SsrcReceiverInfo& stat) {
787 local_stats.push_back(stat);
788 }
789 // Temporary utility function for call sites that only provide SSRC.
790 // As more info is added into SsrcSenderInfo, this function should go away.
791 void add_ssrc(uint32 ssrc) {
792 SsrcReceiverInfo stat;
793 stat.ssrc = ssrc;
794 add_ssrc(stat);
795 }
796 std::vector<uint32> ssrcs() const {
797 std::vector<uint32> retval;
798 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
799 it != local_stats.end(); ++it) {
800 retval.push_back(it->ssrc);
801 }
802 return retval;
803 }
804 // Utility accessor for clients that make the assumption only one ssrc
805 // exists per media.
806 // This will eventually go away.
807 uint32 ssrc() const {
808 if (local_stats.size() > 0) {
809 return local_stats[0].ssrc;
810 } else {
811 return 0;
812 }
813 }
814
wu@webrtc.org97077a32013-10-25 21:18:33 +0000815 int64 bytes_rcvd;
816 int packets_rcvd;
817 int packets_lost;
818 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000819 std::string codec_name;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000820 std::vector<SsrcReceiverInfo> local_stats;
821 std::vector<SsrcSenderInfo> remote_stats;
822};
823
824struct VoiceSenderInfo : public MediaSenderInfo {
825 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000826 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 jitter_ms(0),
828 audio_level(0),
829 aec_quality_min(0.0),
830 echo_delay_median_ms(0),
831 echo_delay_std_ms(0),
832 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000833 echo_return_loss_enhancement(0),
834 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 }
836
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 int jitter_ms;
839 int audio_level;
840 float aec_quality_min;
841 int echo_delay_median_ms;
842 int echo_delay_std_ms;
843 int echo_return_loss;
844 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000845 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846};
847
wu@webrtc.org97077a32013-10-25 21:18:33 +0000848struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000850 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 jitter_ms(0),
852 jitter_buffer_ms(0),
853 jitter_buffer_preferred_ms(0),
854 delay_estimate_ms(0),
855 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000856 expand_rate(0),
857 decoding_calls_to_silence_generator(0),
858 decoding_calls_to_neteq(0),
859 decoding_normal(0),
860 decoding_plc(0),
861 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000862 decoding_plc_cng(0),
863 capture_start_ntp_time_ms(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 }
865
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 int ext_seqnum;
867 int jitter_ms;
868 int jitter_buffer_ms;
869 int jitter_buffer_preferred_ms;
870 int delay_estimate_ms;
871 int audio_level;
872 // fraction of synthesized speech inserted through pre-emptive expansion
873 float expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000874 int decoding_calls_to_silence_generator;
875 int decoding_calls_to_neteq;
876 int decoding_normal;
877 int decoding_plc;
878 int decoding_cng;
879 int decoding_plc_cng;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000880 // Estimated capture start time in NTP time in ms.
881 int64 capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882};
883
wu@webrtc.org97077a32013-10-25 21:18:33 +0000884struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 VideoSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000886 : packets_cached(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000888 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000890 input_frame_width(0),
891 input_frame_height(0),
892 send_frame_width(0),
893 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 framerate_input(0),
895 framerate_sent(0),
896 nominal_bitrate(0),
897 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000898 adapt_reason(0),
899 capture_jitter_ms(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000900 avg_encode_ms(0),
901 encode_usage_percent(0),
buildbot@webrtc.orgc800c1c2014-06-13 07:56:17 +0000902 encode_rsd(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000903 capture_queue_delay_ms_per_s(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 }
905
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000909 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000911 int input_frame_width;
912 int input_frame_height;
913 int send_frame_width;
914 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 int framerate_input;
916 int framerate_sent;
917 int nominal_bitrate;
918 int preferred_bitrate;
919 int adapt_reason;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000920 int capture_jitter_ms;
921 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000922 int encode_usage_percent;
buildbot@webrtc.orgc800c1c2014-06-13 07:56:17 +0000923 int encode_rsd;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000924 int capture_queue_delay_ms_per_s;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000925 VariableInfo<int> adapt_frame_drops;
926 VariableInfo<int> effects_frame_drops;
927 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928};
929
wu@webrtc.org97077a32013-10-25 21:18:33 +0000930struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 VideoReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000932 : packets_concealed(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000934 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 nacks_sent(0),
936 frame_width(0),
937 frame_height(0),
938 framerate_rcvd(0),
939 framerate_decoded(0),
940 framerate_output(0),
941 framerate_render_input(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000942 framerate_render_output(0),
943 decode_ms(0),
944 max_decode_ms(0),
945 jitter_buffer_ms(0),
946 min_playout_delay_ms(0),
947 render_delay_ms(0),
948 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000949 current_delay_ms(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000950 capture_start_ntp_time_ms(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 }
952
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000956 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 int nacks_sent;
958 int frame_width;
959 int frame_height;
960 int framerate_rcvd;
961 int framerate_decoded;
962 int framerate_output;
963 // Framerate as sent to the renderer.
964 int framerate_render_input;
965 // Framerate that the renderer reports.
966 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000967
968 // All stats below are gathered per-VideoReceiver, but some will be correlated
969 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
970 // structures, reflect this in the new layout.
971
972 // Current frame decode latency.
973 int decode_ms;
974 // Maximum observed frame decode latency.
975 int max_decode_ms;
976 // Jitter (network-related) latency.
977 int jitter_buffer_ms;
978 // Requested minimum playout latency.
979 int min_playout_delay_ms;
980 // Requested latency to account for rendering delay.
981 int render_delay_ms;
982 // Target overall delay: network+decode+render, accounting for
983 // min_playout_delay_ms.
984 int target_delay_ms;
985 // Current overall delay, possibly ramping towards target_delay_ms.
986 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000987
988 // Estimated capture start time in NTP time in ms.
989 int64 capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990};
991
wu@webrtc.org97077a32013-10-25 21:18:33 +0000992struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000994 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 }
996
997 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998};
999
wu@webrtc.org97077a32013-10-25 21:18:33 +00001000struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +00001002 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 }
1004
1005 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006};
1007
1008struct BandwidthEstimationInfo {
1009 BandwidthEstimationInfo()
1010 : available_send_bandwidth(0),
1011 available_recv_bandwidth(0),
1012 target_enc_bitrate(0),
1013 actual_enc_bitrate(0),
1014 retransmit_bitrate(0),
1015 transmit_bitrate(0),
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001016 bucket_delay(0),
1017 total_received_propagation_delta_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 }
1019
1020 int available_send_bandwidth;
1021 int available_recv_bandwidth;
1022 int target_enc_bitrate;
1023 int actual_enc_bitrate;
1024 int retransmit_bitrate;
1025 int transmit_bitrate;
1026 int bucket_delay;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001027 // The following stats are only valid when
1028 // StatsOptions::include_received_propagation_stats is true.
1029 int total_received_propagation_delta_ms;
1030 std::vector<int> recent_received_propagation_delta_ms;
1031 std::vector<int64> recent_received_packet_group_arrival_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032};
1033
1034struct VoiceMediaInfo {
1035 void Clear() {
1036 senders.clear();
1037 receivers.clear();
1038 }
1039 std::vector<VoiceSenderInfo> senders;
1040 std::vector<VoiceReceiverInfo> receivers;
1041};
1042
1043struct VideoMediaInfo {
1044 void Clear() {
1045 senders.clear();
1046 receivers.clear();
1047 bw_estimations.clear();
1048 }
1049 std::vector<VideoSenderInfo> senders;
1050 std::vector<VideoReceiverInfo> receivers;
1051 std::vector<BandwidthEstimationInfo> bw_estimations;
1052};
1053
1054struct DataMediaInfo {
1055 void Clear() {
1056 senders.clear();
1057 receivers.clear();
1058 }
1059 std::vector<DataSenderInfo> senders;
1060 std::vector<DataReceiverInfo> receivers;
1061};
1062
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001063struct StatsOptions {
1064 StatsOptions() : include_received_propagation_stats(false) {}
1065
1066 bool include_received_propagation_stats;
1067};
1068
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069class VoiceMediaChannel : public MediaChannel {
1070 public:
1071 enum Error {
1072 ERROR_NONE = 0, // No error.
1073 ERROR_OTHER, // Other errors.
1074 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
1075 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
1076 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
1077 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
1078 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
1079 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
1080 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
1081 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1082 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
1083 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
1084 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
1085 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
1086 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
1087 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
1088 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1089 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1090 };
1091
1092 VoiceMediaChannel() {}
1093 virtual ~VoiceMediaChannel() {}
1094 // Sets the codecs/payload types to be used for incoming media.
1095 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
1096 // Sets the codecs/payload types to be used for outgoing media.
1097 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
1098 // Starts or stops playout of received audio.
1099 virtual bool SetPlayout(bool playout) = 0;
1100 // Starts or stops sending (and potentially capture) of local audio.
1101 virtual bool SetSend(SendFlags flag) = 0;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001102 // Sets the renderer object to be used for the specified remote audio stream.
1103 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
1104 // Sets the renderer object to be used for the specified local audio stream.
1105 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 // Gets current energy levels for all incoming streams.
1107 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1108 // Get the current energy level of the stream sent to the speaker.
1109 virtual int GetOutputLevel() = 0;
1110 // Get the time in milliseconds since last recorded keystroke, or negative.
1111 virtual int GetTimeSinceLastTyping() = 0;
1112 // Temporarily exposed field for tuning typing detect options.
1113 virtual void SetTypingDetectionParameters(int time_window,
1114 int cost_per_typing, int reporting_threshold, int penalty_decay,
1115 int type_event_delay) = 0;
1116 // Set left and right scale for speaker output volume of the specified ssrc.
1117 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
1118 // Get left and right scale for speaker output volume of the specified ssrc.
1119 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0;
1120 // Specifies a ringback tone to be played during call setup.
1121 virtual bool SetRingbackTone(const char *buf, int len) = 0;
1122 // Plays or stops the aforementioned ringback tone
1123 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
1124 // Returns if the telephone-event has been negotiated.
1125 virtual bool CanInsertDtmf() { return false; }
1126 // Send and/or play a DTMF |event| according to the |flags|.
1127 // The DTMF out-of-band signal will be used on sending.
1128 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001129 // The valid value for the |event| are 0 to 15 which corresponding to
1130 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
1132 // Gets quality stats for the channel.
1133 virtual bool GetStats(VoiceMediaInfo* info) = 0;
1134 // Gets last reported error for this media channel.
1135 virtual void GetLastMediaError(uint32* ssrc,
1136 VoiceMediaChannel::Error* error) {
1137 ASSERT(error != NULL);
1138 *error = ERROR_NONE;
1139 }
1140 // Sets the media options to use.
1141 virtual bool SetOptions(const AudioOptions& options) = 0;
1142 virtual bool GetOptions(AudioOptions* options) const = 0;
1143
1144 // Signal errors from MediaChannel. Arguments are:
1145 // ssrc(uint32), and error(VoiceMediaChannel::Error).
1146 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
1147};
1148
1149class VideoMediaChannel : public MediaChannel {
1150 public:
1151 enum Error {
1152 ERROR_NONE = 0, // No error.
1153 ERROR_OTHER, // Other errors.
1154 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1155 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1156 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1157 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1158 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1159 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1160 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1161 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1162 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1163 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1164 };
1165
1166 VideoMediaChannel() : renderer_(NULL) {}
1167 virtual ~VideoMediaChannel() {}
1168 // Sets the codecs/payload types to be used for incoming media.
1169 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
1170 // Sets the codecs/payload types to be used for outgoing media.
1171 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
1172 // Gets the currently set codecs/payload types to be used for outgoing media.
1173 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1174 // Sets the format of a specified outgoing stream.
1175 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
1176 // Starts or stops playout of received video.
1177 virtual bool SetRender(bool render) = 0;
1178 // Starts or stops transmission (and potentially capture) of local video.
1179 virtual bool SetSend(bool send) = 0;
1180 // Sets the renderer object to be used for the specified stream.
1181 // If SSRC is 0, the renderer is used for the 'default' stream.
1182 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
1183 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1184 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
1185 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
1186 // Gets quality stats for the channel.
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001187 virtual bool GetStats(const StatsOptions& options, VideoMediaInfo* info) = 0;
1188 // This is needed for MediaMonitor to use the same template for voice, video
1189 // and data MediaChannels.
1190 bool GetStats(VideoMediaInfo* info) {
1191 return GetStats(StatsOptions(), info);
1192 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001193
1194 // Send an intra frame to the receivers.
1195 virtual bool SendIntraFrame() = 0;
1196 // Reuqest each of the remote senders to send an intra frame.
1197 virtual bool RequestIntraFrame() = 0;
1198 // Sets the media options to use.
1199 virtual bool SetOptions(const VideoOptions& options) = 0;
1200 virtual bool GetOptions(VideoOptions* options) const = 0;
1201 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1202
1203 // Signal errors from MediaChannel. Arguments are:
1204 // ssrc(uint32), and error(VideoMediaChannel::Error).
1205 sigslot::signal2<uint32, Error> SignalMediaError;
1206
1207 protected:
1208 VideoRenderer *renderer_;
1209};
1210
1211enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001212 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1213 // values.
1214 DMT_NONE = 0,
1215 DMT_CONTROL = 1,
1216 DMT_BINARY = 2,
1217 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001218};
1219
1220// Info about data received in DataMediaChannel. For use in
1221// DataMediaChannel::SignalDataReceived and in all of the signals that
1222// signal fires, on up the chain.
1223struct ReceiveDataParams {
1224 // The in-packet stream indentifier.
1225 // For SCTP, this is really SID, not SSRC.
1226 uint32 ssrc;
1227 // The type of message (binary, text, or control).
1228 DataMessageType type;
1229 // A per-stream value incremented per packet in the stream.
1230 int seq_num;
1231 // A per-stream value monotonically increasing with time.
1232 int timestamp;
1233
1234 ReceiveDataParams() :
1235 ssrc(0),
1236 type(DMT_TEXT),
1237 seq_num(0),
1238 timestamp(0) {
1239 }
1240};
1241
1242struct SendDataParams {
1243 // The in-packet stream indentifier.
1244 // For SCTP, this is really SID, not SSRC.
1245 uint32 ssrc;
1246 // The type of message (binary, text, or control).
1247 DataMessageType type;
1248
1249 // For SCTP, whether to send messages flagged as ordered or not.
1250 // If false, messages can be received out of order.
1251 bool ordered;
1252 // For SCTP, whether the messages are sent reliably or not.
1253 // If false, messages may be lost.
1254 bool reliable;
1255 // For SCTP, if reliable == false, provide partial reliability by
1256 // resending up to this many times. Either count or millis
1257 // is supported, not both at the same time.
1258 int max_rtx_count;
1259 // For SCTP, if reliable == false, provide partial reliability by
1260 // resending for up to this many milliseconds. Either count or millis
1261 // is supported, not both at the same time.
1262 int max_rtx_ms;
1263
1264 SendDataParams() :
1265 ssrc(0),
1266 type(DMT_TEXT),
1267 // TODO(pthatcher): Make these true by default?
1268 ordered(false),
1269 reliable(false),
1270 max_rtx_count(0),
1271 max_rtx_ms(0) {
1272 }
1273};
1274
1275enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1276
1277class DataMediaChannel : public MediaChannel {
1278 public:
1279 enum Error {
1280 ERROR_NONE = 0, // No error.
1281 ERROR_OTHER, // Other errors.
1282 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1283 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1284 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1285 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1286 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1287 };
1288
1289 virtual ~DataMediaChannel() {}
1290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
1292 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001293
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
1295 // TODO(pthatcher): Implement this.
1296 virtual bool GetStats(DataMediaInfo* info) { return true; }
1297
1298 virtual bool SetSend(bool send) = 0;
1299 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300
1301 virtual bool SendData(
1302 const SendDataParams& params,
1303 const talk_base::Buffer& payload,
1304 SendDataResult* result = NULL) = 0;
1305 // Signals when data is received (params, data, len)
1306 sigslot::signal3<const ReceiveDataParams&,
1307 const char*,
1308 size_t> SignalDataReceived;
1309 // Signal errors from MediaChannel. Arguments are:
1310 // ssrc(uint32), and error(DataMediaChannel::Error).
1311 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001312 // Signal when the media channel is ready to send the stream. Arguments are:
1313 // writable(bool)
1314 sigslot::signal1<bool> SignalReadyToSend;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001315 // Signal for notifying that the remote side has closed the DataChannel.
1316 sigslot::signal1<uint32> SignalStreamClosedRemotely;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317};
1318
1319} // namespace cricket
1320
1321#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_