blob: c2ea26f1bd3244e379b14f0a3003b000e4c9c0b9 [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);
171 aec_dump.SetFrom(change.aec_dump);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000172 experimental_acm.SetFrom(change.experimental_acm);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000173 tx_agc_target_dbov.SetFrom(change.tx_agc_target_dbov);
174 tx_agc_digital_compression_gain.SetFrom(
175 change.tx_agc_digital_compression_gain);
176 tx_agc_limiter.SetFrom(change.tx_agc_limiter);
177 rx_agc_target_dbov.SetFrom(change.rx_agc_target_dbov);
178 rx_agc_digital_compression_gain.SetFrom(
179 change.rx_agc_digital_compression_gain);
180 rx_agc_limiter.SetFrom(change.rx_agc_limiter);
181 recording_sample_rate.SetFrom(change.recording_sample_rate);
182 playout_sample_rate.SetFrom(change.playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000183 dscp.SetFrom(change.dscp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 }
185
186 bool operator==(const AudioOptions& o) const {
187 return echo_cancellation == o.echo_cancellation &&
188 auto_gain_control == o.auto_gain_control &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000189 rx_auto_gain_control == o.rx_auto_gain_control &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 noise_suppression == o.noise_suppression &&
191 highpass_filter == o.highpass_filter &&
192 stereo_swapping == o.stereo_swapping &&
193 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000194 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 conference_mode == o.conference_mode &&
196 experimental_agc == o.experimental_agc &&
197 experimental_aec == o.experimental_aec &&
198 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000199 aec_dump == o.aec_dump &&
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000200 experimental_acm == o.experimental_acm &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000201 tx_agc_target_dbov == o.tx_agc_target_dbov &&
202 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
203 tx_agc_limiter == o.tx_agc_limiter &&
204 rx_agc_target_dbov == o.rx_agc_target_dbov &&
205 rx_agc_digital_compression_gain == o.rx_agc_digital_compression_gain &&
206 rx_agc_limiter == o.rx_agc_limiter &&
207 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000208 playout_sample_rate == o.playout_sample_rate &&
209 dscp == o.dscp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 }
211
212 std::string ToString() const {
213 std::ostringstream ost;
214 ost << "AudioOptions {";
215 ost << ToStringIfSet("aec", echo_cancellation);
216 ost << ToStringIfSet("agc", auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000217 ost << ToStringIfSet("rx_agc", rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 ost << ToStringIfSet("ns", noise_suppression);
219 ost << ToStringIfSet("hf", highpass_filter);
220 ost << ToStringIfSet("swap", stereo_swapping);
221 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000222 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223 ost << ToStringIfSet("conference", conference_mode);
224 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
225 ost << ToStringIfSet("experimental_agc", experimental_agc);
226 ost << ToStringIfSet("experimental_aec", experimental_aec);
227 ost << ToStringIfSet("aec_dump", aec_dump);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000228 ost << ToStringIfSet("experimental_acm", experimental_acm);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000229 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
230 ost << ToStringIfSet("tx_agc_digital_compression_gain",
231 tx_agc_digital_compression_gain);
232 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
233 ost << ToStringIfSet("rx_agc_target_dbov", rx_agc_target_dbov);
234 ost << ToStringIfSet("rx_agc_digital_compression_gain",
235 rx_agc_digital_compression_gain);
236 ost << ToStringIfSet("rx_agc_limiter", rx_agc_limiter);
237 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
238 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000239 ost << ToStringIfSet("dscp", dscp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 ost << "}";
241 return ost.str();
242 }
243
244 // Audio processing that attempts to filter away the output signal from
245 // later inbound pickup.
246 Settable<bool> echo_cancellation;
247 // Audio processing to adjust the sensitivity of the local mic dynamically.
248 Settable<bool> auto_gain_control;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000249 // Audio processing to apply gain to the remote audio.
250 Settable<bool> rx_auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 // Audio processing to filter out background noise.
252 Settable<bool> noise_suppression;
253 // Audio processing to remove background noise of lower frequencies.
254 Settable<bool> highpass_filter;
255 // Audio processing to swap the left and right channels.
256 Settable<bool> stereo_swapping;
257 // Audio processing to detect typing.
258 Settable<bool> typing_detection;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000259 Settable<bool> aecm_generate_comfort_noise;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 Settable<bool> conference_mode;
261 Settable<int> adjust_agc_delta;
262 Settable<bool> experimental_agc;
263 Settable<bool> experimental_aec;
264 Settable<bool> aec_dump;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000265 Settable<bool> experimental_acm;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000266 // Note that tx_agc_* only applies to non-experimental AGC.
267 Settable<uint16> tx_agc_target_dbov;
268 Settable<uint16> tx_agc_digital_compression_gain;
269 Settable<bool> tx_agc_limiter;
270 Settable<uint16> rx_agc_target_dbov;
271 Settable<uint16> rx_agc_digital_compression_gain;
272 Settable<bool> rx_agc_limiter;
273 Settable<uint32> recording_sample_rate;
274 Settable<uint32> playout_sample_rate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000275 // Set DSCP value for packet sent from audio channel.
276 Settable<bool> dscp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277};
278
279// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
280// Used to be flags, but that makes it hard to selectively apply options.
281// We are moving all of the setting of options to structs like this,
282// but some things currently still use flags.
283struct VideoOptions {
284 VideoOptions() {
285 process_adaptation_threshhold.Set(kProcessCpuThreshold);
286 system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold);
287 system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold);
288 }
289
290 void SetAll(const VideoOptions& change) {
291 adapt_input_to_encoder.SetFrom(change.adapt_input_to_encoder);
292 adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000293 adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 adapt_view_switch.SetFrom(change.adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000295 video_adapt_third.SetFrom(change.video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296 video_noise_reduction.SetFrom(change.video_noise_reduction);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 video_one_layer_screencast.SetFrom(change.video_one_layer_screencast);
298 video_high_bitrate.SetFrom(change.video_high_bitrate);
299 video_watermark.SetFrom(change.video_watermark);
300 video_temporal_layer_screencast.SetFrom(
301 change.video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000302 video_temporal_layer_realtime.SetFrom(
303 change.video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 video_leaky_bucket.SetFrom(change.video_leaky_bucket);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000305 cpu_overuse_detection.SetFrom(change.cpu_overuse_detection);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306 conference_mode.SetFrom(change.conference_mode);
307 process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
308 system_low_adaptation_threshhold.SetFrom(
309 change.system_low_adaptation_threshhold);
310 system_high_adaptation_threshhold.SetFrom(
311 change.system_high_adaptation_threshhold);
312 buffered_mode_latency.SetFrom(change.buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000313 lower_min_bitrate.SetFrom(change.lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000314 dscp.SetFrom(change.dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000315 suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 }
317
318 bool operator==(const VideoOptions& o) const {
319 return adapt_input_to_encoder == o.adapt_input_to_encoder &&
320 adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000321 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 adapt_view_switch == o.adapt_view_switch &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000323 video_adapt_third == o.video_adapt_third &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 video_noise_reduction == o.video_noise_reduction &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 video_one_layer_screencast == o.video_one_layer_screencast &&
326 video_high_bitrate == o.video_high_bitrate &&
327 video_watermark == o.video_watermark &&
328 video_temporal_layer_screencast == o.video_temporal_layer_screencast &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000329 video_temporal_layer_realtime == o.video_temporal_layer_realtime &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 video_leaky_bucket == o.video_leaky_bucket &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000331 cpu_overuse_detection == o.cpu_overuse_detection &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 conference_mode == o.conference_mode &&
333 process_adaptation_threshhold == o.process_adaptation_threshhold &&
334 system_low_adaptation_threshhold ==
335 o.system_low_adaptation_threshhold &&
336 system_high_adaptation_threshhold ==
337 o.system_high_adaptation_threshhold &&
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000338 buffered_mode_latency == o.buffered_mode_latency &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000339 lower_min_bitrate == o.lower_min_bitrate &&
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000340 dscp == o.dscp &&
341 suspend_below_min_bitrate == o.suspend_below_min_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 }
343
344 std::string ToString() const {
345 std::ostringstream ost;
346 ost << "VideoOptions {";
347 ost << ToStringIfSet("encoder adaption", adapt_input_to_encoder);
348 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000349 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 ost << ToStringIfSet("adapt view switch", adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000351 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000353 ost << ToStringIfSet("1 layer screencast", video_one_layer_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 ost << ToStringIfSet("high bitrate", video_high_bitrate);
355 ost << ToStringIfSet("watermark", video_watermark);
356 ost << ToStringIfSet("video temporal layer screencast",
357 video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000358 ost << ToStringIfSet("video temporal layer realtime",
359 video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 ost << ToStringIfSet("leaky bucket", video_leaky_bucket);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000361 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 ost << ToStringIfSet("conference mode", conference_mode);
363 ost << ToStringIfSet("process", process_adaptation_threshhold);
364 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
365 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
366 ost << ToStringIfSet("buffered mode latency", buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000367 ost << ToStringIfSet("lower min bitrate", lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000368 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000369 ost << ToStringIfSet("suspend below min bitrate",
370 suspend_below_min_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 ost << "}";
372 return ost.str();
373 }
374
375 // Encoder adaption, which is the gd callback in LMI, and TBA in WebRTC.
376 Settable<bool> adapt_input_to_encoder;
377 // Enable CPU adaptation?
378 Settable<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000379 // Enable CPU adaptation smoothing?
380 Settable<bool> adapt_cpu_with_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 // Enable Adapt View Switch?
382 Settable<bool> adapt_view_switch;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000383 // Enable video adapt third?
384 Settable<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 // Enable denoising?
386 Settable<bool> video_noise_reduction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387 // Experimental: Enable one layer screencast?
388 Settable<bool> video_one_layer_screencast;
389 // Experimental: Enable WebRtc higher bitrate?
390 Settable<bool> video_high_bitrate;
391 // Experimental: Add watermark to the rendered video image.
392 Settable<bool> video_watermark;
393 // Experimental: Enable WebRTC layered screencast.
394 Settable<bool> video_temporal_layer_screencast;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000395 // Experimental: Enable WebRTC temporal layer strategy for realtime video.
396 Settable<bool> video_temporal_layer_realtime;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 // Enable WebRTC leaky bucket when sending media packets.
398 Settable<bool> video_leaky_bucket;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000399 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
400 // adaptation algorithm. So this option will override the
401 // |adapt_input_to_cpu_usage|.
402 Settable<bool> cpu_overuse_detection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 // Use conference mode?
404 Settable<bool> conference_mode;
405 // Threshhold for process cpu adaptation. (Process limit)
406 SettablePercent process_adaptation_threshhold;
407 // Low threshhold for cpu adaptation. (Adapt up)
408 SettablePercent system_low_adaptation_threshhold;
409 // High threshhold for cpu adaptation. (Adapt down)
410 SettablePercent system_high_adaptation_threshhold;
411 // Specify buffered mode latency in milliseconds.
412 Settable<int> buffered_mode_latency;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000413 // Make minimum configured send bitrate even lower than usual, at 30kbit.
414 Settable<bool> lower_min_bitrate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000415 // Set DSCP value for packet sent from video channel.
416 Settable<bool> dscp;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000417 // Enable WebRTC suspension of video. No video frames will be sent when the
418 // bitrate is below the configured minimum bitrate.
419 Settable<bool> suspend_below_min_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420};
421
422// A class for playing out soundclips.
423class SoundclipMedia {
424 public:
425 enum SoundclipFlags {
426 SF_LOOP = 1,
427 };
428
429 virtual ~SoundclipMedia() {}
430
431 // Plays a sound out to the speakers with the given audio stream. The stream
432 // must be 16-bit little-endian 16 kHz PCM. If a stream is already playing
433 // on this SoundclipMedia, it is stopped. If clip is NULL, nothing is played.
434 // Returns whether it was successful.
435 virtual bool PlaySound(const char *clip, int len, int flags) = 0;
436};
437
438struct RtpHeaderExtension {
439 RtpHeaderExtension() : id(0) {}
440 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
441 std::string uri;
442 int id;
443 // TODO(juberti): SendRecv direction;
444
445 bool operator==(const RtpHeaderExtension& ext) const {
446 // id is a reserved word in objective-c. Therefore the id attribute has to
447 // be a fully qualified name in order to compile on IOS.
448 return this->id == ext.id &&
449 uri == ext.uri;
450 }
451};
452
453// Returns the named header extension if found among all extensions, NULL
454// otherwise.
455inline const RtpHeaderExtension* FindHeaderExtension(
456 const std::vector<RtpHeaderExtension>& extensions,
457 const std::string& name) {
458 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
459 it != extensions.end(); ++it) {
460 if (it->uri == name)
461 return &(*it);
462 }
463 return NULL;
464}
465
466enum MediaChannelOptions {
467 // Tune the stream for conference mode.
468 OPT_CONFERENCE = 0x0001
469};
470
471enum VoiceMediaChannelOptions {
472 // Tune the audio stream for vcs with different target levels.
473 OPT_AGC_MINUS_10DB = 0x80000000
474};
475
476// DTMF flags to control if a DTMF tone should be played and/or sent.
477enum DtmfFlags {
478 DF_PLAY = 0x01,
479 DF_SEND = 0x02,
480};
481
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482class MediaChannel : public sigslot::has_slots<> {
483 public:
484 class NetworkInterface {
485 public:
486 enum SocketType { ST_RTP, ST_RTCP };
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000487 virtual bool SendPacket(
488 talk_base::Buffer* packet,
489 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
490 virtual bool SendRtcp(
491 talk_base::Buffer* packet,
492 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493 virtual int SetOption(SocketType type, talk_base::Socket::Option opt,
494 int option) = 0;
495 virtual ~NetworkInterface() {}
496 };
497
498 MediaChannel() : network_interface_(NULL) {}
499 virtual ~MediaChannel() {}
500
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000501 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 virtual void SetInterface(NetworkInterface *iface) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000503 talk_base::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504 network_interface_ = iface;
505 }
506
507 // Called when a RTP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000508 virtual void OnPacketReceived(talk_base::Buffer* packet,
509 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510 // Called when a RTCP packet is received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000511 virtual void OnRtcpReceived(talk_base::Buffer* packet,
512 const talk_base::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513 // Called when the socket's ability to send has changed.
514 virtual void OnReadyToSend(bool ready) = 0;
515 // Creates a new outgoing media stream with SSRCs and CNAME as described
516 // by sp.
517 virtual bool AddSendStream(const StreamParams& sp) = 0;
518 // Removes an outgoing media stream.
519 // ssrc must be the first SSRC of the media stream if the stream uses
520 // multiple SSRCs.
521 virtual bool RemoveSendStream(uint32 ssrc) = 0;
522 // Creates a new incoming media stream with SSRCs and CNAME as described
523 // by sp.
524 virtual bool AddRecvStream(const StreamParams& sp) = 0;
525 // Removes an incoming media stream.
526 // ssrc must be the first SSRC of the media stream if the stream uses
527 // multiple SSRCs.
528 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
529
530 // Mutes the channel.
531 virtual bool MuteStream(uint32 ssrc, bool on) = 0;
532
533 // Sets the RTP extension headers and IDs to use when sending RTP.
534 virtual bool SetRecvRtpHeaderExtensions(
535 const std::vector<RtpHeaderExtension>& extensions) = 0;
536 virtual bool SetSendRtpHeaderExtensions(
537 const std::vector<RtpHeaderExtension>& extensions) = 0;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000538 // Sets the initial bandwidth to use when sending starts.
539 virtual bool SetStartSendBandwidth(int bps) = 0;
540 // Sets the maximum allowed bandwidth to use when sending data.
541 virtual bool SetMaxSendBandwidth(int bps) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000542
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000543 // Base method to send packet using NetworkInterface.
544 bool SendPacket(talk_base::Buffer* packet) {
545 return DoSendPacket(packet, false);
546 }
547
548 bool SendRtcp(talk_base::Buffer* packet) {
549 return DoSendPacket(packet, true);
550 }
551
552 int SetOption(NetworkInterface::SocketType type,
553 talk_base::Socket::Option opt,
554 int option) {
555 talk_base::CritScope cs(&network_interface_crit_);
556 if (!network_interface_)
557 return -1;
558
559 return network_interface_->SetOption(type, opt, option);
560 }
561
wu@webrtc.orgde305012013-10-31 15:40:38 +0000562 protected:
563 // This method sets DSCP |value| on both RTP and RTCP channels.
564 int SetDscp(talk_base::DiffServCodePoint value) {
565 int ret;
566 ret = SetOption(NetworkInterface::ST_RTP,
567 talk_base::Socket::OPT_DSCP,
568 value);
569 if (ret == 0) {
570 ret = SetOption(NetworkInterface::ST_RTCP,
571 talk_base::Socket::OPT_DSCP,
572 value);
573 }
574 return ret;
575 }
576
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000577 private:
578 bool DoSendPacket(talk_base::Buffer* packet, bool rtcp) {
579 talk_base::CritScope cs(&network_interface_crit_);
580 if (!network_interface_)
581 return false;
582
583 return (!rtcp) ? network_interface_->SendPacket(packet) :
584 network_interface_->SendRtcp(packet);
585 }
586
587 // |network_interface_| can be accessed from the worker_thread and
588 // from any MediaEngine threads. This critical section is to protect accessing
589 // of network_interface_ object.
590 talk_base::CriticalSection network_interface_crit_;
591 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592};
593
594enum SendFlags {
595 SEND_NOTHING,
596 SEND_RINGBACKTONE,
597 SEND_MICROPHONE
598};
599
wu@webrtc.org97077a32013-10-25 21:18:33 +0000600// The stats information is structured as follows:
601// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
602// Media contains a vector of SSRC infos that are exclusively used by this
603// media. (SSRCs shared between media streams can't be represented.)
604
605// Information about an SSRC.
606// This data may be locally recorded, or received in an RTCP SR or RR.
607struct SsrcSenderInfo {
608 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000610 timestamp(0) {
611 }
612 uint32 ssrc;
613 double timestamp; // NTP timestamp, represented as seconds since epoch.
614};
615
616struct SsrcReceiverInfo {
617 SsrcReceiverInfo()
618 : ssrc(0),
619 timestamp(0) {
620 }
621 uint32 ssrc;
622 double timestamp;
623};
624
625struct MediaSenderInfo {
626 MediaSenderInfo()
627 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628 packets_sent(0),
629 packets_lost(0),
630 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000631 rtt_ms(0) {
632 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000633 void add_ssrc(const SsrcSenderInfo& stat) {
634 local_stats.push_back(stat);
635 }
636 // Temporary utility function for call sites that only provide SSRC.
637 // As more info is added into SsrcSenderInfo, this function should go away.
638 void add_ssrc(uint32 ssrc) {
639 SsrcSenderInfo stat;
640 stat.ssrc = ssrc;
641 add_ssrc(stat);
642 }
643 // Utility accessor for clients that are only interested in ssrc numbers.
644 std::vector<uint32> ssrcs() const {
645 std::vector<uint32> retval;
646 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
647 it != local_stats.end(); ++it) {
648 retval.push_back(it->ssrc);
649 }
650 return retval;
651 }
652 // Utility accessor for clients that make the assumption only one ssrc
653 // exists per media.
654 // This will eventually go away.
655 uint32 ssrc() const {
656 if (local_stats.size() > 0) {
657 return local_stats[0].ssrc;
658 } else {
659 return 0;
660 }
661 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000662 int64 bytes_sent;
663 int packets_sent;
664 int packets_lost;
665 float fraction_lost;
666 int rtt_ms;
667 std::string codec_name;
668 std::vector<SsrcSenderInfo> local_stats;
669 std::vector<SsrcReceiverInfo> remote_stats;
670};
671
672struct MediaReceiverInfo {
673 MediaReceiverInfo()
674 : bytes_rcvd(0),
675 packets_rcvd(0),
676 packets_lost(0),
677 fraction_lost(0.0) {
678 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000679 void add_ssrc(const SsrcReceiverInfo& stat) {
680 local_stats.push_back(stat);
681 }
682 // Temporary utility function for call sites that only provide SSRC.
683 // As more info is added into SsrcSenderInfo, this function should go away.
684 void add_ssrc(uint32 ssrc) {
685 SsrcReceiverInfo stat;
686 stat.ssrc = ssrc;
687 add_ssrc(stat);
688 }
689 std::vector<uint32> ssrcs() const {
690 std::vector<uint32> retval;
691 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
692 it != local_stats.end(); ++it) {
693 retval.push_back(it->ssrc);
694 }
695 return retval;
696 }
697 // Utility accessor for clients that make the assumption only one ssrc
698 // exists per media.
699 // This will eventually go away.
700 uint32 ssrc() const {
701 if (local_stats.size() > 0) {
702 return local_stats[0].ssrc;
703 } else {
704 return 0;
705 }
706 }
707
wu@webrtc.org97077a32013-10-25 21:18:33 +0000708 int64 bytes_rcvd;
709 int packets_rcvd;
710 int packets_lost;
711 float fraction_lost;
712 std::vector<SsrcReceiverInfo> local_stats;
713 std::vector<SsrcSenderInfo> remote_stats;
714};
715
716struct VoiceSenderInfo : public MediaSenderInfo {
717 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000718 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719 jitter_ms(0),
720 audio_level(0),
721 aec_quality_min(0.0),
722 echo_delay_median_ms(0),
723 echo_delay_std_ms(0),
724 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000725 echo_return_loss_enhancement(0),
726 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 }
728
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 int jitter_ms;
731 int audio_level;
732 float aec_quality_min;
733 int echo_delay_median_ms;
734 int echo_delay_std_ms;
735 int echo_return_loss;
736 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000737 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738};
739
wu@webrtc.org97077a32013-10-25 21:18:33 +0000740struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000742 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 jitter_ms(0),
744 jitter_buffer_ms(0),
745 jitter_buffer_preferred_ms(0),
746 delay_estimate_ms(0),
747 audio_level(0),
748 expand_rate(0) {
749 }
750
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751 int ext_seqnum;
752 int jitter_ms;
753 int jitter_buffer_ms;
754 int jitter_buffer_preferred_ms;
755 int delay_estimate_ms;
756 int audio_level;
757 // fraction of synthesized speech inserted through pre-emptive expansion
758 float expand_rate;
759};
760
wu@webrtc.org97077a32013-10-25 21:18:33 +0000761struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 VideoSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000763 : packets_cached(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000764 firs_rcvd(0),
765 nacks_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 frame_width(0),
767 frame_height(0),
768 framerate_input(0),
769 framerate_sent(0),
770 nominal_bitrate(0),
771 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000772 adapt_reason(0),
773 capture_jitter_ms(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000774 avg_encode_ms(0),
775 encode_usage_percent(0),
776 capture_queue_delay_ms_per_s(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000777 }
778
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 int firs_rcvd;
782 int nacks_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 int frame_width;
784 int frame_height;
785 int framerate_input;
786 int framerate_sent;
787 int nominal_bitrate;
788 int preferred_bitrate;
789 int adapt_reason;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000790 int capture_jitter_ms;
791 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000792 int encode_usage_percent;
793 int capture_queue_delay_ms_per_s;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794};
795
wu@webrtc.org97077a32013-10-25 21:18:33 +0000796struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 VideoReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000798 : packets_concealed(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 firs_sent(0),
800 nacks_sent(0),
801 frame_width(0),
802 frame_height(0),
803 framerate_rcvd(0),
804 framerate_decoded(0),
805 framerate_output(0),
806 framerate_render_input(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000807 framerate_render_output(0),
808 decode_ms(0),
809 max_decode_ms(0),
810 jitter_buffer_ms(0),
811 min_playout_delay_ms(0),
812 render_delay_ms(0),
813 target_delay_ms(0),
814 current_delay_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 }
816
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 int firs_sent;
820 int nacks_sent;
821 int frame_width;
822 int frame_height;
823 int framerate_rcvd;
824 int framerate_decoded;
825 int framerate_output;
826 // Framerate as sent to the renderer.
827 int framerate_render_input;
828 // Framerate that the renderer reports.
829 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000830
831 // All stats below are gathered per-VideoReceiver, but some will be correlated
832 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
833 // structures, reflect this in the new layout.
834
835 // Current frame decode latency.
836 int decode_ms;
837 // Maximum observed frame decode latency.
838 int max_decode_ms;
839 // Jitter (network-related) latency.
840 int jitter_buffer_ms;
841 // Requested minimum playout latency.
842 int min_playout_delay_ms;
843 // Requested latency to account for rendering delay.
844 int render_delay_ms;
845 // Target overall delay: network+decode+render, accounting for
846 // min_playout_delay_ms.
847 int target_delay_ms;
848 // Current overall delay, possibly ramping towards target_delay_ms.
849 int current_delay_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850};
851
wu@webrtc.org97077a32013-10-25 21:18:33 +0000852struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000854 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 }
856
857 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858};
859
wu@webrtc.org97077a32013-10-25 21:18:33 +0000860struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000862 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 }
864
865 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866};
867
868struct BandwidthEstimationInfo {
869 BandwidthEstimationInfo()
870 : available_send_bandwidth(0),
871 available_recv_bandwidth(0),
872 target_enc_bitrate(0),
873 actual_enc_bitrate(0),
874 retransmit_bitrate(0),
875 transmit_bitrate(0),
876 bucket_delay(0) {
877 }
878
879 int available_send_bandwidth;
880 int available_recv_bandwidth;
881 int target_enc_bitrate;
882 int actual_enc_bitrate;
883 int retransmit_bitrate;
884 int transmit_bitrate;
885 int bucket_delay;
886};
887
888struct VoiceMediaInfo {
889 void Clear() {
890 senders.clear();
891 receivers.clear();
892 }
893 std::vector<VoiceSenderInfo> senders;
894 std::vector<VoiceReceiverInfo> receivers;
895};
896
897struct VideoMediaInfo {
898 void Clear() {
899 senders.clear();
900 receivers.clear();
901 bw_estimations.clear();
902 }
903 std::vector<VideoSenderInfo> senders;
904 std::vector<VideoReceiverInfo> receivers;
905 std::vector<BandwidthEstimationInfo> bw_estimations;
906};
907
908struct DataMediaInfo {
909 void Clear() {
910 senders.clear();
911 receivers.clear();
912 }
913 std::vector<DataSenderInfo> senders;
914 std::vector<DataReceiverInfo> receivers;
915};
916
917class VoiceMediaChannel : public MediaChannel {
918 public:
919 enum Error {
920 ERROR_NONE = 0, // No error.
921 ERROR_OTHER, // Other errors.
922 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
923 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
924 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
925 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
926 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
927 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
928 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
929 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
930 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
931 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
932 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
933 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
934 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
935 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
936 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
937 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
938 };
939
940 VoiceMediaChannel() {}
941 virtual ~VoiceMediaChannel() {}
942 // Sets the codecs/payload types to be used for incoming media.
943 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
944 // Sets the codecs/payload types to be used for outgoing media.
945 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
946 // Starts or stops playout of received audio.
947 virtual bool SetPlayout(bool playout) = 0;
948 // Starts or stops sending (and potentially capture) of local audio.
949 virtual bool SetSend(SendFlags flag) = 0;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000950 // Sets the renderer object to be used for the specified remote audio stream.
951 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
952 // Sets the renderer object to be used for the specified local audio stream.
953 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 // Gets current energy levels for all incoming streams.
955 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
956 // Get the current energy level of the stream sent to the speaker.
957 virtual int GetOutputLevel() = 0;
958 // Get the time in milliseconds since last recorded keystroke, or negative.
959 virtual int GetTimeSinceLastTyping() = 0;
960 // Temporarily exposed field for tuning typing detect options.
961 virtual void SetTypingDetectionParameters(int time_window,
962 int cost_per_typing, int reporting_threshold, int penalty_decay,
963 int type_event_delay) = 0;
964 // Set left and right scale for speaker output volume of the specified ssrc.
965 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
966 // Get left and right scale for speaker output volume of the specified ssrc.
967 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0;
968 // Specifies a ringback tone to be played during call setup.
969 virtual bool SetRingbackTone(const char *buf, int len) = 0;
970 // Plays or stops the aforementioned ringback tone
971 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
972 // Returns if the telephone-event has been negotiated.
973 virtual bool CanInsertDtmf() { return false; }
974 // Send and/or play a DTMF |event| according to the |flags|.
975 // The DTMF out-of-band signal will be used on sending.
976 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000977 // The valid value for the |event| are 0 to 15 which corresponding to
978 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
980 // Gets quality stats for the channel.
981 virtual bool GetStats(VoiceMediaInfo* info) = 0;
982 // Gets last reported error for this media channel.
983 virtual void GetLastMediaError(uint32* ssrc,
984 VoiceMediaChannel::Error* error) {
985 ASSERT(error != NULL);
986 *error = ERROR_NONE;
987 }
988 // Sets the media options to use.
989 virtual bool SetOptions(const AudioOptions& options) = 0;
990 virtual bool GetOptions(AudioOptions* options) const = 0;
991
992 // Signal errors from MediaChannel. Arguments are:
993 // ssrc(uint32), and error(VoiceMediaChannel::Error).
994 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
995};
996
997class VideoMediaChannel : public MediaChannel {
998 public:
999 enum Error {
1000 ERROR_NONE = 0, // No error.
1001 ERROR_OTHER, // Other errors.
1002 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1003 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1004 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1005 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1006 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1007 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1008 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1009 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1010 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1011 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1012 };
1013
1014 VideoMediaChannel() : renderer_(NULL) {}
1015 virtual ~VideoMediaChannel() {}
1016 // Sets the codecs/payload types to be used for incoming media.
1017 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
1018 // Sets the codecs/payload types to be used for outgoing media.
1019 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
1020 // Gets the currently set codecs/payload types to be used for outgoing media.
1021 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1022 // Sets the format of a specified outgoing stream.
1023 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
1024 // Starts or stops playout of received video.
1025 virtual bool SetRender(bool render) = 0;
1026 // Starts or stops transmission (and potentially capture) of local video.
1027 virtual bool SetSend(bool send) = 0;
1028 // Sets the renderer object to be used for the specified stream.
1029 // If SSRC is 0, the renderer is used for the 'default' stream.
1030 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
1031 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1032 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
1033 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
1034 // Gets quality stats for the channel.
1035 virtual bool GetStats(VideoMediaInfo* info) = 0;
1036
1037 // Send an intra frame to the receivers.
1038 virtual bool SendIntraFrame() = 0;
1039 // Reuqest each of the remote senders to send an intra frame.
1040 virtual bool RequestIntraFrame() = 0;
1041 // Sets the media options to use.
1042 virtual bool SetOptions(const VideoOptions& options) = 0;
1043 virtual bool GetOptions(VideoOptions* options) const = 0;
1044 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1045
1046 // Signal errors from MediaChannel. Arguments are:
1047 // ssrc(uint32), and error(VideoMediaChannel::Error).
1048 sigslot::signal2<uint32, Error> SignalMediaError;
1049
1050 protected:
1051 VideoRenderer *renderer_;
1052};
1053
1054enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001055 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1056 // values.
1057 DMT_NONE = 0,
1058 DMT_CONTROL = 1,
1059 DMT_BINARY = 2,
1060 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061};
1062
1063// Info about data received in DataMediaChannel. For use in
1064// DataMediaChannel::SignalDataReceived and in all of the signals that
1065// signal fires, on up the chain.
1066struct ReceiveDataParams {
1067 // The in-packet stream indentifier.
1068 // For SCTP, this is really SID, not SSRC.
1069 uint32 ssrc;
1070 // The type of message (binary, text, or control).
1071 DataMessageType type;
1072 // A per-stream value incremented per packet in the stream.
1073 int seq_num;
1074 // A per-stream value monotonically increasing with time.
1075 int timestamp;
1076
1077 ReceiveDataParams() :
1078 ssrc(0),
1079 type(DMT_TEXT),
1080 seq_num(0),
1081 timestamp(0) {
1082 }
1083};
1084
1085struct SendDataParams {
1086 // The in-packet stream indentifier.
1087 // For SCTP, this is really SID, not SSRC.
1088 uint32 ssrc;
1089 // The type of message (binary, text, or control).
1090 DataMessageType type;
1091
1092 // For SCTP, whether to send messages flagged as ordered or not.
1093 // If false, messages can be received out of order.
1094 bool ordered;
1095 // For SCTP, whether the messages are sent reliably or not.
1096 // If false, messages may be lost.
1097 bool reliable;
1098 // For SCTP, if reliable == false, provide partial reliability by
1099 // resending up to this many times. Either count or millis
1100 // is supported, not both at the same time.
1101 int max_rtx_count;
1102 // For SCTP, if reliable == false, provide partial reliability by
1103 // resending for up to this many milliseconds. Either count or millis
1104 // is supported, not both at the same time.
1105 int max_rtx_ms;
1106
1107 SendDataParams() :
1108 ssrc(0),
1109 type(DMT_TEXT),
1110 // TODO(pthatcher): Make these true by default?
1111 ordered(false),
1112 reliable(false),
1113 max_rtx_count(0),
1114 max_rtx_ms(0) {
1115 }
1116};
1117
1118enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1119
1120class DataMediaChannel : public MediaChannel {
1121 public:
1122 enum Error {
1123 ERROR_NONE = 0, // No error.
1124 ERROR_OTHER, // Other errors.
1125 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1126 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1127 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1128 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1129 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1130 };
1131
1132 virtual ~DataMediaChannel() {}
1133
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
1135 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001136
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001137 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
1138 // TODO(pthatcher): Implement this.
1139 virtual bool GetStats(DataMediaInfo* info) { return true; }
1140
1141 virtual bool SetSend(bool send) = 0;
1142 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001143
1144 virtual bool SendData(
1145 const SendDataParams& params,
1146 const talk_base::Buffer& payload,
1147 SendDataResult* result = NULL) = 0;
1148 // Signals when data is received (params, data, len)
1149 sigslot::signal3<const ReceiveDataParams&,
1150 const char*,
1151 size_t> SignalDataReceived;
1152 // Signal errors from MediaChannel. Arguments are:
1153 // ssrc(uint32), and error(DataMediaChannel::Error).
1154 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001155 // Signal when the media channel is ready to send the stream. Arguments are:
1156 // writable(bool)
1157 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158};
1159
1160} // namespace cricket
1161
1162#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_