blob: 5768944122b0c3fe0916500a5f59cab97ed9fa48 [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
Steve Antone78bcb92017-10-31 09:53:08 -070014#include <map>
kwiberg686a8ef2016-02-26 03:00:35 -080015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
Patrik Höglundaba85d12017-11-28 15:46:08 +010017#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <vector>
19
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "api/audio_codecs/audio_encoder.h"
21#include "api/optional.h"
22#include "api/rtpparameters.h"
23#include "api/rtpreceiverinterface.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010024#include "api/video/video_content_type.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "api/video/video_timing.h"
26#include "call/video_config.h"
27#include "media/base/codec.h"
28#include "media/base/mediaconstants.h"
29#include "media/base/streamparams.h"
30#include "media/base/videosinkinterface.h"
31#include "media/base/videosourceinterface.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010032#include "modules/audio_processing/include/audio_processing_statistics.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010033#include "rtc_base/asyncpacketsocket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020034#include "rtc_base/basictypes.h"
35#include "rtc_base/buffer.h"
36#include "rtc_base/copyonwritebuffer.h"
37#include "rtc_base/dscp.h"
38#include "rtc_base/logging.h"
39#include "rtc_base/networkroute.h"
40#include "rtc_base/sigslot.h"
41#include "rtc_base/socket.h"
Niels Möller9a44f962017-12-08 15:57:38 +010042#include "rtc_base/stringencode.h"
Patrik Höglundaba85d12017-11-28 15:46:08 +010043
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000045namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046class RateLimiter;
47class Timing;
48}
49
Tommif888bb52015-12-12 01:37:01 +010050namespace webrtc {
51class AudioSinkInterface;
nisseacd935b2016-11-11 03:55:13 -080052class VideoFrame;
Tommif888bb52015-12-12 01:37:01 +010053}
54
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055namespace cricket {
56
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -080057class AudioSource;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058class VideoCapturer;
tommi1d5c19d2015-12-13 22:54:29 -080059struct RtpHeader;
60struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062const int kScreencastDefaultFps = 5;
63
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064template <class T>
Karl Wibergbe579832015-11-10 22:34:18 +010065static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070067 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068 str = key;
69 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070070 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071 str += ", ";
72 }
73 return str;
74}
75
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070076template <class T>
77static std::string VectorToString(const std::vector<T>& vals) {
78 std::ostringstream ost;
79 ost << "[";
80 for (size_t i = 0; i < vals.size(); ++i) {
81 if (i > 0) {
82 ost << ", ";
83 }
84 ost << vals[i].ToString();
85 }
86 ost << "]";
87 return ost.str();
88}
89
nisse528b7932017-05-08 03:21:43 -070090// Construction-time settings, passed on when creating
nisse51542be2016-02-12 02:27:06 -080091// MediaChannels.
92struct MediaConfig {
93 // Set DSCP value on packets. This flag comes from the
94 // PeerConnection constraint 'googDscp'.
95 bool enable_dscp = false;
96
nisse0db023a2016-03-01 04:29:59 -080097 // Video-specific config.
98 struct Video {
99 // Enable WebRTC CPU Overuse Detection. This flag comes from the
perkj803d97f2016-11-01 11:45:46 -0700100 // PeerConnection constraint 'googCpuOveruseDetection'.
nisse0db023a2016-03-01 04:29:59 -0800101 bool enable_cpu_overuse_detection = true;
nisse51542be2016-02-12 02:27:06 -0800102
nisse0db023a2016-03-01 04:29:59 -0800103 // Enable WebRTC suspension of video. No video frames will be sent
104 // when the bitrate is below the configured minimum bitrate. This
105 // flag comes from the PeerConnection constraint
eladalonf1841382017-06-12 01:16:46 -0700106 // 'googSuspendBelowMinBitrate', and WebRtcVideoChannel copies it
nisse0db023a2016-03-01 04:29:59 -0800107 // to VideoSendStream::Config::suspend_below_min_bitrate.
108 bool suspend_below_min_bitrate = false;
nisse51542be2016-02-12 02:27:06 -0800109
nisse0db023a2016-03-01 04:29:59 -0800110 // Set to true if the renderer has an algorithm of frame selection.
111 // If the value is true, then WebRTC will hand over a frame as soon as
112 // possible without delay, and rendering smoothness is completely the duty
113 // of the renderer;
114 // If the value is false, then WebRTC is responsible to delay frame release
115 // in order to increase rendering smoothness.
116 //
117 // This flag comes from PeerConnection's RtcConfiguration, but is
118 // currently only set by the command line flag
119 // 'disable-rtc-smoothness-algorithm'.
eladalonf1841382017-06-12 01:16:46 -0700120 // WebRtcVideoChannel::AddRecvStream copies it to the created
nisse0db023a2016-03-01 04:29:59 -0800121 // WebRtcVideoReceiveStream, where it is returned by the
122 // SmoothsRenderedFrames method. This method is used by the
123 // VideoReceiveStream, where the value is passed on to the
124 // IncomingVideoStream constructor.
125 bool disable_prerenderer_smoothing = false;
sergeyu80ed35e2016-11-28 13:11:13 -0800126
127 // Enables periodic bandwidth probing in application-limited region.
128 bool periodic_alr_bandwidth_probing = false;
nisse0db023a2016-03-01 04:29:59 -0800129 } video;
deadbeef293e9262017-01-11 12:28:30 -0800130
131 bool operator==(const MediaConfig& o) const {
132 return enable_dscp == o.enable_dscp &&
133 video.enable_cpu_overuse_detection ==
134 o.video.enable_cpu_overuse_detection &&
135 video.suspend_below_min_bitrate ==
136 o.video.suspend_below_min_bitrate &&
137 video.disable_prerenderer_smoothing ==
138 o.video.disable_prerenderer_smoothing &&
139 video.periodic_alr_bandwidth_probing ==
140 o.video.periodic_alr_bandwidth_probing;
141 }
142
143 bool operator!=(const MediaConfig& o) const { return !(*this == o); }
nisse51542be2016-02-12 02:27:06 -0800144};
145
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
147// Used to be flags, but that makes it hard to selectively apply options.
148// We are moving all of the setting of options to structs like this,
149// but some things currently still use flags.
150struct AudioOptions {
151 void SetAll(const AudioOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700152 SetFrom(&echo_cancellation, change.echo_cancellation);
153 SetFrom(&auto_gain_control, change.auto_gain_control);
154 SetFrom(&noise_suppression, change.noise_suppression);
155 SetFrom(&highpass_filter, change.highpass_filter);
156 SetFrom(&stereo_swapping, change.stereo_swapping);
157 SetFrom(&audio_jitter_buffer_max_packets,
158 change.audio_jitter_buffer_max_packets);
159 SetFrom(&audio_jitter_buffer_fast_accelerate,
160 change.audio_jitter_buffer_fast_accelerate);
161 SetFrom(&typing_detection, change.typing_detection);
162 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise);
kwiberg102c6a62015-10-30 02:47:38 -0700163 SetFrom(&experimental_agc, change.experimental_agc);
164 SetFrom(&extended_filter_aec, change.extended_filter_aec);
165 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec);
166 SetFrom(&experimental_ns, change.experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700167 SetFrom(&intelligibility_enhancer, change.intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700168 SetFrom(&level_control, change.level_control);
ivocb829d9f2016-11-15 02:34:47 -0800169 SetFrom(&residual_echo_detector, change.residual_echo_detector);
kwiberg102c6a62015-10-30 02:47:38 -0700170 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov);
171 SetFrom(&tx_agc_digital_compression_gain,
172 change.tx_agc_digital_compression_gain);
173 SetFrom(&tx_agc_limiter, change.tx_agc_limiter);
kwiberg102c6a62015-10-30 02:47:38 -0700174 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700175 SetFrom(&audio_network_adaptor, change.audio_network_adaptor);
176 SetFrom(&audio_network_adaptor_config, change.audio_network_adaptor_config);
aleloie33c5d92016-10-20 01:53:27 -0700177 SetFrom(&level_control_initial_peak_level_dbfs,
178 change.level_control_initial_peak_level_dbfs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 }
180
181 bool operator==(const AudioOptions& o) const {
182 return echo_cancellation == o.echo_cancellation &&
peaha3333bf2016-06-30 00:02:34 -0700183 auto_gain_control == o.auto_gain_control &&
184 noise_suppression == o.noise_suppression &&
185 highpass_filter == o.highpass_filter &&
186 stereo_swapping == o.stereo_swapping &&
187 audio_jitter_buffer_max_packets ==
188 o.audio_jitter_buffer_max_packets &&
189 audio_jitter_buffer_fast_accelerate ==
190 o.audio_jitter_buffer_fast_accelerate &&
191 typing_detection == o.typing_detection &&
192 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
193 experimental_agc == o.experimental_agc &&
194 extended_filter_aec == o.extended_filter_aec &&
195 delay_agnostic_aec == o.delay_agnostic_aec &&
196 experimental_ns == o.experimental_ns &&
197 intelligibility_enhancer == o.intelligibility_enhancer &&
198 level_control == o.level_control &&
ivocb829d9f2016-11-15 02:34:47 -0800199 residual_echo_detector == o.residual_echo_detector &&
peaha3333bf2016-06-30 00:02:34 -0700200 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 &&
aleloie33c5d92016-10-20 01:53:27 -0700204 combined_audio_video_bwe == o.combined_audio_video_bwe &&
minyue6b825df2016-10-31 04:08:32 -0700205 audio_network_adaptor == o.audio_network_adaptor &&
206 audio_network_adaptor_config == o.audio_network_adaptor_config &&
aleloie33c5d92016-10-20 01:53:27 -0700207 level_control_initial_peak_level_dbfs ==
208 o.level_control_initial_peak_level_dbfs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 }
deadbeef119760a2016-04-04 11:43:27 -0700210 bool operator!=(const AudioOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211
212 std::string ToString() const {
213 std::ostringstream ost;
214 ost << "AudioOptions {";
215 ost << ToStringIfSet("aec", echo_cancellation);
216 ost << ToStringIfSet("agc", auto_gain_control);
217 ost << ToStringIfSet("ns", noise_suppression);
218 ost << ToStringIfSet("hf", highpass_filter);
219 ost << ToStringIfSet("swap", stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200220 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
221 audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200222 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
223 audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000225 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 ost << ToStringIfSet("experimental_agc", experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200227 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100228 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000229 ost << ToStringIfSet("experimental_ns", experimental_ns);
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700230 ost << ToStringIfSet("intelligibility_enhancer", intelligibility_enhancer);
peaha3333bf2016-06-30 00:02:34 -0700231 ost << ToStringIfSet("level_control", level_control);
aleloie33c5d92016-10-20 01:53:27 -0700232 ost << ToStringIfSet("level_control_initial_peak_level_dbfs",
233 level_control_initial_peak_level_dbfs);
ivocb829d9f2016-11-15 02:34:47 -0800234 ost << ToStringIfSet("residual_echo_detector", residual_echo_detector);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000235 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
236 ost << ToStringIfSet("tx_agc_digital_compression_gain",
237 tx_agc_digital_compression_gain);
238 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000239 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
minyue6b825df2016-10-31 04:08:32 -0700240 ost << ToStringIfSet("audio_network_adaptor", audio_network_adaptor);
241 // The adaptor config is a serialized proto buffer and therefore not human
242 // readable. So we comment out the following line.
243 // ost << ToStringIfSet("audio_network_adaptor_config",
244 // audio_network_adaptor_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 ost << "}";
246 return ost.str();
247 }
248
249 // Audio processing that attempts to filter away the output signal from
250 // later inbound pickup.
Karl Wibergbe579832015-11-10 22:34:18 +0100251 rtc::Optional<bool> echo_cancellation;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 // Audio processing to adjust the sensitivity of the local mic dynamically.
Karl Wibergbe579832015-11-10 22:34:18 +0100253 rtc::Optional<bool> auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 // Audio processing to filter out background noise.
Karl Wibergbe579832015-11-10 22:34:18 +0100255 rtc::Optional<bool> noise_suppression;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 // Audio processing to remove background noise of lower frequencies.
Karl Wibergbe579832015-11-10 22:34:18 +0100257 rtc::Optional<bool> highpass_filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 // Audio processing to swap the left and right channels.
Karl Wibergbe579832015-11-10 22:34:18 +0100259 rtc::Optional<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200260 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Karl Wibergbe579832015-11-10 22:34:18 +0100261 rtc::Optional<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200262 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Karl Wibergbe579832015-11-10 22:34:18 +0100263 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 // Audio processing to detect typing.
Karl Wibergbe579832015-11-10 22:34:18 +0100265 rtc::Optional<bool> typing_detection;
266 rtc::Optional<bool> aecm_generate_comfort_noise;
Karl Wibergbe579832015-11-10 22:34:18 +0100267 rtc::Optional<bool> experimental_agc;
268 rtc::Optional<bool> extended_filter_aec;
269 rtc::Optional<bool> delay_agnostic_aec;
270 rtc::Optional<bool> experimental_ns;
Alejandro Luebsc9b0c262016-05-16 15:32:38 -0700271 rtc::Optional<bool> intelligibility_enhancer;
peaha3333bf2016-06-30 00:02:34 -0700272 rtc::Optional<bool> level_control;
aleloie33c5d92016-10-20 01:53:27 -0700273 // Specifies an optional initialization value for the level controller.
274 rtc::Optional<float> level_control_initial_peak_level_dbfs;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000275 // Note that tx_agc_* only applies to non-experimental AGC.
ivocb829d9f2016-11-15 02:34:47 -0800276 rtc::Optional<bool> residual_echo_detector;
Karl Wibergbe579832015-11-10 22:34:18 +0100277 rtc::Optional<uint16_t> tx_agc_target_dbov;
278 rtc::Optional<uint16_t> tx_agc_digital_compression_gain;
279 rtc::Optional<bool> tx_agc_limiter;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000280 // Enable combined audio+bandwidth BWE.
nisse51542be2016-02-12 02:27:06 -0800281 // TODO(pthatcher): This flag is set from the
282 // "googCombinedAudioVideoBwe", but not used anywhere. So delete it,
283 // and check if any other AudioOptions members are unused.
Karl Wibergbe579832015-11-10 22:34:18 +0100284 rtc::Optional<bool> combined_audio_video_bwe;
minyue6b825df2016-10-31 04:08:32 -0700285 // Enable audio network adaptor.
286 rtc::Optional<bool> audio_network_adaptor;
287 // Config string for audio network adaptor.
288 rtc::Optional<std::string> audio_network_adaptor_config;
kwiberg102c6a62015-10-30 02:47:38 -0700289
290 private:
291 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100292 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700293 if (o) {
294 *s = o;
295 }
296 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297};
298
299// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
300// Used to be flags, but that makes it hard to selectively apply options.
301// We are moving all of the setting of options to structs like this,
302// but some things currently still use flags.
303struct VideoOptions {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700305 SetFrom(&video_noise_reduction, change.video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800306 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100307 SetFrom(&is_screencast, change.is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 }
309
310 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800311 return video_noise_reduction == o.video_noise_reduction &&
Niels Möller60653ba2016-03-02 11:41:36 +0100312 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
313 is_screencast == o.is_screencast;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 }
deadbeef119760a2016-04-04 11:43:27 -0700315 bool operator!=(const VideoOptions& o) const { return !(*this == o); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316
317 std::string ToString() const {
318 std::ostringstream ost;
319 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 ost << ToStringIfSet("noise reduction", video_noise_reduction);
nisseb163c3f2016-01-29 01:14:38 -0800321 ost << ToStringIfSet("screencast min bitrate kbps",
322 screencast_min_bitrate_kbps);
Niels Möller60653ba2016-03-02 11:41:36 +0100323 ost << ToStringIfSet("is_screencast ", is_screencast);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 ost << "}";
325 return ost.str();
326 }
327
nisseb163c3f2016-01-29 01:14:38 -0800328 // Enable denoising? This flag comes from the getUserMedia
eladalonf1841382017-06-12 01:16:46 -0700329 // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it
nisseb163c3f2016-01-29 01:14:38 -0800330 // on to the codec options. Disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100331 rtc::Optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800332 // Force screencast to use a minimum bitrate. This flag comes from
333 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
eladalonf1841382017-06-12 01:16:46 -0700334 // copied to the encoder config by WebRtcVideoChannel.
nisseb163c3f2016-01-29 01:14:38 -0800335 rtc::Optional<int> screencast_min_bitrate_kbps;
Niels Möller60653ba2016-03-02 11:41:36 +0100336 // Set by screencast sources. Implies selection of encoding settings
337 // suitable for screencast. Most likely not the right way to do
338 // things, e.g., screencast of a text document and screencast of a
339 // youtube video have different needs.
340 rtc::Optional<bool> is_screencast;
kwiberg102c6a62015-10-30 02:47:38 -0700341
342 private:
343 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100344 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700345 if (o) {
346 *s = o;
347 }
348 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349};
350
isheriffa1c548b2016-05-31 16:12:24 -0700351// TODO(isheriff): Remove this once client usage is fixed to use RtpExtension.
352struct RtpHeaderExtension {
353 RtpHeaderExtension() : id(0) {}
354 RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {}
355
356 std::string ToString() const {
357 std::ostringstream ost;
358 ost << "{";
359 ost << "uri: " << uri;
360 ost << ", id: " << id;
361 ost << "}";
362 return ost.str();
363 }
364
365 std::string uri;
366 int id;
367};
368
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369class MediaChannel : public sigslot::has_slots<> {
370 public:
371 class NetworkInterface {
372 public:
373 enum SocketType { ST_RTP, ST_RTCP };
jbaucheec21bd2016-03-20 06:15:43 -0700374 virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700375 const rtc::PacketOptions& options) = 0;
jbaucheec21bd2016-03-20 06:15:43 -0700376 virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700377 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000378 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 int option) = 0;
380 virtual ~NetworkInterface() {}
381 };
382
terelius54f91712016-06-01 11:18:56 -0700383 explicit MediaChannel(const MediaConfig& config)
nisse51542be2016-02-12 02:27:06 -0800384 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
385 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 virtual ~MediaChannel() {}
387
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000388 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000390 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391 network_interface_ = iface;
nisse51542be2016-02-12 02:27:06 -0800392 SetDscp(enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 }
nisse51542be2016-02-12 02:27:06 -0800394 virtual rtc::DiffServCodePoint PreferredDscp() const {
395 return rtc::DSCP_DEFAULT;
396 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 // Called when a RTP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700398 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000399 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400 // Called when a RTCP packet is received.
jbaucheec21bd2016-03-20 06:15:43 -0700401 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000402 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 // Called when the socket's ability to send has changed.
404 virtual void OnReadyToSend(bool ready) = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -0700405 // Called when the network route used for sending packets changed.
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700406 virtual void OnNetworkRouteChanged(
407 const std::string& transport_name,
408 const rtc::NetworkRoute& network_route) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000409 // Creates a new outgoing media stream with SSRCs and CNAME as described
410 // by sp.
411 virtual bool AddSendStream(const StreamParams& sp) = 0;
412 // Removes an outgoing media stream.
413 // ssrc must be the first SSRC of the media stream if the stream uses
414 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200415 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416 // Creates a new incoming media stream with SSRCs and CNAME as described
417 // by sp.
418 virtual bool AddRecvStream(const StreamParams& sp) = 0;
419 // Removes an incoming 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 RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000423
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000424 // Returns the absoulte sendtime extension id value from media channel.
425 virtual int GetRtpSendTimeExtnId() const {
426 return -1;
427 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000429 // Base method to send packet using NetworkInterface.
jbaucheec21bd2016-03-20 06:15:43 -0700430 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
431 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700432 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000433 }
434
jbaucheec21bd2016-03-20 06:15:43 -0700435 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
436 const rtc::PacketOptions& options) {
stefanc1aeaf02015-10-15 07:26:07 -0700437 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000438 }
439
440 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000441 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000442 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000443 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000444 if (!network_interface_)
445 return -1;
446
447 return network_interface_->SetOption(type, opt, option);
448 }
449
nisse51542be2016-02-12 02:27:06 -0800450 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000451 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000452 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000453 int ret;
454 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000455 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000456 value);
457 if (ret == 0) {
458 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000459 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000460 value);
461 }
462 return ret;
463 }
464
jbaucheec21bd2016-03-20 06:15:43 -0700465 bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
stefanc1aeaf02015-10-15 07:26:07 -0700466 bool rtcp,
467 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000468 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000469 if (!network_interface_)
470 return false;
471
stefanc1aeaf02015-10-15 07:26:07 -0700472 return (!rtcp) ? network_interface_->SendPacket(packet, options)
473 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000474 }
475
nisse51542be2016-02-12 02:27:06 -0800476 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000477 // |network_interface_| can be accessed from the worker_thread and
478 // from any MediaEngine threads. This critical section is to protect accessing
479 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000480 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000481 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482};
483
wu@webrtc.org97077a32013-10-25 21:18:33 +0000484// The stats information is structured as follows:
485// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
486// Media contains a vector of SSRC infos that are exclusively used by this
487// media. (SSRCs shared between media streams can't be represented.)
488
489// Information about an SSRC.
490// This data may be locally recorded, or received in an RTCP SR or RR.
491struct SsrcSenderInfo {
492 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000494 timestamp(0) {
495 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200496 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000497 double timestamp; // NTP timestamp, represented as seconds since epoch.
498};
499
500struct SsrcReceiverInfo {
501 SsrcReceiverInfo()
502 : ssrc(0),
503 timestamp(0) {
504 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200505 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000506 double timestamp;
507};
508
509struct MediaSenderInfo {
510 MediaSenderInfo()
511 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512 packets_sent(0),
513 packets_lost(0),
514 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000515 rtt_ms(0) {
516 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000517 void add_ssrc(const SsrcSenderInfo& stat) {
518 local_stats.push_back(stat);
519 }
520 // Temporary utility function for call sites that only provide SSRC.
521 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200522 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000523 SsrcSenderInfo stat;
524 stat.ssrc = ssrc;
525 add_ssrc(stat);
526 }
527 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200528 std::vector<uint32_t> ssrcs() const {
529 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000530 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
531 it != local_stats.end(); ++it) {
532 retval.push_back(it->ssrc);
533 }
534 return retval;
535 }
536 // Utility accessor for clients that make the assumption only one ssrc
537 // exists per media.
538 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200539 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000540 if (local_stats.size() > 0) {
541 return local_stats[0].ssrc;
542 } else {
543 return 0;
544 }
545 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200546 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000547 int packets_sent;
548 int packets_lost;
549 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000550 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000551 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800552 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000553 std::vector<SsrcSenderInfo> local_stats;
554 std::vector<SsrcReceiverInfo> remote_stats;
555};
556
557struct MediaReceiverInfo {
558 MediaReceiverInfo()
559 : bytes_rcvd(0),
560 packets_rcvd(0),
561 packets_lost(0),
562 fraction_lost(0.0) {
563 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000564 void add_ssrc(const SsrcReceiverInfo& stat) {
565 local_stats.push_back(stat);
566 }
567 // Temporary utility function for call sites that only provide SSRC.
568 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200569 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000570 SsrcReceiverInfo stat;
571 stat.ssrc = ssrc;
572 add_ssrc(stat);
573 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200574 std::vector<uint32_t> ssrcs() const {
575 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000576 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
577 it != local_stats.end(); ++it) {
578 retval.push_back(it->ssrc);
579 }
580 return retval;
581 }
582 // Utility accessor for clients that make the assumption only one ssrc
583 // exists per media.
584 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200585 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000586 if (local_stats.size() > 0) {
587 return local_stats[0].ssrc;
588 } else {
589 return 0;
590 }
591 }
592
Peter Boström0c4e06b2015-10-07 12:23:21 +0200593 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000594 int packets_rcvd;
595 int packets_lost;
596 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000597 std::string codec_name;
hbos1acfbd22016-11-17 23:43:29 -0800598 rtc::Optional<int> codec_payload_type;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000599 std::vector<SsrcReceiverInfo> local_stats;
600 std::vector<SsrcSenderInfo> remote_stats;
601};
602
603struct VoiceSenderInfo : public MediaSenderInfo {
604 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000605 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606 jitter_ms(0),
607 audio_level(0),
zsteine76bd3a2017-07-14 12:17:49 -0700608 total_input_energy(0.0),
609 total_input_duration(0.0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 echo_delay_median_ms(0),
611 echo_delay_std_ms(0),
612 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000613 echo_return_loss_enhancement(0),
ivoc8c63a822016-10-21 04:10:03 -0700614 residual_echo_likelihood(0.0f),
ivoc4e477a12017-01-15 08:29:46 -0800615 residual_echo_likelihood_recent_max(0.0f),
616 typing_noise_detected(false) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000617
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000619 int jitter_ms;
620 int audio_level;
zsteine76bd3a2017-07-14 12:17:49 -0700621 // See description of "totalAudioEnergy" in the WebRTC stats spec:
622 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
623 double total_input_energy;
624 double total_input_duration;
Ivo Creusen56d46092017-11-24 17:29:59 +0100625 // TODO(bugs.webrtc.org/8572): Remove APM stats from this struct, since they
626 // are no longer needed now that we have apm_statistics.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 int echo_delay_median_ms;
628 int echo_delay_std_ms;
629 int echo_return_loss;
630 int echo_return_loss_enhancement;
ivoc8c63a822016-10-21 04:10:03 -0700631 float residual_echo_likelihood;
ivoc4e477a12017-01-15 08:29:46 -0800632 float residual_echo_likelihood_recent_max;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000633 bool typing_noise_detected;
ivoce1198e02017-09-08 08:13:19 -0700634 webrtc::ANAStats ana_statistics;
Ivo Creusen56d46092017-11-24 17:29:59 +0100635 webrtc::AudioProcessingStats apm_statistics;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636};
637
wu@webrtc.org97077a32013-10-25 21:18:33 +0000638struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000640 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641 jitter_ms(0),
642 jitter_buffer_ms(0),
643 jitter_buffer_preferred_ms(0),
644 delay_estimate_ms(0),
645 audio_level(0),
zsteine76bd3a2017-07-14 12:17:49 -0700646 total_output_energy(0.0),
Steve Anton2dbc69f2017-08-24 17:15:13 -0700647 total_samples_received(0),
zsteine76bd3a2017-07-14 12:17:49 -0700648 total_output_duration(0.0),
Steve Anton2dbc69f2017-08-24 17:15:13 -0700649 concealed_samples(0),
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200650 concealment_events(0),
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200651 jitter_buffer_delay_seconds(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000652 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000653 speech_expand_rate(0),
654 secondary_decoded_rate(0),
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200655 secondary_discarded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200656 accelerate_rate(0),
657 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000658 decoding_calls_to_silence_generator(0),
659 decoding_calls_to_neteq(0),
660 decoding_normal(0),
661 decoding_plc(0),
662 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000663 decoding_plc_cng(0),
henrik.lundin63489782016-09-20 01:47:12 -0700664 decoding_muted_output(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200665 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000667 int ext_seqnum;
668 int jitter_ms;
669 int jitter_buffer_ms;
670 int jitter_buffer_preferred_ms;
671 int delay_estimate_ms;
672 int audio_level;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200673 // Stats below correspond to similarly-named fields in the WebRTC stats spec.
674 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
zsteine76bd3a2017-07-14 12:17:49 -0700675 double total_output_energy;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700676 uint64_t total_samples_received;
zsteine76bd3a2017-07-14 12:17:49 -0700677 double total_output_duration;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700678 uint64_t concealed_samples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200679 uint64_t concealment_events;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200680 double jitter_buffer_delay_seconds;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200681 // Stats below DO NOT correspond directly to anything in the WebRTC stats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000682 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000684 // fraction of synthesized speech inserted through expansion.
685 float speech_expand_rate;
686 // fraction of data out of secondary decoding, including FEC and RED.
687 float secondary_decoded_rate;
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200688 // Fraction of secondary data, including FEC and RED, that is discarded.
689 // Discarding of secondary data can be caused by the reception of the primary
690 // data, obsoleting the secondary data. It can also be caused by early
691 // or late arrival of secondary data. This metric is the percentage of
692 // discarded secondary data since last query of receiver info.
693 float secondary_discarded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200694 // Fraction of data removed through time compression.
695 float accelerate_rate;
696 // Fraction of data inserted through time stretching.
697 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000698 int decoding_calls_to_silence_generator;
699 int decoding_calls_to_neteq;
700 int decoding_normal;
701 int decoding_plc;
702 int decoding_cng;
703 int decoding_plc_cng;
henrik.lundin63489782016-09-20 01:47:12 -0700704 int decoding_muted_output;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000705 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200706 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707};
708
wu@webrtc.org97077a32013-10-25 21:18:33 +0000709struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000711 : packets_cached(0),
712 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000713 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000715 send_frame_width(0),
716 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 framerate_input(0),
718 framerate_sent(0),
719 nominal_bitrate(0),
720 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000721 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000722 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000723 avg_encode_ms(0),
sakal43536c32016-10-24 01:46:43 -0700724 encode_usage_percent(0),
ilnik50864a82017-09-06 12:32:35 -0700725 frames_encoded(0),
Åsa Perssonc3ed6302017-11-16 14:04:52 +0100726 has_entered_low_resolution(false),
ilnik50864a82017-09-06 12:32:35 -0700727 content_type(webrtc::VideoContentType::UNSPECIFIED) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000729 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800730 // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100731 std::string encoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000732 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000734 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000736 int send_frame_width;
737 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 int framerate_input;
739 int framerate_sent;
740 int nominal_bitrate;
741 int preferred_bitrate;
742 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000743 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000744 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000745 int encode_usage_percent;
sakal43536c32016-10-24 01:46:43 -0700746 uint32_t frames_encoded;
Åsa Perssonc3ed6302017-11-16 14:04:52 +0100747 bool has_entered_low_resolution;
sakal87da4042016-10-31 06:53:47 -0700748 rtc::Optional<uint64_t> qp_sum;
ilnik50864a82017-09-06 12:32:35 -0700749 webrtc::VideoContentType content_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750};
751
wu@webrtc.org97077a32013-10-25 21:18:33 +0000752struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000754 : packets_concealed(0),
755 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000756 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 nacks_sent(0),
758 frame_width(0),
759 frame_height(0),
760 framerate_rcvd(0),
761 framerate_decoded(0),
762 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000763 framerate_render_input(0),
764 framerate_render_output(0),
hbos42f6d2f2017-01-20 03:56:50 -0800765 frames_received(0),
sakale5ba44e2016-10-26 07:09:24 -0700766 frames_decoded(0),
hbos50cfe1f2017-01-23 07:21:55 -0800767 frames_rendered(0),
ilnika79cc282017-08-23 05:24:10 -0700768 interframe_delay_max_ms(-1),
ilnik2e1b40b2017-09-04 07:57:17 -0700769 content_type(webrtc::VideoContentType::UNSPECIFIED),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000770 decode_ms(0),
771 max_decode_ms(0),
772 jitter_buffer_ms(0),
773 min_playout_delay_ms(0),
774 render_delay_ms(0),
775 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000776 current_delay_ms(0),
ilnik2edc6842017-07-06 03:06:50 -0700777 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000779 std::vector<SsrcGroup> ssrc_groups;
hbosa65704b2016-11-14 02:28:16 -0800780 // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|?
Peter Boströmb7d9a972015-12-18 16:01:11 +0100781 std::string decoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000782 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000784 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 int nacks_sent;
786 int frame_width;
787 int frame_height;
788 int framerate_rcvd;
789 int framerate_decoded;
790 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000791 // Framerate as sent to the renderer.
792 int framerate_render_input;
793 // Framerate that the renderer reports.
794 int framerate_render_output;
hbos42f6d2f2017-01-20 03:56:50 -0800795 uint32_t frames_received;
sakale5ba44e2016-10-26 07:09:24 -0700796 uint32_t frames_decoded;
hbos50cfe1f2017-01-23 07:21:55 -0800797 uint32_t frames_rendered;
sakalcc452e12017-02-09 04:53:45 -0800798 rtc::Optional<uint64_t> qp_sum;
ilnika79cc282017-08-23 05:24:10 -0700799 int64_t interframe_delay_max_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000800
ilnik2e1b40b2017-09-04 07:57:17 -0700801 webrtc::VideoContentType content_type;
802
wu@webrtc.org97077a32013-10-25 21:18:33 +0000803 // All stats below are gathered per-VideoReceiver, but some will be correlated
804 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
805 // structures, reflect this in the new layout.
806
807 // Current frame decode latency.
808 int decode_ms;
809 // Maximum observed frame decode latency.
810 int max_decode_ms;
811 // Jitter (network-related) latency.
812 int jitter_buffer_ms;
813 // Requested minimum playout latency.
814 int min_playout_delay_ms;
815 // Requested latency to account for rendering delay.
816 int render_delay_ms;
817 // Target overall delay: network+decode+render, accounting for
818 // min_playout_delay_ms.
819 int target_delay_ms;
820 // Current overall delay, possibly ramping towards target_delay_ms.
821 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000822
823 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200824 int64_t capture_start_ntp_time_ms;
ilnik2edc6842017-07-06 03:06:50 -0700825
826 // Timing frame info: all important timestamps for a full lifetime of a
827 // single 'timing frame'.
828 rtc::Optional<webrtc::TimingFrameInfo> timing_frame_info;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829};
830
wu@webrtc.org97077a32013-10-25 21:18:33 +0000831struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000833 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 }
835
Peter Boström0c4e06b2015-10-07 12:23:21 +0200836 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837};
838
wu@webrtc.org97077a32013-10-25 21:18:33 +0000839struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 DataReceiverInfo()
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
847struct BandwidthEstimationInfo {
848 BandwidthEstimationInfo()
849 : available_send_bandwidth(0),
850 available_recv_bandwidth(0),
851 target_enc_bitrate(0),
852 actual_enc_bitrate(0),
853 retransmit_bitrate(0),
854 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000855 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 }
857
858 int available_send_bandwidth;
859 int available_recv_bandwidth;
860 int target_enc_bitrate;
861 int actual_enc_bitrate;
862 int retransmit_bitrate;
863 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000864 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865};
866
hbosa65704b2016-11-14 02:28:16 -0800867// Maps from payload type to |RtpCodecParameters|.
868typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap;
869
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870struct VoiceMediaInfo {
871 void Clear() {
872 senders.clear();
873 receivers.clear();
hbos1acfbd22016-11-17 23:43:29 -0800874 send_codecs.clear();
875 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 }
877 std::vector<VoiceSenderInfo> senders;
878 std::vector<VoiceReceiverInfo> receivers;
hbos1acfbd22016-11-17 23:43:29 -0800879 RtpCodecParametersMap send_codecs;
880 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881};
882
883struct VideoMediaInfo {
884 void Clear() {
885 senders.clear();
886 receivers.clear();
charujaind72098a2017-06-01 08:54:47 -0700887 bw_estimations.clear();
hbosa65704b2016-11-14 02:28:16 -0800888 send_codecs.clear();
889 receive_codecs.clear();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 }
891 std::vector<VideoSenderInfo> senders;
892 std::vector<VideoReceiverInfo> receivers;
stefanf79ade12017-06-02 06:44:03 -0700893 // Deprecated.
894 // TODO(holmer): Remove once upstream projects no longer use this.
charujaind72098a2017-06-01 08:54:47 -0700895 std::vector<BandwidthEstimationInfo> bw_estimations;
hbosa65704b2016-11-14 02:28:16 -0800896 RtpCodecParametersMap send_codecs;
897 RtpCodecParametersMap receive_codecs;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898};
899
900struct DataMediaInfo {
901 void Clear() {
902 senders.clear();
903 receivers.clear();
904 }
905 std::vector<DataSenderInfo> senders;
906 std::vector<DataReceiverInfo> receivers;
907};
908
deadbeef13871492015-12-09 12:37:51 -0800909struct RtcpParameters {
910 bool reduced_size = false;
911};
912
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700913template <class Codec>
914struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800915 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700916 std::ostringstream ost;
917 ost << "{";
918 ost << "codecs: " << VectorToString(codecs) << ", ";
919 ost << "extensions: " << VectorToString(extensions);
920 ost << "}";
921 return ost.str();
922 }
923
924 std::vector<Codec> codecs;
isheriff6f8d6862016-05-26 11:24:55 -0700925 std::vector<webrtc::RtpExtension> extensions;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700926 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800927 RtcpParameters rtcp;
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200928 virtual ~RtpParameters() = default;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700929};
930
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700931// TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to
932// encapsulate all the parameters needed for an RtpSender.
nisse05103312016-03-16 02:22:50 -0700933template <class Codec>
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700934struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800935 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700936 std::ostringstream ost;
937 ost << "{";
938 ost << "codecs: " << VectorToString(this->codecs) << ", ";
939 ost << "extensions: " << VectorToString(this->extensions) << ", ";
pbos378dc772016-01-28 15:58:41 -0800940 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
nisse05103312016-03-16 02:22:50 -0700941 ost << "}";
942 return ost.str();
943 }
944
945 int max_bandwidth_bps = -1;
946};
947
948struct AudioSendParameters : RtpSendParameters<AudioCodec> {
949 std::string ToString() const override {
950 std::ostringstream ost;
951 ost << "{";
952 ost << "codecs: " << VectorToString(this->codecs) << ", ";
953 ost << "extensions: " << VectorToString(this->extensions) << ", ";
954 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700955 ost << "options: " << options.ToString();
956 ost << "}";
957 return ost.str();
958 }
959
nisse05103312016-03-16 02:22:50 -0700960 AudioOptions options;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700961};
962
963struct AudioRecvParameters : RtpParameters<AudioCodec> {
964};
965
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966class VoiceMediaChannel : public MediaChannel {
967 public:
968 enum Error {
969 ERROR_NONE = 0, // No error.
970 ERROR_OTHER, // Other errors.
971 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
972 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
973 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
974 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
975 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
976 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
977 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
978 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
979 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
980 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
981 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
982 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
983 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
984 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
985 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
986 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
987 };
988
989 VoiceMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -0700990 explicit VoiceMediaChannel(const MediaConfig& config)
991 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200993 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
994 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700995 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
996 virtual bool SetRtpSendParameters(
997 uint32_t ssrc,
998 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -0700999 // Get the receive parameters for the incoming stream identified by |ssrc|.
1000 // If |ssrc| is 0, retrieve the receive parameters for the default receive
1001 // stream, which is used when SSRCs are not signaled. Note that calling with
1002 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
1003 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001004 virtual webrtc::RtpParameters GetRtpReceiveParameters(
1005 uint32_t ssrc) const = 0;
1006 virtual bool SetRtpReceiveParameters(
1007 uint32_t ssrc,
1008 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 // Starts or stops playout of received audio.
aleloi84ef6152016-08-04 05:28:21 -07001010 virtual void SetPlayout(bool playout) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 // Starts or stops sending (and potentially capture) of local audio.
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08001012 virtual void SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -07001013 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001014 virtual bool SetAudioSend(uint32_t ssrc,
1015 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -07001016 const AudioOptions* options,
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -08001017 AudioSource* source) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 // Gets current energy levels for all incoming streams.
Patrik Höglundaba85d12017-11-28 15:46:08 +01001019 typedef std::vector<std::pair<uint32_t, int>> StreamList;
1020 virtual bool GetActiveStreams(StreamList* actives) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021 // Get the current energy level of the stream sent to the speaker.
1022 virtual int GetOutputLevel() = 0;
solenberg4bac9c52015-10-09 02:32:53 -07001023 // Set speaker output volume of the specified ssrc.
1024 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -08001026 virtual bool CanInsertDtmf() = 0;
1027 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00001029 // The valid value for the |event| are 0 to 15 which corresponding to
1030 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -08001031 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 // Gets quality stats for the channel.
1033 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +01001034
1035 virtual void SetRawAudioSink(
1036 uint32_t ssrc,
kwiberg686a8ef2016-02-26 03:00:35 -08001037 std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0;
zhihuang38ede132017-06-15 12:52:32 -07001038
1039 virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040};
1041
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001042// TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to
1043// encapsulate all the parameters needed for a video RtpSender.
nisse05103312016-03-16 02:22:50 -07001044struct VideoSendParameters : RtpSendParameters<VideoCodec> {
nisse4b4dc862016-02-17 05:25:36 -08001045 // Use conference mode? This flag comes from the remote
1046 // description's SDP line 'a=x-google-flag:conference', copied over
1047 // by VideoChannel::SetRemoteContent_w, and ultimately used by
1048 // conference mode screencast logic in
eladalonf1841382017-06-12 01:16:46 -07001049 // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig.
nisse4b4dc862016-02-17 05:25:36 -08001050 // The special screencast behaviour is disabled by default.
1051 bool conference_mode = false;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001052};
1053
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -07001054// TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to
1055// encapsulate all the parameters needed for a video RtpReceiver.
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001056struct VideoRecvParameters : RtpParameters<VideoCodec> {
1057};
1058
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059class VideoMediaChannel : public MediaChannel {
1060 public:
1061 enum Error {
1062 ERROR_NONE = 0, // No error.
1063 ERROR_OTHER, // Other errors.
1064 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
1065 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
1066 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
1067 ERROR_REC_DEVICE_REMOVED, // Device is removed.
1068 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
1069 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1070 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
1071 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
1072 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1073 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
1074 };
1075
nisse08582ff2016-02-04 01:24:52 -08001076 VideoMediaChannel() {}
terelius54f91712016-06-01 11:18:56 -07001077 explicit VideoMediaChannel(const MediaConfig& config)
1078 : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001080
1081 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
1082 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001083 virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0;
1084 virtual bool SetRtpSendParameters(
1085 uint32_t ssrc,
1086 const webrtc::RtpParameters& parameters) = 0;
deadbeef3bc15102017-04-20 19:25:07 -07001087 // Get the receive parameters for the incoming stream identified by |ssrc|.
1088 // If |ssrc| is 0, retrieve the receive parameters for the default receive
1089 // stream, which is used when SSRCs are not signaled. Note that calling with
1090 // an |ssrc| of 0 will return encoding parameters with an unset |ssrc|
1091 // member.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001092 virtual webrtc::RtpParameters GetRtpReceiveParameters(
1093 uint32_t ssrc) const = 0;
1094 virtual bool SetRtpReceiveParameters(
1095 uint32_t ssrc,
1096 const webrtc::RtpParameters& parameters) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097 // Gets the currently set codecs/payload types to be used for outgoing media.
1098 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099 // Starts or stops transmission (and potentially capture) of local video.
1100 virtual bool SetSend(bool send) = 0;
deadbeef5a4a75a2016-06-02 16:23:38 -07001101 // Configure stream for sending and register a source.
1102 // The |ssrc| must correspond to a registered send stream.
1103 virtual bool SetVideoSend(
1104 uint32_t ssrc,
1105 bool enable,
1106 const VideoOptions* options,
nisseacd935b2016-11-11 03:55:13 -08001107 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0;
nisse08582ff2016-02-04 01:24:52 -08001108 // Sets the sink object to be used for the specified stream.
deadbeef3bc15102017-04-20 19:25:07 -07001109 // If SSRC is 0, the sink is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -08001110 virtual bool SetSink(uint32_t ssrc,
nisseacd935b2016-11-11 03:55:13 -08001111 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0;
stefanf79ade12017-06-02 06:44:03 -07001112 // This fills the "bitrate parts" (rtx, video bitrate) of the
1113 // BandwidthEstimationInfo, since that part that isn't possible to get
1114 // through webrtc::Call::GetStats, as they are statistics of the send
1115 // streams.
1116 // TODO(holmer): We should change this so that either BWE graphs doesn't
1117 // need access to bitrates of the streams, or change the (RTC)StatsCollector
1118 // so that it's getting the send stream stats separately by calling
1119 // GetStats(), and merges with BandwidthEstimationInfo by itself.
1120 virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001122 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001123};
1124
1125enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001126 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1127 // values.
1128 DMT_NONE = 0,
1129 DMT_CONTROL = 1,
1130 DMT_BINARY = 2,
1131 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132};
1133
1134// Info about data received in DataMediaChannel. For use in
1135// DataMediaChannel::SignalDataReceived and in all of the signals that
1136// signal fires, on up the chain.
1137struct ReceiveDataParams {
1138 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001139 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1140 union {
1141 uint32_t ssrc;
1142 int sid;
1143 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 // The type of message (binary, text, or control).
1145 DataMessageType type;
1146 // A per-stream value incremented per packet in the stream.
1147 int seq_num;
1148 // A per-stream value monotonically increasing with time.
1149 int timestamp;
1150
deadbeef953c2ce2017-01-09 14:53:41 -08001151 ReceiveDataParams() : sid(0), type(DMT_TEXT), seq_num(0), timestamp(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001152};
1153
1154struct SendDataParams {
1155 // The in-packet stream indentifier.
deadbeef953c2ce2017-01-09 14:53:41 -08001156 // RTP data channels use SSRCs, SCTP data channels use SIDs.
1157 union {
1158 uint32_t ssrc;
1159 int sid;
1160 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001161 // The type of message (binary, text, or control).
1162 DataMessageType type;
1163
1164 // For SCTP, whether to send messages flagged as ordered or not.
1165 // If false, messages can be received out of order.
1166 bool ordered;
1167 // For SCTP, whether the messages are sent reliably or not.
1168 // If false, messages may be lost.
1169 bool reliable;
1170 // For SCTP, if reliable == false, provide partial reliability by
1171 // resending up to this many times. Either count or millis
1172 // is supported, not both at the same time.
1173 int max_rtx_count;
1174 // For SCTP, if reliable == false, provide partial reliability by
1175 // resending for up to this many milliseconds. Either count or millis
1176 // is supported, not both at the same time.
1177 int max_rtx_ms;
1178
deadbeef953c2ce2017-01-09 14:53:41 -08001179 SendDataParams()
1180 : sid(0),
1181 type(DMT_TEXT),
1182 // TODO(pthatcher): Make these true by default?
1183 ordered(false),
1184 reliable(false),
1185 max_rtx_count(0),
1186 max_rtx_ms(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187};
1188
1189enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1190
nisse05103312016-03-16 02:22:50 -07001191struct DataSendParameters : RtpSendParameters<DataCodec> {
solenberg7e4e01a2015-12-02 08:05:01 -08001192 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001193 std::ostringstream ost;
1194 // Options and extensions aren't used.
1195 ost << "{";
1196 ost << "codecs: " << VectorToString(codecs) << ", ";
pbos378dc772016-01-28 15:58:41 -08001197 ost << "max_bandwidth_bps: " << max_bandwidth_bps;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001198 ost << "}";
1199 return ost.str();
1200 }
1201};
1202
1203struct DataRecvParameters : RtpParameters<DataCodec> {
1204};
1205
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001206class DataMediaChannel : public MediaChannel {
1207 public:
1208 enum Error {
1209 ERROR_NONE = 0, // No error.
1210 ERROR_OTHER, // Other errors.
1211 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1212 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1213 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1214 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1215 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1216 };
1217
zhihuangebbe4f22016-12-06 10:45:42 -08001218 DataMediaChannel() {}
Steve Antone78bcb92017-10-31 09:53:08 -07001219 explicit DataMediaChannel(const MediaConfig& config) : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220 virtual ~DataMediaChannel() {}
1221
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001222 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1223 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001224
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001225 // TODO(pthatcher): Implement this.
1226 virtual bool GetStats(DataMediaInfo* info) { return true; }
1227
1228 virtual bool SetSend(bool send) = 0;
1229 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230
Honghai Zhangcc411c02016-03-29 17:27:21 -07001231 virtual void OnNetworkRouteChanged(const std::string& transport_name,
Honghai Zhang0e533ef2016-04-19 15:41:36 -07001232 const rtc::NetworkRoute& network_route) {}
Honghai Zhangcc411c02016-03-29 17:27:21 -07001233
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001234 virtual bool SendData(
1235 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -07001236 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237 SendDataResult* result = NULL) = 0;
1238 // Signals when data is received (params, data, len)
1239 sigslot::signal3<const ReceiveDataParams&,
1240 const char*,
1241 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001242 // Signal when the media channel is ready to send the stream. Arguments are:
1243 // writable(bool)
1244 sigslot::signal1<bool> SignalReadyToSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245};
1246
1247} // namespace cricket
1248
Mirko Bonadei92ea95e2017-09-15 06:47:31 +02001249#endif // MEDIA_BASE_MEDIACHANNEL_H_