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