blob: 68e01cefd41620d2930ebcb50f19667f655c8381 [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
141// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
142// Used to be flags, but that makes it hard to selectively apply options.
143// We are moving all of the setting of options to structs like this,
144// but some things currently still use flags.
145struct AudioOptions {
146 void SetAll(const AudioOptions& change) {
147 echo_cancellation.SetFrom(change.echo_cancellation);
148 auto_gain_control.SetFrom(change.auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000149 rx_auto_gain_control.SetFrom(change.rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 noise_suppression.SetFrom(change.noise_suppression);
151 highpass_filter.SetFrom(change.highpass_filter);
152 stereo_swapping.SetFrom(change.stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200153 audio_jitter_buffer_max_packets.SetFrom(
154 change.audio_jitter_buffer_max_packets);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 typing_detection.SetFrom(change.typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000156 aecm_generate_comfort_noise.SetFrom(change.aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 conference_mode.SetFrom(change.conference_mode);
158 adjust_agc_delta.SetFrom(change.adjust_agc_delta);
159 experimental_agc.SetFrom(change.experimental_agc);
160 experimental_aec.SetFrom(change.experimental_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100161 delay_agnostic_aec.SetFrom(change.delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000162 experimental_ns.SetFrom(change.experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 aec_dump.SetFrom(change.aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000164 tx_agc_target_dbov.SetFrom(change.tx_agc_target_dbov);
165 tx_agc_digital_compression_gain.SetFrom(
166 change.tx_agc_digital_compression_gain);
167 tx_agc_limiter.SetFrom(change.tx_agc_limiter);
168 rx_agc_target_dbov.SetFrom(change.rx_agc_target_dbov);
169 rx_agc_digital_compression_gain.SetFrom(
170 change.rx_agc_digital_compression_gain);
171 rx_agc_limiter.SetFrom(change.rx_agc_limiter);
172 recording_sample_rate.SetFrom(change.recording_sample_rate);
173 playout_sample_rate.SetFrom(change.playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000174 dscp.SetFrom(change.dscp);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000175 combined_audio_video_bwe.SetFrom(change.combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176 }
177
178 bool operator==(const AudioOptions& o) const {
179 return echo_cancellation == o.echo_cancellation &&
180 auto_gain_control == o.auto_gain_control &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000181 rx_auto_gain_control == o.rx_auto_gain_control &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 noise_suppression == o.noise_suppression &&
183 highpass_filter == o.highpass_filter &&
184 stereo_swapping == o.stereo_swapping &&
Henrik Lundin64dad832015-05-11 12:44:23 +0200185 audio_jitter_buffer_max_packets == o.audio_jitter_buffer_max_packets &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000187 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 conference_mode == o.conference_mode &&
189 experimental_agc == o.experimental_agc &&
190 experimental_aec == o.experimental_aec &&
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100191 delay_agnostic_aec == o.delay_agnostic_aec &&
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000192 experimental_ns == o.experimental_ns &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000194 aec_dump == o.aec_dump &&
195 tx_agc_target_dbov == o.tx_agc_target_dbov &&
196 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
197 tx_agc_limiter == o.tx_agc_limiter &&
198 rx_agc_target_dbov == o.rx_agc_target_dbov &&
199 rx_agc_digital_compression_gain == o.rx_agc_digital_compression_gain &&
200 rx_agc_limiter == o.rx_agc_limiter &&
201 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000202 playout_sample_rate == o.playout_sample_rate &&
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000203 dscp == o.dscp &&
204 combined_audio_video_bwe == o.combined_audio_video_bwe;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 }
206
207 std::string ToString() const {
208 std::ostringstream ost;
209 ost << "AudioOptions {";
210 ost << ToStringIfSet("aec", echo_cancellation);
211 ost << ToStringIfSet("agc", auto_gain_control);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000212 ost << ToStringIfSet("rx_agc", rx_auto_gain_control);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 ost << ToStringIfSet("ns", noise_suppression);
214 ost << ToStringIfSet("hf", highpass_filter);
215 ost << ToStringIfSet("swap", stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200216 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
217 audio_jitter_buffer_max_packets);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000219 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 ost << ToStringIfSet("conference", conference_mode);
221 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
222 ost << ToStringIfSet("experimental_agc", experimental_agc);
223 ost << ToStringIfSet("experimental_aec", experimental_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100224 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000225 ost << ToStringIfSet("experimental_ns", experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 ost << ToStringIfSet("aec_dump", aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000227 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
228 ost << ToStringIfSet("tx_agc_digital_compression_gain",
229 tx_agc_digital_compression_gain);
230 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
231 ost << ToStringIfSet("rx_agc_target_dbov", rx_agc_target_dbov);
232 ost << ToStringIfSet("rx_agc_digital_compression_gain",
233 rx_agc_digital_compression_gain);
234 ost << ToStringIfSet("rx_agc_limiter", rx_agc_limiter);
235 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
236 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000237 ost << ToStringIfSet("dscp", dscp);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000238 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239 ost << "}";
240 return ost.str();
241 }
242
243 // Audio processing that attempts to filter away the output signal from
244 // later inbound pickup.
245 Settable<bool> echo_cancellation;
246 // Audio processing to adjust the sensitivity of the local mic dynamically.
247 Settable<bool> auto_gain_control;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000248 // Audio processing to apply gain to the remote audio.
249 Settable<bool> rx_auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 // Audio processing to filter out background noise.
251 Settable<bool> noise_suppression;
252 // Audio processing to remove background noise of lower frequencies.
253 Settable<bool> highpass_filter;
254 // Audio processing to swap the left and right channels.
255 Settable<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200256 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
257 Settable<int> audio_jitter_buffer_max_packets;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 // 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;
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100265 Settable<bool> delay_agnostic_aec;
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000266 Settable<bool> experimental_ns;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 Settable<bool> aec_dump;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000268 // Note that tx_agc_* only applies to non-experimental AGC.
269 Settable<uint16> tx_agc_target_dbov;
270 Settable<uint16> tx_agc_digital_compression_gain;
271 Settable<bool> tx_agc_limiter;
272 Settable<uint16> rx_agc_target_dbov;
273 Settable<uint16> rx_agc_digital_compression_gain;
274 Settable<bool> rx_agc_limiter;
275 Settable<uint32> recording_sample_rate;
276 Settable<uint32> playout_sample_rate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000277 // Set DSCP value for packet sent from audio channel.
278 Settable<bool> dscp;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000279 // Enable combined audio+bandwidth BWE.
280 Settable<bool> combined_audio_video_bwe;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281};
282
283// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
284// Used to be flags, but that makes it hard to selectively apply options.
285// We are moving all of the setting of options to structs like this,
286// but some things currently still use flags.
287struct VideoOptions {
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000288 enum HighestBitrate {
289 NORMAL,
290 HIGH,
291 VERY_HIGH
292 };
293
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 VideoOptions() {
295 process_adaptation_threshhold.Set(kProcessCpuThreshold);
296 system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold);
297 system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000298 unsignalled_recv_stream_limit.Set(kNumDefaultUnsignalledVideoRecvStreams);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 }
300
301 void SetAll(const VideoOptions& change) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000303 adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000304 video_adapt_third.SetFrom(change.video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 video_noise_reduction.SetFrom(change.video_noise_reduction);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000306 video_start_bitrate.SetFrom(change.video_start_bitrate);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000307 video_highest_bitrate.SetFrom(change.video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000308 cpu_overuse_detection.SetFrom(change.cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000309 cpu_underuse_threshold.SetFrom(change.cpu_underuse_threshold);
310 cpu_overuse_threshold.SetFrom(change.cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000311 cpu_underuse_encode_rsd_threshold.SetFrom(
312 change.cpu_underuse_encode_rsd_threshold);
313 cpu_overuse_encode_rsd_threshold.SetFrom(
314 change.cpu_overuse_encode_rsd_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000315 cpu_overuse_encode_usage.SetFrom(change.cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 conference_mode.SetFrom(change.conference_mode);
317 process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
318 system_low_adaptation_threshhold.SetFrom(
319 change.system_low_adaptation_threshhold);
320 system_high_adaptation_threshhold.SetFrom(
321 change.system_high_adaptation_threshhold);
322 buffered_mode_latency.SetFrom(change.buffered_mode_latency);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000323 dscp.SetFrom(change.dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000324 suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000325 unsignalled_recv_stream_limit.SetFrom(change.unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000326 use_simulcast_adapter.SetFrom(change.use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000327 screencast_min_bitrate.SetFrom(change.screencast_min_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 }
329
330 bool operator==(const VideoOptions& o) const {
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000331 return adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
332 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
333 video_adapt_third == o.video_adapt_third &&
334 video_noise_reduction == o.video_noise_reduction &&
335 video_start_bitrate == o.video_start_bitrate &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000336 video_highest_bitrate == o.video_highest_bitrate &&
337 cpu_overuse_detection == o.cpu_overuse_detection &&
338 cpu_underuse_threshold == o.cpu_underuse_threshold &&
339 cpu_overuse_threshold == o.cpu_overuse_threshold &&
340 cpu_underuse_encode_rsd_threshold ==
341 o.cpu_underuse_encode_rsd_threshold &&
342 cpu_overuse_encode_rsd_threshold ==
343 o.cpu_overuse_encode_rsd_threshold &&
344 cpu_overuse_encode_usage == o.cpu_overuse_encode_usage &&
345 conference_mode == o.conference_mode &&
346 process_adaptation_threshhold == o.process_adaptation_threshhold &&
347 system_low_adaptation_threshhold ==
348 o.system_low_adaptation_threshhold &&
349 system_high_adaptation_threshhold ==
350 o.system_high_adaptation_threshhold &&
351 buffered_mode_latency == o.buffered_mode_latency && dscp == o.dscp &&
352 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
353 unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit &&
354 use_simulcast_adapter == o.use_simulcast_adapter &&
stefan@webrtc.org742386a2014-12-19 15:33:17 +0000355 screencast_min_bitrate == o.screencast_min_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 }
357
358 std::string ToString() const {
359 std::ostringstream ost;
360 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000362 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000363 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000365 ost << ToStringIfSet("start bitrate", video_start_bitrate);
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000366 ost << ToStringIfSet("highest video bitrate", video_highest_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000367 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000368 ost << ToStringIfSet("cpu underuse threshold", cpu_underuse_threshold);
369 ost << ToStringIfSet("cpu overuse threshold", cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000370 ost << ToStringIfSet("cpu underuse encode rsd threshold",
371 cpu_underuse_encode_rsd_threshold);
372 ost << ToStringIfSet("cpu overuse encode rsd threshold",
373 cpu_overuse_encode_rsd_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000374 ost << ToStringIfSet("cpu overuse encode usage",
375 cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376 ost << ToStringIfSet("conference mode", conference_mode);
377 ost << ToStringIfSet("process", process_adaptation_threshhold);
378 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
379 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
380 ost << ToStringIfSet("buffered mode latency", buffered_mode_latency);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000381 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000382 ost << ToStringIfSet("suspend below min bitrate",
383 suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000384 ost << ToStringIfSet("num channels for early receive",
385 unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000386 ost << ToStringIfSet("use simulcast adapter", use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000387 ost << ToStringIfSet("screencast min bitrate", screencast_min_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 ost << "}";
389 return ost.str();
390 }
391
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 // Enable CPU adaptation?
393 Settable<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000394 // Enable CPU adaptation smoothing?
395 Settable<bool> adapt_cpu_with_smoothing;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000396 // Enable video adapt third?
397 Settable<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398 // Enable denoising?
399 Settable<bool> video_noise_reduction;
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000400 // Experimental: Enable WebRtc higher start bitrate?
401 Settable<int> video_start_bitrate;
henrike@webrtc.orgf45a5502014-03-13 18:51:34 +0000402 // Set highest bitrate mode for video.
wu@webrtc.orgcfe5e9c2014-03-27 17:03:58 +0000403 Settable<HighestBitrate> video_highest_bitrate;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000404 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
405 // adaptation algorithm. So this option will override the
406 // |adapt_input_to_cpu_usage|.
407 Settable<bool> cpu_overuse_detection;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000408 // Low threshold (t1) for cpu overuse adaptation. (Adapt up)
409 // Metric: encode usage (m1). m1 < t1 => underuse.
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000410 Settable<int> cpu_underuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000411 // High threshold (t1) for cpu overuse adaptation. (Adapt down)
412 // Metric: encode usage (m1). m1 > t1 => overuse.
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000413 Settable<int> cpu_overuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000414 // Low threshold (t2) for cpu overuse adaptation. (Adapt up)
415 // Metric: relative standard deviation of encode time (m2).
416 // Optional threshold. If set, (m1 < t1 && m2 < t2) => underuse.
417 // Note: t2 will have no effect if t1 is not set.
418 Settable<int> cpu_underuse_encode_rsd_threshold;
419 // High threshold (t2) for cpu overuse adaptation. (Adapt down)
420 // Metric: relative standard deviation of encode time (m2).
421 // Optional threshold. If set, (m1 > t1 || m2 > t2) => overuse.
422 // Note: t2 will have no effect if t1 is not set.
423 Settable<int> cpu_overuse_encode_rsd_threshold;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000424 // Use encode usage for cpu detection.
425 Settable<bool> cpu_overuse_encode_usage;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 // Use conference mode?
427 Settable<bool> conference_mode;
428 // Threshhold for process cpu adaptation. (Process limit)
pthatcher@webrtc.org40b276e2014-12-12 02:44:30 +0000429 Settable<float> process_adaptation_threshhold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 // Low threshhold for cpu adaptation. (Adapt up)
pthatcher@webrtc.org40b276e2014-12-12 02:44:30 +0000431 Settable<float> system_low_adaptation_threshhold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432 // High threshhold for cpu adaptation. (Adapt down)
pthatcher@webrtc.org40b276e2014-12-12 02:44:30 +0000433 Settable<float> system_high_adaptation_threshhold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 // Specify buffered mode latency in milliseconds.
435 Settable<int> buffered_mode_latency;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000436 // Set DSCP value for packet sent from video channel.
437 Settable<bool> dscp;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000438 // Enable WebRTC suspension of video. No video frames will be sent when the
439 // bitrate is below the configured minimum bitrate.
440 Settable<bool> suspend_below_min_bitrate;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000441 // Limit on the number of early receive channels that can be created.
442 Settable<int> unsignalled_recv_stream_limit;
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000443 // Enable use of simulcast adapter.
444 Settable<bool> use_simulcast_adapter;
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000445 // Force screencast to use a minimum bitrate
446 Settable<int> screencast_min_bitrate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447};
448
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449struct RtpHeaderExtension {
450 RtpHeaderExtension() : id(0) {}
451 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
452 std::string uri;
453 int id;
454 // TODO(juberti): SendRecv direction;
455
456 bool operator==(const RtpHeaderExtension& ext) const {
457 // id is a reserved word in objective-c. Therefore the id attribute has to
458 // be a fully qualified name in order to compile on IOS.
459 return this->id == ext.id &&
460 uri == ext.uri;
461 }
462};
463
464// Returns the named header extension if found among all extensions, NULL
465// otherwise.
466inline const RtpHeaderExtension* FindHeaderExtension(
467 const std::vector<RtpHeaderExtension>& extensions,
468 const std::string& name) {
469 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
470 it != extensions.end(); ++it) {
471 if (it->uri == name)
472 return &(*it);
473 }
474 return NULL;
475}
476
477enum MediaChannelOptions {
478 // Tune the stream for conference mode.
479 OPT_CONFERENCE = 0x0001
480};
481
482enum VoiceMediaChannelOptions {
483 // Tune the audio stream for vcs with different target levels.
484 OPT_AGC_MINUS_10DB = 0x80000000
485};
486
487// DTMF flags to control if a DTMF tone should be played and/or sent.
488enum DtmfFlags {
489 DF_PLAY = 0x01,
490 DF_SEND = 0x02,
491};
492
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493class MediaChannel : public sigslot::has_slots<> {
494 public:
495 class NetworkInterface {
496 public:
497 enum SocketType { ST_RTP, ST_RTCP };
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000498 virtual bool SendPacket(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000499 rtc::Buffer* packet,
500 rtc::DiffServCodePoint dscp = rtc::DSCP_NO_CHANGE) = 0;
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000501 virtual bool SendRtcp(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000502 rtc::Buffer* packet,
503 rtc::DiffServCodePoint dscp = rtc::DSCP_NO_CHANGE) = 0;
504 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000505 int option) = 0;
506 virtual ~NetworkInterface() {}
507 };
508
509 MediaChannel() : network_interface_(NULL) {}
510 virtual ~MediaChannel() {}
511
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000512 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000514 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 network_interface_ = iface;
516 }
517
518 // Called when a RTP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000519 virtual void OnPacketReceived(rtc::Buffer* packet,
520 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 // Called when a RTCP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000522 virtual void OnRtcpReceived(rtc::Buffer* packet,
523 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 // Called when the socket's ability to send has changed.
525 virtual void OnReadyToSend(bool ready) = 0;
526 // Creates a new outgoing media stream with SSRCs and CNAME as described
527 // by sp.
528 virtual bool AddSendStream(const StreamParams& sp) = 0;
529 // Removes an outgoing media stream.
530 // ssrc must be the first SSRC of the media stream if the stream uses
531 // multiple SSRCs.
532 virtual bool RemoveSendStream(uint32 ssrc) = 0;
533 // Creates a new incoming media stream with SSRCs and CNAME as described
534 // by sp.
535 virtual bool AddRecvStream(const StreamParams& sp) = 0;
536 // Removes an incoming media stream.
537 // ssrc must be the first SSRC of the media stream if the stream uses
538 // multiple SSRCs.
539 virtual bool RemoveRecvStream(uint32 ssrc) = 0;
540
541 // Mutes the channel.
542 virtual bool MuteStream(uint32 ssrc, bool on) = 0;
543
544 // Sets the RTP extension headers and IDs to use when sending RTP.
545 virtual bool SetRecvRtpHeaderExtensions(
546 const std::vector<RtpHeaderExtension>& extensions) = 0;
547 virtual bool SetSendRtpHeaderExtensions(
548 const std::vector<RtpHeaderExtension>& extensions) = 0;
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000549 // Returns the absoulte sendtime extension id value from media channel.
550 virtual int GetRtpSendTimeExtnId() const {
551 return -1;
552 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000553 // Sets the maximum allowed bandwidth to use when sending data.
554 virtual bool SetMaxSendBandwidth(int bps) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000556 // Base method to send packet using NetworkInterface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000557 bool SendPacket(rtc::Buffer* packet) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000558 return DoSendPacket(packet, false);
559 }
560
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000561 bool SendRtcp(rtc::Buffer* packet) {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000562 return DoSendPacket(packet, true);
563 }
564
565 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000566 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000567 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000568 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000569 if (!network_interface_)
570 return -1;
571
572 return network_interface_->SetOption(type, opt, option);
573 }
574
wu@webrtc.orgde305012013-10-31 15:40:38 +0000575 protected:
576 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000577 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000578 int ret;
579 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000580 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000581 value);
582 if (ret == 0) {
583 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000584 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000585 value);
586 }
587 return ret;
588 }
589
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000590 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000591 bool DoSendPacket(rtc::Buffer* packet, bool rtcp) {
592 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000593 if (!network_interface_)
594 return false;
595
596 return (!rtcp) ? network_interface_->SendPacket(packet) :
597 network_interface_->SendRtcp(packet);
598 }
599
600 // |network_interface_| can be accessed from the worker_thread and
601 // from any MediaEngine threads. This critical section is to protect accessing
602 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000603 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000604 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000605};
606
607enum SendFlags {
608 SEND_NOTHING,
609 SEND_RINGBACKTONE,
610 SEND_MICROPHONE
611};
612
wu@webrtc.org97077a32013-10-25 21:18:33 +0000613// The stats information is structured as follows:
614// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
615// Media contains a vector of SSRC infos that are exclusively used by this
616// media. (SSRCs shared between media streams can't be represented.)
617
618// Information about an SSRC.
619// This data may be locally recorded, or received in an RTCP SR or RR.
620struct SsrcSenderInfo {
621 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000623 timestamp(0) {
624 }
625 uint32 ssrc;
626 double timestamp; // NTP timestamp, represented as seconds since epoch.
627};
628
629struct SsrcReceiverInfo {
630 SsrcReceiverInfo()
631 : ssrc(0),
632 timestamp(0) {
633 }
634 uint32 ssrc;
635 double timestamp;
636};
637
638struct MediaSenderInfo {
639 MediaSenderInfo()
640 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641 packets_sent(0),
642 packets_lost(0),
643 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000644 rtt_ms(0) {
645 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000646 void add_ssrc(const SsrcSenderInfo& stat) {
647 local_stats.push_back(stat);
648 }
649 // Temporary utility function for call sites that only provide SSRC.
650 // As more info is added into SsrcSenderInfo, this function should go away.
651 void add_ssrc(uint32 ssrc) {
652 SsrcSenderInfo stat;
653 stat.ssrc = ssrc;
654 add_ssrc(stat);
655 }
656 // Utility accessor for clients that are only interested in ssrc numbers.
657 std::vector<uint32> ssrcs() const {
658 std::vector<uint32> retval;
659 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
660 it != local_stats.end(); ++it) {
661 retval.push_back(it->ssrc);
662 }
663 return retval;
664 }
665 // Utility accessor for clients that make the assumption only one ssrc
666 // exists per media.
667 // This will eventually go away.
668 uint32 ssrc() const {
669 if (local_stats.size() > 0) {
670 return local_stats[0].ssrc;
671 } else {
672 return 0;
673 }
674 }
wu@webrtc.org97077a32013-10-25 21:18:33 +0000675 int64 bytes_sent;
676 int packets_sent;
677 int packets_lost;
678 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000679 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000680 std::string codec_name;
681 std::vector<SsrcSenderInfo> local_stats;
682 std::vector<SsrcReceiverInfo> remote_stats;
683};
684
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000685template<class T>
686struct VariableInfo {
687 VariableInfo()
688 : min_val(),
689 mean(0.0),
690 max_val(),
691 variance(0.0) {
692 }
693 T min_val;
694 double mean;
695 T max_val;
696 double variance;
697};
698
wu@webrtc.org97077a32013-10-25 21:18:33 +0000699struct MediaReceiverInfo {
700 MediaReceiverInfo()
701 : bytes_rcvd(0),
702 packets_rcvd(0),
703 packets_lost(0),
704 fraction_lost(0.0) {
705 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000706 void add_ssrc(const SsrcReceiverInfo& stat) {
707 local_stats.push_back(stat);
708 }
709 // Temporary utility function for call sites that only provide SSRC.
710 // As more info is added into SsrcSenderInfo, this function should go away.
711 void add_ssrc(uint32 ssrc) {
712 SsrcReceiverInfo stat;
713 stat.ssrc = ssrc;
714 add_ssrc(stat);
715 }
716 std::vector<uint32> ssrcs() const {
717 std::vector<uint32> retval;
718 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
719 it != local_stats.end(); ++it) {
720 retval.push_back(it->ssrc);
721 }
722 return retval;
723 }
724 // Utility accessor for clients that make the assumption only one ssrc
725 // exists per media.
726 // This will eventually go away.
727 uint32 ssrc() const {
728 if (local_stats.size() > 0) {
729 return local_stats[0].ssrc;
730 } else {
731 return 0;
732 }
733 }
734
wu@webrtc.org97077a32013-10-25 21:18:33 +0000735 int64 bytes_rcvd;
736 int packets_rcvd;
737 int packets_lost;
738 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000739 std::string codec_name;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000740 std::vector<SsrcReceiverInfo> local_stats;
741 std::vector<SsrcSenderInfo> remote_stats;
742};
743
744struct VoiceSenderInfo : public MediaSenderInfo {
745 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000746 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 jitter_ms(0),
748 audio_level(0),
749 aec_quality_min(0.0),
750 echo_delay_median_ms(0),
751 echo_delay_std_ms(0),
752 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000753 echo_return_loss_enhancement(0),
754 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 }
756
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 int jitter_ms;
759 int audio_level;
760 float aec_quality_min;
761 int echo_delay_median_ms;
762 int echo_delay_std_ms;
763 int echo_return_loss;
764 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000765 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766};
767
wu@webrtc.org97077a32013-10-25 21:18:33 +0000768struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000770 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771 jitter_ms(0),
772 jitter_buffer_ms(0),
773 jitter_buffer_preferred_ms(0),
774 delay_estimate_ms(0),
775 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000776 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000777 speech_expand_rate(0),
778 secondary_decoded_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000779 decoding_calls_to_silence_generator(0),
780 decoding_calls_to_neteq(0),
781 decoding_normal(0),
782 decoding_plc(0),
783 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000784 decoding_plc_cng(0),
785 capture_start_ntp_time_ms(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 }
787
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 int ext_seqnum;
789 int jitter_ms;
790 int jitter_buffer_ms;
791 int jitter_buffer_preferred_ms;
792 int delay_estimate_ms;
793 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000794 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000796 // fraction of synthesized speech inserted through expansion.
797 float speech_expand_rate;
798 // fraction of data out of secondary decoding, including FEC and RED.
799 float secondary_decoded_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000800 int decoding_calls_to_silence_generator;
801 int decoding_calls_to_neteq;
802 int decoding_normal;
803 int decoding_plc;
804 int decoding_cng;
805 int decoding_plc_cng;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000806 // Estimated capture start time in NTP time in ms.
807 int64 capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808};
809
wu@webrtc.org97077a32013-10-25 21:18:33 +0000810struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000812 : packets_cached(0),
813 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000814 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000816 input_frame_width(0),
817 input_frame_height(0),
818 send_frame_width(0),
819 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 framerate_input(0),
821 framerate_sent(0),
822 nominal_bitrate(0),
823 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000824 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000825 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000826 avg_encode_ms(0),
Peter Boström8ed6a4b2015-03-27 10:01:02 +0100827 encode_usage_percent(0) {
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000828 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000830 std::vector<SsrcGroup> ssrc_groups;
831 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000833 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000835 int input_frame_width;
836 int input_frame_height;
837 int send_frame_width;
838 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 int framerate_input;
840 int framerate_sent;
841 int nominal_bitrate;
842 int preferred_bitrate;
843 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000844 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000845 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000846 int encode_usage_percent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000847 VariableInfo<int> adapt_frame_drops;
848 VariableInfo<int> effects_frame_drops;
849 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850};
851
wu@webrtc.org97077a32013-10-25 21:18:33 +0000852struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000854 : packets_concealed(0),
855 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000856 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 nacks_sent(0),
858 frame_width(0),
859 frame_height(0),
860 framerate_rcvd(0),
861 framerate_decoded(0),
862 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000863 framerate_render_input(0),
864 framerate_render_output(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000865 decode_ms(0),
866 max_decode_ms(0),
867 jitter_buffer_ms(0),
868 min_playout_delay_ms(0),
869 render_delay_ms(0),
870 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000871 current_delay_ms(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000872 capture_start_ntp_time_ms(-1) {
873 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000875 std::vector<SsrcGroup> ssrc_groups;
876 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000878 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 int nacks_sent;
880 int frame_width;
881 int frame_height;
882 int framerate_rcvd;
883 int framerate_decoded;
884 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000885 // Framerate as sent to the renderer.
886 int framerate_render_input;
887 // Framerate that the renderer reports.
888 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000889
890 // All stats below are gathered per-VideoReceiver, but some will be correlated
891 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
892 // structures, reflect this in the new layout.
893
894 // Current frame decode latency.
895 int decode_ms;
896 // Maximum observed frame decode latency.
897 int max_decode_ms;
898 // Jitter (network-related) latency.
899 int jitter_buffer_ms;
900 // Requested minimum playout latency.
901 int min_playout_delay_ms;
902 // Requested latency to account for rendering delay.
903 int render_delay_ms;
904 // Target overall delay: network+decode+render, accounting for
905 // min_playout_delay_ms.
906 int target_delay_ms;
907 // Current overall delay, possibly ramping towards target_delay_ms.
908 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000909
910 // Estimated capture start time in NTP time in ms.
911 int64 capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912};
913
wu@webrtc.org97077a32013-10-25 21:18:33 +0000914struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000916 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 }
918
919 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920};
921
wu@webrtc.org97077a32013-10-25 21:18:33 +0000922struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000924 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 }
926
927 uint32 ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928};
929
930struct BandwidthEstimationInfo {
931 BandwidthEstimationInfo()
932 : available_send_bandwidth(0),
933 available_recv_bandwidth(0),
934 target_enc_bitrate(0),
935 actual_enc_bitrate(0),
936 retransmit_bitrate(0),
937 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000938 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939 }
940
941 int available_send_bandwidth;
942 int available_recv_bandwidth;
943 int target_enc_bitrate;
944 int actual_enc_bitrate;
945 int retransmit_bitrate;
946 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000947 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948};
949
950struct VoiceMediaInfo {
951 void Clear() {
952 senders.clear();
953 receivers.clear();
954 }
955 std::vector<VoiceSenderInfo> senders;
956 std::vector<VoiceReceiverInfo> receivers;
957};
958
959struct VideoMediaInfo {
960 void Clear() {
961 senders.clear();
962 receivers.clear();
963 bw_estimations.clear();
964 }
965 std::vector<VideoSenderInfo> senders;
966 std::vector<VideoReceiverInfo> receivers;
967 std::vector<BandwidthEstimationInfo> bw_estimations;
968};
969
970struct DataMediaInfo {
971 void Clear() {
972 senders.clear();
973 receivers.clear();
974 }
975 std::vector<DataSenderInfo> senders;
976 std::vector<DataReceiverInfo> receivers;
977};
978
979class VoiceMediaChannel : public MediaChannel {
980 public:
981 enum Error {
982 ERROR_NONE = 0, // No error.
983 ERROR_OTHER, // Other errors.
984 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
985 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
986 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
987 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
988 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
989 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
990 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
991 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
992 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
993 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
994 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
995 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
996 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
997 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
998 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
999 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1000 };
1001
1002 VoiceMediaChannel() {}
1003 virtual ~VoiceMediaChannel() {}
1004 // Sets the codecs/payload types to be used for incoming media.
1005 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0;
1006 // Sets the codecs/payload types to be used for outgoing media.
1007 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0;
1008 // Starts or stops playout of received audio.
1009 virtual bool SetPlayout(bool playout) = 0;
1010 // Starts or stops sending (and potentially capture) of local audio.
1011 virtual bool SetSend(SendFlags flag) = 0;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001012 // Sets the renderer object to be used for the specified remote audio stream.
1013 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
1014 // Sets the renderer object to be used for the specified local audio stream.
1015 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 // Gets current energy levels for all incoming streams.
1017 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1018 // Get the current energy level of the stream sent to the speaker.
1019 virtual int GetOutputLevel() = 0;
1020 // Get the time in milliseconds since last recorded keystroke, or negative.
1021 virtual int GetTimeSinceLastTyping() = 0;
1022 // Temporarily exposed field for tuning typing detect options.
1023 virtual void SetTypingDetectionParameters(int time_window,
1024 int cost_per_typing, int reporting_threshold, int penalty_decay,
1025 int type_event_delay) = 0;
1026 // Set left and right scale for speaker output volume of the specified ssrc.
1027 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0;
1028 // Get left and right scale for speaker output volume of the specified ssrc.
1029 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0;
1030 // Specifies a ringback tone to be played during call setup.
1031 virtual bool SetRingbackTone(const char *buf, int len) = 0;
1032 // Plays or stops the aforementioned ringback tone
1033 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0;
1034 // Returns if the telephone-event has been negotiated.
1035 virtual bool CanInsertDtmf() { return false; }
1036 // Send and/or play a DTMF |event| according to the |flags|.
1037 // The DTMF out-of-band signal will be used on sending.
1038 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001039 // The valid value for the |event| are 0 to 15 which corresponding to
1040 // DTMF event 0-9, *, #, A-D.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0;
1042 // Gets quality stats for the channel.
1043 virtual bool GetStats(VoiceMediaInfo* info) = 0;
1044 // Gets last reported error for this media channel.
1045 virtual void GetLastMediaError(uint32* ssrc,
1046 VoiceMediaChannel::Error* error) {
1047 ASSERT(error != NULL);
1048 *error = ERROR_NONE;
1049 }
1050 // Sets the media options to use.
1051 virtual bool SetOptions(const AudioOptions& options) = 0;
1052 virtual bool GetOptions(AudioOptions* options) const = 0;
1053
1054 // Signal errors from MediaChannel. Arguments are:
1055 // ssrc(uint32), and error(VoiceMediaChannel::Error).
1056 sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError;
1057};
1058
1059class VideoMediaChannel : public MediaChannel {
1060 public:
1061 enum Error {
1062 ERROR_NONE = 0, // No error.
1063 ERROR_OTHER, // Other errors.
1064 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1065 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1066 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1067 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1068 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1069 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1070 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1071 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1072 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1073 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1074 };
1075
1076 VideoMediaChannel() : renderer_(NULL) {}
1077 virtual ~VideoMediaChannel() {}
Fredrik Solenberg4b60c732015-05-07 14:07:48 +02001078 // Allow video channel to unhook itself from an associated voice channel.
1079 virtual void DetachVoiceChannel() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 // Sets the codecs/payload types to be used for incoming media.
1081 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0;
1082 // Sets the codecs/payload types to be used for outgoing media.
1083 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0;
1084 // Gets the currently set codecs/payload types to be used for outgoing media.
1085 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1086 // Sets the format of a specified outgoing stream.
1087 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0;
1088 // Starts or stops playout of received video.
1089 virtual bool SetRender(bool render) = 0;
1090 // Starts or stops transmission (and potentially capture) of local video.
1091 virtual bool SetSend(bool send) = 0;
1092 // Sets the renderer object to be used for the specified stream.
1093 // If SSRC is 0, the renderer is used for the 'default' stream.
1094 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0;
1095 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1096 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
1097 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0;
1098 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001099 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 // Send an intra frame to the receivers.
1101 virtual bool SendIntraFrame() = 0;
1102 // Reuqest each of the remote senders to send an intra frame.
1103 virtual bool RequestIntraFrame() = 0;
1104 // Sets the media options to use.
1105 virtual bool SetOptions(const VideoOptions& options) = 0;
1106 virtual bool GetOptions(VideoOptions* options) const = 0;
1107 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1108
1109 // Signal errors from MediaChannel. Arguments are:
1110 // ssrc(uint32), and error(VideoMediaChannel::Error).
1111 sigslot::signal2<uint32, Error> SignalMediaError;
1112
1113 protected:
1114 VideoRenderer *renderer_;
1115};
1116
1117enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001118 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1119 // values.
1120 DMT_NONE = 0,
1121 DMT_CONTROL = 1,
1122 DMT_BINARY = 2,
1123 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124};
1125
1126// Info about data received in DataMediaChannel. For use in
1127// DataMediaChannel::SignalDataReceived and in all of the signals that
1128// signal fires, on up the chain.
1129struct ReceiveDataParams {
1130 // The in-packet stream indentifier.
1131 // For SCTP, this is really SID, not SSRC.
1132 uint32 ssrc;
1133 // The type of message (binary, text, or control).
1134 DataMessageType type;
1135 // A per-stream value incremented per packet in the stream.
1136 int seq_num;
1137 // A per-stream value monotonically increasing with time.
1138 int timestamp;
1139
1140 ReceiveDataParams() :
1141 ssrc(0),
1142 type(DMT_TEXT),
1143 seq_num(0),
1144 timestamp(0) {
1145 }
1146};
1147
1148struct SendDataParams {
1149 // The in-packet stream indentifier.
1150 // For SCTP, this is really SID, not SSRC.
1151 uint32 ssrc;
1152 // The type of message (binary, text, or control).
1153 DataMessageType type;
1154
1155 // For SCTP, whether to send messages flagged as ordered or not.
1156 // If false, messages can be received out of order.
1157 bool ordered;
1158 // For SCTP, whether the messages are sent reliably or not.
1159 // If false, messages may be lost.
1160 bool reliable;
1161 // For SCTP, if reliable == false, provide partial reliability by
1162 // resending up to this many times. Either count or millis
1163 // is supported, not both at the same time.
1164 int max_rtx_count;
1165 // For SCTP, if reliable == false, provide partial reliability by
1166 // resending for up to this many milliseconds. Either count or millis
1167 // is supported, not both at the same time.
1168 int max_rtx_ms;
1169
1170 SendDataParams() :
1171 ssrc(0),
1172 type(DMT_TEXT),
1173 // TODO(pthatcher): Make these true by default?
1174 ordered(false),
1175 reliable(false),
1176 max_rtx_count(0),
1177 max_rtx_ms(0) {
1178 }
1179};
1180
1181enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1182
1183class DataMediaChannel : public MediaChannel {
1184 public:
1185 enum Error {
1186 ERROR_NONE = 0, // No error.
1187 ERROR_OTHER, // Other errors.
1188 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1189 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1190 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1191 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1192 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1193 };
1194
1195 virtual ~DataMediaChannel() {}
1196
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001197 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0;
1198 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001199
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
1201 // TODO(pthatcher): Implement this.
1202 virtual bool GetStats(DataMediaInfo* info) { return true; }
1203
1204 virtual bool SetSend(bool send) = 0;
1205 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001206
1207 virtual bool SendData(
1208 const SendDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001209 const rtc::Buffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001210 SendDataResult* result = NULL) = 0;
1211 // Signals when data is received (params, data, len)
1212 sigslot::signal3<const ReceiveDataParams&,
1213 const char*,
1214 size_t> SignalDataReceived;
1215 // Signal errors from MediaChannel. Arguments are:
1216 // ssrc(uint32), and error(DataMediaChannel::Error).
1217 sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001218 // Signal when the media channel is ready to send the stream. Arguments are:
1219 // writable(bool)
1220 sigslot::signal1<bool> SignalReadyToSend;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001221 // Signal for notifying that the remote side has closed the DataChannel.
1222 sigslot::signal1<uint32> SignalStreamClosedRemotely;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001223};
1224
1225} // namespace cricket
1226
1227#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_