blob: 4c6b024947b087c6a697e0143aa01c3df5f79383 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kjellandera96e2d72016-02-04 23:52:28 -080011#ifndef WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_
12#define WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
terelius54f91712016-06-01 11:18:56 -070014#include <algorithm>
kwiberg686a8ef2016-02-26 03:00:35 -080015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
17#include <vector>
18
skvladdc1c62c2016-03-16 19:07:43 -070019#include "webrtc/api/rtpparameters.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000020#include "webrtc/base/basictypes.h"
kwiberga4ac4782016-04-29 08:00:22 -070021#include "webrtc/base/buffer.h"
jbaucheec21bd2016-03-20 06:15:43 -070022#include "webrtc/base/copyonwritebuffer.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000023#include "webrtc/base/dscp.h"
24#include "webrtc/base/logging.h"
Honghai Zhangcc411c02016-03-29 17:27:21 -070025#include "webrtc/base/networkroute.h"
Karl Wibergbe579832015-11-10 22:34:18 +010026#include "webrtc/base/optional.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000027#include "webrtc/base/sigslot.h"
28#include "webrtc/base/socket.h"
29#include "webrtc/base/window.h"
isheriff6f8d6862016-05-26 11:24:55 -070030#include "webrtc/config.h"
kjellandera96e2d72016-02-04 23:52:28 -080031#include "webrtc/media/base/codec.h"
kjellanderf4752772016-03-02 05:42:30 -080032#include "webrtc/media/base/mediaconstants.h"
kjellandera96e2d72016-02-04 23:52:28 -080033#include "webrtc/media/base/streamparams.h"
nisse08582ff2016-02-04 01:24:52 -080034#include "webrtc/media/base/videosinkinterface.h"
nisse2ded9b12016-04-08 02:23:55 -070035#include "webrtc/media/base/videosourceinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036// TODO(juberti): re-evaluate this include
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010037#include "webrtc/pc/audiomonitor.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000039namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040class RateLimiter;
41class Timing;
42}
43
Tommif888bb52015-12-12 01:37:01 +010044namespace webrtc {
45class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080046class VideoFrame;
Tommif888bb52015-12-12 01:37:01 +010047}
48
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049namespace cricket {
50
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080051class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080053struct RtpHeader;
54struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056const int kScreencastDefaultFps = 5;
57
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058template <class T>
Karl Wibergbe579832015-11-10 22:34:18 +010059static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070061 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062 str = key;
63 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070064 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065 str += ", ";
66 }
67 return str;
68}
69
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070070template <class T>
71static std::string VectorToString(const std::vector<T>& vals) {
72 std::ostringstream ost;
73 ost << "[";
74 for (size_t i = 0; i < vals.size(); ++i) {
75 if (i > 0) {
76 ost << ", ";
77 }
78 ost << vals[i].ToString();
79 }
80 ost << "]";
81 return ost.str();
82}
83
skvladdc1c62c2016-03-16 19:07:43 -070084template <typename T>
85static T MinPositive(T a, T b) {
86 if (a <= 0) {
87 return b;
88 }
89 if (b <= 0) {
90 return a;
91 }
92 return std::min(a, b);
93}
94
nisse51542be2016-02-12 02:27:06 -080095// Construction-time settings, passed to
96// MediaControllerInterface::Create, and passed on when creating
97// MediaChannels.
98struct MediaConfig {
99 // Set DSCP value on packets. This flag comes from the
100 // PeerConnection constraint 'googDscp'.
101 bool enable_dscp = false;
102
nisse0db023a2016-03-01 04:29:59 -0800103 // Video-specific config.
104 struct Video {
105 // Enable WebRTC CPU Overuse Detection. This flag comes from the
perkj803d97f2016-11-01 11:45:46 -0700106 // PeerConnection constraint 'googCpuOveruseDetection'.
nisse0db023a2016-03-01 04:29:59 -0800107 bool enable_cpu_overuse_detection = true;
nisse51542be2016-02-12 02:27:06 -0800108
nisse0db023a2016-03-01 04:29:59 -0800109 // Enable WebRTC suspension of video. No video frames will be sent
110 // when the bitrate is below the configured minimum bitrate. This
111 // flag comes from the PeerConnection constraint
112 // 'googSuspendBelowMinBitrate', and WebRtcVideoChannel2 copies it
113 // to VideoSendStream::Config::suspend_below_min_bitrate.
114 bool suspend_below_min_bitrate = false;
nisse51542be2016-02-12 02:27:06 -0800115
nisse0db023a2016-03-01 04:29:59 -0800116 // Set to true if the renderer has an algorithm of frame selection.
117 // If the value is true, then WebRTC will hand over a frame as soon as
118 // possible without delay, and rendering smoothness is completely the duty
119 // of the renderer;
120 // If the value is false, then WebRTC is responsible to delay frame release
121 // in order to increase rendering smoothness.
122 //
123 // This flag comes from PeerConnection's RtcConfiguration, but is
124 // currently only set by the command line flag
125 // 'disable-rtc-smoothness-algorithm'.
126 // WebRtcVideoChannel2::AddRecvStream copies it to the created
127 // WebRtcVideoReceiveStream, where it is returned by the
128 // SmoothsRenderedFrames method. This method is used by the
129 // VideoReceiveStream, where the value is passed on to the
130 // IncomingVideoStream constructor.
131 bool disable_prerenderer_smoothing = false;
sergeyu80ed35e2016-11-28 13:11:13 -0800132
133 // Enables periodic bandwidth probing in application-limited region.
134 bool periodic_alr_bandwidth_probing = false;
nisse0db023a2016-03-01 04:29:59 -0800135 } video;
nisse51542be2016-02-12 02:27:06 -0800136};
137
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
139// Used to be flags, but that makes it hard to selectively apply options.
140// We are moving all of the setting of options to structs like this,
141// but some things currently still use flags.
142struct AudioOptions {
143 void SetAll(const AudioOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700144 SetFrom(&echo_cancellation, change.echo_cancellation);
145 SetFrom(&auto_gain_control, change.auto_gain_control);
146 SetFrom(&noise_suppression, change.noise_suppression);
147 SetFrom(&highpass_filter, change.highpass_filter);
148 SetFrom(&stereo_swapping, change.stereo_swapping);
149 SetFrom(&audio_jitter_buffer_max_packets,
150 change.audio_jitter_buffer_max_packets);
151 SetFrom(&audio_jitter_buffer_fast_accelerate,
152 change.audio_jitter_buffer_fast_accelerate);
153 SetFrom(&typing_detection, change.typing_detection);
154 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise);
kwiberg102c6a62015-10-30 02:47:38 -0700155 SetFrom(&adjust_agc_delta, change.adjust_agc_delta);
156 SetFrom(&experimental_agc, change.experimental_agc);
157 SetFrom(&extended_filter_aec, change.extended_filter_aec);
158 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec);
159 SetFrom(&experimental_ns, change.experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700160 SetFrom(&intelligibility_enhancer, change.intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700161 SetFrom(&level_control, change.level_control);
ivocb829d9f2016-11-15 02:34:47 -0800162 SetFrom(&residual_echo_detector, change.residual_echo_detector);
kwiberg102c6a62015-10-30 02:47:38 -0700163 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov);
164 SetFrom(&tx_agc_digital_compression_gain,
165 change.tx_agc_digital_compression_gain);
166 SetFrom(&tx_agc_limiter, change.tx_agc_limiter);
167 SetFrom(&recording_sample_rate, change.recording_sample_rate);
168 SetFrom(&playout_sample_rate, change.playout_sample_rate);
kwiberg102c6a62015-10-30 02:47:38 -0700169 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700170 SetFrom(&audio_network_adaptor, change.audio_network_adaptor);
171 SetFrom(&audio_network_adaptor_config, change.audio_network_adaptor_config);
aleloie33c5d92016-10-20 01:53:27 -0700172 SetFrom(&level_control_initial_peak_level_dbfs,
173 change.level_control_initial_peak_level_dbfs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 }
175
176 bool operator==(const AudioOptions& o) const {
177 return echo_cancellation == o.echo_cancellation &&
peaha3333bf2016-06-30 00:02:34 -0700178 auto_gain_control == o.auto_gain_control &&
179 noise_suppression == o.noise_suppression &&
180 highpass_filter == o.highpass_filter &&
181 stereo_swapping == o.stereo_swapping &&
182 audio_jitter_buffer_max_packets ==
183 o.audio_jitter_buffer_max_packets &&
184 audio_jitter_buffer_fast_accelerate ==
185 o.audio_jitter_buffer_fast_accelerate &&
186 typing_detection == o.typing_detection &&
187 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
188 experimental_agc == o.experimental_agc &&
189 extended_filter_aec == o.extended_filter_aec &&
190 delay_agnostic_aec == o.delay_agnostic_aec &&
191 experimental_ns == o.experimental_ns &&
192 intelligibility_enhancer == o.intelligibility_enhancer &&
193 level_control == o.level_control &&
ivocb829d9f2016-11-15 02:34:47 -0800194 residual_echo_detector == o.residual_echo_detector &&
peaha3333bf2016-06-30 00:02:34 -0700195 adjust_agc_delta == o.adjust_agc_delta &&
196 tx_agc_target_dbov == o.tx_agc_target_dbov &&
197 tx_agc_digital_compression_gain ==
198 o.tx_agc_digital_compression_gain &&
199 tx_agc_limiter == o.tx_agc_limiter &&
200 recording_sample_rate == o.recording_sample_rate &&
201 playout_sample_rate == o.playout_sample_rate &&
aleloie33c5d92016-10-20 01:53:27 -0700202 combined_audio_video_bwe == o.combined_audio_video_bwe &&
minyue6b825df2016-10-31 04:08:32 -0700203 audio_network_adaptor == o.audio_network_adaptor &&
204 audio_network_adaptor_config == o.audio_network_adaptor_config &&
aleloie33c5d92016-10-20 01:53:27 -0700205 level_control_initial_peak_level_dbfs ==
206 o.level_control_initial_peak_level_dbfs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 }
deadbeef119760a2016-04-04 11:43:27 -0700208 bool operator!=(const AudioOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209
210 std::string ToString() const {
211 std::ostringstream ost;
212 ost << "AudioOptions {";
213 ost << ToStringIfSet("aec", echo_cancellation);
214 ost << ToStringIfSet("agc", auto_gain_control);
215 ost << ToStringIfSet("ns", noise_suppression);
216 ost << ToStringIfSet("hf", highpass_filter);
217 ost << ToStringIfSet("swap", stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200218 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
219 audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200220 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
221 audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000223 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
225 ost << ToStringIfSet("experimental_agc", experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200226 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100227 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000228 ost << ToStringIfSet("experimental_ns", experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700229 ost << ToStringIfSet("intelligibility_enhancer", intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700230 ost << ToStringIfSet("level_control", level_control);
aleloie33c5d92016-10-20 01:53:27 -0700231 ost << ToStringIfSet("level_control_initial_peak_level_dbfs",
232 level_control_initial_peak_level_dbfs);
ivocb829d9f2016-11-15 02:34:47 -0800233 ost << ToStringIfSet("residual_echo_detector", residual_echo_detector);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000234 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
235 ost << ToStringIfSet("tx_agc_digital_compression_gain",
236 tx_agc_digital_compression_gain);
237 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000238 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
239 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000240 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700241 ost << ToStringIfSet("audio_network_adaptor", audio_network_adaptor);
242 // The adaptor config is a serialized proto buffer and therefore not human
243 // readable. So we comment out the following line.
244 // ost << ToStringIfSet("audio_network_adaptor_config",
245 // audio_network_adaptor_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246 ost << "}";
247 return ost.str();
248 }
249
250 // Audio processing that attempts to filter away the output signal from
251 // later inbound pickup.
Karl Wibergbe579832015-11-10 22:34:18 +0100252 rtc::Optional<bool> echo_cancellation;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 // Audio processing to adjust the sensitivity of the local mic dynamically.
Karl Wibergbe579832015-11-10 22:34:18 +0100254 rtc::Optional<bool> auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 // Audio processing to filter out background noise.
Karl Wibergbe579832015-11-10 22:34:18 +0100256 rtc::Optional<bool> noise_suppression;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 // Audio processing to remove background noise of lower frequencies.
Karl Wibergbe579832015-11-10 22:34:18 +0100258 rtc::Optional<bool> highpass_filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 // Audio processing to swap the left and right channels.
Karl Wibergbe579832015-11-10 22:34:18 +0100260 rtc::Optional<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200261 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Karl Wibergbe579832015-11-10 22:34:18 +0100262 rtc::Optional<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200263 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Karl Wibergbe579832015-11-10 22:34:18 +0100264 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265 // Audio processing to detect typing.
Karl Wibergbe579832015-11-10 22:34:18 +0100266 rtc::Optional<bool> typing_detection;
267 rtc::Optional<bool> aecm_generate_comfort_noise;
Karl Wibergbe579832015-11-10 22:34:18 +0100268 rtc::Optional<int> adjust_agc_delta;
269 rtc::Optional<bool> experimental_agc;
270 rtc::Optional<bool> extended_filter_aec;
271 rtc::Optional<bool> delay_agnostic_aec;
272 rtc::Optional<bool> experimental_ns;
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700273 rtc::Optional<bool> intelligibility_enhancer;
peaha3333bf2016-06-30 00:02:34 -0700274 rtc::Optional<bool> level_control;
aleloie33c5d92016-10-20 01:53:27 -0700275 // Specifies an optional initialization value for the level controller.
276 rtc::Optional<float> level_control_initial_peak_level_dbfs;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000277 // Note that tx_agc_* only applies to non-experimental AGC.
ivocb829d9f2016-11-15 02:34:47 -0800278 rtc::Optional<bool> residual_echo_detector;
Karl Wibergbe579832015-11-10 22:34:18 +0100279 rtc::Optional<uint16_t> tx_agc_target_dbov;
280 rtc::Optional<uint16_t> tx_agc_digital_compression_gain;
281 rtc::Optional<bool> tx_agc_limiter;
282 rtc::Optional<uint32_t> recording_sample_rate;
283 rtc::Optional<uint32_t> playout_sample_rate;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000284 // Enable combined audio+bandwidth BWE.
nisse51542be2016-02-12 02:27:06 -0800285 // TODO(pthatcher): This flag is set from the
286 // "googCombinedAudioVideoBwe", but not used anywhere. So delete it,
287 // and check if any other AudioOptions members are unused.
Karl Wibergbe579832015-11-10 22:34:18 +0100288 rtc::Optional<bool> combined_audio_video_bwe;
minyue6b825df2016-10-31 04:08:32 -0700289 // Enable audio network adaptor.
290 rtc::Optional<bool> audio_network_adaptor;
291 // Config string for audio network adaptor.
292 rtc::Optional<std::string> audio_network_adaptor_config;
kwiberg102c6a62015-10-30 02:47:38 -0700293
294 private:
295 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100296 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700297 if (o) {
298 *s = o;
299 }
300 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301};
302
303// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
304// Used to be flags, but that makes it hard to selectively apply options.
305// We are moving all of the setting of options to structs like this,
306// but some things currently still use flags.
307struct VideoOptions {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700309 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800310 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100311 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 }
313
314 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800315 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100316 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
317 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 }
deadbeef119760a2016-04-04 11:43:27 -0700319 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320
321 std::string ToString() const {
322 std::ostringstream ost;
323 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800325 ost << ToStringIfSet("screencast min bitrate kbps",
326 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100327 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 ost << "}";
329 return ost.str();
330 }
331
nisseb163c3f2016-01-29 01:14:38 -0800332 // Enable denoising? This flag comes from the getUserMedia
333 // constraint 'googNoiseReduction', and WebRtcVideoEngine2 passes it
334 // on to the codec options. Disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100335 rtc::Optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800336 // Force screencast to use a minimum bitrate. This flag comes from
337 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
338 // copied to the encoder config by WebRtcVideoChannel2.
339 rtc::Optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100340 // Set by screencast sources. Implies selection of encoding settings
341 // suitable for screencast. Most likely not the right way to do
342 // things, e.g., screencast of a text document and screencast of a
343 // youtube video have different needs.
344 rtc::Optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700345
346 private:
347 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100348 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700349 if (o) {
350 *s = o;
351 }
352 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353};
354
isheriffa1c548b2016-05-31 16:12:24 -0700355// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
356struct RtpHeaderExtension {
357 RtpHeaderExtension() : id(0) {}
358 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
359
360 std::string ToString() const {
361 std::ostringstream ost;
362 ost << "{";
363 ost << "uri: " << uri;
364 ost << ", id: " << id;
365 ost << "}";
366 return ost.str();
367 }
368
369 std::string uri;
370 int id;
371};
372
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373class MediaChannel : public sigslot::has_slots<> {
374 public:
375 class NetworkInterface {
376 public:
377 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700378 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700379 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700380 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700381 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000382 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 int option) = 0;
384 virtual ~NetworkInterface() {}
385 };
386
terelius54f91712016-06-01 11:18:56 -0700387 explicit MediaChannel(const MediaConfig& config)
nisse51542be2016-02-12 02:27:06 -0800388 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
389 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 virtual ~MediaChannel() {}
391
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000392 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000394 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395 network_interface_ = iface;
nisse51542be2016-02-12 02:27:06 -0800396 SetDscp(enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 }
nisse51542be2016-02-12 02:27:06 -0800398 virtual rtc::DiffServCodePoint PreferredDscp() const {
399 return rtc::DSCP_DEFAULT;
400 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000401 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700402 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000403 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700405 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000406 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407 // Called when the socket's ability to send has changed.
408 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700409 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700410 virtual void OnNetworkRouteChanged(
411 const std::string& transport_name,
412 const rtc::NetworkRoute& network_route) = 0;
michaelt79e05882016-11-08 02:50:09 -0800413 // Called when the rtp transport overhead changed.
414 virtual void OnTransportOverheadChanged(
415 int transport_overhead_per_packet) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416 // Creates a new outgoing media stream with SSRCs and CNAME as described
417 // by sp.
418 virtual bool AddSendStream(const StreamParams& sp) = 0;
419 // Removes an outgoing media stream.
420 // ssrc must be the first SSRC of the media stream if the stream uses
421 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200422 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000423 // Creates a new incoming media stream with SSRCs and CNAME as described
424 // by sp.
425 virtual bool AddRecvStream(const StreamParams& sp) = 0;
426 // Removes an incoming media stream.
427 // ssrc must be the first SSRC of the media stream if the stream uses
428 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200429 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000431 // Returns the absoulte sendtime extension id value from media channel.
432 virtual int GetRtpSendTimeExtnId() const {
433 return -1;
434 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000436 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700437 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
438 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700439 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000440 }
441
jbaucheec21bd2016-03-20 06:15:43 -0700442 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
443 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700444 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000445 }
446
447 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000448 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000449 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000450 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000451 if (!network_interface_)
452 return -1;
453
454 return network_interface_->SetOption(type, opt, option);
455 }
456
nisse51542be2016-02-12 02:27:06 -0800457 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000458 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000459 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000460 int ret;
461 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000462 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000463 value);
464 if (ret == 0) {
465 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000466 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000467 value);
468 }
469 return ret;
470 }
471
jbaucheec21bd2016-03-20 06:15:43 -0700472 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700473 bool rtcp,
474 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000475 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000476 if (!network_interface_)
477 return false;
478
stefanc1aeaf02015-10-15 07:26:07 -0700479 return (!rtcp) ? network_interface_->SendPacket(packet, options)
480 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000481 }
482
nisse51542be2016-02-12 02:27:06 -0800483 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000484 // |network_interface_| can be accessed from the worker_thread and
485 // from any MediaEngine threads. This critical section is to protect accessing
486 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000487 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000488 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000489};
490
wu@webrtc.org97077a32013-10-25 21:18:33 +0000491// The stats information is structured as follows:
492// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
493// Media contains a vector of SSRC infos that are exclusively used by this
494// media. (SSRCs shared between media streams can't be represented.)
495
496// Information about an SSRC.
497// This data may be locally recorded, or received in an RTCP SR or RR.
498struct SsrcSenderInfo {
499 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000500 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000501 timestamp(0) {
502 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200503 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000504 double timestamp; // NTP timestamp, represented as seconds since epoch.
505};
506
507struct SsrcReceiverInfo {
508 SsrcReceiverInfo()
509 : ssrc(0),
510 timestamp(0) {
511 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200512 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000513 double timestamp;
514};
515
516struct MediaSenderInfo {
517 MediaSenderInfo()
518 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 packets_sent(0),
520 packets_lost(0),
521 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000522 rtt_ms(0) {
523 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000524 void add_ssrc(const SsrcSenderInfo& stat) {
525 local_stats.push_back(stat);
526 }
527 // Temporary utility function for call sites that only provide SSRC.
528 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200529 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000530 SsrcSenderInfo stat;
531 stat.ssrc = ssrc;
532 add_ssrc(stat);
533 }
534 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200535 std::vector<uint32_t> ssrcs() const {
536 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000537 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
538 it != local_stats.end(); ++it) {
539 retval.push_back(it->ssrc);
540 }
541 return retval;
542 }
543 // Utility accessor for clients that make the assumption only one ssrc
544 // exists per media.
545 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200546 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000547 if (local_stats.size() > 0) {
548 return local_stats[0].ssrc;
549 } else {
550 return 0;
551 }
552 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200553 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000554 int packets_sent;
555 int packets_lost;
556 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000557 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000558 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800559 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000560 std::vector<SsrcSenderInfo> local_stats;
561 std::vector<SsrcReceiverInfo> remote_stats;
562};
563
564struct MediaReceiverInfo {
565 MediaReceiverInfo()
566 : bytes_rcvd(0),
567 packets_rcvd(0),
568 packets_lost(0),
569 fraction_lost(0.0) {
570 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000571 void add_ssrc(const SsrcReceiverInfo& stat) {
572 local_stats.push_back(stat);
573 }
574 // Temporary utility function for call sites that only provide SSRC.
575 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200576 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000577 SsrcReceiverInfo stat;
578 stat.ssrc = ssrc;
579 add_ssrc(stat);
580 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200581 std::vector<uint32_t> ssrcs() const {
582 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000583 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
584 it != local_stats.end(); ++it) {
585 retval.push_back(it->ssrc);
586 }
587 return retval;
588 }
589 // Utility accessor for clients that make the assumption only one ssrc
590 // exists per media.
591 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200592 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000593 if (local_stats.size() > 0) {
594 return local_stats[0].ssrc;
595 } else {
596 return 0;
597 }
598 }
599
Peter Boström0c4e06b2015-10-07 12:23:21 +0200600 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000601 int packets_rcvd;
602 int packets_lost;
603 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000604 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800605 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000606 std::vector<SsrcReceiverInfo> local_stats;
607 std::vector<SsrcSenderInfo> remote_stats;
608};
609
610struct VoiceSenderInfo : public MediaSenderInfo {
611 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000612 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000613 jitter_ms(0),
614 audio_level(0),
615 aec_quality_min(0.0),
616 echo_delay_median_ms(0),
617 echo_delay_std_ms(0),
618 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000619 echo_return_loss_enhancement(0),
ivoc8c63a822016-10-21 04:10:03 -0700620 residual_echo_likelihood(0.0f),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000621 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 }
623
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625 int jitter_ms;
626 int audio_level;
627 float aec_quality_min;
628 int echo_delay_median_ms;
629 int echo_delay_std_ms;
630 int echo_return_loss;
631 int echo_return_loss_enhancement;
ivoc8c63a822016-10-21 04:10:03 -0700632 float residual_echo_likelihood;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000633 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000634};
635
wu@webrtc.org97077a32013-10-25 21:18:33 +0000636struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000638 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639 jitter_ms(0),
640 jitter_buffer_ms(0),
641 jitter_buffer_preferred_ms(0),
642 delay_estimate_ms(0),
643 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000644 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000645 speech_expand_rate(0),
646 secondary_decoded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200647 accelerate_rate(0),
648 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000649 decoding_calls_to_silence_generator(0),
650 decoding_calls_to_neteq(0),
651 decoding_normal(0),
652 decoding_plc(0),
653 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000654 decoding_plc_cng(0),
henrik.lundin63489782016-09-20 01:47:12 -0700655 decoding_muted_output(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200656 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000658 int ext_seqnum;
659 int jitter_ms;
660 int jitter_buffer_ms;
661 int jitter_buffer_preferred_ms;
662 int delay_estimate_ms;
663 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000664 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000666 // fraction of synthesized speech inserted through expansion.
667 float speech_expand_rate;
668 // fraction of data out of secondary decoding, including FEC and RED.
669 float secondary_decoded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200670 // Fraction of data removed through time compression.
671 float accelerate_rate;
672 // Fraction of data inserted through time stretching.
673 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000674 int decoding_calls_to_silence_generator;
675 int decoding_calls_to_neteq;
676 int decoding_normal;
677 int decoding_plc;
678 int decoding_cng;
679 int decoding_plc_cng;
henrik.lundin63489782016-09-20 01:47:12 -0700680 int decoding_muted_output;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000681 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200682 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683};
684
wu@webrtc.org97077a32013-10-25 21:18:33 +0000685struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000687 : packets_cached(0),
688 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000689 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000691 send_frame_width(0),
692 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 framerate_input(0),
694 framerate_sent(0),
695 nominal_bitrate(0),
696 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000697 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000698 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000699 avg_encode_ms(0),
sakal43536c32016-10-24 01:46:43 -0700700 encode_usage_percent(0),
701 frames_encoded(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000703 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800704 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100705 std::string encoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000706 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000708 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000710 int send_frame_width;
711 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 int framerate_input;
713 int framerate_sent;
714 int nominal_bitrate;
715 int preferred_bitrate;
716 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000717 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000718 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000719 int encode_usage_percent;
sakal43536c32016-10-24 01:46:43 -0700720 uint32_t frames_encoded;
sakal87da4042016-10-31 06:53:47 -0700721 rtc::Optional<uint64_t> qp_sum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722};
723
wu@webrtc.org97077a32013-10-25 21:18:33 +0000724struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000726 : packets_concealed(0),
727 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000728 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 nacks_sent(0),
730 frame_width(0),
731 frame_height(0),
732 framerate_rcvd(0),
733 framerate_decoded(0),
734 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000735 framerate_render_input(0),
736 framerate_render_output(0),
sakale5ba44e2016-10-26 07:09:24 -0700737 frames_decoded(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000738 decode_ms(0),
739 max_decode_ms(0),
740 jitter_buffer_ms(0),
741 min_playout_delay_ms(0),
742 render_delay_ms(0),
743 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000744 current_delay_ms(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000745 capture_start_ntp_time_ms(-1) {
746 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000748 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800749 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100750 std::string decoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000751 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000753 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 int nacks_sent;
755 int frame_width;
756 int frame_height;
757 int framerate_rcvd;
758 int framerate_decoded;
759 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000760 // Framerate as sent to the renderer.
761 int framerate_render_input;
762 // Framerate that the renderer reports.
763 int framerate_render_output;
sakale5ba44e2016-10-26 07:09:24 -0700764 uint32_t frames_decoded;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000765
766 // All stats below are gathered per-VideoReceiver, but some will be correlated
767 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
768 // structures, reflect this in the new layout.
769
770 // Current frame decode latency.
771 int decode_ms;
772 // Maximum observed frame decode latency.
773 int max_decode_ms;
774 // Jitter (network-related) latency.
775 int jitter_buffer_ms;
776 // Requested minimum playout latency.
777 int min_playout_delay_ms;
778 // Requested latency to account for rendering delay.
779 int render_delay_ms;
780 // Target overall delay: network+decode+render, accounting for
781 // min_playout_delay_ms.
782 int target_delay_ms;
783 // Current overall delay, possibly ramping towards target_delay_ms.
784 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000785
786 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200787 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788};
789
wu@webrtc.org97077a32013-10-25 21:18:33 +0000790struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000792 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 }
794
Peter Boström0c4e06b2015-10-07 12:23:21 +0200795 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796};
797
wu@webrtc.org97077a32013-10-25 21:18:33 +0000798struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000800 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 }
802
Peter Boström0c4e06b2015-10-07 12:23:21 +0200803 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804};
805
806struct BandwidthEstimationInfo {
807 BandwidthEstimationInfo()
808 : available_send_bandwidth(0),
809 available_recv_bandwidth(0),
810 target_enc_bitrate(0),
811 actual_enc_bitrate(0),
812 retransmit_bitrate(0),
813 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000814 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 }
816
817 int available_send_bandwidth;
818 int available_recv_bandwidth;
819 int target_enc_bitrate;
820 int actual_enc_bitrate;
821 int retransmit_bitrate;
822 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000823 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824};
825
hbosa65704b2016-11-14 02:28:16 -0800826// Maps from payload type to |RtpCodecParameters|.
827typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
828
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829struct VoiceMediaInfo {
830 void Clear() {
831 senders.clear();
832 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800833 send_codecs.clear();
834 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 }
836 std::vector<VoiceSenderInfo> senders;
837 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800838 RtpCodecParametersMap send_codecs;
839 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840};
841
842struct VideoMediaInfo {
843 void Clear() {
844 senders.clear();
845 receivers.clear();
846 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800847 send_codecs.clear();
848 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 }
850 std::vector<VideoSenderInfo> senders;
851 std::vector<VideoReceiverInfo> receivers;
852 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800853 RtpCodecParametersMap send_codecs;
854 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855};
856
857struct DataMediaInfo {
858 void Clear() {
859 senders.clear();
860 receivers.clear();
861 }
862 std::vector<DataSenderInfo> senders;
863 std::vector<DataReceiverInfo> receivers;
864};
865
deadbeef13871492015-12-09 12:37:51 -0800866struct RtcpParameters {
867 bool reduced_size = false;
868};
869
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700870template <class Codec>
871struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800872 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700873 std::ostringstream ost;
874 ost << "{";
875 ost << "codecs: " << VectorToString(codecs) << ", ";
876 ost << "extensions: " << VectorToString(extensions);
877 ost << "}";
878 return ost.str();
879 }
880
881 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700882 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700883 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800884 RtcpParameters rtcp;
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200885 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700886};
887
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700888// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
889// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700890template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700891struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800892 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700893 std::ostringstream ost;
894 ost << "{";
895 ost << "codecs: " << VectorToString(this->codecs) << ", ";
896 ost << "extensions: " << VectorToString(this->extensions) << ", ";
pbos378dc772016-01-28 15:58:41 -0800897 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
nisse05103312016-03-16 02:22:50 -0700898 ost << "}";
899 return ost.str();
900 }
901
902 int max_bandwidth_bps = -1;
903};
904
905struct AudioSendParameters : RtpSendParameters<AudioCodec> {
906 std::string ToString() const override {
907 std::ostringstream ost;
908 ost << "{";
909 ost << "codecs: " << VectorToString(this->codecs) << ", ";
910 ost << "extensions: " << VectorToString(this->extensions) << ", ";
911 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700912 ost << "options: " << options.ToString();
913 ost << "}";
914 return ost.str();
915 }
916
nisse05103312016-03-16 02:22:50 -0700917 AudioOptions options;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700918};
919
920struct AudioRecvParameters : RtpParameters<AudioCodec> {
921};
922
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923class VoiceMediaChannel : public MediaChannel {
924 public:
925 enum Error {
926 ERROR_NONE = 0, // No error.
927 ERROR_OTHER, // Other errors.
928 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
929 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
930 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
931 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
932 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
933 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
934 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
935 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
936 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
937 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
938 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
939 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
940 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
941 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
942 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
943 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
944 };
945
946 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700947 explicit VoiceMediaChannel(const MediaConfig& config)
948 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200950 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
951 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700952 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
953 virtual bool SetRtpSendParameters(
954 uint32_t ssrc,
955 const webrtc::RtpParameters& parameters) = 0;
956 virtual webrtc::RtpParameters GetRtpReceiveParameters(
957 uint32_t ssrc) const = 0;
958 virtual bool SetRtpReceiveParameters(
959 uint32_t ssrc,
960 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -0700962 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800964 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700965 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200966 virtual bool SetAudioSend(uint32_t ssrc,
967 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700968 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800969 AudioSource* source) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 // Gets current energy levels for all incoming streams.
971 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
972 // Get the current energy level of the stream sent to the speaker.
973 virtual int GetOutputLevel() = 0;
974 // Get the time in milliseconds since last recorded keystroke, or negative.
975 virtual int GetTimeSinceLastTyping() = 0;
976 // Temporarily exposed field for tuning typing detect options.
977 virtual void SetTypingDetectionParameters(int time_window,
978 int cost_per_typing, int reporting_threshold, int penalty_decay,
979 int type_event_delay) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700980 // Set speaker output volume of the specified ssrc.
981 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800983 virtual bool CanInsertDtmf() = 0;
984 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000986 // The valid value for the |event| are 0 to 15 which corresponding to
987 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800988 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 // Gets quality stats for the channel.
990 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100991
992 virtual void SetRawAudioSink(
993 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -0800994 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995};
996
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700997// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
998// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -0700999struct VideoSendParameters : RtpSendParameters<VideoCodec> {
nisse4b4dc862016-02-17 05:25:36 -08001000 // Use conference mode? This flag comes from the remote
1001 // description's SDP line 'a=x-google-flag:conference', copied over
1002 // by VideoChannel::SetRemoteContent_w, and ultimately used by
1003 // conference mode screencast logic in
1004 // WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig.
1005 // The special screencast behaviour is disabled by default.
1006 bool conference_mode = false;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001007};
1008
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001009// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
1010// encapsulate all the parameters needed for a video RtpReceiver.
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001011struct VideoRecvParameters : RtpParameters<VideoCodec> {
1012};
1013
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014class VideoMediaChannel : public MediaChannel {
1015 public:
1016 enum Error {
1017 ERROR_NONE = 0, // No error.
1018 ERROR_OTHER, // Other errors.
1019 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1020 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1021 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1022 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1023 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1024 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1025 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1026 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1027 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1028 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1029 };
1030
nisse08582ff2016-02-04 01:24:52 -08001031 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -07001032 explicit VideoMediaChannel(const MediaConfig& config)
1033 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001035
1036 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
1037 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001038 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
1039 virtual bool SetRtpSendParameters(
1040 uint32_t ssrc,
1041 const webrtc::RtpParameters& parameters) = 0;
1042 virtual webrtc::RtpParameters GetRtpReceiveParameters(
1043 uint32_t ssrc) const = 0;
1044 virtual bool SetRtpReceiveParameters(
1045 uint32_t ssrc,
1046 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 // Gets the currently set codecs/payload types to be used for outgoing media.
1048 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001049 // Starts or stops transmission (and potentially capture) of local video.
1050 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -07001051 // Configure stream for sending and register a source.
1052 // The |ssrc| must correspond to a registered send stream.
1053 virtual bool SetVideoSend(
1054 uint32_t ssrc,
1055 bool enable,
1056 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -08001057 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -08001058 // Sets the sink object to be used for the specified stream.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 // If SSRC is 0, the renderer is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -08001060 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -08001061 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001063 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064};
1065
1066enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001067 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1068 // values.
1069 DMT_NONE = 0,
1070 DMT_CONTROL = 1,
1071 DMT_BINARY = 2,
1072 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073};
1074
1075// Info about data received in DataMediaChannel. For use in
1076// DataMediaChannel::SignalDataReceived and in all of the signals that
1077// signal fires, on up the chain.
1078struct ReceiveDataParams {
1079 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001080 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1081 union {
1082 uint32_t ssrc;
1083 int sid;
1084 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 // The type of message (binary, text, or control).
1086 DataMessageType type;
1087 // A per-stream value incremented per packet in the stream.
1088 int seq_num;
1089 // A per-stream value monotonically increasing with time.
1090 int timestamp;
1091
deadbeef953c2ce2017-01-09 14:53:41 -08001092 ReceiveDataParams() : sid(0), type(DMT_TEXT), seq_num(0), timestamp(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093};
1094
1095struct SendDataParams {
1096 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001097 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1098 union {
1099 uint32_t ssrc;
1100 int sid;
1101 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 // The type of message (binary, text, or control).
1103 DataMessageType type;
1104
1105 // For SCTP, whether to send messages flagged as ordered or not.
1106 // If false, messages can be received out of order.
1107 bool ordered;
1108 // For SCTP, whether the messages are sent reliably or not.
1109 // If false, messages may be lost.
1110 bool reliable;
1111 // For SCTP, if reliable == false, provide partial reliability by
1112 // resending up to this many times. Either count or millis
1113 // is supported, not both at the same time.
1114 int max_rtx_count;
1115 // For SCTP, if reliable == false, provide partial reliability by
1116 // resending for up to this many milliseconds. Either count or millis
1117 // is supported, not both at the same time.
1118 int max_rtx_ms;
1119
deadbeef953c2ce2017-01-09 14:53:41 -08001120 SendDataParams()
1121 : sid(0),
1122 type(DMT_TEXT),
1123 // TODO(pthatcher): Make these true by default?
1124 ordered(false),
1125 reliable(false),
1126 max_rtx_count(0),
1127 max_rtx_ms(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128};
1129
1130enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1131
nisse05103312016-03-16 02:22:50 -07001132struct DataSendParameters : RtpSendParameters<DataCodec> {
solenberg7e4e01a2015-12-02 08:05:01 -08001133 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001134 std::ostringstream ost;
1135 // Options and extensions aren't used.
1136 ost << "{";
1137 ost << "codecs: " << VectorToString(codecs) << ", ";
pbos378dc772016-01-28 15:58:41 -08001138 ost << "max_bandwidth_bps: " << max_bandwidth_bps;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001139 ost << "}";
1140 return ost.str();
1141 }
1142};
1143
1144struct DataRecvParameters : RtpParameters<DataCodec> {
1145};
1146
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001147class DataMediaChannel : public MediaChannel {
1148 public:
1149 enum Error {
1150 ERROR_NONE = 0, // No error.
1151 ERROR_OTHER, // Other errors.
1152 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1153 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1154 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1155 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1156 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1157 };
1158
zhihuangebbe4f22016-12-06 10:45:42 -08001159 DataMediaChannel() {}
1160 DataMediaChannel(const MediaConfig& config) : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001161 virtual ~DataMediaChannel() {}
1162
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001163 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1164 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001165
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001166 // TODO(pthatcher): Implement this.
1167 virtual bool GetStats(DataMediaInfo* info) { return true; }
1168
1169 virtual bool SetSend(bool send) = 0;
1170 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001171
Honghai Zhangcc411c02016-03-29 17:27:21 -07001172 virtual void OnNetworkRouteChanged(const std::string& transport_name,
Honghai Zhang0e533ef2016-04-19 15:41:36 -07001173 const rtc::NetworkRoute& network_route) {}
Honghai Zhangcc411c02016-03-29 17:27:21 -07001174
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001175 virtual bool SendData(
1176 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -07001177 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001178 SendDataResult* result = NULL) = 0;
1179 // Signals when data is received (params, data, len)
1180 sigslot::signal3<const ReceiveDataParams&,
1181 const char*,
1182 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001183 // Signal when the media channel is ready to send the stream. Arguments are:
1184 // writable(bool)
1185 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001186};
1187
1188} // namespace cricket
1189
kjellandera96e2d72016-02-04 23:52:28 -08001190#endif // WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_