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> |
| 20 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "api/call/audio_sink.h" |
| 24 | #include "media/base/audiosource.h" |
| 25 | #include "media/base/mediaengine.h" |
| 26 | #include "media/base/rtputils.h" |
| 27 | #include "media/base/streamparams.h" |
| 28 | #include "media/engine/webrtcvideoengine.h" |
| 29 | #include "modules/audio_processing/include/audio_processing.h" |
| 30 | #include "p2p/base/sessiondescription.h" |
| 31 | #include "rtc_base/checks.h" |
| 32 | #include "rtc_base/copyonwritebuffer.h" |
| 33 | #include "rtc_base/networkroute.h" |
| 34 | #include "rtc_base/ptr_util.h" |
| 35 | #include "rtc_base/stringutils.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 36 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 37 | using webrtc::RtpExtension; |
| 38 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | namespace cricket { |
| 40 | |
| 41 | class FakeMediaEngine; |
| 42 | class FakeVideoEngine; |
| 43 | class FakeVoiceEngine; |
| 44 | |
| 45 | // A common helper class that handles sending and receiving RTP/RTCP packets. |
| 46 | template <class Base> class RtpHelper : public Base { |
| 47 | public: |
| 48 | RtpHelper() |
| 49 | : sending_(false), |
| 50 | playout_(false), |
| 51 | fail_set_send_codecs_(false), |
| 52 | fail_set_recv_codecs_(false), |
| 53 | send_ssrc_(0), |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 54 | ready_to_send_(false), |
| 55 | transport_overhead_per_packet_(0), |
| 56 | num_network_route_changes_(0) {} |
| 57 | virtual ~RtpHelper() = default; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 58 | const std::vector<RtpExtension>& recv_extensions() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | return recv_extensions_; |
| 60 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 61 | const std::vector<RtpExtension>& send_extensions() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | return send_extensions_; |
| 63 | } |
| 64 | bool sending() const { return sending_; } |
| 65 | bool playout() const { return playout_; } |
| 66 | const std::list<std::string>& rtp_packets() const { return rtp_packets_; } |
| 67 | const std::list<std::string>& rtcp_packets() const { return rtcp_packets_; } |
| 68 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 69 | bool SendRtp(const void* data, |
| 70 | size_t len, |
| 71 | const rtc::PacketOptions& options) { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 72 | if (!sending_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | return false; |
| 74 | } |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 75 | rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len, |
| 76 | kMaxRtpPacketLen); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 77 | return Base::SendPacket(&packet, options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 79 | bool SendRtcp(const void* data, size_t len) { |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 80 | rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len, |
| 81 | kMaxRtpPacketLen); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 82 | return Base::SendRtcp(&packet, rtc::PacketOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 85 | bool CheckRtp(const void* data, size_t len) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | bool success = !rtp_packets_.empty(); |
| 87 | if (success) { |
| 88 | std::string packet = rtp_packets_.front(); |
| 89 | rtp_packets_.pop_front(); |
| 90 | success = (packet == std::string(static_cast<const char*>(data), len)); |
| 91 | } |
| 92 | return success; |
| 93 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 94 | bool CheckRtcp(const void* data, size_t len) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | bool success = !rtcp_packets_.empty(); |
| 96 | if (success) { |
| 97 | std::string packet = rtcp_packets_.front(); |
| 98 | rtcp_packets_.pop_front(); |
| 99 | success = (packet == std::string(static_cast<const char*>(data), len)); |
| 100 | } |
| 101 | return success; |
| 102 | } |
| 103 | bool CheckNoRtp() { return rtp_packets_.empty(); } |
| 104 | bool CheckNoRtcp() { return rtcp_packets_.empty(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 105 | void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; } |
| 106 | void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; } |
| 107 | virtual bool AddSendStream(const StreamParams& sp) { |
| 108 | if (std::find(send_streams_.begin(), send_streams_.end(), sp) != |
| 109 | send_streams_.end()) { |
| 110 | return false; |
| 111 | } |
| 112 | send_streams_.push_back(sp); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 113 | rtp_send_parameters_[sp.first_ssrc()] = |
| 114 | CreateRtpParametersWithOneEncoding(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 115 | return true; |
| 116 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 117 | virtual bool RemoveSendStream(uint32_t ssrc) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 118 | auto parameters_iterator = rtp_send_parameters_.find(ssrc); |
| 119 | if (parameters_iterator != rtp_send_parameters_.end()) { |
| 120 | rtp_send_parameters_.erase(parameters_iterator); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 121 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | return RemoveStreamBySsrc(&send_streams_, ssrc); |
| 123 | } |
| 124 | virtual bool AddRecvStream(const StreamParams& sp) { |
| 125 | if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) != |
| 126 | receive_streams_.end()) { |
| 127 | return false; |
| 128 | } |
| 129 | receive_streams_.push_back(sp); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 130 | rtp_receive_parameters_[sp.first_ssrc()] = |
| 131 | CreateRtpParametersWithOneEncoding(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 132 | return true; |
| 133 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 134 | virtual bool RemoveRecvStream(uint32_t ssrc) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 135 | auto parameters_iterator = rtp_receive_parameters_.find(ssrc); |
| 136 | if (parameters_iterator != rtp_receive_parameters_.end()) { |
| 137 | rtp_receive_parameters_.erase(parameters_iterator); |
| 138 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 139 | return RemoveStreamBySsrc(&receive_streams_, ssrc); |
| 140 | } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 141 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 142 | virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const { |
| 143 | auto parameters_iterator = rtp_send_parameters_.find(ssrc); |
| 144 | if (parameters_iterator != rtp_send_parameters_.end()) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 145 | return parameters_iterator->second; |
| 146 | } |
| 147 | return webrtc::RtpParameters(); |
| 148 | } |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 149 | virtual bool SetRtpSendParameters(uint32_t ssrc, |
| 150 | const webrtc::RtpParameters& parameters) { |
| 151 | auto parameters_iterator = rtp_send_parameters_.find(ssrc); |
| 152 | if (parameters_iterator != rtp_send_parameters_.end()) { |
| 153 | parameters_iterator->second = parameters; |
| 154 | return true; |
| 155 | } |
| 156 | // Replicate the behavior of the real media channel: return false |
| 157 | // when setting parameters for unknown SSRCs. |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | virtual webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const { |
| 162 | auto parameters_iterator = rtp_receive_parameters_.find(ssrc); |
| 163 | if (parameters_iterator != rtp_receive_parameters_.end()) { |
| 164 | return parameters_iterator->second; |
| 165 | } |
| 166 | return webrtc::RtpParameters(); |
| 167 | } |
| 168 | virtual bool SetRtpReceiveParameters( |
| 169 | uint32_t ssrc, |
| 170 | const webrtc::RtpParameters& parameters) { |
| 171 | auto parameters_iterator = rtp_receive_parameters_.find(ssrc); |
| 172 | if (parameters_iterator != rtp_receive_parameters_.end()) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 173 | parameters_iterator->second = parameters; |
| 174 | return true; |
| 175 | } |
| 176 | // Replicate the behavior of the real media channel: return false |
| 177 | // when setting parameters for unknown SSRCs. |
| 178 | return false; |
| 179 | } |
| 180 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 181 | bool IsStreamMuted(uint32_t ssrc) const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 182 | bool ret = muted_streams_.find(ssrc) != muted_streams_.end(); |
| 183 | // If |ssrc = 0| check if the first send stream is muted. |
| 184 | if (!ret && ssrc == 0 && !send_streams_.empty()) { |
| 185 | return muted_streams_.find(send_streams_[0].first_ssrc()) != |
| 186 | muted_streams_.end(); |
| 187 | } |
| 188 | return ret; |
| 189 | } |
| 190 | const std::vector<StreamParams>& send_streams() const { |
| 191 | return send_streams_; |
| 192 | } |
| 193 | const std::vector<StreamParams>& recv_streams() const { |
| 194 | return receive_streams_; |
| 195 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 196 | bool HasRecvStream(uint32_t ssrc) const { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 197 | return GetStreamBySsrc(receive_streams_, ssrc) != nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 198 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 199 | bool HasSendStream(uint32_t ssrc) const { |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 200 | return GetStreamBySsrc(send_streams_, ssrc) != nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 201 | } |
| 202 | // TODO(perkj): This is to support legacy unit test that only check one |
| 203 | // sending stream. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 204 | uint32_t send_ssrc() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 205 | if (send_streams_.empty()) |
| 206 | return 0; |
| 207 | return send_streams_[0].first_ssrc(); |
| 208 | } |
| 209 | |
| 210 | // TODO(perkj): This is to support legacy unit test that only check one |
| 211 | // sending stream. |
| 212 | const std::string rtcp_cname() { |
| 213 | if (send_streams_.empty()) |
| 214 | return ""; |
| 215 | return send_streams_[0].cname; |
| 216 | } |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 217 | const RtcpParameters& send_rtcp_parameters() { return send_rtcp_parameters_; } |
| 218 | const RtcpParameters& recv_rtcp_parameters() { return recv_rtcp_parameters_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 219 | |
| 220 | bool ready_to_send() const { |
| 221 | return ready_to_send_; |
| 222 | } |
| 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 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 255 | bool SetSendRtpHeaderExtensions(const std::vector<RtpExtension>& extensions) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 256 | send_extensions_ = extensions; |
| 257 | return true; |
| 258 | } |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 259 | void set_send_rtcp_parameters(const RtcpParameters& params) { |
| 260 | send_rtcp_parameters_ = params; |
| 261 | } |
| 262 | void set_recv_rtcp_parameters(const RtcpParameters& params) { |
| 263 | recv_rtcp_parameters_ = params; |
| 264 | } |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 265 | virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 266 | const rtc::PacketTime& packet_time) { |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 267 | rtp_packets_.push_back(std::string(packet->data<char>(), packet->size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 268 | } |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 269 | virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 270 | const rtc::PacketTime& packet_time) { |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 271 | rtcp_packets_.push_back(std::string(packet->data<char>(), packet->size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 272 | } |
| 273 | virtual void OnReadyToSend(bool ready) { |
| 274 | ready_to_send_ = ready; |
| 275 | } |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 276 | virtual void OnTransportOverheadChanged(int transport_overhead_per_packet) { |
| 277 | transport_overhead_per_packet_ = transport_overhead_per_packet; |
| 278 | } |
| 279 | |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 280 | virtual void OnNetworkRouteChanged(const std::string& transport_name, |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 281 | const rtc::NetworkRoute& network_route) { |
Honghai Zhang | cc411c0 | 2016-03-29 17:27:21 -0700 | [diff] [blame] | 282 | last_network_route_ = network_route; |
| 283 | ++num_network_route_changes_; |
| 284 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 285 | bool fail_set_send_codecs() const { return fail_set_send_codecs_; } |
| 286 | bool fail_set_recv_codecs() const { return fail_set_recv_codecs_; } |
| 287 | |
| 288 | private: |
| 289 | bool sending_; |
| 290 | bool playout_; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 291 | std::vector<RtpExtension> recv_extensions_; |
| 292 | std::vector<RtpExtension> send_extensions_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 293 | std::list<std::string> rtp_packets_; |
| 294 | std::list<std::string> rtcp_packets_; |
| 295 | std::vector<StreamParams> send_streams_; |
| 296 | std::vector<StreamParams> receive_streams_; |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 297 | RtcpParameters send_rtcp_parameters_; |
| 298 | RtcpParameters recv_rtcp_parameters_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 299 | std::set<uint32_t> muted_streams_; |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 300 | std::map<uint32_t, webrtc::RtpParameters> rtp_send_parameters_; |
| 301 | std::map<uint32_t, webrtc::RtpParameters> rtp_receive_parameters_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 302 | bool fail_set_send_codecs_; |
| 303 | bool fail_set_recv_codecs_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 304 | uint32_t send_ssrc_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 305 | std::string rtcp_cname_; |
| 306 | bool ready_to_send_; |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 307 | int transport_overhead_per_packet_; |
Honghai Zhang | 0e533ef | 2016-04-19 15:41:36 -0700 | [diff] [blame] | 308 | rtc::NetworkRoute last_network_route_; |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 309 | int num_network_route_changes_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 310 | }; |
| 311 | |
| 312 | class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { |
| 313 | public: |
| 314 | struct DtmfInfo { |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 315 | DtmfInfo(uint32_t ssrc, int event_code, int duration) |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 316 | : ssrc(ssrc), |
| 317 | event_code(event_code), |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 318 | duration(duration) {} |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 319 | uint32_t ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 320 | int event_code; |
| 321 | int duration; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 322 | }; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 323 | explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine, |
| 324 | const AudioOptions& options) |
solenberg | 55c5be0 | 2017-02-10 01:20:25 -0800 | [diff] [blame] | 325 | : engine_(engine), max_bps_(-1) { |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 326 | output_scalings_[0] = 1.0; // For default channel. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 327 | SetOptions(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 328 | } |
| 329 | ~FakeVoiceMediaChannel(); |
| 330 | const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; } |
| 331 | const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; } |
| 332 | const std::vector<AudioCodec>& codecs() const { return send_codecs(); } |
| 333 | const std::vector<DtmfInfo>& dtmf_info_queue() const { |
| 334 | return dtmf_info_queue_; |
| 335 | } |
| 336 | const AudioOptions& options() const { return options_; } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 337 | int max_bps() const { return max_bps_; } |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 338 | virtual bool SetSendParameters(const AudioSendParameters& params) { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 339 | set_send_rtcp_parameters(params.rtcp); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 340 | return (SetSendCodecs(params.codecs) && |
| 341 | SetSendRtpHeaderExtensions(params.extensions) && |
| 342 | SetMaxSendBandwidth(params.max_bandwidth_bps) && |
| 343 | SetOptions(params.options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 344 | } |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 345 | |
| 346 | virtual bool SetRecvParameters(const AudioRecvParameters& params) { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 347 | set_recv_rtcp_parameters(params.rtcp); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 348 | return (SetRecvCodecs(params.codecs) && |
| 349 | SetRecvRtpHeaderExtensions(params.extensions)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 350 | } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 351 | |
aleloi | 84ef615 | 2016-08-04 05:28:21 -0700 | [diff] [blame] | 352 | virtual void SetPlayout(bool playout) { set_playout(playout); } |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 353 | virtual void SetSend(bool send) { set_sending(send); } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 354 | virtual bool SetAudioSend(uint32_t ssrc, |
| 355 | bool enable, |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 356 | const AudioOptions* options, |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 357 | AudioSource* source) { |
| 358 | if (!SetLocalSource(ssrc, source)) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 359 | return false; |
| 360 | } |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 361 | if (!RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, !enable)) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 362 | return false; |
| 363 | } |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 364 | if (enable && options) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 365 | return SetOptions(*options); |
| 366 | } |
| 367 | return true; |
| 368 | } |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 369 | |
| 370 | bool HasSource(uint32_t ssrc) const { |
| 371 | return local_sinks_.find(ssrc) != local_sinks_.end(); |
| 372 | } |
| 373 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 374 | virtual bool AddRecvStream(const StreamParams& sp) { |
| 375 | if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp)) |
| 376 | return false; |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 377 | output_scalings_[sp.first_ssrc()] = 1.0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 378 | return true; |
| 379 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 380 | virtual bool RemoveRecvStream(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 381 | if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc)) |
| 382 | return false; |
| 383 | output_scalings_.erase(ssrc); |
| 384 | return true; |
| 385 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 386 | |
| 387 | virtual bool GetActiveStreams(AudioInfo::StreamList* streams) { return true; } |
| 388 | virtual int GetOutputLevel() { return 0; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 389 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 390 | virtual bool CanInsertDtmf() { |
| 391 | for (std::vector<AudioCodec>::const_iterator it = send_codecs_.begin(); |
| 392 | it != send_codecs_.end(); ++it) { |
| 393 | // Find the DTMF telephone event "codec". |
| 394 | if (_stricmp(it->name.c_str(), "telephone-event") == 0) { |
| 395 | return true; |
| 396 | } |
| 397 | } |
| 398 | return false; |
| 399 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 400 | virtual bool InsertDtmf(uint32_t ssrc, |
| 401 | int event_code, |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 402 | int duration) { |
| 403 | dtmf_info_queue_.push_back(DtmfInfo(ssrc, event_code, duration)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 404 | return true; |
| 405 | } |
| 406 | |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 407 | virtual bool SetOutputVolume(uint32_t ssrc, double volume) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 408 | if (0 == ssrc) { |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 409 | std::map<uint32_t, double>::iterator it; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 410 | for (it = output_scalings_.begin(); it != output_scalings_.end(); ++it) { |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 411 | it->second = volume; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 412 | } |
| 413 | return true; |
| 414 | } else if (output_scalings_.find(ssrc) != output_scalings_.end()) { |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 415 | output_scalings_[ssrc] = volume; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 416 | return true; |
| 417 | } |
| 418 | return false; |
| 419 | } |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 420 | bool GetOutputVolume(uint32_t ssrc, double* volume) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 421 | if (output_scalings_.find(ssrc) == output_scalings_.end()) |
| 422 | return false; |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 423 | *volume = output_scalings_[ssrc]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 424 | return true; |
| 425 | } |
| 426 | |
| 427 | virtual bool GetStats(VoiceMediaInfo* info) { return false; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 428 | |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 429 | virtual void SetRawAudioSink( |
| 430 | uint32_t ssrc, |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 431 | std::unique_ptr<webrtc::AudioSinkInterface> sink) { |
deadbeef | 2d110be | 2016-01-13 12:00:26 -0800 | [diff] [blame] | 432 | sink_ = std::move(sink); |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 433 | } |
| 434 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 435 | virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const { |
| 436 | return std::vector<webrtc::RtpSource>(); |
| 437 | } |
| 438 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 439 | private: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 440 | class VoiceChannelAudioSink : public AudioSource::Sink { |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 441 | public: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 442 | explicit VoiceChannelAudioSink(AudioSource* source) : source_(source) { |
| 443 | source_->SetSink(this); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 444 | } |
| 445 | virtual ~VoiceChannelAudioSink() { |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 446 | if (source_) { |
| 447 | source_->SetSink(nullptr); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 448 | } |
| 449 | } |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 450 | void OnData(const void* audio_data, |
| 451 | int bits_per_sample, |
| 452 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 453 | size_t number_of_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 454 | size_t number_of_frames) override {} |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 455 | void OnClose() override { source_ = nullptr; } |
| 456 | AudioSource* source() const { return source_; } |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 457 | |
| 458 | private: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 459 | AudioSource* source_; |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 460 | }; |
| 461 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 462 | bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { |
| 463 | if (fail_set_recv_codecs()) { |
| 464 | // Fake the failure in SetRecvCodecs. |
| 465 | return false; |
| 466 | } |
| 467 | recv_codecs_ = codecs; |
| 468 | return true; |
| 469 | } |
| 470 | bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { |
| 471 | if (fail_set_send_codecs()) { |
| 472 | // Fake the failure in SetSendCodecs. |
| 473 | return false; |
| 474 | } |
| 475 | send_codecs_ = codecs; |
| 476 | return true; |
| 477 | } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 478 | bool SetMaxSendBandwidth(int bps) { |
| 479 | max_bps_ = bps; |
| 480 | return true; |
| 481 | } |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 482 | bool SetOptions(const AudioOptions& options) { |
| 483 | // Does a "merge" of current options and set options. |
| 484 | options_.SetAll(options); |
| 485 | return true; |
| 486 | } |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 487 | bool SetLocalSource(uint32_t ssrc, AudioSource* source) { |
| 488 | auto it = local_sinks_.find(ssrc); |
| 489 | if (source) { |
| 490 | if (it != local_sinks_.end()) { |
nisse | c16fa5e | 2017-02-07 07:18:43 -0800 | [diff] [blame] | 491 | RTC_CHECK(it->second->source() == source); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 492 | } else { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 493 | local_sinks_.insert(std::make_pair( |
| 494 | ssrc, rtc::MakeUnique<VoiceChannelAudioSink>(source))); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 495 | } |
| 496 | } else { |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 497 | if (it != local_sinks_.end()) { |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 498 | local_sinks_.erase(it); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | return true; |
| 502 | } |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 503 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 504 | FakeVoiceEngine* engine_; |
| 505 | std::vector<AudioCodec> recv_codecs_; |
| 506 | std::vector<AudioCodec> send_codecs_; |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 507 | std::map<uint32_t, double> output_scalings_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 508 | std::vector<DtmfInfo> dtmf_info_queue_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 509 | AudioOptions options_; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 510 | std::map<uint32_t, std::unique_ptr<VoiceChannelAudioSink>> local_sinks_; |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 511 | std::unique_ptr<webrtc::AudioSinkInterface> sink_; |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 512 | int max_bps_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 513 | }; |
| 514 | |
| 515 | // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. |
| 516 | inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 517 | uint32_t ssrc, |
| 518 | int event_code, |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 519 | int duration) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 520 | return (info.duration == duration && info.event_code == event_code && |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 521 | info.ssrc == ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { |
| 525 | public: |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 526 | FakeVideoMediaChannel(FakeVideoEngine* engine, const VideoOptions& options) |
Peter Boström | a6c39d9 | 2016-02-01 19:30:33 +0100 | [diff] [blame] | 527 | : engine_(engine), max_bps_(-1) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 528 | SetOptions(options); |
| 529 | } |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 530 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 531 | ~FakeVideoMediaChannel(); |
| 532 | |
| 533 | const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; } |
| 534 | const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; } |
| 535 | const std::vector<VideoCodec>& codecs() const { return send_codecs(); } |
| 536 | bool rendering() const { return playout(); } |
| 537 | const VideoOptions& options() const { return options_; } |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 538 | const std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*>& |
| 539 | sinks() const { |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 540 | return sinks_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 541 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 542 | int max_bps() const { return max_bps_; } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 543 | bool SetSendParameters(const VideoSendParameters& params) override { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 544 | set_send_rtcp_parameters(params.rtcp); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 545 | return (SetSendCodecs(params.codecs) && |
| 546 | SetSendRtpHeaderExtensions(params.extensions) && |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 547 | SetMaxSendBandwidth(params.max_bandwidth_bps)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 548 | } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 549 | bool SetRecvParameters(const VideoRecvParameters& params) override { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 550 | set_recv_rtcp_parameters(params.rtcp); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 551 | return (SetRecvCodecs(params.codecs) && |
| 552 | SetRecvRtpHeaderExtensions(params.extensions)); |
| 553 | } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 554 | bool AddSendStream(const StreamParams& sp) override { |
Peter Boström | ce23bee | 2016-02-02 14:14:30 +0100 | [diff] [blame] | 555 | return RtpHelper<VideoMediaChannel>::AddSendStream(sp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 556 | } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 557 | bool RemoveSendStream(uint32_t ssrc) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 558 | return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc); |
| 559 | } |
| 560 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 561 | bool GetSendCodec(VideoCodec* send_codec) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 562 | if (send_codecs_.empty()) { |
| 563 | return false; |
| 564 | } |
| 565 | *send_codec = send_codecs_[0]; |
| 566 | return true; |
| 567 | } |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 568 | bool SetSink(uint32_t ssrc, |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 569 | rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override { |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 570 | if (ssrc != 0 && sinks_.find(ssrc) == sinks_.end()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 571 | return false; |
| 572 | } |
| 573 | if (ssrc != 0) { |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 574 | sinks_[ssrc] = sink; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 575 | } |
| 576 | return true; |
| 577 | } |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 578 | bool HasSink(uint32_t ssrc) const { |
| 579 | return sinks_.find(ssrc) != sinks_.end() && sinks_.at(ssrc) != nullptr; |
| 580 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 581 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 582 | bool SetSend(bool send) override { return set_sending(send); } |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 583 | bool SetVideoSend( |
| 584 | uint32_t ssrc, |
| 585 | bool enable, |
| 586 | const VideoOptions* options, |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 587 | rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override { |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 588 | if (!RtpHelper<VideoMediaChannel>::MuteStream(ssrc, !enable)) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 589 | return false; |
| 590 | } |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 591 | if (enable && options) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 592 | if (!SetOptions(*options)) { |
| 593 | return false; |
| 594 | } |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 595 | } |
nisse | 2ded9b1 | 2016-04-08 02:23:55 -0700 | [diff] [blame] | 596 | sources_[ssrc] = source; |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 597 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 598 | } |
nisse | 2ded9b1 | 2016-04-08 02:23:55 -0700 | [diff] [blame] | 599 | |
| 600 | bool HasSource(uint32_t ssrc) const { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 601 | return sources_.find(ssrc) != sources_.end() && |
| 602 | sources_.at(ssrc) != nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 603 | } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 604 | bool AddRecvStream(const StreamParams& sp) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 605 | if (!RtpHelper<VideoMediaChannel>::AddRecvStream(sp)) |
| 606 | return false; |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 607 | sinks_[sp.first_ssrc()] = NULL; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 608 | return true; |
| 609 | } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 610 | bool RemoveRecvStream(uint32_t ssrc) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 611 | if (!RtpHelper<VideoMediaChannel>::RemoveRecvStream(ssrc)) |
| 612 | return false; |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 613 | sinks_.erase(ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 614 | return true; |
| 615 | } |
| 616 | |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 617 | void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override {} |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 618 | bool GetStats(VideoMediaInfo* info) override { return false; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 619 | |
| 620 | private: |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 621 | bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) { |
| 622 | if (fail_set_recv_codecs()) { |
| 623 | // Fake the failure in SetRecvCodecs. |
| 624 | return false; |
| 625 | } |
| 626 | recv_codecs_ = codecs; |
| 627 | return true; |
| 628 | } |
| 629 | bool SetSendCodecs(const std::vector<VideoCodec>& codecs) { |
| 630 | if (fail_set_send_codecs()) { |
| 631 | // Fake the failure in SetSendCodecs. |
| 632 | return false; |
| 633 | } |
| 634 | send_codecs_ = codecs; |
| 635 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 636 | return true; |
| 637 | } |
| 638 | bool SetOptions(const VideoOptions& options) { |
| 639 | options_ = options; |
| 640 | return true; |
| 641 | } |
| 642 | bool SetMaxSendBandwidth(int bps) { |
| 643 | max_bps_ = bps; |
| 644 | return true; |
| 645 | } |
| 646 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 647 | FakeVideoEngine* engine_; |
| 648 | std::vector<VideoCodec> recv_codecs_; |
| 649 | std::vector<VideoCodec> send_codecs_; |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 650 | std::map<uint32_t, rtc::VideoSinkInterface<webrtc::VideoFrame>*> sinks_; |
| 651 | std::map<uint32_t, rtc::VideoSourceInterface<webrtc::VideoFrame>*> sources_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 652 | VideoOptions options_; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 653 | int max_bps_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 654 | }; |
| 655 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 656 | // Dummy option class, needed for the DataTraits abstraction in |
| 657 | // channel_unittest.c. |
| 658 | class DataOptions {}; |
| 659 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 660 | class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { |
| 661 | public: |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 662 | explicit FakeDataMediaChannel(void* unused, const DataOptions& options) |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 663 | : send_blocked_(false), max_bps_(-1) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 664 | ~FakeDataMediaChannel() {} |
| 665 | const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; } |
| 666 | const std::vector<DataCodec>& send_codecs() const { return send_codecs_; } |
| 667 | const std::vector<DataCodec>& codecs() const { return send_codecs(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 668 | int max_bps() const { return max_bps_; } |
| 669 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 670 | virtual bool SetSendParameters(const DataSendParameters& params) { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 671 | set_send_rtcp_parameters(params.rtcp); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 672 | return (SetSendCodecs(params.codecs) && |
| 673 | SetMaxSendBandwidth(params.max_bandwidth_bps)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 674 | } |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 675 | virtual bool SetRecvParameters(const DataRecvParameters& params) { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 676 | set_recv_rtcp_parameters(params.rtcp); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 677 | return SetRecvCodecs(params.codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 678 | } |
| 679 | virtual bool SetSend(bool send) { return set_sending(send); } |
| 680 | virtual bool SetReceive(bool receive) { |
| 681 | set_playout(receive); |
| 682 | return true; |
| 683 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 684 | virtual bool AddRecvStream(const StreamParams& sp) { |
| 685 | if (!RtpHelper<DataMediaChannel>::AddRecvStream(sp)) |
| 686 | return false; |
| 687 | return true; |
| 688 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 689 | virtual bool RemoveRecvStream(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 690 | if (!RtpHelper<DataMediaChannel>::RemoveRecvStream(ssrc)) |
| 691 | return false; |
| 692 | return true; |
| 693 | } |
| 694 | |
| 695 | virtual bool SendData(const SendDataParams& params, |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 696 | const rtc::CopyOnWriteBuffer& payload, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 697 | SendDataResult* result) { |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 698 | if (send_blocked_) { |
| 699 | *result = SDR_BLOCK; |
| 700 | return false; |
| 701 | } else { |
| 702 | last_sent_data_params_ = params; |
Karl Wiberg | 9478437 | 2015-04-20 14:03:07 +0200 | [diff] [blame] | 703 | last_sent_data_ = std::string(payload.data<char>(), payload.size()); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 704 | return true; |
| 705 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | SendDataParams last_sent_data_params() { return last_sent_data_params_; } |
| 709 | std::string last_sent_data() { return last_sent_data_; } |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 710 | bool is_send_blocked() { return send_blocked_; } |
| 711 | void set_send_blocked(bool blocked) { send_blocked_ = blocked; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 712 | |
| 713 | private: |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 714 | bool SetRecvCodecs(const std::vector<DataCodec>& codecs) { |
| 715 | if (fail_set_recv_codecs()) { |
| 716 | // Fake the failure in SetRecvCodecs. |
| 717 | return false; |
| 718 | } |
| 719 | recv_codecs_ = codecs; |
| 720 | return true; |
| 721 | } |
| 722 | bool SetSendCodecs(const std::vector<DataCodec>& codecs) { |
| 723 | if (fail_set_send_codecs()) { |
| 724 | // Fake the failure in SetSendCodecs. |
| 725 | return false; |
| 726 | } |
| 727 | send_codecs_ = codecs; |
| 728 | return true; |
| 729 | } |
| 730 | bool SetMaxSendBandwidth(int bps) { |
| 731 | max_bps_ = bps; |
| 732 | return true; |
| 733 | } |
| 734 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 735 | std::vector<DataCodec> recv_codecs_; |
| 736 | std::vector<DataCodec> send_codecs_; |
| 737 | SendDataParams last_sent_data_params_; |
| 738 | std::string last_sent_data_; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 739 | bool send_blocked_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 740 | int max_bps_; |
| 741 | }; |
| 742 | |
| 743 | // A base class for all of the shared parts between FakeVoiceEngine |
| 744 | // and FakeVideoEngine. |
| 745 | class FakeBaseEngine { |
| 746 | public: |
| 747 | FakeBaseEngine() |
solenberg | bd13838 | 2015-11-20 16:08:07 -0800 | [diff] [blame] | 748 | : options_changed_(false), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 749 | fail_create_channel_(false) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 750 | void set_fail_create_channel(bool fail) { fail_create_channel_ = fail; } |
| 751 | |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 752 | RtpCapabilities GetCapabilities() const { return capabilities_; } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 753 | void set_rtp_header_extensions(const std::vector<RtpExtension>& extensions) { |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 754 | capabilities_.header_extensions = extensions; |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 755 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 756 | |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 757 | void set_rtp_header_extensions( |
| 758 | const std::vector<cricket::RtpHeaderExtension>& extensions) { |
| 759 | for (const cricket::RtpHeaderExtension& ext : extensions) { |
| 760 | RtpExtension webrtc_ext; |
| 761 | webrtc_ext.uri = ext.uri; |
| 762 | webrtc_ext.id = ext.id; |
| 763 | capabilities_.header_extensions.push_back(webrtc_ext); |
| 764 | } |
| 765 | } |
| 766 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 767 | protected: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 768 | // Flag used by optionsmessagehandler_unittest for checking whether any |
| 769 | // relevant setting has been updated. |
| 770 | // TODO(thaloun): Replace with explicit checks of before & after values. |
| 771 | bool options_changed_; |
| 772 | bool fail_create_channel_; |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 773 | RtpCapabilities capabilities_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 774 | }; |
| 775 | |
| 776 | class FakeVoiceEngine : public FakeBaseEngine { |
| 777 | public: |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 778 | FakeVoiceEngine() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 779 | // Add a fake audio codec. Note that the name must not be "" as there are |
| 780 | // sanity checks against that. |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 781 | codecs_.push_back(AudioCodec(101, "fake_audio_codec", 0, 0, 1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 782 | } |
deadbeef | eb02c03 | 2017-06-15 08:29:25 -0700 | [diff] [blame] | 783 | void Init() {} |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 784 | rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const { |
| 785 | return rtc::scoped_refptr<webrtc::AudioState>(); |
| 786 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 787 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 788 | VoiceMediaChannel* CreateChannel(webrtc::Call* call, |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 789 | const MediaConfig& config, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 790 | const AudioOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 791 | if (fail_create_channel_) { |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 792 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 795 | FakeVoiceMediaChannel* ch = new FakeVoiceMediaChannel(this, options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 796 | channels_.push_back(ch); |
| 797 | return ch; |
| 798 | } |
| 799 | FakeVoiceMediaChannel* GetChannel(size_t index) { |
| 800 | return (channels_.size() > index) ? channels_[index] : NULL; |
| 801 | } |
| 802 | void UnregisterChannel(VoiceMediaChannel* channel) { |
| 803 | channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); |
| 804 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 805 | |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 806 | // TODO(ossu): For proper testing, These should either individually settable |
| 807 | // or the voice engine should reference mockable factories. |
| 808 | const std::vector<AudioCodec>& send_codecs() { return codecs_; } |
| 809 | const std::vector<AudioCodec>& recv_codecs() { return codecs_; } |
| 810 | void SetCodecs(const std::vector<AudioCodec>& codecs) { codecs_ = codecs; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 811 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 812 | int GetInputLevel() { return 0; } |
| 813 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 814 | bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) { |
| 815 | return false; |
| 816 | } |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 817 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 818 | void StopAecDump() {} |
| 819 | |
ivoc | c1513ee | 2016-05-13 08:30:39 -0700 | [diff] [blame] | 820 | bool StartRtcEventLog(rtc::PlatformFile file, int64_t max_size_bytes) { |
| 821 | return false; |
| 822 | } |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 823 | |
| 824 | void StopRtcEventLog() {} |
| 825 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 826 | private: |
| 827 | std::vector<FakeVoiceMediaChannel*> channels_; |
| 828 | std::vector<AudioCodec> codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 829 | |
| 830 | friend class FakeMediaEngine; |
| 831 | }; |
| 832 | |
| 833 | class FakeVideoEngine : public FakeBaseEngine { |
| 834 | public: |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 835 | FakeVideoEngine() : capture_(false) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 836 | // Add a fake video codec. Note that the name must not be "" as there are |
| 837 | // sanity checks against that. |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 838 | codecs_.push_back(VideoCodec(0, "fake_video_codec")); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 839 | } |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 840 | |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 841 | bool SetOptions(const VideoOptions& options) { |
| 842 | options_ = options; |
| 843 | options_changed_ = true; |
| 844 | return true; |
| 845 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 846 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 847 | VideoMediaChannel* CreateChannel(webrtc::Call* call, |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 848 | const MediaConfig& config, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 849 | const VideoOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 850 | if (fail_create_channel_) { |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 851 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 852 | } |
| 853 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 854 | FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this, options); |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 855 | channels_.emplace_back(ch); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 856 | return ch; |
| 857 | } |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 858 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 859 | FakeVideoMediaChannel* GetChannel(size_t index) { |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 860 | return (channels_.size() > index) ? channels_[index] : nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 861 | } |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 862 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 863 | void UnregisterChannel(VideoMediaChannel* channel) { |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 864 | auto it = std::find(channels_.begin(), channels_.end(), channel); |
| 865 | RTC_DCHECK(it != channels_.end()); |
| 866 | channels_.erase(it); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | const std::vector<VideoCodec>& codecs() const { return codecs_; } |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 870 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 871 | void SetCodecs(const std::vector<VideoCodec> codecs) { codecs_ = codecs; } |
| 872 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 873 | bool SetCapture(bool capture) { |
| 874 | capture_ = capture; |
| 875 | return true; |
| 876 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 877 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 878 | private: |
| 879 | std::vector<FakeVideoMediaChannel*> channels_; |
| 880 | std::vector<VideoCodec> codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 881 | bool capture_; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 882 | VideoOptions options_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 883 | |
| 884 | friend class FakeMediaEngine; |
| 885 | }; |
| 886 | |
| 887 | class FakeMediaEngine : |
| 888 | public CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine> { |
| 889 | public: |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 890 | FakeMediaEngine() |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 891 | : CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine>(std::tuple<>(), |
| 892 | std::tuple<>()) { |
| 893 | } |
| 894 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 895 | virtual ~FakeMediaEngine() {} |
| 896 | |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 897 | void SetAudioCodecs(const std::vector<AudioCodec>& codecs) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 898 | voice().SetCodecs(codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 899 | } |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 900 | void SetVideoCodecs(const std::vector<VideoCodec>& codecs) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 901 | video().SetCodecs(codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 902 | } |
| 903 | |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 904 | void SetAudioRtpHeaderExtensions( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 905 | const std::vector<RtpExtension>& extensions) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 906 | voice().set_rtp_header_extensions(extensions); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 907 | } |
| 908 | void SetVideoRtpHeaderExtensions( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 909 | const std::vector<RtpExtension>& extensions) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 910 | video().set_rtp_header_extensions(extensions); |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 911 | } |
| 912 | |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 913 | void SetAudioRtpHeaderExtensions( |
| 914 | const std::vector<cricket::RtpHeaderExtension>& extensions) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 915 | voice().set_rtp_header_extensions(extensions); |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 916 | } |
| 917 | void SetVideoRtpHeaderExtensions( |
| 918 | const std::vector<cricket::RtpHeaderExtension>& extensions) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 919 | video().set_rtp_header_extensions(extensions); |
isheriff | a1c548b | 2016-05-31 16:12:24 -0700 | [diff] [blame] | 920 | } |
| 921 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 922 | FakeVoiceMediaChannel* GetVoiceChannel(size_t index) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 923 | return voice().GetChannel(index); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 924 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 925 | FakeVideoMediaChannel* GetVideoChannel(size_t index) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 926 | return video().GetChannel(index); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 927 | } |
| 928 | |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 929 | bool capture() const { return video().capture_; } |
| 930 | bool options_changed() const { return video().options_changed_; } |
| 931 | void clear_options_changed() { video().options_changed_ = false; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 932 | void set_fail_create_channel(bool fail) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 933 | voice().set_fail_create_channel(fail); |
| 934 | video().set_fail_create_channel(fail); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 935 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 936 | }; |
| 937 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 938 | // Have to come afterwards due to declaration order |
| 939 | inline FakeVoiceMediaChannel::~FakeVoiceMediaChannel() { |
| 940 | if (engine_) { |
| 941 | engine_->UnregisterChannel(this); |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | inline FakeVideoMediaChannel::~FakeVideoMediaChannel() { |
| 946 | if (engine_) { |
| 947 | engine_->UnregisterChannel(this); |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | class FakeDataEngine : public DataEngineInterface { |
| 952 | public: |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 953 | virtual DataMediaChannel* CreateChannel(const MediaConfig& config) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 954 | FakeDataMediaChannel* ch = new FakeDataMediaChannel(this, DataOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 955 | channels_.push_back(ch); |
| 956 | return ch; |
| 957 | } |
| 958 | |
| 959 | FakeDataMediaChannel* GetChannel(size_t index) { |
| 960 | return (channels_.size() > index) ? channels_[index] : NULL; |
| 961 | } |
| 962 | |
| 963 | void UnregisterChannel(DataMediaChannel* channel) { |
| 964 | channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); |
| 965 | } |
| 966 | |
| 967 | virtual void SetDataCodecs(const std::vector<DataCodec>& data_codecs) { |
| 968 | data_codecs_ = data_codecs; |
| 969 | } |
| 970 | |
| 971 | virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; } |
| 972 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 973 | private: |
| 974 | std::vector<FakeDataMediaChannel*> channels_; |
| 975 | std::vector<DataCodec> data_codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 976 | }; |
| 977 | |
| 978 | } // namespace cricket |
| 979 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 980 | #endif // MEDIA_BASE_FAKEMEDIAENGINE_H_ |