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_FAKEMEDIAENGINE_H_ |
| 12 | #define MEDIA_BASE_FAKEMEDIAENGINE_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
| 14 | #include <list> |
| 15 | #include <map> |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 16 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 17 | #include <set> |
| 18 | #include <string> |
Steve Anton | e78bcb9 | 2017-10-31 09:53:08 -0700 | [diff] [blame] | 19 | #include <tuple> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "api/call/audio_sink.h" |
| 23 | #include "media/base/audiosource.h" |
| 24 | #include "media/base/mediaengine.h" |
| 25 | #include "media/base/rtputils.h" |
| 26 | #include "media/base/streamparams.h" |
| 27 | #include "media/engine/webrtcvideoengine.h" |
| 28 | #include "modules/audio_processing/include/audio_processing.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "rtc_base/copyonwritebuffer.h" |
| 30 | #include "rtc_base/networkroute.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 31 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 32 | using webrtc::RtpExtension; |
| 33 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | namespace cricket { |
| 35 | |
| 36 | class FakeMediaEngine; |
| 37 | class FakeVideoEngine; |
| 38 | class FakeVoiceEngine; |
| 39 | |
| 40 | // A common helper class that handles sending and receiving RTP/RTCP packets. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 41 | template <class Base> |
| 42 | class RtpHelper : public Base { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | public: |
| 44 | RtpHelper() |
| 45 | : sending_(false), |
| 46 | playout_(false), |
| 47 | fail_set_send_codecs_(false), |
| 48 | fail_set_recv_codecs_(false), |
| 49 | send_ssrc_(0), |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 50 | ready_to_send_(false), |
| 51 | transport_overhead_per_packet_(0), |
| 52 | num_network_route_changes_(0) {} |
| 53 | virtual ~RtpHelper() = default; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 54 | const std::vector<RtpExtension>& recv_extensions() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 55 | return recv_extensions_; |
| 56 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 57 | const std::vector<RtpExtension>& send_extensions() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | return send_extensions_; |
| 59 | } |
| 60 | bool sending() const { return sending_; } |
| 61 | bool playout() const { return playout_; } |
| 62 | const std::list<std::string>& rtp_packets() const { return rtp_packets_; } |
| 63 | const std::list<std::string>& rtcp_packets() const { return rtcp_packets_; } |
| 64 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 65 | bool SendRtp(const void* data, |
| 66 | size_t len, |
| 67 | const rtc::PacketOptions& options) { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 68 | if (!sending_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 69 | return false; |
| 70 | } |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 71 | rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len, |
| 72 | kMaxRtpPacketLen); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 73 | return Base::SendPacket(&packet, options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 75 | bool SendRtcp(const void* data, size_t len) { |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 76 | rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len, |
| 77 | kMaxRtpPacketLen); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 78 | return Base::SendRtcp(&packet, rtc::PacketOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 81 | bool CheckRtp(const void* data, size_t len) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | bool success = !rtp_packets_.empty(); |
| 83 | if (success) { |
| 84 | std::string packet = rtp_packets_.front(); |
| 85 | rtp_packets_.pop_front(); |
| 86 | success = (packet == std::string(static_cast<const char*>(data), len)); |
| 87 | } |
| 88 | return success; |
| 89 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 90 | bool CheckRtcp(const void* data, size_t len) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | bool success = !rtcp_packets_.empty(); |
| 92 | if (success) { |
| 93 | std::string packet = rtcp_packets_.front(); |
| 94 | rtcp_packets_.pop_front(); |
| 95 | success = (packet == std::string(static_cast<const char*>(data), len)); |
| 96 | } |
| 97 | return success; |
| 98 | } |
| 99 | bool CheckNoRtp() { return rtp_packets_.empty(); } |
| 100 | bool CheckNoRtcp() { return rtcp_packets_.empty(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; } |
| 102 | void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; } |
| 103 | virtual bool AddSendStream(const StreamParams& sp) { |
| 104 | if (std::find(send_streams_.begin(), send_streams_.end(), sp) != |
| 105 | send_streams_.end()) { |
| 106 | return false; |
| 107 | } |
| 108 | send_streams_.push_back(sp); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 109 | rtp_send_parameters_[sp.first_ssrc()] = |
Seth Hampson | 2d2c888 | 2018-05-16 16:02:32 -0700 | [diff] [blame] | 110 | CreateRtpParametersWithEncodings(sp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 111 | return true; |
| 112 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 113 | virtual bool RemoveSendStream(uint32_t ssrc) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 114 | auto parameters_iterator = rtp_send_parameters_.find(ssrc); |
| 115 | if (parameters_iterator != rtp_send_parameters_.end()) { |
| 116 | rtp_send_parameters_.erase(parameters_iterator); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 117 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 118 | return RemoveStreamBySsrc(&send_streams_, ssrc); |
| 119 | } |
| 120 | virtual bool AddRecvStream(const StreamParams& sp) { |
| 121 | if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) != |
| 122 | receive_streams_.end()) { |
| 123 | return false; |
| 124 | } |
| 125 | receive_streams_.push_back(sp); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 126 | rtp_receive_parameters_[sp.first_ssrc()] = |
| 127 | CreateRtpParametersWithOneEncoding(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 128 | return true; |
| 129 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 130 | virtual bool RemoveRecvStream(uint32_t ssrc) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 131 | auto parameters_iterator = rtp_receive_parameters_.find(ssrc); |
| 132 | if (parameters_iterator != rtp_receive_parameters_.end()) { |
| 133 | rtp_receive_parameters_.erase(parameters_iterator); |
| 134 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 135 | return RemoveStreamBySsrc(&receive_streams_, ssrc); |
| 136 | } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 137 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 138 | virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const { |
| 139 | auto parameters_iterator = rtp_send_parameters_.find(ssrc); |
| 140 | if (parameters_iterator != rtp_send_parameters_.end()) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 141 | return parameters_iterator->second; |
| 142 | } |
| 143 | return webrtc::RtpParameters(); |
| 144 | } |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 145 | virtual webrtc::RTCError SetRtpSendParameters( |
| 146 | uint32_t ssrc, |
| 147 | const webrtc::RtpParameters& parameters) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 148 | auto parameters_iterator = rtp_send_parameters_.find(ssrc); |
| 149 | if (parameters_iterator != rtp_send_parameters_.end()) { |
Florent Castelli | 892acf0 | 2018-10-01 22:47:20 +0200 | [diff] [blame] | 150 | auto result = |
| 151 | ValidateRtpParameters(parameters_iterator->second, parameters); |
| 152 | if (!result.ok()) |
| 153 | return result; |
| 154 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 155 | parameters_iterator->second = parameters; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 156 | return webrtc::RTCError::OK(); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 157 | } |
| 158 | // Replicate the behavior of the real media channel: return false |
| 159 | // when setting parameters for unknown SSRCs. |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 160 | return webrtc::RTCError(webrtc::RTCErrorType::INTERNAL_ERROR); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | virtual webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const { |
| 164 | auto parameters_iterator = rtp_receive_parameters_.find(ssrc); |
| 165 | if (parameters_iterator != rtp_receive_parameters_.end()) { |
| 166 | return parameters_iterator->second; |
| 167 | } |
| 168 | return webrtc::RtpParameters(); |
| 169 | } |
| 170 | virtual bool SetRtpReceiveParameters( |
| 171 | uint32_t ssrc, |
| 172 | const webrtc::RtpParameters& parameters) { |
| 173 | auto parameters_iterator = rtp_receive_parameters_.find(ssrc); |
| 174 | if (parameters_iterator != rtp_receive_parameters_.end()) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 175 | parameters_iterator->second = parameters; |
| 176 | return true; |
| 177 | } |
| 178 | // Replicate the behavior of the real media channel: return false |
| 179 | // when setting parameters for unknown SSRCs. |
| 180 | return false; |
| 181 | } |
| 182 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 183 | bool IsStreamMuted(uint32_t ssrc) const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 184 | bool ret = muted_streams_.find(ssrc) != muted_streams_.end(); |
| 185 | // If |ssrc = 0| check if the first send stream is muted. |
| 186 | if (!ret && ssrc == 0 && !send_streams_.empty()) { |
| 187 | return muted_streams_.find(send_streams_[0].first_ssrc()) != |
| 188 | muted_streams_.end(); |
| 189 | } |
| 190 | return ret; |
| 191 | } |
| 192 | const std::vector<StreamParams>& send_streams() const { |
| 193 | return send_streams_; |
| 194 | } |
| 195 | const std::vector<StreamParams>& recv_streams() const { |
| 196 | return receive_streams_; |
| 197 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 198 | bool HasRecvStream(uint32_t ssrc) const { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 199 | return GetStreamBySsrc(receive_streams_, ssrc) != nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 200 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 201 | bool HasSendStream(uint32_t ssrc) const { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 202 | return GetStreamBySsrc(send_streams_, ssrc) != nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 203 | } |
| 204 | // TODO(perkj): This is to support legacy unit test that only check one |
| 205 | // sending stream. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 206 | uint32_t send_ssrc() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 207 | if (send_streams_.empty()) |
| 208 | return 0; |
| 209 | return send_streams_[0].first_ssrc(); |
| 210 | } |
| 211 | |
| 212 | // TODO(perkj): This is to support legacy unit test that only check one |
| 213 | // sending stream. |
| 214 | const std::string rtcp_cname() { |
| 215 | if (send_streams_.empty()) |
| 216 | return ""; |
| 217 | return send_streams_[0].cname; |
| 218 | } |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 219 | const RtcpParameters& send_rtcp_parameters() { return send_rtcp_parameters_; } |
| 220 | const RtcpParameters& recv_rtcp_parameters() { return recv_rtcp_parameters_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 221 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 222 | bool ready_to_send() const { return ready_to_send_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 223 | |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 224 | int transport_overhead_per_packet() const { |
| 225 | return transport_overhead_per_packet_; |
| 226 | } |
| 227 | |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 228 | rtc::NetworkRoute last_network_route() const { return last_network_route_; } |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 229 | int num_network_route_changes() const { return num_network_route_changes_; } |
| 230 | void set_num_network_route_changes(int changes) { |
| 231 | num_network_route_changes_ = changes; |
| 232 | } |
| 233 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 234 | protected: |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 235 | bool MuteStream(uint32_t ssrc, bool mute) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 236 | if (!HasSendStream(ssrc) && ssrc != 0) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 237 | return false; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 238 | } |
| 239 | if (mute) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 240 | muted_streams_.insert(ssrc); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 241 | } else { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 242 | muted_streams_.erase(ssrc); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 243 | } |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 244 | return true; |
| 245 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 246 | bool set_sending(bool send) { |
| 247 | sending_ = send; |
| 248 | return true; |
| 249 | } |
| 250 | void set_playout(bool playout) { playout_ = playout; } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 251 | bool SetRecvRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 252 | recv_extensions_ = extensions; |
| 253 | return true; |
| 254 | } |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 255 | bool SetSendExtmapAllowMixed(bool extmap_allow_mixed) { |
| 256 | if (Base::ExtmapAllowMixed() != extmap_allow_mixed) { |
| 257 | Base::SetExtmapAllowMixed(extmap_allow_mixed); |
| 258 | } |
| 259 | return true; |
| 260 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 261 | bool SetSendRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 262 | send_extensions_ = extensions; |
| 263 | return true; |
| 264 | } |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 265 | void set_send_rtcp_parameters(const RtcpParameters& params) { |
| 266 | send_rtcp_parameters_ = params; |
| 267 | } |
| 268 | void set_recv_rtcp_parameters(const RtcpParameters& params) { |
| 269 | recv_rtcp_parameters_ = params; |
| 270 | } |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 271 | virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 272 | int64_t packet_time_us) { |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 273 | rtp_packets_.push_back(std::string(packet->data<char>(), packet->size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 274 | } |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 275 | virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 276 | int64_t packet_time_us) { |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 277 | rtcp_packets_.push_back(std::string(packet->data<char>(), packet->size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 278 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 279 | virtual void OnReadyToSend(bool ready) { ready_to_send_ = ready; } |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 280 | |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 281 | virtual void OnNetworkRouteChanged(const std::string& transport_name, |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 282 | const rtc::NetworkRoute& network_route) { |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 283 | last_network_route_ = network_route; |
| 284 | ++num_network_route_changes_; |
Zhi Huang | 5f5918f | 2017-11-12 17:26:23 -0800 | [diff] [blame] | 285 | transport_overhead_per_packet_ = network_route.packet_overhead; |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 286 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 287 | bool fail_set_send_codecs() const { return fail_set_send_codecs_; } |
| 288 | bool fail_set_recv_codecs() const { return fail_set_recv_codecs_; } |
| 289 | |
| 290 | private: |
| 291 | bool sending_; |
| 292 | bool playout_; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 293 | std::vector<RtpExtension> recv_extensions_; |
| 294 | std::vector<RtpExtension> send_extensions_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 295 | std::list<std::string> rtp_packets_; |
| 296 | std::list<std::string> rtcp_packets_; |
| 297 | std::vector<StreamParams> send_streams_; |
| 298 | std::vector<StreamParams> receive_streams_; |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 299 | RtcpParameters send_rtcp_parameters_; |
| 300 | RtcpParameters recv_rtcp_parameters_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 301 | std::set<uint32_t> muted_streams_; |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 302 | std::map<uint32_t, webrtc::RtpParameters> rtp_send_parameters_; |
| 303 | std::map<uint32_t, webrtc::RtpParameters> rtp_receive_parameters_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 304 | bool fail_set_send_codecs_; |
| 305 | bool fail_set_recv_codecs_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 306 | uint32_t send_ssrc_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 307 | std::string rtcp_cname_; |
| 308 | bool ready_to_send_; |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 309 | int transport_overhead_per_packet_; |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 310 | rtc::NetworkRoute last_network_route_; |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 311 | int num_network_route_changes_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 312 | }; |
| 313 | |
| 314 | class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { |
| 315 | public: |
| 316 | struct DtmfInfo { |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 317 | DtmfInfo(uint32_t ssrc, int event_code, int duration); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 318 | uint32_t ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 319 | int event_code; |
| 320 | int duration; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 321 | }; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 322 | explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 323 | const AudioOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 324 | ~FakeVoiceMediaChannel(); |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 325 | const std::vector<AudioCodec>& recv_codecs() const; |
| 326 | const std::vector<AudioCodec>& send_codecs() const; |
| 327 | const std::vector<AudioCodec>& codecs() const; |
| 328 | const std::vector<DtmfInfo>& dtmf_info_queue() const; |
| 329 | const AudioOptions& options() const; |
| 330 | int max_bps() const; |
| 331 | bool SetSendParameters(const AudioSendParameters& params) override; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 332 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 333 | bool SetRecvParameters(const AudioRecvParameters& params) override; |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 334 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 335 | void SetPlayout(bool playout) override; |
| 336 | void SetSend(bool send) override; |
| 337 | bool SetAudioSend(uint32_t ssrc, |
| 338 | bool enable, |
| 339 | const AudioOptions* options, |
| 340 | AudioSource* source) override; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 341 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 342 | bool HasSource(uint32_t ssrc) const; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 343 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 344 | bool AddRecvStream(const StreamParams& sp) override; |
| 345 | bool RemoveRecvStream(uint32_t ssrc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 346 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 347 | bool CanInsertDtmf() override; |
| 348 | bool InsertDtmf(uint32_t ssrc, int event_code, int duration) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 349 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 350 | bool SetOutputVolume(uint32_t ssrc, double volume) override; |
| 351 | bool GetOutputVolume(uint32_t ssrc, double* volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 352 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 353 | bool GetStats(VoiceMediaInfo* info) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 354 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 355 | void SetRawAudioSink( |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 356 | uint32_t ssrc, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 357 | std::unique_ptr<webrtc::AudioSinkInterface> sink) override; |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 358 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 359 | std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override; |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 360 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 361 | private: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 362 | class VoiceChannelAudioSink : public AudioSource::Sink { |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 363 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 364 | explicit VoiceChannelAudioSink(AudioSource* source); |
| 365 | ~VoiceChannelAudioSink() override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 366 | void OnData(const void* audio_data, |
| 367 | int bits_per_sample, |
| 368 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 369 | size_t number_of_channels, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 370 | size_t number_of_frames) override; |
| 371 | void OnClose() override; |
| 372 | AudioSource* source() const; |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 373 | |
| 374 | private: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 375 | AudioSource* source_; |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 376 | }; |
| 377 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 378 | bool SetRecvCodecs(const std::vector<AudioCodec>& codecs); |
| 379 | bool SetSendCodecs(const std::vector<AudioCodec>& codecs); |
| 380 | bool SetMaxSendBandwidth(int bps); |
| 381 | bool SetOptions(const AudioOptions& options); |
| 382 | bool SetLocalSource(uint32_t ssrc, AudioSource* source); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 383 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 384 | FakeVoiceEngine* engine_; |
| 385 | std::vector<AudioCodec> recv_codecs_; |
| 386 | std::vector<AudioCodec> send_codecs_; |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 387 | std::map<uint32_t, double> output_scalings_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 388 | std::vector<DtmfInfo> dtmf_info_queue_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 389 | AudioOptions options_; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 390 | std::map<uint32_t, std::unique_ptr<VoiceChannelAudioSink>> local_sinks_; |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 391 | std::unique_ptr<webrtc::AudioSinkInterface> sink_; |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 392 | int max_bps_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 393 | }; |
| 394 | |
| 395 | // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 396 | bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, |
| 397 | uint32_t ssrc, |
| 398 | int event_code, |
| 399 | int duration); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 400 | |
| 401 | class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { |
| 402 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 403 | FakeVideoMediaChannel(FakeVideoEngine* engine, const VideoOptions& options); |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 404 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 405 | ~FakeVideoMediaChannel(); |
| 406 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 407 | const std::vector<VideoCodec>& recv_codecs() const; |
| 408 | const std::vector<VideoCodec>& send_codecs() const; |
| 409 | const std::vector<VideoCodec>& codecs() const; |
| 410 | bool rendering() const; |
| 411 | const VideoOptions& options() const; |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 412 | const std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*>& |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 413 | sinks() const; |
| 414 | int max_bps() const; |
| 415 | bool SetSendParameters(const VideoSendParameters& params) override; |
| 416 | bool SetRecvParameters(const VideoRecvParameters& params) override; |
| 417 | bool AddSendStream(const StreamParams& sp) override; |
| 418 | bool RemoveSendStream(uint32_t ssrc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 419 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 420 | bool GetSendCodec(VideoCodec* send_codec) override; |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 421 | bool SetSink(uint32_t ssrc, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 422 | rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override; |
| 423 | bool HasSink(uint32_t ssrc) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 424 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 425 | bool SetSend(bool send) override; |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 426 | bool SetVideoSend( |
| 427 | uint32_t ssrc, |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 428 | const VideoOptions* options, |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 429 | rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override; |
nisse | 2ded9b1 | 2016-04-08 02:23:55 -0700 | [diff] [blame] | 430 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 431 | bool HasSource(uint32_t ssrc) const; |
| 432 | bool AddRecvStream(const StreamParams& sp) override; |
| 433 | bool RemoveRecvStream(uint32_t ssrc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 434 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 435 | void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override; |
| 436 | bool GetStats(VideoMediaInfo* info) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 437 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 438 | std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override; |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame] | 439 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 440 | private: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 441 | bool SetRecvCodecs(const std::vector<VideoCodec>& codecs); |
| 442 | bool SetSendCodecs(const std::vector<VideoCodec>& codecs); |
| 443 | bool SetOptions(const VideoOptions& options); |
| 444 | bool SetMaxSendBandwidth(int bps); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 445 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 446 | FakeVideoEngine* engine_; |
| 447 | std::vector<VideoCodec> recv_codecs_; |
| 448 | std::vector<VideoCodec> send_codecs_; |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 449 | std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*> sinks_; |
| 450 | std::map<uint32_t, rtc::VideoSourceInterface<webrtc::VideoFrame>*> sources_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 451 | VideoOptions options_; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 452 | int max_bps_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 453 | }; |
| 454 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 455 | // Dummy option class, needed for the DataTraits abstraction in |
| 456 | // channel_unittest.c. |
| 457 | class DataOptions {}; |
| 458 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 459 | class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { |
| 460 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 461 | explicit FakeDataMediaChannel(void* unused, const DataOptions& options); |
| 462 | ~FakeDataMediaChannel(); |
| 463 | const std::vector<DataCodec>& recv_codecs() const; |
| 464 | const std::vector<DataCodec>& send_codecs() const; |
| 465 | const std::vector<DataCodec>& codecs() const; |
| 466 | int max_bps() const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 467 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 468 | bool SetSendParameters(const DataSendParameters& params) override; |
| 469 | bool SetRecvParameters(const DataRecvParameters& params) override; |
| 470 | bool SetSend(bool send) override; |
| 471 | bool SetReceive(bool receive) override; |
| 472 | bool AddRecvStream(const StreamParams& sp) override; |
| 473 | bool RemoveRecvStream(uint32_t ssrc) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 474 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 475 | bool SendData(const SendDataParams& params, |
| 476 | const rtc::CopyOnWriteBuffer& payload, |
| 477 | SendDataResult* result) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 478 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 479 | SendDataParams last_sent_data_params(); |
| 480 | std::string last_sent_data(); |
| 481 | bool is_send_blocked(); |
| 482 | void set_send_blocked(bool blocked); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 483 | |
| 484 | private: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 485 | bool SetRecvCodecs(const std::vector<DataCodec>& codecs); |
| 486 | bool SetSendCodecs(const std::vector<DataCodec>& codecs); |
| 487 | bool SetMaxSendBandwidth(int bps); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 488 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 489 | std::vector<DataCodec> recv_codecs_; |
| 490 | std::vector<DataCodec> send_codecs_; |
| 491 | SendDataParams last_sent_data_params_; |
| 492 | std::string last_sent_data_; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 493 | bool send_blocked_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 494 | int max_bps_; |
| 495 | }; |
| 496 | |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame^] | 497 | class FakeVoiceEngine : public VoiceEngineInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 498 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 499 | FakeVoiceEngine(); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame^] | 500 | RtpCapabilities GetCapabilities() const override; |
| 501 | void Init() override; |
| 502 | rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 503 | |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame^] | 504 | VoiceMediaChannel* CreateMediaChannel( |
| 505 | webrtc::Call* call, |
| 506 | const MediaConfig& config, |
| 507 | const AudioOptions& options, |
| 508 | const webrtc::CryptoOptions& crypto_options) override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 509 | FakeVoiceMediaChannel* GetChannel(size_t index); |
| 510 | void UnregisterChannel(VoiceMediaChannel* channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 511 | |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 512 | // TODO(ossu): For proper testing, These should either individually settable |
| 513 | // or the voice engine should reference mockable factories. |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame^] | 514 | const std::vector<AudioCodec>& send_codecs() const override; |
| 515 | const std::vector<AudioCodec>& recv_codecs() const override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 516 | void SetCodecs(const std::vector<AudioCodec>& codecs); |
| 517 | int GetInputLevel(); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame^] | 518 | bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) override; |
| 519 | void StopAecDump() override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 520 | bool StartRtcEventLog(rtc::PlatformFile file, int64_t max_size_bytes); |
| 521 | void StopRtcEventLog(); |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 522 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 523 | private: |
| 524 | std::vector<FakeVoiceMediaChannel*> channels_; |
| 525 | std::vector<AudioCodec> codecs_; |
Sebastian Jansson | 7e6b528 | 2018-10-23 14:04:07 +0200 | [diff] [blame] | 526 | bool fail_create_channel_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 527 | |
| 528 | friend class FakeMediaEngine; |
| 529 | }; |
| 530 | |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame^] | 531 | class FakeVideoEngine : public VideoEngineInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 532 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 533 | FakeVideoEngine(); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame^] | 534 | RtpCapabilities GetCapabilities() const override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 535 | bool SetOptions(const VideoOptions& options); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame^] | 536 | VideoMediaChannel* CreateMediaChannel( |
| 537 | webrtc::Call* call, |
| 538 | const MediaConfig& config, |
| 539 | const VideoOptions& options, |
| 540 | const webrtc::CryptoOptions& crypto_options) override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 541 | FakeVideoMediaChannel* GetChannel(size_t index); |
| 542 | void UnregisterChannel(VideoMediaChannel* channel); |
Sebastian Jansson | 84848f2 | 2018-11-16 10:40:36 +0100 | [diff] [blame^] | 543 | std::vector<VideoCodec> codecs() const override; |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 544 | void SetCodecs(const std::vector<VideoCodec> codecs); |
| 545 | bool SetCapture(bool capture); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 546 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 547 | private: |
| 548 | std::vector<FakeVideoMediaChannel*> channels_; |
| 549 | std::vector<VideoCodec> codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 550 | bool capture_; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 551 | VideoOptions options_; |
Sebastian Jansson | 7e6b528 | 2018-10-23 14:04:07 +0200 | [diff] [blame] | 552 | bool fail_create_channel_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 553 | |
| 554 | friend class FakeMediaEngine; |
| 555 | }; |
| 556 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 557 | class FakeMediaEngine |
| 558 | : public CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 559 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 560 | FakeMediaEngine(); |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 561 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 562 | ~FakeMediaEngine() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 563 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 564 | void SetAudioCodecs(const std::vector<AudioCodec>& codecs); |
| 565 | void SetVideoCodecs(const std::vector<VideoCodec>& codecs); |
| 566 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 567 | FakeVoiceMediaChannel* GetVoiceChannel(size_t index); |
| 568 | FakeVideoMediaChannel* GetVideoChannel(size_t index); |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 569 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 570 | void set_fail_create_channel(bool fail); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 571 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 572 | private: |
| 573 | FakeVoiceEngine* const voice_; |
| 574 | FakeVideoEngine* const video_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 575 | }; |
| 576 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 577 | // Have to come afterwards due to declaration order |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 578 | |
| 579 | class FakeDataEngine : public DataEngineInterface { |
| 580 | public: |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 581 | DataMediaChannel* CreateChannel(const MediaConfig& config) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 582 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 583 | FakeDataMediaChannel* GetChannel(size_t index); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 584 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 585 | void UnregisterChannel(DataMediaChannel* channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 586 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 587 | void SetDataCodecs(const std::vector<DataCodec>& data_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 588 | |
Sebastian Jansson | cb06cac | 2018-10-18 17:03:30 +0200 | [diff] [blame] | 589 | const std::vector<DataCodec>& data_codecs() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 590 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 591 | private: |
| 592 | std::vector<FakeDataMediaChannel*> channels_; |
| 593 | std::vector<DataCodec> data_codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 594 | }; |
| 595 | |
| 596 | } // namespace cricket |
| 597 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 598 | #endif // MEDIA_BASE_FAKEMEDIAENGINE_H_ |