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