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