henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 4 | * 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef MEDIA_BASE_MEDIA_CHANNEL_H_ |
| 12 | #define MEDIA_BASE_MEDIA_CHANNEL_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
Steve Anton | e78bcb9 | 2017-10-31 09:53:08 -0700 | [diff] [blame] | 14 | #include <map> |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 15 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 16 | #include <string> |
Patrik Höglund | aba85d1 | 2017-11-28 15:46:08 +0100 | [diff] [blame] | 17 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 20 | #include "absl/types/optional.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "api/audio_codecs/audio_encoder.h" |
Niels Möller | a6fe261 | 2018-01-19 11:28:54 +0100 | [diff] [blame] | 22 | #include "api/audio_options.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #include "api/crypto/frame_decryptor_interface.h" |
| 24 | #include "api/crypto/frame_encryptor_interface.h" |
Anton Sukhanov | 98a462c | 2018-10-17 13:15:42 -0700 | [diff] [blame] | 25 | #include "api/media_transport_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 26 | #include "api/rtc_error.h" |
| 27 | #include "api/rtp_parameters.h" |
| 28 | #include "api/rtp_receiver_interface.h" |
Patrik Höglund | 3e11343 | 2017-12-15 14:40:10 +0100 | [diff] [blame] | 29 | #include "api/video/video_content_type.h" |
Niels Möller | c6ce9c5 | 2018-05-11 11:15:30 +0200 | [diff] [blame] | 30 | #include "api/video/video_sink_interface.h" |
Niels Möller | 0327c2d | 2018-05-21 14:09:31 +0200 | [diff] [blame] | 31 | #include "api/video/video_source_interface.h" |
| 32 | #include "api/video/video_timing.h" |
| 33 | #include "api/video_codecs/video_encoder_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 34 | #include "media/base/codec.h" |
Ruslan Burakov | 493a650 | 2019-02-27 15:32:48 +0100 | [diff] [blame] | 35 | #include "media/base/delayable.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 36 | #include "media/base/media_config.h" |
| 37 | #include "media/base/media_constants.h" |
| 38 | #include "media/base/stream_params.h" |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 39 | #include "modules/audio_processing/include/audio_processing_statistics.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 40 | #include "rtc_base/async_packet_socket.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 41 | #include "rtc_base/buffer.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 42 | #include "rtc_base/copy_on_write_buffer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 43 | #include "rtc_base/dscp.h" |
| 44 | #include "rtc_base/logging.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 45 | #include "rtc_base/network_route.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 46 | #include "rtc_base/socket.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 47 | #include "rtc_base/string_encode.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 48 | #include "rtc_base/strings/string_builder.h" |
Artem Titov | e41c433 | 2018-07-25 15:04:28 +0200 | [diff] [blame] | 49 | #include "rtc_base/third_party/sigslot/sigslot.h" |
Patrik Höglund | aba85d1 | 2017-11-28 15:46:08 +0100 | [diff] [blame] | 50 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 51 | namespace rtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 52 | class Timing; |
| 53 | } |
| 54 | |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 55 | namespace webrtc { |
| 56 | class AudioSinkInterface; |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 57 | class VideoFrame; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 58 | } // namespace webrtc |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 59 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | namespace cricket { |
| 61 | |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 62 | class AudioSource; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | class VideoCapturer; |
tommi | 1d5c19d | 2015-12-13 22:54:29 -0800 | [diff] [blame] | 64 | struct RtpHeader; |
| 65 | struct VideoFormat; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | const int kScreencastDefaultFps = 5; |
| 68 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 69 | template <class T> |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 70 | static std::string ToStringIfSet(const char* key, |
| 71 | const absl::optional<T>& val) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | std::string str; |
kwiberg | 102c6a6 | 2015-10-30 02:47:38 -0700 | [diff] [blame] | 73 | if (val) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | str = key; |
| 75 | str += ": "; |
kwiberg | 102c6a6 | 2015-10-30 02:47:38 -0700 | [diff] [blame] | 76 | str += val ? rtc::ToString(*val) : ""; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 77 | str += ", "; |
| 78 | } |
| 79 | return str; |
| 80 | } |
| 81 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 82 | template <class T> |
| 83 | static std::string VectorToString(const std::vector<T>& vals) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 84 | rtc::StringBuilder ost; // no-presubmit-check TODO(webrtc:8982) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 85 | ost << "["; |
| 86 | for (size_t i = 0; i < vals.size(); ++i) { |
| 87 | if (i > 0) { |
| 88 | ost << ", "; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 89 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 90 | ost << vals[i].ToString(); |
| 91 | } |
| 92 | ost << "]"; |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 93 | return ost.Release(); |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 94 | } |
| 95 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | // Options that can be applied to a VideoMediaChannel or a VideoMediaEngine. |
| 97 | // Used to be flags, but that makes it hard to selectively apply options. |
| 98 | // We are moving all of the setting of options to structs like this, |
| 99 | // but some things currently still use flags. |
| 100 | struct VideoOptions { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 101 | VideoOptions(); |
| 102 | ~VideoOptions(); |
| 103 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 104 | void SetAll(const VideoOptions& change) { |
kwiberg | 102c6a6 | 2015-10-30 02:47:38 -0700 | [diff] [blame] | 105 | SetFrom(&video_noise_reduction, change.video_noise_reduction); |
nisse | b163c3f | 2016-01-29 01:14:38 -0800 | [diff] [blame] | 106 | SetFrom(&screencast_min_bitrate_kbps, change.screencast_min_bitrate_kbps); |
Niels Möller | 60653ba | 2016-03-02 11:41:36 +0100 | [diff] [blame] | 107 | SetFrom(&is_screencast, change.is_screencast); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | bool operator==(const VideoOptions& o) const { |
nisse | b163c3f | 2016-01-29 01:14:38 -0800 | [diff] [blame] | 111 | return video_noise_reduction == o.video_noise_reduction && |
Niels Möller | 60653ba | 2016-03-02 11:41:36 +0100 | [diff] [blame] | 112 | screencast_min_bitrate_kbps == o.screencast_min_bitrate_kbps && |
| 113 | is_screencast == o.is_screencast; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | } |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 115 | bool operator!=(const VideoOptions& o) const { return !(*this == o); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | |
| 117 | std::string ToString() const { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 118 | rtc::StringBuilder ost; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 119 | ost << "VideoOptions {"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 120 | ost << ToStringIfSet("noise reduction", video_noise_reduction); |
nisse | b163c3f | 2016-01-29 01:14:38 -0800 | [diff] [blame] | 121 | ost << ToStringIfSet("screencast min bitrate kbps", |
| 122 | screencast_min_bitrate_kbps); |
Niels Möller | 60653ba | 2016-03-02 11:41:36 +0100 | [diff] [blame] | 123 | ost << ToStringIfSet("is_screencast ", is_screencast); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 124 | ost << "}"; |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 125 | return ost.Release(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 126 | } |
| 127 | |
nisse | b163c3f | 2016-01-29 01:14:38 -0800 | [diff] [blame] | 128 | // Enable denoising? This flag comes from the getUserMedia |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 129 | // constraint 'googNoiseReduction', and WebRtcVideoEngine passes it |
nisse | b163c3f | 2016-01-29 01:14:38 -0800 | [diff] [blame] | 130 | // on to the codec options. Disabled by default. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 131 | absl::optional<bool> video_noise_reduction; |
nisse | b163c3f | 2016-01-29 01:14:38 -0800 | [diff] [blame] | 132 | // Force screencast to use a minimum bitrate. This flag comes from |
| 133 | // the PeerConnection constraint 'googScreencastMinBitrate'. It is |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 134 | // copied to the encoder config by WebRtcVideoChannel. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 135 | absl::optional<int> screencast_min_bitrate_kbps; |
Niels Möller | 60653ba | 2016-03-02 11:41:36 +0100 | [diff] [blame] | 136 | // Set by screencast sources. Implies selection of encoding settings |
| 137 | // suitable for screencast. Most likely not the right way to do |
| 138 | // things, e.g., screencast of a text document and screencast of a |
| 139 | // youtube video have different needs. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 140 | absl::optional<bool> is_screencast; |
kwiberg | 102c6a6 | 2015-10-30 02:47:38 -0700 | [diff] [blame] | 141 | |
| 142 | private: |
| 143 | template <typename T> |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 144 | static void SetFrom(absl::optional<T>* s, const absl::optional<T>& o) { |
kwiberg | 102c6a6 | 2015-10-30 02:47:38 -0700 | [diff] [blame] | 145 | if (o) { |
| 146 | *s = o; |
| 147 | } |
| 148 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 149 | }; |
| 150 | |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 151 | // TODO(isheriff): Remove this once client usage is fixed to use RtpExtension. |
| 152 | struct RtpHeaderExtension { |
| 153 | RtpHeaderExtension() : id(0) {} |
| 154 | RtpHeaderExtension(const std::string& uri, int id) : uri(uri), id(id) {} |
| 155 | |
| 156 | std::string ToString() const { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 157 | rtc::StringBuilder ost; |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 158 | ost << "{"; |
| 159 | ost << "uri: " << uri; |
| 160 | ost << ", id: " << id; |
| 161 | ost << "}"; |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 162 | return ost.Release(); |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | std::string uri; |
| 166 | int id; |
| 167 | }; |
| 168 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 169 | class MediaChannel : public sigslot::has_slots<> { |
| 170 | public: |
| 171 | class NetworkInterface { |
| 172 | public: |
| 173 | enum SocketType { ST_RTP, ST_RTCP }; |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 174 | virtual bool SendPacket(rtc::CopyOnWriteBuffer* packet, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 175 | const rtc::PacketOptions& options) = 0; |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 176 | virtual bool SendRtcp(rtc::CopyOnWriteBuffer* packet, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 177 | const rtc::PacketOptions& options) = 0; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 178 | virtual int SetOption(SocketType type, |
| 179 | rtc::Socket::Option opt, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | int option) = 0; |
| 181 | virtual ~NetworkInterface() {} |
| 182 | }; |
| 183 | |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 184 | explicit MediaChannel(const MediaConfig& config); |
| 185 | MediaChannel(); |
| 186 | ~MediaChannel() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 187 | |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 188 | virtual cricket::MediaType media_type() const = 0; |
| 189 | |
Anton Sukhanov | 98a462c | 2018-10-17 13:15:42 -0700 | [diff] [blame] | 190 | // Sets the abstract interface class for sending RTP/RTCP data and |
| 191 | // interface for media transport (experimental). If media transport is |
| 192 | // provided, it should be used instead of RTP/RTCP. |
| 193 | // TODO(sukhanov): Currently media transport can co-exist with RTP/RTCP, but |
| 194 | // in the future we will refactor code to send all frames with media |
| 195 | // transport. |
| 196 | virtual void SetInterface(NetworkInterface* iface, |
| 197 | webrtc::MediaTransportInterface* media_transport); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 198 | // Called when a RTP packet is received. |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 199 | virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 200 | int64_t packet_time_us) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 201 | // Called when a RTCP packet is received. |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 202 | virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 203 | int64_t packet_time_us) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 204 | // Called when the socket's ability to send has changed. |
| 205 | virtual void OnReadyToSend(bool ready) = 0; |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 206 | // Called when the network route used for sending packets changed. |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 207 | virtual void OnNetworkRouteChanged( |
| 208 | const std::string& transport_name, |
| 209 | const rtc::NetworkRoute& network_route) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 210 | // Creates a new outgoing media stream with SSRCs and CNAME as described |
| 211 | // by sp. |
| 212 | virtual bool AddSendStream(const StreamParams& sp) = 0; |
| 213 | // Removes an outgoing media stream. |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 214 | // SSRC must be the first SSRC of the media stream if the stream uses |
| 215 | // multiple SSRCs. In the case of an ssrc of 0, the possibly cached |
| 216 | // StreamParams is removed. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 217 | virtual bool RemoveSendStream(uint32_t ssrc) = 0; |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 218 | // Creates a new incoming media stream with SSRCs, CNAME as described |
| 219 | // by sp. In the case of a sp without SSRCs, the unsignaled sp is cached |
| 220 | // to be used later for unsignaled streams received. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 221 | virtual bool AddRecvStream(const StreamParams& sp) = 0; |
| 222 | // Removes an incoming media stream. |
| 223 | // ssrc must be the first SSRC of the media stream if the stream uses |
| 224 | // multiple SSRCs. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 225 | virtual bool RemoveRecvStream(uint32_t ssrc) = 0; |
mallinath@webrtc.org | 92fdfeb | 2014-02-17 18:49:41 +0000 | [diff] [blame] | 226 | // Returns the absoulte sendtime extension id value from media channel. |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 227 | virtual int GetRtpSendTimeExtnId() const; |
Benjamin Wright | bfd412e | 2018-09-10 14:06:02 -0700 | [diff] [blame] | 228 | // Set the frame encryptor to use on all outgoing frames. This is optional. |
| 229 | // This pointers lifetime is managed by the set of RtpSender it is attached |
| 230 | // to. |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 231 | // TODO(benwright) make pure virtual once internal supports it. |
Benjamin Wright | bfd412e | 2018-09-10 14:06:02 -0700 | [diff] [blame] | 232 | virtual void SetFrameEncryptor( |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 233 | uint32_t ssrc, |
| 234 | rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor); |
Benjamin Wright | bfd412e | 2018-09-10 14:06:02 -0700 | [diff] [blame] | 235 | // Set the frame decryptor to use on all incoming frames. This is optional. |
| 236 | // This pointers lifetimes is managed by the set of RtpReceivers it is |
| 237 | // attached to. |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 238 | // TODO(benwright) make pure virtual once internal supports it. |
Benjamin Wright | bfd412e | 2018-09-10 14:06:02 -0700 | [diff] [blame] | 239 | virtual void SetFrameDecryptor( |
Benjamin Wright | 84583f6 | 2018-10-04 14:22:34 -0700 | [diff] [blame] | 240 | uint32_t ssrc, |
| 241 | rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 242 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 243 | // Base method to send packet using NetworkInterface. |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 244 | bool SendPacket(rtc::CopyOnWriteBuffer* packet, |
| 245 | const rtc::PacketOptions& options) { |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 246 | return DoSendPacket(packet, false, options); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 247 | } |
| 248 | |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 249 | bool SendRtcp(rtc::CopyOnWriteBuffer* packet, |
| 250 | const rtc::PacketOptions& options) { |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 251 | return DoSendPacket(packet, true, options); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | int SetOption(NetworkInterface::SocketType type, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 255 | rtc::Socket::Option opt, |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 256 | int option) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 257 | rtc::CritScope cs(&network_interface_crit_); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 258 | if (!network_interface_) |
| 259 | return -1; |
| 260 | |
| 261 | return network_interface_->SetOption(type, opt, option); |
| 262 | } |
| 263 | |
Anton Sukhanov | 98a462c | 2018-10-17 13:15:42 -0700 | [diff] [blame] | 264 | webrtc::MediaTransportInterface* media_transport() { |
| 265 | return media_transport_; |
| 266 | } |
| 267 | |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 268 | // Corresponds to the SDP attribute extmap-allow-mixed, see RFC8285. |
| 269 | // Set to true if it's allowed to mix one- and two-byte RTP header extensions |
| 270 | // in the same stream. The setter and getter must only be called from |
| 271 | // worker_thread. |
| 272 | void SetExtmapAllowMixed(bool extmap_allow_mixed) { |
| 273 | extmap_allow_mixed_ = extmap_allow_mixed; |
| 274 | } |
| 275 | bool ExtmapAllowMixed() const { return extmap_allow_mixed_; } |
| 276 | |
Amit Hilbuch | ea7ef2a | 2019-02-19 15:20:21 -0800 | [diff] [blame] | 277 | virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0; |
| 278 | virtual webrtc::RTCError SetRtpSendParameters( |
| 279 | uint32_t ssrc, |
| 280 | const webrtc::RtpParameters& parameters) = 0; |
| 281 | |
Tim Haloun | 6ca9836 | 2018-09-17 17:06:08 -0700 | [diff] [blame] | 282 | protected: |
Tim Haloun | 6ca9836 | 2018-09-17 17:06:08 -0700 | [diff] [blame] | 283 | bool DscpEnabled() const { return enable_dscp_; } |
| 284 | |
Steve Anton | e25f595 | 2019-03-08 15:09:16 -0800 | [diff] [blame] | 285 | // This is the DSCP value used for both RTP and RTCP channels if DSCP is |
| 286 | // enabled. It can be changed at any time via |SetPreferredDscp|. |
| 287 | rtc::DiffServCodePoint PreferredDscp() const { |
| 288 | rtc::CritScope cs(&network_interface_crit_); |
| 289 | return preferred_dscp_; |
| 290 | } |
| 291 | |
| 292 | int SetPreferredDscp(rtc::DiffServCodePoint preferred_dscp) { |
| 293 | rtc::CritScope cs(&network_interface_crit_); |
| 294 | if (preferred_dscp == preferred_dscp_) { |
| 295 | return 0; |
| 296 | } |
| 297 | preferred_dscp_ = preferred_dscp; |
| 298 | return UpdateDscp(); |
| 299 | } |
| 300 | |
| 301 | private: |
| 302 | // Apply the preferred DSCP setting to the underlying network interface RTP |
| 303 | // and RTCP channels. If DSCP is disabled, then apply the default DSCP value. |
| 304 | int UpdateDscp() RTC_EXCLUSIVE_LOCKS_REQUIRED(network_interface_crit_) { |
Tim Haloun | 648d28a | 2018-10-18 16:52:22 -0700 | [diff] [blame] | 305 | rtc::DiffServCodePoint value = |
Steve Anton | e25f595 | 2019-03-08 15:09:16 -0800 | [diff] [blame] | 306 | enable_dscp_ ? preferred_dscp_ : rtc::DSCP_DEFAULT; |
| 307 | int ret = SetOption(NetworkInterface::ST_RTP, rtc::Socket::OPT_DSCP, value); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 308 | if (ret == 0) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 309 | ret = SetOption(NetworkInterface::ST_RTCP, rtc::Socket::OPT_DSCP, value); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 310 | } |
| 311 | return ret; |
| 312 | } |
| 313 | |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 314 | bool DoSendPacket(rtc::CopyOnWriteBuffer* packet, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 315 | bool rtcp, |
| 316 | const rtc::PacketOptions& options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 317 | rtc::CritScope cs(&network_interface_crit_); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 318 | if (!network_interface_) |
| 319 | return false; |
| 320 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 321 | return (!rtcp) ? network_interface_->SendPacket(packet, options) |
| 322 | : network_interface_->SendRtcp(packet, options); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 323 | } |
| 324 | |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 325 | const bool enable_dscp_; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 326 | // |network_interface_| can be accessed from the worker_thread and |
| 327 | // from any MediaEngine threads. This critical section is to protect accessing |
| 328 | // of network_interface_ object. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 329 | rtc::CriticalSection network_interface_crit_; |
Steve Anton | e25f595 | 2019-03-08 15:09:16 -0800 | [diff] [blame] | 330 | NetworkInterface* network_interface_ RTC_GUARDED_BY(network_interface_crit_) = |
| 331 | nullptr; |
| 332 | rtc::DiffServCodePoint preferred_dscp_ |
| 333 | RTC_GUARDED_BY(network_interface_crit_) = rtc::DSCP_DEFAULT; |
Anton Sukhanov | 98a462c | 2018-10-17 13:15:42 -0700 | [diff] [blame] | 334 | webrtc::MediaTransportInterface* media_transport_ = nullptr; |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 335 | bool extmap_allow_mixed_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 336 | }; |
| 337 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 338 | // The stats information is structured as follows: |
| 339 | // Media are represented by either MediaSenderInfo or MediaReceiverInfo. |
| 340 | // Media contains a vector of SSRC infos that are exclusively used by this |
| 341 | // media. (SSRCs shared between media streams can't be represented.) |
| 342 | |
| 343 | // Information about an SSRC. |
| 344 | // This data may be locally recorded, or received in an RTCP SR or RR. |
| 345 | struct SsrcSenderInfo { |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 346 | uint32_t ssrc = 0; |
| 347 | double timestamp = 0.0; // NTP timestamp, represented as seconds since epoch. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 348 | }; |
| 349 | |
| 350 | struct SsrcReceiverInfo { |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 351 | uint32_t ssrc = 0; |
| 352 | double timestamp = 0.0; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 353 | }; |
| 354 | |
| 355 | struct MediaSenderInfo { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 356 | MediaSenderInfo(); |
| 357 | ~MediaSenderInfo(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 358 | void add_ssrc(const SsrcSenderInfo& stat) { local_stats.push_back(stat); } |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 359 | // Temporary utility function for call sites that only provide SSRC. |
| 360 | // As more info is added into SsrcSenderInfo, this function should go away. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 361 | void add_ssrc(uint32_t ssrc) { |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 362 | SsrcSenderInfo stat; |
| 363 | stat.ssrc = ssrc; |
| 364 | add_ssrc(stat); |
| 365 | } |
| 366 | // Utility accessor for clients that are only interested in ssrc numbers. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 367 | std::vector<uint32_t> ssrcs() const { |
| 368 | std::vector<uint32_t> retval; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 369 | for (std::vector<SsrcSenderInfo>::const_iterator it = local_stats.begin(); |
| 370 | it != local_stats.end(); ++it) { |
| 371 | retval.push_back(it->ssrc); |
| 372 | } |
| 373 | return retval; |
| 374 | } |
Harald Alvestrand | b8e1201 | 2018-01-23 15:28:16 +0100 | [diff] [blame] | 375 | // Returns true if the media has been connected. |
| 376 | bool connected() const { return local_stats.size() > 0; } |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 377 | // Utility accessor for clients that make the assumption only one ssrc |
| 378 | // exists per media. |
| 379 | // This will eventually go away. |
Harald Alvestrand | b8e1201 | 2018-01-23 15:28:16 +0100 | [diff] [blame] | 380 | // Call sites that compare this to zero should use connected() instead. |
| 381 | // https://bugs.webrtc.org/8694 |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 382 | uint32_t ssrc() const { |
Harald Alvestrand | b8e1201 | 2018-01-23 15:28:16 +0100 | [diff] [blame] | 383 | if (connected()) { |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 384 | return local_stats[0].ssrc; |
| 385 | } else { |
| 386 | return 0; |
| 387 | } |
| 388 | } |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 389 | int64_t bytes_sent = 0; |
| 390 | int packets_sent = 0; |
| 391 | int packets_lost = 0; |
| 392 | float fraction_lost = 0.0f; |
| 393 | int64_t rtt_ms = 0; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 394 | std::string codec_name; |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 395 | absl::optional<int> codec_payload_type; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 396 | std::vector<SsrcSenderInfo> local_stats; |
| 397 | std::vector<SsrcReceiverInfo> remote_stats; |
| 398 | }; |
| 399 | |
| 400 | struct MediaReceiverInfo { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 401 | MediaReceiverInfo(); |
| 402 | ~MediaReceiverInfo(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 403 | void add_ssrc(const SsrcReceiverInfo& stat) { local_stats.push_back(stat); } |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 404 | // Temporary utility function for call sites that only provide SSRC. |
| 405 | // As more info is added into SsrcSenderInfo, this function should go away. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 406 | void add_ssrc(uint32_t ssrc) { |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 407 | SsrcReceiverInfo stat; |
| 408 | stat.ssrc = ssrc; |
| 409 | add_ssrc(stat); |
| 410 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 411 | std::vector<uint32_t> ssrcs() const { |
| 412 | std::vector<uint32_t> retval; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 413 | for (std::vector<SsrcReceiverInfo>::const_iterator it = local_stats.begin(); |
| 414 | it != local_stats.end(); ++it) { |
| 415 | retval.push_back(it->ssrc); |
| 416 | } |
| 417 | return retval; |
| 418 | } |
Harald Alvestrand | b8e1201 | 2018-01-23 15:28:16 +0100 | [diff] [blame] | 419 | // Returns true if the media has been connected. |
| 420 | bool connected() const { return local_stats.size() > 0; } |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 421 | // Utility accessor for clients that make the assumption only one ssrc |
| 422 | // exists per media. |
| 423 | // This will eventually go away. |
Harald Alvestrand | b8e1201 | 2018-01-23 15:28:16 +0100 | [diff] [blame] | 424 | // Call sites that compare this to zero should use connected(); |
| 425 | // https://bugs.webrtc.org/8694 |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 426 | uint32_t ssrc() const { |
Harald Alvestrand | b8e1201 | 2018-01-23 15:28:16 +0100 | [diff] [blame] | 427 | if (connected()) { |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 428 | return local_stats[0].ssrc; |
| 429 | } else { |
| 430 | return 0; |
| 431 | } |
| 432 | } |
| 433 | |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 434 | int64_t bytes_rcvd = 0; |
| 435 | int packets_rcvd = 0; |
| 436 | int packets_lost = 0; |
| 437 | float fraction_lost = 0.0f; |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 438 | std::string codec_name; |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 439 | absl::optional<int> codec_payload_type; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 440 | std::vector<SsrcReceiverInfo> local_stats; |
| 441 | std::vector<SsrcSenderInfo> remote_stats; |
| 442 | }; |
| 443 | |
| 444 | struct VoiceSenderInfo : public MediaSenderInfo { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 445 | VoiceSenderInfo(); |
| 446 | ~VoiceSenderInfo(); |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 447 | int ext_seqnum = 0; |
| 448 | int jitter_ms = 0; |
| 449 | int audio_level = 0; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 450 | // See description of "totalAudioEnergy" in the WebRTC stats spec: |
| 451 | // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 452 | double total_input_energy = 0.0; |
| 453 | double total_input_duration = 0.0; |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 454 | bool typing_noise_detected = false; |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 455 | webrtc::ANAStats ana_statistics; |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 456 | webrtc::AudioProcessingStats apm_statistics; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 457 | }; |
| 458 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 459 | struct VoiceReceiverInfo : public MediaReceiverInfo { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 460 | VoiceReceiverInfo(); |
| 461 | ~VoiceReceiverInfo(); |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 462 | int ext_seqnum = 0; |
| 463 | int jitter_ms = 0; |
| 464 | int jitter_buffer_ms = 0; |
| 465 | int jitter_buffer_preferred_ms = 0; |
| 466 | int delay_estimate_ms = 0; |
| 467 | int audio_level = 0; |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 468 | // Stats below correspond to similarly-named fields in the WebRTC stats spec. |
| 469 | // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 470 | double total_output_energy = 0.0; |
| 471 | uint64_t total_samples_received = 0; |
| 472 | double total_output_duration = 0.0; |
| 473 | uint64_t concealed_samples = 0; |
| 474 | uint64_t concealment_events = 0; |
Chen Xing | 0acffb5 | 2019-01-15 15:46:29 +0100 | [diff] [blame] | 475 | double jitter_buffer_delay_seconds = 0.0; |
| 476 | uint64_t jitter_buffer_emitted_count = 0; |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 477 | // Stats below DO NOT correspond directly to anything in the WebRTC stats |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 478 | // fraction of synthesized audio inserted through expansion. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 479 | float expand_rate = 0.0f; |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 480 | // fraction of synthesized speech inserted through expansion. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 481 | float speech_expand_rate = 0.0f; |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 482 | // fraction of data out of secondary decoding, including FEC and RED. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 483 | float secondary_decoded_rate = 0.0f; |
minyue-webrtc | 0e320ec | 2017-08-28 13:51:27 +0200 | [diff] [blame] | 484 | // Fraction of secondary data, including FEC and RED, that is discarded. |
| 485 | // Discarding of secondary data can be caused by the reception of the primary |
| 486 | // data, obsoleting the secondary data. It can also be caused by early |
| 487 | // or late arrival of secondary data. This metric is the percentage of |
| 488 | // discarded secondary data since last query of receiver info. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 489 | float secondary_discarded_rate = 0.0f; |
Henrik Lundin | 8e6fd46 | 2015-06-02 09:24:52 +0200 | [diff] [blame] | 490 | // Fraction of data removed through time compression. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 491 | float accelerate_rate = 0.0f; |
Henrik Lundin | 8e6fd46 | 2015-06-02 09:24:52 +0200 | [diff] [blame] | 492 | // Fraction of data inserted through time stretching. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 493 | float preemptive_expand_rate = 0.0f; |
| 494 | int decoding_calls_to_silence_generator = 0; |
| 495 | int decoding_calls_to_neteq = 0; |
| 496 | int decoding_normal = 0; |
| 497 | int decoding_plc = 0; |
| 498 | int decoding_cng = 0; |
| 499 | int decoding_plc_cng = 0; |
| 500 | int decoding_muted_output = 0; |
buildbot@webrtc.org | b525a9d | 2014-06-03 09:42:15 +0000 | [diff] [blame] | 501 | // Estimated capture start time in NTP time in ms. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 502 | int64_t capture_start_ntp_time_ms = -1; |
Ruslan Burakov | 8af8896 | 2018-11-22 17:21:10 +0100 | [diff] [blame] | 503 | // Count of the number of buffer flushes. |
| 504 | uint64_t jitter_buffer_flushes = 0; |
Jakob Ivarsson | 352ce5c | 2018-11-27 12:52:16 +0100 | [diff] [blame] | 505 | // Number of samples expanded due to delayed packets. |
| 506 | uint64_t delayed_packet_outage_samples = 0; |
Jakob Ivarsson | 232b3fd | 2019-03-06 09:18:40 +0100 | [diff] [blame] | 507 | // Arrival delay of received audio packets. |
| 508 | double relative_packet_arrival_delay_seconds = 0.0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 509 | }; |
| 510 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 511 | struct VideoSenderInfo : public MediaSenderInfo { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 512 | VideoSenderInfo(); |
| 513 | ~VideoSenderInfo(); |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 514 | std::vector<SsrcGroup> ssrc_groups; |
hbos | a65704b | 2016-11-14 02:28:16 -0800 | [diff] [blame] | 515 | // TODO(hbos): Move this to |VideoMediaInfo::send_codecs|? |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 516 | std::string encoder_implementation_name; |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 517 | int firs_rcvd = 0; |
| 518 | int plis_rcvd = 0; |
| 519 | int nacks_rcvd = 0; |
| 520 | int send_frame_width = 0; |
| 521 | int send_frame_height = 0; |
| 522 | int framerate_input = 0; |
| 523 | int framerate_sent = 0; |
| 524 | int nominal_bitrate = 0; |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 525 | int adapt_reason = 0; |
| 526 | int adapt_changes = 0; |
| 527 | int avg_encode_ms = 0; |
| 528 | int encode_usage_percent = 0; |
| 529 | uint32_t frames_encoded = 0; |
| 530 | bool has_entered_low_resolution = false; |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 531 | absl::optional<uint64_t> qp_sum; |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 532 | webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED; |
Ilya Nikolaevskiy | 70473fc | 2018-02-28 16:35:03 +0100 | [diff] [blame] | 533 | // https://w3c.github.io/webrtc-stats/#dom-rtcvideosenderstats-hugeframessent |
| 534 | uint32_t huge_frames_sent = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 535 | }; |
| 536 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 537 | struct VideoReceiverInfo : public MediaReceiverInfo { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 538 | VideoReceiverInfo(); |
| 539 | ~VideoReceiverInfo(); |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 540 | std::vector<SsrcGroup> ssrc_groups; |
hbos | a65704b | 2016-11-14 02:28:16 -0800 | [diff] [blame] | 541 | // TODO(hbos): Move this to |VideoMediaInfo::receive_codecs|? |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 542 | std::string decoder_implementation_name; |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 543 | int packets_concealed = 0; |
| 544 | int firs_sent = 0; |
| 545 | int plis_sent = 0; |
| 546 | int nacks_sent = 0; |
| 547 | int frame_width = 0; |
| 548 | int frame_height = 0; |
| 549 | int framerate_rcvd = 0; |
| 550 | int framerate_decoded = 0; |
| 551 | int framerate_output = 0; |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 552 | // Framerate as sent to the renderer. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 553 | int framerate_render_input = 0; |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 554 | // Framerate that the renderer reports. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 555 | int framerate_render_output = 0; |
| 556 | uint32_t frames_received = 0; |
| 557 | uint32_t frames_decoded = 0; |
| 558 | uint32_t frames_rendered = 0; |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 559 | absl::optional<uint64_t> qp_sum; |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 560 | int64_t interframe_delay_max_ms = -1; |
Sergey Silkin | 0237106 | 2019-01-31 16:45:42 +0100 | [diff] [blame] | 561 | uint32_t freeze_count = 0; |
| 562 | uint32_t pause_count = 0; |
| 563 | uint32_t total_freezes_duration_ms = 0; |
| 564 | uint32_t total_pauses_duration_ms = 0; |
| 565 | uint32_t total_frames_duration_ms = 0; |
| 566 | double sum_squared_frame_durations = 0.0; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 567 | |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 568 | webrtc::VideoContentType content_type = webrtc::VideoContentType::UNSPECIFIED; |
ilnik | 2e1b40b | 2017-09-04 07:57:17 -0700 | [diff] [blame] | 569 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 570 | // All stats below are gathered per-VideoReceiver, but some will be correlated |
| 571 | // across MediaStreamTracks. NOTE(hta): when sinking stats into per-SSRC |
| 572 | // structures, reflect this in the new layout. |
| 573 | |
| 574 | // Current frame decode latency. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 575 | int decode_ms = 0; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 576 | // Maximum observed frame decode latency. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 577 | int max_decode_ms = 0; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 578 | // Jitter (network-related) latency. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 579 | int jitter_buffer_ms = 0; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 580 | // Requested minimum playout latency. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 581 | int min_playout_delay_ms = 0; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 582 | // Requested latency to account for rendering delay. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 583 | int render_delay_ms = 0; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 584 | // Target overall delay: network+decode+render, accounting for |
| 585 | // min_playout_delay_ms. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 586 | int target_delay_ms = 0; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 587 | // Current overall delay, possibly ramping towards target_delay_ms. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 588 | int current_delay_ms = 0; |
buildbot@webrtc.org | 0581f0b | 2014-05-06 21:36:31 +0000 | [diff] [blame] | 589 | |
| 590 | // Estimated capture start time in NTP time in ms. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 591 | int64_t capture_start_ntp_time_ms = -1; |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 592 | |
Benjamin Wright | 514f084 | 2018-12-10 09:55:17 -0800 | [diff] [blame] | 593 | // First frame received to first frame decoded latency. |
| 594 | int64_t first_frame_received_to_decoded_ms = -1; |
| 595 | |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 596 | // Timing frame info: all important timestamps for a full lifetime of a |
| 597 | // single 'timing frame'. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 598 | absl::optional<webrtc::TimingFrameInfo> timing_frame_info; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 599 | }; |
| 600 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 601 | struct DataSenderInfo : public MediaSenderInfo { |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 602 | uint32_t ssrc = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 603 | }; |
| 604 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 605 | struct DataReceiverInfo : public MediaReceiverInfo { |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 606 | uint32_t ssrc = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 607 | }; |
| 608 | |
| 609 | struct BandwidthEstimationInfo { |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 610 | int available_send_bandwidth = 0; |
| 611 | int available_recv_bandwidth = 0; |
| 612 | int target_enc_bitrate = 0; |
| 613 | int actual_enc_bitrate = 0; |
| 614 | int retransmit_bitrate = 0; |
| 615 | int transmit_bitrate = 0; |
| 616 | int64_t bucket_delay = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 617 | }; |
| 618 | |
hbos | a65704b | 2016-11-14 02:28:16 -0800 | [diff] [blame] | 619 | // Maps from payload type to |RtpCodecParameters|. |
| 620 | typedef std::map<int, webrtc::RtpCodecParameters> RtpCodecParametersMap; |
| 621 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 622 | struct VoiceMediaInfo { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 623 | VoiceMediaInfo(); |
| 624 | ~VoiceMediaInfo(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 625 | void Clear() { |
| 626 | senders.clear(); |
| 627 | receivers.clear(); |
hbos | 1acfbd2 | 2016-11-17 23:43:29 -0800 | [diff] [blame] | 628 | send_codecs.clear(); |
| 629 | receive_codecs.clear(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 630 | } |
| 631 | std::vector<VoiceSenderInfo> senders; |
| 632 | std::vector<VoiceReceiverInfo> receivers; |
hbos | 1acfbd2 | 2016-11-17 23:43:29 -0800 | [diff] [blame] | 633 | RtpCodecParametersMap send_codecs; |
| 634 | RtpCodecParametersMap receive_codecs; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 635 | }; |
| 636 | |
| 637 | struct VideoMediaInfo { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 638 | VideoMediaInfo(); |
| 639 | ~VideoMediaInfo(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 640 | void Clear() { |
| 641 | senders.clear(); |
| 642 | receivers.clear(); |
charujain | d72098a | 2017-06-01 08:54:47 -0700 | [diff] [blame] | 643 | bw_estimations.clear(); |
hbos | a65704b | 2016-11-14 02:28:16 -0800 | [diff] [blame] | 644 | send_codecs.clear(); |
| 645 | receive_codecs.clear(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 646 | } |
| 647 | std::vector<VideoSenderInfo> senders; |
| 648 | std::vector<VideoReceiverInfo> receivers; |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 649 | // Deprecated. |
| 650 | // TODO(holmer): Remove once upstream projects no longer use this. |
charujain | d72098a | 2017-06-01 08:54:47 -0700 | [diff] [blame] | 651 | std::vector<BandwidthEstimationInfo> bw_estimations; |
hbos | a65704b | 2016-11-14 02:28:16 -0800 | [diff] [blame] | 652 | RtpCodecParametersMap send_codecs; |
| 653 | RtpCodecParametersMap receive_codecs; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 654 | }; |
| 655 | |
| 656 | struct DataMediaInfo { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 657 | DataMediaInfo(); |
| 658 | ~DataMediaInfo(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 659 | void Clear() { |
| 660 | senders.clear(); |
| 661 | receivers.clear(); |
| 662 | } |
| 663 | std::vector<DataSenderInfo> senders; |
| 664 | std::vector<DataReceiverInfo> receivers; |
| 665 | }; |
| 666 | |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 667 | struct RtcpParameters { |
| 668 | bool reduced_size = false; |
| 669 | }; |
| 670 | |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 671 | template <class Codec> |
| 672 | struct RtpParameters { |
Steve Anton | 003930a | 2018-03-29 12:37:21 -0700 | [diff] [blame] | 673 | virtual ~RtpParameters() = default; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 674 | |
| 675 | std::vector<Codec> codecs; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 676 | std::vector<webrtc::RtpExtension> extensions; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 677 | // TODO(pthatcher): Add streams. |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 678 | RtcpParameters rtcp; |
Steve Anton | 003930a | 2018-03-29 12:37:21 -0700 | [diff] [blame] | 679 | |
| 680 | std::string ToString() const { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 681 | rtc::StringBuilder ost; |
Steve Anton | 003930a | 2018-03-29 12:37:21 -0700 | [diff] [blame] | 682 | ost << "{"; |
| 683 | const char* separator = ""; |
| 684 | for (const auto& entry : ToStringMap()) { |
| 685 | ost << separator << entry.first << ": " << entry.second; |
| 686 | separator = ", "; |
| 687 | } |
| 688 | ost << "}"; |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 689 | return ost.Release(); |
Steve Anton | 003930a | 2018-03-29 12:37:21 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | protected: |
| 693 | virtual std::map<std::string, std::string> ToStringMap() const { |
| 694 | return {{"codecs", VectorToString(codecs)}, |
| 695 | {"extensions", VectorToString(extensions)}}; |
| 696 | } |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 697 | }; |
| 698 | |
Taylor Brandstetter | 5f0b83b | 2016-03-18 15:02:07 -0700 | [diff] [blame] | 699 | // TODO(deadbeef): Rename to RtpSenderParameters, since they're intended to |
| 700 | // encapsulate all the parameters needed for an RtpSender. |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 701 | template <class Codec> |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 702 | struct RtpSendParameters : RtpParameters<Codec> { |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 703 | int max_bandwidth_bps = -1; |
Steve Anton | bb50ce5 | 2018-03-26 10:24:32 -0700 | [diff] [blame] | 704 | // This is the value to be sent in the MID RTP header extension (if the header |
| 705 | // extension in included in the list of extensions). |
| 706 | std::string mid; |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 707 | bool extmap_allow_mixed = false; |
Steve Anton | 003930a | 2018-03-29 12:37:21 -0700 | [diff] [blame] | 708 | |
| 709 | protected: |
| 710 | std::map<std::string, std::string> ToStringMap() const override { |
| 711 | auto params = RtpParameters<Codec>::ToStringMap(); |
| 712 | params["max_bandwidth_bps"] = rtc::ToString(max_bandwidth_bps); |
| 713 | params["mid"] = (mid.empty() ? "<not set>" : mid); |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 714 | params["extmap-allow-mixed"] = extmap_allow_mixed ? "true" : "false"; |
Steve Anton | 003930a | 2018-03-29 12:37:21 -0700 | [diff] [blame] | 715 | return params; |
| 716 | } |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 717 | }; |
| 718 | |
| 719 | struct AudioSendParameters : RtpSendParameters<AudioCodec> { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 720 | AudioSendParameters(); |
| 721 | ~AudioSendParameters() override; |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 722 | AudioOptions options; |
Steve Anton | 003930a | 2018-03-29 12:37:21 -0700 | [diff] [blame] | 723 | |
| 724 | protected: |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 725 | std::map<std::string, std::string> ToStringMap() const override; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 726 | }; |
| 727 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 728 | struct AudioRecvParameters : RtpParameters<AudioCodec> {}; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 729 | |
Ruslan Burakov | 493a650 | 2019-02-27 15:32:48 +0100 | [diff] [blame] | 730 | class VoiceMediaChannel : public MediaChannel, public Delayable { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 731 | public: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 732 | VoiceMediaChannel() {} |
terelius | 54f9171 | 2016-06-01 11:18:56 -0700 | [diff] [blame] | 733 | explicit VoiceMediaChannel(const MediaConfig& config) |
| 734 | : MediaChannel(config) {} |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 735 | ~VoiceMediaChannel() override {} |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 736 | |
| 737 | cricket::MediaType media_type() const override; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 738 | virtual bool SetSendParameters(const AudioSendParameters& params) = 0; |
| 739 | virtual bool SetRecvParameters(const AudioRecvParameters& params) = 0; |
deadbeef | 3bc1510 | 2017-04-20 19:25:07 -0700 | [diff] [blame] | 740 | // Get the receive parameters for the incoming stream identified by |ssrc|. |
| 741 | // If |ssrc| is 0, retrieve the receive parameters for the default receive |
| 742 | // stream, which is used when SSRCs are not signaled. Note that calling with |
| 743 | // an |ssrc| of 0 will return encoding parameters with an unset |ssrc| |
| 744 | // member. |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 745 | virtual webrtc::RtpParameters GetRtpReceiveParameters( |
| 746 | uint32_t ssrc) const = 0; |
| 747 | virtual bool SetRtpReceiveParameters( |
| 748 | uint32_t ssrc, |
| 749 | const webrtc::RtpParameters& parameters) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 750 | // Starts or stops playout of received audio. |
aleloi | 84ef615 | 2016-08-04 05:28:21 -0700 | [diff] [blame] | 751 | virtual void SetPlayout(bool playout) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 752 | // Starts or stops sending (and potentially capture) of local audio. |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 753 | virtual void SetSend(bool send) = 0; |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 754 | // Configure stream for sending. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 755 | virtual bool SetAudioSend(uint32_t ssrc, |
| 756 | bool enable, |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 757 | const AudioOptions* options, |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 758 | AudioSource* source) = 0; |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 759 | // Set speaker output volume of the specified ssrc. |
| 760 | virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 761 | // Returns if the telephone-event has been negotiated. |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 762 | virtual bool CanInsertDtmf() = 0; |
| 763 | // Send a DTMF |event|. The DTMF out-of-band signal will be used. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 764 | // The |ssrc| should be either 0 or a valid send stream ssrc. |
henrike@webrtc.org | 9de257d | 2013-07-17 14:42:53 +0000 | [diff] [blame] | 765 | // The valid value for the |event| are 0 to 15 which corresponding to |
| 766 | // DTMF event 0-9, *, #, A-D. |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 767 | virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 768 | // Gets quality stats for the channel. |
| 769 | virtual bool GetStats(VoiceMediaInfo* info) = 0; |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 770 | |
| 771 | virtual void SetRawAudioSink( |
| 772 | uint32_t ssrc, |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 773 | std::unique_ptr<webrtc::AudioSinkInterface> sink) = 0; |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 774 | |
| 775 | virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 776 | }; |
| 777 | |
Taylor Brandstetter | 5f0b83b | 2016-03-18 15:02:07 -0700 | [diff] [blame] | 778 | // TODO(deadbeef): Rename to VideoSenderParameters, since they're intended to |
| 779 | // encapsulate all the parameters needed for a video RtpSender. |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 780 | struct VideoSendParameters : RtpSendParameters<VideoCodec> { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 781 | VideoSendParameters(); |
| 782 | ~VideoSendParameters() override; |
nisse | 4b4dc86 | 2016-02-17 05:25:36 -0800 | [diff] [blame] | 783 | // Use conference mode? This flag comes from the remote |
| 784 | // description's SDP line 'a=x-google-flag:conference', copied over |
| 785 | // by VideoChannel::SetRemoteContent_w, and ultimately used by |
| 786 | // conference mode screencast logic in |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 787 | // WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig. |
nisse | 4b4dc86 | 2016-02-17 05:25:36 -0800 | [diff] [blame] | 788 | // The special screencast behaviour is disabled by default. |
| 789 | bool conference_mode = false; |
Steve Anton | 003930a | 2018-03-29 12:37:21 -0700 | [diff] [blame] | 790 | |
| 791 | protected: |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 792 | std::map<std::string, std::string> ToStringMap() const override; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 793 | }; |
| 794 | |
Taylor Brandstetter | 5f0b83b | 2016-03-18 15:02:07 -0700 | [diff] [blame] | 795 | // TODO(deadbeef): Rename to VideoReceiverParameters, since they're intended to |
| 796 | // encapsulate all the parameters needed for a video RtpReceiver. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 797 | struct VideoRecvParameters : RtpParameters<VideoCodec> {}; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 798 | |
Ruslan Burakov | 493a650 | 2019-02-27 15:32:48 +0100 | [diff] [blame] | 799 | class VideoMediaChannel : public MediaChannel, public Delayable { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 800 | public: |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 801 | VideoMediaChannel() {} |
terelius | 54f9171 | 2016-06-01 11:18:56 -0700 | [diff] [blame] | 802 | explicit VideoMediaChannel(const MediaConfig& config) |
| 803 | : MediaChannel(config) {} |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 804 | ~VideoMediaChannel() override {} |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 805 | |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 806 | cricket::MediaType media_type() const override; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 807 | virtual bool SetSendParameters(const VideoSendParameters& params) = 0; |
| 808 | virtual bool SetRecvParameters(const VideoRecvParameters& params) = 0; |
deadbeef | 3bc1510 | 2017-04-20 19:25:07 -0700 | [diff] [blame] | 809 | // Get the receive parameters for the incoming stream identified by |ssrc|. |
| 810 | // If |ssrc| is 0, retrieve the receive parameters for the default receive |
| 811 | // stream, which is used when SSRCs are not signaled. Note that calling with |
| 812 | // an |ssrc| of 0 will return encoding parameters with an unset |ssrc| |
| 813 | // member. |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 814 | virtual webrtc::RtpParameters GetRtpReceiveParameters( |
| 815 | uint32_t ssrc) const = 0; |
| 816 | virtual bool SetRtpReceiveParameters( |
| 817 | uint32_t ssrc, |
| 818 | const webrtc::RtpParameters& parameters) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 819 | // Gets the currently set codecs/payload types to be used for outgoing media. |
| 820 | virtual bool GetSendCodec(VideoCodec* send_codec) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 821 | // Starts or stops transmission (and potentially capture) of local video. |
| 822 | virtual bool SetSend(bool send) = 0; |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 823 | // Configure stream for sending and register a source. |
| 824 | // The |ssrc| must correspond to a registered send stream. |
| 825 | virtual bool SetVideoSend( |
| 826 | uint32_t ssrc, |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 827 | const VideoOptions* options, |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 828 | rtc::VideoSourceInterface<webrtc::VideoFrame>* source) = 0; |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 829 | // Sets the sink object to be used for the specified stream. |
deadbeef | 3bc1510 | 2017-04-20 19:25:07 -0700 | [diff] [blame] | 830 | // If SSRC is 0, the sink is used for the 'default' stream. |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 831 | virtual bool SetSink(uint32_t ssrc, |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 832 | rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) = 0; |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 833 | // This fills the "bitrate parts" (rtx, video bitrate) of the |
| 834 | // BandwidthEstimationInfo, since that part that isn't possible to get |
| 835 | // through webrtc::Call::GetStats, as they are statistics of the send |
| 836 | // streams. |
| 837 | // TODO(holmer): We should change this so that either BWE graphs doesn't |
| 838 | // need access to bitrates of the streams, or change the (RTC)StatsCollector |
| 839 | // so that it's getting the send stream stats separately by calling |
| 840 | // GetStats(), and merges with BandwidthEstimationInfo by itself. |
| 841 | virtual void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 842 | // Gets quality stats for the channel. |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 843 | virtual bool GetStats(VideoMediaInfo* info) = 0; |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 844 | |
| 845 | virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 846 | }; |
| 847 | |
| 848 | enum DataMessageType { |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 849 | // Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID |
| 850 | // values. |
| 851 | DMT_NONE = 0, |
| 852 | DMT_CONTROL = 1, |
| 853 | DMT_BINARY = 2, |
| 854 | DMT_TEXT = 3, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 855 | }; |
| 856 | |
| 857 | // Info about data received in DataMediaChannel. For use in |
| 858 | // DataMediaChannel::SignalDataReceived and in all of the signals that |
| 859 | // signal fires, on up the chain. |
| 860 | struct ReceiveDataParams { |
| 861 | // The in-packet stream indentifier. |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 862 | // RTP data channels use SSRCs, SCTP data channels use SIDs. |
| 863 | union { |
| 864 | uint32_t ssrc; |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 865 | int sid = 0; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 866 | }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 867 | // The type of message (binary, text, or control). |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 868 | DataMessageType type = DMT_TEXT; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 869 | // A per-stream value incremented per packet in the stream. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 870 | int seq_num = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 871 | // A per-stream value monotonically increasing with time. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 872 | int timestamp = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 873 | }; |
| 874 | |
| 875 | struct SendDataParams { |
| 876 | // The in-packet stream indentifier. |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 877 | // RTP data channels use SSRCs, SCTP data channels use SIDs. |
| 878 | union { |
| 879 | uint32_t ssrc; |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 880 | int sid = 0; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 881 | }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 882 | // The type of message (binary, text, or control). |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 883 | DataMessageType type = DMT_TEXT; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 884 | |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 885 | // TODO(pthatcher): Make |ordered| and |reliable| true by default? |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 886 | // For SCTP, whether to send messages flagged as ordered or not. |
| 887 | // If false, messages can be received out of order. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 888 | bool ordered = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 889 | // For SCTP, whether the messages are sent reliably or not. |
| 890 | // If false, messages may be lost. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 891 | bool reliable = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 892 | // For SCTP, if reliable == false, provide partial reliability by |
| 893 | // resending up to this many times. Either count or millis |
| 894 | // is supported, not both at the same time. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 895 | int max_rtx_count = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 896 | // For SCTP, if reliable == false, provide partial reliability by |
| 897 | // resending for up to this many milliseconds. Either count or millis |
| 898 | // is supported, not both at the same time. |
Steve Anton | 002f921 | 2018-01-09 16:38:15 -0800 | [diff] [blame] | 899 | int max_rtx_ms = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 900 | }; |
| 901 | |
| 902 | enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK }; |
| 903 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 904 | struct DataSendParameters : RtpSendParameters<DataCodec> {}; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 905 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 906 | struct DataRecvParameters : RtpParameters<DataCodec> {}; |
Peter Thatcher | c2ee2c8 | 2015-08-07 16:05:34 -0700 | [diff] [blame] | 907 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 908 | class DataMediaChannel : public MediaChannel { |
| 909 | public: |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 910 | DataMediaChannel(); |
| 911 | explicit DataMediaChannel(const MediaConfig& config); |
| 912 | ~DataMediaChannel() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 913 | |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 914 | cricket::MediaType media_type() const override; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 915 | virtual bool SetSendParameters(const DataSendParameters& params) = 0; |
| 916 | virtual bool SetRecvParameters(const DataRecvParameters& params) = 0; |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 917 | |
Amit Hilbuch | ea7ef2a | 2019-02-19 15:20:21 -0800 | [diff] [blame] | 918 | // RtpParameter methods are not supported for Data channel. |
| 919 | webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override; |
| 920 | webrtc::RTCError SetRtpSendParameters( |
| 921 | uint32_t ssrc, |
| 922 | const webrtc::RtpParameters& parameters) override; |
| 923 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 924 | // TODO(pthatcher): Implement this. |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 925 | virtual bool GetStats(DataMediaInfo* info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 926 | |
| 927 | virtual bool SetSend(bool send) = 0; |
| 928 | virtual bool SetReceive(bool receive) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 929 | |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 930 | void OnNetworkRouteChanged(const std::string& transport_name, |
| 931 | const rtc::NetworkRoute& network_route) override {} |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 932 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 933 | virtual bool SendData(const SendDataParams& params, |
| 934 | const rtc::CopyOnWriteBuffer& payload, |
| 935 | SendDataResult* result = NULL) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 936 | // Signals when data is received (params, data, len) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 937 | sigslot::signal3<const ReceiveDataParams&, const char*, size_t> |
| 938 | SignalDataReceived; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 939 | // Signal when the media channel is ready to send the stream. Arguments are: |
| 940 | // writable(bool) |
| 941 | sigslot::signal1<bool> SignalReadyToSend; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 942 | }; |
| 943 | |
| 944 | } // namespace cricket |
| 945 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 946 | #endif // MEDIA_BASE_MEDIA_CHANNEL_H_ |