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