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