blob: 919248f7f37bd54734a1d7945fa26ffb51092f25 [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);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000176 tx_agc_target_dbov.SetFrom(change.tx_agc_target_dbov);
177 tx_agc_digital_compression_gain.SetFrom(
178 change.tx_agc_digital_compression_gain);
179 tx_agc_limiter.SetFrom(change.tx_agc_limiter);
180 rx_agc_target_dbov.SetFrom(change.rx_agc_target_dbov);
181 rx_agc_digital_compression_gain.SetFrom(
182 change.rx_agc_digital_compression_gain);
183 rx_agc_limiter.SetFrom(change.rx_agc_limiter);
184 recording_sample_rate.SetFrom(change.recording_sample_rate);
185 playout_sample_rate.SetFrom(change.playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000186 dscp.SetFrom(change.dscp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 }
188
189 bool operator==(const AudioOptions& o) const {
190 return echo_cancellation == o.echo_cancellation &&
191 auto_gain_control == o.auto_gain_control &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000192 rx_auto_gain_control == o.rx_auto_gain_control &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 noise_suppression == o.noise_suppression &&
194 highpass_filter == o.highpass_filter &&
195 stereo_swapping == o.stereo_swapping &&
196 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000197 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 conference_mode == o.conference_mode &&
199 experimental_agc == o.experimental_agc &&
200 experimental_aec == o.experimental_aec &&
201 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000202 aec_dump == o.aec_dump &&
203 tx_agc_target_dbov == o.tx_agc_target_dbov &&
204 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
205 tx_agc_limiter == o.tx_agc_limiter &&
206 rx_agc_target_dbov == o.rx_agc_target_dbov &&
207 rx_agc_digital_compression_gain == o.rx_agc_digital_compression_gain &&
208 rx_agc_limiter == o.rx_agc_limiter &&
209 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000210 playout_sample_rate == o.playout_sample_rate &&
211 dscp == o.dscp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 }
213
214 std::string ToString() const {
215 std::ostringstream ost;
216 ost << "AudioOptions {";
217 ost << ToStringIfSet("aec", echo_cancellation);
218 ost << ToStringIfSet("agc", auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000219 ost << ToStringIfSet("rx_agc", rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 ost << ToStringIfSet("ns", noise_suppression);
221 ost << ToStringIfSet("hf", highpass_filter);
222 ost << ToStringIfSet("swap", stereo_swapping);
223 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000224 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 ost << ToStringIfSet("conference", conference_mode);
226 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
227 ost << ToStringIfSet("experimental_agc", experimental_agc);
228 ost << ToStringIfSet("experimental_aec", experimental_aec);
229 ost << ToStringIfSet("aec_dump", aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000230 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
231 ost << ToStringIfSet("tx_agc_digital_compression_gain",
232 tx_agc_digital_compression_gain);
233 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
234 ost << ToStringIfSet("rx_agc_target_dbov", rx_agc_target_dbov);
235 ost << ToStringIfSet("rx_agc_digital_compression_gain",
236 rx_agc_digital_compression_gain);
237 ost << ToStringIfSet("rx_agc_limiter", rx_agc_limiter);
238 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
239 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000240 ost << ToStringIfSet("dscp", dscp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 ost << "}";
242 return ost.str();
243 }
244
245 // Audio processing that attempts to filter away the output signal from
246 // later inbound pickup.
247 Settable<bool> echo_cancellation;
248 // Audio processing to adjust the sensitivity of the local mic dynamically.
249 Settable<bool> auto_gain_control;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000250 // Audio processing to apply gain to the remote audio.
251 Settable<bool> rx_auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 // Audio processing to filter out background noise.
253 Settable<bool> noise_suppression;
254 // Audio processing to remove background noise of lower frequencies.
255 Settable<bool> highpass_filter;
256 // Audio processing to swap the left and right channels.
257 Settable<bool> stereo_swapping;
258 // Audio processing to detect typing.
259 Settable<bool> typing_detection;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000260 Settable<bool> aecm_generate_comfort_noise;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 Settable<bool> conference_mode;
262 Settable<int> adjust_agc_delta;
263 Settable<bool> experimental_agc;
264 Settable<bool> experimental_aec;
265 Settable<bool> aec_dump;
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);
297 video_three_layers.SetFrom(change.video_three_layers);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298 video_one_layer_screencast.SetFrom(change.video_one_layer_screencast);
299 video_high_bitrate.SetFrom(change.video_high_bitrate);
300 video_watermark.SetFrom(change.video_watermark);
301 video_temporal_layer_screencast.SetFrom(
302 change.video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000303 video_temporal_layer_realtime.SetFrom(
304 change.video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 video_leaky_bucket.SetFrom(change.video_leaky_bucket);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000306 cpu_overuse_detection.SetFrom(change.cpu_overuse_detection);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 conference_mode.SetFrom(change.conference_mode);
308 process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
309 system_low_adaptation_threshhold.SetFrom(
310 change.system_low_adaptation_threshhold);
311 system_high_adaptation_threshhold.SetFrom(
312 change.system_high_adaptation_threshhold);
313 buffered_mode_latency.SetFrom(change.buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000314 lower_min_bitrate.SetFrom(change.lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000315 dscp.SetFrom(change.dscp);
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 &&
325 video_three_layers == o.video_three_layers &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 video_one_layer_screencast == o.video_one_layer_screencast &&
327 video_high_bitrate == o.video_high_bitrate &&
328 video_watermark == o.video_watermark &&
329 video_temporal_layer_screencast == o.video_temporal_layer_screencast &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000330 video_temporal_layer_realtime == o.video_temporal_layer_realtime &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 video_leaky_bucket == o.video_leaky_bucket &&
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000332 cpu_overuse_detection == o.cpu_overuse_detection &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 conference_mode == o.conference_mode &&
334 process_adaptation_threshhold == o.process_adaptation_threshhold &&
335 system_low_adaptation_threshhold ==
336 o.system_low_adaptation_threshhold &&
337 system_high_adaptation_threshhold ==
338 o.system_high_adaptation_threshhold &&
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000339 buffered_mode_latency == o.buffered_mode_latency &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000340 lower_min_bitrate == o.lower_min_bitrate &&
341 dscp == o.dscp;
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);
353 ost << ToStringIfSet("3 layers", video_three_layers);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000354 ost << ToStringIfSet("1 layer screencast", video_one_layer_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 ost << ToStringIfSet("high bitrate", video_high_bitrate);
356 ost << ToStringIfSet("watermark", video_watermark);
357 ost << ToStringIfSet("video temporal layer screencast",
358 video_temporal_layer_screencast);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000359 ost << ToStringIfSet("video temporal layer realtime",
360 video_temporal_layer_realtime);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 ost << ToStringIfSet("leaky bucket", video_leaky_bucket);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000362 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 ost << ToStringIfSet("conference mode", conference_mode);
364 ost << ToStringIfSet("process", process_adaptation_threshhold);
365 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
366 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
367 ost << ToStringIfSet("buffered mode latency", buffered_mode_latency);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000368 ost << ToStringIfSet("lower min bitrate", lower_min_bitrate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000369 ost << ToStringIfSet("dscp", dscp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 ost << "}";
371 return ost.str();
372 }
373
374 // Encoder adaption, which is the gd callback in LMI, and TBA in WebRTC.
375 Settable<bool> adapt_input_to_encoder;
376 // Enable CPU adaptation?
377 Settable<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000378 // Enable CPU adaptation smoothing?
379 Settable<bool> adapt_cpu_with_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 // Enable Adapt View Switch?
381 Settable<bool> adapt_view_switch;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000382 // Enable video adapt third?
383 Settable<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 // Enable denoising?
385 Settable<bool> video_noise_reduction;
386 // Experimental: Enable multi layer?
387 Settable<bool> video_three_layers;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 // Experimental: Enable one layer screencast?
389 Settable<bool> video_one_layer_screencast;
390 // Experimental: Enable WebRtc higher bitrate?
391 Settable<bool> video_high_bitrate;
392 // Experimental: Add watermark to the rendered video image.
393 Settable<bool> video_watermark;
394 // Experimental: Enable WebRTC layered screencast.
395 Settable<bool> video_temporal_layer_screencast;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000396 // Experimental: Enable WebRTC temporal layer strategy for realtime video.
397 Settable<bool> video_temporal_layer_realtime;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398 // Enable WebRTC leaky bucket when sending media packets.
399 Settable<bool> video_leaky_bucket;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000400 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
401 // adaptation algorithm. So this option will override the
402 // |adapt_input_to_cpu_usage|.
403 Settable<bool> cpu_overuse_detection;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 // Use conference mode?
405 Settable<bool> conference_mode;
406 // Threshhold for process cpu adaptation. (Process limit)
407 SettablePercent process_adaptation_threshhold;
408 // Low threshhold for cpu adaptation. (Adapt up)
409 SettablePercent system_low_adaptation_threshhold;
410 // High threshhold for cpu adaptation. (Adapt down)
411 SettablePercent system_high_adaptation_threshhold;
412 // Specify buffered mode latency in milliseconds.
413 Settable<int> buffered_mode_latency;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000414 // Make minimum configured send bitrate even lower than usual, at 30kbit.
415 Settable<bool> lower_min_bitrate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000416 // Set DSCP value for packet sent from video channel.
417 Settable<bool> dscp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418};
419
420// A class for playing out soundclips.
421class SoundclipMedia {
422 public:
423 enum SoundclipFlags {
424 SF_LOOP = 1,
425 };
426
427 virtual ~SoundclipMedia() {}
428
429 // Plays a sound out to the speakers with the given audio stream. The stream
430 // must be 16-bit little-endian 16 kHz PCM. If a stream is already playing
431 // on this SoundclipMedia, it is stopped. If clip is NULL, nothing is played.
432 // Returns whether it was successful.
433 virtual bool PlaySound(const char *clip, int len, int flags) = 0;
434};
435
436struct RtpHeaderExtension {
437 RtpHeaderExtension() : id(0) {}
438 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
439 std::string uri;
440 int id;
441 // TODO(juberti): SendRecv direction;
442
443 bool operator==(const RtpHeaderExtension& ext) const {
444 // id is a reserved word in objective-c. Therefore the id attribute has to
445 // be a fully qualified name in order to compile on IOS.
446 return this->id == ext.id &&
447 uri == ext.uri;
448 }
449};
450
451// Returns the named header extension if found among all extensions, NULL
452// otherwise.
453inline const RtpHeaderExtension* FindHeaderExtension(
454 const std::vector<RtpHeaderExtension>& extensions,
455 const std::string& name) {
456 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
457 it != extensions.end(); ++it) {
458 if (it->uri == name)
459 return &(*it);
460 }
461 return NULL;
462}
463
464enum MediaChannelOptions {
465 // Tune the stream for conference mode.
466 OPT_CONFERENCE = 0x0001
467};
468
469enum VoiceMediaChannelOptions {
470 // Tune the audio stream for vcs with different target levels.
471 OPT_AGC_MINUS_10DB = 0x80000000
472};
473
474// DTMF flags to control if a DTMF tone should be played and/or sent.
475enum DtmfFlags {
476 DF_PLAY = 0x01,
477 DF_SEND = 0x02,
478};
479
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480class MediaChannel : public sigslot::has_slots<> {
481 public:
482 class NetworkInterface {
483 public:
484 enum SocketType { ST_RTP, ST_RTCP };
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000485 virtual bool SendPacket(
486 talk_base::Buffer* packet,
487 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
488 virtual bool SendRtcp(
489 talk_base::Buffer* packet,
490 talk_base::DiffServCodePoint dscp = talk_base::DSCP_NO_CHANGE) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000491 virtual int SetOption(SocketType type, talk_base::Socket::Option opt,
492 int option) = 0;
493 virtual ~NetworkInterface() {}
494 };
495
496 MediaChannel() : network_interface_(NULL) {}
497 virtual ~MediaChannel() {}
498
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000499 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000500 virtual void SetInterface(NetworkInterface *iface) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000501 talk_base::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 network_interface_ = iface;
503 }
504
505 // Called when a RTP packet is received.
506 virtual void OnPacketReceived(talk_base::Buffer* packet) = 0;
507 // Called when a RTCP packet is received.
508 virtual void OnRtcpReceived(talk_base::Buffer* packet) = 0;
509 // Called when the socket's ability to send has changed.
510 virtual void OnReadyToSend(bool ready) = 0;
511 // Creates a new outgoing media stream with SSRCs and CNAME as described
512 // by sp.
513 virtual bool AddSendStream(const StreamParams& sp) = 0;
514 // Removes an outgoing media stream.
515 // ssrc must be the first SSRC of the media stream if the stream uses
516 // multiple SSRCs.
517 virtual bool RemoveSendStream(uint32 ssrc) = 0;
518 // Creates a new incoming media stream with SSRCs and CNAME as described
519 // by sp.
520 virtual bool AddRecvStream(const StreamParams& sp) = 0;
521 // Removes an incoming media stream.
522 // ssrc must be the first SSRC of the media stream if the stream uses
523 // multiple SSRCs.
524 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
525
526 // Mutes the channel.
527 virtual bool MuteStream(uint32 ssrc, bool on) = 0;
528
529 // Sets the RTP extension headers and IDs to use when sending RTP.
530 virtual bool SetRecvRtpHeaderExtensions(
531 const std::vector<RtpHeaderExtension>& extensions) = 0;
532 virtual bool SetSendRtpHeaderExtensions(
533 const std::vector<RtpHeaderExtension>& extensions) = 0;
534 // Sets the rate control to use when sending data.
535 virtual bool SetSendBandwidth(bool autobw, int bps) = 0;
536
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000537 // Base method to send packet using NetworkInterface.
538 bool SendPacket(talk_base::Buffer* packet) {
539 return DoSendPacket(packet, false);
540 }
541
542 bool SendRtcp(talk_base::Buffer* packet) {
543 return DoSendPacket(packet, true);
544 }
545
546 int SetOption(NetworkInterface::SocketType type,
547 talk_base::Socket::Option opt,
548 int option) {
549 talk_base::CritScope cs(&network_interface_crit_);
550 if (!network_interface_)
551 return -1;
552
553 return network_interface_->SetOption(type, opt, option);
554 }
555
wu@webrtc.orgde305012013-10-31 15:40:38 +0000556 protected:
557 // This method sets DSCP |value| on both RTP and RTCP channels.
558 int SetDscp(talk_base::DiffServCodePoint value) {
559 int ret;
560 ret = SetOption(NetworkInterface::ST_RTP,
561 talk_base::Socket::OPT_DSCP,
562 value);
563 if (ret == 0) {
564 ret = SetOption(NetworkInterface::ST_RTCP,
565 talk_base::Socket::OPT_DSCP,
566 value);
567 }
568 return ret;
569 }
570
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000571 private:
572 bool DoSendPacket(talk_base::Buffer* packet, bool rtcp) {
573 talk_base::CritScope cs(&network_interface_crit_);
574 if (!network_interface_)
575 return false;
576
577 return (!rtcp) ? network_interface_->SendPacket(packet) :
578 network_interface_->SendRtcp(packet);
579 }
580
581 // |network_interface_| can be accessed from the worker_thread and
582 // from any MediaEngine threads. This critical section is to protect accessing
583 // of network_interface_ object.
584 talk_base::CriticalSection network_interface_crit_;
585 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000586};
587
588enum SendFlags {
589 SEND_NOTHING,
590 SEND_RINGBACKTONE,
591 SEND_MICROPHONE
592};
593
wu@webrtc.org97077a32013-10-25 21:18:33 +0000594// The stats information is structured as follows:
595// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
596// Media contains a vector of SSRC infos that are exclusively used by this
597// media. (SSRCs shared between media streams can't be represented.)
598
599// Information about an SSRC.
600// This data may be locally recorded, or received in an RTCP SR or RR.
601struct SsrcSenderInfo {
602 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000604 timestamp(0) {
605 }
606 uint32 ssrc;
607 double timestamp; // NTP timestamp, represented as seconds since epoch.
608};
609
610struct SsrcReceiverInfo {
611 SsrcReceiverInfo()
612 : ssrc(0),
613 timestamp(0) {
614 }
615 uint32 ssrc;
616 double timestamp;
617};
618
619struct MediaSenderInfo {
620 MediaSenderInfo()
621 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 packets_sent(0),
623 packets_lost(0),
624 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000625 rtt_ms(0) {
626 }
627 int64 bytes_sent;
628 int packets_sent;
629 int packets_lost;
630 float fraction_lost;
631 int rtt_ms;
632 std::string codec_name;
633 std::vector<SsrcSenderInfo> local_stats;
634 std::vector<SsrcReceiverInfo> remote_stats;
635};
636
637struct MediaReceiverInfo {
638 MediaReceiverInfo()
639 : bytes_rcvd(0),
640 packets_rcvd(0),
641 packets_lost(0),
642 fraction_lost(0.0) {
643 }
644 int64 bytes_rcvd;
645 int packets_rcvd;
646 int packets_lost;
647 float fraction_lost;
648 std::vector<SsrcReceiverInfo> local_stats;
649 std::vector<SsrcSenderInfo> remote_stats;
650};
651
652struct VoiceSenderInfo : public MediaSenderInfo {
653 VoiceSenderInfo()
654 : ssrc(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655 ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656 jitter_ms(0),
657 audio_level(0),
658 aec_quality_min(0.0),
659 echo_delay_median_ms(0),
660 echo_delay_std_ms(0),
661 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000662 echo_return_loss_enhancement(0),
663 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 }
665
666 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000667 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668 int jitter_ms;
669 int audio_level;
670 float aec_quality_min;
671 int echo_delay_median_ms;
672 int echo_delay_std_ms;
673 int echo_return_loss;
674 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000675 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676};
677
wu@webrtc.org97077a32013-10-25 21:18:33 +0000678struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 VoiceReceiverInfo()
680 : ssrc(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681 ext_seqnum(0),
682 jitter_ms(0),
683 jitter_buffer_ms(0),
684 jitter_buffer_preferred_ms(0),
685 delay_estimate_ms(0),
686 audio_level(0),
687 expand_rate(0) {
688 }
689
690 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 int ext_seqnum;
692 int jitter_ms;
693 int jitter_buffer_ms;
694 int jitter_buffer_preferred_ms;
695 int delay_estimate_ms;
696 int audio_level;
697 // fraction of synthesized speech inserted through pre-emptive expansion
698 float expand_rate;
699};
700
wu@webrtc.org97077a32013-10-25 21:18:33 +0000701struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702 VideoSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000703 : packets_cached(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 firs_rcvd(0),
705 nacks_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706 frame_width(0),
707 frame_height(0),
708 framerate_input(0),
709 framerate_sent(0),
710 nominal_bitrate(0),
711 preferred_bitrate(0),
712 adapt_reason(0) {
713 }
714
715 std::vector<uint32> ssrcs;
716 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 int firs_rcvd;
719 int nacks_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720 int frame_width;
721 int frame_height;
722 int framerate_input;
723 int framerate_sent;
724 int nominal_bitrate;
725 int preferred_bitrate;
726 int adapt_reason;
727};
728
wu@webrtc.org97077a32013-10-25 21:18:33 +0000729struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 VideoReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000731 : packets_concealed(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 firs_sent(0),
733 nacks_sent(0),
734 frame_width(0),
735 frame_height(0),
736 framerate_rcvd(0),
737 framerate_decoded(0),
738 framerate_output(0),
739 framerate_render_input(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000740 framerate_render_output(0),
741 decode_ms(0),
742 max_decode_ms(0),
743 jitter_buffer_ms(0),
744 min_playout_delay_ms(0),
745 render_delay_ms(0),
746 target_delay_ms(0),
747 current_delay_ms(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000748 }
749
750 std::vector<uint32> ssrcs;
751 std::vector<SsrcGroup> ssrc_groups;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 int firs_sent;
754 int nacks_sent;
755 int frame_width;
756 int frame_height;
757 int framerate_rcvd;
758 int framerate_decoded;
759 int framerate_output;
760 // Framerate as sent to the renderer.
761 int framerate_render_input;
762 // Framerate that the renderer reports.
763 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000764
765 // All stats below are gathered per-VideoReceiver, but some will be correlated
766 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
767 // structures, reflect this in the new layout.
768
769 // Current frame decode latency.
770 int decode_ms;
771 // Maximum observed frame decode latency.
772 int max_decode_ms;
773 // Jitter (network-related) latency.
774 int jitter_buffer_ms;
775 // Requested minimum playout latency.
776 int min_playout_delay_ms;
777 // Requested latency to account for rendering delay.
778 int render_delay_ms;
779 // Target overall delay: network+decode+render, accounting for
780 // min_playout_delay_ms.
781 int target_delay_ms;
782 // Current overall delay, possibly ramping towards target_delay_ms.
783 int current_delay_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784};
785
wu@webrtc.org97077a32013-10-25 21:18:33 +0000786struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000788 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 }
790
791 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792};
793
wu@webrtc.org97077a32013-10-25 21:18:33 +0000794struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000796 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 }
798
799 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800};
801
802struct BandwidthEstimationInfo {
803 BandwidthEstimationInfo()
804 : available_send_bandwidth(0),
805 available_recv_bandwidth(0),
806 target_enc_bitrate(0),
807 actual_enc_bitrate(0),
808 retransmit_bitrate(0),
809 transmit_bitrate(0),
810 bucket_delay(0) {
811 }
812
813 int available_send_bandwidth;
814 int available_recv_bandwidth;
815 int target_enc_bitrate;
816 int actual_enc_bitrate;
817 int retransmit_bitrate;
818 int transmit_bitrate;
819 int bucket_delay;
820};
821
822struct VoiceMediaInfo {
823 void Clear() {
824 senders.clear();
825 receivers.clear();
826 }
827 std::vector<VoiceSenderInfo> senders;
828 std::vector<VoiceReceiverInfo> receivers;
829};
830
831struct VideoMediaInfo {
832 void Clear() {
833 senders.clear();
834 receivers.clear();
835 bw_estimations.clear();
836 }
837 std::vector<VideoSenderInfo> senders;
838 std::vector<VideoReceiverInfo> receivers;
839 std::vector<BandwidthEstimationInfo> bw_estimations;
840};
841
842struct DataMediaInfo {
843 void Clear() {
844 senders.clear();
845 receivers.clear();
846 }
847 std::vector<DataSenderInfo> senders;
848 std::vector<DataReceiverInfo> receivers;
849};
850
851class VoiceMediaChannel : public MediaChannel {
852 public:
853 enum Error {
854 ERROR_NONE = 0, // No error.
855 ERROR_OTHER, // Other errors.
856 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
857 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
858 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
859 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
860 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
861 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
862 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
863 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
864 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
865 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
866 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
867 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
868 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
869 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
870 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
871 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
872 };
873
874 VoiceMediaChannel() {}
875 virtual ~VoiceMediaChannel() {}
876 // Sets the codecs/payload types to be used for incoming media.
877 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
878 // Sets the codecs/payload types to be used for outgoing media.
879 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
880 // Starts or stops playout of received audio.
881 virtual bool SetPlayout(bool playout) = 0;
882 // Starts or stops sending (and potentially capture) of local audio.
883 virtual bool SetSend(SendFlags flag) = 0;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000884 // Sets the renderer object to be used for the specified remote audio stream.
885 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
886 // Sets the renderer object to be used for the specified local audio stream.
887 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 // Gets current energy levels for all incoming streams.
889 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
890 // Get the current energy level of the stream sent to the speaker.
891 virtual int GetOutputLevel() = 0;
892 // Get the time in milliseconds since last recorded keystroke, or negative.
893 virtual int GetTimeSinceLastTyping() = 0;
894 // Temporarily exposed field for tuning typing detect options.
895 virtual void SetTypingDetectionParameters(int time_window,
896 int cost_per_typing, int reporting_threshold, int penalty_decay,
897 int type_event_delay) = 0;
898 // Set left and right scale for speaker output volume of the specified ssrc.
899 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
900 // Get left and right scale for speaker output volume of the specified ssrc.
901 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0;
902 // Specifies a ringback tone to be played during call setup.
903 virtual bool SetRingbackTone(const char *buf, int len) = 0;
904 // Plays or stops the aforementioned ringback tone
905 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
906 // Returns if the telephone-event has been negotiated.
907 virtual bool CanInsertDtmf() { return false; }
908 // Send and/or play a DTMF |event| according to the |flags|.
909 // The DTMF out-of-band signal will be used on sending.
910 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000911 // The valid value for the |event| are 0 to 15 which corresponding to
912 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
914 // Gets quality stats for the channel.
915 virtual bool GetStats(VoiceMediaInfo* info) = 0;
916 // Gets last reported error for this media channel.
917 virtual void GetLastMediaError(uint32* ssrc,
918 VoiceMediaChannel::Error* error) {
919 ASSERT(error != NULL);
920 *error = ERROR_NONE;
921 }
922 // Sets the media options to use.
923 virtual bool SetOptions(const AudioOptions& options) = 0;
924 virtual bool GetOptions(AudioOptions* options) const = 0;
925
926 // Signal errors from MediaChannel. Arguments are:
927 // ssrc(uint32), and error(VoiceMediaChannel::Error).
928 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
929};
930
931class VideoMediaChannel : public MediaChannel {
932 public:
933 enum Error {
934 ERROR_NONE = 0, // No error.
935 ERROR_OTHER, // Other errors.
936 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
937 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
938 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
939 ERROR_REC_DEVICE_REMOVED, // Device is removed.
940 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
941 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
942 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
943 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
944 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
945 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
946 };
947
948 VideoMediaChannel() : renderer_(NULL) {}
949 virtual ~VideoMediaChannel() {}
950 // Sets the codecs/payload types to be used for incoming media.
951 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
952 // Sets the codecs/payload types to be used for outgoing media.
953 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
954 // Gets the currently set codecs/payload types to be used for outgoing media.
955 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
956 // Sets the format of a specified outgoing stream.
957 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
958 // Starts or stops playout of received video.
959 virtual bool SetRender(bool render) = 0;
960 // Starts or stops transmission (and potentially capture) of local video.
961 virtual bool SetSend(bool send) = 0;
962 // Sets the renderer object to be used for the specified stream.
963 // If SSRC is 0, the renderer is used for the 'default' stream.
964 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
965 // If |ssrc| is 0, replace the default capturer (engine capturer) with
966 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
967 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
968 // Gets quality stats for the channel.
969 virtual bool GetStats(VideoMediaInfo* info) = 0;
970
971 // Send an intra frame to the receivers.
972 virtual bool SendIntraFrame() = 0;
973 // Reuqest each of the remote senders to send an intra frame.
974 virtual bool RequestIntraFrame() = 0;
975 // Sets the media options to use.
976 virtual bool SetOptions(const VideoOptions& options) = 0;
977 virtual bool GetOptions(VideoOptions* options) const = 0;
978 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
979
980 // Signal errors from MediaChannel. Arguments are:
981 // ssrc(uint32), and error(VideoMediaChannel::Error).
982 sigslot::signal2<uint32, Error> SignalMediaError;
983
984 protected:
985 VideoRenderer *renderer_;
986};
987
988enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000989 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
990 // values.
991 DMT_NONE = 0,
992 DMT_CONTROL = 1,
993 DMT_BINARY = 2,
994 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995};
996
997// Info about data received in DataMediaChannel. For use in
998// DataMediaChannel::SignalDataReceived and in all of the signals that
999// signal fires, on up the chain.
1000struct ReceiveDataParams {
1001 // The in-packet stream indentifier.
1002 // For SCTP, this is really SID, not SSRC.
1003 uint32 ssrc;
1004 // The type of message (binary, text, or control).
1005 DataMessageType type;
1006 // A per-stream value incremented per packet in the stream.
1007 int seq_num;
1008 // A per-stream value monotonically increasing with time.
1009 int timestamp;
1010
1011 ReceiveDataParams() :
1012 ssrc(0),
1013 type(DMT_TEXT),
1014 seq_num(0),
1015 timestamp(0) {
1016 }
1017};
1018
1019struct SendDataParams {
1020 // The in-packet stream indentifier.
1021 // For SCTP, this is really SID, not SSRC.
1022 uint32 ssrc;
1023 // The type of message (binary, text, or control).
1024 DataMessageType type;
1025
1026 // For SCTP, whether to send messages flagged as ordered or not.
1027 // If false, messages can be received out of order.
1028 bool ordered;
1029 // For SCTP, whether the messages are sent reliably or not.
1030 // If false, messages may be lost.
1031 bool reliable;
1032 // For SCTP, if reliable == false, provide partial reliability by
1033 // resending up to this many times. Either count or millis
1034 // is supported, not both at the same time.
1035 int max_rtx_count;
1036 // For SCTP, if reliable == false, provide partial reliability by
1037 // resending for up to this many milliseconds. Either count or millis
1038 // is supported, not both at the same time.
1039 int max_rtx_ms;
1040
1041 SendDataParams() :
1042 ssrc(0),
1043 type(DMT_TEXT),
1044 // TODO(pthatcher): Make these true by default?
1045 ordered(false),
1046 reliable(false),
1047 max_rtx_count(0),
1048 max_rtx_ms(0) {
1049 }
1050};
1051
1052enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1053
1054class DataMediaChannel : public MediaChannel {
1055 public:
1056 enum Error {
1057 ERROR_NONE = 0, // No error.
1058 ERROR_OTHER, // Other errors.
1059 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1060 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1061 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1062 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1063 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1064 };
1065
1066 virtual ~DataMediaChannel() {}
1067
1068 virtual bool SetSendBandwidth(bool autobw, int bps) = 0;
1069 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
1070 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
1071 virtual bool SetRecvRtpHeaderExtensions(
1072 const std::vector<RtpHeaderExtension>& extensions) = 0;
1073 virtual bool SetSendRtpHeaderExtensions(
1074 const std::vector<RtpHeaderExtension>& extensions) = 0;
1075 virtual bool AddSendStream(const StreamParams& sp) = 0;
1076 virtual bool RemoveSendStream(uint32 ssrc) = 0;
1077 virtual bool AddRecvStream(const StreamParams& sp) = 0;
1078 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
1079 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
1080 // TODO(pthatcher): Implement this.
1081 virtual bool GetStats(DataMediaInfo* info) { return true; }
1082
1083 virtual bool SetSend(bool send) = 0;
1084 virtual bool SetReceive(bool receive) = 0;
1085 virtual void OnPacketReceived(talk_base::Buffer* packet) = 0;
1086 virtual void OnRtcpReceived(talk_base::Buffer* packet) = 0;
1087
1088 virtual bool SendData(
1089 const SendDataParams& params,
1090 const talk_base::Buffer& payload,
1091 SendDataResult* result = NULL) = 0;
1092 // Signals when data is received (params, data, len)
1093 sigslot::signal3<const ReceiveDataParams&,
1094 const char*,
1095 size_t> SignalDataReceived;
1096 // Signal errors from MediaChannel. Arguments are:
1097 // ssrc(uint32), and error(DataMediaChannel::Error).
1098 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001099 // Signal when the media channel is ready to send the stream. Arguments are:
1100 // writable(bool)
1101 sigslot::signal1<bool> SignalReadyToSend;
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +00001102 // Signal for notifying when a new stream is added from the remote side. Used
1103 // for the in-band negotioation through the OPEN message for SCTP data
1104 // channel.
1105 sigslot::signal2<const std::string&, const webrtc::DataChannelInit&>
1106 SignalNewStreamReceived;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001107};
1108
1109} // namespace cricket
1110
1111#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_