blob: 0af14a961cfa082675d45387b1b19c4747b7ac47 [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 {
288 VideoOptions() {
289 process_adaptation_threshhold.Set(kProcessCpuThreshold);
290 system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold);
291 system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000292 unsignalled_recv_stream_limit.Set(kNumDefaultUnsignalledVideoRecvStreams);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293 }
294
295 void SetAll(const VideoOptions& change) {
296 adapt_input_to_encoder.SetFrom(change.adapt_input_to_encoder);
297 adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000298 adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 adapt_view_switch.SetFrom(change.adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000300 video_adapt_third.SetFrom(change.video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301 video_noise_reduction.SetFrom(change.video_noise_reduction);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 video_one_layer_screencast.SetFrom(change.video_one_layer_screencast);
303 video_high_bitrate.SetFrom(change.video_high_bitrate);
304 video_watermark.SetFrom(change.video_watermark);
305 video_temporal_layer_screencast.SetFrom(
306 change.video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000307 video_temporal_layer_realtime.SetFrom(
308 change.video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 video_leaky_bucket.SetFrom(change.video_leaky_bucket);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000310 cpu_overuse_detection.SetFrom(change.cpu_overuse_detection);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 conference_mode.SetFrom(change.conference_mode);
312 process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
313 system_low_adaptation_threshhold.SetFrom(
314 change.system_low_adaptation_threshhold);
315 system_high_adaptation_threshhold.SetFrom(
316 change.system_high_adaptation_threshhold);
317 buffered_mode_latency.SetFrom(change.buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000318 lower_min_bitrate.SetFrom(change.lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000319 dscp.SetFrom(change.dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000320 suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000321 unsignalled_recv_stream_limit.SetFrom(change.unsignalled_recv_stream_limit);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 }
323
324 bool operator==(const VideoOptions& o) const {
325 return adapt_input_to_encoder == o.adapt_input_to_encoder &&
326 adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000327 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 adapt_view_switch == o.adapt_view_switch &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000329 video_adapt_third == o.video_adapt_third &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 video_noise_reduction == o.video_noise_reduction &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 video_one_layer_screencast == o.video_one_layer_screencast &&
332 video_high_bitrate == o.video_high_bitrate &&
333 video_watermark == o.video_watermark &&
334 video_temporal_layer_screencast == o.video_temporal_layer_screencast &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000335 video_temporal_layer_realtime == o.video_temporal_layer_realtime &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336 video_leaky_bucket == o.video_leaky_bucket &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000337 cpu_overuse_detection == o.cpu_overuse_detection &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 conference_mode == o.conference_mode &&
339 process_adaptation_threshhold == o.process_adaptation_threshhold &&
340 system_low_adaptation_threshhold ==
341 o.system_low_adaptation_threshhold &&
342 system_high_adaptation_threshhold ==
343 o.system_high_adaptation_threshhold &&
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000344 buffered_mode_latency == o.buffered_mode_latency &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000345 lower_min_bitrate == o.lower_min_bitrate &&
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000346 dscp == o.dscp &&
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000347 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
348 unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
350
351 std::string ToString() const {
352 std::ostringstream ost;
353 ost << "VideoOptions {";
354 ost << ToStringIfSet("encoder adaption", adapt_input_to_encoder);
355 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000356 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 ost << ToStringIfSet("adapt view switch", adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000358 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000360 ost << ToStringIfSet("1 layer screencast", video_one_layer_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 ost << ToStringIfSet("high bitrate", video_high_bitrate);
362 ost << ToStringIfSet("watermark", video_watermark);
363 ost << ToStringIfSet("video temporal layer screencast",
364 video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000365 ost << ToStringIfSet("video temporal layer realtime",
366 video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 ost << ToStringIfSet("leaky bucket", video_leaky_bucket);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000368 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 ost << ToStringIfSet("conference mode", conference_mode);
370 ost << ToStringIfSet("process", process_adaptation_threshhold);
371 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
372 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
373 ost << ToStringIfSet("buffered mode latency", buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000374 ost << ToStringIfSet("lower min bitrate", lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000375 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000376 ost << ToStringIfSet("suspend below min bitrate",
377 suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000378 ost << ToStringIfSet("num channels for early receive",
379 unsignalled_recv_stream_limit);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 ost << "}";
381 return ost.str();
382 }
383
384 // Encoder adaption, which is the gd callback in LMI, and TBA in WebRTC.
385 Settable<bool> adapt_input_to_encoder;
386 // Enable CPU adaptation?
387 Settable<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000388 // Enable CPU adaptation smoothing?
389 Settable<bool> adapt_cpu_with_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 // Enable Adapt View Switch?
391 Settable<bool> adapt_view_switch;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000392 // Enable video adapt third?
393 Settable<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394 // Enable denoising?
395 Settable<bool> video_noise_reduction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396 // Experimental: Enable one layer screencast?
397 Settable<bool> video_one_layer_screencast;
398 // Experimental: Enable WebRtc higher bitrate?
399 Settable<bool> video_high_bitrate;
400 // Experimental: Add watermark to the rendered video image.
401 Settable<bool> video_watermark;
402 // Experimental: Enable WebRTC layered screencast.
403 Settable<bool> video_temporal_layer_screencast;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000404 // Experimental: Enable WebRTC temporal layer strategy for realtime video.
405 Settable<bool> video_temporal_layer_realtime;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000406 // Enable WebRTC leaky bucket when sending media packets.
407 Settable<bool> video_leaky_bucket;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000408 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
409 // adaptation algorithm. So this option will override the
410 // |adapt_input_to_cpu_usage|.
411 Settable<bool> cpu_overuse_detection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 // Use conference mode?
413 Settable<bool> conference_mode;
414 // Threshhold for process cpu adaptation. (Process limit)
415 SettablePercent process_adaptation_threshhold;
416 // Low threshhold for cpu adaptation. (Adapt up)
417 SettablePercent system_low_adaptation_threshhold;
418 // High threshhold for cpu adaptation. (Adapt down)
419 SettablePercent system_high_adaptation_threshhold;
420 // Specify buffered mode latency in milliseconds.
421 Settable<int> buffered_mode_latency;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000422 // Make minimum configured send bitrate even lower than usual, at 30kbit.
423 Settable<bool> lower_min_bitrate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000424 // Set DSCP value for packet sent from video channel.
425 Settable<bool> dscp;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000426 // Enable WebRTC suspension of video. No video frames will be sent when the
427 // bitrate is below the configured minimum bitrate.
428 Settable<bool> suspend_below_min_bitrate;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000429 // Limit on the number of early receive channels that can be created.
430 Settable<int> unsignalled_recv_stream_limit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431};
432
433// A class for playing out soundclips.
434class SoundclipMedia {
435 public:
436 enum SoundclipFlags {
437 SF_LOOP = 1,
438 };
439
440 virtual ~SoundclipMedia() {}
441
442 // Plays a sound out to the speakers with the given audio stream. The stream
443 // must be 16-bit little-endian 16 kHz PCM. If a stream is already playing
444 // on this SoundclipMedia, it is stopped. If clip is NULL, nothing is played.
445 // Returns whether it was successful.
446 virtual bool PlaySound(const char *clip, int len, int flags) = 0;
447};
448
449struct RtpHeaderExtension {
450 RtpHeaderExtension() : id(0) {}
451 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
452 std::string uri;
453 int id;
454 // TODO(juberti): SendRecv direction;
455
456 bool operator==(const RtpHeaderExtension& ext) const {
457 // id is a reserved word in objective-c. Therefore the id attribute has to
458 // be a fully qualified name in order to compile on IOS.
459 return this->id == ext.id &&
460 uri == ext.uri;
461 }
462};
463
464// Returns the named header extension if found among all extensions, NULL
465// otherwise.
466inline const RtpHeaderExtension* FindHeaderExtension(
467 const std::vector<RtpHeaderExtension>& extensions,
468 const std::string& name) {
469 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
470 it != extensions.end(); ++it) {
471 if (it->uri == name)
472 return &(*it);
473 }
474 return NULL;
475}
476
477enum MediaChannelOptions {
478 // Tune the stream for conference mode.
479 OPT_CONFERENCE = 0x0001
480};
481
482enum VoiceMediaChannelOptions {
483 // Tune the audio stream for vcs with different target levels.
484 OPT_AGC_MINUS_10DB = 0x80000000
485};
486
487// DTMF flags to control if a DTMF tone should be played and/or sent.
488enum DtmfFlags {
489 DF_PLAY = 0x01,
490 DF_SEND = 0x02,
491};
492
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493class MediaChannel : public sigslot::has_slots<> {
494 public:
495 class NetworkInterface {
496 public:
497 enum SocketType { ST_RTP, ST_RTCP };
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000498 virtual bool SendPacket(
499 talk_base::Buffer* packet,
500 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
501 virtual bool SendRtcp(
502 talk_base::Buffer* packet,
503 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504 virtual int SetOption(SocketType type, talk_base::Socket::Option opt,
505 int option) = 0;
506 virtual ~NetworkInterface() {}
507 };
508
509 MediaChannel() : network_interface_(NULL) {}
510 virtual ~MediaChannel() {}
511
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000512 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513 virtual void SetInterface(NetworkInterface *iface) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000514 talk_base::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 network_interface_ = iface;
516 }
517
518 // Called when a RTP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000519 virtual void OnPacketReceived(talk_base::Buffer* packet,
520 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 // Called when a RTCP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000522 virtual void OnRtcpReceived(talk_base::Buffer* packet,
523 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 // Called when the socket's ability to send has changed.
525 virtual void OnReadyToSend(bool ready) = 0;
526 // Creates a new outgoing media stream with SSRCs and CNAME as described
527 // by sp.
528 virtual bool AddSendStream(const StreamParams& sp) = 0;
529 // Removes an outgoing media stream.
530 // ssrc must be the first SSRC of the media stream if the stream uses
531 // multiple SSRCs.
532 virtual bool RemoveSendStream(uint32 ssrc) = 0;
533 // Creates a new incoming media stream with SSRCs and CNAME as described
534 // by sp.
535 virtual bool AddRecvStream(const StreamParams& sp) = 0;
536 // Removes an incoming media stream.
537 // ssrc must be the first SSRC of the media stream if the stream uses
538 // multiple SSRCs.
539 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
540
541 // Mutes the channel.
542 virtual bool MuteStream(uint32 ssrc, bool on) = 0;
543
544 // Sets the RTP extension headers and IDs to use when sending RTP.
545 virtual bool SetRecvRtpHeaderExtensions(
546 const std::vector<RtpHeaderExtension>& extensions) = 0;
547 virtual bool SetSendRtpHeaderExtensions(
548 const std::vector<RtpHeaderExtension>& extensions) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000549 // Returns the absoulte sendtime extension id value from media channel.
550 virtual int GetRtpSendTimeExtnId() const {
551 return -1;
552 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000553 // Sets the initial bandwidth to use when sending starts.
554 virtual bool SetStartSendBandwidth(int bps) = 0;
555 // Sets the maximum allowed bandwidth to use when sending data.
556 virtual bool SetMaxSendBandwidth(int bps) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000558 // Base method to send packet using NetworkInterface.
559 bool SendPacket(talk_base::Buffer* packet) {
560 return DoSendPacket(packet, false);
561 }
562
563 bool SendRtcp(talk_base::Buffer* packet) {
564 return DoSendPacket(packet, true);
565 }
566
567 int SetOption(NetworkInterface::SocketType type,
568 talk_base::Socket::Option opt,
569 int option) {
570 talk_base::CritScope cs(&network_interface_crit_);
571 if (!network_interface_)
572 return -1;
573
574 return network_interface_->SetOption(type, opt, option);
575 }
576
wu@webrtc.orgde305012013-10-31 15:40:38 +0000577 protected:
578 // This method sets DSCP |value| on both RTP and RTCP channels.
579 int SetDscp(talk_base::DiffServCodePoint value) {
580 int ret;
581 ret = SetOption(NetworkInterface::ST_RTP,
582 talk_base::Socket::OPT_DSCP,
583 value);
584 if (ret == 0) {
585 ret = SetOption(NetworkInterface::ST_RTCP,
586 talk_base::Socket::OPT_DSCP,
587 value);
588 }
589 return ret;
590 }
591
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000592 private:
593 bool DoSendPacket(talk_base::Buffer* packet, bool rtcp) {
594 talk_base::CritScope cs(&network_interface_crit_);
595 if (!network_interface_)
596 return false;
597
598 return (!rtcp) ? network_interface_->SendPacket(packet) :
599 network_interface_->SendRtcp(packet);
600 }
601
602 // |network_interface_| can be accessed from the worker_thread and
603 // from any MediaEngine threads. This critical section is to protect accessing
604 // of network_interface_ object.
605 talk_base::CriticalSection network_interface_crit_;
606 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607};
608
609enum SendFlags {
610 SEND_NOTHING,
611 SEND_RINGBACKTONE,
612 SEND_MICROPHONE
613};
614
wu@webrtc.org97077a32013-10-25 21:18:33 +0000615// The stats information is structured as follows:
616// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
617// Media contains a vector of SSRC infos that are exclusively used by this
618// media. (SSRCs shared between media streams can't be represented.)
619
620// Information about an SSRC.
621// This data may be locally recorded, or received in an RTCP SR or RR.
622struct SsrcSenderInfo {
623 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000625 timestamp(0) {
626 }
627 uint32 ssrc;
628 double timestamp; // NTP timestamp, represented as seconds since epoch.
629};
630
631struct SsrcReceiverInfo {
632 SsrcReceiverInfo()
633 : ssrc(0),
634 timestamp(0) {
635 }
636 uint32 ssrc;
637 double timestamp;
638};
639
640struct MediaSenderInfo {
641 MediaSenderInfo()
642 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643 packets_sent(0),
644 packets_lost(0),
645 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000646 rtt_ms(0) {
647 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000648 void add_ssrc(const SsrcSenderInfo& stat) {
649 local_stats.push_back(stat);
650 }
651 // Temporary utility function for call sites that only provide SSRC.
652 // As more info is added into SsrcSenderInfo, this function should go away.
653 void add_ssrc(uint32 ssrc) {
654 SsrcSenderInfo stat;
655 stat.ssrc = ssrc;
656 add_ssrc(stat);
657 }
658 // Utility accessor for clients that are only interested in ssrc numbers.
659 std::vector<uint32> ssrcs() const {
660 std::vector<uint32> retval;
661 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
662 it != local_stats.end(); ++it) {
663 retval.push_back(it->ssrc);
664 }
665 return retval;
666 }
667 // Utility accessor for clients that make the assumption only one ssrc
668 // exists per media.
669 // This will eventually go away.
670 uint32 ssrc() const {
671 if (local_stats.size() > 0) {
672 return local_stats[0].ssrc;
673 } else {
674 return 0;
675 }
676 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000677 int64 bytes_sent;
678 int packets_sent;
679 int packets_lost;
680 float fraction_lost;
681 int rtt_ms;
682 std::string codec_name;
683 std::vector<SsrcSenderInfo> local_stats;
684 std::vector<SsrcReceiverInfo> remote_stats;
685};
686
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000687template<class T>
688struct VariableInfo {
689 VariableInfo()
690 : min_val(),
691 mean(0.0),
692 max_val(),
693 variance(0.0) {
694 }
695 T min_val;
696 double mean;
697 T max_val;
698 double variance;
699};
700
wu@webrtc.org97077a32013-10-25 21:18:33 +0000701struct MediaReceiverInfo {
702 MediaReceiverInfo()
703 : bytes_rcvd(0),
704 packets_rcvd(0),
705 packets_lost(0),
706 fraction_lost(0.0) {
707 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000708 void add_ssrc(const SsrcReceiverInfo& stat) {
709 local_stats.push_back(stat);
710 }
711 // Temporary utility function for call sites that only provide SSRC.
712 // As more info is added into SsrcSenderInfo, this function should go away.
713 void add_ssrc(uint32 ssrc) {
714 SsrcReceiverInfo stat;
715 stat.ssrc = ssrc;
716 add_ssrc(stat);
717 }
718 std::vector<uint32> ssrcs() const {
719 std::vector<uint32> retval;
720 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
721 it != local_stats.end(); ++it) {
722 retval.push_back(it->ssrc);
723 }
724 return retval;
725 }
726 // Utility accessor for clients that make the assumption only one ssrc
727 // exists per media.
728 // This will eventually go away.
729 uint32 ssrc() const {
730 if (local_stats.size() > 0) {
731 return local_stats[0].ssrc;
732 } else {
733 return 0;
734 }
735 }
736
wu@webrtc.org97077a32013-10-25 21:18:33 +0000737 int64 bytes_rcvd;
738 int packets_rcvd;
739 int packets_lost;
740 float fraction_lost;
741 std::vector<SsrcReceiverInfo> local_stats;
742 std::vector<SsrcSenderInfo> remote_stats;
743};
744
745struct VoiceSenderInfo : public MediaSenderInfo {
746 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000747 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000748 jitter_ms(0),
749 audio_level(0),
750 aec_quality_min(0.0),
751 echo_delay_median_ms(0),
752 echo_delay_std_ms(0),
753 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000754 echo_return_loss_enhancement(0),
755 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 }
757
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 int jitter_ms;
760 int audio_level;
761 float aec_quality_min;
762 int echo_delay_median_ms;
763 int echo_delay_std_ms;
764 int echo_return_loss;
765 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000766 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767};
768
wu@webrtc.org97077a32013-10-25 21:18:33 +0000769struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000771 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772 jitter_ms(0),
773 jitter_buffer_ms(0),
774 jitter_buffer_preferred_ms(0),
775 delay_estimate_ms(0),
776 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000777 expand_rate(0),
778 decoding_calls_to_silence_generator(0),
779 decoding_calls_to_neteq(0),
780 decoding_normal(0),
781 decoding_plc(0),
782 decoding_cng(0),
783 decoding_plc_cng(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 }
785
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 int ext_seqnum;
787 int jitter_ms;
788 int jitter_buffer_ms;
789 int jitter_buffer_preferred_ms;
790 int delay_estimate_ms;
791 int audio_level;
792 // fraction of synthesized speech inserted through pre-emptive expansion
793 float expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000794 int decoding_calls_to_silence_generator;
795 int decoding_calls_to_neteq;
796 int decoding_normal;
797 int decoding_plc;
798 int decoding_cng;
799 int decoding_plc_cng;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800};
801
wu@webrtc.org97077a32013-10-25 21:18:33 +0000802struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 VideoSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000804 : packets_cached(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000806 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 nacks_rcvd(0),
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000808 input_frame_width(0),
809 input_frame_height(0),
810 send_frame_width(0),
811 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 framerate_input(0),
813 framerate_sent(0),
814 nominal_bitrate(0),
815 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000816 adapt_reason(0),
817 capture_jitter_ms(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000818 avg_encode_ms(0),
819 encode_usage_percent(0),
820 capture_queue_delay_ms_per_s(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 }
822
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000826 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 int nacks_rcvd;
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000828 int input_frame_width;
829 int input_frame_height;
830 int send_frame_width;
831 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 int framerate_input;
833 int framerate_sent;
834 int nominal_bitrate;
835 int preferred_bitrate;
836 int adapt_reason;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000837 int capture_jitter_ms;
838 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000839 int encode_usage_percent;
840 int capture_queue_delay_ms_per_s;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000841 VariableInfo<int> adapt_frame_drops;
842 VariableInfo<int> effects_frame_drops;
843 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844};
845
wu@webrtc.org97077a32013-10-25 21:18:33 +0000846struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 VideoReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000848 : packets_concealed(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000850 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 nacks_sent(0),
852 frame_width(0),
853 frame_height(0),
854 framerate_rcvd(0),
855 framerate_decoded(0),
856 framerate_output(0),
857 framerate_render_input(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000858 framerate_render_output(0),
859 decode_ms(0),
860 max_decode_ms(0),
861 jitter_buffer_ms(0),
862 min_playout_delay_ms(0),
863 render_delay_ms(0),
864 target_delay_ms(0),
865 current_delay_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 }
867
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000871 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 int nacks_sent;
873 int frame_width;
874 int frame_height;
875 int framerate_rcvd;
876 int framerate_decoded;
877 int framerate_output;
878 // Framerate as sent to the renderer.
879 int framerate_render_input;
880 // Framerate that the renderer reports.
881 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000882
883 // All stats below are gathered per-VideoReceiver, but some will be correlated
884 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
885 // structures, reflect this in the new layout.
886
887 // Current frame decode latency.
888 int decode_ms;
889 // Maximum observed frame decode latency.
890 int max_decode_ms;
891 // Jitter (network-related) latency.
892 int jitter_buffer_ms;
893 // Requested minimum playout latency.
894 int min_playout_delay_ms;
895 // Requested latency to account for rendering delay.
896 int render_delay_ms;
897 // Target overall delay: network+decode+render, accounting for
898 // min_playout_delay_ms.
899 int target_delay_ms;
900 // Current overall delay, possibly ramping towards target_delay_ms.
901 int current_delay_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902};
903
wu@webrtc.org97077a32013-10-25 21:18:33 +0000904struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000906 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 }
908
909 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910};
911
wu@webrtc.org97077a32013-10-25 21:18:33 +0000912struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000914 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 }
916
917 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918};
919
920struct BandwidthEstimationInfo {
921 BandwidthEstimationInfo()
922 : available_send_bandwidth(0),
923 available_recv_bandwidth(0),
924 target_enc_bitrate(0),
925 actual_enc_bitrate(0),
926 retransmit_bitrate(0),
927 transmit_bitrate(0),
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000928 bucket_delay(0),
929 total_received_propagation_delta_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 }
931
932 int available_send_bandwidth;
933 int available_recv_bandwidth;
934 int target_enc_bitrate;
935 int actual_enc_bitrate;
936 int retransmit_bitrate;
937 int transmit_bitrate;
938 int bucket_delay;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000939 // The following stats are only valid when
940 // StatsOptions::include_received_propagation_stats is true.
941 int total_received_propagation_delta_ms;
942 std::vector<int> recent_received_propagation_delta_ms;
943 std::vector<int64> recent_received_packet_group_arrival_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944};
945
946struct VoiceMediaInfo {
947 void Clear() {
948 senders.clear();
949 receivers.clear();
950 }
951 std::vector<VoiceSenderInfo> senders;
952 std::vector<VoiceReceiverInfo> receivers;
953};
954
955struct VideoMediaInfo {
956 void Clear() {
957 senders.clear();
958 receivers.clear();
959 bw_estimations.clear();
960 }
961 std::vector<VideoSenderInfo> senders;
962 std::vector<VideoReceiverInfo> receivers;
963 std::vector<BandwidthEstimationInfo> bw_estimations;
964};
965
966struct DataMediaInfo {
967 void Clear() {
968 senders.clear();
969 receivers.clear();
970 }
971 std::vector<DataSenderInfo> senders;
972 std::vector<DataReceiverInfo> receivers;
973};
974
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000975struct StatsOptions {
976 StatsOptions() : include_received_propagation_stats(false) {}
977
978 bool include_received_propagation_stats;
979};
980
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981class VoiceMediaChannel : public MediaChannel {
982 public:
983 enum Error {
984 ERROR_NONE = 0, // No error.
985 ERROR_OTHER, // Other errors.
986 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
987 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
988 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
989 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
990 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
991 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
992 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
993 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
994 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
995 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
996 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
997 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
998 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
999 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
1000 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1001 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1002 };
1003
1004 VoiceMediaChannel() {}
1005 virtual ~VoiceMediaChannel() {}
1006 // Sets the codecs/payload types to be used for incoming media.
1007 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
1008 // Sets the codecs/payload types to be used for outgoing media.
1009 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
1010 // Starts or stops playout of received audio.
1011 virtual bool SetPlayout(bool playout) = 0;
1012 // Starts or stops sending (and potentially capture) of local audio.
1013 virtual bool SetSend(SendFlags flag) = 0;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001014 // Sets the renderer object to be used for the specified remote audio stream.
1015 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
1016 // Sets the renderer object to be used for the specified local audio stream.
1017 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 // Gets current energy levels for all incoming streams.
1019 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1020 // Get the current energy level of the stream sent to the speaker.
1021 virtual int GetOutputLevel() = 0;
1022 // Get the time in milliseconds since last recorded keystroke, or negative.
1023 virtual int GetTimeSinceLastTyping() = 0;
1024 // Temporarily exposed field for tuning typing detect options.
1025 virtual void SetTypingDetectionParameters(int time_window,
1026 int cost_per_typing, int reporting_threshold, int penalty_decay,
1027 int type_event_delay) = 0;
1028 // Set left and right scale for speaker output volume of the specified ssrc.
1029 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
1030 // Get left and right scale for speaker output volume of the specified ssrc.
1031 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0;
1032 // Specifies a ringback tone to be played during call setup.
1033 virtual bool SetRingbackTone(const char *buf, int len) = 0;
1034 // Plays or stops the aforementioned ringback tone
1035 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
1036 // Returns if the telephone-event has been negotiated.
1037 virtual bool CanInsertDtmf() { return false; }
1038 // Send and/or play a DTMF |event| according to the |flags|.
1039 // The DTMF out-of-band signal will be used on sending.
1040 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001041 // The valid value for the |event| are 0 to 15 which corresponding to
1042 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
1044 // Gets quality stats for the channel.
1045 virtual bool GetStats(VoiceMediaInfo* info) = 0;
1046 // Gets last reported error for this media channel.
1047 virtual void GetLastMediaError(uint32* ssrc,
1048 VoiceMediaChannel::Error* error) {
1049 ASSERT(error != NULL);
1050 *error = ERROR_NONE;
1051 }
1052 // Sets the media options to use.
1053 virtual bool SetOptions(const AudioOptions& options) = 0;
1054 virtual bool GetOptions(AudioOptions* options) const = 0;
1055
1056 // Signal errors from MediaChannel. Arguments are:
1057 // ssrc(uint32), and error(VoiceMediaChannel::Error).
1058 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
1059};
1060
1061class VideoMediaChannel : public MediaChannel {
1062 public:
1063 enum Error {
1064 ERROR_NONE = 0, // No error.
1065 ERROR_OTHER, // Other errors.
1066 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1067 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1068 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1069 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1070 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1071 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1072 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1073 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1074 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1075 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1076 };
1077
1078 VideoMediaChannel() : renderer_(NULL) {}
1079 virtual ~VideoMediaChannel() {}
1080 // Sets the codecs/payload types to be used for incoming media.
1081 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
1082 // Sets the codecs/payload types to be used for outgoing media.
1083 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
1084 // Gets the currently set codecs/payload types to be used for outgoing media.
1085 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1086 // Sets the format of a specified outgoing stream.
1087 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
1088 // Starts or stops playout of received video.
1089 virtual bool SetRender(bool render) = 0;
1090 // Starts or stops transmission (and potentially capture) of local video.
1091 virtual bool SetSend(bool send) = 0;
1092 // Sets the renderer object to be used for the specified stream.
1093 // If SSRC is 0, the renderer is used for the 'default' stream.
1094 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
1095 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1096 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
1097 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
1098 // Gets quality stats for the channel.
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001099 virtual bool GetStats(const StatsOptions& options, VideoMediaInfo* info) = 0;
1100 // This is needed for MediaMonitor to use the same template for voice, video
1101 // and data MediaChannels.
1102 bool GetStats(VideoMediaInfo* info) {
1103 return GetStats(StatsOptions(), info);
1104 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105
1106 // Send an intra frame to the receivers.
1107 virtual bool SendIntraFrame() = 0;
1108 // Reuqest each of the remote senders to send an intra frame.
1109 virtual bool RequestIntraFrame() = 0;
1110 // Sets the media options to use.
1111 virtual bool SetOptions(const VideoOptions& options) = 0;
1112 virtual bool GetOptions(VideoOptions* options) const = 0;
1113 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1114
1115 // Signal errors from MediaChannel. Arguments are:
1116 // ssrc(uint32), and error(VideoMediaChannel::Error).
1117 sigslot::signal2<uint32, Error> SignalMediaError;
1118
1119 protected:
1120 VideoRenderer *renderer_;
1121};
1122
1123enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001124 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1125 // values.
1126 DMT_NONE = 0,
1127 DMT_CONTROL = 1,
1128 DMT_BINARY = 2,
1129 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130};
1131
1132// Info about data received in DataMediaChannel. For use in
1133// DataMediaChannel::SignalDataReceived and in all of the signals that
1134// signal fires, on up the chain.
1135struct ReceiveDataParams {
1136 // The in-packet stream indentifier.
1137 // For SCTP, this is really SID, not SSRC.
1138 uint32 ssrc;
1139 // The type of message (binary, text, or control).
1140 DataMessageType type;
1141 // A per-stream value incremented per packet in the stream.
1142 int seq_num;
1143 // A per-stream value monotonically increasing with time.
1144 int timestamp;
1145
1146 ReceiveDataParams() :
1147 ssrc(0),
1148 type(DMT_TEXT),
1149 seq_num(0),
1150 timestamp(0) {
1151 }
1152};
1153
1154struct SendDataParams {
1155 // The in-packet stream indentifier.
1156 // For SCTP, this is really SID, not SSRC.
1157 uint32 ssrc;
1158 // The type of message (binary, text, or control).
1159 DataMessageType type;
1160
1161 // For SCTP, whether to send messages flagged as ordered or not.
1162 // If false, messages can be received out of order.
1163 bool ordered;
1164 // For SCTP, whether the messages are sent reliably or not.
1165 // If false, messages may be lost.
1166 bool reliable;
1167 // For SCTP, if reliable == false, provide partial reliability by
1168 // resending up to this many times. Either count or millis
1169 // is supported, not both at the same time.
1170 int max_rtx_count;
1171 // For SCTP, if reliable == false, provide partial reliability by
1172 // resending for up to this many milliseconds. Either count or millis
1173 // is supported, not both at the same time.
1174 int max_rtx_ms;
1175
1176 SendDataParams() :
1177 ssrc(0),
1178 type(DMT_TEXT),
1179 // TODO(pthatcher): Make these true by default?
1180 ordered(false),
1181 reliable(false),
1182 max_rtx_count(0),
1183 max_rtx_ms(0) {
1184 }
1185};
1186
1187enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1188
1189class DataMediaChannel : public MediaChannel {
1190 public:
1191 enum Error {
1192 ERROR_NONE = 0, // No error.
1193 ERROR_OTHER, // Other errors.
1194 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1195 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1196 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1197 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1198 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1199 };
1200
1201 virtual ~DataMediaChannel() {}
1202
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001203 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
1204 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001205
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001206 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
1207 // TODO(pthatcher): Implement this.
1208 virtual bool GetStats(DataMediaInfo* info) { return true; }
1209
1210 virtual bool SetSend(bool send) = 0;
1211 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212
1213 virtual bool SendData(
1214 const SendDataParams& params,
1215 const talk_base::Buffer& payload,
1216 SendDataResult* result = NULL) = 0;
1217 // Signals when data is received (params, data, len)
1218 sigslot::signal3<const ReceiveDataParams&,
1219 const char*,
1220 size_t> SignalDataReceived;
1221 // Signal errors from MediaChannel. Arguments are:
1222 // ssrc(uint32), and error(DataMediaChannel::Error).
1223 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001224 // Signal when the media channel is ready to send the stream. Arguments are:
1225 // writable(bool)
1226 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001227};
1228
1229} // namespace cricket
1230
1231#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_