blob: 2509cb025e9834b19d9c145bbd6cca9df663595e [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
54namespace cricket {
55
56class AudioRenderer;
57struct RtpHeader;
58class ScreencastId;
59struct VideoFormat;
60class VideoCapturer;
61class VideoRenderer;
62
63const int kMinRtpHeaderExtensionId = 1;
64const int kMaxRtpHeaderExtensionId = 255;
65const int kScreencastDefaultFps = 5;
66
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067template <class T>
Karl Wibergbe579832015-11-10 22:34:18 +010068static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070070 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071 str = key;
72 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070073 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074 str += ", ";
75 }
76 return str;
77}
78
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070079template <class T>
80static std::string VectorToString(const std::vector<T>& vals) {
81 std::ostringstream ost;
82 ost << "[";
83 for (size_t i = 0; i < vals.size(); ++i) {
84 if (i > 0) {
85 ost << ", ";
86 }
87 ost << vals[i].ToString();
88 }
89 ost << "]";
90 return ost.str();
91}
92
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
94// Used to be flags, but that makes it hard to selectively apply options.
95// We are moving all of the setting of options to structs like this,
96// but some things currently still use flags.
97struct AudioOptions {
98 void SetAll(const AudioOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -070099 SetFrom(&echo_cancellation, change.echo_cancellation);
100 SetFrom(&auto_gain_control, change.auto_gain_control);
101 SetFrom(&noise_suppression, change.noise_suppression);
102 SetFrom(&highpass_filter, change.highpass_filter);
103 SetFrom(&stereo_swapping, change.stereo_swapping);
104 SetFrom(&audio_jitter_buffer_max_packets,
105 change.audio_jitter_buffer_max_packets);
106 SetFrom(&audio_jitter_buffer_fast_accelerate,
107 change.audio_jitter_buffer_fast_accelerate);
108 SetFrom(&typing_detection, change.typing_detection);
109 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise);
110 SetFrom(&conference_mode, change.conference_mode);
111 SetFrom(&adjust_agc_delta, change.adjust_agc_delta);
112 SetFrom(&experimental_agc, change.experimental_agc);
113 SetFrom(&extended_filter_aec, change.extended_filter_aec);
114 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec);
115 SetFrom(&experimental_ns, change.experimental_ns);
116 SetFrom(&aec_dump, change.aec_dump);
117 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov);
118 SetFrom(&tx_agc_digital_compression_gain,
119 change.tx_agc_digital_compression_gain);
120 SetFrom(&tx_agc_limiter, change.tx_agc_limiter);
121 SetFrom(&recording_sample_rate, change.recording_sample_rate);
122 SetFrom(&playout_sample_rate, change.playout_sample_rate);
123 SetFrom(&dscp, change.dscp);
124 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 }
126
127 bool operator==(const AudioOptions& o) const {
128 return echo_cancellation == o.echo_cancellation &&
129 auto_gain_control == o.auto_gain_control &&
130 noise_suppression == o.noise_suppression &&
131 highpass_filter == o.highpass_filter &&
132 stereo_swapping == o.stereo_swapping &&
Henrik Lundin64dad832015-05-11 12:44:23 +0200133 audio_jitter_buffer_max_packets == o.audio_jitter_buffer_max_packets &&
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200134 audio_jitter_buffer_fast_accelerate ==
135 o.audio_jitter_buffer_fast_accelerate &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000137 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138 conference_mode == o.conference_mode &&
139 experimental_agc == o.experimental_agc &&
Henrik Lundin441f6342015-06-09 16:03:13 +0200140 extended_filter_aec == o.extended_filter_aec &&
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100141 delay_agnostic_aec == o.delay_agnostic_aec &&
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000142 experimental_ns == o.experimental_ns &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000144 aec_dump == o.aec_dump &&
145 tx_agc_target_dbov == o.tx_agc_target_dbov &&
146 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
147 tx_agc_limiter == o.tx_agc_limiter &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000148 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000149 playout_sample_rate == o.playout_sample_rate &&
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000150 dscp == o.dscp &&
151 combined_audio_video_bwe == o.combined_audio_video_bwe;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 }
153
154 std::string ToString() const {
155 std::ostringstream ost;
156 ost << "AudioOptions {";
157 ost << ToStringIfSet("aec", echo_cancellation);
158 ost << ToStringIfSet("agc", auto_gain_control);
159 ost << ToStringIfSet("ns", noise_suppression);
160 ost << ToStringIfSet("hf", highpass_filter);
161 ost << ToStringIfSet("swap", stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200162 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
163 audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200164 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
165 audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000167 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 ost << ToStringIfSet("conference", conference_mode);
169 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
170 ost << ToStringIfSet("experimental_agc", experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200171 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100172 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000173 ost << ToStringIfSet("experimental_ns", experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 ost << ToStringIfSet("aec_dump", aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000175 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
176 ost << ToStringIfSet("tx_agc_digital_compression_gain",
177 tx_agc_digital_compression_gain);
178 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000179 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
180 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000181 ost << ToStringIfSet("dscp", dscp);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000182 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183 ost << "}";
184 return ost.str();
185 }
186
187 // Audio processing that attempts to filter away the output signal from
188 // later inbound pickup.
Karl Wibergbe579832015-11-10 22:34:18 +0100189 rtc::Optional<bool> echo_cancellation;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 // Audio processing to adjust the sensitivity of the local mic dynamically.
Karl Wibergbe579832015-11-10 22:34:18 +0100191 rtc::Optional<bool> auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 // Audio processing to filter out background noise.
Karl Wibergbe579832015-11-10 22:34:18 +0100193 rtc::Optional<bool> noise_suppression;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 // Audio processing to remove background noise of lower frequencies.
Karl Wibergbe579832015-11-10 22:34:18 +0100195 rtc::Optional<bool> highpass_filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 // Audio processing to swap the left and right channels.
Karl Wibergbe579832015-11-10 22:34:18 +0100197 rtc::Optional<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200198 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Karl Wibergbe579832015-11-10 22:34:18 +0100199 rtc::Optional<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200200 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Karl Wibergbe579832015-11-10 22:34:18 +0100201 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202 // Audio processing to detect typing.
Karl Wibergbe579832015-11-10 22:34:18 +0100203 rtc::Optional<bool> typing_detection;
204 rtc::Optional<bool> aecm_generate_comfort_noise;
205 rtc::Optional<bool> conference_mode;
206 rtc::Optional<int> adjust_agc_delta;
207 rtc::Optional<bool> experimental_agc;
208 rtc::Optional<bool> extended_filter_aec;
209 rtc::Optional<bool> delay_agnostic_aec;
210 rtc::Optional<bool> experimental_ns;
211 rtc::Optional<bool> aec_dump;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000212 // Note that tx_agc_* only applies to non-experimental AGC.
Karl Wibergbe579832015-11-10 22:34:18 +0100213 rtc::Optional<uint16_t> tx_agc_target_dbov;
214 rtc::Optional<uint16_t> tx_agc_digital_compression_gain;
215 rtc::Optional<bool> tx_agc_limiter;
216 rtc::Optional<uint32_t> recording_sample_rate;
217 rtc::Optional<uint32_t> playout_sample_rate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000218 // Set DSCP value for packet sent from audio channel.
Karl Wibergbe579832015-11-10 22:34:18 +0100219 rtc::Optional<bool> dscp;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000220 // Enable combined audio+bandwidth BWE.
Karl Wibergbe579832015-11-10 22:34:18 +0100221 rtc::Optional<bool> combined_audio_video_bwe;
kwiberg102c6a62015-10-30 02:47:38 -0700222
223 private:
224 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100225 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700226 if (o) {
227 *s = o;
228 }
229 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230};
231
232// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
233// Used to be flags, but that makes it hard to selectively apply options.
234// We are moving all of the setting of options to structs like this,
235// but some things currently still use flags.
236struct VideoOptions {
kwiberg102c6a62015-10-30 02:47:38 -0700237 VideoOptions()
238 : process_adaptation_threshhold(kProcessCpuThreshold),
239 system_low_adaptation_threshhold(kLowSystemCpuThreshold),
240 system_high_adaptation_threshhold(kHighSystemCpuThreshold),
241 unsignalled_recv_stream_limit(kNumDefaultUnsignalledVideoRecvStreams) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242
243 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700244 SetFrom(&adapt_input_to_cpu_usage, change.adapt_input_to_cpu_usage);
245 SetFrom(&adapt_cpu_with_smoothing, change.adapt_cpu_with_smoothing);
246 SetFrom(&video_adapt_third, change.video_adapt_third);
247 SetFrom(&video_noise_reduction, change.video_noise_reduction);
248 SetFrom(&video_start_bitrate, change.video_start_bitrate);
249 SetFrom(&cpu_overuse_detection, change.cpu_overuse_detection);
250 SetFrom(&cpu_underuse_threshold, change.cpu_underuse_threshold);
251 SetFrom(&cpu_overuse_threshold, change.cpu_overuse_threshold);
252 SetFrom(&cpu_underuse_encode_rsd_threshold,
253 change.cpu_underuse_encode_rsd_threshold);
254 SetFrom(&cpu_overuse_encode_rsd_threshold,
255 change.cpu_overuse_encode_rsd_threshold);
256 SetFrom(&cpu_overuse_encode_usage, change.cpu_overuse_encode_usage);
257 SetFrom(&conference_mode, change.conference_mode);
258 SetFrom(&process_adaptation_threshhold,
259 change.process_adaptation_threshhold);
260 SetFrom(&system_low_adaptation_threshhold,
261 change.system_low_adaptation_threshhold);
262 SetFrom(&system_high_adaptation_threshhold,
263 change.system_high_adaptation_threshhold);
264 SetFrom(&dscp, change.dscp);
265 SetFrom(&suspend_below_min_bitrate, change.suspend_below_min_bitrate);
266 SetFrom(&unsignalled_recv_stream_limit,
267 change.unsignalled_recv_stream_limit);
268 SetFrom(&use_simulcast_adapter, change.use_simulcast_adapter);
269 SetFrom(&screencast_min_bitrate, change.screencast_min_bitrate);
qiangchen444682a2015-11-24 18:07:56 -0800270 SetFrom(&disable_prerenderer_smoothing,
271 change.disable_prerenderer_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 }
273
274 bool operator==(const VideoOptions& o) const {
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000275 return adapt_input_to_cpu_usage == o.adapt_input_to_cpu_usage &&
276 adapt_cpu_with_smoothing == o.adapt_cpu_with_smoothing &&
277 video_adapt_third == o.video_adapt_third &&
278 video_noise_reduction == o.video_noise_reduction &&
279 video_start_bitrate == o.video_start_bitrate &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000280 cpu_overuse_detection == o.cpu_overuse_detection &&
281 cpu_underuse_threshold == o.cpu_underuse_threshold &&
282 cpu_overuse_threshold == o.cpu_overuse_threshold &&
283 cpu_underuse_encode_rsd_threshold ==
284 o.cpu_underuse_encode_rsd_threshold &&
285 cpu_overuse_encode_rsd_threshold ==
286 o.cpu_overuse_encode_rsd_threshold &&
287 cpu_overuse_encode_usage == o.cpu_overuse_encode_usage &&
288 conference_mode == o.conference_mode &&
289 process_adaptation_threshhold == o.process_adaptation_threshhold &&
290 system_low_adaptation_threshhold ==
291 o.system_low_adaptation_threshhold &&
292 system_high_adaptation_threshhold ==
293 o.system_high_adaptation_threshhold &&
Peter Thatchera9b4c322015-07-16 03:47:28 -0700294 dscp == o.dscp &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000295 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
296 unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit &&
297 use_simulcast_adapter == o.use_simulcast_adapter &&
qiangchen444682a2015-11-24 18:07:56 -0800298 screencast_min_bitrate == o.screencast_min_bitrate &&
299 disable_prerenderer_smoothing == o.disable_prerenderer_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 }
301
302 std::string ToString() const {
303 std::ostringstream ost;
304 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 ost << ToStringIfSet("cpu adaption", adapt_input_to_cpu_usage);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000306 ost << ToStringIfSet("cpu adaptation smoothing", adapt_cpu_with_smoothing);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000307 ost << ToStringIfSet("video adapt third", video_adapt_third);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000309 ost << ToStringIfSet("start bitrate", video_start_bitrate);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000310 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.orge9793ab2014-03-18 14:36:23 +0000311 ost << ToStringIfSet("cpu underuse threshold", cpu_underuse_threshold);
312 ost << ToStringIfSet("cpu overuse threshold", cpu_overuse_threshold);
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000313 ost << ToStringIfSet("cpu underuse encode rsd threshold",
314 cpu_underuse_encode_rsd_threshold);
315 ost << ToStringIfSet("cpu overuse encode rsd threshold",
316 cpu_overuse_encode_rsd_threshold);
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000317 ost << ToStringIfSet("cpu overuse encode usage",
318 cpu_overuse_encode_usage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 ost << ToStringIfSet("conference mode", conference_mode);
320 ost << ToStringIfSet("process", process_adaptation_threshhold);
321 ost << ToStringIfSet("low", system_low_adaptation_threshhold);
322 ost << ToStringIfSet("high", system_high_adaptation_threshhold);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000323 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000324 ost << ToStringIfSet("suspend below min bitrate",
325 suspend_below_min_bitrate);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000326 ost << ToStringIfSet("num channels for early receive",
327 unsignalled_recv_stream_limit);
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000328 ost << ToStringIfSet("use simulcast adapter", use_simulcast_adapter);
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000329 ost << ToStringIfSet("screencast min bitrate", screencast_min_bitrate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 ost << "}";
331 return ost.str();
332 }
333
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 // Enable CPU adaptation?
Karl Wibergbe579832015-11-10 22:34:18 +0100335 rtc::Optional<bool> adapt_input_to_cpu_usage;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000336 // Enable CPU adaptation smoothing?
Karl Wibergbe579832015-11-10 22:34:18 +0100337 rtc::Optional<bool> adapt_cpu_with_smoothing;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000338 // Enable video adapt third?
Karl Wibergbe579832015-11-10 22:34:18 +0100339 rtc::Optional<bool> video_adapt_third;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340 // Enable denoising?
Karl Wibergbe579832015-11-10 22:34:18 +0100341 rtc::Optional<bool> video_noise_reduction;
wu@webrtc.org1e6cb2c2014-03-24 17:01:50 +0000342 // Experimental: Enable WebRtc higher start bitrate?
Karl Wibergbe579832015-11-10 22:34:18 +0100343 rtc::Optional<int> video_start_bitrate;
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000344 // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU
345 // adaptation algorithm. So this option will override the
346 // |adapt_input_to_cpu_usage|.
Karl Wibergbe579832015-11-10 22:34:18 +0100347 rtc::Optional<bool> cpu_overuse_detection;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000348 // Low threshold (t1) for cpu overuse adaptation. (Adapt up)
349 // Metric: encode usage (m1). m1 < t1 => underuse.
Karl Wibergbe579832015-11-10 22:34:18 +0100350 rtc::Optional<int> cpu_underuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000351 // High threshold (t1) for cpu overuse adaptation. (Adapt down)
352 // Metric: encode usage (m1). m1 > t1 => overuse.
Karl Wibergbe579832015-11-10 22:34:18 +0100353 rtc::Optional<int> cpu_overuse_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000354 // Low threshold (t2) for cpu overuse adaptation. (Adapt up)
355 // Metric: relative standard deviation of encode time (m2).
356 // Optional threshold. If set, (m1 < t1 && m2 < t2) => underuse.
357 // Note: t2 will have no effect if t1 is not set.
Karl Wibergbe579832015-11-10 22:34:18 +0100358 rtc::Optional<int> cpu_underuse_encode_rsd_threshold;
buildbot@webrtc.org27626a62014-06-16 13:39:40 +0000359 // High threshold (t2) for cpu overuse adaptation. (Adapt down)
360 // Metric: relative standard deviation of encode time (m2).
361 // Optional threshold. If set, (m1 > t1 || m2 > t2) => overuse.
362 // Note: t2 will have no effect if t1 is not set.
Karl Wibergbe579832015-11-10 22:34:18 +0100363 rtc::Optional<int> cpu_overuse_encode_rsd_threshold;
henrike@webrtc.orgb0ecc1c2014-03-26 22:44:28 +0000364 // Use encode usage for cpu detection.
Karl Wibergbe579832015-11-10 22:34:18 +0100365 rtc::Optional<bool> cpu_overuse_encode_usage;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 // Use conference mode?
Karl Wibergbe579832015-11-10 22:34:18 +0100367 rtc::Optional<bool> conference_mode;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 // Threshhold for process cpu adaptation. (Process limit)
Karl Wibergbe579832015-11-10 22:34:18 +0100369 rtc::Optional<float> process_adaptation_threshhold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 // Low threshhold for cpu adaptation. (Adapt up)
Karl Wibergbe579832015-11-10 22:34:18 +0100371 rtc::Optional<float> system_low_adaptation_threshhold;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 // High threshhold for cpu adaptation. (Adapt down)
Karl Wibergbe579832015-11-10 22:34:18 +0100373 rtc::Optional<float> system_high_adaptation_threshhold;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000374 // Set DSCP value for packet sent from video channel.
Karl Wibergbe579832015-11-10 22:34:18 +0100375 rtc::Optional<bool> dscp;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000376 // Enable WebRTC suspension of video. No video frames will be sent when the
377 // bitrate is below the configured minimum bitrate.
Karl Wibergbe579832015-11-10 22:34:18 +0100378 rtc::Optional<bool> suspend_below_min_bitrate;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000379 // Limit on the number of early receive channels that can be created.
Karl Wibergbe579832015-11-10 22:34:18 +0100380 rtc::Optional<int> unsignalled_recv_stream_limit;
henrike@webrtc.org10bd88e2014-03-11 21:07:25 +0000381 // Enable use of simulcast adapter.
Karl Wibergbe579832015-11-10 22:34:18 +0100382 rtc::Optional<bool> use_simulcast_adapter;
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +0000383 // Force screencast to use a minimum bitrate
Karl Wibergbe579832015-11-10 22:34:18 +0100384 rtc::Optional<int> screencast_min_bitrate;
qiangchen444682a2015-11-24 18:07:56 -0800385 // Set to true if the renderer has an algorithm of frame selection.
386 // If the value is true, then WebRTC will hand over a frame as soon as
387 // possible without delay, and rendering smoothness is completely the duty
388 // of the renderer;
389 // If the value is false, then WebRTC is responsible to delay frame release
390 // in order to increase rendering smoothness.
391 rtc::Optional<bool> disable_prerenderer_smoothing;
kwiberg102c6a62015-10-30 02:47:38 -0700392
393 private:
394 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100395 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700396 if (o) {
397 *s = o;
398 }
399 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400};
401
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402struct RtpHeaderExtension {
403 RtpHeaderExtension() : id(0) {}
404 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405
406 bool operator==(const RtpHeaderExtension& ext) const {
407 // id is a reserved word in objective-c. Therefore the id attribute has to
408 // be a fully qualified name in order to compile on IOS.
409 return this->id == ext.id &&
410 uri == ext.uri;
411 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700412
413 std::string ToString() const {
414 std::ostringstream ost;
415 ost << "{";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700416 ost << "uri: " << uri;
solenberg7e4e01a2015-12-02 08:05:01 -0800417 ost << ", id: " << id;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700418 ost << "}";
419 return ost.str();
420 }
421
422 std::string uri;
423 int id;
424 // TODO(juberti): SendRecv direction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425};
426
427// Returns the named header extension if found among all extensions, NULL
428// otherwise.
429inline const RtpHeaderExtension* FindHeaderExtension(
430 const std::vector<RtpHeaderExtension>& extensions,
431 const std::string& name) {
432 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
433 it != extensions.end(); ++it) {
434 if (it->uri == name)
435 return &(*it);
436 }
437 return NULL;
438}
439
440enum MediaChannelOptions {
441 // Tune the stream for conference mode.
442 OPT_CONFERENCE = 0x0001
443};
444
445enum VoiceMediaChannelOptions {
446 // Tune the audio stream for vcs with different target levels.
447 OPT_AGC_MINUS_10DB = 0x80000000
448};
449
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450class MediaChannel : public sigslot::has_slots<> {
451 public:
452 class NetworkInterface {
453 public:
454 enum SocketType { ST_RTP, ST_RTCP };
stefanc1aeaf02015-10-15 07:26:07 -0700455 virtual bool SendPacket(rtc::Buffer* packet,
456 const rtc::PacketOptions& options) = 0;
457 virtual bool SendRtcp(rtc::Buffer* packet,
458 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000459 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460 int option) = 0;
461 virtual ~NetworkInterface() {}
462 };
463
464 MediaChannel() : network_interface_(NULL) {}
465 virtual ~MediaChannel() {}
466
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000467 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000469 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470 network_interface_ = iface;
471 }
472
473 // Called when a RTP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000474 virtual void OnPacketReceived(rtc::Buffer* packet,
475 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476 // Called when a RTCP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000477 virtual void OnRtcpReceived(rtc::Buffer* packet,
478 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 // Called when the socket's ability to send has changed.
480 virtual void OnReadyToSend(bool ready) = 0;
481 // Creates a new outgoing media stream with SSRCs and CNAME as described
482 // by sp.
483 virtual bool AddSendStream(const StreamParams& sp) = 0;
484 // Removes an outgoing media stream.
485 // ssrc must be the first SSRC of the media stream if the stream uses
486 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200487 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488 // Creates a new incoming media stream with SSRCs and CNAME as described
489 // by sp.
490 virtual bool AddRecvStream(const StreamParams& sp) = 0;
491 // Removes an incoming media stream.
492 // ssrc must be the first SSRC of the media stream if the stream uses
493 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200494 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000495
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000496 // Returns the absoulte sendtime extension id value from media channel.
497 virtual int GetRtpSendTimeExtnId() const {
498 return -1;
499 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000500
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000501 // Base method to send packet using NetworkInterface.
stefanc1aeaf02015-10-15 07:26:07 -0700502 bool SendPacket(rtc::Buffer* packet, const rtc::PacketOptions& options) {
503 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000504 }
505
stefanc1aeaf02015-10-15 07:26:07 -0700506 bool SendRtcp(rtc::Buffer* packet, const rtc::PacketOptions& options) {
507 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000508 }
509
510 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000511 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000512 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000513 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000514 if (!network_interface_)
515 return -1;
516
517 return network_interface_->SetOption(type, opt, option);
518 }
519
wu@webrtc.orgde305012013-10-31 15:40:38 +0000520 protected:
521 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000522 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000523 int ret;
524 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000525 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000526 value);
527 if (ret == 0) {
528 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000529 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000530 value);
531 }
532 return ret;
533 }
534
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000535 private:
stefanc1aeaf02015-10-15 07:26:07 -0700536 bool DoSendPacket(rtc::Buffer* packet,
537 bool rtcp,
538 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000539 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000540 if (!network_interface_)
541 return false;
542
stefanc1aeaf02015-10-15 07:26:07 -0700543 return (!rtcp) ? network_interface_->SendPacket(packet, options)
544 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000545 }
546
547 // |network_interface_| can be accessed from the worker_thread and
548 // from any MediaEngine threads. This critical section is to protect accessing
549 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000550 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000551 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000552};
553
554enum SendFlags {
555 SEND_NOTHING,
556 SEND_RINGBACKTONE,
557 SEND_MICROPHONE
558};
559
wu@webrtc.org97077a32013-10-25 21:18:33 +0000560// The stats information is structured as follows:
561// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
562// Media contains a vector of SSRC infos that are exclusively used by this
563// media. (SSRCs shared between media streams can't be represented.)
564
565// Information about an SSRC.
566// This data may be locally recorded, or received in an RTCP SR or RR.
567struct SsrcSenderInfo {
568 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000570 timestamp(0) {
571 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200572 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000573 double timestamp; // NTP timestamp, represented as seconds since epoch.
574};
575
576struct SsrcReceiverInfo {
577 SsrcReceiverInfo()
578 : ssrc(0),
579 timestamp(0) {
580 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200581 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000582 double timestamp;
583};
584
585struct MediaSenderInfo {
586 MediaSenderInfo()
587 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588 packets_sent(0),
589 packets_lost(0),
590 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000591 rtt_ms(0) {
592 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000593 void add_ssrc(const SsrcSenderInfo& stat) {
594 local_stats.push_back(stat);
595 }
596 // Temporary utility function for call sites that only provide SSRC.
597 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200598 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000599 SsrcSenderInfo stat;
600 stat.ssrc = ssrc;
601 add_ssrc(stat);
602 }
603 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200604 std::vector<uint32_t> ssrcs() const {
605 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000606 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
607 it != local_stats.end(); ++it) {
608 retval.push_back(it->ssrc);
609 }
610 return retval;
611 }
612 // Utility accessor for clients that make the assumption only one ssrc
613 // exists per media.
614 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200615 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000616 if (local_stats.size() > 0) {
617 return local_stats[0].ssrc;
618 } else {
619 return 0;
620 }
621 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200622 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000623 int packets_sent;
624 int packets_lost;
625 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000626 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000627 std::string codec_name;
628 std::vector<SsrcSenderInfo> local_stats;
629 std::vector<SsrcReceiverInfo> remote_stats;
630};
631
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000632template<class T>
633struct VariableInfo {
634 VariableInfo()
635 : min_val(),
636 mean(0.0),
637 max_val(),
638 variance(0.0) {
639 }
640 T min_val;
641 double mean;
642 T max_val;
643 double variance;
644};
645
wu@webrtc.org97077a32013-10-25 21:18:33 +0000646struct MediaReceiverInfo {
647 MediaReceiverInfo()
648 : bytes_rcvd(0),
649 packets_rcvd(0),
650 packets_lost(0),
651 fraction_lost(0.0) {
652 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000653 void add_ssrc(const SsrcReceiverInfo& stat) {
654 local_stats.push_back(stat);
655 }
656 // Temporary utility function for call sites that only provide SSRC.
657 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200658 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000659 SsrcReceiverInfo stat;
660 stat.ssrc = ssrc;
661 add_ssrc(stat);
662 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200663 std::vector<uint32_t> ssrcs() const {
664 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000665 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
666 it != local_stats.end(); ++it) {
667 retval.push_back(it->ssrc);
668 }
669 return retval;
670 }
671 // Utility accessor for clients that make the assumption only one ssrc
672 // exists per media.
673 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200674 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000675 if (local_stats.size() > 0) {
676 return local_stats[0].ssrc;
677 } else {
678 return 0;
679 }
680 }
681
Peter Boström0c4e06b2015-10-07 12:23:21 +0200682 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000683 int packets_rcvd;
684 int packets_lost;
685 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000686 std::string codec_name;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000687 std::vector<SsrcReceiverInfo> local_stats;
688 std::vector<SsrcSenderInfo> remote_stats;
689};
690
691struct VoiceSenderInfo : public MediaSenderInfo {
692 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000693 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 jitter_ms(0),
695 audio_level(0),
696 aec_quality_min(0.0),
697 echo_delay_median_ms(0),
698 echo_delay_std_ms(0),
699 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000700 echo_return_loss_enhancement(0),
701 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702 }
703
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 int jitter_ms;
706 int audio_level;
707 float aec_quality_min;
708 int echo_delay_median_ms;
709 int echo_delay_std_ms;
710 int echo_return_loss;
711 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000712 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713};
714
wu@webrtc.org97077a32013-10-25 21:18:33 +0000715struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000717 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 jitter_ms(0),
719 jitter_buffer_ms(0),
720 jitter_buffer_preferred_ms(0),
721 delay_estimate_ms(0),
722 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000723 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000724 speech_expand_rate(0),
725 secondary_decoded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200726 accelerate_rate(0),
727 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000728 decoding_calls_to_silence_generator(0),
729 decoding_calls_to_neteq(0),
730 decoding_normal(0),
731 decoding_plc(0),
732 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000733 decoding_plc_cng(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200734 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 int ext_seqnum;
737 int jitter_ms;
738 int jitter_buffer_ms;
739 int jitter_buffer_preferred_ms;
740 int delay_estimate_ms;
741 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000742 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000744 // fraction of synthesized speech inserted through expansion.
745 float speech_expand_rate;
746 // fraction of data out of secondary decoding, including FEC and RED.
747 float secondary_decoded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200748 // Fraction of data removed through time compression.
749 float accelerate_rate;
750 // Fraction of data inserted through time stretching.
751 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000752 int decoding_calls_to_silence_generator;
753 int decoding_calls_to_neteq;
754 int decoding_normal;
755 int decoding_plc;
756 int decoding_cng;
757 int decoding_plc_cng;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000758 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200759 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760};
761
wu@webrtc.org97077a32013-10-25 21:18:33 +0000762struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000764 : packets_cached(0),
765 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000766 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000768 input_frame_width(0),
769 input_frame_height(0),
770 send_frame_width(0),
771 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772 framerate_input(0),
773 framerate_sent(0),
774 nominal_bitrate(0),
775 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000776 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000777 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000778 avg_encode_ms(0),
Peter Boström8ed6a4b2015-03-27 10:01:02 +0100779 encode_usage_percent(0) {
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000780 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000782 std::vector<SsrcGroup> ssrc_groups;
783 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000785 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000787 int input_frame_width;
788 int input_frame_height;
789 int send_frame_width;
790 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 int framerate_input;
792 int framerate_sent;
793 int nominal_bitrate;
794 int preferred_bitrate;
795 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000796 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000797 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000798 int encode_usage_percent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000799 VariableInfo<int> adapt_frame_drops;
800 VariableInfo<int> effects_frame_drops;
801 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802};
803
wu@webrtc.org97077a32013-10-25 21:18:33 +0000804struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000806 : packets_concealed(0),
807 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000808 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 nacks_sent(0),
810 frame_width(0),
811 frame_height(0),
812 framerate_rcvd(0),
813 framerate_decoded(0),
814 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000815 framerate_render_input(0),
816 framerate_render_output(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000817 decode_ms(0),
818 max_decode_ms(0),
819 jitter_buffer_ms(0),
820 min_playout_delay_ms(0),
821 render_delay_ms(0),
822 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000823 current_delay_ms(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000824 capture_start_ntp_time_ms(-1) {
825 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000827 std::vector<SsrcGroup> ssrc_groups;
828 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000830 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 int nacks_sent;
832 int frame_width;
833 int frame_height;
834 int framerate_rcvd;
835 int framerate_decoded;
836 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000837 // Framerate as sent to the renderer.
838 int framerate_render_input;
839 // Framerate that the renderer reports.
840 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000841
842 // All stats below are gathered per-VideoReceiver, but some will be correlated
843 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
844 // structures, reflect this in the new layout.
845
846 // Current frame decode latency.
847 int decode_ms;
848 // Maximum observed frame decode latency.
849 int max_decode_ms;
850 // Jitter (network-related) latency.
851 int jitter_buffer_ms;
852 // Requested minimum playout latency.
853 int min_playout_delay_ms;
854 // Requested latency to account for rendering delay.
855 int render_delay_ms;
856 // Target overall delay: network+decode+render, accounting for
857 // min_playout_delay_ms.
858 int target_delay_ms;
859 // Current overall delay, possibly ramping towards target_delay_ms.
860 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000861
862 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200863 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864};
865
wu@webrtc.org97077a32013-10-25 21:18:33 +0000866struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000868 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 }
870
Peter Boström0c4e06b2015-10-07 12:23:21 +0200871 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872};
873
wu@webrtc.org97077a32013-10-25 21:18:33 +0000874struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000876 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 }
878
Peter Boström0c4e06b2015-10-07 12:23:21 +0200879 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880};
881
882struct BandwidthEstimationInfo {
883 BandwidthEstimationInfo()
884 : available_send_bandwidth(0),
885 available_recv_bandwidth(0),
886 target_enc_bitrate(0),
887 actual_enc_bitrate(0),
888 retransmit_bitrate(0),
889 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000890 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 }
892
893 int available_send_bandwidth;
894 int available_recv_bandwidth;
895 int target_enc_bitrate;
896 int actual_enc_bitrate;
897 int retransmit_bitrate;
898 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000899 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900};
901
902struct VoiceMediaInfo {
903 void Clear() {
904 senders.clear();
905 receivers.clear();
906 }
907 std::vector<VoiceSenderInfo> senders;
908 std::vector<VoiceReceiverInfo> receivers;
909};
910
911struct VideoMediaInfo {
912 void Clear() {
913 senders.clear();
914 receivers.clear();
915 bw_estimations.clear();
916 }
917 std::vector<VideoSenderInfo> senders;
918 std::vector<VideoReceiverInfo> receivers;
919 std::vector<BandwidthEstimationInfo> bw_estimations;
920};
921
922struct DataMediaInfo {
923 void Clear() {
924 senders.clear();
925 receivers.clear();
926 }
927 std::vector<DataSenderInfo> senders;
928 std::vector<DataReceiverInfo> receivers;
929};
930
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700931template <class Codec>
932struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800933 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700934 std::ostringstream ost;
935 ost << "{";
936 ost << "codecs: " << VectorToString(codecs) << ", ";
937 ost << "extensions: " << VectorToString(extensions);
938 ost << "}";
939 return ost.str();
940 }
941
942 std::vector<Codec> codecs;
943 std::vector<RtpHeaderExtension> extensions;
944 // TODO(pthatcher): Add streams.
945};
946
947template <class Codec, class Options>
948struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800949 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700950 std::ostringstream ost;
951 ost << "{";
952 ost << "codecs: " << VectorToString(this->codecs) << ", ";
953 ost << "extensions: " << VectorToString(this->extensions) << ", ";
954 ost << "max_bandiwidth_bps: " << max_bandwidth_bps << ", ";
955 ost << "options: " << options.ToString();
956 ost << "}";
957 return ost.str();
958 }
959
960 int max_bandwidth_bps = -1;
961 Options options;
962};
963
964struct AudioSendParameters : RtpSendParameters<AudioCodec, AudioOptions> {
965};
966
967struct AudioRecvParameters : RtpParameters<AudioCodec> {
968};
969
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970class VoiceMediaChannel : public MediaChannel {
971 public:
972 enum Error {
973 ERROR_NONE = 0, // No error.
974 ERROR_OTHER, // Other errors.
975 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
976 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
977 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
978 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
979 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
980 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
981 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
982 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
983 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
984 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
985 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
986 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
987 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
988 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
989 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
990 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
991 };
992
993 VoiceMediaChannel() {}
994 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200995 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
996 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997 // Starts or stops playout of received audio.
998 virtual bool SetPlayout(bool playout) = 0;
999 // Starts or stops sending (and potentially capture) of local audio.
1000 virtual bool SetSend(SendFlags flag) = 0;
solenberg1dd98f32015-09-10 01:57:14 -07001001 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001002 virtual bool SetAudioSend(uint32_t ssrc,
1003 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -07001004 const AudioOptions* options,
solenberg1dd98f32015-09-10 01:57:14 -07001005 AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 // Gets current energy levels for all incoming streams.
1007 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1008 // Get the current energy level of the stream sent to the speaker.
1009 virtual int GetOutputLevel() = 0;
1010 // Get the time in milliseconds since last recorded keystroke, or negative.
1011 virtual int GetTimeSinceLastTyping() = 0;
1012 // Temporarily exposed field for tuning typing detect options.
1013 virtual void SetTypingDetectionParameters(int time_window,
1014 int cost_per_typing, int reporting_threshold, int penalty_decay,
1015 int type_event_delay) = 0;
solenberg4bac9c52015-10-09 02:32:53 -07001016 // Set speaker output volume of the specified ssrc.
1017 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -08001019 virtual bool CanInsertDtmf() = 0;
1020 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001022 // The valid value for the |event| are 0 to 15 which corresponding to
1023 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -08001024 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025 // Gets quality stats for the channel.
1026 virtual bool GetStats(VoiceMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001027};
1028
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001029struct VideoSendParameters : RtpSendParameters<VideoCodec, VideoOptions> {
1030};
1031
1032struct VideoRecvParameters : RtpParameters<VideoCodec> {
1033};
1034
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035class VideoMediaChannel : public MediaChannel {
1036 public:
1037 enum Error {
1038 ERROR_NONE = 0, // No error.
1039 ERROR_OTHER, // Other errors.
1040 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1041 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1042 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1043 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1044 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1045 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1046 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1047 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1048 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1049 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1050 };
1051
1052 VideoMediaChannel() : renderer_(NULL) {}
1053 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001054
1055 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
1056 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 // Gets the currently set codecs/payload types to be used for outgoing media.
1058 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1059 // Sets the format of a specified outgoing stream.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001060 virtual bool SetSendStreamFormat(uint32_t ssrc,
1061 const VideoFormat& format) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062 // Starts or stops transmission (and potentially capture) of local video.
1063 virtual bool SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -07001064 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001065 virtual bool SetVideoSend(uint32_t ssrc,
1066 bool enable,
solenberg1dd98f32015-09-10 01:57:14 -07001067 const VideoOptions* options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 // Sets the renderer object to be used for the specified stream.
1069 // If SSRC is 0, the renderer is used for the 'default' stream.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001070 virtual bool SetRenderer(uint32_t ssrc, VideoRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1072 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001073 virtual bool SetCapturer(uint32_t ssrc, VideoCapturer* capturer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001075 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 // Send an intra frame to the receivers.
1077 virtual bool SendIntraFrame() = 0;
1078 // Reuqest each of the remote senders to send an intra frame.
1079 virtual bool RequestIntraFrame() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1081
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 protected:
1083 VideoRenderer *renderer_;
1084};
1085
1086enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001087 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1088 // values.
1089 DMT_NONE = 0,
1090 DMT_CONTROL = 1,
1091 DMT_BINARY = 2,
1092 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093};
1094
1095// Info about data received in DataMediaChannel. For use in
1096// DataMediaChannel::SignalDataReceived and in all of the signals that
1097// signal fires, on up the chain.
1098struct ReceiveDataParams {
1099 // The in-packet stream indentifier.
1100 // For SCTP, this is really SID, not SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001101 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 // The type of message (binary, text, or control).
1103 DataMessageType type;
1104 // A per-stream value incremented per packet in the stream.
1105 int seq_num;
1106 // A per-stream value monotonically increasing with time.
1107 int timestamp;
1108
1109 ReceiveDataParams() :
1110 ssrc(0),
1111 type(DMT_TEXT),
1112 seq_num(0),
1113 timestamp(0) {
1114 }
1115};
1116
1117struct SendDataParams {
1118 // The in-packet stream indentifier.
1119 // For SCTP, this is really SID, not SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001120 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 // The type of message (binary, text, or control).
1122 DataMessageType type;
1123
1124 // For SCTP, whether to send messages flagged as ordered or not.
1125 // If false, messages can be received out of order.
1126 bool ordered;
1127 // For SCTP, whether the messages are sent reliably or not.
1128 // If false, messages may be lost.
1129 bool reliable;
1130 // For SCTP, if reliable == false, provide partial reliability by
1131 // resending up to this many times. Either count or millis
1132 // is supported, not both at the same time.
1133 int max_rtx_count;
1134 // For SCTP, if reliable == false, provide partial reliability by
1135 // resending for up to this many milliseconds. Either count or millis
1136 // is supported, not both at the same time.
1137 int max_rtx_ms;
1138
1139 SendDataParams() :
1140 ssrc(0),
1141 type(DMT_TEXT),
1142 // TODO(pthatcher): Make these true by default?
1143 ordered(false),
1144 reliable(false),
1145 max_rtx_count(0),
1146 max_rtx_ms(0) {
1147 }
1148};
1149
1150enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1151
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001152struct DataOptions {
solenberg7e4e01a2015-12-02 08:05:01 -08001153 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001154 return "{}";
1155 }
1156};
1157
1158struct DataSendParameters : RtpSendParameters<DataCodec, DataOptions> {
solenberg7e4e01a2015-12-02 08:05:01 -08001159 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001160 std::ostringstream ost;
1161 // Options and extensions aren't used.
1162 ost << "{";
1163 ost << "codecs: " << VectorToString(codecs) << ", ";
1164 ost << "max_bandiwidth_bps: " << max_bandwidth_bps;
1165 ost << "}";
1166 return ost.str();
1167 }
1168};
1169
1170struct DataRecvParameters : RtpParameters<DataCodec> {
1171};
1172
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001173class DataMediaChannel : public MediaChannel {
1174 public:
1175 enum Error {
1176 ERROR_NONE = 0, // No error.
1177 ERROR_OTHER, // Other errors.
1178 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1179 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1180 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1181 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1182 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1183 };
1184
1185 virtual ~DataMediaChannel() {}
1186
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001187 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1188 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001189
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001190 // TODO(pthatcher): Implement this.
1191 virtual bool GetStats(DataMediaInfo* info) { return true; }
1192
1193 virtual bool SetSend(bool send) = 0;
1194 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001195
1196 virtual bool SendData(
1197 const SendDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001198 const rtc::Buffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001199 SendDataResult* result = NULL) = 0;
1200 // Signals when data is received (params, data, len)
1201 sigslot::signal3<const ReceiveDataParams&,
1202 const char*,
1203 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001204 // Signal when the media channel is ready to send the stream. Arguments are:
1205 // writable(bool)
1206 sigslot::signal1<bool> SignalReadyToSend;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001207 // Signal for notifying that the remote side has closed the DataChannel.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001208 sigslot::signal1<uint32_t> SignalStreamClosedRemotely;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001209};
1210
1211} // namespace cricket
1212
1213#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_