henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 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.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 34 | #include "talk/media/base/codec.h" |
| 35 | #include "talk/media/base/constants.h" |
| 36 | #include "talk/media/base/streamparams.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 37 | #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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | // TODO(juberti): re-evaluate this include |
| 45 | #include "talk/session/media/audiomonitor.h" |
| 46 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 47 | namespace rtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 48 | class Buffer; |
| 49 | class RateLimiter; |
| 50 | class Timing; |
| 51 | } |
| 52 | |
| 53 | namespace cricket { |
| 54 | |
| 55 | class AudioRenderer; |
| 56 | struct RtpHeader; |
| 57 | class ScreencastId; |
| 58 | struct VideoFormat; |
| 59 | class VideoCapturer; |
| 60 | class VideoRenderer; |
| 61 | |
| 62 | const int kMinRtpHeaderExtensionId = 1; |
| 63 | const int kMaxRtpHeaderExtensionId = 255; |
| 64 | const int kScreencastDefaultFps = 5; |
wu@webrtc.org | cfe5e9c | 2014-03-27 17:03:58 +0000 | [diff] [blame] | 65 | const int kHighStartBitrate = 1500; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | |
| 67 | // Used in AudioOptions and VideoOptions to signify "unset" values. |
| 68 | template <class T> |
| 69 | class 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.org | 40b276e | 2014-12-12 02:44:30 +0000 | [diff] [blame] | 87 | void Set(T val) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 88 | 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 107 | return set_ ? rtc::ToString(val_) : ""; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | } |
| 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 129 | template <class T> |
| 130 | static 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. |
| 145 | struct 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.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 149 | rx_auto_gain_control.SetFrom(change.rx_auto_gain_control); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 150 | noise_suppression.SetFrom(change.noise_suppression); |
| 151 | highpass_filter.SetFrom(change.highpass_filter); |
| 152 | stereo_swapping.SetFrom(change.stereo_swapping); |
| 153 | typing_detection.SetFrom(change.typing_detection); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 154 | aecm_generate_comfort_noise.SetFrom(change.aecm_generate_comfort_noise); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 155 | conference_mode.SetFrom(change.conference_mode); |
| 156 | adjust_agc_delta.SetFrom(change.adjust_agc_delta); |
| 157 | experimental_agc.SetFrom(change.experimental_agc); |
| 158 | experimental_aec.SetFrom(change.experimental_aec); |
Bjorn Volcker | bf395c1 | 2015-03-25 22:45:56 +0100 | [diff] [blame] | 159 | delay_agnostic_aec.SetFrom(change.delay_agnostic_aec); |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 160 | experimental_ns.SetFrom(change.experimental_ns); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 161 | aec_dump.SetFrom(change.aec_dump); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 162 | tx_agc_target_dbov.SetFrom(change.tx_agc_target_dbov); |
| 163 | tx_agc_digital_compression_gain.SetFrom( |
| 164 | change.tx_agc_digital_compression_gain); |
| 165 | tx_agc_limiter.SetFrom(change.tx_agc_limiter); |
| 166 | rx_agc_target_dbov.SetFrom(change.rx_agc_target_dbov); |
| 167 | rx_agc_digital_compression_gain.SetFrom( |
| 168 | change.rx_agc_digital_compression_gain); |
| 169 | rx_agc_limiter.SetFrom(change.rx_agc_limiter); |
| 170 | recording_sample_rate.SetFrom(change.recording_sample_rate); |
| 171 | playout_sample_rate.SetFrom(change.playout_sample_rate); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 172 | dscp.SetFrom(change.dscp); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 173 | combined_audio_video_bwe.SetFrom(change.combined_audio_video_bwe); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | bool operator==(const AudioOptions& o) const { |
| 177 | return echo_cancellation == o.echo_cancellation && |
| 178 | auto_gain_control == o.auto_gain_control && |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 179 | rx_auto_gain_control == o.rx_auto_gain_control && |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | noise_suppression == o.noise_suppression && |
| 181 | highpass_filter == o.highpass_filter && |
| 182 | stereo_swapping == o.stereo_swapping && |
| 183 | typing_detection == o.typing_detection && |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 184 | aecm_generate_comfort_noise == o.aecm_generate_comfort_noise && |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | conference_mode == o.conference_mode && |
| 186 | experimental_agc == o.experimental_agc && |
| 187 | experimental_aec == o.experimental_aec && |
Bjorn Volcker | bf395c1 | 2015-03-25 22:45:56 +0100 | [diff] [blame] | 188 | delay_agnostic_aec == o.delay_agnostic_aec && |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 189 | experimental_ns == o.experimental_ns && |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 190 | adjust_agc_delta == o.adjust_agc_delta && |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 191 | aec_dump == o.aec_dump && |
| 192 | tx_agc_target_dbov == o.tx_agc_target_dbov && |
| 193 | tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain && |
| 194 | tx_agc_limiter == o.tx_agc_limiter && |
| 195 | rx_agc_target_dbov == o.rx_agc_target_dbov && |
| 196 | rx_agc_digital_compression_gain == o.rx_agc_digital_compression_gain && |
| 197 | rx_agc_limiter == o.rx_agc_limiter && |
| 198 | recording_sample_rate == o.recording_sample_rate && |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 199 | playout_sample_rate == o.playout_sample_rate && |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 200 | dscp == o.dscp && |
| 201 | combined_audio_video_bwe == o.combined_audio_video_bwe; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | std::string ToString() const { |
| 205 | std::ostringstream ost; |
| 206 | ost << "AudioOptions {"; |
| 207 | ost << ToStringIfSet("aec", echo_cancellation); |
| 208 | ost << ToStringIfSet("agc", auto_gain_control); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 209 | ost << ToStringIfSet("rx_agc", rx_auto_gain_control); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 210 | ost << ToStringIfSet("ns", noise_suppression); |
| 211 | ost << ToStringIfSet("hf", highpass_filter); |
| 212 | ost << ToStringIfSet("swap", stereo_swapping); |
| 213 | ost << ToStringIfSet("typing", typing_detection); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 214 | ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 215 | ost << ToStringIfSet("conference", conference_mode); |
| 216 | ost << ToStringIfSet("agc_delta", adjust_agc_delta); |
| 217 | ost << ToStringIfSet("experimental_agc", experimental_agc); |
| 218 | ost << ToStringIfSet("experimental_aec", experimental_aec); |
Bjorn Volcker | bf395c1 | 2015-03-25 22:45:56 +0100 | [diff] [blame] | 219 | ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec); |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 220 | ost << ToStringIfSet("experimental_ns", experimental_ns); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 221 | ost << ToStringIfSet("aec_dump", aec_dump); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 222 | ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov); |
| 223 | ost << ToStringIfSet("tx_agc_digital_compression_gain", |
| 224 | tx_agc_digital_compression_gain); |
| 225 | ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter); |
| 226 | ost << ToStringIfSet("rx_agc_target_dbov", rx_agc_target_dbov); |
| 227 | ost << ToStringIfSet("rx_agc_digital_compression_gain", |
| 228 | rx_agc_digital_compression_gain); |
| 229 | ost << ToStringIfSet("rx_agc_limiter", rx_agc_limiter); |
| 230 | ost << ToStringIfSet("recording_sample_rate", recording_sample_rate); |
| 231 | ost << ToStringIfSet("playout_sample_rate", playout_sample_rate); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 232 | ost << ToStringIfSet("dscp", dscp); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 233 | ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 234 | ost << "}"; |
| 235 | return ost.str(); |
| 236 | } |
| 237 | |
| 238 | // Audio processing that attempts to filter away the output signal from |
| 239 | // later inbound pickup. |
| 240 | Settable<bool> echo_cancellation; |
| 241 | // Audio processing to adjust the sensitivity of the local mic dynamically. |
| 242 | Settable<bool> auto_gain_control; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 243 | // Audio processing to apply gain to the remote audio. |
| 244 | Settable<bool> rx_auto_gain_control; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 245 | // Audio processing to filter out background noise. |
| 246 | Settable<bool> noise_suppression; |
| 247 | // Audio processing to remove background noise of lower frequencies. |
| 248 | Settable<bool> highpass_filter; |
| 249 | // Audio processing to swap the left and right channels. |
| 250 | Settable<bool> stereo_swapping; |
| 251 | // Audio processing to detect typing. |
| 252 | Settable<bool> typing_detection; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 253 | Settable<bool> aecm_generate_comfort_noise; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 254 | Settable<bool> conference_mode; |
| 255 | Settable<int> adjust_agc_delta; |
| 256 | Settable<bool> experimental_agc; |
| 257 | Settable<bool> experimental_aec; |
Bjorn Volcker | bf395c1 | 2015-03-25 22:45:56 +0100 | [diff] [blame] | 258 | Settable<bool> delay_agnostic_aec; |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 259 | Settable<bool> experimental_ns; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 260 | Settable<bool> aec_dump; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 261 | // Note that tx_agc_* only applies to non-experimental AGC. |
| 262 | Settable<uint16> tx_agc_target_dbov; |
| 263 | Settable<uint16> tx_agc_digital_compression_gain; |
| 264 | Settable<bool> tx_agc_limiter; |
| 265 | Settable<uint16> rx_agc_target_dbov; |
| 266 | Settable<uint16> rx_agc_digital_compression_gain; |
| 267 | Settable<bool> rx_agc_limiter; |
| 268 | Settable<uint32> recording_sample_rate; |
| 269 | Settable<uint32> playout_sample_rate; |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 270 | // Set DSCP value for packet sent from audio channel. |
| 271 | Settable<bool> dscp; |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 272 | // Enable combined audio+bandwidth BWE. |
| 273 | Settable<bool> combined_audio_video_bwe; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 274 | }; |
| 275 | |
| 276 | // Options that can be applied to a VideoMediaChannel or a VideoMediaEngine. |
| 277 | // Used to be flags, but that makes it hard to selectively apply options. |
| 278 | // We are moving all of the setting of options to structs like this, |
| 279 | // but some things currently still use flags. |
| 280 | struct VideoOptions { |
henrike@webrtc.org | f45a550 | 2014-03-13 18:51:34 +0000 | [diff] [blame] | 281 | enum HighestBitrate { |
| 282 | NORMAL, |
| 283 | HIGH, |
| 284 | VERY_HIGH |
| 285 | }; |
| 286 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 287 | VideoOptions() { |
| 288 | process_adaptation_threshhold.Set(kProcessCpuThreshold); |
| 289 | system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold); |
| 290 | system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 291 | unsignalled_recv_stream_limit.Set(kNumDefaultUnsignalledVideoRecvStreams); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void SetAll(const VideoOptions& change) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 295 | adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 296 | adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 297 | video_adapt_third.SetFrom(change.video_adapt_third); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 298 | video_noise_reduction.SetFrom(change.video_noise_reduction); |
wu@webrtc.org | 1e6cb2c | 2014-03-24 17:01:50 +0000 | [diff] [blame] | 299 | video_start_bitrate.SetFrom(change.video_start_bitrate); |
henrike@webrtc.org | f45a550 | 2014-03-13 18:51:34 +0000 | [diff] [blame] | 300 | video_highest_bitrate.SetFrom(change.video_highest_bitrate); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 301 | cpu_overuse_detection.SetFrom(change.cpu_overuse_detection); |
henrike@webrtc.org | e9793ab | 2014-03-18 14:36:23 +0000 | [diff] [blame] | 302 | cpu_underuse_threshold.SetFrom(change.cpu_underuse_threshold); |
| 303 | cpu_overuse_threshold.SetFrom(change.cpu_overuse_threshold); |
buildbot@webrtc.org | 27626a6 | 2014-06-16 13:39:40 +0000 | [diff] [blame] | 304 | cpu_underuse_encode_rsd_threshold.SetFrom( |
| 305 | change.cpu_underuse_encode_rsd_threshold); |
| 306 | cpu_overuse_encode_rsd_threshold.SetFrom( |
| 307 | change.cpu_overuse_encode_rsd_threshold); |
henrike@webrtc.org | b0ecc1c | 2014-03-26 22:44:28 +0000 | [diff] [blame] | 308 | cpu_overuse_encode_usage.SetFrom(change.cpu_overuse_encode_usage); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 309 | conference_mode.SetFrom(change.conference_mode); |
| 310 | process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold); |
| 311 | system_low_adaptation_threshhold.SetFrom( |
| 312 | change.system_low_adaptation_threshhold); |
| 313 | system_high_adaptation_threshhold.SetFrom( |
| 314 | change.system_high_adaptation_threshhold); |
| 315 | buffered_mode_latency.SetFrom(change.buffered_mode_latency); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 316 | dscp.SetFrom(change.dscp); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 317 | suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 318 | unsignalled_recv_stream_limit.SetFrom(change.unsignalled_recv_stream_limit); |
henrike@webrtc.org | 10bd88e | 2014-03-11 21:07:25 +0000 | [diff] [blame] | 319 | use_simulcast_adapter.SetFrom(change.use_simulcast_adapter); |
henrike@webrtc.org | dce3feb | 2014-03-26 01:17:30 +0000 | [diff] [blame] | 320 | screencast_min_bitrate.SetFrom(change.screencast_min_bitrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | bool operator==(const VideoOptions& o) const { |
pbos@webrtc.org | 43336b6 | 2014-10-14 19:12:06 +0000 | [diff] [blame] | 324 | return adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage && |
| 325 | adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing && |
| 326 | video_adapt_third == o.video_adapt_third && |
| 327 | video_noise_reduction == o.video_noise_reduction && |
| 328 | video_start_bitrate == o.video_start_bitrate && |
pbos@webrtc.org | 43336b6 | 2014-10-14 19:12:06 +0000 | [diff] [blame] | 329 | video_highest_bitrate == o.video_highest_bitrate && |
| 330 | cpu_overuse_detection == o.cpu_overuse_detection && |
| 331 | cpu_underuse_threshold == o.cpu_underuse_threshold && |
| 332 | cpu_overuse_threshold == o.cpu_overuse_threshold && |
| 333 | cpu_underuse_encode_rsd_threshold == |
| 334 | o.cpu_underuse_encode_rsd_threshold && |
| 335 | cpu_overuse_encode_rsd_threshold == |
| 336 | o.cpu_overuse_encode_rsd_threshold && |
| 337 | cpu_overuse_encode_usage == o.cpu_overuse_encode_usage && |
| 338 | conference_mode == o.conference_mode && |
| 339 | process_adaptation_threshhold == o.process_adaptation_threshhold && |
| 340 | system_low_adaptation_threshhold == |
| 341 | o.system_low_adaptation_threshhold && |
| 342 | system_high_adaptation_threshhold == |
| 343 | o.system_high_adaptation_threshhold && |
| 344 | buffered_mode_latency == o.buffered_mode_latency && dscp == o.dscp && |
| 345 | suspend_below_min_bitrate == o.suspend_below_min_bitrate && |
| 346 | unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit && |
| 347 | use_simulcast_adapter == o.use_simulcast_adapter && |
stefan@webrtc.org | 742386a | 2014-12-19 15:33:17 +0000 | [diff] [blame] | 348 | screencast_min_bitrate == o.screencast_min_bitrate; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | std::string ToString() const { |
| 352 | std::ostringstream ost; |
| 353 | ost << "VideoOptions {"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 354 | ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 355 | ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 356 | ost << ToStringIfSet("video adapt third", video_adapt_third); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 357 | ost << ToStringIfSet("noise reduction", video_noise_reduction); |
wu@webrtc.org | 1e6cb2c | 2014-03-24 17:01:50 +0000 | [diff] [blame] | 358 | ost << ToStringIfSet("start bitrate", video_start_bitrate); |
henrike@webrtc.org | f45a550 | 2014-03-13 18:51:34 +0000 | [diff] [blame] | 359 | ost << ToStringIfSet("highest video bitrate", video_highest_bitrate); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 360 | ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection); |
henrike@webrtc.org | e9793ab | 2014-03-18 14:36:23 +0000 | [diff] [blame] | 361 | ost << ToStringIfSet("cpu underuse threshold", cpu_underuse_threshold); |
| 362 | ost << ToStringIfSet("cpu overuse threshold", cpu_overuse_threshold); |
buildbot@webrtc.org | 27626a6 | 2014-06-16 13:39:40 +0000 | [diff] [blame] | 363 | ost << ToStringIfSet("cpu underuse encode rsd threshold", |
| 364 | cpu_underuse_encode_rsd_threshold); |
| 365 | ost << ToStringIfSet("cpu overuse encode rsd threshold", |
| 366 | cpu_overuse_encode_rsd_threshold); |
henrike@webrtc.org | b0ecc1c | 2014-03-26 22:44:28 +0000 | [diff] [blame] | 367 | ost << ToStringIfSet("cpu overuse encode usage", |
| 368 | cpu_overuse_encode_usage); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 369 | ost << ToStringIfSet("conference mode", conference_mode); |
| 370 | ost << ToStringIfSet("process", process_adaptation_threshhold); |
| 371 | ost << ToStringIfSet("low", system_low_adaptation_threshhold); |
| 372 | ost << ToStringIfSet("high", system_high_adaptation_threshhold); |
| 373 | ost << ToStringIfSet("buffered mode latency", buffered_mode_latency); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 374 | ost << ToStringIfSet("dscp", dscp); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 375 | ost << ToStringIfSet("suspend below min bitrate", |
| 376 | suspend_below_min_bitrate); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 377 | ost << ToStringIfSet("num channels for early receive", |
| 378 | unsignalled_recv_stream_limit); |
henrike@webrtc.org | 10bd88e | 2014-03-11 21:07:25 +0000 | [diff] [blame] | 379 | ost << ToStringIfSet("use simulcast adapter", use_simulcast_adapter); |
henrike@webrtc.org | dce3feb | 2014-03-26 01:17:30 +0000 | [diff] [blame] | 380 | ost << ToStringIfSet("screencast min bitrate", screencast_min_bitrate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 381 | ost << "}"; |
| 382 | return ost.str(); |
| 383 | } |
| 384 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 385 | // Enable CPU adaptation? |
| 386 | Settable<bool> adapt_input_to_cpu_usage; |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 387 | // Enable CPU adaptation smoothing? |
| 388 | Settable<bool> adapt_cpu_with_smoothing; |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 389 | // Enable video adapt third? |
| 390 | Settable<bool> video_adapt_third; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 391 | // Enable denoising? |
| 392 | Settable<bool> video_noise_reduction; |
wu@webrtc.org | 1e6cb2c | 2014-03-24 17:01:50 +0000 | [diff] [blame] | 393 | // Experimental: Enable WebRtc higher start bitrate? |
| 394 | Settable<int> video_start_bitrate; |
henrike@webrtc.org | f45a550 | 2014-03-13 18:51:34 +0000 | [diff] [blame] | 395 | // Set highest bitrate mode for video. |
wu@webrtc.org | cfe5e9c | 2014-03-27 17:03:58 +0000 | [diff] [blame] | 396 | Settable<HighestBitrate> video_highest_bitrate; |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 397 | // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU |
| 398 | // adaptation algorithm. So this option will override the |
| 399 | // |adapt_input_to_cpu_usage|. |
| 400 | Settable<bool> cpu_overuse_detection; |
buildbot@webrtc.org | 27626a6 | 2014-06-16 13:39:40 +0000 | [diff] [blame] | 401 | // Low threshold (t1) for cpu overuse adaptation. (Adapt up) |
| 402 | // Metric: encode usage (m1). m1 < t1 => underuse. |
henrike@webrtc.org | e9793ab | 2014-03-18 14:36:23 +0000 | [diff] [blame] | 403 | Settable<int> cpu_underuse_threshold; |
buildbot@webrtc.org | 27626a6 | 2014-06-16 13:39:40 +0000 | [diff] [blame] | 404 | // High threshold (t1) for cpu overuse adaptation. (Adapt down) |
| 405 | // Metric: encode usage (m1). m1 > t1 => overuse. |
henrike@webrtc.org | e9793ab | 2014-03-18 14:36:23 +0000 | [diff] [blame] | 406 | Settable<int> cpu_overuse_threshold; |
buildbot@webrtc.org | 27626a6 | 2014-06-16 13:39:40 +0000 | [diff] [blame] | 407 | // Low threshold (t2) for cpu overuse adaptation. (Adapt up) |
| 408 | // Metric: relative standard deviation of encode time (m2). |
| 409 | // Optional threshold. If set, (m1 < t1 && m2 < t2) => underuse. |
| 410 | // Note: t2 will have no effect if t1 is not set. |
| 411 | Settable<int> cpu_underuse_encode_rsd_threshold; |
| 412 | // High threshold (t2) for cpu overuse adaptation. (Adapt down) |
| 413 | // Metric: relative standard deviation of encode time (m2). |
| 414 | // Optional threshold. If set, (m1 > t1 || m2 > t2) => overuse. |
| 415 | // Note: t2 will have no effect if t1 is not set. |
| 416 | Settable<int> cpu_overuse_encode_rsd_threshold; |
henrike@webrtc.org | b0ecc1c | 2014-03-26 22:44:28 +0000 | [diff] [blame] | 417 | // Use encode usage for cpu detection. |
| 418 | Settable<bool> cpu_overuse_encode_usage; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 419 | // Use conference mode? |
| 420 | Settable<bool> conference_mode; |
| 421 | // Threshhold for process cpu adaptation. (Process limit) |
pthatcher@webrtc.org | 40b276e | 2014-12-12 02:44:30 +0000 | [diff] [blame] | 422 | Settable<float> process_adaptation_threshhold; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 423 | // Low threshhold for cpu adaptation. (Adapt up) |
pthatcher@webrtc.org | 40b276e | 2014-12-12 02:44:30 +0000 | [diff] [blame] | 424 | Settable<float> system_low_adaptation_threshhold; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 425 | // High threshhold for cpu adaptation. (Adapt down) |
pthatcher@webrtc.org | 40b276e | 2014-12-12 02:44:30 +0000 | [diff] [blame] | 426 | Settable<float> system_high_adaptation_threshhold; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 427 | // Specify buffered mode latency in milliseconds. |
| 428 | Settable<int> buffered_mode_latency; |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 429 | // Set DSCP value for packet sent from video channel. |
| 430 | Settable<bool> dscp; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 431 | // Enable WebRTC suspension of video. No video frames will be sent when the |
| 432 | // bitrate is below the configured minimum bitrate. |
| 433 | Settable<bool> suspend_below_min_bitrate; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 434 | // Limit on the number of early receive channels that can be created. |
| 435 | Settable<int> unsignalled_recv_stream_limit; |
henrike@webrtc.org | 10bd88e | 2014-03-11 21:07:25 +0000 | [diff] [blame] | 436 | // Enable use of simulcast adapter. |
| 437 | Settable<bool> use_simulcast_adapter; |
henrike@webrtc.org | dce3feb | 2014-03-26 01:17:30 +0000 | [diff] [blame] | 438 | // Force screencast to use a minimum bitrate |
| 439 | Settable<int> screencast_min_bitrate; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 440 | }; |
| 441 | |
| 442 | // A class for playing out soundclips. |
| 443 | class SoundclipMedia { |
| 444 | public: |
| 445 | enum SoundclipFlags { |
| 446 | SF_LOOP = 1, |
| 447 | }; |
| 448 | |
| 449 | virtual ~SoundclipMedia() {} |
| 450 | |
| 451 | // Plays a sound out to the speakers with the given audio stream. The stream |
| 452 | // must be 16-bit little-endian 16 kHz PCM. If a stream is already playing |
| 453 | // on this SoundclipMedia, it is stopped. If clip is NULL, nothing is played. |
| 454 | // Returns whether it was successful. |
| 455 | virtual bool PlaySound(const char *clip, int len, int flags) = 0; |
| 456 | }; |
| 457 | |
| 458 | struct RtpHeaderExtension { |
| 459 | RtpHeaderExtension() : id(0) {} |
| 460 | RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {} |
| 461 | std::string uri; |
| 462 | int id; |
| 463 | // TODO(juberti): SendRecv direction; |
| 464 | |
| 465 | bool operator==(const RtpHeaderExtension& ext) const { |
| 466 | // id is a reserved word in objective-c. Therefore the id attribute has to |
| 467 | // be a fully qualified name in order to compile on IOS. |
| 468 | return this->id == ext.id && |
| 469 | uri == ext.uri; |
| 470 | } |
| 471 | }; |
| 472 | |
| 473 | // Returns the named header extension if found among all extensions, NULL |
| 474 | // otherwise. |
| 475 | inline const RtpHeaderExtension* FindHeaderExtension( |
| 476 | const std::vector<RtpHeaderExtension>& extensions, |
| 477 | const std::string& name) { |
| 478 | for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin(); |
| 479 | it != extensions.end(); ++it) { |
| 480 | if (it->uri == name) |
| 481 | return &(*it); |
| 482 | } |
| 483 | return NULL; |
| 484 | } |
| 485 | |
| 486 | enum MediaChannelOptions { |
| 487 | // Tune the stream for conference mode. |
| 488 | OPT_CONFERENCE = 0x0001 |
| 489 | }; |
| 490 | |
| 491 | enum VoiceMediaChannelOptions { |
| 492 | // Tune the audio stream for vcs with different target levels. |
| 493 | OPT_AGC_MINUS_10DB = 0x80000000 |
| 494 | }; |
| 495 | |
| 496 | // DTMF flags to control if a DTMF tone should be played and/or sent. |
| 497 | enum DtmfFlags { |
| 498 | DF_PLAY = 0x01, |
| 499 | DF_SEND = 0x02, |
| 500 | }; |
| 501 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 502 | class MediaChannel : public sigslot::has_slots<> { |
| 503 | public: |
| 504 | class NetworkInterface { |
| 505 | public: |
| 506 | enum SocketType { ST_RTP, ST_RTCP }; |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 507 | virtual bool SendPacket( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 508 | rtc::Buffer* packet, |
| 509 | rtc::DiffServCodePoint dscp = rtc::DSCP_NO_CHANGE) = 0; |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 510 | virtual bool SendRtcp( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 511 | rtc::Buffer* packet, |
| 512 | rtc::DiffServCodePoint dscp = rtc::DSCP_NO_CHANGE) = 0; |
| 513 | virtual int SetOption(SocketType type, rtc::Socket::Option opt, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 514 | int option) = 0; |
| 515 | virtual ~NetworkInterface() {} |
| 516 | }; |
| 517 | |
| 518 | MediaChannel() : network_interface_(NULL) {} |
| 519 | virtual ~MediaChannel() {} |
| 520 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 521 | // Sets the abstract interface class for sending RTP/RTCP data. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 522 | virtual void SetInterface(NetworkInterface *iface) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 523 | rtc::CritScope cs(&network_interface_crit_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 524 | network_interface_ = iface; |
| 525 | } |
| 526 | |
| 527 | // Called when a RTP packet is received. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 528 | virtual void OnPacketReceived(rtc::Buffer* packet, |
| 529 | const rtc::PacketTime& packet_time) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 530 | // Called when a RTCP packet is received. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 531 | virtual void OnRtcpReceived(rtc::Buffer* packet, |
| 532 | const rtc::PacketTime& packet_time) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 533 | // Called when the socket's ability to send has changed. |
| 534 | virtual void OnReadyToSend(bool ready) = 0; |
| 535 | // Creates a new outgoing media stream with SSRCs and CNAME as described |
| 536 | // by sp. |
| 537 | virtual bool AddSendStream(const StreamParams& sp) = 0; |
| 538 | // Removes an outgoing media stream. |
| 539 | // ssrc must be the first SSRC of the media stream if the stream uses |
| 540 | // multiple SSRCs. |
| 541 | virtual bool RemoveSendStream(uint32 ssrc) = 0; |
| 542 | // Creates a new incoming media stream with SSRCs and CNAME as described |
| 543 | // by sp. |
| 544 | virtual bool AddRecvStream(const StreamParams& sp) = 0; |
| 545 | // Removes an incoming media stream. |
| 546 | // ssrc must be the first SSRC of the media stream if the stream uses |
| 547 | // multiple SSRCs. |
| 548 | virtual bool RemoveRecvStream(uint32 ssrc) = 0; |
| 549 | |
| 550 | // Mutes the channel. |
| 551 | virtual bool MuteStream(uint32 ssrc, bool on) = 0; |
| 552 | |
| 553 | // Sets the RTP extension headers and IDs to use when sending RTP. |
| 554 | virtual bool SetRecvRtpHeaderExtensions( |
| 555 | const std::vector<RtpHeaderExtension>& extensions) = 0; |
| 556 | virtual bool SetSendRtpHeaderExtensions( |
| 557 | const std::vector<RtpHeaderExtension>& extensions) = 0; |
mallinath@webrtc.org | 92fdfeb | 2014-02-17 18:49:41 +0000 | [diff] [blame] | 558 | // Returns the absoulte sendtime extension id value from media channel. |
| 559 | virtual int GetRtpSendTimeExtnId() const { |
| 560 | return -1; |
| 561 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 562 | // Sets the maximum allowed bandwidth to use when sending data. |
| 563 | virtual bool SetMaxSendBandwidth(int bps) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 564 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 565 | // Base method to send packet using NetworkInterface. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 566 | bool SendPacket(rtc::Buffer* packet) { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 567 | return DoSendPacket(packet, false); |
| 568 | } |
| 569 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 570 | bool SendRtcp(rtc::Buffer* packet) { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 571 | return DoSendPacket(packet, true); |
| 572 | } |
| 573 | |
| 574 | int SetOption(NetworkInterface::SocketType type, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 575 | rtc::Socket::Option opt, |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 576 | int option) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 577 | rtc::CritScope cs(&network_interface_crit_); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 578 | if (!network_interface_) |
| 579 | return -1; |
| 580 | |
| 581 | return network_interface_->SetOption(type, opt, option); |
| 582 | } |
| 583 | |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 584 | protected: |
| 585 | // This method sets DSCP |value| on both RTP and RTCP channels. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 586 | int SetDscp(rtc::DiffServCodePoint value) { |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 587 | int ret; |
| 588 | ret = SetOption(NetworkInterface::ST_RTP, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 589 | rtc::Socket::OPT_DSCP, |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 590 | value); |
| 591 | if (ret == 0) { |
| 592 | ret = SetOption(NetworkInterface::ST_RTCP, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 593 | rtc::Socket::OPT_DSCP, |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 594 | value); |
| 595 | } |
| 596 | return ret; |
| 597 | } |
| 598 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 599 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 600 | bool DoSendPacket(rtc::Buffer* packet, bool rtcp) { |
| 601 | rtc::CritScope cs(&network_interface_crit_); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 602 | if (!network_interface_) |
| 603 | return false; |
| 604 | |
| 605 | return (!rtcp) ? network_interface_->SendPacket(packet) : |
| 606 | network_interface_->SendRtcp(packet); |
| 607 | } |
| 608 | |
| 609 | // |network_interface_| can be accessed from the worker_thread and |
| 610 | // from any MediaEngine threads. This critical section is to protect accessing |
| 611 | // of network_interface_ object. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 612 | rtc::CriticalSection network_interface_crit_; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 613 | NetworkInterface* network_interface_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 614 | }; |
| 615 | |
| 616 | enum SendFlags { |
| 617 | SEND_NOTHING, |
| 618 | SEND_RINGBACKTONE, |
| 619 | SEND_MICROPHONE |
| 620 | }; |
| 621 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 622 | // The stats information is structured as follows: |
| 623 | // Media are represented by either MediaSenderInfo or MediaReceiverInfo. |
| 624 | // Media contains a vector of SSRC infos that are exclusively used by this |
| 625 | // media. (SSRCs shared between media streams can't be represented.) |
| 626 | |
| 627 | // Information about an SSRC. |
| 628 | // This data may be locally recorded, or received in an RTCP SR or RR. |
| 629 | struct SsrcSenderInfo { |
| 630 | SsrcSenderInfo() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 631 | : ssrc(0), |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 632 | timestamp(0) { |
| 633 | } |
| 634 | uint32 ssrc; |
| 635 | double timestamp; // NTP timestamp, represented as seconds since epoch. |
| 636 | }; |
| 637 | |
| 638 | struct SsrcReceiverInfo { |
| 639 | SsrcReceiverInfo() |
| 640 | : ssrc(0), |
| 641 | timestamp(0) { |
| 642 | } |
| 643 | uint32 ssrc; |
| 644 | double timestamp; |
| 645 | }; |
| 646 | |
| 647 | struct MediaSenderInfo { |
| 648 | MediaSenderInfo() |
| 649 | : bytes_sent(0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 650 | packets_sent(0), |
| 651 | packets_lost(0), |
| 652 | fraction_lost(0.0), |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 653 | rtt_ms(0) { |
| 654 | } |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 655 | void add_ssrc(const SsrcSenderInfo& stat) { |
| 656 | local_stats.push_back(stat); |
| 657 | } |
| 658 | // Temporary utility function for call sites that only provide SSRC. |
| 659 | // As more info is added into SsrcSenderInfo, this function should go away. |
| 660 | void add_ssrc(uint32 ssrc) { |
| 661 | SsrcSenderInfo stat; |
| 662 | stat.ssrc = ssrc; |
| 663 | add_ssrc(stat); |
| 664 | } |
| 665 | // Utility accessor for clients that are only interested in ssrc numbers. |
| 666 | std::vector<uint32> ssrcs() const { |
| 667 | std::vector<uint32> retval; |
| 668 | for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin(); |
| 669 | it != local_stats.end(); ++it) { |
| 670 | retval.push_back(it->ssrc); |
| 671 | } |
| 672 | return retval; |
| 673 | } |
| 674 | // Utility accessor for clients that make the assumption only one ssrc |
| 675 | // exists per media. |
| 676 | // This will eventually go away. |
| 677 | uint32 ssrc() const { |
| 678 | if (local_stats.size() > 0) { |
| 679 | return local_stats[0].ssrc; |
| 680 | } else { |
| 681 | return 0; |
| 682 | } |
| 683 | } |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 684 | int64 bytes_sent; |
| 685 | int packets_sent; |
| 686 | int packets_lost; |
| 687 | float fraction_lost; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 688 | int64_t rtt_ms; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 689 | std::string codec_name; |
| 690 | std::vector<SsrcSenderInfo> local_stats; |
| 691 | std::vector<SsrcReceiverInfo> remote_stats; |
| 692 | }; |
| 693 | |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 694 | template<class T> |
| 695 | struct VariableInfo { |
| 696 | VariableInfo() |
| 697 | : min_val(), |
| 698 | mean(0.0), |
| 699 | max_val(), |
| 700 | variance(0.0) { |
| 701 | } |
| 702 | T min_val; |
| 703 | double mean; |
| 704 | T max_val; |
| 705 | double variance; |
| 706 | }; |
| 707 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 708 | struct MediaReceiverInfo { |
| 709 | MediaReceiverInfo() |
| 710 | : bytes_rcvd(0), |
| 711 | packets_rcvd(0), |
| 712 | packets_lost(0), |
| 713 | fraction_lost(0.0) { |
| 714 | } |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 715 | void add_ssrc(const SsrcReceiverInfo& stat) { |
| 716 | local_stats.push_back(stat); |
| 717 | } |
| 718 | // Temporary utility function for call sites that only provide SSRC. |
| 719 | // As more info is added into SsrcSenderInfo, this function should go away. |
| 720 | void add_ssrc(uint32 ssrc) { |
| 721 | SsrcReceiverInfo stat; |
| 722 | stat.ssrc = ssrc; |
| 723 | add_ssrc(stat); |
| 724 | } |
| 725 | std::vector<uint32> ssrcs() const { |
| 726 | std::vector<uint32> retval; |
| 727 | for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin(); |
| 728 | it != local_stats.end(); ++it) { |
| 729 | retval.push_back(it->ssrc); |
| 730 | } |
| 731 | return retval; |
| 732 | } |
| 733 | // Utility accessor for clients that make the assumption only one ssrc |
| 734 | // exists per media. |
| 735 | // This will eventually go away. |
| 736 | uint32 ssrc() const { |
| 737 | if (local_stats.size() > 0) { |
| 738 | return local_stats[0].ssrc; |
| 739 | } else { |
| 740 | return 0; |
| 741 | } |
| 742 | } |
| 743 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 744 | int64 bytes_rcvd; |
| 745 | int packets_rcvd; |
| 746 | int packets_lost; |
| 747 | float fraction_lost; |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 748 | std::string codec_name; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 749 | std::vector<SsrcReceiverInfo> local_stats; |
| 750 | std::vector<SsrcSenderInfo> remote_stats; |
| 751 | }; |
| 752 | |
| 753 | struct VoiceSenderInfo : public MediaSenderInfo { |
| 754 | VoiceSenderInfo() |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 755 | : ext_seqnum(0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 756 | jitter_ms(0), |
| 757 | audio_level(0), |
| 758 | aec_quality_min(0.0), |
| 759 | echo_delay_median_ms(0), |
| 760 | echo_delay_std_ms(0), |
| 761 | echo_return_loss(0), |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 762 | echo_return_loss_enhancement(0), |
| 763 | typing_noise_detected(false) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 764 | } |
| 765 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 766 | int ext_seqnum; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 767 | int jitter_ms; |
| 768 | int audio_level; |
| 769 | float aec_quality_min; |
| 770 | int echo_delay_median_ms; |
| 771 | int echo_delay_std_ms; |
| 772 | int echo_return_loss; |
| 773 | int echo_return_loss_enhancement; |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 774 | bool typing_noise_detected; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 775 | }; |
| 776 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 777 | struct VoiceReceiverInfo : public MediaReceiverInfo { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 778 | VoiceReceiverInfo() |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 779 | : ext_seqnum(0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 780 | jitter_ms(0), |
| 781 | jitter_buffer_ms(0), |
| 782 | jitter_buffer_preferred_ms(0), |
| 783 | delay_estimate_ms(0), |
| 784 | audio_level(0), |
henrike@webrtc.org | b8c254a | 2014-02-14 23:38:45 +0000 | [diff] [blame] | 785 | expand_rate(0), |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 786 | speech_expand_rate(0), |
| 787 | secondary_decoded_rate(0), |
henrike@webrtc.org | b8c254a | 2014-02-14 23:38:45 +0000 | [diff] [blame] | 788 | decoding_calls_to_silence_generator(0), |
| 789 | decoding_calls_to_neteq(0), |
| 790 | decoding_normal(0), |
| 791 | decoding_plc(0), |
| 792 | decoding_cng(0), |
buildbot@webrtc.org | b525a9d | 2014-06-03 09:42:15 +0000 | [diff] [blame] | 793 | decoding_plc_cng(0), |
| 794 | capture_start_ntp_time_ms(-1) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 795 | } |
| 796 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 797 | int ext_seqnum; |
| 798 | int jitter_ms; |
| 799 | int jitter_buffer_ms; |
| 800 | int jitter_buffer_preferred_ms; |
| 801 | int delay_estimate_ms; |
| 802 | int audio_level; |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 803 | // fraction of synthesized audio inserted through expansion. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 804 | float expand_rate; |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 805 | // fraction of synthesized speech inserted through expansion. |
| 806 | float speech_expand_rate; |
| 807 | // fraction of data out of secondary decoding, including FEC and RED. |
| 808 | float secondary_decoded_rate; |
henrike@webrtc.org | b8c254a | 2014-02-14 23:38:45 +0000 | [diff] [blame] | 809 | int decoding_calls_to_silence_generator; |
| 810 | int decoding_calls_to_neteq; |
| 811 | int decoding_normal; |
| 812 | int decoding_plc; |
| 813 | int decoding_cng; |
| 814 | int decoding_plc_cng; |
buildbot@webrtc.org | b525a9d | 2014-06-03 09:42:15 +0000 | [diff] [blame] | 815 | // Estimated capture start time in NTP time in ms. |
| 816 | int64 capture_start_ntp_time_ms; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 817 | }; |
| 818 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 819 | struct VideoSenderInfo : public MediaSenderInfo { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 820 | VideoSenderInfo() |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 821 | : packets_cached(0), |
| 822 | firs_rcvd(0), |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 823 | plis_rcvd(0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 824 | nacks_rcvd(0), |
wu@webrtc.org | 987f2c9 | 2014-03-28 16:22:19 +0000 | [diff] [blame] | 825 | input_frame_width(0), |
| 826 | input_frame_height(0), |
| 827 | send_frame_width(0), |
| 828 | send_frame_height(0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 829 | framerate_input(0), |
| 830 | framerate_sent(0), |
| 831 | nominal_bitrate(0), |
| 832 | preferred_bitrate(0), |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 833 | adapt_reason(0), |
buildbot@webrtc.org | 71dffb7 | 2014-06-24 07:24:49 +0000 | [diff] [blame] | 834 | adapt_changes(0), |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 835 | avg_encode_ms(0), |
Peter Boström | 8ed6a4b | 2015-03-27 10:01:02 +0100 | [diff] [blame^] | 836 | encode_usage_percent(0) { |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 837 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 838 | |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 839 | std::vector<SsrcGroup> ssrc_groups; |
| 840 | int packets_cached; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 841 | int firs_rcvd; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 842 | int plis_rcvd; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 843 | int nacks_rcvd; |
wu@webrtc.org | 987f2c9 | 2014-03-28 16:22:19 +0000 | [diff] [blame] | 844 | int input_frame_width; |
| 845 | int input_frame_height; |
| 846 | int send_frame_width; |
| 847 | int send_frame_height; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 848 | int framerate_input; |
| 849 | int framerate_sent; |
| 850 | int nominal_bitrate; |
| 851 | int preferred_bitrate; |
| 852 | int adapt_reason; |
buildbot@webrtc.org | 71dffb7 | 2014-06-24 07:24:49 +0000 | [diff] [blame] | 853 | int adapt_changes; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 854 | int avg_encode_ms; |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 855 | int encode_usage_percent; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 856 | VariableInfo<int> adapt_frame_drops; |
| 857 | VariableInfo<int> effects_frame_drops; |
| 858 | VariableInfo<double> capturer_frame_time; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 859 | }; |
| 860 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 861 | struct VideoReceiverInfo : public MediaReceiverInfo { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 862 | VideoReceiverInfo() |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 863 | : packets_concealed(0), |
| 864 | firs_sent(0), |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 865 | plis_sent(0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 866 | nacks_sent(0), |
| 867 | frame_width(0), |
| 868 | frame_height(0), |
| 869 | framerate_rcvd(0), |
| 870 | framerate_decoded(0), |
| 871 | framerate_output(0), |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 872 | framerate_render_input(0), |
| 873 | framerate_render_output(0), |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 874 | decode_ms(0), |
| 875 | max_decode_ms(0), |
| 876 | jitter_buffer_ms(0), |
| 877 | min_playout_delay_ms(0), |
| 878 | render_delay_ms(0), |
| 879 | target_delay_ms(0), |
buildbot@webrtc.org | 0581f0b | 2014-05-06 21:36:31 +0000 | [diff] [blame] | 880 | current_delay_ms(0), |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 881 | capture_start_ntp_time_ms(-1) { |
| 882 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 883 | |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 884 | std::vector<SsrcGroup> ssrc_groups; |
| 885 | int packets_concealed; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 886 | int firs_sent; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 887 | int plis_sent; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 888 | int nacks_sent; |
| 889 | int frame_width; |
| 890 | int frame_height; |
| 891 | int framerate_rcvd; |
| 892 | int framerate_decoded; |
| 893 | int framerate_output; |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 894 | // Framerate as sent to the renderer. |
| 895 | int framerate_render_input; |
| 896 | // Framerate that the renderer reports. |
| 897 | int framerate_render_output; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 898 | |
| 899 | // All stats below are gathered per-VideoReceiver, but some will be correlated |
| 900 | // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC |
| 901 | // structures, reflect this in the new layout. |
| 902 | |
| 903 | // Current frame decode latency. |
| 904 | int decode_ms; |
| 905 | // Maximum observed frame decode latency. |
| 906 | int max_decode_ms; |
| 907 | // Jitter (network-related) latency. |
| 908 | int jitter_buffer_ms; |
| 909 | // Requested minimum playout latency. |
| 910 | int min_playout_delay_ms; |
| 911 | // Requested latency to account for rendering delay. |
| 912 | int render_delay_ms; |
| 913 | // Target overall delay: network+decode+render, accounting for |
| 914 | // min_playout_delay_ms. |
| 915 | int target_delay_ms; |
| 916 | // Current overall delay, possibly ramping towards target_delay_ms. |
| 917 | int current_delay_ms; |
buildbot@webrtc.org | 0581f0b | 2014-05-06 21:36:31 +0000 | [diff] [blame] | 918 | |
| 919 | // Estimated capture start time in NTP time in ms. |
| 920 | int64 capture_start_ntp_time_ms; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 921 | }; |
| 922 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 923 | struct DataSenderInfo : public MediaSenderInfo { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 924 | DataSenderInfo() |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 925 | : ssrc(0) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | uint32 ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 929 | }; |
| 930 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 931 | struct DataReceiverInfo : public MediaReceiverInfo { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 932 | DataReceiverInfo() |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 933 | : ssrc(0) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | uint32 ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 937 | }; |
| 938 | |
| 939 | struct BandwidthEstimationInfo { |
| 940 | BandwidthEstimationInfo() |
| 941 | : available_send_bandwidth(0), |
| 942 | available_recv_bandwidth(0), |
| 943 | target_enc_bitrate(0), |
| 944 | actual_enc_bitrate(0), |
| 945 | retransmit_bitrate(0), |
| 946 | transmit_bitrate(0), |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 947 | bucket_delay(0) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | int available_send_bandwidth; |
| 951 | int available_recv_bandwidth; |
| 952 | int target_enc_bitrate; |
| 953 | int actual_enc_bitrate; |
| 954 | int retransmit_bitrate; |
| 955 | int transmit_bitrate; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 956 | int64_t bucket_delay; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 957 | }; |
| 958 | |
| 959 | struct VoiceMediaInfo { |
| 960 | void Clear() { |
| 961 | senders.clear(); |
| 962 | receivers.clear(); |
| 963 | } |
| 964 | std::vector<VoiceSenderInfo> senders; |
| 965 | std::vector<VoiceReceiverInfo> receivers; |
| 966 | }; |
| 967 | |
| 968 | struct VideoMediaInfo { |
| 969 | void Clear() { |
| 970 | senders.clear(); |
| 971 | receivers.clear(); |
| 972 | bw_estimations.clear(); |
| 973 | } |
| 974 | std::vector<VideoSenderInfo> senders; |
| 975 | std::vector<VideoReceiverInfo> receivers; |
| 976 | std::vector<BandwidthEstimationInfo> bw_estimations; |
| 977 | }; |
| 978 | |
| 979 | struct DataMediaInfo { |
| 980 | void Clear() { |
| 981 | senders.clear(); |
| 982 | receivers.clear(); |
| 983 | } |
| 984 | std::vector<DataSenderInfo> senders; |
| 985 | std::vector<DataReceiverInfo> receivers; |
| 986 | }; |
| 987 | |
| 988 | class VoiceMediaChannel : public MediaChannel { |
| 989 | public: |
| 990 | enum Error { |
| 991 | ERROR_NONE = 0, // No error. |
| 992 | ERROR_OTHER, // Other errors. |
| 993 | ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic. |
| 994 | ERROR_REC_DEVICE_MUTED, // Mic was muted by OS. |
| 995 | ERROR_REC_DEVICE_SILENT, // No background noise picked up. |
| 996 | ERROR_REC_DEVICE_SATURATION, // Mic input is clipping. |
| 997 | ERROR_REC_DEVICE_REMOVED, // Mic was removed while active. |
| 998 | ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors. |
| 999 | ERROR_REC_SRTP_ERROR, // Generic SRTP failure. |
| 1000 | ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets. |
| 1001 | ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected. |
| 1002 | ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout. |
| 1003 | ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS. |
| 1004 | ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active. |
| 1005 | ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing. |
| 1006 | ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure. |
| 1007 | ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets. |
| 1008 | ERROR_PLAY_SRTP_REPLAY, // Packet replay detected. |
| 1009 | }; |
| 1010 | |
| 1011 | VoiceMediaChannel() {} |
| 1012 | virtual ~VoiceMediaChannel() {} |
| 1013 | // Sets the codecs/payload types to be used for incoming media. |
| 1014 | virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) = 0; |
| 1015 | // Sets the codecs/payload types to be used for outgoing media. |
| 1016 | virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) = 0; |
| 1017 | // Starts or stops playout of received audio. |
| 1018 | virtual bool SetPlayout(bool playout) = 0; |
| 1019 | // Starts or stops sending (and potentially capture) of local audio. |
| 1020 | virtual bool SetSend(SendFlags flag) = 0; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 1021 | // Sets the renderer object to be used for the specified remote audio stream. |
| 1022 | virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) = 0; |
| 1023 | // Sets the renderer object to be used for the specified local audio stream. |
| 1024 | virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1025 | // Gets current energy levels for all incoming streams. |
| 1026 | virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0; |
| 1027 | // Get the current energy level of the stream sent to the speaker. |
| 1028 | virtual int GetOutputLevel() = 0; |
| 1029 | // Get the time in milliseconds since last recorded keystroke, or negative. |
| 1030 | virtual int GetTimeSinceLastTyping() = 0; |
| 1031 | // Temporarily exposed field for tuning typing detect options. |
| 1032 | virtual void SetTypingDetectionParameters(int time_window, |
| 1033 | int cost_per_typing, int reporting_threshold, int penalty_decay, |
| 1034 | int type_event_delay) = 0; |
| 1035 | // Set left and right scale for speaker output volume of the specified ssrc. |
| 1036 | virtual bool SetOutputScaling(uint32 ssrc, double left, double right) = 0; |
| 1037 | // Get left and right scale for speaker output volume of the specified ssrc. |
| 1038 | virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) = 0; |
| 1039 | // Specifies a ringback tone to be played during call setup. |
| 1040 | virtual bool SetRingbackTone(const char *buf, int len) = 0; |
| 1041 | // Plays or stops the aforementioned ringback tone |
| 1042 | virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) = 0; |
| 1043 | // Returns if the telephone-event has been negotiated. |
| 1044 | virtual bool CanInsertDtmf() { return false; } |
| 1045 | // Send and/or play a DTMF |event| according to the |flags|. |
| 1046 | // The DTMF out-of-band signal will be used on sending. |
| 1047 | // The |ssrc| should be either 0 or a valid send stream ssrc. |
henrike@webrtc.org | 9de257d | 2013-07-17 14:42:53 +0000 | [diff] [blame] | 1048 | // The valid value for the |event| are 0 to 15 which corresponding to |
| 1049 | // DTMF event 0-9, *, #, A-D. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1050 | virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) = 0; |
| 1051 | // Gets quality stats for the channel. |
| 1052 | virtual bool GetStats(VoiceMediaInfo* info) = 0; |
| 1053 | // Gets last reported error for this media channel. |
| 1054 | virtual void GetLastMediaError(uint32* ssrc, |
| 1055 | VoiceMediaChannel::Error* error) { |
| 1056 | ASSERT(error != NULL); |
| 1057 | *error = ERROR_NONE; |
| 1058 | } |
| 1059 | // Sets the media options to use. |
| 1060 | virtual bool SetOptions(const AudioOptions& options) = 0; |
| 1061 | virtual bool GetOptions(AudioOptions* options) const = 0; |
| 1062 | |
| 1063 | // Signal errors from MediaChannel. Arguments are: |
| 1064 | // ssrc(uint32), and error(VoiceMediaChannel::Error). |
| 1065 | sigslot::signal2<uint32, VoiceMediaChannel::Error> SignalMediaError; |
| 1066 | }; |
| 1067 | |
| 1068 | class VideoMediaChannel : public MediaChannel { |
| 1069 | public: |
| 1070 | enum Error { |
| 1071 | ERROR_NONE = 0, // No error. |
| 1072 | ERROR_OTHER, // Other errors. |
| 1073 | ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera. |
| 1074 | ERROR_REC_DEVICE_NO_DEVICE, // No camera. |
| 1075 | ERROR_REC_DEVICE_IN_USE, // Device is in already use. |
| 1076 | ERROR_REC_DEVICE_REMOVED, // Device is removed. |
| 1077 | ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure. |
| 1078 | ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets. |
| 1079 | ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore. |
| 1080 | ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure. |
| 1081 | ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets. |
| 1082 | ERROR_PLAY_SRTP_REPLAY, // Packet replay detected. |
| 1083 | }; |
| 1084 | |
| 1085 | VideoMediaChannel() : renderer_(NULL) {} |
| 1086 | virtual ~VideoMediaChannel() {} |
| 1087 | // Sets the codecs/payload types to be used for incoming media. |
| 1088 | virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) = 0; |
| 1089 | // Sets the codecs/payload types to be used for outgoing media. |
| 1090 | virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) = 0; |
| 1091 | // Gets the currently set codecs/payload types to be used for outgoing media. |
| 1092 | virtual bool GetSendCodec(VideoCodec* send_codec) = 0; |
| 1093 | // Sets the format of a specified outgoing stream. |
| 1094 | virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) = 0; |
| 1095 | // Starts or stops playout of received video. |
| 1096 | virtual bool SetRender(bool render) = 0; |
| 1097 | // Starts or stops transmission (and potentially capture) of local video. |
| 1098 | virtual bool SetSend(bool send) = 0; |
| 1099 | // Sets the renderer object to be used for the specified stream. |
| 1100 | // If SSRC is 0, the renderer is used for the 'default' stream. |
| 1101 | virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) = 0; |
| 1102 | // If |ssrc| is 0, replace the default capturer (engine capturer) with |
| 1103 | // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC. |
| 1104 | virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) = 0; |
| 1105 | // Gets quality stats for the channel. |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 1106 | virtual bool GetStats(VideoMediaInfo* info) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1107 | // Send an intra frame to the receivers. |
| 1108 | virtual bool SendIntraFrame() = 0; |
| 1109 | // Reuqest each of the remote senders to send an intra frame. |
| 1110 | virtual bool RequestIntraFrame() = 0; |
| 1111 | // Sets the media options to use. |
| 1112 | virtual bool SetOptions(const VideoOptions& options) = 0; |
| 1113 | virtual bool GetOptions(VideoOptions* options) const = 0; |
| 1114 | virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0; |
| 1115 | |
| 1116 | // Signal errors from MediaChannel. Arguments are: |
| 1117 | // ssrc(uint32), and error(VideoMediaChannel::Error). |
| 1118 | sigslot::signal2<uint32, Error> SignalMediaError; |
| 1119 | |
| 1120 | protected: |
| 1121 | VideoRenderer *renderer_; |
| 1122 | }; |
| 1123 | |
| 1124 | enum DataMessageType { |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 1125 | // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID |
| 1126 | // values. |
| 1127 | DMT_NONE = 0, |
| 1128 | DMT_CONTROL = 1, |
| 1129 | DMT_BINARY = 2, |
| 1130 | DMT_TEXT = 3, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1131 | }; |
| 1132 | |
| 1133 | // Info about data received in DataMediaChannel. For use in |
| 1134 | // DataMediaChannel::SignalDataReceived and in all of the signals that |
| 1135 | // signal fires, on up the chain. |
| 1136 | struct ReceiveDataParams { |
| 1137 | // The in-packet stream indentifier. |
| 1138 | // For SCTP, this is really SID, not SSRC. |
| 1139 | uint32 ssrc; |
| 1140 | // The type of message (binary, text, or control). |
| 1141 | DataMessageType type; |
| 1142 | // A per-stream value incremented per packet in the stream. |
| 1143 | int seq_num; |
| 1144 | // A per-stream value monotonically increasing with time. |
| 1145 | int timestamp; |
| 1146 | |
| 1147 | ReceiveDataParams() : |
| 1148 | ssrc(0), |
| 1149 | type(DMT_TEXT), |
| 1150 | seq_num(0), |
| 1151 | timestamp(0) { |
| 1152 | } |
| 1153 | }; |
| 1154 | |
| 1155 | struct SendDataParams { |
| 1156 | // The in-packet stream indentifier. |
| 1157 | // For SCTP, this is really SID, not SSRC. |
| 1158 | uint32 ssrc; |
| 1159 | // The type of message (binary, text, or control). |
| 1160 | DataMessageType type; |
| 1161 | |
| 1162 | // For SCTP, whether to send messages flagged as ordered or not. |
| 1163 | // If false, messages can be received out of order. |
| 1164 | bool ordered; |
| 1165 | // For SCTP, whether the messages are sent reliably or not. |
| 1166 | // If false, messages may be lost. |
| 1167 | bool reliable; |
| 1168 | // For SCTP, if reliable == false, provide partial reliability by |
| 1169 | // resending up to this many times. Either count or millis |
| 1170 | // is supported, not both at the same time. |
| 1171 | int max_rtx_count; |
| 1172 | // For SCTP, if reliable == false, provide partial reliability by |
| 1173 | // resending for up to this many milliseconds. Either count or millis |
| 1174 | // is supported, not both at the same time. |
| 1175 | int max_rtx_ms; |
| 1176 | |
| 1177 | SendDataParams() : |
| 1178 | ssrc(0), |
| 1179 | type(DMT_TEXT), |
| 1180 | // TODO(pthatcher): Make these true by default? |
| 1181 | ordered(false), |
| 1182 | reliable(false), |
| 1183 | max_rtx_count(0), |
| 1184 | max_rtx_ms(0) { |
| 1185 | } |
| 1186 | }; |
| 1187 | |
| 1188 | enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK }; |
| 1189 | |
| 1190 | class DataMediaChannel : public MediaChannel { |
| 1191 | public: |
| 1192 | enum Error { |
| 1193 | ERROR_NONE = 0, // No error. |
| 1194 | ERROR_OTHER, // Other errors. |
| 1195 | ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure. |
| 1196 | ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets. |
| 1197 | ERROR_RECV_SRTP_ERROR, // Generic SRTP failure. |
| 1198 | ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets. |
| 1199 | ERROR_RECV_SRTP_REPLAY, // Packet replay detected. |
| 1200 | }; |
| 1201 | |
| 1202 | virtual ~DataMediaChannel() {} |
| 1203 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1204 | virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) = 0; |
| 1205 | virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) = 0; |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 1206 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1207 | virtual bool MuteStream(uint32 ssrc, bool on) { return false; } |
| 1208 | // TODO(pthatcher): Implement this. |
| 1209 | virtual bool GetStats(DataMediaInfo* info) { return true; } |
| 1210 | |
| 1211 | virtual bool SetSend(bool send) = 0; |
| 1212 | virtual bool SetReceive(bool receive) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1213 | |
| 1214 | virtual bool SendData( |
| 1215 | const SendDataParams& params, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1216 | const rtc::Buffer& payload, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1217 | SendDataResult* result = NULL) = 0; |
| 1218 | // Signals when data is received (params, data, len) |
| 1219 | sigslot::signal3<const ReceiveDataParams&, |
| 1220 | const char*, |
| 1221 | size_t> SignalDataReceived; |
| 1222 | // Signal errors from MediaChannel. Arguments are: |
| 1223 | // ssrc(uint32), and error(DataMediaChannel::Error). |
| 1224 | sigslot::signal2<uint32, DataMediaChannel::Error> SignalMediaError; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 1225 | // Signal when the media channel is ready to send the stream. Arguments are: |
| 1226 | // writable(bool) |
| 1227 | sigslot::signal1<bool> SignalReadyToSend; |
buildbot@webrtc.org | 1d66be2 | 2014-05-29 22:54:24 +0000 | [diff] [blame] | 1228 | // Signal for notifying that the remote side has closed the DataChannel. |
| 1229 | sigslot::signal1<uint32> SignalStreamClosedRemotely; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1230 | }; |
| 1231 | |
| 1232 | } // namespace cricket |
| 1233 | |
| 1234 | #endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_ |