blob: d7e719278de834ef9df7e9577dcf7ca3ef062b8e [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
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +000053namespace webrtc {
54struct DataChannelInit;
55}
56
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057namespace cricket {
58
59class AudioRenderer;
60struct RtpHeader;
61class ScreencastId;
62struct VideoFormat;
63class VideoCapturer;
64class VideoRenderer;
65
66const int kMinRtpHeaderExtensionId = 1;
67const int kMaxRtpHeaderExtensionId = 255;
68const int kScreencastDefaultFps = 5;
69
70// Used in AudioOptions and VideoOptions to signify "unset" values.
71template <class T>
72class Settable {
73 public:
74 Settable() : set_(false), val_() {}
75 explicit Settable(T val) : set_(true), val_(val) {}
76
77 bool IsSet() const {
78 return set_;
79 }
80
81 bool Get(T* out) const {
82 *out = val_;
83 return set_;
84 }
85
86 T GetWithDefaultIfUnset(const T& default_value) const {
87 return set_ ? val_ : default_value;
88 }
89
90 virtual void Set(T val) {
91 set_ = true;
92 val_ = val;
93 }
94
95 void Clear() {
96 Set(T());
97 set_ = false;
98 }
99
100 void SetFrom(const Settable<T>& o) {
101 // Set this value based on the value of o, iff o is set. If this value is
102 // set and o is unset, the current value will be unchanged.
103 T val;
104 if (o.Get(&val)) {
105 Set(val);
106 }
107 }
108
109 std::string ToString() const {
110 return set_ ? talk_base::ToString(val_) : "";
111 }
112
113 bool operator==(const Settable<T>& o) const {
114 // Equal if both are unset with any value or both set with the same value.
115 return (set_ == o.set_) && (!set_ || (val_ == o.val_));
116 }
117
118 bool operator!=(const Settable<T>& o) const {
119 return !operator==(o);
120 }
121
122 protected:
123 void InitializeValue(const T &val) {
124 val_ = val;
125 }
126
127 private:
128 bool set_;
129 T val_;
130};
131
132class SettablePercent : public Settable<float> {
133 public:
134 virtual void Set(float val) {
135 if (val < 0) {
136 val = 0;
137 }
138 if (val > 1.0) {
139 val = 1.0;
140 }
141 Settable<float>::Set(val);
142 }
143};
144
145template <class T>
146static std::string ToStringIfSet(const char* key, const Settable<T>& val) {
147 std::string str;
148 if (val.IsSet()) {
149 str = key;
150 str += ": ";
151 str += val.ToString();
152 str += ", ";
153 }
154 return str;
155}
156
157// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
158// Used to be flags, but that makes it hard to selectively apply options.
159// We are moving all of the setting of options to structs like this,
160// but some things currently still use flags.
161struct AudioOptions {
162 void SetAll(const AudioOptions& change) {
163 echo_cancellation.SetFrom(change.echo_cancellation);
164 auto_gain_control.SetFrom(change.auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000165 rx_auto_gain_control.SetFrom(change.rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166 noise_suppression.SetFrom(change.noise_suppression);
167 highpass_filter.SetFrom(change.highpass_filter);
168 stereo_swapping.SetFrom(change.stereo_swapping);
169 typing_detection.SetFrom(change.typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000170 aecm_generate_comfort_noise.SetFrom(change.aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 conference_mode.SetFrom(change.conference_mode);
172 adjust_agc_delta.SetFrom(change.adjust_agc_delta);
173 experimental_agc.SetFrom(change.experimental_agc);
174 experimental_aec.SetFrom(change.experimental_aec);
175 aec_dump.SetFrom(change.aec_dump);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000176 experimental_acm.SetFrom(change.experimental_acm);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000177 tx_agc_target_dbov.SetFrom(change.tx_agc_target_dbov);
178 tx_agc_digital_compression_gain.SetFrom(
179 change.tx_agc_digital_compression_gain);
180 tx_agc_limiter.SetFrom(change.tx_agc_limiter);
181 rx_agc_target_dbov.SetFrom(change.rx_agc_target_dbov);
182 rx_agc_digital_compression_gain.SetFrom(
183 change.rx_agc_digital_compression_gain);
184 rx_agc_limiter.SetFrom(change.rx_agc_limiter);
185 recording_sample_rate.SetFrom(change.recording_sample_rate);
186 playout_sample_rate.SetFrom(change.playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000187 dscp.SetFrom(change.dscp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 }
189
190 bool operator==(const AudioOptions& o) const {
191 return echo_cancellation == o.echo_cancellation &&
192 auto_gain_control == o.auto_gain_control &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000193 rx_auto_gain_control == o.rx_auto_gain_control &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 noise_suppression == o.noise_suppression &&
195 highpass_filter == o.highpass_filter &&
196 stereo_swapping == o.stereo_swapping &&
197 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000198 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199 conference_mode == o.conference_mode &&
200 experimental_agc == o.experimental_agc &&
201 experimental_aec == o.experimental_aec &&
202 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000203 aec_dump == o.aec_dump &&
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000204 experimental_acm == o.experimental_acm &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000205 tx_agc_target_dbov == o.tx_agc_target_dbov &&
206 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
207 tx_agc_limiter == o.tx_agc_limiter &&
208 rx_agc_target_dbov == o.rx_agc_target_dbov &&
209 rx_agc_digital_compression_gain == o.rx_agc_digital_compression_gain &&
210 rx_agc_limiter == o.rx_agc_limiter &&
211 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000212 playout_sample_rate == o.playout_sample_rate &&
213 dscp == o.dscp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 }
215
216 std::string ToString() const {
217 std::ostringstream ost;
218 ost << "AudioOptions {";
219 ost << ToStringIfSet("aec", echo_cancellation);
220 ost << ToStringIfSet("agc", auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000221 ost << ToStringIfSet("rx_agc", rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 ost << ToStringIfSet("ns", noise_suppression);
223 ost << ToStringIfSet("hf", highpass_filter);
224 ost << ToStringIfSet("swap", stereo_swapping);
225 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000226 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 ost << ToStringIfSet("conference", conference_mode);
228 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
229 ost << ToStringIfSet("experimental_agc", experimental_agc);
230 ost << ToStringIfSet("experimental_aec", experimental_aec);
231 ost << ToStringIfSet("aec_dump", aec_dump);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000232 ost << ToStringIfSet("experimental_acm", experimental_acm);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000233 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
234 ost << ToStringIfSet("tx_agc_digital_compression_gain",
235 tx_agc_digital_compression_gain);
236 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
237 ost << ToStringIfSet("rx_agc_target_dbov", rx_agc_target_dbov);
238 ost << ToStringIfSet("rx_agc_digital_compression_gain",
239 rx_agc_digital_compression_gain);
240 ost << ToStringIfSet("rx_agc_limiter", rx_agc_limiter);
241 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
242 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000243 ost << ToStringIfSet("dscp", dscp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 ost << "}";
245 return ost.str();
246 }
247
248 // Audio processing that attempts to filter away the output signal from
249 // later inbound pickup.
250 Settable<bool> echo_cancellation;
251 // Audio processing to adjust the sensitivity of the local mic dynamically.
252 Settable<bool> auto_gain_control;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000253 // Audio processing to apply gain to the remote audio.
254 Settable<bool> rx_auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 // Audio processing to filter out background noise.
256 Settable<bool> noise_suppression;
257 // Audio processing to remove background noise of lower frequencies.
258 Settable<bool> highpass_filter;
259 // Audio processing to swap the left and right channels.
260 Settable<bool> stereo_swapping;
261 // Audio processing to detect typing.
262 Settable<bool> typing_detection;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000263 Settable<bool> aecm_generate_comfort_noise;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 Settable<bool> conference_mode;
265 Settable<int> adjust_agc_delta;
266 Settable<bool> experimental_agc;
267 Settable<bool> experimental_aec;
268 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);
292 }
293
294 void SetAll(const VideoOptions& change) {
295 adapt_input_to_encoder.SetFrom(change.adapt_input_to_encoder);
296 adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000297 adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298 adapt_view_switch.SetFrom(change.adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000299 video_adapt_third.SetFrom(change.video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 video_noise_reduction.SetFrom(change.video_noise_reduction);
301 video_three_layers.SetFrom(change.video_three_layers);
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.org28e20752013-07-10 00:45:36 +0000321 }
322
323 bool operator==(const VideoOptions& o) const {
324 return adapt_input_to_encoder == o.adapt_input_to_encoder &&
325 adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000326 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 adapt_view_switch == o.adapt_view_switch &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000328 video_adapt_third == o.video_adapt_third &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 video_noise_reduction == o.video_noise_reduction &&
330 video_three_layers == o.video_three_layers &&
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 &&
347 suspend_below_min_bitrate == o.suspend_below_min_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 }
349
350 std::string ToString() const {
351 std::ostringstream ost;
352 ost << "VideoOptions {";
353 ost << ToStringIfSet("encoder adaption", adapt_input_to_encoder);
354 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000355 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 ost << ToStringIfSet("adapt view switch", adapt_view_switch);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000357 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 ost << ToStringIfSet("noise reduction", video_noise_reduction);
359 ost << ToStringIfSet("3 layers", video_three_layers);
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.org28e20752013-07-10 00:45:36 +0000378 ost << "}";
379 return ost.str();
380 }
381
382 // Encoder adaption, which is the gd callback in LMI, and TBA in WebRTC.
383 Settable<bool> adapt_input_to_encoder;
384 // Enable CPU adaptation?
385 Settable<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000386 // Enable CPU adaptation smoothing?
387 Settable<bool> adapt_cpu_with_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 // Enable Adapt View Switch?
389 Settable<bool> adapt_view_switch;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000390 // Enable video adapt third?
391 Settable<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 // Enable denoising?
393 Settable<bool> video_noise_reduction;
394 // Experimental: Enable multi layer?
395 Settable<bool> video_three_layers;
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.org28e20752013-07-10 00:45:36 +0000429};
430
431// A class for playing out soundclips.
432class SoundclipMedia {
433 public:
434 enum SoundclipFlags {
435 SF_LOOP = 1,
436 };
437
438 virtual ~SoundclipMedia() {}
439
440 // Plays a sound out to the speakers with the given audio stream. The stream
441 // must be 16-bit little-endian 16 kHz PCM. If a stream is already playing
442 // on this SoundclipMedia, it is stopped. If clip is NULL, nothing is played.
443 // Returns whether it was successful.
444 virtual bool PlaySound(const char *clip, int len, int flags) = 0;
445};
446
447struct RtpHeaderExtension {
448 RtpHeaderExtension() : id(0) {}
449 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
450 std::string uri;
451 int id;
452 // TODO(juberti): SendRecv direction;
453
454 bool operator==(const RtpHeaderExtension& ext) const {
455 // id is a reserved word in objective-c. Therefore the id attribute has to
456 // be a fully qualified name in order to compile on IOS.
457 return this->id == ext.id &&
458 uri == ext.uri;
459 }
460};
461
462// Returns the named header extension if found among all extensions, NULL
463// otherwise.
464inline const RtpHeaderExtension* FindHeaderExtension(
465 const std::vector<RtpHeaderExtension>& extensions,
466 const std::string& name) {
467 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
468 it != extensions.end(); ++it) {
469 if (it->uri == name)
470 return &(*it);
471 }
472 return NULL;
473}
474
475enum MediaChannelOptions {
476 // Tune the stream for conference mode.
477 OPT_CONFERENCE = 0x0001
478};
479
480enum VoiceMediaChannelOptions {
481 // Tune the audio stream for vcs with different target levels.
482 OPT_AGC_MINUS_10DB = 0x80000000
483};
484
485// DTMF flags to control if a DTMF tone should be played and/or sent.
486enum DtmfFlags {
487 DF_PLAY = 0x01,
488 DF_SEND = 0x02,
489};
490
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000491class MediaChannel : public sigslot::has_slots<> {
492 public:
493 class NetworkInterface {
494 public:
495 enum SocketType { ST_RTP, ST_RTCP };
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000496 virtual bool SendPacket(
497 talk_base::Buffer* packet,
498 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
499 virtual bool SendRtcp(
500 talk_base::Buffer* packet,
501 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 virtual int SetOption(SocketType type, talk_base::Socket::Option opt,
503 int option) = 0;
504 virtual ~NetworkInterface() {}
505 };
506
507 MediaChannel() : network_interface_(NULL) {}
508 virtual ~MediaChannel() {}
509
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000510 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000511 virtual void SetInterface(NetworkInterface *iface) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000512 talk_base::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513 network_interface_ = iface;
514 }
515
516 // Called when a RTP packet is received.
517 virtual void OnPacketReceived(talk_base::Buffer* packet) = 0;
518 // Called when a RTCP packet is received.
519 virtual void OnRtcpReceived(talk_base::Buffer* packet) = 0;
520 // Called when the socket's ability to send has changed.
521 virtual void OnReadyToSend(bool ready) = 0;
522 // Creates a new outgoing media stream with SSRCs and CNAME as described
523 // by sp.
524 virtual bool AddSendStream(const StreamParams& sp) = 0;
525 // Removes an outgoing media stream.
526 // ssrc must be the first SSRC of the media stream if the stream uses
527 // multiple SSRCs.
528 virtual bool RemoveSendStream(uint32 ssrc) = 0;
529 // Creates a new incoming media stream with SSRCs and CNAME as described
530 // by sp.
531 virtual bool AddRecvStream(const StreamParams& sp) = 0;
532 // Removes an incoming media stream.
533 // ssrc must be the first SSRC of the media stream if the stream uses
534 // multiple SSRCs.
535 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
536
537 // Mutes the channel.
538 virtual bool MuteStream(uint32 ssrc, bool on) = 0;
539
540 // Sets the RTP extension headers and IDs to use when sending RTP.
541 virtual bool SetRecvRtpHeaderExtensions(
542 const std::vector<RtpHeaderExtension>& extensions) = 0;
543 virtual bool SetSendRtpHeaderExtensions(
544 const std::vector<RtpHeaderExtension>& extensions) = 0;
545 // Sets the rate control to use when sending data.
546 virtual bool SetSendBandwidth(bool autobw, int bps) = 0;
547
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000548 // Base method to send packet using NetworkInterface.
549 bool SendPacket(talk_base::Buffer* packet) {
550 return DoSendPacket(packet, false);
551 }
552
553 bool SendRtcp(talk_base::Buffer* packet) {
554 return DoSendPacket(packet, true);
555 }
556
557 int SetOption(NetworkInterface::SocketType type,
558 talk_base::Socket::Option opt,
559 int option) {
560 talk_base::CritScope cs(&network_interface_crit_);
561 if (!network_interface_)
562 return -1;
563
564 return network_interface_->SetOption(type, opt, option);
565 }
566
wu@webrtc.orgde305012013-10-31 15:40:38 +0000567 protected:
568 // This method sets DSCP |value| on both RTP and RTCP channels.
569 int SetDscp(talk_base::DiffServCodePoint value) {
570 int ret;
571 ret = SetOption(NetworkInterface::ST_RTP,
572 talk_base::Socket::OPT_DSCP,
573 value);
574 if (ret == 0) {
575 ret = SetOption(NetworkInterface::ST_RTCP,
576 talk_base::Socket::OPT_DSCP,
577 value);
578 }
579 return ret;
580 }
581
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000582 private:
583 bool DoSendPacket(talk_base::Buffer* packet, bool rtcp) {
584 talk_base::CritScope cs(&network_interface_crit_);
585 if (!network_interface_)
586 return false;
587
588 return (!rtcp) ? network_interface_->SendPacket(packet) :
589 network_interface_->SendRtcp(packet);
590 }
591
592 // |network_interface_| can be accessed from the worker_thread and
593 // from any MediaEngine threads. This critical section is to protect accessing
594 // of network_interface_ object.
595 talk_base::CriticalSection network_interface_crit_;
596 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597};
598
599enum SendFlags {
600 SEND_NOTHING,
601 SEND_RINGBACKTONE,
602 SEND_MICROPHONE
603};
604
wu@webrtc.org97077a32013-10-25 21:18:33 +0000605// The stats information is structured as follows:
606// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
607// Media contains a vector of SSRC infos that are exclusively used by this
608// media. (SSRCs shared between media streams can't be represented.)
609
610// Information about an SSRC.
611// This data may be locally recorded, or received in an RTCP SR or RR.
612struct SsrcSenderInfo {
613 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000615 timestamp(0) {
616 }
617 uint32 ssrc;
618 double timestamp; // NTP timestamp, represented as seconds since epoch.
619};
620
621struct SsrcReceiverInfo {
622 SsrcReceiverInfo()
623 : ssrc(0),
624 timestamp(0) {
625 }
626 uint32 ssrc;
627 double timestamp;
628};
629
630struct MediaSenderInfo {
631 MediaSenderInfo()
632 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633 packets_sent(0),
634 packets_lost(0),
635 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000636 rtt_ms(0) {
637 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000638 void add_ssrc(const SsrcSenderInfo& stat) {
639 local_stats.push_back(stat);
640 }
641 // Temporary utility function for call sites that only provide SSRC.
642 // As more info is added into SsrcSenderInfo, this function should go away.
643 void add_ssrc(uint32 ssrc) {
644 SsrcSenderInfo stat;
645 stat.ssrc = ssrc;
646 add_ssrc(stat);
647 }
648 // Utility accessor for clients that are only interested in ssrc numbers.
649 std::vector<uint32> ssrcs() const {
650 std::vector<uint32> retval;
651 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
652 it != local_stats.end(); ++it) {
653 retval.push_back(it->ssrc);
654 }
655 return retval;
656 }
657 // Utility accessor for clients that make the assumption only one ssrc
658 // exists per media.
659 // This will eventually go away.
660 uint32 ssrc() const {
661 if (local_stats.size() > 0) {
662 return local_stats[0].ssrc;
663 } else {
664 return 0;
665 }
666 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000667 int64 bytes_sent;
668 int packets_sent;
669 int packets_lost;
670 float fraction_lost;
671 int rtt_ms;
672 std::string codec_name;
673 std::vector<SsrcSenderInfo> local_stats;
674 std::vector<SsrcReceiverInfo> remote_stats;
675};
676
677struct MediaReceiverInfo {
678 MediaReceiverInfo()
679 : bytes_rcvd(0),
680 packets_rcvd(0),
681 packets_lost(0),
682 fraction_lost(0.0) {
683 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000684 void add_ssrc(const SsrcReceiverInfo& stat) {
685 local_stats.push_back(stat);
686 }
687 // Temporary utility function for call sites that only provide SSRC.
688 // As more info is added into SsrcSenderInfo, this function should go away.
689 void add_ssrc(uint32 ssrc) {
690 SsrcReceiverInfo stat;
691 stat.ssrc = ssrc;
692 add_ssrc(stat);
693 }
694 std::vector<uint32> ssrcs() const {
695 std::vector<uint32> retval;
696 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
697 it != local_stats.end(); ++it) {
698 retval.push_back(it->ssrc);
699 }
700 return retval;
701 }
702 // Utility accessor for clients that make the assumption only one ssrc
703 // exists per media.
704 // This will eventually go away.
705 uint32 ssrc() const {
706 if (local_stats.size() > 0) {
707 return local_stats[0].ssrc;
708 } else {
709 return 0;
710 }
711 }
712
wu@webrtc.org97077a32013-10-25 21:18:33 +0000713 int64 bytes_rcvd;
714 int packets_rcvd;
715 int packets_lost;
716 float fraction_lost;
717 std::vector<SsrcReceiverInfo> local_stats;
718 std::vector<SsrcSenderInfo> remote_stats;
719};
720
721struct VoiceSenderInfo : public MediaSenderInfo {
722 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000723 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 jitter_ms(0),
725 audio_level(0),
726 aec_quality_min(0.0),
727 echo_delay_median_ms(0),
728 echo_delay_std_ms(0),
729 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000730 echo_return_loss_enhancement(0),
731 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 }
733
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 int jitter_ms;
736 int audio_level;
737 float aec_quality_min;
738 int echo_delay_median_ms;
739 int echo_delay_std_ms;
740 int echo_return_loss;
741 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000742 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743};
744
wu@webrtc.org97077a32013-10-25 21:18:33 +0000745struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746 VoiceReceiverInfo()
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 jitter_buffer_ms(0),
750 jitter_buffer_preferred_ms(0),
751 delay_estimate_ms(0),
752 audio_level(0),
753 expand_rate(0) {
754 }
755
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 int ext_seqnum;
757 int jitter_ms;
758 int jitter_buffer_ms;
759 int jitter_buffer_preferred_ms;
760 int delay_estimate_ms;
761 int audio_level;
762 // fraction of synthesized speech inserted through pre-emptive expansion
763 float expand_rate;
764};
765
wu@webrtc.org97077a32013-10-25 21:18:33 +0000766struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767 VideoSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000768 : packets_cached(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 firs_rcvd(0),
770 nacks_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771 frame_width(0),
772 frame_height(0),
773 framerate_input(0),
774 framerate_sent(0),
775 nominal_bitrate(0),
776 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000777 adapt_reason(0),
778 capture_jitter_ms(0),
779 avg_encode_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780 }
781
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 int firs_rcvd;
785 int nacks_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 int frame_width;
787 int frame_height;
788 int framerate_input;
789 int framerate_sent;
790 int nominal_bitrate;
791 int preferred_bitrate;
792 int adapt_reason;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000793 int capture_jitter_ms;
794 int avg_encode_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795};
796
wu@webrtc.org97077a32013-10-25 21:18:33 +0000797struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 VideoReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000799 : packets_concealed(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 firs_sent(0),
801 nacks_sent(0),
802 frame_width(0),
803 frame_height(0),
804 framerate_rcvd(0),
805 framerate_decoded(0),
806 framerate_output(0),
807 framerate_render_input(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000808 framerate_render_output(0),
809 decode_ms(0),
810 max_decode_ms(0),
811 jitter_buffer_ms(0),
812 min_playout_delay_ms(0),
813 render_delay_ms(0),
814 target_delay_ms(0),
815 current_delay_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 }
817
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 int firs_sent;
821 int nacks_sent;
822 int frame_width;
823 int frame_height;
824 int framerate_rcvd;
825 int framerate_decoded;
826 int framerate_output;
827 // Framerate as sent to the renderer.
828 int framerate_render_input;
829 // Framerate that the renderer reports.
830 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000831
832 // All stats below are gathered per-VideoReceiver, but some will be correlated
833 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
834 // structures, reflect this in the new layout.
835
836 // Current frame decode latency.
837 int decode_ms;
838 // Maximum observed frame decode latency.
839 int max_decode_ms;
840 // Jitter (network-related) latency.
841 int jitter_buffer_ms;
842 // Requested minimum playout latency.
843 int min_playout_delay_ms;
844 // Requested latency to account for rendering delay.
845 int render_delay_ms;
846 // Target overall delay: network+decode+render, accounting for
847 // min_playout_delay_ms.
848 int target_delay_ms;
849 // Current overall delay, possibly ramping towards target_delay_ms.
850 int current_delay_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851};
852
wu@webrtc.org97077a32013-10-25 21:18:33 +0000853struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000855 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 }
857
858 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859};
860
wu@webrtc.org97077a32013-10-25 21:18:33 +0000861struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000863 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 }
865
866 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867};
868
869struct BandwidthEstimationInfo {
870 BandwidthEstimationInfo()
871 : available_send_bandwidth(0),
872 available_recv_bandwidth(0),
873 target_enc_bitrate(0),
874 actual_enc_bitrate(0),
875 retransmit_bitrate(0),
876 transmit_bitrate(0),
877 bucket_delay(0) {
878 }
879
880 int available_send_bandwidth;
881 int available_recv_bandwidth;
882 int target_enc_bitrate;
883 int actual_enc_bitrate;
884 int retransmit_bitrate;
885 int transmit_bitrate;
886 int bucket_delay;
887};
888
889struct VoiceMediaInfo {
890 void Clear() {
891 senders.clear();
892 receivers.clear();
893 }
894 std::vector<VoiceSenderInfo> senders;
895 std::vector<VoiceReceiverInfo> receivers;
896};
897
898struct VideoMediaInfo {
899 void Clear() {
900 senders.clear();
901 receivers.clear();
902 bw_estimations.clear();
903 }
904 std::vector<VideoSenderInfo> senders;
905 std::vector<VideoReceiverInfo> receivers;
906 std::vector<BandwidthEstimationInfo> bw_estimations;
907};
908
909struct DataMediaInfo {
910 void Clear() {
911 senders.clear();
912 receivers.clear();
913 }
914 std::vector<DataSenderInfo> senders;
915 std::vector<DataReceiverInfo> receivers;
916};
917
918class VoiceMediaChannel : public MediaChannel {
919 public:
920 enum Error {
921 ERROR_NONE = 0, // No error.
922 ERROR_OTHER, // Other errors.
923 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
924 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
925 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
926 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
927 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
928 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
929 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
930 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
931 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
932 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
933 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
934 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
935 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
936 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
937 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
938 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
939 };
940
941 VoiceMediaChannel() {}
942 virtual ~VoiceMediaChannel() {}
943 // Sets the codecs/payload types to be used for incoming media.
944 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
945 // Sets the codecs/payload types to be used for outgoing media.
946 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
947 // Starts or stops playout of received audio.
948 virtual bool SetPlayout(bool playout) = 0;
949 // Starts or stops sending (and potentially capture) of local audio.
950 virtual bool SetSend(SendFlags flag) = 0;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000951 // Sets the renderer object to be used for the specified remote audio stream.
952 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
953 // Sets the renderer object to be used for the specified local audio stream.
954 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 // Gets current energy levels for all incoming streams.
956 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
957 // Get the current energy level of the stream sent to the speaker.
958 virtual int GetOutputLevel() = 0;
959 // Get the time in milliseconds since last recorded keystroke, or negative.
960 virtual int GetTimeSinceLastTyping() = 0;
961 // Temporarily exposed field for tuning typing detect options.
962 virtual void SetTypingDetectionParameters(int time_window,
963 int cost_per_typing, int reporting_threshold, int penalty_decay,
964 int type_event_delay) = 0;
965 // Set left and right scale for speaker output volume of the specified ssrc.
966 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
967 // Get left and right scale for speaker output volume of the specified ssrc.
968 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0;
969 // Specifies a ringback tone to be played during call setup.
970 virtual bool SetRingbackTone(const char *buf, int len) = 0;
971 // Plays or stops the aforementioned ringback tone
972 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
973 // Returns if the telephone-event has been negotiated.
974 virtual bool CanInsertDtmf() { return false; }
975 // Send and/or play a DTMF |event| according to the |flags|.
976 // The DTMF out-of-band signal will be used on sending.
977 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000978 // The valid value for the |event| are 0 to 15 which corresponding to
979 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
981 // Gets quality stats for the channel.
982 virtual bool GetStats(VoiceMediaInfo* info) = 0;
983 // Gets last reported error for this media channel.
984 virtual void GetLastMediaError(uint32* ssrc,
985 VoiceMediaChannel::Error* error) {
986 ASSERT(error != NULL);
987 *error = ERROR_NONE;
988 }
989 // Sets the media options to use.
990 virtual bool SetOptions(const AudioOptions& options) = 0;
991 virtual bool GetOptions(AudioOptions* options) const = 0;
992
993 // Signal errors from MediaChannel. Arguments are:
994 // ssrc(uint32), and error(VoiceMediaChannel::Error).
995 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
996};
997
998class VideoMediaChannel : public MediaChannel {
999 public:
1000 enum Error {
1001 ERROR_NONE = 0, // No error.
1002 ERROR_OTHER, // Other errors.
1003 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1004 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1005 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1006 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1007 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1008 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1009 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1010 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1011 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1012 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1013 };
1014
1015 VideoMediaChannel() : renderer_(NULL) {}
1016 virtual ~VideoMediaChannel() {}
1017 // Sets the codecs/payload types to be used for incoming media.
1018 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
1019 // Sets the codecs/payload types to be used for outgoing media.
1020 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
1021 // Gets the currently set codecs/payload types to be used for outgoing media.
1022 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1023 // Sets the format of a specified outgoing stream.
1024 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
1025 // Starts or stops playout of received video.
1026 virtual bool SetRender(bool render) = 0;
1027 // Starts or stops transmission (and potentially capture) of local video.
1028 virtual bool SetSend(bool send) = 0;
1029 // Sets the renderer object to be used for the specified stream.
1030 // If SSRC is 0, the renderer is used for the 'default' stream.
1031 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
1032 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1033 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
1034 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
1035 // Gets quality stats for the channel.
1036 virtual bool GetStats(VideoMediaInfo* info) = 0;
1037
1038 // Send an intra frame to the receivers.
1039 virtual bool SendIntraFrame() = 0;
1040 // Reuqest each of the remote senders to send an intra frame.
1041 virtual bool RequestIntraFrame() = 0;
1042 // Sets the media options to use.
1043 virtual bool SetOptions(const VideoOptions& options) = 0;
1044 virtual bool GetOptions(VideoOptions* options) const = 0;
1045 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1046
1047 // Signal errors from MediaChannel. Arguments are:
1048 // ssrc(uint32), and error(VideoMediaChannel::Error).
1049 sigslot::signal2<uint32, Error> SignalMediaError;
1050
1051 protected:
1052 VideoRenderer *renderer_;
1053};
1054
1055enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001056 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1057 // values.
1058 DMT_NONE = 0,
1059 DMT_CONTROL = 1,
1060 DMT_BINARY = 2,
1061 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062};
1063
1064// Info about data received in DataMediaChannel. For use in
1065// DataMediaChannel::SignalDataReceived and in all of the signals that
1066// signal fires, on up the chain.
1067struct ReceiveDataParams {
1068 // The in-packet stream indentifier.
1069 // For SCTP, this is really SID, not SSRC.
1070 uint32 ssrc;
1071 // The type of message (binary, text, or control).
1072 DataMessageType type;
1073 // A per-stream value incremented per packet in the stream.
1074 int seq_num;
1075 // A per-stream value monotonically increasing with time.
1076 int timestamp;
1077
1078 ReceiveDataParams() :
1079 ssrc(0),
1080 type(DMT_TEXT),
1081 seq_num(0),
1082 timestamp(0) {
1083 }
1084};
1085
1086struct SendDataParams {
1087 // The in-packet stream indentifier.
1088 // For SCTP, this is really SID, not SSRC.
1089 uint32 ssrc;
1090 // The type of message (binary, text, or control).
1091 DataMessageType type;
1092
1093 // For SCTP, whether to send messages flagged as ordered or not.
1094 // If false, messages can be received out of order.
1095 bool ordered;
1096 // For SCTP, whether the messages are sent reliably or not.
1097 // If false, messages may be lost.
1098 bool reliable;
1099 // For SCTP, if reliable == false, provide partial reliability by
1100 // resending up to this many times. Either count or millis
1101 // is supported, not both at the same time.
1102 int max_rtx_count;
1103 // For SCTP, if reliable == false, provide partial reliability by
1104 // resending for up to this many milliseconds. Either count or millis
1105 // is supported, not both at the same time.
1106 int max_rtx_ms;
1107
1108 SendDataParams() :
1109 ssrc(0),
1110 type(DMT_TEXT),
1111 // TODO(pthatcher): Make these true by default?
1112 ordered(false),
1113 reliable(false),
1114 max_rtx_count(0),
1115 max_rtx_ms(0) {
1116 }
1117};
1118
1119enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1120
1121class DataMediaChannel : public MediaChannel {
1122 public:
1123 enum Error {
1124 ERROR_NONE = 0, // No error.
1125 ERROR_OTHER, // Other errors.
1126 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1127 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1128 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1129 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1130 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1131 };
1132
1133 virtual ~DataMediaChannel() {}
1134
1135 virtual bool SetSendBandwidth(bool autobw, int bps) = 0;
1136 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
1137 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
1138 virtual bool SetRecvRtpHeaderExtensions(
1139 const std::vector<RtpHeaderExtension>& extensions) = 0;
1140 virtual bool SetSendRtpHeaderExtensions(
1141 const std::vector<RtpHeaderExtension>& extensions) = 0;
1142 virtual bool AddSendStream(const StreamParams& sp) = 0;
1143 virtual bool RemoveSendStream(uint32 ssrc) = 0;
1144 virtual bool AddRecvStream(const StreamParams& sp) = 0;
1145 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
1146 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
1147 // TODO(pthatcher): Implement this.
1148 virtual bool GetStats(DataMediaInfo* info) { return true; }
1149
1150 virtual bool SetSend(bool send) = 0;
1151 virtual bool SetReceive(bool receive) = 0;
1152 virtual void OnPacketReceived(talk_base::Buffer* packet) = 0;
1153 virtual void OnRtcpReceived(talk_base::Buffer* packet) = 0;
1154
1155 virtual bool SendData(
1156 const SendDataParams& params,
1157 const talk_base::Buffer& payload,
1158 SendDataResult* result = NULL) = 0;
1159 // Signals when data is received (params, data, len)
1160 sigslot::signal3<const ReceiveDataParams&,
1161 const char*,
1162 size_t> SignalDataReceived;
1163 // Signal errors from MediaChannel. Arguments are:
1164 // ssrc(uint32), and error(DataMediaChannel::Error).
1165 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001166 // Signal when the media channel is ready to send the stream. Arguments are:
1167 // writable(bool)
1168 sigslot::signal1<bool> SignalReadyToSend;
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00001169 // Signal for notifying when a new stream is added from the remote side. Used
1170 // for the in-band negotioation through the OPEN message for SCTP data
1171 // channel.
1172 sigslot::signal2<const std::string&, const webrtc::DataChannelInit&>
1173 SignalNewStreamReceived;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174};
1175
1176} // namespace cricket
1177
1178#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_