blob: 35948b62f6844f61102f390de8ba9191839d7000 [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);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000317 cpu_overuse_encode_usage.SetFrom(change.cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 conference_mode.SetFrom(change.conference_mode);
319 process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
320 system_low_adaptation_threshhold.SetFrom(
321 change.system_low_adaptation_threshhold);
322 system_high_adaptation_threshhold.SetFrom(
323 change.system_high_adaptation_threshhold);
324 buffered_mode_latency.SetFrom(change.buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000325 lower_min_bitrate.SetFrom(change.lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000326 dscp.SetFrom(change.dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000327 suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000328 unsignalled_recv_stream_limit.SetFrom(change.unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000329 use_simulcast_adapter.SetFrom(change.use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000330 skip_encoding_unused_streams.SetFrom(change.skip_encoding_unused_streams);
331 screencast_min_bitrate.SetFrom(change.screencast_min_bitrate);
332 use_improved_wifi_bandwidth_estimator.SetFrom(
333 change.use_improved_wifi_bandwidth_estimator);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 }
335
336 bool operator==(const VideoOptions& o) const {
337 return adapt_input_to_encoder == o.adapt_input_to_encoder &&
338 adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000339 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340 adapt_view_switch == o.adapt_view_switch &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000341 video_adapt_third == o.video_adapt_third &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 video_noise_reduction == o.video_noise_reduction &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000343 video_one_layer_screencast == o.video_one_layer_screencast &&
344 video_high_bitrate == o.video_high_bitrate &&
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000345 video_start_bitrate == o.video_start_bitrate &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 video_temporal_layer_screencast == o.video_temporal_layer_screencast &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000347 video_temporal_layer_realtime == o.video_temporal_layer_realtime &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 video_leaky_bucket == o.video_leaky_bucket &&
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000349 video_highest_bitrate == o.video_highest_bitrate &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000350 cpu_overuse_detection == o.cpu_overuse_detection &&
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000351 cpu_underuse_threshold == o.cpu_underuse_threshold &&
352 cpu_overuse_threshold == o.cpu_overuse_threshold &&
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000353 cpu_overuse_encode_usage == o.cpu_overuse_encode_usage &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 conference_mode == o.conference_mode &&
355 process_adaptation_threshhold == o.process_adaptation_threshhold &&
356 system_low_adaptation_threshhold ==
357 o.system_low_adaptation_threshhold &&
358 system_high_adaptation_threshhold ==
359 o.system_high_adaptation_threshhold &&
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000360 buffered_mode_latency == o.buffered_mode_latency &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000361 lower_min_bitrate == o.lower_min_bitrate &&
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000362 dscp == o.dscp &&
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000363 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000364 unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit &&
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000365 use_simulcast_adapter == o.use_simulcast_adapter &&
366 skip_encoding_unused_streams == o.skip_encoding_unused_streams &&
henrike@webrtc.org5fb74282014-03-26 02:00:10 +0000367 screencast_min_bitrate == o.screencast_min_bitrate &&
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000368 use_improved_wifi_bandwidth_estimator ==
369 o.use_improved_wifi_bandwidth_estimator;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 }
371
372 std::string ToString() const {
373 std::ostringstream ost;
374 ost << "VideoOptions {";
375 ost << ToStringIfSet("encoder adaption", adapt_input_to_encoder);
376 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000377 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000378 ost << ToStringIfSet("adapt view switch", adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000379 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000381 ost << ToStringIfSet("1 layer screencast", video_one_layer_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382 ost << ToStringIfSet("high bitrate", video_high_bitrate);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000383 ost << ToStringIfSet("start bitrate", video_start_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 ost << ToStringIfSet("video temporal layer screencast",
385 video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000386 ost << ToStringIfSet("video temporal layer realtime",
387 video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 ost << ToStringIfSet("leaky bucket", video_leaky_bucket);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000389 ost << ToStringIfSet("highest video bitrate", video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000390 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000391 ost << ToStringIfSet("cpu underuse threshold", cpu_underuse_threshold);
392 ost << ToStringIfSet("cpu overuse threshold", cpu_overuse_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000393 ost << ToStringIfSet("cpu overuse encode usage",
394 cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395 ost << ToStringIfSet("conference mode", conference_mode);
396 ost << ToStringIfSet("process", process_adaptation_threshhold);
397 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
398 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
399 ost << ToStringIfSet("buffered mode latency", buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000400 ost << ToStringIfSet("lower min bitrate", lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000401 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000402 ost << ToStringIfSet("suspend below min bitrate",
403 suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000404 ost << ToStringIfSet("num channels for early receive",
405 unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000406 ost << ToStringIfSet("use simulcast adapter", use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000407 ost << ToStringIfSet("skip encoding unused streams",
408 skip_encoding_unused_streams);
409 ost << ToStringIfSet("screencast min bitrate", screencast_min_bitrate);
410 ost << ToStringIfSet("improved wifi bwe",
411 use_improved_wifi_bandwidth_estimator);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 ost << "}";
413 return ost.str();
414 }
415
416 // Encoder adaption, which is the gd callback in LMI, and TBA in WebRTC.
417 Settable<bool> adapt_input_to_encoder;
418 // Enable CPU adaptation?
419 Settable<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000420 // Enable CPU adaptation smoothing?
421 Settable<bool> adapt_cpu_with_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 // Enable Adapt View Switch?
423 Settable<bool> adapt_view_switch;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000424 // Enable video adapt third?
425 Settable<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 // Enable denoising?
427 Settable<bool> video_noise_reduction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428 // Experimental: Enable one layer screencast?
429 Settable<bool> video_one_layer_screencast;
430 // Experimental: Enable WebRtc higher bitrate?
431 Settable<bool> video_high_bitrate;
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000432 // Experimental: Enable WebRtc higher start bitrate?
433 Settable<int> video_start_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 // Experimental: Enable WebRTC layered screencast.
435 Settable<bool> video_temporal_layer_screencast;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000436 // Experimental: Enable WebRTC temporal layer strategy for realtime video.
437 Settable<bool> video_temporal_layer_realtime;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438 // Enable WebRTC leaky bucket when sending media packets.
439 Settable<bool> video_leaky_bucket;
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000440 // Set highest bitrate mode for video.
wu@webrtc.orgcfe5e9c2014-03-27 17:03:58 +0000441 Settable<HighestBitrate> video_highest_bitrate;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000442 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
443 // adaptation algorithm. So this option will override the
444 // |adapt_input_to_cpu_usage|.
445 Settable<bool> cpu_overuse_detection;
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000446 // Low threshold for cpu overuse adaptation in ms. (Adapt up)
447 Settable<int> cpu_underuse_threshold;
448 // High threshold for cpu overuse adaptation in ms. (Adapt down)
449 Settable<int> cpu_overuse_threshold;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000450 // Use encode usage for cpu detection.
451 Settable<bool> cpu_overuse_encode_usage;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 // Use conference mode?
453 Settable<bool> conference_mode;
454 // Threshhold for process cpu adaptation. (Process limit)
455 SettablePercent process_adaptation_threshhold;
456 // Low threshhold for cpu adaptation. (Adapt up)
457 SettablePercent system_low_adaptation_threshhold;
458 // High threshhold for cpu adaptation. (Adapt down)
459 SettablePercent system_high_adaptation_threshhold;
460 // Specify buffered mode latency in milliseconds.
461 Settable<int> buffered_mode_latency;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000462 // Make minimum configured send bitrate even lower than usual, at 30kbit.
463 Settable<bool> lower_min_bitrate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000464 // Set DSCP value for packet sent from video channel.
465 Settable<bool> dscp;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000466 // Enable WebRTC suspension of video. No video frames will be sent when the
467 // bitrate is below the configured minimum bitrate.
468 Settable<bool> suspend_below_min_bitrate;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000469 // Limit on the number of early receive channels that can be created.
470 Settable<int> unsignalled_recv_stream_limit;
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000471 // Enable use of simulcast adapter.
472 Settable<bool> use_simulcast_adapter;
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000473 // Enables the encoder to skip encoding stream not actually sent due to too
474 // low available bit rate.
475 Settable<bool> skip_encoding_unused_streams;
476 // Force screencast to use a minimum bitrate
477 Settable<int> screencast_min_bitrate;
478 // Enable improved bandwidth estiamtor on wifi.
479 Settable<bool> use_improved_wifi_bandwidth_estimator;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480};
481
482// A class for playing out soundclips.
483class SoundclipMedia {
484 public:
485 enum SoundclipFlags {
486 SF_LOOP = 1,
487 };
488
489 virtual ~SoundclipMedia() {}
490
491 // Plays a sound out to the speakers with the given audio stream. The stream
492 // must be 16-bit little-endian 16 kHz PCM. If a stream is already playing
493 // on this SoundclipMedia, it is stopped. If clip is NULL, nothing is played.
494 // Returns whether it was successful.
495 virtual bool PlaySound(const char *clip, int len, int flags) = 0;
496};
497
498struct RtpHeaderExtension {
499 RtpHeaderExtension() : id(0) {}
500 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
501 std::string uri;
502 int id;
503 // TODO(juberti): SendRecv direction;
504
505 bool operator==(const RtpHeaderExtension& ext) const {
506 // id is a reserved word in objective-c. Therefore the id attribute has to
507 // be a fully qualified name in order to compile on IOS.
508 return this->id == ext.id &&
509 uri == ext.uri;
510 }
511};
512
513// Returns the named header extension if found among all extensions, NULL
514// otherwise.
515inline const RtpHeaderExtension* FindHeaderExtension(
516 const std::vector<RtpHeaderExtension>& extensions,
517 const std::string& name) {
518 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
519 it != extensions.end(); ++it) {
520 if (it->uri == name)
521 return &(*it);
522 }
523 return NULL;
524}
525
526enum MediaChannelOptions {
527 // Tune the stream for conference mode.
528 OPT_CONFERENCE = 0x0001
529};
530
531enum VoiceMediaChannelOptions {
532 // Tune the audio stream for vcs with different target levels.
533 OPT_AGC_MINUS_10DB = 0x80000000
534};
535
536// DTMF flags to control if a DTMF tone should be played and/or sent.
537enum DtmfFlags {
538 DF_PLAY = 0x01,
539 DF_SEND = 0x02,
540};
541
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000542class MediaChannel : public sigslot::has_slots<> {
543 public:
544 class NetworkInterface {
545 public:
546 enum SocketType { ST_RTP, ST_RTCP };
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000547 virtual bool SendPacket(
548 talk_base::Buffer* packet,
549 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
550 virtual bool SendRtcp(
551 talk_base::Buffer* packet,
552 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 virtual int SetOption(SocketType type, talk_base::Socket::Option opt,
554 int option) = 0;
555 virtual ~NetworkInterface() {}
556 };
557
558 MediaChannel() : network_interface_(NULL) {}
559 virtual ~MediaChannel() {}
560
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000561 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000562 virtual void SetInterface(NetworkInterface *iface) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000563 talk_base::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 network_interface_ = iface;
565 }
566
567 // Called when a RTP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000568 virtual void OnPacketReceived(talk_base::Buffer* packet,
569 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 // Called when a RTCP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000571 virtual void OnRtcpReceived(talk_base::Buffer* packet,
572 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 // Called when the socket's ability to send has changed.
574 virtual void OnReadyToSend(bool ready) = 0;
575 // Creates a new outgoing media stream with SSRCs and CNAME as described
576 // by sp.
577 virtual bool AddSendStream(const StreamParams& sp) = 0;
578 // Removes an outgoing media stream.
579 // ssrc must be the first SSRC of the media stream if the stream uses
580 // multiple SSRCs.
581 virtual bool RemoveSendStream(uint32 ssrc) = 0;
582 // Creates a new incoming media stream with SSRCs and CNAME as described
583 // by sp.
584 virtual bool AddRecvStream(const StreamParams& sp) = 0;
585 // Removes an incoming media stream.
586 // ssrc must be the first SSRC of the media stream if the stream uses
587 // multiple SSRCs.
588 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
589
590 // Mutes the channel.
591 virtual bool MuteStream(uint32 ssrc, bool on) = 0;
592
593 // Sets the RTP extension headers and IDs to use when sending RTP.
594 virtual bool SetRecvRtpHeaderExtensions(
595 const std::vector<RtpHeaderExtension>& extensions) = 0;
596 virtual bool SetSendRtpHeaderExtensions(
597 const std::vector<RtpHeaderExtension>& extensions) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000598 // Returns the absoulte sendtime extension id value from media channel.
599 virtual int GetRtpSendTimeExtnId() const {
600 return -1;
601 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000602 // Sets the initial bandwidth to use when sending starts.
603 virtual bool SetStartSendBandwidth(int bps) = 0;
604 // Sets the maximum allowed bandwidth to use when sending data.
605 virtual bool SetMaxSendBandwidth(int bps) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000607 // Base method to send packet using NetworkInterface.
608 bool SendPacket(talk_base::Buffer* packet) {
609 return DoSendPacket(packet, false);
610 }
611
612 bool SendRtcp(talk_base::Buffer* packet) {
613 return DoSendPacket(packet, true);
614 }
615
616 int SetOption(NetworkInterface::SocketType type,
617 talk_base::Socket::Option opt,
618 int option) {
619 talk_base::CritScope cs(&network_interface_crit_);
620 if (!network_interface_)
621 return -1;
622
623 return network_interface_->SetOption(type, opt, option);
624 }
625
wu@webrtc.orgde305012013-10-31 15:40:38 +0000626 protected:
627 // This method sets DSCP |value| on both RTP and RTCP channels.
628 int SetDscp(talk_base::DiffServCodePoint value) {
629 int ret;
630 ret = SetOption(NetworkInterface::ST_RTP,
631 talk_base::Socket::OPT_DSCP,
632 value);
633 if (ret == 0) {
634 ret = SetOption(NetworkInterface::ST_RTCP,
635 talk_base::Socket::OPT_DSCP,
636 value);
637 }
638 return ret;
639 }
640
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000641 private:
642 bool DoSendPacket(talk_base::Buffer* packet, bool rtcp) {
643 talk_base::CritScope cs(&network_interface_crit_);
644 if (!network_interface_)
645 return false;
646
647 return (!rtcp) ? network_interface_->SendPacket(packet) :
648 network_interface_->SendRtcp(packet);
649 }
650
651 // |network_interface_| can be accessed from the worker_thread and
652 // from any MediaEngine threads. This critical section is to protect accessing
653 // of network_interface_ object.
654 talk_base::CriticalSection network_interface_crit_;
655 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656};
657
658enum SendFlags {
659 SEND_NOTHING,
660 SEND_RINGBACKTONE,
661 SEND_MICROPHONE
662};
663
wu@webrtc.org97077a32013-10-25 21:18:33 +0000664// The stats information is structured as follows:
665// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
666// Media contains a vector of SSRC infos that are exclusively used by this
667// media. (SSRCs shared between media streams can't be represented.)
668
669// Information about an SSRC.
670// This data may be locally recorded, or received in an RTCP SR or RR.
671struct SsrcSenderInfo {
672 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000674 timestamp(0) {
675 }
676 uint32 ssrc;
677 double timestamp; // NTP timestamp, represented as seconds since epoch.
678};
679
680struct SsrcReceiverInfo {
681 SsrcReceiverInfo()
682 : ssrc(0),
683 timestamp(0) {
684 }
685 uint32 ssrc;
686 double timestamp;
687};
688
689struct MediaSenderInfo {
690 MediaSenderInfo()
691 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 packets_sent(0),
693 packets_lost(0),
694 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000695 rtt_ms(0) {
696 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000697 void add_ssrc(const SsrcSenderInfo& stat) {
698 local_stats.push_back(stat);
699 }
700 // Temporary utility function for call sites that only provide SSRC.
701 // As more info is added into SsrcSenderInfo, this function should go away.
702 void add_ssrc(uint32 ssrc) {
703 SsrcSenderInfo stat;
704 stat.ssrc = ssrc;
705 add_ssrc(stat);
706 }
707 // Utility accessor for clients that are only interested in ssrc numbers.
708 std::vector<uint32> ssrcs() const {
709 std::vector<uint32> retval;
710 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
711 it != local_stats.end(); ++it) {
712 retval.push_back(it->ssrc);
713 }
714 return retval;
715 }
716 // Utility accessor for clients that make the assumption only one ssrc
717 // exists per media.
718 // This will eventually go away.
719 uint32 ssrc() const {
720 if (local_stats.size() > 0) {
721 return local_stats[0].ssrc;
722 } else {
723 return 0;
724 }
725 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000726 int64 bytes_sent;
727 int packets_sent;
728 int packets_lost;
729 float fraction_lost;
730 int rtt_ms;
731 std::string codec_name;
732 std::vector<SsrcSenderInfo> local_stats;
733 std::vector<SsrcReceiverInfo> remote_stats;
734};
735
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000736template<class T>
737struct VariableInfo {
738 VariableInfo()
739 : min_val(),
740 mean(0.0),
741 max_val(),
742 variance(0.0) {
743 }
744 T min_val;
745 double mean;
746 T max_val;
747 double variance;
748};
749
wu@webrtc.org97077a32013-10-25 21:18:33 +0000750struct MediaReceiverInfo {
751 MediaReceiverInfo()
752 : bytes_rcvd(0),
753 packets_rcvd(0),
754 packets_lost(0),
755 fraction_lost(0.0) {
756 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000757 void add_ssrc(const SsrcReceiverInfo& stat) {
758 local_stats.push_back(stat);
759 }
760 // Temporary utility function for call sites that only provide SSRC.
761 // As more info is added into SsrcSenderInfo, this function should go away.
762 void add_ssrc(uint32 ssrc) {
763 SsrcReceiverInfo stat;
764 stat.ssrc = ssrc;
765 add_ssrc(stat);
766 }
767 std::vector<uint32> ssrcs() const {
768 std::vector<uint32> retval;
769 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
770 it != local_stats.end(); ++it) {
771 retval.push_back(it->ssrc);
772 }
773 return retval;
774 }
775 // Utility accessor for clients that make the assumption only one ssrc
776 // exists per media.
777 // This will eventually go away.
778 uint32 ssrc() const {
779 if (local_stats.size() > 0) {
780 return local_stats[0].ssrc;
781 } else {
782 return 0;
783 }
784 }
785
wu@webrtc.org97077a32013-10-25 21:18:33 +0000786 int64 bytes_rcvd;
787 int packets_rcvd;
788 int packets_lost;
789 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000790 std::string codec_name;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000791 std::vector<SsrcReceiverInfo> local_stats;
792 std::vector<SsrcSenderInfo> remote_stats;
793};
794
795struct VoiceSenderInfo : public MediaSenderInfo {
796 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000797 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 jitter_ms(0),
799 audio_level(0),
800 aec_quality_min(0.0),
801 echo_delay_median_ms(0),
802 echo_delay_std_ms(0),
803 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000804 echo_return_loss_enhancement(0),
805 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 }
807
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 int jitter_ms;
810 int audio_level;
811 float aec_quality_min;
812 int echo_delay_median_ms;
813 int echo_delay_std_ms;
814 int echo_return_loss;
815 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000816 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817};
818
wu@webrtc.org97077a32013-10-25 21:18:33 +0000819struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000821 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 jitter_ms(0),
823 jitter_buffer_ms(0),
824 jitter_buffer_preferred_ms(0),
825 delay_estimate_ms(0),
826 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000827 expand_rate(0),
828 decoding_calls_to_silence_generator(0),
829 decoding_calls_to_neteq(0),
830 decoding_normal(0),
831 decoding_plc(0),
832 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000833 decoding_plc_cng(0),
834 capture_start_ntp_time_ms(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 }
836
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 int ext_seqnum;
838 int jitter_ms;
839 int jitter_buffer_ms;
840 int jitter_buffer_preferred_ms;
841 int delay_estimate_ms;
842 int audio_level;
843 // fraction of synthesized speech inserted through pre-emptive expansion
844 float expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000845 int decoding_calls_to_silence_generator;
846 int decoding_calls_to_neteq;
847 int decoding_normal;
848 int decoding_plc;
849 int decoding_cng;
850 int decoding_plc_cng;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000851 // Estimated capture start time in NTP time in ms.
852 int64 capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853};
854
wu@webrtc.org97077a32013-10-25 21:18:33 +0000855struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 VideoSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000857 : packets_cached(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000859 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000861 input_frame_width(0),
862 input_frame_height(0),
863 send_frame_width(0),
864 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 framerate_input(0),
866 framerate_sent(0),
867 nominal_bitrate(0),
868 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000869 adapt_reason(0),
870 capture_jitter_ms(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000871 avg_encode_ms(0),
872 encode_usage_percent(0),
873 capture_queue_delay_ms_per_s(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 }
875
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000879 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000881 int input_frame_width;
882 int input_frame_height;
883 int send_frame_width;
884 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 int framerate_input;
886 int framerate_sent;
887 int nominal_bitrate;
888 int preferred_bitrate;
889 int adapt_reason;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000890 int capture_jitter_ms;
891 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000892 int encode_usage_percent;
893 int capture_queue_delay_ms_per_s;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000894 VariableInfo<int> adapt_frame_drops;
895 VariableInfo<int> effects_frame_drops;
896 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897};
898
wu@webrtc.org97077a32013-10-25 21:18:33 +0000899struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 VideoReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000901 : packets_concealed(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000903 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 nacks_sent(0),
905 frame_width(0),
906 frame_height(0),
907 framerate_rcvd(0),
908 framerate_decoded(0),
909 framerate_output(0),
910 framerate_render_input(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000911 framerate_render_output(0),
912 decode_ms(0),
913 max_decode_ms(0),
914 jitter_buffer_ms(0),
915 min_playout_delay_ms(0),
916 render_delay_ms(0),
917 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000918 current_delay_ms(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000919 capture_start_ntp_time_ms(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 }
921
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000925 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 int nacks_sent;
927 int frame_width;
928 int frame_height;
929 int framerate_rcvd;
930 int framerate_decoded;
931 int framerate_output;
932 // Framerate as sent to the renderer.
933 int framerate_render_input;
934 // Framerate that the renderer reports.
935 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000936
937 // All stats below are gathered per-VideoReceiver, but some will be correlated
938 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
939 // structures, reflect this in the new layout.
940
941 // Current frame decode latency.
942 int decode_ms;
943 // Maximum observed frame decode latency.
944 int max_decode_ms;
945 // Jitter (network-related) latency.
946 int jitter_buffer_ms;
947 // Requested minimum playout latency.
948 int min_playout_delay_ms;
949 // Requested latency to account for rendering delay.
950 int render_delay_ms;
951 // Target overall delay: network+decode+render, accounting for
952 // min_playout_delay_ms.
953 int target_delay_ms;
954 // Current overall delay, possibly ramping towards target_delay_ms.
955 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000956
957 // Estimated capture start time in NTP time in ms.
958 int64 capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959};
960
wu@webrtc.org97077a32013-10-25 21:18:33 +0000961struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000963 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 }
965
966 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967};
968
wu@webrtc.org97077a32013-10-25 21:18:33 +0000969struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000971 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 }
973
974 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975};
976
977struct BandwidthEstimationInfo {
978 BandwidthEstimationInfo()
979 : available_send_bandwidth(0),
980 available_recv_bandwidth(0),
981 target_enc_bitrate(0),
982 actual_enc_bitrate(0),
983 retransmit_bitrate(0),
984 transmit_bitrate(0),
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000985 bucket_delay(0),
986 total_received_propagation_delta_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987 }
988
989 int available_send_bandwidth;
990 int available_recv_bandwidth;
991 int target_enc_bitrate;
992 int actual_enc_bitrate;
993 int retransmit_bitrate;
994 int transmit_bitrate;
995 int bucket_delay;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000996 // The following stats are only valid when
997 // StatsOptions::include_received_propagation_stats is true.
998 int total_received_propagation_delta_ms;
999 std::vector<int> recent_received_propagation_delta_ms;
1000 std::vector<int64> recent_received_packet_group_arrival_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001};
1002
1003struct VoiceMediaInfo {
1004 void Clear() {
1005 senders.clear();
1006 receivers.clear();
1007 }
1008 std::vector<VoiceSenderInfo> senders;
1009 std::vector<VoiceReceiverInfo> receivers;
1010};
1011
1012struct VideoMediaInfo {
1013 void Clear() {
1014 senders.clear();
1015 receivers.clear();
1016 bw_estimations.clear();
1017 }
1018 std::vector<VideoSenderInfo> senders;
1019 std::vector<VideoReceiverInfo> receivers;
1020 std::vector<BandwidthEstimationInfo> bw_estimations;
1021};
1022
1023struct DataMediaInfo {
1024 void Clear() {
1025 senders.clear();
1026 receivers.clear();
1027 }
1028 std::vector<DataSenderInfo> senders;
1029 std::vector<DataReceiverInfo> receivers;
1030};
1031
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001032struct StatsOptions {
1033 StatsOptions() : include_received_propagation_stats(false) {}
1034
1035 bool include_received_propagation_stats;
1036};
1037
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001038class VoiceMediaChannel : public MediaChannel {
1039 public:
1040 enum Error {
1041 ERROR_NONE = 0, // No error.
1042 ERROR_OTHER, // Other errors.
1043 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
1044 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
1045 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
1046 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
1047 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
1048 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
1049 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
1050 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1051 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
1052 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
1053 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
1054 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
1055 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
1056 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
1057 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1058 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1059 };
1060
1061 VoiceMediaChannel() {}
1062 virtual ~VoiceMediaChannel() {}
1063 // Sets the codecs/payload types to be used for incoming media.
1064 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
1065 // Sets the codecs/payload types to be used for outgoing media.
1066 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
1067 // Starts or stops playout of received audio.
1068 virtual bool SetPlayout(bool playout) = 0;
1069 // Starts or stops sending (and potentially capture) of local audio.
1070 virtual bool SetSend(SendFlags flag) = 0;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001071 // Sets the renderer object to be used for the specified remote audio stream.
1072 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
1073 // Sets the renderer object to be used for the specified local audio stream.
1074 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 // Gets current energy levels for all incoming streams.
1076 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1077 // Get the current energy level of the stream sent to the speaker.
1078 virtual int GetOutputLevel() = 0;
1079 // Get the time in milliseconds since last recorded keystroke, or negative.
1080 virtual int GetTimeSinceLastTyping() = 0;
1081 // Temporarily exposed field for tuning typing detect options.
1082 virtual void SetTypingDetectionParameters(int time_window,
1083 int cost_per_typing, int reporting_threshold, int penalty_decay,
1084 int type_event_delay) = 0;
1085 // Set left and right scale for speaker output volume of the specified ssrc.
1086 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
1087 // Get left and right scale for speaker output volume of the specified ssrc.
1088 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0;
1089 // Specifies a ringback tone to be played during call setup.
1090 virtual bool SetRingbackTone(const char *buf, int len) = 0;
1091 // Plays or stops the aforementioned ringback tone
1092 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
1093 // Returns if the telephone-event has been negotiated.
1094 virtual bool CanInsertDtmf() { return false; }
1095 // Send and/or play a DTMF |event| according to the |flags|.
1096 // The DTMF out-of-band signal will be used on sending.
1097 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001098 // The valid value for the |event| are 0 to 15 which corresponding to
1099 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
1101 // Gets quality stats for the channel.
1102 virtual bool GetStats(VoiceMediaInfo* info) = 0;
1103 // Gets last reported error for this media channel.
1104 virtual void GetLastMediaError(uint32* ssrc,
1105 VoiceMediaChannel::Error* error) {
1106 ASSERT(error != NULL);
1107 *error = ERROR_NONE;
1108 }
1109 // Sets the media options to use.
1110 virtual bool SetOptions(const AudioOptions& options) = 0;
1111 virtual bool GetOptions(AudioOptions* options) const = 0;
1112
1113 // Signal errors from MediaChannel. Arguments are:
1114 // ssrc(uint32), and error(VoiceMediaChannel::Error).
1115 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
1116};
1117
1118class VideoMediaChannel : public MediaChannel {
1119 public:
1120 enum Error {
1121 ERROR_NONE = 0, // No error.
1122 ERROR_OTHER, // Other errors.
1123 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1124 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1125 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1126 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1127 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1128 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1129 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1130 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1131 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1132 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1133 };
1134
1135 VideoMediaChannel() : renderer_(NULL) {}
1136 virtual ~VideoMediaChannel() {}
1137 // Sets the codecs/payload types to be used for incoming media.
1138 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
1139 // Sets the codecs/payload types to be used for outgoing media.
1140 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
1141 // Gets the currently set codecs/payload types to be used for outgoing media.
1142 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1143 // Sets the format of a specified outgoing stream.
1144 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
1145 // Starts or stops playout of received video.
1146 virtual bool SetRender(bool render) = 0;
1147 // Starts or stops transmission (and potentially capture) of local video.
1148 virtual bool SetSend(bool send) = 0;
1149 // Sets the renderer object to be used for the specified stream.
1150 // If SSRC is 0, the renderer is used for the 'default' stream.
1151 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
1152 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1153 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
1154 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
1155 // Gets quality stats for the channel.
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001156 virtual bool GetStats(const StatsOptions& options, VideoMediaInfo* info) = 0;
1157 // This is needed for MediaMonitor to use the same template for voice, video
1158 // and data MediaChannels.
1159 bool GetStats(VideoMediaInfo* info) {
1160 return GetStats(StatsOptions(), info);
1161 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001162
1163 // Send an intra frame to the receivers.
1164 virtual bool SendIntraFrame() = 0;
1165 // Reuqest each of the remote senders to send an intra frame.
1166 virtual bool RequestIntraFrame() = 0;
1167 // Sets the media options to use.
1168 virtual bool SetOptions(const VideoOptions& options) = 0;
1169 virtual bool GetOptions(VideoOptions* options) const = 0;
1170 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1171
1172 // Signal errors from MediaChannel. Arguments are:
1173 // ssrc(uint32), and error(VideoMediaChannel::Error).
1174 sigslot::signal2<uint32, Error> SignalMediaError;
1175
1176 protected:
1177 VideoRenderer *renderer_;
1178};
1179
1180enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001181 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1182 // values.
1183 DMT_NONE = 0,
1184 DMT_CONTROL = 1,
1185 DMT_BINARY = 2,
1186 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187};
1188
1189// Info about data received in DataMediaChannel. For use in
1190// DataMediaChannel::SignalDataReceived and in all of the signals that
1191// signal fires, on up the chain.
1192struct ReceiveDataParams {
1193 // The in-packet stream indentifier.
1194 // For SCTP, this is really SID, not SSRC.
1195 uint32 ssrc;
1196 // The type of message (binary, text, or control).
1197 DataMessageType type;
1198 // A per-stream value incremented per packet in the stream.
1199 int seq_num;
1200 // A per-stream value monotonically increasing with time.
1201 int timestamp;
1202
1203 ReceiveDataParams() :
1204 ssrc(0),
1205 type(DMT_TEXT),
1206 seq_num(0),
1207 timestamp(0) {
1208 }
1209};
1210
1211struct SendDataParams {
1212 // The in-packet stream indentifier.
1213 // For SCTP, this is really SID, not SSRC.
1214 uint32 ssrc;
1215 // The type of message (binary, text, or control).
1216 DataMessageType type;
1217
1218 // For SCTP, whether to send messages flagged as ordered or not.
1219 // If false, messages can be received out of order.
1220 bool ordered;
1221 // For SCTP, whether the messages are sent reliably or not.
1222 // If false, messages may be lost.
1223 bool reliable;
1224 // For SCTP, if reliable == false, provide partial reliability by
1225 // resending up to this many times. Either count or millis
1226 // is supported, not both at the same time.
1227 int max_rtx_count;
1228 // For SCTP, if reliable == false, provide partial reliability by
1229 // resending for up to this many milliseconds. Either count or millis
1230 // is supported, not both at the same time.
1231 int max_rtx_ms;
1232
1233 SendDataParams() :
1234 ssrc(0),
1235 type(DMT_TEXT),
1236 // TODO(pthatcher): Make these true by default?
1237 ordered(false),
1238 reliable(false),
1239 max_rtx_count(0),
1240 max_rtx_ms(0) {
1241 }
1242};
1243
1244enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1245
1246class DataMediaChannel : public MediaChannel {
1247 public:
1248 enum Error {
1249 ERROR_NONE = 0, // No error.
1250 ERROR_OTHER, // Other errors.
1251 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1252 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1253 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1254 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1255 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1256 };
1257
1258 virtual ~DataMediaChannel() {}
1259
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
1261 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001262
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
1264 // TODO(pthatcher): Implement this.
1265 virtual bool GetStats(DataMediaInfo* info) { return true; }
1266
1267 virtual bool SetSend(bool send) = 0;
1268 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269
1270 virtual bool SendData(
1271 const SendDataParams& params,
1272 const talk_base::Buffer& payload,
1273 SendDataResult* result = NULL) = 0;
1274 // Signals when data is received (params, data, len)
1275 sigslot::signal3<const ReceiveDataParams&,
1276 const char*,
1277 size_t> SignalDataReceived;
1278 // Signal errors from MediaChannel. Arguments are:
1279 // ssrc(uint32), and error(DataMediaChannel::Error).
1280 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001281 // Signal when the media channel is ready to send the stream. Arguments are:
1282 // writable(bool)
1283 sigslot::signal1<bool> SignalReadyToSend;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001284 // Signal for notifying that the remote side has closed the DataChannel.
1285 sigslot::signal1<uint32> SignalStreamClosedRemotely;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286};
1287
1288} // namespace cricket
1289
1290#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_