blob: fe223bba0418d27454aae73cb6b3dc2be3df392a [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,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 SEND_MICROPHONE
557};
558
wu@webrtc.org97077a32013-10-25 21:18:33 +0000559// The stats information is structured as follows:
560// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
561// Media contains a vector of SSRC infos that are exclusively used by this
562// media. (SSRCs shared between media streams can't be represented.)
563
564// Information about an SSRC.
565// This data may be locally recorded, or received in an RTCP SR or RR.
566struct SsrcSenderInfo {
567 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000569 timestamp(0) {
570 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200571 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000572 double timestamp; // NTP timestamp, represented as seconds since epoch.
573};
574
575struct SsrcReceiverInfo {
576 SsrcReceiverInfo()
577 : ssrc(0),
578 timestamp(0) {
579 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200580 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000581 double timestamp;
582};
583
584struct MediaSenderInfo {
585 MediaSenderInfo()
586 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587 packets_sent(0),
588 packets_lost(0),
589 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000590 rtt_ms(0) {
591 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000592 void add_ssrc(const SsrcSenderInfo& stat) {
593 local_stats.push_back(stat);
594 }
595 // Temporary utility function for call sites that only provide SSRC.
596 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200597 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000598 SsrcSenderInfo stat;
599 stat.ssrc = ssrc;
600 add_ssrc(stat);
601 }
602 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200603 std::vector<uint32_t> ssrcs() const {
604 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000605 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
606 it != local_stats.end(); ++it) {
607 retval.push_back(it->ssrc);
608 }
609 return retval;
610 }
611 // Utility accessor for clients that make the assumption only one ssrc
612 // exists per media.
613 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200614 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000615 if (local_stats.size() > 0) {
616 return local_stats[0].ssrc;
617 } else {
618 return 0;
619 }
620 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200621 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000622 int packets_sent;
623 int packets_lost;
624 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000625 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000626 std::string codec_name;
627 std::vector<SsrcSenderInfo> local_stats;
628 std::vector<SsrcReceiverInfo> remote_stats;
629};
630
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000631template<class T>
632struct VariableInfo {
633 VariableInfo()
634 : min_val(),
635 mean(0.0),
636 max_val(),
637 variance(0.0) {
638 }
639 T min_val;
640 double mean;
641 T max_val;
642 double variance;
643};
644
wu@webrtc.org97077a32013-10-25 21:18:33 +0000645struct MediaReceiverInfo {
646 MediaReceiverInfo()
647 : bytes_rcvd(0),
648 packets_rcvd(0),
649 packets_lost(0),
650 fraction_lost(0.0) {
651 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000652 void add_ssrc(const SsrcReceiverInfo& stat) {
653 local_stats.push_back(stat);
654 }
655 // Temporary utility function for call sites that only provide SSRC.
656 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200657 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000658 SsrcReceiverInfo stat;
659 stat.ssrc = ssrc;
660 add_ssrc(stat);
661 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200662 std::vector<uint32_t> ssrcs() const {
663 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000664 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
665 it != local_stats.end(); ++it) {
666 retval.push_back(it->ssrc);
667 }
668 return retval;
669 }
670 // Utility accessor for clients that make the assumption only one ssrc
671 // exists per media.
672 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200673 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000674 if (local_stats.size() > 0) {
675 return local_stats[0].ssrc;
676 } else {
677 return 0;
678 }
679 }
680
Peter Boström0c4e06b2015-10-07 12:23:21 +0200681 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000682 int packets_rcvd;
683 int packets_lost;
684 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000685 std::string codec_name;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000686 std::vector<SsrcReceiverInfo> local_stats;
687 std::vector<SsrcSenderInfo> remote_stats;
688};
689
690struct VoiceSenderInfo : public MediaSenderInfo {
691 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000692 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 jitter_ms(0),
694 audio_level(0),
695 aec_quality_min(0.0),
696 echo_delay_median_ms(0),
697 echo_delay_std_ms(0),
698 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000699 echo_return_loss_enhancement(0),
700 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 }
702
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 int jitter_ms;
705 int audio_level;
706 float aec_quality_min;
707 int echo_delay_median_ms;
708 int echo_delay_std_ms;
709 int echo_return_loss;
710 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000711 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712};
713
wu@webrtc.org97077a32013-10-25 21:18:33 +0000714struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000716 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 jitter_ms(0),
718 jitter_buffer_ms(0),
719 jitter_buffer_preferred_ms(0),
720 delay_estimate_ms(0),
721 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000722 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000723 speech_expand_rate(0),
724 secondary_decoded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200725 accelerate_rate(0),
726 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000727 decoding_calls_to_silence_generator(0),
728 decoding_calls_to_neteq(0),
729 decoding_normal(0),
730 decoding_plc(0),
731 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000732 decoding_plc_cng(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200733 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 int ext_seqnum;
736 int jitter_ms;
737 int jitter_buffer_ms;
738 int jitter_buffer_preferred_ms;
739 int delay_estimate_ms;
740 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000741 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000743 // fraction of synthesized speech inserted through expansion.
744 float speech_expand_rate;
745 // fraction of data out of secondary decoding, including FEC and RED.
746 float secondary_decoded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200747 // Fraction of data removed through time compression.
748 float accelerate_rate;
749 // Fraction of data inserted through time stretching.
750 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000751 int decoding_calls_to_silence_generator;
752 int decoding_calls_to_neteq;
753 int decoding_normal;
754 int decoding_plc;
755 int decoding_cng;
756 int decoding_plc_cng;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000757 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200758 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759};
760
wu@webrtc.org97077a32013-10-25 21:18:33 +0000761struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000763 : packets_cached(0),
764 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000765 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000767 input_frame_width(0),
768 input_frame_height(0),
769 send_frame_width(0),
770 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771 framerate_input(0),
772 framerate_sent(0),
773 nominal_bitrate(0),
774 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000775 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000776 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000777 avg_encode_ms(0),
Peter Boström8ed6a4b2015-03-27 10:01:02 +0100778 encode_usage_percent(0) {
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000779 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000781 std::vector<SsrcGroup> ssrc_groups;
782 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000784 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000786 int input_frame_width;
787 int input_frame_height;
788 int send_frame_width;
789 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 int framerate_input;
791 int framerate_sent;
792 int nominal_bitrate;
793 int preferred_bitrate;
794 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000795 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000796 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000797 int encode_usage_percent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000798 VariableInfo<int> adapt_frame_drops;
799 VariableInfo<int> effects_frame_drops;
800 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801};
802
wu@webrtc.org97077a32013-10-25 21:18:33 +0000803struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000805 : packets_concealed(0),
806 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000807 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 nacks_sent(0),
809 frame_width(0),
810 frame_height(0),
811 framerate_rcvd(0),
812 framerate_decoded(0),
813 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000814 framerate_render_input(0),
815 framerate_render_output(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000816 decode_ms(0),
817 max_decode_ms(0),
818 jitter_buffer_ms(0),
819 min_playout_delay_ms(0),
820 render_delay_ms(0),
821 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000822 current_delay_ms(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000823 capture_start_ntp_time_ms(-1) {
824 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000826 std::vector<SsrcGroup> ssrc_groups;
827 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000829 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 int nacks_sent;
831 int frame_width;
832 int frame_height;
833 int framerate_rcvd;
834 int framerate_decoded;
835 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000836 // Framerate as sent to the renderer.
837 int framerate_render_input;
838 // Framerate that the renderer reports.
839 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000840
841 // All stats below are gathered per-VideoReceiver, but some will be correlated
842 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
843 // structures, reflect this in the new layout.
844
845 // Current frame decode latency.
846 int decode_ms;
847 // Maximum observed frame decode latency.
848 int max_decode_ms;
849 // Jitter (network-related) latency.
850 int jitter_buffer_ms;
851 // Requested minimum playout latency.
852 int min_playout_delay_ms;
853 // Requested latency to account for rendering delay.
854 int render_delay_ms;
855 // Target overall delay: network+decode+render, accounting for
856 // min_playout_delay_ms.
857 int target_delay_ms;
858 // Current overall delay, possibly ramping towards target_delay_ms.
859 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000860
861 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200862 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863};
864
wu@webrtc.org97077a32013-10-25 21:18:33 +0000865struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000867 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 }
869
Peter Boström0c4e06b2015-10-07 12:23:21 +0200870 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871};
872
wu@webrtc.org97077a32013-10-25 21:18:33 +0000873struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000875 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 }
877
Peter Boström0c4e06b2015-10-07 12:23:21 +0200878 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879};
880
881struct BandwidthEstimationInfo {
882 BandwidthEstimationInfo()
883 : available_send_bandwidth(0),
884 available_recv_bandwidth(0),
885 target_enc_bitrate(0),
886 actual_enc_bitrate(0),
887 retransmit_bitrate(0),
888 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000889 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 }
891
892 int available_send_bandwidth;
893 int available_recv_bandwidth;
894 int target_enc_bitrate;
895 int actual_enc_bitrate;
896 int retransmit_bitrate;
897 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000898 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899};
900
901struct VoiceMediaInfo {
902 void Clear() {
903 senders.clear();
904 receivers.clear();
905 }
906 std::vector<VoiceSenderInfo> senders;
907 std::vector<VoiceReceiverInfo> receivers;
908};
909
910struct VideoMediaInfo {
911 void Clear() {
912 senders.clear();
913 receivers.clear();
914 bw_estimations.clear();
915 }
916 std::vector<VideoSenderInfo> senders;
917 std::vector<VideoReceiverInfo> receivers;
918 std::vector<BandwidthEstimationInfo> bw_estimations;
919};
920
921struct DataMediaInfo {
922 void Clear() {
923 senders.clear();
924 receivers.clear();
925 }
926 std::vector<DataSenderInfo> senders;
927 std::vector<DataReceiverInfo> receivers;
928};
929
deadbeef13871492015-12-09 12:37:51 -0800930struct RtcpParameters {
931 bool reduced_size = false;
932};
933
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700934template <class Codec>
935struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800936 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700937 std::ostringstream ost;
938 ost << "{";
939 ost << "codecs: " << VectorToString(codecs) << ", ";
940 ost << "extensions: " << VectorToString(extensions);
941 ost << "}";
942 return ost.str();
943 }
944
945 std::vector<Codec> codecs;
946 std::vector<RtpHeaderExtension> extensions;
947 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800948 RtcpParameters rtcp;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700949};
950
951template <class Codec, class Options>
952struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800953 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700954 std::ostringstream ost;
955 ost << "{";
956 ost << "codecs: " << VectorToString(this->codecs) << ", ";
957 ost << "extensions: " << VectorToString(this->extensions) << ", ";
958 ost << "max_bandiwidth_bps: " << max_bandwidth_bps << ", ";
959 ost << "options: " << options.ToString();
960 ost << "}";
961 return ost.str();
962 }
963
964 int max_bandwidth_bps = -1;
965 Options options;
966};
967
968struct AudioSendParameters : RtpSendParameters<AudioCodec, AudioOptions> {
969};
970
971struct AudioRecvParameters : RtpParameters<AudioCodec> {
972};
973
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974class VoiceMediaChannel : public MediaChannel {
975 public:
976 enum Error {
977 ERROR_NONE = 0, // No error.
978 ERROR_OTHER, // Other errors.
979 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
980 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
981 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
982 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
983 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
984 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
985 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
986 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
987 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
988 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
989 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
990 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
991 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
992 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
993 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
994 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
995 };
996
997 VoiceMediaChannel() {}
998 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200999 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
1000 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 // Starts or stops playout of received audio.
1002 virtual bool SetPlayout(bool playout) = 0;
1003 // Starts or stops sending (and potentially capture) of local audio.
1004 virtual bool SetSend(SendFlags flag) = 0;
solenberg1dd98f32015-09-10 01:57:14 -07001005 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001006 virtual bool SetAudioSend(uint32_t ssrc,
1007 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -07001008 const AudioOptions* options,
solenberg1dd98f32015-09-10 01:57:14 -07001009 AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010 // Gets current energy levels for all incoming streams.
1011 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1012 // Get the current energy level of the stream sent to the speaker.
1013 virtual int GetOutputLevel() = 0;
1014 // Get the time in milliseconds since last recorded keystroke, or negative.
1015 virtual int GetTimeSinceLastTyping() = 0;
1016 // Temporarily exposed field for tuning typing detect options.
1017 virtual void SetTypingDetectionParameters(int time_window,
1018 int cost_per_typing, int reporting_threshold, int penalty_decay,
1019 int type_event_delay) = 0;
solenberg4bac9c52015-10-09 02:32:53 -07001020 // Set speaker output volume of the specified ssrc.
1021 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -08001023 virtual bool CanInsertDtmf() = 0;
1024 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001026 // The valid value for the |event| are 0 to 15 which corresponding to
1027 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -08001028 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 // Gets quality stats for the channel.
1030 virtual bool GetStats(VoiceMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031};
1032
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001033struct VideoSendParameters : RtpSendParameters<VideoCodec, VideoOptions> {
1034};
1035
1036struct VideoRecvParameters : RtpParameters<VideoCodec> {
1037};
1038
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039class VideoMediaChannel : public MediaChannel {
1040 public:
1041 enum Error {
1042 ERROR_NONE = 0, // No error.
1043 ERROR_OTHER, // Other errors.
1044 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1045 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1046 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1047 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1048 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1049 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1050 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1051 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1052 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1053 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1054 };
1055
1056 VideoMediaChannel() : renderer_(NULL) {}
1057 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001058
1059 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
1060 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 // Gets the currently set codecs/payload types to be used for outgoing media.
1062 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
1063 // Sets the format of a specified outgoing stream.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001064 virtual bool SetSendStreamFormat(uint32_t ssrc,
1065 const VideoFormat& format) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001066 // Starts or stops transmission (and potentially capture) of local video.
1067 virtual bool SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -07001068 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001069 virtual bool SetVideoSend(uint32_t ssrc,
1070 bool enable,
solenberg1dd98f32015-09-10 01:57:14 -07001071 const VideoOptions* options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 // Sets the renderer object to be used for the specified stream.
1073 // If SSRC is 0, the renderer is used for the 'default' stream.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001074 virtual bool SetRenderer(uint32_t ssrc, VideoRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1076 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001077 virtual bool SetCapturer(uint32_t ssrc, VideoCapturer* capturer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001079 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 // Send an intra frame to the receivers.
1081 virtual bool SendIntraFrame() = 0;
1082 // Reuqest each of the remote senders to send an intra frame.
1083 virtual bool RequestIntraFrame() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1085
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 protected:
1087 VideoRenderer *renderer_;
1088};
1089
1090enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001091 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1092 // values.
1093 DMT_NONE = 0,
1094 DMT_CONTROL = 1,
1095 DMT_BINARY = 2,
1096 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097};
1098
1099// Info about data received in DataMediaChannel. For use in
1100// DataMediaChannel::SignalDataReceived and in all of the signals that
1101// signal fires, on up the chain.
1102struct ReceiveDataParams {
1103 // The in-packet stream indentifier.
1104 // For SCTP, this is really SID, not SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001105 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 // The type of message (binary, text, or control).
1107 DataMessageType type;
1108 // A per-stream value incremented per packet in the stream.
1109 int seq_num;
1110 // A per-stream value monotonically increasing with time.
1111 int timestamp;
1112
1113 ReceiveDataParams() :
1114 ssrc(0),
1115 type(DMT_TEXT),
1116 seq_num(0),
1117 timestamp(0) {
1118 }
1119};
1120
1121struct SendDataParams {
1122 // The in-packet stream indentifier.
1123 // For SCTP, this is really SID, not SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001124 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001125 // The type of message (binary, text, or control).
1126 DataMessageType type;
1127
1128 // For SCTP, whether to send messages flagged as ordered or not.
1129 // If false, messages can be received out of order.
1130 bool ordered;
1131 // For SCTP, whether the messages are sent reliably or not.
1132 // If false, messages may be lost.
1133 bool reliable;
1134 // For SCTP, if reliable == false, provide partial reliability by
1135 // resending up to this many times. Either count or millis
1136 // is supported, not both at the same time.
1137 int max_rtx_count;
1138 // For SCTP, if reliable == false, provide partial reliability by
1139 // resending for up to this many milliseconds. Either count or millis
1140 // is supported, not both at the same time.
1141 int max_rtx_ms;
1142
1143 SendDataParams() :
1144 ssrc(0),
1145 type(DMT_TEXT),
1146 // TODO(pthatcher): Make these true by default?
1147 ordered(false),
1148 reliable(false),
1149 max_rtx_count(0),
1150 max_rtx_ms(0) {
1151 }
1152};
1153
1154enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1155
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001156struct DataOptions {
solenberg7e4e01a2015-12-02 08:05:01 -08001157 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001158 return "{}";
1159 }
1160};
1161
1162struct DataSendParameters : RtpSendParameters<DataCodec, DataOptions> {
solenberg7e4e01a2015-12-02 08:05:01 -08001163 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001164 std::ostringstream ost;
1165 // Options and extensions aren't used.
1166 ost << "{";
1167 ost << "codecs: " << VectorToString(codecs) << ", ";
1168 ost << "max_bandiwidth_bps: " << max_bandwidth_bps;
1169 ost << "}";
1170 return ost.str();
1171 }
1172};
1173
1174struct DataRecvParameters : RtpParameters<DataCodec> {
1175};
1176
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001177class DataMediaChannel : public MediaChannel {
1178 public:
1179 enum Error {
1180 ERROR_NONE = 0, // No error.
1181 ERROR_OTHER, // Other errors.
1182 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1183 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1184 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1185 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1186 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1187 };
1188
1189 virtual ~DataMediaChannel() {}
1190
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001191 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1192 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001193
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001194 // TODO(pthatcher): Implement this.
1195 virtual bool GetStats(DataMediaInfo* info) { return true; }
1196
1197 virtual bool SetSend(bool send) = 0;
1198 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001199
1200 virtual bool SendData(
1201 const SendDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001202 const rtc::Buffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001203 SendDataResult* result = NULL) = 0;
1204 // Signals when data is received (params, data, len)
1205 sigslot::signal3<const ReceiveDataParams&,
1206 const char*,
1207 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001208 // Signal when the media channel is ready to send the stream. Arguments are:
1209 // writable(bool)
1210 sigslot::signal1<bool> SignalReadyToSend;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001211 // Signal for notifying that the remote side has closed the DataChannel.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001212 sigslot::signal1<uint32_t> SignalStreamClosedRemotely;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213};
1214
1215} // namespace cricket
1216
1217#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_