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