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