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