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