blob: 0a59019256e5541295f52bc5e8ec35225d725272 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
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.orga09a9992014-08-13 17:26:08 +000034#include "talk/media/base/codec.h"
35#include "talk/media/base/constants.h"
36#include "talk/media/base/streamparams.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000037#include "webrtc/base/basictypes.h"
38#include "webrtc/base/buffer.h"
39#include "webrtc/base/dscp.h"
40#include "webrtc/base/logging.h"
Karl Wibergbe579832015-11-10 22:34:18 +010041#include "webrtc/base/optional.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000042#include "webrtc/base/sigslot.h"
43#include "webrtc/base/socket.h"
44#include "webrtc/base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045// TODO(juberti): re-evaluate this include
46#include "talk/session/media/audiomonitor.h"
47
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000048namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049class Buffer;
50class RateLimiter;
51class Timing;
52}
53
Tommif888bb52015-12-12 01:37:01 +010054namespace webrtc {
55class AudioSinkInterface;
56}
57
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058namespace cricket {
59
tommi1d5c19d2015-12-13 22:54:29 -080060class AudioRenderer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061class ScreencastId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062class VideoCapturer;
63class VideoRenderer;
tommi1d5c19d2015-12-13 22:54:29 -080064struct RtpHeader;
65struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066
67const int kMinRtpHeaderExtensionId = 1;
68const int kMaxRtpHeaderExtensionId = 255;
69const int kScreencastDefaultFps = 5;
70
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071template <class T>
Karl Wibergbe579832015-11-10 22:34:18 +010072static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070074 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075 str = key;
76 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070077 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 str += ", ";
79 }
80 return str;
81}
82
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070083template <class T>
84static 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.org28e20752013-07-10 00:45:36 +000097// 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.
101struct AudioOptions {
102 void SetAll(const AudioOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700103 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.org28e20752013-07-10 00:45:36 +0000129 }
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 Lundin64dad832015-05-11 12:44:23 +0200137 audio_jitter_buffer_max_packets == o.audio_jitter_buffer_max_packets &&
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200138 audio_jitter_buffer_fast_accelerate ==
139 o.audio_jitter_buffer_fast_accelerate &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000141 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 conference_mode == o.conference_mode &&
143 experimental_agc == o.experimental_agc &&
Henrik Lundin441f6342015-06-09 16:03:13 +0200144 extended_filter_aec == o.extended_filter_aec &&
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100145 delay_agnostic_aec == o.delay_agnostic_aec &&
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000146 experimental_ns == o.experimental_ns &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000148 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.org97077a32013-10-25 21:18:33 +0000152 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000153 playout_sample_rate == o.playout_sample_rate &&
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000154 dscp == o.dscp &&
155 combined_audio_video_bwe == o.combined_audio_video_bwe;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 }
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 Lundin64dad832015-05-11 12:44:23 +0200166 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
167 audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200168 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
169 audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000171 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 ost << ToStringIfSet("conference", conference_mode);
173 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
174 ost << ToStringIfSet("experimental_agc", experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200175 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100176 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000177 ost << ToStringIfSet("experimental_ns", experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 ost << ToStringIfSet("aec_dump", aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000179 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.org97077a32013-10-25 21:18:33 +0000183 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
184 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000185 ost << ToStringIfSet("dscp", dscp);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000186 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 ost << "}";
188 return ost.str();
189 }
190
191 // Audio processing that attempts to filter away the output signal from
192 // later inbound pickup.
Karl Wibergbe579832015-11-10 22:34:18 +0100193 rtc::Optional<bool> echo_cancellation;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 // Audio processing to adjust the sensitivity of the local mic dynamically.
Karl Wibergbe579832015-11-10 22:34:18 +0100195 rtc::Optional<bool> auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 // Audio processing to filter out background noise.
Karl Wibergbe579832015-11-10 22:34:18 +0100197 rtc::Optional<bool> noise_suppression;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 // Audio processing to remove background noise of lower frequencies.
Karl Wibergbe579832015-11-10 22:34:18 +0100199 rtc::Optional<bool> highpass_filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 // Audio processing to swap the left and right channels.
Karl Wibergbe579832015-11-10 22:34:18 +0100201 rtc::Optional<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200202 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Karl Wibergbe579832015-11-10 22:34:18 +0100203 rtc::Optional<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200204 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Karl Wibergbe579832015-11-10 22:34:18 +0100205 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 // Audio processing to detect typing.
Karl Wibergbe579832015-11-10 22:34:18 +0100207 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.org97077a32013-10-25 21:18:33 +0000216 // Note that tx_agc_* only applies to non-experimental AGC.
Karl Wibergbe579832015-11-10 22:34:18 +0100217 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.orgde305012013-10-31 15:40:38 +0000222 // Set DSCP value for packet sent from audio channel.
Karl Wibergbe579832015-11-10 22:34:18 +0100223 rtc::Optional<bool> dscp;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000224 // Enable combined audio+bandwidth BWE.
Karl Wibergbe579832015-11-10 22:34:18 +0100225 rtc::Optional<bool> combined_audio_video_bwe;
kwiberg102c6a62015-10-30 02:47:38 -0700226
227 private:
228 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100229 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700230 if (o) {
231 *s = o;
232 }
233 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234};
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.
240struct VideoOptions {
kwiberg102c6a62015-10-30 02:47:38 -0700241 VideoOptions()
242 : process_adaptation_threshhold(kProcessCpuThreshold),
243 system_low_adaptation_threshhold(kLowSystemCpuThreshold),
244 system_high_adaptation_threshhold(kHighSystemCpuThreshold),
245 unsignalled_recv_stream_limit(kNumDefaultUnsignalledVideoRecvStreams) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246
247 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700248 SetFrom(&adapt_input_to_cpu_usage, change.adapt_input_to_cpu_usage);
249 SetFrom(&adapt_cpu_with_smoothing, change.adapt_cpu_with_smoothing);
250 SetFrom(&video_adapt_third, change.video_adapt_third);
251 SetFrom(&video_noise_reduction, change.video_noise_reduction);
252 SetFrom(&video_start_bitrate, change.video_start_bitrate);
253 SetFrom(&cpu_overuse_detection, change.cpu_overuse_detection);
254 SetFrom(&cpu_underuse_threshold, change.cpu_underuse_threshold);
255 SetFrom(&cpu_overuse_threshold, change.cpu_overuse_threshold);
256 SetFrom(&cpu_underuse_encode_rsd_threshold,
257 change.cpu_underuse_encode_rsd_threshold);
258 SetFrom(&cpu_overuse_encode_rsd_threshold,
259 change.cpu_overuse_encode_rsd_threshold);
260 SetFrom(&cpu_overuse_encode_usage, change.cpu_overuse_encode_usage);
261 SetFrom(&conference_mode, change.conference_mode);
262 SetFrom(&process_adaptation_threshhold,
263 change.process_adaptation_threshhold);
264 SetFrom(&system_low_adaptation_threshhold,
265 change.system_low_adaptation_threshhold);
266 SetFrom(&system_high_adaptation_threshhold,
267 change.system_high_adaptation_threshhold);
268 SetFrom(&dscp, change.dscp);
269 SetFrom(&suspend_below_min_bitrate, change.suspend_below_min_bitrate);
270 SetFrom(&unsignalled_recv_stream_limit,
271 change.unsignalled_recv_stream_limit);
272 SetFrom(&use_simulcast_adapter, change.use_simulcast_adapter);
273 SetFrom(&screencast_min_bitrate, change.screencast_min_bitrate);
qiangchen444682a2015-11-24 18:07:56 -0800274 SetFrom(&disable_prerenderer_smoothing,
275 change.disable_prerenderer_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276 }
277
278 bool operator==(const VideoOptions& o) const {
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000279 return adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
280 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
281 video_adapt_third == o.video_adapt_third &&
282 video_noise_reduction == o.video_noise_reduction &&
283 video_start_bitrate == o.video_start_bitrate &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000284 cpu_overuse_detection == o.cpu_overuse_detection &&
285 cpu_underuse_threshold == o.cpu_underuse_threshold &&
286 cpu_overuse_threshold == o.cpu_overuse_threshold &&
287 cpu_underuse_encode_rsd_threshold ==
288 o.cpu_underuse_encode_rsd_threshold &&
289 cpu_overuse_encode_rsd_threshold ==
290 o.cpu_overuse_encode_rsd_threshold &&
291 cpu_overuse_encode_usage == o.cpu_overuse_encode_usage &&
292 conference_mode == o.conference_mode &&
293 process_adaptation_threshhold == o.process_adaptation_threshhold &&
294 system_low_adaptation_threshhold ==
295 o.system_low_adaptation_threshhold &&
296 system_high_adaptation_threshhold ==
297 o.system_high_adaptation_threshhold &&
Peter Thatchera9b4c322015-07-16 03:47:28 -0700298 dscp == o.dscp &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000299 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
300 unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit &&
301 use_simulcast_adapter == o.use_simulcast_adapter &&
qiangchen444682a2015-11-24 18:07:56 -0800302 screencast_min_bitrate == o.screencast_min_bitrate &&
303 disable_prerenderer_smoothing == o.disable_prerenderer_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 }
305
306 std::string ToString() const {
307 std::ostringstream ost;
308 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000310 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000311 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000313 ost << ToStringIfSet("start bitrate", video_start_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000314 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000315 ost << ToStringIfSet("cpu underuse threshold", cpu_underuse_threshold);
316 ost << ToStringIfSet("cpu overuse threshold", cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000317 ost << ToStringIfSet("cpu underuse encode rsd threshold",
318 cpu_underuse_encode_rsd_threshold);
319 ost << ToStringIfSet("cpu overuse encode rsd threshold",
320 cpu_overuse_encode_rsd_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000321 ost << ToStringIfSet("cpu overuse encode usage",
322 cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 ost << ToStringIfSet("conference mode", conference_mode);
324 ost << ToStringIfSet("process", process_adaptation_threshhold);
325 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
326 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000327 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000328 ost << ToStringIfSet("suspend below min bitrate",
329 suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000330 ost << ToStringIfSet("num channels for early receive",
331 unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000332 ost << ToStringIfSet("use simulcast adapter", use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000333 ost << ToStringIfSet("screencast min bitrate", screencast_min_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 ost << "}";
335 return ost.str();
336 }
337
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 // Enable CPU adaptation?
Karl Wibergbe579832015-11-10 22:34:18 +0100339 rtc::Optional<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000340 // Enable CPU adaptation smoothing?
Karl Wibergbe579832015-11-10 22:34:18 +0100341 rtc::Optional<bool> adapt_cpu_with_smoothing;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000342 // Enable video adapt third?
Karl Wibergbe579832015-11-10 22:34:18 +0100343 rtc::Optional<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 // Enable denoising?
Karl Wibergbe579832015-11-10 22:34:18 +0100345 rtc::Optional<bool> video_noise_reduction;
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000346 // Experimental: Enable WebRtc higher start bitrate?
Karl Wibergbe579832015-11-10 22:34:18 +0100347 rtc::Optional<int> video_start_bitrate;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000348 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
349 // adaptation algorithm. So this option will override the
350 // |adapt_input_to_cpu_usage|.
Karl Wibergbe579832015-11-10 22:34:18 +0100351 rtc::Optional<bool> cpu_overuse_detection;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000352 // Low threshold (t1) for cpu overuse adaptation. (Adapt up)
353 // Metric: encode usage (m1). m1 < t1 => underuse.
Karl Wibergbe579832015-11-10 22:34:18 +0100354 rtc::Optional<int> cpu_underuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000355 // High threshold (t1) for cpu overuse adaptation. (Adapt down)
356 // Metric: encode usage (m1). m1 > t1 => overuse.
Karl Wibergbe579832015-11-10 22:34:18 +0100357 rtc::Optional<int> cpu_overuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000358 // Low threshold (t2) for cpu overuse adaptation. (Adapt up)
359 // Metric: relative standard deviation of encode time (m2).
360 // Optional threshold. If set, (m1 < t1 && m2 < t2) => underuse.
361 // Note: t2 will have no effect if t1 is not set.
Karl Wibergbe579832015-11-10 22:34:18 +0100362 rtc::Optional<int> cpu_underuse_encode_rsd_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000363 // High threshold (t2) for cpu overuse adaptation. (Adapt down)
364 // Metric: relative standard deviation of encode time (m2).
365 // Optional threshold. If set, (m1 > t1 || m2 > t2) => overuse.
366 // Note: t2 will have no effect if t1 is not set.
Karl Wibergbe579832015-11-10 22:34:18 +0100367 rtc::Optional<int> cpu_overuse_encode_rsd_threshold;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000368 // Use encode usage for cpu detection.
Karl Wibergbe579832015-11-10 22:34:18 +0100369 rtc::Optional<bool> cpu_overuse_encode_usage;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 // Use conference mode?
Karl Wibergbe579832015-11-10 22:34:18 +0100371 rtc::Optional<bool> conference_mode;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 // Threshhold for process cpu adaptation. (Process limit)
Karl Wibergbe579832015-11-10 22:34:18 +0100373 rtc::Optional<float> process_adaptation_threshhold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 // Low threshhold for cpu adaptation. (Adapt up)
Karl Wibergbe579832015-11-10 22:34:18 +0100375 rtc::Optional<float> system_low_adaptation_threshhold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376 // High threshhold for cpu adaptation. (Adapt down)
Karl Wibergbe579832015-11-10 22:34:18 +0100377 rtc::Optional<float> system_high_adaptation_threshhold;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000378 // Set DSCP value for packet sent from video channel.
Karl Wibergbe579832015-11-10 22:34:18 +0100379 rtc::Optional<bool> dscp;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000380 // Enable WebRTC suspension of video. No video frames will be sent when the
381 // bitrate is below the configured minimum bitrate.
Karl Wibergbe579832015-11-10 22:34:18 +0100382 rtc::Optional<bool> suspend_below_min_bitrate;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000383 // Limit on the number of early receive channels that can be created.
Karl Wibergbe579832015-11-10 22:34:18 +0100384 rtc::Optional<int> unsignalled_recv_stream_limit;
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000385 // Enable use of simulcast adapter.
Karl Wibergbe579832015-11-10 22:34:18 +0100386 rtc::Optional<bool> use_simulcast_adapter;
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000387 // Force screencast to use a minimum bitrate
Karl Wibergbe579832015-11-10 22:34:18 +0100388 rtc::Optional<int> screencast_min_bitrate;
qiangchen444682a2015-11-24 18:07:56 -0800389 // Set to true if the renderer has an algorithm of frame selection.
390 // If the value is true, then WebRTC will hand over a frame as soon as
391 // possible without delay, and rendering smoothness is completely the duty
392 // of the renderer;
393 // If the value is false, then WebRTC is responsible to delay frame release
394 // in order to increase rendering smoothness.
395 rtc::Optional<bool> disable_prerenderer_smoothing;
kwiberg102c6a62015-10-30 02:47:38 -0700396
397 private:
398 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100399 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700400 if (o) {
401 *s = o;
402 }
403 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404};
405
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000406struct RtpHeaderExtension {
407 RtpHeaderExtension() : id(0) {}
408 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000409
410 bool operator==(const RtpHeaderExtension& ext) const {
411 // id is a reserved word in objective-c. Therefore the id attribute has to
412 // be a fully qualified name in order to compile on IOS.
413 return this->id == ext.id &&
414 uri == ext.uri;
415 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700416
417 std::string ToString() const {
418 std::ostringstream ost;
419 ost << "{";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700420 ost << "uri: " << uri;
solenberg7e4e01a2015-12-02 08:05:01 -0800421 ost << ", id: " << id;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700422 ost << "}";
423 return ost.str();
424 }
425
426 std::string uri;
427 int id;
428 // TODO(juberti): SendRecv direction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000429};
430
431// Returns the named header extension if found among all extensions, NULL
432// otherwise.
433inline const RtpHeaderExtension* FindHeaderExtension(
434 const std::vector<RtpHeaderExtension>& extensions,
435 const std::string& name) {
436 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
437 it != extensions.end(); ++it) {
438 if (it->uri == name)
439 return &(*it);
440 }
441 return NULL;
442}
443
444enum MediaChannelOptions {
445 // Tune the stream for conference mode.
446 OPT_CONFERENCE = 0x0001
447};
448
449enum VoiceMediaChannelOptions {
450 // Tune the audio stream for vcs with different target levels.
451 OPT_AGC_MINUS_10DB = 0x80000000
452};
453
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454class MediaChannel : public sigslot::has_slots<> {
455 public:
456 class NetworkInterface {
457 public:
458 enum SocketType { ST_RTP, ST_RTCP };
stefanc1aeaf02015-10-15 07:26:07 -0700459 virtual bool SendPacket(rtc::Buffer* packet,
460 const rtc::PacketOptions& options) = 0;
461 virtual bool SendRtcp(rtc::Buffer* packet,
462 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000463 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464 int option) = 0;
465 virtual ~NetworkInterface() {}
466 };
467
468 MediaChannel() : network_interface_(NULL) {}
469 virtual ~MediaChannel() {}
470
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000471 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000473 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474 network_interface_ = iface;
475 }
476
477 // Called when a RTP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000478 virtual void OnPacketReceived(rtc::Buffer* packet,
479 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480 // Called when a RTCP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000481 virtual void OnRtcpReceived(rtc::Buffer* packet,
482 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483 // Called when the socket's ability to send has changed.
484 virtual void OnReadyToSend(bool ready) = 0;
485 // Creates a new outgoing media stream with SSRCs and CNAME as described
486 // by sp.
487 virtual bool AddSendStream(const StreamParams& sp) = 0;
488 // Removes an outgoing media stream.
489 // ssrc must be the first SSRC of the media stream if the stream uses
490 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200491 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492 // Creates a new incoming media stream with SSRCs and CNAME as described
493 // by sp.
494 virtual bool AddRecvStream(const StreamParams& sp) = 0;
495 // Removes an incoming media stream.
496 // ssrc must be the first SSRC of the media stream if the stream uses
497 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200498 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000500 // Returns the absoulte sendtime extension id value from media channel.
501 virtual int GetRtpSendTimeExtnId() const {
502 return -1;
503 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000505 // Base method to send packet using NetworkInterface.
stefanc1aeaf02015-10-15 07:26:07 -0700506 bool SendPacket(rtc::Buffer* packet, const rtc::PacketOptions& options) {
507 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000508 }
509
stefanc1aeaf02015-10-15 07:26:07 -0700510 bool SendRtcp(rtc::Buffer* packet, const rtc::PacketOptions& options) {
511 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000512 }
513
514 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000515 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000516 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000517 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000518 if (!network_interface_)
519 return -1;
520
521 return network_interface_->SetOption(type, opt, option);
522 }
523
wu@webrtc.orgde305012013-10-31 15:40:38 +0000524 protected:
525 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000526 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000527 int ret;
528 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000529 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000530 value);
531 if (ret == 0) {
532 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000533 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000534 value);
535 }
536 return ret;
537 }
538
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000539 private:
stefanc1aeaf02015-10-15 07:26:07 -0700540 bool DoSendPacket(rtc::Buffer* packet,
541 bool rtcp,
542 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000543 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000544 if (!network_interface_)
545 return false;
546
stefanc1aeaf02015-10-15 07:26:07 -0700547 return (!rtcp) ? network_interface_->SendPacket(packet, options)
548 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000549 }
550
551 // |network_interface_| can be accessed from the worker_thread and
552 // from any MediaEngine threads. This critical section is to protect accessing
553 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000554 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000555 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556};
557
558enum SendFlags {
559 SEND_NOTHING,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 SEND_MICROPHONE
561};
562
wu@webrtc.org97077a32013-10-25 21:18:33 +0000563// The stats information is structured as follows:
564// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
565// Media contains a vector of SSRC infos that are exclusively used by this
566// media. (SSRCs shared between media streams can't be represented.)
567
568// Information about an SSRC.
569// This data may be locally recorded, or received in an RTCP SR or RR.
570struct SsrcSenderInfo {
571 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000573 timestamp(0) {
574 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200575 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000576 double timestamp; // NTP timestamp, represented as seconds since epoch.
577};
578
579struct SsrcReceiverInfo {
580 SsrcReceiverInfo()
581 : ssrc(0),
582 timestamp(0) {
583 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200584 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000585 double timestamp;
586};
587
588struct MediaSenderInfo {
589 MediaSenderInfo()
590 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 packets_sent(0),
592 packets_lost(0),
593 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000594 rtt_ms(0) {
595 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000596 void add_ssrc(const SsrcSenderInfo& stat) {
597 local_stats.push_back(stat);
598 }
599 // Temporary utility function for call sites that only provide SSRC.
600 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200601 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000602 SsrcSenderInfo stat;
603 stat.ssrc = ssrc;
604 add_ssrc(stat);
605 }
606 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200607 std::vector<uint32_t> ssrcs() const {
608 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000609 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
610 it != local_stats.end(); ++it) {
611 retval.push_back(it->ssrc);
612 }
613 return retval;
614 }
615 // Utility accessor for clients that make the assumption only one ssrc
616 // exists per media.
617 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200618 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000619 if (local_stats.size() > 0) {
620 return local_stats[0].ssrc;
621 } else {
622 return 0;
623 }
624 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200625 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000626 int packets_sent;
627 int packets_lost;
628 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000629 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000630 std::string codec_name;
631 std::vector<SsrcSenderInfo> local_stats;
632 std::vector<SsrcReceiverInfo> remote_stats;
633};
634
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000635template<class T>
636struct VariableInfo {
637 VariableInfo()
638 : min_val(),
639 mean(0.0),
640 max_val(),
641 variance(0.0) {
642 }
643 T min_val;
644 double mean;
645 T max_val;
646 double variance;
647};
648
wu@webrtc.org97077a32013-10-25 21:18:33 +0000649struct MediaReceiverInfo {
650 MediaReceiverInfo()
651 : bytes_rcvd(0),
652 packets_rcvd(0),
653 packets_lost(0),
654 fraction_lost(0.0) {
655 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000656 void add_ssrc(const SsrcReceiverInfo& stat) {
657 local_stats.push_back(stat);
658 }
659 // Temporary utility function for call sites that only provide SSRC.
660 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200661 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000662 SsrcReceiverInfo stat;
663 stat.ssrc = ssrc;
664 add_ssrc(stat);
665 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200666 std::vector<uint32_t> ssrcs() const {
667 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000668 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
669 it != local_stats.end(); ++it) {
670 retval.push_back(it->ssrc);
671 }
672 return retval;
673 }
674 // Utility accessor for clients that make the assumption only one ssrc
675 // exists per media.
676 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200677 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000678 if (local_stats.size() > 0) {
679 return local_stats[0].ssrc;
680 } else {
681 return 0;
682 }
683 }
684
Peter Boström0c4e06b2015-10-07 12:23:21 +0200685 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000686 int packets_rcvd;
687 int packets_lost;
688 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000689 std::string codec_name;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000690 std::vector<SsrcReceiverInfo> local_stats;
691 std::vector<SsrcSenderInfo> remote_stats;
692};
693
694struct VoiceSenderInfo : public MediaSenderInfo {
695 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000696 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 jitter_ms(0),
698 audio_level(0),
699 aec_quality_min(0.0),
700 echo_delay_median_ms(0),
701 echo_delay_std_ms(0),
702 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000703 echo_return_loss_enhancement(0),
704 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 }
706
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 int jitter_ms;
709 int audio_level;
710 float aec_quality_min;
711 int echo_delay_median_ms;
712 int echo_delay_std_ms;
713 int echo_return_loss;
714 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000715 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716};
717
wu@webrtc.org97077a32013-10-25 21:18:33 +0000718struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000720 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 jitter_ms(0),
722 jitter_buffer_ms(0),
723 jitter_buffer_preferred_ms(0),
724 delay_estimate_ms(0),
725 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000726 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000727 speech_expand_rate(0),
728 secondary_decoded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200729 accelerate_rate(0),
730 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000731 decoding_calls_to_silence_generator(0),
732 decoding_calls_to_neteq(0),
733 decoding_normal(0),
734 decoding_plc(0),
735 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000736 decoding_plc_cng(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200737 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 int ext_seqnum;
740 int jitter_ms;
741 int jitter_buffer_ms;
742 int jitter_buffer_preferred_ms;
743 int delay_estimate_ms;
744 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000745 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000747 // fraction of synthesized speech inserted through expansion.
748 float speech_expand_rate;
749 // fraction of data out of secondary decoding, including FEC and RED.
750 float secondary_decoded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200751 // Fraction of data removed through time compression.
752 float accelerate_rate;
753 // Fraction of data inserted through time stretching.
754 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000755 int decoding_calls_to_silence_generator;
756 int decoding_calls_to_neteq;
757 int decoding_normal;
758 int decoding_plc;
759 int decoding_cng;
760 int decoding_plc_cng;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000761 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200762 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763};
764
wu@webrtc.org97077a32013-10-25 21:18:33 +0000765struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000767 : packets_cached(0),
768 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000769 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000771 input_frame_width(0),
772 input_frame_height(0),
773 send_frame_width(0),
774 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 framerate_input(0),
776 framerate_sent(0),
777 nominal_bitrate(0),
778 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000779 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000780 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000781 avg_encode_ms(0),
Peter Boström8ed6a4b2015-03-27 10:01:02 +0100782 encode_usage_percent(0) {
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000783 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000785 std::vector<SsrcGroup> ssrc_groups;
786 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000788 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000790 int input_frame_width;
791 int input_frame_height;
792 int send_frame_width;
793 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 int framerate_input;
795 int framerate_sent;
796 int nominal_bitrate;
797 int preferred_bitrate;
798 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000799 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000800 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000801 int encode_usage_percent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000802 VariableInfo<int> adapt_frame_drops;
803 VariableInfo<int> effects_frame_drops;
804 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805};
806
wu@webrtc.org97077a32013-10-25 21:18:33 +0000807struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000809 : packets_concealed(0),
810 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000811 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 nacks_sent(0),
813 frame_width(0),
814 frame_height(0),
815 framerate_rcvd(0),
816 framerate_decoded(0),
817 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000818 framerate_render_input(0),
819 framerate_render_output(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000820 decode_ms(0),
821 max_decode_ms(0),
822 jitter_buffer_ms(0),
823 min_playout_delay_ms(0),
824 render_delay_ms(0),
825 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000826 current_delay_ms(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000827 capture_start_ntp_time_ms(-1) {
828 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000830 std::vector<SsrcGroup> ssrc_groups;
831 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000833 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 int nacks_sent;
835 int frame_width;
836 int frame_height;
837 int framerate_rcvd;
838 int framerate_decoded;
839 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000840 // Framerate as sent to the renderer.
841 int framerate_render_input;
842 // Framerate that the renderer reports.
843 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000844
845 // All stats below are gathered per-VideoReceiver, but some will be correlated
846 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
847 // structures, reflect this in the new layout.
848
849 // Current frame decode latency.
850 int decode_ms;
851 // Maximum observed frame decode latency.
852 int max_decode_ms;
853 // Jitter (network-related) latency.
854 int jitter_buffer_ms;
855 // Requested minimum playout latency.
856 int min_playout_delay_ms;
857 // Requested latency to account for rendering delay.
858 int render_delay_ms;
859 // Target overall delay: network+decode+render, accounting for
860 // min_playout_delay_ms.
861 int target_delay_ms;
862 // Current overall delay, possibly ramping towards target_delay_ms.
863 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000864
865 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200866 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867};
868
wu@webrtc.org97077a32013-10-25 21:18:33 +0000869struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000871 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 }
873
Peter Boström0c4e06b2015-10-07 12:23:21 +0200874 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875};
876
wu@webrtc.org97077a32013-10-25 21:18:33 +0000877struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000879 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 }
881
Peter Boström0c4e06b2015-10-07 12:23:21 +0200882 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883};
884
885struct BandwidthEstimationInfo {
886 BandwidthEstimationInfo()
887 : available_send_bandwidth(0),
888 available_recv_bandwidth(0),
889 target_enc_bitrate(0),
890 actual_enc_bitrate(0),
891 retransmit_bitrate(0),
892 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000893 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 }
895
896 int available_send_bandwidth;
897 int available_recv_bandwidth;
898 int target_enc_bitrate;
899 int actual_enc_bitrate;
900 int retransmit_bitrate;
901 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000902 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903};
904
905struct VoiceMediaInfo {
906 void Clear() {
907 senders.clear();
908 receivers.clear();
909 }
910 std::vector<VoiceSenderInfo> senders;
911 std::vector<VoiceReceiverInfo> receivers;
912};
913
914struct VideoMediaInfo {
915 void Clear() {
916 senders.clear();
917 receivers.clear();
918 bw_estimations.clear();
919 }
920 std::vector<VideoSenderInfo> senders;
921 std::vector<VideoReceiverInfo> receivers;
922 std::vector<BandwidthEstimationInfo> bw_estimations;
923};
924
925struct DataMediaInfo {
926 void Clear() {
927 senders.clear();
928 receivers.clear();
929 }
930 std::vector<DataSenderInfo> senders;
931 std::vector<DataReceiverInfo> receivers;
932};
933
deadbeef13871492015-12-09 12:37:51 -0800934struct RtcpParameters {
935 bool reduced_size = false;
936};
937
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700938template <class Codec>
939struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800940 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700941 std::ostringstream ost;
942 ost << "{";
943 ost << "codecs: " << VectorToString(codecs) << ", ";
944 ost << "extensions: " << VectorToString(extensions);
945 ost << "}";
946 return ost.str();
947 }
948
949 std::vector<Codec> codecs;
950 std::vector<RtpHeaderExtension> extensions;
951 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800952 RtcpParameters rtcp;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700953};
954
955template <class Codec, class Options>
956struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800957 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700958 std::ostringstream ost;
959 ost << "{";
960 ost << "codecs: " << VectorToString(this->codecs) << ", ";
961 ost << "extensions: " << VectorToString(this->extensions) << ", ";
962 ost << "max_bandiwidth_bps: " << max_bandwidth_bps << ", ";
963 ost << "options: " << options.ToString();
964 ost << "}";
965 return ost.str();
966 }
967
968 int max_bandwidth_bps = -1;
969 Options options;
970};
971
972struct AudioSendParameters : RtpSendParameters<AudioCodec, AudioOptions> {
973};
974
975struct AudioRecvParameters : RtpParameters<AudioCodec> {
976};
977
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978class VoiceMediaChannel : public MediaChannel {
979 public:
980 enum Error {
981 ERROR_NONE = 0, // No error.
982 ERROR_OTHER, // Other errors.
983 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
984 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
985 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
986 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
987 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
988 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
989 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
990 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
991 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
992 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
993 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
994 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
995 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
996 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
997 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
998 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
999 };
1000
1001 VoiceMediaChannel() {}
1002 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001003 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
1004 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 // Starts or stops playout of received audio.
1006 virtual bool SetPlayout(bool playout) = 0;
1007 // Starts or stops sending (and potentially capture) of local audio.
1008 virtual bool SetSend(SendFlags flag) = 0;
solenberg1dd98f32015-09-10 01:57:14 -07001009 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001010 virtual bool SetAudioSend(uint32_t ssrc,
1011 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -07001012 const AudioOptions* options,
solenberg1dd98f32015-09-10 01:57:14 -07001013 AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014 // Gets current energy levels for all incoming streams.
1015 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1016 // Get the current energy level of the stream sent to the speaker.
1017 virtual int GetOutputLevel() = 0;
1018 // Get the time in milliseconds since last recorded keystroke, or negative.
1019 virtual int GetTimeSinceLastTyping() = 0;
1020 // Temporarily exposed field for tuning typing detect options.
1021 virtual void SetTypingDetectionParameters(int time_window,
1022 int cost_per_typing, int reporting_threshold, int penalty_decay,
1023 int type_event_delay) = 0;
solenberg4bac9c52015-10-09 02:32:53 -07001024 // Set speaker output volume of the specified ssrc.
1025 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -08001027 virtual bool CanInsertDtmf() = 0;
1028 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001030 // The valid value for the |event| are 0 to 15 which corresponding to
1031 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -08001032 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001033 // Gets quality stats for the channel.
1034 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +01001035
1036 virtual void SetRawAudioSink(
1037 uint32_t ssrc,
1038 rtc::scoped_ptr<webrtc::AudioSinkInterface> sink) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039};
1040
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001041struct VideoSendParameters : RtpSendParameters<VideoCodec, VideoOptions> {
1042};
1043
1044struct VideoRecvParameters : RtpParameters<VideoCodec> {
1045};
1046
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047class VideoMediaChannel : public MediaChannel {
1048 public:
1049 enum Error {
1050 ERROR_NONE = 0, // No error.
1051 ERROR_OTHER, // Other errors.
1052 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1053 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1054 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1055 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1056 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1057 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1058 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1059 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1060 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1061 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1062 };
1063
1064 VideoMediaChannel() : renderer_(NULL) {}
1065 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001066
1067 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
1068 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 // Gets the currently set codecs/payload types to be used for outgoing media.
1070 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1071 // Sets the format of a specified outgoing stream.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001072 virtual bool SetSendStreamFormat(uint32_t ssrc,
1073 const VideoFormat& format) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 // Starts or stops transmission (and potentially capture) of local video.
1075 virtual bool SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -07001076 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001077 virtual bool SetVideoSend(uint32_t ssrc,
1078 bool enable,
solenberg1dd98f32015-09-10 01:57:14 -07001079 const VideoOptions* options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 // Sets the renderer object to be used for the specified stream.
1081 // If SSRC is 0, the renderer is used for the 'default' stream.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001082 virtual bool SetRenderer(uint32_t ssrc, VideoRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1084 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001085 virtual bool SetCapturer(uint32_t ssrc, VideoCapturer* capturer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001087 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 // Send an intra frame to the receivers.
1089 virtual bool SendIntraFrame() = 0;
1090 // Reuqest each of the remote senders to send an intra frame.
1091 virtual bool RequestIntraFrame() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1093
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094 protected:
1095 VideoRenderer *renderer_;
1096};
1097
1098enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001099 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1100 // values.
1101 DMT_NONE = 0,
1102 DMT_CONTROL = 1,
1103 DMT_BINARY = 2,
1104 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105};
1106
1107// Info about data received in DataMediaChannel. For use in
1108// DataMediaChannel::SignalDataReceived and in all of the signals that
1109// signal fires, on up the chain.
1110struct ReceiveDataParams {
1111 // The in-packet stream indentifier.
1112 // For SCTP, this is really SID, not SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001113 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114 // The type of message (binary, text, or control).
1115 DataMessageType type;
1116 // A per-stream value incremented per packet in the stream.
1117 int seq_num;
1118 // A per-stream value monotonically increasing with time.
1119 int timestamp;
1120
1121 ReceiveDataParams() :
1122 ssrc(0),
1123 type(DMT_TEXT),
1124 seq_num(0),
1125 timestamp(0) {
1126 }
1127};
1128
1129struct SendDataParams {
1130 // The in-packet stream indentifier.
1131 // For SCTP, this is really SID, not SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001132 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001133 // The type of message (binary, text, or control).
1134 DataMessageType type;
1135
1136 // For SCTP, whether to send messages flagged as ordered or not.
1137 // If false, messages can be received out of order.
1138 bool ordered;
1139 // For SCTP, whether the messages are sent reliably or not.
1140 // If false, messages may be lost.
1141 bool reliable;
1142 // For SCTP, if reliable == false, provide partial reliability by
1143 // resending up to this many times. Either count or millis
1144 // is supported, not both at the same time.
1145 int max_rtx_count;
1146 // For SCTP, if reliable == false, provide partial reliability by
1147 // resending for up to this many milliseconds. Either count or millis
1148 // is supported, not both at the same time.
1149 int max_rtx_ms;
1150
1151 SendDataParams() :
1152 ssrc(0),
1153 type(DMT_TEXT),
1154 // TODO(pthatcher): Make these true by default?
1155 ordered(false),
1156 reliable(false),
1157 max_rtx_count(0),
1158 max_rtx_ms(0) {
1159 }
1160};
1161
1162enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1163
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001164struct DataOptions {
solenberg7e4e01a2015-12-02 08:05:01 -08001165 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001166 return "{}";
1167 }
1168};
1169
1170struct DataSendParameters : RtpSendParameters<DataCodec, DataOptions> {
solenberg7e4e01a2015-12-02 08:05:01 -08001171 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001172 std::ostringstream ost;
1173 // Options and extensions aren't used.
1174 ost << "{";
1175 ost << "codecs: " << VectorToString(codecs) << ", ";
1176 ost << "max_bandiwidth_bps: " << max_bandwidth_bps;
1177 ost << "}";
1178 return ost.str();
1179 }
1180};
1181
1182struct DataRecvParameters : RtpParameters<DataCodec> {
1183};
1184
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001185class DataMediaChannel : public MediaChannel {
1186 public:
1187 enum Error {
1188 ERROR_NONE = 0, // No error.
1189 ERROR_OTHER, // Other errors.
1190 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1191 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1192 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1193 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1194 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1195 };
1196
1197 virtual ~DataMediaChannel() {}
1198
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001199 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1200 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001201
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001202 // TODO(pthatcher): Implement this.
1203 virtual bool GetStats(DataMediaInfo* info) { return true; }
1204
1205 virtual bool SetSend(bool send) = 0;
1206 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001207
1208 virtual bool SendData(
1209 const SendDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001210 const rtc::Buffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001211 SendDataResult* result = NULL) = 0;
1212 // Signals when data is received (params, data, len)
1213 sigslot::signal3<const ReceiveDataParams&,
1214 const char*,
1215 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001216 // Signal when the media channel is ready to send the stream. Arguments are:
1217 // writable(bool)
1218 sigslot::signal1<bool> SignalReadyToSend;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001219 // Signal for notifying that the remote side has closed the DataChannel.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001220 sigslot::signal1<uint32_t> SignalStreamClosedRemotely;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001221};
1222
1223} // namespace cricket
1224
1225#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_