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