blob: cfeb2d8c919c9cea16f80f0c75d69a9984cf35b1 [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
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000034#include "talk/media/base/codec.h"
35#include "talk/media/base/constants.h"
36#include "talk/media/base/streamparams.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000037#include "webrtc/base/basictypes.h"
38#include "webrtc/base/buffer.h"
39#include "webrtc/base/dscp.h"
40#include "webrtc/base/logging.h"
41#include "webrtc/base/sigslot.h"
42#include "webrtc/base/socket.h"
43#include "webrtc/base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044// TODO(juberti): re-evaluate this include
45#include "talk/session/media/audiomonitor.h"
46
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000047namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048class Buffer;
49class RateLimiter;
50class Timing;
51}
52
53namespace cricket {
54
55class AudioRenderer;
56struct RtpHeader;
57class ScreencastId;
58struct VideoFormat;
59class VideoCapturer;
60class VideoRenderer;
61
62const int kMinRtpHeaderExtensionId = 1;
63const int kMaxRtpHeaderExtensionId = 255;
64const int kScreencastDefaultFps = 5;
wu@webrtc.orgcfe5e9c2014-03-27 17:03:58 +000065const int kHighStartBitrate = 1500;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066
67// Used in AudioOptions and VideoOptions to signify "unset" values.
68template <class T>
69class Settable {
70 public:
71 Settable() : set_(false), val_() {}
72 explicit Settable(T val) : set_(true), val_(val) {}
73
74 bool IsSet() const {
75 return set_;
76 }
77
78 bool Get(T* out) const {
79 *out = val_;
80 return set_;
81 }
82
83 T GetWithDefaultIfUnset(const T& default_value) const {
84 return set_ ? val_ : default_value;
85 }
86
pthatcher@webrtc.org40b276e2014-12-12 02:44:30 +000087 void Set(T val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 set_ = true;
89 val_ = val;
90 }
91
92 void Clear() {
93 Set(T());
94 set_ = false;
95 }
96
97 void SetFrom(const Settable<T>& o) {
98 // Set this value based on the value of o, iff o is set. If this value is
99 // set and o is unset, the current value will be unchanged.
100 T val;
101 if (o.Get(&val)) {
102 Set(val);
103 }
104 }
105
106 std::string ToString() const {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000107 return set_ ? rtc::ToString(val_) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108 }
109
110 bool operator==(const Settable<T>& o) const {
111 // Equal if both are unset with any value or both set with the same value.
112 return (set_ == o.set_) && (!set_ || (val_ == o.val_));
113 }
114
115 bool operator!=(const Settable<T>& o) const {
116 return !operator==(o);
117 }
118
119 protected:
120 void InitializeValue(const T &val) {
121 val_ = val;
122 }
123
124 private:
125 bool set_;
126 T val_;
127};
128
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129template <class T>
130static std::string ToStringIfSet(const char* key, const Settable<T>& val) {
131 std::string str;
132 if (val.IsSet()) {
133 str = key;
134 str += ": ";
135 str += val.ToString();
136 str += ", ";
137 }
138 return str;
139}
140
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700141template <class T>
142static std::string VectorToString(const std::vector<T>& vals) {
143 std::ostringstream ost;
144 ost << "[";
145 for (size_t i = 0; i < vals.size(); ++i) {
146 if (i > 0) {
147 ost << ", ";
148 }
149 ost << vals[i].ToString();
150 }
151 ost << "]";
152 return ost.str();
153}
154
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
156// Used to be flags, but that makes it hard to selectively apply options.
157// We are moving all of the setting of options to structs like this,
158// but some things currently still use flags.
159struct AudioOptions {
160 void SetAll(const AudioOptions& change) {
161 echo_cancellation.SetFrom(change.echo_cancellation);
162 auto_gain_control.SetFrom(change.auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000163 rx_auto_gain_control.SetFrom(change.rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 noise_suppression.SetFrom(change.noise_suppression);
165 highpass_filter.SetFrom(change.highpass_filter);
166 stereo_swapping.SetFrom(change.stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200167 audio_jitter_buffer_max_packets.SetFrom(
168 change.audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200169 audio_jitter_buffer_fast_accelerate.SetFrom(
170 change.audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 typing_detection.SetFrom(change.typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000172 aecm_generate_comfort_noise.SetFrom(change.aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 conference_mode.SetFrom(change.conference_mode);
174 adjust_agc_delta.SetFrom(change.adjust_agc_delta);
175 experimental_agc.SetFrom(change.experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200176 extended_filter_aec.SetFrom(change.extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100177 delay_agnostic_aec.SetFrom(change.delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000178 experimental_ns.SetFrom(change.experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 aec_dump.SetFrom(change.aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000180 tx_agc_target_dbov.SetFrom(change.tx_agc_target_dbov);
181 tx_agc_digital_compression_gain.SetFrom(
182 change.tx_agc_digital_compression_gain);
183 tx_agc_limiter.SetFrom(change.tx_agc_limiter);
184 rx_agc_target_dbov.SetFrom(change.rx_agc_target_dbov);
185 rx_agc_digital_compression_gain.SetFrom(
186 change.rx_agc_digital_compression_gain);
187 rx_agc_limiter.SetFrom(change.rx_agc_limiter);
188 recording_sample_rate.SetFrom(change.recording_sample_rate);
189 playout_sample_rate.SetFrom(change.playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000190 dscp.SetFrom(change.dscp);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000191 combined_audio_video_bwe.SetFrom(change.combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 }
193
194 bool operator==(const AudioOptions& o) const {
195 return echo_cancellation == o.echo_cancellation &&
196 auto_gain_control == o.auto_gain_control &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000197 rx_auto_gain_control == o.rx_auto_gain_control &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 noise_suppression == o.noise_suppression &&
199 highpass_filter == o.highpass_filter &&
200 stereo_swapping == o.stereo_swapping &&
Henrik Lundin64dad832015-05-11 12:44:23 +0200201 audio_jitter_buffer_max_packets == o.audio_jitter_buffer_max_packets &&
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200202 audio_jitter_buffer_fast_accelerate ==
203 o.audio_jitter_buffer_fast_accelerate &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000205 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 conference_mode == o.conference_mode &&
207 experimental_agc == o.experimental_agc &&
Henrik Lundin441f6342015-06-09 16:03:13 +0200208 extended_filter_aec == o.extended_filter_aec &&
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100209 delay_agnostic_aec == o.delay_agnostic_aec &&
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000210 experimental_ns == o.experimental_ns &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000212 aec_dump == o.aec_dump &&
213 tx_agc_target_dbov == o.tx_agc_target_dbov &&
214 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
215 tx_agc_limiter == o.tx_agc_limiter &&
216 rx_agc_target_dbov == o.rx_agc_target_dbov &&
217 rx_agc_digital_compression_gain == o.rx_agc_digital_compression_gain &&
218 rx_agc_limiter == o.rx_agc_limiter &&
219 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000220 playout_sample_rate == o.playout_sample_rate &&
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000221 dscp == o.dscp &&
222 combined_audio_video_bwe == o.combined_audio_video_bwe;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223 }
224
225 std::string ToString() const {
226 std::ostringstream ost;
227 ost << "AudioOptions {";
228 ost << ToStringIfSet("aec", echo_cancellation);
229 ost << ToStringIfSet("agc", auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000230 ost << ToStringIfSet("rx_agc", rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 ost << ToStringIfSet("ns", noise_suppression);
232 ost << ToStringIfSet("hf", highpass_filter);
233 ost << ToStringIfSet("swap", stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200234 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
235 audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200236 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
237 audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000239 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 ost << ToStringIfSet("conference", conference_mode);
241 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
242 ost << ToStringIfSet("experimental_agc", experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200243 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100244 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000245 ost << ToStringIfSet("experimental_ns", experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246 ost << ToStringIfSet("aec_dump", aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000247 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
248 ost << ToStringIfSet("tx_agc_digital_compression_gain",
249 tx_agc_digital_compression_gain);
250 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
251 ost << ToStringIfSet("rx_agc_target_dbov", rx_agc_target_dbov);
252 ost << ToStringIfSet("rx_agc_digital_compression_gain",
253 rx_agc_digital_compression_gain);
254 ost << ToStringIfSet("rx_agc_limiter", rx_agc_limiter);
255 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
256 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000257 ost << ToStringIfSet("dscp", dscp);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000258 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 ost << "}";
260 return ost.str();
261 }
262
263 // Audio processing that attempts to filter away the output signal from
264 // later inbound pickup.
265 Settable<bool> echo_cancellation;
266 // Audio processing to adjust the sensitivity of the local mic dynamically.
267 Settable<bool> auto_gain_control;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000268 // Audio processing to apply gain to the remote audio.
269 Settable<bool> rx_auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 // Audio processing to filter out background noise.
271 Settable<bool> noise_suppression;
272 // Audio processing to remove background noise of lower frequencies.
273 Settable<bool> highpass_filter;
274 // Audio processing to swap the left and right channels.
275 Settable<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200276 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
277 Settable<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200278 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
279 Settable<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 // Audio processing to detect typing.
281 Settable<bool> typing_detection;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000282 Settable<bool> aecm_generate_comfort_noise;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 Settable<bool> conference_mode;
284 Settable<int> adjust_agc_delta;
285 Settable<bool> experimental_agc;
Henrik Lundin441f6342015-06-09 16:03:13 +0200286 Settable<bool> extended_filter_aec;
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100287 Settable<bool> delay_agnostic_aec;
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000288 Settable<bool> experimental_ns;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 Settable<bool> aec_dump;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000290 // Note that tx_agc_* only applies to non-experimental AGC.
291 Settable<uint16> tx_agc_target_dbov;
292 Settable<uint16> tx_agc_digital_compression_gain;
293 Settable<bool> tx_agc_limiter;
294 Settable<uint16> rx_agc_target_dbov;
295 Settable<uint16> rx_agc_digital_compression_gain;
296 Settable<bool> rx_agc_limiter;
297 Settable<uint32> recording_sample_rate;
298 Settable<uint32> playout_sample_rate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000299 // Set DSCP value for packet sent from audio channel.
300 Settable<bool> dscp;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000301 // Enable combined audio+bandwidth BWE.
302 Settable<bool> combined_audio_video_bwe;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303};
304
305// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
306// Used to be flags, but that makes it hard to selectively apply options.
307// We are moving all of the setting of options to structs like this,
308// but some things currently still use flags.
309struct VideoOptions {
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000310 enum HighestBitrate {
311 NORMAL,
312 HIGH,
313 VERY_HIGH
314 };
315
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 VideoOptions() {
317 process_adaptation_threshhold.Set(kProcessCpuThreshold);
318 system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold);
319 system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000320 unsignalled_recv_stream_limit.Set(kNumDefaultUnsignalledVideoRecvStreams);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 }
322
323 void SetAll(const VideoOptions& change) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000325 adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000326 video_adapt_third.SetFrom(change.video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 video_noise_reduction.SetFrom(change.video_noise_reduction);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000328 video_start_bitrate.SetFrom(change.video_start_bitrate);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000329 video_highest_bitrate.SetFrom(change.video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000330 cpu_overuse_detection.SetFrom(change.cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000331 cpu_underuse_threshold.SetFrom(change.cpu_underuse_threshold);
332 cpu_overuse_threshold.SetFrom(change.cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000333 cpu_underuse_encode_rsd_threshold.SetFrom(
334 change.cpu_underuse_encode_rsd_threshold);
335 cpu_overuse_encode_rsd_threshold.SetFrom(
336 change.cpu_overuse_encode_rsd_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000337 cpu_overuse_encode_usage.SetFrom(change.cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 conference_mode.SetFrom(change.conference_mode);
339 process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
340 system_low_adaptation_threshhold.SetFrom(
341 change.system_low_adaptation_threshhold);
342 system_high_adaptation_threshhold.SetFrom(
343 change.system_high_adaptation_threshhold);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000344 dscp.SetFrom(change.dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000345 suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000346 unsignalled_recv_stream_limit.SetFrom(change.unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000347 use_simulcast_adapter.SetFrom(change.use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000348 screencast_min_bitrate.SetFrom(change.screencast_min_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
350
351 bool operator==(const VideoOptions& o) const {
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000352 return adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
353 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
354 video_adapt_third == o.video_adapt_third &&
355 video_noise_reduction == o.video_noise_reduction &&
356 video_start_bitrate == o.video_start_bitrate &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000357 video_highest_bitrate == o.video_highest_bitrate &&
358 cpu_overuse_detection == o.cpu_overuse_detection &&
359 cpu_underuse_threshold == o.cpu_underuse_threshold &&
360 cpu_overuse_threshold == o.cpu_overuse_threshold &&
361 cpu_underuse_encode_rsd_threshold ==
362 o.cpu_underuse_encode_rsd_threshold &&
363 cpu_overuse_encode_rsd_threshold ==
364 o.cpu_overuse_encode_rsd_threshold &&
365 cpu_overuse_encode_usage == o.cpu_overuse_encode_usage &&
366 conference_mode == o.conference_mode &&
367 process_adaptation_threshhold == o.process_adaptation_threshhold &&
368 system_low_adaptation_threshhold ==
369 o.system_low_adaptation_threshhold &&
370 system_high_adaptation_threshhold ==
371 o.system_high_adaptation_threshhold &&
Peter Thatchera9b4c322015-07-16 03:47:28 -0700372 dscp == o.dscp &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000373 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
374 unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit &&
375 use_simulcast_adapter == o.use_simulcast_adapter &&
stefan@webrtc.org742386a2014-12-19 15:33:17 +0000376 screencast_min_bitrate == o.screencast_min_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377 }
378
379 std::string ToString() const {
380 std::ostringstream ost;
381 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000383 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000384 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000386 ost << ToStringIfSet("start bitrate", video_start_bitrate);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000387 ost << ToStringIfSet("highest video bitrate", video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000388 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000389 ost << ToStringIfSet("cpu underuse threshold", cpu_underuse_threshold);
390 ost << ToStringIfSet("cpu overuse threshold", cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000391 ost << ToStringIfSet("cpu underuse encode rsd threshold",
392 cpu_underuse_encode_rsd_threshold);
393 ost << ToStringIfSet("cpu overuse encode rsd threshold",
394 cpu_overuse_encode_rsd_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000395 ost << ToStringIfSet("cpu overuse encode usage",
396 cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 ost << ToStringIfSet("conference mode", conference_mode);
398 ost << ToStringIfSet("process", process_adaptation_threshhold);
399 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
400 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000401 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000402 ost << ToStringIfSet("suspend below min bitrate",
403 suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000404 ost << ToStringIfSet("num channels for early receive",
405 unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000406 ost << ToStringIfSet("use simulcast adapter", use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000407 ost << ToStringIfSet("screencast min bitrate", screencast_min_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 ost << "}";
409 return ost.str();
410 }
411
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 // Enable CPU adaptation?
413 Settable<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000414 // Enable CPU adaptation smoothing?
415 Settable<bool> adapt_cpu_with_smoothing;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000416 // Enable video adapt third?
417 Settable<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 // Enable denoising?
419 Settable<bool> video_noise_reduction;
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000420 // Experimental: Enable WebRtc higher start bitrate?
421 Settable<int> video_start_bitrate;
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000422 // Set highest bitrate mode for video.
wu@webrtc.orgcfe5e9c2014-03-27 17:03:58 +0000423 Settable<HighestBitrate> video_highest_bitrate;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000424 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
425 // adaptation algorithm. So this option will override the
426 // |adapt_input_to_cpu_usage|.
427 Settable<bool> cpu_overuse_detection;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000428 // Low threshold (t1) for cpu overuse adaptation. (Adapt up)
429 // Metric: encode usage (m1). m1 < t1 => underuse.
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000430 Settable<int> cpu_underuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000431 // High threshold (t1) for cpu overuse adaptation. (Adapt down)
432 // Metric: encode usage (m1). m1 > t1 => overuse.
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000433 Settable<int> cpu_overuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000434 // Low threshold (t2) for cpu overuse adaptation. (Adapt up)
435 // Metric: relative standard deviation of encode time (m2).
436 // Optional threshold. If set, (m1 < t1 && m2 < t2) => underuse.
437 // Note: t2 will have no effect if t1 is not set.
438 Settable<int> cpu_underuse_encode_rsd_threshold;
439 // High threshold (t2) for cpu overuse adaptation. (Adapt down)
440 // Metric: relative standard deviation of encode time (m2).
441 // Optional threshold. If set, (m1 > t1 || m2 > t2) => overuse.
442 // Note: t2 will have no effect if t1 is not set.
443 Settable<int> cpu_overuse_encode_rsd_threshold;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000444 // Use encode usage for cpu detection.
445 Settable<bool> cpu_overuse_encode_usage;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 // Use conference mode?
447 Settable<bool> conference_mode;
448 // Threshhold for process cpu adaptation. (Process limit)
pthatcher@webrtc.org40b276e2014-12-12 02:44:30 +0000449 Settable<float> process_adaptation_threshhold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 // Low threshhold for cpu adaptation. (Adapt up)
pthatcher@webrtc.org40b276e2014-12-12 02:44:30 +0000451 Settable<float> system_low_adaptation_threshhold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 // High threshhold for cpu adaptation. (Adapt down)
pthatcher@webrtc.org40b276e2014-12-12 02:44:30 +0000453 Settable<float> system_high_adaptation_threshhold;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000454 // Set DSCP value for packet sent from video channel.
455 Settable<bool> dscp;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000456 // Enable WebRTC suspension of video. No video frames will be sent when the
457 // bitrate is below the configured minimum bitrate.
458 Settable<bool> suspend_below_min_bitrate;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000459 // Limit on the number of early receive channels that can be created.
460 Settable<int> unsignalled_recv_stream_limit;
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000461 // Enable use of simulcast adapter.
462 Settable<bool> use_simulcast_adapter;
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000463 // Force screencast to use a minimum bitrate
464 Settable<int> screencast_min_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465};
466
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467struct RtpHeaderExtension {
468 RtpHeaderExtension() : id(0) {}
469 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470
471 bool operator==(const RtpHeaderExtension& ext) const {
472 // id is a reserved word in objective-c. Therefore the id attribute has to
473 // be a fully qualified name in order to compile on IOS.
474 return this->id == ext.id &&
475 uri == ext.uri;
476 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700477
478 std::string ToString() const {
479 std::ostringstream ost;
480 ost << "{";
481 ost << "id: , " << id;
482 ost << "uri: " << uri;
483 ost << "}";
484 return ost.str();
485 }
486
487 std::string uri;
488 int id;
489 // TODO(juberti): SendRecv direction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490};
491
492// Returns the named header extension if found among all extensions, NULL
493// otherwise.
494inline const RtpHeaderExtension* FindHeaderExtension(
495 const std::vector<RtpHeaderExtension>& extensions,
496 const std::string& name) {
497 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
498 it != extensions.end(); ++it) {
499 if (it->uri == name)
500 return &(*it);
501 }
502 return NULL;
503}
504
505enum MediaChannelOptions {
506 // Tune the stream for conference mode.
507 OPT_CONFERENCE = 0x0001
508};
509
510enum VoiceMediaChannelOptions {
511 // Tune the audio stream for vcs with different target levels.
512 OPT_AGC_MINUS_10DB = 0x80000000
513};
514
515// DTMF flags to control if a DTMF tone should be played and/or sent.
516enum DtmfFlags {
517 DF_PLAY = 0x01,
518 DF_SEND = 0x02,
519};
520
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521class MediaChannel : public sigslot::has_slots<> {
522 public:
523 class NetworkInterface {
524 public:
525 enum SocketType { ST_RTP, ST_RTCP };
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000526 virtual bool SendPacket(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000527 rtc::Buffer* packet,
528 rtc::DiffServCodePoint dscp = rtc::DSCP_NO_CHANGE) = 0;
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000529 virtual bool SendRtcp(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000530 rtc::Buffer* packet,
531 rtc::DiffServCodePoint dscp = rtc::DSCP_NO_CHANGE) = 0;
532 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 int option) = 0;
534 virtual ~NetworkInterface() {}
535 };
536
537 MediaChannel() : network_interface_(NULL) {}
538 virtual ~MediaChannel() {}
539
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000540 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000542 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000543 network_interface_ = iface;
544 }
545
546 // Called when a RTP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000547 virtual void OnPacketReceived(rtc::Buffer* packet,
548 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 // Called when a RTCP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000550 virtual void OnRtcpReceived(rtc::Buffer* packet,
551 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000552 // Called when the socket's ability to send has changed.
553 virtual void OnReadyToSend(bool ready) = 0;
554 // Creates a new outgoing media stream with SSRCs and CNAME as described
555 // by sp.
556 virtual bool AddSendStream(const StreamParams& sp) = 0;
557 // Removes an outgoing media stream.
558 // ssrc must be the first SSRC of the media stream if the stream uses
559 // multiple SSRCs.
560 virtual bool RemoveSendStream(uint32 ssrc) = 0;
561 // Creates a new incoming media stream with SSRCs and CNAME as described
562 // by sp.
563 virtual bool AddRecvStream(const StreamParams& sp) = 0;
564 // Removes an incoming media stream.
565 // ssrc must be the first SSRC of the media stream if the stream uses
566 // multiple SSRCs.
567 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
568
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569 // Sets the RTP extension headers and IDs to use when sending RTP.
570 virtual bool SetRecvRtpHeaderExtensions(
571 const std::vector<RtpHeaderExtension>& extensions) = 0;
572 virtual bool SetSendRtpHeaderExtensions(
573 const std::vector<RtpHeaderExtension>& extensions) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000574 // Returns the absoulte sendtime extension id value from media channel.
575 virtual int GetRtpSendTimeExtnId() const {
576 return -1;
577 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000578 // Sets the maximum allowed bandwidth to use when sending data.
579 virtual bool SetMaxSendBandwidth(int bps) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000581 // Base method to send packet using NetworkInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000582 bool SendPacket(rtc::Buffer* packet) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000583 return DoSendPacket(packet, false);
584 }
585
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000586 bool SendRtcp(rtc::Buffer* packet) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000587 return DoSendPacket(packet, true);
588 }
589
590 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000591 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000592 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000593 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000594 if (!network_interface_)
595 return -1;
596
597 return network_interface_->SetOption(type, opt, option);
598 }
599
wu@webrtc.orgde305012013-10-31 15:40:38 +0000600 protected:
601 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000602 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000603 int ret;
604 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000605 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000606 value);
607 if (ret == 0) {
608 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000609 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000610 value);
611 }
612 return ret;
613 }
614
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000615 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000616 bool DoSendPacket(rtc::Buffer* packet, bool rtcp) {
617 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000618 if (!network_interface_)
619 return false;
620
621 return (!rtcp) ? network_interface_->SendPacket(packet) :
622 network_interface_->SendRtcp(packet);
623 }
624
625 // |network_interface_| can be accessed from the worker_thread and
626 // from any MediaEngine threads. This critical section is to protect accessing
627 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000628 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000629 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630};
631
632enum SendFlags {
633 SEND_NOTHING,
634 SEND_RINGBACKTONE,
635 SEND_MICROPHONE
636};
637
wu@webrtc.org97077a32013-10-25 21:18:33 +0000638// The stats information is structured as follows:
639// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
640// Media contains a vector of SSRC infos that are exclusively used by this
641// media. (SSRCs shared between media streams can't be represented.)
642
643// Information about an SSRC.
644// This data may be locally recorded, or received in an RTCP SR or RR.
645struct SsrcSenderInfo {
646 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000647 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000648 timestamp(0) {
649 }
650 uint32 ssrc;
651 double timestamp; // NTP timestamp, represented as seconds since epoch.
652};
653
654struct SsrcReceiverInfo {
655 SsrcReceiverInfo()
656 : ssrc(0),
657 timestamp(0) {
658 }
659 uint32 ssrc;
660 double timestamp;
661};
662
663struct MediaSenderInfo {
664 MediaSenderInfo()
665 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666 packets_sent(0),
667 packets_lost(0),
668 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000669 rtt_ms(0) {
670 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000671 void add_ssrc(const SsrcSenderInfo& stat) {
672 local_stats.push_back(stat);
673 }
674 // Temporary utility function for call sites that only provide SSRC.
675 // As more info is added into SsrcSenderInfo, this function should go away.
676 void add_ssrc(uint32 ssrc) {
677 SsrcSenderInfo stat;
678 stat.ssrc = ssrc;
679 add_ssrc(stat);
680 }
681 // Utility accessor for clients that are only interested in ssrc numbers.
682 std::vector<uint32> ssrcs() const {
683 std::vector<uint32> retval;
684 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
685 it != local_stats.end(); ++it) {
686 retval.push_back(it->ssrc);
687 }
688 return retval;
689 }
690 // Utility accessor for clients that make the assumption only one ssrc
691 // exists per media.
692 // This will eventually go away.
693 uint32 ssrc() const {
694 if (local_stats.size() > 0) {
695 return local_stats[0].ssrc;
696 } else {
697 return 0;
698 }
699 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000700 int64 bytes_sent;
701 int packets_sent;
702 int packets_lost;
703 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000704 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000705 std::string codec_name;
706 std::vector<SsrcSenderInfo> local_stats;
707 std::vector<SsrcReceiverInfo> remote_stats;
708};
709
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000710template<class T>
711struct VariableInfo {
712 VariableInfo()
713 : min_val(),
714 mean(0.0),
715 max_val(),
716 variance(0.0) {
717 }
718 T min_val;
719 double mean;
720 T max_val;
721 double variance;
722};
723
wu@webrtc.org97077a32013-10-25 21:18:33 +0000724struct MediaReceiverInfo {
725 MediaReceiverInfo()
726 : bytes_rcvd(0),
727 packets_rcvd(0),
728 packets_lost(0),
729 fraction_lost(0.0) {
730 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000731 void add_ssrc(const SsrcReceiverInfo& stat) {
732 local_stats.push_back(stat);
733 }
734 // Temporary utility function for call sites that only provide SSRC.
735 // As more info is added into SsrcSenderInfo, this function should go away.
736 void add_ssrc(uint32 ssrc) {
737 SsrcReceiverInfo stat;
738 stat.ssrc = ssrc;
739 add_ssrc(stat);
740 }
741 std::vector<uint32> ssrcs() const {
742 std::vector<uint32> retval;
743 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
744 it != local_stats.end(); ++it) {
745 retval.push_back(it->ssrc);
746 }
747 return retval;
748 }
749 // Utility accessor for clients that make the assumption only one ssrc
750 // exists per media.
751 // This will eventually go away.
752 uint32 ssrc() const {
753 if (local_stats.size() > 0) {
754 return local_stats[0].ssrc;
755 } else {
756 return 0;
757 }
758 }
759
wu@webrtc.org97077a32013-10-25 21:18:33 +0000760 int64 bytes_rcvd;
761 int packets_rcvd;
762 int packets_lost;
763 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000764 std::string codec_name;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000765 std::vector<SsrcReceiverInfo> local_stats;
766 std::vector<SsrcSenderInfo> remote_stats;
767};
768
769struct VoiceSenderInfo : public MediaSenderInfo {
770 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000771 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772 jitter_ms(0),
773 audio_level(0),
774 aec_quality_min(0.0),
775 echo_delay_median_ms(0),
776 echo_delay_std_ms(0),
777 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000778 echo_return_loss_enhancement(0),
779 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780 }
781
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 int jitter_ms;
784 int audio_level;
785 float aec_quality_min;
786 int echo_delay_median_ms;
787 int echo_delay_std_ms;
788 int echo_return_loss;
789 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000790 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791};
792
wu@webrtc.org97077a32013-10-25 21:18:33 +0000793struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000795 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 jitter_ms(0),
797 jitter_buffer_ms(0),
798 jitter_buffer_preferred_ms(0),
799 delay_estimate_ms(0),
800 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000801 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000802 speech_expand_rate(0),
803 secondary_decoded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200804 accelerate_rate(0),
805 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000806 decoding_calls_to_silence_generator(0),
807 decoding_calls_to_neteq(0),
808 decoding_normal(0),
809 decoding_plc(0),
810 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000811 decoding_plc_cng(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200812 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814 int ext_seqnum;
815 int jitter_ms;
816 int jitter_buffer_ms;
817 int jitter_buffer_preferred_ms;
818 int delay_estimate_ms;
819 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000820 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000822 // fraction of synthesized speech inserted through expansion.
823 float speech_expand_rate;
824 // fraction of data out of secondary decoding, including FEC and RED.
825 float secondary_decoded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200826 // Fraction of data removed through time compression.
827 float accelerate_rate;
828 // Fraction of data inserted through time stretching.
829 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000830 int decoding_calls_to_silence_generator;
831 int decoding_calls_to_neteq;
832 int decoding_normal;
833 int decoding_plc;
834 int decoding_cng;
835 int decoding_plc_cng;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000836 // Estimated capture start time in NTP time in ms.
837 int64 capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838};
839
wu@webrtc.org97077a32013-10-25 21:18:33 +0000840struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000842 : packets_cached(0),
843 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000844 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000846 input_frame_width(0),
847 input_frame_height(0),
848 send_frame_width(0),
849 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 framerate_input(0),
851 framerate_sent(0),
852 nominal_bitrate(0),
853 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000854 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000855 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000856 avg_encode_ms(0),
Peter Boström8ed6a4b2015-03-27 10:01:02 +0100857 encode_usage_percent(0) {
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000858 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000860 std::vector<SsrcGroup> ssrc_groups;
861 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000863 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000865 int input_frame_width;
866 int input_frame_height;
867 int send_frame_width;
868 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 int framerate_input;
870 int framerate_sent;
871 int nominal_bitrate;
872 int preferred_bitrate;
873 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000874 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000875 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000876 int encode_usage_percent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000877 VariableInfo<int> adapt_frame_drops;
878 VariableInfo<int> effects_frame_drops;
879 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880};
881
wu@webrtc.org97077a32013-10-25 21:18:33 +0000882struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000884 : packets_concealed(0),
885 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000886 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 nacks_sent(0),
888 frame_width(0),
889 frame_height(0),
890 framerate_rcvd(0),
891 framerate_decoded(0),
892 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000893 framerate_render_input(0),
894 framerate_render_output(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000895 decode_ms(0),
896 max_decode_ms(0),
897 jitter_buffer_ms(0),
898 min_playout_delay_ms(0),
899 render_delay_ms(0),
900 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000901 current_delay_ms(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000902 capture_start_ntp_time_ms(-1) {
903 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000905 std::vector<SsrcGroup> ssrc_groups;
906 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000908 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 int nacks_sent;
910 int frame_width;
911 int frame_height;
912 int framerate_rcvd;
913 int framerate_decoded;
914 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000915 // Framerate as sent to the renderer.
916 int framerate_render_input;
917 // Framerate that the renderer reports.
918 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000919
920 // All stats below are gathered per-VideoReceiver, but some will be correlated
921 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
922 // structures, reflect this in the new layout.
923
924 // Current frame decode latency.
925 int decode_ms;
926 // Maximum observed frame decode latency.
927 int max_decode_ms;
928 // Jitter (network-related) latency.
929 int jitter_buffer_ms;
930 // Requested minimum playout latency.
931 int min_playout_delay_ms;
932 // Requested latency to account for rendering delay.
933 int render_delay_ms;
934 // Target overall delay: network+decode+render, accounting for
935 // min_playout_delay_ms.
936 int target_delay_ms;
937 // Current overall delay, possibly ramping towards target_delay_ms.
938 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000939
940 // Estimated capture start time in NTP time in ms.
941 int64 capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942};
943
wu@webrtc.org97077a32013-10-25 21:18:33 +0000944struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000946 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 }
948
949 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950};
951
wu@webrtc.org97077a32013-10-25 21:18:33 +0000952struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000954 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 }
956
957 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958};
959
960struct BandwidthEstimationInfo {
961 BandwidthEstimationInfo()
962 : available_send_bandwidth(0),
963 available_recv_bandwidth(0),
964 target_enc_bitrate(0),
965 actual_enc_bitrate(0),
966 retransmit_bitrate(0),
967 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000968 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 }
970
971 int available_send_bandwidth;
972 int available_recv_bandwidth;
973 int target_enc_bitrate;
974 int actual_enc_bitrate;
975 int retransmit_bitrate;
976 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000977 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978};
979
980struct VoiceMediaInfo {
981 void Clear() {
982 senders.clear();
983 receivers.clear();
984 }
985 std::vector<VoiceSenderInfo> senders;
986 std::vector<VoiceReceiverInfo> receivers;
987};
988
989struct VideoMediaInfo {
990 void Clear() {
991 senders.clear();
992 receivers.clear();
993 bw_estimations.clear();
994 }
995 std::vector<VideoSenderInfo> senders;
996 std::vector<VideoReceiverInfo> receivers;
997 std::vector<BandwidthEstimationInfo> bw_estimations;
998};
999
1000struct DataMediaInfo {
1001 void Clear() {
1002 senders.clear();
1003 receivers.clear();
1004 }
1005 std::vector<DataSenderInfo> senders;
1006 std::vector<DataReceiverInfo> receivers;
1007};
1008
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001009template <class Codec>
1010struct RtpParameters {
1011 virtual std::string ToString() {
1012 std::ostringstream ost;
1013 ost << "{";
1014 ost << "codecs: " << VectorToString(codecs) << ", ";
1015 ost << "extensions: " << VectorToString(extensions);
1016 ost << "}";
1017 return ost.str();
1018 }
1019
1020 std::vector<Codec> codecs;
1021 std::vector<RtpHeaderExtension> extensions;
1022 // TODO(pthatcher): Add streams.
1023};
1024
1025template <class Codec, class Options>
1026struct RtpSendParameters : RtpParameters<Codec> {
1027 std::string ToString() override {
1028 std::ostringstream ost;
1029 ost << "{";
1030 ost << "codecs: " << VectorToString(this->codecs) << ", ";
1031 ost << "extensions: " << VectorToString(this->extensions) << ", ";
1032 ost << "max_bandiwidth_bps: " << max_bandwidth_bps << ", ";
1033 ost << "options: " << options.ToString();
1034 ost << "}";
1035 return ost.str();
1036 }
1037
1038 int max_bandwidth_bps = -1;
1039 Options options;
1040};
1041
1042struct AudioSendParameters : RtpSendParameters<AudioCodec, AudioOptions> {
1043};
1044
1045struct AudioRecvParameters : RtpParameters<AudioCodec> {
1046};
1047
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001048class VoiceMediaChannel : public MediaChannel {
1049 public:
1050 enum Error {
1051 ERROR_NONE = 0, // No error.
1052 ERROR_OTHER, // Other errors.
1053 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
1054 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
1055 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
1056 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
1057 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
1058 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
1059 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
1060 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1061 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
1062 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
1063 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
1064 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
1065 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
1066 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
1067 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1068 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1069 };
1070
1071 VoiceMediaChannel() {}
1072 virtual ~VoiceMediaChannel() {}
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001073 // TODO(pthatcher): Remove SetSendCodecs,
1074 // SetSendRtpHeaderExtensions, SetMaxSendBandwidth, and SetOptions
1075 // once all implementations implement SetSendParameters.
1076 virtual bool SetSendParameters(const AudioSendParameters& params) {
1077 return (SetSendCodecs(params.codecs) &&
1078 SetSendRtpHeaderExtensions(params.extensions) &&
1079 SetMaxSendBandwidth(params.max_bandwidth_bps) &&
1080 SetOptions(params.options));
1081 }
1082 // TODO(pthatcher): Remove SetRecvCodecs and
1083 // SetRecvRtpHeaderExtensions once all implementations implement
1084 // SetRecvParameters.
1085 virtual bool SetRecvParameters(const AudioRecvParameters& params) {
1086 return (SetRecvCodecs(params.codecs) &&
1087 SetRecvRtpHeaderExtensions(params.extensions));
1088 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 // Sets the codecs/payload types to be used for incoming media.
1090 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
1091 // Sets the codecs/payload types to be used for outgoing media.
1092 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
1093 // Starts or stops playout of received audio.
1094 virtual bool SetPlayout(bool playout) = 0;
1095 // Starts or stops sending (and potentially capture) of local audio.
1096 virtual bool SetSend(SendFlags flag) = 0;
solenberg1dd98f32015-09-10 01:57:14 -07001097 // Configure stream for sending.
1098 virtual bool SetAudioSend(uint32 ssrc, bool mute, const AudioOptions* options,
1099 AudioRenderer* renderer) = 0;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001100 // Sets the renderer object to be used for the specified remote audio stream.
1101 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 // Gets current energy levels for all incoming streams.
1103 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1104 // Get the current energy level of the stream sent to the speaker.
1105 virtual int GetOutputLevel() = 0;
1106 // Get the time in milliseconds since last recorded keystroke, or negative.
1107 virtual int GetTimeSinceLastTyping() = 0;
1108 // Temporarily exposed field for tuning typing detect options.
1109 virtual void SetTypingDetectionParameters(int time_window,
1110 int cost_per_typing, int reporting_threshold, int penalty_decay,
1111 int type_event_delay) = 0;
1112 // Set left and right scale for speaker output volume of the specified ssrc.
1113 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114 // Specifies a ringback tone to be played during call setup.
1115 virtual bool SetRingbackTone(const char *buf, int len) = 0;
1116 // Plays or stops the aforementioned ringback tone
1117 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
1118 // Returns if the telephone-event has been negotiated.
1119 virtual bool CanInsertDtmf() { return false; }
1120 // Send and/or play a DTMF |event| according to the |flags|.
1121 // The DTMF out-of-band signal will be used on sending.
1122 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001123 // The valid value for the |event| are 0 to 15 which corresponding to
1124 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001125 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
1126 // Gets quality stats for the channel.
1127 virtual bool GetStats(VoiceMediaInfo* info) = 0;
1128 // Gets last reported error for this media channel.
1129 virtual void GetLastMediaError(uint32* ssrc,
1130 VoiceMediaChannel::Error* error) {
1131 ASSERT(error != NULL);
1132 *error = ERROR_NONE;
1133 }
1134 // Sets the media options to use.
1135 virtual bool SetOptions(const AudioOptions& options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136
1137 // Signal errors from MediaChannel. Arguments are:
1138 // ssrc(uint32), and error(VoiceMediaChannel::Error).
1139 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
1140};
1141
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001142struct VideoSendParameters : RtpSendParameters<VideoCodec, VideoOptions> {
1143};
1144
1145struct VideoRecvParameters : RtpParameters<VideoCodec> {
1146};
1147
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001148class VideoMediaChannel : public MediaChannel {
1149 public:
1150 enum Error {
1151 ERROR_NONE = 0, // No error.
1152 ERROR_OTHER, // Other errors.
1153 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1154 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1155 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1156 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1157 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1158 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1159 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1160 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1161 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1162 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1163 };
1164
1165 VideoMediaChannel() : renderer_(NULL) {}
1166 virtual ~VideoMediaChannel() {}
Fredrik Solenberg4b60c732015-05-07 14:07:48 +02001167 // Allow video channel to unhook itself from an associated voice channel.
1168 virtual void DetachVoiceChannel() = 0;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001169 // TODO(pthatcher): Remove SetSendCodecs,
1170 // SetSendRtpHeaderExtensions, SetMaxSendBandwidth, and SetOptions
1171 // once all implementations implement SetSendParameters.
1172 virtual bool SetSendParameters(const VideoSendParameters& params) {
1173 return (SetSendCodecs(params.codecs) &&
1174 SetSendRtpHeaderExtensions(params.extensions) &&
1175 SetMaxSendBandwidth(params.max_bandwidth_bps) &&
1176 SetOptions(params.options));
1177 }
1178 // TODO(pthatcher): Remove SetRecvCodecs and
1179 // SetRecvRtpHeaderExtensions once all implementations implement
1180 // SetRecvParameters.
1181 virtual bool SetRecvParameters(const VideoRecvParameters& params) {
1182 return (SetRecvCodecs(params.codecs) &&
1183 SetRecvRtpHeaderExtensions(params.extensions));
1184 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001185 // Sets the codecs/payload types to be used for incoming media.
1186 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
1187 // Sets the codecs/payload types to be used for outgoing media.
1188 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
1189 // Gets the currently set codecs/payload types to be used for outgoing media.
1190 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1191 // Sets the format of a specified outgoing stream.
1192 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
1193 // Starts or stops playout of received video.
1194 virtual bool SetRender(bool render) = 0;
1195 // Starts or stops transmission (and potentially capture) of local video.
1196 virtual bool SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -07001197 // Configure stream for sending.
1198 virtual bool SetVideoSend(uint32 ssrc, bool mute,
1199 const VideoOptions* options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200 // Sets the renderer object to be used for the specified stream.
1201 // If SSRC is 0, the renderer is used for the 'default' stream.
1202 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
1203 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1204 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
1205 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
1206 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001207 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001208 // Send an intra frame to the receivers.
1209 virtual bool SendIntraFrame() = 0;
1210 // Reuqest each of the remote senders to send an intra frame.
1211 virtual bool RequestIntraFrame() = 0;
1212 // Sets the media options to use.
1213 virtual bool SetOptions(const VideoOptions& options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001214 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1215
1216 // Signal errors from MediaChannel. Arguments are:
1217 // ssrc(uint32), and error(VideoMediaChannel::Error).
1218 sigslot::signal2<uint32, Error> SignalMediaError;
1219
1220 protected:
1221 VideoRenderer *renderer_;
1222};
1223
1224enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001225 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1226 // values.
1227 DMT_NONE = 0,
1228 DMT_CONTROL = 1,
1229 DMT_BINARY = 2,
1230 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001231};
1232
1233// Info about data received in DataMediaChannel. For use in
1234// DataMediaChannel::SignalDataReceived and in all of the signals that
1235// signal fires, on up the chain.
1236struct ReceiveDataParams {
1237 // The in-packet stream indentifier.
1238 // For SCTP, this is really SID, not SSRC.
1239 uint32 ssrc;
1240 // The type of message (binary, text, or control).
1241 DataMessageType type;
1242 // A per-stream value incremented per packet in the stream.
1243 int seq_num;
1244 // A per-stream value monotonically increasing with time.
1245 int timestamp;
1246
1247 ReceiveDataParams() :
1248 ssrc(0),
1249 type(DMT_TEXT),
1250 seq_num(0),
1251 timestamp(0) {
1252 }
1253};
1254
1255struct SendDataParams {
1256 // The in-packet stream indentifier.
1257 // For SCTP, this is really SID, not SSRC.
1258 uint32 ssrc;
1259 // The type of message (binary, text, or control).
1260 DataMessageType type;
1261
1262 // For SCTP, whether to send messages flagged as ordered or not.
1263 // If false, messages can be received out of order.
1264 bool ordered;
1265 // For SCTP, whether the messages are sent reliably or not.
1266 // If false, messages may be lost.
1267 bool reliable;
1268 // For SCTP, if reliable == false, provide partial reliability by
1269 // resending up to this many times. Either count or millis
1270 // is supported, not both at the same time.
1271 int max_rtx_count;
1272 // For SCTP, if reliable == false, provide partial reliability by
1273 // resending for up to this many milliseconds. Either count or millis
1274 // is supported, not both at the same time.
1275 int max_rtx_ms;
1276
1277 SendDataParams() :
1278 ssrc(0),
1279 type(DMT_TEXT),
1280 // TODO(pthatcher): Make these true by default?
1281 ordered(false),
1282 reliable(false),
1283 max_rtx_count(0),
1284 max_rtx_ms(0) {
1285 }
1286};
1287
1288enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1289
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001290struct DataOptions {
1291 std::string ToString() {
1292 return "{}";
1293 }
1294};
1295
1296struct DataSendParameters : RtpSendParameters<DataCodec, DataOptions> {
1297 std::string ToString() {
1298 std::ostringstream ost;
1299 // Options and extensions aren't used.
1300 ost << "{";
1301 ost << "codecs: " << VectorToString(codecs) << ", ";
1302 ost << "max_bandiwidth_bps: " << max_bandwidth_bps;
1303 ost << "}";
1304 return ost.str();
1305 }
1306};
1307
1308struct DataRecvParameters : RtpParameters<DataCodec> {
1309};
1310
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311class DataMediaChannel : public MediaChannel {
1312 public:
1313 enum Error {
1314 ERROR_NONE = 0, // No error.
1315 ERROR_OTHER, // Other errors.
1316 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1317 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1318 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1319 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1320 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1321 };
1322
1323 virtual ~DataMediaChannel() {}
1324
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001325 // TODO(pthatcher): Remove SetSendCodecs,
1326 // SetSendRtpHeaderExtensions, SetMaxSendBandwidth, and SetOptions
1327 // once all implementations implement SetSendParameters.
1328 virtual bool SetSendParameters(const DataSendParameters& params) {
1329 return (SetSendCodecs(params.codecs) &&
1330 SetMaxSendBandwidth(params.max_bandwidth_bps));
1331 }
1332 // TODO(pthatcher): Remove SetRecvCodecs and
1333 // SetRecvRtpHeaderExtensions once all implementations implement
1334 // SetRecvParameters.
1335 virtual bool SetRecvParameters(const DataRecvParameters& params) {
1336 return SetRecvCodecs(params.codecs);
1337 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
1339 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001340
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341 // TODO(pthatcher): Implement this.
1342 virtual bool GetStats(DataMediaInfo* info) { return true; }
1343
1344 virtual bool SetSend(bool send) = 0;
1345 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346
1347 virtual bool SendData(
1348 const SendDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001349 const rtc::Buffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 SendDataResult* result = NULL) = 0;
1351 // Signals when data is received (params, data, len)
1352 sigslot::signal3<const ReceiveDataParams&,
1353 const char*,
1354 size_t> SignalDataReceived;
1355 // Signal errors from MediaChannel. Arguments are:
1356 // ssrc(uint32), and error(DataMediaChannel::Error).
1357 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001358 // Signal when the media channel is ready to send the stream. Arguments are:
1359 // writable(bool)
1360 sigslot::signal1<bool> SignalReadyToSend;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001361 // Signal for notifying that the remote side has closed the DataChannel.
1362 sigslot::signal1<uint32> SignalStreamClosedRemotely;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001363};
1364
1365} // namespace cricket
1366
1367#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_