blob: bb322ed97d435b5ddd6e94b3e80b33c028466cac [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kjellandera96e2d72016-02-04 23:52:28 -080011#ifndef WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_
12#define WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
14#include <string>
15#include <vector>
16
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000017#include "webrtc/base/basictypes.h"
18#include "webrtc/base/buffer.h"
19#include "webrtc/base/dscp.h"
20#include "webrtc/base/logging.h"
Karl Wibergbe579832015-11-10 22:34:18 +010021#include "webrtc/base/optional.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000022#include "webrtc/base/sigslot.h"
23#include "webrtc/base/socket.h"
24#include "webrtc/base/window.h"
kjellandera96e2d72016-02-04 23:52:28 -080025#include "webrtc/media/base/codec.h"
26#include "webrtc/media/base/constants.h"
27#include "webrtc/media/base/streamparams.h"
nisse08582ff2016-02-04 01:24:52 -080028#include "webrtc/media/base/videosinkinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029// TODO(juberti): re-evaluate this include
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010030#include "webrtc/pc/audiomonitor.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000032namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033class Buffer;
34class RateLimiter;
35class Timing;
36}
37
Tommif888bb52015-12-12 01:37:01 +010038namespace webrtc {
39class AudioSinkInterface;
40}
41
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042namespace cricket {
43
tommi1d5c19d2015-12-13 22:54:29 -080044class AudioRenderer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045class ScreencastId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046class VideoCapturer;
nisse08582ff2016-02-04 01:24:52 -080047class VideoFrame;
tommi1d5c19d2015-12-13 22:54:29 -080048struct RtpHeader;
49struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050
51const int kMinRtpHeaderExtensionId = 1;
52const int kMaxRtpHeaderExtensionId = 255;
53const int kScreencastDefaultFps = 5;
54
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055template <class T>
Karl Wibergbe579832015-11-10 22:34:18 +010056static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070058 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059 str = key;
60 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070061 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062 str += ", ";
63 }
64 return str;
65}
66
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070067template <class T>
68static std::string VectorToString(const std::vector<T>& vals) {
69 std::ostringstream ost;
70 ost << "[";
71 for (size_t i = 0; i < vals.size(); ++i) {
72 if (i > 0) {
73 ost << ", ";
74 }
75 ost << vals[i].ToString();
76 }
77 ost << "]";
78 return ost.str();
79}
80
nisse51542be2016-02-12 02:27:06 -080081// Construction-time settings, passed to
82// MediaControllerInterface::Create, and passed on when creating
83// MediaChannels.
84struct MediaConfig {
85 // Set DSCP value on packets. This flag comes from the
86 // PeerConnection constraint 'googDscp'.
87 bool enable_dscp = false;
88
89 // Video-specific config
90
91 // Enable WebRTC CPU Overuse Detection. This flag comes from the
92 // PeerConnection constraint 'googCpuOveruseDetection' and is
93 // checked in WebRtcVideoChannel2::OnLoadUpdate, where it's passed
94 // to VideoCapturer::video_adapter()->OnCpuResolutionRequest.
95 bool enable_cpu_overuse_detection = true;
96
97 // Set to true if the renderer has an algorithm of frame selection.
98 // If the value is true, then WebRTC will hand over a frame as soon as
99 // possible without delay, and rendering smoothness is completely the duty
100 // of the renderer;
101 // If the value is false, then WebRTC is responsible to delay frame release
102 // in order to increase rendering smoothness.
103 //
104 // This flag comes from PeerConnection's RtcConfiguration, but is
105 // currently only set by the command line flag
106 // 'disable-rtc-smoothness-algorithm'.
107 // WebRtcVideoChannel2::AddRecvStream copies it to the created
108 // WebRtcVideoReceiveStream, where it is returned by the
109 // SmoothsRenderedFrames method. This method is used by the
110 // VideoReceiveStream, where the value is passed on to the
111 // IncomingVideoStream constructor.
112 bool disable_prerenderer_smoothing = false;
113};
114
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
116// Used to be flags, but that makes it hard to selectively apply options.
117// We are moving all of the setting of options to structs like this,
118// but some things currently still use flags.
119struct AudioOptions {
120 void SetAll(const AudioOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700121 SetFrom(&echo_cancellation, change.echo_cancellation);
122 SetFrom(&auto_gain_control, change.auto_gain_control);
123 SetFrom(&noise_suppression, change.noise_suppression);
124 SetFrom(&highpass_filter, change.highpass_filter);
125 SetFrom(&stereo_swapping, change.stereo_swapping);
126 SetFrom(&audio_jitter_buffer_max_packets,
127 change.audio_jitter_buffer_max_packets);
128 SetFrom(&audio_jitter_buffer_fast_accelerate,
129 change.audio_jitter_buffer_fast_accelerate);
130 SetFrom(&typing_detection, change.typing_detection);
131 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise);
kwiberg102c6a62015-10-30 02:47:38 -0700132 SetFrom(&adjust_agc_delta, change.adjust_agc_delta);
133 SetFrom(&experimental_agc, change.experimental_agc);
134 SetFrom(&extended_filter_aec, change.extended_filter_aec);
135 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec);
136 SetFrom(&experimental_ns, change.experimental_ns);
kwiberg102c6a62015-10-30 02:47:38 -0700137 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov);
138 SetFrom(&tx_agc_digital_compression_gain,
139 change.tx_agc_digital_compression_gain);
140 SetFrom(&tx_agc_limiter, change.tx_agc_limiter);
141 SetFrom(&recording_sample_rate, change.recording_sample_rate);
142 SetFrom(&playout_sample_rate, change.playout_sample_rate);
kwiberg102c6a62015-10-30 02:47:38 -0700143 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 }
145
146 bool operator==(const AudioOptions& o) const {
147 return echo_cancellation == o.echo_cancellation &&
148 auto_gain_control == o.auto_gain_control &&
149 noise_suppression == o.noise_suppression &&
150 highpass_filter == o.highpass_filter &&
151 stereo_swapping == o.stereo_swapping &&
Henrik Lundin64dad832015-05-11 12:44:23 +0200152 audio_jitter_buffer_max_packets == o.audio_jitter_buffer_max_packets &&
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200153 audio_jitter_buffer_fast_accelerate ==
154 o.audio_jitter_buffer_fast_accelerate &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000156 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 experimental_agc == o.experimental_agc &&
Henrik Lundin441f6342015-06-09 16:03:13 +0200158 extended_filter_aec == o.extended_filter_aec &&
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100159 delay_agnostic_aec == o.delay_agnostic_aec &&
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000160 experimental_ns == o.experimental_ns &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000162 tx_agc_target_dbov == o.tx_agc_target_dbov &&
163 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
164 tx_agc_limiter == o.tx_agc_limiter &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000165 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000166 playout_sample_rate == o.playout_sample_rate &&
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000167 combined_audio_video_bwe == o.combined_audio_video_bwe;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 }
169
170 std::string ToString() const {
171 std::ostringstream ost;
172 ost << "AudioOptions {";
173 ost << ToStringIfSet("aec", echo_cancellation);
174 ost << ToStringIfSet("agc", auto_gain_control);
175 ost << ToStringIfSet("ns", noise_suppression);
176 ost << ToStringIfSet("hf", highpass_filter);
177 ost << ToStringIfSet("swap", stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200178 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
179 audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200180 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
181 audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000183 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
185 ost << ToStringIfSet("experimental_agc", experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200186 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100187 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000188 ost << ToStringIfSet("experimental_ns", experimental_ns);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000189 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
190 ost << ToStringIfSet("tx_agc_digital_compression_gain",
191 tx_agc_digital_compression_gain);
192 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000193 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
194 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000195 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 ost << "}";
197 return ost.str();
198 }
199
200 // Audio processing that attempts to filter away the output signal from
201 // later inbound pickup.
Karl Wibergbe579832015-11-10 22:34:18 +0100202 rtc::Optional<bool> echo_cancellation;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 // Audio processing to adjust the sensitivity of the local mic dynamically.
Karl Wibergbe579832015-11-10 22:34:18 +0100204 rtc::Optional<bool> auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 // Audio processing to filter out background noise.
Karl Wibergbe579832015-11-10 22:34:18 +0100206 rtc::Optional<bool> noise_suppression;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 // Audio processing to remove background noise of lower frequencies.
Karl Wibergbe579832015-11-10 22:34:18 +0100208 rtc::Optional<bool> highpass_filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 // Audio processing to swap the left and right channels.
Karl Wibergbe579832015-11-10 22:34:18 +0100210 rtc::Optional<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200211 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Karl Wibergbe579832015-11-10 22:34:18 +0100212 rtc::Optional<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200213 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Karl Wibergbe579832015-11-10 22:34:18 +0100214 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 // Audio processing to detect typing.
Karl Wibergbe579832015-11-10 22:34:18 +0100216 rtc::Optional<bool> typing_detection;
217 rtc::Optional<bool> aecm_generate_comfort_noise;
Karl Wibergbe579832015-11-10 22:34:18 +0100218 rtc::Optional<int> adjust_agc_delta;
219 rtc::Optional<bool> experimental_agc;
220 rtc::Optional<bool> extended_filter_aec;
221 rtc::Optional<bool> delay_agnostic_aec;
222 rtc::Optional<bool> experimental_ns;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000223 // Note that tx_agc_* only applies to non-experimental AGC.
Karl Wibergbe579832015-11-10 22:34:18 +0100224 rtc::Optional<uint16_t> tx_agc_target_dbov;
225 rtc::Optional<uint16_t> tx_agc_digital_compression_gain;
226 rtc::Optional<bool> tx_agc_limiter;
227 rtc::Optional<uint32_t> recording_sample_rate;
228 rtc::Optional<uint32_t> playout_sample_rate;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000229 // Enable combined audio+bandwidth BWE.
nisse51542be2016-02-12 02:27:06 -0800230 // TODO(pthatcher): This flag is set from the
231 // "googCombinedAudioVideoBwe", but not used anywhere. So delete it,
232 // and check if any other AudioOptions members are unused.
Karl Wibergbe579832015-11-10 22:34:18 +0100233 rtc::Optional<bool> combined_audio_video_bwe;
kwiberg102c6a62015-10-30 02:47:38 -0700234
235 private:
236 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100237 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700238 if (o) {
239 *s = o;
240 }
241 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242};
243
244// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
245// Used to be flags, but that makes it hard to selectively apply options.
246// We are moving all of the setting of options to structs like this,
247// but some things currently still use flags.
248struct VideoOptions {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700250 SetFrom(&video_noise_reduction, change.video_noise_reduction);
kwiberg102c6a62015-10-30 02:47:38 -0700251 SetFrom(&suspend_below_min_bitrate, change.suspend_below_min_bitrate);
nisseb163c3f2016-01-29 01:14:38 -0800252 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 }
254
255 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800256 return video_noise_reduction == o.video_noise_reduction &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000257 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
nisse51542be2016-02-12 02:27:06 -0800258 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 }
260
261 std::string ToString() const {
262 std::ostringstream ost;
263 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 ost << ToStringIfSet("noise reduction", video_noise_reduction);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000265 ost << ToStringIfSet("suspend below min bitrate",
266 suspend_below_min_bitrate);
nisseb163c3f2016-01-29 01:14:38 -0800267 ost << ToStringIfSet("screencast min bitrate kbps",
268 screencast_min_bitrate_kbps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269 ost << "}";
270 return ost.str();
271 }
272
nisseb163c3f2016-01-29 01:14:38 -0800273 // Enable denoising? This flag comes from the getUserMedia
274 // constraint 'googNoiseReduction', and WebRtcVideoEngine2 passes it
275 // on to the codec options. Disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100276 rtc::Optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800277 // Enable WebRTC suspension of video. No video frames will be sent
278 // when the bitrate is below the configured minimum bitrate. This
279 // flag comes from the PeerConnection constraint
280 // 'googSuspendBelowMinBitrate', and WebRtcVideoChannel2 copies it
281 // to VideoSendStream::Config::suspend_below_min_bitrate.
Karl Wibergbe579832015-11-10 22:34:18 +0100282 rtc::Optional<bool> suspend_below_min_bitrate;
nisseb163c3f2016-01-29 01:14:38 -0800283 // Force screencast to use a minimum bitrate. This flag comes from
284 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
285 // copied to the encoder config by WebRtcVideoChannel2.
286 rtc::Optional<int> screencast_min_bitrate_kbps;
kwiberg102c6a62015-10-30 02:47:38 -0700287
288 private:
289 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100290 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700291 if (o) {
292 *s = o;
293 }
294 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295};
296
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297struct RtpHeaderExtension {
298 RtpHeaderExtension() : id(0) {}
299 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300
301 bool operator==(const RtpHeaderExtension& ext) const {
302 // id is a reserved word in objective-c. Therefore the id attribute has to
303 // be a fully qualified name in order to compile on IOS.
304 return this->id == ext.id &&
305 uri == ext.uri;
306 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700307
308 std::string ToString() const {
309 std::ostringstream ost;
310 ost << "{";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700311 ost << "uri: " << uri;
solenberg7e4e01a2015-12-02 08:05:01 -0800312 ost << ", id: " << id;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700313 ost << "}";
314 return ost.str();
315 }
316
317 std::string uri;
318 int id;
319 // TODO(juberti): SendRecv direction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320};
321
322// Returns the named header extension if found among all extensions, NULL
323// otherwise.
324inline const RtpHeaderExtension* FindHeaderExtension(
325 const std::vector<RtpHeaderExtension>& extensions,
326 const std::string& name) {
327 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
328 it != extensions.end(); ++it) {
329 if (it->uri == name)
330 return &(*it);
331 }
332 return NULL;
333}
334
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335class MediaChannel : public sigslot::has_slots<> {
336 public:
337 class NetworkInterface {
338 public:
339 enum SocketType { ST_RTP, ST_RTCP };
stefanc1aeaf02015-10-15 07:26:07 -0700340 virtual bool SendPacket(rtc::Buffer* packet,
341 const rtc::PacketOptions& options) = 0;
342 virtual bool SendRtcp(rtc::Buffer* packet,
343 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000344 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 int option) = 0;
346 virtual ~NetworkInterface() {}
347 };
348
nisse51542be2016-02-12 02:27:06 -0800349 MediaChannel(const MediaConfig& config)
350 : enable_dscp_(config.enable_dscp), network_interface_(NULL) {}
351 MediaChannel() : enable_dscp_(false), network_interface_(NULL) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 virtual ~MediaChannel() {}
353
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000354 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000356 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 network_interface_ = iface;
nisse51542be2016-02-12 02:27:06 -0800358 SetDscp(enable_dscp_ ? PreferredDscp() : rtc::DSCP_DEFAULT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 }
nisse51542be2016-02-12 02:27:06 -0800360 virtual rtc::DiffServCodePoint PreferredDscp() const {
361 return rtc::DSCP_DEFAULT;
362 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 // Called when a RTP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000364 virtual void OnPacketReceived(rtc::Buffer* packet,
365 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 // Called when a RTCP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000367 virtual void OnRtcpReceived(rtc::Buffer* packet,
368 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 // Called when the socket's ability to send has changed.
370 virtual void OnReadyToSend(bool ready) = 0;
371 // Creates a new outgoing media stream with SSRCs and CNAME as described
372 // by sp.
373 virtual bool AddSendStream(const StreamParams& sp) = 0;
374 // Removes an outgoing media stream.
375 // ssrc must be the first SSRC of the media stream if the stream uses
376 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200377 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000378 // Creates a new incoming media stream with SSRCs and CNAME as described
379 // by sp.
380 virtual bool AddRecvStream(const StreamParams& sp) = 0;
381 // Removes an incoming media stream.
382 // ssrc must be the first SSRC of the media stream if the stream uses
383 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200384 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000386 // Returns the absoulte sendtime extension id value from media channel.
387 virtual int GetRtpSendTimeExtnId() const {
388 return -1;
389 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000391 // Base method to send packet using NetworkInterface.
stefanc1aeaf02015-10-15 07:26:07 -0700392 bool SendPacket(rtc::Buffer* packet, const rtc::PacketOptions& options) {
393 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000394 }
395
stefanc1aeaf02015-10-15 07:26:07 -0700396 bool SendRtcp(rtc::Buffer* packet, const rtc::PacketOptions& options) {
397 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000398 }
399
400 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000401 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000402 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000403 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000404 if (!network_interface_)
405 return -1;
406
407 return network_interface_->SetOption(type, opt, option);
408 }
409
nisse51542be2016-02-12 02:27:06 -0800410 private:
wu@webrtc.orgde305012013-10-31 15:40:38 +0000411 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000412 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000413 int ret;
414 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000415 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000416 value);
417 if (ret == 0) {
418 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000419 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000420 value);
421 }
422 return ret;
423 }
424
stefanc1aeaf02015-10-15 07:26:07 -0700425 bool DoSendPacket(rtc::Buffer* packet,
426 bool rtcp,
427 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000428 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000429 if (!network_interface_)
430 return false;
431
stefanc1aeaf02015-10-15 07:26:07 -0700432 return (!rtcp) ? network_interface_->SendPacket(packet, options)
433 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000434 }
435
nisse51542be2016-02-12 02:27:06 -0800436 const bool enable_dscp_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000437 // |network_interface_| can be accessed from the worker_thread and
438 // from any MediaEngine threads. This critical section is to protect accessing
439 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000440 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000441 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000442};
443
444enum SendFlags {
445 SEND_NOTHING,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 SEND_MICROPHONE
447};
448
wu@webrtc.org97077a32013-10-25 21:18:33 +0000449// The stats information is structured as follows:
450// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
451// Media contains a vector of SSRC infos that are exclusively used by this
452// media. (SSRCs shared between media streams can't be represented.)
453
454// Information about an SSRC.
455// This data may be locally recorded, or received in an RTCP SR or RR.
456struct SsrcSenderInfo {
457 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000459 timestamp(0) {
460 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200461 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000462 double timestamp; // NTP timestamp, represented as seconds since epoch.
463};
464
465struct SsrcReceiverInfo {
466 SsrcReceiverInfo()
467 : ssrc(0),
468 timestamp(0) {
469 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200470 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000471 double timestamp;
472};
473
474struct MediaSenderInfo {
475 MediaSenderInfo()
476 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000477 packets_sent(0),
478 packets_lost(0),
479 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000480 rtt_ms(0) {
481 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000482 void add_ssrc(const SsrcSenderInfo& stat) {
483 local_stats.push_back(stat);
484 }
485 // Temporary utility function for call sites that only provide SSRC.
486 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200487 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000488 SsrcSenderInfo stat;
489 stat.ssrc = ssrc;
490 add_ssrc(stat);
491 }
492 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200493 std::vector<uint32_t> ssrcs() const {
494 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000495 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
496 it != local_stats.end(); ++it) {
497 retval.push_back(it->ssrc);
498 }
499 return retval;
500 }
501 // Utility accessor for clients that make the assumption only one ssrc
502 // exists per media.
503 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200504 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000505 if (local_stats.size() > 0) {
506 return local_stats[0].ssrc;
507 } else {
508 return 0;
509 }
510 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200511 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000512 int packets_sent;
513 int packets_lost;
514 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000515 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000516 std::string codec_name;
517 std::vector<SsrcSenderInfo> local_stats;
518 std::vector<SsrcReceiverInfo> remote_stats;
519};
520
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000521template<class T>
522struct VariableInfo {
523 VariableInfo()
524 : min_val(),
525 mean(0.0),
526 max_val(),
527 variance(0.0) {
528 }
529 T min_val;
530 double mean;
531 T max_val;
532 double variance;
533};
534
wu@webrtc.org97077a32013-10-25 21:18:33 +0000535struct MediaReceiverInfo {
536 MediaReceiverInfo()
537 : bytes_rcvd(0),
538 packets_rcvd(0),
539 packets_lost(0),
540 fraction_lost(0.0) {
541 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000542 void add_ssrc(const SsrcReceiverInfo& stat) {
543 local_stats.push_back(stat);
544 }
545 // Temporary utility function for call sites that only provide SSRC.
546 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200547 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000548 SsrcReceiverInfo stat;
549 stat.ssrc = ssrc;
550 add_ssrc(stat);
551 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200552 std::vector<uint32_t> ssrcs() const {
553 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000554 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
555 it != local_stats.end(); ++it) {
556 retval.push_back(it->ssrc);
557 }
558 return retval;
559 }
560 // Utility accessor for clients that make the assumption only one ssrc
561 // exists per media.
562 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200563 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000564 if (local_stats.size() > 0) {
565 return local_stats[0].ssrc;
566 } else {
567 return 0;
568 }
569 }
570
Peter Boström0c4e06b2015-10-07 12:23:21 +0200571 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000572 int packets_rcvd;
573 int packets_lost;
574 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000575 std::string codec_name;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000576 std::vector<SsrcReceiverInfo> local_stats;
577 std::vector<SsrcSenderInfo> remote_stats;
578};
579
580struct VoiceSenderInfo : public MediaSenderInfo {
581 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000582 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 jitter_ms(0),
584 audio_level(0),
585 aec_quality_min(0.0),
586 echo_delay_median_ms(0),
587 echo_delay_std_ms(0),
588 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000589 echo_return_loss_enhancement(0),
590 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 }
592
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594 int jitter_ms;
595 int audio_level;
596 float aec_quality_min;
597 int echo_delay_median_ms;
598 int echo_delay_std_ms;
599 int echo_return_loss;
600 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000601 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602};
603
wu@webrtc.org97077a32013-10-25 21:18:33 +0000604struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000605 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000606 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607 jitter_ms(0),
608 jitter_buffer_ms(0),
609 jitter_buffer_preferred_ms(0),
610 delay_estimate_ms(0),
611 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000612 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000613 speech_expand_rate(0),
614 secondary_decoded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200615 accelerate_rate(0),
616 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000617 decoding_calls_to_silence_generator(0),
618 decoding_calls_to_neteq(0),
619 decoding_normal(0),
620 decoding_plc(0),
621 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000622 decoding_plc_cng(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200623 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625 int ext_seqnum;
626 int jitter_ms;
627 int jitter_buffer_ms;
628 int jitter_buffer_preferred_ms;
629 int delay_estimate_ms;
630 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000631 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000633 // fraction of synthesized speech inserted through expansion.
634 float speech_expand_rate;
635 // fraction of data out of secondary decoding, including FEC and RED.
636 float secondary_decoded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200637 // Fraction of data removed through time compression.
638 float accelerate_rate;
639 // Fraction of data inserted through time stretching.
640 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000641 int decoding_calls_to_silence_generator;
642 int decoding_calls_to_neteq;
643 int decoding_normal;
644 int decoding_plc;
645 int decoding_cng;
646 int decoding_plc_cng;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000647 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200648 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000649};
650
wu@webrtc.org97077a32013-10-25 21:18:33 +0000651struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000652 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000653 : packets_cached(0),
654 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000655 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000657 input_frame_width(0),
658 input_frame_height(0),
659 send_frame_width(0),
660 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661 framerate_input(0),
662 framerate_sent(0),
663 nominal_bitrate(0),
664 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000665 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000666 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000667 avg_encode_ms(0),
Peter Boström8ed6a4b2015-03-27 10:01:02 +0100668 encode_usage_percent(0) {
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000669 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000670
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000671 std::vector<SsrcGroup> ssrc_groups;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100672 std::string encoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000673 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000675 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000677 int input_frame_width;
678 int input_frame_height;
679 int send_frame_width;
680 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681 int framerate_input;
682 int framerate_sent;
683 int nominal_bitrate;
684 int preferred_bitrate;
685 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000686 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000687 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000688 int encode_usage_percent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000689 VariableInfo<int> adapt_frame_drops;
690 VariableInfo<int> effects_frame_drops;
691 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692};
693
wu@webrtc.org97077a32013-10-25 21:18:33 +0000694struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000696 : packets_concealed(0),
697 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000698 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000699 nacks_sent(0),
700 frame_width(0),
701 frame_height(0),
702 framerate_rcvd(0),
703 framerate_decoded(0),
704 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000705 framerate_render_input(0),
706 framerate_render_output(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000707 decode_ms(0),
708 max_decode_ms(0),
709 jitter_buffer_ms(0),
710 min_playout_delay_ms(0),
711 render_delay_ms(0),
712 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000713 current_delay_ms(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000714 capture_start_ntp_time_ms(-1) {
715 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000717 std::vector<SsrcGroup> ssrc_groups;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100718 std::string decoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000719 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000721 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 int nacks_sent;
723 int frame_width;
724 int frame_height;
725 int framerate_rcvd;
726 int framerate_decoded;
727 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000728 // Framerate as sent to the renderer.
729 int framerate_render_input;
730 // Framerate that the renderer reports.
731 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000732
733 // All stats below are gathered per-VideoReceiver, but some will be correlated
734 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
735 // structures, reflect this in the new layout.
736
737 // Current frame decode latency.
738 int decode_ms;
739 // Maximum observed frame decode latency.
740 int max_decode_ms;
741 // Jitter (network-related) latency.
742 int jitter_buffer_ms;
743 // Requested minimum playout latency.
744 int min_playout_delay_ms;
745 // Requested latency to account for rendering delay.
746 int render_delay_ms;
747 // Target overall delay: network+decode+render, accounting for
748 // min_playout_delay_ms.
749 int target_delay_ms;
750 // Current overall delay, possibly ramping towards target_delay_ms.
751 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000752
753 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200754 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755};
756
wu@webrtc.org97077a32013-10-25 21:18:33 +0000757struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000759 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 }
761
Peter Boström0c4e06b2015-10-07 12:23:21 +0200762 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763};
764
wu@webrtc.org97077a32013-10-25 21:18:33 +0000765struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000767 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768 }
769
Peter Boström0c4e06b2015-10-07 12:23:21 +0200770 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771};
772
773struct BandwidthEstimationInfo {
774 BandwidthEstimationInfo()
775 : available_send_bandwidth(0),
776 available_recv_bandwidth(0),
777 target_enc_bitrate(0),
778 actual_enc_bitrate(0),
779 retransmit_bitrate(0),
780 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000781 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782 }
783
784 int available_send_bandwidth;
785 int available_recv_bandwidth;
786 int target_enc_bitrate;
787 int actual_enc_bitrate;
788 int retransmit_bitrate;
789 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000790 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791};
792
793struct VoiceMediaInfo {
794 void Clear() {
795 senders.clear();
796 receivers.clear();
797 }
798 std::vector<VoiceSenderInfo> senders;
799 std::vector<VoiceReceiverInfo> receivers;
800};
801
802struct VideoMediaInfo {
803 void Clear() {
804 senders.clear();
805 receivers.clear();
806 bw_estimations.clear();
807 }
808 std::vector<VideoSenderInfo> senders;
809 std::vector<VideoReceiverInfo> receivers;
810 std::vector<BandwidthEstimationInfo> bw_estimations;
811};
812
813struct DataMediaInfo {
814 void Clear() {
815 senders.clear();
816 receivers.clear();
817 }
818 std::vector<DataSenderInfo> senders;
819 std::vector<DataReceiverInfo> receivers;
820};
821
deadbeef13871492015-12-09 12:37:51 -0800822struct RtcpParameters {
823 bool reduced_size = false;
824};
825
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700826template <class Codec>
827struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800828 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700829 std::ostringstream ost;
830 ost << "{";
831 ost << "codecs: " << VectorToString(codecs) << ", ";
832 ost << "extensions: " << VectorToString(extensions);
833 ost << "}";
834 return ost.str();
835 }
836
837 std::vector<Codec> codecs;
838 std::vector<RtpHeaderExtension> extensions;
839 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800840 RtcpParameters rtcp;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700841};
842
843template <class Codec, class Options>
844struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800845 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700846 std::ostringstream ost;
847 ost << "{";
848 ost << "codecs: " << VectorToString(this->codecs) << ", ";
849 ost << "extensions: " << VectorToString(this->extensions) << ", ";
pbos378dc772016-01-28 15:58:41 -0800850 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700851 ost << "options: " << options.ToString();
852 ost << "}";
853 return ost.str();
854 }
855
856 int max_bandwidth_bps = -1;
857 Options options;
858};
859
860struct AudioSendParameters : RtpSendParameters<AudioCodec, AudioOptions> {
861};
862
863struct AudioRecvParameters : RtpParameters<AudioCodec> {
864};
865
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866class VoiceMediaChannel : public MediaChannel {
867 public:
868 enum Error {
869 ERROR_NONE = 0, // No error.
870 ERROR_OTHER, // Other errors.
871 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
872 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
873 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
874 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
875 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
876 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
877 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
878 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
879 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
880 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
881 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
882 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
883 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
884 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
885 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
886 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
887 };
888
889 VoiceMediaChannel() {}
nisse51542be2016-02-12 02:27:06 -0800890 VoiceMediaChannel(const MediaConfig& config) : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200892 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
893 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 // Starts or stops playout of received audio.
895 virtual bool SetPlayout(bool playout) = 0;
896 // Starts or stops sending (and potentially capture) of local audio.
897 virtual bool SetSend(SendFlags flag) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700898 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200899 virtual bool SetAudioSend(uint32_t ssrc,
900 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700901 const AudioOptions* options,
solenberg1dd98f32015-09-10 01:57:14 -0700902 AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 // Gets current energy levels for all incoming streams.
904 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
905 // Get the current energy level of the stream sent to the speaker.
906 virtual int GetOutputLevel() = 0;
907 // Get the time in milliseconds since last recorded keystroke, or negative.
908 virtual int GetTimeSinceLastTyping() = 0;
909 // Temporarily exposed field for tuning typing detect options.
910 virtual void SetTypingDetectionParameters(int time_window,
911 int cost_per_typing, int reporting_threshold, int penalty_decay,
912 int type_event_delay) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700913 // Set speaker output volume of the specified ssrc.
914 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800916 virtual bool CanInsertDtmf() = 0;
917 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000919 // The valid value for the |event| are 0 to 15 which corresponding to
920 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800921 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 // Gets quality stats for the channel.
923 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100924
925 virtual void SetRawAudioSink(
926 uint32_t ssrc,
deadbeef2d110be2016-01-13 12:00:26 -0800927 rtc::scoped_ptr<webrtc::AudioSinkInterface> sink) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928};
929
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700930struct VideoSendParameters : RtpSendParameters<VideoCodec, VideoOptions> {
nisse4b4dc862016-02-17 05:25:36 -0800931 // Use conference mode? This flag comes from the remote
932 // description's SDP line 'a=x-google-flag:conference', copied over
933 // by VideoChannel::SetRemoteContent_w, and ultimately used by
934 // conference mode screencast logic in
935 // WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig.
936 // The special screencast behaviour is disabled by default.
937 bool conference_mode = false;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700938};
939
940struct VideoRecvParameters : RtpParameters<VideoCodec> {
941};
942
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943class VideoMediaChannel : public MediaChannel {
944 public:
945 enum Error {
946 ERROR_NONE = 0, // No error.
947 ERROR_OTHER, // Other errors.
948 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
949 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
950 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
951 ERROR_REC_DEVICE_REMOVED, // Device is removed.
952 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
953 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
954 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
955 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
956 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
957 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
958 };
959
nisse08582ff2016-02-04 01:24:52 -0800960 VideoMediaChannel() {}
nisse51542be2016-02-12 02:27:06 -0800961 VideoMediaChannel(const MediaConfig& config) : MediaChannel(config) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200963
964 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
965 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 // Gets the currently set codecs/payload types to be used for outgoing media.
967 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 // Starts or stops transmission (and potentially capture) of local video.
969 virtual bool SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700970 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200971 virtual bool SetVideoSend(uint32_t ssrc,
972 bool enable,
solenberg1dd98f32015-09-10 01:57:14 -0700973 const VideoOptions* options) = 0;
nisse08582ff2016-02-04 01:24:52 -0800974 // Sets the sink object to be used for the specified stream.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 // If SSRC is 0, the renderer is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800976 virtual bool SetSink(uint32_t ssrc,
977 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978 // If |ssrc| is 0, replace the default capturer (engine capturer) with
979 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200980 virtual bool SetCapturer(uint32_t ssrc, VideoCapturer* capturer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000982 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983};
984
985enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000986 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
987 // values.
988 DMT_NONE = 0,
989 DMT_CONTROL = 1,
990 DMT_BINARY = 2,
991 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992};
993
994// Info about data received in DataMediaChannel. For use in
995// DataMediaChannel::SignalDataReceived and in all of the signals that
996// signal fires, on up the chain.
997struct ReceiveDataParams {
998 // The in-packet stream indentifier.
999 // For SCTP, this is really SID, not SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001000 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 // The type of message (binary, text, or control).
1002 DataMessageType type;
1003 // A per-stream value incremented per packet in the stream.
1004 int seq_num;
1005 // A per-stream value monotonically increasing with time.
1006 int timestamp;
1007
1008 ReceiveDataParams() :
1009 ssrc(0),
1010 type(DMT_TEXT),
1011 seq_num(0),
1012 timestamp(0) {
1013 }
1014};
1015
1016struct SendDataParams {
1017 // The in-packet stream indentifier.
1018 // For SCTP, this is really SID, not SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001019 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 // The type of message (binary, text, or control).
1021 DataMessageType type;
1022
1023 // For SCTP, whether to send messages flagged as ordered or not.
1024 // If false, messages can be received out of order.
1025 bool ordered;
1026 // For SCTP, whether the messages are sent reliably or not.
1027 // If false, messages may be lost.
1028 bool reliable;
1029 // For SCTP, if reliable == false, provide partial reliability by
1030 // resending up to this many times. Either count or millis
1031 // is supported, not both at the same time.
1032 int max_rtx_count;
1033 // For SCTP, if reliable == false, provide partial reliability by
1034 // resending for up to this many milliseconds. Either count or millis
1035 // is supported, not both at the same time.
1036 int max_rtx_ms;
1037
1038 SendDataParams() :
1039 ssrc(0),
1040 type(DMT_TEXT),
1041 // TODO(pthatcher): Make these true by default?
1042 ordered(false),
1043 reliable(false),
1044 max_rtx_count(0),
1045 max_rtx_ms(0) {
1046 }
1047};
1048
1049enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1050
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001051struct DataOptions {
solenberg7e4e01a2015-12-02 08:05:01 -08001052 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001053 return "{}";
1054 }
1055};
1056
1057struct DataSendParameters : RtpSendParameters<DataCodec, DataOptions> {
solenberg7e4e01a2015-12-02 08:05:01 -08001058 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001059 std::ostringstream ost;
1060 // Options and extensions aren't used.
1061 ost << "{";
1062 ost << "codecs: " << VectorToString(codecs) << ", ";
pbos378dc772016-01-28 15:58:41 -08001063 ost << "max_bandwidth_bps: " << max_bandwidth_bps;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001064 ost << "}";
1065 return ost.str();
1066 }
1067};
1068
1069struct DataRecvParameters : RtpParameters<DataCodec> {
1070};
1071
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072class DataMediaChannel : public MediaChannel {
1073 public:
1074 enum Error {
1075 ERROR_NONE = 0, // No error.
1076 ERROR_OTHER, // Other errors.
1077 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1078 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1079 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1080 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1081 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1082 };
1083
1084 virtual ~DataMediaChannel() {}
1085
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001086 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1087 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001088
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 // TODO(pthatcher): Implement this.
1090 virtual bool GetStats(DataMediaInfo* info) { return true; }
1091
1092 virtual bool SetSend(bool send) = 0;
1093 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094
1095 virtual bool SendData(
1096 const SendDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001097 const rtc::Buffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 SendDataResult* result = NULL) = 0;
1099 // Signals when data is received (params, data, len)
1100 sigslot::signal3<const ReceiveDataParams&,
1101 const char*,
1102 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001103 // Signal when the media channel is ready to send the stream. Arguments are:
1104 // writable(bool)
1105 sigslot::signal1<bool> SignalReadyToSend;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001106 // Signal for notifying that the remote side has closed the DataChannel.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001107 sigslot::signal1<uint32_t> SignalStreamClosedRemotely;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108};
1109
1110} // namespace cricket
1111
kjellandera96e2d72016-02-04 23:52:28 -08001112#endif // WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_