blob: 2c7696ceb9b97d200f51cefa897e55e4c94d8ae5 [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
30#include "talk/session/media/audiomonitor.h"
31
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
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
82// Used to be flags, but that makes it hard to selectively apply options.
83// We are moving all of the setting of options to structs like this,
84// but some things currently still use flags.
85struct AudioOptions {
86 void SetAll(const AudioOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -070087 SetFrom(&echo_cancellation, change.echo_cancellation);
88 SetFrom(&auto_gain_control, change.auto_gain_control);
89 SetFrom(&noise_suppression, change.noise_suppression);
90 SetFrom(&highpass_filter, change.highpass_filter);
91 SetFrom(&stereo_swapping, change.stereo_swapping);
92 SetFrom(&audio_jitter_buffer_max_packets,
93 change.audio_jitter_buffer_max_packets);
94 SetFrom(&audio_jitter_buffer_fast_accelerate,
95 change.audio_jitter_buffer_fast_accelerate);
96 SetFrom(&typing_detection, change.typing_detection);
97 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise);
98 SetFrom(&conference_mode, change.conference_mode);
99 SetFrom(&adjust_agc_delta, change.adjust_agc_delta);
100 SetFrom(&experimental_agc, change.experimental_agc);
101 SetFrom(&extended_filter_aec, change.extended_filter_aec);
102 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec);
103 SetFrom(&experimental_ns, change.experimental_ns);
104 SetFrom(&aec_dump, change.aec_dump);
105 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov);
106 SetFrom(&tx_agc_digital_compression_gain,
107 change.tx_agc_digital_compression_gain);
108 SetFrom(&tx_agc_limiter, change.tx_agc_limiter);
109 SetFrom(&recording_sample_rate, change.recording_sample_rate);
110 SetFrom(&playout_sample_rate, change.playout_sample_rate);
111 SetFrom(&dscp, change.dscp);
112 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113 }
114
115 bool operator==(const AudioOptions& o) const {
116 return echo_cancellation == o.echo_cancellation &&
117 auto_gain_control == o.auto_gain_control &&
118 noise_suppression == o.noise_suppression &&
119 highpass_filter == o.highpass_filter &&
120 stereo_swapping == o.stereo_swapping &&
Henrik Lundin64dad832015-05-11 12:44:23 +0200121 audio_jitter_buffer_max_packets == o.audio_jitter_buffer_max_packets &&
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200122 audio_jitter_buffer_fast_accelerate ==
123 o.audio_jitter_buffer_fast_accelerate &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000125 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126 conference_mode == o.conference_mode &&
127 experimental_agc == o.experimental_agc &&
Henrik Lundin441f6342015-06-09 16:03:13 +0200128 extended_filter_aec == o.extended_filter_aec &&
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100129 delay_agnostic_aec == o.delay_agnostic_aec &&
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000130 experimental_ns == o.experimental_ns &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000132 aec_dump == o.aec_dump &&
133 tx_agc_target_dbov == o.tx_agc_target_dbov &&
134 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
135 tx_agc_limiter == o.tx_agc_limiter &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000136 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000137 playout_sample_rate == o.playout_sample_rate &&
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000138 dscp == o.dscp &&
139 combined_audio_video_bwe == o.combined_audio_video_bwe;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140 }
141
142 std::string ToString() const {
143 std::ostringstream ost;
144 ost << "AudioOptions {";
145 ost << ToStringIfSet("aec", echo_cancellation);
146 ost << ToStringIfSet("agc", auto_gain_control);
147 ost << ToStringIfSet("ns", noise_suppression);
148 ost << ToStringIfSet("hf", highpass_filter);
149 ost << ToStringIfSet("swap", stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200150 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
151 audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200152 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
153 audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000155 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 ost << ToStringIfSet("conference", conference_mode);
157 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
158 ost << ToStringIfSet("experimental_agc", experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200159 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100160 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000161 ost << ToStringIfSet("experimental_ns", experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 ost << ToStringIfSet("aec_dump", aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000163 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
164 ost << ToStringIfSet("tx_agc_digital_compression_gain",
165 tx_agc_digital_compression_gain);
166 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000167 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
168 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000169 ost << ToStringIfSet("dscp", dscp);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000170 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 ost << "}";
172 return ost.str();
173 }
174
175 // Audio processing that attempts to filter away the output signal from
176 // later inbound pickup.
Karl Wibergbe579832015-11-10 22:34:18 +0100177 rtc::Optional<bool> echo_cancellation;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 // Audio processing to adjust the sensitivity of the local mic dynamically.
Karl Wibergbe579832015-11-10 22:34:18 +0100179 rtc::Optional<bool> auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 // Audio processing to filter out background noise.
Karl Wibergbe579832015-11-10 22:34:18 +0100181 rtc::Optional<bool> noise_suppression;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 // Audio processing to remove background noise of lower frequencies.
Karl Wibergbe579832015-11-10 22:34:18 +0100183 rtc::Optional<bool> highpass_filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 // Audio processing to swap the left and right channels.
Karl Wibergbe579832015-11-10 22:34:18 +0100185 rtc::Optional<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200186 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Karl Wibergbe579832015-11-10 22:34:18 +0100187 rtc::Optional<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200188 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Karl Wibergbe579832015-11-10 22:34:18 +0100189 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 // Audio processing to detect typing.
Karl Wibergbe579832015-11-10 22:34:18 +0100191 rtc::Optional<bool> typing_detection;
192 rtc::Optional<bool> aecm_generate_comfort_noise;
193 rtc::Optional<bool> conference_mode;
194 rtc::Optional<int> adjust_agc_delta;
195 rtc::Optional<bool> experimental_agc;
196 rtc::Optional<bool> extended_filter_aec;
197 rtc::Optional<bool> delay_agnostic_aec;
198 rtc::Optional<bool> experimental_ns;
199 rtc::Optional<bool> aec_dump;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000200 // Note that tx_agc_* only applies to non-experimental AGC.
Karl Wibergbe579832015-11-10 22:34:18 +0100201 rtc::Optional<uint16_t> tx_agc_target_dbov;
202 rtc::Optional<uint16_t> tx_agc_digital_compression_gain;
203 rtc::Optional<bool> tx_agc_limiter;
204 rtc::Optional<uint32_t> recording_sample_rate;
205 rtc::Optional<uint32_t> playout_sample_rate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000206 // Set DSCP value for packet sent from audio channel.
Karl Wibergbe579832015-11-10 22:34:18 +0100207 rtc::Optional<bool> dscp;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000208 // Enable combined audio+bandwidth BWE.
Karl Wibergbe579832015-11-10 22:34:18 +0100209 rtc::Optional<bool> combined_audio_video_bwe;
kwiberg102c6a62015-10-30 02:47:38 -0700210
211 private:
212 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100213 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700214 if (o) {
215 *s = o;
216 }
217 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218};
219
220// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
221// Used to be flags, but that makes it hard to selectively apply options.
222// We are moving all of the setting of options to structs like this,
223// but some things currently still use flags.
224struct VideoOptions {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700226 SetFrom(&video_noise_reduction, change.video_noise_reduction);
kwiberg102c6a62015-10-30 02:47:38 -0700227 SetFrom(&cpu_overuse_detection, change.cpu_overuse_detection);
kwiberg102c6a62015-10-30 02:47:38 -0700228 SetFrom(&conference_mode, change.conference_mode);
kwiberg102c6a62015-10-30 02:47:38 -0700229 SetFrom(&dscp, change.dscp);
230 SetFrom(&suspend_below_min_bitrate, change.suspend_below_min_bitrate);
nisseb163c3f2016-01-29 01:14:38 -0800231 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
qiangchen444682a2015-11-24 18:07:56 -0800232 SetFrom(&disable_prerenderer_smoothing,
233 change.disable_prerenderer_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 }
235
236 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800237 return video_noise_reduction == o.video_noise_reduction &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000238 cpu_overuse_detection == o.cpu_overuse_detection &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000239 conference_mode == o.conference_mode &&
Peter Thatchera9b4c322015-07-16 03:47:28 -0700240 dscp == o.dscp &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000241 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
nisseb163c3f2016-01-29 01:14:38 -0800242 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
qiangchen444682a2015-11-24 18:07:56 -0800243 disable_prerenderer_smoothing == o.disable_prerenderer_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 }
245
246 std::string ToString() const {
247 std::ostringstream ost;
248 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000250 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 ost << ToStringIfSet("conference mode", conference_mode);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000252 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000253 ost << ToStringIfSet("suspend below min bitrate",
254 suspend_below_min_bitrate);
nisseb163c3f2016-01-29 01:14:38 -0800255 ost << ToStringIfSet("screencast min bitrate kbps",
256 screencast_min_bitrate_kbps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 ost << "}";
258 return ost.str();
259 }
260
nisseb163c3f2016-01-29 01:14:38 -0800261 // Enable denoising? This flag comes from the getUserMedia
262 // constraint 'googNoiseReduction', and WebRtcVideoEngine2 passes it
263 // on to the codec options. Disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100264 rtc::Optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800265 // Enable WebRTC Cpu Overuse Detection. This flag comes from the
266 // PeerConnection constraint 'googCpuOveruseDetection' and is
267 // checked in WebRtcVideoChannel2::OnLoadUpdate, where it's passed
268 // to VideoCapturer::video_adapter()->OnCpuResolutionRequest.
Karl Wibergbe579832015-11-10 22:34:18 +0100269 rtc::Optional<bool> cpu_overuse_detection;
nisseb163c3f2016-01-29 01:14:38 -0800270 // Use conference mode? This flag comes from the remote
271 // description's SDP line 'a=x-google-flag:conference', copied over
272 // by VideoChannel::SetRemoteContent_w, and ultimately used by
273 // conference mode screencast logic in
274 // WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig.
275 // The special screencast behaviour is disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100276 rtc::Optional<bool> conference_mode;
nisseb163c3f2016-01-29 01:14:38 -0800277 // Set DSCP value for packet sent from video channel. This flag
278 // comes from the PeerConnection constraint 'googDscp' and,
279 // WebRtcVideoChannel2::SetOptions checks it before calling
280 // MediaChannel::SetDscp. If enabled, rtc::DSCP_AF41 is used. If
281 // disabled, which is the default, rtc::DSCP_DEFAULT is used.
Karl Wibergbe579832015-11-10 22:34:18 +0100282 rtc::Optional<bool> dscp;
nisseb163c3f2016-01-29 01:14:38 -0800283 // Enable WebRTC suspension of video. No video frames will be sent
284 // when the bitrate is below the configured minimum bitrate. This
285 // flag comes from the PeerConnection constraint
286 // 'googSuspendBelowMinBitrate', and WebRtcVideoChannel2 copies it
287 // to VideoSendStream::Config::suspend_below_min_bitrate.
Karl Wibergbe579832015-11-10 22:34:18 +0100288 rtc::Optional<bool> suspend_below_min_bitrate;
nisseb163c3f2016-01-29 01:14:38 -0800289 // Force screencast to use a minimum bitrate. This flag comes from
290 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
291 // copied to the encoder config by WebRtcVideoChannel2.
292 rtc::Optional<int> screencast_min_bitrate_kbps;
qiangchen444682a2015-11-24 18:07:56 -0800293 // Set to true if the renderer has an algorithm of frame selection.
294 // If the value is true, then WebRTC will hand over a frame as soon as
295 // possible without delay, and rendering smoothness is completely the duty
296 // of the renderer;
297 // If the value is false, then WebRTC is responsible to delay frame release
298 // in order to increase rendering smoothness.
nisseb163c3f2016-01-29 01:14:38 -0800299 //
300 // This flag comes from PeerConnection's RtcConfiguration, but is
301 // currently only set by the command line flag
302 // 'disable-rtc-smoothness-algorithm'.
303 // WebRtcVideoChannel2::AddRecvStream copies it to the created
304 // WebRtcVideoReceiveStream, where it is returned by the
305 // SmoothsRenderedFrames method. This method is used by the
306 // VideoReceiveStream, where the value is passed on to the
307 // IncomingVideoStream constructor.
qiangchen444682a2015-11-24 18:07:56 -0800308 rtc::Optional<bool> disable_prerenderer_smoothing;
kwiberg102c6a62015-10-30 02:47:38 -0700309
310 private:
311 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100312 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700313 if (o) {
314 *s = o;
315 }
316 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317};
318
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319struct RtpHeaderExtension {
320 RtpHeaderExtension() : id(0) {}
321 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322
323 bool operator==(const RtpHeaderExtension& ext) const {
324 // id is a reserved word in objective-c. Therefore the id attribute has to
325 // be a fully qualified name in order to compile on IOS.
326 return this->id == ext.id &&
327 uri == ext.uri;
328 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700329
330 std::string ToString() const {
331 std::ostringstream ost;
332 ost << "{";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700333 ost << "uri: " << uri;
solenberg7e4e01a2015-12-02 08:05:01 -0800334 ost << ", id: " << id;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700335 ost << "}";
336 return ost.str();
337 }
338
339 std::string uri;
340 int id;
341 // TODO(juberti): SendRecv direction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342};
343
344// Returns the named header extension if found among all extensions, NULL
345// otherwise.
346inline const RtpHeaderExtension* FindHeaderExtension(
347 const std::vector<RtpHeaderExtension>& extensions,
348 const std::string& name) {
349 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
350 it != extensions.end(); ++it) {
351 if (it->uri == name)
352 return &(*it);
353 }
354 return NULL;
355}
356
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357class MediaChannel : public sigslot::has_slots<> {
358 public:
359 class NetworkInterface {
360 public:
361 enum SocketType { ST_RTP, ST_RTCP };
stefanc1aeaf02015-10-15 07:26:07 -0700362 virtual bool SendPacket(rtc::Buffer* packet,
363 const rtc::PacketOptions& options) = 0;
364 virtual bool SendRtcp(rtc::Buffer* packet,
365 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000366 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 int option) = 0;
368 virtual ~NetworkInterface() {}
369 };
370
371 MediaChannel() : network_interface_(NULL) {}
372 virtual ~MediaChannel() {}
373
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000374 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000376 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377 network_interface_ = iface;
378 }
379
380 // Called when a RTP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000381 virtual void OnPacketReceived(rtc::Buffer* packet,
382 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 // Called when a RTCP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000384 virtual void OnRtcpReceived(rtc::Buffer* packet,
385 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 // Called when the socket's ability to send has changed.
387 virtual void OnReadyToSend(bool ready) = 0;
388 // Creates a new outgoing media stream with SSRCs and CNAME as described
389 // by sp.
390 virtual bool AddSendStream(const StreamParams& sp) = 0;
391 // Removes an outgoing media stream.
392 // ssrc must be the first SSRC of the media stream if the stream uses
393 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200394 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395 // Creates a new incoming media stream with SSRCs and CNAME as described
396 // by sp.
397 virtual bool AddRecvStream(const StreamParams& sp) = 0;
398 // Removes an incoming media stream.
399 // ssrc must be the first SSRC of the media stream if the stream uses
400 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200401 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000403 // Returns the absoulte sendtime extension id value from media channel.
404 virtual int GetRtpSendTimeExtnId() const {
405 return -1;
406 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000408 // Base method to send packet using NetworkInterface.
stefanc1aeaf02015-10-15 07:26:07 -0700409 bool SendPacket(rtc::Buffer* packet, const rtc::PacketOptions& options) {
410 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000411 }
412
stefanc1aeaf02015-10-15 07:26:07 -0700413 bool SendRtcp(rtc::Buffer* packet, const rtc::PacketOptions& options) {
414 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000415 }
416
417 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000418 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000419 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000420 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000421 if (!network_interface_)
422 return -1;
423
424 return network_interface_->SetOption(type, opt, option);
425 }
426
wu@webrtc.orgde305012013-10-31 15:40:38 +0000427 protected:
428 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000429 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000430 int ret;
431 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000432 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000433 value);
434 if (ret == 0) {
435 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000436 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000437 value);
438 }
439 return ret;
440 }
441
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000442 private:
stefanc1aeaf02015-10-15 07:26:07 -0700443 bool DoSendPacket(rtc::Buffer* packet,
444 bool rtcp,
445 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000446 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000447 if (!network_interface_)
448 return false;
449
stefanc1aeaf02015-10-15 07:26:07 -0700450 return (!rtcp) ? network_interface_->SendPacket(packet, options)
451 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000452 }
453
454 // |network_interface_| can be accessed from the worker_thread and
455 // from any MediaEngine threads. This critical section is to protect accessing
456 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000457 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000458 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459};
460
461enum SendFlags {
462 SEND_NOTHING,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463 SEND_MICROPHONE
464};
465
wu@webrtc.org97077a32013-10-25 21:18:33 +0000466// The stats information is structured as follows:
467// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
468// Media contains a vector of SSRC infos that are exclusively used by this
469// media. (SSRCs shared between media streams can't be represented.)
470
471// Information about an SSRC.
472// This data may be locally recorded, or received in an RTCP SR or RR.
473struct SsrcSenderInfo {
474 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000476 timestamp(0) {
477 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200478 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000479 double timestamp; // NTP timestamp, represented as seconds since epoch.
480};
481
482struct SsrcReceiverInfo {
483 SsrcReceiverInfo()
484 : ssrc(0),
485 timestamp(0) {
486 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200487 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000488 double timestamp;
489};
490
491struct MediaSenderInfo {
492 MediaSenderInfo()
493 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 packets_sent(0),
495 packets_lost(0),
496 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000497 rtt_ms(0) {
498 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000499 void add_ssrc(const SsrcSenderInfo& stat) {
500 local_stats.push_back(stat);
501 }
502 // Temporary utility function for call sites that only provide SSRC.
503 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200504 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000505 SsrcSenderInfo stat;
506 stat.ssrc = ssrc;
507 add_ssrc(stat);
508 }
509 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200510 std::vector<uint32_t> ssrcs() const {
511 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000512 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
513 it != local_stats.end(); ++it) {
514 retval.push_back(it->ssrc);
515 }
516 return retval;
517 }
518 // Utility accessor for clients that make the assumption only one ssrc
519 // exists per media.
520 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200521 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000522 if (local_stats.size() > 0) {
523 return local_stats[0].ssrc;
524 } else {
525 return 0;
526 }
527 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200528 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000529 int packets_sent;
530 int packets_lost;
531 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000532 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000533 std::string codec_name;
534 std::vector<SsrcSenderInfo> local_stats;
535 std::vector<SsrcReceiverInfo> remote_stats;
536};
537
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000538template<class T>
539struct VariableInfo {
540 VariableInfo()
541 : min_val(),
542 mean(0.0),
543 max_val(),
544 variance(0.0) {
545 }
546 T min_val;
547 double mean;
548 T max_val;
549 double variance;
550};
551
wu@webrtc.org97077a32013-10-25 21:18:33 +0000552struct MediaReceiverInfo {
553 MediaReceiverInfo()
554 : bytes_rcvd(0),
555 packets_rcvd(0),
556 packets_lost(0),
557 fraction_lost(0.0) {
558 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000559 void add_ssrc(const SsrcReceiverInfo& stat) {
560 local_stats.push_back(stat);
561 }
562 // Temporary utility function for call sites that only provide SSRC.
563 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200564 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000565 SsrcReceiverInfo stat;
566 stat.ssrc = ssrc;
567 add_ssrc(stat);
568 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200569 std::vector<uint32_t> ssrcs() const {
570 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000571 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
572 it != local_stats.end(); ++it) {
573 retval.push_back(it->ssrc);
574 }
575 return retval;
576 }
577 // Utility accessor for clients that make the assumption only one ssrc
578 // exists per media.
579 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200580 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000581 if (local_stats.size() > 0) {
582 return local_stats[0].ssrc;
583 } else {
584 return 0;
585 }
586 }
587
Peter Boström0c4e06b2015-10-07 12:23:21 +0200588 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000589 int packets_rcvd;
590 int packets_lost;
591 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000592 std::string codec_name;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000593 std::vector<SsrcReceiverInfo> local_stats;
594 std::vector<SsrcSenderInfo> remote_stats;
595};
596
597struct VoiceSenderInfo : public MediaSenderInfo {
598 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000599 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600 jitter_ms(0),
601 audio_level(0),
602 aec_quality_min(0.0),
603 echo_delay_median_ms(0),
604 echo_delay_std_ms(0),
605 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000606 echo_return_loss_enhancement(0),
607 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000608 }
609
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000611 int jitter_ms;
612 int audio_level;
613 float aec_quality_min;
614 int echo_delay_median_ms;
615 int echo_delay_std_ms;
616 int echo_return_loss;
617 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000618 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000619};
620
wu@webrtc.org97077a32013-10-25 21:18:33 +0000621struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000623 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 jitter_ms(0),
625 jitter_buffer_ms(0),
626 jitter_buffer_preferred_ms(0),
627 delay_estimate_ms(0),
628 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000629 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000630 speech_expand_rate(0),
631 secondary_decoded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200632 accelerate_rate(0),
633 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000634 decoding_calls_to_silence_generator(0),
635 decoding_calls_to_neteq(0),
636 decoding_normal(0),
637 decoding_plc(0),
638 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000639 decoding_plc_cng(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200640 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000642 int ext_seqnum;
643 int jitter_ms;
644 int jitter_buffer_ms;
645 int jitter_buffer_preferred_ms;
646 int delay_estimate_ms;
647 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000648 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000649 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000650 // fraction of synthesized speech inserted through expansion.
651 float speech_expand_rate;
652 // fraction of data out of secondary decoding, including FEC and RED.
653 float secondary_decoded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200654 // Fraction of data removed through time compression.
655 float accelerate_rate;
656 // Fraction of data inserted through time stretching.
657 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000658 int decoding_calls_to_silence_generator;
659 int decoding_calls_to_neteq;
660 int decoding_normal;
661 int decoding_plc;
662 int decoding_cng;
663 int decoding_plc_cng;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000664 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200665 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666};
667
wu@webrtc.org97077a32013-10-25 21:18:33 +0000668struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000670 : packets_cached(0),
671 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000672 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000674 input_frame_width(0),
675 input_frame_height(0),
676 send_frame_width(0),
677 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000678 framerate_input(0),
679 framerate_sent(0),
680 nominal_bitrate(0),
681 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000682 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000683 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000684 avg_encode_ms(0),
Peter Boström8ed6a4b2015-03-27 10:01:02 +0100685 encode_usage_percent(0) {
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000686 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000688 std::vector<SsrcGroup> ssrc_groups;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100689 std::string encoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000690 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000692 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000694 int input_frame_width;
695 int input_frame_height;
696 int send_frame_width;
697 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698 int framerate_input;
699 int framerate_sent;
700 int nominal_bitrate;
701 int preferred_bitrate;
702 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000703 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000704 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000705 int encode_usage_percent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000706 VariableInfo<int> adapt_frame_drops;
707 VariableInfo<int> effects_frame_drops;
708 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709};
710
wu@webrtc.org97077a32013-10-25 21:18:33 +0000711struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000713 : packets_concealed(0),
714 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000715 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 nacks_sent(0),
717 frame_width(0),
718 frame_height(0),
719 framerate_rcvd(0),
720 framerate_decoded(0),
721 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000722 framerate_render_input(0),
723 framerate_render_output(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000724 decode_ms(0),
725 max_decode_ms(0),
726 jitter_buffer_ms(0),
727 min_playout_delay_ms(0),
728 render_delay_ms(0),
729 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000730 current_delay_ms(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000731 capture_start_ntp_time_ms(-1) {
732 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000734 std::vector<SsrcGroup> ssrc_groups;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100735 std::string decoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000736 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000738 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 int nacks_sent;
740 int frame_width;
741 int frame_height;
742 int framerate_rcvd;
743 int framerate_decoded;
744 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000745 // Framerate as sent to the renderer.
746 int framerate_render_input;
747 // Framerate that the renderer reports.
748 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000749
750 // All stats below are gathered per-VideoReceiver, but some will be correlated
751 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
752 // structures, reflect this in the new layout.
753
754 // Current frame decode latency.
755 int decode_ms;
756 // Maximum observed frame decode latency.
757 int max_decode_ms;
758 // Jitter (network-related) latency.
759 int jitter_buffer_ms;
760 // Requested minimum playout latency.
761 int min_playout_delay_ms;
762 // Requested latency to account for rendering delay.
763 int render_delay_ms;
764 // Target overall delay: network+decode+render, accounting for
765 // min_playout_delay_ms.
766 int target_delay_ms;
767 // Current overall delay, possibly ramping towards target_delay_ms.
768 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000769
770 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200771 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772};
773
wu@webrtc.org97077a32013-10-25 21:18:33 +0000774struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000776 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000777 }
778
Peter Boström0c4e06b2015-10-07 12:23:21 +0200779 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780};
781
wu@webrtc.org97077a32013-10-25 21:18:33 +0000782struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000784 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 }
786
Peter Boström0c4e06b2015-10-07 12:23:21 +0200787 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788};
789
790struct BandwidthEstimationInfo {
791 BandwidthEstimationInfo()
792 : available_send_bandwidth(0),
793 available_recv_bandwidth(0),
794 target_enc_bitrate(0),
795 actual_enc_bitrate(0),
796 retransmit_bitrate(0),
797 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000798 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 }
800
801 int available_send_bandwidth;
802 int available_recv_bandwidth;
803 int target_enc_bitrate;
804 int actual_enc_bitrate;
805 int retransmit_bitrate;
806 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000807 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808};
809
810struct VoiceMediaInfo {
811 void Clear() {
812 senders.clear();
813 receivers.clear();
814 }
815 std::vector<VoiceSenderInfo> senders;
816 std::vector<VoiceReceiverInfo> receivers;
817};
818
819struct VideoMediaInfo {
820 void Clear() {
821 senders.clear();
822 receivers.clear();
823 bw_estimations.clear();
824 }
825 std::vector<VideoSenderInfo> senders;
826 std::vector<VideoReceiverInfo> receivers;
827 std::vector<BandwidthEstimationInfo> bw_estimations;
828};
829
830struct DataMediaInfo {
831 void Clear() {
832 senders.clear();
833 receivers.clear();
834 }
835 std::vector<DataSenderInfo> senders;
836 std::vector<DataReceiverInfo> receivers;
837};
838
deadbeef13871492015-12-09 12:37:51 -0800839struct RtcpParameters {
840 bool reduced_size = false;
841};
842
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700843template <class Codec>
844struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800845 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700846 std::ostringstream ost;
847 ost << "{";
848 ost << "codecs: " << VectorToString(codecs) << ", ";
849 ost << "extensions: " << VectorToString(extensions);
850 ost << "}";
851 return ost.str();
852 }
853
854 std::vector<Codec> codecs;
855 std::vector<RtpHeaderExtension> extensions;
856 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800857 RtcpParameters rtcp;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700858};
859
860template <class Codec, class Options>
861struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800862 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700863 std::ostringstream ost;
864 ost << "{";
865 ost << "codecs: " << VectorToString(this->codecs) << ", ";
866 ost << "extensions: " << VectorToString(this->extensions) << ", ";
pbos378dc772016-01-28 15:58:41 -0800867 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700868 ost << "options: " << options.ToString();
869 ost << "}";
870 return ost.str();
871 }
872
873 int max_bandwidth_bps = -1;
874 Options options;
875};
876
877struct AudioSendParameters : RtpSendParameters<AudioCodec, AudioOptions> {
878};
879
880struct AudioRecvParameters : RtpParameters<AudioCodec> {
881};
882
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883class VoiceMediaChannel : public MediaChannel {
884 public:
885 enum Error {
886 ERROR_NONE = 0, // No error.
887 ERROR_OTHER, // Other errors.
888 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
889 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
890 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
891 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
892 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
893 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
894 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
895 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
896 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
897 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
898 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
899 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
900 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
901 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
902 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
903 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
904 };
905
906 VoiceMediaChannel() {}
907 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200908 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
909 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 // Starts or stops playout of received audio.
911 virtual bool SetPlayout(bool playout) = 0;
912 // Starts or stops sending (and potentially capture) of local audio.
913 virtual bool SetSend(SendFlags flag) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700914 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200915 virtual bool SetAudioSend(uint32_t ssrc,
916 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700917 const AudioOptions* options,
solenberg1dd98f32015-09-10 01:57:14 -0700918 AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 // Gets current energy levels for all incoming streams.
920 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
921 // Get the current energy level of the stream sent to the speaker.
922 virtual int GetOutputLevel() = 0;
923 // Get the time in milliseconds since last recorded keystroke, or negative.
924 virtual int GetTimeSinceLastTyping() = 0;
925 // Temporarily exposed field for tuning typing detect options.
926 virtual void SetTypingDetectionParameters(int time_window,
927 int cost_per_typing, int reporting_threshold, int penalty_decay,
928 int type_event_delay) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700929 // Set speaker output volume of the specified ssrc.
930 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800932 virtual bool CanInsertDtmf() = 0;
933 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000935 // The valid value for the |event| are 0 to 15 which corresponding to
936 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800937 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 // Gets quality stats for the channel.
939 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100940
941 virtual void SetRawAudioSink(
942 uint32_t ssrc,
deadbeef2d110be2016-01-13 12:00:26 -0800943 rtc::scoped_ptr<webrtc::AudioSinkInterface> sink) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944};
945
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700946struct VideoSendParameters : RtpSendParameters<VideoCodec, VideoOptions> {
947};
948
949struct VideoRecvParameters : RtpParameters<VideoCodec> {
950};
951
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000952class VideoMediaChannel : public MediaChannel {
953 public:
954 enum Error {
955 ERROR_NONE = 0, // No error.
956 ERROR_OTHER, // Other errors.
957 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
958 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
959 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
960 ERROR_REC_DEVICE_REMOVED, // Device is removed.
961 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
962 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
963 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
964 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
965 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
966 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
967 };
968
nisse08582ff2016-02-04 01:24:52 -0800969 VideoMediaChannel() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200971
972 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
973 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974 // Gets the currently set codecs/payload types to be used for outgoing media.
975 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 // Starts or stops transmission (and potentially capture) of local video.
977 virtual bool SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700978 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200979 virtual bool SetVideoSend(uint32_t ssrc,
980 bool enable,
solenberg1dd98f32015-09-10 01:57:14 -0700981 const VideoOptions* options) = 0;
nisse08582ff2016-02-04 01:24:52 -0800982 // Sets the sink object to be used for the specified stream.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 // If SSRC is 0, the renderer is used for the 'default' stream.
nisse08582ff2016-02-04 01:24:52 -0800984 virtual bool SetSink(uint32_t ssrc,
985 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 // If |ssrc| is 0, replace the default capturer (engine capturer) with
987 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200988 virtual bool SetCapturer(uint32_t ssrc, VideoCapturer* capturer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000990 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991};
992
993enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000994 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
995 // values.
996 DMT_NONE = 0,
997 DMT_CONTROL = 1,
998 DMT_BINARY = 2,
999 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000};
1001
1002// Info about data received in DataMediaChannel. For use in
1003// DataMediaChannel::SignalDataReceived and in all of the signals that
1004// signal fires, on up the chain.
1005struct ReceiveDataParams {
1006 // The in-packet stream indentifier.
1007 // For SCTP, this is really SID, not SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001008 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 // The type of message (binary, text, or control).
1010 DataMessageType type;
1011 // A per-stream value incremented per packet in the stream.
1012 int seq_num;
1013 // A per-stream value monotonically increasing with time.
1014 int timestamp;
1015
1016 ReceiveDataParams() :
1017 ssrc(0),
1018 type(DMT_TEXT),
1019 seq_num(0),
1020 timestamp(0) {
1021 }
1022};
1023
1024struct SendDataParams {
1025 // The in-packet stream indentifier.
1026 // For SCTP, this is really SID, not SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001027 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 // The type of message (binary, text, or control).
1029 DataMessageType type;
1030
1031 // For SCTP, whether to send messages flagged as ordered or not.
1032 // If false, messages can be received out of order.
1033 bool ordered;
1034 // For SCTP, whether the messages are sent reliably or not.
1035 // If false, messages may be lost.
1036 bool reliable;
1037 // For SCTP, if reliable == false, provide partial reliability by
1038 // resending up to this many times. Either count or millis
1039 // is supported, not both at the same time.
1040 int max_rtx_count;
1041 // For SCTP, if reliable == false, provide partial reliability by
1042 // resending for up to this many milliseconds. Either count or millis
1043 // is supported, not both at the same time.
1044 int max_rtx_ms;
1045
1046 SendDataParams() :
1047 ssrc(0),
1048 type(DMT_TEXT),
1049 // TODO(pthatcher): Make these true by default?
1050 ordered(false),
1051 reliable(false),
1052 max_rtx_count(0),
1053 max_rtx_ms(0) {
1054 }
1055};
1056
1057enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1058
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001059struct DataOptions {
solenberg7e4e01a2015-12-02 08:05:01 -08001060 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001061 return "{}";
1062 }
1063};
1064
1065struct DataSendParameters : RtpSendParameters<DataCodec, DataOptions> {
solenberg7e4e01a2015-12-02 08:05:01 -08001066 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001067 std::ostringstream ost;
1068 // Options and extensions aren't used.
1069 ost << "{";
1070 ost << "codecs: " << VectorToString(codecs) << ", ";
pbos378dc772016-01-28 15:58:41 -08001071 ost << "max_bandwidth_bps: " << max_bandwidth_bps;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001072 ost << "}";
1073 return ost.str();
1074 }
1075};
1076
1077struct DataRecvParameters : RtpParameters<DataCodec> {
1078};
1079
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080class DataMediaChannel : public MediaChannel {
1081 public:
1082 enum Error {
1083 ERROR_NONE = 0, // No error.
1084 ERROR_OTHER, // Other errors.
1085 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1086 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1087 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1088 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1089 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1090 };
1091
1092 virtual ~DataMediaChannel() {}
1093
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001094 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1095 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001096
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097 // TODO(pthatcher): Implement this.
1098 virtual bool GetStats(DataMediaInfo* info) { return true; }
1099
1100 virtual bool SetSend(bool send) = 0;
1101 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102
1103 virtual bool SendData(
1104 const SendDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001105 const rtc::Buffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 SendDataResult* result = NULL) = 0;
1107 // Signals when data is received (params, data, len)
1108 sigslot::signal3<const ReceiveDataParams&,
1109 const char*,
1110 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001111 // Signal when the media channel is ready to send the stream. Arguments are:
1112 // writable(bool)
1113 sigslot::signal1<bool> SignalReadyToSend;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001114 // Signal for notifying that the remote side has closed the DataChannel.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001115 sigslot::signal1<uint32_t> SignalStreamClosedRemotely;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001116};
1117
1118} // namespace cricket
1119
kjellandera96e2d72016-02-04 23:52:28 -08001120#endif // WEBRTC_MEDIA_BASE_MEDIACHANNEL_H_