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