blob: 4ac578c40732c0bc6acb44870169821021c28091 [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;
65
66// Used in AudioOptions and VideoOptions to signify "unset" values.
67template <class T>
68class Settable {
69 public:
70 Settable() : set_(false), val_() {}
71 explicit Settable(T val) : set_(true), val_(val) {}
72
73 bool IsSet() const {
74 return set_;
75 }
76
77 bool Get(T* out) const {
78 *out = val_;
79 return set_;
80 }
81
82 T GetWithDefaultIfUnset(const T& default_value) const {
83 return set_ ? val_ : default_value;
84 }
85
86 virtual void Set(T val) {
87 set_ = true;
88 val_ = val;
89 }
90
91 void Clear() {
92 Set(T());
93 set_ = false;
94 }
95
96 void SetFrom(const Settable<T>& o) {
97 // Set this value based on the value of o, iff o is set. If this value is
98 // set and o is unset, the current value will be unchanged.
99 T val;
100 if (o.Get(&val)) {
101 Set(val);
102 }
103 }
104
105 std::string ToString() const {
106 return set_ ? talk_base::ToString(val_) : "";
107 }
108
109 bool operator==(const Settable<T>& o) const {
110 // Equal if both are unset with any value or both set with the same value.
111 return (set_ == o.set_) && (!set_ || (val_ == o.val_));
112 }
113
114 bool operator!=(const Settable<T>& o) const {
115 return !operator==(o);
116 }
117
118 protected:
119 void InitializeValue(const T &val) {
120 val_ = val;
121 }
122
123 private:
124 bool set_;
125 T val_;
126};
127
128class SettablePercent : public Settable<float> {
129 public:
130 virtual void Set(float val) {
131 if (val < 0) {
132 val = 0;
133 }
134 if (val > 1.0) {
135 val = 1.0;
136 }
137 Settable<float>::Set(val);
138 }
139};
140
141template <class T>
142static std::string ToStringIfSet(const char* key, const Settable<T>& val) {
143 std::string str;
144 if (val.IsSet()) {
145 str = key;
146 str += ": ";
147 str += val.ToString();
148 str += ", ";
149 }
150 return str;
151}
152
153// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
154// Used to be flags, but that makes it hard to selectively apply options.
155// We are moving all of the setting of options to structs like this,
156// but some things currently still use flags.
157struct AudioOptions {
158 void SetAll(const AudioOptions& change) {
159 echo_cancellation.SetFrom(change.echo_cancellation);
160 auto_gain_control.SetFrom(change.auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000161 rx_auto_gain_control.SetFrom(change.rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 noise_suppression.SetFrom(change.noise_suppression);
163 highpass_filter.SetFrom(change.highpass_filter);
164 stereo_swapping.SetFrom(change.stereo_swapping);
165 typing_detection.SetFrom(change.typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000166 aecm_generate_comfort_noise.SetFrom(change.aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 conference_mode.SetFrom(change.conference_mode);
168 adjust_agc_delta.SetFrom(change.adjust_agc_delta);
169 experimental_agc.SetFrom(change.experimental_agc);
170 experimental_aec.SetFrom(change.experimental_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000171 experimental_ns.SetFrom(change.experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 aec_dump.SetFrom(change.aec_dump);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000173 experimental_acm.SetFrom(change.experimental_acm);
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 &&
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000202 experimental_acm == o.experimental_acm &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000203 tx_agc_target_dbov == o.tx_agc_target_dbov &&
204 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
205 tx_agc_limiter == o.tx_agc_limiter &&
206 rx_agc_target_dbov == o.rx_agc_target_dbov &&
207 rx_agc_digital_compression_gain == o.rx_agc_digital_compression_gain &&
208 rx_agc_limiter == o.rx_agc_limiter &&
209 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000210 playout_sample_rate == o.playout_sample_rate &&
211 dscp == o.dscp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 }
213
214 std::string ToString() const {
215 std::ostringstream ost;
216 ost << "AudioOptions {";
217 ost << ToStringIfSet("aec", echo_cancellation);
218 ost << ToStringIfSet("agc", auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000219 ost << ToStringIfSet("rx_agc", rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 ost << ToStringIfSet("ns", noise_suppression);
221 ost << ToStringIfSet("hf", highpass_filter);
222 ost << ToStringIfSet("swap", stereo_swapping);
223 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000224 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 ost << ToStringIfSet("conference", conference_mode);
226 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
227 ost << ToStringIfSet("experimental_agc", experimental_agc);
228 ost << ToStringIfSet("experimental_aec", experimental_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000229 ost << ToStringIfSet("experimental_ns", experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 ost << ToStringIfSet("aec_dump", aec_dump);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000231 ost << ToStringIfSet("experimental_acm", experimental_acm);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000232 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
233 ost << ToStringIfSet("tx_agc_digital_compression_gain",
234 tx_agc_digital_compression_gain);
235 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
236 ost << ToStringIfSet("rx_agc_target_dbov", rx_agc_target_dbov);
237 ost << ToStringIfSet("rx_agc_digital_compression_gain",
238 rx_agc_digital_compression_gain);
239 ost << ToStringIfSet("rx_agc_limiter", rx_agc_limiter);
240 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
241 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000242 ost << ToStringIfSet("dscp", dscp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243 ost << "}";
244 return ost.str();
245 }
246
247 // Audio processing that attempts to filter away the output signal from
248 // later inbound pickup.
249 Settable<bool> echo_cancellation;
250 // Audio processing to adjust the sensitivity of the local mic dynamically.
251 Settable<bool> auto_gain_control;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000252 // Audio processing to apply gain to the remote audio.
253 Settable<bool> rx_auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 // Audio processing to filter out background noise.
255 Settable<bool> noise_suppression;
256 // Audio processing to remove background noise of lower frequencies.
257 Settable<bool> highpass_filter;
258 // Audio processing to swap the left and right channels.
259 Settable<bool> stereo_swapping;
260 // Audio processing to detect typing.
261 Settable<bool> typing_detection;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000262 Settable<bool> aecm_generate_comfort_noise;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263 Settable<bool> conference_mode;
264 Settable<int> adjust_agc_delta;
265 Settable<bool> experimental_agc;
266 Settable<bool> experimental_aec;
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000267 Settable<bool> experimental_ns;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 Settable<bool> aec_dump;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000269 Settable<bool> experimental_acm;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000270 // Note that tx_agc_* only applies to non-experimental AGC.
271 Settable<uint16> tx_agc_target_dbov;
272 Settable<uint16> tx_agc_digital_compression_gain;
273 Settable<bool> tx_agc_limiter;
274 Settable<uint16> rx_agc_target_dbov;
275 Settable<uint16> rx_agc_digital_compression_gain;
276 Settable<bool> rx_agc_limiter;
277 Settable<uint32> recording_sample_rate;
278 Settable<uint32> playout_sample_rate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000279 // Set DSCP value for packet sent from audio channel.
280 Settable<bool> dscp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281};
282
283// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
284// Used to be flags, but that makes it hard to selectively apply options.
285// We are moving all of the setting of options to structs like this,
286// but some things currently still use flags.
287struct VideoOptions {
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000288 enum HighestBitrate {
289 NORMAL,
290 HIGH,
291 VERY_HIGH
292 };
293
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 VideoOptions() {
295 process_adaptation_threshhold.Set(kProcessCpuThreshold);
296 system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold);
297 system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000298 unsignalled_recv_stream_limit.Set(kNumDefaultUnsignalledVideoRecvStreams);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 }
300
301 void SetAll(const VideoOptions& change) {
302 adapt_input_to_encoder.SetFrom(change.adapt_input_to_encoder);
303 adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000304 adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 adapt_view_switch.SetFrom(change.adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000306 video_adapt_third.SetFrom(change.video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 video_noise_reduction.SetFrom(change.video_noise_reduction);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 video_one_layer_screencast.SetFrom(change.video_one_layer_screencast);
309 video_high_bitrate.SetFrom(change.video_high_bitrate);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000310 video_start_bitrate.SetFrom(change.video_start_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 video_temporal_layer_screencast.SetFrom(
312 change.video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000313 video_temporal_layer_realtime.SetFrom(
314 change.video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315 video_leaky_bucket.SetFrom(change.video_leaky_bucket);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000316 video_highest_bitrate.SetFrom(change.video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000317 cpu_overuse_detection.SetFrom(change.cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000318 cpu_underuse_threshold.SetFrom(change.cpu_underuse_threshold);
319 cpu_overuse_threshold.SetFrom(change.cpu_overuse_threshold);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 conference_mode.SetFrom(change.conference_mode);
321 process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
322 system_low_adaptation_threshhold.SetFrom(
323 change.system_low_adaptation_threshhold);
324 system_high_adaptation_threshhold.SetFrom(
325 change.system_high_adaptation_threshhold);
326 buffered_mode_latency.SetFrom(change.buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000327 lower_min_bitrate.SetFrom(change.lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000328 dscp.SetFrom(change.dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000329 suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000330 unsignalled_recv_stream_limit.SetFrom(change.unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000331 use_simulcast_adapter.SetFrom(change.use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000332 skip_encoding_unused_streams.SetFrom(change.skip_encoding_unused_streams);
333 screencast_min_bitrate.SetFrom(change.screencast_min_bitrate);
334 use_improved_wifi_bandwidth_estimator.SetFrom(
335 change.use_improved_wifi_bandwidth_estimator);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336 }
337
338 bool operator==(const VideoOptions& o) const {
339 return adapt_input_to_encoder == o.adapt_input_to_encoder &&
340 adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000341 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 adapt_view_switch == o.adapt_view_switch &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000343 video_adapt_third == o.video_adapt_third &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 video_noise_reduction == o.video_noise_reduction &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 video_one_layer_screencast == o.video_one_layer_screencast &&
346 video_high_bitrate == o.video_high_bitrate &&
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000347 video_start_bitrate == o.video_start_bitrate &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 video_temporal_layer_screencast == o.video_temporal_layer_screencast &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000349 video_temporal_layer_realtime == o.video_temporal_layer_realtime &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 video_leaky_bucket == o.video_leaky_bucket &&
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000351 video_highest_bitrate == o.video_highest_bitrate &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000352 cpu_overuse_detection == o.cpu_overuse_detection &&
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000353 cpu_underuse_threshold == o.cpu_underuse_threshold &&
354 cpu_overuse_threshold == o.cpu_overuse_threshold &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 conference_mode == o.conference_mode &&
356 process_adaptation_threshhold == o.process_adaptation_threshhold &&
357 system_low_adaptation_threshhold ==
358 o.system_low_adaptation_threshhold &&
359 system_high_adaptation_threshhold ==
360 o.system_high_adaptation_threshhold &&
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000361 buffered_mode_latency == o.buffered_mode_latency &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000362 lower_min_bitrate == o.lower_min_bitrate &&
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000363 dscp == o.dscp &&
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000364 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000365 unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit &&
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000366 use_simulcast_adapter == o.use_simulcast_adapter &&
367 skip_encoding_unused_streams == o.skip_encoding_unused_streams &&
368 screencast_min_bitrate == o.screencast_min_bitrate;
369 use_improved_wifi_bandwidth_estimator ==
370 o.use_improved_wifi_bandwidth_estimator;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 }
372
373 std::string ToString() const {
374 std::ostringstream ost;
375 ost << "VideoOptions {";
376 ost << ToStringIfSet("encoder adaption", adapt_input_to_encoder);
377 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000378 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 ost << ToStringIfSet("adapt view switch", adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000380 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000382 ost << ToStringIfSet("1 layer screencast", video_one_layer_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 ost << ToStringIfSet("high bitrate", video_high_bitrate);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000384 ost << ToStringIfSet("start bitrate", video_start_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 ost << ToStringIfSet("video temporal layer screencast",
386 video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000387 ost << ToStringIfSet("video temporal layer realtime",
388 video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389 ost << ToStringIfSet("leaky bucket", video_leaky_bucket);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000390 ost << ToStringIfSet("highest video bitrate", video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000391 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000392 ost << ToStringIfSet("cpu underuse threshold", cpu_underuse_threshold);
393 ost << ToStringIfSet("cpu overuse threshold", cpu_overuse_threshold);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394 ost << ToStringIfSet("conference mode", conference_mode);
395 ost << ToStringIfSet("process", process_adaptation_threshhold);
396 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
397 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
398 ost << ToStringIfSet("buffered mode latency", buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000399 ost << ToStringIfSet("lower min bitrate", lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000400 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000401 ost << ToStringIfSet("suspend below min bitrate",
402 suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000403 ost << ToStringIfSet("num channels for early receive",
404 unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000405 ost << ToStringIfSet("use simulcast adapter", use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000406 ost << ToStringIfSet("skip encoding unused streams",
407 skip_encoding_unused_streams);
408 ost << ToStringIfSet("screencast min bitrate", screencast_min_bitrate);
409 ost << ToStringIfSet("improved wifi bwe",
410 use_improved_wifi_bandwidth_estimator);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 ost << "}";
412 return ost.str();
413 }
414
415 // Encoder adaption, which is the gd callback in LMI, and TBA in WebRTC.
416 Settable<bool> adapt_input_to_encoder;
417 // Enable CPU adaptation?
418 Settable<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000419 // Enable CPU adaptation smoothing?
420 Settable<bool> adapt_cpu_with_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421 // Enable Adapt View Switch?
422 Settable<bool> adapt_view_switch;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000423 // Enable video adapt third?
424 Settable<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425 // Enable denoising?
426 Settable<bool> video_noise_reduction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427 // Experimental: Enable one layer screencast?
428 Settable<bool> video_one_layer_screencast;
429 // Experimental: Enable WebRtc higher bitrate?
430 Settable<bool> video_high_bitrate;
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000431 // Experimental: Enable WebRtc higher start bitrate?
432 Settable<int> video_start_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433 // Experimental: Enable WebRTC layered screencast.
434 Settable<bool> video_temporal_layer_screencast;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000435 // Experimental: Enable WebRTC temporal layer strategy for realtime video.
436 Settable<bool> video_temporal_layer_realtime;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437 // Enable WebRTC leaky bucket when sending media packets.
438 Settable<bool> video_leaky_bucket;
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000439 // Set highest bitrate mode for video.
440 Settable<int> video_highest_bitrate;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000441 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
442 // adaptation algorithm. So this option will override the
443 // |adapt_input_to_cpu_usage|.
444 Settable<bool> cpu_overuse_detection;
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000445 // Low threshold for cpu overuse adaptation in ms. (Adapt up)
446 Settable<int> cpu_underuse_threshold;
447 // High threshold for cpu overuse adaptation in ms. (Adapt down)
448 Settable<int> cpu_overuse_threshold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 // Use conference mode?
450 Settable<bool> conference_mode;
451 // Threshhold for process cpu adaptation. (Process limit)
452 SettablePercent process_adaptation_threshhold;
453 // Low threshhold for cpu adaptation. (Adapt up)
454 SettablePercent system_low_adaptation_threshhold;
455 // High threshhold for cpu adaptation. (Adapt down)
456 SettablePercent system_high_adaptation_threshhold;
457 // Specify buffered mode latency in milliseconds.
458 Settable<int> buffered_mode_latency;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000459 // Make minimum configured send bitrate even lower than usual, at 30kbit.
460 Settable<bool> lower_min_bitrate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000461 // Set DSCP value for packet sent from video channel.
462 Settable<bool> dscp;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000463 // Enable WebRTC suspension of video. No video frames will be sent when the
464 // bitrate is below the configured minimum bitrate.
465 Settable<bool> suspend_below_min_bitrate;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000466 // Limit on the number of early receive channels that can be created.
467 Settable<int> unsignalled_recv_stream_limit;
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000468 // Enable use of simulcast adapter.
469 Settable<bool> use_simulcast_adapter;
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000470 // Enables the encoder to skip encoding stream not actually sent due to too
471 // low available bit rate.
472 Settable<bool> skip_encoding_unused_streams;
473 // Force screencast to use a minimum bitrate
474 Settable<int> screencast_min_bitrate;
475 // Enable improved bandwidth estiamtor on wifi.
476 Settable<bool> use_improved_wifi_bandwidth_estimator;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000477};
478
479// A class for playing out soundclips.
480class SoundclipMedia {
481 public:
482 enum SoundclipFlags {
483 SF_LOOP = 1,
484 };
485
486 virtual ~SoundclipMedia() {}
487
488 // Plays a sound out to the speakers with the given audio stream. The stream
489 // must be 16-bit little-endian 16 kHz PCM. If a stream is already playing
490 // on this SoundclipMedia, it is stopped. If clip is NULL, nothing is played.
491 // Returns whether it was successful.
492 virtual bool PlaySound(const char *clip, int len, int flags) = 0;
493};
494
495struct RtpHeaderExtension {
496 RtpHeaderExtension() : id(0) {}
497 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
498 std::string uri;
499 int id;
500 // TODO(juberti): SendRecv direction;
501
502 bool operator==(const RtpHeaderExtension& ext) const {
503 // id is a reserved word in objective-c. Therefore the id attribute has to
504 // be a fully qualified name in order to compile on IOS.
505 return this->id == ext.id &&
506 uri == ext.uri;
507 }
508};
509
510// Returns the named header extension if found among all extensions, NULL
511// otherwise.
512inline const RtpHeaderExtension* FindHeaderExtension(
513 const std::vector<RtpHeaderExtension>& extensions,
514 const std::string& name) {
515 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
516 it != extensions.end(); ++it) {
517 if (it->uri == name)
518 return &(*it);
519 }
520 return NULL;
521}
522
523enum MediaChannelOptions {
524 // Tune the stream for conference mode.
525 OPT_CONFERENCE = 0x0001
526};
527
528enum VoiceMediaChannelOptions {
529 // Tune the audio stream for vcs with different target levels.
530 OPT_AGC_MINUS_10DB = 0x80000000
531};
532
533// DTMF flags to control if a DTMF tone should be played and/or sent.
534enum DtmfFlags {
535 DF_PLAY = 0x01,
536 DF_SEND = 0x02,
537};
538
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539class MediaChannel : public sigslot::has_slots<> {
540 public:
541 class NetworkInterface {
542 public:
543 enum SocketType { ST_RTP, ST_RTCP };
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000544 virtual bool SendPacket(
545 talk_base::Buffer* packet,
546 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
547 virtual bool SendRtcp(
548 talk_base::Buffer* packet,
549 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 virtual int SetOption(SocketType type, talk_base::Socket::Option opt,
551 int option) = 0;
552 virtual ~NetworkInterface() {}
553 };
554
555 MediaChannel() : network_interface_(NULL) {}
556 virtual ~MediaChannel() {}
557
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000558 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 virtual void SetInterface(NetworkInterface *iface) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000560 talk_base::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 network_interface_ = iface;
562 }
563
564 // Called when a RTP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000565 virtual void OnPacketReceived(talk_base::Buffer* packet,
566 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567 // Called when a RTCP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000568 virtual void OnRtcpReceived(talk_base::Buffer* packet,
569 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 // Called when the socket's ability to send has changed.
571 virtual void OnReadyToSend(bool ready) = 0;
572 // Creates a new outgoing media stream with SSRCs and CNAME as described
573 // by sp.
574 virtual bool AddSendStream(const StreamParams& sp) = 0;
575 // Removes an outgoing media stream.
576 // ssrc must be the first SSRC of the media stream if the stream uses
577 // multiple SSRCs.
578 virtual bool RemoveSendStream(uint32 ssrc) = 0;
579 // Creates a new incoming media stream with SSRCs and CNAME as described
580 // by sp.
581 virtual bool AddRecvStream(const StreamParams& sp) = 0;
582 // Removes an incoming media stream.
583 // ssrc must be the first SSRC of the media stream if the stream uses
584 // multiple SSRCs.
585 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
586
587 // Mutes the channel.
588 virtual bool MuteStream(uint32 ssrc, bool on) = 0;
589
590 // Sets the RTP extension headers and IDs to use when sending RTP.
591 virtual bool SetRecvRtpHeaderExtensions(
592 const std::vector<RtpHeaderExtension>& extensions) = 0;
593 virtual bool SetSendRtpHeaderExtensions(
594 const std::vector<RtpHeaderExtension>& extensions) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000595 // Returns the absoulte sendtime extension id value from media channel.
596 virtual int GetRtpSendTimeExtnId() const {
597 return -1;
598 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000599 // Sets the initial bandwidth to use when sending starts.
600 virtual bool SetStartSendBandwidth(int bps) = 0;
601 // Sets the maximum allowed bandwidth to use when sending data.
602 virtual bool SetMaxSendBandwidth(int bps) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000604 // Base method to send packet using NetworkInterface.
605 bool SendPacket(talk_base::Buffer* packet) {
606 return DoSendPacket(packet, false);
607 }
608
609 bool SendRtcp(talk_base::Buffer* packet) {
610 return DoSendPacket(packet, true);
611 }
612
613 int SetOption(NetworkInterface::SocketType type,
614 talk_base::Socket::Option opt,
615 int option) {
616 talk_base::CritScope cs(&network_interface_crit_);
617 if (!network_interface_)
618 return -1;
619
620 return network_interface_->SetOption(type, opt, option);
621 }
622
wu@webrtc.orgde305012013-10-31 15:40:38 +0000623 protected:
624 // This method sets DSCP |value| on both RTP and RTCP channels.
625 int SetDscp(talk_base::DiffServCodePoint value) {
626 int ret;
627 ret = SetOption(NetworkInterface::ST_RTP,
628 talk_base::Socket::OPT_DSCP,
629 value);
630 if (ret == 0) {
631 ret = SetOption(NetworkInterface::ST_RTCP,
632 talk_base::Socket::OPT_DSCP,
633 value);
634 }
635 return ret;
636 }
637
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000638 private:
639 bool DoSendPacket(talk_base::Buffer* packet, bool rtcp) {
640 talk_base::CritScope cs(&network_interface_crit_);
641 if (!network_interface_)
642 return false;
643
644 return (!rtcp) ? network_interface_->SendPacket(packet) :
645 network_interface_->SendRtcp(packet);
646 }
647
648 // |network_interface_| can be accessed from the worker_thread and
649 // from any MediaEngine threads. This critical section is to protect accessing
650 // of network_interface_ object.
651 talk_base::CriticalSection network_interface_crit_;
652 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653};
654
655enum SendFlags {
656 SEND_NOTHING,
657 SEND_RINGBACKTONE,
658 SEND_MICROPHONE
659};
660
wu@webrtc.org97077a32013-10-25 21:18:33 +0000661// The stats information is structured as follows:
662// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
663// Media contains a vector of SSRC infos that are exclusively used by this
664// media. (SSRCs shared between media streams can't be represented.)
665
666// Information about an SSRC.
667// This data may be locally recorded, or received in an RTCP SR or RR.
668struct SsrcSenderInfo {
669 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000670 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000671 timestamp(0) {
672 }
673 uint32 ssrc;
674 double timestamp; // NTP timestamp, represented as seconds since epoch.
675};
676
677struct SsrcReceiverInfo {
678 SsrcReceiverInfo()
679 : ssrc(0),
680 timestamp(0) {
681 }
682 uint32 ssrc;
683 double timestamp;
684};
685
686struct MediaSenderInfo {
687 MediaSenderInfo()
688 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689 packets_sent(0),
690 packets_lost(0),
691 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000692 rtt_ms(0) {
693 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000694 void add_ssrc(const SsrcSenderInfo& stat) {
695 local_stats.push_back(stat);
696 }
697 // Temporary utility function for call sites that only provide SSRC.
698 // As more info is added into SsrcSenderInfo, this function should go away.
699 void add_ssrc(uint32 ssrc) {
700 SsrcSenderInfo stat;
701 stat.ssrc = ssrc;
702 add_ssrc(stat);
703 }
704 // Utility accessor for clients that are only interested in ssrc numbers.
705 std::vector<uint32> ssrcs() const {
706 std::vector<uint32> retval;
707 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
708 it != local_stats.end(); ++it) {
709 retval.push_back(it->ssrc);
710 }
711 return retval;
712 }
713 // Utility accessor for clients that make the assumption only one ssrc
714 // exists per media.
715 // This will eventually go away.
716 uint32 ssrc() const {
717 if (local_stats.size() > 0) {
718 return local_stats[0].ssrc;
719 } else {
720 return 0;
721 }
722 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000723 int64 bytes_sent;
724 int packets_sent;
725 int packets_lost;
726 float fraction_lost;
727 int rtt_ms;
728 std::string codec_name;
729 std::vector<SsrcSenderInfo> local_stats;
730 std::vector<SsrcReceiverInfo> remote_stats;
731};
732
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000733template<class T>
734struct VariableInfo {
735 VariableInfo()
736 : min_val(),
737 mean(0.0),
738 max_val(),
739 variance(0.0) {
740 }
741 T min_val;
742 double mean;
743 T max_val;
744 double variance;
745};
746
wu@webrtc.org97077a32013-10-25 21:18:33 +0000747struct MediaReceiverInfo {
748 MediaReceiverInfo()
749 : bytes_rcvd(0),
750 packets_rcvd(0),
751 packets_lost(0),
752 fraction_lost(0.0) {
753 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000754 void add_ssrc(const SsrcReceiverInfo& stat) {
755 local_stats.push_back(stat);
756 }
757 // Temporary utility function for call sites that only provide SSRC.
758 // As more info is added into SsrcSenderInfo, this function should go away.
759 void add_ssrc(uint32 ssrc) {
760 SsrcReceiverInfo stat;
761 stat.ssrc = ssrc;
762 add_ssrc(stat);
763 }
764 std::vector<uint32> ssrcs() const {
765 std::vector<uint32> retval;
766 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
767 it != local_stats.end(); ++it) {
768 retval.push_back(it->ssrc);
769 }
770 return retval;
771 }
772 // Utility accessor for clients that make the assumption only one ssrc
773 // exists per media.
774 // This will eventually go away.
775 uint32 ssrc() const {
776 if (local_stats.size() > 0) {
777 return local_stats[0].ssrc;
778 } else {
779 return 0;
780 }
781 }
782
wu@webrtc.org97077a32013-10-25 21:18:33 +0000783 int64 bytes_rcvd;
784 int packets_rcvd;
785 int packets_lost;
786 float fraction_lost;
787 std::vector<SsrcReceiverInfo> local_stats;
788 std::vector<SsrcSenderInfo> remote_stats;
789};
790
791struct VoiceSenderInfo : public MediaSenderInfo {
792 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000793 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 jitter_ms(0),
795 audio_level(0),
796 aec_quality_min(0.0),
797 echo_delay_median_ms(0),
798 echo_delay_std_ms(0),
799 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000800 echo_return_loss_enhancement(0),
801 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 }
803
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 int jitter_ms;
806 int audio_level;
807 float aec_quality_min;
808 int echo_delay_median_ms;
809 int echo_delay_std_ms;
810 int echo_return_loss;
811 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000812 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813};
814
wu@webrtc.org97077a32013-10-25 21:18:33 +0000815struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000817 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 jitter_ms(0),
819 jitter_buffer_ms(0),
820 jitter_buffer_preferred_ms(0),
821 delay_estimate_ms(0),
822 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000823 expand_rate(0),
824 decoding_calls_to_silence_generator(0),
825 decoding_calls_to_neteq(0),
826 decoding_normal(0),
827 decoding_plc(0),
828 decoding_cng(0),
829 decoding_plc_cng(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 }
831
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 int ext_seqnum;
833 int jitter_ms;
834 int jitter_buffer_ms;
835 int jitter_buffer_preferred_ms;
836 int delay_estimate_ms;
837 int audio_level;
838 // fraction of synthesized speech inserted through pre-emptive expansion
839 float expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000840 int decoding_calls_to_silence_generator;
841 int decoding_calls_to_neteq;
842 int decoding_normal;
843 int decoding_plc;
844 int decoding_cng;
845 int decoding_plc_cng;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846};
847
wu@webrtc.org97077a32013-10-25 21:18:33 +0000848struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 VideoSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000850 : packets_cached(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000852 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 nacks_rcvd(0),
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000854 input_frame_width(0),
855 input_frame_height(0),
856 send_frame_width(0),
857 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 framerate_input(0),
859 framerate_sent(0),
860 nominal_bitrate(0),
861 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000862 adapt_reason(0),
863 capture_jitter_ms(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000864 avg_encode_ms(0),
865 encode_usage_percent(0),
866 capture_queue_delay_ms_per_s(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 }
868
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000872 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 int nacks_rcvd;
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000874 int input_frame_width;
875 int input_frame_height;
876 int send_frame_width;
877 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 int framerate_input;
879 int framerate_sent;
880 int nominal_bitrate;
881 int preferred_bitrate;
882 int adapt_reason;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000883 int capture_jitter_ms;
884 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000885 int encode_usage_percent;
886 int capture_queue_delay_ms_per_s;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000887 VariableInfo<int> adapt_frame_drops;
888 VariableInfo<int> effects_frame_drops;
889 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890};
891
wu@webrtc.org97077a32013-10-25 21:18:33 +0000892struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 VideoReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000894 : packets_concealed(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000896 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 nacks_sent(0),
898 frame_width(0),
899 frame_height(0),
900 framerate_rcvd(0),
901 framerate_decoded(0),
902 framerate_output(0),
903 framerate_render_input(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000904 framerate_render_output(0),
905 decode_ms(0),
906 max_decode_ms(0),
907 jitter_buffer_ms(0),
908 min_playout_delay_ms(0),
909 render_delay_ms(0),
910 target_delay_ms(0),
911 current_delay_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 }
913
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000917 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 int nacks_sent;
919 int frame_width;
920 int frame_height;
921 int framerate_rcvd;
922 int framerate_decoded;
923 int framerate_output;
924 // Framerate as sent to the renderer.
925 int framerate_render_input;
926 // Framerate that the renderer reports.
927 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000928
929 // All stats below are gathered per-VideoReceiver, but some will be correlated
930 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
931 // structures, reflect this in the new layout.
932
933 // Current frame decode latency.
934 int decode_ms;
935 // Maximum observed frame decode latency.
936 int max_decode_ms;
937 // Jitter (network-related) latency.
938 int jitter_buffer_ms;
939 // Requested minimum playout latency.
940 int min_playout_delay_ms;
941 // Requested latency to account for rendering delay.
942 int render_delay_ms;
943 // Target overall delay: network+decode+render, accounting for
944 // min_playout_delay_ms.
945 int target_delay_ms;
946 // Current overall delay, possibly ramping towards target_delay_ms.
947 int current_delay_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948};
949
wu@webrtc.org97077a32013-10-25 21:18:33 +0000950struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000952 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 }
954
955 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956};
957
wu@webrtc.org97077a32013-10-25 21:18:33 +0000958struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000960 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961 }
962
963 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964};
965
966struct BandwidthEstimationInfo {
967 BandwidthEstimationInfo()
968 : available_send_bandwidth(0),
969 available_recv_bandwidth(0),
970 target_enc_bitrate(0),
971 actual_enc_bitrate(0),
972 retransmit_bitrate(0),
973 transmit_bitrate(0),
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000974 bucket_delay(0),
975 total_received_propagation_delta_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 }
977
978 int available_send_bandwidth;
979 int available_recv_bandwidth;
980 int target_enc_bitrate;
981 int actual_enc_bitrate;
982 int retransmit_bitrate;
983 int transmit_bitrate;
984 int bucket_delay;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000985 // The following stats are only valid when
986 // StatsOptions::include_received_propagation_stats is true.
987 int total_received_propagation_delta_ms;
988 std::vector<int> recent_received_propagation_delta_ms;
989 std::vector<int64> recent_received_packet_group_arrival_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990};
991
992struct VoiceMediaInfo {
993 void Clear() {
994 senders.clear();
995 receivers.clear();
996 }
997 std::vector<VoiceSenderInfo> senders;
998 std::vector<VoiceReceiverInfo> receivers;
999};
1000
1001struct VideoMediaInfo {
1002 void Clear() {
1003 senders.clear();
1004 receivers.clear();
1005 bw_estimations.clear();
1006 }
1007 std::vector<VideoSenderInfo> senders;
1008 std::vector<VideoReceiverInfo> receivers;
1009 std::vector<BandwidthEstimationInfo> bw_estimations;
1010};
1011
1012struct DataMediaInfo {
1013 void Clear() {
1014 senders.clear();
1015 receivers.clear();
1016 }
1017 std::vector<DataSenderInfo> senders;
1018 std::vector<DataReceiverInfo> receivers;
1019};
1020
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001021struct StatsOptions {
1022 StatsOptions() : include_received_propagation_stats(false) {}
1023
1024 bool include_received_propagation_stats;
1025};
1026
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001027class VoiceMediaChannel : public MediaChannel {
1028 public:
1029 enum Error {
1030 ERROR_NONE = 0, // No error.
1031 ERROR_OTHER, // Other errors.
1032 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
1033 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
1034 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
1035 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
1036 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
1037 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
1038 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
1039 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1040 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
1041 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
1042 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
1043 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
1044 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
1045 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
1046 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1047 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1048 };
1049
1050 VoiceMediaChannel() {}
1051 virtual ~VoiceMediaChannel() {}
1052 // Sets the codecs/payload types to be used for incoming media.
1053 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
1054 // Sets the codecs/payload types to be used for outgoing media.
1055 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
1056 // Starts or stops playout of received audio.
1057 virtual bool SetPlayout(bool playout) = 0;
1058 // Starts or stops sending (and potentially capture) of local audio.
1059 virtual bool SetSend(SendFlags flag) = 0;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001060 // Sets the renderer object to be used for the specified remote audio stream.
1061 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
1062 // Sets the renderer object to be used for the specified local audio stream.
1063 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 // Gets current energy levels for all incoming streams.
1065 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1066 // Get the current energy level of the stream sent to the speaker.
1067 virtual int GetOutputLevel() = 0;
1068 // Get the time in milliseconds since last recorded keystroke, or negative.
1069 virtual int GetTimeSinceLastTyping() = 0;
1070 // Temporarily exposed field for tuning typing detect options.
1071 virtual void SetTypingDetectionParameters(int time_window,
1072 int cost_per_typing, int reporting_threshold, int penalty_decay,
1073 int type_event_delay) = 0;
1074 // Set left and right scale for speaker output volume of the specified ssrc.
1075 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
1076 // Get left and right scale for speaker output volume of the specified ssrc.
1077 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0;
1078 // Specifies a ringback tone to be played during call setup.
1079 virtual bool SetRingbackTone(const char *buf, int len) = 0;
1080 // Plays or stops the aforementioned ringback tone
1081 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
1082 // Returns if the telephone-event has been negotiated.
1083 virtual bool CanInsertDtmf() { return false; }
1084 // Send and/or play a DTMF |event| according to the |flags|.
1085 // The DTMF out-of-band signal will be used on sending.
1086 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001087 // The valid value for the |event| are 0 to 15 which corresponding to
1088 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
1090 // Gets quality stats for the channel.
1091 virtual bool GetStats(VoiceMediaInfo* info) = 0;
1092 // Gets last reported error for this media channel.
1093 virtual void GetLastMediaError(uint32* ssrc,
1094 VoiceMediaChannel::Error* error) {
1095 ASSERT(error != NULL);
1096 *error = ERROR_NONE;
1097 }
1098 // Sets the media options to use.
1099 virtual bool SetOptions(const AudioOptions& options) = 0;
1100 virtual bool GetOptions(AudioOptions* options) const = 0;
1101
1102 // Signal errors from MediaChannel. Arguments are:
1103 // ssrc(uint32), and error(VoiceMediaChannel::Error).
1104 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
1105};
1106
1107class VideoMediaChannel : public MediaChannel {
1108 public:
1109 enum Error {
1110 ERROR_NONE = 0, // No error.
1111 ERROR_OTHER, // Other errors.
1112 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1113 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1114 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1115 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1116 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1117 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1118 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1119 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1120 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1121 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1122 };
1123
1124 VideoMediaChannel() : renderer_(NULL) {}
1125 virtual ~VideoMediaChannel() {}
1126 // Sets the codecs/payload types to be used for incoming media.
1127 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
1128 // Sets the codecs/payload types to be used for outgoing media.
1129 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
1130 // Gets the currently set codecs/payload types to be used for outgoing media.
1131 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1132 // Sets the format of a specified outgoing stream.
1133 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
1134 // Starts or stops playout of received video.
1135 virtual bool SetRender(bool render) = 0;
1136 // Starts or stops transmission (and potentially capture) of local video.
1137 virtual bool SetSend(bool send) = 0;
1138 // Sets the renderer object to be used for the specified stream.
1139 // If SSRC is 0, the renderer is used for the 'default' stream.
1140 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
1141 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1142 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
1143 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
1144 // Gets quality stats for the channel.
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001145 virtual bool GetStats(const StatsOptions& options, VideoMediaInfo* info) = 0;
1146 // This is needed for MediaMonitor to use the same template for voice, video
1147 // and data MediaChannels.
1148 bool GetStats(VideoMediaInfo* info) {
1149 return GetStats(StatsOptions(), info);
1150 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001151
1152 // Send an intra frame to the receivers.
1153 virtual bool SendIntraFrame() = 0;
1154 // Reuqest each of the remote senders to send an intra frame.
1155 virtual bool RequestIntraFrame() = 0;
1156 // Sets the media options to use.
1157 virtual bool SetOptions(const VideoOptions& options) = 0;
1158 virtual bool GetOptions(VideoOptions* options) const = 0;
1159 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1160
1161 // Signal errors from MediaChannel. Arguments are:
1162 // ssrc(uint32), and error(VideoMediaChannel::Error).
1163 sigslot::signal2<uint32, Error> SignalMediaError;
1164
1165 protected:
1166 VideoRenderer *renderer_;
1167};
1168
1169enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001170 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1171 // values.
1172 DMT_NONE = 0,
1173 DMT_CONTROL = 1,
1174 DMT_BINARY = 2,
1175 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001176};
1177
1178// Info about data received in DataMediaChannel. For use in
1179// DataMediaChannel::SignalDataReceived and in all of the signals that
1180// signal fires, on up the chain.
1181struct ReceiveDataParams {
1182 // The in-packet stream indentifier.
1183 // For SCTP, this is really SID, not SSRC.
1184 uint32 ssrc;
1185 // The type of message (binary, text, or control).
1186 DataMessageType type;
1187 // A per-stream value incremented per packet in the stream.
1188 int seq_num;
1189 // A per-stream value monotonically increasing with time.
1190 int timestamp;
1191
1192 ReceiveDataParams() :
1193 ssrc(0),
1194 type(DMT_TEXT),
1195 seq_num(0),
1196 timestamp(0) {
1197 }
1198};
1199
1200struct SendDataParams {
1201 // The in-packet stream indentifier.
1202 // For SCTP, this is really SID, not SSRC.
1203 uint32 ssrc;
1204 // The type of message (binary, text, or control).
1205 DataMessageType type;
1206
1207 // For SCTP, whether to send messages flagged as ordered or not.
1208 // If false, messages can be received out of order.
1209 bool ordered;
1210 // For SCTP, whether the messages are sent reliably or not.
1211 // If false, messages may be lost.
1212 bool reliable;
1213 // For SCTP, if reliable == false, provide partial reliability by
1214 // resending up to this many times. Either count or millis
1215 // is supported, not both at the same time.
1216 int max_rtx_count;
1217 // For SCTP, if reliable == false, provide partial reliability by
1218 // resending for up to this many milliseconds. Either count or millis
1219 // is supported, not both at the same time.
1220 int max_rtx_ms;
1221
1222 SendDataParams() :
1223 ssrc(0),
1224 type(DMT_TEXT),
1225 // TODO(pthatcher): Make these true by default?
1226 ordered(false),
1227 reliable(false),
1228 max_rtx_count(0),
1229 max_rtx_ms(0) {
1230 }
1231};
1232
1233enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1234
1235class DataMediaChannel : public MediaChannel {
1236 public:
1237 enum Error {
1238 ERROR_NONE = 0, // No error.
1239 ERROR_OTHER, // Other errors.
1240 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1241 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1242 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1243 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1244 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1245 };
1246
1247 virtual ~DataMediaChannel() {}
1248
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
1250 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001251
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
1253 // TODO(pthatcher): Implement this.
1254 virtual bool GetStats(DataMediaInfo* info) { return true; }
1255
1256 virtual bool SetSend(bool send) = 0;
1257 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258
1259 virtual bool SendData(
1260 const SendDataParams& params,
1261 const talk_base::Buffer& payload,
1262 SendDataResult* result = NULL) = 0;
1263 // Signals when data is received (params, data, len)
1264 sigslot::signal3<const ReceiveDataParams&,
1265 const char*,
1266 size_t> SignalDataReceived;
1267 // Signal errors from MediaChannel. Arguments are:
1268 // ssrc(uint32), and error(DataMediaChannel::Error).
1269 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001270 // Signal when the media channel is ready to send the stream. Arguments are:
1271 // writable(bool)
1272 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273};
1274
1275} // namespace cricket
1276
1277#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_