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