blob: 06766a851f165d012b46f3cc0c6fd94963afb61e [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MEDIA_BASE_MEDIACHANNEL_H_
12#define MEDIA_BASE_MEDIACHANNEL_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
kwiberg686a8ef2016-02-26 03:00:35 -080014#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015#include <string>
16#include <vector>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/audio_codecs/audio_encoder.h"
19#include "api/optional.h"
20#include "api/rtpparameters.h"
21#include "api/rtpreceiverinterface.h"
22#include "api/video/video_timing.h"
23#include "call/video_config.h"
24#include "media/base/codec.h"
25#include "media/base/mediaconstants.h"
26#include "media/base/streamparams.h"
27#include "media/base/videosinkinterface.h"
28#include "media/base/videosourceinterface.h"
29#include "rtc_base/basictypes.h"
30#include "rtc_base/buffer.h"
31#include "rtc_base/copyonwritebuffer.h"
32#include "rtc_base/dscp.h"
33#include "rtc_base/logging.h"
34#include "rtc_base/networkroute.h"
35#include "rtc_base/sigslot.h"
36#include "rtc_base/socket.h"
37#include "rtc_base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038// TODO(juberti): re-evaluate this include
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020039#include "pc/audiomonitor.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000041namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042class RateLimiter;
43class Timing;
44}
45
Tommif888bb52015-12-12 01:37:01 +010046namespace webrtc {
47class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080048class VideoFrame;
Tommif888bb52015-12-12 01:37:01 +010049}
50
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051namespace cricket {
52
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080053class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080055struct RtpHeader;
56struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058const int kScreencastDefaultFps = 5;
59
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060template <class T>
Karl Wibergbe579832015-11-10 22:34:18 +010061static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070063 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064 str = key;
65 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070066 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067 str += ", ";
68 }
69 return str;
70}
71
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070072template <class T>
73static std::string VectorToString(const std::vector<T>& vals) {
74 std::ostringstream ost;
75 ost << "[";
76 for (size_t i = 0; i < vals.size(); ++i) {
77 if (i > 0) {
78 ost << ", ";
79 }
80 ost << vals[i].ToString();
81 }
82 ost << "]";
83 return ost.str();
84}
85
nisse528b7932017-05-08 03:21:43 -070086// Construction-time settings, passed on when creating
nisse51542be2016-02-12 02:27:06 -080087// MediaChannels.
88struct MediaConfig {
89 // Set DSCP value on packets. This flag comes from the
90 // PeerConnection constraint 'googDscp'.
91 bool enable_dscp = false;
92
nisse0db023a2016-03-01 04:29:59 -080093 // Video-specific config.
94 struct Video {
95 // Enable WebRTC CPU Overuse Detection. This flag comes from the
perkj803d97f2016-11-01 11:45:46 -070096 // PeerConnection constraint 'googCpuOveruseDetection'.
nisse0db023a2016-03-01 04:29:59 -080097 bool enable_cpu_overuse_detection = true;
nisse51542be2016-02-12 02:27:06 -080098
nisse0db023a2016-03-01 04:29:59 -080099 // Enable WebRTC suspension of video. No video frames will be sent
100 // when the bitrate is below the configured minimum bitrate. This
101 // flag comes from the PeerConnection constraint
eladalonf1841382017-06-12 01:16:46 -0700102 // 'googSuspendBelowMinBitrate', and WebRtcVideoChannel copies it
nisse0db023a2016-03-01 04:29:59 -0800103 // to VideoSendStream::Config::suspend_below_min_bitrate.
104 bool suspend_below_min_bitrate = false;
nisse51542be2016-02-12 02:27:06 -0800105
nisse0db023a2016-03-01 04:29:59 -0800106 // Set to true if the renderer has an algorithm of frame selection.
107 // If the value is true, then WebRTC will hand over a frame as soon as
108 // possible without delay, and rendering smoothness is completely the duty
109 // of the renderer;
110 // If the value is false, then WebRTC is responsible to delay frame release
111 // in order to increase rendering smoothness.
112 //
113 // This flag comes from PeerConnection's RtcConfiguration, but is
114 // currently only set by the command line flag
115 // 'disable-rtc-smoothness-algorithm'.
eladalonf1841382017-06-12 01:16:46 -0700116 // WebRtcVideoChannel::AddRecvStream copies it to the created
nisse0db023a2016-03-01 04:29:59 -0800117 // WebRtcVideoReceiveStream, where it is returned by the
118 // SmoothsRenderedFrames method. This method is used by the
119 // VideoReceiveStream, where the value is passed on to the
120 // IncomingVideoStream constructor.
121 bool disable_prerenderer_smoothing = false;
sergeyu80ed35e2016-11-28 13:11:13 -0800122
123 // Enables periodic bandwidth probing in application-limited region.
124 bool periodic_alr_bandwidth_probing = false;
nisse0db023a2016-03-01 04:29:59 -0800125 } video;
deadbeef293e9262017-01-11 12:28:30 -0800126
127 bool operator==(const MediaConfig& o) const {
128 return enable_dscp == o.enable_dscp &&
129 video.enable_cpu_overuse_detection ==
130 o.video.enable_cpu_overuse_detection &&
131 video.suspend_below_min_bitrate ==
132 o.video.suspend_below_min_bitrate &&
133 video.disable_prerenderer_smoothing ==
134 o.video.disable_prerenderer_smoothing &&
135 video.periodic_alr_bandwidth_probing ==
136 o.video.periodic_alr_bandwidth_probing;
137 }
138
139 bool operator!=(const MediaConfig& o) const { return !(*this == o); }
nisse51542be2016-02-12 02:27:06 -0800140};
141
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
143// Used to be flags, but that makes it hard to selectively apply options.
144// We are moving all of the setting of options to structs like this,
145// but some things currently still use flags.
146struct AudioOptions {
147 void SetAll(const AudioOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700148 SetFrom(&echo_cancellation, change.echo_cancellation);
149 SetFrom(&auto_gain_control, change.auto_gain_control);
150 SetFrom(&noise_suppression, change.noise_suppression);
151 SetFrom(&highpass_filter, change.highpass_filter);
152 SetFrom(&stereo_swapping, change.stereo_swapping);
153 SetFrom(&audio_jitter_buffer_max_packets,
154 change.audio_jitter_buffer_max_packets);
155 SetFrom(&audio_jitter_buffer_fast_accelerate,
156 change.audio_jitter_buffer_fast_accelerate);
157 SetFrom(&typing_detection, change.typing_detection);
158 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise);
kwiberg102c6a62015-10-30 02:47:38 -0700159 SetFrom(&adjust_agc_delta, change.adjust_agc_delta);
160 SetFrom(&experimental_agc, change.experimental_agc);
161 SetFrom(&extended_filter_aec, change.extended_filter_aec);
162 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec);
163 SetFrom(&experimental_ns, change.experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700164 SetFrom(&intelligibility_enhancer, change.intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700165 SetFrom(&level_control, change.level_control);
ivocb829d9f2016-11-15 02:34:47 -0800166 SetFrom(&residual_echo_detector, change.residual_echo_detector);
kwiberg102c6a62015-10-30 02:47:38 -0700167 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov);
168 SetFrom(&tx_agc_digital_compression_gain,
169 change.tx_agc_digital_compression_gain);
170 SetFrom(&tx_agc_limiter, change.tx_agc_limiter);
171 SetFrom(&recording_sample_rate, change.recording_sample_rate);
172 SetFrom(&playout_sample_rate, change.playout_sample_rate);
kwiberg102c6a62015-10-30 02:47:38 -0700173 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700174 SetFrom(&audio_network_adaptor, change.audio_network_adaptor);
175 SetFrom(&audio_network_adaptor_config, change.audio_network_adaptor_config);
aleloie33c5d92016-10-20 01:53:27 -0700176 SetFrom(&level_control_initial_peak_level_dbfs,
177 change.level_control_initial_peak_level_dbfs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 }
179
180 bool operator==(const AudioOptions& o) const {
181 return echo_cancellation == o.echo_cancellation &&
peaha3333bf2016-06-30 00:02:34 -0700182 auto_gain_control == o.auto_gain_control &&
183 noise_suppression == o.noise_suppression &&
184 highpass_filter == o.highpass_filter &&
185 stereo_swapping == o.stereo_swapping &&
186 audio_jitter_buffer_max_packets ==
187 o.audio_jitter_buffer_max_packets &&
188 audio_jitter_buffer_fast_accelerate ==
189 o.audio_jitter_buffer_fast_accelerate &&
190 typing_detection == o.typing_detection &&
191 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
192 experimental_agc == o.experimental_agc &&
193 extended_filter_aec == o.extended_filter_aec &&
194 delay_agnostic_aec == o.delay_agnostic_aec &&
195 experimental_ns == o.experimental_ns &&
196 intelligibility_enhancer == o.intelligibility_enhancer &&
197 level_control == o.level_control &&
ivocb829d9f2016-11-15 02:34:47 -0800198 residual_echo_detector == o.residual_echo_detector &&
peaha3333bf2016-06-30 00:02:34 -0700199 adjust_agc_delta == o.adjust_agc_delta &&
200 tx_agc_target_dbov == o.tx_agc_target_dbov &&
201 tx_agc_digital_compression_gain ==
202 o.tx_agc_digital_compression_gain &&
203 tx_agc_limiter == o.tx_agc_limiter &&
204 recording_sample_rate == o.recording_sample_rate &&
205 playout_sample_rate == o.playout_sample_rate &&
aleloie33c5d92016-10-20 01:53:27 -0700206 combined_audio_video_bwe == o.combined_audio_video_bwe &&
minyue6b825df2016-10-31 04:08:32 -0700207 audio_network_adaptor == o.audio_network_adaptor &&
208 audio_network_adaptor_config == o.audio_network_adaptor_config &&
aleloie33c5d92016-10-20 01:53:27 -0700209 level_control_initial_peak_level_dbfs ==
210 o.level_control_initial_peak_level_dbfs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 }
deadbeef119760a2016-04-04 11:43:27 -0700212 bool operator!=(const AudioOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213
214 std::string ToString() const {
215 std::ostringstream ost;
216 ost << "AudioOptions {";
217 ost << ToStringIfSet("aec", echo_cancellation);
218 ost << ToStringIfSet("agc", auto_gain_control);
219 ost << ToStringIfSet("ns", noise_suppression);
220 ost << ToStringIfSet("hf", highpass_filter);
221 ost << ToStringIfSet("swap", stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200222 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
223 audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200224 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
225 audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000227 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
229 ost << ToStringIfSet("experimental_agc", experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200230 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100231 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000232 ost << ToStringIfSet("experimental_ns", experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700233 ost << ToStringIfSet("intelligibility_enhancer", intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700234 ost << ToStringIfSet("level_control", level_control);
aleloie33c5d92016-10-20 01:53:27 -0700235 ost << ToStringIfSet("level_control_initial_peak_level_dbfs",
236 level_control_initial_peak_level_dbfs);
ivocb829d9f2016-11-15 02:34:47 -0800237 ost << ToStringIfSet("residual_echo_detector", residual_echo_detector);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000238 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
239 ost << ToStringIfSet("tx_agc_digital_compression_gain",
240 tx_agc_digital_compression_gain);
241 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000242 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
243 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000244 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700245 ost << ToStringIfSet("audio_network_adaptor", audio_network_adaptor);
246 // The adaptor config is a serialized proto buffer and therefore not human
247 // readable. So we comment out the following line.
248 // ost << ToStringIfSet("audio_network_adaptor_config",
249 // audio_network_adaptor_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 ost << "}";
251 return ost.str();
252 }
253
254 // Audio processing that attempts to filter away the output signal from
255 // later inbound pickup.
Karl Wibergbe579832015-11-10 22:34:18 +0100256 rtc::Optional<bool> echo_cancellation;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 // Audio processing to adjust the sensitivity of the local mic dynamically.
Karl Wibergbe579832015-11-10 22:34:18 +0100258 rtc::Optional<bool> auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 // Audio processing to filter out background noise.
Karl Wibergbe579832015-11-10 22:34:18 +0100260 rtc::Optional<bool> noise_suppression;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 // Audio processing to remove background noise of lower frequencies.
Karl Wibergbe579832015-11-10 22:34:18 +0100262 rtc::Optional<bool> highpass_filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263 // Audio processing to swap the left and right channels.
Karl Wibergbe579832015-11-10 22:34:18 +0100264 rtc::Optional<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200265 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Karl Wibergbe579832015-11-10 22:34:18 +0100266 rtc::Optional<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200267 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Karl Wibergbe579832015-11-10 22:34:18 +0100268 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269 // Audio processing to detect typing.
Karl Wibergbe579832015-11-10 22:34:18 +0100270 rtc::Optional<bool> typing_detection;
271 rtc::Optional<bool> aecm_generate_comfort_noise;
Karl Wibergbe579832015-11-10 22:34:18 +0100272 rtc::Optional<int> adjust_agc_delta;
273 rtc::Optional<bool> experimental_agc;
274 rtc::Optional<bool> extended_filter_aec;
275 rtc::Optional<bool> delay_agnostic_aec;
276 rtc::Optional<bool> experimental_ns;
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700277 rtc::Optional<bool> intelligibility_enhancer;
peaha3333bf2016-06-30 00:02:34 -0700278 rtc::Optional<bool> level_control;
aleloie33c5d92016-10-20 01:53:27 -0700279 // Specifies an optional initialization value for the level controller.
280 rtc::Optional<float> level_control_initial_peak_level_dbfs;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000281 // Note that tx_agc_* only applies to non-experimental AGC.
ivocb829d9f2016-11-15 02:34:47 -0800282 rtc::Optional<bool> residual_echo_detector;
Karl Wibergbe579832015-11-10 22:34:18 +0100283 rtc::Optional<uint16_t> tx_agc_target_dbov;
284 rtc::Optional<uint16_t> tx_agc_digital_compression_gain;
285 rtc::Optional<bool> tx_agc_limiter;
286 rtc::Optional<uint32_t> recording_sample_rate;
287 rtc::Optional<uint32_t> playout_sample_rate;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000288 // Enable combined audio+bandwidth BWE.
nisse51542be2016-02-12 02:27:06 -0800289 // TODO(pthatcher): This flag is set from the
290 // "googCombinedAudioVideoBwe", but not used anywhere. So delete it,
291 // and check if any other AudioOptions members are unused.
Karl Wibergbe579832015-11-10 22:34:18 +0100292 rtc::Optional<bool> combined_audio_video_bwe;
minyue6b825df2016-10-31 04:08:32 -0700293 // Enable audio network adaptor.
294 rtc::Optional<bool> audio_network_adaptor;
295 // Config string for audio network adaptor.
296 rtc::Optional<std::string> audio_network_adaptor_config;
kwiberg102c6a62015-10-30 02:47:38 -0700297
298 private:
299 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100300 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700301 if (o) {
302 *s = o;
303 }
304 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305};
306
307// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
308// Used to be flags, but that makes it hard to selectively apply options.
309// We are moving all of the setting of options to structs like this,
310// but some things currently still use flags.
311struct VideoOptions {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700313 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800314 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100315 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 }
317
318 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800319 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100320 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
321 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 }
deadbeef119760a2016-04-04 11:43:27 -0700323 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324
325 std::string ToString() const {
326 std::ostringstream ost;
327 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800329 ost << ToStringIfSet("screencast min bitrate kbps",
330 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100331 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 ost << "}";
333 return ost.str();
334 }
335
nisseb163c3f2016-01-29 01:14:38 -0800336 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700337 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800338 // on to the codec options. Disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100339 rtc::Optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800340 // Force screencast to use a minimum bitrate. This flag comes from
341 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700342 // copied to the encoder config by WebRtcVideoChannel.
nisseb163c3f2016-01-29 01:14:38 -0800343 rtc::Optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100344 // Set by screencast sources. Implies selection of encoding settings
345 // suitable for screencast. Most likely not the right way to do
346 // things, e.g., screencast of a text document and screencast of a
347 // youtube video have different needs.
348 rtc::Optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700349
350 private:
351 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100352 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700353 if (o) {
354 *s = o;
355 }
356 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357};
358
isheriffa1c548b2016-05-31 16:12:24 -0700359// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
360struct RtpHeaderExtension {
361 RtpHeaderExtension() : id(0) {}
362 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
363
364 std::string ToString() const {
365 std::ostringstream ost;
366 ost << "{";
367 ost << "uri: " << uri;
368 ost << ", id: " << id;
369 ost << "}";
370 return ost.str();
371 }
372
373 std::string uri;
374 int id;
375};
376
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377class MediaChannel : public sigslot::has_slots<> {
378 public:
379 class NetworkInterface {
380 public:
381 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700382 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700383 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700384 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700385 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000386 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387 int option) = 0;
388 virtual ~NetworkInterface() {}
389 };
390
terelius54f91712016-06-01 11:18:56 -0700391 explicit MediaChannel(const MediaConfig& config)
nisse51542be2016-02-12 02:27:06 -0800392 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
393 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394 virtual ~MediaChannel() {}
395
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000396 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000398 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399 network_interface_ = iface;
nisse51542be2016-02-12 02:27:06 -0800400 SetDscp(enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000401 }
nisse51542be2016-02-12 02:27:06 -0800402 virtual rtc::DiffServCodePoint PreferredDscp() const {
403 return rtc::DSCP_DEFAULT;
404 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700406 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000407 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700409 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000410 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 // Called when the socket's ability to send has changed.
412 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700413 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700414 virtual void OnNetworkRouteChanged(
415 const std::string& transport_name,
416 const rtc::NetworkRoute& network_route) = 0;
michaelt79e05882016-11-08 02:50:09 -0800417 // Called when the rtp transport overhead changed.
418 virtual void OnTransportOverheadChanged(
419 int transport_overhead_per_packet) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420 // Creates a new outgoing media stream with SSRCs and CNAME as described
421 // by sp.
422 virtual bool AddSendStream(const StreamParams& sp) = 0;
423 // Removes an outgoing media stream.
424 // ssrc must be the first SSRC of the media stream if the stream uses
425 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200426 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427 // Creates a new incoming media stream with SSRCs and CNAME as described
428 // by sp.
429 virtual bool AddRecvStream(const StreamParams& sp) = 0;
430 // Removes an incoming media stream.
431 // ssrc must be the first SSRC of the media stream if the stream uses
432 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200433 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000435 // Returns the absoulte sendtime extension id value from media channel.
436 virtual int GetRtpSendTimeExtnId() const {
437 return -1;
438 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000440 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700441 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
442 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700443 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000444 }
445
jbaucheec21bd2016-03-20 06:15:43 -0700446 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
447 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700448 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000449 }
450
451 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000452 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000453 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000454 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000455 if (!network_interface_)
456 return -1;
457
458 return network_interface_->SetOption(type, opt, option);
459 }
460
nisse51542be2016-02-12 02:27:06 -0800461 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000462 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000463 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000464 int ret;
465 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000466 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000467 value);
468 if (ret == 0) {
469 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000470 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000471 value);
472 }
473 return ret;
474 }
475
jbaucheec21bd2016-03-20 06:15:43 -0700476 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700477 bool rtcp,
478 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000479 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000480 if (!network_interface_)
481 return false;
482
stefanc1aeaf02015-10-15 07:26:07 -0700483 return (!rtcp) ? network_interface_->SendPacket(packet, options)
484 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000485 }
486
nisse51542be2016-02-12 02:27:06 -0800487 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000488 // |network_interface_| can be accessed from the worker_thread and
489 // from any MediaEngine threads. This critical section is to protect accessing
490 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000491 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000492 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493};
494
wu@webrtc.org97077a32013-10-25 21:18:33 +0000495// The stats information is structured as follows:
496// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
497// Media contains a vector of SSRC infos that are exclusively used by this
498// media. (SSRCs shared between media streams can't be represented.)
499
500// Information about an SSRC.
501// This data may be locally recorded, or received in an RTCP SR or RR.
502struct SsrcSenderInfo {
503 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000505 timestamp(0) {
506 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200507 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000508 double timestamp; // NTP timestamp, represented as seconds since epoch.
509};
510
511struct SsrcReceiverInfo {
512 SsrcReceiverInfo()
513 : ssrc(0),
514 timestamp(0) {
515 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200516 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000517 double timestamp;
518};
519
520struct MediaSenderInfo {
521 MediaSenderInfo()
522 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000523 packets_sent(0),
524 packets_lost(0),
525 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000526 rtt_ms(0) {
527 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000528 void add_ssrc(const SsrcSenderInfo& stat) {
529 local_stats.push_back(stat);
530 }
531 // Temporary utility function for call sites that only provide SSRC.
532 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200533 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000534 SsrcSenderInfo stat;
535 stat.ssrc = ssrc;
536 add_ssrc(stat);
537 }
538 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200539 std::vector<uint32_t> ssrcs() const {
540 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000541 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
542 it != local_stats.end(); ++it) {
543 retval.push_back(it->ssrc);
544 }
545 return retval;
546 }
547 // Utility accessor for clients that make the assumption only one ssrc
548 // exists per media.
549 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200550 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000551 if (local_stats.size() > 0) {
552 return local_stats[0].ssrc;
553 } else {
554 return 0;
555 }
556 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200557 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000558 int packets_sent;
559 int packets_lost;
560 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000561 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000562 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800563 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000564 std::vector<SsrcSenderInfo> local_stats;
565 std::vector<SsrcReceiverInfo> remote_stats;
566};
567
568struct MediaReceiverInfo {
569 MediaReceiverInfo()
570 : bytes_rcvd(0),
571 packets_rcvd(0),
572 packets_lost(0),
573 fraction_lost(0.0) {
574 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000575 void add_ssrc(const SsrcReceiverInfo& stat) {
576 local_stats.push_back(stat);
577 }
578 // Temporary utility function for call sites that only provide SSRC.
579 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200580 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000581 SsrcReceiverInfo stat;
582 stat.ssrc = ssrc;
583 add_ssrc(stat);
584 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200585 std::vector<uint32_t> ssrcs() const {
586 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000587 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
588 it != local_stats.end(); ++it) {
589 retval.push_back(it->ssrc);
590 }
591 return retval;
592 }
593 // Utility accessor for clients that make the assumption only one ssrc
594 // exists per media.
595 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200596 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000597 if (local_stats.size() > 0) {
598 return local_stats[0].ssrc;
599 } else {
600 return 0;
601 }
602 }
603
Peter Boström0c4e06b2015-10-07 12:23:21 +0200604 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000605 int packets_rcvd;
606 int packets_lost;
607 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000608 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800609 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000610 std::vector<SsrcReceiverInfo> local_stats;
611 std::vector<SsrcSenderInfo> remote_stats;
612};
613
614struct VoiceSenderInfo : public MediaSenderInfo {
615 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000616 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000617 jitter_ms(0),
618 audio_level(0),
zsteine76bd3a2017-07-14 12:17:49 -0700619 total_input_energy(0.0),
620 total_input_duration(0.0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000621 aec_quality_min(0.0),
622 echo_delay_median_ms(0),
623 echo_delay_std_ms(0),
624 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000625 echo_return_loss_enhancement(0),
ivoc8c63a822016-10-21 04:10:03 -0700626 residual_echo_likelihood(0.0f),
ivoc4e477a12017-01-15 08:29:46 -0800627 residual_echo_likelihood_recent_max(0.0f),
628 typing_noise_detected(false) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000631 int jitter_ms;
632 int audio_level;
zsteine76bd3a2017-07-14 12:17:49 -0700633 // See description of "totalAudioEnergy" in the WebRTC stats spec:
634 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
635 double total_input_energy;
636 double total_input_duration;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637 float aec_quality_min;
638 int echo_delay_median_ms;
639 int echo_delay_std_ms;
640 int echo_return_loss;
641 int echo_return_loss_enhancement;
ivoc8c63a822016-10-21 04:10:03 -0700642 float residual_echo_likelihood;
ivoc4e477a12017-01-15 08:29:46 -0800643 float residual_echo_likelihood_recent_max;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000644 bool typing_noise_detected;
ivoce1198e02017-09-08 08:13:19 -0700645 webrtc::ANAStats ana_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646};
647
wu@webrtc.org97077a32013-10-25 21:18:33 +0000648struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000649 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000650 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000651 jitter_ms(0),
652 jitter_buffer_ms(0),
653 jitter_buffer_preferred_ms(0),
654 delay_estimate_ms(0),
655 audio_level(0),
zsteine76bd3a2017-07-14 12:17:49 -0700656 total_output_energy(0.0),
Steve Anton2dbc69f2017-08-24 17:15:13 -0700657 total_samples_received(0),
zsteine76bd3a2017-07-14 12:17:49 -0700658 total_output_duration(0.0),
Steve Anton2dbc69f2017-08-24 17:15:13 -0700659 concealed_samples(0),
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200660 concealment_events(0),
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200661 jitter_buffer_delay_seconds(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000662 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000663 speech_expand_rate(0),
664 secondary_decoded_rate(0),
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200665 secondary_discarded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200666 accelerate_rate(0),
667 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000668 decoding_calls_to_silence_generator(0),
669 decoding_calls_to_neteq(0),
670 decoding_normal(0),
671 decoding_plc(0),
672 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000673 decoding_plc_cng(0),
henrik.lundin63489782016-09-20 01:47:12 -0700674 decoding_muted_output(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200675 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677 int ext_seqnum;
678 int jitter_ms;
679 int jitter_buffer_ms;
680 int jitter_buffer_preferred_ms;
681 int delay_estimate_ms;
682 int audio_level;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200683 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
684 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
zsteine76bd3a2017-07-14 12:17:49 -0700685 double total_output_energy;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700686 uint64_t total_samples_received;
zsteine76bd3a2017-07-14 12:17:49 -0700687 double total_output_duration;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700688 uint64_t concealed_samples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200689 uint64_t concealment_events;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200690 double jitter_buffer_delay_seconds;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200691 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000692 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000694 // fraction of synthesized speech inserted through expansion.
695 float speech_expand_rate;
696 // fraction of data out of secondary decoding, including FEC and RED.
697 float secondary_decoded_rate;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200698 // Fraction of secondary data, including FEC and RED, that is discarded.
699 // Discarding of secondary data can be caused by the reception of the primary
700 // data, obsoleting the secondary data. It can also be caused by early
701 // or late arrival of secondary data. This metric is the percentage of
702 // discarded secondary data since last query of receiver info.
703 float secondary_discarded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200704 // Fraction of data removed through time compression.
705 float accelerate_rate;
706 // Fraction of data inserted through time stretching.
707 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000708 int decoding_calls_to_silence_generator;
709 int decoding_calls_to_neteq;
710 int decoding_normal;
711 int decoding_plc;
712 int decoding_cng;
713 int decoding_plc_cng;
henrik.lundin63489782016-09-20 01:47:12 -0700714 int decoding_muted_output;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000715 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200716 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717};
718
wu@webrtc.org97077a32013-10-25 21:18:33 +0000719struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000721 : packets_cached(0),
722 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000723 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000725 send_frame_width(0),
726 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 framerate_input(0),
728 framerate_sent(0),
729 nominal_bitrate(0),
730 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000731 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000732 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000733 avg_encode_ms(0),
sakal43536c32016-10-24 01:46:43 -0700734 encode_usage_percent(0),
ilnik50864a82017-09-06 12:32:35 -0700735 frames_encoded(0),
736 content_type(webrtc::VideoContentType::UNSPECIFIED) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000738 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800739 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100740 std::string encoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000741 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000743 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000745 int send_frame_width;
746 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 int framerate_input;
748 int framerate_sent;
749 int nominal_bitrate;
750 int preferred_bitrate;
751 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000752 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000753 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000754 int encode_usage_percent;
sakal43536c32016-10-24 01:46:43 -0700755 uint32_t frames_encoded;
sakal87da4042016-10-31 06:53:47 -0700756 rtc::Optional<uint64_t> qp_sum;
ilnik50864a82017-09-06 12:32:35 -0700757 webrtc::VideoContentType content_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758};
759
wu@webrtc.org97077a32013-10-25 21:18:33 +0000760struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000762 : packets_concealed(0),
763 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000764 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765 nacks_sent(0),
766 frame_width(0),
767 frame_height(0),
768 framerate_rcvd(0),
769 framerate_decoded(0),
770 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000771 framerate_render_input(0),
772 framerate_render_output(0),
hbos42f6d2f2017-01-20 03:56:50 -0800773 frames_received(0),
sakale5ba44e2016-10-26 07:09:24 -0700774 frames_decoded(0),
hbos50cfe1f2017-01-23 07:21:55 -0800775 frames_rendered(0),
ilnika79cc282017-08-23 05:24:10 -0700776 interframe_delay_max_ms(-1),
ilnik2e1b40b2017-09-04 07:57:17 -0700777 content_type(webrtc::VideoContentType::UNSPECIFIED),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000778 decode_ms(0),
779 max_decode_ms(0),
780 jitter_buffer_ms(0),
781 min_playout_delay_ms(0),
782 render_delay_ms(0),
783 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000784 current_delay_ms(0),
ilnik2edc6842017-07-06 03:06:50 -0700785 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000787 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800788 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100789 std::string decoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000790 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000792 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 int nacks_sent;
794 int frame_width;
795 int frame_height;
796 int framerate_rcvd;
797 int framerate_decoded;
798 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000799 // Framerate as sent to the renderer.
800 int framerate_render_input;
801 // Framerate that the renderer reports.
802 int framerate_render_output;
hbos42f6d2f2017-01-20 03:56:50 -0800803 uint32_t frames_received;
sakale5ba44e2016-10-26 07:09:24 -0700804 uint32_t frames_decoded;
hbos50cfe1f2017-01-23 07:21:55 -0800805 uint32_t frames_rendered;
sakalcc452e12017-02-09 04:53:45 -0800806 rtc::Optional<uint64_t> qp_sum;
ilnika79cc282017-08-23 05:24:10 -0700807 int64_t interframe_delay_max_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000808
ilnik2e1b40b2017-09-04 07:57:17 -0700809 webrtc::VideoContentType content_type;
810
wu@webrtc.org97077a32013-10-25 21:18:33 +0000811 // All stats below are gathered per-VideoReceiver, but some will be correlated
812 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
813 // structures, reflect this in the new layout.
814
815 // Current frame decode latency.
816 int decode_ms;
817 // Maximum observed frame decode latency.
818 int max_decode_ms;
819 // Jitter (network-related) latency.
820 int jitter_buffer_ms;
821 // Requested minimum playout latency.
822 int min_playout_delay_ms;
823 // Requested latency to account for rendering delay.
824 int render_delay_ms;
825 // Target overall delay: network+decode+render, accounting for
826 // min_playout_delay_ms.
827 int target_delay_ms;
828 // Current overall delay, possibly ramping towards target_delay_ms.
829 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000830
831 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200832 int64_t capture_start_ntp_time_ms;
ilnik2edc6842017-07-06 03:06:50 -0700833
834 // Timing frame info: all important timestamps for a full lifetime of a
835 // single 'timing frame'.
836 rtc::Optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837};
838
wu@webrtc.org97077a32013-10-25 21:18:33 +0000839struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000841 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 }
843
Peter Boström0c4e06b2015-10-07 12:23:21 +0200844 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845};
846
wu@webrtc.org97077a32013-10-25 21:18:33 +0000847struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000849 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 }
851
Peter Boström0c4e06b2015-10-07 12:23:21 +0200852 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853};
854
855struct BandwidthEstimationInfo {
856 BandwidthEstimationInfo()
857 : available_send_bandwidth(0),
858 available_recv_bandwidth(0),
859 target_enc_bitrate(0),
860 actual_enc_bitrate(0),
861 retransmit_bitrate(0),
862 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000863 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 }
865
866 int available_send_bandwidth;
867 int available_recv_bandwidth;
868 int target_enc_bitrate;
869 int actual_enc_bitrate;
870 int retransmit_bitrate;
871 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000872 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873};
874
hbosa65704b2016-11-14 02:28:16 -0800875// Maps from payload type to |RtpCodecParameters|.
876typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
877
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878struct VoiceMediaInfo {
879 void Clear() {
880 senders.clear();
881 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800882 send_codecs.clear();
883 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 }
885 std::vector<VoiceSenderInfo> senders;
886 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800887 RtpCodecParametersMap send_codecs;
888 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889};
890
891struct VideoMediaInfo {
892 void Clear() {
893 senders.clear();
894 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700895 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800896 send_codecs.clear();
897 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 }
899 std::vector<VideoSenderInfo> senders;
900 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700901 // Deprecated.
902 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700903 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800904 RtpCodecParametersMap send_codecs;
905 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906};
907
908struct DataMediaInfo {
909 void Clear() {
910 senders.clear();
911 receivers.clear();
912 }
913 std::vector<DataSenderInfo> senders;
914 std::vector<DataReceiverInfo> receivers;
915};
916
deadbeef13871492015-12-09 12:37:51 -0800917struct RtcpParameters {
918 bool reduced_size = false;
919};
920
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700921template <class Codec>
922struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800923 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700924 std::ostringstream ost;
925 ost << "{";
926 ost << "codecs: " << VectorToString(codecs) << ", ";
927 ost << "extensions: " << VectorToString(extensions);
928 ost << "}";
929 return ost.str();
930 }
931
932 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700933 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700934 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800935 RtcpParameters rtcp;
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200936 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700937};
938
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700939// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
940// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700941template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700942struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800943 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700944 std::ostringstream ost;
945 ost << "{";
946 ost << "codecs: " << VectorToString(this->codecs) << ", ";
947 ost << "extensions: " << VectorToString(this->extensions) << ", ";
pbos378dc772016-01-28 15:58:41 -0800948 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
nisse05103312016-03-16 02:22:50 -0700949 ost << "}";
950 return ost.str();
951 }
952
953 int max_bandwidth_bps = -1;
954};
955
956struct AudioSendParameters : RtpSendParameters<AudioCodec> {
957 std::string ToString() const override {
958 std::ostringstream ost;
959 ost << "{";
960 ost << "codecs: " << VectorToString(this->codecs) << ", ";
961 ost << "extensions: " << VectorToString(this->extensions) << ", ";
962 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700963 ost << "options: " << options.ToString();
964 ost << "}";
965 return ost.str();
966 }
967
nisse05103312016-03-16 02:22:50 -0700968 AudioOptions options;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700969};
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() {}
terelius54f91712016-06-01 11:18:56 -0700998 explicit VoiceMediaChannel(const MediaConfig& config)
999 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001001 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
1002 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001003 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
1004 virtual bool SetRtpSendParameters(
1005 uint32_t ssrc,
1006 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -07001007 // Get the receive parameters for the incoming stream identified by |ssrc|.
1008 // If |ssrc| is 0, retrieve the receive parameters for the default receive
1009 // stream, which is used when SSRCs are not signaled. Note that calling with
1010 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
1011 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001012 virtual webrtc::RtpParameters GetRtpReceiveParameters(
1013 uint32_t ssrc) const = 0;
1014 virtual bool SetRtpReceiveParameters(
1015 uint32_t ssrc,
1016 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -07001018 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08001020 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -07001021 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001022 virtual bool SetAudioSend(uint32_t ssrc,
1023 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -07001024 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08001025 AudioSource* source) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026 // Gets current energy levels for all incoming streams.
1027 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
1028 // Get the current energy level of the stream sent to the speaker.
1029 virtual int GetOutputLevel() = 0;
solenberg4bac9c52015-10-09 02:32:53 -07001030 // Set speaker output volume of the specified ssrc.
1031 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -08001033 virtual bool CanInsertDtmf() = 0;
1034 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001036 // The valid value for the |event| are 0 to 15 which corresponding to
1037 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -08001038 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039 // Gets quality stats for the channel.
1040 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +01001041
1042 virtual void SetRawAudioSink(
1043 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -08001044 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -07001045
1046 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047};
1048
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001049// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
1050// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -07001051struct VideoSendParameters : RtpSendParameters<VideoCodec> {
nisse4b4dc862016-02-17 05:25:36 -08001052 // Use conference mode? This flag comes from the remote
1053 // description's SDP line 'a=x-google-flag:conference', copied over
1054 // by VideoChannel::SetRemoteContent_w, and ultimately used by
1055 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -07001056 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -08001057 // The special screencast behaviour is disabled by default.
1058 bool conference_mode = false;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001059};
1060
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001061// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
1062// encapsulate all the parameters needed for a video RtpReceiver.
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001063struct VideoRecvParameters : RtpParameters<VideoCodec> {
1064};
1065
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001066class VideoMediaChannel : public MediaChannel {
1067 public:
1068 enum Error {
1069 ERROR_NONE = 0, // No error.
1070 ERROR_OTHER, // Other errors.
1071 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1072 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1073 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1074 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1075 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1076 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1077 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1078 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1079 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1080 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1081 };
1082
nisse08582ff2016-02-04 01:24:52 -08001083 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -07001084 explicit VideoMediaChannel(const MediaConfig& config)
1085 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001087
1088 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
1089 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001090 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
1091 virtual bool SetRtpSendParameters(
1092 uint32_t ssrc,
1093 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -07001094 // Get the receive parameters for the incoming stream identified by |ssrc|.
1095 // If |ssrc| is 0, retrieve the receive parameters for the default receive
1096 // stream, which is used when SSRCs are not signaled. Note that calling with
1097 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
1098 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001099 virtual webrtc::RtpParameters GetRtpReceiveParameters(
1100 uint32_t ssrc) const = 0;
1101 virtual bool SetRtpReceiveParameters(
1102 uint32_t ssrc,
1103 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 // Gets the currently set codecs/payload types to be used for outgoing media.
1105 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 // Starts or stops transmission (and potentially capture) of local video.
1107 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -07001108 // Configure stream for sending and register a source.
1109 // The |ssrc| must correspond to a registered send stream.
1110 virtual bool SetVideoSend(
1111 uint32_t ssrc,
1112 bool enable,
1113 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -08001114 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -08001115 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -07001116 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -08001117 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -08001118 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -07001119 // This fills the "bitrate parts" (rtx, video bitrate) of the
1120 // BandwidthEstimationInfo, since that part that isn't possible to get
1121 // through webrtc::Call::GetStats, as they are statistics of the send
1122 // streams.
1123 // TODO(holmer): We should change this so that either BWE graphs doesn't
1124 // need access to bitrates of the streams, or change the (RTC)StatsCollector
1125 // so that it's getting the send stream stats separately by calling
1126 // GetStats(), and merges with BandwidthEstimationInfo by itself.
1127 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001129 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130};
1131
1132enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001133 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1134 // values.
1135 DMT_NONE = 0,
1136 DMT_CONTROL = 1,
1137 DMT_BINARY = 2,
1138 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139};
1140
1141// Info about data received in DataMediaChannel. For use in
1142// DataMediaChannel::SignalDataReceived and in all of the signals that
1143// signal fires, on up the chain.
1144struct ReceiveDataParams {
1145 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001146 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1147 union {
1148 uint32_t ssrc;
1149 int sid;
1150 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001151 // The type of message (binary, text, or control).
1152 DataMessageType type;
1153 // A per-stream value incremented per packet in the stream.
1154 int seq_num;
1155 // A per-stream value monotonically increasing with time.
1156 int timestamp;
1157
deadbeef953c2ce2017-01-09 14:53:41 -08001158 ReceiveDataParams() : sid(0), type(DMT_TEXT), seq_num(0), timestamp(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001159};
1160
1161struct SendDataParams {
1162 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001163 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1164 union {
1165 uint32_t ssrc;
1166 int sid;
1167 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001168 // The type of message (binary, text, or control).
1169 DataMessageType type;
1170
1171 // For SCTP, whether to send messages flagged as ordered or not.
1172 // If false, messages can be received out of order.
1173 bool ordered;
1174 // For SCTP, whether the messages are sent reliably or not.
1175 // If false, messages may be lost.
1176 bool reliable;
1177 // For SCTP, if reliable == false, provide partial reliability by
1178 // resending up to this many times. Either count or millis
1179 // is supported, not both at the same time.
1180 int max_rtx_count;
1181 // For SCTP, if reliable == false, provide partial reliability by
1182 // resending for up to this many milliseconds. Either count or millis
1183 // is supported, not both at the same time.
1184 int max_rtx_ms;
1185
deadbeef953c2ce2017-01-09 14:53:41 -08001186 SendDataParams()
1187 : sid(0),
1188 type(DMT_TEXT),
1189 // TODO(pthatcher): Make these true by default?
1190 ordered(false),
1191 reliable(false),
1192 max_rtx_count(0),
1193 max_rtx_ms(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001194};
1195
1196enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1197
nisse05103312016-03-16 02:22:50 -07001198struct DataSendParameters : RtpSendParameters<DataCodec> {
solenberg7e4e01a2015-12-02 08:05:01 -08001199 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001200 std::ostringstream ost;
1201 // Options and extensions aren't used.
1202 ost << "{";
1203 ost << "codecs: " << VectorToString(codecs) << ", ";
pbos378dc772016-01-28 15:58:41 -08001204 ost << "max_bandwidth_bps: " << max_bandwidth_bps;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001205 ost << "}";
1206 return ost.str();
1207 }
1208};
1209
1210struct DataRecvParameters : RtpParameters<DataCodec> {
1211};
1212
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213class DataMediaChannel : public MediaChannel {
1214 public:
1215 enum Error {
1216 ERROR_NONE = 0, // No error.
1217 ERROR_OTHER, // Other errors.
1218 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1219 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1220 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1221 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1222 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1223 };
1224
zhihuangebbe4f22016-12-06 10:45:42 -08001225 DataMediaChannel() {}
1226 DataMediaChannel(const MediaConfig& config) : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001227 virtual ~DataMediaChannel() {}
1228
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001229 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1230 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001231
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 // TODO(pthatcher): Implement this.
1233 virtual bool GetStats(DataMediaInfo* info) { return true; }
1234
1235 virtual bool SetSend(bool send) = 0;
1236 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237
Honghai Zhangcc411c02016-03-29 17:27:21 -07001238 virtual void OnNetworkRouteChanged(const std::string& transport_name,
Honghai Zhang0e533ef2016-04-19 15:41:36 -07001239 const rtc::NetworkRoute& network_route) {}
Honghai Zhangcc411c02016-03-29 17:27:21 -07001240
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001241 virtual bool SendData(
1242 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -07001243 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001244 SendDataResult* result = NULL) = 0;
1245 // Signals when data is received (params, data, len)
1246 sigslot::signal3<const ReceiveDataParams&,
1247 const char*,
1248 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001249 // Signal when the media channel is ready to send the stream. Arguments are:
1250 // writable(bool)
1251 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252};
1253
1254} // namespace cricket
1255
Mirko Bonadei92ea95e2017-09-15 06:47:31 +02001256#endif // MEDIA_BASE_MEDIACHANNEL_H_