blob: 9bdf4d9f4660c802da3a1c0c509b096fcec52be7 [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);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000174 experimental_acm.SetFrom(change.experimental_acm);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000175 tx_agc_target_dbov.SetFrom(change.tx_agc_target_dbov);
176 tx_agc_digital_compression_gain.SetFrom(
177 change.tx_agc_digital_compression_gain);
178 tx_agc_limiter.SetFrom(change.tx_agc_limiter);
179 rx_agc_target_dbov.SetFrom(change.rx_agc_target_dbov);
180 rx_agc_digital_compression_gain.SetFrom(
181 change.rx_agc_digital_compression_gain);
182 rx_agc_limiter.SetFrom(change.rx_agc_limiter);
183 recording_sample_rate.SetFrom(change.recording_sample_rate);
184 playout_sample_rate.SetFrom(change.playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000185 dscp.SetFrom(change.dscp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 }
187
188 bool operator==(const AudioOptions& o) const {
189 return echo_cancellation == o.echo_cancellation &&
190 auto_gain_control == o.auto_gain_control &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000191 rx_auto_gain_control == o.rx_auto_gain_control &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 noise_suppression == o.noise_suppression &&
193 highpass_filter == o.highpass_filter &&
194 stereo_swapping == o.stereo_swapping &&
195 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000196 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197 conference_mode == o.conference_mode &&
198 experimental_agc == o.experimental_agc &&
199 experimental_aec == o.experimental_aec &&
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000200 experimental_ns == o.experimental_ns &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000202 aec_dump == o.aec_dump &&
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000203 experimental_acm == o.experimental_acm &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000204 tx_agc_target_dbov == o.tx_agc_target_dbov &&
205 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
206 tx_agc_limiter == o.tx_agc_limiter &&
207 rx_agc_target_dbov == o.rx_agc_target_dbov &&
208 rx_agc_digital_compression_gain == o.rx_agc_digital_compression_gain &&
209 rx_agc_limiter == o.rx_agc_limiter &&
210 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000211 playout_sample_rate == o.playout_sample_rate &&
212 dscp == o.dscp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 }
214
215 std::string ToString() const {
216 std::ostringstream ost;
217 ost << "AudioOptions {";
218 ost << ToStringIfSet("aec", echo_cancellation);
219 ost << ToStringIfSet("agc", auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000220 ost << ToStringIfSet("rx_agc", rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 ost << ToStringIfSet("ns", noise_suppression);
222 ost << ToStringIfSet("hf", highpass_filter);
223 ost << ToStringIfSet("swap", stereo_swapping);
224 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000225 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 ost << ToStringIfSet("conference", conference_mode);
227 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
228 ost << ToStringIfSet("experimental_agc", experimental_agc);
229 ost << ToStringIfSet("experimental_aec", experimental_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000230 ost << ToStringIfSet("experimental_ns", experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 ost << ToStringIfSet("aec_dump", aec_dump);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000232 ost << ToStringIfSet("experimental_acm", experimental_acm);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000233 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
234 ost << ToStringIfSet("tx_agc_digital_compression_gain",
235 tx_agc_digital_compression_gain);
236 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
237 ost << ToStringIfSet("rx_agc_target_dbov", rx_agc_target_dbov);
238 ost << ToStringIfSet("rx_agc_digital_compression_gain",
239 rx_agc_digital_compression_gain);
240 ost << ToStringIfSet("rx_agc_limiter", rx_agc_limiter);
241 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
242 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000243 ost << ToStringIfSet("dscp", dscp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 ost << "}";
245 return ost.str();
246 }
247
248 // Audio processing that attempts to filter away the output signal from
249 // later inbound pickup.
250 Settable<bool> echo_cancellation;
251 // Audio processing to adjust the sensitivity of the local mic dynamically.
252 Settable<bool> auto_gain_control;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000253 // Audio processing to apply gain to the remote audio.
254 Settable<bool> rx_auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 // Audio processing to filter out background noise.
256 Settable<bool> noise_suppression;
257 // Audio processing to remove background noise of lower frequencies.
258 Settable<bool> highpass_filter;
259 // Audio processing to swap the left and right channels.
260 Settable<bool> stereo_swapping;
261 // Audio processing to detect typing.
262 Settable<bool> typing_detection;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000263 Settable<bool> aecm_generate_comfort_noise;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 Settable<bool> conference_mode;
265 Settable<int> adjust_agc_delta;
266 Settable<bool> experimental_agc;
267 Settable<bool> experimental_aec;
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000268 Settable<bool> experimental_ns;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269 Settable<bool> aec_dump;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000270 Settable<bool> experimental_acm;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000271 // Note that tx_agc_* only applies to non-experimental AGC.
272 Settable<uint16> tx_agc_target_dbov;
273 Settable<uint16> tx_agc_digital_compression_gain;
274 Settable<bool> tx_agc_limiter;
275 Settable<uint16> rx_agc_target_dbov;
276 Settable<uint16> rx_agc_digital_compression_gain;
277 Settable<bool> rx_agc_limiter;
278 Settable<uint32> recording_sample_rate;
279 Settable<uint32> playout_sample_rate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000280 // Set DSCP value for packet sent from audio channel.
281 Settable<bool> dscp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282};
283
284// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
285// Used to be flags, but that makes it hard to selectively apply options.
286// We are moving all of the setting of options to structs like this,
287// but some things currently still use flags.
288struct VideoOptions {
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000289 enum HighestBitrate {
290 NORMAL,
291 HIGH,
292 VERY_HIGH
293 };
294
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 VideoOptions() {
296 process_adaptation_threshhold.Set(kProcessCpuThreshold);
297 system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold);
298 system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000299 unsignalled_recv_stream_limit.Set(kNumDefaultUnsignalledVideoRecvStreams);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 }
301
302 void SetAll(const VideoOptions& change) {
303 adapt_input_to_encoder.SetFrom(change.adapt_input_to_encoder);
304 adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000305 adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306 adapt_view_switch.SetFrom(change.adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000307 video_adapt_third.SetFrom(change.video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 video_noise_reduction.SetFrom(change.video_noise_reduction);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 video_one_layer_screencast.SetFrom(change.video_one_layer_screencast);
310 video_high_bitrate.SetFrom(change.video_high_bitrate);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000311 video_start_bitrate.SetFrom(change.video_start_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 video_temporal_layer_screencast.SetFrom(
313 change.video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000314 video_temporal_layer_realtime.SetFrom(
315 change.video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 video_leaky_bucket.SetFrom(change.video_leaky_bucket);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000317 video_highest_bitrate.SetFrom(change.video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000318 cpu_overuse_detection.SetFrom(change.cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000319 cpu_underuse_threshold.SetFrom(change.cpu_underuse_threshold);
320 cpu_overuse_threshold.SetFrom(change.cpu_overuse_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000321 cpu_overuse_encode_usage.SetFrom(change.cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 conference_mode.SetFrom(change.conference_mode);
323 process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
324 system_low_adaptation_threshhold.SetFrom(
325 change.system_low_adaptation_threshhold);
326 system_high_adaptation_threshhold.SetFrom(
327 change.system_high_adaptation_threshhold);
328 buffered_mode_latency.SetFrom(change.buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000329 lower_min_bitrate.SetFrom(change.lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000330 dscp.SetFrom(change.dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000331 suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000332 unsignalled_recv_stream_limit.SetFrom(change.unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000333 use_simulcast_adapter.SetFrom(change.use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000334 skip_encoding_unused_streams.SetFrom(change.skip_encoding_unused_streams);
335 screencast_min_bitrate.SetFrom(change.screencast_min_bitrate);
336 use_improved_wifi_bandwidth_estimator.SetFrom(
337 change.use_improved_wifi_bandwidth_estimator);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 }
339
340 bool operator==(const VideoOptions& o) const {
341 return adapt_input_to_encoder == o.adapt_input_to_encoder &&
342 adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000343 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 adapt_view_switch == o.adapt_view_switch &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000345 video_adapt_third == o.video_adapt_third &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 video_noise_reduction == o.video_noise_reduction &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 video_one_layer_screencast == o.video_one_layer_screencast &&
348 video_high_bitrate == o.video_high_bitrate &&
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000349 video_start_bitrate == o.video_start_bitrate &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 video_temporal_layer_screencast == o.video_temporal_layer_screencast &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000351 video_temporal_layer_realtime == o.video_temporal_layer_realtime &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 video_leaky_bucket == o.video_leaky_bucket &&
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000353 video_highest_bitrate == o.video_highest_bitrate &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000354 cpu_overuse_detection == o.cpu_overuse_detection &&
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000355 cpu_underuse_threshold == o.cpu_underuse_threshold &&
356 cpu_overuse_threshold == o.cpu_overuse_threshold &&
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000357 cpu_overuse_encode_usage == o.cpu_overuse_encode_usage &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 conference_mode == o.conference_mode &&
359 process_adaptation_threshhold == o.process_adaptation_threshhold &&
360 system_low_adaptation_threshhold ==
361 o.system_low_adaptation_threshhold &&
362 system_high_adaptation_threshhold ==
363 o.system_high_adaptation_threshhold &&
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000364 buffered_mode_latency == o.buffered_mode_latency &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000365 lower_min_bitrate == o.lower_min_bitrate &&
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000366 dscp == o.dscp &&
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000367 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000368 unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit &&
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000369 use_simulcast_adapter == o.use_simulcast_adapter &&
370 skip_encoding_unused_streams == o.skip_encoding_unused_streams &&
henrike@webrtc.org5fb74282014-03-26 02:00:10 +0000371 screencast_min_bitrate == o.screencast_min_bitrate &&
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000372 use_improved_wifi_bandwidth_estimator ==
373 o.use_improved_wifi_bandwidth_estimator;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 }
375
376 std::string ToString() const {
377 std::ostringstream ost;
378 ost << "VideoOptions {";
379 ost << ToStringIfSet("encoder adaption", adapt_input_to_encoder);
380 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000381 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382 ost << ToStringIfSet("adapt view switch", adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000383 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000385 ost << ToStringIfSet("1 layer screencast", video_one_layer_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 ost << ToStringIfSet("high bitrate", video_high_bitrate);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000387 ost << ToStringIfSet("start bitrate", video_start_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 ost << ToStringIfSet("video temporal layer screencast",
389 video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000390 ost << ToStringIfSet("video temporal layer realtime",
391 video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 ost << ToStringIfSet("leaky bucket", video_leaky_bucket);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000393 ost << ToStringIfSet("highest video bitrate", video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000394 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000395 ost << ToStringIfSet("cpu underuse threshold", cpu_underuse_threshold);
396 ost << ToStringIfSet("cpu overuse threshold", cpu_overuse_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000397 ost << ToStringIfSet("cpu overuse encode usage",
398 cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399 ost << ToStringIfSet("conference mode", conference_mode);
400 ost << ToStringIfSet("process", process_adaptation_threshhold);
401 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
402 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
403 ost << ToStringIfSet("buffered mode latency", buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000404 ost << ToStringIfSet("lower min bitrate", lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000405 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000406 ost << ToStringIfSet("suspend below min bitrate",
407 suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000408 ost << ToStringIfSet("num channels for early receive",
409 unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000410 ost << ToStringIfSet("use simulcast adapter", use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000411 ost << ToStringIfSet("skip encoding unused streams",
412 skip_encoding_unused_streams);
413 ost << ToStringIfSet("screencast min bitrate", screencast_min_bitrate);
414 ost << ToStringIfSet("improved wifi bwe",
415 use_improved_wifi_bandwidth_estimator);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416 ost << "}";
417 return ost.str();
418 }
419
420 // Encoder adaption, which is the gd callback in LMI, and TBA in WebRTC.
421 Settable<bool> adapt_input_to_encoder;
422 // Enable CPU adaptation?
423 Settable<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000424 // Enable CPU adaptation smoothing?
425 Settable<bool> adapt_cpu_with_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 // Enable Adapt View Switch?
427 Settable<bool> adapt_view_switch;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000428 // Enable video adapt third?
429 Settable<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 // Enable denoising?
431 Settable<bool> video_noise_reduction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432 // Experimental: Enable one layer screencast?
433 Settable<bool> video_one_layer_screencast;
434 // Experimental: Enable WebRtc higher bitrate?
435 Settable<bool> video_high_bitrate;
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000436 // Experimental: Enable WebRtc higher start bitrate?
437 Settable<int> video_start_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438 // Experimental: Enable WebRTC layered screencast.
439 Settable<bool> video_temporal_layer_screencast;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000440 // Experimental: Enable WebRTC temporal layer strategy for realtime video.
441 Settable<bool> video_temporal_layer_realtime;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000442 // Enable WebRTC leaky bucket when sending media packets.
443 Settable<bool> video_leaky_bucket;
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000444 // Set highest bitrate mode for video.
wu@webrtc.orgcfe5e9c2014-03-27 17:03:58 +0000445 Settable<HighestBitrate> video_highest_bitrate;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000446 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
447 // adaptation algorithm. So this option will override the
448 // |adapt_input_to_cpu_usage|.
449 Settable<bool> cpu_overuse_detection;
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000450 // Low threshold for cpu overuse adaptation in ms. (Adapt up)
451 Settable<int> cpu_underuse_threshold;
452 // High threshold for cpu overuse adaptation in ms. (Adapt down)
453 Settable<int> cpu_overuse_threshold;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000454 // Use encode usage for cpu detection.
455 Settable<bool> cpu_overuse_encode_usage;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456 // Use conference mode?
457 Settable<bool> conference_mode;
458 // Threshhold for process cpu adaptation. (Process limit)
459 SettablePercent process_adaptation_threshhold;
460 // Low threshhold for cpu adaptation. (Adapt up)
461 SettablePercent system_low_adaptation_threshhold;
462 // High threshhold for cpu adaptation. (Adapt down)
463 SettablePercent system_high_adaptation_threshhold;
464 // Specify buffered mode latency in milliseconds.
465 Settable<int> buffered_mode_latency;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000466 // Make minimum configured send bitrate even lower than usual, at 30kbit.
467 Settable<bool> lower_min_bitrate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000468 // Set DSCP value for packet sent from video channel.
469 Settable<bool> dscp;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000470 // Enable WebRTC suspension of video. No video frames will be sent when the
471 // bitrate is below the configured minimum bitrate.
472 Settable<bool> suspend_below_min_bitrate;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000473 // Limit on the number of early receive channels that can be created.
474 Settable<int> unsignalled_recv_stream_limit;
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000475 // Enable use of simulcast adapter.
476 Settable<bool> use_simulcast_adapter;
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000477 // Enables the encoder to skip encoding stream not actually sent due to too
478 // low available bit rate.
479 Settable<bool> skip_encoding_unused_streams;
480 // Force screencast to use a minimum bitrate
481 Settable<int> screencast_min_bitrate;
482 // Enable improved bandwidth estiamtor on wifi.
483 Settable<bool> use_improved_wifi_bandwidth_estimator;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484};
485
486// A class for playing out soundclips.
487class SoundclipMedia {
488 public:
489 enum SoundclipFlags {
490 SF_LOOP = 1,
491 };
492
493 virtual ~SoundclipMedia() {}
494
495 // Plays a sound out to the speakers with the given audio stream. The stream
496 // must be 16-bit little-endian 16 kHz PCM. If a stream is already playing
497 // on this SoundclipMedia, it is stopped. If clip is NULL, nothing is played.
498 // Returns whether it was successful.
499 virtual bool PlaySound(const char *clip, int len, int flags) = 0;
500};
501
502struct RtpHeaderExtension {
503 RtpHeaderExtension() : id(0) {}
504 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
505 std::string uri;
506 int id;
507 // TODO(juberti): SendRecv direction;
508
509 bool operator==(const RtpHeaderExtension& ext) const {
510 // id is a reserved word in objective-c. Therefore the id attribute has to
511 // be a fully qualified name in order to compile on IOS.
512 return this->id == ext.id &&
513 uri == ext.uri;
514 }
515};
516
517// Returns the named header extension if found among all extensions, NULL
518// otherwise.
519inline const RtpHeaderExtension* FindHeaderExtension(
520 const std::vector<RtpHeaderExtension>& extensions,
521 const std::string& name) {
522 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
523 it != extensions.end(); ++it) {
524 if (it->uri == name)
525 return &(*it);
526 }
527 return NULL;
528}
529
530enum MediaChannelOptions {
531 // Tune the stream for conference mode.
532 OPT_CONFERENCE = 0x0001
533};
534
535enum VoiceMediaChannelOptions {
536 // Tune the audio stream for vcs with different target levels.
537 OPT_AGC_MINUS_10DB = 0x80000000
538};
539
540// DTMF flags to control if a DTMF tone should be played and/or sent.
541enum DtmfFlags {
542 DF_PLAY = 0x01,
543 DF_SEND = 0x02,
544};
545
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546class MediaChannel : public sigslot::has_slots<> {
547 public:
548 class NetworkInterface {
549 public:
550 enum SocketType { ST_RTP, ST_RTCP };
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000551 virtual bool SendPacket(
552 talk_base::Buffer* packet,
553 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
554 virtual bool SendRtcp(
555 talk_base::Buffer* packet,
556 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 virtual int SetOption(SocketType type, talk_base::Socket::Option opt,
558 int option) = 0;
559 virtual ~NetworkInterface() {}
560 };
561
562 MediaChannel() : network_interface_(NULL) {}
563 virtual ~MediaChannel() {}
564
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000565 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 virtual void SetInterface(NetworkInterface *iface) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000567 talk_base::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 network_interface_ = iface;
569 }
570
571 // Called when a RTP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000572 virtual void OnPacketReceived(talk_base::Buffer* packet,
573 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 // Called when a RTCP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000575 virtual void OnRtcpReceived(talk_base::Buffer* packet,
576 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000577 // Called when the socket's ability to send has changed.
578 virtual void OnReadyToSend(bool ready) = 0;
579 // Creates a new outgoing media stream with SSRCs and CNAME as described
580 // by sp.
581 virtual bool AddSendStream(const StreamParams& sp) = 0;
582 // Removes an outgoing media stream.
583 // ssrc must be the first SSRC of the media stream if the stream uses
584 // multiple SSRCs.
585 virtual bool RemoveSendStream(uint32 ssrc) = 0;
586 // Creates a new incoming media stream with SSRCs and CNAME as described
587 // by sp.
588 virtual bool AddRecvStream(const StreamParams& sp) = 0;
589 // Removes an incoming media stream.
590 // ssrc must be the first SSRC of the media stream if the stream uses
591 // multiple SSRCs.
592 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
593
594 // Mutes the channel.
595 virtual bool MuteStream(uint32 ssrc, bool on) = 0;
596
597 // Sets the RTP extension headers and IDs to use when sending RTP.
598 virtual bool SetRecvRtpHeaderExtensions(
599 const std::vector<RtpHeaderExtension>& extensions) = 0;
600 virtual bool SetSendRtpHeaderExtensions(
601 const std::vector<RtpHeaderExtension>& extensions) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000602 // Returns the absoulte sendtime extension id value from media channel.
603 virtual int GetRtpSendTimeExtnId() const {
604 return -1;
605 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000606 // Sets the initial bandwidth to use when sending starts.
607 virtual bool SetStartSendBandwidth(int bps) = 0;
608 // Sets the maximum allowed bandwidth to use when sending data.
609 virtual bool SetMaxSendBandwidth(int bps) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000611 // Base method to send packet using NetworkInterface.
612 bool SendPacket(talk_base::Buffer* packet) {
613 return DoSendPacket(packet, false);
614 }
615
616 bool SendRtcp(talk_base::Buffer* packet) {
617 return DoSendPacket(packet, true);
618 }
619
620 int SetOption(NetworkInterface::SocketType type,
621 talk_base::Socket::Option opt,
622 int option) {
623 talk_base::CritScope cs(&network_interface_crit_);
624 if (!network_interface_)
625 return -1;
626
627 return network_interface_->SetOption(type, opt, option);
628 }
629
wu@webrtc.orgde305012013-10-31 15:40:38 +0000630 protected:
631 // This method sets DSCP |value| on both RTP and RTCP channels.
632 int SetDscp(talk_base::DiffServCodePoint value) {
633 int ret;
634 ret = SetOption(NetworkInterface::ST_RTP,
635 talk_base::Socket::OPT_DSCP,
636 value);
637 if (ret == 0) {
638 ret = SetOption(NetworkInterface::ST_RTCP,
639 talk_base::Socket::OPT_DSCP,
640 value);
641 }
642 return ret;
643 }
644
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000645 private:
646 bool DoSendPacket(talk_base::Buffer* packet, bool rtcp) {
647 talk_base::CritScope cs(&network_interface_crit_);
648 if (!network_interface_)
649 return false;
650
651 return (!rtcp) ? network_interface_->SendPacket(packet) :
652 network_interface_->SendRtcp(packet);
653 }
654
655 // |network_interface_| can be accessed from the worker_thread and
656 // from any MediaEngine threads. This critical section is to protect accessing
657 // of network_interface_ object.
658 talk_base::CriticalSection network_interface_crit_;
659 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660};
661
662enum SendFlags {
663 SEND_NOTHING,
664 SEND_RINGBACKTONE,
665 SEND_MICROPHONE
666};
667
wu@webrtc.org97077a32013-10-25 21:18:33 +0000668// The stats information is structured as follows:
669// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
670// Media contains a vector of SSRC infos that are exclusively used by this
671// media. (SSRCs shared between media streams can't be represented.)
672
673// Information about an SSRC.
674// This data may be locally recorded, or received in an RTCP SR or RR.
675struct SsrcSenderInfo {
676 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000678 timestamp(0) {
679 }
680 uint32 ssrc;
681 double timestamp; // NTP timestamp, represented as seconds since epoch.
682};
683
684struct SsrcReceiverInfo {
685 SsrcReceiverInfo()
686 : ssrc(0),
687 timestamp(0) {
688 }
689 uint32 ssrc;
690 double timestamp;
691};
692
693struct MediaSenderInfo {
694 MediaSenderInfo()
695 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696 packets_sent(0),
697 packets_lost(0),
698 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000699 rtt_ms(0) {
700 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000701 void add_ssrc(const SsrcSenderInfo& stat) {
702 local_stats.push_back(stat);
703 }
704 // Temporary utility function for call sites that only provide SSRC.
705 // As more info is added into SsrcSenderInfo, this function should go away.
706 void add_ssrc(uint32 ssrc) {
707 SsrcSenderInfo stat;
708 stat.ssrc = ssrc;
709 add_ssrc(stat);
710 }
711 // Utility accessor for clients that are only interested in ssrc numbers.
712 std::vector<uint32> ssrcs() const {
713 std::vector<uint32> retval;
714 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
715 it != local_stats.end(); ++it) {
716 retval.push_back(it->ssrc);
717 }
718 return retval;
719 }
720 // Utility accessor for clients that make the assumption only one ssrc
721 // exists per media.
722 // This will eventually go away.
723 uint32 ssrc() const {
724 if (local_stats.size() > 0) {
725 return local_stats[0].ssrc;
726 } else {
727 return 0;
728 }
729 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000730 int64 bytes_sent;
731 int packets_sent;
732 int packets_lost;
733 float fraction_lost;
734 int rtt_ms;
735 std::string codec_name;
736 std::vector<SsrcSenderInfo> local_stats;
737 std::vector<SsrcReceiverInfo> remote_stats;
738};
739
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000740template<class T>
741struct VariableInfo {
742 VariableInfo()
743 : min_val(),
744 mean(0.0),
745 max_val(),
746 variance(0.0) {
747 }
748 T min_val;
749 double mean;
750 T max_val;
751 double variance;
752};
753
wu@webrtc.org97077a32013-10-25 21:18:33 +0000754struct MediaReceiverInfo {
755 MediaReceiverInfo()
756 : bytes_rcvd(0),
757 packets_rcvd(0),
758 packets_lost(0),
759 fraction_lost(0.0) {
760 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000761 void add_ssrc(const SsrcReceiverInfo& stat) {
762 local_stats.push_back(stat);
763 }
764 // Temporary utility function for call sites that only provide SSRC.
765 // As more info is added into SsrcSenderInfo, this function should go away.
766 void add_ssrc(uint32 ssrc) {
767 SsrcReceiverInfo stat;
768 stat.ssrc = ssrc;
769 add_ssrc(stat);
770 }
771 std::vector<uint32> ssrcs() const {
772 std::vector<uint32> retval;
773 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
774 it != local_stats.end(); ++it) {
775 retval.push_back(it->ssrc);
776 }
777 return retval;
778 }
779 // Utility accessor for clients that make the assumption only one ssrc
780 // exists per media.
781 // This will eventually go away.
782 uint32 ssrc() const {
783 if (local_stats.size() > 0) {
784 return local_stats[0].ssrc;
785 } else {
786 return 0;
787 }
788 }
789
wu@webrtc.org97077a32013-10-25 21:18:33 +0000790 int64 bytes_rcvd;
791 int packets_rcvd;
792 int packets_lost;
793 float fraction_lost;
794 std::vector<SsrcReceiverInfo> local_stats;
795 std::vector<SsrcSenderInfo> remote_stats;
796};
797
798struct VoiceSenderInfo : public MediaSenderInfo {
799 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000800 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 jitter_ms(0),
802 audio_level(0),
803 aec_quality_min(0.0),
804 echo_delay_median_ms(0),
805 echo_delay_std_ms(0),
806 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000807 echo_return_loss_enhancement(0),
808 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 }
810
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 int jitter_ms;
813 int audio_level;
814 float aec_quality_min;
815 int echo_delay_median_ms;
816 int echo_delay_std_ms;
817 int echo_return_loss;
818 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000819 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820};
821
wu@webrtc.org97077a32013-10-25 21:18:33 +0000822struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000824 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 jitter_ms(0),
826 jitter_buffer_ms(0),
827 jitter_buffer_preferred_ms(0),
828 delay_estimate_ms(0),
829 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000830 expand_rate(0),
831 decoding_calls_to_silence_generator(0),
832 decoding_calls_to_neteq(0),
833 decoding_normal(0),
834 decoding_plc(0),
835 decoding_cng(0),
836 decoding_plc_cng(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 }
838
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 int ext_seqnum;
840 int jitter_ms;
841 int jitter_buffer_ms;
842 int jitter_buffer_preferred_ms;
843 int delay_estimate_ms;
844 int audio_level;
845 // fraction of synthesized speech inserted through pre-emptive expansion
846 float expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000847 int decoding_calls_to_silence_generator;
848 int decoding_calls_to_neteq;
849 int decoding_normal;
850 int decoding_plc;
851 int decoding_cng;
852 int decoding_plc_cng;
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),
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +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;
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +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),
918 current_delay_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 }
920
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000924 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 int nacks_sent;
926 int frame_width;
927 int frame_height;
928 int framerate_rcvd;
929 int framerate_decoded;
930 int framerate_output;
931 // Framerate as sent to the renderer.
932 int framerate_render_input;
933 // Framerate that the renderer reports.
934 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000935
936 // All stats below are gathered per-VideoReceiver, but some will be correlated
937 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
938 // structures, reflect this in the new layout.
939
940 // Current frame decode latency.
941 int decode_ms;
942 // Maximum observed frame decode latency.
943 int max_decode_ms;
944 // Jitter (network-related) latency.
945 int jitter_buffer_ms;
946 // Requested minimum playout latency.
947 int min_playout_delay_ms;
948 // Requested latency to account for rendering delay.
949 int render_delay_ms;
950 // Target overall delay: network+decode+render, accounting for
951 // min_playout_delay_ms.
952 int target_delay_ms;
953 // Current overall delay, possibly ramping towards target_delay_ms.
954 int current_delay_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955};
956
wu@webrtc.org97077a32013-10-25 21:18:33 +0000957struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000959 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 }
961
962 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963};
964
wu@webrtc.org97077a32013-10-25 21:18:33 +0000965struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000967 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 }
969
970 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971};
972
973struct BandwidthEstimationInfo {
974 BandwidthEstimationInfo()
975 : available_send_bandwidth(0),
976 available_recv_bandwidth(0),
977 target_enc_bitrate(0),
978 actual_enc_bitrate(0),
979 retransmit_bitrate(0),
980 transmit_bitrate(0),
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000981 bucket_delay(0),
982 total_received_propagation_delta_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 }
984
985 int available_send_bandwidth;
986 int available_recv_bandwidth;
987 int target_enc_bitrate;
988 int actual_enc_bitrate;
989 int retransmit_bitrate;
990 int transmit_bitrate;
991 int bucket_delay;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000992 // The following stats are only valid when
993 // StatsOptions::include_received_propagation_stats is true.
994 int total_received_propagation_delta_ms;
995 std::vector<int> recent_received_propagation_delta_ms;
996 std::vector<int64> recent_received_packet_group_arrival_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997};
998
999struct VoiceMediaInfo {
1000 void Clear() {
1001 senders.clear();
1002 receivers.clear();
1003 }
1004 std::vector<VoiceSenderInfo> senders;
1005 std::vector<VoiceReceiverInfo> receivers;
1006};
1007
1008struct VideoMediaInfo {
1009 void Clear() {
1010 senders.clear();
1011 receivers.clear();
1012 bw_estimations.clear();
1013 }
1014 std::vector<VideoSenderInfo> senders;
1015 std::vector<VideoReceiverInfo> receivers;
1016 std::vector<BandwidthEstimationInfo> bw_estimations;
1017};
1018
1019struct DataMediaInfo {
1020 void Clear() {
1021 senders.clear();
1022 receivers.clear();
1023 }
1024 std::vector<DataSenderInfo> senders;
1025 std::vector<DataReceiverInfo> receivers;
1026};
1027
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001028struct StatsOptions {
1029 StatsOptions() : include_received_propagation_stats(false) {}
1030
1031 bool include_received_propagation_stats;
1032};
1033
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034class VoiceMediaChannel : public MediaChannel {
1035 public:
1036 enum Error {
1037 ERROR_NONE = 0, // No error.
1038 ERROR_OTHER, // Other errors.
1039 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
1040 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
1041 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
1042 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
1043 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
1044 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
1045 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
1046 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1047 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
1048 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
1049 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
1050 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
1051 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
1052 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
1053 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1054 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1055 };
1056
1057 VoiceMediaChannel() {}
1058 virtual ~VoiceMediaChannel() {}
1059 // Sets the codecs/payload types to be used for incoming media.
1060 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
1061 // Sets the codecs/payload types to be used for outgoing media.
1062 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
1063 // Starts or stops playout of received audio.
1064 virtual bool SetPlayout(bool playout) = 0;
1065 // Starts or stops sending (and potentially capture) of local audio.
1066 virtual bool SetSend(SendFlags flag) = 0;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001067 // Sets the renderer object to be used for the specified remote audio stream.
1068 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
1069 // Sets the renderer object to be used for the specified local audio stream.
1070 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071 // Gets current energy levels for all incoming streams.
1072 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1073 // Get the current energy level of the stream sent to the speaker.
1074 virtual int GetOutputLevel() = 0;
1075 // Get the time in milliseconds since last recorded keystroke, or negative.
1076 virtual int GetTimeSinceLastTyping() = 0;
1077 // Temporarily exposed field for tuning typing detect options.
1078 virtual void SetTypingDetectionParameters(int time_window,
1079 int cost_per_typing, int reporting_threshold, int penalty_decay,
1080 int type_event_delay) = 0;
1081 // Set left and right scale for speaker output volume of the specified ssrc.
1082 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
1083 // Get left and right scale for speaker output volume of the specified ssrc.
1084 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0;
1085 // Specifies a ringback tone to be played during call setup.
1086 virtual bool SetRingbackTone(const char *buf, int len) = 0;
1087 // Plays or stops the aforementioned ringback tone
1088 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
1089 // Returns if the telephone-event has been negotiated.
1090 virtual bool CanInsertDtmf() { return false; }
1091 // Send and/or play a DTMF |event| according to the |flags|.
1092 // The DTMF out-of-band signal will be used on sending.
1093 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001094 // The valid value for the |event| are 0 to 15 which corresponding to
1095 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
1097 // Gets quality stats for the channel.
1098 virtual bool GetStats(VoiceMediaInfo* info) = 0;
1099 // Gets last reported error for this media channel.
1100 virtual void GetLastMediaError(uint32* ssrc,
1101 VoiceMediaChannel::Error* error) {
1102 ASSERT(error != NULL);
1103 *error = ERROR_NONE;
1104 }
1105 // Sets the media options to use.
1106 virtual bool SetOptions(const AudioOptions& options) = 0;
1107 virtual bool GetOptions(AudioOptions* options) const = 0;
1108
1109 // Signal errors from MediaChannel. Arguments are:
1110 // ssrc(uint32), and error(VoiceMediaChannel::Error).
1111 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
1112};
1113
1114class VideoMediaChannel : public MediaChannel {
1115 public:
1116 enum Error {
1117 ERROR_NONE = 0, // No error.
1118 ERROR_OTHER, // Other errors.
1119 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1120 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1121 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1122 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1123 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1124 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1125 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1126 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1127 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1128 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1129 };
1130
1131 VideoMediaChannel() : renderer_(NULL) {}
1132 virtual ~VideoMediaChannel() {}
1133 // Sets the codecs/payload types to be used for incoming media.
1134 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
1135 // Sets the codecs/payload types to be used for outgoing media.
1136 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
1137 // Gets the currently set codecs/payload types to be used for outgoing media.
1138 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1139 // Sets the format of a specified outgoing stream.
1140 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
1141 // Starts or stops playout of received video.
1142 virtual bool SetRender(bool render) = 0;
1143 // Starts or stops transmission (and potentially capture) of local video.
1144 virtual bool SetSend(bool send) = 0;
1145 // Sets the renderer object to be used for the specified stream.
1146 // If SSRC is 0, the renderer is used for the 'default' stream.
1147 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
1148 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1149 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
1150 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
1151 // Gets quality stats for the channel.
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001152 virtual bool GetStats(const StatsOptions& options, VideoMediaInfo* info) = 0;
1153 // This is needed for MediaMonitor to use the same template for voice, video
1154 // and data MediaChannels.
1155 bool GetStats(VideoMediaInfo* info) {
1156 return GetStats(StatsOptions(), info);
1157 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158
1159 // Send an intra frame to the receivers.
1160 virtual bool SendIntraFrame() = 0;
1161 // Reuqest each of the remote senders to send an intra frame.
1162 virtual bool RequestIntraFrame() = 0;
1163 // Sets the media options to use.
1164 virtual bool SetOptions(const VideoOptions& options) = 0;
1165 virtual bool GetOptions(VideoOptions* options) const = 0;
1166 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1167
1168 // Signal errors from MediaChannel. Arguments are:
1169 // ssrc(uint32), and error(VideoMediaChannel::Error).
1170 sigslot::signal2<uint32, Error> SignalMediaError;
1171
1172 protected:
1173 VideoRenderer *renderer_;
1174};
1175
1176enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001177 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1178 // values.
1179 DMT_NONE = 0,
1180 DMT_CONTROL = 1,
1181 DMT_BINARY = 2,
1182 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001183};
1184
1185// Info about data received in DataMediaChannel. For use in
1186// DataMediaChannel::SignalDataReceived and in all of the signals that
1187// signal fires, on up the chain.
1188struct ReceiveDataParams {
1189 // The in-packet stream indentifier.
1190 // For SCTP, this is really SID, not SSRC.
1191 uint32 ssrc;
1192 // The type of message (binary, text, or control).
1193 DataMessageType type;
1194 // A per-stream value incremented per packet in the stream.
1195 int seq_num;
1196 // A per-stream value monotonically increasing with time.
1197 int timestamp;
1198
1199 ReceiveDataParams() :
1200 ssrc(0),
1201 type(DMT_TEXT),
1202 seq_num(0),
1203 timestamp(0) {
1204 }
1205};
1206
1207struct SendDataParams {
1208 // The in-packet stream indentifier.
1209 // For SCTP, this is really SID, not SSRC.
1210 uint32 ssrc;
1211 // The type of message (binary, text, or control).
1212 DataMessageType type;
1213
1214 // For SCTP, whether to send messages flagged as ordered or not.
1215 // If false, messages can be received out of order.
1216 bool ordered;
1217 // For SCTP, whether the messages are sent reliably or not.
1218 // If false, messages may be lost.
1219 bool reliable;
1220 // For SCTP, if reliable == false, provide partial reliability by
1221 // resending up to this many times. Either count or millis
1222 // is supported, not both at the same time.
1223 int max_rtx_count;
1224 // For SCTP, if reliable == false, provide partial reliability by
1225 // resending for up to this many milliseconds. Either count or millis
1226 // is supported, not both at the same time.
1227 int max_rtx_ms;
1228
1229 SendDataParams() :
1230 ssrc(0),
1231 type(DMT_TEXT),
1232 // TODO(pthatcher): Make these true by default?
1233 ordered(false),
1234 reliable(false),
1235 max_rtx_count(0),
1236 max_rtx_ms(0) {
1237 }
1238};
1239
1240enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1241
1242class DataMediaChannel : public MediaChannel {
1243 public:
1244 enum Error {
1245 ERROR_NONE = 0, // No error.
1246 ERROR_OTHER, // Other errors.
1247 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1248 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1249 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1250 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1251 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1252 };
1253
1254 virtual ~DataMediaChannel() {}
1255
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
1257 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001258
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
1260 // TODO(pthatcher): Implement this.
1261 virtual bool GetStats(DataMediaInfo* info) { return true; }
1262
1263 virtual bool SetSend(bool send) = 0;
1264 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265
1266 virtual bool SendData(
1267 const SendDataParams& params,
1268 const talk_base::Buffer& payload,
1269 SendDataResult* result = NULL) = 0;
1270 // Signals when data is received (params, data, len)
1271 sigslot::signal3<const ReceiveDataParams&,
1272 const char*,
1273 size_t> SignalDataReceived;
1274 // Signal errors from MediaChannel. Arguments are:
1275 // ssrc(uint32), and error(DataMediaChannel::Error).
1276 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001277 // Signal when the media channel is ready to send the stream. Arguments are:
1278 // writable(bool)
1279 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280};
1281
1282} // namespace cricket
1283
1284#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_