blob: 3b27b92dd96d613764f44386e4b9d3dcd07e6297 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2004 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef TALK_MEDIA_BASE_MEDIACHANNEL_H_
29#define TALK_MEDIA_BASE_MEDIACHANNEL_H_
30
31#include <string>
32#include <vector>
33
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000034#include "talk/media/base/codec.h"
35#include "talk/media/base/constants.h"
36#include "talk/media/base/streamparams.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000037#include "webrtc/base/basictypes.h"
38#include "webrtc/base/buffer.h"
39#include "webrtc/base/dscp.h"
40#include "webrtc/base/logging.h"
Karl Wibergbe579832015-11-10 22:34:18 +010041#include "webrtc/base/optional.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000042#include "webrtc/base/sigslot.h"
43#include "webrtc/base/socket.h"
44#include "webrtc/base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045// TODO(juberti): re-evaluate this include
46#include "talk/session/media/audiomonitor.h"
47
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000048namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049class Buffer;
50class RateLimiter;
51class Timing;
52}
53
Tommif888bb52015-12-12 01:37:01 +010054namespace webrtc {
55class AudioSinkInterface;
56}
57
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058namespace cricket {
59
tommi1d5c19d2015-12-13 22:54:29 -080060class AudioRenderer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061class ScreencastId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062class VideoCapturer;
63class VideoRenderer;
tommi1d5c19d2015-12-13 22:54:29 -080064struct RtpHeader;
65struct VideoFormat;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066
67const int kMinRtpHeaderExtensionId = 1;
68const int kMaxRtpHeaderExtensionId = 255;
69const int kScreencastDefaultFps = 5;
70
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071template <class T>
Karl Wibergbe579832015-11-10 22:34:18 +010072static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 std::string str;
kwiberg102c6a62015-10-30 02:47:38 -070074 if (val) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075 str = key;
76 str += ": ";
kwiberg102c6a62015-10-30 02:47:38 -070077 str += val ? rtc::ToString(*val) : "";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 str += ", ";
79 }
80 return str;
81}
82
Peter Thatcherc2ee2c82015-08-07 16:05:34 -070083template <class T>
84static std::string VectorToString(const std::vector<T>& vals) {
85 std::ostringstream ost;
86 ost << "[";
87 for (size_t i = 0; i < vals.size(); ++i) {
88 if (i > 0) {
89 ost << ", ";
90 }
91 ost << vals[i].ToString();
92 }
93 ost << "]";
94 return ost.str();
95}
96
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097// Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine.
98// Used to be flags, but that makes it hard to selectively apply options.
99// We are moving all of the setting of options to structs like this,
100// but some things currently still use flags.
101struct AudioOptions {
102 void SetAll(const AudioOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700103 SetFrom(&echo_cancellation, change.echo_cancellation);
104 SetFrom(&auto_gain_control, change.auto_gain_control);
105 SetFrom(&noise_suppression, change.noise_suppression);
106 SetFrom(&highpass_filter, change.highpass_filter);
107 SetFrom(&stereo_swapping, change.stereo_swapping);
108 SetFrom(&audio_jitter_buffer_max_packets,
109 change.audio_jitter_buffer_max_packets);
110 SetFrom(&audio_jitter_buffer_fast_accelerate,
111 change.audio_jitter_buffer_fast_accelerate);
112 SetFrom(&typing_detection, change.typing_detection);
113 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise);
114 SetFrom(&conference_mode, change.conference_mode);
115 SetFrom(&adjust_agc_delta, change.adjust_agc_delta);
116 SetFrom(&experimental_agc, change.experimental_agc);
117 SetFrom(&extended_filter_aec, change.extended_filter_aec);
118 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec);
119 SetFrom(&experimental_ns, change.experimental_ns);
120 SetFrom(&aec_dump, change.aec_dump);
121 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov);
122 SetFrom(&tx_agc_digital_compression_gain,
123 change.tx_agc_digital_compression_gain);
124 SetFrom(&tx_agc_limiter, change.tx_agc_limiter);
125 SetFrom(&recording_sample_rate, change.recording_sample_rate);
126 SetFrom(&playout_sample_rate, change.playout_sample_rate);
127 SetFrom(&dscp, change.dscp);
128 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129 }
130
131 bool operator==(const AudioOptions& o) const {
132 return echo_cancellation == o.echo_cancellation &&
133 auto_gain_control == o.auto_gain_control &&
134 noise_suppression == o.noise_suppression &&
135 highpass_filter == o.highpass_filter &&
136 stereo_swapping == o.stereo_swapping &&
Henrik Lundin64dad832015-05-11 12:44:23 +0200137 audio_jitter_buffer_max_packets == o.audio_jitter_buffer_max_packets &&
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200138 audio_jitter_buffer_fast_accelerate ==
139 o.audio_jitter_buffer_fast_accelerate &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140 typing_detection == o.typing_detection &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000141 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 conference_mode == o.conference_mode &&
143 experimental_agc == o.experimental_agc &&
Henrik Lundin441f6342015-06-09 16:03:13 +0200144 extended_filter_aec == o.extended_filter_aec &&
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100145 delay_agnostic_aec == o.delay_agnostic_aec &&
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000146 experimental_ns == o.experimental_ns &&
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147 adjust_agc_delta == o.adjust_agc_delta &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000148 aec_dump == o.aec_dump &&
149 tx_agc_target_dbov == o.tx_agc_target_dbov &&
150 tx_agc_digital_compression_gain == o.tx_agc_digital_compression_gain &&
151 tx_agc_limiter == o.tx_agc_limiter &&
wu@webrtc.org97077a32013-10-25 21:18:33 +0000152 recording_sample_rate == o.recording_sample_rate &&
wu@webrtc.orgde305012013-10-31 15:40:38 +0000153 playout_sample_rate == o.playout_sample_rate &&
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000154 dscp == o.dscp &&
155 combined_audio_video_bwe == o.combined_audio_video_bwe;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 }
157
158 std::string ToString() const {
159 std::ostringstream ost;
160 ost << "AudioOptions {";
161 ost << ToStringIfSet("aec", echo_cancellation);
162 ost << ToStringIfSet("agc", auto_gain_control);
163 ost << ToStringIfSet("ns", noise_suppression);
164 ost << ToStringIfSet("hf", highpass_filter);
165 ost << ToStringIfSet("swap", stereo_swapping);
Henrik Lundin64dad832015-05-11 12:44:23 +0200166 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
167 audio_jitter_buffer_max_packets);
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200168 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
169 audio_jitter_buffer_fast_accelerate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 ost << ToStringIfSet("typing", typing_detection);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000171 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 ost << ToStringIfSet("conference", conference_mode);
173 ost << ToStringIfSet("agc_delta", adjust_agc_delta);
174 ost << ToStringIfSet("experimental_agc", experimental_agc);
Henrik Lundin441f6342015-06-09 16:03:13 +0200175 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
Bjorn Volckerbf395c12015-03-25 22:45:56 +0100176 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000177 ost << ToStringIfSet("experimental_ns", experimental_ns);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 ost << ToStringIfSet("aec_dump", aec_dump);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000179 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
180 ost << ToStringIfSet("tx_agc_digital_compression_gain",
181 tx_agc_digital_compression_gain);
182 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000183 ost << ToStringIfSet("recording_sample_rate", recording_sample_rate);
184 ost << ToStringIfSet("playout_sample_rate", playout_sample_rate);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000185 ost << ToStringIfSet("dscp", dscp);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000186 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 ost << "}";
188 return ost.str();
189 }
190
191 // Audio processing that attempts to filter away the output signal from
192 // later inbound pickup.
Karl Wibergbe579832015-11-10 22:34:18 +0100193 rtc::Optional<bool> echo_cancellation;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 // Audio processing to adjust the sensitivity of the local mic dynamically.
Karl Wibergbe579832015-11-10 22:34:18 +0100195 rtc::Optional<bool> auto_gain_control;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 // Audio processing to filter out background noise.
Karl Wibergbe579832015-11-10 22:34:18 +0100197 rtc::Optional<bool> noise_suppression;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 // Audio processing to remove background noise of lower frequencies.
Karl Wibergbe579832015-11-10 22:34:18 +0100199 rtc::Optional<bool> highpass_filter;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 // Audio processing to swap the left and right channels.
Karl Wibergbe579832015-11-10 22:34:18 +0100201 rtc::Optional<bool> stereo_swapping;
Henrik Lundin64dad832015-05-11 12:44:23 +0200202 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Karl Wibergbe579832015-11-10 22:34:18 +0100203 rtc::Optional<int> audio_jitter_buffer_max_packets;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200204 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Karl Wibergbe579832015-11-10 22:34:18 +0100205 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 // Audio processing to detect typing.
Karl Wibergbe579832015-11-10 22:34:18 +0100207 rtc::Optional<bool> typing_detection;
208 rtc::Optional<bool> aecm_generate_comfort_noise;
209 rtc::Optional<bool> conference_mode;
210 rtc::Optional<int> adjust_agc_delta;
211 rtc::Optional<bool> experimental_agc;
212 rtc::Optional<bool> extended_filter_aec;
213 rtc::Optional<bool> delay_agnostic_aec;
214 rtc::Optional<bool> experimental_ns;
215 rtc::Optional<bool> aec_dump;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000216 // Note that tx_agc_* only applies to non-experimental AGC.
Karl Wibergbe579832015-11-10 22:34:18 +0100217 rtc::Optional<uint16_t> tx_agc_target_dbov;
218 rtc::Optional<uint16_t> tx_agc_digital_compression_gain;
219 rtc::Optional<bool> tx_agc_limiter;
220 rtc::Optional<uint32_t> recording_sample_rate;
221 rtc::Optional<uint32_t> playout_sample_rate;
wu@webrtc.orgde305012013-10-31 15:40:38 +0000222 // Set DSCP value for packet sent from audio channel.
Karl Wibergbe579832015-11-10 22:34:18 +0100223 rtc::Optional<bool> dscp;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000224 // Enable combined audio+bandwidth BWE.
Karl Wibergbe579832015-11-10 22:34:18 +0100225 rtc::Optional<bool> combined_audio_video_bwe;
kwiberg102c6a62015-10-30 02:47:38 -0700226
227 private:
228 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100229 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700230 if (o) {
231 *s = o;
232 }
233 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234};
235
236// Options that can be applied to a VideoMediaChannel or a VideoMediaEngine.
237// Used to be flags, but that makes it hard to selectively apply options.
238// We are moving all of the setting of options to structs like this,
239// but some things currently still use flags.
240struct VideoOptions {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 void SetAll(const VideoOptions& change) {
kwiberg102c6a62015-10-30 02:47:38 -0700242 SetFrom(&video_noise_reduction, change.video_noise_reduction);
kwiberg102c6a62015-10-30 02:47:38 -0700243 SetFrom(&cpu_overuse_detection, change.cpu_overuse_detection);
kwiberg102c6a62015-10-30 02:47:38 -0700244 SetFrom(&conference_mode, change.conference_mode);
kwiberg102c6a62015-10-30 02:47:38 -0700245 SetFrom(&dscp, change.dscp);
246 SetFrom(&suspend_below_min_bitrate, change.suspend_below_min_bitrate);
nisseb163c3f2016-01-29 01:14:38 -0800247 SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps);
qiangchen444682a2015-11-24 18:07:56 -0800248 SetFrom(&disable_prerenderer_smoothing,
249 change.disable_prerenderer_smoothing);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 }
251
252 bool operator==(const VideoOptions& o) const {
nisseb163c3f2016-01-29 01:14:38 -0800253 return video_noise_reduction == o.video_noise_reduction &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000254 cpu_overuse_detection == o.cpu_overuse_detection &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000255 conference_mode == o.conference_mode &&
Peter Thatchera9b4c322015-07-16 03:47:28 -0700256 dscp == o.dscp &&
pbos@webrtc.org43336b62014-10-14 19:12:06 +0000257 suspend_below_min_bitrate == o.suspend_below_min_bitrate &&
nisseb163c3f2016-01-29 01:14:38 -0800258 screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps &&
qiangchen444682a2015-11-24 18:07:56 -0800259 disable_prerenderer_smoothing == o.disable_prerenderer_smoothing;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 }
261
262 std::string ToString() const {
263 std::ostringstream ost;
264 ost << "VideoOptions {";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265 ost << ToStringIfSet("noise reduction", video_noise_reduction);
wu@webrtc.orgcadf9042013-08-30 21:24:16 +0000266 ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 ost << ToStringIfSet("conference mode", conference_mode);
wu@webrtc.orgde305012013-10-31 15:40:38 +0000268 ost << ToStringIfSet("dscp", dscp);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000269 ost << ToStringIfSet("suspend below min bitrate",
270 suspend_below_min_bitrate);
nisseb163c3f2016-01-29 01:14:38 -0800271 ost << ToStringIfSet("screencast min bitrate kbps",
272 screencast_min_bitrate_kbps);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 ost << "}";
274 return ost.str();
275 }
276
nisseb163c3f2016-01-29 01:14:38 -0800277 // Enable denoising? This flag comes from the getUserMedia
278 // constraint 'googNoiseReduction', and WebRtcVideoEngine2 passes it
279 // on to the codec options. Disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100280 rtc::Optional<bool> video_noise_reduction;
nisseb163c3f2016-01-29 01:14:38 -0800281 // Enable WebRTC Cpu Overuse Detection. This flag comes from the
282 // PeerConnection constraint 'googCpuOveruseDetection' and is
283 // checked in WebRtcVideoChannel2::OnLoadUpdate, where it's passed
284 // to VideoCapturer::video_adapter()->OnCpuResolutionRequest.
Karl Wibergbe579832015-11-10 22:34:18 +0100285 rtc::Optional<bool> cpu_overuse_detection;
nisseb163c3f2016-01-29 01:14:38 -0800286 // Use conference mode? This flag comes from the remote
287 // description's SDP line 'a=x-google-flag:conference', copied over
288 // by VideoChannel::SetRemoteContent_w, and ultimately used by
289 // conference mode screencast logic in
290 // WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig.
291 // The special screencast behaviour is disabled by default.
Karl Wibergbe579832015-11-10 22:34:18 +0100292 rtc::Optional<bool> conference_mode;
nisseb163c3f2016-01-29 01:14:38 -0800293 // Set DSCP value for packet sent from video channel. This flag
294 // comes from the PeerConnection constraint 'googDscp' and,
295 // WebRtcVideoChannel2::SetOptions checks it before calling
296 // MediaChannel::SetDscp. If enabled, rtc::DSCP_AF41 is used. If
297 // disabled, which is the default, rtc::DSCP_DEFAULT is used.
Karl Wibergbe579832015-11-10 22:34:18 +0100298 rtc::Optional<bool> dscp;
nisseb163c3f2016-01-29 01:14:38 -0800299 // Enable WebRTC suspension of video. No video frames will be sent
300 // when the bitrate is below the configured minimum bitrate. This
301 // flag comes from the PeerConnection constraint
302 // 'googSuspendBelowMinBitrate', and WebRtcVideoChannel2 copies it
303 // to VideoSendStream::Config::suspend_below_min_bitrate.
Karl Wibergbe579832015-11-10 22:34:18 +0100304 rtc::Optional<bool> suspend_below_min_bitrate;
nisseb163c3f2016-01-29 01:14:38 -0800305 // Force screencast to use a minimum bitrate. This flag comes from
306 // the PeerConnection constraint 'googScreencastMinBitrate'. It is
307 // copied to the encoder config by WebRtcVideoChannel2.
308 rtc::Optional<int> screencast_min_bitrate_kbps;
qiangchen444682a2015-11-24 18:07:56 -0800309 // Set to true if the renderer has an algorithm of frame selection.
310 // If the value is true, then WebRTC will hand over a frame as soon as
311 // possible without delay, and rendering smoothness is completely the duty
312 // of the renderer;
313 // If the value is false, then WebRTC is responsible to delay frame release
314 // in order to increase rendering smoothness.
nisseb163c3f2016-01-29 01:14:38 -0800315 //
316 // This flag comes from PeerConnection's RtcConfiguration, but is
317 // currently only set by the command line flag
318 // 'disable-rtc-smoothness-algorithm'.
319 // WebRtcVideoChannel2::AddRecvStream copies it to the created
320 // WebRtcVideoReceiveStream, where it is returned by the
321 // SmoothsRenderedFrames method. This method is used by the
322 // VideoReceiveStream, where the value is passed on to the
323 // IncomingVideoStream constructor.
qiangchen444682a2015-11-24 18:07:56 -0800324 rtc::Optional<bool> disable_prerenderer_smoothing;
kwiberg102c6a62015-10-30 02:47:38 -0700325
326 private:
327 template <typename T>
Karl Wibergbe579832015-11-10 22:34:18 +0100328 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
kwiberg102c6a62015-10-30 02:47:38 -0700329 if (o) {
330 *s = o;
331 }
332 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333};
334
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335struct RtpHeaderExtension {
336 RtpHeaderExtension() : id(0) {}
337 RtpHeaderExtension(const std::string& u, int i) : uri(u), id(i) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338
339 bool operator==(const RtpHeaderExtension& ext) const {
340 // id is a reserved word in objective-c. Therefore the id attribute has to
341 // be a fully qualified name in order to compile on IOS.
342 return this->id == ext.id &&
343 uri == ext.uri;
344 }
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700345
346 std::string ToString() const {
347 std::ostringstream ost;
348 ost << "{";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700349 ost << "uri: " << uri;
solenberg7e4e01a2015-12-02 08:05:01 -0800350 ost << ", id: " << id;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700351 ost << "}";
352 return ost.str();
353 }
354
355 std::string uri;
356 int id;
357 // TODO(juberti): SendRecv direction;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358};
359
360// Returns the named header extension if found among all extensions, NULL
361// otherwise.
362inline const RtpHeaderExtension* FindHeaderExtension(
363 const std::vector<RtpHeaderExtension>& extensions,
364 const std::string& name) {
365 for (std::vector<RtpHeaderExtension>::const_iterator it = extensions.begin();
366 it != extensions.end(); ++it) {
367 if (it->uri == name)
368 return &(*it);
369 }
370 return NULL;
371}
372
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373class MediaChannel : public sigslot::has_slots<> {
374 public:
375 class NetworkInterface {
376 public:
377 enum SocketType { ST_RTP, ST_RTCP };
stefanc1aeaf02015-10-15 07:26:07 -0700378 virtual bool SendPacket(rtc::Buffer* packet,
379 const rtc::PacketOptions& options) = 0;
380 virtual bool SendRtcp(rtc::Buffer* packet,
381 const rtc::PacketOptions& options) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000382 virtual int SetOption(SocketType type, rtc::Socket::Option opt,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 int option) = 0;
384 virtual ~NetworkInterface() {}
385 };
386
387 MediaChannel() : network_interface_(NULL) {}
388 virtual ~MediaChannel() {}
389
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000390 // Sets the abstract interface class for sending RTP/RTCP data.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391 virtual void SetInterface(NetworkInterface *iface) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000392 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 network_interface_ = iface;
394 }
395
396 // Called when a RTP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000397 virtual void OnPacketReceived(rtc::Buffer* packet,
398 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399 // Called when a RTCP packet is received.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000400 virtual void OnRtcpReceived(rtc::Buffer* packet,
401 const rtc::PacketTime& packet_time) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402 // Called when the socket's ability to send has changed.
403 virtual void OnReadyToSend(bool ready) = 0;
404 // Creates a new outgoing media stream with SSRCs and CNAME as described
405 // by sp.
406 virtual bool AddSendStream(const StreamParams& sp) = 0;
407 // Removes an outgoing media stream.
408 // ssrc must be the first SSRC of the media stream if the stream uses
409 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200410 virtual bool RemoveSendStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 // Creates a new incoming media stream with SSRCs and CNAME as described
412 // by sp.
413 virtual bool AddRecvStream(const StreamParams& sp) = 0;
414 // Removes an incoming media stream.
415 // ssrc must be the first SSRC of the media stream if the stream uses
416 // multiple SSRCs.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200417 virtual bool RemoveRecvStream(uint32_t ssrc) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418
mallinath@webrtc.org92fdfeb2014-02-17 18:49:41 +0000419 // Returns the absoulte sendtime extension id value from media channel.
420 virtual int GetRtpSendTimeExtnId() const {
421 return -1;
422 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000423
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000424 // Base method to send packet using NetworkInterface.
stefanc1aeaf02015-10-15 07:26:07 -0700425 bool SendPacket(rtc::Buffer* packet, const rtc::PacketOptions& options) {
426 return DoSendPacket(packet, false, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000427 }
428
stefanc1aeaf02015-10-15 07:26:07 -0700429 bool SendRtcp(rtc::Buffer* packet, const rtc::PacketOptions& options) {
430 return DoSendPacket(packet, true, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000431 }
432
433 int SetOption(NetworkInterface::SocketType type,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000434 rtc::Socket::Option opt,
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000435 int option) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000436 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000437 if (!network_interface_)
438 return -1;
439
440 return network_interface_->SetOption(type, opt, option);
441 }
442
wu@webrtc.orgde305012013-10-31 15:40:38 +0000443 protected:
444 // This method sets DSCP |value| on both RTP and RTCP channels.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000445 int SetDscp(rtc::DiffServCodePoint value) {
wu@webrtc.orgde305012013-10-31 15:40:38 +0000446 int ret;
447 ret = SetOption(NetworkInterface::ST_RTP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000448 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000449 value);
450 if (ret == 0) {
451 ret = SetOption(NetworkInterface::ST_RTCP,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000452 rtc::Socket::OPT_DSCP,
wu@webrtc.orgde305012013-10-31 15:40:38 +0000453 value);
454 }
455 return ret;
456 }
457
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000458 private:
stefanc1aeaf02015-10-15 07:26:07 -0700459 bool DoSendPacket(rtc::Buffer* packet,
460 bool rtcp,
461 const rtc::PacketOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000462 rtc::CritScope cs(&network_interface_crit_);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000463 if (!network_interface_)
464 return false;
465
stefanc1aeaf02015-10-15 07:26:07 -0700466 return (!rtcp) ? network_interface_->SendPacket(packet, options)
467 : network_interface_->SendRtcp(packet, options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000468 }
469
470 // |network_interface_| can be accessed from the worker_thread and
471 // from any MediaEngine threads. This critical section is to protect accessing
472 // of network_interface_ object.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000473 rtc::CriticalSection network_interface_crit_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000474 NetworkInterface* network_interface_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475};
476
477enum SendFlags {
478 SEND_NOTHING,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 SEND_MICROPHONE
480};
481
wu@webrtc.org97077a32013-10-25 21:18:33 +0000482// The stats information is structured as follows:
483// Media are represented by either MediaSenderInfo or MediaReceiverInfo.
484// Media contains a vector of SSRC infos that are exclusively used by this
485// media. (SSRCs shared between media streams can't be represented.)
486
487// Information about an SSRC.
488// This data may be locally recorded, or received in an RTCP SR or RR.
489struct SsrcSenderInfo {
490 SsrcSenderInfo()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000491 : ssrc(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000492 timestamp(0) {
493 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200494 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000495 double timestamp; // NTP timestamp, represented as seconds since epoch.
496};
497
498struct SsrcReceiverInfo {
499 SsrcReceiverInfo()
500 : ssrc(0),
501 timestamp(0) {
502 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200503 uint32_t ssrc;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000504 double timestamp;
505};
506
507struct MediaSenderInfo {
508 MediaSenderInfo()
509 : bytes_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510 packets_sent(0),
511 packets_lost(0),
512 fraction_lost(0.0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000513 rtt_ms(0) {
514 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000515 void add_ssrc(const SsrcSenderInfo& stat) {
516 local_stats.push_back(stat);
517 }
518 // Temporary utility function for call sites that only provide SSRC.
519 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200520 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000521 SsrcSenderInfo stat;
522 stat.ssrc = ssrc;
523 add_ssrc(stat);
524 }
525 // Utility accessor for clients that are only interested in ssrc numbers.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200526 std::vector<uint32_t> ssrcs() const {
527 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000528 for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin();
529 it != local_stats.end(); ++it) {
530 retval.push_back(it->ssrc);
531 }
532 return retval;
533 }
534 // Utility accessor for clients that make the assumption only one ssrc
535 // exists per media.
536 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200537 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000538 if (local_stats.size() > 0) {
539 return local_stats[0].ssrc;
540 } else {
541 return 0;
542 }
543 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200544 int64_t bytes_sent;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000545 int packets_sent;
546 int packets_lost;
547 float fraction_lost;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000548 int64_t rtt_ms;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000549 std::string codec_name;
550 std::vector<SsrcSenderInfo> local_stats;
551 std::vector<SsrcReceiverInfo> remote_stats;
552};
553
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000554template<class T>
555struct VariableInfo {
556 VariableInfo()
557 : min_val(),
558 mean(0.0),
559 max_val(),
560 variance(0.0) {
561 }
562 T min_val;
563 double mean;
564 T max_val;
565 double variance;
566};
567
wu@webrtc.org97077a32013-10-25 21:18:33 +0000568struct MediaReceiverInfo {
569 MediaReceiverInfo()
570 : bytes_rcvd(0),
571 packets_rcvd(0),
572 packets_lost(0),
573 fraction_lost(0.0) {
574 }
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000575 void add_ssrc(const SsrcReceiverInfo& stat) {
576 local_stats.push_back(stat);
577 }
578 // Temporary utility function for call sites that only provide SSRC.
579 // As more info is added into SsrcSenderInfo, this function should go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200580 void add_ssrc(uint32_t ssrc) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000581 SsrcReceiverInfo stat;
582 stat.ssrc = ssrc;
583 add_ssrc(stat);
584 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200585 std::vector<uint32_t> ssrcs() const {
586 std::vector<uint32_t> retval;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000587 for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin();
588 it != local_stats.end(); ++it) {
589 retval.push_back(it->ssrc);
590 }
591 return retval;
592 }
593 // Utility accessor for clients that make the assumption only one ssrc
594 // exists per media.
595 // This will eventually go away.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200596 uint32_t ssrc() const {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000597 if (local_stats.size() > 0) {
598 return local_stats[0].ssrc;
599 } else {
600 return 0;
601 }
602 }
603
Peter Boström0c4e06b2015-10-07 12:23:21 +0200604 int64_t bytes_rcvd;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000605 int packets_rcvd;
606 int packets_lost;
607 float fraction_lost;
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000608 std::string codec_name;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000609 std::vector<SsrcReceiverInfo> local_stats;
610 std::vector<SsrcSenderInfo> remote_stats;
611};
612
613struct VoiceSenderInfo : public MediaSenderInfo {
614 VoiceSenderInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000615 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 jitter_ms(0),
617 audio_level(0),
618 aec_quality_min(0.0),
619 echo_delay_median_ms(0),
620 echo_delay_std_ms(0),
621 echo_return_loss(0),
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000622 echo_return_loss_enhancement(0),
623 typing_noise_detected(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 }
625
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626 int ext_seqnum;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 int jitter_ms;
628 int audio_level;
629 float aec_quality_min;
630 int echo_delay_median_ms;
631 int echo_delay_std_ms;
632 int echo_return_loss;
633 int echo_return_loss_enhancement;
wu@webrtc.org967bfff2013-09-19 05:49:50 +0000634 bool typing_noise_detected;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000635};
636
wu@webrtc.org97077a32013-10-25 21:18:33 +0000637struct VoiceReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000638 VoiceReceiverInfo()
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000639 : ext_seqnum(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640 jitter_ms(0),
641 jitter_buffer_ms(0),
642 jitter_buffer_preferred_ms(0),
643 delay_estimate_ms(0),
644 audio_level(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000645 expand_rate(0),
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000646 speech_expand_rate(0),
647 secondary_decoded_rate(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200648 accelerate_rate(0),
649 preemptive_expand_rate(0),
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000650 decoding_calls_to_silence_generator(0),
651 decoding_calls_to_neteq(0),
652 decoding_normal(0),
653 decoding_plc(0),
654 decoding_cng(0),
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000655 decoding_plc_cng(0),
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200656 capture_start_ntp_time_ms(-1) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000658 int ext_seqnum;
659 int jitter_ms;
660 int jitter_buffer_ms;
661 int jitter_buffer_preferred_ms;
662 int delay_estimate_ms;
663 int audio_level;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000664 // fraction of synthesized audio inserted through expansion.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665 float expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000666 // fraction of synthesized speech inserted through expansion.
667 float speech_expand_rate;
668 // fraction of data out of secondary decoding, including FEC and RED.
669 float secondary_decoded_rate;
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200670 // Fraction of data removed through time compression.
671 float accelerate_rate;
672 // Fraction of data inserted through time stretching.
673 float preemptive_expand_rate;
henrike@webrtc.orgb8c254a2014-02-14 23:38:45 +0000674 int decoding_calls_to_silence_generator;
675 int decoding_calls_to_neteq;
676 int decoding_normal;
677 int decoding_plc;
678 int decoding_cng;
679 int decoding_plc_cng;
buildbot@webrtc.orgb525a9d2014-06-03 09:42:15 +0000680 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200681 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682};
683
wu@webrtc.org97077a32013-10-25 21:18:33 +0000684struct VideoSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 VideoSenderInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000686 : packets_cached(0),
687 firs_rcvd(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000688 plis_rcvd(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689 nacks_rcvd(0),
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000690 input_frame_width(0),
691 input_frame_height(0),
692 send_frame_width(0),
693 send_frame_height(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 framerate_input(0),
695 framerate_sent(0),
696 nominal_bitrate(0),
697 preferred_bitrate(0),
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000698 adapt_reason(0),
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000699 adapt_changes(0),
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000700 avg_encode_ms(0),
Peter Boström8ed6a4b2015-03-27 10:01:02 +0100701 encode_usage_percent(0) {
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000702 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000704 std::vector<SsrcGroup> ssrc_groups;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100705 std::string encoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000706 int packets_cached;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 int firs_rcvd;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000708 int plis_rcvd;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 int nacks_rcvd;
wu@webrtc.org987f2c92014-03-28 16:22:19 +0000710 int input_frame_width;
711 int input_frame_height;
712 int send_frame_width;
713 int send_frame_height;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 int framerate_input;
715 int framerate_sent;
716 int nominal_bitrate;
717 int preferred_bitrate;
718 int adapt_reason;
buildbot@webrtc.org71dffb72014-06-24 07:24:49 +0000719 int adapt_changes;
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000720 int avg_encode_ms;
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000721 int encode_usage_percent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000722 VariableInfo<int> adapt_frame_drops;
723 VariableInfo<int> effects_frame_drops;
724 VariableInfo<double> capturer_frame_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725};
726
wu@webrtc.org97077a32013-10-25 21:18:33 +0000727struct VideoReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 VideoReceiverInfo()
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000729 : packets_concealed(0),
730 firs_sent(0),
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000731 plis_sent(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 nacks_sent(0),
733 frame_width(0),
734 frame_height(0),
735 framerate_rcvd(0),
736 framerate_decoded(0),
737 framerate_output(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000738 framerate_render_input(0),
739 framerate_render_output(0),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000740 decode_ms(0),
741 max_decode_ms(0),
742 jitter_buffer_ms(0),
743 min_playout_delay_ms(0),
744 render_delay_ms(0),
745 target_delay_ms(0),
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000746 current_delay_ms(0),
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000747 capture_start_ntp_time_ms(-1) {
748 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000750 std::vector<SsrcGroup> ssrc_groups;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100751 std::string decoder_implementation_name;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000752 int packets_concealed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 int firs_sent;
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000754 int plis_sent;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 int nacks_sent;
756 int frame_width;
757 int frame_height;
758 int framerate_rcvd;
759 int framerate_decoded;
760 int framerate_output;
pbos@webrtc.org1ed62242015-02-19 13:57:03 +0000761 // Framerate as sent to the renderer.
762 int framerate_render_input;
763 // Framerate that the renderer reports.
764 int framerate_render_output;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000765
766 // All stats below are gathered per-VideoReceiver, but some will be correlated
767 // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC
768 // structures, reflect this in the new layout.
769
770 // Current frame decode latency.
771 int decode_ms;
772 // Maximum observed frame decode latency.
773 int max_decode_ms;
774 // Jitter (network-related) latency.
775 int jitter_buffer_ms;
776 // Requested minimum playout latency.
777 int min_playout_delay_ms;
778 // Requested latency to account for rendering delay.
779 int render_delay_ms;
780 // Target overall delay: network+decode+render, accounting for
781 // min_playout_delay_ms.
782 int target_delay_ms;
783 // Current overall delay, possibly ramping towards target_delay_ms.
784 int current_delay_ms;
buildbot@webrtc.org0581f0b2014-05-06 21:36:31 +0000785
786 // Estimated capture start time in NTP time in ms.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200787 int64_t capture_start_ntp_time_ms;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788};
789
wu@webrtc.org97077a32013-10-25 21:18:33 +0000790struct DataSenderInfo : public MediaSenderInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 DataSenderInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000792 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 }
794
Peter Boström0c4e06b2015-10-07 12:23:21 +0200795 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796};
797
wu@webrtc.org97077a32013-10-25 21:18:33 +0000798struct DataReceiverInfo : public MediaReceiverInfo {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 DataReceiverInfo()
wu@webrtc.org97077a32013-10-25 21:18:33 +0000800 : ssrc(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 }
802
Peter Boström0c4e06b2015-10-07 12:23:21 +0200803 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804};
805
806struct BandwidthEstimationInfo {
807 BandwidthEstimationInfo()
808 : available_send_bandwidth(0),
809 available_recv_bandwidth(0),
810 target_enc_bitrate(0),
811 actual_enc_bitrate(0),
812 retransmit_bitrate(0),
813 transmit_bitrate(0),
pbos@webrtc.org058b1f12015-03-04 08:54:32 +0000814 bucket_delay(0) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 }
816
817 int available_send_bandwidth;
818 int available_recv_bandwidth;
819 int target_enc_bitrate;
820 int actual_enc_bitrate;
821 int retransmit_bitrate;
822 int transmit_bitrate;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000823 int64_t bucket_delay;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824};
825
826struct VoiceMediaInfo {
827 void Clear() {
828 senders.clear();
829 receivers.clear();
830 }
831 std::vector<VoiceSenderInfo> senders;
832 std::vector<VoiceReceiverInfo> receivers;
833};
834
835struct VideoMediaInfo {
836 void Clear() {
837 senders.clear();
838 receivers.clear();
839 bw_estimations.clear();
840 }
841 std::vector<VideoSenderInfo> senders;
842 std::vector<VideoReceiverInfo> receivers;
843 std::vector<BandwidthEstimationInfo> bw_estimations;
844};
845
846struct DataMediaInfo {
847 void Clear() {
848 senders.clear();
849 receivers.clear();
850 }
851 std::vector<DataSenderInfo> senders;
852 std::vector<DataReceiverInfo> receivers;
853};
854
deadbeef13871492015-12-09 12:37:51 -0800855struct RtcpParameters {
856 bool reduced_size = false;
857};
858
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700859template <class Codec>
860struct RtpParameters {
solenberg7e4e01a2015-12-02 08:05:01 -0800861 virtual std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700862 std::ostringstream ost;
863 ost << "{";
864 ost << "codecs: " << VectorToString(codecs) << ", ";
865 ost << "extensions: " << VectorToString(extensions);
866 ost << "}";
867 return ost.str();
868 }
869
870 std::vector<Codec> codecs;
871 std::vector<RtpHeaderExtension> extensions;
872 // TODO(pthatcher): Add streams.
deadbeef13871492015-12-09 12:37:51 -0800873 RtcpParameters rtcp;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700874};
875
876template <class Codec, class Options>
877struct RtpSendParameters : RtpParameters<Codec> {
solenberg7e4e01a2015-12-02 08:05:01 -0800878 std::string ToString() const override {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700879 std::ostringstream ost;
880 ost << "{";
881 ost << "codecs: " << VectorToString(this->codecs) << ", ";
882 ost << "extensions: " << VectorToString(this->extensions) << ", ";
pbos378dc772016-01-28 15:58:41 -0800883 ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700884 ost << "options: " << options.ToString();
885 ost << "}";
886 return ost.str();
887 }
888
889 int max_bandwidth_bps = -1;
890 Options options;
891};
892
893struct AudioSendParameters : RtpSendParameters<AudioCodec, AudioOptions> {
894};
895
896struct AudioRecvParameters : RtpParameters<AudioCodec> {
897};
898
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899class VoiceMediaChannel : public MediaChannel {
900 public:
901 enum Error {
902 ERROR_NONE = 0, // No error.
903 ERROR_OTHER, // Other errors.
904 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open mic.
905 ERROR_REC_DEVICE_MUTED, // Mic was muted by OS.
906 ERROR_REC_DEVICE_SILENT, // No background noise picked up.
907 ERROR_REC_DEVICE_SATURATION, // Mic input is clipping.
908 ERROR_REC_DEVICE_REMOVED, // Mic was removed while active.
909 ERROR_REC_RUNTIME_ERROR, // Processing is encountering errors.
910 ERROR_REC_SRTP_ERROR, // Generic SRTP failure.
911 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
912 ERROR_REC_TYPING_NOISE_DETECTED, // Typing noise is detected.
913 ERROR_PLAY_DEVICE_OPEN_FAILED = 200, // Could not open playout.
914 ERROR_PLAY_DEVICE_MUTED, // Playout muted by OS.
915 ERROR_PLAY_DEVICE_REMOVED, // Playout removed while active.
916 ERROR_PLAY_RUNTIME_ERROR, // Errors in voice processing.
917 ERROR_PLAY_SRTP_ERROR, // Generic SRTP failure.
918 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
919 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
920 };
921
922 VoiceMediaChannel() {}
923 virtual ~VoiceMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200924 virtual bool SetSendParameters(const AudioSendParameters& params) = 0;
925 virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 // Starts or stops playout of received audio.
927 virtual bool SetPlayout(bool playout) = 0;
928 // Starts or stops sending (and potentially capture) of local audio.
929 virtual bool SetSend(SendFlags flag) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700930 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200931 virtual bool SetAudioSend(uint32_t ssrc,
932 bool enable,
solenbergdfc8f4f2015-10-01 02:31:10 -0700933 const AudioOptions* options,
solenberg1dd98f32015-09-10 01:57:14 -0700934 AudioRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 // Gets current energy levels for all incoming streams.
936 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) = 0;
937 // Get the current energy level of the stream sent to the speaker.
938 virtual int GetOutputLevel() = 0;
939 // Get the time in milliseconds since last recorded keystroke, or negative.
940 virtual int GetTimeSinceLastTyping() = 0;
941 // Temporarily exposed field for tuning typing detect options.
942 virtual void SetTypingDetectionParameters(int time_window,
943 int cost_per_typing, int reporting_threshold, int penalty_decay,
944 int type_event_delay) = 0;
solenberg4bac9c52015-10-09 02:32:53 -0700945 // Set speaker output volume of the specified ssrc.
946 virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 // Returns if the telephone-event has been negotiated.
solenberg1d63dd02015-12-02 12:35:09 -0800948 virtual bool CanInsertDtmf() = 0;
949 // Send a DTMF |event|. The DTMF out-of-band signal will be used.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 // The |ssrc| should be either 0 or a valid send stream ssrc.
henrike@webrtc.org9de257d2013-07-17 14:42:53 +0000951 // The valid value for the |event| are 0 to 15 which corresponding to
952 // DTMF event 0-9, *, #, A-D.
solenberg1d63dd02015-12-02 12:35:09 -0800953 virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 // Gets quality stats for the channel.
955 virtual bool GetStats(VoiceMediaInfo* info) = 0;
Tommif888bb52015-12-12 01:37:01 +0100956
957 virtual void SetRawAudioSink(
958 uint32_t ssrc,
deadbeef2d110be2016-01-13 12:00:26 -0800959 rtc::scoped_ptr<webrtc::AudioSinkInterface> sink) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960};
961
Peter Thatcherc2ee2c82015-08-07 16:05:34 -0700962struct VideoSendParameters : RtpSendParameters<VideoCodec, VideoOptions> {
963};
964
965struct VideoRecvParameters : RtpParameters<VideoCodec> {
966};
967
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968class VideoMediaChannel : public MediaChannel {
969 public:
970 enum Error {
971 ERROR_NONE = 0, // No error.
972 ERROR_OTHER, // Other errors.
973 ERROR_REC_DEVICE_OPEN_FAILED = 100, // Could not open camera.
974 ERROR_REC_DEVICE_NO_DEVICE, // No camera.
975 ERROR_REC_DEVICE_IN_USE, // Device is in already use.
976 ERROR_REC_DEVICE_REMOVED, // Device is removed.
977 ERROR_REC_SRTP_ERROR, // Generic sender SRTP failure.
978 ERROR_REC_SRTP_AUTH_FAILED, // Failed to authenticate packets.
979 ERROR_REC_CPU_MAX_CANT_DOWNGRADE, // Can't downgrade capture anymore.
980 ERROR_PLAY_SRTP_ERROR = 200, // Generic receiver SRTP failure.
981 ERROR_PLAY_SRTP_AUTH_FAILED, // Failed to authenticate packets.
982 ERROR_PLAY_SRTP_REPLAY, // Packet replay detected.
983 };
984
985 VideoMediaChannel() : renderer_(NULL) {}
986 virtual ~VideoMediaChannel() {}
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200987
988 virtual bool SetSendParameters(const VideoSendParameters& params) = 0;
989 virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 // Gets the currently set codecs/payload types to be used for outgoing media.
991 virtual bool GetSendCodec(VideoCodec* send_codec) = 0;
992 // Sets the format of a specified outgoing stream.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200993 virtual bool SetSendStreamFormat(uint32_t ssrc,
994 const VideoFormat& format) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 // Starts or stops transmission (and potentially capture) of local video.
996 virtual bool SetSend(bool send) = 0;
solenberg1dd98f32015-09-10 01:57:14 -0700997 // Configure stream for sending.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200998 virtual bool SetVideoSend(uint32_t ssrc,
999 bool enable,
solenberg1dd98f32015-09-10 01:57:14 -07001000 const VideoOptions* options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 // Sets the renderer object to be used for the specified stream.
1002 // If SSRC is 0, the renderer is used for the 'default' stream.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001003 virtual bool SetRenderer(uint32_t ssrc, VideoRenderer* renderer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 // If |ssrc| is 0, replace the default capturer (engine capturer) with
1005 // |capturer|. If |ssrc| is non zero create a new stream with |ssrc| as SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001006 virtual bool SetCapturer(uint32_t ssrc, VideoCapturer* capturer) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 // Gets quality stats for the channel.
pbos@webrtc.org058b1f12015-03-04 08:54:32 +00001008 virtual bool GetStats(VideoMediaInfo* info) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 // Send an intra frame to the receivers.
1010 virtual bool SendIntraFrame() = 0;
1011 // Reuqest each of the remote senders to send an intra frame.
1012 virtual bool RequestIntraFrame() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) = 0;
1014
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 protected:
1016 VideoRenderer *renderer_;
1017};
1018
1019enum DataMessageType {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00001020 // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
1021 // values.
1022 DMT_NONE = 0,
1023 DMT_CONTROL = 1,
1024 DMT_BINARY = 2,
1025 DMT_TEXT = 3,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026};
1027
1028// Info about data received in DataMediaChannel. For use in
1029// DataMediaChannel::SignalDataReceived and in all of the signals that
1030// signal fires, on up the chain.
1031struct ReceiveDataParams {
1032 // The in-packet stream indentifier.
1033 // For SCTP, this is really SID, not SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001034 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035 // The type of message (binary, text, or control).
1036 DataMessageType type;
1037 // A per-stream value incremented per packet in the stream.
1038 int seq_num;
1039 // A per-stream value monotonically increasing with time.
1040 int timestamp;
1041
1042 ReceiveDataParams() :
1043 ssrc(0),
1044 type(DMT_TEXT),
1045 seq_num(0),
1046 timestamp(0) {
1047 }
1048};
1049
1050struct SendDataParams {
1051 // The in-packet stream indentifier.
1052 // For SCTP, this is really SID, not SSRC.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001053 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001054 // The type of message (binary, text, or control).
1055 DataMessageType type;
1056
1057 // For SCTP, whether to send messages flagged as ordered or not.
1058 // If false, messages can be received out of order.
1059 bool ordered;
1060 // For SCTP, whether the messages are sent reliably or not.
1061 // If false, messages may be lost.
1062 bool reliable;
1063 // For SCTP, if reliable == false, provide partial reliability by
1064 // resending up to this many times. Either count or millis
1065 // is supported, not both at the same time.
1066 int max_rtx_count;
1067 // For SCTP, if reliable == false, provide partial reliability by
1068 // resending for up to this many milliseconds. Either count or millis
1069 // is supported, not both at the same time.
1070 int max_rtx_ms;
1071
1072 SendDataParams() :
1073 ssrc(0),
1074 type(DMT_TEXT),
1075 // TODO(pthatcher): Make these true by default?
1076 ordered(false),
1077 reliable(false),
1078 max_rtx_count(0),
1079 max_rtx_ms(0) {
1080 }
1081};
1082
1083enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
1084
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001085struct DataOptions {
solenberg7e4e01a2015-12-02 08:05:01 -08001086 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001087 return "{}";
1088 }
1089};
1090
1091struct DataSendParameters : RtpSendParameters<DataCodec, DataOptions> {
solenberg7e4e01a2015-12-02 08:05:01 -08001092 std::string ToString() const {
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001093 std::ostringstream ost;
1094 // Options and extensions aren't used.
1095 ost << "{";
1096 ost << "codecs: " << VectorToString(codecs) << ", ";
pbos378dc772016-01-28 15:58:41 -08001097 ost << "max_bandwidth_bps: " << max_bandwidth_bps;
Peter Thatcherc2ee2c82015-08-07 16:05:34 -07001098 ost << "}";
1099 return ost.str();
1100 }
1101};
1102
1103struct DataRecvParameters : RtpParameters<DataCodec> {
1104};
1105
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106class DataMediaChannel : public MediaChannel {
1107 public:
1108 enum Error {
1109 ERROR_NONE = 0, // No error.
1110 ERROR_OTHER, // Other errors.
1111 ERROR_SEND_SRTP_ERROR = 200, // Generic SRTP failure.
1112 ERROR_SEND_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1113 ERROR_RECV_SRTP_ERROR, // Generic SRTP failure.
1114 ERROR_RECV_SRTP_AUTH_FAILED, // Failed to authenticate packets.
1115 ERROR_RECV_SRTP_REPLAY, // Packet replay detected.
1116 };
1117
1118 virtual ~DataMediaChannel() {}
1119
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001120 virtual bool SetSendParameters(const DataSendParameters& params) = 0;
1121 virtual bool SetRecvParameters(const DataRecvParameters& params) = 0;
wu@webrtc.orga9890802013-12-13 00:21:03 +00001122
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001123 // TODO(pthatcher): Implement this.
1124 virtual bool GetStats(DataMediaInfo* info) { return true; }
1125
1126 virtual bool SetSend(bool send) = 0;
1127 virtual bool SetReceive(bool receive) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128
1129 virtual bool SendData(
1130 const SendDataParams& params,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001131 const rtc::Buffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132 SendDataResult* result = NULL) = 0;
1133 // Signals when data is received (params, data, len)
1134 sigslot::signal3<const ReceiveDataParams&,
1135 const char*,
1136 size_t> SignalDataReceived;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +00001137 // Signal when the media channel is ready to send the stream. Arguments are:
1138 // writable(bool)
1139 sigslot::signal1<bool> SignalReadyToSend;
buildbot@webrtc.org1d66be22014-05-29 22:54:24 +00001140 // Signal for notifying that the remote side has closed the DataChannel.
Peter Boström0c4e06b2015-10-07 12:23:21 +02001141 sigslot::signal1<uint32_t> SignalStreamClosedRemotely;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142};
1143
1144} // namespace cricket
1145
1146#endif // TALK_MEDIA_BASE_MEDIACHANNEL_H_